@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.
- package/LICENSE +21 -0
- package/README.md +42 -2
- package/assets/icon.svg +12 -0
- package/cordis.patch.yml +28 -0
- package/lib/agents/presets.d.ts +91 -0
- package/lib/agents/presets.js +282 -0
- package/lib/agents/profiles.d.ts +58 -0
- package/lib/agents/profiles.js +278 -0
- package/lib/agents/row.d.ts +17 -0
- package/lib/agents/row.js +146 -0
- package/lib/client/styles.d.ts +8 -0
- package/lib/client/styles.js +89 -0
- package/lib/client/typert.d.ts +14 -0
- package/lib/client/typert.js +110 -0
- package/lib/client.js +22500 -0
- package/lib/commands/definition.d.ts +40 -0
- package/lib/commands/definition.js +113 -0
- package/lib/commands/output-styles.d.ts +42 -0
- package/lib/commands/output-styles.js +152 -0
- package/lib/commands/row.d.ts +9 -0
- package/lib/commands/row.js +157 -0
- package/lib/context/instructions.d.ts +32 -0
- package/lib/context/instructions.js +88 -0
- package/lib/context/row.d.ts +16 -0
- package/lib/context/row.js +17 -0
- package/lib/dsh/commands.d.ts +30 -0
- package/lib/dsh/commands.js +61 -0
- package/lib/dsh/host.d.ts +107 -0
- package/lib/dsh/host.js +214 -0
- package/lib/dsh/model-route.d.ts +21 -0
- package/lib/dsh/model-route.js +37 -0
- package/lib/dsh/session-records.d.ts +78 -0
- package/lib/dsh/session-records.js +36 -0
- package/lib/dsh/subagents.d.ts +46 -0
- package/lib/dsh/subagents.js +14 -0
- package/lib/forge/contract.d.ts +231 -0
- package/lib/forge/contract.js +43 -0
- package/lib/forge/ledger.d.ts +143 -0
- package/lib/forge/ledger.js +733 -0
- package/lib/forge/live-mounts.d.ts +45 -0
- package/lib/forge/live-mounts.js +78 -0
- package/lib/forge/marketplace-install.d.ts +3 -0
- package/lib/forge/marketplace-install.js +64 -0
- package/lib/forge/npm.d.ts +31 -0
- package/lib/forge/npm.js +60 -0
- package/lib/forge/projects.d.ts +94 -0
- package/lib/forge/projects.js +336 -0
- package/lib/forge/receipts.d.ts +5 -0
- package/lib/forge/receipts.js +31 -0
- package/lib/forge/row.d.ts +32 -0
- package/lib/forge/row.js +59 -0
- package/lib/forge/service.d.ts +105 -0
- package/lib/forge/service.js +274 -0
- package/lib/forge/settings.d.ts +41 -0
- package/lib/forge/settings.js +115 -0
- package/lib/forge/state.d.ts +69 -0
- package/lib/forge/state.js +150 -0
- package/lib/forge/trust.d.ts +48 -0
- package/lib/forge/trust.js +107 -0
- package/lib/forge/turns.d.ts +13 -0
- package/lib/forge/turns.js +56 -0
- package/lib/hooks/broker/engine.d.ts +112 -0
- package/lib/hooks/broker/engine.js +728 -0
- package/lib/hooks/broker/helpers.d.ts +10 -0
- package/lib/hooks/broker/helpers.js +22 -0
- package/lib/hooks/broker/lifecycle.d.ts +65 -0
- package/lib/hooks/broker/lifecycle.js +342 -0
- package/lib/hooks/broker/session-events.d.ts +22 -0
- package/lib/hooks/broker/session-events.js +196 -0
- package/lib/hooks/broker/tools.d.ts +52 -0
- package/lib/hooks/broker/tools.js +424 -0
- package/lib/hooks/broker/types.d.ts +262 -0
- package/lib/hooks/broker/types.js +1 -0
- package/lib/hooks/broker.d.ts +80 -0
- package/lib/hooks/broker.js +95 -0
- package/lib/hooks/codex-user.d.ts +5 -0
- package/lib/hooks/codex-user.js +109 -0
- package/lib/hooks/condition.d.ts +11 -0
- package/lib/hooks/condition.js +181 -0
- package/lib/hooks/config.d.ts +85 -0
- package/lib/hooks/config.js +150 -0
- package/lib/hooks/matcher.d.ts +20 -0
- package/lib/hooks/matcher.js +39 -0
- package/lib/hooks/notice.d.ts +17 -0
- package/lib/hooks/notice.js +39 -0
- package/lib/hooks/output.d.ts +56 -0
- package/lib/hooks/output.js +214 -0
- package/lib/hooks/permissions.d.ts +14 -0
- package/lib/hooks/permissions.js +109 -0
- package/lib/hooks/process.d.ts +47 -0
- package/lib/hooks/process.js +134 -0
- package/lib/hooks/row.d.ts +17 -0
- package/lib/hooks/row.js +94 -0
- package/lib/hooks/runner.d.ts +85 -0
- package/lib/hooks/runner.js +293 -0
- package/lib/hooks/shell-commands.d.ts +19 -0
- package/lib/hooks/shell-commands.js +177 -0
- package/lib/hooks/shell.d.ts +43 -0
- package/lib/hooks/shell.js +126 -0
- package/lib/hooks/transcript.d.ts +28 -0
- package/lib/hooks/transcript.js +141 -0
- package/lib/hooks/vocabulary.d.ts +57 -0
- package/lib/hooks/vocabulary.js +364 -0
- package/lib/index.d.ts +31 -0
- package/lib/index.js +287 -0
- package/lib/mcp/auth.d.ts +35 -0
- package/lib/mcp/auth.js +178 -0
- package/lib/mcp/catalog.d.ts +36 -0
- package/lib/mcp/catalog.js +61 -0
- package/lib/mcp/mount.d.ts +75 -0
- package/lib/mcp/mount.js +217 -0
- package/lib/mcp/remote.d.ts +45 -0
- package/lib/mcp/remote.js +143 -0
- package/lib/mcp/row.d.ts +9 -0
- package/lib/mcp/row.js +131 -0
- package/lib/mods/bundler.d.ts +38 -0
- package/lib/mods/bundler.js +157 -0
- package/lib/mods/chain.d.ts +103 -0
- package/lib/mods/chain.js +436 -0
- package/lib/mods/claude.d.ts +27 -0
- package/lib/mods/claude.js +56 -0
- package/lib/mods/engine.d.ts +160 -0
- package/lib/mods/engine.js +701 -0
- package/lib/mods/expect.d.ts +8 -0
- package/lib/mods/expect.js +248 -0
- package/lib/mods/host.d.ts +105 -0
- package/lib/mods/host.js +462 -0
- package/lib/mods/loader.d.ts +53 -0
- package/lib/mods/loader.js +227 -0
- package/lib/mods/ops.d.ts +13 -0
- package/lib/mods/ops.js +117 -0
- package/lib/mods/row.d.ts +9 -0
- package/lib/mods/row.js +77 -0
- package/lib/mods/runtime.d.ts +60 -0
- package/lib/mods/runtime.js +133 -0
- package/lib/mods/service/commands.d.ts +17 -0
- package/lib/mods/service/commands.js +121 -0
- package/lib/mods/service/drawings.d.ts +36 -0
- package/lib/mods/service/drawings.js +64 -0
- package/lib/mods/service/sessions.d.ts +63 -0
- package/lib/mods/service/sessions.js +345 -0
- package/lib/mods/service/tools.d.ts +32 -0
- package/lib/mods/service/tools.js +253 -0
- package/lib/mods/service/turns.d.ts +32 -0
- package/lib/mods/service/turns.js +161 -0
- package/lib/mods/service/types.d.ts +151 -0
- package/lib/mods/service/types.js +1 -0
- package/lib/mods/service.d.ts +72 -0
- package/lib/mods/service.js +104 -0
- package/lib/mods/surfaces.d.ts +93 -0
- package/lib/mods/surfaces.js +309 -0
- package/lib/mods/values.d.ts +30 -0
- package/lib/mods/values.js +95 -0
- package/lib/opencode/bun.d.ts +40 -0
- package/lib/opencode/bun.js +156 -0
- package/lib/opencode/convert.d.ts +53 -0
- package/lib/opencode/convert.js +255 -0
- package/lib/opencode/row.d.ts +9 -0
- package/lib/opencode/row.js +86 -0
- package/lib/opencode/runtime/core.d.ts +74 -0
- package/lib/opencode/runtime/core.js +249 -0
- package/lib/opencode/runtime/events.d.ts +80 -0
- package/lib/opencode/runtime/events.js +281 -0
- package/lib/opencode/runtime/mount.d.ts +27 -0
- package/lib/opencode/runtime/mount.js +283 -0
- package/lib/opencode/runtime/server.d.ts +27 -0
- package/lib/opencode/runtime/server.js +353 -0
- package/lib/opencode/runtime/types.d.ts +109 -0
- package/lib/opencode/runtime/types.js +1 -0
- package/lib/opencode/runtime.d.ts +55 -0
- package/lib/opencode/runtime.js +79 -0
- package/lib/porting/port-gap.d.ts +30 -0
- package/lib/porting/port-gap.js +122 -0
- package/lib/porting/port-sessions.d.ts +41 -0
- package/lib/porting/port-sessions.js +98 -0
- package/lib/porting/prompt.d.ts +23 -0
- package/lib/porting/prompt.js +49 -0
- package/lib/porting/row.d.ts +16 -0
- package/lib/porting/row.js +25 -0
- package/lib/porting/verify-port.d.ts +53 -0
- package/lib/porting/verify-port.js +104 -0
- package/lib/presets/fs-search.d.ts +25 -0
- package/lib/presets/fs-search.js +17 -0
- package/lib/presets/tool-filter.d.ts +35 -0
- package/lib/presets/tool-filter.js +91 -0
- package/lib/sessions/claude.d.ts +29 -0
- package/lib/sessions/claude.js +83 -0
- package/lib/sessions/codex.d.ts +30 -0
- package/lib/sessions/codex.js +303 -0
- package/lib/sessions/opencode.d.ts +32 -0
- package/lib/sessions/opencode.js +320 -0
- package/lib/sessions/row.d.ts +14 -0
- package/lib/sessions/row.js +35 -0
- package/lib/shared/invocation.d.ts +169 -0
- package/lib/shared/invocation.js +325 -0
- package/lib/shared/render.d.ts +72 -0
- package/lib/shared/render.js +588 -0
- package/lib/shared/util.d.ts +21 -0
- package/lib/shared/util.js +32 -0
- package/lib/skills/bundled.d.ts +3 -0
- package/lib/skills/bundled.js +42 -0
- package/lib/skills/provider.d.ts +72 -0
- package/lib/skills/provider.js +340 -0
- package/lib/skills/row.d.ts +22 -0
- package/lib/skills/row.js +204 -0
- package/lib/workbench/adapter-coverage.d.ts +47 -0
- package/lib/workbench/adapter-coverage.js +102 -0
- package/lib/workbench/model-tools.d.ts +10 -0
- package/lib/workbench/model-tools.js +122 -0
- package/lib/workbench/overview.d.ts +103 -0
- package/lib/workbench/overview.js +159 -0
- package/lib/workbench/remote.d.ts +118 -0
- package/lib/workbench/remote.js +422 -0
- package/lib/workbench/row.d.ts +15 -0
- package/lib/workbench/row.js +16 -0
- package/lib/workbench/settings.d.ts +15 -0
- package/lib/workbench/settings.js +56 -0
- package/lib/workbench/workbench.d.ts +100 -0
- package/lib/workbench/workbench.js +260 -0
- package/locale/agents/en.json +6 -0
- package/locale/agents/zh.json +6 -0
- package/locale/commands/en.json +6 -0
- package/locale/commands/zh.json +6 -0
- package/locale/context/en.json +6 -0
- package/locale/context/zh.json +6 -0
- package/locale/en.json +6 -0
- package/locale/hooks/en.json +6 -0
- package/locale/hooks/zh.json +6 -0
- package/locale/mcp/en.json +6 -0
- package/locale/mcp/zh.json +6 -0
- package/locale/mods/en.json +6 -0
- package/locale/mods/zh.json +6 -0
- package/locale/opencode/en.json +6 -0
- package/locale/opencode/zh.json +6 -0
- package/locale/porter/en.json +6 -0
- package/locale/porter/zh.json +6 -0
- package/locale/sessions/en.json +6 -0
- package/locale/sessions/zh.json +6 -0
- package/locale/skills/en.json +6 -0
- package/locale/skills/zh.json +6 -0
- package/locale/workbench/en.json +6 -0
- package/locale/workbench/zh.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +246 -3
- package/runtime/opencode-host.mjs +270 -0
- package/skills/harness-forge/SKILL.md +47 -0
|
@@ -0,0 +1,364 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool vocabulary of each foreign dialect. Hook matchers, hook payloads and
|
|
3
|
+
* agent `tools:` lists name tools the way their own harness does (`Bash`,
|
|
4
|
+
* `Write`, `apply_patch`, `mcp__plugin_x_y__z`) and expect that harness's
|
|
5
|
+
* input and output shapes; DSH names the same capabilities `pwsh`/`bash`,
|
|
6
|
+
* `write`, `edit` with its own shapes. This module translates both ways:
|
|
7
|
+
* DSH call → foreign `tool_name`/`tool_input`/`tool_response`, and a hook's
|
|
8
|
+
* `updatedInput`/`updatedToolOutput` → DSH arguments/value.
|
|
9
|
+
* @module @kirkchinese/harness-forge
|
|
10
|
+
*/
|
|
11
|
+
import { homedir } from 'node:os';
|
|
12
|
+
import { isAbsolute, resolve } from 'node:path';
|
|
13
|
+
import { CATALOG_CALL_TOOL, CATALOG_TOOLS, catalogToolName } from '../mcp/catalog.js';
|
|
14
|
+
/** DSH tool name → foreign names, canonical first. */
|
|
15
|
+
const TABLE = {
|
|
16
|
+
bash: { claude: ['Bash'], codex: ['Bash', 'shell', 'local_shell', 'exec_command'] },
|
|
17
|
+
// On Windows the DSH shell tool is PowerShell. Claude hooks written for the
|
|
18
|
+
// shell tool match `Bash`, the name Claude Code gives its shell tool on a
|
|
19
|
+
// machine with Git Bash; a hook that names `PowerShell` sees that name.
|
|
20
|
+
pwsh: { claude: ['Bash', 'PowerShell'], codex: ['Bash', 'shell', 'local_shell', 'exec_command'] },
|
|
21
|
+
read: { claude: ['Read'], codex: ['Read'] },
|
|
22
|
+
read_image: { claude: ['Read'], codex: ['view_image', 'Read'] },
|
|
23
|
+
write: { claude: ['Write'], codex: ['apply_patch', 'Write', 'Edit'] },
|
|
24
|
+
edit: { claude: ['Edit'], codex: ['apply_patch', 'Edit', 'Write'] },
|
|
25
|
+
glob: { claude: ['Glob'], codex: ['Glob'] },
|
|
26
|
+
grep: { claude: ['Grep'], codex: ['Grep'] },
|
|
27
|
+
web_fetch: { claude: ['WebFetch'], codex: ['web_fetch', 'WebFetch'] },
|
|
28
|
+
web_search: { claude: ['WebSearch'], codex: ['web_search', 'WebSearch'] },
|
|
29
|
+
todo_write: { claude: ['TodoWrite'], codex: ['update_plan', 'TodoWrite'] },
|
|
30
|
+
subagent: { claude: ['Agent', 'Task'], codex: ['spawn_agent', 'Agent'] },
|
|
31
|
+
subagent_fork: { claude: ['Agent', 'Task'], codex: ['spawn_agent', 'Agent'] },
|
|
32
|
+
agent: { claude: ['Agent', 'Task'], codex: ['spawn_agent', 'Agent'] },
|
|
33
|
+
ask_user_question: { claude: ['AskUserQuestion'], codex: ['request_user_input', 'AskUserQuestion'] },
|
|
34
|
+
exit_plan_mode: { claude: ['ExitPlanMode'], codex: ['ExitPlanMode'] },
|
|
35
|
+
skill: { claude: ['Skill'], codex: ['Skill'] },
|
|
36
|
+
job_output: { claude: ['TaskOutput', 'BashOutput'], codex: ['write_stdin'] },
|
|
37
|
+
job_kill: { claude: ['TaskStop', 'KillShell'], codex: ['KillShell'] },
|
|
38
|
+
};
|
|
39
|
+
const SHELL_TOOLS = new Set(['bash', 'pwsh']);
|
|
40
|
+
const AGENT_TOOLS = new Set(['subagent', 'subagent_fork', 'agent']);
|
|
41
|
+
const FILE_TOOLS = new Set(['read', 'read_image', 'write', 'edit']);
|
|
42
|
+
/** The foreign view of one DSH tool call. MCP and unknown tools keep their names and input. */
|
|
43
|
+
export function foreignTool(dialect, dshName, args, context = {}) {
|
|
44
|
+
const raw = isRecord(args) ? args : {};
|
|
45
|
+
// A capability-catalog call is the MCP tool its id names, with that tool's arguments.
|
|
46
|
+
const catalogName = dshName === CATALOG_CALL_TOOL ? catalogToolName(raw['id']) : undefined;
|
|
47
|
+
if (catalogName !== undefined) {
|
|
48
|
+
return { dshName, name: catalogName, aliases: [catalogName, dshName], input: isRecord(raw['arguments']) ? { ...raw['arguments'] } : {} };
|
|
49
|
+
}
|
|
50
|
+
const entry = TABLE[dshName];
|
|
51
|
+
if (entry === undefined)
|
|
52
|
+
return { dshName, name: dshName, aliases: [dshName], input: { ...raw } };
|
|
53
|
+
const names = dialect === 'codex' ? entry.codex : entry.claude;
|
|
54
|
+
return {
|
|
55
|
+
dshName,
|
|
56
|
+
name: names[0] ?? dshName,
|
|
57
|
+
aliases: [...names, dshName],
|
|
58
|
+
input: foreignInput(dialect, dshName, raw, context),
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Map a foreign tool name from an agent/skill allow list or a rule to DSH
|
|
63
|
+
* names. An MCP tool is reachable directly or through the capability catalog.
|
|
64
|
+
*/
|
|
65
|
+
export function dshToolsFor(foreignName, dialect) {
|
|
66
|
+
if (foreignName.startsWith('mcp__'))
|
|
67
|
+
return [foreignName, ...CATALOG_TOOLS];
|
|
68
|
+
const bare = foreignName.replace(/\(.*\)$/u, '').trim();
|
|
69
|
+
const names = [];
|
|
70
|
+
for (const [dsh, entry] of Object.entries(TABLE)) {
|
|
71
|
+
// In one dialect a name means that dialect's tool only: Claude's `Write` is not Codex's patch-writer that also edits.
|
|
72
|
+
const foreign = dialect === 'claude-code' ? entry.claude : dialect === 'codex' ? entry.codex : [...entry.claude, ...entry.codex];
|
|
73
|
+
if (foreign.includes(bare) || dsh === bare)
|
|
74
|
+
names.push(dsh);
|
|
75
|
+
}
|
|
76
|
+
return names;
|
|
77
|
+
}
|
|
78
|
+
function foreignInput(dialect, dshName, input, context) {
|
|
79
|
+
if (SHELL_TOOLS.has(dshName)) {
|
|
80
|
+
const command = typeof input['command'] === 'string' ? input['command'] : '';
|
|
81
|
+
if (dialect === 'codex')
|
|
82
|
+
return { command };
|
|
83
|
+
return {
|
|
84
|
+
command,
|
|
85
|
+
...(typeof input['description'] === 'string' ? { description: input['description'] } : {}),
|
|
86
|
+
...(typeof input['timeoutMs'] === 'number' ? { timeout: input['timeoutMs'] } : {}),
|
|
87
|
+
...(typeof input['run_in_background'] === 'boolean' ? { run_in_background: input['run_in_background'] } : {}),
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
if (FILE_TOOLS.has(dshName)) {
|
|
91
|
+
const filePath = absolutePath(String(input['file_path'] ?? input['path'] ?? ''), context.cwd);
|
|
92
|
+
if (dialect === 'codex' && (dshName === 'write' || dshName === 'edit')) {
|
|
93
|
+
return { command: patchText(dshName, filePath, input) };
|
|
94
|
+
}
|
|
95
|
+
const { sandbox_permissions: _sandbox, justification: _justification, path: _path, ...rest } = input;
|
|
96
|
+
return { ...rest, file_path: filePath };
|
|
97
|
+
}
|
|
98
|
+
switch (dshName) {
|
|
99
|
+
case 'glob':
|
|
100
|
+
return { pattern: input['pattern'], ...(typeof input['path'] === 'string' ? { path: absolutePath(input['path'], context.cwd) } : {}) };
|
|
101
|
+
case 'grep':
|
|
102
|
+
return {
|
|
103
|
+
pattern: input['pattern'],
|
|
104
|
+
...(typeof input['path'] === 'string' ? { path: absolutePath(input['path'], context.cwd) } : {}),
|
|
105
|
+
...(typeof input['include'] === 'string' ? { glob: input['include'] } : {}),
|
|
106
|
+
output_mode: 'content',
|
|
107
|
+
};
|
|
108
|
+
case 'web_search': {
|
|
109
|
+
const queries = Array.isArray(input['queries']) ? input['queries'].map(String) : [];
|
|
110
|
+
return { query: queries[0] ?? '', ...(queries.length > 1 ? { queries } : {}) };
|
|
111
|
+
}
|
|
112
|
+
case 'skill':
|
|
113
|
+
return { skill: input['name'] };
|
|
114
|
+
case 'ask_user_question':
|
|
115
|
+
return { questions: Array.isArray(input['questions']) ? input['questions'].map(foreignQuestion) : [] };
|
|
116
|
+
case 'job_output':
|
|
117
|
+
return { task_id: input['job_id'], bash_id: input['job_id'], block: input['wait'] === true };
|
|
118
|
+
case 'job_kill':
|
|
119
|
+
return { task_id: input['job_id'], shell_id: input['job_id'] };
|
|
120
|
+
default:
|
|
121
|
+
break;
|
|
122
|
+
}
|
|
123
|
+
if (AGENT_TOOLS.has(dshName)) {
|
|
124
|
+
const preset = input['agent_preset'];
|
|
125
|
+
const subagentType = typeof preset === 'string' ? context.agentName?.(preset) ?? preset : 'general-purpose';
|
|
126
|
+
return dialect === 'codex'
|
|
127
|
+
? { message: input['prompt'], agent_type: subagentType }
|
|
128
|
+
: { prompt: input['prompt'], description: input['description'], subagent_type: subagentType };
|
|
129
|
+
}
|
|
130
|
+
return { ...input };
|
|
131
|
+
}
|
|
132
|
+
function foreignQuestion(value) {
|
|
133
|
+
if (!isRecord(value))
|
|
134
|
+
return value;
|
|
135
|
+
const { multi_select: multi, id: _id, ...rest } = value;
|
|
136
|
+
return { ...rest, multiSelect: multi === true };
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* DSH arguments for a hook's `updatedInput`. The foreign input replaces the
|
|
140
|
+
* whole input; DSH-only fields the hook cannot see (working directory,
|
|
141
|
+
* sandbox escalation) keep their original values.
|
|
142
|
+
* @throws when the replacement cannot be expressed as DSH arguments.
|
|
143
|
+
*/
|
|
144
|
+
export function dshInput(dialect, dshName, original, updated, context = {}) {
|
|
145
|
+
const base = isRecord(original) ? original : {};
|
|
146
|
+
if (dshName === CATALOG_CALL_TOOL && catalogToolName(base['id']) !== undefined)
|
|
147
|
+
return { id: base['id'], arguments: updated };
|
|
148
|
+
const keep = (...keys) => Object.fromEntries(keys.filter(key => key in base).map(key => [key, base[key]]));
|
|
149
|
+
if (SHELL_TOOLS.has(dshName)) {
|
|
150
|
+
if (typeof updated['command'] !== 'string')
|
|
151
|
+
throw new Error('updatedInput for a shell call needs a string "command"');
|
|
152
|
+
return {
|
|
153
|
+
...keep('workdir', 'sandbox_permissions', 'justification'),
|
|
154
|
+
command: updated['command'],
|
|
155
|
+
description: typeof updated['description'] === 'string' ? updated['description'] : String(base['description'] ?? ''),
|
|
156
|
+
...(typeof updated['timeout'] === 'number' ? { timeoutMs: updated['timeout'] } : {}),
|
|
157
|
+
...(typeof updated['run_in_background'] === 'boolean' ? { run_in_background: updated['run_in_background'] } : {}),
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
if (dialect === 'codex' && (dshName === 'write' || dshName === 'edit')) {
|
|
161
|
+
if (typeof updated['command'] !== 'string')
|
|
162
|
+
throw new Error('updatedInput for apply_patch needs a string "command"');
|
|
163
|
+
return { ...keep('sandbox_permissions', 'justification'), ...patchArguments(dshName, updated['command']) };
|
|
164
|
+
}
|
|
165
|
+
if (FILE_TOOLS.has(dshName)) {
|
|
166
|
+
const { file_path: filePath, ...rest } = updated;
|
|
167
|
+
return { ...keep('sandbox_permissions', 'justification'), ...rest, file_path: typeof filePath === 'string' ? filePath : base['file_path'] };
|
|
168
|
+
}
|
|
169
|
+
switch (dshName) {
|
|
170
|
+
case 'grep': {
|
|
171
|
+
const { glob, output_mode: _mode, ...rest } = updated;
|
|
172
|
+
return { ...rest, ...(typeof glob === 'string' ? { include: glob } : {}) };
|
|
173
|
+
}
|
|
174
|
+
case 'web_search': {
|
|
175
|
+
const queries = Array.isArray(updated['queries']) ? updated['queries'].map(String) : typeof updated['query'] === 'string' ? [updated['query']] : [];
|
|
176
|
+
return { queries };
|
|
177
|
+
}
|
|
178
|
+
case 'skill':
|
|
179
|
+
return { name: updated['skill'] ?? base['name'] };
|
|
180
|
+
case 'ask_user_question':
|
|
181
|
+
return {
|
|
182
|
+
questions: Array.isArray(updated['questions'])
|
|
183
|
+
? updated['questions'].map((question) => {
|
|
184
|
+
if (!isRecord(question))
|
|
185
|
+
return question;
|
|
186
|
+
const { multiSelect, ...rest } = question;
|
|
187
|
+
return { ...rest, multi_select: multiSelect === true };
|
|
188
|
+
})
|
|
189
|
+
: base['questions'],
|
|
190
|
+
};
|
|
191
|
+
case 'job_output':
|
|
192
|
+
return { job_id: updated['task_id'] ?? updated['bash_id'] ?? base['job_id'], ...(typeof updated['block'] === 'boolean' ? { wait: updated['block'] } : {}) };
|
|
193
|
+
case 'job_kill':
|
|
194
|
+
return { job_id: updated['task_id'] ?? updated['shell_id'] ?? base['job_id'] };
|
|
195
|
+
default:
|
|
196
|
+
break;
|
|
197
|
+
}
|
|
198
|
+
if (AGENT_TOOLS.has(dshName)) {
|
|
199
|
+
const type = updated['subagent_type'] ?? updated['agent_type'];
|
|
200
|
+
const preset = typeof type === 'string' ? context.presetOf?.(type) : undefined;
|
|
201
|
+
return {
|
|
202
|
+
...keep('cwd'),
|
|
203
|
+
prompt: updated['prompt'] ?? updated['message'] ?? base['prompt'],
|
|
204
|
+
description: updated['description'] ?? base['description'],
|
|
205
|
+
...(preset !== undefined ? { agent_preset: preset } : 'agent_preset' in base ? { agent_preset: base['agent_preset'] } : {}),
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
return updated;
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* A shell call that ran but failed, as Claude Code reports it: a non-zero
|
|
212
|
+
* exit, a timeout or an abort is a tool failure (`PostToolUseFailure`), with
|
|
213
|
+
* `Exit code N` on the first line of the error. DSH returns such a call as a
|
|
214
|
+
* value carrying the exit code.
|
|
215
|
+
*/
|
|
216
|
+
export function shellFailure(dshName, value) {
|
|
217
|
+
if (!SHELL_TOOLS.has(dshName) || !isRecord(value) || value['kind'] !== 'foreground')
|
|
218
|
+
return undefined;
|
|
219
|
+
const exitCode = typeof value['exitCode'] === 'number' ? value['exitCode'] : undefined;
|
|
220
|
+
const stopped = value['timedOut'] === true || value['aborted'] === true;
|
|
221
|
+
if (!stopped && (exitCode === undefined || exitCode === 0))
|
|
222
|
+
return undefined;
|
|
223
|
+
const output = [textField(value['stderr']), textField(value['stdout'])].find(text => text.trim().length > 0) ?? '';
|
|
224
|
+
const head = value['timedOut'] === true ? 'Command timed out' : value['aborted'] === true ? 'Command was aborted' : `Exit code ${String(exitCode)}`;
|
|
225
|
+
return output.length > 0 ? `${head}\n${output.trimEnd()}` : head;
|
|
226
|
+
}
|
|
227
|
+
/** The structured result a foreign PostToolUse hook receives as `tool_response`. */
|
|
228
|
+
export function foreignResponse(dialect, dshName, args, value, text) {
|
|
229
|
+
const input = isRecord(args) ? args : {};
|
|
230
|
+
const out = isRecord(value) ? value : undefined;
|
|
231
|
+
// A catalog call answers as the MCP tool would: its structured content, else its content blocks.
|
|
232
|
+
if (dshName === CATALOG_CALL_TOOL && catalogToolName(input['id']) !== undefined) {
|
|
233
|
+
return out?.['structuredContent'] ?? [{ type: 'text', text: typeof out?.['text'] === 'string' ? out['text'] : text }];
|
|
234
|
+
}
|
|
235
|
+
if (dialect === 'codex' && !dshName.startsWith('mcp__'))
|
|
236
|
+
return text;
|
|
237
|
+
if (out === undefined)
|
|
238
|
+
return value ?? text;
|
|
239
|
+
if (SHELL_TOOLS.has(dshName)) {
|
|
240
|
+
if (out['kind'] === 'foreground') {
|
|
241
|
+
return {
|
|
242
|
+
stdout: textField(out['stdout']),
|
|
243
|
+
stderr: textField(out['stderr']),
|
|
244
|
+
interrupted: out['timedOut'] === true || out['aborted'] === true,
|
|
245
|
+
isImage: false,
|
|
246
|
+
...(typeof out['exitCode'] === 'number' ? { exitCode: out['exitCode'] } : {}),
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
return { stdout: '', stderr: '', interrupted: false, isImage: false, backgroundTaskId: out['jobId'] };
|
|
250
|
+
}
|
|
251
|
+
switch (dshName) {
|
|
252
|
+
case 'read': {
|
|
253
|
+
const lines = Array.isArray(out['lines']) ? out['lines'].filter(isRecord) : [];
|
|
254
|
+
const content = lines.map(line => String(line['text'] ?? '')).join('\n');
|
|
255
|
+
return { type: 'text', file: { filePath: out['path'], content, numLines: lines.length, startLine: out['offset'], totalLines: out['totalLines'] ?? lines.length } };
|
|
256
|
+
}
|
|
257
|
+
case 'write':
|
|
258
|
+
return { type: out['operation'], filePath: out['path'], content: out['after'], structuredPatch: [], originalFile: out['before'] ?? null };
|
|
259
|
+
case 'edit':
|
|
260
|
+
return {
|
|
261
|
+
filePath: out['path'],
|
|
262
|
+
oldString: input['old_string'],
|
|
263
|
+
newString: input['new_string'],
|
|
264
|
+
originalFile: out['before'],
|
|
265
|
+
structuredPatch: [],
|
|
266
|
+
userModified: false,
|
|
267
|
+
replaceAll: input['replace_all'] === true,
|
|
268
|
+
};
|
|
269
|
+
case 'glob': {
|
|
270
|
+
const paths = Array.isArray(out['paths']) ? out['paths'].map(String) : [];
|
|
271
|
+
return { filenames: paths, numFiles: paths.length, durationMs: 0, truncated: false };
|
|
272
|
+
}
|
|
273
|
+
case 'grep': {
|
|
274
|
+
const matches = Array.isArray(out['matches']) ? out['matches'].filter(isRecord) : [];
|
|
275
|
+
const filenames = [...new Set(matches.map(match => String(match['path'])))];
|
|
276
|
+
return {
|
|
277
|
+
mode: 'content',
|
|
278
|
+
numFiles: filenames.length,
|
|
279
|
+
filenames,
|
|
280
|
+
content: matches.map(match => `${String(match['path'])}:${String(match['lineNumber'])}:${String(match['line'])}`).join('\n'),
|
|
281
|
+
numLines: matches.length,
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
case 'web_fetch': {
|
|
285
|
+
const body = isRecord(out['body']) ? out['body'] : {};
|
|
286
|
+
const content = typeof body['content'] === 'string' ? body['content'] : text;
|
|
287
|
+
return { url: out['url'], code: out['statusCode'], codeText: '', result: content, bytes: Buffer.byteLength(content), durationMs: 0 };
|
|
288
|
+
}
|
|
289
|
+
default:
|
|
290
|
+
break;
|
|
291
|
+
}
|
|
292
|
+
if (AGENT_TOOLS.has(dshName))
|
|
293
|
+
return { status: 'completed', content: [{ type: 'text', text }], ...out };
|
|
294
|
+
return value;
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* The DSH value for a hook's `updatedToolOutput`, when the replacement has the
|
|
298
|
+
* foreign output shape of a tool whose DSH value can carry it.
|
|
299
|
+
* @returns undefined when only the model-facing text can be replaced.
|
|
300
|
+
*/
|
|
301
|
+
export function dshValue(dshName, original, updated) {
|
|
302
|
+
const out = isRecord(original) ? original : undefined;
|
|
303
|
+
if (out === undefined || !isRecord(updated))
|
|
304
|
+
return undefined;
|
|
305
|
+
if (SHELL_TOOLS.has(dshName) && out['kind'] === 'foreground' && typeof updated['stdout'] === 'string') {
|
|
306
|
+
return {
|
|
307
|
+
...out,
|
|
308
|
+
stdout: { ...(isRecord(out['stdout']) ? out['stdout'] : {}), text: updated['stdout'], truncated: false },
|
|
309
|
+
stderr: { ...(isRecord(out['stderr']) ? out['stderr'] : {}), text: typeof updated['stderr'] === 'string' ? updated['stderr'] : '', truncated: false },
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
if (dshName === 'read' && isRecord(updated['file']) && typeof updated['file']['content'] === 'string') {
|
|
313
|
+
const start = typeof out['offset'] === 'number' ? out['offset'] : 1;
|
|
314
|
+
return { ...out, lines: updated['file']['content'].split('\n').map((text, index) => ({ number: start + index, text })) };
|
|
315
|
+
}
|
|
316
|
+
return undefined;
|
|
317
|
+
}
|
|
318
|
+
/** The value a rule such as `Edit(src
|
|
319
|
+
|
|
320
|
+
/** Whether a DSH tool runs shell commands. */
|
|
321
|
+
export function isShellTool(dshName) {
|
|
322
|
+
return SHELL_TOOLS.has(dshName);
|
|
323
|
+
}
|
|
324
|
+
/** An absolute path in the platform's native form; `~` expands to the home directory. */
|
|
325
|
+
export function absolutePath(path, cwd) {
|
|
326
|
+
if (path.length === 0)
|
|
327
|
+
return path;
|
|
328
|
+
const expanded = path === '~' ? homedir() : path.startsWith('~/') || path.startsWith('~\\') ? resolve(homedir(), path.slice(2)) : path;
|
|
329
|
+
return isAbsolute(expanded) ? resolve(expanded) : resolve(cwd ?? process.cwd(), expanded);
|
|
330
|
+
}
|
|
331
|
+
/** A Codex `apply_patch` rendering of a DSH write or edit. */
|
|
332
|
+
function patchText(dshName, filePath, input) {
|
|
333
|
+
if (dshName === 'write') {
|
|
334
|
+
return `*** Begin Patch\n*** Add File: ${filePath}\n${String(input['content'] ?? '').split('\n').map(line => `+${line}`).join('\n')}\n*** End Patch`;
|
|
335
|
+
}
|
|
336
|
+
const before = String(input['old_string'] ?? '').split('\n').map(line => `-${line}`).join('\n');
|
|
337
|
+
const after = String(input['new_string'] ?? '').split('\n').map(line => `+${line}`).join('\n');
|
|
338
|
+
return `*** Begin Patch\n*** Update File: ${filePath}\n@@\n${before}\n${after}\n*** End Patch`;
|
|
339
|
+
}
|
|
340
|
+
/** DSH write/edit arguments from a single-file Codex patch. */
|
|
341
|
+
function patchArguments(dshName, patch) {
|
|
342
|
+
const lines = patch.replace(/\r\n/gu, '\n').split('\n');
|
|
343
|
+
const header = lines.find(line => /^\*\*\* (Add|Update) File: /u.test(line));
|
|
344
|
+
if (header === undefined)
|
|
345
|
+
throw new Error('apply_patch updatedInput has no "*** Add File" or "*** Update File" header');
|
|
346
|
+
const filePath = header.replace(/^\*\*\* (Add|Update) File: /u, '').trim();
|
|
347
|
+
const body = lines.slice(lines.indexOf(header) + 1).filter(line => !line.startsWith('*** ') && !line.startsWith('@@'));
|
|
348
|
+
if (header.startsWith('*** Add File: ')) {
|
|
349
|
+
return { file_path: filePath, content: body.map(line => line.startsWith('+') ? line.slice(1) : line).join('\n') };
|
|
350
|
+
}
|
|
351
|
+
if (dshName === 'write')
|
|
352
|
+
throw new Error('apply_patch updatedInput turned a file creation into an update');
|
|
353
|
+
return {
|
|
354
|
+
file_path: filePath,
|
|
355
|
+
old_string: body.filter(line => line.startsWith('-') || line.startsWith(' ')).map(line => line.slice(1)).join('\n'),
|
|
356
|
+
new_string: body.filter(line => line.startsWith('+') || line.startsWith(' ')).map(line => line.slice(1)).join('\n'),
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
function textField(value) {
|
|
360
|
+
return isRecord(value) && typeof value['text'] === 'string' ? value['text'] : typeof value === 'string' ? value : '';
|
|
361
|
+
}
|
|
362
|
+
function isRecord(value) {
|
|
363
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
364
|
+
}
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
2
|
+
import z from '@deepseek-ai/schemastery';
|
|
3
|
+
/** Plugin configuration. */
|
|
4
|
+
export interface Config {
|
|
5
|
+
/** Plugin roots installed automatically at boot (acceptance/demo profiles). */
|
|
6
|
+
preload?: string[];
|
|
7
|
+
/** Write lifecycle diagnostics to `$DSH_HOME/harness-forge/debug.log`. */
|
|
8
|
+
debug?: boolean;
|
|
9
|
+
/**
|
|
10
|
+
* The model a Claude alias (`haiku`, `sonnet`, `opus`, or a `claude-…` id of that family) runs on, as
|
|
11
|
+
* `provider/model`. Without an entry the session's model answers it: model names do not say which is stronger.
|
|
12
|
+
*/
|
|
13
|
+
modelAliases?: {
|
|
14
|
+
haiku?: string;
|
|
15
|
+
sonnet?: string;
|
|
16
|
+
opus?: string;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
/** Schemastery validation for the plugin configuration. */
|
|
20
|
+
export declare const Config: z<Config>;
|
|
21
|
+
/** Cordis plugin name. */
|
|
22
|
+
export declare const name = "harness-compat";
|
|
23
|
+
/** Every DSH service the row uses is optional: a headless profile runs the ledger alone. */
|
|
24
|
+
export declare const inject: string[];
|
|
25
|
+
/**
|
|
26
|
+
* Activate the ledger and the shared service. The ledger and `preload`
|
|
27
|
+
* plugins mount in the background; a new session's first request waits for
|
|
28
|
+
* them (at most a while), so it already has their skills, commands, hooks,
|
|
29
|
+
* MCP tools and agents, as Claude Code loads plugins before a session starts.
|
|
30
|
+
*/
|
|
31
|
+
export declare function apply(ctx: Context, config: Config): Promise<void>;
|