@shuind/dsh-codex-harness 0.2.14 → 0.2.16

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.
@@ -3,8 +3,10 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
3
3
  import { useEffect, useLayoutEffect, useRef, 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_PERSONA, DEFAULT_CODEX_SYSTEM_PROMPT, DEFAULT_DSH_CORE_SOURCE_PROMPT, DEFAULT_DSH_CORE_WEB_PROMPT, } from "../prompt.js";
7
6
  import { modelActivity, sameModelActivity } from "./activity.js";
7
+ import presetEditorRemote from "../preset-editor-remote.js";
8
+ import { PresetManagerCard } from "./preset-manager.js";
9
+ import { presetEn, presetZh } from "./preset-copy.js";
8
10
  const NS = 'codex';
9
11
  const SETTINGS_NAMESPACE = 'codex';
10
12
  const FAST_FALLBACK_SLOT = 'conversation.input.right';
@@ -12,6 +14,7 @@ const LEGACY_OVERLAY_SLOT = 'conversation.input.overlay';
12
14
  const PLUGIN_SETTINGS_SLOT = 'settings.plugin.item';
13
15
  const DEFAULT_CONTEXT_WINDOW = 262_144;
14
16
  const en = {
17
+ ...presetEn,
15
18
  fast: 'Fast mode',
16
19
  fastOn: 'Fast mode on (priority tier)',
17
20
  fastOff: 'Fast mode off',
@@ -21,13 +24,10 @@ const en = {
21
24
  contextSizeDescription: 'Next request capacity in K tokens.',
22
25
  contextRestore: 'Restore model default',
23
26
  promptCardTitle: 'Codex Harness',
24
- promptCardDescription: 'Choose Codex capabilities and customize the operating prompt.',
25
- codexOnlyCapabilitiesLabel: 'Codex mode only',
26
- otherCapabilitiesLabel: 'Additional capabilities',
27
+ promptCardDescription: 'Edit presets and their Codex capabilities. Activity status is global.',
28
+ otherCapabilitiesLabel: 'Global capabilities',
27
29
  capabilityPrompt: 'Codex operating prompt',
28
30
  capabilityPromptHint: 'Inject the editable instructions and persona-first prompt layout.',
29
- capabilityFast: 'Fast mode control',
30
- capabilityFastHint: 'Show the Fast mode switch beside the conversation composer.',
31
31
  compactRemote: 'Remote compaction',
32
32
  compactRemoteHint: 'Use the provider remote compaction endpoint first.',
33
33
  compactLocal: 'Local compaction',
@@ -44,21 +44,7 @@ const en = {
44
44
  capabilityCompactionHint: 'Prefer the provider Responses compact endpoint before local compaction.',
45
45
  capabilityActivity: 'Activity indicator',
46
46
  capabilityActivityHint: 'Show request, reply, and compaction status beside the conversation.',
47
- promptCustomizationLabel: 'Prompt customization',
48
- personaLabel: 'Persona',
49
- personaHint: 'Deployment identity and role. Supports {{model}} and {{cwd}}.',
50
- sourcePromptLabel: 'DSH Core source instructions',
51
- sourcePromptHint: 'Guidance about the DSH checkout and working directory. Supports {{sourceRoot}}.',
52
- webPromptLabel: 'DSH Core Web instructions',
53
- webPromptHint: 'Guidance about this Web GUI, HMR, builds, and verification. Supports {{webUrl}}.',
54
- promptRestoreAll: 'Restore all prompt defaults',
55
47
  promptLabel: 'Codex operating prompt',
56
- promptHint: 'This is the Codex operating prompt. Persona and DSH Core instructions are edited separately above.',
57
- promptUnsaved: 'Unsaved',
58
- promptDiscard: 'Discard',
59
- promptSave: 'Save',
60
- promptSaving: 'Saving...',
61
- promptSaveFailed: 'Could not save the prompt.',
62
48
  promptExpand: 'Expand settings',
63
49
  promptCollapse: 'Collapse settings',
64
50
  promptReadOnly: 'This settings document is read-only.',
@@ -67,6 +53,7 @@ const en = {
67
53
  activityModelReply: 'Model replying...',
68
54
  };
69
55
  const zh = {
56
+ ...presetZh,
70
57
  fast: 'Fast',
71
58
  fastOn: 'Fast mode on (priority tier)',
72
59
  fastOff: 'Fast mode off',
@@ -76,13 +63,10 @@ const zh = {
76
63
  contextSizeDescription: '\u8bbe\u7f6e\u4e0b\u6b21\u8bf7\u6c42\u7684\u4e0a\u4e0b\u6587\u5bb9\u91cf\uff0c\u5355\u4f4d\u4e3a K tokens\u3002',
77
64
  contextRestore: '\u6062\u590d\u6a21\u578b\u9ed8\u8ba4\u503c',
78
65
  promptCardTitle: 'Codex Harness',
79
- promptCardDescription: '\u9009\u62e9 Codex \u80fd\u529b\u5e76\u81ea\u5b9a\u4e49\u5b8c\u6574\u7684\u64cd\u4f5c\u63d0\u793a\u8bcd\u3002',
80
- codexOnlyCapabilitiesLabel: '\u4ec5\u5728 Codex \u6a21\u5f0f\u4e0b',
81
- otherCapabilitiesLabel: '\u5176\u4ed6\u80fd\u529b',
66
+ promptCardDescription: '\u7f16\u8f91\u9884\u8bbe\u53ca\u5176 Codex \u80fd\u529b\uff0c\u6d3b\u52a8\u72b6\u6001\u662f\u5168\u5c40\u8bbe\u7f6e\u3002',
67
+ otherCapabilitiesLabel: '\u5168\u5c40\u80fd\u529b',
82
68
  capabilityPrompt: 'Codex \u64cd\u4f5c\u63d0\u793a\u8bcd',
83
69
  capabilityPromptHint: '\u6ce8\u5165\u53ef\u7f16\u8f91\u6307\u4ee4\uff0c\u5e76\u5c06 Persona \u653e\u5728\u63d0\u793a\u8bcd\u9996\u4f4d\u3002',
84
- capabilityFast: '\u663e\u793a Fast \u6a21\u5f0f',
85
- capabilityFastHint: '\u5728\u5bf9\u8bdd\u8f93\u5165\u533a\u65c1\u663e\u793a Fast \u5f00\u5173\u3002',
86
70
  compactRemote: '\u8fdc\u7a0b\u538b\u7f29',
87
71
  compactRemoteHint: '\u4f18\u5148\u4f7f\u7528\u63d0\u4f9b\u5546\u7684\u8fdc\u7a0b\u538b\u7f29\u7aef\u70b9\u3002',
88
72
  compactLocal: '\u672c\u5730\u538b\u7f29',
@@ -99,21 +83,7 @@ const zh = {
99
83
  capabilityCompactionHint: '\u4f18\u5148\u8c03\u7528\u63d0\u4f9b\u5546\u7684 Responses compact \u7aef\u70b9\uff0c\u5931\u8d25\u65f6\u56de\u9000\u672c\u5730\u538b\u7f29\u3002',
100
84
  capabilityActivity: '\u6d3b\u52a8\u72b6\u6001',
101
85
  capabilityActivityHint: '\u5728\u5bf9\u8bdd\u65c1\u663e\u793a\u8bf7\u6c42\u3001\u56de\u590d\u548c\u538b\u7f29\u72b6\u6001\u3002',
102
- promptCustomizationLabel: '\u63d0\u793a\u8bcd\u5b9a\u5236',
103
- personaLabel: 'Persona',
104
- personaHint: '\u5b9a\u4e49 Agent \u7684\u8eab\u4efd\u4e0e\u89d2\u8272\uff0c\u652f\u6301 {{model}} \u548c {{cwd}}\u3002',
105
- sourcePromptLabel: 'DSH Core \u6e90\u7801\u8bf4\u660e',
106
- sourcePromptHint: '\u8bf4\u660e DSH \u6e90\u7801\u68c0\u51fa\u76ee\u5f55\u4e0e\u5de5\u4f5c\u76ee\u5f55\uff0c\u652f\u6301 {{sourceRoot}}\u3002',
107
- webPromptLabel: 'DSH Core Web \u8bf4\u660e',
108
- webPromptHint: '\u8bf4\u660e Web GUI\u3001HMR\u3001\u6784\u5efa\u4e0e\u9a8c\u8bc1\uff0c\u652f\u6301 {{webUrl}}\u3002',
109
- promptRestoreAll: '\u6062\u590d\u6240\u6709\u63d0\u793a\u8bcd\u9ed8\u8ba4\u503c',
110
86
  promptLabel: 'Codex \u64cd\u4f5c\u63d0\u793a\u8bcd',
111
- promptHint: '\u8fd9\u662f Codex \u64cd\u4f5c\u63d0\u793a\u8bcd\u3002Persona \u548c DSH Core \u8bf4\u660e\u5728\u4e0a\u65b9\u5206\u522b\u7f16\u8f91\u3002',
112
- promptUnsaved: '\u672a\u4fdd\u5b58',
113
- promptDiscard: '\u653e\u5f03',
114
- promptSave: '\u4fdd\u5b58',
115
- promptSaving: '\u4fdd\u5b58\u4e2d...',
116
- promptSaveFailed: '\u63d0\u793a\u8bcd\u4fdd\u5b58\u5931\u8d25\u3002',
117
87
  promptExpand: '\u5c55\u5f00\u8bbe\u7f6e',
118
88
  promptCollapse: '\u6536\u8d77\u8bbe\u7f6e',
119
89
  promptReadOnly: '\u5f53\u524d\u8bbe\u7f6e\u6587\u4ef6\u4e3a\u53ea\u8bfb\u3002',
@@ -166,128 +136,17 @@ function CapabilityGroup({ id, label, children, accent }) {
166
136
  paddingLeft: 12,
167
137
  }, children: children }))] }));
168
138
  }
169
- function PromptEditor({ id, label, hint, value, writable, saving, minHeight, onChange, }) {
170
- const [open, setOpen] = useState(false);
171
- const labelId = `${id}-label`;
172
- const panelId = `${id}-panel`;
173
- return (_jsxs("div", { style: { display: 'grid', gap: open ? 8 : 0 }, children: [_jsxs("button", { type: "button", "aria-expanded": open, "aria-controls": panelId, onClick: () => { setOpen(!open); }, style: {
174
- display: 'flex',
175
- alignItems: 'center',
176
- gap: 8,
177
- width: '100%',
178
- padding: 0,
179
- border: 0,
180
- background: 'none',
181
- color: 'var(--dsw-alias-label-primary)',
182
- font: 'inherit',
183
- fontSize: 13,
184
- fontWeight: 500,
185
- textAlign: 'left',
186
- cursor: 'pointer',
187
- }, children: [_jsx("span", { id: labelId, style: { flex: 1 }, children: label }), _jsx("span", { "aria-hidden": "true", style: { color: 'var(--dsw-alias-label-tertiary)', fontSize: 16 }, children: open ? '-' : '+' })] }), open && (_jsxs("div", { id: panelId, style: { display: 'grid', gap: 5 }, children: [_jsx("textarea", { id: id, "aria-labelledby": labelId, value: value, disabled: !writable || saving, onChange: event => { onChange(event.target.value); }, spellCheck: false, style: {
188
- boxSizing: 'border-box',
189
- width: '100%',
190
- minHeight,
191
- resize: 'vertical',
192
- padding: 10,
193
- border: '1px solid var(--dsw-alias-border-l2)',
194
- borderRadius: 8,
195
- background: 'var(--dsw-alias-bg-layer-3)',
196
- color: 'var(--dsw-alias-label-primary)',
197
- font: 'inherit',
198
- fontSize: 12,
199
- lineHeight: 1.5,
200
- } }), _jsx("span", { style: { color: 'var(--dsw-alias-label-tertiary)', fontSize: 11, lineHeight: 1.45 }, children: hint })] }))] }));
201
- }
202
- /** Full-prompt editor contributed to Settings > Plugins. */
139
+ /** Preset editor and global activity control contributed to Settings > Plugins. */
203
140
  export function PromptSettingsCard(props) {
204
- const { useSettings, setSetting, t } = props;
141
+ const { useSettings, setSetting, presetManager, t } = props;
205
142
  const snapshot = useSettings(state => state);
206
- const currentPersona = snapshot.value?.persona ?? DEFAULT_CODEX_PERSONA;
207
- const currentSourcePrompt = snapshot.value?.harnessSourcePrompt ?? DEFAULT_DSH_CORE_SOURCE_PROMPT;
208
- const currentWebPrompt = snapshot.value?.webSurfacePrompt ?? DEFAULT_DSH_CORE_WEB_PROMPT;
209
- const current = snapshot.value?.systemPrompt ?? DEFAULT_CODEX_SYSTEM_PROMPT;
210
- const codexOnlyCapabilities = [
211
- { field: 'fastModeControlEnabled', label: 'capabilityFast', hint: 'capabilityFastHint' },
212
- { field: 'promptEnabled', label: 'capabilityPrompt', hint: 'capabilityPromptHint' },
213
- { field: 'terminalToolsEnabled', label: 'capabilityTerminal', hint: 'capabilityTerminalHint' },
214
- { field: 'patchToolEnabled', label: 'capabilityPatch', hint: 'capabilityPatchHint' },
215
- { field: 'planToolEnabled', label: 'capabilityPlan', hint: 'capabilityPlanHint' },
216
- ];
217
143
  const otherCapabilities = [
218
- { field: 'hostedWebSearchEnabled', label: 'capabilityWebSearch', hint: 'capabilityWebSearchHint' },
219
- { field: 'remoteCompactionEnabled', label: 'capabilityCompaction', hint: 'capabilityCompactionHint' },
220
144
  { field: 'activityIndicatorEnabled', label: 'capabilityActivity', hint: 'capabilityActivityHint' },
221
145
  ];
222
146
  const [open, setOpen] = useState(false);
223
- const [personaDraft, setPersonaDraft] = useState(currentPersona);
224
- const [sourcePromptDraft, setSourcePromptDraft] = useState(currentSourcePrompt);
225
- const [webPromptDraft, setWebPromptDraft] = useState(currentWebPrompt);
226
- const [draft, setDraft] = useState(current);
227
- const [saving, setSaving] = useState(false);
228
- const [failed, setFailed] = useState(false);
229
- useEffect(() => {
230
- setPersonaDraft(currentPersona);
231
- setSourcePromptDraft(currentSourcePrompt);
232
- setWebPromptDraft(currentWebPrompt);
233
- setDraft(current);
234
- }, [current, currentPersona, currentSourcePrompt, currentWebPrompt]);
235
147
  if (snapshot.status === 'unavailable')
236
148
  return null;
237
- const dirty = personaDraft !== currentPersona
238
- || sourcePromptDraft !== currentSourcePrompt
239
- || webPromptDraft !== currentWebPrompt
240
- || draft !== current;
241
- const canRestore = dirty
242
- || currentPersona !== DEFAULT_CODEX_PERSONA
243
- || currentSourcePrompt !== DEFAULT_DSH_CORE_SOURCE_PROMPT
244
- || currentWebPrompt !== DEFAULT_DSH_CORE_WEB_PROMPT
245
- || current !== DEFAULT_CODEX_SYSTEM_PROMPT;
246
- const renderCapability = (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));
247
- const save = async () => {
248
- setSaving(true);
249
- setFailed(false);
250
- try {
251
- await Promise.all([
252
- setSetting('persona', personaDraft),
253
- setSetting('harnessSourcePrompt', sourcePromptDraft),
254
- setSetting('webSurfacePrompt', webPromptDraft),
255
- setSetting('systemPrompt', draft),
256
- ]);
257
- }
258
- catch {
259
- setFailed(true);
260
- }
261
- finally {
262
- setSaving(false);
263
- }
264
- };
265
- const reset = async () => {
266
- setSaving(true);
267
- setFailed(false);
268
- setPersonaDraft(DEFAULT_CODEX_PERSONA);
269
- setSourcePromptDraft(DEFAULT_DSH_CORE_SOURCE_PROMPT);
270
- setWebPromptDraft(DEFAULT_DSH_CORE_WEB_PROMPT);
271
- setDraft(DEFAULT_CODEX_SYSTEM_PROMPT);
272
- try {
273
- await Promise.all([
274
- setSetting('persona', DEFAULT_CODEX_PERSONA),
275
- setSetting('harnessSourcePrompt', DEFAULT_DSH_CORE_SOURCE_PROMPT),
276
- setSetting('webSurfacePrompt', DEFAULT_DSH_CORE_WEB_PROMPT),
277
- setSetting('systemPrompt', DEFAULT_CODEX_SYSTEM_PROMPT),
278
- ]);
279
- }
280
- catch {
281
- setFailed(true);
282
- setPersonaDraft(currentPersona);
283
- setSourcePromptDraft(currentSourcePrompt);
284
- setWebPromptDraft(currentWebPrompt);
285
- setDraft(current);
286
- }
287
- finally {
288
- setSaving(false);
289
- }
290
- };
149
+ const renderCapability = (capability) => (_jsx(CapabilityToggle, { field: capability.field, label: t(capability.label), hint: t(capability.hint), enabled: snapshot.value?.[capability.field] ?? true, disabled: !snapshot.writable, setSetting: setSetting }, capability.field));
291
150
  return (_jsxs("li", { style: {
292
151
  listStyle: 'none',
293
152
  border: '1px solid var(--dsw-alias-border-l2)',
@@ -306,31 +165,7 @@ export function PromptSettingsCard(props) {
306
165
  textAlign: 'left',
307
166
  cursor: 'pointer',
308
167
  font: 'inherit',
309
- }, 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: {
310
- borderRadius: 999,
311
- padding: '1px 8px',
312
- background: 'var(--dsw-alias-bg-module-platform)',
313
- color: 'var(--dsw-alias-label-secondary)',
314
- fontSize: 11,
315
- }, 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: 'grid', gap: 16, marginBottom: 14 }, children: [_jsx(CapabilityGroup, { id: "codex-only-capabilities", label: t('codexOnlyCapabilitiesLabel'), accent: "var(--dsw-static-blue-500)", children: codexOnlyCapabilities.map(renderCapability) }), _jsx(CapabilityGroup, { id: "other-capabilities", label: t('otherCapabilitiesLabel'), accent: "var(--dsw-alias-label-tertiary)", children: otherCapabilities.map(renderCapability) })] }), _jsxs("div", { style: {
316
- display: 'grid',
317
- gap: 14,
318
- paddingTop: 12,
319
- borderTop: '1px solid var(--dsw-alias-border-l2)',
320
- }, children: [_jsxs("div", { style: { display: 'flex', alignItems: 'center', gap: 8 }, children: [_jsx("strong", { style: { flex: 1, fontSize: 13 }, children: t('promptCustomizationLabel') }), _jsx("button", { type: "button", disabled: !snapshot.writable || saving || !canRestore, onClick: () => { void reset(); }, style: { border: 0, padding: 0, background: 'none', color: 'var(--dsw-alias-label-secondary)', font: 'inherit', fontSize: 11, cursor: 'pointer' }, children: t('promptRestoreAll') })] }), _jsx(PromptEditor, { id: "codex-persona", label: t('personaLabel'), hint: t('personaHint'), value: personaDraft, writable: snapshot.writable, saving: saving, minHeight: 84, onChange: setPersonaDraft }), _jsx(PromptEditor, { id: "codex-harness-source-prompt", label: t('sourcePromptLabel'), hint: t('sourcePromptHint'), value: sourcePromptDraft, writable: snapshot.writable, saving: saving, minHeight: 100, onChange: setSourcePromptDraft }), _jsx(PromptEditor, { id: "codex-web-surface-prompt", label: t('webPromptLabel'), hint: t('webPromptHint'), value: webPromptDraft, writable: snapshot.writable, saving: saving, minHeight: 120, onChange: setWebPromptDraft }), _jsx(PromptEditor, { id: "codex-system-prompt", label: t('promptLabel'), hint: t('promptHint'), value: draft, writable: snapshot.writable, saving: saving, minHeight: 320, onChange: setDraft })] }), _jsxs("div", { style: {
321
- display: 'flex',
322
- justifyContent: 'flex-end',
323
- alignItems: 'center',
324
- gap: 8,
325
- paddingTop: 12,
326
- borderTop: '1px solid var(--dsw-alias-border-l2)',
327
- }, 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: () => {
328
- setPersonaDraft(currentPersona);
329
- setSourcePromptDraft(currentSourcePrompt);
330
- setWebPromptDraft(currentWebPrompt);
331
- setDraft(current);
332
- setFailed(false);
333
- }, 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') })] })] }))] }));
168
+ }, 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') })] }), _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: [_jsx(PresetManagerCard, { presetManager: presetManager, t: t }), _jsxs("details", { style: { marginTop: 22, borderTop: '1px solid var(--dsw-alias-border-l2)', paddingTop: 14 }, children: [_jsx("summary", { style: { cursor: 'pointer', fontWeight: 600, marginBottom: 14 }, children: t('pmGlobalSettings') }), !snapshot.writable && (_jsx("p", { style: { margin: '0 0 10px', color: 'var(--dsw-alias-label-tertiary)', fontSize: 12 }, children: t('promptReadOnly') })), _jsx(CapabilityGroup, { id: "global-capabilities", label: t('otherCapabilitiesLabel'), accent: "var(--dsw-alias-label-tertiary)", children: otherCapabilities.map(renderCapability) })] })] }))] }));
334
169
  }
335
170
  /** The legacy composer seat is a compact inline row, not a menu panel. */
336
171
  function FastModeFallback(props) {
@@ -673,7 +508,50 @@ function LegacyOverlay(props) {
673
508
  const contextWindow = contextWindowFromProjection(useProjection);
674
509
  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')] }));
675
510
  }
676
- export const inject = ['commandUi', 'sessions', 'slots', 'locale', 'settingsScope'];
511
+ export const inject = [
512
+ 'commandUi', 'sessions', 'slots', 'locale', 'settingsScope',
513
+ 'remote', 'remote.agentPresets', 'remote.settings',
514
+ ];
515
+ function createPresetManager(ctx) {
516
+ const remote = ctx.remote;
517
+ const ready = remote === undefined
518
+ ? Promise.resolve()
519
+ : remote.$mount(presetEditorRemote).then(dispose => {
520
+ ctx.effect(() => () => { void dispose(); }, 'codex client: preset editor remote');
521
+ });
522
+ // Keep an unavailable optional host remote from becoming an unhandled rejection
523
+ // when the settings card is never opened. The card still awaits the same promise
524
+ // and renders the actual error if the user opens it.
525
+ void ready.catch(() => { });
526
+ return {
527
+ remote: remote,
528
+ ready,
529
+ };
530
+ }
531
+ /**
532
+ * The Codex editor contribution is mounted by this client entry itself. Its
533
+ * namespace therefore cannot be a top-level dependency (that would make the
534
+ * entry wait for the contribution it is responsible for mounting). Wait for
535
+ * the namespace in a child fiber instead, and capture that protected Remote
536
+ * face for the settings card.
537
+ */
538
+ function registerPresetSettingsCard(ctx, settings, presetManager) {
539
+ const settingsPresetManager = {
540
+ ...presetManager,
541
+ remote: ctx.remote,
542
+ };
543
+ return ctx.slots.inject(PLUGIN_SETTINGS_SLOT, () => ctx.slots.register({
544
+ name: PLUGIN_SETTINGS_SLOT,
545
+ key: SETTINGS_NAMESPACE,
546
+ locale: NS,
547
+ inject: () => ({
548
+ hooks: { settings },
549
+ setSetting: (field, value) => settings.set(field, value),
550
+ unsetSetting: (field) => settings.unset(field),
551
+ presetManager: settingsPresetManager,
552
+ }),
553
+ }, PromptSettingsCard));
554
+ }
677
555
  /** Mount request controls and the plugin settings card through shared slots. */
678
556
  export function apply(ctx) {
679
557
  ctx.effect(() => ctx.locale.register(NS, { en, zh }), 'codex client: dictionaries');
@@ -703,10 +581,12 @@ export function apply(ctx) {
703
581
  },
704
582
  }), 'codex client: /compact mode picker');
705
583
  const settings = ctx.settingsScope.bind({ namespace: SETTINGS_NAMESPACE });
584
+ const presetManager = createPresetManager(ctx);
706
585
  const injected = () => ({
707
586
  hooks: { settings },
708
587
  setSetting: (field, value) => settings.set(field, value),
709
588
  unsetSetting: (field) => settings.unset(field),
589
+ presetManager,
710
590
  });
711
591
  ctx.slots.inject(FAST_FALLBACK_SLOT, () => ctx.slots.register({
712
592
  name: FAST_FALLBACK_SLOT,
@@ -729,12 +609,10 @@ export function apply(ctx) {
729
609
  locale: NS,
730
610
  inject: injected,
731
611
  }, LegacyOverlay));
732
- ctx.slots.inject(PLUGIN_SETTINGS_SLOT, () => ctx.slots.register({
733
- name: PLUGIN_SETTINGS_SLOT,
734
- key: SETTINGS_NAMESPACE,
735
- locale: NS,
736
- inject: injected,
737
- }, PromptSettingsCard));
612
+ // `codexPresetEditor` is mounted by createPresetManager above. Keep its
613
+ // namespace dependency local to the settings card so the main client entry
614
+ // can start and perform that mount first.
615
+ ctx.inject(['remote', 'remote.agentPresets', 'remote.settings', 'remote.codexPresetEditor'], settingsCtx => registerPresetSettingsCard(settingsCtx, settings, presetManager));
738
616
  }
739
617
  export default { inject, apply };
740
618
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,30 @@
1
+ export declare const presetEn: {
2
+ readonly peTitle: "Preset editor";
3
+ readonly peHierarchy: "Codex mode and other presets are peers. Choose one to edit, or make an editable copy of a built-in preset first.";
4
+ readonly peSelect: "Preset";
5
+ readonly peSelectPlaceholder: "Choose a preset…";
6
+ readonly peEditable: "This is an editable user preset.";
7
+ readonly peBuiltinEdit: "Built-in presets are read-only. Create a copy to edit it.";
8
+ readonly peCreateCopy: "Create editable copy";
9
+ readonly peCodexSection: "Codex mode capabilities";
10
+ readonly peAddCodex: "Add Codex capabilities to this preset";
11
+ readonly peAddCodexHint: "Adds the Codex prompt, tools, hosted search, and remote compaction to this preset.";
12
+ readonly peActivityGlobal: "Activity status is a global display setting and is shared by all presets.";
13
+ readonly peSaveCopy: "Save new preset";
14
+ readonly peSaved: "Saved. Select this preset in a new conversation.";
15
+ readonly pmGlobalSettings: "Global settings";
16
+ readonly pmRefresh: "Refresh";
17
+ readonly pmBuiltIn: "Built-in";
18
+ readonly pmCustom: "Custom";
19
+ readonly pmDiscard: "Discard your unsaved changes?";
20
+ readonly pmConflict: "This preset changed in another page or on disk. Reopen the latest version before saving.";
21
+ readonly pmYamlError: "The configuration must be valid YAML. Your draft has not been saved.";
22
+ readonly pmErrorDetails: "Technical details";
23
+ readonly pmSaveError: "Could not complete this action. Your draft is still here.";
24
+ readonly pmName: "Name";
25
+ readonly pmDescription: "Description";
26
+ readonly pmCancel: "Cancel";
27
+ readonly pmSave: "Save changes";
28
+ };
29
+ export declare const presetZh: Record<keyof typeof presetEn, string>;
30
+ //# sourceMappingURL=preset-copy.d.ts.map
@@ -0,0 +1,57 @@
1
+ export const presetEn = {
2
+ peTitle: 'Preset editor',
3
+ peHierarchy: 'Codex mode and other presets are peers. Choose one to edit, or make an editable copy of a built-in preset first.',
4
+ peSelect: 'Preset',
5
+ peSelectPlaceholder: 'Choose a preset…',
6
+ peEditable: 'This is an editable user preset.',
7
+ peBuiltinEdit: 'Built-in presets are read-only. Create a copy to edit it.',
8
+ peCreateCopy: 'Create editable copy',
9
+ peCodexSection: 'Codex mode capabilities',
10
+ peAddCodex: 'Add Codex capabilities to this preset',
11
+ peAddCodexHint: 'Adds the Codex prompt, tools, hosted search, and remote compaction to this preset.',
12
+ peActivityGlobal: 'Activity status is a global display setting and is shared by all presets.',
13
+ peSaveCopy: 'Save new preset',
14
+ peSaved: 'Saved. Select this preset in a new conversation.',
15
+ pmGlobalSettings: 'Global settings',
16
+ pmRefresh: 'Refresh',
17
+ pmBuiltIn: 'Built-in',
18
+ pmCustom: 'Custom',
19
+ pmDiscard: 'Discard your unsaved changes?',
20
+ pmConflict: 'This preset changed in another page or on disk. Reopen the latest version before saving.',
21
+ pmYamlError: 'The configuration must be valid YAML. Your draft has not been saved.',
22
+ pmErrorDetails: 'Technical details',
23
+ pmSaveError: 'Could not complete this action. Your draft is still here.',
24
+ pmName: 'Name',
25
+ pmDescription: 'Description',
26
+ pmCancel: 'Cancel',
27
+ pmSave: 'Save changes',
28
+ };
29
+ export const presetZh = {
30
+ peTitle: '预设编辑',
31
+ peHierarchy: 'Codex 模式和其它预设处于同一级。选择一个预设编辑;内置预设先创建可编辑副本。',
32
+ peSelect: '选择预设',
33
+ peSelectPlaceholder: '选择一个预设…',
34
+ peEditable: '这是可编辑的用户预设。',
35
+ peBuiltinEdit: '内置预设只读,需要先创建副本。',
36
+ peCreateCopy: '创建可编辑副本',
37
+ peCodexSection: 'Codex 模式能力',
38
+ peAddCodex: '为这个预设加入 Codex 能力',
39
+ peAddCodexHint: '加入 Codex 提示词、工具、托管搜索和远程上下文压缩。',
40
+ peActivityGlobal: '活动状态是全局显示设置,由所有预设共享。',
41
+ peSaveCopy: '保存新预设',
42
+ peSaved: '已保存,在新会话中选择此预设即可使用。',
43
+ pmGlobalSettings: '全局设置',
44
+ pmRefresh: '刷新',
45
+ pmBuiltIn: '内置',
46
+ pmCustom: '自定义',
47
+ pmDiscard: '放弃尚未保存的修改?',
48
+ pmConflict: '此预设已被其他页面或文件修改,请重新打开最新版本后再保存。',
49
+ pmYamlError: '配置必须是有效 YAML,草稿尚未保存。',
50
+ pmErrorDetails: '技术详情',
51
+ pmSaveError: '操作未完成,填写的内容仍然保留。',
52
+ pmName: '名称',
53
+ pmDescription: '用途说明',
54
+ pmCancel: '取消',
55
+ pmSave: '保存修改',
56
+ };
57
+ //# sourceMappingURL=preset-copy.js.map
@@ -0,0 +1,22 @@
1
+ import type { InjectFace, PropsLocale } from '@deepseek-ai/dsh-client-ui-slots';
2
+ import type { RemoteResult, TypertClientRemote } from '@deepseek-ai/dsh-typert-protocol';
3
+ import type { PresetCatalog, PresetCreateInput, PresetEditorDocument, PresetEditorInput } from '../preset-contract.ts';
4
+ export interface PresetClientRemote extends TypertClientRemote {
5
+ codexPresetEditor: {
6
+ catalog(): Promise<RemoteResult<PresetCatalog>>;
7
+ read(id: string): Promise<RemoteResult<PresetEditorDocument>>;
8
+ update(input: PresetEditorInput): Promise<RemoteResult<PresetEditorDocument>>;
9
+ create(input: PresetCreateInput): Promise<RemoteResult<PresetEditorDocument>>;
10
+ };
11
+ }
12
+ export interface PresetManagerActions {
13
+ remote: PresetClientRemote;
14
+ ready: Promise<void>;
15
+ }
16
+ type Props = InjectFace<{
17
+ presetManager: PresetManagerActions;
18
+ }> & PropsLocale<'codex'>;
19
+ /** Presets are peers: choose one to edit, or make an editable copy first. */
20
+ export declare function PresetManagerCard({ presetManager, t }: Props): import("react").JSX.Element;
21
+ export default PresetManagerCard;
22
+ //# sourceMappingURL=preset-manager.d.ts.map
@@ -0,0 +1,156 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { useEffect, useRef, useState } from 'react';
3
+ const catalogCache = new WeakMap();
4
+ const CODEX_DEFAULT_ID = 'codex-collaboration';
5
+ function unwrap(result) {
6
+ if (result.ok)
7
+ return result.value;
8
+ throw new Error(result.error.message ?? 'remote-request-failed');
9
+ }
10
+ function equalEditorState(a, b) {
11
+ if (!a || !b)
12
+ return a === b;
13
+ return a.name === b.name && a.description === b.description && a.systemPrompt === b.systemPrompt
14
+ && a.inheritPrompt === b.inheritPrompt && a.codex === b.codex
15
+ && JSON.stringify(a.codexOptions) === JSON.stringify(b.codexOptions);
16
+ }
17
+ const styles = `
18
+ .codex-preset-editor { display:grid; gap:12px; min-width:0; font-size:13px; }
19
+ .codex-preset-editor label { display:grid; gap:6px; }
20
+ .codex-preset-editor .pe-row { display:flex; align-items:center; gap:10px; flex-wrap:wrap; }
21
+ .codex-preset-editor input:not([type=checkbox]), .codex-preset-editor textarea, .codex-preset-editor select { box-sizing:border-box; width:100%; padding:8px; border:1px solid var(--dsw-alias-border-l2); border-radius:6px; background:var(--dsw-alias-bg-layer-3); color:inherit; font:inherit; }
22
+ .codex-preset-editor textarea { resize:vertical; line-height:1.5; }
23
+ .codex-preset-editor button { font:inherit; padding:6px 12px; border:1px solid var(--dsw-alias-border-l2); border-radius:6px; background:var(--dsw-alias-bg-layer-3); color:inherit; cursor:pointer; }
24
+ .codex-preset-editor button:disabled { opacity:.5; cursor:default; }
25
+ .codex-preset-editor .pe-primary { background:#425ce5; border-color:#425ce5; color:white; }
26
+ .codex-preset-editor .pe-block { display:grid; gap:9px; padding-top:12px; border-top:1px solid var(--dsw-alias-border-l2); }
27
+ .codex-preset-editor .pe-toggle { display:flex; align-items:flex-start; gap:9px; }
28
+ .codex-preset-editor .pe-toggle span { display:grid; gap:2px; }
29
+ .codex-preset-editor p { margin:0; font-size:12px; line-height:1.55; color:var(--dsw-alias-label-tertiary); }
30
+ `;
31
+ function optionToggle(key, label, hint, options, setOptions, disabled) {
32
+ return _jsxs("label", { className: "pe-toggle", children: [_jsx("input", { type: "checkbox", checked: options[key], disabled: disabled, onChange: event => setOptions({ ...options, [key]: event.target.checked }) }), _jsxs("span", { children: [_jsx("strong", { children: label }), _jsx("small", { children: hint })] })] }, key);
33
+ }
34
+ /** Presets are peers: choose one to edit, or make an editable copy first. */
35
+ export function PresetManagerCard({ presetManager, t }) {
36
+ const [catalog, setCatalog] = useState(() => catalogCache.get(presetManager));
37
+ const [selectedId, setSelectedId] = useState('');
38
+ const [original, setOriginal] = useState();
39
+ const [draft, setDraft] = useState();
40
+ const [sourceId, setSourceId] = useState('');
41
+ const [copyMode, setCopyMode] = useState(false);
42
+ const [codexEnabled, setCodexEnabled] = useState(false);
43
+ const [busy, setBusy] = useState(false);
44
+ const [error, setError] = useState('');
45
+ const [notice, setNotice] = useState('');
46
+ const alive = useRef(true);
47
+ const remote = presetManager.remote.codexPresetEditor;
48
+ const dirty = !!draft && (!original || !equalEditorState(draft, original) || codexEnabled !== draft.codex);
49
+ async function run(work) {
50
+ setBusy(true);
51
+ setError('');
52
+ setNotice('');
53
+ try {
54
+ await presetManager.ready;
55
+ if (alive.current)
56
+ await work();
57
+ }
58
+ catch (cause) {
59
+ if (alive.current)
60
+ setError(cause instanceof Error ? cause.message : String(cause));
61
+ }
62
+ finally {
63
+ if (alive.current)
64
+ setBusy(false);
65
+ }
66
+ }
67
+ async function load(id, confirmDirty = true) {
68
+ if (!id)
69
+ return;
70
+ if (confirmDirty && dirty && !window.confirm(t('pmDiscard')))
71
+ return;
72
+ await run(async () => {
73
+ const value = unwrap(await remote.read(id));
74
+ if (!alive.current)
75
+ return;
76
+ setSelectedId(id);
77
+ setSourceId(id);
78
+ setOriginal(value);
79
+ setDraft(value);
80
+ setCopyMode(false);
81
+ setCodexEnabled(value.codex);
82
+ });
83
+ }
84
+ async function refresh() {
85
+ const value = unwrap(await remote.catalog());
86
+ if (!alive.current)
87
+ return;
88
+ catalogCache.set(presetManager, value);
89
+ setCatalog(value);
90
+ const current = selectedId || (value.presets.some(row => row.id === CODEX_DEFAULT_ID) ? CODEX_DEFAULT_ID : value.presets[0]?.id ?? '');
91
+ if (current && current !== selectedId)
92
+ await load(current, false);
93
+ }
94
+ useEffect(() => {
95
+ alive.current = true;
96
+ if (!catalogCache.has(presetManager))
97
+ void run(refresh);
98
+ else if (!selectedId)
99
+ void load(catalogCache.get(presetManager)?.presets.some(row => row.id === CODEX_DEFAULT_ID) ? CODEX_DEFAULT_ID : catalogCache.get(presetManager)?.presets[0]?.id ?? '', false);
100
+ return () => { alive.current = false; };
101
+ }, [presetManager]);
102
+ useEffect(() => {
103
+ if (!dirty)
104
+ return;
105
+ const guard = (event) => { event.preventDefault(); event.returnValue = ''; };
106
+ window.addEventListener('beforeunload', guard);
107
+ return () => window.removeEventListener('beforeunload', guard);
108
+ }, [dirty]);
109
+ function patch(value) { if (draft)
110
+ setDraft({ ...draft, ...value }); }
111
+ function beginCopy() {
112
+ if (!draft || !sourceId)
113
+ return;
114
+ if (dirty && !window.confirm(t('pmDiscard')))
115
+ return;
116
+ setCopyMode(true);
117
+ setCodexEnabled(draft.codex);
118
+ setOriginal({ ...draft });
119
+ setDraft({ ...draft, id: '', revision: '', editable: true, name: `${draft.name} · ${t('pmCustom')}` });
120
+ }
121
+ function save() {
122
+ if (!draft || busy || !draft.name.trim())
123
+ return;
124
+ void run(async () => {
125
+ const options = codexEnabled ? draft.codexOptions : undefined;
126
+ const payload = { name: draft.name, description: draft.description, systemPrompt: draft.systemPrompt,
127
+ inheritPrompt: draft.inheritPrompt, enableCodex: codexEnabled, ...(options === undefined ? {} : { codexOptions: options }) };
128
+ const value = unwrap(await (copyMode
129
+ ? remote.create({ ...payload, sourceId })
130
+ : remote.update({ ...payload, id: draft.id, revision: draft.revision })));
131
+ if (!alive.current)
132
+ return;
133
+ setSelectedId(value.id);
134
+ setSourceId(value.id);
135
+ setOriginal(value);
136
+ setDraft(value);
137
+ setCopyMode(false);
138
+ setCodexEnabled(value.codex);
139
+ setNotice(t('peSaved'));
140
+ if (catalog) {
141
+ const row = { id: value.id, name: value.name, description: value.description, editable: value.editable,
142
+ isDefault: catalog.presets.find(item => item.id === value.id)?.isDefault ?? false };
143
+ const presets = catalog.presets.some(item => item.id === value.id)
144
+ ? catalog.presets.map(item => item.id === value.id ? row : item) : [...catalog.presets, row];
145
+ catalogCache.set(presetManager, { ...catalog, presets });
146
+ setCatalog({ ...catalog, presets });
147
+ }
148
+ });
149
+ }
150
+ const selectedRow = catalog?.presets.find(row => row.id === selectedId);
151
+ const readOnly = !!draft && !draft.editable && !copyMode;
152
+ const options = draft?.codexOptions;
153
+ return _jsxs("section", { className: "codex-preset-editor", "aria-label": t('peTitle'), "aria-busy": busy, children: [_jsx("style", { children: styles }), _jsxs("div", { className: "pe-row", style: { justifyContent: 'space-between' }, children: [_jsx("strong", { children: t('peTitle') }), _jsx("button", { type: "button", disabled: busy, onClick: () => { void run(refresh); }, children: t('pmRefresh') })] }), _jsx("p", { children: t('peHierarchy') }), _jsxs("label", { children: [t('peSelect'), _jsxs("select", { value: selectedId, disabled: busy || !catalog, onChange: event => { void load(event.target.value); }, children: [_jsx("option", { value: "", children: t('peSelectPlaceholder') }), catalog?.presets.map(row => _jsxs("option", { value: row.id, children: [row.name, row.editable ? '' : ` · ${t('pmBuiltIn')}`] }, row.id))] })] }), selectedRow && _jsx("p", { children: selectedRow.editable ? t('peEditable') : t('peBuiltinEdit') }), error && _jsxs("div", { role: "alert", children: [_jsx("p", { children: error.includes('preset-conflict') ? t('pmConflict') : error.includes('invalid-preset-yaml') ? t('pmYamlError') : t('pmSaveError') }), _jsxs("details", { children: [_jsx("summary", { children: t('pmErrorDetails') }), _jsx("pre", { style: { whiteSpace: 'pre-wrap' }, children: error })] })] }), notice && _jsx("p", { role: "status", children: notice }), draft && _jsxs(_Fragment, { children: [_jsxs("label", { children: [t('pmName'), _jsx("input", { value: draft.name, maxLength: 200, disabled: busy || readOnly, onChange: event => patch({ name: event.target.value }) })] }), _jsxs("label", { children: [t('pmDescription'), _jsx("input", { value: draft.description, maxLength: 4000, disabled: busy || readOnly, onChange: event => patch({ description: event.target.value }) })] }), readOnly && _jsx("button", { type: "button", className: "pe-primary", disabled: busy || !catalog?.authorable, onClick: beginCopy, children: t('peCreateCopy') }), !readOnly && _jsxs(_Fragment, { children: [_jsxs("div", { className: "pe-block", children: [_jsx("strong", { children: t('peCodexSection') }), !draft.codex && _jsxs("label", { className: "pe-toggle", children: [_jsx("input", { type: "checkbox", checked: codexEnabled, disabled: busy, onChange: event => setCodexEnabled(event.target.checked) }), _jsxs("span", { children: [_jsx("strong", { children: t('peAddCodex') }), _jsx("small", { children: t('peAddCodexHint') })] })] }), codexEnabled && options && _jsxs(_Fragment, { children: [optionToggle('hostedWebSearchEnabled', t('capabilityWebSearch'), t('capabilityWebSearchHint'), options, next => patch({ codexOptions: next }), busy), optionToggle('remoteCompactionEnabled', t('capabilityCompaction'), t('capabilityCompactionHint'), options, next => patch({ codexOptions: next }), busy), optionToggle('terminalToolsEnabled', t('capabilityTerminal'), t('capabilityTerminalHint'), options, next => patch({ codexOptions: next }), busy), optionToggle('patchToolEnabled', t('capabilityPatch'), t('capabilityPatchHint'), options, next => patch({ codexOptions: next }), busy), optionToggle('planToolEnabled', t('capabilityPlan'), t('capabilityPlanHint'), options, next => patch({ codexOptions: next }), busy), optionToggle('promptEnabled', t('capabilityPrompt'), t('capabilityPromptHint'), options, next => patch({ codexOptions: next }), busy), options.promptEnabled && _jsxs("label", { children: [t('promptLabel'), _jsx("textarea", { rows: 10, value: draft.systemPrompt, disabled: busy, onChange: event => patch({ systemPrompt: event.target.value, inheritPrompt: false }) })] }), _jsx("p", { children: t('peActivityGlobal') })] })] }), _jsxs("div", { className: "pe-row", children: [_jsx("button", { type: "button", className: "pe-primary", disabled: busy || !catalog?.authorable || !draft.name.trim() || !dirty, onClick: save, children: copyMode ? t('peSaveCopy') : t('pmSave') }), copyMode && _jsx("button", { type: "button", disabled: busy, onClick: () => { void load(sourceId, false); }, children: t('pmCancel') }), !copyMode && _jsx("button", { type: "button", disabled: busy, onClick: () => { void load(draft.id, false); }, children: t('pmCancel') })] })] })] })] });
154
+ }
155
+ export default PresetManagerCard;
156
+ //# sourceMappingURL=preset-manager.js.map