# Skills The Skills plugin is SkillsCatalog at the process. It registers Skills in every Session and SkillsBranch in every branch; each enabled Skill is a SkillContent row of its Session's SkillContentInstances group. ## SkillsCatalog Owner: [skills/catalog.rs](../../../../crates/dim-agent-capabilities/src/skills/catalog.rs) and [discovery.rs](../../../../crates/dim-agent-capabilities/src/skills/discovery.rs). The Skills plugin. It owns process-wide skill discovery caches and enablement, combining the user `.agents/skills` root, the skills roots plugins registered and the project `.agents/skills` root, in that order of precedence, into queryable views with issues, and registers the Skills parts that read them: [Skills](Skills.md#skills) in every Session and [SkillsBranch](Skills.md#skillsbranch) in every branch. The App Server's plugin of the same name mounts this catalog, adds its management methods and registers the same parts. ### Plugin content data face `skillsCatalog` is the process data face for the existing plugin-content operations. Each method accepts one object: `register({plugin, root})` returns the scan's `SkillIssue[]`, `withdraw({plugin})` returns `null`, `plugins({})` returns the registered plugin ids, and `issues({plugin})` returns that plugin's current issues. The Rust binding calls the same catalog operations directly. The embedding host and the Skills Session parts retain a private binding to this same owner for query, content and management work; no second catalog or scan is introduced. Rust consumers use `SkillsCatalogBinding` under this name. The binding exposes only these four owner operations, has no dereference or owner accessor, and shares one Arc with its dispatcher. Its static constructor lets an embedding host bind the catalog it already owns; it does not publish services or change `SkillsCatalogPlugin::mount`'s lifetime. The raw `SkillsCatalog` type is provided only at the private owner key. PluginManager keeps a public binding dependency. The wire root is a string converted at the filesystem input boundary. Native paths remain lossless. Diagnostic issues are tagged by `kind`: `invalidManifest {path, reason}`, `unreadable {path, reason}`, `rootUnreadable {root, reason}` and `scanLimitReached {root}`. Diagnostic paths use their existing display representation; they are not file identities. Errors retain the owner's code and message (`closed`, `skills_write_failed`, `skills_unavailable`); malformed requests return `invalid_request`. These operations have no caller cancellation argument. Once an asynchronous wire operation starts, abandoning its wait does not cancel or roll it back. Settings work uses the existing owner closing token. Completed registrations remain in Settings and are restored when the catalog reloads. The plugin identifier is a content key, not authorization. Product registration retains the existing Settings validation of a nonblank plugin string and an absolute root. A registration is persisted independently of the caller row; callers explicitly withdraw it when needed. Caller unload does not automatically remove registered content. ### Dependencies | Service | Purpose | | --- | --- | | `P:HostPlatform` | Resolve the user home root. | | `P:SkillSettingsHost` | Read and update enablement. | | `P:PartRegistry` | Register the Skills parts, until this plugin unloads. | ### Events and lifetime No Timeline events. Each time its version advances (a rescan, or a changed disabled set) the catalog emits `skills.catalog_changed {version}` on `catalog_changes()` (`skills/catalog`) from its own context, under its state lock, so announcements follow version order; listeners query the catalog for the view. Before its first settings read, the catalog listens with `ctx.events().on` to `settings.changed` on `settings_changes(SOURCE)`, its Settings source `skills`. The listener only wakes a tracked reader, which rereads the settings one read at a time so a stale response cannot overwrite newer settings. A host whose storage changes outside the catalog announces those writes there; the catalog reads back its own writes, so `MemorySkillSettings` (xtask, tests) announces nothing. A plugin's skills root is registered with `register_plugin(plugin, root)` and withdrawn with `withdraw_plugin(plugin)` ([PluginManager §3.7](../../../design/plugins/PluginManager.md#37-content-registration)). The catalog keeps the roots in its settings (`pluginSkills`), so they come back after its reload; registering scans the root at once and returns its issues, and `plugin_issues(plugin)` reads them later. Its Skills have ids `plugin::`. A queried entry reports the root it was found in as its source: `user`, `project` or `plugin:`. A client groups entries by that field and never reads the id's spelling, which names an absolute path for a project. ### Installations A Skill installation records a source the user chose, the Skills taken from it and the files it owns under the user root ([design](../../../design/plugins/Skills.md)). It is a member of the same Skills document (`installations`), read and written through the same port; its files live under `//`. | Operation | Behavior | | --- | --- | | `preview(root, id, cwd)` | Scans an acquired source tree, digests each Skill directory, and reports the user-root Skills a selection would conflict with and the plugin Skills, and the `cwd` project's Skills, it would hide. Writes nothing. | | `install(id, source, root, operation_dir, selection, replace)` | Digests the selected Skills and refuses a changed one (`StalePreview`), then replaces only what `replace` names: `Create` refuses a recorded id, `Recorded` replaces it, `Expected(record)` replaces exactly that record and refuses a changed one. A directory no record owns is reported as `UnmanagedDirectory` and never replaced. It copies the selection into `/place`, swaps it into place, commits the record, then rescans the user root and advances the version. | | `uninstall(id)` | Deletes `/` after a directory and link check, then the record, then rescans. A failed deletion keeps the record, the only proof of what the installation owns. | | `installation(id)`, `installations()` | The record, after a query. | A Skill's revision is a digest over its regular files, by relative path and bytes, with `.git` skipped and symbolic links refused; files are read in chunks, and one larger than 8 MiB is reported as an issue instead of digested. An installation's revision digests its ordered path and revision pairs. A separate `operating` lock serializes every root scan with an installation's placement, so no view is built from a half-swapped directory. Files are written before the record and the record before the version advances. First use scans roots via blocking work; explicit refresh updates cached discovery. Cancellation closes the catalog; cleanup joins its reader. Reload creates fresh discovery caches. Read failures remain explicit and queries can retry unavailable settings; this is not a filesystem watcher or proof that a settings mutation was durably saved. ### Tests [skills.rs](../../../../tests/integration/tests/skills.rs): `discovery_precedence_and_list_injection`, `enablement_changes_the_list_and_loading`, `a_late_update_response_does_not_overwrite_a_newer_setting`, `a_failed_read_back_is_reported_and_recovered_by_the_next_query`, `preview_lists_a_source_without_installing_it`, `install_copies_only_the_selected_skill`, `a_change_under_a_selected_skill_makes_the_preview_stale`, `install_refuses_conflicts_and_selections_outside_the_tree`, `install_replaces_an_installation_only_with_overwrite`, `install_replaces_only_a_directory_the_record_owns`, `an_update_cannot_reinstall_an_installation_removed_or_replaced_meanwhile`, `a_file_too_large_for_a_revision_is_reported_and_not_read`, `a_failed_record_write_restores_the_previous_installation`, `update_keeps_the_selection_and_reports_the_previous_record`, `remove_deletes_only_what_the_record_owns`, `a_new_catalog_restores_installations_from_settings`; [plugin_manager.rs](../../../../crates/dim-app-server/tests/transport_flow/plugin_manager.rs): `plugin_content_reaches_sessions_through_its_owners`; [skills_installation.rs](../../../../crates/dim-app-server/tests/transport_flow/skills_installation.rs): `skills_preview_install_update_and_remove_a_repository`, `skills_replies_and_the_user_document_stay_safe`, `skills_startup_removes_a_staging_root_an_abnormal_end_left`. ## Skills Owner: [skills/session.rs](../../../../crates/dim-agent-capabilities/src/skills/session.rs). Selects content from the catalog, owns Session loader content instances and aggregates their contributions into the skill tool and instructions/list prompt sources. ### Model-facing texts Skills writes two texts for the model. Each is protocol or policy as [model-facing prompts §4](../../../design/model-prompts.md#4-protocol-and-policy) decides; the instructions are mixed. | Text | Class and sentences | | --- | --- | | `dim/skills/instructions`, in the system prefix | Protocol: "A skill is a local instruction bundle stored in a SKILL.md file." states what a skill is, "Discovery: The latest `` lists the skills available in this session, each with a name and, when space allows, a description." names the state source the list arrives in, "A `/skill:name` token names the exact skill to load." names a token, "Use `skill({ "skill_name": "" })` to load the full SKILL.md instructions." states the call shape, and "A `/skill:name` token followed in the same message by a `` block means that skill is already loaded: follow the block and do not call `skill` for it." states which path loaded it. Policy: the trigger rules, loading, multiple-match, missing-or-blocked, context-hygiene and safety guidance, and "Use the `skill` tool to load the full instructions before applying a skill." | | `dim/skills/list`, as a `` block | Protocol: the format — one `- : ` or `- ` line per enabled skill the model may invoke, names listed always and descriptions added cheapest first within the character budget, escaped — and the source name the block carries. The names and descriptions are the skills' own data | The list arrives in a `` block, so its guide entry is Prompt's ([Prompt §4](../../../design/plugins/Prompt.md#4-the-built-in-entries-and-their-writers)): Skills writes no marker of its own and contributes no entry. The `skill` tool's declaration is built-in and mixed: its schema is protocol, and so is "Load and apply a named skill's full SKILL.md instructions." because it states what the tool loads; the rest is policy — the `BLOCKING REQUIREMENT` rule, what makes a request match a skill, and invoking the tool before answering. Those policy sentences have no factory member yet, and get one in the change that first evaluates a candidate for them. Its result is Skills' own: the `Skill:`, `Description:`, `File:`, `Allowed tools:` and `Instructions:` layout and the refusals "Invalid input: skill_name must be a string", "Skills unavailable: …", "Skill is disabled: …" and "Unknown skill: …" are protocol, and the loaded body is the skill author's own text. ### Dependencies | Service | Purpose | | --- | --- | | `P:SkillsCatalog#dim/skills/catalog-owner` | Query user/project skills; its `skills.catalog_changed` events drive replacement. | | `S:SessionConfig` | Select the Session working directory. | | `S:SessionLoader` | Lock-free creation of Session-owned content instances. | | `S:SessionLifecycle` | Start catalog-driven replacement only after the Session is published. | | `S:SkillsConfig` | The factory configuration of this plugin, registered and provided by `skills::install_with_config`; its `instructions` text replaces the built-in skill instructions when set, `skillsConfig.get` exposes it as data, and a profile that registers the parts without the install declares and reads none. | | `S:PromptRegistry` | Register the list and instructions sources, until this part unloads. | | `S:ToolRegistry` | Register the `skill` tool, until this part unloads. | | `S:SubmitChecks` | Register the check `skills` with the Session's submit checks, until this part unloads: `/skill:` tokens in operator input load those Skills with the same input ([Skills §9](../../../design/plugins/Skills.md#9-references-load-with-the-operators-input)). | `SkillsInstructionsSettingsHost`, the operator's override of the instructions, is provided by the App Server's execution-root assembly. The part declares it only where its name is registered, reads it while applying, and keeps the built-in text when it is absent or fails; the factory `SkillsConfig` outranks it ([prompt overrides](../../../design/appserver/prompt-overrides.md)). ### Content instances `SkillContentInstances` is an instanced Session extension template. Skills calls `sessionLoader.create` with the Skill id as `definitionId` and the immutable definition as `instanceData`. SkillContent publishes the definition at its private Session-scoped key. Skills reads the contributions of the instances it owns and releases them through `sessionLoader.remove`. The catalog still owns source precedence, shadowing and enablement. Skills owns selection and reconciliation, not a second lifecycle tree. Unchanged definitions retain their instances. Body-only refresh replaces only changed content and changes the view digest, without repeating unchanged list text. Views are built from ready content services, never directly from enabled catalog definitions. A view is rebuilt at each catalog change; a leaf withdrawn on its own does not change the current view until then. Apply listens to `catalog_changes()` with `ctx.events().on` before its first query and creates the initial instances as part of Session assembly. The listener only wakes the Session's tracked replacement task: rutis awaits one channel's listeners in turn, and every Session listens on the same channel. Replacement after a catalog change waits for `SessionLifecycle::activated()`, so assembly readiness never observes an instance that the replacement task retires, and a Session that fails assembly never replaces content. Changes announced meanwhile are adopted by the first update after publication. Replacement ends when `SessionLifecycle::closing()` returns: closing wins over a simultaneous change, and an update in progress is cancelled but awaited, so a closing Session creates no content and abandons no partial instance. Cancellation is not logged as a content failure. ### Events and lifetime No direct Timeline events. The tracked replacement task replaces the Session view; SkillsBranch requests list adoption. The tool returns full skill content as a plain tool result, not a second history-rendering route. Cleanup joins the replacement task and shuts down every content fiber; tool handlers reject work after generation cancellation. Initial creation also runs in a tracked task, so dropping apply cannot abandon it. Creation is awaited to settlement even if cancelled, then an unusable instance is shut down. Failed updates drain partial/current instances and publish an unavailable view. `sessionLoader.remove` propagates cleanup failures; no lock-taking loader mutation runs in apply or dispose. Content lifecycle failures use the existing public `SkillsError::Closed` state, with details logged; disposer failures propagate to Session shutdown. Catalog errors retain their existing public variants. Closing one Session cannot dispose another Session's contents. Reload queries a fresh view. Unavailable settings isolate skills without disabling unrelated execution. Listed metadata and loaded body can change between view updates; loading uses the current view rather than an old model-visible list. ### Tests [skills.rs](../../../../tests/integration/tests/skills.rs): `load_returns_the_body_as_a_plain_tool_result`, `enablement_changes_the_list_and_loading`, `skill_loads_the_latest_view_after_queue_and_steer_interleave`, `content_instances_are_session_owned_and_only_changed_content_is_replaced`, `catalog_changes_during_assembly_wait_for_session_publication`, `a_closing_session_creates_no_content_instances`, `unavailable_settings_isolate_skills_and_refresh_recovers_existing_sessions`. The `skills` check is covered by `crates/dim-app-server/tests/transport_flow/skill_references.rs` (`a_reference_loads_the_skill_with_the_submitted_input`, `a_steer_reference_gets_the_block`, `a_branch_prompt_gets_no_block`, `a_disabled_or_unknown_name_adds_nothing`, `repeated_references_load_one_block_each_in_first_reference_order`, `a_restored_session_keeps_the_block_in_its_recorded_input`) and `hooks_flow::a_prompt_submit_hook_precedes_a_referenced_skill`. ## SkillsBranch Owner: [skills/session.rs](../../../../crates/dim-agent-capabilities/src/skills/session.rs). Provides `skillsBranch`, the read-only Session skill list reached through a branch, and requests adoption of a changed list through `ConfigureControl`; initial adoption belongs to Prompt. ### Data face `skillsBranch.list({})` is synchronous and returns the existing ordered list of enabled Skills: `[{id, name, description, userInvocable}]`. A Skill with `userInvocable: false` remains in the reply; input palettes use that field to omit it. The request must be one empty object; malformed requests fail with `invalid_request`. Owner failures retain the existing Skills error code and message; the management client boundary still maps owner `closed` to its reload error. Rust `SkillsBranch::list` and the dispatcher read the same Session-owned view once. The call performs no scan, reload, subscription or asynchronous work, so it has no retained wait to cancel. The branch's service is withdrawn with the branch. Session view updates and prompt adoption keep their existing lifetimes below. `SessionSkills` is private Skills owner state. The Session part and branch parts share its typed key in the Session instance; it has no public catalog name. Its content, prompt loader and change watch remain with Skills. The public face returns data without exposing that owner object. TypeScript callers import the `SkillsBranch` binding from `dimcode/plugin` (declared in `npm/plugin.d.ts`). This manually dispatched face is not an entry in the generated `Services` map. ### Dependencies | Service | Purpose | | --- | --- | | `S:SessionSkills` | Private typed key for the current view and change watch within the Skills owner. | | `B:BranchLifecycle` | Wait for activation; stop on closing. | | `B:dyn ConfigureControl` | Adopt the changed list as prompt configuration. | ### Events and lifetime No direct Timeline subscription or production. A tracked watcher starts after activation, coalesces Session view changes and requests `dim/skills/list` configuration. Generation cancellation stops the watcher; cleanup joins it. Reload creates a new watcher, not a filesystem watcher or durable catalog. Failed adoption is logged; a later view change can retry. ### Tests [skills.rs](../../../../tests/integration/tests/skills.rs), especially `a_view_change_inside_a_turn_reaches_the_next_request` and `enablement_changes_the_list_and_loading`. ## SkillContentInstances Owner: [skills/mod.rs](../../../../crates/dim-agent-capabilities/src/skills/mod.rs). The instanced loader group containing one [SkillContent](Skills.md#skillcontent) leaf. ### Dependencies None on the group itself. ### Events and lifetime This is a structural template, not an installer or a second lifecycle manager. Skills creates instances in the Session subtree and supplies immutable private content. Closing the Session disposes its groups. Template configuration never carries mutable per-Session definitions. See [Skills](Skills.md) for selection. ### Tests [skills.rs](../../../../tests/integration/tests/skills.rs) covers independent instances and selective replacement through public Session flows. ## SkillContent Owner: [skills/content.rs](../../../../crates/dim-agent-capabilities/src/skills/content.rs). An immutable enabled Skill definition contributed by a Session-owned loader instance. ### Dependencies None: its instance value carries what it needs. ### Events and lifetime The leaf publishes its immutable definition under the private key derived from `definitionId` in its Session. Unloading the leaf withdraws that binding. See [Skills](Skills.md) for update and failure rules. ### Tests [skills.rs](../../../../tests/integration/tests/skills.rs) covers loading actual content, selective replacement, disabled content and independent Session closure.