@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,204 @@
1
+ /**
2
+ * The skills row: imported `SKILL.md` bundles served zero-copy through one
3
+ * DSH skill provider, their frontmatter taking effect when a skill is invoked
4
+ * (`allowed-tools`, `model`, `context: fork`, arguments of a typed `/skill`),
5
+ * and the hooks a skill's frontmatter declares, which the hooks row runs.
6
+ * @module @kirkchinese/harness-forge/skills
7
+ */
8
+ import { isAbsolute, join, dirname } from 'node:path';
9
+ import z from '@deepseek-ai/schemastery';
10
+ import { renderSkillContent } from '@deepseek-ai/dsh-skill';
11
+ import { HarnessError } from '@kirkchinese/harness-forge-core';
12
+ import { onDsh } from '../dsh/host.js';
13
+ import { skillRootOf } from '../forge/ledger.js';
14
+ import { FORGE_SERVICE } from '../forge/service.js';
15
+ import { hookSource, parseHookTable } from '../hooks/config.js';
16
+ import { appendNotice } from '../hooks/notice.js';
17
+ import { isOwnAssets, projectRootOf, templateScope } from '../mcp/mount.js';
18
+ import { ForeignSkillProvider } from './provider.js';
19
+ import { messageOf } from '../shared/util.js';
20
+ import { mounted, Parts, rowEffect } from '../forge/row.js';
21
+ export const Config = z.object({
22
+ skillRoots: z.array(z.string()),
23
+ });
24
+ export const name = 'harness-forge-skills';
25
+ export const inject = [FORGE_SERVICE, 'skills'];
26
+ /** The skills row. */
27
+ export function apply(ctx, config = {}) {
28
+ rowEffect(ctx, 'skills', forge => startSkills(ctx, forge, config));
29
+ }
30
+ function textOf(message) {
31
+ return message.content.map(block => block.type === 'text' ? block.text ?? '' : '').join('');
32
+ }
33
+ /** The arguments after a `/name` gesture in what the user typed. */
34
+ export function gestureArguments(typed, name) {
35
+ const match = new RegExp(`(?:^|\\s)/${name.replace(/[.*+?^${}()|[\]\\/]/gu, '\\$&')}(?=\\s|$)([^\\n]*)`, 'u').exec(typed);
36
+ return match?.[1]?.trim() ?? '';
37
+ }
38
+ /**
39
+ * Put a body rendered with the gesture's arguments in place of the one the
40
+ * host rendered without them, keeping the host's header lines.
41
+ */
42
+ function replaceBody(injected, body) {
43
+ const headerEnd = injected.indexOf('\n\n');
44
+ return headerEnd === -1 ? body : `${injected.slice(0, headerEnd)}\n\n${body}`;
45
+ }
46
+ /** Start the skills row on the shared service. Returns its teardown. */
47
+ export function startSkills(ctx, forge, config) {
48
+ /** Files each session has worked with, for skills with `paths`. */
49
+ const worked = new Map();
50
+ /** The component of each skill body, for its load evidence. */
51
+ const bodies = new Map();
52
+ const skillHooks = new Map();
53
+ const provider = new ForeignSkillProvider(forge.shell, (bodyPath) => {
54
+ const componentId = bodies.get(bodyPath);
55
+ if (componentId !== undefined)
56
+ forge.observe(componentId, 'skill-load', true, 'loaded by the model');
57
+ }, sessionId => worked.get(sessionId) ?? new Set(), dir => forge.projects.trust.state(dir));
58
+ const invocations = forge.invocations;
59
+ const directory = (agent, signal) => forge.directory(agent, signal);
60
+ /**
61
+ * A skill the user invoked with `/name args` is rendered with its arguments
62
+ * and takes effect (a `context: fork` skill runs in a forked agent instead of
63
+ * entering the conversation). Prepended so it sees the skill tool's own injection.
64
+ */
65
+ const preStep = async (payload, next) => {
66
+ const { agent, messages, signal } = payload;
67
+ const sessionId = agent.session.header.id;
68
+ const decision = await next();
69
+ if (decision.kind === 'reject' || decision.messages === undefined)
70
+ return decision;
71
+ const typed = messages.filter(message => message.source?.kind === 'user').map(textOf).join('\n');
72
+ const out = [];
73
+ for (const message of decision.messages) {
74
+ const name = message.source?.kind === 'skill-invocation' ? message.source.name : undefined;
75
+ const spec = typeof name === 'string' ? invocations.skill(name) : undefined;
76
+ if (typeof name === 'string') {
77
+ // `UserPromptExpansion` sees every skill the user typed, ours or DSH's own.
78
+ const expansion = await forge.lookup('hooks')?.expandSkill(agent, {
79
+ name,
80
+ foreignName: spec?.foreignName ?? name,
81
+ args: gestureArguments(typed, name),
82
+ source: spec?.source ?? 'user',
83
+ }, signal);
84
+ if (expansion?.blocked !== undefined) {
85
+ appendNotice(agent.session, { kind: 'blocked', event: 'UserPromptExpansion', subject: name, plugin: spec?.pluginId ?? 'harness-forge', text: expansion.blocked });
86
+ continue;
87
+ }
88
+ for (const text of expansion?.context ?? [])
89
+ out.push({ source: { kind: 'user' }, content: [{ type: 'text', text }] });
90
+ }
91
+ if (spec === undefined || spec.places.skillDir === undefined) {
92
+ out.push(message);
93
+ continue;
94
+ }
95
+ try {
96
+ const rawArguments = gestureArguments(typed, spec.name);
97
+ const cwd = await directory(agent, signal).catch(() => agent.session.header.cwd ?? process.cwd());
98
+ const body = await provider.renderFor(join(spec.places.skillDir, 'SKILL.md'), rawArguments, cwd, sessionId, signal).catch(() => undefined);
99
+ const directives = await invocations.activate(agent, spec, signal);
100
+ const rendered = body ?? textOf(message);
101
+ if (directives.fork !== undefined) {
102
+ const result = await invocations.fork(agent, spec, directives, rendered, signal).catch((error) => `Skill ${spec.name} could not start its forked agent: ${messageOf(error)}`);
103
+ out.push({ ...message, content: [{ type: 'text', text: `<skill-result name="${spec.name}">\n${result}\n</skill-result>` }] });
104
+ }
105
+ else {
106
+ out.push(body === undefined ? message : { ...message, content: [{ type: 'text', text: replaceBody(textOf(message), body) }] });
107
+ }
108
+ }
109
+ catch (error) {
110
+ // The skill still reaches the model as the host injected it.
111
+ out.push(message);
112
+ appendNotice(agent.session, { kind: 'hook-error', event: 'SkillInvocation', subject: spec.name, plugin: spec.pluginId, text: `frontmatter of ${spec.name} not applied: ${messageOf(error)}` });
113
+ }
114
+ }
115
+ return { ...decision, messages: out };
116
+ };
117
+ /** A model-invoked skill takes effect; a `context: fork` skill answers with its forked agent's result. */
118
+ const executeSkill = async (exec, next) => {
119
+ const result = await next();
120
+ const name = exec.arguments?.name;
121
+ const spec = typeof name === 'string' ? invocations.skill(name) : undefined;
122
+ if (exec.name !== 'skill' || result.isError || exec.agent === undefined || spec === undefined)
123
+ return result;
124
+ const directives = await invocations.activate(exec.agent, spec, exec.signal);
125
+ if (directives.fork === undefined || result.value === undefined)
126
+ return result;
127
+ const output = await invocations.fork(exec.agent, spec, directives, result.value.content, exec.signal);
128
+ const value = { ...result.value, content: output };
129
+ return { isError: false, value, content: [{ type: 'text', text: renderSkillContent(value) }] };
130
+ };
131
+ /** Remember the files a session reads or writes. */
132
+ const noteFile = (exec) => {
133
+ if (exec.agent === undefined || !['read', 'read_image', 'write', 'edit'].includes(exec.name))
134
+ return;
135
+ const path = exec.arguments?.file_path ?? exec.arguments?.path;
136
+ if (typeof path !== 'string')
137
+ return;
138
+ const id = exec.agent.session.header.id;
139
+ const files = worked.get(id) ?? new Set();
140
+ const absolute = isAbsolute(path) ? path : join(exec.agent.session.header.cwd ?? process.cwd(), path);
141
+ if (files.has(absolute))
142
+ return;
143
+ files.add(absolute);
144
+ worked.set(id, files);
145
+ provider.refresh();
146
+ };
147
+ const api = {
148
+ skillHooks: name => skillHooks.get(name),
149
+ reload: () => { provider.refresh(); },
150
+ // The configured roots, and the directories of the skills mounted one by one.
151
+ roots: () => [...new Set([...provider.listRoots(), ...provider.listSkills().map(skillRootOf)])].sort((a, b) => a.localeCompare(b, 'en')),
152
+ };
153
+ const parts = new Parts(ctx, forge, 'skills');
154
+ parts.add('skill provider', () => ctx.skills.registerProvider((control) => {
155
+ provider.attach(control);
156
+ provider.addRoots(config.skillRoots ?? []);
157
+ return provider;
158
+ }));
159
+ parts.add('typed skills', () => onDsh(ctx, 'agent/pre-step', preStep, { prepend: true, owner: 'skills' }));
160
+ parts.add('skill tool', () => onDsh(ctx, 'tools/execute', ((exec, next) => exec.name === 'skill' ? executeSkill(exec, next) : next()), { owner: 'skills' }));
161
+ parts.add('worked files', () => onDsh(ctx, 'tools/post-execute', ((exec, result, next) => {
162
+ if (!result.isError)
163
+ noteFile(exec);
164
+ return next();
165
+ }), { owner: 'skills' }));
166
+ parts.add('skill mounter', () => forge.registerMounter('skill', {
167
+ mount: async ({ component, plugin, dataDir }) => {
168
+ if (component.kind !== 'skill')
169
+ throw new HarnessError('component-failed', `action expects a skill: ${component.id}`);
170
+ const projectRoot = projectRootOf(plugin);
171
+ const releaseSkill = provider.addSkill(component.bodyPath, { pluginRoot: plugin.root, pluginName: plugin.name, dataDir, scope: templateScope(plugin), ...(projectRoot !== undefined ? { projectRoot } : {}) });
172
+ bodies.set(component.bodyPath, component.id);
173
+ const hooks = component.frontmatter.raw['hooks'];
174
+ const name = component.frontmatter.name;
175
+ const source = hooks === undefined ? undefined : hookSource(component.id, plugin, dataDir, parseHookTable(hooks), 'skill');
176
+ if (source !== undefined)
177
+ skillHooks.set(name, source);
178
+ // `allowed-tools`, `model`, `effort`, `context: fork` take effect when the skill is invoked.
179
+ const withdrawInvocation = invocations.registerSkill({
180
+ name,
181
+ kind: 'skill',
182
+ foreignName: isOwnAssets(plugin) ? name : `${plugin.name}:${name}`,
183
+ source: isOwnAssets(plugin) ? String(plugin.manifest['scope']) : 'plugin',
184
+ pluginId: plugin.id,
185
+ componentId: component.id,
186
+ frontmatter: component.frontmatter.raw,
187
+ places: { skillDir: dirname(component.bodyPath), ...(isOwnAssets(plugin) ? {} : { pluginRoot: plugin.root, dataDir }) },
188
+ });
189
+ return {
190
+ outcome: mounted(component, 'L1a', name),
191
+ disposer: async () => {
192
+ if (bodies.get(component.bodyPath) === component.id)
193
+ bodies.delete(component.bodyPath);
194
+ if (source !== undefined && skillHooks.get(name) === source)
195
+ skillHooks.delete(name);
196
+ withdrawInvocation();
197
+ releaseSkill();
198
+ },
199
+ };
200
+ },
201
+ }));
202
+ parts.add('api', () => forge.provide('skills', api));
203
+ return () => parts.dispose();
204
+ }
@@ -0,0 +1,47 @@
1
+ import type { AdapterCoverage } from './overview.js';
2
+ /**
3
+ * The adapters installed in this DSH profile.
4
+ * @param profileDir - the DSH profile directory; its packages and its parent's shared ones are read.
5
+ */
6
+ export declare function adapterCoverage(profileDir: string | undefined): AdapterCoverage[];
7
+ /** The part of `pluginManager` (`@deepseek-ai/dsh-plugin-manager`) adapter checks read. */
8
+ export interface PluginManagerLike {
9
+ listBundles(): Promise<ReadonlyArray<{
10
+ readonly name: string;
11
+ readonly enabled: boolean;
12
+ readonly error?: {
13
+ readonly code: string;
14
+ readonly diagnostic?: string;
15
+ };
16
+ readonly rows: ReadonlyArray<{
17
+ readonly rowId: string;
18
+ readonly entryId?: string;
19
+ }>;
20
+ }>>;
21
+ listPlugins(): Promise<ReadonlyArray<{
22
+ readonly entryId: string;
23
+ readonly enabled: boolean;
24
+ readonly fiberPhase: string | null;
25
+ readonly diagnostic?: string;
26
+ }>>;
27
+ }
28
+ export type ListedBundle = Awaited<ReturnType<PluginManagerLike['listBundles']>>[number];
29
+ /** Where an adapter package stands with DSH: installed and enabled as a bundle that loads, or why not. */
30
+ export type BundleState = {
31
+ readonly state: 'enabled';
32
+ readonly bundle: ListedBundle;
33
+ } | {
34
+ readonly state: 'unlisted';
35
+ } | {
36
+ readonly state: 'off';
37
+ } | {
38
+ readonly state: 'broken';
39
+ readonly error: NonNullable<ListedBundle['error']>;
40
+ };
41
+ /** The state of the bundle named `name` among the plugin manager's bundles. */
42
+ export declare function bundleState(name: string, bundles: readonly ListedBundle[]): BundleState;
43
+ /**
44
+ * The adapters on disk that DSH has installed and enabled (see `bundleState`). Without a plugin manager none is
45
+ * confirmed, so none counts.
46
+ */
47
+ export declare function enabledAdapters(adapters: readonly AdapterCoverage[], manager: PluginManagerLike | undefined): Promise<AdapterCoverage[]>;
@@ -0,0 +1,102 @@
1
+ /**
2
+ * Which plugin parts installed adapters bring: an adapter package (a local
3
+ * `dsh-adapter-*` bundle written in DSH's creation mode from a porting brief,
4
+ * or one installed from npm) declares `harnessForge.ports`
5
+ * (`[{ plugin, component }]`, the original's names) in its package.json.
6
+ * A package found on disk only counts once DSH's plugin manager lists it as an
7
+ * enabled bundle that loads (`enabledAdapters`): a failed install can leave a
8
+ * `node_modules` link behind that DSH never runs. The workbench overview and
9
+ * `harness_verify_port` apply the same criterion.
10
+ * @module @kirkchinese/harness-forge
11
+ */
12
+ import { existsSync, readdirSync, readFileSync, realpathSync } from 'node:fs';
13
+ import { dirname, join } from 'node:path';
14
+ function readJson(path) {
15
+ try {
16
+ const value = JSON.parse(readFileSync(path, 'utf8'));
17
+ return typeof value === 'object' && value !== null ? value : undefined;
18
+ }
19
+ catch {
20
+ return undefined;
21
+ }
22
+ }
23
+ function portsOf(manifest) {
24
+ const ports = manifest['harnessForge']?.ports;
25
+ if (!Array.isArray(ports))
26
+ return [];
27
+ return ports.flatMap((port) => {
28
+ const plugin = port.plugin;
29
+ const component = port.component;
30
+ return typeof plugin === 'string' && typeof component === 'string' ? [{ plugin, component }] : [];
31
+ });
32
+ }
33
+ /** Where a package's files are: a local install is a link to its source directory. */
34
+ function realDir(dir) {
35
+ try {
36
+ return realpathSync(dir);
37
+ }
38
+ catch {
39
+ return dir;
40
+ }
41
+ }
42
+ /** Package manifests directly under a node_modules directory (scoped ones included). */
43
+ function manifestsUnder(modules) {
44
+ if (!existsSync(modules))
45
+ return [];
46
+ const out = [];
47
+ for (const entry of readdirSync(modules, { withFileTypes: true })) {
48
+ if (!entry.isDirectory() && !entry.isSymbolicLink())
49
+ continue;
50
+ const dirs = entry.name.startsWith('@')
51
+ ? readdirSync(join(modules, entry.name), { withFileTypes: true }).map(inner => join(modules, entry.name, inner.name))
52
+ : [join(modules, entry.name)];
53
+ for (const dir of dirs) {
54
+ const manifest = readJson(join(dir, 'package.json'));
55
+ if (manifest !== undefined)
56
+ out.push({ manifest, dir });
57
+ }
58
+ }
59
+ return out;
60
+ }
61
+ /**
62
+ * The adapters installed in this DSH profile.
63
+ * @param profileDir - the DSH profile directory; its packages and its parent's shared ones are read.
64
+ */
65
+ export function adapterCoverage(profileDir) {
66
+ const out = [];
67
+ const seen = new Set();
68
+ const roots = profileDir === undefined ? [] : [join(profileDir, 'node_modules'), join(dirname(profileDir), 'node_modules')];
69
+ for (const modules of roots) {
70
+ for (const { manifest, dir } of manifestsUnder(modules)) {
71
+ const name = typeof manifest['name'] === 'string' ? manifest['name'] : undefined;
72
+ const ports = portsOf(manifest);
73
+ // A `dsh-adapter-*` package without ports still covers the part its name was given for (see `adapterPackageName`).
74
+ if (name === undefined || (ports.length === 0 && !name.startsWith('dsh-adapter-')) || seen.has(name))
75
+ continue;
76
+ seen.add(name);
77
+ out.push({ name, ports, dir: realDir(dir) });
78
+ }
79
+ }
80
+ return out;
81
+ }
82
+ /** The state of the bundle named `name` among the plugin manager's bundles. */
83
+ export function bundleState(name, bundles) {
84
+ const bundle = bundles.find(item => item.name === name);
85
+ if (bundle === undefined)
86
+ return { state: 'unlisted' };
87
+ if (!bundle.enabled)
88
+ return { state: 'off' };
89
+ if (bundle.error !== undefined)
90
+ return { state: 'broken', error: bundle.error };
91
+ return { state: 'enabled', bundle };
92
+ }
93
+ /**
94
+ * The adapters on disk that DSH has installed and enabled (see `bundleState`). Without a plugin manager none is
95
+ * confirmed, so none counts.
96
+ */
97
+ export async function enabledAdapters(adapters, manager) {
98
+ if (manager === undefined || adapters.length === 0)
99
+ return [];
100
+ const bundles = await manager.listBundles();
101
+ return adapters.filter(adapter => bundleState(adapter.name, bundles).state === 'enabled');
102
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Model-facing Harness Forge tools. They are thin adapters over the same
3
+ * service the workbench uses, so a model can discover, inspect and install a
4
+ * plugin without inventing a second code path.
5
+ * @module @kirkchinese/harness-forge
6
+ */
7
+ import type { Context } from '@deepseek-ai/cordis';
8
+ import type { HarnessForge } from '../forge/service.js';
9
+ /** Register the `harness_*` tool family; returns one disposer. */
10
+ export declare function registerModelTools(ctx: Context, forge: HarnessForge): () => void;
@@ -0,0 +1,122 @@
1
+ import { dialectIds } from '@kirkchinese/harness-forge-core';
2
+ import { Workbench } from './workbench.js';
3
+ import { dshService } from '../dsh/host.js';
4
+ import { forgeVerifyDeps, verifyPort } from '../porting/verify-port.js';
5
+ import { VERIFY_TOOL } from '../porting/prompt.js';
6
+ const inputSchema = (properties, required = []) => ({
7
+ type: 'object',
8
+ properties,
9
+ ...(required.length > 0 ? { required } : {}),
10
+ additionalProperties: false,
11
+ });
12
+ function textOutput() {
13
+ return {
14
+ schema: { type: 'object', additionalProperties: true },
15
+ render: (_args, value) => [{ type: 'text', text: JSON.stringify(value, null, 2) }],
16
+ };
17
+ }
18
+ /** Register the `harness_*` tool family; returns one disposer. */
19
+ export function registerModelTools(ctx, forge) {
20
+ const tools = dshService(ctx, 'tools');
21
+ if (tools === undefined)
22
+ return () => { };
23
+ const workbench = new Workbench(forge);
24
+ const disposers = [
25
+ tools.register({
26
+ name: 'harness_status',
27
+ description: 'List installed Harness Forge plugins, component mounts, compatibility vectors and gaps.',
28
+ parameters: inputSchema({}),
29
+ output: textOutput(),
30
+ execute: async () => ({ plugins: forge.list(), host: workbench.hostCapabilities() }),
31
+ }),
32
+ tools.register({
33
+ name: 'harness_discover',
34
+ description: 'Discover plugin roots under the configured Claude, Codex and OpenCode directories.',
35
+ parameters: inputSchema({}),
36
+ output: textOutput(),
37
+ execute: async () => workbench.discover(),
38
+ }),
39
+ tools.register({
40
+ name: 'harness_capabilities',
41
+ description: 'Return the installed capability catalog, per-plugin compatibility and context-budget usage.',
42
+ parameters: inputSchema({}),
43
+ output: textOutput(),
44
+ execute: async () => workbench.capabilities(),
45
+ }),
46
+ tools.register({
47
+ name: 'harness_scan',
48
+ description: 'Scan one foreign plugin root without installing it.',
49
+ parameters: inputSchema({
50
+ path: { type: 'string', description: 'Absolute plugin root' },
51
+ source: { type: 'string', enum: dialectIds() },
52
+ }, ['path']),
53
+ output: textOutput(),
54
+ execute: async (args) => {
55
+ const input = args;
56
+ const path = typeof input.path === 'string' ? input.path : '';
57
+ const source = typeof input.source === 'string' ? input.source : 'claude-code';
58
+ return forge.scan(path, source);
59
+ },
60
+ }),
61
+ tools.register({
62
+ name: 'harness_plan',
63
+ description: 'Build the reversible action plan for one foreign plugin root.',
64
+ parameters: inputSchema({
65
+ path: { type: 'string', description: 'Absolute plugin root' },
66
+ source: { type: 'string', enum: dialectIds() },
67
+ }, ['path']),
68
+ output: textOutput(),
69
+ execute: async (args) => {
70
+ const input = args;
71
+ const path = typeof input.path === 'string' ? input.path : '';
72
+ const source = typeof input.source === 'string' ? input.source : 'claude-code';
73
+ return forge.plan(path, source);
74
+ },
75
+ }),
76
+ tools.register({
77
+ name: 'harness_mcp_login',
78
+ description: 'Open the browser sign-in page of an imported remote MCP server that requires OAuth (its status shows "sign-in required"). The server connects when the user finishes; tell the user to complete the sign-in in the browser.',
79
+ parameters: inputSchema({ server: { type: 'string', description: 'MCP server name, e.g. plugin_context7_context7' } }, ['server']),
80
+ output: textOutput(),
81
+ execute: async (args, exec) => {
82
+ const server = String(args.server ?? '');
83
+ const mcp = forge.lookup('mcp');
84
+ if (mcp === undefined)
85
+ throw new Error('the Harness Forge mcp row is off');
86
+ const sessionId = exec?.agent?.session?.header?.id;
87
+ return { server, signInUrl: mcp.startSignIn(server, sessionId), waiting: mcp.pendingSignIns(sessionId) };
88
+ },
89
+ }),
90
+ tools.register({
91
+ name: 'harness_install',
92
+ description: 'Install one foreign plugin root and execute its hooks, MCP servers and code shims.',
93
+ parameters: inputSchema({
94
+ path: { type: 'string', description: 'Absolute plugin root' },
95
+ source: { type: 'string', enum: dialectIds() },
96
+ }, ['path']),
97
+ output: textOutput(),
98
+ execute: async (args) => {
99
+ const input = args;
100
+ const path = typeof input.path === 'string' ? input.path : '';
101
+ const source = typeof input.source === 'string' ? input.source : 'claude-code';
102
+ return forge.install(path, source);
103
+ },
104
+ }),
105
+ tools.register({
106
+ name: VERIFY_TOOL,
107
+ description: 'Check that an installed adapter now covers a plugin part Harness Forge could not run: an installed package declares it in package.json "harnessForge.ports", its DSH bundle is enabled, and its plugins started without a fault. Answers { covered, checks[] } and records the result in Harness Forge\'s Gaps screen. Call it after installing an adapter, before reporting the port done; when covered is false, fix what the failing check says and call it again.',
108
+ parameters: inputSchema({
109
+ pluginId: { type: 'string', description: 'The original plugin\'s id, as the porting brief gives it (e.g. claude-code:claude-hud)' },
110
+ componentId: { type: 'string', description: 'The part\'s component id, as the porting brief gives it' },
111
+ }, ['pluginId', 'componentId']),
112
+ output: textOutput(),
113
+ execute: async (args, exec) => {
114
+ const input = args;
115
+ const sessionId = exec?.agent?.session?.header?.id;
116
+ return verifyPort(forgeVerifyDeps(forge, workbench), String(input.pluginId ?? ''), String(input.componentId ?? ''), sessionId);
117
+ },
118
+ }),
119
+ ];
120
+ return () => { for (const dispose of disposers)
121
+ dispose(); };
122
+ }
@@ -0,0 +1,103 @@
1
+ /**
2
+ * The workbench's plain-language view: for each harness (Claude Code, Codex,
3
+ * OpenCode) the person's plugins and own assets, and for each part one of
4
+ * five states with the reason. Levels, plans and receipts stay in the
5
+ * details; this is what a person who never heard of them reads.
6
+ *
7
+ * | State | When |
8
+ * | --- | --- |
9
+ * | `works` | set up in DSH (or covered by an installed adapter) with nothing known missing; `checked` says whether a run here was observed |
10
+ * | `partial` | set up, but something it uses does not carry over, or a run of it failed in part |
11
+ * | `needs-port` | DSH has no equivalent; DSH's creation mode can write an adapter from its brief |
12
+ * | `unsupported` | DSH has no equivalent and none can be written from what the plugin declares |
13
+ * | `failed` | setting it up or running it failed |
14
+ * | `inactive` | the part of Harness Forge that runs it is switched off |
15
+ * | `off` | the person switched this part off |
16
+ *
17
+ * A reason is a code the browser words in the person's language, plus the
18
+ * specifics (event names, the error) as they are. A plugin not migrated yet
19
+ * shows the states its parts would have, predicted from its scan.
20
+ * @module @kirkchinese/harness-forge
21
+ */
22
+ import { type ComponentOutcome, type ForeignComponent, type ForeignPlugin, type Gap } from '@kirkchinese/harness-forge-core';
23
+ export type PartState = 'works' | 'partial' | 'needs-port' | 'unsupported' | 'failed' | 'inactive' | 'off';
24
+ export type ReasonCode = 'events-never-raised' | 'cannot-block' | 'handlers-inert' | 'output-style' | 'experimental-runtime' | 'no-equivalent-ui' | 'not-mapped' | 'hosted-connector' | 'unknown-transport' | 'run-failed' | 'setup-failed' | 'unreadable' | 'row-off' | 'other';
25
+ export interface OverviewPart {
26
+ readonly id: string;
27
+ readonly kind: ForeignComponent['kind'];
28
+ readonly name: string;
29
+ readonly state: PartState;
30
+ /** Whether a run in DSH was observed (a `works` part that is only set up says so). */
31
+ readonly checked: boolean;
32
+ readonly reasons: ReadonlyArray<{
33
+ readonly code: ReasonCode;
34
+ readonly detail: string;
35
+ }>;
36
+ /** The gap an adapter can close (needs-port, and partial parts an adapter could complete). */
37
+ readonly portGap?: string;
38
+ /** The installed adapter that covers this part. */
39
+ readonly adapter?: string;
40
+ }
41
+ export interface OverviewItem {
42
+ readonly id: string;
43
+ readonly name: string;
44
+ readonly source: string;
45
+ readonly root: string;
46
+ /** The person's own assets (`~/.claude`, `~/.codex`) rather than a plugin. */
47
+ readonly own: boolean;
48
+ readonly installed: boolean;
49
+ readonly version?: string;
50
+ readonly parts: readonly OverviewPart[];
51
+ readonly counts: Readonly<Record<PartState, number>>;
52
+ /** Of the parts that work, how many have run here and been checked. */
53
+ readonly checked: number;
54
+ }
55
+ export interface OverviewHarness {
56
+ readonly source: string;
57
+ /** Product name; not translated. */
58
+ readonly label: string;
59
+ readonly items: readonly OverviewItem[];
60
+ readonly counts: Readonly<Record<PartState, number>>;
61
+ /** Of the parts that work, how many have run here and been checked. */
62
+ readonly checked: number;
63
+ readonly toMigrate: number;
64
+ }
65
+ export interface Overview {
66
+ readonly harnesses: readonly OverviewHarness[];
67
+ }
68
+ /** An installed adapter and the parts it brings: plugin name and component name of the original. */
69
+ export interface AdapterCoverage {
70
+ readonly name: string;
71
+ readonly ports: ReadonlyArray<{
72
+ readonly plugin: string;
73
+ readonly component: string;
74
+ }>;
75
+ /** Its package directory (a local install's source directory). */
76
+ readonly dir?: string;
77
+ }
78
+ /** The installed adapter that covers a part: one declaring it in `harnessForge.ports`, or named for it (`adapterPackageName`). */
79
+ export declare function coveringAdapter(plugin: Pick<ForeignPlugin, 'name'>, component: Pick<ForeignComponent, 'name'>, adapters: readonly AdapterCoverage[]): string | undefined;
80
+ /** The state of one part, from what happened when it was set up and run (or, before migration, from its gaps). */
81
+ export declare function partOf(component: ForeignComponent, gaps: readonly Gap[], outcome: ComponentOutcome | undefined, adapter: string | undefined, off?: boolean): OverviewPart;
82
+ /** One plugin or own-assets root, installed (with outcomes) or only discovered. */
83
+ export declare function itemOf(plugin: ForeignPlugin, record: {
84
+ readonly outcomes?: readonly ComponentOutcome[];
85
+ readonly compat?: {
86
+ readonly gaps: readonly Gap[];
87
+ };
88
+ readonly disabled?: readonly string[];
89
+ } | undefined, adapters?: readonly AdapterCoverage[]): OverviewItem;
90
+ /** An installed plugin whose files can no longer be read: every recorded part is an error, with the reason. */
91
+ export declare function unreadableItemOf(record: {
92
+ readonly id: string;
93
+ readonly name: string;
94
+ readonly source: string;
95
+ readonly root: string;
96
+ readonly version?: string;
97
+ readonly components: ReadonlyArray<{
98
+ readonly kind: string;
99
+ readonly name: string;
100
+ }>;
101
+ }, error: string): OverviewItem;
102
+ /** Group items by harness, in dialect order: own assets first, then installed plugins, then the rest by name. */
103
+ export declare function overviewOf(items: readonly OverviewItem[]): Overview;