@shuind/dsh-codex-harness 0.2.2 → 0.2.3

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.
@@ -2,7 +2,7 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
2
2
  /** Browser controls for Codex requests and the editable operating prompt. */
3
3
  import { useEffect, useLayoutEffect, useState } from 'react';
4
4
  import { createPortal } from 'react-dom';
5
- import { CODEX_CONTEXT_MAX, CODEX_CONTEXT_UNIT, isCodexPresetId } from "../context.js";
5
+ import { CODEX_CONTEXT_MAX, CODEX_CONTEXT_UNIT } from "../context.js";
6
6
  import { DEFAULT_CODEX_SYSTEM_PROMPT } from "../prompt.js";
7
7
  import { modelActivity, sameModelActivity } from "./activity.js";
8
8
  const NS = 'codex';
@@ -21,7 +21,22 @@ const en = {
21
21
  contextSizeDescription: 'Next request capacity in K tokens.',
22
22
  contextRestore: 'Restore model default',
23
23
  promptCardTitle: 'Codex Harness',
24
- promptCardDescription: 'View and customize the complete Codex operating prompt.',
24
+ promptCardDescription: 'Choose Codex capabilities and customize the operating prompt.',
25
+ capabilitiesLabel: 'Codex mode capabilities',
26
+ capabilityPrompt: 'Codex operating prompt',
27
+ capabilityPromptHint: 'Inject the editable instructions and persona-first prompt layout in Codex mode.',
28
+ capabilityTerminal: 'Terminal tools',
29
+ capabilityTerminalHint: 'Expose exec_command and write_stdin in Codex mode.',
30
+ capabilityPatch: 'Patch tool',
31
+ capabilityPatchHint: 'Expose apply_patch in Codex mode, using the native Responses grammar when supported.',
32
+ capabilityPlan: 'Plan tool',
33
+ capabilityPlanHint: 'Expose update_plan for implementation task tracking in Codex mode.',
34
+ capabilityWebSearch: 'Hosted web search',
35
+ capabilityWebSearchHint: 'Use the provider-native Responses web_search tool when available.',
36
+ capabilityCompaction: 'Remote compaction',
37
+ capabilityCompactionHint: 'Prefer the provider Responses compact endpoint before local compaction.',
38
+ capabilityActivity: 'Activity indicator',
39
+ capabilityActivityHint: 'Show request, reply, and compaction status beside the conversation.',
25
40
  promptLabel: 'System prompt',
26
41
  promptHint: 'This is the full prompt owned by this plugin. Persona and DSH tool guidance stay dynamic.',
27
42
  promptOverridden: 'Overridden',
@@ -48,7 +63,22 @@ const zh = {
48
63
  contextSizeDescription: '\u8bbe\u7f6e\u4e0b\u6b21\u8bf7\u6c42\u7684\u4e0a\u4e0b\u6587\u5bb9\u91cf\uff0c\u5355\u4f4d\u4e3a K tokens\u3002',
49
64
  contextRestore: '\u6062\u590d\u6a21\u578b\u9ed8\u8ba4\u503c',
50
65
  promptCardTitle: 'Codex Harness',
51
- promptCardDescription: '\u67e5\u770b\u548c\u81ea\u5b9a\u4e49\u5b8c\u6574\u7684 Codex \u7cfb\u7edf\u63d0\u793a\u8bcd\u3002',
66
+ promptCardDescription: '\u9009\u62e9 Codex \u80fd\u529b\u5e76\u81ea\u5b9a\u4e49\u5b8c\u6574\u7684\u64cd\u4f5c\u63d0\u793a\u8bcd\u3002',
67
+ capabilitiesLabel: 'Codex \u6a21\u5f0f\u80fd\u529b',
68
+ capabilityPrompt: 'Codex \u64cd\u4f5c\u63d0\u793a\u8bcd',
69
+ capabilityPromptHint: '\u4ec5\u5728 Codex \u6a21\u5f0f\u6ce8\u5165\u53ef\u7f16\u8f91\u6307\u4ee4\uff0c\u5e76\u5c06 Persona \u653e\u5728\u63d0\u793a\u8bcd\u9996\u4f4d\u3002',
70
+ capabilityTerminal: '\u7ec8\u7aef\u5de5\u5177',
71
+ capabilityTerminalHint: '\u4ec5\u5728 Codex \u6a21\u5f0f\u63d0\u4f9b exec_command \u548c write_stdin\u3002',
72
+ capabilityPatch: '\u8865\u4e01\u5de5\u5177',
73
+ capabilityPatchHint: '\u4ec5\u5728 Codex \u6a21\u5f0f\u63d0\u4f9b apply_patch\uff0c\u5e76\u5728\u652f\u6301\u65f6\u4f7f\u7528 Responses \u539f\u751f\u8bed\u6cd5\u3002',
74
+ capabilityPlan: '\u8ba1\u5212\u5de5\u5177',
75
+ capabilityPlanHint: '\u4ec5\u5728 Codex \u6a21\u5f0f\u63d0\u4f9b update_plan\uff0c\u7528\u4e8e\u8ddf\u8e2a\u5b9e\u65bd\u4efb\u52a1\u3002',
76
+ capabilityWebSearch: '\u6258\u7ba1\u7f51\u7edc\u641c\u7d22',
77
+ capabilityWebSearchHint: '\u53ef\u7528\u65f6\u4f7f\u7528\u63d0\u4f9b\u5546\u539f\u751f\u7684 Responses web_search \u5de5\u5177\u3002',
78
+ capabilityCompaction: '\u8fdc\u7a0b\u4e0a\u4e0b\u6587\u538b\u7f29',
79
+ capabilityCompactionHint: '\u4f18\u5148\u8c03\u7528\u63d0\u4f9b\u5546\u7684 Responses compact \u7aef\u70b9\uff0c\u5931\u8d25\u65f6\u56de\u9000\u672c\u5730\u538b\u7f29\u3002',
80
+ capabilityActivity: '\u6d3b\u52a8\u72b6\u6001',
81
+ capabilityActivityHint: '\u5728\u5bf9\u8bdd\u65c1\u663e\u793a\u8bf7\u6c42\u3001\u56de\u590d\u548c\u538b\u7f29\u72b6\u6001\u3002',
52
82
  promptLabel: '\u7cfb\u7edf\u63d0\u793a\u8bcd',
53
83
  promptHint: '\u8fd9\u662f\u672c\u63d2\u4ef6\u8d1f\u8d23\u7684\u5168\u90e8\u63d0\u793a\u8bcd\uff1bPersona \u548c DSH \u5de5\u5177\u6307\u5bfc\u4ecd\u4f1a\u52a8\u6001\u6ce8\u5165\u3002',
54
84
  promptOverridden: '\u5df2\u8986\u76d6',
@@ -77,6 +107,15 @@ function hasPromptOverride(layer) {
77
107
  && !Array.isArray(layer)
78
108
  && Object.hasOwn(layer, 'systemPrompt');
79
109
  }
110
+ function CapabilityToggle({ field, label, hint, enabled, disabled, setSetting, }) {
111
+ return (_jsxs("label", { style: {
112
+ display: 'flex',
113
+ alignItems: 'flex-start',
114
+ gap: 12,
115
+ padding: '9px 0',
116
+ cursor: disabled ? 'default' : 'pointer',
117
+ }, children: [_jsxs("span", { style: { flex: 1, minWidth: 0, display: 'grid', gap: 2 }, children: [_jsx("strong", { style: { fontSize: 13, fontWeight: 500 }, children: label }), _jsx("span", { style: { color: 'var(--dsw-alias-label-tertiary)', fontSize: 12, lineHeight: 1.45 }, children: hint })] }), _jsx("input", { type: "checkbox", role: "switch", checked: enabled, disabled: disabled, "aria-label": label, onChange: event => { void setSetting(field, event.target.checked); }, style: { marginTop: 3, accentColor: 'var(--dsw-static-blue-500)' } })] }));
118
+ }
80
119
  /** Full-prompt editor contributed to Settings > Plugins. */
81
120
  export function PromptSettingsCard(props) {
82
121
  const { useSettings, setSetting, unsetSetting, t } = props;
@@ -84,6 +123,15 @@ export function PromptSettingsCard(props) {
84
123
  const current = snapshot.value?.systemPrompt ?? DEFAULT_CODEX_SYSTEM_PROMPT;
85
124
  const inherited = promptFromLayer(snapshot.base) ?? DEFAULT_CODEX_SYSTEM_PROMPT;
86
125
  const overridden = hasPromptOverride(snapshot.user);
126
+ const capabilities = [
127
+ { field: 'promptEnabled', label: 'capabilityPrompt', hint: 'capabilityPromptHint' },
128
+ { field: 'terminalToolsEnabled', label: 'capabilityTerminal', hint: 'capabilityTerminalHint' },
129
+ { field: 'patchToolEnabled', label: 'capabilityPatch', hint: 'capabilityPatchHint' },
130
+ { field: 'planToolEnabled', label: 'capabilityPlan', hint: 'capabilityPlanHint' },
131
+ { field: 'hostedWebSearchEnabled', label: 'capabilityWebSearch', hint: 'capabilityWebSearchHint' },
132
+ { field: 'remoteCompactionEnabled', label: 'capabilityCompaction', hint: 'capabilityCompactionHint' },
133
+ { field: 'activityIndicatorEnabled', label: 'capabilityActivity', hint: 'capabilityActivityHint' },
134
+ ];
87
135
  const [open, setOpen] = useState(false);
88
136
  const [draft, setDraft] = useState(current);
89
137
  const [saving, setSaving] = useState(false);
@@ -144,7 +192,14 @@ export function PromptSettingsCard(props) {
144
192
  background: 'var(--dsw-alias-bg-module-platform)',
145
193
  color: 'var(--dsw-alias-label-secondary)',
146
194
  fontSize: 11,
147
- }, children: t('promptUnsaved') })), _jsx("span", { "aria-hidden": "true", style: { color: 'var(--dsw-alias-label-tertiary)', fontSize: 16 }, children: open ? '-' : '+' })] }), open && (_jsxs("div", { style: { borderTop: '1px solid var(--dsw-alias-border-l2)', margin: '0 16px', padding: '12px 0' }, children: [!snapshot.writable && (_jsx("p", { style: { margin: '0 0 10px', color: 'var(--dsw-alias-label-tertiary)', fontSize: 12 }, children: t('promptReadOnly') })), _jsxs("div", { style: { display: 'flex', alignItems: 'center', gap: 8, marginBottom: 7 }, children: [_jsx("label", { htmlFor: "codex-system-prompt", style: { flex: 1, fontSize: 13, fontWeight: 500 }, children: t('promptLabel') }), overridden && (_jsxs(_Fragment, { children: [_jsx("span", { style: {
195
+ }, children: t('promptUnsaved') })), _jsx("span", { "aria-hidden": "true", style: { color: 'var(--dsw-alias-label-tertiary)', fontSize: 16 }, children: open ? '-' : '+' })] }), open && (_jsxs("div", { style: { borderTop: '1px solid var(--dsw-alias-border-l2)', margin: '0 16px', padding: '12px 0' }, children: [!snapshot.writable && (_jsx("p", { style: { margin: '0 0 10px', color: 'var(--dsw-alias-label-tertiary)', fontSize: 12 }, children: t('promptReadOnly') })), _jsx("strong", { style: { display: 'block', marginBottom: 4, fontSize: 13 }, children: t('capabilitiesLabel') }), _jsx("div", { style: { display: 'grid', marginBottom: 14 }, children: capabilities.map(capability => (_jsx(CapabilityToggle, { field: capability.field, label: t(capability.label), hint: t(capability.hint), enabled: snapshot.value?.[capability.field] ?? true, disabled: !snapshot.writable || saving, setSetting: setSetting }, capability.field))) }), _jsxs("div", { style: {
196
+ display: 'flex',
197
+ alignItems: 'center',
198
+ gap: 8,
199
+ marginBottom: 7,
200
+ paddingTop: 12,
201
+ borderTop: '1px solid var(--dsw-alias-border-l2)',
202
+ }, children: [_jsx("label", { htmlFor: "codex-system-prompt", style: { flex: 1, fontSize: 13, fontWeight: 500 }, children: t('promptLabel') }), overridden && (_jsxs(_Fragment, { children: [_jsx("span", { style: {
148
203
  borderRadius: 999,
149
204
  padding: '1px 8px',
150
205
  background: 'var(--dsw-alias-bg-module-platform)',
@@ -174,12 +229,9 @@ export function PromptSettingsCard(props) {
174
229
  }
175
230
  /** The legacy composer seat is a compact inline row, not a menu panel. */
176
231
  function FastModeFallback(props) {
177
- const { sessionId, useSessions, useSettings, setSetting, t } = props;
178
- const agentPreset = useSessions(state => state.byId[sessionId]?.agentPreset);
232
+ const { useSettings, setSetting, t } = props;
179
233
  const snapshot = useSettings(state => state);
180
234
  const fast = snapshot.value?.fast ?? false;
181
- if (!isCodexPresetId(agentPreset))
182
- return null;
183
235
  return (_jsxs("button", { type: "button", role: "switch", disabled: snapshot.writable === false, "aria-checked": fast, "aria-label": fast ? t('fastOn') : t('fastOff'), title: fast ? t('fastOn') : t('fastOff'), onClick: () => { void setSetting('fast', !fast); }, style: {
184
236
  boxSizing: 'border-box',
185
237
  display: 'inline-flex',
@@ -206,11 +258,8 @@ function contextWindowFromProjection(useProjection) {
206
258
  : DEFAULT_CONTEXT_WINDOW;
207
259
  }
208
260
  /** Settings form appended to the old host's context meter panel. */
209
- function ContextSizeControl({ contextWindow, sessionId, useSessions, useSettings, setSetting, unsetSetting, t, }) {
210
- const agentPreset = useSessions(state => state.byId[sessionId]?.agentPreset);
261
+ function ContextSizeControl({ contextWindow, sessionId: _sessionId, useSessions: _useSessions, useSettings, setSetting, unsetSetting, t, }) {
211
262
  const snapshot = useSettings(state => state);
212
- if (!isCodexPresetId(agentPreset))
213
- return null;
214
263
  const configured = snapshot.value?.contextWindow;
215
264
  const maxK = CODEX_CONTEXT_MAX / CODEX_CONTEXT_UNIT;
216
265
  const valueK = Math.min(maxK, Math.max(1, Math.round((configured ?? contextWindow) / CODEX_CONTEXT_UNIT)));
@@ -259,9 +308,7 @@ function elapsedSeconds(startedAt, now) {
259
308
  return Math.max(0, Math.floor((now - startedAt) / 1_000));
260
309
  }
261
310
  /** Prefer the session snapshot when an older projection host only exposes null. */
262
- export function resolveActivity(agentPreset, projectedActivity, fallbackActivity) {
263
- if (!isCodexPresetId(agentPreset))
264
- return null;
311
+ export function resolveActivity(projectedActivity, fallbackActivity) {
265
312
  if (projectedActivity?.activity === 'awaiting-model') {
266
313
  return {
267
314
  activity: fallbackActivity?.activity ?? 'requesting-model',
@@ -272,8 +319,9 @@ export function resolveActivity(agentPreset, projectedActivity, fallbackActivity
272
319
  return fallbackActivity ?? null;
273
320
  return projectedActivity ?? fallbackActivity ?? null;
274
321
  }
275
- export function ActivityLine({ sessionId, useSession, useSessions, useProjection, t, position, }) {
276
- const agentPreset = useSessions(state => state.byId[sessionId]?.agentPreset);
322
+ export function ActivityLine({ sessionId: _sessionId, useSession, useSessions: _useSessions, useProjection, useSettings, t, position, }) {
323
+ const settings = useSettings(state => state);
324
+ const enabled = settings.value?.activityIndicatorEnabled ?? true;
277
325
  // Keep the projection seam optional: this package must still load when the
278
326
  // host has no session-projection registry or has not carried this key.
279
327
  const projectedActivity = useProjection('codexActivity');
@@ -281,16 +329,16 @@ export function ActivityLine({ sessionId, useSession, useSessions, useProjection
281
329
  // fallback only covers the short wire gap before the next projection frame;
282
330
  // tool calls intentionally remain silent because their cards own the status.
283
331
  const fallbackActivity = useSession(modelActivity, sameModelActivity);
284
- const activity = resolveActivity(agentPreset, projectedActivity, fallbackActivity);
332
+ const activity = resolveActivity(projectedActivity, fallbackActivity);
285
333
  const [now, setNow] = useState(() => Date.now());
286
334
  useEffect(() => {
287
- if (!isCodexPresetId(agentPreset) || activity === undefined || activity === null)
335
+ if (!enabled || activity === undefined || activity === null)
288
336
  return undefined;
289
337
  setNow(Date.now());
290
338
  const timer = setInterval(() => { setNow(Date.now()); }, 1_000);
291
339
  return () => clearInterval(timer);
292
- }, [agentPreset, activity?.activity, activity?.startedAt]);
293
- if (!isCodexPresetId(agentPreset) || activity === undefined || activity === null)
340
+ }, [enabled, activity?.activity, activity?.startedAt]);
341
+ if (!enabled || activity === undefined || activity === null)
294
342
  return null;
295
343
  const label = activity.activity === 'compaction'
296
344
  ? t('activityCompacting')
@@ -416,10 +464,7 @@ function LegacyOverlay(props) {
416
464
  const { contextDialog, turnStatus } = useLegacyHostTargets();
417
465
  const turnStatusPosition = useTurnStatusPosition(turnStatus);
418
466
  const contextWindow = contextWindowFromProjection(useProjection);
419
- const agentPreset = useSessions(state => state.byId[sessionId]?.agentPreset);
420
- if (!isCodexPresetId(agentPreset))
421
- return null;
422
- return (_jsxs(_Fragment, { children: [contextDialog !== null && createPortal(_jsx(ContextSizeControl, { contextWindow: contextWindow, sessionId: sessionId, useSessions: useSessions, useSettings: useSettings, setSetting: setSetting, unsetSetting: unsetSetting, t: t }), contextDialog, 'codex-context-size'), turnStatusPosition !== null && typeof document !== 'undefined' && document.body !== null && createPortal(_jsx(ActivityLine, { sessionId: sessionId, useSession: useSession, useSessions: useSessions, useProjection: useProjection, t: t, position: turnStatusPosition }), document.body, 'codex-activity')] }));
467
+ return (_jsxs(_Fragment, { children: [contextDialog !== null && createPortal(_jsx(ContextSizeControl, { contextWindow: contextWindow, sessionId: sessionId, useSessions: useSessions, useSettings: useSettings, setSetting: setSetting, unsetSetting: unsetSetting, t: t }), contextDialog, 'codex-context-size'), turnStatusPosition !== null && typeof document !== 'undefined' && document.body !== null && createPortal(_jsx(ActivityLine, { sessionId: sessionId, useSession: useSession, useSessions: useSessions, useProjection: useProjection, useSettings: useSettings, t: t, position: turnStatusPosition }), document.body, 'codex-activity')] }));
423
468
  }
424
469
  export const inject = ['slots', 'locale', 'settingsScope'];
425
470
  /** Mount request controls and the plugin settings card through shared slots. */
@@ -12,6 +12,10 @@ export declare const name = "codex";
12
12
  export declare const inject: string[];
13
13
  /** Configuration for the Codex shell result bridge. */
14
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;
15
19
  /** Default wait before a pipe-backed command yields a session id. */
16
20
  defaultYieldTimeMs?: number;
17
21
  /** Default wait for an empty `write_stdin` poll. */
@@ -57,6 +61,8 @@ export declare function syncCodexContextWindow(session: Session, contextWindow:
57
61
  export declare function applyCodexRequestSettings(request: CodexRequestConfig, settings: CodexSettings): CodexRequestConfig;
58
62
  /** Put the agent persona first and omit the generic Harness identity opener. */
59
63
  export declare function normalizeCodexPromptAssembly(assembly: PromptAssembly): PromptAssembly;
64
+ /** Remove disabled Codex capabilities from the next model-visible assembly. */
65
+ export declare function applyCodexCapabilitySettings(assembly: PromptAssembly, settings: CodexSettings): PromptAssembly;
60
66
  /** Build the complete plugin-owned prompt, preserving an intentional empty value. */
61
67
  export declare function buildCodexSystemPrompt(config?: Pick<Config, 'systemPrompt'>): string;
62
68
  /** Mount the Codex prompt/tool layer inside one fixed agent preset. */
@@ -15,6 +15,8 @@ export const inject = ['tools', 'systemPrompt', 'shell', 'fs', 'llm', 'credentia
15
15
  const DEFAULT_MAX_OUTPUT_BYTES = 1024 * 1024;
16
16
  /** Runtime configuration schema for the Codex tool bridge. */
17
17
  export const Config = z.object({
18
+ globalEnhancements: z.boolean().default(true),
19
+ codexCore: z.boolean().default(true),
18
20
  defaultYieldTimeMs: z.number().step(1).min(0).default(10_000),
19
21
  pollYieldTimeMs: z.number().step(1).min(0).default(5_000),
20
22
  writeYieldTimeMs: z.number().step(1).min(0).default(250),
@@ -118,10 +120,14 @@ function watchConfiguredGptModels(ctx) {
118
120
  /** Install the optional settings source used by requests and prompt assembly. */
119
121
  function installCodexSettings(ctx, systemPrompt) {
120
122
  const entry = { ...CODEX_SETTINGS_ENTRY, systemPrompt };
123
+ const withDefaults = (value) => ({
124
+ ...entry,
125
+ ...value,
126
+ });
121
127
  const settings = ctx.get('settings');
122
128
  if (settings?.get(CODEX_SETTINGS_NAMESPACE) !== undefined) {
123
129
  return {
124
- current: () => settings.get(CODEX_SETTINGS_NAMESPACE) ?? entry,
130
+ current: () => withDefaults(settings.get(CODEX_SETTINGS_NAMESPACE)),
125
131
  };
126
132
  }
127
133
  let source = () => entry;
@@ -129,7 +135,7 @@ function installCodexSettings(ctx, systemPrompt) {
129
135
  setSource: (current) => { source = current; },
130
136
  onChange: () => { },
131
137
  });
132
- return { current: () => source() };
138
+ return { current: () => withDefaults(source()) };
133
139
  }
134
140
  function hasOpenTurn(session) {
135
141
  const start = session.events.findLast(event => event.type === 'turn/start');
@@ -235,6 +241,25 @@ export function normalizeCodexPromptAssembly(assembly) {
235
241
  sections: [persona, ...sections.filter(section => section.name !== 'deployment:persona')],
236
242
  };
237
243
  }
244
+ const CODEX_TOOL_NAMES = {
245
+ terminalToolsEnabled: new Set(['exec_command', 'write_stdin']),
246
+ patchToolEnabled: new Set(['apply_patch']),
247
+ planToolEnabled: new Set(['update_plan']),
248
+ };
249
+ /** Remove disabled Codex capabilities from the next model-visible assembly. */
250
+ export function applyCodexCapabilitySettings(assembly, settings) {
251
+ const disabled = new Set();
252
+ for (const [setting, names] of Object.entries(CODEX_TOOL_NAMES)) {
253
+ if (settings[setting])
254
+ continue;
255
+ for (const name of names)
256
+ disabled.add(name);
257
+ }
258
+ const filtered = disabled.size === 0
259
+ ? assembly
260
+ : { ...assembly, tools: assembly.tools.filter(tool => !disabled.has(tool.name)) };
261
+ return settings.promptEnabled ? normalizeCodexPromptAssembly(filtered) : filtered;
262
+ }
238
263
  /** Build the complete plugin-owned prompt, preserving an intentional empty value. */
239
264
  export function buildCodexSystemPrompt(config = {}) {
240
265
  return resolveCodexSystemPrompt(config.systemPrompt);
@@ -243,6 +268,10 @@ const EXEC_COMMAND_DESCRIPTION = 'Runs a command in a PTY, returning output, a s
243
268
  const WRITE_STDIN_DESCRIPTION = 'Writes characters to an existing unified exec session and returns recent output.';
244
269
  const UPDATE_PLAN_DESCRIPTION = 'Updates the task plan.\nProvide an optional explanation and a list of plan items, each with a step and status.\nAt most one step can be in_progress at a time.';
245
270
  const PLAN_STATUSES = ['pending', 'in_progress', 'completed'];
271
+ function assertCapabilityEnabled(current, setting, toolName) {
272
+ if (!current()[setting])
273
+ throw new Error(`${toolName}: disabled in Codex Harness plugin settings`);
274
+ }
246
275
  function sessionCwd(exec) {
247
276
  return exec.agent?.session.header.cwd;
248
277
  }
@@ -373,6 +402,7 @@ function registerExecTools(ctx, config) {
373
402
  render: (_args, value) => [{ type: 'text', text: renderExecResult(value) }],
374
403
  },
375
404
  async execute(args, exec) {
405
+ assertCapabilityEnabled(config.currentSettings, 'terminalToolsEnabled', 'exec_command');
376
406
  return runExecCommand(ctx, args, exec, config);
377
407
  },
378
408
  presentCall: args => ({
@@ -406,11 +436,12 @@ function registerExecTools(ctx, config) {
406
436
  render: (_args, value) => [{ type: 'text', text: renderExecResult(value) }],
407
437
  },
408
438
  async execute(args, exec) {
439
+ assertCapabilityEnabled(config.currentSettings, 'terminalToolsEnabled', 'write_stdin');
409
440
  return runWriteStdin(ctx, args, exec, config);
410
441
  },
411
442
  }));
412
443
  }
413
- function registerPatchTool(ctx) {
444
+ function registerPatchTool(ctx, currentSettings) {
414
445
  ctx.tools.register(defineTool({
415
446
  name: 'apply_patch',
416
447
  description: APPLY_PATCH_DESCRIPTION,
@@ -440,6 +471,7 @@ function registerPatchTool(ctx) {
440
471
  render: (_args, value) => [{ type: 'text', text: patchSummary(value) }],
441
472
  },
442
473
  async execute(args, exec) {
474
+ assertCapabilityEnabled(currentSettings, 'patchToolEnabled', 'apply_patch');
443
475
  const files = parsePatch(args.input);
444
476
  const policy = resolvePolicy(ctx, exec);
445
477
  const applied = [];
@@ -457,7 +489,7 @@ function registerPatchTool(ctx) {
457
489
  },
458
490
  }));
459
491
  }
460
- function registerPlanTool(ctx) {
492
+ function registerPlanTool(ctx, currentSettings) {
461
493
  ctx.tools.register(defineTool({
462
494
  name: 'update_plan',
463
495
  description: UPDATE_PLAN_DESCRIPTION,
@@ -482,6 +514,7 @@ function registerPlanTool(ctx) {
482
514
  render: () => [{ type: 'text', text: 'Plan updated' }],
483
515
  },
484
516
  execute(args, exec) {
517
+ assertCapabilityEnabled(currentSettings, 'planToolEnabled', 'update_plan');
485
518
  const agent = exec.agent;
486
519
  if (agent === undefined)
487
520
  throw new Error('update_plan requires an owning agent session');
@@ -493,6 +526,8 @@ function registerPlanTool(ctx) {
493
526
  /** Mount the Codex prompt/tool layer inside one fixed agent preset. */
494
527
  export function apply(ctx, config = {}) {
495
528
  const resolved = {
529
+ globalEnhancements: config.globalEnhancements ?? true,
530
+ codexCore: config.codexCore ?? true,
496
531
  defaultYieldTimeMs: config.defaultYieldTimeMs ?? 10_000,
497
532
  pollYieldTimeMs: config.pollYieldTimeMs ?? 5_000,
498
533
  writeYieldTimeMs: config.writeYieldTimeMs ?? 250,
@@ -501,48 +536,61 @@ export function apply(ctx, config = {}) {
501
536
  remoteCompact: config.remoteCompact ?? true,
502
537
  systemPrompt: config.systemPrompt ?? DEFAULT_CODEX_SYSTEM_PROMPT,
503
538
  };
504
- if (ctx.fs.sandboxMode !== undefined && ctx.get('sandboxPolicy') === undefined) {
539
+ if (resolved.codexCore
540
+ && ctx.fs.sandboxMode !== undefined
541
+ && ctx.get('sandboxPolicy') === undefined) {
505
542
  throw new Error('codex: a sandboxing filesystem requires ctx.sandboxPolicy');
506
543
  }
507
- // The generic pi-ai plugin remains the owner of the user's configured
508
- // provider routes. Codex adds only scoped transport behavior and capability
509
- // metadata; failed remote operations continue through the generic path.
510
- watchConfiguredGptModels(ctx);
511
- registerCodexActivityProjection(ctx);
512
544
  const codexSettings = installCodexSettings(ctx, resolved.systemPrompt);
513
- installCodexContextProjection(ctx, codexSettings.current);
514
- // Keep these controls in the request config rather than mutating provider
515
- // settings. That makes a change apply to the next step without rebuilding
516
- // the user's model catalog, while the LLM service still freezes it per call.
517
- ctx.on('agent/request', async (_payload, next) => {
518
- const request = await next();
519
- return applyCodexRequestSettings(request, codexSettings.current());
520
- });
521
- if (typeof ctx.effect === 'function') {
522
- const disposeHostedWebSearch = installHostedWebSearch();
523
- ctx.effect(() => disposeHostedWebSearch, 'codex: Responses transport wrapper');
524
- }
525
- ctx.on('llm/stream', ((options, next) => {
526
- if (resolved.remoteCompact && options.purpose === 'compaction' && isGptModel(options.model)) {
527
- return remoteCompactStream(ctx, options, next);
528
- }
529
- // Keep all ordinary GPT Responses calls inside the plugin-owned transport
530
- // scope so apply_patch can use the same wire bridge even when hosted search
531
- // and remote compaction are disabled.
532
- if (options.purpose === undefined && isGptModel(options.model)) {
533
- return hostedWebSearchStream(next, { serviceTier: options.serviceTier });
545
+ const execConfig = { ...resolved, currentSettings: codexSettings.current };
546
+ if (resolved.globalEnhancements) {
547
+ // The generic pi-ai plugin remains the owner of provider routes. This
548
+ // layer adds only request metadata and remote-first transport behavior.
549
+ watchConfiguredGptModels(ctx);
550
+ registerCodexActivityProjection(ctx);
551
+ installCodexContextProjection(ctx, codexSettings.current);
552
+ ctx.on('agent/request', async (_payload, next) => {
553
+ const request = await next();
554
+ return applyCodexRequestSettings(request, codexSettings.current());
555
+ });
556
+ if (typeof ctx.effect === 'function') {
557
+ const disposeHostedWebSearch = installHostedWebSearch();
558
+ ctx.effect(() => disposeHostedWebSearch, 'codex: Responses transport wrapper');
534
559
  }
535
- return next();
536
- }));
537
- ctx.on('system-prompt/assemble', async (_assembly, _context, next) => normalizeCodexPromptAssembly(await next()));
538
- ctx.systemPrompt.section({
539
- name: 'codex:base',
540
- order: 10,
541
- text: () => resolveCodexSystemPrompt(codexSettings.current().systemPrompt),
542
- });
543
- registerExecTools(ctx, resolved);
544
- registerPatchTool(ctx);
545
- registerPlanTool(ctx);
560
+ ctx.on('llm/stream', ((options, next) => {
561
+ const settings = codexSettings.current();
562
+ if (resolved.remoteCompact
563
+ && settings.remoteCompactionEnabled
564
+ && options.purpose === 'compaction'
565
+ && isGptModel(options.model)) {
566
+ return remoteCompactStream(ctx, options, next, {
567
+ hostedWebSearch: resolved.hostedWebSearch && settings.hostedWebSearchEnabled,
568
+ customApplyPatch: settings.patchToolEnabled,
569
+ });
570
+ }
571
+ if (options.purpose === undefined && isGptModel(options.model)) {
572
+ return hostedWebSearchStream(next, {
573
+ serviceTier: options.serviceTier,
574
+ hostedWebSearch: resolved.hostedWebSearch && settings.hostedWebSearchEnabled,
575
+ customApplyPatch: settings.patchToolEnabled,
576
+ });
577
+ }
578
+ return next();
579
+ }));
580
+ }
581
+ if (resolved.codexCore) {
582
+ ctx.on('system-prompt/assemble', async (_assembly, _context, next) => applyCodexCapabilitySettings(await next(), codexSettings.current()));
583
+ ctx.systemPrompt.section({
584
+ name: 'codex:base',
585
+ order: 10,
586
+ text: () => codexSettings.current().promptEnabled
587
+ ? resolveCodexSystemPrompt(codexSettings.current().systemPrompt)
588
+ : '',
589
+ });
590
+ registerExecTools(ctx, execConfig);
591
+ registerPatchTool(ctx, codexSettings.current);
592
+ registerPlanTool(ctx, codexSettings.current);
593
+ }
546
594
  }
547
595
  export default { name, inject, Config, apply };
548
596
  //# sourceMappingURL=index.js.map
@@ -27,6 +27,7 @@ const BUNDLED_PRESET_SIGNATURES = new Set([
27
27
  'd1de30f5c13049621b1c1ae3fb22d35b031797a4762638265822b0ff62749854',
28
28
  'b50e1d616f9b4188a33c0da0fe355478b7b75b615f3792c094e2b67995622cf4',
29
29
  '6132523d92893f6ae9214b30105e9cc1ba64854df6ca8a84213069eb6c38d286',
30
+ '7957bc5e9b0f2fa0b74d2d8bae0d4ee153a2ba7bb430f5a848e700386cc7ce3f',
30
31
  ]);
31
32
  function dshHomePath(...segments) {
32
33
  const configured = process.env.DSH_HOME?.trim();
@@ -1,21 +1,21 @@
1
1
  /** Parser and line-oriented applicator for Codex's `apply_patch` language. */
2
2
  export const APPLY_PATCH_DESCRIPTION = 'Edits files using Codex patch syntax with Begin/End Patch markers and file update directives. In hunk lines, the first character is the operation marker; repeat a source-leading marker when the source line itself starts with one.';
3
3
  /** The grammar sent to providers that support OpenAI custom grammar tools. */
4
- export const APPLY_PATCH_GRAMMAR = String.raw `start: begin_patch hunk+ end_patch
5
- begin_patch: "*** Begin Patch" LF
6
- end_patch: "*** End Patch" LF?
7
- hunk: add_hunk | delete_hunk | update_hunk
8
- add_hunk: "*** Add File: " filename LF add_line+
9
- delete_hunk: "*** Delete File: " filename LF
10
- update_hunk: "*** Update File: " filename LF change_move? change?
11
- filename: /(.+)/
12
- add_line: "+" /(.*)/ LF -> line
13
- change_move: "*** Move to: " filename LF
14
- change: (change_context | change_line)+ eof_line?
15
- change_context: ("@@" | "@@ " /(.+)/) LF
16
- change_line: ("+" | "-" | " ") /(.*)/ LF
17
- eof_line: "*** End of File" LF
18
- %import common.LF
4
+ export const APPLY_PATCH_GRAMMAR = String.raw `start: begin_patch hunk+ end_patch
5
+ begin_patch: "*** Begin Patch" LF
6
+ end_patch: "*** End Patch" LF?
7
+ hunk: add_hunk | delete_hunk | update_hunk
8
+ add_hunk: "*** Add File: " filename LF add_line+
9
+ delete_hunk: "*** Delete File: " filename LF
10
+ update_hunk: "*** Update File: " filename LF change_move? change?
11
+ filename: /(.+)/
12
+ add_line: "+" /(.*)/ LF -> line
13
+ change_move: "*** Move to: " filename LF
14
+ change: (change_context | change_line)+ eof_line?
15
+ change_context: ("@@" | "@@ " /(.+)/) LF
16
+ change_line: ("+" | "-" | " ") /(.*)/ LF
17
+ eof_line: "*** End of File" LF
18
+ %import common.LF
19
19
  `;
20
20
  function invalid(message) {
21
21
  throw new Error(`apply_patch: ${message}`);
@@ -1,39 +1,39 @@
1
1
  /** Default plugin-owned Codex operating prompt. */
2
- export const DEFAULT_CODEX_SYSTEM_PROMPT = String.raw `## General
3
-
4
- - When searching for text or files, prefer using rg or rg --files respectively because rg is much faster than alternatives like grep. If rg is not available, use the next best alternative.
5
-
6
- ## Editing constraints
7
-
8
- - Default to ASCII when editing or creating files. Only introduce non-ASCII or other Unicode characters when there is a clear justification and the file already uses them.
9
- - Add succinct code comments that explain non-obvious code. Do not add comments that merely narrate assignments or control flow.
10
- - You may be in a dirty git worktree. Never revert existing changes you did not make unless the user explicitly requests it. If unrelated files are changed, leave them alone.
11
-
12
- ## Planning
13
-
14
- - Use update_plan for work with multiple meaningful steps. Keep the plan current as the task progresses.
15
- - Do not use a plan for a trivial one-step request.
16
-
17
- ## dsh session
18
-
19
- - The user and you share one workspace. Inspect the repository and every applicable AGENTS.md before editing.
20
-
21
- ## Task execution
22
-
23
- - Keep the user informed with concise progress updates and lead with the result.
24
-
25
- ## Presenting your work
26
-
27
- - Be concise, direct, friendly, and actionable.
28
- - For substantial work, explain what changed and why, then briefly note how the work was verified and what comes next.
29
- - Do not dump large files into the conversation; refer to their paths.
30
- - Use plain text with short sections only when they improve scanability.
31
-
32
- ## Working principles
33
-
34
- - Ask, align, and clarify first. Gather enough context from the user, then align the approach to achieve the user's goal through the clearest, most effective path.
35
- - Keep only the essential logic and core actions. Don't explain or test what was removed or why something wasn't done, especially when writing documentation or communicating. Convey enough valuable information with as few words as possible.
36
- - Solve problems by thinking from first principles and at a higher level.
2
+ export const DEFAULT_CODEX_SYSTEM_PROMPT = String.raw `## General
3
+
4
+ - When searching for text or files, prefer using rg or rg --files respectively because rg is much faster than alternatives like grep. If rg is not available, use the next best alternative.
5
+
6
+ ## Editing constraints
7
+
8
+ - Default to ASCII when editing or creating files. Only introduce non-ASCII or other Unicode characters when there is a clear justification and the file already uses them.
9
+ - Add succinct code comments that explain non-obvious code. Do not add comments that merely narrate assignments or control flow.
10
+ - You may be in a dirty git worktree. Never revert existing changes you did not make unless the user explicitly requests it. If unrelated files are changed, leave them alone.
11
+
12
+ ## Planning
13
+
14
+ - Use update_plan for work with multiple meaningful steps. Keep the plan current as the task progresses.
15
+ - Do not use a plan for a trivial one-step request.
16
+
17
+ ## dsh session
18
+
19
+ - The user and you share one workspace. Inspect the repository and every applicable AGENTS.md before editing.
20
+
21
+ ## Task execution
22
+
23
+ - Keep the user informed with concise progress updates and lead with the result.
24
+
25
+ ## Presenting your work
26
+
27
+ - Be concise, direct, friendly, and actionable.
28
+ - For substantial work, explain what changed and why, then briefly note how the work was verified and what comes next.
29
+ - Do not dump large files into the conversation; refer to their paths.
30
+ - Use plain text with short sections only when they improve scanability.
31
+
32
+ ## Working principles
33
+
34
+ - Ask, align, and clarify first. Gather enough context from the user, then align the approach to achieve the user's goal through the clearest, most effective path.
35
+ - Keep only the essential logic and core actions. Don't explain or test what was removed or why something wasn't done, especially when writing documentation or communicating. Convey enough valuable information with as few words as possible.
36
+ - Solve problems by thinking from first principles and at a higher level.
37
37
  `;
38
38
  /** Resolve the full plugin-owned prompt, preserving intentional empty overrides. */
39
39
  export function resolveCodexSystemPrompt(systemPrompt) {
@@ -10,13 +10,17 @@ interface JsonObject {
10
10
  interface CodexRequestWireOptions {
11
11
  /** Provider-facing request option preserved by older DSH LLM adapters. */
12
12
  serviceTier?: string;
13
+ /** Whether local web_search should become the hosted Responses tool. */
14
+ hostedWebSearch?: boolean;
15
+ /** Whether apply_patch should use the Responses custom grammar tool. */
16
+ customApplyPatch?: boolean;
13
17
  }
14
18
  /** Replace DSH's JSON function declaration with the Responses custom grammar tool. */
15
19
  export declare function addCodexApplyPatch(body: JsonObject): JsonObject;
16
20
  /** Replay apply_patch calls as custom tool items after pi-ai's generic conversion. */
17
21
  export declare function rewriteCodexApplyPatchHistory(body: JsonObject): JsonObject;
18
22
  /** Compose the plugin-only Responses rewrites without changing DSH's tool API. */
19
- export declare function rewriteCodexResponsesBody(body: JsonObject): JsonObject;
23
+ export declare function rewriteCodexResponsesBody(body: JsonObject, options?: Pick<CodexRequestWireOptions, 'hostedWebSearch' | 'customApplyPatch'>): JsonObject;
20
24
  /** Convert a generic DSH Responses tool list to the hosted Codex variant. */
21
25
  export declare function addHostedWebSearch(body: JsonObject): JsonObject;
22
26
  /** Replace the text placeholder written by dsh-compaction-basic with the native item. */
@@ -26,6 +30,6 @@ export declare function installHostedWebSearch(): () => void;
26
30
  /** Iterate an existing DSH stream with the hosted-request context installed. */
27
31
  export declare function hostedWebSearchStream(next: () => AsyncIterable<StreamChunk>, options?: CodexRequestWireOptions): AsyncIterable<StreamChunk>;
28
32
  /** Remote-first compaction waterfall with the existing DSH path as fallback. */
29
- export declare function remoteCompactStream(ctx: Context, options: GenerateOptions, next: () => AsyncIterable<StreamChunk>): AsyncIterable<StreamChunk>;
33
+ export declare function remoteCompactStream(ctx: Context, options: GenerateOptions, next: () => AsyncIterable<StreamChunk>, wireOptions?: CodexRequestWireOptions): AsyncIterable<StreamChunk>;
30
34
  export {};
31
35
  //# sourceMappingURL=remote.d.ts.map