Files
deepseek-harness/website/zh-CN/api/harness/commands.md
2026-07-19 22:11:59 +08:00

3.7 KiB

ctx.commands

CommandService — provided by @deepseek-ai/dsh-commands.

Human-command registry. Plain-context definitions are global; definitions registered through a command-injected child of an agent context shadow globals for that agent.

Source

ctx.commands.register(definition)

/**
 * Register a global or calling-agent-scoped command.
 * @param definition - discovery metadata, surface mask, and direct UI handler.
 * @returns the exact effect disposer that unregisters this definition.
 */
register(definition: CommandDefinition): () => void

Register a global or calling-agent-scoped command.

  • definition — discovery metadata, surface mask, and direct UI handler.

Returns the exact effect disposer that unregisters this definition.

Source

ctx.commands.list(agent, surface)

/**
 * List the effective immutable command descriptors for one agent and surface.
 * @param agent - exact receiving agent and scoped-layer key.
 * @param surface - UI adapter requesting discovery metadata.
 * @returns name-sorted descriptors after scoped shadowing and surface filtering.
 */
list(agent: Agent, surface: CommandSurface): readonly CommandDescriptor[]

List the effective immutable command descriptors for one agent and surface.

  • agent — exact receiving agent and scoped-layer key.
  • surface — UI adapter requesting discovery metadata.

Returns name-sorted descriptors after scoped shadowing and surface filtering.

Source

ctx.commands.find(agent, surface, name)

/**
 * Resolve one effective command definition.
 * @param agent - exact receiving agent and scoped-layer key.
 * @param surface - UI adapter performing the lookup.
 * @param name - command name without a slash.
 * @returns the scoped shadow or global definition when visible on the surface.
 */
find(agent: Agent, surface: CommandSurface, name: string): CommandDefinition | undefined

Resolve one effective command definition.

  • agent — exact receiving agent and scoped-layer key.
  • surface — UI adapter performing the lookup.
  • name — command name without a slash.

Returns the scoped shadow or global definition when visible on the surface.

Source

ctx.commands.execute(agent, surface, line, signal)

/**
 * Parse and execute a known command without sending it to the model.
 * @param agent - exact receiving agent.
 * @param surface - dispatching UI adapter.
 * @param line - complete slash-command line.
 * @param signal - cancellation signal owned by the UI request.
 * @returns a detached result, or `undefined` when syntax/name/surface does not resolve.
 */
async execute( agent: Agent, surface: CommandSurface, line: string, signal: AbortSignal, ): Promise<CommandResult | undefined>

Parse and execute a known command without sending it to the model.

  • agent — exact receiving agent.
  • surface — dispatching UI adapter.
  • line — complete slash-command line.
  • signal — cancellation signal owned by the UI request.

Returns a detached result, or undefined when syntax/name/surface does not resolve.

Source