@kirkchinese/harness-forge 0.0.0-stage → 0.4.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 (246) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +42 -2
  3. package/assets/icon.svg +12 -0
  4. package/cordis.patch.yml +28 -0
  5. package/lib/agents/presets.d.ts +91 -0
  6. package/lib/agents/presets.js +282 -0
  7. package/lib/agents/profiles.d.ts +58 -0
  8. package/lib/agents/profiles.js +278 -0
  9. package/lib/agents/row.d.ts +17 -0
  10. package/lib/agents/row.js +146 -0
  11. package/lib/client/styles.d.ts +8 -0
  12. package/lib/client/styles.js +89 -0
  13. package/lib/client/typert.d.ts +14 -0
  14. package/lib/client/typert.js +110 -0
  15. package/lib/client.js +22500 -0
  16. package/lib/commands/definition.d.ts +40 -0
  17. package/lib/commands/definition.js +113 -0
  18. package/lib/commands/output-styles.d.ts +42 -0
  19. package/lib/commands/output-styles.js +152 -0
  20. package/lib/commands/row.d.ts +9 -0
  21. package/lib/commands/row.js +157 -0
  22. package/lib/context/instructions.d.ts +32 -0
  23. package/lib/context/instructions.js +88 -0
  24. package/lib/context/row.d.ts +16 -0
  25. package/lib/context/row.js +17 -0
  26. package/lib/dsh/commands.d.ts +30 -0
  27. package/lib/dsh/commands.js +61 -0
  28. package/lib/dsh/host.d.ts +107 -0
  29. package/lib/dsh/host.js +214 -0
  30. package/lib/dsh/model-route.d.ts +21 -0
  31. package/lib/dsh/model-route.js +37 -0
  32. package/lib/dsh/session-records.d.ts +78 -0
  33. package/lib/dsh/session-records.js +36 -0
  34. package/lib/dsh/subagents.d.ts +46 -0
  35. package/lib/dsh/subagents.js +14 -0
  36. package/lib/forge/contract.d.ts +231 -0
  37. package/lib/forge/contract.js +43 -0
  38. package/lib/forge/ledger.d.ts +143 -0
  39. package/lib/forge/ledger.js +733 -0
  40. package/lib/forge/live-mounts.d.ts +45 -0
  41. package/lib/forge/live-mounts.js +78 -0
  42. package/lib/forge/marketplace-install.d.ts +3 -0
  43. package/lib/forge/marketplace-install.js +64 -0
  44. package/lib/forge/npm.d.ts +31 -0
  45. package/lib/forge/npm.js +60 -0
  46. package/lib/forge/projects.d.ts +94 -0
  47. package/lib/forge/projects.js +336 -0
  48. package/lib/forge/receipts.d.ts +5 -0
  49. package/lib/forge/receipts.js +31 -0
  50. package/lib/forge/row.d.ts +32 -0
  51. package/lib/forge/row.js +59 -0
  52. package/lib/forge/service.d.ts +105 -0
  53. package/lib/forge/service.js +274 -0
  54. package/lib/forge/settings.d.ts +41 -0
  55. package/lib/forge/settings.js +115 -0
  56. package/lib/forge/state.d.ts +69 -0
  57. package/lib/forge/state.js +150 -0
  58. package/lib/forge/trust.d.ts +48 -0
  59. package/lib/forge/trust.js +107 -0
  60. package/lib/forge/turns.d.ts +13 -0
  61. package/lib/forge/turns.js +56 -0
  62. package/lib/hooks/broker/engine.d.ts +112 -0
  63. package/lib/hooks/broker/engine.js +728 -0
  64. package/lib/hooks/broker/helpers.d.ts +10 -0
  65. package/lib/hooks/broker/helpers.js +22 -0
  66. package/lib/hooks/broker/lifecycle.d.ts +65 -0
  67. package/lib/hooks/broker/lifecycle.js +342 -0
  68. package/lib/hooks/broker/session-events.d.ts +22 -0
  69. package/lib/hooks/broker/session-events.js +196 -0
  70. package/lib/hooks/broker/tools.d.ts +52 -0
  71. package/lib/hooks/broker/tools.js +424 -0
  72. package/lib/hooks/broker/types.d.ts +262 -0
  73. package/lib/hooks/broker/types.js +1 -0
  74. package/lib/hooks/broker.d.ts +80 -0
  75. package/lib/hooks/broker.js +95 -0
  76. package/lib/hooks/codex-user.d.ts +5 -0
  77. package/lib/hooks/codex-user.js +109 -0
  78. package/lib/hooks/condition.d.ts +11 -0
  79. package/lib/hooks/condition.js +181 -0
  80. package/lib/hooks/config.d.ts +85 -0
  81. package/lib/hooks/config.js +150 -0
  82. package/lib/hooks/matcher.d.ts +20 -0
  83. package/lib/hooks/matcher.js +39 -0
  84. package/lib/hooks/notice.d.ts +17 -0
  85. package/lib/hooks/notice.js +39 -0
  86. package/lib/hooks/output.d.ts +56 -0
  87. package/lib/hooks/output.js +214 -0
  88. package/lib/hooks/permissions.d.ts +14 -0
  89. package/lib/hooks/permissions.js +109 -0
  90. package/lib/hooks/process.d.ts +47 -0
  91. package/lib/hooks/process.js +134 -0
  92. package/lib/hooks/row.d.ts +17 -0
  93. package/lib/hooks/row.js +94 -0
  94. package/lib/hooks/runner.d.ts +85 -0
  95. package/lib/hooks/runner.js +293 -0
  96. package/lib/hooks/shell-commands.d.ts +19 -0
  97. package/lib/hooks/shell-commands.js +177 -0
  98. package/lib/hooks/shell.d.ts +43 -0
  99. package/lib/hooks/shell.js +126 -0
  100. package/lib/hooks/transcript.d.ts +28 -0
  101. package/lib/hooks/transcript.js +141 -0
  102. package/lib/hooks/vocabulary.d.ts +57 -0
  103. package/lib/hooks/vocabulary.js +364 -0
  104. package/lib/index.d.ts +31 -0
  105. package/lib/index.js +287 -0
  106. package/lib/mcp/auth.d.ts +35 -0
  107. package/lib/mcp/auth.js +178 -0
  108. package/lib/mcp/catalog.d.ts +36 -0
  109. package/lib/mcp/catalog.js +61 -0
  110. package/lib/mcp/mount.d.ts +75 -0
  111. package/lib/mcp/mount.js +217 -0
  112. package/lib/mcp/remote.d.ts +45 -0
  113. package/lib/mcp/remote.js +143 -0
  114. package/lib/mcp/row.d.ts +9 -0
  115. package/lib/mcp/row.js +131 -0
  116. package/lib/mods/bundler.d.ts +38 -0
  117. package/lib/mods/bundler.js +157 -0
  118. package/lib/mods/chain.d.ts +103 -0
  119. package/lib/mods/chain.js +436 -0
  120. package/lib/mods/claude.d.ts +27 -0
  121. package/lib/mods/claude.js +56 -0
  122. package/lib/mods/engine.d.ts +160 -0
  123. package/lib/mods/engine.js +701 -0
  124. package/lib/mods/expect.d.ts +8 -0
  125. package/lib/mods/expect.js +248 -0
  126. package/lib/mods/host.d.ts +105 -0
  127. package/lib/mods/host.js +462 -0
  128. package/lib/mods/loader.d.ts +53 -0
  129. package/lib/mods/loader.js +227 -0
  130. package/lib/mods/ops.d.ts +13 -0
  131. package/lib/mods/ops.js +117 -0
  132. package/lib/mods/row.d.ts +9 -0
  133. package/lib/mods/row.js +77 -0
  134. package/lib/mods/runtime.d.ts +60 -0
  135. package/lib/mods/runtime.js +133 -0
  136. package/lib/mods/service/commands.d.ts +17 -0
  137. package/lib/mods/service/commands.js +121 -0
  138. package/lib/mods/service/drawings.d.ts +36 -0
  139. package/lib/mods/service/drawings.js +64 -0
  140. package/lib/mods/service/sessions.d.ts +63 -0
  141. package/lib/mods/service/sessions.js +345 -0
  142. package/lib/mods/service/tools.d.ts +32 -0
  143. package/lib/mods/service/tools.js +253 -0
  144. package/lib/mods/service/turns.d.ts +32 -0
  145. package/lib/mods/service/turns.js +161 -0
  146. package/lib/mods/service/types.d.ts +151 -0
  147. package/lib/mods/service/types.js +1 -0
  148. package/lib/mods/service.d.ts +72 -0
  149. package/lib/mods/service.js +104 -0
  150. package/lib/mods/surfaces.d.ts +93 -0
  151. package/lib/mods/surfaces.js +309 -0
  152. package/lib/mods/values.d.ts +30 -0
  153. package/lib/mods/values.js +95 -0
  154. package/lib/opencode/bun.d.ts +40 -0
  155. package/lib/opencode/bun.js +156 -0
  156. package/lib/opencode/convert.d.ts +53 -0
  157. package/lib/opencode/convert.js +255 -0
  158. package/lib/opencode/row.d.ts +9 -0
  159. package/lib/opencode/row.js +86 -0
  160. package/lib/opencode/runtime/core.d.ts +74 -0
  161. package/lib/opencode/runtime/core.js +249 -0
  162. package/lib/opencode/runtime/events.d.ts +80 -0
  163. package/lib/opencode/runtime/events.js +281 -0
  164. package/lib/opencode/runtime/mount.d.ts +27 -0
  165. package/lib/opencode/runtime/mount.js +283 -0
  166. package/lib/opencode/runtime/server.d.ts +27 -0
  167. package/lib/opencode/runtime/server.js +353 -0
  168. package/lib/opencode/runtime/types.d.ts +109 -0
  169. package/lib/opencode/runtime/types.js +1 -0
  170. package/lib/opencode/runtime.d.ts +55 -0
  171. package/lib/opencode/runtime.js +79 -0
  172. package/lib/porting/port-gap.d.ts +30 -0
  173. package/lib/porting/port-gap.js +122 -0
  174. package/lib/porting/port-sessions.d.ts +41 -0
  175. package/lib/porting/port-sessions.js +98 -0
  176. package/lib/porting/prompt.d.ts +23 -0
  177. package/lib/porting/prompt.js +49 -0
  178. package/lib/porting/row.d.ts +16 -0
  179. package/lib/porting/row.js +25 -0
  180. package/lib/porting/verify-port.d.ts +53 -0
  181. package/lib/porting/verify-port.js +104 -0
  182. package/lib/presets/fs-search.d.ts +25 -0
  183. package/lib/presets/fs-search.js +17 -0
  184. package/lib/presets/tool-filter.d.ts +35 -0
  185. package/lib/presets/tool-filter.js +91 -0
  186. package/lib/sessions/claude.d.ts +29 -0
  187. package/lib/sessions/claude.js +83 -0
  188. package/lib/sessions/codex.d.ts +30 -0
  189. package/lib/sessions/codex.js +303 -0
  190. package/lib/sessions/opencode.d.ts +32 -0
  191. package/lib/sessions/opencode.js +320 -0
  192. package/lib/sessions/row.d.ts +14 -0
  193. package/lib/sessions/row.js +35 -0
  194. package/lib/shared/invocation.d.ts +169 -0
  195. package/lib/shared/invocation.js +325 -0
  196. package/lib/shared/render.d.ts +72 -0
  197. package/lib/shared/render.js +588 -0
  198. package/lib/shared/util.d.ts +21 -0
  199. package/lib/shared/util.js +32 -0
  200. package/lib/skills/bundled.d.ts +3 -0
  201. package/lib/skills/bundled.js +42 -0
  202. package/lib/skills/provider.d.ts +72 -0
  203. package/lib/skills/provider.js +340 -0
  204. package/lib/skills/row.d.ts +22 -0
  205. package/lib/skills/row.js +204 -0
  206. package/lib/workbench/adapter-coverage.d.ts +47 -0
  207. package/lib/workbench/adapter-coverage.js +102 -0
  208. package/lib/workbench/model-tools.d.ts +10 -0
  209. package/lib/workbench/model-tools.js +122 -0
  210. package/lib/workbench/overview.d.ts +103 -0
  211. package/lib/workbench/overview.js +159 -0
  212. package/lib/workbench/remote.d.ts +118 -0
  213. package/lib/workbench/remote.js +422 -0
  214. package/lib/workbench/row.d.ts +15 -0
  215. package/lib/workbench/row.js +16 -0
  216. package/lib/workbench/settings.d.ts +15 -0
  217. package/lib/workbench/settings.js +56 -0
  218. package/lib/workbench/workbench.d.ts +100 -0
  219. package/lib/workbench/workbench.js +260 -0
  220. package/locale/agents/en.json +6 -0
  221. package/locale/agents/zh.json +6 -0
  222. package/locale/commands/en.json +6 -0
  223. package/locale/commands/zh.json +6 -0
  224. package/locale/context/en.json +6 -0
  225. package/locale/context/zh.json +6 -0
  226. package/locale/en.json +6 -0
  227. package/locale/hooks/en.json +6 -0
  228. package/locale/hooks/zh.json +6 -0
  229. package/locale/mcp/en.json +6 -0
  230. package/locale/mcp/zh.json +6 -0
  231. package/locale/mods/en.json +6 -0
  232. package/locale/mods/zh.json +6 -0
  233. package/locale/opencode/en.json +6 -0
  234. package/locale/opencode/zh.json +6 -0
  235. package/locale/porter/en.json +6 -0
  236. package/locale/porter/zh.json +6 -0
  237. package/locale/sessions/en.json +6 -0
  238. package/locale/sessions/zh.json +6 -0
  239. package/locale/skills/en.json +6 -0
  240. package/locale/skills/zh.json +6 -0
  241. package/locale/workbench/en.json +6 -0
  242. package/locale/workbench/zh.json +6 -0
  243. package/locale/zh.json +6 -0
  244. package/package.json +246 -3
  245. package/runtime/opencode-host.mjs +270 -0
  246. package/skills/harness-forge/SKILL.md +47 -0
@@ -0,0 +1,17 @@
1
+ import { ContextInstructions } from './instructions.js';
2
+ import { FORGE_SERVICE } from '../forge/service.js';
3
+ import { Parts, rowEffect } from '../forge/row.js';
4
+ export const name = 'harness-forge-context';
5
+ export const inject = [FORGE_SERVICE];
6
+ /** The context row. */
7
+ export function apply(ctx) {
8
+ rowEffect(ctx, 'context', forge => startContext(ctx, forge));
9
+ }
10
+ /** Start the context row on the shared service. Returns its teardown. */
11
+ export function startContext(ctx, forge) {
12
+ const instructions = new ContextInstructions(ctx, forge);
13
+ const parts = new Parts(ctx, forge, 'context');
14
+ parts.add('prompt section', () => instructions.install());
15
+ parts.add('api', () => forge.provide('context', instructions.api()));
16
+ return () => parts.dispose();
17
+ }
@@ -0,0 +1,30 @@
1
+ /**
2
+ * One interception point on DSH's slash-command execution.
3
+ *
4
+ * DSH's `commands` service has no hook around `execute` (DSH 0.2.2-rc.3 and
5
+ * 0.2.2-rc.5: it emits only `commands/change`), yet Harness Forge must act
6
+ * there twice: commands wait for Harness Forge's startup, and a Claude Code
7
+ * mod's `command.run` hooks see, answer or replace a typed command. So the
8
+ * service's `execute` is wrapped once, here, and every use adds an
9
+ * interceptor to one ordered chain; the wrapper goes when the last
10
+ * interceptor does. Interceptors added later run first (outermost).
11
+ *
12
+ * DSH has no such hook yet. When it has one,
13
+ * only this module changes.
14
+ * @module @kirkchinese/harness-forge
15
+ */
16
+ /** `commands.execute`'s arguments: the agent, the line, its attachments, the signal. */
17
+ export type ExecuteArgs = readonly unknown[];
18
+ /** One interceptor: call `next` to go on (with the same or changed arguments), or answer without it. */
19
+ export type CommandInterceptor = (args: ExecuteArgs, next: (args?: ExecuteArgs) => Promise<unknown>) => Promise<unknown>;
20
+ interface CommandsService {
21
+ execute(...args: unknown[]): Promise<unknown>;
22
+ }
23
+ /**
24
+ * Add an interceptor around the commands service's `execute`.
25
+ * @param commands - DSH's `commands` service.
26
+ * @param interceptor - the interceptor.
27
+ * @returns a function that removes it.
28
+ */
29
+ export declare function interceptCommands(commands: CommandsService, interceptor: CommandInterceptor): () => void;
30
+ export {};
@@ -0,0 +1,61 @@
1
+ /**
2
+ * One interception point on DSH's slash-command execution.
3
+ *
4
+ * DSH's `commands` service has no hook around `execute` (DSH 0.2.2-rc.3 and
5
+ * 0.2.2-rc.5: it emits only `commands/change`), yet Harness Forge must act
6
+ * there twice: commands wait for Harness Forge's startup, and a Claude Code
7
+ * mod's `command.run` hooks see, answer or replace a typed command. So the
8
+ * service's `execute` is wrapped once, here, and every use adds an
9
+ * interceptor to one ordered chain; the wrapper goes when the last
10
+ * interceptor does. Interceptors added later run first (outermost).
11
+ *
12
+ * DSH has no such hook yet. When it has one,
13
+ * only this module changes.
14
+ * @module @kirkchinese/harness-forge
15
+ */
16
+ const chains = new WeakMap();
17
+ /**
18
+ * Add an interceptor around the commands service's `execute`.
19
+ * @param commands - DSH's `commands` service.
20
+ * @param interceptor - the interceptor.
21
+ * @returns a function that removes it.
22
+ */
23
+ export function interceptCommands(commands, interceptor) {
24
+ let chain = chains.get(commands);
25
+ if (chain === undefined) {
26
+ const original = commands.execute;
27
+ const own = Object.prototype.hasOwnProperty.call(commands, 'execute');
28
+ const interceptors = [];
29
+ const wrapper = async (...args) => {
30
+ // The interceptors present when the call starts: one added or removed meanwhile does not shift this call.
31
+ const present = [...interceptors];
32
+ const run = async (index, current) => {
33
+ const next = present[index];
34
+ if (next === undefined)
35
+ return original.apply(commands, current);
36
+ return next(current, (changed) => run(index + 1, changed ?? current));
37
+ };
38
+ return run(0, args);
39
+ };
40
+ chain = { interceptors, original, wrapper, own };
41
+ chains.set(commands, chain);
42
+ Object.defineProperty(commands, 'execute', { value: wrapper, configurable: true, writable: true });
43
+ }
44
+ chain.interceptors.unshift(interceptor);
45
+ const owned = chain;
46
+ return () => {
47
+ const at = owned.interceptors.indexOf(interceptor);
48
+ if (at >= 0)
49
+ owned.interceptors.splice(at, 1);
50
+ if (owned.interceptors.length > 0 || chains.get(commands) !== owned)
51
+ return;
52
+ chains.delete(commands);
53
+ // Back to what DSH had, unless something else replaced the wrapper meanwhile.
54
+ if (commands.execute !== owned.wrapper)
55
+ return;
56
+ if (owned.own)
57
+ Object.defineProperty(commands, 'execute', { value: owned.original, configurable: true, writable: true });
58
+ else
59
+ delete commands.execute;
60
+ };
61
+ }
@@ -0,0 +1,107 @@
1
+ /**
2
+ * The DSH services and events Harness Forge uses, in one place.
3
+ *
4
+ * Every service and event below is declared by a DSH package (its Cordis
5
+ * `Context` or `Events` augmentation), so it is DSH's plugin surface rather
6
+ * than an internal; but DSH is pre-1.0 and changes it between releases, and
7
+ * Harness Forge does not import those packages' types (most are not its
8
+ * dependencies). So the names are listed here with the package that declares
9
+ * them, the only place that reaches them untyped: an upgrade of DSH is checked
10
+ * against this list. Checked against DSH 0.2.2-rc.3 and 0.2.2-rc.5.
11
+ *
12
+ * What is not DSH's surface at all lives beside this module: the command
13
+ * interception (`commands.ts`).
14
+ * @module @kirkchinese/harness-forge
15
+ */
16
+ /** Services read with `ctx.get`, by the DSH package that provides them. */
17
+ export declare const DSH_SERVICES: {
18
+ readonly agentDefaultModel: "@deepseek-ai/dsh-agent-default-model";
19
+ readonly agentPresets: "@deepseek-ai/dsh-agent-preset-registry";
20
+ readonly agents: "@deepseek-ai/dsh-agent";
21
+ readonly approval: "@deepseek-ai/dsh-user-approval";
22
+ readonly capabilityCatalog: "@kirkchinese/dsh-capability-catalog";
23
+ readonly capabilityCatalogServers: "@kirkchinese/dsh-capability-catalog";
24
+ readonly commands: "@deepseek-ai/dsh-commands";
25
+ readonly deepseekAccount: "@deepseek-ai/dsh-deepseek-account";
26
+ readonly llm: "@deepseek-ai/dsh-llm";
27
+ readonly permissionPresets: "@deepseek-ai/dsh-permission-presets";
28
+ readonly planMode: "@deepseek-ai/dsh-plan-mode";
29
+ readonly pluginManager: "@deepseek-ai/dsh-plugin-manager";
30
+ readonly profileContext: "@deepseek-ai/dsh-app-boot";
31
+ readonly recollect: "@kirkchinese/dsh-recollect";
32
+ readonly sessionController: "@deepseek-ai/dsh-api-session-controller";
33
+ readonly sessionPersistence: "@deepseek-ai/dsh-session-persistence";
34
+ readonly sessionTitle: "@deepseek-ai/dsh-session-title";
35
+ readonly shell: "@deepseek-ai/dsh-shell";
36
+ readonly skills: "@deepseek-ai/dsh-skill";
37
+ readonly subagents: "@deepseek-ai/dsh-subagent";
38
+ readonly systemPrompt: "@deepseek-ai/dsh-system-prompt";
39
+ readonly tokenMeter: "@deepseek-ai/dsh-token-meter";
40
+ readonly tools: "@deepseek-ai/dsh-tools";
41
+ readonly userQuestions: "@deepseek-ai/dsh-user-questions";
42
+ readonly webServer: "@deepseek-ai/dsh-host-webserver";
43
+ readonly workingDirectory: "@deepseek-ai/dsh-working-directory";
44
+ };
45
+ /** Events listened to with `ctx.on`, by the DSH package that declares them. */
46
+ export declare const DSH_EVENTS: {
47
+ readonly 'agent/created': "@deepseek-ai/dsh-agent";
48
+ readonly 'agent/disposed': "@deepseek-ai/dsh-agent";
49
+ readonly 'agent/pre-step': "@deepseek-ai/dsh-agent";
50
+ readonly 'agent/request': "@deepseek-ai/dsh-agent";
51
+ readonly 'agent/turn-stopping': "@deepseek-ai/dsh-agent";
52
+ readonly 'approval/request': "@deepseek-ai/dsh-user-approval";
53
+ readonly 'session/event': "@deepseek-ai/dsh-session";
54
+ readonly 'subagent/end': "@deepseek-ai/dsh-subagent";
55
+ readonly 'subagent/start': "@deepseek-ai/dsh-subagent";
56
+ readonly 'system-prompt/assemble': "@deepseek-ai/dsh-system-prompt";
57
+ readonly 'tools/change': "@deepseek-ai/dsh-tools";
58
+ readonly 'tools/execute': "@deepseek-ai/dsh-tools";
59
+ readonly 'tools/post-execute': "@deepseek-ai/dsh-tools";
60
+ readonly 'tools/pre-execute': "@deepseek-ai/dsh-tools";
61
+ readonly 'tools/result': "@deepseek-ai/dsh-tools";
62
+ readonly 'user-questions/request': "@deepseek-ai/dsh-user-questions";
63
+ };
64
+ export type DshService = keyof typeof DSH_SERVICES;
65
+ export type DshEvent = keyof typeof DSH_EVENTS;
66
+ /**
67
+ * A DSH service, or undefined when the profile does not compose it; the caller states the shape it relies on.
68
+ * @param ctx - a Cordis context: the plugin's, or an agent's (`agent.ctx`, where agent-scoped services live).
69
+ */
70
+ export declare function dshService(ctx: object | undefined, name: DshService): unknown;
71
+ /** How a listener is added; its failure is logged and handed to the context's fault sink (`reportFaults`). */
72
+ export interface ListenOptions {
73
+ readonly prepend?: boolean;
74
+ /** Names the part of Harness Forge the listener belongs to, in the log. */
75
+ readonly owner?: string;
76
+ }
77
+ /**
78
+ * Listen to a DSH event; returns the disposer (for `ctx.effect`).
79
+ *
80
+ * The listener is isolated: when it throws, the failure is logged and the event goes on as if the listener had
81
+ * not been there. A waterfall listener's `next` (its last argument) is called then, unless the listener already
82
+ * called it, whose result stands; so one failing part of Harness Forge never fails a tool call, a step or a prompt
83
+ * of DSH or of the other parts. A cancellation (`AbortError`) still propagates.
84
+ */
85
+ export declare function onDsh(ctx: object, name: DshEvent, listener: (...args: never[]) => unknown, options?: ListenOptions): () => void;
86
+ /** Report the failures of every listener `onDsh` adds on `ctx` to `fault`. Returns the disposer. */
87
+ export declare function reportFaults(ctx: object, fault: (error: unknown, event: DshEvent) => void): () => void;
88
+ /**
89
+ * Whether DSH is tearing down the tree this plugin runs in (exiting), as opposed to this plugin alone being
90
+ * unloaded or reloaded (an upgrade, a config change) while DSH and its sessions go on: a fiber above the plugin's
91
+ * own is unloading. DSH has no public "exiting" signal (0.2.2-rc.3: `app-boot` emits only `config-reload`), so the
92
+ * fiber states of Cordis 4 tell.
93
+ */
94
+ export declare function hostShuttingDown(ctx: object): boolean;
95
+ /** A session's working directory, as hooks and commands see it (`workingDirectory`, else the process's). */
96
+ export declare function sessionDirectory(ctx: object, agent: unknown, signal: AbortSignal): Promise<string>;
97
+ /** The agent preset a session runs under (`agentPresets.presetForSession`). */
98
+ export declare function presetOfSession(ctx: object, session: unknown): string | undefined;
99
+ /** The last turn of a session (`agents.turnBoundaryOf`), or undefined. */
100
+ export declare function lastTurnOf(ctx: object, session: unknown): number | undefined;
101
+ /** A session's context pressure (`tokenMeter.contextPressure`), or undefined. */
102
+ export declare function contextPressureOf(ctx: object, session: unknown): {
103
+ readonly pressureTokens?: number;
104
+ readonly contextWindow?: number;
105
+ } | undefined;
106
+ /** Whether an agent's session is in plan mode (`planMode.get`). */
107
+ export declare function planModeActive(ctx: object, agent: unknown): boolean;
@@ -0,0 +1,214 @@
1
+ /**
2
+ * The DSH services and events Harness Forge uses, in one place.
3
+ *
4
+ * Every service and event below is declared by a DSH package (its Cordis
5
+ * `Context` or `Events` augmentation), so it is DSH's plugin surface rather
6
+ * than an internal; but DSH is pre-1.0 and changes it between releases, and
7
+ * Harness Forge does not import those packages' types (most are not its
8
+ * dependencies). So the names are listed here with the package that declares
9
+ * them, the only place that reaches them untyped: an upgrade of DSH is checked
10
+ * against this list. Checked against DSH 0.2.2-rc.3 and 0.2.2-rc.5.
11
+ *
12
+ * What is not DSH's surface at all lives beside this module: the command
13
+ * interception (`commands.ts`).
14
+ * @module @kirkchinese/harness-forge
15
+ */
16
+ /** Services read with `ctx.get`, by the DSH package that provides them. */
17
+ export const DSH_SERVICES = {
18
+ agentDefaultModel: '@deepseek-ai/dsh-agent-default-model',
19
+ agentPresets: '@deepseek-ai/dsh-agent-preset-registry',
20
+ agents: '@deepseek-ai/dsh-agent',
21
+ approval: '@deepseek-ai/dsh-user-approval',
22
+ capabilityCatalog: '@kirkchinese/dsh-capability-catalog',
23
+ capabilityCatalogServers: '@kirkchinese/dsh-capability-catalog',
24
+ commands: '@deepseek-ai/dsh-commands',
25
+ deepseekAccount: '@deepseek-ai/dsh-deepseek-account',
26
+ llm: '@deepseek-ai/dsh-llm',
27
+ permissionPresets: '@deepseek-ai/dsh-permission-presets',
28
+ planMode: '@deepseek-ai/dsh-plan-mode',
29
+ pluginManager: '@deepseek-ai/dsh-plugin-manager',
30
+ profileContext: '@deepseek-ai/dsh-app-boot',
31
+ recollect: '@kirkchinese/dsh-recollect',
32
+ sessionController: '@deepseek-ai/dsh-api-session-controller',
33
+ sessionPersistence: '@deepseek-ai/dsh-session-persistence',
34
+ sessionTitle: '@deepseek-ai/dsh-session-title',
35
+ shell: '@deepseek-ai/dsh-shell',
36
+ skills: '@deepseek-ai/dsh-skill',
37
+ subagents: '@deepseek-ai/dsh-subagent',
38
+ systemPrompt: '@deepseek-ai/dsh-system-prompt',
39
+ tokenMeter: '@deepseek-ai/dsh-token-meter',
40
+ tools: '@deepseek-ai/dsh-tools',
41
+ userQuestions: '@deepseek-ai/dsh-user-questions',
42
+ webServer: '@deepseek-ai/dsh-host-webserver',
43
+ workingDirectory: '@deepseek-ai/dsh-working-directory',
44
+ };
45
+ /** Events listened to with `ctx.on`, by the DSH package that declares them. */
46
+ export const DSH_EVENTS = {
47
+ 'agent/created': '@deepseek-ai/dsh-agent',
48
+ 'agent/disposed': '@deepseek-ai/dsh-agent',
49
+ 'agent/pre-step': '@deepseek-ai/dsh-agent',
50
+ 'agent/request': '@deepseek-ai/dsh-agent',
51
+ 'agent/turn-stopping': '@deepseek-ai/dsh-agent',
52
+ 'approval/request': '@deepseek-ai/dsh-user-approval',
53
+ 'session/event': '@deepseek-ai/dsh-session',
54
+ 'subagent/end': '@deepseek-ai/dsh-subagent',
55
+ 'subagent/start': '@deepseek-ai/dsh-subagent',
56
+ 'system-prompt/assemble': '@deepseek-ai/dsh-system-prompt',
57
+ 'tools/change': '@deepseek-ai/dsh-tools',
58
+ 'tools/execute': '@deepseek-ai/dsh-tools',
59
+ 'tools/post-execute': '@deepseek-ai/dsh-tools',
60
+ 'tools/pre-execute': '@deepseek-ai/dsh-tools',
61
+ 'tools/result': '@deepseek-ai/dsh-tools',
62
+ 'user-questions/request': '@deepseek-ai/dsh-user-questions',
63
+ };
64
+ /**
65
+ * A DSH service, or undefined when the profile does not compose it; the caller states the shape it relies on.
66
+ * @param ctx - a Cordis context: the plugin's, or an agent's (`agent.ctx`, where agent-scoped services live).
67
+ */
68
+ export function dshService(ctx, name) {
69
+ return ctx?.get?.(name);
70
+ }
71
+ /**
72
+ * Listen to a DSH event; returns the disposer (for `ctx.effect`).
73
+ *
74
+ * The listener is isolated: when it throws, the failure is logged and the event goes on as if the listener had
75
+ * not been there. A waterfall listener's `next` (its last argument) is called then, unless the listener already
76
+ * called it, whose result stands; so one failing part of Harness Forge never fails a tool call, a step or a prompt
77
+ * of DSH or of the other parts. A cancellation (`AbortError`) still propagates.
78
+ */
79
+ export function onDsh(ctx, name, listener, options = {}) {
80
+ const report = (error) => {
81
+ try {
82
+ const logger = ctx.logger;
83
+ logger?.warn?.(`harness-forge${options.owner !== undefined ? `/${options.owner}` : ''}: ${name} listener failed: ${error instanceof Error ? error.message : String(error)}`);
84
+ faultSinks.get(ctx)?.(error, name);
85
+ }
86
+ catch {
87
+ // Reporting never fails the event.
88
+ }
89
+ };
90
+ const guarded = (...args) => {
91
+ const last = args.at(-1);
92
+ let forwarded;
93
+ // What the rest of the chain threw is not this listener's failure: it propagates as it would have.
94
+ let downstream;
95
+ const next = typeof last === 'function'
96
+ ? (...nextArgs) => {
97
+ if (forwarded === undefined) {
98
+ try {
99
+ forwarded = { result: last(...nextArgs) };
100
+ }
101
+ catch (error) {
102
+ downstream = { error };
103
+ throw error;
104
+ }
105
+ if (forwarded.result instanceof Promise)
106
+ forwarded.result.then(undefined, (error) => { downstream = { error }; });
107
+ }
108
+ return forwarded.result;
109
+ }
110
+ : undefined;
111
+ const recover = (error) => {
112
+ if (isAbort(error) || (downstream !== undefined && downstream.error === error))
113
+ throw error;
114
+ report(error);
115
+ if (next === undefined)
116
+ return undefined;
117
+ return forwarded !== undefined ? forwarded.result : next();
118
+ };
119
+ try {
120
+ const result = listener(...(next === undefined ? args : [...args.slice(0, -1), next]));
121
+ return result instanceof Promise ? result.catch(recover) : result;
122
+ }
123
+ catch (error) {
124
+ return recover(error);
125
+ }
126
+ };
127
+ return ctx.on(name, guarded, options.prepend === undefined ? undefined : { prepend: options.prepend });
128
+ }
129
+ /** Where the listeners of one context report their failures, besides the log: the row's fault record. */
130
+ const faultSinks = new WeakMap();
131
+ /** Report the failures of every listener `onDsh` adds on `ctx` to `fault`. Returns the disposer. */
132
+ export function reportFaults(ctx, fault) {
133
+ faultSinks.set(ctx, fault);
134
+ return () => { if (faultSinks.get(ctx) === fault)
135
+ faultSinks.delete(ctx); };
136
+ }
137
+ function isAbort(error) {
138
+ return error instanceof Error && error.name === 'AbortError';
139
+ }
140
+ /** Cordis fiber states that mean a fiber is going away; the types check the numbers against Cordis's own enum. */
141
+ const DISPOSED = 4;
142
+ const UNLOADING = 5;
143
+ const LEAVING = new Set([DISPOSED, UNLOADING]);
144
+ /**
145
+ * Whether DSH is tearing down the tree this plugin runs in (exiting), as opposed to this plugin alone being
146
+ * unloaded or reloaded (an upgrade, a config change) while DSH and its sessions go on: a fiber above the plugin's
147
+ * own is unloading. DSH has no public "exiting" signal (0.2.2-rc.3: `app-boot` emits only `config-reload`), so the
148
+ * fiber states of Cordis 4 tell.
149
+ */
150
+ export function hostShuttingDown(ctx) {
151
+ const own = ctx.fiber;
152
+ let fiber = own?.parent?.fiber;
153
+ for (let depth = 0; fiber !== undefined && fiber !== own && depth < 64; depth++) {
154
+ if (fiber.state !== undefined && LEAVING.has(fiber.state))
155
+ return true;
156
+ const parent = fiber.parent?.fiber;
157
+ if (parent === fiber)
158
+ break;
159
+ fiber = parent;
160
+ }
161
+ return false;
162
+ }
163
+ /** A session's working directory, as hooks and commands see it (`workingDirectory`, else the process's). */
164
+ export async function sessionDirectory(ctx, agent, signal) {
165
+ const service = dshService(ctx, 'workingDirectory');
166
+ if (service === undefined || agent === undefined)
167
+ return process.cwd();
168
+ try {
169
+ return await service.ensure(agent, signal);
170
+ }
171
+ catch {
172
+ return service.get(agent.session) ?? process.cwd();
173
+ }
174
+ }
175
+ /** The agent preset a session runs under (`agentPresets.presetForSession`). */
176
+ export function presetOfSession(ctx, session) {
177
+ const presets = dshService(ctx, 'agentPresets');
178
+ try {
179
+ return presets?.presetForSession?.(session) ?? undefined;
180
+ }
181
+ catch {
182
+ return undefined;
183
+ }
184
+ }
185
+ /** The last turn of a session (`agents.turnBoundaryOf`), or undefined. */
186
+ export function lastTurnOf(ctx, session) {
187
+ const agents = dshService(ctx, 'agents');
188
+ try {
189
+ return agents?.turnBoundaryOf?.(session).lastTurn;
190
+ }
191
+ catch {
192
+ return undefined;
193
+ }
194
+ }
195
+ /** A session's context pressure (`tokenMeter.contextPressure`), or undefined. */
196
+ export function contextPressureOf(ctx, session) {
197
+ const meter = dshService(ctx, 'tokenMeter');
198
+ try {
199
+ return meter?.contextPressure?.(session);
200
+ }
201
+ catch {
202
+ return undefined;
203
+ }
204
+ }
205
+ /** Whether an agent's session is in plan mode (`planMode.get`). */
206
+ export function planModeActive(ctx, agent) {
207
+ const planMode = dshService(ctx, 'planMode');
208
+ try {
209
+ return planMode?.get?.(agent).active === true;
210
+ }
211
+ catch {
212
+ return false;
213
+ }
214
+ }
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Running an agent's steps on another model route (a Claude `model:` or
3
+ * `effort:` in an agent's or a skill's frontmatter): DSH fixes a request's
4
+ * provider, model and reasoning effort before `agent/request`, so the route is
5
+ * selected on the agent (`agent.model.select`) for its next steps.
6
+ * Checked against DSH 0.2.2-rc.3 and 0.2.2-rc.5.
7
+ * @module @kirkchinese/harness-forge
8
+ */
9
+ /** A route override: what differs from the agent's current route. */
10
+ export interface RouteOverride {
11
+ readonly provider?: string;
12
+ readonly model?: string;
13
+ readonly reasoningEffort?: string;
14
+ }
15
+ /**
16
+ * Select the route for the agent's next steps. Returns how to put the previous selection back, or undefined where
17
+ * the agent has no current route.
18
+ */
19
+ export declare function selectRoute(agent: unknown, route: RouteOverride): {
20
+ restore(): void;
21
+ } | undefined;
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Running an agent's steps on another model route (a Claude `model:` or
3
+ * `effort:` in an agent's or a skill's frontmatter): DSH fixes a request's
4
+ * provider, model and reasoning effort before `agent/request`, so the route is
5
+ * selected on the agent (`agent.model.select`) for its next steps.
6
+ * Checked against DSH 0.2.2-rc.3 and 0.2.2-rc.5.
7
+ * @module @kirkchinese/harness-forge
8
+ */
9
+ function modelOf(agent) {
10
+ const model = agent?.model;
11
+ return typeof model?.select === 'function' && typeof model.current === 'function' ? model : undefined;
12
+ }
13
+ /** The route with an override applied: a model of its own does not inherit the old effort. */
14
+ function overridden(base, route) {
15
+ const { reasoningEffort: _inherited, ...rest } = base;
16
+ return {
17
+ ...(route.reasoningEffort !== undefined || route.model !== undefined ? rest : base),
18
+ ...(route.provider !== undefined ? { provider: route.provider } : {}),
19
+ ...(route.model !== undefined ? { model: route.model } : {}),
20
+ ...(route.reasoningEffort !== undefined ? { reasoningEffort: route.reasoningEffort } : {}),
21
+ };
22
+ }
23
+ /**
24
+ * Select the route for the agent's next steps. Returns how to put the previous selection back, or undefined where
25
+ * the agent has no current route.
26
+ */
27
+ export function selectRoute(agent, route) {
28
+ const model = modelOf(agent);
29
+ const current = model?.current();
30
+ if (model === undefined || current === undefined)
31
+ return undefined;
32
+ const next = overridden({ ...current }, route);
33
+ if (next.provider === current.provider && next.model === current.model && next.reasoningEffort === current.reasoningEffort)
34
+ return { restore: () => { } };
35
+ model.select(next);
36
+ return { restore: () => { model.select(current); } };
37
+ }
@@ -0,0 +1,78 @@
1
+ /**
2
+ * Harness Forge's records in a DSH session log, in one place.
3
+ *
4
+ * DSH stores a plugin's own facts in the session log as plugin records
5
+ * (`appendPluginRecord`, `@deepseek-ai/dsh-session`; typed by augmenting its
6
+ * `PluginRecordMap`), and hook runs as `hook/invoked` / `hook/result` events
7
+ * (`@deepseek-ai/dsh-hook-protocol`, the same records DSH's own hook bridges
8
+ * write, so DSH's session views show imported hooks like its own). Both are
9
+ * pre-1.0 DSH API: every record Harness Forge writes is declared and written
10
+ * here, the only module that names these functions.
11
+ * Checked against DSH 0.2.2-rc.3 and 0.2.2-rc.5.
12
+ * @module @kirkchinese/harness-forge
13
+ */
14
+ import type { appendHookInvoked, appendHookResult } from '@deepseek-ai/dsh-hook-protocol';
15
+ import type { ComponentOutcome } from '@kirkchinese/harness-forge-core';
16
+ /** What one hook handler answered. */
17
+ export interface HookOutputRecord {
18
+ readonly handlerId: string;
19
+ readonly event: string;
20
+ readonly callId?: string;
21
+ readonly block?: string;
22
+ readonly json?: Readonly<Record<string, unknown>>;
23
+ readonly plain?: string;
24
+ }
25
+ /** One user-facing hook message. */
26
+ export interface HookNotice {
27
+ /** `system-message`, `hook-error`, `blocked`, `stopped`, `terminal`, `feedback`. */
28
+ readonly kind: 'system-message' | 'hook-error' | 'blocked' | 'stopped' | 'terminal' | 'feedback';
29
+ /** The hook event, such as `PreToolUse`. */
30
+ readonly event: string;
31
+ /** What the event matched on, such as the tool name. */
32
+ readonly subject?: string;
33
+ /** Plugin id of the hook's source. */
34
+ readonly plugin: string;
35
+ readonly text: string;
36
+ }
37
+ /** A mod's hook ran for an event in a session: the lab's and the workbench's evidence. */
38
+ export interface ModEventRecord {
39
+ readonly mod: string;
40
+ readonly event: string;
41
+ }
42
+ /** What a session records about the project assets it loaded. */
43
+ export interface ProjectRecord {
44
+ readonly root: string;
45
+ readonly pluginId: string;
46
+ readonly components: ReadonlyArray<{
47
+ readonly id: string;
48
+ readonly kind: string;
49
+ readonly name: string;
50
+ }>;
51
+ readonly outcomes: readonly ComponentOutcome[];
52
+ }
53
+ /** Every plugin record Harness Forge writes, by record type. */
54
+ export interface HarnessRecords {
55
+ /** A hook's message for the user (Claude Code's `systemMessage`, a blocked call, a failed handler). */
56
+ 'plugin:harness-forge/notice': HookNotice;
57
+ /** What one hook handler answered (its block, JSON or plain output), keyed by its `hook/invoked` id. */
58
+ 'plugin:harness-forge/hook-output': HookOutputRecord;
59
+ /** A Claude Code mod event that ran in the session. */
60
+ 'plugin:harness-forge/mod-event': ModEventRecord;
61
+ /** The project assets (CLAUDE.md, settings, hooks…) a session loaded. */
62
+ 'plugin:harness-forge/project': ProjectRecord;
63
+ }
64
+ declare module '@deepseek-ai/dsh-session/types' {
65
+ interface PluginRecordMap extends HarnessRecords {
66
+ }
67
+ }
68
+ /** Append one of Harness Forge's records to a session's log. Throws when the session no longer accepts records. */
69
+ export declare function appendRecord<K extends keyof HarnessRecords>(session: unknown, type: K, data: HarnessRecords[K]): void;
70
+ /**
71
+ * Record that a hook handler starts (DSH's `hook/invoked`), as `appendHookInvoked` of
72
+ * `@deepseek-ai/dsh-hook-protocol` writes it. Written here rather than imported: that package requires
73
+ * `dsh-session` and `dsh-shell` of its own exact release as peers, which a profile install would put beside
74
+ * DSH's own and so break a DSH of another release.
75
+ */
76
+ export declare function recordHookInvoked(session: unknown, invocation: Parameters<typeof appendHookInvoked>[1]): void;
77
+ /** Record a hook handler's result (DSH's `hook/result`), as `appendHookResult` writes it. */
78
+ export declare function recordHookResult(session: unknown, record: Parameters<typeof appendHookResult>[1]): void;
@@ -0,0 +1,36 @@
1
+ import { appendPluginRecord } from '@deepseek-ai/dsh-session';
2
+ /** Append one of Harness Forge's records to a session's log. Throws when the session no longer accepts records. */
3
+ export function appendRecord(session, type, data) {
4
+ appendPluginRecord(session, type, data);
5
+ }
6
+ /**
7
+ * Record that a hook handler starts (DSH's `hook/invoked`), as `appendHookInvoked` of
8
+ * `@deepseek-ai/dsh-hook-protocol` writes it. Written here rather than imported: that package requires
9
+ * `dsh-session` and `dsh-shell` of its own exact release as peers, which a profile install would put beside
10
+ * DSH's own and so break a DSH of another release.
11
+ */
12
+ export function recordHookInvoked(session, invocation) {
13
+ ;
14
+ session.append('hook/invoked', {
15
+ turn: invocation.turn,
16
+ point: invocation.point,
17
+ dialect: invocation.dialect,
18
+ handlerId: invocation.handlerId,
19
+ ...(invocation.matcher !== undefined ? { matcher: invocation.matcher } : {}),
20
+ });
21
+ }
22
+ /** Record a hook handler's result (DSH's `hook/result`), as `appendHookResult` writes it. */
23
+ export function recordHookResult(session, record) {
24
+ const { output } = record;
25
+ const stderr = output.stderr.trim();
26
+ const stderrSummary = stderr.length === 0 ? undefined : stderr.length > record.stderrSummaryMaxChars ? `${stderr.slice(0, record.stderrSummaryMaxChars)}…` : stderr;
27
+ session.append('hook/result', {
28
+ turn: record.turn,
29
+ point: record.point,
30
+ handlerId: record.handlerId,
31
+ decision: output.decision ?? (output.continue === false ? 'stop' : 'pass'),
32
+ ...(output.exitCode !== undefined ? { exitCode: output.exitCode } : {}),
33
+ ...(stderrSummary !== undefined ? { stderrSummary } : {}),
34
+ durationMs: record.durationMs,
35
+ });
36
+ }
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Starting a delegated agent through DSH's `subagents` service: the
3
+ * activation spec takes the task fields at the top level
4
+ * (`SubagentActivationSpec extends SubagentStartRequest`).
5
+ * Checked against DSH 0.2.2-rc.3 and 0.2.2-rc.5.
6
+ * @module @kirkchinese/harness-forge
7
+ */
8
+ /** What a delegated agent runs with. */
9
+ export interface ActivationTask {
10
+ /** The spawning agent. */
11
+ readonly parent: unknown;
12
+ readonly prompt: ReadonlyArray<Record<string, unknown>>;
13
+ readonly agentPreset?: string;
14
+ readonly outputSchema?: Record<string, unknown>;
15
+ /** The child's provider, model and effort, over the parent's. */
16
+ readonly agentOptions?: {
17
+ readonly provider?: string;
18
+ readonly model?: string;
19
+ readonly reasoningEffort?: string;
20
+ };
21
+ }
22
+ /** How the activation is managed. */
23
+ export interface ActivationOptions {
24
+ readonly provider: string;
25
+ readonly label: string;
26
+ readonly signal: AbortSignal;
27
+ readonly delivery: 'parent' | 'caller';
28
+ }
29
+ /** A started activation, as far as Harness Forge reads it. */
30
+ export interface Activation {
31
+ readonly childId?: string;
32
+ readonly result: Promise<{
33
+ readonly structured?: unknown;
34
+ readonly output?: ReadonlyArray<{
35
+ readonly type: string;
36
+ readonly text?: string;
37
+ }>;
38
+ readonly stopReason?: string;
39
+ }>;
40
+ dispose(): Promise<void>;
41
+ }
42
+ /**
43
+ * Start a delegated agent.
44
+ * @param subagents - DSH's `subagents` service.
45
+ */
46
+ export declare function startActivation(subagents: unknown, task: ActivationTask, options: ActivationOptions): Promise<Activation>;