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.
Files changed (234) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +56 -0
  3. package/cordis.patch.yml +12 -0
  4. package/kb/INDEX.md +210 -0
  5. package/kb/README.md +69 -0
  6. package/kb/extra/AGENTS.md +75 -0
  7. package/kb/extra/api-gateway.md +164 -0
  8. package/kb/extra/api-gateway.zh.md +164 -0
  9. package/kb/extra/cookbook/adding-a-vendored-package.md +59 -0
  10. package/kb/extra/cookbook/adding-a-vendored-package.zh.md +59 -0
  11. package/kb/extra/cookbook/maintaining-dsh-code-review.md +64 -0
  12. package/kb/extra/cookbook/maintaining-dsh-code-review.zh.md +64 -0
  13. package/kb/extra/cookbook/responding-to-pr-review-on-a-stack.md +32 -0
  14. package/kb/extra/cookbook/responding-to-pr-review-on-a-stack.zh.md +32 -0
  15. package/kb/extra/defensive-patterns.md +33 -0
  16. package/kb/extra/defensive-patterns.zh.md +33 -0
  17. package/kb/extra/development.md +171 -0
  18. package/kb/extra/development.zh.md +171 -0
  19. package/kb/extra/event-producer-consumer.md +76 -0
  20. package/kb/extra/event-producer-consumer.zh.md +78 -0
  21. package/kb/extra/glossary.md +45 -0
  22. package/kb/extra/glossary.zh.md +45 -0
  23. package/kb/extra/graph-atlas.md +24 -0
  24. package/kb/extra/graph-atlas.zh.md +26 -0
  25. package/kb/extra/i18n/README.md +60 -0
  26. package/kb/extra/i18n/README.zh.md +60 -0
  27. package/kb/extra/i18n/style-samples.md +87 -0
  28. package/kb/extra/i18n/terminology.md +214 -0
  29. package/kb/extra/i18n/translation-prompt.md +263 -0
  30. package/kb/extra/i18n/translation-rules.md +69 -0
  31. package/kb/extra/i18n/translation-rules.zh.md +69 -0
  32. package/kb/extra/module-graph.md +1641 -0
  33. package/kb/extra/module-graph.zh.md +1643 -0
  34. package/kb/extra/postmortem/0001-acp-default-export-drops-inject.md +113 -0
  35. package/kb/extra/postmortem/0001-acp-default-export-drops-inject.zh.md +113 -0
  36. package/kb/extra/postmortem/0002-js-expression-disabled-filesystem-tools.md +47 -0
  37. package/kb/extra/postmortem/0002-js-expression-disabled-filesystem-tools.zh.md +47 -0
  38. package/kb/extra/postmortem/0003-web-agent-gui-feedback-loop.md +53 -0
  39. package/kb/extra/postmortem/0003-web-agent-gui-feedback-loop.zh.md +53 -0
  40. package/kb/extra/postmortem/0004-landlock-partial-notice-misclassified-child-failures.md +55 -0
  41. package/kb/extra/postmortem/0004-landlock-partial-notice-misclassified-child-failures.zh.md +55 -0
  42. package/kb/extra/postmortem/README.md +18 -0
  43. package/kb/extra/postmortem/README.zh.md +18 -0
  44. package/kb/extra/rescope.md +53 -0
  45. package/kb/extra/rescope.zh.md +53 -0
  46. package/kb/extra/subsystems/attachment.md +125 -0
  47. package/kb/extra/subsystems/attachment.zh.md +125 -0
  48. package/kb/extra/subsystems/extensions.md +364 -0
  49. package/kb/extra/subsystems/extensions.zh.md +364 -0
  50. package/kb/extra/subsystems/feedback.md +266 -0
  51. package/kb/extra/subsystems/feedback.zh.md +266 -0
  52. package/kb/extra/testing.md +49 -0
  53. package/kb/extra/testing.zh.md +49 -0
  54. package/kb/extra/web-styling.md +25 -0
  55. package/kb/extra/web-styling.zh.md +25 -0
  56. package/kb/meta/search-index.json +1328 -0
  57. package/kb/meta/site-pages.txt +168 -0
  58. package/kb/meta/source.json +13 -0
  59. package/kb/meta/topics.md +75 -0
  60. package/kb/site/develop/basic/config.md +108 -0
  61. package/kb/site/develop/basic/index.md +146 -0
  62. package/kb/site/develop/basic/publish.md +185 -0
  63. package/kb/site/develop/basic/tool.md +54 -0
  64. package/kb/site/develop/cordis-tutorial/01-first-plugin.md +95 -0
  65. package/kb/site/develop/cordis-tutorial/02-lifecycle-and-effects.md +98 -0
  66. package/kb/site/develop/cordis-tutorial/03-services.md +98 -0
  67. package/kb/site/develop/cordis-tutorial/04-events.md +144 -0
  68. package/kb/site/develop/cordis-tutorial/05-config.md +84 -0
  69. package/kb/site/develop/cordis-tutorial/06-composition-and-hmr.md +113 -0
  70. package/kb/site/develop/cordis-tutorial/07-into-the-harness.md +107 -0
  71. package/kb/site/develop/cordis-tutorial/index.md +62 -0
  72. package/kb/site/develop/framework/events.md +145 -0
  73. package/kb/site/develop/framework/index.md +139 -0
  74. package/kb/site/develop/framework/service.md +152 -0
  75. package/kb/site/develop/practice/index.md +157 -0
  76. package/kb/site/develop/practice/llm-adapter.md +190 -0
  77. package/kb/site/en/develop/basic/config.md +108 -0
  78. package/kb/site/en/develop/basic/index.md +146 -0
  79. package/kb/site/en/develop/basic/publish.md +185 -0
  80. package/kb/site/en/develop/basic/tool.md +54 -0
  81. package/kb/site/en/develop/cordis-tutorial/01-first-plugin.md +95 -0
  82. package/kb/site/en/develop/cordis-tutorial/02-lifecycle-and-effects.md +98 -0
  83. package/kb/site/en/develop/cordis-tutorial/03-services.md +98 -0
  84. package/kb/site/en/develop/cordis-tutorial/04-events.md +144 -0
  85. package/kb/site/en/develop/cordis-tutorial/05-config.md +84 -0
  86. package/kb/site/en/develop/cordis-tutorial/06-composition-and-hmr.md +113 -0
  87. package/kb/site/en/develop/cordis-tutorial/07-into-the-harness.md +107 -0
  88. package/kb/site/en/develop/cordis-tutorial/index.md +60 -0
  89. package/kb/site/en/develop/framework/events.md +145 -0
  90. package/kb/site/en/develop/framework/index.md +139 -0
  91. package/kb/site/en/develop/framework/service.md +150 -0
  92. package/kb/site/en/develop/practice/index.md +157 -0
  93. package/kb/site/en/develop/practice/llm-adapter.md +190 -0
  94. package/kb/site/en/guide/providers-custom-form.png +0 -0
  95. package/kb/site/en/guide/providers-models-page.png +0 -0
  96. package/kb/site/en/guide/providers.md +100 -0
  97. package/kb/site/en/guide/python-sdk.md +106 -0
  98. package/kb/site/en/guide/quickstart.md +32 -0
  99. package/kb/site/en/index.md +8 -0
  100. package/kb/site/en/reference/agent-lifecycle.md +86 -0
  101. package/kb/site/en/reference/capability-seams.md +475 -0
  102. package/kb/site/en/reference/config-catalog.md +3155 -0
  103. package/kb/site/en/reference/cookbook/adding-a-conversation-node.md +235 -0
  104. package/kb/site/en/reference/cookbook/adding-a-package.md +120 -0
  105. package/kb/site/en/reference/cookbook/adding-a-settings-card.md +102 -0
  106. package/kb/site/en/reference/cookbook/adding-a-tool.md +96 -0
  107. package/kb/site/en/reference/cookbook/adding-an-llm-adapter.md +45 -0
  108. package/kb/site/en/reference/cookbook/extension-cookbook.md +131 -0
  109. package/kb/site/en/reference/cordis-api/context.md +368 -0
  110. package/kb/site/en/reference/cordis-api/events.md +211 -0
  111. package/kb/site/en/reference/cordis-api/fiber.md +379 -0
  112. package/kb/site/en/reference/cordis-api/inherited.md +43 -0
  113. package/kb/site/en/reference/cordis-api/registry.md +156 -0
  114. package/kb/site/en/reference/cordis-api/service.md +106 -0
  115. package/kb/site/en/reference/cordis-primer.md +46 -0
  116. package/kb/site/en/reference/index.md +131 -0
  117. package/kb/site/en/reference/persistence-catalog.md +949 -0
  118. package/kb/site/en/reference/subsystems/approval.md +173 -0
  119. package/kb/site/en/reference/subsystems/client-modules.md +121 -0
  120. package/kb/site/en/reference/subsystems/code-runtime.md +194 -0
  121. package/kb/site/en/reference/subsystems/commands.md +190 -0
  122. package/kb/site/en/reference/subsystems/compaction.md +241 -0
  123. package/kb/site/en/reference/subsystems/core.md +1073 -0
  124. package/kb/site/en/reference/subsystems/credentials.md +136 -0
  125. package/kb/site/en/reference/subsystems/filesystem.md +498 -0
  126. package/kb/site/en/reference/subsystems/goal.md +280 -0
  127. package/kb/site/en/reference/subsystems/index.md +58 -0
  128. package/kb/site/en/reference/subsystems/invariants.md +91 -0
  129. package/kb/site/en/reference/subsystems/jobs.md +293 -0
  130. package/kb/site/en/reference/subsystems/llm-streaming.md +920 -0
  131. package/kb/site/en/reference/subsystems/lsp.md +205 -0
  132. package/kb/site/en/reference/subsystems/permission-presets.md +134 -0
  133. package/kb/site/en/reference/subsystems/persistence.md +388 -0
  134. package/kb/site/en/reference/subsystems/plan.md +90 -0
  135. package/kb/site/en/reference/subsystems/sandbox.md +221 -0
  136. package/kb/site/en/reference/subsystems/schedule.md +189 -0
  137. package/kb/site/en/reference/subsystems/scope.md +62 -0
  138. package/kb/site/en/reference/subsystems/session-projection.md +265 -0
  139. package/kb/site/en/reference/subsystems/session-query.md +498 -0
  140. package/kb/site/en/reference/subsystems/session-reference.md +111 -0
  141. package/kb/site/en/reference/subsystems/session-telemetry.md +197 -0
  142. package/kb/site/en/reference/subsystems/session-title.md +207 -0
  143. package/kb/site/en/reference/subsystems/session.md +852 -0
  144. package/kb/site/en/reference/subsystems/settings.md +313 -0
  145. package/kb/site/en/reference/subsystems/shell.md +306 -0
  146. package/kb/site/en/reference/subsystems/skills.md +334 -0
  147. package/kb/site/en/reference/subsystems/spill.md +120 -0
  148. package/kb/site/en/reference/subsystems/storage.md +232 -0
  149. package/kb/site/en/reference/subsystems/subagent.md +737 -0
  150. package/kb/site/en/reference/subsystems/subprocess.md +327 -0
  151. package/kb/site/en/reference/subsystems/system-prompt.md +210 -0
  152. package/kb/site/en/reference/subsystems/terminal.md +187 -0
  153. package/kb/site/en/reference/subsystems/token-meter.md +93 -0
  154. package/kb/site/en/reference/subsystems/tools.md +723 -0
  155. package/kb/site/en/reference/subsystems/typert.md +339 -0
  156. package/kb/site/en/reference/subsystems/user-questions.md +181 -0
  157. package/kb/site/en/reference/subsystems/web-server.md +111 -0
  158. package/kb/site/en/reference/subsystems/web.md +202 -0
  159. package/kb/site/en/reference/subsystems/workflow.md +281 -0
  160. package/kb/site/en/reference/subsystems/workspace.md +231 -0
  161. package/kb/site/en/reference/tool-catalog.md +1877 -0
  162. package/kb/site/en/reference/tool-execution-pipeline.md +66 -0
  163. package/kb/site/guide/providers-custom-form.zh.png +0 -0
  164. package/kb/site/guide/providers-models-page.zh.png +0 -0
  165. package/kb/site/guide/providers.md +100 -0
  166. package/kb/site/guide/python-sdk.md +106 -0
  167. package/kb/site/guide/quickstart.md +32 -0
  168. package/kb/site/index.md +8 -0
  169. package/kb/site/reference/agent-lifecycle.md +86 -0
  170. package/kb/site/reference/capability-seams.md +475 -0
  171. package/kb/site/reference/config-catalog.md +3154 -0
  172. package/kb/site/reference/cookbook/adding-a-conversation-node.md +235 -0
  173. package/kb/site/reference/cookbook/adding-a-package.md +120 -0
  174. package/kb/site/reference/cookbook/adding-a-settings-card.md +102 -0
  175. package/kb/site/reference/cookbook/adding-a-tool.md +98 -0
  176. package/kb/site/reference/cookbook/adding-an-llm-adapter.md +45 -0
  177. package/kb/site/reference/cookbook/extension-cookbook.md +133 -0
  178. package/kb/site/reference/cordis-api/context.md +368 -0
  179. package/kb/site/reference/cordis-api/events.md +211 -0
  180. package/kb/site/reference/cordis-api/fiber.md +379 -0
  181. package/kb/site/reference/cordis-api/inherited.md +43 -0
  182. package/kb/site/reference/cordis-api/registry.md +156 -0
  183. package/kb/site/reference/cordis-api/service.md +106 -0
  184. package/kb/site/reference/cordis-primer.md +52 -0
  185. package/kb/site/reference/index.md +135 -0
  186. package/kb/site/reference/persistence-catalog.md +949 -0
  187. package/kb/site/reference/subsystems/approval.md +173 -0
  188. package/kb/site/reference/subsystems/client-modules.md +121 -0
  189. package/kb/site/reference/subsystems/code-runtime.md +194 -0
  190. package/kb/site/reference/subsystems/commands.md +190 -0
  191. package/kb/site/reference/subsystems/compaction.md +241 -0
  192. package/kb/site/reference/subsystems/core.md +1081 -0
  193. package/kb/site/reference/subsystems/credentials.md +136 -0
  194. package/kb/site/reference/subsystems/filesystem.md +498 -0
  195. package/kb/site/reference/subsystems/goal.md +280 -0
  196. package/kb/site/reference/subsystems/index.md +58 -0
  197. package/kb/site/reference/subsystems/invariants.md +91 -0
  198. package/kb/site/reference/subsystems/jobs.md +293 -0
  199. package/kb/site/reference/subsystems/llm-streaming.md +926 -0
  200. package/kb/site/reference/subsystems/lsp.md +205 -0
  201. package/kb/site/reference/subsystems/permission-presets.md +134 -0
  202. package/kb/site/reference/subsystems/persistence.md +388 -0
  203. package/kb/site/reference/subsystems/plan.md +90 -0
  204. package/kb/site/reference/subsystems/sandbox.md +221 -0
  205. package/kb/site/reference/subsystems/schedule.md +189 -0
  206. package/kb/site/reference/subsystems/scope.md +62 -0
  207. package/kb/site/reference/subsystems/session-projection.md +265 -0
  208. package/kb/site/reference/subsystems/session-query.md +498 -0
  209. package/kb/site/reference/subsystems/session-reference.md +111 -0
  210. package/kb/site/reference/subsystems/session-telemetry.md +197 -0
  211. package/kb/site/reference/subsystems/session-title.md +207 -0
  212. package/kb/site/reference/subsystems/session.md +854 -0
  213. package/kb/site/reference/subsystems/settings.md +313 -0
  214. package/kb/site/reference/subsystems/shell.md +306 -0
  215. package/kb/site/reference/subsystems/skills.md +334 -0
  216. package/kb/site/reference/subsystems/spill.md +120 -0
  217. package/kb/site/reference/subsystems/storage.md +232 -0
  218. package/kb/site/reference/subsystems/subagent.md +739 -0
  219. package/kb/site/reference/subsystems/subprocess.md +327 -0
  220. package/kb/site/reference/subsystems/system-prompt.md +210 -0
  221. package/kb/site/reference/subsystems/terminal.md +187 -0
  222. package/kb/site/reference/subsystems/token-meter.md +93 -0
  223. package/kb/site/reference/subsystems/tools.md +723 -0
  224. package/kb/site/reference/subsystems/typert.md +339 -0
  225. package/kb/site/reference/subsystems/user-questions.md +181 -0
  226. package/kb/site/reference/subsystems/web-server.md +111 -0
  227. package/kb/site/reference/subsystems/web.md +202 -0
  228. package/kb/site/reference/subsystems/workflow.md +281 -0
  229. package/kb/site/reference/subsystems/workspace.md +231 -0
  230. package/kb/site/reference/tool-catalog.md +1880 -0
  231. package/kb/site/reference/tool-execution-pipeline.md +66 -0
  232. package/package.json +40 -0
  233. package/scripts/rebuild-index.mjs +88 -0
  234. package/skills/dsh-plugin-dev-kb.md +66 -0
@@ -0,0 +1,190 @@
1
+ ---
2
+ editSource: "docs/subsystems/commands.zh.md"
3
+ outline: [2,3]
4
+ ---
5
+
6
+ # 用户命令
7
+
8
+ [`dsh-commands`](https://github.com/deepseek-ai/deepseek-harness/tree/master/packages/interaction/commands) 提供的用户命令注册表服务。交互式适配器用它发现插件拥有的命令,并针对确切的 agent(智能体)直接执行这些命令,而不创建模型消息。[命令 Agent Note](https://github.com/deepseek-ai/deepseek-harness/blob/master/.agents/notes/implemented/feature/2026-07-19-plugin-command-registration.md) 负责分发与生命周期的决策依据;[包 README](https://github.com/deepseek-ai/deepseek-harness/blob/master/packages/interaction/commands/README.md) 负责组合方式与限制。
9
+
10
+ 来源:[`packages/interaction/commands/src/index.ts`](https://github.com/deepseek-ai/deepseek-harness/blob/master/packages/interaction/commands/src/index.ts)
11
+
12
+ ## 输入元数据
13
+
14
+ 该服务公开一个可选的非结构化输入提示。命令的可用性由插件组合决定:每个消费注册表的适配器都会看到全部生效定义。
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
+ ## 定义
25
+
26
+ `CommandDefinition` 是由插件编写的注册定义。注册表会验证并冻结一份与原始注册对象脱离的生效定义。
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
+ ## 调用与结果
49
+
50
+ 取消由适配器负责,适配器会传入确切的目标 agent。`rawInput` 紧接在解析后的名称之后,并保留适配器传入的分隔符与后缀。结果会直接呈现给 UI,而不是工具结果或会话事件。
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` 是可选字段,且只用于成功结果。存在时,它指向接收会话日志中更早的一条非命令事件;`command/done` 会持久化同一引用,让客户端能够将命令生命周期与该领域投影合并,而无须解析 `text` 或依赖相邻行。
79
+
80
+ ## 发现与解析视图
81
+
82
+ 作用域解析后,适配器会获得不含处理器的不可变描述符。`parseCommand()` 在注册表解析前返回 `ParsedCommand`;语法有效的输入仍可能指向不可用的命令。
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.zh.md"
3
+ outline: [2,3]
4
+ ---
5
+
6
+ # 压缩(compaction)
7
+
8
+ 压缩 seam 是一个[能力 seam](https://github.com/deepseek-ai/deepseek-harness/blob/master/.agents/notes/implemented/architecture/2026-06-13-capability-seams.md),与 bash 一样分为 Service Definition([dsh-compaction](https://github.com/deepseek-ai/deepseek-harness/tree/master/packages/compaction/compaction),`ctx.compaction`)、Service Provider(例如 [dsh-compaction-basic](https://github.com/deepseek-ai/deepseek-harness/tree/master/packages/compaction/compaction-basic) 后端)和面向用户的 Consumer([dsh-command-compact](https://github.com/deepseek-ai/deepseek-harness/tree/master/packages/compaction/command-compact))。压缩是**一项可选能力**,不属于 agent loop(智能体循环)主干,因此其词汇定义在此而非 [core.md](./core.md) 中。基于 tokenizer 或模板的后端是实现同一接口的兄弟包。与 bash 不同,该接口必然依赖 `dsh-session` 和 `dsh-llm`:其动词作用于 agent 所有的 `Session`,而其持久摘要事件使用 `ContentBlock` 词汇(见[压缩能力 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
+ 源码:[`packages/compaction/compaction/src/types.ts`](https://github.com/deepseek-ai/deepseek-harness/blob/master/packages/compaction/compaction/src/types.ts)
11
+
12
+ ## `compaction/*` 会话事件
13
+
14
+ 压缩通过声明合并为 [`SessionEventMap`](./session.md) 扩展三种事件类型。三者都**仅写入日志**——它们记录锁、摘要、选中范围、被遮蔽事件 seq、token 数以及模型调用,绝不进入 surface。这里有意不扩展 `SurfaceEventType`(只有产生消息的事件才到达模型),因此摘要本身承载在另一条带有 `surfaceOp: { op: 'replace', start, end }` 的 `user/message` 上——这是摘要压缩执行的唯一 surface 变更。[Agent Note](https://github.com/deepseek-ai/deepseek-harness/blob/master/.agents/notes/implemented/feature/2026-06-18-compaction-capability-seam.md) 负责复用 `user/message` 的决策依据。
15
+
16
+ | 事件 | 载荷 | 作用 |
17
+ |---|---|---|
18
+ | `compaction/start` | `{ turn }` | 获取日志记录的锁;数字标识尚未结束的自动轮次,`null` 标识独立手动尝试 |
19
+ | `compaction/summary` | `{ summary, rawOutput?, llmStreamCall?, shadowedRange, shadowedSeqs, shadowedTokenCount, provider, model, maxTokens?, usage? }` | 安全摘要投影、可选的完整提供方输出与 usage、生成结果时恰好通过此上下文的 `ctx.llm.stream()` 发起一次调用所带的 `llmStreamCall: true` 标记(此时必须提供完整的 `rawOutput`)、被遮蔽的 surface 边界对(`start`/`end` seq——位置跨度,而非数值区间)、按 surface 顺序排列的被遮蔽 seq、估算 token 数,以及摘要调用的 envelope(`provider`、`model`,若有生成上限则还包括该上限)——写入日志后,该一次性请求可由日志 + 代码重建(见可重建性 Agent Note);未带标记的 `rawOutput` 并不能判定调用路径 |
20
+ | `compaction/end` | `{ turn, error? }` | 使用相同的数字或 `null` 归属值释放锁(`error` 记录失败尝试) |
21
+
22
+ 锁括住**整个**操作:先追加 `compaction/start`,然后执行摘要生成、写入 `compaction/summary` 记录与 `user/message` 替换,最后才追加 `compaction/end`。最后释放锁意味着操作中途崩溃会表现为可检测的遗留锁(有 `compaction/start` 而无匹配的 `compaction/end`),而非一个虚假声称压缩已完成的 `compaction/end`。
23
+
24
+ 这些标记表示锁的时间点,而不是排他的容器。摘要等待期间,不相关的空闲注入可以出现在独立的手动 start 与 end 之间。手动路径只重新验证所选位置 span,因此替换检查点之后仍保留该注入上下文。活动的未匹配 start 会阻塞所有入口点;较新 `session/end-seed` 之前的未匹配 start 是先前生命周期留下的陈旧证据,会被忽略。
25
+
26
+ 这些变体在 `declare module '@deepseek-ai/dsh-session/types'` 块内合并,因此——与其他子系统页面上的顶层类型不同——它们不以漂移检查的 ` ```ts type-equiv ` 块粘贴(`verify-type-equiv` 提取器只按名称匹配顶层声明)。上方的载荷表即为目录条目;权威字段请循源码链接查看。
27
+
28
+ ## `CompactionResult`
29
+
30
+ 成功压缩向调用方返回:记账事件 seq、安全摘要投影、被遮蔽的范围与 seq,以及估算 token 数。
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
+ ## 服务
64
+
65
+ 自动调用方会说明策略为何运行;实现可以比普通压力更激进地处理已确认的溢出。
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` 暴露 `compactIfNeeded(agent, trigger, signal)` 以执行自动 `pressure` 或 `context-overflow` 策略,暴露 `compactNow(agent, signal)` 以便即使未达到压力也对空闲会话进行一次有效缩减,还针对显式、两端均包含的 surface 范围暴露 `compactRegion(...)`。`compactNow()` 作为轮次之间的 agent maintenance 运行;没有有效范围时返回 `null` 且不写入;在摘要前记录独立的 `turn: null` 标记对,并在后续排队提示词能够从新表层派生前 flush 已闭合尝试。每个后端都使用 `compactCheckpointSource(compactionId, sourceCommandId?)` 创建替换用 `user/message` 的源;client 与 wire 消费方从无 Cordis 的 `@deepseek-ai/dsh-compaction/checkpoint` 子路径导入该构造函数、`CompactionCheckpointSource` 和 `isCompactCheckpointSource()`,包根则为 host 消费方重新导出它们。必填的事务身份会关联替换检查点,而该判定函数使检查点识别不依赖任一特定后端。实现必须把传入的 signal 转发给摘要流程。该 seam 不拥有计价 API:单例 [`ctx.tokenMeter`](./token-meter.md) 直接拥有估算与回放,而 `dsh-compaction-basic` 拥有保留策略、事件排序、按路由执行的摘要调用及其配置。
73
+
74
+ 预期的手动失败使用 `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` 和 `summary` 保持会话表层不变,但仍会闭合失败尝试并将其持久化到日志。`commit` 可能发生在部分变更之后;`persistence` 表示内存中的标记对已闭合,但 flush 失败。取消独立于这些失败,并在完成必要清理后抛出原始 abort 原因。
88
+
89
+ 压力压缩在串行 `agent/pre-step` 中运行,先于请求推导。一旦压力或规范化溢出满足条件,compaction-basic 会在选择范围前调用可选的 [`ctx.toolResultPruner`](https://github.com/deepseek-ai/deepseek-harness/blob/master/packages/compaction/compaction-tool-result-pruner/README.md),再通过 `ctx.tokenMeter` 重新测量,并且可以在不生成摘要的情况下推进 surface。失败请求的恢复在失败的步骤关闭后通过 `agent/request-error` 运行;仅当 surface replacement generation 前进时才返回重试动作,即便后续摘要工作在剪枝后抛异常亦如此;取消仍然优先。区域边界保持工具调用/结果配对,但不保持整个轮次,因此一个过大轮次中较早关闭的步骤可以被压缩。`dsh-compaction-basic` 拥有阈值、保留尾部策略、溢出上限与失败处理。
90
+
91
+ 该 Service Definition 导出 `toolPairingBalancedBefore(session, seq)` 与 `toolPairingBalancedAfter(session, seq)`,用于检查 seq 之前与之后的工具调用/结果配对。两者都会验证当前 surface 成员关系,并拒绝缺失的 seq 与遗留结果;[包约定](https://github.com/deepseek-ai/deepseek-harness/blob/master/packages/compaction/compaction/README.md#tool-pairing-boundaries)定义其缓存行为。
92
+
93
+ ## 工具结果剪枝产出
94
+
95
+ 可选的工具结果剪枝服务会报告每次持久内容替换以及 Unicode code point 的总减少量。其公开结果类型位于 [`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 -->