@shuind/dsh-codex-harness 0.2.21 → 0.3.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/CHANGELOG.md +185 -0
- package/README.md +38 -50
- package/RELEASE.md +61 -0
- package/assets/codex.svg +5 -0
- package/cordis.patch.yml +181 -6
- package/docs/preset-library.md +33 -23
- package/docs/tool-policy-benchmark.json +310 -0
- package/docs/tool-policy.md +148 -0
- package/lib/client.js +4774 -2416
- package/lib/compact-command.js +416 -0
- package/lib/compaction.js +141 -12
- package/lib/hybrid-executor.js +1196 -0
- package/lib/index.js +3658 -2334
- package/lib/preferences.js +117 -0
- package/lib/tool-policy.js +2422 -0
- package/lib/typert.js +86 -79
- package/lib/types/client/activity.d.ts +33 -9
- package/lib/types/client/activity.js +4 -3
- package/lib/types/client/desktop.d.ts +67 -0
- package/lib/types/client/desktop.js +229 -0
- package/lib/types/client/index.d.ts +207 -110
- package/lib/types/client/index.js +99 -492
- package/lib/types/client/policy-drafts.d.ts +25 -0
- package/lib/types/client/policy-drafts.js +47 -0
- package/lib/types/client/policy-locale.d.ts +260 -0
- package/lib/types/client/policy-locale.js +357 -0
- package/lib/types/client/preset-manager.d.ts +38 -10
- package/lib/types/client/preset-manager.js +235 -185
- package/lib/types/client/preset-requests.d.ts +12 -0
- package/lib/types/client/preset-requests.js +101 -0
- package/lib/types/client/tool-policy.d.ts +33 -0
- package/lib/types/client/tool-policy.js +336 -0
- package/lib/types/contracts/preset-editor-schema.d.ts +78 -0
- package/lib/types/contracts/preset-editor-schema.js +95 -0
- package/lib/types/{prompt.js → contracts/prompt.js} +13 -7
- package/lib/types/{settings.d.ts → contracts/settings.d.ts} +11 -4
- package/lib/types/{settings.js → contracts/settings.js} +22 -6
- package/lib/types/contracts/tool-policy-contract.d.ts +63 -0
- package/lib/types/contracts/tool-policy-contract.js +33 -0
- package/lib/types/contracts/ui-contracts.d.ts +92 -0
- package/lib/types/contracts/ui-contracts.js +83 -0
- package/lib/types/entries/client.d.ts +10 -0
- package/lib/types/entries/client.js +10 -0
- package/lib/types/{compact-command.d.ts → entries/compact-command.d.ts} +2 -0
- package/lib/types/entries/compact-command.js +176 -0
- package/lib/types/{compaction.d.ts → entries/compaction.d.ts} +15 -3
- package/lib/types/{compaction.js → entries/compaction.js} +47 -11
- package/lib/types/entries/hybrid-executor.d.ts +19 -0
- package/lib/types/entries/hybrid-executor.js +57 -0
- package/lib/types/entries/index.d.ts +66 -0
- package/lib/types/entries/index.js +192 -0
- package/lib/types/entries/preferences.d.ts +11 -0
- package/lib/types/entries/preferences.js +16 -0
- package/lib/types/entries/tool-policy.d.ts +97 -0
- package/lib/types/entries/tool-policy.js +158 -0
- package/lib/types/entries/typert.host.d.ts +23 -0
- package/lib/types/entries/typert.host.js +24 -0
- package/lib/types/hybrid/codex-hybrid-executor.d.ts +44 -0
- package/lib/types/hybrid/codex-hybrid-executor.js +257 -0
- package/lib/types/hybrid/hybrid-sdk.d.ts +13 -0
- package/lib/types/hybrid/hybrid-sdk.js +196 -0
- package/lib/types/hybrid/program-calls.d.ts +28 -0
- package/lib/types/hybrid/program-calls.js +193 -0
- package/lib/types/hybrid/subcall-scheduler.d.ts +90 -0
- package/lib/types/hybrid/subcall-scheduler.js +343 -0
- package/lib/types/policy/deferred-tools.d.ts +42 -0
- package/lib/types/policy/deferred-tools.js +264 -0
- package/lib/types/policy/overlay-installer.d.ts +12 -0
- package/lib/types/policy/overlay-installer.js +179 -0
- package/lib/types/policy/rule-resolver.d.ts +94 -0
- package/lib/types/policy/rule-resolver.js +114 -0
- package/lib/types/policy/tool-capabilities.d.ts +33 -0
- package/lib/types/policy/tool-capabilities.js +46 -0
- package/lib/types/{activity.d.ts → presets/activity.d.ts} +3 -5
- package/lib/types/{activity.js → presets/activity.js} +51 -27
- package/lib/types/presets/desktop-preset.d.ts +22 -0
- package/lib/types/presets/desktop-preset.js +43 -0
- package/lib/types/presets/preset-editor.d.ts +47 -0
- package/lib/types/presets/preset-editor.js +81 -0
- package/lib/types/presets/preset-prompt-catalog.d.ts +23 -0
- package/lib/types/presets/preset-prompt-catalog.js +215 -0
- package/lib/types/presets/preset-tool-catalog.d.ts +5 -0
- package/lib/types/presets/preset-tool-catalog.js +58 -0
- package/lib/types/presets/runtime-enhancements.d.ts +45 -0
- package/lib/types/presets/runtime-enhancements.js +349 -0
- package/lib/types/presets/small-window-compaction.d.ts +15 -0
- package/lib/types/presets/small-window-compaction.js +121 -0
- package/lib/types/responses/compact-checkpoint.d.ts +27 -0
- package/lib/types/responses/compact-checkpoint.js +257 -0
- package/lib/types/responses/fetch-transport.d.ts +16 -0
- package/lib/types/responses/fetch-transport.js +257 -0
- package/lib/types/responses/remote-compact.d.ts +13 -0
- package/lib/types/responses/remote-compact.js +319 -0
- package/lib/types/responses/sse-diagnostics.d.ts +9 -0
- package/lib/types/responses/sse-diagnostics.js +157 -0
- package/lib/types/responses/wire-rewrite.d.ts +35 -0
- package/lib/types/responses/wire-rewrite.js +237 -0
- package/lib/types/tools/exec-output.d.ts +58 -0
- package/lib/types/tools/exec-output.js +173 -0
- package/lib/types/tools/exec-plan-tools.d.ts +37 -0
- package/lib/types/tools/exec-plan-tools.js +265 -0
- package/lib/types/tools/exec-runner.d.ts +21 -0
- package/lib/types/tools/exec-runner.js +385 -0
- package/lib/types/tools/patch-tool.d.ts +16 -0
- package/lib/types/tools/patch-tool.js +258 -0
- package/lib/types/{patch.d.ts → tools/patch.d.ts} +1 -1
- package/lib/types/{patch.js → tools/patch.js} +96 -21
- package/locale/en.json +6 -0
- package/locale/hybrid-executor/en.json +6 -0
- package/locale/hybrid-executor/zh.json +6 -0
- package/locale/tool-policy/en.json +6 -0
- package/locale/tool-policy/zh.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +297 -299
- package/presets/{codex-collaboration → codex-hybrid}/agent.cordis.yml +45 -48
- package/presets/codex-hybrid/preset.yml +3 -0
- package/scripts/benchmark-tool-policy.mjs +186 -0
- package/scripts/build-preset.mjs +19 -0
- package/scripts/clean-build.mjs +11 -0
- package/src/client/activity.ts +83 -0
- package/src/client/desktop.tsx +276 -0
- package/src/client/index.tsx +391 -0
- package/src/client/policy-drafts.ts +56 -0
- package/src/client/policy-locale.ts +362 -0
- package/src/client/preset-manager.tsx +376 -0
- package/src/client/preset-requests.ts +113 -0
- package/src/client/tool-policy.tsx +402 -0
- package/src/contracts/preset-editor-schema.ts +110 -0
- package/src/contracts/prompt.ts +66 -0
- package/src/contracts/settings.ts +103 -0
- package/src/contracts/tool-policy-contract.ts +93 -0
- package/src/contracts/ui-contracts.ts +173 -0
- package/src/entries/client.tsx +14 -0
- package/src/entries/compact-command.ts +256 -0
- package/src/entries/compaction.ts +218 -0
- package/src/entries/hybrid-executor.ts +76 -0
- package/src/entries/index.ts +298 -0
- package/src/entries/preferences.ts +17 -0
- package/src/entries/tool-policy.ts +162 -0
- package/src/entries/typert.host.ts +29 -0
- package/src/hybrid/codex-hybrid-executor.ts +310 -0
- package/src/hybrid/hybrid-sdk.ts +217 -0
- package/src/hybrid/program-calls.ts +202 -0
- package/src/hybrid/subcall-scheduler.ts +446 -0
- package/src/policy/deferred-tools.ts +331 -0
- package/src/policy/overlay-installer.ts +191 -0
- package/src/policy/rule-resolver.ts +128 -0
- package/src/policy/tool-capabilities.ts +88 -0
- package/src/presets/activity.ts +146 -0
- package/src/presets/desktop-preset.ts +60 -0
- package/src/presets/preset-editor.ts +101 -0
- package/src/presets/preset-prompt-catalog.ts +221 -0
- package/src/presets/preset-tool-catalog.ts +58 -0
- package/src/presets/runtime-enhancements.ts +415 -0
- package/src/presets/small-window-compaction.ts +166 -0
- package/src/responses/compact-checkpoint.ts +264 -0
- package/src/responses/fetch-transport.ts +290 -0
- package/src/responses/remote-compact.ts +393 -0
- package/src/responses/sse-diagnostics.ts +156 -0
- package/src/responses/wire-rewrite.ts +261 -0
- package/src/tools/exec-output.ts +211 -0
- package/src/tools/exec-plan-tools.ts +307 -0
- package/src/tools/exec-runner.ts +445 -0
- package/src/tools/patch-tool.ts +331 -0
- package/src/tools/patch.ts +328 -0
- package/tsconfig.json +29 -0
- package/tsdown.config.ts +110 -0
- package/lib/installer.js +0 -237
- package/lib/invariant.js +0 -23
- package/lib/types/activity-types.d.ts +0 -6
- package/lib/types/activity-types.js +0 -3
- package/lib/types/client/preset-copy.d.ts +0 -42
- package/lib/types/client/preset-copy.js +0 -81
- package/lib/types/compact-command.js +0 -79
- package/lib/types/context.d.ts +0 -8
- package/lib/types/context.js +0 -14
- package/lib/types/exec.d.ts +0 -46
- package/lib/types/exec.js +0 -365
- package/lib/types/index.d.ts +0 -95
- package/lib/types/index.js +0 -738
- package/lib/types/installer.d.ts +0 -27
- package/lib/types/installer.js +0 -146
- package/lib/types/invariant.d.ts +0 -16
- package/lib/types/invariant.js +0 -22
- package/lib/types/preset-contract.d.ts +0 -69
- package/lib/types/preset-contract.js +0 -22
- package/lib/types/preset-editor-remote.d.ts +0 -30
- package/lib/types/preset-editor-remote.js +0 -37
- package/lib/types/preset-editor.d.ts +0 -69
- package/lib/types/preset-editor.js +0 -557
- package/lib/types/preset-templates.d.ts +0 -36
- package/lib/types/preset-templates.js +0 -12
- package/lib/types/prompt-sections.d.ts +0 -15
- package/lib/types/prompt-sections.js +0 -23
- package/lib/types/remote.d.ts +0 -40
- package/lib/types/remote.js +0 -683
- package/lib/types/typert.host.d.ts +0 -47
- package/lib/types/typert.host.js +0 -99
- package/presets/codex-collaboration/preset.yml +0 -3
- /package/lib/types/{prompt.d.ts → contracts/prompt.d.ts} +0 -0
package/lib/types/exec.js
DELETED
|
@@ -1,365 +0,0 @@
|
|
|
1
|
-
/** Codex `exec_command` and `write_stdin` execution over dsh capability seams. */
|
|
2
|
-
import { randomBytes } from 'node:crypto';
|
|
3
|
-
import { resolve as resolvePath } from 'node:path';
|
|
4
|
-
const STATES = new WeakMap();
|
|
5
|
-
const MIN_YIELD_TIME_MS = 250;
|
|
6
|
-
const WINDOWS_INITIAL_EXEC_YIELD_TIME_MS = 10_000;
|
|
7
|
-
const MIN_EMPTY_YIELD_TIME_MS = 5_000;
|
|
8
|
-
const MAX_YIELD_TIME_MS = 30_000;
|
|
9
|
-
const MAX_EMPTY_YIELD_TIME_MS = 300_000;
|
|
10
|
-
const DEFAULT_OUTPUT_TOKENS = 10_000;
|
|
11
|
-
const APPROX_BYTES_PER_TOKEN = 4;
|
|
12
|
-
function stateFor(agent) {
|
|
13
|
-
const current = STATES.get(agent);
|
|
14
|
-
if (current !== undefined)
|
|
15
|
-
return current;
|
|
16
|
-
const created = { nextId: 0, sessions: new Map() };
|
|
17
|
-
STATES.set(agent, created);
|
|
18
|
-
return created;
|
|
19
|
-
}
|
|
20
|
-
function positiveFinite(name, value) {
|
|
21
|
-
if (value !== undefined && (!Number.isFinite(value) || value < 0)) {
|
|
22
|
-
throw new Error(`${name} must be a non-negative finite number`);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
export function normalizeWaitMs(value, fallback, empty = false, initialExec = false) {
|
|
26
|
-
const lower = empty
|
|
27
|
-
? MIN_EMPTY_YIELD_TIME_MS
|
|
28
|
-
: initialExec && process.platform === 'win32'
|
|
29
|
-
? WINDOWS_INITIAL_EXEC_YIELD_TIME_MS
|
|
30
|
-
: MIN_YIELD_TIME_MS;
|
|
31
|
-
const upper = empty ? MAX_EMPTY_YIELD_TIME_MS : MAX_YIELD_TIME_MS;
|
|
32
|
-
return Math.max(lower, Math.min(upper, Math.trunc(value ?? fallback)));
|
|
33
|
-
}
|
|
34
|
-
function outputLimit(maxOutputBytes, maxOutputTokens) {
|
|
35
|
-
const tokens = maxOutputTokens ?? DEFAULT_OUTPUT_TOKENS;
|
|
36
|
-
if (maxOutputTokens !== undefined)
|
|
37
|
-
positiveFinite('max_output_tokens', maxOutputTokens);
|
|
38
|
-
return Math.max(1, Math.min(maxOutputBytes, Math.trunc(tokens * APPROX_BYTES_PER_TOKEN)));
|
|
39
|
-
}
|
|
40
|
-
function limitOutput(text, maxBytes) {
|
|
41
|
-
if (Buffer.byteLength(text, 'utf8') <= maxBytes)
|
|
42
|
-
return text;
|
|
43
|
-
let end = Math.min(text.length, maxBytes);
|
|
44
|
-
while (end > 0 && Buffer.byteLength(text.slice(0, end), 'utf8') > maxBytes)
|
|
45
|
-
end--;
|
|
46
|
-
return `${text.slice(0, end)}\n[output truncated]`;
|
|
47
|
-
}
|
|
48
|
-
function newChunkId() {
|
|
49
|
-
return randomBytes(3).toString('hex');
|
|
50
|
-
}
|
|
51
|
-
function withChunkId(result) {
|
|
52
|
-
return { chunk_id: newChunkId(), ...result };
|
|
53
|
-
}
|
|
54
|
-
/** Render the ordinary Responses tool result text used by Codex's unified exec tools. */
|
|
55
|
-
export function renderExecResult(result) {
|
|
56
|
-
const sections = [];
|
|
57
|
-
if (result.chunk_id !== undefined)
|
|
58
|
-
sections.push(`Chunk ID: ${result.chunk_id}`);
|
|
59
|
-
sections.push(`Wall time: ${result.wall_time_seconds.toFixed(4)} seconds`);
|
|
60
|
-
if (result.exit_code !== undefined)
|
|
61
|
-
sections.push(`Process exited with code ${result.exit_code}`);
|
|
62
|
-
if (result.session_id !== undefined)
|
|
63
|
-
sections.push(`Process running with session ID ${result.session_id}`);
|
|
64
|
-
if (result.job_id !== undefined)
|
|
65
|
-
sections.push(`Background job ID: ${result.job_id}`);
|
|
66
|
-
if (result.original_token_count !== undefined)
|
|
67
|
-
sections.push(`Original token count: ${result.original_token_count}`);
|
|
68
|
-
sections.push('Output:', result.output);
|
|
69
|
-
return sections.join('\n');
|
|
70
|
-
}
|
|
71
|
-
function sessionCwd(exec, workdir) {
|
|
72
|
-
const base = exec.agent?.session.header.cwd ?? process.cwd();
|
|
73
|
-
if (workdir === undefined)
|
|
74
|
-
return exec.agent?.session.header.cwd;
|
|
75
|
-
return resolvePath(base, workdir);
|
|
76
|
-
}
|
|
77
|
-
function readShellOutput(read, maxBytes) {
|
|
78
|
-
return limitOutput(read.delta, maxBytes);
|
|
79
|
-
}
|
|
80
|
-
function terminalResult(result, maxBytes, startedAt) {
|
|
81
|
-
const output = limitOutput(result.viewport, maxBytes);
|
|
82
|
-
return withChunkId({
|
|
83
|
-
wall_time_seconds: (performance.now() - startedAt) / 1000,
|
|
84
|
-
output,
|
|
85
|
-
...result.sessionStatus.kind === 'exited' ? {
|
|
86
|
-
...result.sessionStatus.exitCode === null ? {} : { exit_code: result.sessionStatus.exitCode },
|
|
87
|
-
} : {},
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
/** Map a detached shell process onto the generic DSH job outcome contract. */
|
|
91
|
-
function backgroundOutcome(process) {
|
|
92
|
-
if (process.status === 'killed') {
|
|
93
|
-
return {
|
|
94
|
-
status: 'killed',
|
|
95
|
-
detail: process.signal !== null ? `signal: ${process.signal}` : 'killed before exit',
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
return { status: 'completed', detail: `exit code: ${process.exitCode ?? 0}` };
|
|
99
|
-
}
|
|
100
|
-
function sleep(ms, signal) {
|
|
101
|
-
return new Promise(resolve => {
|
|
102
|
-
let timer;
|
|
103
|
-
const finish = (result) => {
|
|
104
|
-
if (timer !== undefined)
|
|
105
|
-
clearTimeout(timer);
|
|
106
|
-
signal.removeEventListener('abort', onAbort);
|
|
107
|
-
resolve(result);
|
|
108
|
-
};
|
|
109
|
-
const onAbort = () => finish('aborted');
|
|
110
|
-
if (signal.aborted) {
|
|
111
|
-
finish('aborted');
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
signal.addEventListener('abort', onAbort, { once: true });
|
|
115
|
-
timer = setTimeout(() => finish('elapsed'), ms);
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
async function waitForShell(process, ms, signal) {
|
|
119
|
-
const timer = sleep(ms, signal);
|
|
120
|
-
const completed = await Promise.race([
|
|
121
|
-
process.done.then(() => true),
|
|
122
|
-
timer.then(result => result === 'aborted' ? false : undefined),
|
|
123
|
-
]);
|
|
124
|
-
if (signal.aborted)
|
|
125
|
-
signal.throwIfAborted();
|
|
126
|
-
return completed === true || process.status !== 'running';
|
|
127
|
-
}
|
|
128
|
-
/** Stop a pipe-backed session when the current Codex tool is cancelled. */
|
|
129
|
-
async function stopShellOnAbort(process, signal) {
|
|
130
|
-
if (!signal.aborted || process.status !== 'running')
|
|
131
|
-
return;
|
|
132
|
-
process.kill();
|
|
133
|
-
await process.done;
|
|
134
|
-
}
|
|
135
|
-
function allocateSession(agent, session) {
|
|
136
|
-
const state = stateFor(agent);
|
|
137
|
-
const id = ++state.nextId;
|
|
138
|
-
state.sessions.set(id, session);
|
|
139
|
-
return id;
|
|
140
|
-
}
|
|
141
|
-
function storedSession(agent, id) {
|
|
142
|
-
const session = stateFor(agent).sessions.get(id);
|
|
143
|
-
if (session === undefined)
|
|
144
|
-
throw new Error(`unknown unified exec session ${id}`);
|
|
145
|
-
return session;
|
|
146
|
-
}
|
|
147
|
-
function forgetSession(agent, id) {
|
|
148
|
-
stateFor(agent).sessions.delete(id);
|
|
149
|
-
}
|
|
150
|
-
function commandFor(args) {
|
|
151
|
-
// The selected dsh shell provider owns the actual executable and login
|
|
152
|
-
// defaults. These fields remain accepted so Codex's argument contract is
|
|
153
|
-
// stable; dsh's shell capability is the deployment extension point.
|
|
154
|
-
return args.cmd;
|
|
155
|
-
}
|
|
156
|
-
/** Execute one Codex command through the configured pipe or PTY capability. */
|
|
157
|
-
export async function runExecCommand(ctx, args, exec, config) {
|
|
158
|
-
if (args.cmd.trim().length === 0)
|
|
159
|
-
throw new Error('cmd must be a non-empty string');
|
|
160
|
-
positiveFinite('yield_time_ms', args.yield_time_ms);
|
|
161
|
-
const maxBytes = outputLimit(config.maxOutputBytes, args.max_output_tokens);
|
|
162
|
-
const workdir = sessionCwd(exec, args.workdir);
|
|
163
|
-
const startedAt = performance.now();
|
|
164
|
-
if (args.run_in_background === true && args.tty === true) {
|
|
165
|
-
throw new Error('run_in_background is only supported for pipe-backed commands; omit tty');
|
|
166
|
-
}
|
|
167
|
-
if (args.tty === true) {
|
|
168
|
-
const agent = exec.agent;
|
|
169
|
-
const terminals = ctx.get('terminals');
|
|
170
|
-
if (agent === undefined || terminals === undefined) {
|
|
171
|
-
throw new Error('exec_command with tty=true requires the dsh terminal capability and an owning agent session');
|
|
172
|
-
}
|
|
173
|
-
const spawnRequest = {
|
|
174
|
-
type: 'shell',
|
|
175
|
-
...args.shell === undefined ? {} : { shell: args.shell },
|
|
176
|
-
login: args.login ?? true,
|
|
177
|
-
...workdir === undefined ? {} : { cwd: workdir },
|
|
178
|
-
};
|
|
179
|
-
const spawned = await terminals.spawn(agent, spawnRequest, exec.signal);
|
|
180
|
-
let retained = false;
|
|
181
|
-
let closeReason = 'Codex command failed';
|
|
182
|
-
try {
|
|
183
|
-
const sendRequest = {
|
|
184
|
-
text: commandFor(args),
|
|
185
|
-
submit: true,
|
|
186
|
-
waitMs: normalizeWaitMs(args.yield_time_ms, config.defaultYieldTimeMs, false, true),
|
|
187
|
-
signal: exec.signal,
|
|
188
|
-
};
|
|
189
|
-
const operation = terminals.startSend(agent, spawned.sessionId, sendRequest);
|
|
190
|
-
const result = await operation.done;
|
|
191
|
-
const output = terminalResult(result, maxBytes, startedAt);
|
|
192
|
-
if (result.sessionStatus.kind === 'running') {
|
|
193
|
-
output.session_id = allocateSession(agent, { kind: 'terminal', owner: agent, id: spawned.sessionId });
|
|
194
|
-
retained = true;
|
|
195
|
-
}
|
|
196
|
-
else {
|
|
197
|
-
closeReason = 'Codex command exited';
|
|
198
|
-
}
|
|
199
|
-
return output;
|
|
200
|
-
}
|
|
201
|
-
finally {
|
|
202
|
-
// A PTY is published by spawn before the first send starts. Do not leave
|
|
203
|
-
// that session behind when send setup or its foreground operation fails.
|
|
204
|
-
if (!retained)
|
|
205
|
-
await terminals.kill(agent, spawned.sessionId, closeReason);
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
const policy = ctx.get('sandboxPolicy')?.resolve(exec.agent === undefined ? {} : { session: exec.agent.session });
|
|
209
|
-
const dshEnv = ctx.get('shellEnv')?.collect(exec);
|
|
210
|
-
// Background jobs intentionally omit the tool-call signal. Once this call
|
|
211
|
-
// returns, the job lifetime belongs to the jobs registry, not the request.
|
|
212
|
-
const shellRequest = {
|
|
213
|
-
command: commandFor(args),
|
|
214
|
-
...args.shell === undefined ? {} : { shell: args.shell },
|
|
215
|
-
login: args.login ?? true,
|
|
216
|
-
...workdir === undefined ? {} : { workdir },
|
|
217
|
-
stdoutMaxBytes: maxBytes,
|
|
218
|
-
...dshEnv === undefined ? {} : { dshEnv },
|
|
219
|
-
...policy === undefined ? {} : { sandboxPolicy: policy },
|
|
220
|
-
};
|
|
221
|
-
if (args.run_in_background === true) {
|
|
222
|
-
const owner = exec.agent;
|
|
223
|
-
if (owner === undefined)
|
|
224
|
-
throw new Error('run_in_background requires an owning agent session');
|
|
225
|
-
const jobs = ctx.get('jobs');
|
|
226
|
-
if (jobs === undefined) {
|
|
227
|
-
throw new Error('background jobs unavailable: load @deepseek-ai/dsh-jobs and @deepseek-ai/dsh-tool-jobs');
|
|
228
|
-
}
|
|
229
|
-
if (exec.signal.aborted) {
|
|
230
|
-
exec.signal.throwIfAborted();
|
|
231
|
-
throw new Error('tool call aborted');
|
|
232
|
-
}
|
|
233
|
-
const id = jobs.start({
|
|
234
|
-
kind: 'bash',
|
|
235
|
-
label: args.cmd,
|
|
236
|
-
owner,
|
|
237
|
-
outputLimitBytes: maxBytes,
|
|
238
|
-
run: () => {
|
|
239
|
-
const process = ctx.shell.start(ctx.shell.resolve(shellRequest));
|
|
240
|
-
return {
|
|
241
|
-
cancel: () => void process.kill(),
|
|
242
|
-
done: process.done.then(() => backgroundOutcome(process)),
|
|
243
|
-
readOutput: () => readShellOutput(process.readOutput(), maxBytes),
|
|
244
|
-
};
|
|
245
|
-
},
|
|
246
|
-
});
|
|
247
|
-
return withChunkId({
|
|
248
|
-
wall_time_seconds: (performance.now() - startedAt) / 1000,
|
|
249
|
-
job_id: id,
|
|
250
|
-
output: `Started background job ${id}. Use job_output with job_id "${id}" to read output.`,
|
|
251
|
-
});
|
|
252
|
-
}
|
|
253
|
-
const process = ctx.shell.start(ctx.shell.resolve({
|
|
254
|
-
...shellRequest,
|
|
255
|
-
signal: exec.signal,
|
|
256
|
-
}));
|
|
257
|
-
try {
|
|
258
|
-
await waitForShell(process, normalizeWaitMs(args.yield_time_ms, config.defaultYieldTimeMs, false, true), exec.signal);
|
|
259
|
-
const output = readShellOutput(process.readOutput(), maxBytes);
|
|
260
|
-
if (process.status === 'running') {
|
|
261
|
-
if (exec.agent === undefined) {
|
|
262
|
-
process.kill();
|
|
263
|
-
await process.done;
|
|
264
|
-
return withChunkId({
|
|
265
|
-
wall_time_seconds: (performance.now() - startedAt) / 1000,
|
|
266
|
-
output: readShellOutput(process.readOutput(), maxBytes),
|
|
267
|
-
});
|
|
268
|
-
}
|
|
269
|
-
return withChunkId({
|
|
270
|
-
wall_time_seconds: (performance.now() - startedAt) / 1000,
|
|
271
|
-
output,
|
|
272
|
-
session_id: allocateSession(exec.agent, { kind: 'shell', process }),
|
|
273
|
-
});
|
|
274
|
-
}
|
|
275
|
-
return withChunkId({
|
|
276
|
-
wall_time_seconds: (performance.now() - startedAt) / 1000,
|
|
277
|
-
output,
|
|
278
|
-
...process.exitCode === null ? {} : { exit_code: process.exitCode },
|
|
279
|
-
});
|
|
280
|
-
}
|
|
281
|
-
finally {
|
|
282
|
-
await stopShellOnAbort(process, exec.signal);
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
/** Poll or write to one session returned by {@link runExecCommand}. */
|
|
286
|
-
export async function runWriteStdin(ctx, args, exec, config) {
|
|
287
|
-
positiveFinite('yield_time_ms', args.yield_time_ms);
|
|
288
|
-
if (!Number.isSafeInteger(args.session_id) || args.session_id <= 0) {
|
|
289
|
-
throw new Error('session_id must be a positive integer');
|
|
290
|
-
}
|
|
291
|
-
const agent = exec.agent;
|
|
292
|
-
if (agent === undefined)
|
|
293
|
-
throw new Error('write_stdin requires an owning agent session');
|
|
294
|
-
const session = storedSession(agent, args.session_id);
|
|
295
|
-
const maxBytes = outputLimit(config.maxOutputBytes, args.max_output_tokens);
|
|
296
|
-
const startedAt = performance.now();
|
|
297
|
-
const chars = args.chars ?? '';
|
|
298
|
-
if (session.kind === 'shell') {
|
|
299
|
-
if (chars.length > 0) {
|
|
300
|
-
throw new Error('this unified exec session uses pipes and does not accept stdin; rerun exec_command with tty=true');
|
|
301
|
-
}
|
|
302
|
-
try {
|
|
303
|
-
await waitForShell(session.process, normalizeWaitMs(args.yield_time_ms, config.pollYieldTimeMs, true), exec.signal);
|
|
304
|
-
const output = readShellOutput(session.process.readOutput(), maxBytes);
|
|
305
|
-
if (session.process.status !== 'running') {
|
|
306
|
-
forgetSession(agent, args.session_id);
|
|
307
|
-
return withChunkId({
|
|
308
|
-
wall_time_seconds: (performance.now() - startedAt) / 1000,
|
|
309
|
-
output,
|
|
310
|
-
...session.process.exitCode === null ? {} : { exit_code: session.process.exitCode },
|
|
311
|
-
});
|
|
312
|
-
}
|
|
313
|
-
return withChunkId({
|
|
314
|
-
wall_time_seconds: (performance.now() - startedAt) / 1000,
|
|
315
|
-
output,
|
|
316
|
-
session_id: args.session_id,
|
|
317
|
-
});
|
|
318
|
-
}
|
|
319
|
-
finally {
|
|
320
|
-
if (exec.signal.aborted) {
|
|
321
|
-
try {
|
|
322
|
-
await stopShellOnAbort(session.process, exec.signal);
|
|
323
|
-
}
|
|
324
|
-
finally {
|
|
325
|
-
forgetSession(agent, args.session_id);
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
const terminals = ctx.get('terminals');
|
|
331
|
-
if (terminals === undefined)
|
|
332
|
-
throw new Error('the dsh terminal capability is no longer available');
|
|
333
|
-
const sendRequest = {
|
|
334
|
-
text: chars,
|
|
335
|
-
submit: false,
|
|
336
|
-
waitMs: normalizeWaitMs(args.yield_time_ms, chars.length > 0 ? config.writeYieldTimeMs : config.pollYieldTimeMs, chars.length === 0),
|
|
337
|
-
signal: exec.signal,
|
|
338
|
-
};
|
|
339
|
-
let retained = false;
|
|
340
|
-
let closeReason = 'Codex command failed';
|
|
341
|
-
try {
|
|
342
|
-
const operation = terminals.startSend(agent, session.id, sendRequest);
|
|
343
|
-
const result = await operation.done;
|
|
344
|
-
const output = terminalResult(result, maxBytes, startedAt);
|
|
345
|
-
if (result.sessionStatus.kind === 'running') {
|
|
346
|
-
output.session_id = args.session_id;
|
|
347
|
-
retained = true;
|
|
348
|
-
}
|
|
349
|
-
else {
|
|
350
|
-
closeReason = 'Codex command exited';
|
|
351
|
-
forgetSession(agent, args.session_id);
|
|
352
|
-
}
|
|
353
|
-
return output;
|
|
354
|
-
}
|
|
355
|
-
finally {
|
|
356
|
-
// A failed send must not strand either side of the two-level session
|
|
357
|
-
// registry: the local numeric id and the underlying PTY must be retired
|
|
358
|
-
// together. A successful running result is the only retained case.
|
|
359
|
-
if (!retained) {
|
|
360
|
-
forgetSession(agent, args.session_id);
|
|
361
|
-
await terminals.kill(agent, session.id, closeReason);
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
//# sourceMappingURL=exec.js.map
|
package/lib/types/index.d.ts
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
/** Codex-compatible prompt overlay and core tools for a dsh agent preset. */
|
|
2
|
-
import type { Context } from '@deepseek-ai/cordis';
|
|
3
|
-
import z from '@deepseek-ai/schemastery';
|
|
4
|
-
import type { LlmCallConfig } from '@deepseek-ai/dsh-llm';
|
|
5
|
-
import type { Session } from '@deepseek-ai/dsh-session';
|
|
6
|
-
import type { PromptAssembly } from '@deepseek-ai/dsh-system-prompt';
|
|
7
|
-
import type { CodexSettings } from './settings.ts';
|
|
8
|
-
export { DEFAULT_CODEX_PERSONA, DEFAULT_CODEX_SYSTEM_PROMPT, DEFAULT_DSH_CORE_SOURCE_PROMPT, DEFAULT_DSH_CORE_WEB_PROMPT, } from './prompt.ts';
|
|
9
|
-
export { CODEX_SETTINGS_NAMESPACE, CODEX_SETTINGS_SCHEMA } from './settings.ts';
|
|
10
|
-
export type { CodexSettings } from './settings.ts';
|
|
11
|
-
export declare const name = "codex";
|
|
12
|
-
export declare const inject: string[];
|
|
13
|
-
/** Configuration for the Codex shell result bridge. */
|
|
14
|
-
export interface Config {
|
|
15
|
-
/** Install request/transport/activity enhancements for every agent scope. */
|
|
16
|
-
globalEnhancements?: boolean;
|
|
17
|
-
/** Install the Codex operating prompt and four core tools in this scope. */
|
|
18
|
-
codexCore?: boolean;
|
|
19
|
-
/** Default wait before a pipe-backed command yields a session id. */
|
|
20
|
-
defaultYieldTimeMs?: number;
|
|
21
|
-
/** Default wait for an empty `write_stdin` poll. */
|
|
22
|
-
pollYieldTimeMs?: number;
|
|
23
|
-
/** Default wait for a non-empty `write_stdin` send. */
|
|
24
|
-
writeYieldTimeMs?: number;
|
|
25
|
-
/** Maximum output retained in one canonical result, in UTF-8 bytes. */
|
|
26
|
-
maxOutputBytes?: number;
|
|
27
|
-
/** Send GPT Responses requests with the native hosted web_search tool first. */
|
|
28
|
-
hostedWebSearch?: boolean;
|
|
29
|
-
/** Use the provider's /responses/compact endpoint before local compaction. */
|
|
30
|
-
remoteCompact?: boolean;
|
|
31
|
-
/** Complete plugin-owned Codex operating prompt. */
|
|
32
|
-
systemPrompt?: string;
|
|
33
|
-
/** Explicit per-preset operating prompt; overrides the shared prompt only. */
|
|
34
|
-
presetPrompt?: string;
|
|
35
|
-
presetSections?: import('./prompt-sections.ts').Config;
|
|
36
|
-
/** Per-preset Codex capability overrides. Omitted values follow shared settings. */
|
|
37
|
-
promptEnabled?: boolean;
|
|
38
|
-
terminalToolsEnabled?: boolean;
|
|
39
|
-
patchToolEnabled?: boolean;
|
|
40
|
-
planToolEnabled?: boolean;
|
|
41
|
-
hostedWebSearchEnabled?: boolean;
|
|
42
|
-
remoteCompactionEnabled?: boolean;
|
|
43
|
-
/** Deployment Persona template. */
|
|
44
|
-
persona?: string;
|
|
45
|
-
/** DSH Core source-checkout guidance template. */
|
|
46
|
-
harnessSourcePrompt?: string;
|
|
47
|
-
/** DSH Core Web GUI guidance template. */
|
|
48
|
-
webSurfacePrompt?: string;
|
|
49
|
-
}
|
|
50
|
-
/** Runtime configuration schema for the Codex tool bridge. */
|
|
51
|
-
export declare const Config: z<Config>;
|
|
52
|
-
/** Codex request envelope with the plugin's provider-facing service-tier field. */
|
|
53
|
-
export interface CodexRequestConfig extends LlmCallConfig {
|
|
54
|
-
/** Codex request context capacity override, retained for older DSH hosts. */
|
|
55
|
-
contextWindow?: number;
|
|
56
|
-
/** Provider-facing service tier, for example Responses `priority`. */
|
|
57
|
-
serviceTier?: string;
|
|
58
|
-
}
|
|
59
|
-
export interface CodexModelProfile {
|
|
60
|
-
id: string;
|
|
61
|
-
input?: string[];
|
|
62
|
-
reasoningEfforts?: false | Record<string, string | null>;
|
|
63
|
-
[key: string]: unknown;
|
|
64
|
-
}
|
|
65
|
-
/** Add Codex defaults without overwriting explicit user capabilities. */
|
|
66
|
-
export declare function enrichCodexModel(model: CodexModelProfile): CodexModelProfile;
|
|
67
|
-
/**
|
|
68
|
-
* Pair the live Codex capacity with the token-meter context projection.
|
|
69
|
-
*
|
|
70
|
-
* The core loop records adapter metadata in `request/context`, while Codex's
|
|
71
|
-
* setting is a request-scoped LLM capacity. Appending the override after the
|
|
72
|
-
* loop's metadata event keeps the official ContextMeter and compaction engine
|
|
73
|
-
* on the same effective capacity.
|
|
74
|
-
*/
|
|
75
|
-
export declare function syncCodexContextWindow(session: Session, contextWindow: number | undefined): void;
|
|
76
|
-
/** Apply the live Codex controls to one agent request without leaking them to other routes. */
|
|
77
|
-
export declare function applyCodexRequestSettings(request: CodexRequestConfig, settings: CodexSettings): CodexRequestConfig;
|
|
78
|
-
/** Put the agent persona first and omit the generic Harness identity opener. */
|
|
79
|
-
export declare function normalizeCodexPromptAssembly(assembly: PromptAssembly): PromptAssembly;
|
|
80
|
-
/** Remove disabled Codex capabilities from the next model-visible assembly. */
|
|
81
|
-
export declare function applyCodexCapabilitySettings(assembly: PromptAssembly, settings: CodexSettings): PromptAssembly;
|
|
82
|
-
/** Build the complete plugin-owned prompt, preserving an intentional empty value. */
|
|
83
|
-
export declare function buildCodexSystemPrompt(config?: Pick<Config, 'systemPrompt'>): string;
|
|
84
|
-
/** Explicit preset instructions win without changing shared tools or permissions. */
|
|
85
|
-
export declare function withPresetPrompt(settings: CodexSettings, presetPrompt: string | undefined): CodexSettings;
|
|
86
|
-
/** Mount the Codex prompt/tool layer inside one fixed agent preset. */
|
|
87
|
-
export declare function apply(ctx: Context, config?: Config): void;
|
|
88
|
-
declare const _default: {
|
|
89
|
-
name: string;
|
|
90
|
-
inject: string[];
|
|
91
|
-
Config: z<Config>;
|
|
92
|
-
apply: typeof apply;
|
|
93
|
-
};
|
|
94
|
-
export default _default;
|
|
95
|
-
//# sourceMappingURL=index.d.ts.map
|