/** * Optional `/refine` slash-command adapter: parses raw input into a coordinator * request, executes it detached, and renders the result as plain text. * Registered only when the host provides a `commands` capability * (`@deepseek-ai/dsh-commands`). The host contract is a single-definition * `register()` and a result carrying a `kind` discriminator; this adapter * speaks that contract so the command works against the real dsh host without * a shim. * * Detached, not awaited: the host `commands` executor awaits the handler for * the whole RPC round-trip, and the UI keeps the submitted draft visible until * that settle. The handler therefore acknowledges immediately with a * `status: started` result and runs the coordinator in the background; when * the execution settles, the default outcome reporter updates the original * command card in place (a second `command/done` lifecycle event carrying the * rendered result, keyed by the host's `commandId`) and mirrors the same text * into the harness log. The two cards are stage-labeled — `stage: ack-done` * while the refine runs, `stage: refine-done` for the settled result — so a * user can tell the acknowledgment apart from the outcome. The invocation's * `signal` is deliberately not forwarded: it belongs to the UI request and * may abort once the handler settles, which would kill the very refinement * the user just started. * @module dsh-continual-harness */ import type { Agent } from '@deepseek-ai/dsh-agent'; import type { RefineCoordinator, RefineExecutionResult } from './coordinator-types.ts'; import type { HarnessScope } from './types.ts'; /** * One command invocation from a host `commands` capability. The host passes * the raw input without the command name and `/` prefix; the adapter also * accepts the full `/refine ...` form. `commandId` is the host's lifecycle * pairing id for this execution (`command/run` ↔ `command/done`); the default * outcome reporter reuses it to update the original command card once the * detached execution settles. */ export interface CommandInvocation { rawInput: string; agent?: Agent; signal?: AbortSignal; /** Host-minted lifecycle pairing id, when the host provides one. */ commandId?: string; } /** A command handler result in the host's discriminated shape. */ export type CommandResult = { kind: 'success'; text: string; } | { kind: 'error'; text: string; }; /** A command definition accepted by the host `commands.register()`. */ export interface CommandDefinition { name: string; description: string; input?: { hint: string; images?: boolean; }; handler: (invocation: CommandInvocation) => Promise; } /** * Async outcome reporter for a detached `/refine` execution. Called exactly * once per admitted invocation, after the coordinator settles (or throws), * with the requested scope so failures of `--global` runs still render the * truth. Sync or async; `runDetached` awaits it inside its own containment, * so a throwing reporter never surfaces as an unhandled rejection. */ export type RefineOutcomeReporter = (invocation: CommandInvocation, execution: RefineExecutionResult, scope: HarnessScope) => void | Promise; /** Options for the `/refine` command adapter. */ export interface CommandAdapterOptions { /** Scope used by a normal plan that omits `--global`/`--local`. */ defaultGlobal: boolean; /** Optional outcome reporter; defaults to {@link reportRefineOutcome}. */ report?: RefineOutcomeReporter; } /** * Optional host capability that registers slash commands. The coordinator * plugin never requires this service; when the host provides it, the * `/refine` command registers through the returned disposer. */ export interface CommandsCapability { register(definition: CommandDefinition): () => void; } /** Parser output for one validated `/refine` invocation. */ export type ParsedRefineCommand = { mode: 'plan'; scope: 'local' | 'global'; instructions?: string; } | { mode: 'rollback'; scope: 'local' | 'global'; rollbackId: string; }; /** * Parse one `/refine` raw input into a domain request shape. Pure: never * touches the coordinator, the store, or any live agent. * @param rawInput - full command input, with or without the `/refine` prefix. * @param defaultGlobal - scope used by a normal plan that omits `--global`/`--local`. */ export declare function parseRefineCommand(rawInput: string, defaultGlobal: boolean): ParsedRefineCommand | { error: string; }; /** * Build the `/refine` command handler: parse the raw input, translate it into * one coordinator request (`source: 'command'`), start the execution detached * on a later tick, and acknowledge immediately with a `status: started` * result — the ack path is parse-only, so the submit RPC settles at once. A * missing live agent or a parse error returns usage text without any * coordinator call. The invocation signal is never forwarded to the detached * execution (see the module header). One execution per session may be in * flight; a second submit while one runs is acknowledged `already-running` * and skipped. */ export declare function createRefineCommandAdapter(coordinator: RefineCoordinator, options: CommandAdapterOptions): (invocation: CommandInvocation) => Promise; /** * Default outcome reporter for a detached `/refine` execution. With the * host's `commandId`, appends a second `command/done` lifecycle event for the * same pairing id carrying the rendered outcome, so the client updates the * original command card in place (started → result); without it, falls back * to one plugin-source `user/message` so the outcome stays visible. Mirrors * the same text into the harness logger — the log copy also survives a * session that is disposed mid-execution. Fully contained: an append or log * failure never breaks the agent loop. */ export declare function reportRefineOutcome(invocation: CommandInvocation, execution: RefineExecutionResult, scope: HarnessScope): void; /** * Register the `/refine` command through an optional `CommandsCapability`. * The returned disposable removes the registration through the capability's * own handle. */ export declare function registerRefineCommand(commands: CommandsCapability, coordinator: RefineCoordinator, options: CommandAdapterOptions): () => void; //# sourceMappingURL=command.d.ts.map