@shuind/dsh-codex-harness 0.2.21 → 0.2.32-dsh-v0.2.2-rc.1

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 (128) hide show
  1. package/CHANGELOG.md +121 -0
  2. package/README.md +48 -38
  3. package/RELEASE.md +61 -0
  4. package/assets/codex.svg +5 -0
  5. package/cordis.patch.yml +150 -6
  6. package/docs/preset-library.md +39 -23
  7. package/docs/tool-policy-benchmark.json +310 -0
  8. package/docs/tool-policy.md +144 -0
  9. package/lib/client.js +1639 -111
  10. package/lib/compaction.js +17 -2
  11. package/lib/index.js +799 -188
  12. package/lib/installer.js +50 -6
  13. package/lib/preferences.js +111 -0
  14. package/lib/tool-policy.js +2235 -0
  15. package/lib/typert.js +57 -10
  16. package/lib/types/activity.d.ts +1 -1
  17. package/lib/types/activity.js +50 -14
  18. package/lib/types/client/activity.d.ts +33 -9
  19. package/lib/types/client/desktop.d.ts +43 -0
  20. package/lib/types/client/desktop.js +121 -0
  21. package/lib/types/client/entry.d.ts +10 -0
  22. package/lib/types/client/entry.js +12 -0
  23. package/lib/types/client/index.d.ts +109 -19
  24. package/lib/types/client/index.js +21 -40
  25. package/lib/types/client/policy-drafts.d.ts +25 -0
  26. package/lib/types/client/policy-drafts.js +47 -0
  27. package/lib/types/client/preset-copy.d.ts +1 -0
  28. package/lib/types/client/preset-copy.js +2 -0
  29. package/lib/types/client/preset-manager.d.ts +12 -2
  30. package/lib/types/client/preset-manager.js +70 -25
  31. package/lib/types/client/preset-requests.d.ts +12 -0
  32. package/lib/types/client/preset-requests.js +101 -0
  33. package/lib/types/client/session.d.ts +6 -0
  34. package/lib/types/client/session.js +9 -0
  35. package/lib/types/client/tool-policy.d.ts +120 -0
  36. package/lib/types/client/tool-policy.js +394 -0
  37. package/lib/types/compaction.d.ts +3 -3
  38. package/lib/types/compaction.js +6 -2
  39. package/lib/types/desktop-preset.d.ts +20 -0
  40. package/lib/types/desktop-preset.js +39 -0
  41. package/lib/types/exec.d.ts +4 -0
  42. package/lib/types/exec.js +192 -66
  43. package/lib/types/host-settings.d.ts +4 -0
  44. package/lib/types/host-settings.js +13 -0
  45. package/lib/types/index.d.ts +20 -2
  46. package/lib/types/index.js +181 -68
  47. package/lib/types/installer.js +11 -2
  48. package/lib/types/preferences.d.ts +11 -0
  49. package/lib/types/preferences.js +16 -0
  50. package/lib/types/preset-editor-remote.d.ts +2 -0
  51. package/lib/types/preset-editor-remote.js +6 -2
  52. package/lib/types/preset-editor.d.ts +12 -7
  53. package/lib/types/preset-editor.js +43 -13
  54. package/lib/types/preset-prompt-catalog-schema.d.ts +16 -0
  55. package/lib/types/preset-prompt-catalog-schema.js +11 -0
  56. package/lib/types/preset-prompt-catalog.d.ts +21 -0
  57. package/lib/types/preset-prompt-catalog.js +192 -0
  58. package/lib/types/preset-prompt-contract.d.ts +22 -0
  59. package/lib/types/preset-prompt-contract.js +3 -0
  60. package/lib/types/preset-tool-catalog-schema.d.ts +38 -0
  61. package/lib/types/preset-tool-catalog-schema.js +28 -0
  62. package/lib/types/preset-tool-catalog.d.ts +5 -0
  63. package/lib/types/preset-tool-catalog.js +51 -0
  64. package/lib/types/prompt-sections.d.ts +1 -1
  65. package/lib/types/prompt-sections.js +9 -3
  66. package/lib/types/prompt.js +4 -2
  67. package/lib/types/remote.js +23 -8
  68. package/lib/types/settings.d.ts +3 -3
  69. package/lib/types/settings.js +3 -3
  70. package/lib/types/tool-capabilities.d.ts +32 -0
  71. package/lib/types/tool-capabilities.js +42 -0
  72. package/lib/types/tool-policy-contract.d.ts +60 -0
  73. package/lib/types/tool-policy-contract.js +26 -0
  74. package/lib/types/tool-policy.d.ts +171 -0
  75. package/lib/types/tool-policy.js +367 -0
  76. package/lib/types/typert.host.d.ts +2 -2
  77. package/lib/types/typert.host.js +12 -2
  78. package/locale/en.json +6 -0
  79. package/locale/tool-policy/en.json +6 -0
  80. package/locale/tool-policy/zh.json +6 -0
  81. package/locale/zh.json +6 -0
  82. package/package.json +375 -299
  83. package/scripts/benchmark-tool-policy.mjs +186 -0
  84. package/scripts/build-preset.mjs +19 -0
  85. package/scripts/clean-build.mjs +11 -0
  86. package/src/activity-types.ts +7 -0
  87. package/src/activity.ts +158 -0
  88. package/src/client/activity.ts +82 -0
  89. package/src/client/desktop.tsx +162 -0
  90. package/src/client/entry.tsx +16 -0
  91. package/src/client/index.tsx +972 -0
  92. package/src/client/policy-drafts.ts +56 -0
  93. package/src/client/preset-copy.ts +83 -0
  94. package/src/client/preset-manager.tsx +281 -0
  95. package/src/client/preset-requests.ts +113 -0
  96. package/src/client/session.ts +11 -0
  97. package/src/client/tool-policy.tsx +380 -0
  98. package/src/compact-command.ts +112 -0
  99. package/src/compaction.ts +190 -0
  100. package/src/context.ts +15 -0
  101. package/src/desktop-preset.ts +55 -0
  102. package/src/exec.ts +570 -0
  103. package/src/host-settings.ts +17 -0
  104. package/src/index.ts +1097 -0
  105. package/src/installer.ts +172 -0
  106. package/src/invariant.ts +34 -0
  107. package/src/patch.ts +258 -0
  108. package/src/preferences.ts +17 -0
  109. package/src/preset-contract.ts +85 -0
  110. package/src/preset-editor-remote.ts +41 -0
  111. package/src/preset-editor.ts +502 -0
  112. package/src/preset-prompt-catalog-schema.ts +10 -0
  113. package/src/preset-prompt-catalog.ts +191 -0
  114. package/src/preset-prompt-contract.ts +21 -0
  115. package/src/preset-tool-catalog-schema.ts +28 -0
  116. package/src/preset-tool-catalog.ts +51 -0
  117. package/src/prompt-sections.ts +33 -0
  118. package/src/prompt.ts +62 -0
  119. package/src/remote.ts +748 -0
  120. package/src/settings.ts +79 -0
  121. package/src/tool-capabilities.ts +76 -0
  122. package/src/tool-policy-contract.ts +76 -0
  123. package/src/tool-policy.ts +388 -0
  124. package/src/typert.host.ts +119 -0
  125. package/tsconfig.json +29 -0
  126. package/tsdown.config.ts +110 -0
  127. package/lib/types/preset-templates.d.ts +0 -36
  128. package/lib/types/preset-templates.js +0 -12
@@ -0,0 +1,39 @@
1
+ import { readFileSync } from 'node:fs';
2
+ import { join } from 'node:path';
3
+ import { parseDocument } from 'yaml';
4
+ /** Keep expressions literal for the Desktop Loader, not YAML strings or eager eval. */
5
+ function readYaml(path) {
6
+ const document = parseDocument(readFileSync(path, 'utf8'), {
7
+ customTags: [{
8
+ tag: 'tag:yaml.org,2002:js',
9
+ resolve: (expression) => ({ __jsExpr: expression }),
10
+ }],
11
+ });
12
+ if (document.errors.length)
13
+ throw document.errors[0];
14
+ return document.toJS();
15
+ }
16
+ /** Convert the legacy file composition to Harness 0.2.2's declarative preset APIs. */
17
+ export function desktopCodexPreset(sourceDirectory) {
18
+ const metadata = readYaml(join(sourceDirectory, 'preset.yml'));
19
+ const plugins = readYaml(join(sourceDirectory, 'agent.cordis.yml'));
20
+ function adapt(rows) {
21
+ // Child discovery now belongs to the control plugin's root export.
22
+ return rows.filter(row => row.name !== '@deepseek-ai/dsh-tool-subagent-control/list-agents').map(row => {
23
+ if (row.name === '@deepseek-ai/dsh-workflow-worker-thread') {
24
+ row.name = '@deepseek-ai/dsh-workflow-ptc';
25
+ }
26
+ if (row.name === '@deepseek-ai/dsh-tool-subagent' && row.config && !Array.isArray(row.config)) {
27
+ const { modelSelectionSettings, backgroundMode: _backgroundMode, ...config } = row.config;
28
+ row.config = modelSelectionSettings === undefined ? config : {
29
+ ...config, modelSelection: modelSelectionSettings, modelDiscovery: modelSelectionSettings,
30
+ };
31
+ }
32
+ if (row.group && Array.isArray(row.config))
33
+ row.config = adapt(row.config);
34
+ return row;
35
+ });
36
+ }
37
+ return { ...metadata, id: 'codex-collaboration', plugins: adapt(plugins) };
38
+ }
39
+ //# sourceMappingURL=desktop-preset.js.map
@@ -11,6 +11,8 @@ export interface ExecCommandArgs {
11
11
  max_output_tokens?: number;
12
12
  shell?: string;
13
13
  login?: boolean;
14
+ sandbox_permissions?: string;
15
+ justification?: string;
14
16
  }
15
17
  /** The exact model-facing argument vocabulary of Codex's stdin poll tool. */
16
18
  export interface WriteStdinArgs {
@@ -32,6 +34,8 @@ export interface ExecResult {
32
34
  export declare function normalizeWaitMs(value: number | undefined, fallback: number, empty?: boolean, initialExec?: boolean): number;
33
35
  /** Render the ordinary Responses tool result text used by Codex's unified exec tools. */
34
36
  export declare function renderExecResult(result: ExecResult): string;
37
+ /** Per-call shell selection belonged to legacy providers, not the current shell seam. */
38
+ export declare function supportsLegacyShellOptions(ctx: Context): boolean;
35
39
  /** Execute one Codex command through the configured pipe or PTY capability. */
36
40
  export declare function runExecCommand(ctx: Context, args: ExecCommandArgs, exec: ToolExecution, config: {
37
41
  defaultYieldTimeMs: number;
package/lib/types/exec.js CHANGED
@@ -1,6 +1,8 @@
1
1
  /** Codex `exec_command` and `write_stdin` execution over dsh capability seams. */
2
2
  import { randomBytes } from 'node:crypto';
3
3
  import { resolve as resolvePath } from 'node:path';
4
+ import { HarnessError } from '@deepseek-ai/dsh-llm';
5
+ import { approveEscalation, escalationHintMarker, sandboxDenialMarker, validateEscalationArgs } from '@deepseek-ai/dsh-sandbox';
4
6
  const STATES = new WeakMap();
5
7
  const MIN_YIELD_TIME_MS = 250;
6
8
  const WINDOWS_INITIAL_EXEC_YIELD_TIME_MS = 10_000;
@@ -68,14 +70,66 @@ export function renderExecResult(result) {
68
70
  sections.push('Output:', result.output);
69
71
  return sections.join('\n');
70
72
  }
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);
73
+ function sessionCwd(ctx, exec, workdir) {
74
+ const directories = ctx.get('workingDirectory');
75
+ const cwd = exec.agent === undefined
76
+ ? undefined
77
+ : directories?.get(exec.agent.session) ?? exec.agent.session.header.cwd;
78
+ return workdir === undefined ? cwd : resolvePath(cwd ?? process.cwd(), workdir);
76
79
  }
77
- function readShellOutput(read, maxBytes) {
78
- return limitOutput(read.delta, maxBytes);
80
+ /** Per-call shell selection belonged to legacy providers, not the current shell seam. */
81
+ export function supportsLegacyShellOptions(ctx) {
82
+ const shell = ctx.get('shell');
83
+ if (shell === undefined)
84
+ throw new Error('exec_command requires ctx.shell');
85
+ return typeof shell.execute !== 'function';
86
+ }
87
+ /** Surface infrastructure failures from the current execution handle without reclassifying nonzero exits. */
88
+ async function assertShellCompleted(process, escalationAvailable = false) {
89
+ const result = process.result;
90
+ if (typeof result !== 'function')
91
+ return undefined;
92
+ try {
93
+ return await result.call(process);
94
+ }
95
+ catch (error) {
96
+ const notes = sandboxNotes(process.sandbox, escalationAvailable);
97
+ if (notes.length === 0)
98
+ throw error;
99
+ const message = [error instanceof Error ? error.message : String(error), ...notes].join('\n');
100
+ const failure = error instanceof HarnessError
101
+ ? new HarnessError(message, error.code, { cause: error })
102
+ : new Error(message, { cause: error });
103
+ if (error instanceof Error)
104
+ failure.name = error.name;
105
+ throw failure;
106
+ }
107
+ }
108
+ /** Preserve policy/runner facts after bounding command output; never truncate these markers. */
109
+ function sandboxNotes(sandbox, escalationAvailable) {
110
+ if (sandbox?.runnerFailed)
111
+ return [`[sandbox: the sandbox runner itself failed under ${sandbox.mode} mode — the command did not run; this is a sandbox problem, not a command failure]`];
112
+ if (!sandbox?.denied)
113
+ return [];
114
+ return [sandboxDenialMarker(sandbox.mode), ...escalationAvailable ? [escalationHintMarker('command')] : []];
115
+ }
116
+ /** Current executors prepare asynchronously; old providers published a handle synchronously. */
117
+ function startShell(ctx, request) {
118
+ const provider = ctx.get('shell');
119
+ if (provider === undefined)
120
+ throw new Error('exec_command requires ctx.shell');
121
+ const shell = provider;
122
+ const spec = shell.resolve(request);
123
+ if (typeof shell.execute === 'function')
124
+ return shell.execute(spec);
125
+ if (typeof shell.start === 'function')
126
+ return shell.start(spec);
127
+ throw new Error('exec_command: the configured shell has no execution capability');
128
+ }
129
+ function readShellOutput(read, maxBytes, sandbox, escalationAvailable = false) {
130
+ const output = limitOutput(read.delta, maxBytes);
131
+ const notes = sandboxNotes(sandbox, escalationAvailable);
132
+ return notes.length === 0 ? output : `${output}${output.length > 0 && !output.endsWith('\n') ? '\n' : ''}${notes.join('\n')}`;
79
133
  }
80
134
  function terminalResult(result, maxBytes, startedAt) {
81
135
  const output = limitOutput(result.viewport, maxBytes);
@@ -88,42 +142,37 @@ function terminalResult(result, maxBytes, startedAt) {
88
142
  });
89
143
  }
90
144
  /** 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}` };
145
+ function backgroundOutcome(process, escalationAvailable, sandbox = process.sandbox) {
146
+ const base = process.status === 'killed'
147
+ ? { status: 'killed', detail: process.signal !== null ? `signal: ${process.signal}` : 'killed before exit' }
148
+ : { status: 'completed', detail: `exit code: ${process.exitCode ?? 0}` };
149
+ const notes = sandboxNotes(sandbox, escalationAvailable);
150
+ return notes.length === 0 ? base : { ...base, detail: `${base.detail}; ${notes.join(' ')}` };
99
151
  }
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');
152
+ async function waitForShell(process, ms, signal) {
153
+ let timer;
154
+ let onAbort = () => { };
155
+ const elapsed = new Promise(resolve => {
156
+ onAbort = () => resolve(false);
110
157
  if (signal.aborted) {
111
- finish('aborted');
158
+ onAbort();
112
159
  return;
113
160
  }
114
161
  signal.addEventListener('abort', onAbort, { once: true });
115
- timer = setTimeout(() => finish('elapsed'), ms);
162
+ timer = setTimeout(() => resolve(undefined), ms);
116
163
  });
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';
164
+ try {
165
+ const completed = await Promise.race([process.done.then(() => true), elapsed]);
166
+ if (signal.aborted)
167
+ signal.throwIfAborted();
168
+ return completed === true || process.status !== 'running';
169
+ }
170
+ finally {
171
+ // Retire the losing wait even when the process completes before its deadline.
172
+ if (timer !== undefined)
173
+ clearTimeout(timer);
174
+ signal.removeEventListener('abort', onAbort);
175
+ }
127
176
  }
128
177
  /** Stop a pipe-backed session when the current Codex tool is cancelled. */
129
178
  async function stopShellOnAbort(process, signal) {
@@ -148,9 +197,8 @@ function forgetSession(agent, id) {
148
197
  stateFor(agent).sessions.delete(id);
149
198
  }
150
199
  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.
200
+ // Pass the command verbatim; executable/startup selection belongs to the
201
+ // mounted provider. Legacy shell controls are handled before this seam.
154
202
  return args.cmd;
155
203
  }
156
204
  /** Execute one Codex command through the configured pipe or PTY capability. */
@@ -159,7 +207,37 @@ export async function runExecCommand(ctx, args, exec, config) {
159
207
  throw new Error('cmd must be a non-empty string');
160
208
  positiveFinite('yield_time_ms', args.yield_time_ms);
161
209
  const maxBytes = outputLimit(config.maxOutputBytes, args.max_output_tokens);
162
- const workdir = sessionCwd(exec, args.workdir);
210
+ const legacyShellOptions = supportsLegacyShellOptions(ctx);
211
+ if (!legacyShellOptions && (args.shell !== undefined || args.login !== undefined)) {
212
+ throw new Error('exec_command: this host selects the shell and startup mode in its configuration; per-call shell/login options are unavailable');
213
+ }
214
+ validateEscalationArgs(args.sandbox_permissions, args.justification);
215
+ const confines = ctx.get('shell')?.sandboxMode !== undefined;
216
+ const policyService = ctx.get('sandboxPolicy');
217
+ if (confines && policyService === undefined)
218
+ throw new Error('exec_command: a sandboxing shell requires ctx.sandboxPolicy');
219
+ if (confines && args.tty === true)
220
+ throw new Error('exec_command: tty=true cannot carry the sandbox policy; use pipe-backed execution on this host');
221
+ let policy = policyService?.resolve(exec.agent === undefined ? {} : { session: exec.agent.session });
222
+ if (args.sandbox_permissions !== undefined) {
223
+ if (!confines)
224
+ throw new Error('sandbox_permissions is not available in this composition (no sandboxing executor to escalate)');
225
+ const approvedMode = await approveEscalation({
226
+ requestedMode: args.sandbox_permissions,
227
+ justification: args.justification,
228
+ effectiveMode: policy.mode,
229
+ subject: 'command',
230
+ }, {
231
+ approver: ctx.get('approval'),
232
+ agent: exec.agent,
233
+ callId: exec.callId,
234
+ toolName: 'exec_command',
235
+ signal: exec.signal,
236
+ });
237
+ exec.signal.throwIfAborted();
238
+ policy = { ...policy, mode: approvedMode };
239
+ }
240
+ const workdir = sessionCwd(ctx, exec, args.workdir);
163
241
  const startedAt = performance.now();
164
242
  if (args.run_in_background === true && args.tty === true) {
165
243
  throw new Error('run_in_background is only supported for pipe-backed commands; omit tty');
@@ -172,8 +250,10 @@ export async function runExecCommand(ctx, args, exec, config) {
172
250
  }
173
251
  const spawnRequest = {
174
252
  type: 'shell',
175
- ...args.shell === undefined ? {} : { shell: args.shell },
176
- login: args.login ?? true,
253
+ ...legacyShellOptions ? {
254
+ ...args.shell === undefined ? {} : { shell: args.shell },
255
+ login: args.login ?? true,
256
+ } : {},
177
257
  ...workdir === undefined ? {} : { cwd: workdir },
178
258
  };
179
259
  const spawned = await terminals.spawn(agent, spawnRequest, exec.signal);
@@ -205,14 +285,17 @@ export async function runExecCommand(ctx, args, exec, config) {
205
285
  await terminals.kill(agent, spawned.sessionId, closeReason);
206
286
  }
207
287
  }
208
- const policy = ctx.get('sandboxPolicy')?.resolve(exec.agent === undefined ? {} : { session: exec.agent.session });
209
288
  const dshEnv = ctx.get('shellEnv')?.collect(exec);
210
289
  // Background jobs intentionally omit the tool-call signal. Once this call
211
290
  // returns, the job lifetime belongs to the jobs registry, not the request.
212
291
  const shellRequest = {
213
292
  command: commandFor(args),
214
- ...args.shell === undefined ? {} : { shell: args.shell },
215
- login: args.login ?? true,
293
+ // Unified exec bounds its own wait; yielding must not arm the provider's kill deadline.
294
+ onExpiry: 'none',
295
+ ...legacyShellOptions ? {
296
+ ...args.shell === undefined ? {} : { shell: args.shell },
297
+ login: args.login ?? true,
298
+ } : {},
216
299
  ...workdir === undefined ? {} : { workdir },
217
300
  stdoutMaxBytes: maxBytes,
218
301
  ...dshEnv === undefined ? {} : { dshEnv },
@@ -230,19 +313,56 @@ export async function runExecCommand(ctx, args, exec, config) {
230
313
  exec.signal.throwIfAborted();
231
314
  throw new Error('tool call aborted');
232
315
  }
316
+ // The ring-backed jobs API owns output cursors and identifies owners by SessionId.
317
+ // Legacy registries instead accept the exact Agent and a consuming readOutput hook.
318
+ const ringBacked = typeof jobs.readAt === 'function';
319
+ let process;
320
+ let cancelled = false;
321
+ const lifetime = new AbortController();
322
+ const start = () => {
323
+ const prepared = startShell(ctx, {
324
+ ...shellRequest,
325
+ ...ringBacked ? { signal: lifetime.signal } : {},
326
+ });
327
+ const done = (async () => {
328
+ try {
329
+ process = 'then' in prepared ? await prepared : prepared;
330
+ if (cancelled)
331
+ process.kill();
332
+ await process.done;
333
+ const completed = await assertShellCompleted(process, confines);
334
+ return backgroundOutcome(process, confines, completed?.sandbox ?? process.sandbox);
335
+ }
336
+ catch (error) {
337
+ if (cancelled)
338
+ return { status: 'killed', detail: 'cancelled during shell preparation' };
339
+ return { status: 'failed', detail: [error instanceof Error ? error.message : String(error), ...sandboxNotes(process?.sandbox, confines)].join('; ') };
340
+ }
341
+ })();
342
+ return {
343
+ cancel: () => {
344
+ cancelled = true;
345
+ lifetime.abort();
346
+ process?.kill();
347
+ },
348
+ done,
349
+ ...ringBacked ? {} : {
350
+ readOutput: () => process === undefined ? '' : readShellOutput(process.readOutput(), maxBytes, process.sandbox, confines),
351
+ },
352
+ };
353
+ };
354
+ const output = ['stdout', 'stderr'].map(channel => ({
355
+ channel,
356
+ read: (fromByte) => process?.observed?.[channel].readFrom(fromByte)
357
+ ?? { text: '', nextOffset: fromByte, lossy: false },
358
+ }));
233
359
  const id = jobs.start({
234
360
  kind: 'bash',
235
361
  label: args.cmd,
236
- owner,
362
+ owner: ringBacked ? owner.id : owner,
237
363
  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
- },
364
+ ...ringBacked ? { output } : {},
365
+ run: start,
246
366
  });
247
367
  return withChunkId({
248
368
  wall_time_seconds: (performance.now() - startedAt) / 1000,
@@ -250,31 +370,32 @@ export async function runExecCommand(ctx, args, exec, config) {
250
370
  output: `Started background job ${id}. Use job_output with job_id "${id}" to read output.`,
251
371
  });
252
372
  }
253
- const process = ctx.shell.start(ctx.shell.resolve({
254
- ...shellRequest,
255
- signal: exec.signal,
256
- }));
373
+ const prepared = startShell(ctx, { ...shellRequest, signal: exec.signal });
374
+ const process = 'then' in prepared ? await prepared : prepared;
257
375
  try {
258
376
  await waitForShell(process, normalizeWaitMs(args.yield_time_ms, config.defaultYieldTimeMs, false, true), exec.signal);
259
- const output = readShellOutput(process.readOutput(), maxBytes);
377
+ const read = process.readOutput();
260
378
  if (process.status === 'running') {
379
+ const output = readShellOutput(read, maxBytes, process.sandbox, confines);
261
380
  if (exec.agent === undefined) {
262
381
  process.kill();
263
382
  await process.done;
383
+ const completed = await assertShellCompleted(process, confines);
264
384
  return withChunkId({
265
385
  wall_time_seconds: (performance.now() - startedAt) / 1000,
266
- output: readShellOutput(process.readOutput(), maxBytes),
386
+ output: readShellOutput({ ...read, delta: read.delta + process.readOutput().delta }, maxBytes, completed?.sandbox ?? process.sandbox, confines),
267
387
  });
268
388
  }
269
389
  return withChunkId({
270
390
  wall_time_seconds: (performance.now() - startedAt) / 1000,
271
391
  output,
272
- session_id: allocateSession(exec.agent, { kind: 'shell', process }),
392
+ session_id: allocateSession(exec.agent, { kind: 'shell', process, escalationAvailable: confines }),
273
393
  });
274
394
  }
395
+ const completed = await assertShellCompleted(process, confines);
275
396
  return withChunkId({
276
397
  wall_time_seconds: (performance.now() - startedAt) / 1000,
277
- output,
398
+ output: readShellOutput(read, maxBytes, completed?.sandbox ?? process.sandbox, confines),
278
399
  ...process.exitCode === null ? {} : { exit_code: process.exitCode },
279
400
  });
280
401
  }
@@ -284,6 +405,10 @@ export async function runExecCommand(ctx, args, exec, config) {
284
405
  }
285
406
  /** Poll or write to one session returned by {@link runExecCommand}. */
286
407
  export async function runWriteStdin(ctx, args, exec, config) {
408
+ const escalation = args;
409
+ if (escalation.sandbox_permissions !== undefined || escalation.justification !== undefined) {
410
+ throw new Error('write_stdin cannot change an existing command sandbox; use exec_command for an approved one-shot retry');
411
+ }
287
412
  positiveFinite('yield_time_ms', args.yield_time_ms);
288
413
  if (!Number.isSafeInteger(args.session_id) || args.session_id <= 0) {
289
414
  throw new Error('session_id must be a positive integer');
@@ -301,18 +426,19 @@ export async function runWriteStdin(ctx, args, exec, config) {
301
426
  }
302
427
  try {
303
428
  await waitForShell(session.process, normalizeWaitMs(args.yield_time_ms, config.pollYieldTimeMs, true), exec.signal);
304
- const output = readShellOutput(session.process.readOutput(), maxBytes);
429
+ const read = session.process.readOutput();
305
430
  if (session.process.status !== 'running') {
306
431
  forgetSession(agent, args.session_id);
432
+ const completed = await assertShellCompleted(session.process, session.escalationAvailable);
307
433
  return withChunkId({
308
434
  wall_time_seconds: (performance.now() - startedAt) / 1000,
309
- output,
435
+ output: readShellOutput(read, maxBytes, completed?.sandbox ?? session.process.sandbox, session.escalationAvailable),
310
436
  ...session.process.exitCode === null ? {} : { exit_code: session.process.exitCode },
311
437
  });
312
438
  }
313
439
  return withChunkId({
314
440
  wall_time_seconds: (performance.now() - startedAt) / 1000,
315
- output,
441
+ output: readShellOutput(read, maxBytes, session.process.sandbox, session.escalationAvailable),
316
442
  session_id: args.session_id,
317
443
  });
318
444
  }
@@ -0,0 +1,4 @@
1
+ import type { Context } from '@deepseek-ai/cordis';
2
+ /** Host-only reads: never expose the unredacted provider configuration to clients. */
3
+ export declare function readHostSettings<T>(ctx: Context, namespace: string): T | undefined;
4
+ //# sourceMappingURL=host-settings.d.ts.map
@@ -0,0 +1,13 @@
1
+ /** Host-only reads: never expose the unredacted provider configuration to clients. */
2
+ export function readHostSettings(ctx, namespace) {
3
+ const settings = ctx.get('settings');
4
+ if (typeof settings?.get === 'function')
5
+ return settings.get(namespace);
6
+ if (namespace === 'codex') {
7
+ const preferences = ctx.get('codexPreferences');
8
+ if (preferences !== undefined)
9
+ return preferences.current();
10
+ }
11
+ return settings?.describe?.().find(row => row.ns === namespace)?.value;
12
+ }
13
+ //# sourceMappingURL=host-settings.js.map
@@ -5,6 +5,7 @@ import type { LlmCallConfig } from '@deepseek-ai/dsh-llm';
5
5
  import type { Session } from '@deepseek-ai/dsh-session';
6
6
  import type { PromptAssembly } from '@deepseek-ai/dsh-system-prompt';
7
7
  import type { CodexSettings } from './settings.ts';
8
+ import type { CodexCapability } from './tool-policy-contract.ts';
8
9
  export { DEFAULT_CODEX_PERSONA, DEFAULT_CODEX_SYSTEM_PROMPT, DEFAULT_DSH_CORE_SOURCE_PROMPT, DEFAULT_DSH_CORE_WEB_PROMPT, } from './prompt.ts';
9
10
  export { CODEX_SETTINGS_NAMESPACE, CODEX_SETTINGS_SCHEMA } from './settings.ts';
10
11
  export type { CodexSettings } from './settings.ts';
@@ -64,6 +65,7 @@ export interface CodexModelProfile {
64
65
  }
65
66
  /** Add Codex defaults without overwriting explicit user capabilities. */
66
67
  export declare function enrichCodexModel(model: CodexModelProfile): CodexModelProfile;
68
+ type CodexPromptPresentation = Pick<PromptAssembly, 'sections' | 'contexts' | 'variables'>;
67
69
  /**
68
70
  * Pair the live Codex capacity with the token-meter context projection.
69
71
  *
@@ -76,11 +78,27 @@ export declare function syncCodexContextWindow(session: Session, contextWindow:
76
78
  /** Apply the live Codex controls to one agent request without leaking them to other routes. */
77
79
  export declare function applyCodexRequestSettings(request: CodexRequestConfig, settings: CodexSettings): CodexRequestConfig;
78
80
  /** Put the agent persona first and omit the generic Harness identity opener. */
79
- export declare function normalizeCodexPromptAssembly(assembly: PromptAssembly): PromptAssembly;
81
+ export declare function normalizeCodexPromptAssembly<T extends CodexPromptPresentation>(assembly: T): T;
80
82
  /** Remove disabled Codex capabilities from the next model-visible assembly. */
81
- export declare function applyCodexCapabilitySettings(assembly: PromptAssembly, settings: CodexSettings): PromptAssembly;
83
+ export declare function applyCodexCapabilitySettings<T extends CodexPromptPresentation>(assembly: T, settings: CodexSettings): T;
82
84
  /** Build the complete plugin-owned prompt, preserving an intentional empty value. */
83
85
  export declare function buildCodexSystemPrompt(config?: Pick<Config, 'systemPrompt'>): string;
86
+ /** Select only the execution/plan contributions; omitted capability flags mean enabled. */
87
+ export interface CodexExecAndPlanOptions {
88
+ terminal?: boolean;
89
+ plan?: boolean;
90
+ defaultYieldTimeMs?: number;
91
+ pollYieldTimeMs?: number;
92
+ writeYieldTimeMs?: number;
93
+ maxOutputBytes?: number;
94
+ /** Internal compiled-plan authority; omitted preserves the unsnapshotted legacy path. */
95
+ capabilityAuthority?: Partial<Record<CodexCapability, boolean>>;
96
+ }
97
+ /**
98
+ * Register selected Codex tools through the existing pipeline, without file tools or prompt hooks.
99
+ * Compiled adapters receive authority once; the disposer supports an additional owner.
100
+ */
101
+ export declare function registerCodexExecAndPlan(ctx: Context, options?: CodexExecAndPlanOptions): () => void;
84
102
  /** Explicit preset instructions win without changing shared tools or permissions. */
85
103
  export declare function withPresetPrompt(settings: CodexSettings, presetPrompt: string | undefined): CodexSettings;
86
104
  /** Mount the Codex prompt/tool layer inside one fixed agent preset. */