@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,14 @@
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
+ /**
9
+ * Start a delegated agent.
10
+ * @param subagents - DSH's `subagents` service.
11
+ */
12
+ export function startActivation(subagents, task, options) {
13
+ return subagents.startActivation({ ...options, ...task });
14
+ }
@@ -0,0 +1,231 @@
1
+ /**
2
+ * The contract between Harness Forge's rows. The `harness-forge` row owns the
3
+ * ledger and provides the shared service (`harnessForge`); every capability
4
+ * row (skills, commands, agents, hooks, MCP, mods, OpenCode) mounts its kind
5
+ * of component through a mounter it registers, and offers what other rows
6
+ * may ask of it as an optional API. A row that is off simply is not there:
7
+ * its components show as inactive and every lookup of it returns nothing.
8
+ *
9
+ * This module imports no row, so no row depends on another through it.
10
+ * @module @kirkchinese/harness-forge
11
+ */
12
+ import type { Context } from '@deepseek-ai/cordis';
13
+ import type { ComponentOutcome, ForeignComponent, ForeignPlugin, Gap, PlanAction } from '@kirkchinese/harness-forge-core';
14
+ import type { HookConfigSource } from '../hooks/config.js';
15
+ import type { RemoteMcpHost } from '../mcp/mount.js';
16
+ /** What a row's start returns: its teardown. */
17
+ export type Disposer = () => unknown;
18
+ /**
19
+ * The kinds of mount, one per mounter. A planned action maps to one kind by
20
+ * its action and component (see `mountKindOf`).
21
+ */
22
+ export type MountKind = 'skill' | 'command' | 'output-style' | 'mcp' | 'hooks' | 'codex-notify' | 'codex-instructions' | 'agent' | 'claude-mod' | 'opencode-plugin' | 'settings';
23
+ /** The row that mounts each kind, as the workbench names it when that row is off. */
24
+ export declare const ROW_OF_KIND: Readonly<Record<MountKind, string>>;
25
+ /**
26
+ * Where a mount lives: process-wide (an installed plugin), or one session's
27
+ * project assets, in that session's agent context.
28
+ */
29
+ export interface MountScope {
30
+ /** The session's agent context; absent for a process-wide mount. */
31
+ readonly ctx?: Context;
32
+ /** Limits hooks and settings to this session and its delegated agents. */
33
+ readonly sessionId?: string;
34
+ }
35
+ /** One planned action to mount. */
36
+ export interface MountRequest {
37
+ readonly action: PlanAction;
38
+ readonly component: ForeignComponent;
39
+ readonly plugin: ForeignPlugin;
40
+ /** The plugin's writable data directory (`${CLAUDE_PLUGIN_DATA}`). */
41
+ readonly dataDir: string;
42
+ readonly scope: MountScope;
43
+ /**
44
+ * Command names of this apply, by component id: a command keeps its name
45
+ * across restarts, and names given here are taken.
46
+ */
47
+ readonly commandNames: Map<string, string>;
48
+ /** Every command name in use outside this plugin. */
49
+ takenNames(): Set<string>;
50
+ }
51
+ /** A mount's outcome: `mounted` at most (only a runtime observation upgrades it), and its withdrawal. */
52
+ export interface Mounted {
53
+ readonly outcome: ComponentOutcome;
54
+ readonly disposer?: () => Promise<void>;
55
+ }
56
+ /** Mounts one kind of component; registered by the row that owns the kind. */
57
+ export interface Mounter {
58
+ mount(request: MountRequest): Promise<Mounted>;
59
+ /** Every action of one apply in `scope` ran (the delegation tool restarts once, after all agents). */
60
+ settle?(scope: MountScope): Promise<void>;
61
+ /** A session's project scope ended: release what `mount` kept for it. */
62
+ release?(scope: MountScope): Promise<void>;
63
+ }
64
+ /** A hook configuration a skill's or agent's frontmatter declares, as the hooks row runs it. */
65
+ export type FrontmatterHooks = HookConfigSource;
66
+ /** A permission verdict as Claude Code's `tool.check` carries it. */
67
+ export interface ToolVerdict {
68
+ readonly decision: 'allow' | 'ask' | 'deny';
69
+ readonly reason?: string;
70
+ readonly rule?: string;
71
+ readonly hook?: string;
72
+ }
73
+ /** What the hooks row offers. */
74
+ export interface HooksApi {
75
+ /** A rewrite of a call's arguments (DSH vocabulary) the hooks and the tool see. */
76
+ rewrite(callId: string, args: Record<string, unknown>): void;
77
+ /** `UserPromptExpansion` for a skill the user typed. */
78
+ expandSkill(agent: unknown, skill: {
79
+ readonly name: string;
80
+ readonly foreignName: string;
81
+ readonly args: string;
82
+ readonly source: string;
83
+ }, signal: AbortSignal): Promise<{
84
+ blocked?: string;
85
+ context: string[];
86
+ }>;
87
+ /** `UserPromptSubmit` and `UserPromptExpansion` for an imported command the user typed. */
88
+ expandCommand(agent: unknown, command: {
89
+ readonly name: string;
90
+ readonly foreignName: string;
91
+ readonly args: string;
92
+ readonly expanded: string;
93
+ }, signal: AbortSignal): Promise<{
94
+ blocked?: string;
95
+ context: string[];
96
+ }>;
97
+ /** Add a hook source (a command's frontmatter hooks); returns its removal. */
98
+ add(source: FrontmatterHooks & {
99
+ readonly sessionId?: string;
100
+ readonly agentSessionId?: string;
101
+ }): () => void;
102
+ /** Mods' `tool.check` over the verdict the hooks reached; one checker at most. */
103
+ setChecker(checker: {
104
+ checks(exec: unknown): boolean;
105
+ check(exec: unknown, verdict: ToolVerdict): Promise<ToolVerdict>;
106
+ }): Disposer;
107
+ /** Variables another runtime adds to a shell call's environment (OpenCode's `shell.env`). */
108
+ addShellEnv(provider: (exec: unknown) => Promise<Record<string, string>>): Disposer;
109
+ }
110
+ /** What the skills row offers. */
111
+ export interface SkillsApi {
112
+ /** Hooks declared in an imported skill's frontmatter, by DSH skill name. */
113
+ skillHooks(name: string): FrontmatterHooks | undefined;
114
+ /** Re-scan the imported skills. */
115
+ reload(): void;
116
+ /** The configured skill roots and the directories of the mounted skills (only the mounted ones are served from those). */
117
+ roots(): readonly string[];
118
+ }
119
+ /** What the agents row offers. */
120
+ export interface AgentsApi {
121
+ /** The foreign name (`plugin:agent`) of an imported agent preset. */
122
+ foreignName(presetId: string): string | undefined;
123
+ /** The DSH preset of a foreign agent name. */
124
+ presetOf(foreignName: string): string | undefined;
125
+ /** Hooks declared in an imported agent's frontmatter, by preset id. */
126
+ agentHooks(presetId: string): FrontmatterHooks | undefined;
127
+ }
128
+ /** A command an imported plugin's code added (OpenCode's `config` hook). */
129
+ export interface ForeignCommand {
130
+ readonly component: ForeignComponent;
131
+ readonly name: string;
132
+ readonly foreignName: string;
133
+ readonly pluginId: string;
134
+ readonly pluginRoot: string;
135
+ readonly dataDir: string;
136
+ }
137
+ /** What the commands row offers. */
138
+ export interface CommandsApi {
139
+ /** Register an added command under a free name; returns the name and the removal. */
140
+ registerAdded(command: ForeignCommand, scope: MountScope, takenNames: Set<string>): {
141
+ readonly name: string;
142
+ readonly dispose: () => void;
143
+ } | undefined;
144
+ /** OpenCode's `command.execute.before` for imported OpenCode commands; one provider at most. */
145
+ setBeforeSubmit(hook: (agent: unknown, command: {
146
+ name: string;
147
+ args: string;
148
+ }, prompt: string) => Promise<string[] | {
149
+ stopped: string;
150
+ }>): Disposer;
151
+ }
152
+ /** What the MCP row offers. */
153
+ export interface McpApi {
154
+ /** Remote MCP servers that wait for the user to sign in: those a session sees (its project's and process-wide ones), or all. */
155
+ pendingSignIns(sessionId?: string): string[];
156
+ /**
157
+ * Start one server's sign-in in the background; returns the page to sign in on. With a session, its own
158
+ * project server of that name is preferred to the process-wide one.
159
+ */
160
+ startSignIn(serverName: string, sessionId?: string): string;
161
+ /** The remote-MCP host a component's servers use: its sign-in state becomes the component's evidence. */
162
+ remoteHost(componentId: string, scope?: MountScope): RemoteMcpHost;
163
+ }
164
+ /** What the mods row offers. */
165
+ export interface ModsApi {
166
+ watch(sessionId: string, listener: (snapshot: unknown) => void): (() => void) | undefined;
167
+ act(sessionId: string, generation: number, actionId: string, value?: unknown): Promise<unknown>;
168
+ closePane(sessionId: string, id: string): Promise<unknown>;
169
+ move(sessionId: string, kind: 'focus' | 'scroll', target: Readonly<Record<string, unknown>>): Promise<unknown>;
170
+ }
171
+ /** A harness whose sessions can be imported. */
172
+ export type SessionSource = 'claude-code' | 'codex' | 'opencode';
173
+ /** What the sessions row offers. */
174
+ export interface SessionsApi {
175
+ /** The sessions of one harness available for import. */
176
+ sessions(root: string | undefined, source: SessionSource): Promise<readonly unknown[]>;
177
+ /** Import one session into DSH. */
178
+ importSession(path: string, targetId: string | undefined, source: SessionSource, sourceId: string | undefined): Promise<unknown>;
179
+ }
180
+ /** What the instruction files of a workspace are, for the workbench. */
181
+ export interface ContextStatus {
182
+ /** Whether Harness Forge adds instruction files: false while the row is off or yielding. */
183
+ readonly active: boolean;
184
+ /** The plugin that owns instruction injection instead, when it runs. */
185
+ readonly yieldingTo?: string;
186
+ /** The files Harness Forge adds. */
187
+ readonly files: readonly {
188
+ readonly path: string;
189
+ readonly bytes: number;
190
+ }[];
191
+ /** The files DSH injects itself (`CLAUDE.md`, `CLAUDE.local.md`); only their imports come from here. */
192
+ readonly hostFiles?: readonly {
193
+ readonly path: string;
194
+ readonly bytes: number;
195
+ }[];
196
+ }
197
+ /** What the context row offers. */
198
+ export interface ContextApi {
199
+ /** The instruction files of a workspace; the default workspace without `cwd`. */
200
+ status(cwd?: string): ContextStatus;
201
+ }
202
+ /** What the porter row offers: a gap described as a brief, handed to DSH's creation mode. */
203
+ export interface PorterApi {
204
+ /** The brief for one part of a plugin, as Markdown. */
205
+ brief(plugin: ForeignPlugin, gaps: readonly Gap[], componentId: string): string;
206
+ /** The first message of its port session: the working protocol, then the brief; `language` is the user's interface language. */
207
+ task(plugin: ForeignPlugin, gaps: readonly Gap[], componentId: string, language?: string): string;
208
+ /** Start a creation-mode session working on the part's task, and record it as the part's port session. */
209
+ port(plugin: ForeignPlugin, gaps: readonly Gap[], componentId: string, location: {
210
+ readonly workspaceId?: string;
211
+ readonly cwd?: string;
212
+ }, language?: string): Promise<{
213
+ readonly sessionId: string;
214
+ }>;
215
+ }
216
+ /** The optional APIs, by row. */
217
+ export interface RowApis {
218
+ context: ContextApi;
219
+ hooks: HooksApi;
220
+ skills: SkillsApi;
221
+ agents: AgentsApi;
222
+ commands: CommandsApi;
223
+ mcp: McpApi;
224
+ mods: ModsApi;
225
+ sessions: SessionsApi;
226
+ porter: PorterApi;
227
+ }
228
+ /** A plugin component's planned action, as the kind of mount it needs; `undefined` when DSH has nothing for it. */
229
+ export declare function mountKindOf(action: PlanAction, component: ForeignComponent): MountKind | {
230
+ readonly skipped: string;
231
+ };
@@ -0,0 +1,43 @@
1
+ /** The row that mounts each kind, as the workbench names it when that row is off. */
2
+ export const ROW_OF_KIND = {
3
+ 'skill': 'skills',
4
+ 'command': 'commands',
5
+ 'output-style': 'commands',
6
+ 'mcp': 'mcp',
7
+ 'hooks': 'hooks',
8
+ 'codex-notify': 'hooks',
9
+ 'codex-instructions': 'hooks',
10
+ 'agent': 'agents',
11
+ 'claude-mod': 'mods',
12
+ 'opencode-plugin': 'opencode',
13
+ 'settings': 'harness-forge',
14
+ };
15
+ /** A plugin component's planned action, as the kind of mount it needs; `undefined` when DSH has nothing for it. */
16
+ export function mountKindOf(action, component) {
17
+ switch (action.kind) {
18
+ case 'link-skill-root': return 'skill';
19
+ case 'register-command': return 'command';
20
+ case 'mount-mcp': return 'mcp';
21
+ case 'mount-hooks': return 'hooks';
22
+ case 'register-agent': return 'agent';
23
+ case 'apply-settings': return 'settings';
24
+ case 'report-ui':
25
+ return component.kind === 'ui' && component.surface === 'output-style' && component.specPath !== undefined
26
+ ? 'output-style'
27
+ : { skipped: 'UI surface has no DSH adapter yet' };
28
+ case 'report-code':
29
+ if (component.kind === 'other' && component.originalKind === 'codex-notify')
30
+ return 'codex-notify';
31
+ if (component.kind === 'other' && component.originalKind === 'codex-instructions' && component.path !== undefined)
32
+ return 'codex-instructions';
33
+ if (component.kind === 'other')
34
+ return { skipped: `${component.originalKind} is not mapped to DSH` };
35
+ if (component.kind === 'code' && component.runtime === 'claude-mod')
36
+ return 'claude-mod';
37
+ if (component.kind === 'code' && component.runtime === 'opencode-plugin')
38
+ return 'opencode-plugin';
39
+ return { skipped: component.kind === 'code' ? `no runtime for ${component.runtime}` : `unsupported action ${action.kind} for ${component.kind}` };
40
+ default:
41
+ return { skipped: `unsupported action ${String(action.kind)}` };
42
+ }
43
+ }
@@ -0,0 +1,143 @@
1
+ import type { Context } from '@deepseek-ai/cordis';
2
+ import { type CompatibilityVector, type ComponentOutcome, type ForeignPlugin, type Observation, type Plan, type Receipt } from '@kirkchinese/harness-forge-core';
3
+ import { type MountKind, type Mounter } from './contract.js';
4
+ import { LiveMounts } from './live-mounts.js';
5
+ import { type InstalledPluginRecord, type MountRecord } from './state.js';
6
+ /** One MCP mount outcome. */
7
+ export interface McpReport {
8
+ readonly name: string;
9
+ readonly status: 'mounted' | 'failed';
10
+ readonly error?: string;
11
+ }
12
+ /** One hooks mount outcome. */
13
+ export interface HookReport {
14
+ readonly name: string;
15
+ readonly dialect: 'claude-code' | 'codex';
16
+ readonly status: 'mounted' | 'failed';
17
+ readonly error?: string;
18
+ }
19
+ /** One agent preset outcome. */
20
+ export interface AgentReport {
21
+ readonly name: string;
22
+ readonly presetId: string;
23
+ readonly status: 'mounted' | 'failed';
24
+ readonly error?: string;
25
+ }
26
+ /** Result of one apply. */
27
+ export interface ApplyResult {
28
+ readonly plugin: ForeignPlugin;
29
+ readonly compat: CompatibilityVector;
30
+ readonly receipt: Receipt;
31
+ readonly outcomes: readonly ComponentOutcome[];
32
+ readonly alreadyInstalled: boolean;
33
+ }
34
+ /** Result of installing one plugin (plan + apply). */
35
+ export interface InstallReport extends ApplyResult {
36
+ readonly skillRoots: readonly string[];
37
+ readonly commands: readonly string[];
38
+ readonly mcp: readonly McpReport[];
39
+ readonly hooks: readonly HookReport[];
40
+ readonly agents: readonly AgentReport[];
41
+ }
42
+ /** One live installation and its live registrations, by plan action. */
43
+ export interface LiveInstall {
44
+ record: InstalledPluginRecord;
45
+ readonly mounts: LiveMounts;
46
+ readonly outcomes: Map<string, ComponentOutcome>;
47
+ plan?: Plan;
48
+ /** A first install that failed but left registrations live: listed, never written, withdrawn on removal or the next install. */
49
+ readonly unrecorded?: true;
50
+ }
51
+ /** The outcome of a component whose row is off. */
52
+ export declare function inactive(componentId: string, kind: MountKind): ComponentOutcome;
53
+ /** What an outcome's message says when the person switched the component off. */
54
+ export declare const SWITCHED_OFF = "switched off";
55
+ /** The outcome of a component the person switched off. */
56
+ export declare function switchedOff(componentId: string): ComponentOutcome;
57
+ /** The outcome of a component whose withdrawal failed: it stays live, and switching it off again retries. */
58
+ export declare function failedToSwitchOff(componentId: string, reason: string): ComponentOutcome;
59
+ /** The outcome of a component a failed install could not withdraw: it stays live until removing the plugin (or installing it again) withdraws it. */
60
+ export declare function failedToCleanUp(componentId: string, reason: string): ComponentOutcome;
61
+ /**
62
+ * The installations: the in-memory registry, plan application, undo and
63
+ * teardown, runtime evidence and the durable ledger, every mutation through
64
+ * one queue.
65
+ */
66
+ export declare class Ledger {
67
+ readonly ctx: Context;
68
+ readonly statePath: string;
69
+ readonly dataRoot: string;
70
+ /** Where a withdrawal that failed is recorded (the shared service's faults). */
71
+ private readonly fault?;
72
+ readonly live: Map<string, LiveInstall>;
73
+ readonly plans: Map<string, Plan>;
74
+ readonly mounters: Map<MountKind, Mounter>;
75
+ disposed: boolean;
76
+ queue: Promise<unknown>;
77
+ persistTimer: NodeJS.Timeout | undefined;
78
+ /** Why the ledger could not be read at startup; while set, it is never written. */
79
+ private unreadLedger;
80
+ constructor(ctx: Context, statePath: string, dataRoot: string,
81
+ /** Where a withdrawal that failed is recorded (the shared service's faults). */
82
+ fault?: ((error: unknown) => void) | undefined);
83
+ private readonly faultOf;
84
+ /**
85
+ * Register the mounter of one kind: components of that kind waiting as
86
+ * inactive mount now. The disposer withdraws them back to inactive.
87
+ */
88
+ registerMounter(kind: MountKind, mounter: Mounter): () => void;
89
+ /**
90
+ * Re-apply installed plans; only actions without a live registration run.
91
+ * Called when a mounter appears.
92
+ */
93
+ reapply(): void;
94
+ /**
95
+ * Withdraw every mount of one kind (its row went away): those components
96
+ * wait as inactive. The live registrations say what to withdraw, so a source
97
+ * that no longer scans is withdrawn as well.
98
+ */
99
+ private withdraw;
100
+ /** The plugin as its source scans now, or undefined when it no longer does. */
101
+ private tryScan;
102
+ /**
103
+ * The record's derived fields after its outcomes changed. Without the
104
+ * scanned plugin (its source is gone) only the outcomes are updated.
105
+ */
106
+ private refreshRecord;
107
+ /** Scan one plugin without writing anything. */
108
+ scan(root: string, source?: string): ForeignPlugin;
109
+ /** List current installations in stable name order. */
110
+ list(): readonly InstalledPluginRecord[];
111
+ exclusive<T>(operation: () => Promise<T>): Promise<T>;
112
+ restoreNow(): Promise<void>;
113
+ /** Keep a record that could not be restored visible, with the reason. */
114
+ private keepUnrestored;
115
+ planNow(root: string, source?: string): Plan;
116
+ applyNow(plan: Plan): Promise<ApplyResult>;
117
+ undoNow(receiptId: string): Promise<boolean>;
118
+ /**
119
+ * Switch one component of an installed plugin off (its registrations are
120
+ * released and it stays off across restarts) or on again (it mounts as at
121
+ * install). Returns whether anything changed.
122
+ */
123
+ setEnabledNow(pluginId: string, componentId: string, enabled: boolean): Promise<boolean>;
124
+ /** Release one installation without deciding whether the ledger survives. */
125
+ teardown(id: string): Promise<boolean>;
126
+ /** Record one runtime observation; the component's status follows its evidence. */
127
+ observe(componentId: string, observation: Observation | {
128
+ readonly clear: string;
129
+ }): void;
130
+ scanRoot(root: string, source?: string): ForeignPlugin;
131
+ private buildRecord;
132
+ report(result: ApplyResult): InstallReport;
133
+ allCommandNames(excludePluginId?: string): Set<string>;
134
+ private assertAlive;
135
+ private persistSoon;
136
+ /** Write the ledger, or try again shortly when the write fails transiently. */
137
+ persist(): void;
138
+ private writeLedger;
139
+ }
140
+ /** The directory a skill provider root must contain for this skill body. */
141
+ export declare function skillRootOf(bodyPath: string): string;
142
+ /** Project the current component outcomes into the workbench mount list. */
143
+ export declare function mountsFor(plugin: ForeignPlugin, outcomes: ReadonlyMap<string, ComponentOutcome>): MountRecord[];