@kirkchinese/harness-forge 0.0.0-stage → 0.5.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 (279) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +46 -2
  3. package/assets/icon.svg +12 -0
  4. package/cordis.patch.yml +28 -0
  5. package/docs/DETAIL.zh.md +47 -0
  6. package/lib/agents/presets.d.ts +98 -0
  7. package/lib/agents/presets.js +292 -0
  8. package/lib/agents/profiles.d.ts +58 -0
  9. package/lib/agents/profiles.js +279 -0
  10. package/lib/agents/row.d.ts +17 -0
  11. package/lib/agents/row.js +148 -0
  12. package/lib/client/paths.d.ts +12 -0
  13. package/lib/client/paths.js +68 -0
  14. package/lib/client/styles.d.ts +8 -0
  15. package/lib/client/styles.js +89 -0
  16. package/lib/client/typert.d.ts +25 -0
  17. package/lib/client/typert.js +158 -0
  18. package/lib/client.js +23823 -0
  19. package/lib/commands/definition.d.ts +40 -0
  20. package/lib/commands/definition.js +113 -0
  21. package/lib/commands/output-styles.d.ts +42 -0
  22. package/lib/commands/output-styles.js +152 -0
  23. package/lib/commands/row.d.ts +9 -0
  24. package/lib/commands/row.js +157 -0
  25. package/lib/context/instructions.d.ts +32 -0
  26. package/lib/context/instructions.js +88 -0
  27. package/lib/context/row.d.ts +16 -0
  28. package/lib/context/row.js +17 -0
  29. package/lib/dsh/commands.d.ts +30 -0
  30. package/lib/dsh/commands.js +61 -0
  31. package/lib/dsh/host.d.ts +110 -0
  32. package/lib/dsh/host.js +217 -0
  33. package/lib/dsh/model-route.d.ts +21 -0
  34. package/lib/dsh/model-route.js +37 -0
  35. package/lib/dsh/session-records.d.ts +78 -0
  36. package/lib/dsh/session-records.js +36 -0
  37. package/lib/dsh/subagents.d.ts +46 -0
  38. package/lib/dsh/subagents.js +14 -0
  39. package/lib/forge/contract.d.ts +271 -0
  40. package/lib/forge/contract.js +45 -0
  41. package/lib/forge/follow.d.ts +30 -0
  42. package/lib/forge/follow.js +73 -0
  43. package/lib/forge/ledger.d.ts +206 -0
  44. package/lib/forge/ledger.js +1005 -0
  45. package/lib/forge/live-mounts.d.ts +45 -0
  46. package/lib/forge/live-mounts.js +78 -0
  47. package/lib/forge/npm.d.ts +31 -0
  48. package/lib/forge/npm.js +60 -0
  49. package/lib/forge/projects.d.ts +97 -0
  50. package/lib/forge/projects.js +343 -0
  51. package/lib/forge/receipts.d.ts +5 -0
  52. package/lib/forge/receipts.js +31 -0
  53. package/lib/forge/remote/archive.d.ts +65 -0
  54. package/lib/forge/remote/archive.js +565 -0
  55. package/lib/forge/remote/code-parts.d.ts +18 -0
  56. package/lib/forge/remote/code-parts.js +76 -0
  57. package/lib/forge/remote/fetch.d.ts +265 -0
  58. package/lib/forge/remote/fetch.js +1133 -0
  59. package/lib/forge/remote/service.d.ts +256 -0
  60. package/lib/forge/remote/service.js +868 -0
  61. package/lib/forge/row.d.ts +32 -0
  62. package/lib/forge/row.js +59 -0
  63. package/lib/forge/service.d.ts +115 -0
  64. package/lib/forge/service.js +290 -0
  65. package/lib/forge/settings.d.ts +43 -0
  66. package/lib/forge/settings.js +122 -0
  67. package/lib/forge/state.d.ts +129 -0
  68. package/lib/forge/state.js +266 -0
  69. package/lib/forge/trust.d.ts +48 -0
  70. package/lib/forge/trust.js +107 -0
  71. package/lib/forge/turns.d.ts +13 -0
  72. package/lib/forge/turns.js +56 -0
  73. package/lib/hooks/broker/engine.d.ts +112 -0
  74. package/lib/hooks/broker/engine.js +722 -0
  75. package/lib/hooks/broker/helpers.d.ts +10 -0
  76. package/lib/hooks/broker/helpers.js +22 -0
  77. package/lib/hooks/broker/lifecycle.d.ts +65 -0
  78. package/lib/hooks/broker/lifecycle.js +342 -0
  79. package/lib/hooks/broker/session-events.d.ts +27 -0
  80. package/lib/hooks/broker/session-events.js +205 -0
  81. package/lib/hooks/broker/tools.d.ts +52 -0
  82. package/lib/hooks/broker/tools.js +424 -0
  83. package/lib/hooks/broker/types.d.ts +264 -0
  84. package/lib/hooks/broker/types.js +1 -0
  85. package/lib/hooks/broker.d.ts +80 -0
  86. package/lib/hooks/broker.js +95 -0
  87. package/lib/hooks/codex-user.d.ts +5 -0
  88. package/lib/hooks/codex-user.js +109 -0
  89. package/lib/hooks/condition.d.ts +87 -0
  90. package/lib/hooks/condition.js +602 -0
  91. package/lib/hooks/config.d.ts +85 -0
  92. package/lib/hooks/config.js +154 -0
  93. package/lib/hooks/glob.d.ts +41 -0
  94. package/lib/hooks/glob.js +114 -0
  95. package/lib/hooks/matcher.d.ts +20 -0
  96. package/lib/hooks/matcher.js +39 -0
  97. package/lib/hooks/notice.d.ts +17 -0
  98. package/lib/hooks/notice.js +39 -0
  99. package/lib/hooks/output.d.ts +56 -0
  100. package/lib/hooks/output.js +214 -0
  101. package/lib/hooks/permissions.d.ts +19 -0
  102. package/lib/hooks/permissions.js +202 -0
  103. package/lib/hooks/powershell-aliases.d.ts +19 -0
  104. package/lib/hooks/powershell-aliases.js +58 -0
  105. package/lib/hooks/process.d.ts +64 -0
  106. package/lib/hooks/process.js +289 -0
  107. package/lib/hooks/row.d.ts +17 -0
  108. package/lib/hooks/row.js +96 -0
  109. package/lib/hooks/runner.d.ts +98 -0
  110. package/lib/hooks/runner.js +322 -0
  111. package/lib/hooks/shell-commands.d.ts +28 -0
  112. package/lib/hooks/shell-commands.js +241 -0
  113. package/lib/hooks/shell.d.ts +44 -0
  114. package/lib/hooks/shell.js +129 -0
  115. package/lib/hooks/transcript.d.ts +28 -0
  116. package/lib/hooks/transcript.js +141 -0
  117. package/lib/hooks/vocabulary.d.ts +57 -0
  118. package/lib/hooks/vocabulary.js +366 -0
  119. package/lib/index.d.ts +31 -0
  120. package/lib/index.js +287 -0
  121. package/lib/mcp/auth.d.ts +35 -0
  122. package/lib/mcp/auth.js +178 -0
  123. package/lib/mcp/catalog.d.ts +39 -0
  124. package/lib/mcp/catalog.js +69 -0
  125. package/lib/mcp/mount.d.ts +113 -0
  126. package/lib/mcp/mount.js +317 -0
  127. package/lib/mcp/policy.d.ts +42 -0
  128. package/lib/mcp/policy.js +43 -0
  129. package/lib/mcp/remote.d.ts +45 -0
  130. package/lib/mcp/remote.js +133 -0
  131. package/lib/mcp/row.d.ts +9 -0
  132. package/lib/mcp/row.js +225 -0
  133. package/lib/mods/bundler.d.ts +38 -0
  134. package/lib/mods/bundler.js +157 -0
  135. package/lib/mods/chain.d.ts +103 -0
  136. package/lib/mods/chain.js +436 -0
  137. package/lib/mods/claude.d.ts +27 -0
  138. package/lib/mods/claude.js +56 -0
  139. package/lib/mods/engine.d.ts +160 -0
  140. package/lib/mods/engine.js +701 -0
  141. package/lib/mods/expect.d.ts +8 -0
  142. package/lib/mods/expect.js +248 -0
  143. package/lib/mods/host.d.ts +105 -0
  144. package/lib/mods/host.js +462 -0
  145. package/lib/mods/loader.d.ts +53 -0
  146. package/lib/mods/loader.js +231 -0
  147. package/lib/mods/ops.d.ts +13 -0
  148. package/lib/mods/ops.js +117 -0
  149. package/lib/mods/row.d.ts +9 -0
  150. package/lib/mods/row.js +77 -0
  151. package/lib/mods/runtime.d.ts +60 -0
  152. package/lib/mods/runtime.js +133 -0
  153. package/lib/mods/service/commands.d.ts +17 -0
  154. package/lib/mods/service/commands.js +121 -0
  155. package/lib/mods/service/drawings.d.ts +36 -0
  156. package/lib/mods/service/drawings.js +64 -0
  157. package/lib/mods/service/sessions.d.ts +63 -0
  158. package/lib/mods/service/sessions.js +345 -0
  159. package/lib/mods/service/tools.d.ts +32 -0
  160. package/lib/mods/service/tools.js +253 -0
  161. package/lib/mods/service/turns.d.ts +33 -0
  162. package/lib/mods/service/turns.js +136 -0
  163. package/lib/mods/service/types.d.ts +151 -0
  164. package/lib/mods/service/types.js +1 -0
  165. package/lib/mods/service.d.ts +72 -0
  166. package/lib/mods/service.js +104 -0
  167. package/lib/mods/surfaces.d.ts +93 -0
  168. package/lib/mods/surfaces.js +309 -0
  169. package/lib/mods/values.d.ts +30 -0
  170. package/lib/mods/values.js +95 -0
  171. package/lib/opencode/bun.d.ts +40 -0
  172. package/lib/opencode/bun.js +168 -0
  173. package/lib/opencode/convert.d.ts +53 -0
  174. package/lib/opencode/convert.js +255 -0
  175. package/lib/opencode/row.d.ts +22 -0
  176. package/lib/opencode/row.js +104 -0
  177. package/lib/opencode/runtime/core.d.ts +74 -0
  178. package/lib/opencode/runtime/core.js +249 -0
  179. package/lib/opencode/runtime/events.d.ts +80 -0
  180. package/lib/opencode/runtime/events.js +281 -0
  181. package/lib/opencode/runtime/mount.d.ts +27 -0
  182. package/lib/opencode/runtime/mount.js +283 -0
  183. package/lib/opencode/runtime/server.d.ts +27 -0
  184. package/lib/opencode/runtime/server.js +354 -0
  185. package/lib/opencode/runtime/types.d.ts +109 -0
  186. package/lib/opencode/runtime/types.js +1 -0
  187. package/lib/opencode/runtime.d.ts +55 -0
  188. package/lib/opencode/runtime.js +79 -0
  189. package/lib/porting/adapter-paths.d.ts +13 -0
  190. package/lib/porting/adapter-paths.js +120 -0
  191. package/lib/porting/port-gap.d.ts +36 -0
  192. package/lib/porting/port-gap.js +158 -0
  193. package/lib/porting/port-sessions.d.ts +41 -0
  194. package/lib/porting/port-sessions.js +98 -0
  195. package/lib/porting/prompt.d.ts +23 -0
  196. package/lib/porting/prompt.js +51 -0
  197. package/lib/porting/row.d.ts +16 -0
  198. package/lib/porting/row.js +27 -0
  199. package/lib/porting/verify-port.d.ts +46 -0
  200. package/lib/porting/verify-port.js +82 -0
  201. package/lib/presets/fs-search.d.ts +25 -0
  202. package/lib/presets/fs-search.js +17 -0
  203. package/lib/presets/tool-filter.d.ts +35 -0
  204. package/lib/presets/tool-filter.js +91 -0
  205. package/lib/sessions/chat-import.d.ts +48 -0
  206. package/lib/sessions/chat-import.js +44 -0
  207. package/lib/sessions/claude.d.ts +35 -0
  208. package/lib/sessions/claude.js +104 -0
  209. package/lib/sessions/codex-discover.d.ts +34 -0
  210. package/lib/sessions/codex-discover.js +205 -0
  211. package/lib/sessions/codex-meta.d.ts +63 -0
  212. package/lib/sessions/codex-meta.js +148 -0
  213. package/lib/sessions/codex-text.d.ts +9 -0
  214. package/lib/sessions/codex-text.js +44 -0
  215. package/lib/sessions/codex.d.ts +42 -0
  216. package/lib/sessions/codex.js +270 -0
  217. package/lib/sessions/opencode.d.ts +38 -0
  218. package/lib/sessions/opencode.js +339 -0
  219. package/lib/sessions/persist.d.ts +162 -0
  220. package/lib/sessions/persist.js +377 -0
  221. package/lib/sessions/row.d.ts +15 -0
  222. package/lib/sessions/row.js +101 -0
  223. package/lib/sessions/turns.d.ts +31 -0
  224. package/lib/sessions/turns.js +63 -0
  225. package/lib/sessions/zstd.d.ts +15 -0
  226. package/lib/sessions/zstd.js +152 -0
  227. package/lib/shared/invocation.d.ts +169 -0
  228. package/lib/shared/invocation.js +325 -0
  229. package/lib/shared/render.d.ts +101 -0
  230. package/lib/shared/render.js +1353 -0
  231. package/lib/shared/util.d.ts +21 -0
  232. package/lib/shared/util.js +32 -0
  233. package/lib/skills/bundled.d.ts +3 -0
  234. package/lib/skills/bundled.js +42 -0
  235. package/lib/skills/provider.d.ts +74 -0
  236. package/lib/skills/provider.js +346 -0
  237. package/lib/skills/row.d.ts +22 -0
  238. package/lib/skills/row.js +204 -0
  239. package/lib/workbench/adapter-coverage.d.ts +65 -0
  240. package/lib/workbench/adapter-coverage.js +141 -0
  241. package/lib/workbench/model-tools.d.ts +10 -0
  242. package/lib/workbench/model-tools.js +122 -0
  243. package/lib/workbench/overview.d.ts +153 -0
  244. package/lib/workbench/overview.js +246 -0
  245. package/lib/workbench/remote.d.ts +161 -0
  246. package/lib/workbench/remote.js +561 -0
  247. package/lib/workbench/row.d.ts +15 -0
  248. package/lib/workbench/row.js +16 -0
  249. package/lib/workbench/settings.d.ts +19 -0
  250. package/lib/workbench/settings.js +60 -0
  251. package/lib/workbench/workbench.d.ts +130 -0
  252. package/lib/workbench/workbench.js +361 -0
  253. package/locale/agents/en.json +6 -0
  254. package/locale/agents/zh.json +6 -0
  255. package/locale/commands/en.json +6 -0
  256. package/locale/commands/zh.json +6 -0
  257. package/locale/context/en.json +6 -0
  258. package/locale/context/zh.json +6 -0
  259. package/locale/en.json +6 -0
  260. package/locale/hooks/en.json +6 -0
  261. package/locale/hooks/zh.json +6 -0
  262. package/locale/mcp/en.json +6 -0
  263. package/locale/mcp/zh.json +6 -0
  264. package/locale/mods/en.json +6 -0
  265. package/locale/mods/zh.json +6 -0
  266. package/locale/opencode/en.json +6 -0
  267. package/locale/opencode/zh.json +6 -0
  268. package/locale/porter/en.json +6 -0
  269. package/locale/porter/zh.json +6 -0
  270. package/locale/sessions/en.json +6 -0
  271. package/locale/sessions/zh.json +6 -0
  272. package/locale/skills/en.json +6 -0
  273. package/locale/skills/zh.json +6 -0
  274. package/locale/workbench/en.json +6 -0
  275. package/locale/workbench/zh.json +6 -0
  276. package/locale/zh.json +7 -0
  277. package/package.json +247 -3
  278. package/runtime/opencode-host.mjs +270 -0
  279. package/skills/harness-forge/SKILL.md +47 -0
@@ -0,0 +1,82 @@
1
+ /**
2
+ * `harness_verify_port`: whether an installed adapter now covers a plugin
3
+ * part. It reads the adapter packages again, asks DSH's plugin manager whether
4
+ * that package is enabled and its plugins started without a fault, and records
5
+ * the answer for the Gaps screen ("Done — verified", or back to in progress).
6
+ * It also reads the adapter's source for a hard-coded DSH home or a listing of
7
+ * profiles (`adapter-paths.ts`), the brief's data access rules.
8
+ * The creation-mode agent calls it before it reports a port done.
9
+ * @module @kirkchinese/harness-forge/porting
10
+ */
11
+ import { existsSync } from 'node:fs';
12
+ import { adapterPackageName } from '@kirkchinese/harness-forge-core';
13
+ import { coveringAdapter } from '../workbench/overview.js';
14
+ import { adapterReadiness, managerSnapshot } from '../workbench/adapter-coverage.js';
15
+ import { PortSessions } from './port-sessions.js';
16
+ import { hardCodedPaths, pathsDetail } from './adapter-paths.js';
17
+ import { dshService } from '../dsh/host.js';
18
+ const check = (name, ok, detail) => ({ check: name, ok, detail });
19
+ /**
20
+ * Verify that an adapter covers one part, and record the answer.
21
+ * @param callerSession - the session that asked, linked to the part when no port session was recorded for it.
22
+ */
23
+ export async function verifyPort(deps, pluginId, componentId, callerSession) {
24
+ const { plugin } = deps.findPlugin(pluginId);
25
+ const component = plugin.components.find(item => item.id === componentId);
26
+ if (component === undefined)
27
+ throw new Error(`${plugin.name} has no part ${componentId}; its parts are ${plugin.components.map(item => item.id).join(', ')}`);
28
+ const base = { pluginId, componentId, plugin: plugin.name, part: component.name };
29
+ const adapters = deps.adapters();
30
+ const name = coveringAdapter(plugin, component, adapters);
31
+ const checks = [];
32
+ if (name === undefined) {
33
+ checks.push(check('declared', false, `no package installed in this DSH profile declares this part: its package.json needs "harnessForge": { "ports": [${JSON.stringify({ plugin: plugin.name, component: component.name })}] } (or the package is named ${adapterPackageName(plugin, component)}), and it must be installed with plugin_manager install_bundle`));
34
+ }
35
+ else {
36
+ const dir = adapters.find(adapter => adapter.name === name)?.dir;
37
+ checks.push(check('declared', true, `${name}${dir !== undefined ? ` (${dir})` : ''} declares it`));
38
+ if (deps.pluginManager === undefined) {
39
+ checks.push(check('enabled', false, 'this DSH profile composes no plugin manager, so whether the adapter is enabled cannot be checked'));
40
+ }
41
+ else {
42
+ // The decision the workbench overview counts an adapter by.
43
+ checks.push(...adapterReadiness(name, await managerSnapshot(deps.pluginManager)));
44
+ }
45
+ // Only a package whose files are here can be read; an adapter DSH installed always has them.
46
+ if (dir !== undefined && existsSync(dir)) {
47
+ const findings = hardCodedPaths(dir);
48
+ checks.push(check('paths', findings.length === 0, pathsDetail(findings)));
49
+ }
50
+ }
51
+ const covered = checks.every(item => item.ok);
52
+ if (covered && name !== undefined) {
53
+ if (deps.sessions.get(pluginId, componentId) === undefined && callerSession !== undefined)
54
+ deps.sessions.started(pluginId, componentId, callerSession);
55
+ deps.sessions.verified(pluginId, componentId, name);
56
+ }
57
+ else {
58
+ deps.sessions.unverified(pluginId, componentId);
59
+ }
60
+ return { covered, ...base, ...(name !== undefined ? { adapter: name } : {}), checks };
61
+ }
62
+ /** Verification against this Harness Forge and the DSH it runs in. */
63
+ export function forgeVerifyDeps(forge, workbench) {
64
+ return {
65
+ findPlugin: id => workbench.findPlugin(id),
66
+ adapters: () => workbench.adapters(),
67
+ pluginManager: dshService(forge.ctx, 'pluginManager'),
68
+ sessions: new PortSessions(forge.statePath),
69
+ };
70
+ }
71
+ /**
72
+ * The recorded port sessions, without those whose session was deleted (when
73
+ * the profile composes a session controller that can list them).
74
+ */
75
+ export async function livePorts(forge) {
76
+ const sessions = new PortSessions(forge.statePath);
77
+ const controller = dshService(forge.ctx, 'sessionController');
78
+ if (controller?.list === undefined)
79
+ return sessions.list();
80
+ const existing = new Set((await controller.list({}, AbortSignal.timeout(30_000))).items.map(item => item.sessionId));
81
+ return sessions.prune(id => existing.has(id));
82
+ }
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Preset row standing in for DSH's `tool-fs-search` when an agent's tool list
3
+ * keeps only one of `glob` and `grep`: DSH's row registers both and has no
4
+ * switch, and `tools.restrict` cannot hide a tool a preset row registers. This
5
+ * row registers the listed one with DSH's own implementation and caps.
6
+ * @module @kirkchinese/harness-forge/preset-fs-search
7
+ */
8
+ import type { Context } from '@deepseek-ai/cordis';
9
+ /** The listed tools, and DSH's `tool-fs-search` config of the row this one replaces. */
10
+ export interface Config {
11
+ tools: Array<'glob' | 'grep'>;
12
+ sampleOverCapGlobResults?: boolean;
13
+ globMaxResults?: number;
14
+ grepMaxMatches?: number;
15
+ grepMaxLineBytes?: number;
16
+ searchMetaMaxBytes?: number;
17
+ rawOutputMaxBytes?: number;
18
+ graceMs?: number;
19
+ stderrMaxBytes?: number;
20
+ timeoutMs?: number;
21
+ }
22
+ export declare const name = "harness-forge-fs-search";
23
+ /** What DSH's search tools need. */
24
+ export declare const inject: string[];
25
+ export declare function apply(ctx: Context, config: Config): Promise<void>;
@@ -0,0 +1,17 @@
1
+ export const name = 'harness-forge-fs-search';
2
+ /** What DSH's search tools need. */
3
+ export const inject = ['tools', 'systemPrompt', 'subprocess', 'workingDirectory'];
4
+ export async function apply(ctx, config) {
5
+ const search = await import('@deepseek-ai/dsh-tool-fs-search');
6
+ const shared = {
7
+ maxMetaBytes: config.searchMetaMaxBytes ?? search.SEARCH_META_MAX_BYTES,
8
+ rawOutputMaxBytes: config.rawOutputMaxBytes ?? search.RAW_OUTPUT_MAX_BYTES,
9
+ graceMs: config.graceMs ?? search.SEARCH_GRACE_MS,
10
+ stderrMaxBytes: config.stderrMaxBytes ?? search.SEARCH_STDERR_MAX_BYTES,
11
+ timeoutMs: config.timeoutMs ?? search.SEARCH_TIMEOUT_MS,
12
+ };
13
+ if (config.tools.includes('glob'))
14
+ search.applyGlobTool(ctx, { ...shared, sampleOverCapGlobResults: config.sampleOverCapGlobResults ?? false, maxResults: config.globMaxResults ?? search.GLOB_MAX_RESULTS });
15
+ if (config.tools.includes('grep'))
16
+ search.applyGrepTool(ctx, { ...shared, maxMatches: config.grepMaxMatches ?? search.GREP_MAX_MATCHES, maxLineBytes: config.grepMaxLineBytes ?? search.GREP_MAX_LINE_BYTES });
17
+ }
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Tool-filter row mounted inside a generated agent preset. The preset's own
3
+ * rows are already narrowed to the agent's `tools` (see `narrowRows`); this
4
+ * row covers what rows cannot express: a tool a kept row registers but the
5
+ * agent does not list, and the host's global tools (other plugins, MCP).
6
+ * Visible global tools outside the list are hidden with `tools.restrict`; what
7
+ * `restrict` cannot reach (a tool a kept row registers beside a listed one, a
8
+ * tool another plugin registers on the agent itself, such as the capability
9
+ * catalog's `skill`) is taken out of the agent's assembled tool list; and every
10
+ * call outside the list is refused by a scoped `tools.guard`.
11
+ *
12
+ * MCP entries follow Claude Code: `mcp__server` names every tool of a server,
13
+ * `mcp__server__*` too, `mcp__server__tool` one tool. A capability-catalog
14
+ * call is judged as the MCP tool its id names.
15
+ * @module @kirkchinese/harness-forge/preset-tool-filter
16
+ */
17
+ import type { Context } from '@deepseek-ai/cordis';
18
+ import z from '@deepseek-ai/schemastery';
19
+ /** Tool names to allow and/or deny. */
20
+ export interface Config {
21
+ allow?: string[];
22
+ deny?: string[];
23
+ }
24
+ /** Schemastery validation for the filter row. */
25
+ export declare const Config: z<Config>;
26
+ /** Cordis plugin name. */
27
+ export declare const name = "harness-forge-tool-filter";
28
+ /** The filter needs the scoped tool registry. */
29
+ export declare const inject: string[];
30
+ /** Whether an MCP entry of an agent's tool list names this MCP tool. */
31
+ export declare function mcpEntryMatches(entry: string, tool: string): boolean;
32
+ /** Why a call is outside an agent's tool list, or undefined when it is inside. */
33
+ export declare function exclusion(config: Config, tool: string, args: unknown): string | undefined;
34
+ /** Apply the restriction for the lifetime of the preset row. */
35
+ export declare function apply(ctx: Context, config: Config): void;
@@ -0,0 +1,91 @@
1
+ import z from '@deepseek-ai/schemastery';
2
+ import { CATALOG_CALL_TOOL, CATALOG_TOOLS, catalogToolName } from '../mcp/catalog.js';
3
+ import { onDsh } from '../dsh/host.js';
4
+ /** Schemastery validation for the filter row. */
5
+ export const Config = z.object({
6
+ allow: z.array(z.string()),
7
+ deny: z.array(z.string()),
8
+ });
9
+ /** Cordis plugin name. */
10
+ export const name = 'harness-forge-tool-filter';
11
+ /** The filter needs the scoped tool registry. */
12
+ export const inject = ['tools'];
13
+ const CATALOG = new Set(CATALOG_TOOLS);
14
+ /** Whether an MCP entry of an agent's tool list names this MCP tool. */
15
+ export function mcpEntryMatches(entry, tool) {
16
+ const base = entry.endsWith('__*') ? entry.slice(0, -3) : entry;
17
+ return tool === base || tool.startsWith(`${base}__`);
18
+ }
19
+ /** Why a call is outside an agent's tool list, or undefined when it is inside. */
20
+ export function exclusion(config, tool, args) {
21
+ const allow = config.allow;
22
+ const deny = config.deny ?? [];
23
+ const mcpAllow = (allow ?? []).filter(entry => entry.startsWith('mcp__'));
24
+ const mcpDeny = deny.filter(entry => entry.startsWith('mcp__'));
25
+ const refused = `${tool} is not available to this agent`;
26
+ if (CATALOG.has(tool)) {
27
+ if (tool === CATALOG_CALL_TOOL) {
28
+ const mcpName = catalogToolName(args?.id);
29
+ if (mcpName !== undefined) {
30
+ if (mcpDeny.some(entry => mcpEntryMatches(entry, mcpName)))
31
+ return `${mcpName} is not available to this agent`;
32
+ if (allow !== undefined && !mcpAllow.some(entry => mcpEntryMatches(entry, mcpName)))
33
+ return `${mcpName} is not available to this agent`;
34
+ return undefined;
35
+ }
36
+ }
37
+ return allow !== undefined && mcpAllow.length === 0 ? refused : undefined;
38
+ }
39
+ if (tool.startsWith('mcp__')) {
40
+ if (mcpDeny.some(entry => mcpEntryMatches(entry, tool)))
41
+ return refused;
42
+ return allow !== undefined && !mcpAllow.some(entry => mcpEntryMatches(entry, tool)) ? refused : undefined;
43
+ }
44
+ if (deny.includes(tool))
45
+ return refused;
46
+ return allow !== undefined && !allow.includes(tool) ? refused : undefined;
47
+ }
48
+ /** Apply the restriction for the lifetime of the preset row. */
49
+ export function apply(ctx, config) {
50
+ if (config.allow === undefined && (config.deny ?? []).length === 0)
51
+ return;
52
+ ctx.effect(() => ctx.tools.guard(execution => exclusion(config, execution.name, execution.arguments)), 'harness-forge.tool-guard');
53
+ // A catalog meta-tool stays visible when any MCP tool is allowed; its calls are judged one by one.
54
+ // `restrict` reaches global tools only; a tool a kept preset row registers beside a listed one
55
+ // (`glob` beside `grep`) stays visible, and the guard refuses its calls. Global tools registered after
56
+ // the preset started (a delegation tool, an MCP server that connected later) are hidden as they appear.
57
+ const excluded = (tool) => exclusion(config, tool, undefined) !== undefined && !(tool === CATALOG_CALL_TOOL && (config.allow ?? []).some(entry => entry.startsWith('mcp__')));
58
+ const restricted = new Map();
59
+ let hiding = false;
60
+ const hide = () => {
61
+ // Restricting changes the tools, which raises tools/change again: one pass at a time.
62
+ if (hiding)
63
+ return;
64
+ hiding = true;
65
+ try {
66
+ hidePass();
67
+ }
68
+ finally {
69
+ hiding = false;
70
+ }
71
+ };
72
+ const hidePass = () => {
73
+ for (const tool of ctx.tools.schemas().map(schema => schema.name)) {
74
+ if (restricted.has(tool))
75
+ continue;
76
+ if (!excluded(tool))
77
+ continue;
78
+ try {
79
+ restricted.set(tool, ctx.tools.restrict({ deny: [tool] }));
80
+ }
81
+ catch {
82
+ // A tool of this preset's own rows cannot be masked; the guard refuses its calls.
83
+ restricted.set(tool, () => { });
84
+ }
85
+ }
86
+ };
87
+ hide();
88
+ onDsh(ctx, 'tools/change', (() => { hide(); }));
89
+ ctx.effect(() => () => { for (const dispose of restricted.values())
90
+ dispose(); }, 'harness-forge.tool-filter');
91
+ }
@@ -0,0 +1,48 @@
1
+ /**
2
+ * dsh-chat-import, the dedicated session importer for DSH (Claude Code, Codex, OpenCode and 40+ other agents):
3
+ * Harness Forge recommends it, installs it on request through DSH's plugin manager, and yields its own import
4
+ * to it while it runs. Detected by the service it provides (`chatImport`); Harness Forge does not depend on it.
5
+ * @module @kirkchinese/harness-forge
6
+ */
7
+ import type { Context } from '@deepseek-ai/cordis';
8
+ /** Its npm package, which is also its bundle name. */
9
+ export declare const CHAT_IMPORT_PACKAGE = "dsh-chat-import";
10
+ /** The command that installs it into the web profile when the plugin manager is not reachable. */
11
+ export declare const CHAT_IMPORT_COMMAND = "dsh plugin --profile web add dsh-chat-import";
12
+ /** What Harness Forge's import answers while dsh-chat-import runs. */
13
+ export declare const YIELD_MESSAGE = "Session import is provided by dsh-chat-import: use its Import sessions button in the sidebar.";
14
+ /** Whether dsh-chat-import runs in this DSH. */
15
+ export declare function chatImportRunning(ctx: object): boolean;
16
+ /** Where session import stands, for the workbench. */
17
+ export interface SessionImportStatus {
18
+ /** Who imports sessions: Harness Forge, or dsh-chat-import while it runs. */
19
+ readonly provider: 'harness-forge' | 'dsh-chat-import';
20
+ /** Whether Harness Forge can install dsh-chat-import itself (DSH's plugin manager is there). */
21
+ readonly canInstall: boolean;
22
+ readonly command: string;
23
+ }
24
+ export declare function sessionImportStatus(ctx: object): SessionImportStatus;
25
+ interface ChangeResult {
26
+ readonly changed: boolean;
27
+ readonly application: 'applied' | 'restart-required' | 'overridden' | 'failed' | 'cancelled';
28
+ readonly error?: {
29
+ readonly code: string;
30
+ readonly diagnostic?: string;
31
+ };
32
+ readonly pendingBuilds?: readonly string[];
33
+ /** The bundle an installation added. */
34
+ readonly bundle?: string;
35
+ }
36
+ /** How an installation ended. */
37
+ export interface ChatImportInstall {
38
+ /** `applied`: it runs now; `restart-required`: it runs after DSH restarts. */
39
+ readonly application: ChangeResult['application'];
40
+ readonly running: boolean;
41
+ }
42
+ /**
43
+ * Install dsh-chat-import from npm and enable it, through DSH's plugin manager, the way the Plugins page does; an
44
+ * installed but disabled copy is enabled. The browser asks the person first. Throws with the reason, and the
45
+ * command to run instead, when it cannot.
46
+ */
47
+ export declare function installChatImport(ctx: Context): Promise<ChatImportInstall>;
48
+ export {};
@@ -0,0 +1,44 @@
1
+ import { dshService } from '../dsh/host.js';
2
+ /** Its npm package, which is also its bundle name. */
3
+ export const CHAT_IMPORT_PACKAGE = 'dsh-chat-import';
4
+ /** The command that installs it into the web profile when the plugin manager is not reachable. */
5
+ export const CHAT_IMPORT_COMMAND = `dsh plugin --profile web add ${CHAT_IMPORT_PACKAGE}`;
6
+ /** What Harness Forge's import answers while dsh-chat-import runs. */
7
+ export const YIELD_MESSAGE = 'Session import is provided by dsh-chat-import: use its Import sessions button in the sidebar.';
8
+ /** Whether dsh-chat-import runs in this DSH. */
9
+ export function chatImportRunning(ctx) {
10
+ return dshService(ctx, 'chatImport') !== undefined;
11
+ }
12
+ export function sessionImportStatus(ctx) {
13
+ const manager = dshService(ctx, 'pluginManager');
14
+ return {
15
+ provider: chatImportRunning(ctx) ? 'dsh-chat-import' : 'harness-forge',
16
+ canInstall: typeof manager?.installBundle === 'function',
17
+ command: CHAT_IMPORT_COMMAND,
18
+ };
19
+ }
20
+ /**
21
+ * Install dsh-chat-import from npm and enable it, through DSH's plugin manager, the way the Plugins page does; an
22
+ * installed but disabled copy is enabled. The browser asks the person first. Throws with the reason, and the
23
+ * command to run instead, when it cannot.
24
+ */
25
+ export async function installChatImport(ctx) {
26
+ const manager = dshService(ctx, 'pluginManager');
27
+ if (typeof manager?.installBundle !== 'function')
28
+ throw new Error(`DSH's plugin manager is not available here; install dsh-chat-import from the Plugins page, or run: ${CHAT_IMPORT_COMMAND}`);
29
+ if (chatImportRunning(ctx))
30
+ return { application: 'applied', running: true };
31
+ const listed = typeof manager.listBundles === 'function' ? (await manager.listBundles()).find(bundle => bundle.name === CHAT_IMPORT_PACKAGE) : undefined;
32
+ const result = listed !== undefined && listed.installed !== false && typeof manager.setBundleEnabled === 'function'
33
+ ? await manager.setBundleEnabled(CHAT_IMPORT_PACKAGE, true)
34
+ : await manager.installBundle(CHAT_IMPORT_PACKAGE, { enabled: true });
35
+ // A profile whose other entries fail to activate reports that as the change's error too; dsh-chat-import itself
36
+ // was added when the manager names it as the bundle, or when its service runs.
37
+ const added = result.bundle === CHAT_IMPORT_PACKAGE || chatImportRunning(ctx);
38
+ if (result.application === 'failed' || result.application === 'cancelled' || (result.error !== undefined && !added)) {
39
+ const builds = result.pendingBuilds !== undefined && result.pendingBuilds.length > 0 ? ` (its install scripts wait for approval: ${result.pendingBuilds.join(', ')})` : '';
40
+ const reason = result.error?.diagnostic ?? result.error?.code ?? result.application;
41
+ throw new Error(`dsh-chat-import was not installed: ${reason}${builds}. Install it from the Plugins page, or run: ${CHAT_IMPORT_COMMAND}`);
42
+ }
43
+ return { application: result.application, running: chatImportRunning(ctx) };
44
+ }
@@ -0,0 +1,35 @@
1
+ import type { Context } from '@deepseek-ai/cordis';
2
+ import { type SessionPage, type SessionPageRequest } from '../forge/contract.js';
3
+ import { type ImportIdentity, type ImportReport } from './persist.js';
4
+ /** One discoverable Claude Code transcript. */
5
+ export interface SessionCandidate {
6
+ readonly path: string;
7
+ readonly sourceId: string;
8
+ readonly source?: 'claude-code' | 'codex' | 'opencode';
9
+ readonly title?: string;
10
+ readonly cwd?: string;
11
+ readonly createdAt?: number;
12
+ /** When the transcript was last written. */
13
+ readonly updatedAt?: number;
14
+ /** The transcript's size in bytes. */
15
+ readonly bytes?: number;
16
+ readonly origin?: 'subagent';
17
+ }
18
+ /** Result of one session import. */
19
+ export type SessionImportReport = ImportReport;
20
+ /** Default Claude Code projects directory. */
21
+ export declare function defaultClaudeProjectsRoot(home?: string): string;
22
+ /** The id an import gives a Claude Code session (the core mints it the same way: `claude-<session id>`). */
23
+ export declare function claudeSessionId(sourceId: string): string;
24
+ /** How an import finds the DSH session holding a Claude Code session: earlier versions used the bare id. */
25
+ export declare function claudeIdentity(sourceId: string): ImportIdentity;
26
+ /**
27
+ * One page of the Claude Code main transcripts under a root, newest first. The files are only listed and dated;
28
+ * the page's transcripts are the ones opened, so a long history costs no more than a short one.
29
+ */
30
+ export declare function discoverClaudeSessions(root?: string, page?: SessionPageRequest): Promise<SessionPage<SessionCandidate>>;
31
+ /** Import one Claude Code transcript into DSH session persistence. */
32
+ export declare function importClaudeSession(ctx: Context, sourcePath: string, options?: {
33
+ readonly includeSubagents?: boolean;
34
+ readonly targetId?: string;
35
+ }): Promise<SessionImportReport>;
@@ -0,0 +1,104 @@
1
+ /**
2
+ * Claude Code session migration. The adapter normalizes parent-chain JSONL;
3
+ * the shared synthesizer emits DSH v4 events; this module owns discovery and
4
+ * the persistence hand-off so the UI never writes session storage directly.
5
+ * @module @kirkchinese/harness-forge
6
+ */
7
+ import { readdir, stat } from 'node:fs/promises';
8
+ import { homedir } from 'node:os';
9
+ import { join } from 'node:path';
10
+ import { claudeCodeAdapter, discoverClaudeCodeSessions } from '@kirkchinese/harness-forge-core';
11
+ import { SESSION_PAGE_SIZE } from '../forge/contract.js';
12
+ import { importReport, persistImported, targetIdentity } from './persist.js';
13
+ /** Default Claude Code projects directory. */
14
+ export function defaultClaudeProjectsRoot(home = homedir()) {
15
+ return join(home, '.claude', 'projects');
16
+ }
17
+ /** The id an import gives a Claude Code session (the core mints it the same way: `claude-<session id>`). */
18
+ export function claudeSessionId(sourceId) {
19
+ return `claude-${sourceId.trim()}`;
20
+ }
21
+ /** How an import finds the DSH session holding a Claude Code session: earlier versions used the bare id. */
22
+ export function claudeIdentity(sourceId) {
23
+ return { id: claudeSessionId(sourceId), legacyIds: [sourceId.trim()] };
24
+ }
25
+ /** Directories of a project that hold sidecars, not main transcripts. */
26
+ const SIDECAR_DIRS = new Set(['subagents', 'workflows', 'tool-results']);
27
+ /**
28
+ * One page of the Claude Code main transcripts under a root, newest first. The files are only listed and dated;
29
+ * the page's transcripts are the ones opened, so a long history costs no more than a short one.
30
+ */
31
+ export async function discoverClaudeSessions(root = defaultClaudeProjectsRoot(), page = {}) {
32
+ const limit = Math.max(1, page.limit ?? SESSION_PAGE_SIZE);
33
+ const files = await listTranscripts(root);
34
+ const sessions = [];
35
+ let at = Math.max(0, page.cursor ?? 0);
36
+ for (; at < files.length && sessions.length < limit; at++) {
37
+ const file = files[at];
38
+ try {
39
+ for await (const item of discoverClaudeCodeSessions(file.path)) {
40
+ sessions.push({
41
+ path: item.ref,
42
+ sourceId: item.sourceId ?? item.ref,
43
+ source: 'claude-code',
44
+ ...(item.title !== undefined ? { title: item.title } : {}),
45
+ ...(item.cwd !== undefined ? { cwd: item.cwd } : {}),
46
+ ...(item.createdAt !== undefined ? { createdAt: item.createdAt } : {}),
47
+ updatedAt: file.updatedAt,
48
+ bytes: file.bytes,
49
+ ...(item.origin !== undefined ? { origin: item.origin } : {}),
50
+ });
51
+ }
52
+ }
53
+ catch {
54
+ // A transcript that cannot be read is not offered.
55
+ }
56
+ }
57
+ return { sessions, ...(at < files.length ? { next: at } : {}) };
58
+ }
59
+ async function listTranscripts(root) {
60
+ const found = [];
61
+ const walk = async (dir) => {
62
+ let entries;
63
+ try {
64
+ entries = await readdir(dir, { withFileTypes: true });
65
+ }
66
+ catch {
67
+ return;
68
+ }
69
+ for (const entry of entries) {
70
+ const path = join(dir, entry.name);
71
+ if (entry.isDirectory()) {
72
+ if (!SIDECAR_DIRS.has(entry.name))
73
+ await walk(path);
74
+ }
75
+ else if (entry.isFile() && /\.jsonl$/iu.test(entry.name) && !/^journal\.jsonl$/iu.test(entry.name)) {
76
+ const info = await stat(path).catch(() => undefined);
77
+ if (info !== undefined)
78
+ found.push({ path, updatedAt: info.mtimeMs, bytes: info.size });
79
+ }
80
+ }
81
+ };
82
+ const info = await stat(root).catch(() => undefined);
83
+ if (info?.isFile() === true)
84
+ return [{ path: root, updatedAt: info.mtimeMs, bytes: info.size }];
85
+ await walk(root);
86
+ return found.sort((a, b) => b.updatedAt - a.updatedAt || b.path.localeCompare(a.path));
87
+ }
88
+ /** Import one Claude Code transcript into DSH session persistence. */
89
+ export async function importClaudeSession(ctx, sourcePath, options = {}) {
90
+ const candidate = {
91
+ ref: sourcePath,
92
+ sourceId: sourcePath,
93
+ };
94
+ const parsed = await claudeCodeAdapter.readSession(candidate, {
95
+ ...(options.includeSubagents === true ? { includeAuxiliary: true } : {}),
96
+ ...(options.targetId !== undefined ? { targetId: options.targetId } : {}),
97
+ });
98
+ // A transcript with no conversation on its main chain would become an empty session: say why instead.
99
+ if (parsed.session.turns.length === 0)
100
+ throw new Error(`nothing to import from ${sourcePath}: ${parsed.stats.reasons.join('; ') || 'no conversation in the transcript'}`);
101
+ const sourceId = parsed.session.source.sessionId;
102
+ const identity = options.targetId !== undefined ? targetIdentity(options.targetId) : sourceId !== undefined ? claudeIdentity(sourceId) : targetIdentity(parsed.session.id);
103
+ return importReport(sourcePath, parsed.session.title, await persistImported(ctx, parsed.session, identity));
104
+ }
@@ -0,0 +1,34 @@
1
+ import { type SessionPage, type SessionPageRequest } from '../forge/contract.js';
2
+ import { type IndexedThread } from './codex-meta.js';
3
+ export interface CodexSessionCandidate {
4
+ readonly path: string;
5
+ /** The thread. */
6
+ readonly sourceId: string;
7
+ /** The session a forked thread belongs to (its parent's), when it is not the thread itself. */
8
+ readonly parentId?: string;
9
+ readonly title?: string;
10
+ readonly cwd?: string;
11
+ /** When the thread was created (as an import stores it). */
12
+ readonly createdAt?: number;
13
+ /** When the rollout was last written. */
14
+ readonly updatedAt?: number;
15
+ /** The rollout file's size in bytes (compressed, for a `.zst`). */
16
+ readonly bytes?: number;
17
+ /** Codex archived the thread (it is in `archived_sessions`). */
18
+ readonly archived?: boolean;
19
+ /** A subagent's thread: part of the session that spawned it, listed only when an import of it is stored. */
20
+ readonly subagent?: boolean;
21
+ }
22
+ /**
23
+ * One page of the Codex sessions under `root` (`~/.codex/sessions`; the archive and the thread names are read from
24
+ * its siblings), newest first: every `rollout-*.jsonl` and `.jsonl.zst`, a thread once. A subagent's thread is part
25
+ * of the session that spawned it and left out, unless `isImported` says an import of it is stored: an earlier
26
+ * version imported those, and the copy has to stay reachable.
27
+ */
28
+ export declare function discoverCodexSessions(root: string, page?: SessionPageRequest, isImported?: (subagent: CodexSessionCandidate) => Promise<boolean>): Promise<SessionPage<CodexSessionCandidate>>;
29
+ /**
30
+ * Every thread the rollouts under `root` hold, subagent threads included (an earlier version imported those too):
31
+ * what tells whether an id an earlier version gave a thread was given to others. Each file's `session_meta` is read
32
+ * once, until the file changes.
33
+ */
34
+ export declare function codexThreads(root: string): Promise<IndexedThread[]>;