@shuind/dsh-codex-harness 0.1.39 → 0.2.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/README.md +22 -110
- package/cordis.patch.yml +1 -1
- package/lib/client.js +345 -3
- package/lib/index.js +91 -58
- package/lib/installer.js +155 -22
- package/lib/types/client/index.d.ts +26 -2
- package/lib/types/client/index.js +145 -2
- package/lib/types/context.d.ts +1 -1
- package/lib/types/context.js +1 -1
- package/lib/types/index.d.ts +8 -13
- package/lib/types/index.js +41 -58
- package/lib/types/installer.d.ts +7 -5
- package/lib/types/installer.js +98 -25
- package/lib/types/prompt.d.ts +5 -0
- package/lib/types/prompt.js +42 -0
- package/lib/types/settings.d.ts +16 -0
- package/lib/types/settings.js +18 -0
- package/package.json +8 -4
- package/presets/codex-collaboration/agent.cordis.yml +4 -6
- package/presets/codex-collaboration/preset.yml +3 -3
- package/presets/codex/agent.cordis.yml +0 -195
- package/presets/codex/preset.yml +0 -3
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
-
/** Browser controls for
|
|
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
5
|
import { CODEX_CONTEXT_MAX, CODEX_CONTEXT_UNIT, isCodexPresetId } from "../context.js";
|
|
6
|
+
import { DEFAULT_CODEX_SYSTEM_PROMPT } from "../prompt.js";
|
|
6
7
|
import { modelActivity, sameModelActivity } from "./activity.js";
|
|
7
8
|
const NS = 'codex';
|
|
8
9
|
const SETTINGS_NAMESPACE = 'codex';
|
|
9
10
|
const FAST_FALLBACK_SLOT = 'conversation.input.right';
|
|
10
11
|
const LEGACY_OVERLAY_SLOT = 'conversation.input.overlay';
|
|
12
|
+
const PLUGIN_SETTINGS_SLOT = 'settings.plugin.item';
|
|
11
13
|
const DEFAULT_CONTEXT_WINDOW = 262_144;
|
|
12
14
|
const en = {
|
|
13
15
|
fast: 'Fast mode',
|
|
@@ -18,6 +20,20 @@ const en = {
|
|
|
18
20
|
contextSize: 'Context size',
|
|
19
21
|
contextSizeDescription: 'Next request capacity in K tokens.',
|
|
20
22
|
contextRestore: 'Restore model default',
|
|
23
|
+
promptCardTitle: 'Codex Harness',
|
|
24
|
+
promptCardDescription: 'View and customize the complete Codex operating prompt.',
|
|
25
|
+
promptLabel: 'System prompt',
|
|
26
|
+
promptHint: 'This is the full prompt owned by this plugin. Persona and DSH tool guidance stay dynamic.',
|
|
27
|
+
promptOverridden: 'Overridden',
|
|
28
|
+
promptReset: 'Restore default',
|
|
29
|
+
promptUnsaved: 'Unsaved',
|
|
30
|
+
promptDiscard: 'Discard',
|
|
31
|
+
promptSave: 'Save',
|
|
32
|
+
promptSaving: 'Saving...',
|
|
33
|
+
promptSaveFailed: 'Could not save the prompt.',
|
|
34
|
+
promptExpand: 'Expand settings',
|
|
35
|
+
promptCollapse: 'Collapse settings',
|
|
36
|
+
promptReadOnly: 'This settings document is read-only.',
|
|
21
37
|
activityCompacting: 'Compacting context...',
|
|
22
38
|
activityRequestingModel: 'Requesting model...',
|
|
23
39
|
activityModelReply: 'Model replying...',
|
|
@@ -31,10 +47,131 @@ const zh = {
|
|
|
31
47
|
contextSize: '\u4e0a\u4e0b\u6587\u5927\u5c0f',
|
|
32
48
|
contextSizeDescription: '\u8bbe\u7f6e\u4e0b\u6b21\u8bf7\u6c42\u7684\u4e0a\u4e0b\u6587\u5bb9\u91cf\uff0c\u5355\u4f4d\u4e3a K tokens\u3002',
|
|
33
49
|
contextRestore: '\u6062\u590d\u6a21\u578b\u9ed8\u8ba4\u503c',
|
|
50
|
+
promptCardTitle: 'Codex Harness',
|
|
51
|
+
promptCardDescription: '\u67e5\u770b\u548c\u81ea\u5b9a\u4e49\u5b8c\u6574\u7684 Codex \u7cfb\u7edf\u63d0\u793a\u8bcd\u3002',
|
|
52
|
+
promptLabel: '\u7cfb\u7edf\u63d0\u793a\u8bcd',
|
|
53
|
+
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
|
+
promptOverridden: '\u5df2\u8986\u76d6',
|
|
55
|
+
promptReset: '\u6062\u590d\u9ed8\u8ba4',
|
|
56
|
+
promptUnsaved: '\u672a\u4fdd\u5b58',
|
|
57
|
+
promptDiscard: '\u653e\u5f03',
|
|
58
|
+
promptSave: '\u4fdd\u5b58',
|
|
59
|
+
promptSaving: '\u4fdd\u5b58\u4e2d...',
|
|
60
|
+
promptSaveFailed: '\u63d0\u793a\u8bcd\u4fdd\u5b58\u5931\u8d25\u3002',
|
|
61
|
+
promptExpand: '\u5c55\u5f00\u8bbe\u7f6e',
|
|
62
|
+
promptCollapse: '\u6536\u8d77\u8bbe\u7f6e',
|
|
63
|
+
promptReadOnly: '\u5f53\u524d\u8bbe\u7f6e\u6587\u4ef6\u4e3a\u53ea\u8bfb\u3002',
|
|
34
64
|
activityCompacting: '\u6b63\u5728\u538b\u7f29\u4e0a\u4e0b\u6587...',
|
|
35
65
|
activityRequestingModel: '\u8bf7\u6c42\u4e2d...',
|
|
36
66
|
activityModelReply: '\u56de\u590d\u4e2d...',
|
|
37
67
|
};
|
|
68
|
+
function promptFromLayer(layer) {
|
|
69
|
+
if (typeof layer !== 'object' || layer === null || Array.isArray(layer))
|
|
70
|
+
return undefined;
|
|
71
|
+
const value = layer['systemPrompt'];
|
|
72
|
+
return typeof value === 'string' ? value : undefined;
|
|
73
|
+
}
|
|
74
|
+
function hasPromptOverride(layer) {
|
|
75
|
+
return typeof layer === 'object'
|
|
76
|
+
&& layer !== null
|
|
77
|
+
&& !Array.isArray(layer)
|
|
78
|
+
&& Object.hasOwn(layer, 'systemPrompt');
|
|
79
|
+
}
|
|
80
|
+
/** Full-prompt editor contributed to Settings > Plugins. */
|
|
81
|
+
export function PromptSettingsCard(props) {
|
|
82
|
+
const { useSettings, setSetting, unsetSetting, t } = props;
|
|
83
|
+
const snapshot = useSettings(state => state);
|
|
84
|
+
const current = snapshot.value?.systemPrompt ?? DEFAULT_CODEX_SYSTEM_PROMPT;
|
|
85
|
+
const inherited = promptFromLayer(snapshot.base) ?? DEFAULT_CODEX_SYSTEM_PROMPT;
|
|
86
|
+
const overridden = hasPromptOverride(snapshot.user);
|
|
87
|
+
const [open, setOpen] = useState(false);
|
|
88
|
+
const [draft, setDraft] = useState(current);
|
|
89
|
+
const [saving, setSaving] = useState(false);
|
|
90
|
+
const [failed, setFailed] = useState(false);
|
|
91
|
+
useEffect(() => { setDraft(current); }, [current]);
|
|
92
|
+
if (snapshot.status === 'unavailable')
|
|
93
|
+
return null;
|
|
94
|
+
const dirty = draft !== current;
|
|
95
|
+
const save = async () => {
|
|
96
|
+
setSaving(true);
|
|
97
|
+
setFailed(false);
|
|
98
|
+
try {
|
|
99
|
+
await setSetting('systemPrompt', draft);
|
|
100
|
+
}
|
|
101
|
+
catch {
|
|
102
|
+
setFailed(true);
|
|
103
|
+
}
|
|
104
|
+
finally {
|
|
105
|
+
setSaving(false);
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
const reset = async () => {
|
|
109
|
+
setSaving(true);
|
|
110
|
+
setFailed(false);
|
|
111
|
+
setDraft(inherited);
|
|
112
|
+
try {
|
|
113
|
+
await unsetSetting('systemPrompt');
|
|
114
|
+
}
|
|
115
|
+
catch {
|
|
116
|
+
setFailed(true);
|
|
117
|
+
setDraft(current);
|
|
118
|
+
}
|
|
119
|
+
finally {
|
|
120
|
+
setSaving(false);
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
return (_jsxs("li", { style: {
|
|
124
|
+
listStyle: 'none',
|
|
125
|
+
border: '1px solid var(--dsw-alias-border-l2)',
|
|
126
|
+
borderRadius: 12,
|
|
127
|
+
background: open ? 'var(--dsw-alias-bg-layer-2)' : 'var(--dsw-alias-bg-layer-3)',
|
|
128
|
+
overflow: 'hidden',
|
|
129
|
+
}, children: [_jsxs("button", { type: "button", "aria-expanded": open, "aria-label": `${t(open ? 'promptCollapse' : 'promptExpand')}: ${t('promptCardTitle')}`, onClick: () => { setOpen(!open); }, style: {
|
|
130
|
+
width: '100%',
|
|
131
|
+
border: 0,
|
|
132
|
+
background: 'none',
|
|
133
|
+
color: 'inherit',
|
|
134
|
+
padding: '14px 16px',
|
|
135
|
+
display: 'flex',
|
|
136
|
+
alignItems: 'center',
|
|
137
|
+
gap: 12,
|
|
138
|
+
textAlign: 'left',
|
|
139
|
+
cursor: 'pointer',
|
|
140
|
+
font: 'inherit',
|
|
141
|
+
}, children: [_jsxs("span", { style: { flex: 1, minWidth: 0, display: 'flex', flexDirection: 'column', gap: 4 }, children: [_jsx("strong", { style: { fontSize: 15, lineHeight: 1.4 }, children: t('promptCardTitle') }), _jsx("span", { style: { color: 'var(--dsw-alias-label-tertiary)', fontSize: 13, lineHeight: 1.5 }, children: t('promptCardDescription') })] }), dirty && (_jsx("span", { style: {
|
|
142
|
+
borderRadius: 999,
|
|
143
|
+
padding: '1px 8px',
|
|
144
|
+
background: 'var(--dsw-alias-bg-module-platform)',
|
|
145
|
+
color: 'var(--dsw-alias-label-secondary)',
|
|
146
|
+
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: {
|
|
148
|
+
borderRadius: 999,
|
|
149
|
+
padding: '1px 8px',
|
|
150
|
+
background: 'var(--dsw-alias-bg-module-platform)',
|
|
151
|
+
color: 'var(--dsw-alias-label-secondary)',
|
|
152
|
+
fontSize: 11,
|
|
153
|
+
}, children: t('promptOverridden') }), _jsx("button", { type: "button", disabled: !snapshot.writable || saving, onClick: () => { void reset(); }, style: { border: 0, background: 'none', color: 'var(--dsw-alias-label-secondary)', font: 'inherit', fontSize: 12, cursor: 'pointer' }, children: t('promptReset') })] }))] }), _jsx("textarea", { id: "codex-system-prompt", value: draft, disabled: !snapshot.writable || saving, onChange: event => { setDraft(event.target.value); }, spellCheck: false, style: {
|
|
154
|
+
boxSizing: 'border-box',
|
|
155
|
+
width: '100%',
|
|
156
|
+
minHeight: 320,
|
|
157
|
+
resize: 'vertical',
|
|
158
|
+
padding: 12,
|
|
159
|
+
border: '1px solid var(--dsw-alias-border-l2)',
|
|
160
|
+
borderRadius: 8,
|
|
161
|
+
background: 'var(--dsw-alias-bg-layer-3)',
|
|
162
|
+
color: 'var(--dsw-alias-label-primary)',
|
|
163
|
+
fontFamily: 'ui-monospace, SFMono-Regular, Consolas, monospace',
|
|
164
|
+
fontSize: 12,
|
|
165
|
+
lineHeight: 1.55,
|
|
166
|
+
} }), _jsx("p", { style: { margin: '6px 0 12px', color: 'var(--dsw-alias-label-tertiary)', fontSize: 12, lineHeight: 1.5 }, children: t('promptHint') }), _jsxs("div", { style: {
|
|
167
|
+
display: 'flex',
|
|
168
|
+
justifyContent: 'flex-end',
|
|
169
|
+
alignItems: 'center',
|
|
170
|
+
gap: 8,
|
|
171
|
+
paddingTop: 12,
|
|
172
|
+
borderTop: '1px solid var(--dsw-alias-border-l2)',
|
|
173
|
+
}, children: [failed && (_jsx("span", { role: "status", style: { flex: 1, color: 'var(--dsw-alias-label-error)', fontSize: 12 }, children: t('promptSaveFailed') })), _jsx("button", { type: "button", disabled: !dirty || saving, onClick: () => { setDraft(current); setFailed(false); }, style: { border: '1px solid var(--dsw-alias-border-l2)', borderRadius: 8, background: 'none', color: 'inherit', padding: '5px 14px', font: 'inherit', cursor: 'pointer' }, children: t('promptDiscard') }), _jsx("button", { type: "button", disabled: !snapshot.writable || !dirty || saving, onClick: () => { void save(); }, style: { border: 0, borderRadius: 8, background: 'var(--dsw-alias-label-primary)', color: 'var(--dsw-alias-bg-layer-3)', padding: '6px 14px', font: 'inherit', cursor: 'pointer' }, children: saving ? t('promptSaving') : t('promptSave') })] })] }))] }));
|
|
174
|
+
}
|
|
38
175
|
/** The legacy composer seat is a compact inline row, not a menu panel. */
|
|
39
176
|
function FastModeFallback(props) {
|
|
40
177
|
const { sessionId, useSessions, useSettings, setSetting, t } = props;
|
|
@@ -285,7 +422,7 @@ function LegacyOverlay(props) {
|
|
|
285
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')] }));
|
|
286
423
|
}
|
|
287
424
|
export const inject = ['slots', 'locale', 'settingsScope'];
|
|
288
|
-
/** Mount
|
|
425
|
+
/** Mount request controls and the plugin settings card through shared slots. */
|
|
289
426
|
export function apply(ctx) {
|
|
290
427
|
ctx.effect(() => ctx.locale.register(NS, { en, zh }), 'codex client: dictionaries');
|
|
291
428
|
const settings = ctx.settingsScope.bind({ namespace: SETTINGS_NAMESPACE });
|
|
@@ -308,6 +445,12 @@ export function apply(ctx) {
|
|
|
308
445
|
locale: NS,
|
|
309
446
|
inject: injected,
|
|
310
447
|
}, LegacyOverlay));
|
|
448
|
+
ctx.slots.inject(PLUGIN_SETTINGS_SLOT, () => ctx.slots.register({
|
|
449
|
+
name: PLUGIN_SETTINGS_SLOT,
|
|
450
|
+
key: SETTINGS_NAMESPACE,
|
|
451
|
+
locale: NS,
|
|
452
|
+
inject: injected,
|
|
453
|
+
}, PromptSettingsCard));
|
|
311
454
|
}
|
|
312
455
|
export default { inject, apply };
|
|
313
456
|
//# sourceMappingURL=index.js.map
|
package/lib/types/context.d.ts
CHANGED
|
@@ -3,6 +3,6 @@ export declare const CODEX_CONTEXT_UNIT = 1000;
|
|
|
3
3
|
export declare const CODEX_CONTEXT_MAX = 1000000;
|
|
4
4
|
export declare const CODEX_PRESET_ID = "codex";
|
|
5
5
|
export declare const CODEX_COLLABORATION_PRESET_ID = "codex-collaboration";
|
|
6
|
-
/**
|
|
6
|
+
/** The bundled preset and legacy Codex sessions share the same Web controls. */
|
|
7
7
|
export declare function isCodexPresetId(value: string | undefined): boolean;
|
|
8
8
|
//# sourceMappingURL=context.d.ts.map
|
package/lib/types/context.js
CHANGED
|
@@ -7,7 +7,7 @@ const CODEX_PRESET_IDS = new Set([
|
|
|
7
7
|
CODEX_PRESET_ID,
|
|
8
8
|
CODEX_COLLABORATION_PRESET_ID,
|
|
9
9
|
]);
|
|
10
|
-
/**
|
|
10
|
+
/** The bundled preset and legacy Codex sessions share the same Web controls. */
|
|
11
11
|
export function isCodexPresetId(value) {
|
|
12
12
|
return value !== undefined && CODEX_PRESET_IDS.has(value);
|
|
13
13
|
}
|
package/lib/types/index.d.ts
CHANGED
|
@@ -4,6 +4,10 @@ import z from '@deepseek-ai/schemastery';
|
|
|
4
4
|
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
|
+
import type { CodexSettings } from './settings.ts';
|
|
8
|
+
export { DEFAULT_CODEX_SYSTEM_PROMPT } from './prompt.ts';
|
|
9
|
+
export { CODEX_SETTINGS_NAMESPACE, CODEX_SETTINGS_SCHEMA } from './settings.ts';
|
|
10
|
+
export type { CodexSettings } from './settings.ts';
|
|
7
11
|
export declare const name = "codex";
|
|
8
12
|
export declare const inject: string[];
|
|
9
13
|
/** Configuration for the Codex shell result bridge. */
|
|
@@ -20,19 +24,11 @@ export interface Config {
|
|
|
20
24
|
hostedWebSearch?: boolean;
|
|
21
25
|
/** Use the provider's /responses/compact endpoint before local compaction. */
|
|
22
26
|
remoteCompact?: boolean;
|
|
23
|
-
/**
|
|
24
|
-
|
|
27
|
+
/** Complete plugin-owned Codex operating prompt. */
|
|
28
|
+
systemPrompt?: string;
|
|
25
29
|
}
|
|
26
30
|
/** Runtime configuration schema for the Codex tool bridge. */
|
|
27
31
|
export declare const Config: z<Config>;
|
|
28
|
-
/** Live Codex-only request controls shared by the Web controls and agent layer. */
|
|
29
|
-
export declare const CODEX_SETTINGS_NAMESPACE: Branded<"SettingsNamespace">;
|
|
30
|
-
export interface CodexSettings {
|
|
31
|
-
/** Use the Responses priority service tier for GPT requests. */
|
|
32
|
-
fast: boolean;
|
|
33
|
-
/** Optional context capacity override, in tokens. */
|
|
34
|
-
contextWindow?: number;
|
|
35
|
-
}
|
|
36
32
|
/** Plugin-owned extension envelope; official DSH can carry these as unknown fields. */
|
|
37
33
|
export interface CodexRequestConfig extends LlmCallConfig {
|
|
38
34
|
/** Codex request context capacity override, in tokens. */
|
|
@@ -40,7 +36,6 @@ export interface CodexRequestConfig extends LlmCallConfig {
|
|
|
40
36
|
/** Provider-facing service tier, for example Responses `priority`. */
|
|
41
37
|
serviceTier?: string;
|
|
42
38
|
}
|
|
43
|
-
export declare const CODEX_SETTINGS_SCHEMA: z<CodexSettings>;
|
|
44
39
|
export interface CodexModelProfile {
|
|
45
40
|
id: string;
|
|
46
41
|
input?: string[];
|
|
@@ -62,8 +57,8 @@ export declare function syncCodexContextWindow(session: Session, contextWindow:
|
|
|
62
57
|
export declare function applyCodexRequestSettings(request: CodexRequestConfig, settings: CodexSettings): CodexRequestConfig;
|
|
63
58
|
/** Put the agent persona first and omit the generic Harness identity opener. */
|
|
64
59
|
export declare function normalizeCodexPromptAssembly(assembly: PromptAssembly): PromptAssembly;
|
|
65
|
-
/** Build the
|
|
66
|
-
export declare function buildCodexSystemPrompt(config?: Pick<Config, '
|
|
60
|
+
/** Build the complete plugin-owned prompt, preserving an intentional empty value. */
|
|
61
|
+
export declare function buildCodexSystemPrompt(config?: Pick<Config, 'systemPrompt'>): string;
|
|
67
62
|
/** Mount the Codex prompt/tool layer inside one fixed agent preset. */
|
|
68
63
|
export declare function apply(ctx: Context, config?: Config): void;
|
|
69
64
|
declare const _default: {
|
package/lib/types/index.js
CHANGED
|
@@ -2,11 +2,14 @@
|
|
|
2
2
|
import z from '@deepseek-ai/schemastery';
|
|
3
3
|
import { installSettingsSection, settingsNamespace } from '@deepseek-ai/dsh-settings';
|
|
4
4
|
import { defineTool } from '@deepseek-ai/dsh-tools';
|
|
5
|
-
import { CODEX_CONTEXT_MAX } from "./context.js";
|
|
6
5
|
import { APPLY_PATCH_DESCRIPTION, applyPatchHunks, parsePatch } from "./patch.js";
|
|
7
6
|
import { renderExecResult, runExecCommand, runWriteStdin } from "./exec.js";
|
|
8
7
|
import { hostedWebSearchStream, installHostedWebSearch, remoteCompactStream } from "./remote.js";
|
|
9
8
|
import { registerCodexActivityProjection } from "./activity.js";
|
|
9
|
+
import { DEFAULT_CODEX_SYSTEM_PROMPT, resolveCodexSystemPrompt } from "./prompt.js";
|
|
10
|
+
import { CODEX_SETTINGS_ENTRY, CODEX_SETTINGS_NAMESPACE, CODEX_SETTINGS_SCHEMA, } from "./settings.js";
|
|
11
|
+
export { DEFAULT_CODEX_SYSTEM_PROMPT } from "./prompt.js";
|
|
12
|
+
export { CODEX_SETTINGS_NAMESPACE, CODEX_SETTINGS_SCHEMA } from "./settings.js";
|
|
10
13
|
export const name = 'codex';
|
|
11
14
|
export const inject = ['tools', 'systemPrompt', 'shell', 'fs', 'llm', 'credentials', 'settings'];
|
|
12
15
|
const DEFAULT_MAX_OUTPUT_BYTES = 1024 * 1024;
|
|
@@ -18,16 +21,9 @@ export const Config = z.object({
|
|
|
18
21
|
maxOutputBytes: z.number().step(1).min(1).default(DEFAULT_MAX_OUTPUT_BYTES),
|
|
19
22
|
hostedWebSearch: z.boolean().default(true),
|
|
20
23
|
remoteCompact: z.boolean().default(true),
|
|
21
|
-
|
|
24
|
+
systemPrompt: z.string().default(DEFAULT_CODEX_SYSTEM_PROMPT),
|
|
22
25
|
});
|
|
23
26
|
const LLM_PI_AI_SETTINGS = settingsNamespace('llm-pi-ai');
|
|
24
|
-
/** Live Codex-only request controls shared by the Web controls and agent layer. */
|
|
25
|
-
export const CODEX_SETTINGS_NAMESPACE = settingsNamespace('codex');
|
|
26
|
-
export const CODEX_SETTINGS_SCHEMA = z.object({
|
|
27
|
-
fast: z.boolean().default(false),
|
|
28
|
-
contextWindow: z.number().step(1).min(1).max(CODEX_CONTEXT_MAX),
|
|
29
|
-
});
|
|
30
|
-
const CODEX_SETTINGS_ENTRY = { fast: false };
|
|
31
27
|
const GPT_REASONING_EFFORTS = {
|
|
32
28
|
low: 'low',
|
|
33
29
|
medium: 'medium',
|
|
@@ -119,10 +115,17 @@ function watchConfiguredGptModels(ctx) {
|
|
|
119
115
|
});
|
|
120
116
|
schedule();
|
|
121
117
|
}
|
|
122
|
-
/** Install the optional settings source used by
|
|
123
|
-
function installCodexSettings(ctx) {
|
|
124
|
-
|
|
125
|
-
|
|
118
|
+
/** Install the optional settings source used by requests and prompt assembly. */
|
|
119
|
+
function installCodexSettings(ctx, systemPrompt) {
|
|
120
|
+
const entry = { ...CODEX_SETTINGS_ENTRY, systemPrompt };
|
|
121
|
+
const settings = ctx.get('settings');
|
|
122
|
+
if (settings?.get(CODEX_SETTINGS_NAMESPACE) !== undefined) {
|
|
123
|
+
return {
|
|
124
|
+
current: () => settings.get(CODEX_SETTINGS_NAMESPACE) ?? entry,
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
let source = () => entry;
|
|
128
|
+
installSettingsSection(ctx, CODEX_SETTINGS_NAMESPACE, CODEX_SETTINGS_SCHEMA, entry, {
|
|
126
129
|
setSource: (current) => { source = current; },
|
|
127
130
|
onChange: () => { },
|
|
128
131
|
});
|
|
@@ -168,14 +171,29 @@ function installCodexContextProjection(ctx, current) {
|
|
|
168
171
|
const sync = (session, contextWindow = current().contextWindow) => {
|
|
169
172
|
syncCodexContextWindow(session, contextWindow);
|
|
170
173
|
};
|
|
174
|
+
const pending = new WeakSet();
|
|
175
|
+
const syncAfterPublication = (session) => {
|
|
176
|
+
if (pending.has(session))
|
|
177
|
+
return;
|
|
178
|
+
pending.add(session);
|
|
179
|
+
queueMicrotask(() => {
|
|
180
|
+
try {
|
|
181
|
+
sync(session);
|
|
182
|
+
}
|
|
183
|
+
finally {
|
|
184
|
+
pending.delete(session);
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
};
|
|
171
188
|
const syncAll = (contextWindow = current().contextWindow) => {
|
|
172
189
|
const sessions = ctx.get('sessions');
|
|
173
190
|
for (const session of sessions?.list?.() ?? [])
|
|
174
191
|
sync(session, contextWindow);
|
|
175
192
|
};
|
|
176
193
|
ctx.on('session/event', (session, event) => {
|
|
194
|
+
// Session.append() rejects nested appends until every observer returns.
|
|
177
195
|
if (event.type === 'request/header' || event.type === 'request/context')
|
|
178
|
-
|
|
196
|
+
syncAfterPublication(session);
|
|
179
197
|
});
|
|
180
198
|
// Restored sessions may already contain their request/header seed, so no
|
|
181
199
|
// session/event is emitted for the initial capacity. Catch them at the
|
|
@@ -206,43 +224,6 @@ export function applyCodexRequestSettings(request, settings) {
|
|
|
206
224
|
...settings.fast ? { serviceTier: 'priority' } : {},
|
|
207
225
|
};
|
|
208
226
|
}
|
|
209
|
-
// The shipped persona owns the single Codex identity line, model, and working directory.
|
|
210
|
-
const CODEX_BASE_PROMPT = String.raw `## General
|
|
211
|
-
|
|
212
|
-
- 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.
|
|
213
|
-
|
|
214
|
-
## Editing constraints
|
|
215
|
-
|
|
216
|
-
- 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.
|
|
217
|
-
- Add succinct code comments that explain non-obvious code. Do not add comments that merely narrate assignments or control flow.
|
|
218
|
-
- 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.
|
|
219
|
-
|
|
220
|
-
## Planning
|
|
221
|
-
|
|
222
|
-
- Use update_plan for work with multiple meaningful steps. Keep the plan current as the task progresses.
|
|
223
|
-
- Do not use a plan for a trivial one-step request.
|
|
224
|
-
|
|
225
|
-
## dsh session
|
|
226
|
-
|
|
227
|
-
- The user and you share one workspace. Inspect the repository and every applicable AGENTS.md before editing.
|
|
228
|
-
|
|
229
|
-
## Task execution
|
|
230
|
-
|
|
231
|
-
- Keep the user informed with concise progress updates and lead with the result.
|
|
232
|
-
|
|
233
|
-
## Presenting your work
|
|
234
|
-
|
|
235
|
-
- Be concise, direct, friendly, and actionable.
|
|
236
|
-
- For substantial work, explain what changed and why, then briefly note how the work was verified and what comes next.
|
|
237
|
-
- Do not dump large files into the conversation; refer to their paths.
|
|
238
|
-
- Use plain text with short sections only when they improve scanability.
|
|
239
|
-
`;
|
|
240
|
-
const CODEX_COLLABORATION_PROMPT = String.raw `## Working principles
|
|
241
|
-
|
|
242
|
-
- 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.
|
|
243
|
-
- Keep only the essential logic and core actions. There's no need to 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.
|
|
244
|
-
- Solve problems by thinking from first principles and at a higher level.
|
|
245
|
-
`;
|
|
246
227
|
/** Put the agent persona first and omit the generic Harness identity opener. */
|
|
247
228
|
export function normalizeCodexPromptAssembly(assembly) {
|
|
248
229
|
const sections = assembly.sections.filter(section => section.name !== 'harness:identity');
|
|
@@ -254,11 +235,9 @@ export function normalizeCodexPromptAssembly(assembly) {
|
|
|
254
235
|
sections: [persona, ...sections.filter(section => section.name !== 'deployment:persona')],
|
|
255
236
|
};
|
|
256
237
|
}
|
|
257
|
-
/** Build the
|
|
238
|
+
/** Build the complete plugin-owned prompt, preserving an intentional empty value. */
|
|
258
239
|
export function buildCodexSystemPrompt(config = {}) {
|
|
259
|
-
return config.
|
|
260
|
-
? `${CODEX_BASE_PROMPT}\n\n${CODEX_COLLABORATION_PROMPT}`
|
|
261
|
-
: CODEX_BASE_PROMPT;
|
|
240
|
+
return resolveCodexSystemPrompt(config.systemPrompt);
|
|
262
241
|
}
|
|
263
242
|
const EXEC_COMMAND_DESCRIPTION = 'Runs a command in a PTY, returning output, a session ID for ongoing interaction, or a background job ID when requested.';
|
|
264
243
|
const WRITE_STDIN_DESCRIPTION = 'Writes characters to an existing unified exec session and returns recent output.';
|
|
@@ -520,7 +499,7 @@ export function apply(ctx, config = {}) {
|
|
|
520
499
|
maxOutputBytes: config.maxOutputBytes ?? DEFAULT_MAX_OUTPUT_BYTES,
|
|
521
500
|
hostedWebSearch: config.hostedWebSearch ?? true,
|
|
522
501
|
remoteCompact: config.remoteCompact ?? true,
|
|
523
|
-
|
|
502
|
+
systemPrompt: config.systemPrompt ?? DEFAULT_CODEX_SYSTEM_PROMPT,
|
|
524
503
|
};
|
|
525
504
|
if (ctx.fs.sandboxMode !== undefined && ctx.get('sandboxPolicy') === undefined) {
|
|
526
505
|
throw new Error('codex: a sandboxing filesystem requires ctx.sandboxPolicy');
|
|
@@ -530,7 +509,7 @@ export function apply(ctx, config = {}) {
|
|
|
530
509
|
// metadata; failed remote operations continue through the generic path.
|
|
531
510
|
watchConfiguredGptModels(ctx);
|
|
532
511
|
registerCodexActivityProjection(ctx);
|
|
533
|
-
const codexSettings = installCodexSettings(ctx);
|
|
512
|
+
const codexSettings = installCodexSettings(ctx, resolved.systemPrompt);
|
|
534
513
|
installCodexContextProjection(ctx, codexSettings.current);
|
|
535
514
|
// Keep these controls in the request config rather than mutating provider
|
|
536
515
|
// settings. That makes a change apply to the next step without rebuilding
|
|
@@ -556,7 +535,11 @@ export function apply(ctx, config = {}) {
|
|
|
556
535
|
return next();
|
|
557
536
|
}));
|
|
558
537
|
ctx.on('system-prompt/assemble', async (_assembly, _context, next) => normalizeCodexPromptAssembly(await next()));
|
|
559
|
-
ctx.systemPrompt.section({
|
|
538
|
+
ctx.systemPrompt.section({
|
|
539
|
+
name: 'codex:base',
|
|
540
|
+
order: 10,
|
|
541
|
+
text: () => resolveCodexSystemPrompt(codexSettings.current().systemPrompt),
|
|
542
|
+
});
|
|
560
543
|
registerExecTools(ctx, resolved);
|
|
561
544
|
registerPatchTool(ctx);
|
|
562
545
|
registerPlanTool(ctx);
|
package/lib/types/installer.d.ts
CHANGED
|
@@ -2,23 +2,25 @@
|
|
|
2
2
|
import type { Context } from '@deepseek-ai/cordis';
|
|
3
3
|
/** Bundle plugin name for the preset installer. */
|
|
4
4
|
export declare const name = "codex-preset-installer";
|
|
5
|
+
export declare const inject: string[];
|
|
5
6
|
/**
|
|
6
|
-
* Install the shipped Codex preset
|
|
7
|
+
* Install or upgrade the single shipped Codex preset.
|
|
7
8
|
*
|
|
8
9
|
* The directory is committed with a staging rename so a failed copy cannot
|
|
9
|
-
* leave a half-written preset that hides the mode from the roster.
|
|
10
|
-
*
|
|
10
|
+
* leave a half-written preset that hides the mode from the roster. A known
|
|
11
|
+
* shipped copy upgrades in place; any changed or unknown copy is preserved.
|
|
11
12
|
*
|
|
12
13
|
* @param targetDir - destination preset directory.
|
|
13
14
|
* @param sourceDir - directory containing the packaged preset files.
|
|
14
15
|
*/
|
|
15
16
|
export declare function installCodexPreset(targetDir?: string, sourceDir?: string): void;
|
|
16
|
-
/**
|
|
17
|
-
export declare function
|
|
17
|
+
/** Remove an unmodified copy of the retired second Codex mode. */
|
|
18
|
+
export declare function retireLegacyCodexPreset(targetDir?: string, managedSignatures?: ReadonlySet<string>): void;
|
|
18
19
|
/** Install the preset during profile boot without changing the host tool catalog. */
|
|
19
20
|
export declare function apply(ctx: Context): void;
|
|
20
21
|
declare const _default: {
|
|
21
22
|
name: string;
|
|
23
|
+
inject: string[];
|
|
22
24
|
apply: typeof apply;
|
|
23
25
|
};
|
|
24
26
|
export default _default;
|
package/lib/types/installer.js
CHANGED
|
@@ -1,11 +1,33 @@
|
|
|
1
1
|
/** Install the user-visible Codex agent preset supplied by this bundle. */
|
|
2
|
-
import {
|
|
2
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
3
|
+
import { copyFileSync, existsSync, mkdirSync, mkdtempSync, readFileSync, renameSync, rmSync, writeFileSync, } from 'node:fs';
|
|
3
4
|
import { homedir } from 'node:os';
|
|
4
5
|
import { dirname, join, resolve } from 'node:path';
|
|
5
6
|
import { fileURLToPath } from 'node:url';
|
|
7
|
+
import { CODEX_SETTINGS_ENTRY, CODEX_SETTINGS_NAMESPACE, CODEX_SETTINGS_SCHEMA, } from "./settings.js";
|
|
6
8
|
const PRESET_FILES = ['agent.cordis.yml', 'preset.yml'];
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
+
const MANAGED_SIGNATURE_FILE = '.dsh-codex-harness-managed';
|
|
10
|
+
const BUNDLED_PRESET_ID = 'codex-collaboration';
|
|
11
|
+
const LEGACY_PRESET_ID = 'codex';
|
|
12
|
+
const SOURCE_PRESET_DIR = fileURLToPath(new URL('../presets/codex-collaboration/', import.meta.url));
|
|
13
|
+
// Exact signatures of every previously shipped preset. Unknown directories
|
|
14
|
+
// remain user-owned; known copies can be migrated without erasing edits.
|
|
15
|
+
const LEGACY_PRESET_SIGNATURES = new Set([
|
|
16
|
+
'2f6222b6c9fed417d0f8fbfef9b221f0c9088c63347466219309c1c2ca2426bb',
|
|
17
|
+
'40ae944220ca57daae93d1483d6cb6264e6847ed77ee84f38171c34c36f0598e',
|
|
18
|
+
'c6a594797f7044c44c09254635b8381f20533cd26a4661239529dc44ec423d0c',
|
|
19
|
+
'2c373798b9cadbda5fb377dab0d43ac5637263546a5a4fc1740752658fdec658',
|
|
20
|
+
'a4062b59ad0e512e1b1b7e80ae56d8cde4efdaa5ba958364a17653ba1ff3c2ed',
|
|
21
|
+
'16016e7f68ee61354de232151be5b6ad0cda1785183ca0c72f9d0946b6a1d6cd',
|
|
22
|
+
'7f72b1bea9b30074788f05d20b841a797a5b29bb945dd1fb0597c8d03eb2b9b9',
|
|
23
|
+
'6a6c8dc2e7a7dbc1ac30ce608a53c238f19066a786f951f9a295ada86e56ed9e',
|
|
24
|
+
]);
|
|
25
|
+
const BUNDLED_PRESET_SIGNATURES = new Set([
|
|
26
|
+
'2a7ef181266e69275d25091adc74dd619af7c7d3577573887aaaecd2663e13c8',
|
|
27
|
+
'd1de30f5c13049621b1c1ae3fb22d35b031797a4762638265822b0ff62749854',
|
|
28
|
+
'b50e1d616f9b4188a33c0da0fe355478b7b75b615f3792c094e2b67995622cf4',
|
|
29
|
+
'6132523d92893f6ae9214b30105e9cc1ba64854df6ca8a84213069eb6c38d286',
|
|
30
|
+
]);
|
|
9
31
|
function dshHomePath(...segments) {
|
|
10
32
|
const configured = process.env.DSH_HOME?.trim();
|
|
11
33
|
const expanded = configured === undefined || configured.length === 0
|
|
@@ -19,54 +41,105 @@ function dshHomePath(...segments) {
|
|
|
19
41
|
}
|
|
20
42
|
/** Bundle plugin name for the preset installer. */
|
|
21
43
|
export const name = 'codex-preset-installer';
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
44
|
+
export const inject = ['settings'];
|
|
45
|
+
function presetSignature(directory) {
|
|
46
|
+
if (PRESET_FILES.some(file => !existsSync(join(directory, file))))
|
|
47
|
+
return undefined;
|
|
48
|
+
const hash = createHash('sha256');
|
|
49
|
+
hash.update(readFileSync(join(directory, PRESET_FILES[0])));
|
|
50
|
+
hash.update(Buffer.from([0]));
|
|
51
|
+
hash.update(readFileSync(join(directory, PRESET_FILES[1])));
|
|
52
|
+
return hash.digest('hex');
|
|
53
|
+
}
|
|
54
|
+
function stagePreset(targetDir, sourceDir, presetId) {
|
|
25
55
|
const parentDir = dirname(targetDir);
|
|
26
56
|
mkdirSync(parentDir, { recursive: true });
|
|
27
57
|
const stagingDir = mkdtempSync(join(parentDir, `.${presetId}-`));
|
|
28
58
|
try {
|
|
29
59
|
for (const file of PRESET_FILES)
|
|
30
60
|
copyFileSync(join(sourceDir, file), join(stagingDir, file));
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
61
|
+
const signature = presetSignature(stagingDir);
|
|
62
|
+
if (signature === undefined)
|
|
63
|
+
throw new Error(`incomplete bundled preset: ${sourceDir}`);
|
|
64
|
+
writeFileSync(join(stagingDir, MANAGED_SIGNATURE_FILE), `${signature}\n`);
|
|
65
|
+
return stagingDir;
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
rmSync(stagingDir, { recursive: true, force: true });
|
|
69
|
+
throw error;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
function installPreset(targetDir, sourceDir, presetId) {
|
|
73
|
+
const stagingDir = stagePreset(targetDir, sourceDir, presetId);
|
|
74
|
+
try {
|
|
75
|
+
renameSync(stagingDir, targetDir);
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
if (!existsSync(targetDir))
|
|
79
|
+
throw error;
|
|
80
|
+
rmSync(stagingDir, { recursive: true, force: true });
|
|
38
81
|
}
|
|
39
|
-
|
|
82
|
+
}
|
|
83
|
+
function replacePreset(targetDir, sourceDir, presetId) {
|
|
84
|
+
const stagingDir = stagePreset(targetDir, sourceDir, presetId);
|
|
85
|
+
const backupDir = join(dirname(targetDir), `.${presetId}-backup-${randomUUID()}`);
|
|
86
|
+
renameSync(targetDir, backupDir);
|
|
87
|
+
try {
|
|
88
|
+
renameSync(stagingDir, targetDir);
|
|
89
|
+
rmSync(backupDir, { recursive: true, force: true });
|
|
90
|
+
}
|
|
91
|
+
catch (error) {
|
|
40
92
|
if (existsSync(stagingDir))
|
|
41
93
|
rmSync(stagingDir, { recursive: true, force: true });
|
|
94
|
+
if (!existsSync(targetDir))
|
|
95
|
+
renameSync(backupDir, targetDir);
|
|
96
|
+
throw error;
|
|
42
97
|
}
|
|
43
98
|
}
|
|
99
|
+
function hasMatchingManagedMarker(targetDir, signature) {
|
|
100
|
+
const marker = join(targetDir, MANAGED_SIGNATURE_FILE);
|
|
101
|
+
return existsSync(marker) && readFileSync(marker, 'utf8').trim() === signature;
|
|
102
|
+
}
|
|
44
103
|
/**
|
|
45
|
-
* Install the shipped Codex preset
|
|
104
|
+
* Install or upgrade the single shipped Codex preset.
|
|
46
105
|
*
|
|
47
106
|
* The directory is committed with a staging rename so a failed copy cannot
|
|
48
|
-
* leave a half-written preset that hides the mode from the roster.
|
|
49
|
-
*
|
|
107
|
+
* leave a half-written preset that hides the mode from the roster. A known
|
|
108
|
+
* shipped copy upgrades in place; any changed or unknown copy is preserved.
|
|
50
109
|
*
|
|
51
110
|
* @param targetDir - destination preset directory.
|
|
52
111
|
* @param sourceDir - directory containing the packaged preset files.
|
|
53
112
|
*/
|
|
54
|
-
export function installCodexPreset(targetDir = dshHomePath('.agent-presets',
|
|
55
|
-
|
|
113
|
+
export function installCodexPreset(targetDir = dshHomePath('.agent-presets', BUNDLED_PRESET_ID), sourceDir = SOURCE_PRESET_DIR) {
|
|
114
|
+
if (!existsSync(targetDir)) {
|
|
115
|
+
installPreset(targetDir, sourceDir, BUNDLED_PRESET_ID);
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
const signature = presetSignature(targetDir);
|
|
119
|
+
if (signature !== undefined
|
|
120
|
+
&& (BUNDLED_PRESET_SIGNATURES.has(signature) || hasMatchingManagedMarker(targetDir, signature))) {
|
|
121
|
+
replacePreset(targetDir, sourceDir, BUNDLED_PRESET_ID);
|
|
122
|
+
}
|
|
56
123
|
}
|
|
57
|
-
/**
|
|
58
|
-
export function
|
|
59
|
-
|
|
124
|
+
/** Remove an unmodified copy of the retired second Codex mode. */
|
|
125
|
+
export function retireLegacyCodexPreset(targetDir = dshHomePath('.agent-presets', LEGACY_PRESET_ID), managedSignatures = LEGACY_PRESET_SIGNATURES) {
|
|
126
|
+
if (!existsSync(targetDir))
|
|
127
|
+
return;
|
|
128
|
+
const signature = presetSignature(targetDir);
|
|
129
|
+
if (signature !== undefined && managedSignatures.has(signature)) {
|
|
130
|
+
rmSync(targetDir, { recursive: true, force: true });
|
|
131
|
+
}
|
|
60
132
|
}
|
|
61
133
|
/** Install the preset during profile boot without changing the host tool catalog. */
|
|
62
134
|
export function apply(ctx) {
|
|
63
135
|
try {
|
|
136
|
+
ctx.settings.register(CODEX_SETTINGS_NAMESPACE, CODEX_SETTINGS_SCHEMA, { base: CODEX_SETTINGS_ENTRY });
|
|
64
137
|
installCodexPreset();
|
|
65
|
-
|
|
138
|
+
retireLegacyCodexPreset();
|
|
66
139
|
}
|
|
67
140
|
catch (error) {
|
|
68
|
-
ctx.logger.warn(`dsh-codex: could not
|
|
141
|
+
ctx.logger.warn(`dsh-codex: could not reconcile the Codex preset: ${String(error)}`);
|
|
69
142
|
}
|
|
70
143
|
}
|
|
71
|
-
export default { name, apply };
|
|
144
|
+
export default { name, inject, apply };
|
|
72
145
|
//# sourceMappingURL=installer.js.map
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** Default plugin-owned Codex operating prompt. */
|
|
2
|
+
export declare const DEFAULT_CODEX_SYSTEM_PROMPT: string;
|
|
3
|
+
/** Resolve the full plugin-owned prompt, preserving intentional empty overrides. */
|
|
4
|
+
export declare function resolveCodexSystemPrompt(systemPrompt?: string): string;
|
|
5
|
+
//# sourceMappingURL=prompt.d.ts.map
|