dsh-plugin-dev-kb 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +56 -0
- package/cordis.patch.yml +12 -0
- package/kb/INDEX.md +210 -0
- package/kb/README.md +69 -0
- package/kb/extra/AGENTS.md +75 -0
- package/kb/extra/api-gateway.md +164 -0
- package/kb/extra/api-gateway.zh.md +164 -0
- package/kb/extra/cookbook/adding-a-vendored-package.md +59 -0
- package/kb/extra/cookbook/adding-a-vendored-package.zh.md +59 -0
- package/kb/extra/cookbook/maintaining-dsh-code-review.md +64 -0
- package/kb/extra/cookbook/maintaining-dsh-code-review.zh.md +64 -0
- package/kb/extra/cookbook/responding-to-pr-review-on-a-stack.md +32 -0
- package/kb/extra/cookbook/responding-to-pr-review-on-a-stack.zh.md +32 -0
- package/kb/extra/defensive-patterns.md +33 -0
- package/kb/extra/defensive-patterns.zh.md +33 -0
- package/kb/extra/development.md +171 -0
- package/kb/extra/development.zh.md +171 -0
- package/kb/extra/event-producer-consumer.md +76 -0
- package/kb/extra/event-producer-consumer.zh.md +78 -0
- package/kb/extra/glossary.md +45 -0
- package/kb/extra/glossary.zh.md +45 -0
- package/kb/extra/graph-atlas.md +24 -0
- package/kb/extra/graph-atlas.zh.md +26 -0
- package/kb/extra/i18n/README.md +60 -0
- package/kb/extra/i18n/README.zh.md +60 -0
- package/kb/extra/i18n/style-samples.md +87 -0
- package/kb/extra/i18n/terminology.md +214 -0
- package/kb/extra/i18n/translation-prompt.md +263 -0
- package/kb/extra/i18n/translation-rules.md +69 -0
- package/kb/extra/i18n/translation-rules.zh.md +69 -0
- package/kb/extra/module-graph.md +1641 -0
- package/kb/extra/module-graph.zh.md +1643 -0
- package/kb/extra/postmortem/0001-acp-default-export-drops-inject.md +113 -0
- package/kb/extra/postmortem/0001-acp-default-export-drops-inject.zh.md +113 -0
- package/kb/extra/postmortem/0002-js-expression-disabled-filesystem-tools.md +47 -0
- package/kb/extra/postmortem/0002-js-expression-disabled-filesystem-tools.zh.md +47 -0
- package/kb/extra/postmortem/0003-web-agent-gui-feedback-loop.md +53 -0
- package/kb/extra/postmortem/0003-web-agent-gui-feedback-loop.zh.md +53 -0
- package/kb/extra/postmortem/0004-landlock-partial-notice-misclassified-child-failures.md +55 -0
- package/kb/extra/postmortem/0004-landlock-partial-notice-misclassified-child-failures.zh.md +55 -0
- package/kb/extra/postmortem/README.md +18 -0
- package/kb/extra/postmortem/README.zh.md +18 -0
- package/kb/extra/rescope.md +53 -0
- package/kb/extra/rescope.zh.md +53 -0
- package/kb/extra/subsystems/attachment.md +125 -0
- package/kb/extra/subsystems/attachment.zh.md +125 -0
- package/kb/extra/subsystems/extensions.md +364 -0
- package/kb/extra/subsystems/extensions.zh.md +364 -0
- package/kb/extra/subsystems/feedback.md +266 -0
- package/kb/extra/subsystems/feedback.zh.md +266 -0
- package/kb/extra/testing.md +49 -0
- package/kb/extra/testing.zh.md +49 -0
- package/kb/extra/web-styling.md +25 -0
- package/kb/extra/web-styling.zh.md +25 -0
- package/kb/meta/search-index.json +1328 -0
- package/kb/meta/site-pages.txt +168 -0
- package/kb/meta/source.json +13 -0
- package/kb/meta/topics.md +75 -0
- package/kb/site/develop/basic/config.md +108 -0
- package/kb/site/develop/basic/index.md +146 -0
- package/kb/site/develop/basic/publish.md +185 -0
- package/kb/site/develop/basic/tool.md +54 -0
- package/kb/site/develop/cordis-tutorial/01-first-plugin.md +95 -0
- package/kb/site/develop/cordis-tutorial/02-lifecycle-and-effects.md +98 -0
- package/kb/site/develop/cordis-tutorial/03-services.md +98 -0
- package/kb/site/develop/cordis-tutorial/04-events.md +144 -0
- package/kb/site/develop/cordis-tutorial/05-config.md +84 -0
- package/kb/site/develop/cordis-tutorial/06-composition-and-hmr.md +113 -0
- package/kb/site/develop/cordis-tutorial/07-into-the-harness.md +107 -0
- package/kb/site/develop/cordis-tutorial/index.md +62 -0
- package/kb/site/develop/framework/events.md +145 -0
- package/kb/site/develop/framework/index.md +139 -0
- package/kb/site/develop/framework/service.md +152 -0
- package/kb/site/develop/practice/index.md +157 -0
- package/kb/site/develop/practice/llm-adapter.md +190 -0
- package/kb/site/en/develop/basic/config.md +108 -0
- package/kb/site/en/develop/basic/index.md +146 -0
- package/kb/site/en/develop/basic/publish.md +185 -0
- package/kb/site/en/develop/basic/tool.md +54 -0
- package/kb/site/en/develop/cordis-tutorial/01-first-plugin.md +95 -0
- package/kb/site/en/develop/cordis-tutorial/02-lifecycle-and-effects.md +98 -0
- package/kb/site/en/develop/cordis-tutorial/03-services.md +98 -0
- package/kb/site/en/develop/cordis-tutorial/04-events.md +144 -0
- package/kb/site/en/develop/cordis-tutorial/05-config.md +84 -0
- package/kb/site/en/develop/cordis-tutorial/06-composition-and-hmr.md +113 -0
- package/kb/site/en/develop/cordis-tutorial/07-into-the-harness.md +107 -0
- package/kb/site/en/develop/cordis-tutorial/index.md +60 -0
- package/kb/site/en/develop/framework/events.md +145 -0
- package/kb/site/en/develop/framework/index.md +139 -0
- package/kb/site/en/develop/framework/service.md +150 -0
- package/kb/site/en/develop/practice/index.md +157 -0
- package/kb/site/en/develop/practice/llm-adapter.md +190 -0
- package/kb/site/en/guide/providers-custom-form.png +0 -0
- package/kb/site/en/guide/providers-models-page.png +0 -0
- package/kb/site/en/guide/providers.md +100 -0
- package/kb/site/en/guide/python-sdk.md +106 -0
- package/kb/site/en/guide/quickstart.md +32 -0
- package/kb/site/en/index.md +8 -0
- package/kb/site/en/reference/agent-lifecycle.md +86 -0
- package/kb/site/en/reference/capability-seams.md +475 -0
- package/kb/site/en/reference/config-catalog.md +3155 -0
- package/kb/site/en/reference/cookbook/adding-a-conversation-node.md +235 -0
- package/kb/site/en/reference/cookbook/adding-a-package.md +120 -0
- package/kb/site/en/reference/cookbook/adding-a-settings-card.md +102 -0
- package/kb/site/en/reference/cookbook/adding-a-tool.md +96 -0
- package/kb/site/en/reference/cookbook/adding-an-llm-adapter.md +45 -0
- package/kb/site/en/reference/cookbook/extension-cookbook.md +131 -0
- package/kb/site/en/reference/cordis-api/context.md +368 -0
- package/kb/site/en/reference/cordis-api/events.md +211 -0
- package/kb/site/en/reference/cordis-api/fiber.md +379 -0
- package/kb/site/en/reference/cordis-api/inherited.md +43 -0
- package/kb/site/en/reference/cordis-api/registry.md +156 -0
- package/kb/site/en/reference/cordis-api/service.md +106 -0
- package/kb/site/en/reference/cordis-primer.md +46 -0
- package/kb/site/en/reference/index.md +131 -0
- package/kb/site/en/reference/persistence-catalog.md +949 -0
- package/kb/site/en/reference/subsystems/approval.md +173 -0
- package/kb/site/en/reference/subsystems/client-modules.md +121 -0
- package/kb/site/en/reference/subsystems/code-runtime.md +194 -0
- package/kb/site/en/reference/subsystems/commands.md +190 -0
- package/kb/site/en/reference/subsystems/compaction.md +241 -0
- package/kb/site/en/reference/subsystems/core.md +1073 -0
- package/kb/site/en/reference/subsystems/credentials.md +136 -0
- package/kb/site/en/reference/subsystems/filesystem.md +498 -0
- package/kb/site/en/reference/subsystems/goal.md +280 -0
- package/kb/site/en/reference/subsystems/index.md +58 -0
- package/kb/site/en/reference/subsystems/invariants.md +91 -0
- package/kb/site/en/reference/subsystems/jobs.md +293 -0
- package/kb/site/en/reference/subsystems/llm-streaming.md +920 -0
- package/kb/site/en/reference/subsystems/lsp.md +205 -0
- package/kb/site/en/reference/subsystems/permission-presets.md +134 -0
- package/kb/site/en/reference/subsystems/persistence.md +388 -0
- package/kb/site/en/reference/subsystems/plan.md +90 -0
- package/kb/site/en/reference/subsystems/sandbox.md +221 -0
- package/kb/site/en/reference/subsystems/schedule.md +189 -0
- package/kb/site/en/reference/subsystems/scope.md +62 -0
- package/kb/site/en/reference/subsystems/session-projection.md +265 -0
- package/kb/site/en/reference/subsystems/session-query.md +498 -0
- package/kb/site/en/reference/subsystems/session-reference.md +111 -0
- package/kb/site/en/reference/subsystems/session-telemetry.md +197 -0
- package/kb/site/en/reference/subsystems/session-title.md +207 -0
- package/kb/site/en/reference/subsystems/session.md +852 -0
- package/kb/site/en/reference/subsystems/settings.md +313 -0
- package/kb/site/en/reference/subsystems/shell.md +306 -0
- package/kb/site/en/reference/subsystems/skills.md +334 -0
- package/kb/site/en/reference/subsystems/spill.md +120 -0
- package/kb/site/en/reference/subsystems/storage.md +232 -0
- package/kb/site/en/reference/subsystems/subagent.md +737 -0
- package/kb/site/en/reference/subsystems/subprocess.md +327 -0
- package/kb/site/en/reference/subsystems/system-prompt.md +210 -0
- package/kb/site/en/reference/subsystems/terminal.md +187 -0
- package/kb/site/en/reference/subsystems/token-meter.md +93 -0
- package/kb/site/en/reference/subsystems/tools.md +723 -0
- package/kb/site/en/reference/subsystems/typert.md +339 -0
- package/kb/site/en/reference/subsystems/user-questions.md +181 -0
- package/kb/site/en/reference/subsystems/web-server.md +111 -0
- package/kb/site/en/reference/subsystems/web.md +202 -0
- package/kb/site/en/reference/subsystems/workflow.md +281 -0
- package/kb/site/en/reference/subsystems/workspace.md +231 -0
- package/kb/site/en/reference/tool-catalog.md +1877 -0
- package/kb/site/en/reference/tool-execution-pipeline.md +66 -0
- package/kb/site/guide/providers-custom-form.zh.png +0 -0
- package/kb/site/guide/providers-models-page.zh.png +0 -0
- package/kb/site/guide/providers.md +100 -0
- package/kb/site/guide/python-sdk.md +106 -0
- package/kb/site/guide/quickstart.md +32 -0
- package/kb/site/index.md +8 -0
- package/kb/site/reference/agent-lifecycle.md +86 -0
- package/kb/site/reference/capability-seams.md +475 -0
- package/kb/site/reference/config-catalog.md +3154 -0
- package/kb/site/reference/cookbook/adding-a-conversation-node.md +235 -0
- package/kb/site/reference/cookbook/adding-a-package.md +120 -0
- package/kb/site/reference/cookbook/adding-a-settings-card.md +102 -0
- package/kb/site/reference/cookbook/adding-a-tool.md +98 -0
- package/kb/site/reference/cookbook/adding-an-llm-adapter.md +45 -0
- package/kb/site/reference/cookbook/extension-cookbook.md +133 -0
- package/kb/site/reference/cordis-api/context.md +368 -0
- package/kb/site/reference/cordis-api/events.md +211 -0
- package/kb/site/reference/cordis-api/fiber.md +379 -0
- package/kb/site/reference/cordis-api/inherited.md +43 -0
- package/kb/site/reference/cordis-api/registry.md +156 -0
- package/kb/site/reference/cordis-api/service.md +106 -0
- package/kb/site/reference/cordis-primer.md +52 -0
- package/kb/site/reference/index.md +135 -0
- package/kb/site/reference/persistence-catalog.md +949 -0
- package/kb/site/reference/subsystems/approval.md +173 -0
- package/kb/site/reference/subsystems/client-modules.md +121 -0
- package/kb/site/reference/subsystems/code-runtime.md +194 -0
- package/kb/site/reference/subsystems/commands.md +190 -0
- package/kb/site/reference/subsystems/compaction.md +241 -0
- package/kb/site/reference/subsystems/core.md +1081 -0
- package/kb/site/reference/subsystems/credentials.md +136 -0
- package/kb/site/reference/subsystems/filesystem.md +498 -0
- package/kb/site/reference/subsystems/goal.md +280 -0
- package/kb/site/reference/subsystems/index.md +58 -0
- package/kb/site/reference/subsystems/invariants.md +91 -0
- package/kb/site/reference/subsystems/jobs.md +293 -0
- package/kb/site/reference/subsystems/llm-streaming.md +926 -0
- package/kb/site/reference/subsystems/lsp.md +205 -0
- package/kb/site/reference/subsystems/permission-presets.md +134 -0
- package/kb/site/reference/subsystems/persistence.md +388 -0
- package/kb/site/reference/subsystems/plan.md +90 -0
- package/kb/site/reference/subsystems/sandbox.md +221 -0
- package/kb/site/reference/subsystems/schedule.md +189 -0
- package/kb/site/reference/subsystems/scope.md +62 -0
- package/kb/site/reference/subsystems/session-projection.md +265 -0
- package/kb/site/reference/subsystems/session-query.md +498 -0
- package/kb/site/reference/subsystems/session-reference.md +111 -0
- package/kb/site/reference/subsystems/session-telemetry.md +197 -0
- package/kb/site/reference/subsystems/session-title.md +207 -0
- package/kb/site/reference/subsystems/session.md +854 -0
- package/kb/site/reference/subsystems/settings.md +313 -0
- package/kb/site/reference/subsystems/shell.md +306 -0
- package/kb/site/reference/subsystems/skills.md +334 -0
- package/kb/site/reference/subsystems/spill.md +120 -0
- package/kb/site/reference/subsystems/storage.md +232 -0
- package/kb/site/reference/subsystems/subagent.md +739 -0
- package/kb/site/reference/subsystems/subprocess.md +327 -0
- package/kb/site/reference/subsystems/system-prompt.md +210 -0
- package/kb/site/reference/subsystems/terminal.md +187 -0
- package/kb/site/reference/subsystems/token-meter.md +93 -0
- package/kb/site/reference/subsystems/tools.md +723 -0
- package/kb/site/reference/subsystems/typert.md +339 -0
- package/kb/site/reference/subsystems/user-questions.md +181 -0
- package/kb/site/reference/subsystems/web-server.md +111 -0
- package/kb/site/reference/subsystems/web.md +202 -0
- package/kb/site/reference/subsystems/workflow.md +281 -0
- package/kb/site/reference/subsystems/workspace.md +231 -0
- package/kb/site/reference/tool-catalog.md +1880 -0
- package/kb/site/reference/tool-execution-pipeline.md +66 -0
- package/package.json +40 -0
- package/scripts/rebuild-index.mjs +88 -0
- package/skills/dsh-plugin-dev-kb.md +66 -0
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
---
|
|
2
|
+
editSource: "docs/subsystems/commands.md"
|
|
3
|
+
outline: [2,3]
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Human Commands
|
|
7
|
+
|
|
8
|
+
The human-command registry service from [`dsh-commands`](https://github.com/deepseek-ai/deepseek-harness/tree/master/packages/interaction/commands). Interactive adapters use it to discover and directly execute plugin-owned commands for an exact agent without creating a model message. The [command Agent Note](https://github.com/deepseek-ai/deepseek-harness/blob/master/.agents/notes/implemented/feature/2026-07-19-plugin-command-registration.md) owns dispatch and lifecycle rationale; the [package README](https://github.com/deepseek-ai/deepseek-harness/blob/master/packages/interaction/commands/README.md) owns composition and limitations.
|
|
9
|
+
|
|
10
|
+
Source: [`packages/interaction/commands/src/index.ts`](https://github.com/deepseek-ai/deepseek-harness/blob/master/packages/interaction/commands/src/index.ts)
|
|
11
|
+
|
|
12
|
+
## Input metadata
|
|
13
|
+
|
|
14
|
+
The service exposes one optional unstructured-input hint. Command availability follows plugin composition: every adapter consuming the registry sees every effective definition.
|
|
15
|
+
|
|
16
|
+
```ts type-equiv
|
|
17
|
+
/** Immutable metadata for a command's optional unstructured input. */
|
|
18
|
+
interface CommandInputDescriptor {
|
|
19
|
+
/** Placeholder shown before the user supplies free-form input. */
|
|
20
|
+
readonly hint: string
|
|
21
|
+
}
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Definition
|
|
25
|
+
|
|
26
|
+
`CommandDefinition` is the plugin-authored registration. The registry validates and freezes a detached effective definition.
|
|
27
|
+
|
|
28
|
+
```ts type-equiv
|
|
29
|
+
/** Plugin-owned command registration. */
|
|
30
|
+
interface CommandDefinition {
|
|
31
|
+
/** Lowercase command name without the leading slash. */
|
|
32
|
+
readonly name: string
|
|
33
|
+
/** Human-readable summary used in discovery UI. */
|
|
34
|
+
readonly description: string
|
|
35
|
+
/** Optional free-form input hint advertised to capable clients. */
|
|
36
|
+
readonly input?: CommandInputDescriptor
|
|
37
|
+
/**
|
|
38
|
+
* Whether `command/run` records `rawInput`. Defaults to true. A command
|
|
39
|
+
* whose domain event owns the payload sets this false to avoid duplicating
|
|
40
|
+
* that payload in the session log.
|
|
41
|
+
*/
|
|
42
|
+
readonly recordInput?: boolean
|
|
43
|
+
/** Execute against the receiving agent without sending the command to the model. */
|
|
44
|
+
readonly handler: (invocation: CommandInvocation) => CommandResult | Promise<CommandResult>
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Invocation and result
|
|
49
|
+
|
|
50
|
+
The adapter owns cancellation and passes the exact target agent. `rawInput` begins immediately after the parsed name and retains the adapter-delivered separator and suffix. Results are direct UI outcomes, not tool results or session events.
|
|
51
|
+
|
|
52
|
+
```ts type-equiv
|
|
53
|
+
/** Invocation passed to one registered command handler. */
|
|
54
|
+
interface CommandInvocation {
|
|
55
|
+
/** Pairing id already written to this invocation's `command/run` event. */
|
|
56
|
+
readonly commandId: CommandId
|
|
57
|
+
/** Exact agent whose UI received the command. */
|
|
58
|
+
readonly agent: Agent
|
|
59
|
+
/** Exact text following the registered command name, including separator whitespace. */
|
|
60
|
+
readonly rawInput: string
|
|
61
|
+
/** Cancellation signal owned by the dispatching UI request. */
|
|
62
|
+
readonly signal: AbortSignal
|
|
63
|
+
}
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
```ts type-equiv
|
|
67
|
+
/** Expected command outcome rendered directly by the dispatching UI. */
|
|
68
|
+
type CommandResult =
|
|
69
|
+
| {
|
|
70
|
+
readonly kind: 'success'
|
|
71
|
+
readonly text?: string
|
|
72
|
+
/** Earlier authoritative domain event that owns a richer presentation. */
|
|
73
|
+
readonly sourceEventSeq?: number
|
|
74
|
+
}
|
|
75
|
+
| { readonly kind: 'error'; readonly text: string }
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
`sourceEventSeq` is optional and success-only. When present, it names an earlier non-command event in the receiving session log; `command/done` persists the same reference so a client can combine the command lifecycle with that domain projection without parsing `text` or relying on adjacent rows.
|
|
79
|
+
|
|
80
|
+
## Discovery and parsing views
|
|
81
|
+
|
|
82
|
+
Adapters receive handler-free immutable descriptors after scope resolution. `parseCommand()` returns `ParsedCommand` before registry resolution; syntax-valid input can still name an unavailable command.
|
|
83
|
+
|
|
84
|
+
```ts type-equiv
|
|
85
|
+
/** Handler-free immutable command view returned to UI adapters. */
|
|
86
|
+
interface CommandDescriptor {
|
|
87
|
+
/** Lowercase command name without the leading slash. */
|
|
88
|
+
readonly name: string
|
|
89
|
+
/** Human-readable summary used in discovery UI. */
|
|
90
|
+
readonly description: string
|
|
91
|
+
/** Optional free-form input hint advertised to capable clients. */
|
|
92
|
+
readonly input?: CommandInputDescriptor
|
|
93
|
+
}
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
```ts type-equiv
|
|
97
|
+
/** Syntactically valid slash command before registry resolution. */
|
|
98
|
+
interface ParsedCommand {
|
|
99
|
+
/** Lowercase command name without the leading slash. */
|
|
100
|
+
readonly name: string
|
|
101
|
+
/** Exact text following the command name. */
|
|
102
|
+
readonly rawInput: string
|
|
103
|
+
}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
<!-- BEGIN GENERATED cordis-surface (gen-cordis-catalog.ts) — do not edit between markers -->
|
|
107
|
+
|
|
108
|
+
<a id="cordis-surface"></a>
|
|
109
|
+
|
|
110
|
+
## Cordis API
|
|
111
|
+
|
|
112
|
+
Generated from source by `scripts/gen-cordis-catalog.ts` (verified fresh by `pnpm run verify-cordis-catalog` in doc-sync; regenerate with `pnpm run gen-cordis-catalog`) — this section is byte-identical in both language sides of the page. Signature blocks use a `ts cordis-catalog` fence and keep the original source JSDoc; dispatch modes are defined in the [primer](../cordis-primer.md#dispatch-modes), and the framework-inherited `ctx` API lives in [cordis-api/inherited.md](../cordis-api/inherited.md).
|
|
113
|
+
|
|
114
|
+
<a id="ctxcommands--commandruntime"></a>
|
|
115
|
+
|
|
116
|
+
### `ctx.commands` — `CommandRuntime`
|
|
117
|
+
|
|
118
|
+
Human-command registry. Plain-context definitions are global; definitions registered through a command-injected child of an agent context shadow globals for that agent.
|
|
119
|
+
|
|
120
|
+
```ts cordis-catalog
|
|
121
|
+
/**
|
|
122
|
+
* Register a global or calling-agent-scoped command.
|
|
123
|
+
* @param definition - discovery metadata and direct UI handler.
|
|
124
|
+
* @returns the exact effect disposer that unregisters this definition.
|
|
125
|
+
*/
|
|
126
|
+
register(definition: CommandDefinition): () => void
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* List the effective immutable command descriptors for one agent.
|
|
130
|
+
* @param agent - exact receiving agent and scoped-layer key.
|
|
131
|
+
* @returns name-sorted descriptors after scoped shadowing.
|
|
132
|
+
*/
|
|
133
|
+
@Remote list(agent: Agent): readonly CommandDescriptor[]
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Resolve one effective command definition.
|
|
137
|
+
* @param agent - exact receiving agent and scoped-layer key.
|
|
138
|
+
* @param name - command name without a slash.
|
|
139
|
+
* @returns the scoped shadow or global definition.
|
|
140
|
+
*/
|
|
141
|
+
find(agent: Agent, name: string): CommandDefinition | undefined
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Parse and execute a known command without sending it to the model.
|
|
145
|
+
*
|
|
146
|
+
* A resolved command's lifecycle is logged: `command/run` is appended
|
|
147
|
+
* before the handler is invoked and `command/done` after settlement (a
|
|
148
|
+
* thrown or aborted handler settles as `kind: 'error'`). Both are direct
|
|
149
|
+
* log-only appends — no turn wraps them, and persistence drains them at
|
|
150
|
+
* ordinary checkpoints. Admission misses (syntax or unknown name) log
|
|
151
|
+
* nothing — they never entered a handler. A `command/run` append failure
|
|
152
|
+
* fails the execution loud; a `command/done` append failure on the
|
|
153
|
+
* handler-failure path is contained so the handler's own error stays the
|
|
154
|
+
* reported failure.
|
|
155
|
+
*
|
|
156
|
+
* @param agent - exact receiving agent.
|
|
157
|
+
* @param line - complete slash-command line.
|
|
158
|
+
* @param signal - cancellation signal owned by the UI request.
|
|
159
|
+
* @returns the settled execution (result + lifecycle pairing id), or
|
|
160
|
+
* `undefined` when syntax or name does not resolve.
|
|
161
|
+
*/
|
|
162
|
+
@Remote async execute( agent: Agent, line: string, signal: AbortSignal, ): Promise<CommandExecution | undefined>
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
Types: [Agent](./core.md)
|
|
166
|
+
|
|
167
|
+
Source: [`packages/interaction/commands/src/index.ts:225`](https://github.com/deepseek-ai/deepseek-harness/blob/master/packages/interaction/commands/src/index.ts)
|
|
168
|
+
|
|
169
|
+
<a id="commands-events"></a>
|
|
170
|
+
|
|
171
|
+
### `commands/*` events
|
|
172
|
+
|
|
173
|
+
<a id="commandschange--emit"></a>
|
|
174
|
+
|
|
175
|
+
#### `commands/change` — emit
|
|
176
|
+
|
|
177
|
+
A command was registered or unregistered. This is an unfiltered registry notification because a global or scoped change may affect any UI view. Observer failures are contained and cannot veto the registry mutation.
|
|
178
|
+
|
|
179
|
+
```ts cordis-catalog
|
|
180
|
+
/**
|
|
181
|
+
* A command was registered or unregistered. This is an unfiltered registry
|
|
182
|
+
* notification because a global or scoped change may affect any UI view.
|
|
183
|
+
* Observer failures are contained and cannot veto the registry mutation.
|
|
184
|
+
* @mode emit
|
|
185
|
+
*/
|
|
186
|
+
'commands/change'(): void
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
Source: [`packages/interaction/commands/src/types.ts:72`](https://github.com/deepseek-ai/deepseek-harness/blob/master/packages/interaction/commands/src/types.ts)
|
|
190
|
+
<!-- END GENERATED cordis-surface -->
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
---
|
|
2
|
+
editSource: "docs/subsystems/compaction.md"
|
|
3
|
+
outline: [2,3]
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Compaction
|
|
7
|
+
|
|
8
|
+
The compaction seam — a [capability seam](https://github.com/deepseek-ai/deepseek-harness/blob/master/.agents/notes/implemented/architecture/2026-06-13-capability-seams.md) split like bash: Service Definition ([dsh-compaction](https://github.com/deepseek-ai/deepseek-harness/tree/master/packages/compaction/compaction), `ctx.compaction`), Service Provider (a backend such as [dsh-compaction-basic](https://github.com/deepseek-ai/deepseek-harness/tree/master/packages/compaction/compaction-basic)), and human Consumer ([dsh-command-compact](https://github.com/deepseek-ai/deepseek-harness/tree/master/packages/compaction/command-compact)). Compaction is **one optional capability**, not part of the agent-loop spine — so its vocabulary lives here, not in [core.md](./core.md). A tokenizer- or template-based backend is a sibling package implementing the same interface. Unlike bash, the interface necessarily depends on `dsh-session` and `dsh-llm`: its verbs act on an agent-owned `Session`, and its durable summary event uses the `ContentBlock` vocabulary (see the [compaction capability-seam Agent Note](https://github.com/deepseek-ai/deepseek-harness/blob/master/.agents/notes/implemented/feature/2026-06-18-compaction-capability-seam.md)).
|
|
9
|
+
|
|
10
|
+
Source: [`packages/compaction/compaction/src/types.ts`](https://github.com/deepseek-ai/deepseek-harness/blob/master/packages/compaction/compaction/src/types.ts)
|
|
11
|
+
|
|
12
|
+
## The `compaction/*` session events
|
|
13
|
+
|
|
14
|
+
Compaction extends [`SessionEventMap`](./session.md) with three event types via declaration merging. All three are **log-only** — they record the lock, summary, selected range, shadowed event seqs, token count, and model call without joining the surface. `SurfaceEventType` is deliberately NOT extended (only message-producing events reach the model), so the summary itself rides on a separate `user/message` with `surfaceOp: { op: 'replace', start, end }` — the only surface mutation performed by summary compaction. The [Agent Note](https://github.com/deepseek-ai/deepseek-harness/blob/master/.agents/notes/implemented/feature/2026-06-18-compaction-capability-seam.md) owns the rationale for reusing `user/message`.
|
|
15
|
+
|
|
16
|
+
| Event | Payload | Role |
|
|
17
|
+
|---|---|---|
|
|
18
|
+
| `compaction/start` | `{ turn }` | acquires the log-recorded lock; a number identifies the open automatic turn, while `null` identifies a standalone manual attempt |
|
|
19
|
+
| `compaction/summary` | `{ summary, rawOutput?, llmStreamCall?, shadowedRange, shadowedSeqs, shadowedTokenCount, provider, model, maxTokens?, usage? }` | the safe summary projection, optional complete provider output and usage, an `llmStreamCall: true` marker when producing the result consumed exactly one call through this context's `ctx.llm.stream()` (which requires complete `rawOutput`), the shadowed surface-boundary pair (`start`/`end` seqs — a position span, not a numeric interval), the shadowed seqs in surface order, the estimated token count, and the summarize call's envelope (`provider`, `model`, plus its generation cap when one applied) — logged so the one-shot request is reconstructable from log + code (the reconstructability Agent Note); unmarked `rawOutput` does not identify the call path |
|
|
20
|
+
| `compaction/end` | `{ turn, error? }` | releases the lock with the same numeric-or-null owner (`error` records an unsuccessful attempt) |
|
|
21
|
+
|
|
22
|
+
The lock brackets the **whole** operation: `compaction/start` is appended first, then summarization, the `compaction/summary` record, and the `user/message` replacement all land, and only then `compaction/end`. Releasing the lock last turns a crash mid-operation into a detectable orphaned lock (a `compaction/start` with no matching `compaction/end`) rather than a `compaction/end` that falsely claims compaction finished.
|
|
23
|
+
|
|
24
|
+
The markers are lock time points, not an exclusive container. An unrelated idle injection can appear between a standalone manual start and end while summarization is pending. The manual path revalidates only its selected positional span, so that injected context survives after the replacement checkpoint. A live unmatched start blocks every entry point; an unmatched start before a newer `session/end-seed` is stale evidence from a prior lifecycle and is ignored.
|
|
25
|
+
|
|
26
|
+
These variants are merged inside a `declare module '@deepseek-ai/dsh-session/types'` block, so — unlike the top-level types on the other subsystem pages — they are not pasted as a drift-checked ` ```ts type-equiv ` block (the `verify-type-equiv` extractor matches only top-level declarations by name). The payload table above is the catalog entry; follow the source link for the authoritative fields.
|
|
27
|
+
|
|
28
|
+
## `CompactionResult`
|
|
29
|
+
|
|
30
|
+
What a successful compaction returns to its caller: the bookkeeping-event seqs, safe summary projection, shadowed range and seqs, and estimated token count.
|
|
31
|
+
|
|
32
|
+
```ts type-equiv
|
|
33
|
+
/** Result of a successful compaction operation. */
|
|
34
|
+
interface CompactionResult {
|
|
35
|
+
/** Stable identity shared by this compaction's complete durable lifecycle. */
|
|
36
|
+
compactionId: CompactionId
|
|
37
|
+
/** Human command that initiated this compaction, when it was manual. */
|
|
38
|
+
sourceCommandId?: CommandId
|
|
39
|
+
/** The seq of the appended `compaction/start` event. */
|
|
40
|
+
startSeq: number
|
|
41
|
+
/** The seq of the appended `compaction/summary` event. */
|
|
42
|
+
summarySeq: number
|
|
43
|
+
/** The seq of the appended `compaction/end` event. */
|
|
44
|
+
endSeq: number
|
|
45
|
+
/** The summary content blocks produced by the backend. */
|
|
46
|
+
summary: ContentBlock[]
|
|
47
|
+
/**
|
|
48
|
+
* The surface-boundary pair that was shadowed: the seqs of the first
|
|
49
|
+
* (`start`) and last (`end`) surface nodes of the replaced range. A
|
|
50
|
+
* surface-POSITION span, not a numeric seq interval — after a prior replace
|
|
51
|
+
* lands a fresh high-seq summary node at an older range's position, `start`
|
|
52
|
+
* can be GREATER than `end`. {@link CompactionResult.shadowedSeqs} is the
|
|
53
|
+
* authoritative set of shadowed nodes, in surface order.
|
|
54
|
+
*/
|
|
55
|
+
shadowedRange: { start: number; end: number }
|
|
56
|
+
/** The seqs of all shadowed surface nodes, in surface order. */
|
|
57
|
+
shadowedSeqs: number[]
|
|
58
|
+
/** Estimated token count of the shadowed content. */
|
|
59
|
+
shadowedTokenCount: number
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## The service
|
|
64
|
+
|
|
65
|
+
Automatic callers state why policy is running; implementations may treat confirmed overflow more aggressively than ordinary pressure.
|
|
66
|
+
|
|
67
|
+
```ts type-equiv
|
|
68
|
+
/** Why automatic policy is asking a backend to consider compaction. */
|
|
69
|
+
type CompactionTrigger = 'pressure' | 'context-overflow'
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
`CompactionEngine` exposes `compactIfNeeded(agent, trigger, signal)` for automatic `pressure` or `context-overflow` policy, `compactNow(agent, signal)` for one useful idle-session reduction even below pressure, and `compactRegion(...)` for an explicit inclusive surface range. `compactNow()` runs as agent maintenance between turns, returns `null` without writing when no useful range exists, records a standalone `turn: null` bracket before summarization, and flushes a closed attempt before later queued prompts may derive from the new surface. Every backend creates its replacement `user/message` source with `compactCheckpointSource(compactionId, sourceCommandId?)`; client and wire consumers import that constructor, `CompactionCheckpointSource`, and `isCompactCheckpointSource()` from the cordis-free `@deepseek-ai/dsh-compaction/checkpoint` subpath, while the package root re-exports them for host consumers. The required transaction identity correlates the replacement checkpoint, while the predicate keeps recognition independent of any one backend. Implementations must forward the supplied signal to summarization. The seam owns no pricing API: the singleton [`ctx.tokenMeter`](./token-meter.md) directly owns estimation and replay, while `dsh-compaction-basic` owns retention, event sequencing, routed summarization calls, and their configuration.
|
|
73
|
+
|
|
74
|
+
Expected manual failures use `ManualCompactionErrorCode`:
|
|
75
|
+
|
|
76
|
+
```ts type-equiv
|
|
77
|
+
/** Expected failure classes for an explicit idle-session compaction request. */
|
|
78
|
+
type ManualCompactionErrorCode =
|
|
79
|
+
| 'busy'
|
|
80
|
+
| 'cancelled'
|
|
81
|
+
| 'changed'
|
|
82
|
+
| 'summary'
|
|
83
|
+
| 'commit'
|
|
84
|
+
| 'persistence'
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
`changed` and `summary` leave the conversation surface unchanged but still close and persist the failed attempt in the log. `commit` may follow partial mutation; `persistence` means the in-memory bracket closed but its flush failed. Cancellation remains separate and throws the exact abort reason after required cleanup.
|
|
88
|
+
|
|
89
|
+
Pressure compaction runs at serial `agent/pre-step` before request derivation. Once pressure or canonical overflow qualifies, compaction-basic invokes optional [`ctx.toolResultPruner`](https://github.com/deepseek-ai/deepseek-harness/blob/master/packages/compaction/compaction-tool-result-pruner/README.md) before range selection, remeasures through `ctx.tokenMeter`, and can advance the surface without a summary. Failed-request recovery runs through `agent/request-error` after the failed step closes and returns a retry action only when the surface replacement generation advances, even if later summary work throws after pruning; cancellation still wins. Region boundaries preserve tool-call/result pairing but not whole turns, allowing early closed steps of one oversized turn to compact. `dsh-compaction-basic` owns thresholds, retained-tail policy, overflow caps, and failure handling.
|
|
90
|
+
|
|
91
|
+
The Service Definition exports `toolPairingBalancedBefore(session, seq)` and `toolPairingBalancedAfter(session, seq)` for the tool-call/result pairing checks before and after a seq. Both validate current surface membership and reject missing seqs and orphan results; the [package contract](https://github.com/deepseek-ai/deepseek-harness/blob/master/packages/compaction/compaction/README.md#tool-pairing-boundaries) defines their cache behavior.
|
|
92
|
+
|
|
93
|
+
## Tool-result pruning outcomes
|
|
94
|
+
|
|
95
|
+
The optional tool-result pruning service reports each durable content replacement and the aggregate Unicode-code-point reduction. Its public result types live in [`compaction-tool-result-pruner/src/types.ts`](https://github.com/deepseek-ai/deepseek-harness/blob/master/packages/compaction/compaction-tool-result-pruner/src/types.ts).
|
|
96
|
+
|
|
97
|
+
```ts type-equiv
|
|
98
|
+
/** Cited source event and size accounting for one landed surface replacement. */
|
|
99
|
+
interface PrunedEntry {
|
|
100
|
+
/** Full-fidelity tool-result event shadowed by the replacement. */
|
|
101
|
+
readonly originalSeq: number
|
|
102
|
+
/** Newly appended pruned tool-result event. */
|
|
103
|
+
readonly replacementSeq: number
|
|
104
|
+
/** Tool call shared by the original and replacement. */
|
|
105
|
+
readonly callId: CallId
|
|
106
|
+
/** Original text size in Unicode code points. */
|
|
107
|
+
readonly charsBefore: number
|
|
108
|
+
/** Replacement text size in Unicode code points. */
|
|
109
|
+
readonly charsAfter: number
|
|
110
|
+
}
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
```ts type-equiv
|
|
114
|
+
/** Aggregate outcome of one stable-surface pruning pass. */
|
|
115
|
+
interface PruneResult {
|
|
116
|
+
/** Replacements in the snapshotted surface order. */
|
|
117
|
+
readonly pruned: readonly PrunedEntry[]
|
|
118
|
+
/** Total Unicode code points removed across replacements. */
|
|
119
|
+
readonly charsRemoved: number
|
|
120
|
+
}
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
<!-- BEGIN GENERATED cordis-surface (gen-cordis-catalog.ts) — do not edit between markers -->
|
|
124
|
+
|
|
125
|
+
<a id="cordis-surface"></a>
|
|
126
|
+
|
|
127
|
+
## Cordis API
|
|
128
|
+
|
|
129
|
+
Generated from source by `scripts/gen-cordis-catalog.ts` (verified fresh by `pnpm run verify-cordis-catalog` in doc-sync; regenerate with `pnpm run gen-cordis-catalog`) — this section is byte-identical in both language sides of the page. Signature blocks use a `ts cordis-catalog` fence and keep the original source JSDoc; dispatch modes are defined in the [primer](../cordis-primer.md#dispatch-modes), and the framework-inherited `ctx` API lives in [cordis-api/inherited.md](../cordis-api/inherited.md).
|
|
130
|
+
|
|
131
|
+
<a id="ctxcompaction--compactionengine-abstract-seam"></a>
|
|
132
|
+
|
|
133
|
+
### `ctx.compaction` — `CompactionEngine` (abstract seam)
|
|
134
|
+
|
|
135
|
+
Abstract compaction service. Implementations own trigger policy, retention, and summarization, and may consume a separate measurement service. A successful run replaces the selected surface span with one summary node and prevents concurrent compaction of the same session. The replacement user message uses compactCheckpointSource with the transaction identity so consumers recognize and correlate it independently of the backend. Load one implementation per context as `ctx.compaction`.
|
|
136
|
+
|
|
137
|
+
```ts cordis-catalog
|
|
138
|
+
/**
|
|
139
|
+
* Consider automatic compaction for one explicit trigger. Pressure policy
|
|
140
|
+
* uses the latest durable routed request, while context-overflow policy may
|
|
141
|
+
* force a useful balanced reduction even below the normal threshold. Return
|
|
142
|
+
* `null` when no safe range can be compacted. A single oversized retained
|
|
143
|
+
* unit or request envelope cannot be repaired through surface compaction.
|
|
144
|
+
*
|
|
145
|
+
* @param agent - agent context owning the session surface and routing options.
|
|
146
|
+
* @param trigger - normal pressure or provider-confirmed context overflow.
|
|
147
|
+
* @param signal - cancellation signal; model-backed implementations must forward it.
|
|
148
|
+
* @returns the compaction result, or `null` if no compaction was needed.
|
|
149
|
+
*/
|
|
150
|
+
abstract compactIfNeeded( agent: CompactionAgentContext, trigger: CompactionTrigger, signal: AbortSignal, ): Promise<CompactionResult | null>
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Explicitly compact useful history even below automatic pressure thresholds.
|
|
154
|
+
* Implementations synchronously start an idle task before any asynchronous
|
|
155
|
+
* work, select a useful range without writing on a no-op, then
|
|
156
|
+
* append a standalone `compaction/start` before summarization. That durable
|
|
157
|
+
* marker is the compaction lock until one `compaction/end` attempt. Later waking
|
|
158
|
+
* prompts remain accepted in FIFO order and start only after the optional
|
|
159
|
+
* durability checkpoint and idle-task settlement. Context injected while the
|
|
160
|
+
* summary runs may sit between the marker pair; only the selected span must
|
|
161
|
+
* remain stable.
|
|
162
|
+
*
|
|
163
|
+
* @param agent - idle agent whose durable history should be compacted.
|
|
164
|
+
* @param signal - cancellation scoped to this compaction request.
|
|
165
|
+
* @param sourceCommandId - initiating command identity for a manual compaction.
|
|
166
|
+
* @returns the compaction result, or `null` when no safe useful range exists.
|
|
167
|
+
* @throws {@link ManualCompactionError} for expected busy, agent-cancellation,
|
|
168
|
+
* changed-span, summarization/shrink, commit-stage, or persistence failures;
|
|
169
|
+
* an aborted request preserves its exact abort reason. Failed attempts remain
|
|
170
|
+
* visible in the log.
|
|
171
|
+
*/
|
|
172
|
+
abstract compactNow( agent: ManualCompactAgentContext, signal: AbortSignal, sourceCommandId?: CommandId, ): Promise<CompactionResult | null>
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Forcibly compact a range of surface nodes into a single summary node.
|
|
176
|
+
* `start` and `end` name an inclusive span by surface position, not numeric seq
|
|
177
|
+
* order; replacements can make visible seqs non-monotonic. Both edges must be
|
|
178
|
+
* balanced so assistant tool calls remain paired with their results. A model-
|
|
179
|
+
* backed implementation forwards cancellation and rejects active, missing,
|
|
180
|
+
* reversed, or unbalanced ranges. The target session is `agent.session`.
|
|
181
|
+
* Its replacement user message must use {@link compactCheckpointSource} with
|
|
182
|
+
* the transaction's `CompactionId`.
|
|
183
|
+
* Use {@link toolPairingBalancedBefore} and {@link toolPairingBalancedAfter}
|
|
184
|
+
* for the edge checks.
|
|
185
|
+
*
|
|
186
|
+
* @param start - first surface seq, inclusive.
|
|
187
|
+
* @param end - last surface seq, inclusive.
|
|
188
|
+
* @param agent - context whose session is mutated and whose routing options guide summarization.
|
|
189
|
+
* @param signal - optional cancellation; model-backed implementations must forward it.
|
|
190
|
+
* @throws when compaction is active or the range is missing, reversed, or unbalanced.
|
|
191
|
+
* @returns the appended event seqs, summary, replaced range, and token accounting.
|
|
192
|
+
*/
|
|
193
|
+
abstract compactRegion( start: number, end: number, agent: CompactionAgentContext, signal?: AbortSignal, ): Promise<CompactionResult>
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
Types: [CommandId](./commands.md)
|
|
197
|
+
|
|
198
|
+
Source: [`packages/compaction/compaction/src/index.ts:96`](https://github.com/deepseek-ai/deepseek-harness/blob/master/packages/compaction/compaction/src/index.ts)
|
|
199
|
+
|
|
200
|
+
<a id="ctxtoolresultpruner--toolresultpruner"></a>
|
|
201
|
+
|
|
202
|
+
### `ctx.toolResultPruner` — `ToolResultPruner`
|
|
203
|
+
|
|
204
|
+
Deterministic head/middle/tail pruning for current tool-result surface nodes.
|
|
205
|
+
|
|
206
|
+
```ts cordis-catalog
|
|
207
|
+
/**
|
|
208
|
+
* Measure text content in Unicode code points; non-text blocks cost zero.
|
|
209
|
+
* @param blocks - tool-result content to measure.
|
|
210
|
+
* @returns total Unicode code points across text blocks.
|
|
211
|
+
*/
|
|
212
|
+
measureContent(blocks: readonly ContentBlock[]): number
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Replace an over-budget text middle while retaining rich-block order.
|
|
216
|
+
* Text slicing is by Unicode code point, not UTF-16 code unit, so a retained
|
|
217
|
+
* boundary cannot split a surrogate pair. Grapheme clusters may still split.
|
|
218
|
+
* @param blocks - original tool-result content.
|
|
219
|
+
* @returns pruned content, or `null` when the text is within budget.
|
|
220
|
+
*/
|
|
221
|
+
pruneContent(blocks: readonly ContentBlock[]): ContentBlock[] | null
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Prune every over-budget tool result from one stable current-surface snapshot.
|
|
225
|
+
* Each replacement preserves the complete event data except for `content`,
|
|
226
|
+
* cites the shadowed node so replay can recover the replacement input, and is
|
|
227
|
+
* immediately preceded by a `compaction/prune` shadow-price event pricing the
|
|
228
|
+
* shadowed node through the injected token meter, so pure consumers can
|
|
229
|
+
* subtract it without per-node state.
|
|
230
|
+
* @param session - session whose current surface is rewritten.
|
|
231
|
+
* @returns landed replacements and aggregate Unicode-code-point savings.
|
|
232
|
+
* @throws when the session rejects a replacement; replacements committed
|
|
233
|
+
* earlier in the pass remain durable.
|
|
234
|
+
*/
|
|
235
|
+
pruneSession(session: Session): PruneResult
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
Types: [ContentBlock](./llm-streaming.md) · [Session](./session.md)
|
|
239
|
+
|
|
240
|
+
Source: [`packages/compaction/compaction-tool-result-pruner/src/index.ts:44`](https://github.com/deepseek-ai/deepseek-harness/blob/master/packages/compaction/compaction-tool-result-pruner/src/index.ts)
|
|
241
|
+
<!-- END GENERATED cordis-surface -->
|