Files
deepseek-harness/packages/skill/tool-skill
creatixchu ccd27f3775 fix(web): address the second review round on context provenance
- An empty replacement catalog is a real catalog: `renderCatalogUpdate()`
  publishes zero entries when the last skill disappears, and falling back
  would hide that every earlier name was retired.
- The opaque fallback keeps a `form` declaration this version cannot present.
  It is the one place a newer or foreign log's declared shape would otherwise
  vanish from the UI entirely, since the row marker is also absent there.
- An instruction change with an unrecognized `action` disqualifies the record.
  The action decides the word the row shows, so an unknown one would be
  presented as loaded or updated.
- The catalog list bounds itself and reports the withheld count. Entry count
  is unbounded and the scrollport bounds height, not node count.
- A catalog message keeps content blocks this version does not know, instead
  of dropping model-visible content the extensible union may carry.
- `core.md` defines `ContextFormed`, the interface actually carrying the
  optional field, beside `ContextForm`.
- The superseded-in-part bullet states the affected clauses as one rule rather
  than enumerating them; two rounds of enumeration each missed some, which is
  the shape being fragile rather than the list being wrong.
- The note records the one migration case that does not self-heal: an
  old-format catalog as the only one, with an empty current view, leaves a
  stale catalog nothing replaces.
2026-08-05 16:51:01 +08:00
..

@deepseek-ai/dsh-tool-skill

English | 中文

The model-facing skill catalog and skill tool.

Requires ctx.agents, ctx.tools, and ctx.skills (inject: ['agents', 'tools', 'skills']).

Catalog lifecycle

At every agent/step, the plugin calls ctx.skills.snapshot() for the calling session's cwd, forwards the step abort signal to discovery, applies exact skill tool visibility, and renders the ordered name and description entries. When no prior catalog exists and that view is non-empty, it injects an initial durable user-role <system-reminder> before the request. Catalog messages contain only those summaries; skill bodies, paths, sources, providers, and whenToUse hints remain outside the catalog.

Every catalog message carries the skill-catalog source: a catalog-form context whose entries record exactly the name and description pairs it published, plus update on a replacement. The digest covers those durable entries, not the rendered prose, so the surrounding <system-reminder> framing — written for the model — cannot decide whether a republish is needed, and a consumer presenting the list never re-parses the <available_skills> block. The plugin scans durable session events backwards without copying them and derives the comparison baseline from the newest visible skill-catalog message it can read; an unreadable record is skipped like any foreign one. When the digest changes, agent.inject() records a durable user-role message containing the complete replacement catalog; an empty replacement explicitly retires earlier names. If no catalog remains visible but a recognizable historical catalog exists, compaction hid it and the next complete observation re-establishes the current catalog. An incomplete provider snapshot emits nothing and preserves the last-good model view for retry on the next step. If no prior catalog exists and the current view is empty, no tombstone is necessary.

The catalog is omitted when no model-invocable skills are initially available, and also when that agent's tool view restricts away the shipped skill tool or resolves a same-name scoped shadow instead. Visibility changes participate in the digest, keeping prompt guidance, model-visible schema, and executable dispatch aligned.

catalogDescriptionMaxLength controls normalized, XML-escaped catalog descriptions. Its default is 500 and values must be integers of at least 3, which reserves room for a truncation ellipsis. The skill catalog hot-refresh Agent Note owns the durable initial catalog and replacement lifecycle.

Tool: skill

Arg Type Notes
name string (required) Exact kebab-case skill name from the available skills listing.

Execution uses the calling agent's session.header.cwd so workspace-sensitive providers resolve the winning skill. A successful call returns canonical { name, provider, resourceBase?, content }, excluding catalog ranking and provider-internal machinery; its Native renderer produces one text result containing <skill_content name="...">, <skill_resources>, and <skill_instructions>.

Resource guidance resolves only paths or URLs explicitly referenced by the instructions against resourceBase; scripts, references, and assets load on demand, and the result does not enumerate a skill directory. Local providers may supply a directory, while remote or embedded providers may supply a URL or opaque loading guidance.

An unresolved name reports that the skill is unknown or no longer available. Invalid names and skills whose invocation.modelInvocable is false produce distinct error results. invocation.userInvocable does not restrict this model-facing surface.

Tool execution does not call agent.inject(). Its freshly loaded result is already recorded as the tool result and becomes available to the next model step without duplicating the body as synthetic context. Only the catalog projection injects replacement summaries.

Model Experience

Session catalog

What the model sees

If model-invocable skills exist and this exact skill tool is visible, the agent receives the catalog template below as a durable user-role message before the first request, with one data-dependent entry per sorted skill. Later membership, description, or visibility changes append a complete replacement using the same <available_skills> envelope; deleting every skill appends an empty envelope with an explicit instruction not to use older names.

Skill catalog template
<system-reminder>
A skill is a reusable set of task-specific instructions. The following skills are available in this session:

<available_skills>
- `<name>`: <normalized-and-capped-description>
</available_skills>

If the user names a skill, or the task clearly matches a skill's description, call the `skill` tool with the exact skill name before taking task actions. Load all applicable skills, then follow their full instructions. This catalog contains summaries only; do not infer or follow a skill's instructions until it has been loaded.
</system-reminder>

Token effect

Repeated input cost scales with skill count and catalogDescriptionMaxLength; no initial catalog tokens are sent when the list is empty or the tool is hidden or shadowed. Each actual catalog change adds one retained complete replacement message.

KV Cache effect

The initial durable catalog is appended after the existing reusable prefix. Dynamic changes are append-only history after that catalog, so earlier reusable tokens stay intact while each newly appended catalog and later turns form a new suffix. A new or resumed instance with a changed digest may affect cache reuse from the newly appended catalog position.

Tool schema

What the model sees

The model sees the generated skill schema.

Token effect

Fixed schema cost per request where the tool is visible.

KV Cache effect

Prefix-stable while the tool definition and visibility are unchanged. Shadowing, restrictions, or plugin lifecycle changes may invalidate reuse from this schema.

Tool result

What the model sees

A successful call uses the result template and the provider-managed, directory, URL, or opaque resource guidance below.

Skill result template
<skill_content name="<escaped-name>">
<skill_resources>
<resource-guidance>
</skill_resources>

<skill_instructions>
<provider-owned-instruction-body>
</skill_instructions>
</skill_content>
Provider-managed resource guidance
Resources for this skill are managed by provider "<provider>".
Load referenced resources only as needed.
Directory resource guidance
Base directory for this skill: <path>
Resolve relative paths mentioned by this skill against the base directory before using them. Load referenced resources only as needed.
URL resource guidance
Base URL for this skill: <url>
Resolve relative URLs mentioned by this skill against the base URL before using them. Load referenced resources only as needed.
Opaque resource guidance
Resources for this skill: <description>
Load referenced resources only as needed.

Token effect

Loaded instructions are data-dependent tool-result tokens, resent on later steps until compaction; no duplicate agent.inject() copy is made.

KV Cache effect

Append-only; newly visible content follows the reusable request prefix and does not invalidate existing KV-cache entries.

Tool errors

What the model sees

Invalid or stale selections return exactly Error: invalid skill name "<name>", Error: skill "<name>" is unknown or no longer available, or Error: skill "<name>" is not available for model invocation. Provider-thrown lookup text is data-dependent and receives the same Error: <message> wrapper.

Token effect

Only a failing call adds these retained tokens.

KV Cache effect

Append-only; newly visible content follows the reusable request prefix and does not invalidate existing KV-cache entries.

Known Limitations and Deferred Work

  • The catalog omits whenToUse, source, and provider metadata — routing is based only on name and a capped description; whenToUse remains provider metadata and is not rendered by the loaded wrapper either.
  • Loaded instruction bodies have no size cap — a provider can return a skill large enough to consume substantial next-step context; only catalog descriptions are truncated.
  • Resources are guidance, not attachments — the tool reports a base directory/URL/opaque hint but neither enumerates nor fetches referenced files for the model.
  • Loading is one-shot text — there is no partial, streaming, or cached-content handle when a remote provider is slow or a skill body is large.
  • Catalog replacement is whole-list — one changed name or description appends every currently visible summary; this keeps stale-name retirement explicit but costs tokens proportional to the catalog.
  • Bodies are not versioned — body-only edits do not change the catalog digest or notify the model; a later tool call reads the current provider content while earlier tool results remain historical facts.