@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,322 @@
1
+ import { dshService } from '../dsh/host.js';
2
+ import { CATALOG_CALL_TOOL } from '../mcp/catalog.js';
3
+ import { publicToolName } from '../mcp/policy.js';
4
+ import { startActivation } from '../dsh/subagents.js';
5
+ import { messageOf } from '../shared/util.js';
6
+ const PATH_PLACEHOLDERS = ['CLAUDE_PROJECT_DIR', 'CLAUDE_PLUGIN_ROOT', 'CLAUDE_PLUGIN_DATA', 'PLUGIN_ROOT', 'PLUGIN_DATA'];
7
+ /** Executes handlers against the host. */
8
+ export class HandlerRunner {
9
+ ctx;
10
+ shell;
11
+ settingsEnv;
12
+ toolPolicy;
13
+ /**
14
+ * @param settingsEnv - the `env` of the harness settings in effect for the
15
+ * event's agent, under the hook-specific variables.
16
+ */
17
+ /**
18
+ * @param toolPolicy - the MCP row's tool policy (`McpApi.toolPolicy`), which an `mcp_tool` hook's call obeys as a
19
+ * model's call does; without the row no MCP tool is mounted, so nothing needs it.
20
+ */
21
+ constructor(ctx, shell, settingsEnv = () => ({}), toolPolicy = () => undefined) {
22
+ this.ctx = ctx;
23
+ this.shell = shell;
24
+ this.settingsEnv = settingsEnv;
25
+ this.toolPolicy = toolPolicy;
26
+ }
27
+ /** The environment every command handler of a source receives. */
28
+ environment(places, kind, agent) {
29
+ const posix = (value) => value.replace(/\\/gu, '/');
30
+ const env = {
31
+ ...this.settingsEnv(agent),
32
+ CLAUDE_PROJECT_DIR: posix(places.projectDir),
33
+ CLAUDE_PLUGIN_ROOT: posix(places.pluginRoot),
34
+ CLAUDE_PLUGIN_DATA: posix(places.dataDir),
35
+ PLUGIN_ROOT: posix(places.pluginRoot),
36
+ PLUGIN_DATA: posix(places.dataDir),
37
+ CLAUDE_ENV_FILE: kind === 'powershell' ? undefined : places.envFile,
38
+ };
39
+ for (const [key, value] of Object.entries(places.options)) {
40
+ env[`CLAUDE_PLUGIN_OPTION_${key.toUpperCase().replace(/[^A-Z0-9]+/gu, '_')}`] = value;
41
+ }
42
+ return env;
43
+ }
44
+ /** Run a command handler. */
45
+ async command(handler, request) {
46
+ const { places } = request;
47
+ const stdin = `${JSON.stringify(request.payload)}${request.dialect === 'claude-code' ? '\n' : ''}`;
48
+ const base = { cwd: places.cwd, stdin, ...(request.timeoutMs !== undefined ? { timeoutMs: request.timeoutMs } : {}), signal: request.signal };
49
+ const command = process.platform === 'win32' && handler.commandWindows !== undefined ? handler.commandWindows : handler.command;
50
+ let outcome;
51
+ if (handler.args !== undefined) {
52
+ const substitute = (value) => substituteExec(value, places);
53
+ outcome = await this.shell.runExec(substitute(command), handler.args.map(substitute), { ...base, env: this.environment(places, 'exec', request.agent) });
54
+ }
55
+ else {
56
+ if (/\$\{user_config\./u.test(command)) {
57
+ return { stdout: '', stderr: '', durationMs: 0, failure: { kind: 'start', message: 'a shell-form plugin hook command references ${user_config.*}; use CLAUDE_PLUGIN_OPTION_<KEY> or exec form' } };
58
+ }
59
+ const kind = handler.shell ?? this.shell.defaultKind;
60
+ const line = kind === 'powershell' ? powershellPlaceholders(command) : command;
61
+ outcome = await this.shell.runShell(line, kind, { ...base, env: this.environment(places, kind, request.agent) });
62
+ }
63
+ if (outcome.startError !== undefined)
64
+ return { stdout: '', stderr: outcome.startError, durationMs: outcome.durationMs, failure: { kind: 'start', message: `failed to start: ${outcome.startError}` } };
65
+ if (outcome.timedOut)
66
+ return { stdout: outcome.stdout, stderr: outcome.stderr, durationMs: outcome.durationMs, failure: { kind: 'timeout', message: `timed out after ${String(request.timeoutMs)}ms` } };
67
+ if (outcome.cancelled)
68
+ return { stdout: '', stderr: '', durationMs: outcome.durationMs, failure: { kind: 'cancelled', message: 'cancelled' } };
69
+ return {
70
+ ...(outcome.exitCode !== undefined ? { exitCode: outcome.exitCode } : {}),
71
+ stdout: outcome.stdout,
72
+ stderr: outcome.stderr,
73
+ suspectCapture: outcome.suspectCapture,
74
+ durationMs: outcome.durationMs,
75
+ };
76
+ }
77
+ /** Run an HTTP handler. */
78
+ async http(handler, request) {
79
+ const started = performance.now();
80
+ const elapsed = () => Math.round(performance.now() - started);
81
+ const allowed = new Set(handler.allowedEnvVars ?? []);
82
+ const interpolate = (value) => value.replace(/\$\{([A-Za-z_][A-Za-z0-9_]*)\}|\$([A-Za-z_][A-Za-z0-9_]*)/gu, (_match, braced, bare) => {
83
+ const name = braced ?? bare ?? '';
84
+ return allowed.has(name) ? process.env[name] ?? '' : '';
85
+ });
86
+ const signals = [request.signal, ...(request.timeoutMs !== undefined ? [AbortSignal.timeout(request.timeoutMs)] : [])];
87
+ try {
88
+ const response = await fetch(handler.url, {
89
+ method: 'POST',
90
+ headers: { 'content-type': 'application/json', ...Object.fromEntries(Object.entries(handler.headers ?? {}).map(([key, value]) => [key, interpolate(value)])) },
91
+ body: JSON.stringify(request.payload),
92
+ signal: AbortSignal.any(signals),
93
+ });
94
+ const body = await response.text();
95
+ if (!response.ok)
96
+ return { stdout: '', stderr: body, durationMs: elapsed(), failure: { kind: 'transport', message: `HTTP ${String(response.status)} from ${handler.url}` } };
97
+ const trimmed = body.trim();
98
+ if (trimmed.length > 0 && !isJsonObject(trimmed)) {
99
+ return { stdout: '', stderr: body, durationMs: elapsed(), failure: { kind: 'transport', message: 'the response body is neither empty nor a JSON object' } };
100
+ }
101
+ return { exitCode: 0, stdout: trimmed, stderr: '', durationMs: elapsed() };
102
+ }
103
+ catch (error) {
104
+ if (request.signal.aborted)
105
+ return { stdout: '', stderr: '', durationMs: elapsed(), failure: { kind: 'cancelled', message: 'cancelled' } };
106
+ const timedOut = error instanceof Error && (error.name === 'TimeoutError' || error.name === 'AbortError');
107
+ return { stdout: '', stderr: '', durationMs: elapsed(), failure: timedOut ? { kind: 'timeout', message: `timed out after ${String(request.timeoutMs)}ms` } : { kind: 'transport', message: `request to ${handler.url} failed: ${messageOf(error)}` } };
108
+ }
109
+ }
110
+ /**
111
+ * Run an MCP tool handler: the tool the MCP row mounted directly
112
+ * (`mcp__<server>__<tool>`) or, for a server the capability catalog serves,
113
+ * the catalog's `capability_call` with the entry `mcp:<server>/<tool>`.
114
+ * Codex runs such a hook on an already-connected server only, so a server
115
+ * that is neither is reported as not connected.
116
+ * @param serverName - the server as registered (`McpApi.hookServer`); undefined when neither the hook's plugin nor
117
+ * the user's configuration has a mounted server of the name it gives.
118
+ */
119
+ async mcpTool(handler, request, serverName) {
120
+ if (serverName === undefined) {
121
+ return { stdout: '', stderr: '', durationMs: 0, failure: { kind: 'transport', message: `MCP server "${handler.server}" is not a connected server of this plugin or of the user's configuration` } };
122
+ }
123
+ const started = performance.now();
124
+ const elapsed = () => Math.round(performance.now() - started);
125
+ const tools = dshService(this.ctx, 'tools');
126
+ const direct = publicToolName(serverName, handler.tool);
127
+ const viaCatalog = tools?.get(direct) === undefined ? tools?.get(CATALOG_CALL_TOOL) : undefined;
128
+ const toolName = viaCatalog === undefined ? direct : CATALOG_CALL_TOOL;
129
+ const definition = viaCatalog ?? tools?.get(direct);
130
+ if (definition === undefined)
131
+ return { stdout: '', stderr: '', durationMs: 0, failure: { kind: 'transport', message: `MCP tool ${direct} is not connected` } };
132
+ const input = fillTemplate(handler.input ?? {}, request.payload);
133
+ const args = viaCatalog === undefined ? input : { id: `mcp:${serverName}/${handler.tool}`, arguments: input };
134
+ // The server's own filters hold for a hook as for the model: Codex runs hooks only on "policy-allowed tools", and a
135
+ // filtered tool is not registered there, so here it is not available. Codex invokes them "without model-tool
136
+ // approval" (openai/codex#39296; https://developers.openai.com/codex/hooks, "MCP tool hooks": they "don't request
137
+ // tool approval"), the hook itself having passed the trust review, so an approval mode does not stop it.
138
+ const verdict = this.toolPolicy({ name: toolName, arguments: args, agent: request.agent });
139
+ if (verdict?.kind === 'deny')
140
+ return { stdout: '', stderr: '', durationMs: elapsed(), failure: { kind: 'transport', message: `MCP tool ${direct} is not available: ${verdict.reason}` } };
141
+ const signal = request.timeoutMs === undefined ? request.signal : AbortSignal.any([request.signal, AbortSignal.timeout(request.timeoutMs)]);
142
+ try {
143
+ const value = await definition.execute(args, { name: toolName, arguments: args, callId: `hook-${Date.now().toString(36)}`, signal, agent: request.agent });
144
+ const text = definition.output.render(args, value).map(block => block.text ?? '').join('');
145
+ const isError = typeof value === 'object' && value !== null && value.isError === true;
146
+ return isError
147
+ ? { stdout: '', stderr: text, durationMs: elapsed(), failure: { kind: 'transport', message: `MCP tool ${direct} returned an error: ${text.slice(0, 300)}` } }
148
+ : { exitCode: 0, stdout: text, stderr: '', durationMs: elapsed() };
149
+ }
150
+ catch (error) {
151
+ if (request.signal.aborted)
152
+ return { stdout: '', stderr: '', durationMs: elapsed(), failure: { kind: 'cancelled', message: 'cancelled' } };
153
+ return { stdout: '', stderr: '', durationMs: elapsed(), failure: signal.aborted ? { kind: 'timeout', message: `timed out after ${String(request.timeoutMs)}ms` } : { kind: 'transport', message: messageOf(error) } };
154
+ }
155
+ }
156
+ /** Run a prompt handler: one model call that answers `{ ok, reason, impossible }`. */
157
+ async prompt(handler, request) {
158
+ const started = performance.now();
159
+ const elapsed = () => Math.round(performance.now() - started);
160
+ const llm = dshService(this.ctx, 'llm');
161
+ const options = request.agent?.options;
162
+ if (llm === undefined || options?.provider === undefined || options.model === undefined) {
163
+ return { stdout: '', stderr: '', durationMs: 0, failure: { kind: 'start', message: 'no model route is available for prompt hooks in this session' } };
164
+ }
165
+ const signal = request.timeoutMs === undefined ? request.signal : AbortSignal.any([request.signal, AbortSignal.timeout(request.timeoutMs)]);
166
+ try {
167
+ const call = await llm.prepareCall({ provider: options.provider, model: options.model, maxTokens: 1024 }, signal);
168
+ const chunks = [];
169
+ for await (const chunk of call.stream({
170
+ ...call.config,
171
+ messages: [{ role: 'user', content: [{ type: 'text', text: promptText(handler.prompt, request.payload) }], source: { kind: 'harness-forge', event: request.event } }],
172
+ system: VERDICT_SYSTEM,
173
+ purpose: 'hook-evaluation',
174
+ signal,
175
+ })) {
176
+ const text = textDelta(chunk);
177
+ if (text !== undefined)
178
+ chunks.push(text);
179
+ }
180
+ return { exitCode: 0, stdout: '', stderr: '', durationMs: elapsed(), verdict: parseVerdict(chunks.join('')) };
181
+ }
182
+ catch (error) {
183
+ if (request.signal.aborted)
184
+ return { stdout: '', stderr: '', durationMs: elapsed(), failure: { kind: 'cancelled', message: 'cancelled' } };
185
+ return { stdout: '', stderr: '', durationMs: elapsed(), failure: signal.aborted ? { kind: 'timeout', message: `timed out after ${String(request.timeoutMs)}ms` } : { kind: 'transport', message: `prompt hook model call failed: ${messageOf(error)}` } };
186
+ }
187
+ }
188
+ /** Run an agent handler: a delegated agent with tool access that answers `{ ok, reason }`. */
189
+ async agent(handler, request) {
190
+ const started = performance.now();
191
+ const elapsed = () => Math.round(performance.now() - started);
192
+ const subagents = dshService(this.ctx, 'subagents');
193
+ if (subagents === undefined || request.agent === undefined) {
194
+ return { stdout: '', stderr: '', durationMs: 0, failure: { kind: 'start', message: 'agent hooks need the DSH subagent runtime' } };
195
+ }
196
+ const signal = request.timeoutMs === undefined ? request.signal : AbortSignal.any([request.signal, AbortSignal.timeout(request.timeoutMs)]);
197
+ let activation;
198
+ try {
199
+ activation = await startActivation(subagents, {
200
+ parent: request.agent,
201
+ prompt: [{ type: 'text', text: `${promptText(handler.prompt, request.payload)}\n\n${VERDICT_SYSTEM}` }],
202
+ outputSchema: VERDICT_SCHEMA,
203
+ }, { provider: 'spawn', label: `${request.event} hook`, signal, delivery: 'caller' });
204
+ const onAbort = () => { void activation?.dispose(); };
205
+ signal.addEventListener('abort', onAbort, { once: true });
206
+ const result = await activation.result;
207
+ signal.removeEventListener('abort', onAbort);
208
+ const structured = result.structured;
209
+ const verdict = typeof structured === 'object' && structured !== null && typeof structured.ok === 'boolean'
210
+ ? structured
211
+ : parseVerdict((result.output ?? []).map(block => block.type === 'text' ? block.text ?? '' : '').join(''));
212
+ return { exitCode: 0, stdout: '', stderr: '', durationMs: elapsed(), verdict: { ok: verdict.ok, ...(verdict.reason !== undefined ? { reason: verdict.reason } : {}) } };
213
+ }
214
+ catch (error) {
215
+ void activation?.dispose().catch(() => undefined);
216
+ if (request.signal.aborted)
217
+ return { stdout: '', stderr: '', durationMs: elapsed(), failure: { kind: 'cancelled', message: 'cancelled' } };
218
+ return { stdout: '', stderr: '', durationMs: elapsed(), failure: signal.aborted ? { kind: 'timeout', message: `timed out after ${String(request.timeoutMs)}ms` } : { kind: 'transport', message: `agent hook failed: ${messageOf(error)}` } };
219
+ }
220
+ }
221
+ }
222
+ const VERDICT_SYSTEM = 'You evaluate a hook condition for a coding agent. Respond with only a JSON object: {"ok": true} when the condition holds or the action may proceed, or {"ok": false, "reason": "<why>"} when it does not. Add "impossible": true when the condition can never be satisfied.';
223
+ const VERDICT_SCHEMA = {
224
+ type: 'object',
225
+ properties: { ok: { type: 'boolean' }, reason: { type: 'string' } },
226
+ required: ['ok'],
227
+ additionalProperties: false,
228
+ };
229
+ /** `$ARGUMENTS` → the input JSON (`\$` escapes); appended when absent. */
230
+ function promptText(prompt, payload) {
231
+ const json = JSON.stringify(payload);
232
+ let used = false;
233
+ const text = prompt.replace(/\\\$|\$ARGUMENTS\b/gu, (match) => {
234
+ if (match === '\\$')
235
+ return '$';
236
+ used = true;
237
+ return json;
238
+ });
239
+ return used ? text : `${text}\n\n${json}`;
240
+ }
241
+ /** The hook model's `{"ok": …}` answer: the text from its first `{` to its last `}`. */
242
+ export function parseVerdict(text) {
243
+ const start = text.indexOf('{');
244
+ const end = text.lastIndexOf('}');
245
+ if (start !== -1 && end > start) {
246
+ try {
247
+ const value = JSON.parse(text.slice(start, end + 1));
248
+ if (typeof value['ok'] === 'boolean') {
249
+ return {
250
+ ok: value['ok'],
251
+ ...(typeof value['reason'] === 'string' ? { reason: value['reason'] } : {}),
252
+ ...(value['impossible'] === true ? { impossible: true } : {}),
253
+ };
254
+ }
255
+ }
256
+ catch {
257
+ // Fall through.
258
+ }
259
+ }
260
+ return { ok: false, reason: `the hook model did not answer with {"ok": …}: ${text.slice(0, 200)}` };
261
+ }
262
+ function textDelta(chunk) {
263
+ if (typeof chunk !== 'object' || chunk === null)
264
+ return undefined;
265
+ const value = chunk;
266
+ if (value.type === 'text-delta' && typeof value.text === 'string')
267
+ return value.text;
268
+ if (value.type === 'text-delta' && typeof value.delta === 'string')
269
+ return value.delta;
270
+ if (value.type === 'text' && typeof value.text === 'string')
271
+ return value.text;
272
+ return undefined;
273
+ }
274
+ /** Exec form: placeholders are substituted as plain strings. */
275
+ function substituteExec(value, places) {
276
+ const posix = (path) => path.replace(/\\/gu, '/');
277
+ const values = {
278
+ CLAUDE_PROJECT_DIR: posix(places.projectDir),
279
+ CLAUDE_PLUGIN_ROOT: posix(places.pluginRoot),
280
+ CLAUDE_PLUGIN_DATA: posix(places.dataDir),
281
+ PLUGIN_ROOT: posix(places.pluginRoot),
282
+ PLUGIN_DATA: posix(places.dataDir),
283
+ };
284
+ return value
285
+ .replace(/\$\{user_config\.([A-Za-z0-9_.-]+)\}/gu, (_match, key) => places.options[key] ?? '')
286
+ .replace(/\$\{([A-Z_]+)\}/gu, (match, name) => values[name] ?? match);
287
+ }
288
+ /** PowerShell shell form: path placeholders become `${env:NAME}`. */
289
+ export function powershellPlaceholders(command) {
290
+ let out = command;
291
+ for (const name of PATH_PLACEHOLDERS)
292
+ out = out.split(`\${${name}}`).join(`\${env:${name}}`);
293
+ return out;
294
+ }
295
+ /** `${a.b}` fields from the input; a placeholder filling a whole value keeps its JSON type. */
296
+ export function fillTemplate(template, payload) {
297
+ const lookup = (path) => path.split('.').reduce((value, key) => (typeof value === 'object' && value !== null ? value[key] : undefined), payload);
298
+ if (typeof template === 'string') {
299
+ const whole = /^\$\{([A-Za-z0-9_.]+)\}$/u.exec(template);
300
+ if (whole !== null)
301
+ return lookup(whole[1] ?? '');
302
+ return template.replace(/\$\{([A-Za-z0-9_.]+)\}/gu, (_match, path) => {
303
+ const value = lookup(path);
304
+ return value === undefined ? '' : typeof value === 'string' ? value : JSON.stringify(value);
305
+ });
306
+ }
307
+ if (Array.isArray(template))
308
+ return template.map(item => fillTemplate(item, payload));
309
+ if (typeof template === 'object' && template !== null) {
310
+ return Object.fromEntries(Object.entries(template).map(([key, value]) => [key, fillTemplate(value, payload)]));
311
+ }
312
+ return template;
313
+ }
314
+ function isJsonObject(text) {
315
+ try {
316
+ const value = JSON.parse(text);
317
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
318
+ }
319
+ catch {
320
+ return false;
321
+ }
322
+ }
@@ -0,0 +1,28 @@
1
+ /**
2
+ * The commands one shell input runs, as Claude Code's `if` matching sees
3
+ * them: every subcommand of `&&`, `||`, `;`, `|`, `&` and newlines, every
4
+ * command inside `$(…)` and backticks, with leading `VAR=value` assignments
5
+ * stripped.
6
+ * @module @kirkchinese/harness-forge
7
+ */
8
+ /** The commands found in one input. */
9
+ export interface ShellCommands {
10
+ readonly commands: readonly string[];
11
+ /** The input expands something at run time: `$(…)`, backticks or `$VAR`. */
12
+ readonly dynamic: boolean;
13
+ }
14
+ /**
15
+ * What a lone PowerShell `&` (not part of `&&`) is: the call operator before a
16
+ * command (`& ./x.ps1`), PowerShell 7's background operator after one
17
+ * (https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_operators#background-operator-),
18
+ * or, right after `>` or `<`, part of a merge such as `2>&1` (undefined).
19
+ * @param started - whether a command has begun before it.
20
+ */
21
+ export declare function powershellAmpersand(previous: string, next: string, started: boolean): 'call' | 'background' | undefined;
22
+ /**
23
+ * Split a shell input into the commands it runs.
24
+ * @param shell - the shell that reads it: in PowerShell `$null`, `$true` and `$false` are constants, no expansion.
25
+ * @returns undefined when the input cannot be read reliably (unbalanced
26
+ * quotes or substitutions), in which case a caller treats every rule as a match.
27
+ */
28
+ export declare function shellCommands(input: string, shell?: 'bash' | 'powershell'): ShellCommands | undefined;
@@ -0,0 +1,241 @@
1
+ /**
2
+ * The commands one shell input runs, as Claude Code's `if` matching sees
3
+ * them: every subcommand of `&&`, `||`, `;`, `|`, `&` and newlines, every
4
+ * command inside `$(…)` and backticks, with leading `VAR=value` assignments
5
+ * stripped.
6
+ * @module @kirkchinese/harness-forge
7
+ */
8
+ /**
9
+ * PowerShell's constant automatic variables, which expand to nothing a caller
10
+ * chooses (https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_automatic_variables).
11
+ */
12
+ const POWERSHELL_CONSTANT = /^\$(?:null|true|false)(?![\w:])/iu;
13
+ /**
14
+ * What a lone PowerShell `&` (not part of `&&`) is: the call operator before a
15
+ * command (`& ./x.ps1`), PowerShell 7's background operator after one
16
+ * (https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_operators#background-operator-),
17
+ * or, right after `>` or `<`, part of a merge such as `2>&1` (undefined).
18
+ * @param started - whether a command has begun before it.
19
+ */
20
+ export function powershellAmpersand(previous, next, started) {
21
+ if (next === '&' || previous === '&' || previous === '>' || previous === '<')
22
+ return undefined;
23
+ return started ? 'background' : 'call';
24
+ }
25
+ /**
26
+ * Split a shell input into the commands it runs.
27
+ * @param shell - the shell that reads it: in PowerShell `$null`, `$true` and `$false` are constants, no expansion.
28
+ * @returns undefined when the input cannot be read reliably (unbalanced
29
+ * quotes or substitutions), in which case a caller treats every rule as a match.
30
+ */
31
+ export function shellCommands(input, shell = 'bash') {
32
+ const commands = [];
33
+ let dynamic = false;
34
+ const expands = (text, at) => /[A-Za-z_{]/u.test(text[at + 1] ?? '') && !(shell === 'powershell' && POWERSHELL_CONSTANT.test(text.slice(at)));
35
+ const visit = (text, depth) => {
36
+ if (depth > 8)
37
+ return false;
38
+ let current = '';
39
+ const flush = () => {
40
+ const command = stripAssignments(current.trim());
41
+ if (command.length > 0)
42
+ commands.push(command);
43
+ current = '';
44
+ };
45
+ for (let index = 0; index < text.length; index++) {
46
+ const char = text[index] ?? '';
47
+ const next = text[index + 1] ?? '';
48
+ if (char === '\\') {
49
+ current += char + next;
50
+ index++;
51
+ continue;
52
+ }
53
+ if (char === "'") {
54
+ const end = text.indexOf("'", index + 1);
55
+ if (end === -1)
56
+ return false;
57
+ current += text.slice(index, end + 1);
58
+ index = end;
59
+ continue;
60
+ }
61
+ if (char === '"') {
62
+ let end = index + 1;
63
+ let quoted = '';
64
+ for (; end < text.length; end++) {
65
+ const inner = text[end] ?? '';
66
+ if (inner === '\\') {
67
+ quoted += inner + (text[end + 1] ?? '');
68
+ end++;
69
+ continue;
70
+ }
71
+ if (inner === '"')
72
+ break;
73
+ if (inner === '$' && text[end + 1] === '(') {
74
+ const close = matchParen(text, end + 1);
75
+ if (close === -1)
76
+ return false;
77
+ dynamic = true;
78
+ if (!visit(text.slice(end + 2, close), depth + 1))
79
+ return false;
80
+ quoted += text.slice(end, close + 1);
81
+ end = close;
82
+ continue;
83
+ }
84
+ if (inner === '`') {
85
+ const close = text.indexOf('`', end + 1);
86
+ if (close === -1)
87
+ return false;
88
+ dynamic = true;
89
+ if (!visit(text.slice(end + 1, close), depth + 1))
90
+ return false;
91
+ quoted += text.slice(end, close + 1);
92
+ end = close;
93
+ continue;
94
+ }
95
+ if (inner === '$' && expands(text, end))
96
+ dynamic = true;
97
+ quoted += inner;
98
+ }
99
+ if (end >= text.length)
100
+ return false;
101
+ current += `"${quoted}"`;
102
+ index = end;
103
+ continue;
104
+ }
105
+ if (char === '$' && next === '(') {
106
+ const close = matchParen(text, index + 1);
107
+ if (close === -1)
108
+ return false;
109
+ dynamic = true;
110
+ if (!visit(text.slice(index + 2, close), depth + 1))
111
+ return false;
112
+ current += text.slice(index, close + 1);
113
+ index = close;
114
+ continue;
115
+ }
116
+ if (char === '`') {
117
+ const close = text.indexOf('`', index + 1);
118
+ if (close === -1)
119
+ return false;
120
+ dynamic = true;
121
+ if (!visit(text.slice(index + 1, close), depth + 1))
122
+ return false;
123
+ current += text.slice(index, close + 1);
124
+ index = close;
125
+ continue;
126
+ }
127
+ if (char === '$' && expands(text, index))
128
+ dynamic = true;
129
+ if ((char === '&' && next === '&') || (char === '|' && next === '|')) {
130
+ flush();
131
+ index++;
132
+ continue;
133
+ }
134
+ // A lone `&`: bash's background operator (not `&>` or `>&`); in PowerShell the call operator or the background
135
+ // operator (see `powershellAmpersand`), either way where a command starts or ends.
136
+ const ampersand = char === '&' && (shell === 'powershell'
137
+ ? powershellAmpersand(text[index - 1] ?? '', next, current.trim().length > 0) !== undefined
138
+ : next !== '>' && text[index - 1] !== '>');
139
+ if (char === ';' || char === '|' || char === '\n' || ampersand) {
140
+ flush();
141
+ continue;
142
+ }
143
+ // Grouping: `( cmd )` and `{ cmd; }` run the commands inside them.
144
+ if ((char === '(' || char === '{') && current.trim().length === 0)
145
+ continue;
146
+ if ((char === ')' || char === '}') && !/[({]/u.test(current)) {
147
+ flush();
148
+ continue;
149
+ }
150
+ current += char;
151
+ }
152
+ flush();
153
+ return true;
154
+ };
155
+ return visit(input, 0) ? { commands, dynamic } : undefined;
156
+ }
157
+ /**
158
+ * Remove leading `NAME=value` words that whitespace follows. A scan, not a
159
+ * pattern: a pattern for this backtracks exponentially on an assignment that
160
+ * nothing follows, and froze DSH.
161
+ */
162
+ function stripAssignments(command) {
163
+ let start = 0;
164
+ for (;;) {
165
+ const end = assignmentEnd(command, start);
166
+ if (end === undefined || end >= command.length || !/\s/u.test(command[end] ?? ''))
167
+ return command.slice(start);
168
+ start = end;
169
+ while (start < command.length && /\s/u.test(command[start] ?? ''))
170
+ start++;
171
+ }
172
+ }
173
+ /** Where the `NAME=value` word at `start` ends, or undefined when none starts there (or a quote never closes). */
174
+ function assignmentEnd(text, start) {
175
+ let index = start;
176
+ if (!/[A-Za-z_]/u.test(text[index] ?? ''))
177
+ return undefined;
178
+ while (/[A-Za-z0-9_]/u.test(text[index] ?? ''))
179
+ index++;
180
+ if (text[index] !== '=')
181
+ return undefined;
182
+ index++;
183
+ while (index < text.length) {
184
+ const char = text[index] ?? '';
185
+ if (/\s/u.test(char))
186
+ break;
187
+ if (char === "'") {
188
+ const close = text.indexOf("'", index + 1);
189
+ if (close === -1)
190
+ return undefined;
191
+ index = close + 1;
192
+ }
193
+ else if (char === '"') {
194
+ index++;
195
+ while (index < text.length && text[index] !== '"')
196
+ index += text[index] === '\\' ? 2 : 1;
197
+ if (index >= text.length)
198
+ return undefined;
199
+ index++;
200
+ }
201
+ else {
202
+ index += char === '\\' ? 2 : 1;
203
+ }
204
+ }
205
+ return Math.min(index, text.length);
206
+ }
207
+ /** Index of the `)` closing the `(` at `open`, honoring nesting and quotes. */
208
+ function matchParen(text, open) {
209
+ let depth = 0;
210
+ for (let index = open; index < text.length; index++) {
211
+ const char = text[index];
212
+ if (char === '\\') {
213
+ index++;
214
+ continue;
215
+ }
216
+ if (char === "'") {
217
+ const end = text.indexOf("'", index + 1);
218
+ if (end === -1)
219
+ return -1;
220
+ index = end;
221
+ continue;
222
+ }
223
+ if (char === '"') {
224
+ let end = index + 1;
225
+ while (end < text.length && text[end] !== '"')
226
+ end += text[end] === '\\' ? 2 : 1;
227
+ if (end >= text.length)
228
+ return -1;
229
+ index = end;
230
+ continue;
231
+ }
232
+ if (char === '(')
233
+ depth++;
234
+ if (char === ')') {
235
+ depth--;
236
+ if (depth === 0)
237
+ return index;
238
+ }
239
+ }
240
+ return -1;
241
+ }
@@ -0,0 +1,44 @@
1
+ import { type ProcessOutcome } from './process.js';
2
+ /** How one process runs. */
3
+ export interface RunOptions {
4
+ readonly cwd: string;
5
+ readonly env?: Readonly<Record<string, string | undefined>>;
6
+ readonly stdin?: string;
7
+ readonly timeoutMs?: number;
8
+ readonly signal?: AbortSignal;
9
+ }
10
+ /** The executors foreign code runs with. */
11
+ export interface ForeignShell {
12
+ /** Git Bash, bash, or `/bin/sh` without it; undefined on Windows without Git Bash. */
13
+ readonly bash?: string;
14
+ /** `pwsh.exe` when installed, else `powershell.exe` (`pwsh` elsewhere). */
15
+ readonly powershell: string;
16
+ /** The shell a shell-form command uses when none is named. */
17
+ readonly defaultKind: 'bash' | 'powershell';
18
+ /** The environment foreign processes start from, with `extra` applied. */
19
+ environment(extra?: Readonly<Record<string, string | undefined>>): NodeJS.ProcessEnv;
20
+ /** Run a shell-form command line. */
21
+ runShell(command: string, kind: 'bash' | 'powershell', options: RunOptions): Promise<ProcessOutcome>;
22
+ /** Spawn an executable directly with an argument vector (exec form). */
23
+ runExec(file: string, args: readonly string[], options: RunOptions): Promise<ProcessOutcome>;
24
+ }
25
+ /** Locate the POSIX shell foreign hooks expect. */
26
+ export declare function findPosixShell(env?: NodeJS.ProcessEnv): {
27
+ shell: string;
28
+ pathPrefix: string[];
29
+ } | undefined;
30
+ /** PowerShell 7 when it is on PATH, else Windows PowerShell. */
31
+ export declare function findPowerShell(env?: NodeJS.ProcessEnv): string;
32
+ /**
33
+ * Hook scripts call `python3`. On Windows that name is usually the Microsoft
34
+ * Store placeholder while the real interpreter is `python`; a one-line shim
35
+ * makes `python3` run it, so Python hooks work without changing the machine.
36
+ * @returns the shim directory to put first on PATH, when one is needed.
37
+ */
38
+ export declare function python3Shim(shimRoot: string, env?: NodeJS.ProcessEnv): string | undefined;
39
+ /**
40
+ * Build the executors.
41
+ * @param shimRoot - writable directory for command shims (see {@link python3Shim}) and the files that hold hook input.
42
+ * @param onLeftover - told of a hook input file that could not be removed.
43
+ */
44
+ export declare function createForeignShell(base?: NodeJS.ProcessEnv, shimRoot?: string, onLeftover?: (path: string) => void): ForeignShell;