@shuind/dsh-codex-harness 0.2.21 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (200) hide show
  1. package/CHANGELOG.md +185 -0
  2. package/README.md +38 -50
  3. package/RELEASE.md +61 -0
  4. package/assets/codex.svg +5 -0
  5. package/cordis.patch.yml +181 -6
  6. package/docs/preset-library.md +33 -23
  7. package/docs/tool-policy-benchmark.json +310 -0
  8. package/docs/tool-policy.md +148 -0
  9. package/lib/client.js +4774 -2416
  10. package/lib/compact-command.js +416 -0
  11. package/lib/compaction.js +141 -12
  12. package/lib/hybrid-executor.js +1196 -0
  13. package/lib/index.js +3658 -2334
  14. package/lib/preferences.js +117 -0
  15. package/lib/tool-policy.js +2422 -0
  16. package/lib/typert.js +86 -79
  17. package/lib/types/client/activity.d.ts +33 -9
  18. package/lib/types/client/activity.js +4 -3
  19. package/lib/types/client/desktop.d.ts +67 -0
  20. package/lib/types/client/desktop.js +229 -0
  21. package/lib/types/client/index.d.ts +207 -110
  22. package/lib/types/client/index.js +99 -492
  23. package/lib/types/client/policy-drafts.d.ts +25 -0
  24. package/lib/types/client/policy-drafts.js +47 -0
  25. package/lib/types/client/policy-locale.d.ts +260 -0
  26. package/lib/types/client/policy-locale.js +357 -0
  27. package/lib/types/client/preset-manager.d.ts +38 -10
  28. package/lib/types/client/preset-manager.js +235 -185
  29. package/lib/types/client/preset-requests.d.ts +12 -0
  30. package/lib/types/client/preset-requests.js +101 -0
  31. package/lib/types/client/tool-policy.d.ts +33 -0
  32. package/lib/types/client/tool-policy.js +336 -0
  33. package/lib/types/contracts/preset-editor-schema.d.ts +78 -0
  34. package/lib/types/contracts/preset-editor-schema.js +95 -0
  35. package/lib/types/{prompt.js → contracts/prompt.js} +13 -7
  36. package/lib/types/{settings.d.ts → contracts/settings.d.ts} +11 -4
  37. package/lib/types/{settings.js → contracts/settings.js} +22 -6
  38. package/lib/types/contracts/tool-policy-contract.d.ts +63 -0
  39. package/lib/types/contracts/tool-policy-contract.js +33 -0
  40. package/lib/types/contracts/ui-contracts.d.ts +92 -0
  41. package/lib/types/contracts/ui-contracts.js +83 -0
  42. package/lib/types/entries/client.d.ts +10 -0
  43. package/lib/types/entries/client.js +10 -0
  44. package/lib/types/{compact-command.d.ts → entries/compact-command.d.ts} +2 -0
  45. package/lib/types/entries/compact-command.js +176 -0
  46. package/lib/types/{compaction.d.ts → entries/compaction.d.ts} +15 -3
  47. package/lib/types/{compaction.js → entries/compaction.js} +47 -11
  48. package/lib/types/entries/hybrid-executor.d.ts +19 -0
  49. package/lib/types/entries/hybrid-executor.js +57 -0
  50. package/lib/types/entries/index.d.ts +66 -0
  51. package/lib/types/entries/index.js +192 -0
  52. package/lib/types/entries/preferences.d.ts +11 -0
  53. package/lib/types/entries/preferences.js +16 -0
  54. package/lib/types/entries/tool-policy.d.ts +97 -0
  55. package/lib/types/entries/tool-policy.js +158 -0
  56. package/lib/types/entries/typert.host.d.ts +23 -0
  57. package/lib/types/entries/typert.host.js +24 -0
  58. package/lib/types/hybrid/codex-hybrid-executor.d.ts +44 -0
  59. package/lib/types/hybrid/codex-hybrid-executor.js +257 -0
  60. package/lib/types/hybrid/hybrid-sdk.d.ts +13 -0
  61. package/lib/types/hybrid/hybrid-sdk.js +196 -0
  62. package/lib/types/hybrid/program-calls.d.ts +28 -0
  63. package/lib/types/hybrid/program-calls.js +193 -0
  64. package/lib/types/hybrid/subcall-scheduler.d.ts +90 -0
  65. package/lib/types/hybrid/subcall-scheduler.js +343 -0
  66. package/lib/types/policy/deferred-tools.d.ts +42 -0
  67. package/lib/types/policy/deferred-tools.js +264 -0
  68. package/lib/types/policy/overlay-installer.d.ts +12 -0
  69. package/lib/types/policy/overlay-installer.js +179 -0
  70. package/lib/types/policy/rule-resolver.d.ts +94 -0
  71. package/lib/types/policy/rule-resolver.js +114 -0
  72. package/lib/types/policy/tool-capabilities.d.ts +33 -0
  73. package/lib/types/policy/tool-capabilities.js +46 -0
  74. package/lib/types/{activity.d.ts → presets/activity.d.ts} +3 -5
  75. package/lib/types/{activity.js → presets/activity.js} +51 -27
  76. package/lib/types/presets/desktop-preset.d.ts +22 -0
  77. package/lib/types/presets/desktop-preset.js +43 -0
  78. package/lib/types/presets/preset-editor.d.ts +47 -0
  79. package/lib/types/presets/preset-editor.js +81 -0
  80. package/lib/types/presets/preset-prompt-catalog.d.ts +23 -0
  81. package/lib/types/presets/preset-prompt-catalog.js +215 -0
  82. package/lib/types/presets/preset-tool-catalog.d.ts +5 -0
  83. package/lib/types/presets/preset-tool-catalog.js +58 -0
  84. package/lib/types/presets/runtime-enhancements.d.ts +45 -0
  85. package/lib/types/presets/runtime-enhancements.js +349 -0
  86. package/lib/types/presets/small-window-compaction.d.ts +15 -0
  87. package/lib/types/presets/small-window-compaction.js +121 -0
  88. package/lib/types/responses/compact-checkpoint.d.ts +27 -0
  89. package/lib/types/responses/compact-checkpoint.js +257 -0
  90. package/lib/types/responses/fetch-transport.d.ts +16 -0
  91. package/lib/types/responses/fetch-transport.js +257 -0
  92. package/lib/types/responses/remote-compact.d.ts +13 -0
  93. package/lib/types/responses/remote-compact.js +319 -0
  94. package/lib/types/responses/sse-diagnostics.d.ts +9 -0
  95. package/lib/types/responses/sse-diagnostics.js +157 -0
  96. package/lib/types/responses/wire-rewrite.d.ts +35 -0
  97. package/lib/types/responses/wire-rewrite.js +237 -0
  98. package/lib/types/tools/exec-output.d.ts +58 -0
  99. package/lib/types/tools/exec-output.js +173 -0
  100. package/lib/types/tools/exec-plan-tools.d.ts +37 -0
  101. package/lib/types/tools/exec-plan-tools.js +265 -0
  102. package/lib/types/tools/exec-runner.d.ts +21 -0
  103. package/lib/types/tools/exec-runner.js +385 -0
  104. package/lib/types/tools/patch-tool.d.ts +16 -0
  105. package/lib/types/tools/patch-tool.js +258 -0
  106. package/lib/types/{patch.d.ts → tools/patch.d.ts} +1 -1
  107. package/lib/types/{patch.js → tools/patch.js} +96 -21
  108. package/locale/en.json +6 -0
  109. package/locale/hybrid-executor/en.json +6 -0
  110. package/locale/hybrid-executor/zh.json +6 -0
  111. package/locale/tool-policy/en.json +6 -0
  112. package/locale/tool-policy/zh.json +6 -0
  113. package/locale/zh.json +6 -0
  114. package/package.json +297 -299
  115. package/presets/{codex-collaboration → codex-hybrid}/agent.cordis.yml +45 -48
  116. package/presets/codex-hybrid/preset.yml +3 -0
  117. package/scripts/benchmark-tool-policy.mjs +186 -0
  118. package/scripts/build-preset.mjs +19 -0
  119. package/scripts/clean-build.mjs +11 -0
  120. package/src/client/activity.ts +83 -0
  121. package/src/client/desktop.tsx +276 -0
  122. package/src/client/index.tsx +391 -0
  123. package/src/client/policy-drafts.ts +56 -0
  124. package/src/client/policy-locale.ts +362 -0
  125. package/src/client/preset-manager.tsx +376 -0
  126. package/src/client/preset-requests.ts +113 -0
  127. package/src/client/tool-policy.tsx +402 -0
  128. package/src/contracts/preset-editor-schema.ts +110 -0
  129. package/src/contracts/prompt.ts +66 -0
  130. package/src/contracts/settings.ts +103 -0
  131. package/src/contracts/tool-policy-contract.ts +93 -0
  132. package/src/contracts/ui-contracts.ts +173 -0
  133. package/src/entries/client.tsx +14 -0
  134. package/src/entries/compact-command.ts +256 -0
  135. package/src/entries/compaction.ts +218 -0
  136. package/src/entries/hybrid-executor.ts +76 -0
  137. package/src/entries/index.ts +298 -0
  138. package/src/entries/preferences.ts +17 -0
  139. package/src/entries/tool-policy.ts +162 -0
  140. package/src/entries/typert.host.ts +29 -0
  141. package/src/hybrid/codex-hybrid-executor.ts +310 -0
  142. package/src/hybrid/hybrid-sdk.ts +217 -0
  143. package/src/hybrid/program-calls.ts +202 -0
  144. package/src/hybrid/subcall-scheduler.ts +446 -0
  145. package/src/policy/deferred-tools.ts +331 -0
  146. package/src/policy/overlay-installer.ts +191 -0
  147. package/src/policy/rule-resolver.ts +128 -0
  148. package/src/policy/tool-capabilities.ts +88 -0
  149. package/src/presets/activity.ts +146 -0
  150. package/src/presets/desktop-preset.ts +60 -0
  151. package/src/presets/preset-editor.ts +101 -0
  152. package/src/presets/preset-prompt-catalog.ts +221 -0
  153. package/src/presets/preset-tool-catalog.ts +58 -0
  154. package/src/presets/runtime-enhancements.ts +415 -0
  155. package/src/presets/small-window-compaction.ts +166 -0
  156. package/src/responses/compact-checkpoint.ts +264 -0
  157. package/src/responses/fetch-transport.ts +290 -0
  158. package/src/responses/remote-compact.ts +393 -0
  159. package/src/responses/sse-diagnostics.ts +156 -0
  160. package/src/responses/wire-rewrite.ts +261 -0
  161. package/src/tools/exec-output.ts +211 -0
  162. package/src/tools/exec-plan-tools.ts +307 -0
  163. package/src/tools/exec-runner.ts +445 -0
  164. package/src/tools/patch-tool.ts +331 -0
  165. package/src/tools/patch.ts +328 -0
  166. package/tsconfig.json +29 -0
  167. package/tsdown.config.ts +110 -0
  168. package/lib/installer.js +0 -237
  169. package/lib/invariant.js +0 -23
  170. package/lib/types/activity-types.d.ts +0 -6
  171. package/lib/types/activity-types.js +0 -3
  172. package/lib/types/client/preset-copy.d.ts +0 -42
  173. package/lib/types/client/preset-copy.js +0 -81
  174. package/lib/types/compact-command.js +0 -79
  175. package/lib/types/context.d.ts +0 -8
  176. package/lib/types/context.js +0 -14
  177. package/lib/types/exec.d.ts +0 -46
  178. package/lib/types/exec.js +0 -365
  179. package/lib/types/index.d.ts +0 -95
  180. package/lib/types/index.js +0 -738
  181. package/lib/types/installer.d.ts +0 -27
  182. package/lib/types/installer.js +0 -146
  183. package/lib/types/invariant.d.ts +0 -16
  184. package/lib/types/invariant.js +0 -22
  185. package/lib/types/preset-contract.d.ts +0 -69
  186. package/lib/types/preset-contract.js +0 -22
  187. package/lib/types/preset-editor-remote.d.ts +0 -30
  188. package/lib/types/preset-editor-remote.js +0 -37
  189. package/lib/types/preset-editor.d.ts +0 -69
  190. package/lib/types/preset-editor.js +0 -557
  191. package/lib/types/preset-templates.d.ts +0 -36
  192. package/lib/types/preset-templates.js +0 -12
  193. package/lib/types/prompt-sections.d.ts +0 -15
  194. package/lib/types/prompt-sections.js +0 -23
  195. package/lib/types/remote.d.ts +0 -40
  196. package/lib/types/remote.js +0 -683
  197. package/lib/types/typert.host.d.ts +0 -47
  198. package/lib/types/typert.host.js +0 -99
  199. package/presets/codex-collaboration/preset.yml +0 -3
  200. /package/lib/types/{prompt.d.ts → contracts/prompt.d.ts} +0 -0
@@ -0,0 +1,336 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ /** Unified preset plan editor: 1-click segmented tool actions, prompt overrides, and YAML inspector. */
3
+ import { useEffect, useRef, useState, useSyncExternalStore } from 'react';
4
+ import { PresetDefinitionCard } from "./preset-manager.js";
5
+ import { cachedPresetCatalog, cachedPresetPrompts, cachedPresetTools, requestPresetCatalog, requestPresetPrompts, requestPresetTools, } from "./preset-requests.js";
6
+ import { effectiveToolAction, legacyToolAction } from "../contracts/tool-policy-contract.js";
7
+ import { PRESET_PROMPT_NAMES } from "../contracts/ui-contracts.js";
8
+ import { acceptPresetSave, editPresetDraft, preparePresetSave, presetRules, sameRules } from "./policy-drafts.js";
9
+ import { groupOf, humanLabels, policyStyles, toolPolicyEn, toolPolicyZh } from "./policy-locale.js";
10
+ export { toolPolicyEn, toolPolicyZh };
11
+ export const TOOL_POLICY_NAMESPACE = 'codex-tool-policy';
12
+ export function bindToolPolicy(ctx, forms) {
13
+ let form;
14
+ const listeners = new Set();
15
+ const publish = (next) => {
16
+ form = next;
17
+ for (const listener of [...listeners])
18
+ listener();
19
+ };
20
+ ctx.effect(() => forms.whileServed([TOOL_POLICY_NAMESPACE], () => {
21
+ publish(forms.get(TOOL_POLICY_NAMESPACE));
22
+ return () => publish(undefined);
23
+ }), 'codex client: tool-policy availability');
24
+ return {
25
+ getSnapshot: () => form,
26
+ subscribe: listener => { listeners.add(listener); return () => { listeners.delete(listener); }; },
27
+ };
28
+ }
29
+ export function validateToolPolicyRules(rules) {
30
+ const ids = new Set();
31
+ for (const rule of rules) {
32
+ const id = rule.preset.trim();
33
+ if (!id)
34
+ return 'toolPolicyInvalidPreset';
35
+ if (ids.has(id))
36
+ return 'toolPolicyDuplicatePreset';
37
+ ids.add(id);
38
+ }
39
+ return undefined;
40
+ }
41
+ export function withToolAction(rule, name, action, context = {}) {
42
+ const next = { ...rule };
43
+ const tools = [...(rule.tools ?? [])].filter(tool => tool.name !== name);
44
+ if (action !== legacyToolAction(rule, name, context))
45
+ tools.push({ name, action });
46
+ if (tools.length)
47
+ next.tools = tools;
48
+ else
49
+ delete next.tools;
50
+ return next;
51
+ }
52
+ export function saveToolPolicy(form, rules, revision) {
53
+ const value = rules.map(rule => {
54
+ const row = { preset: rule.preset };
55
+ if (rule.allow !== undefined)
56
+ row.allow = [...rule.allow];
57
+ if (rule.deny !== undefined)
58
+ row.deny = [...rule.deny];
59
+ if (rule.replaceShell !== undefined)
60
+ row.replaceShell = rule.replaceShell;
61
+ if (rule.replacePlan !== undefined)
62
+ row.replacePlan = rule.replacePlan;
63
+ if (rule.replacePatch !== undefined)
64
+ row.replacePatch = rule.replacePatch;
65
+ if (rule.tools !== undefined)
66
+ row.tools = rule.tools.map(tool => ({ ...tool }));
67
+ if (rule.promptOverrides !== undefined)
68
+ row.promptOverrides = rule.promptOverrides.map(override => ({ name: override.name, text: override.text }));
69
+ return row;
70
+ });
71
+ return form.mutate([{ op: 'set', path: ['rules'], value }], revision);
72
+ }
73
+ const isPromptName = (name) => PRESET_PROMPT_NAMES.includes(name);
74
+ const GROUP_META = [
75
+ { id: 'command', labelKey: 'toolPolicyCommandGroup' },
76
+ { id: 'file', labelKey: 'toolPolicyFileGroup' },
77
+ { id: 'plan', labelKey: 'toolPolicyPlanGroup' },
78
+ { id: 'collab', labelKey: 'toolPolicyCollabGroup' },
79
+ { id: 'other', labelKey: 'toolPolicyOtherGroup' },
80
+ ];
81
+ export function ToolPolicySection({ binding, ...props }) {
82
+ const form = useSyncExternalStore(binding.subscribe, binding.getSnapshot, binding.getSnapshot);
83
+ return form === undefined ? null : _jsx(ToolPolicySettingsCard, { form: form, ...props });
84
+ }
85
+ export function ToolPolicySettingsCard({ form, presetManager, mode = 'tools', t }) {
86
+ const snapshot = useSyncExternalStore(listener => form.subscribe(listener), () => form.getSnapshot(), () => form.getSnapshot());
87
+ const [subMode, setSubMode] = useState(mode === 'prompts' || mode === 'definition' ? mode : 'tools');
88
+ const prevMode = useRef(mode);
89
+ const modeChanged = prevMode.current !== mode;
90
+ prevMode.current = mode;
91
+ const activeSub = modeChanged && (mode === 'tools' || mode === 'prompts' || mode === 'definition') ? mode : subMode;
92
+ const [drafts, setDrafts] = useState(() => new Map());
93
+ const [saving, setSaving] = useState(false);
94
+ const [error, setError] = useState('');
95
+ const [notice, setNotice] = useState('');
96
+ const [selection, setSelection] = useState();
97
+ const [query, setQuery] = useState('');
98
+ const [filter, setFilter] = useState('all');
99
+ const [groupOpen, setGroupOpen] = useState(() => new Map());
100
+ const [toolsView, setToolsView] = useState();
101
+ const [promptsView, setPromptsView] = useState();
102
+ const alive = useRef(true);
103
+ const catalogRequest = useRef(0);
104
+ const toolsRequest = useRef(0);
105
+ const promptsRequest = useRef(0);
106
+ const [catalog, setCatalog] = useState(() => presetManager === undefined ? undefined : cachedPresetCatalog(presetManager));
107
+ const [catalogState, setCatalogState] = useState(() => catalog ? 'ready' : presetManager ? 'loading' : 'error');
108
+ useEffect(() => {
109
+ if (subMode !== activeSub)
110
+ setSubMode(activeSub);
111
+ }, [activeSub]);
112
+ function loadCatalog(refresh = false) {
113
+ const ticket = ++catalogRequest.current;
114
+ if (presetManager === undefined) {
115
+ setCatalogState('error');
116
+ return;
117
+ }
118
+ setCatalogState('loading');
119
+ void requestPresetCatalog(presetManager, refresh).then(value => {
120
+ if (alive.current && ticket === catalogRequest.current) {
121
+ setCatalog(value);
122
+ setCatalogState('ready');
123
+ }
124
+ }).catch(() => { if (alive.current && ticket === catalogRequest.current)
125
+ setCatalogState('error'); });
126
+ }
127
+ useEffect(() => { alive.current = true; loadCatalog(); return () => { alive.current = false; catalogRequest.current++; toolsRequest.current++; promptsRequest.current++; }; }, [presetManager]);
128
+ const acceptedRules = snapshot.value?.rules ?? [];
129
+ const ids = [...new Set([...(catalog?.presets.map(preset => preset.id) ?? []), ...acceptedRules.map(rule => rule.preset), ...drafts.keys()])].filter(id => id.trim());
130
+ const selectedId = selection ?? ids[0] ?? '';
131
+ const currentDraft = drafts.get(selectedId);
132
+ const currentRules = currentDraft?.rules ?? presetRules(acceptedRules, selectedId);
133
+ const rule = currentRules[0];
134
+ const duplicate = currentRules.length > 1;
135
+ const presetLabel = catalog?.presets.find(preset => preset.id === selectedId)?.name ?? selectedId;
136
+ function loadTools(refresh = false) {
137
+ const ticket = ++toolsRequest.current;
138
+ if (!selectedId || presetManager === undefined) {
139
+ setToolsView({ preset: selectedId, status: 'error' });
140
+ return;
141
+ }
142
+ setToolsView({ preset: selectedId, status: 'loading' });
143
+ void requestPresetTools(presetManager, selectedId, refresh).then(value => {
144
+ if (alive.current && ticket === toolsRequest.current)
145
+ setToolsView({ preset: selectedId, status: 'ready', value });
146
+ }).catch(() => { if (alive.current && ticket === toolsRequest.current)
147
+ setToolsView({ preset: selectedId, status: 'error' }); });
148
+ }
149
+ useEffect(() => { loadTools(); return () => { toolsRequest.current++; }; }, [presetManager, selectedId]);
150
+ const cached = presetManager && selectedId ? cachedPresetTools(presetManager, selectedId) : undefined;
151
+ const inventory = toolsView?.preset === selectedId && toolsView.status === 'error' ? undefined : toolsView?.preset === selectedId && toolsView.status === 'ready' ? toolsView.value : cached;
152
+ const toolsStatus = inventory ? 'ready' : toolsView?.preset === selectedId ? toolsView.status : selectedId ? 'loading' : 'error';
153
+ function loadPrompts(refresh = false) {
154
+ const ticket = ++promptsRequest.current;
155
+ if (!selectedId || presetManager === undefined) {
156
+ setPromptsView({ preset: selectedId, status: 'error' });
157
+ return;
158
+ }
159
+ setPromptsView({ preset: selectedId, status: 'loading' });
160
+ void requestPresetPrompts(presetManager, selectedId, refresh).then(value => {
161
+ if (alive.current && ticket === promptsRequest.current)
162
+ setPromptsView({ preset: selectedId, status: 'ready', value });
163
+ }).catch(() => { if (alive.current && ticket === promptsRequest.current)
164
+ setPromptsView({ preset: selectedId, status: 'error' }); });
165
+ }
166
+ useEffect(() => {
167
+ if (activeSub === 'prompts')
168
+ loadPrompts();
169
+ return () => { promptsRequest.current++; };
170
+ }, [presetManager, selectedId, activeSub === 'prompts']);
171
+ const cachedPrompts = presetManager && selectedId ? cachedPresetPrompts(presetManager, selectedId) : undefined;
172
+ const promptCatalog = promptsView?.preset === selectedId && promptsView.status === 'error' ? undefined
173
+ : promptsView?.preset === selectedId && promptsView.status === 'ready' ? promptsView.value : cachedPrompts;
174
+ const promptsStatus = promptCatalog ? 'ready' : promptsView?.preset === selectedId ? promptsView.status : selectedId ? 'loading' : 'error';
175
+ const inventoryNames = new Set(inventory?.tools.map(tool => tool.name) ?? []);
176
+ const contextFor = (tool) => ({
177
+ ...(inventory?.legacyCapabilities === undefined ? {} : { legacyCapabilities: inventory.legacyCapabilities }),
178
+ ...(tool.codexTool === undefined ? {} : { codexTool: tool.codexTool }),
179
+ ...(tool.defaultDeferred === true ? { defaultDeferred: true } : {}),
180
+ });
181
+ const deferUnavailableReason = (tool) => tool.conditional ? 'conditional' : (tool.name === 'activate_tools' || inventoryNames.has('activate_tools')) ? 'target-exists' : undefined;
182
+ const chosen = (tool) => effectiveToolAction(rule, tool.name, contextFor(tool));
183
+ const customized = (tool) => chosen(tool) !== effectiveToolAction(undefined, tool.name, contextFor(tool)) || !!rule?.tools?.some(choice => choice.name === tool.name);
184
+ const stage = (change) => {
185
+ if (snapshot.status !== 'ready' || !snapshot.writable || saving)
186
+ return;
187
+ const latest = form.getSnapshot();
188
+ setError('');
189
+ setNotice('');
190
+ setDrafts(previous => editPresetDraft(previous, selectedId, { revision: latest.revision, rules: latest.value?.rules ?? [] }, change));
191
+ };
192
+ const editRule = (change) => stage(previous => {
193
+ const base = previous[0] ?? { preset: selectedId, replaceShell: false, replacePlan: false };
194
+ const next = change(base);
195
+ const neutralNew = presetRules(currentDraft?.baseline ?? acceptedRules, selectedId).length === 0 && !next.tools?.length && !next.promptOverrides?.length && next.allow === undefined && !next.deny?.length && next.replaceShell === false && next.replacePlan === false && !next.replacePatch;
196
+ if (neutralNew)
197
+ return [];
198
+ return previous.length === 0 ? [next] : previous.map((value, position) => position === 0 ? next : value);
199
+ });
200
+ const chooseAction = (tool, action) => {
201
+ if (duplicate || !selectedId || (action !== 'keep' && action !== 'hide' && action !== 'defer' && action !== 'codex-exec' && action !== 'codex-plan' && action !== 'codex-patch'))
202
+ return;
203
+ if (action === 'defer' && deferUnavailableReason(tool) !== undefined)
204
+ return;
205
+ if (action !== 'keep' && action !== 'hide' && action !== 'defer' && !tool.replacements.some(replacement => replacement.action === action && replacement.available))
206
+ return;
207
+ const context = contextFor(tool);
208
+ if (rule === undefined && action === legacyToolAction(undefined, tool.name, context))
209
+ return;
210
+ editRule(value => withToolAction(value, tool.name, action, context));
211
+ };
212
+ const removeChoice = (name) => editRule(value => {
213
+ const next = { ...value };
214
+ const tools = (value.tools ?? []).filter(choice => choice.name !== name);
215
+ if (tools.length)
216
+ next.tools = tools;
217
+ else
218
+ delete next.tools;
219
+ return next;
220
+ });
221
+ const changePrompt = (section, text) => {
222
+ if (duplicate || !section.editable || !isPromptName(section.name) || promptCatalog?.preset !== selectedId)
223
+ return;
224
+ const name = section.name;
225
+ editRule(value => ({ ...value, promptOverrides: [...(value.promptOverrides ?? []).filter(entry => entry.name !== name), { name, text }] }));
226
+ };
227
+ const restorePrompt = (section) => {
228
+ if (duplicate || !section.editable || !isPromptName(section.name) || promptCatalog?.preset !== selectedId)
229
+ return;
230
+ editRule(value => {
231
+ const next = { ...value };
232
+ const remaining = (value.promptOverrides ?? []).filter(entry => entry.name !== section.name);
233
+ if (remaining.length)
234
+ next.promptOverrides = remaining;
235
+ else
236
+ delete next.promptOverrides;
237
+ return next;
238
+ });
239
+ };
240
+ const saveCurrent = () => {
241
+ if (!currentDraft || saving || !snapshot.writable || snapshot.status !== 'ready')
242
+ return;
243
+ const latest = form.getSnapshot();
244
+ const target = selectedId;
245
+ const targetName = presetLabel && presetLabel !== target ? `${presetLabel} (${target})` : target || t('toolPolicyInvalidEntry');
246
+ const message = (key) => `${targetName}: ${t(key)}`;
247
+ let prepared;
248
+ try {
249
+ prepared = preparePresetSave(currentDraft, { revision: latest.revision, rules: latest.value?.rules ?? [] });
250
+ const invalid = validateToolPolicyRules(currentDraft.rules);
251
+ const otherIds = new Set((latest.value?.rules ?? []).filter(value => value.preset !== selectedId).map(value => value.preset.trim()));
252
+ if (invalid || currentDraft.rules.some(value => otherIds.has(value.preset.trim()))) {
253
+ setError(message(invalid ?? 'toolPolicyDuplicatePreset'));
254
+ return;
255
+ }
256
+ }
257
+ catch {
258
+ setError(message('toolPolicyRefused'));
259
+ return;
260
+ }
261
+ setSaving(true);
262
+ setError('');
263
+ setNotice('');
264
+ void saveToolPolicy(form, prepared.rules, prepared.revision).then(accepted => {
265
+ if (!alive.current)
266
+ return;
267
+ if (!accepted) {
268
+ setError(message('toolPolicyRefused'));
269
+ return;
270
+ }
271
+ const after = form.getSnapshot();
272
+ setDrafts(previous => acceptPresetSave(previous, prepared, { revision: after.revision, rules: after.value?.rules ?? [] }));
273
+ setNotice(message('toolPolicySaved'));
274
+ }).catch(() => { if (alive.current)
275
+ setError(message('toolPolicyFailed')); }).finally(() => { if (alive.current)
276
+ setSaving(false); });
277
+ };
278
+ const human = (tool) => {
279
+ const key = humanLabels[tool.name];
280
+ if (key !== undefined)
281
+ return t(key);
282
+ const mcp = /^mcp__([^_]+(?:_[^_]+)*)__(.+)$/.exec(tool.name);
283
+ if (mcp !== null)
284
+ return `${t('toolLabelMcpDynamic')} (${mcp[1]} · ${mcp[2]})`;
285
+ return tool.description.split(/[\n。.!]/u)[0]?.trim() || t('toolLabelOther');
286
+ };
287
+ const beforeTarget = currentDraft ? presetRules(currentDraft.baseline, selectedId) : [];
288
+ const beforeRule = beforeTarget[0];
289
+ const choiceFor = (value, name) => value?.tools?.find(choice => choice.name === name);
290
+ const changedNames = currentDraft ? [...new Set([
291
+ ...(inventory?.tools.filter(tool => effectiveToolAction(beforeRule, tool.name, contextFor(tool)) !== chosen(tool)
292
+ || JSON.stringify(choiceFor(beforeRule, tool.name)) !== JSON.stringify(choiceFor(rule, tool.name))).map(tool => tool.name) ?? []),
293
+ ...[...(beforeRule?.tools ?? []), ...(rule?.tools ?? [])].filter(choice => !inventoryNames.has(choice.name)
294
+ && JSON.stringify(choiceFor(beforeRule, choice.name)) !== JSON.stringify(choiceFor(rule, choice.name))).map(choice => choice.name),
295
+ ])] : [];
296
+ const changedPrompts = currentDraft ? [...new Set([...(beforeRule?.promptOverrides ?? []), ...(rule?.promptOverrides ?? [])].map(entry => entry.name))]
297
+ .filter(name => JSON.stringify(beforeRule?.promptOverrides?.find(entry => entry.name === name)) !== JSON.stringify(rule?.promptOverrides?.find(entry => entry.name === name))) : [];
298
+ const summaryParts = [
299
+ ...(changedNames.length ? [`${t('presetSummaryTools')}: ${changedNames.slice(0, 4).join(', ')}${changedNames.length > 4 ? ` (+${changedNames.length - 4})` : ''}`] : []),
300
+ ...(changedPrompts.length ? [`${t('presetSummaryPrompts')}: ${changedPrompts.map(name => promptCatalog?.sections.find(section => section.name === name)?.label || name).join(', ')}`] : []),
301
+ ];
302
+ const changeSummary = summaryParts.join(' · ') || t(currentDraft && !sameRules(beforeTarget, currentDraft.rules) ? 'toolPolicyRuleChanged' : 'toolPolicyNoToolDelta');
303
+ const unavailable = (reason) => t(reason === 'conditional' ? 'toolPolicyConditional' : reason === 'target-exists' ? 'toolPolicyTargetExists' : 'toolPolicyUnsupported');
304
+ const renderRows = (tools) => _jsxs("div", { className: "codex-tool-policy-table", role: "table", "aria-label": t('toolPolicyTitle'), children: [tools.map(tool => {
305
+ const action = chosen(tool);
306
+ const deferReason = deferUnavailableReason(tool);
307
+ const supported = action === 'keep' || action === 'hide' || action === 'defer' || tool.replacements.some(option => option.action === action);
308
+ const custom = customized(tool);
309
+ const hasOverride = !!rule?.tools?.some(choice => choice.name === tool.name);
310
+ return _jsxs("div", { role: "row", className: "codex-tool-policy-tool", "data-tool-name": tool.name, "data-tool-action": action, children: [_jsxs("div", { role: "cell", className: "codex-tool-policy-name", children: [_jsx("code", { className: "codex-tool-policy-identifier", children: tool.name }), _jsx("span", { className: "codex-tool-policy-description", title: tool.description, children: human(tool) }), tool.defaultDeferred && !custom && _jsx("span", { className: "codex-badge", "data-tone": "blue", children: t('toolPolicyDefaultDeferred') }), custom && _jsx("span", { className: "codex-badge", "data-tone": "blue", children: t('toolPolicyModified') }), tool.codexTool?.presetEnabled === false && _jsx("span", { className: "codex-badge", "data-tone": "warn", children: t('toolPolicyPresetDisabled') }), tool.conditional && tool.codexTool === undefined && _jsx("span", { className: "codex-badge", children: t('toolPolicyConditional') })] }), _jsxs("div", { role: "cell", className: "codex-tool-policy-action", children: [_jsxs("div", { className: "codex-seg", role: "group", "aria-label": `${t('toolPolicyAction')} ${tool.name}`, children: [_jsx("button", { type: "button", "data-action": "keep", "aria-pressed": action === 'keep', disabled: duplicate, onClick: () => chooseAction(tool, 'keep'), children: t('toolPolicyKeep') }), tool.replacements.map(option => _jsx("button", { type: "button", "data-action": option.action, "aria-pressed": action === option.action, disabled: duplicate || !option.available, title: option.available ? option.tools.join(' + ') : `${option.tools.join(' + ')} · ${unavailable(option.reason)}`, onClick: () => chooseAction(tool, option.action), children: t('toolPolicyReplaceShort') }, option.action)), _jsx("button", { type: "button", "data-action": "defer", "aria-pressed": action === 'defer', disabled: duplicate || deferReason !== undefined, title: deferReason !== undefined ? unavailable(deferReason) : t('toolPolicyDeferHint'), onClick: () => chooseAction(tool, 'defer'), children: t('toolPolicyDefer') }), _jsx("button", { type: "button", "data-action": "hide", "aria-pressed": action === 'hide', disabled: duplicate, onClick: () => chooseAction(tool, 'hide'), children: t('toolPolicyHide') })] }), !supported && _jsxs("span", { className: "codex-tool-policy-warning", children: [t('toolPolicyUnsupported'), " (", action, ")"] }), hasOverride && _jsx("button", { type: "button", className: "codex-btn", "aria-label": `${t('toolPolicyRestoreChoice')} ${tool.name}`, title: t('toolPolicyRestoreChoice'), onClick: () => removeChoice(tool.name), children: "\u21B6" })] })] }, tool.name);
311
+ }), tools.length === 0 && _jsx("p", { className: "codex-tool-policy-note", style: { padding: '12px 14px' }, children: t('toolPolicyNoMatches') })] });
312
+ if (snapshot.status !== 'ready' || snapshot.value === undefined || mode === 'inactive')
313
+ return null;
314
+ const text = query.trim().toLowerCase();
315
+ const isFiltering = text.length > 0 || filter !== 'all';
316
+ const allTools = inventory?.tools ?? [];
317
+ const hasReplaceable = allTools.some(tool => tool.replacements.some(option => option.available));
318
+ const shown = allTools.filter(tool => (!text || `${human(tool)} ${tool.name} ${tool.description}`.toLowerCase().includes(text))
319
+ && (filter === 'all' || (filter === 'modified' ? customized(tool) : filter === 'deferred' ? chosen(tool) === 'defer' : tool.replacements.some(option => option.available))));
320
+ return _jsxs("section", { className: "codex-tool-policy", "aria-label": t(activeSub === 'prompts' ? 'settingsPresetPrompts' : 'toolPolicyTitle'), children: [_jsx("style", { children: policyStyles }), _jsxs("div", { className: "codex-card codex-preset-bar", children: [_jsxs("label", { className: "codex-preset-select-wrap", children: [_jsx("span", { className: "codex-tool-policy-note", children: t('toolPolicyPresetChoice') }), _jsxs("select", { "aria-label": t('toolPolicyPresetChoice'), value: selectedId, onChange: event => { setSelection(event.target.value); setError(''); setNotice(''); }, children: [!ids.length && _jsx("option", { value: "", children: t('toolPolicyEmpty') }), ids.map(id => _jsxs("option", { value: id, "data-preset-id": id, children: [catalog?.presets.find(preset => preset.id === id)?.name ?? id, drafts.has(id) ? ` · ${t('globalPending')}` : ''] }, id))] })] }), _jsxs("div", { className: "codex-tool-policy-action", children: [_jsx("div", { className: "codex-seg", role: "group", "aria-label": t('settingsTabLabel'), children: [['tools', 'settingsSubTools'], ['prompts', 'settingsPresetPrompts'], ['definition', 'settingsDefinition']].map(([key, labelKey]) => (_jsx("button", { type: "button", "data-submode": key, "aria-pressed": activeSub === key, onClick: () => setSubMode(key), children: t(labelKey) }, key))) }), presetManager && _jsx("button", { type: "button", className: "codex-btn", disabled: catalogState === 'loading', onClick: () => loadCatalog(true), children: t('toolPolicyCatalogRetry') })] })] }), catalogState !== 'ready' && _jsx("p", { className: "codex-tool-policy-note", role: "status", children: t(catalogState === 'loading' ? 'toolPolicyCatalogLoading' : 'toolPolicyCatalogFailed') }), catalogState === 'ready' && !ids.length && _jsx("p", { className: "codex-tool-policy-note", children: t('toolPolicyCatalogEmpty') }), duplicate && _jsx("p", { className: "codex-tool-policy-warning", children: t('toolPolicyDuplicatePreset') }), activeSub === 'definition' && (!selectedId || presetManager === undefined ? _jsx("p", { className: "codex-tool-policy-note", children: t('settingsDefinitionAbsent') }) : _jsx(PresetDefinitionCard, { presetManager: presetManager, id: selectedId, t: t })), activeSub !== 'definition' && _jsx("form", { onSubmit: event => { event.preventDefault(); saveCurrent(); }, children: _jsxs("fieldset", { disabled: !snapshot.writable || saving, children: [activeSub === 'tools' && _jsxs(_Fragment, { children: [toolsStatus !== 'ready' && _jsx("p", { className: "codex-tool-policy-note", role: "status", children: t(toolsStatus === 'loading' ? 'toolPolicyToolsLoading' : 'toolPolicyToolsFailed') }), inventory?.tools.length === 0 && _jsx("p", { className: "codex-tool-policy-note", role: "status", children: t('toolPolicyToolsEmpty') }), inventory && !duplicate && inventory.tools.length > 0 && _jsxs("div", { className: "codex-toolbar", children: [_jsx("input", { type: "text", "aria-label": t('toolPolicySearch'), placeholder: t('toolPolicySearch'), value: query, onChange: event => setQuery(event.target.value) }), _jsx("div", { className: "codex-seg", role: "group", "aria-label": t('toolPolicyFilter'), children: ['all', 'deferred', 'modified', ...(hasReplaceable ? ['replaceable'] : [])].map(item => (_jsx("button", { type: "button", "data-filter": item, "aria-pressed": filter === item, onClick: () => setFilter(item), children: t(item === 'all' ? 'toolPolicyAll' : item === 'modified' ? 'toolPolicyModified' : item === 'deferred' ? 'toolPolicyDeferredFilter' : 'toolPolicyReplaceable') }, item))) }), presetManager && selectedId && _jsx("button", { type: "button", className: "codex-btn", disabled: toolsStatus === 'loading', onClick: () => loadTools(true), children: t('toolPolicyToolsRefresh') })] }), inventory && !duplicate && (isFiltering && shown.length === 0
321
+ ? _jsx("div", { className: "codex-card", children: renderRows(shown) })
322
+ : GROUP_META.map(group => {
323
+ const tools = shown.filter(tool => groupOf(tool) === group.id);
324
+ if (!tools.length)
325
+ return null;
326
+ const changes = tools.filter(customized).length;
327
+ const key = `${selectedId}/${group.id}`;
328
+ return _jsxs("details", { className: "codex-group", "data-tool-group": group.id, open: isFiltering ? true : (groupOpen.get(key) ?? true), onToggle: event => { const open = event.currentTarget.open; setGroupOpen(previous => new Map(previous).set(key, open)); }, children: [_jsxs("summary", { children: [_jsx("span", { children: t(group.labelKey) }), _jsxs("span", { className: "codex-tool-policy-note", children: [tools.length, changes ? ` · ${changes} ${t('toolPolicyCustomized')}` : ''] })] }), renderRows(tools)] }, group.id);
329
+ }))] }), activeSub === 'prompts' && _jsxs(_Fragment, { children: [presetManager && selectedId && _jsx("div", { className: "codex-toolbar", children: _jsx("button", { type: "button", className: "codex-btn", disabled: promptsStatus === 'loading', onClick: () => loadPrompts(true), children: t('presetPromptsReload') }) }), promptsStatus !== 'ready' && _jsx("p", { className: "codex-tool-policy-note", role: "status", children: t(promptsStatus === 'loading' ? 'presetPromptsLoading' : 'presetPromptsFailed') }), promptCatalog?.sections.length === 0 && _jsx("p", { className: "codex-tool-policy-note", children: t('presetPromptsEmpty') }), promptCatalog && _jsx("div", { className: "codex-tool-policy-prompts", children: promptCatalog.sections.map(section => {
330
+ const editable = section.editable && isPromptName(section.name);
331
+ const override = rule?.promptOverrides?.find(entry => entry.name === section.name);
332
+ return _jsxs("section", { className: "codex-card codex-tool-policy-prompt", "data-prompt-section": section.name, children: [_jsxs("div", { style: { display: 'flex', justifyContent: 'space-between', alignItems: 'center', gap: 8 }, children: [_jsx("h4", { children: section.label || section.name }), _jsx("code", { children: section.name })] }), editable ? _jsxs(_Fragment, { children: [_jsx("textarea", { "aria-label": `${t('settingsPresetPrompts')} ${section.name}`, rows: 5, maxLength: 1_000_000, disabled: duplicate || !snapshot.writable || saving, value: override?.text ?? section.text, onChange: event => changePrompt(section, event.target.value) }), _jsx("button", { type: "button", className: "codex-btn", style: { justifySelf: 'start' }, "aria-label": `${t('presetPromptRestore')} ${section.name}`, disabled: !override || duplicate || !snapshot.writable || saving, onClick: () => restorePrompt(section), children: t('presetPromptRestore') })] }) : _jsxs(_Fragment, { children: [_jsx("span", { className: "codex-tool-policy-note", title: section.reason, children: t('presetPromptReadOnly') }), _jsx("pre", { children: section.text })] })] }, section.name);
333
+ }) })] }), _jsxs("div", { className: "codex-save-bar", "data-dirty": Boolean(currentDraft), children: [currentDraft ? _jsxs("span", { className: "codex-tool-policy-note", "aria-label": t('toolPolicyDraftSummary'), children: [t('toolPolicyDraftSummary'), ": ", changeSummary] })
334
+ : _jsx("span", { className: "codex-tool-policy-note", children: t('toolPolicyTiming') }), _jsxs("div", { className: "codex-save-buttons", children: [_jsx("button", { type: "button", className: "codex-btn", disabled: !currentDraft, onClick: () => { setDrafts(previous => { const next = new Map(previous); next.delete(selectedId); return next; }); setError(''); setNotice(''); }, children: t('toolPolicyDiscard') }), _jsx("button", { className: "codex-btn codex-btn-primary", type: "submit", disabled: !currentDraft, children: t(saving ? 'toolPolicySaving' : 'toolPolicySave') })] })] })] }) }), !snapshot.writable && _jsx("p", { className: "codex-tool-policy-note", children: t('toolPolicyReadOnly') }), error && _jsx("p", { className: "codex-tool-policy-error", role: "alert", children: error }), notice && _jsx("p", { className: "codex-tool-policy-note", role: "status", children: notice })] });
335
+ }
336
+ //# sourceMappingURL=tool-policy.js.map
@@ -0,0 +1,78 @@
1
+ /** Shared wire codecs and RPC descriptors for Host/Client preset inspection. */
2
+ import { z } from 'zod';
3
+ import type { InvocationDescriptor } from '@deepseek-ai/dsh-typert-protocol';
4
+ export declare const PRESET_EDITOR_PACKAGE = "@shuind/dsh-codex-harness";
5
+ export declare const PRESET_EDITOR_SERVICE = "codexPresetEditor";
6
+ export declare const presetIdSchema: z.ZodString;
7
+ export declare const presetCatalogSchema: z.ZodObject<{
8
+ presets: z.ZodArray<z.ZodObject<{
9
+ id: z.ZodString;
10
+ name: z.ZodString;
11
+ description: z.ZodString;
12
+ isDefault: z.ZodBoolean;
13
+ }, z.core.$strip>>;
14
+ excludedCount: z.ZodNumber;
15
+ }, z.core.$strip>;
16
+ export declare const presetDefinitionSchema: z.ZodObject<{
17
+ id: z.ZodString;
18
+ name: z.ZodString;
19
+ description: z.ZodString;
20
+ composition: z.ZodString;
21
+ }, z.core.$strip>;
22
+ export declare const presetToolCatalogSchema: z.ZodObject<{
23
+ preset: z.ZodString;
24
+ registeredOnly: z.ZodLiteral<true>;
25
+ legacyCapabilities: z.ZodOptional<z.ZodObject<{
26
+ terminalToolsEnabled: z.ZodOptional<z.ZodBoolean>;
27
+ planToolEnabled: z.ZodOptional<z.ZodBoolean>;
28
+ patchToolEnabled: z.ZodOptional<z.ZodBoolean>;
29
+ }, z.core.$strip>>;
30
+ tools: z.ZodArray<z.ZodObject<{
31
+ name: z.ZodString;
32
+ description: z.ZodString;
33
+ conditional: z.ZodBoolean;
34
+ defaultDeferred: z.ZodOptional<z.ZodBoolean>;
35
+ codexTool: z.ZodOptional<z.ZodObject<{
36
+ capability: z.ZodEnum<{
37
+ terminalToolsEnabled: "terminalToolsEnabled";
38
+ planToolEnabled: "planToolEnabled";
39
+ patchToolEnabled: "patchToolEnabled";
40
+ }>;
41
+ presetEnabled: z.ZodBoolean;
42
+ presetOverridesLegacy: z.ZodOptional<z.ZodBoolean>;
43
+ }, z.core.$strip>>;
44
+ replacements: z.ZodArray<z.ZodObject<{
45
+ action: z.ZodEnum<{
46
+ "codex-exec": "codex-exec";
47
+ "codex-plan": "codex-plan";
48
+ "codex-patch": "codex-patch";
49
+ }>;
50
+ tools: z.ZodArray<z.ZodString>;
51
+ available: z.ZodBoolean;
52
+ reason: z.ZodOptional<z.ZodEnum<{
53
+ conditional: "conditional";
54
+ "target-exists": "target-exists";
55
+ }>>;
56
+ }, z.core.$strip>>;
57
+ }, z.core.$strip>>;
58
+ }, z.core.$strip>;
59
+ export declare const presetPromptCatalogSchema: z.ZodObject<{
60
+ preset: z.ZodString;
61
+ sections: z.ZodArray<z.ZodObject<{
62
+ name: z.ZodString;
63
+ label: z.ZodString;
64
+ text: z.ZodString;
65
+ editable: z.ZodBoolean;
66
+ order: z.ZodOptional<z.ZodNumber>;
67
+ complete: z.ZodOptional<z.ZodBoolean>;
68
+ interpolate: z.ZodOptional<z.ZodBoolean>;
69
+ reason: z.ZodOptional<z.ZodString>;
70
+ }, z.core.$strip>>;
71
+ }, z.core.$strip>;
72
+ export declare function buildPresetEditorDescriptors(): readonly InvocationDescriptor[];
73
+ export declare const presetEditorRemote: {
74
+ package: string;
75
+ descriptors: readonly InvocationDescriptor[];
76
+ };
77
+ export default presetEditorRemote;
78
+ //# sourceMappingURL=preset-editor-schema.d.ts.map
@@ -0,0 +1,95 @@
1
+ /** Shared wire codecs and RPC descriptors for Host/Client preset inspection. */
2
+ import { z } from 'zod';
3
+ export const PRESET_EDITOR_PACKAGE = '@shuind/dsh-codex-harness';
4
+ export const PRESET_EDITOR_SERVICE = 'codexPresetEditor';
5
+ export const presetIdSchema = z.string().min(1).max(256);
6
+ export const presetCatalogSchema = z.object({
7
+ presets: z.array(z.object({
8
+ id: z.string(),
9
+ name: z.string(),
10
+ description: z.string(),
11
+ isDefault: z.boolean(),
12
+ })),
13
+ excludedCount: z.number(),
14
+ });
15
+ export const presetDefinitionSchema = z.object({
16
+ id: z.string(),
17
+ name: z.string(),
18
+ description: z.string(),
19
+ composition: z.string(),
20
+ });
21
+ export const presetToolCatalogSchema = z.object({
22
+ preset: z.string(),
23
+ registeredOnly: z.literal(true),
24
+ legacyCapabilities: z.object({
25
+ terminalToolsEnabled: z.boolean().optional(),
26
+ planToolEnabled: z.boolean().optional(),
27
+ patchToolEnabled: z.boolean().optional(),
28
+ }).optional(),
29
+ tools: z.array(z.object({
30
+ name: z.string(),
31
+ description: z.string(),
32
+ conditional: z.boolean(),
33
+ defaultDeferred: z.boolean().optional(),
34
+ codexTool: z.object({
35
+ capability: z.enum(['terminalToolsEnabled', 'planToolEnabled', 'patchToolEnabled']),
36
+ presetEnabled: z.boolean(),
37
+ presetOverridesLegacy: z.boolean().optional(),
38
+ }).optional(),
39
+ replacements: z.array(z.object({
40
+ action: z.enum(['codex-exec', 'codex-plan', 'codex-patch']),
41
+ tools: z.array(z.string()),
42
+ available: z.boolean(),
43
+ reason: z.enum(['conditional', 'target-exists']).optional(),
44
+ })),
45
+ })),
46
+ });
47
+ export const presetPromptCatalogSchema = z.object({
48
+ preset: z.string(),
49
+ sections: z.array(z.object({
50
+ name: z.string(),
51
+ label: z.string(),
52
+ text: z.string().max(1_000_000),
53
+ editable: z.boolean(),
54
+ order: z.number().finite().optional(),
55
+ complete: z.boolean().optional(),
56
+ interpolate: z.boolean().optional(),
57
+ reason: z.string().optional(),
58
+ })).max(200),
59
+ });
60
+ function descriptor(method, parameter, input, output) {
61
+ const id = `${PRESET_EDITOR_PACKAGE}#${PRESET_EDITOR_SERVICE}/${method}`;
62
+ const strictCodec = (typeSymbol, schema) => ({
63
+ mode: 'strict',
64
+ typeSymbol,
65
+ create: () => schema,
66
+ });
67
+ return {
68
+ id,
69
+ service: PRESET_EDITOR_SERVICE,
70
+ namespace: PRESET_EDITOR_SERVICE,
71
+ method,
72
+ invocation: { kind: 'direct' },
73
+ parameters: parameter === undefined ? [] : [{
74
+ name: parameter,
75
+ wire: parameter,
76
+ source: 'json',
77
+ codec: strictCodec(`${id}:${parameter}`, input),
78
+ }],
79
+ result: strictCodec(`${id}:result`, output),
80
+ };
81
+ }
82
+ export function buildPresetEditorDescriptors() {
83
+ return [
84
+ descriptor('catalog', undefined, z.unknown(), presetCatalogSchema),
85
+ descriptor('tools', 'id', presetIdSchema, presetToolCatalogSchema),
86
+ descriptor('prompts', 'id', presetIdSchema, presetPromptCatalogSchema),
87
+ descriptor('read', 'id', presetIdSchema, presetDefinitionSchema),
88
+ ];
89
+ }
90
+ export const presetEditorRemote = {
91
+ package: PRESET_EDITOR_PACKAGE,
92
+ descriptors: buildPresetEditorDescriptors(),
93
+ };
94
+ export default presetEditorRemote;
95
+ //# sourceMappingURL=preset-editor-schema.js.map
@@ -1,13 +1,14 @@
1
1
  /** Default plugin-owned Codex operating prompt. */
2
2
  export const DEFAULT_CODEX_SYSTEM_PROMPT = String.raw `## General
3
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.
4
+ - Follow the current tool catalog, not assumptions from another Codex client. For unknown paths, use the available list/search tools instead of guessing and reuse the returned paths. If only shell search is available, prefer rg or rg --files.
5
5
 
6
6
  ## Editing constraints
7
7
 
8
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
+ - Prefer apply_patch (or dedicated file tools when present) over shell heredocs or redirection for file edits; do not re-read a file immediately after apply_patch succeeds unless checking external changes.
9
10
  - 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
+ - You may be in a dirty git worktree. Never revert existing changes you did not make unless the user explicitly requests it, never amend commits unless asked, and avoid interactive git commands such as git rebase -i or git add -p. If unrelated files are changed, leave them alone.
11
12
 
12
13
  ## Planning
13
14
 
@@ -17,28 +18,33 @@ export const DEFAULT_CODEX_SYSTEM_PROMPT = String.raw `## General
17
18
  ## dsh session
18
19
 
19
20
  - The user and you share one workspace. Inspect the repository and every applicable AGENTS.md before editing.
21
+ - For Harness APIs, first load the relevant Harness skill. When Inspect tools are available, start with cordis_inspect_list, then query the provider's directory before an exact Service contract. Reuse returned names; Inspect is read-only.
22
+ - A not-found path or unknown Service is a discovery error: check the file list or Service directory before retrying. Preserve actual failures; do not hide them or bypass permission denials.
20
23
 
21
24
  ## Task execution
22
25
 
23
- - Keep the user informed with concise progress updates and lead with the result.
26
+ - Parallelize independent read, search, and check calls. Do not sleep-poll background jobs or subagents; they wake on completion.
27
+ - When delegating parallel edits, assign disjoint write scopes. Record key paths and facts as you go since older large tool outputs may be pruned.
28
+ - Never claim unrun checks passed, and keep the user informed with concise progress updates.
24
29
 
25
30
  ## Presenting your work
26
31
 
27
- - Be concise, direct, friendly, and actionable.
32
+ - Be concise, direct, friendly, and actionable, and lead with the result.
28
33
  - For substantial work, explain what changed and why, then briefly note how the work was verified and what comes next.
34
+ - For code reviews, lead with concrete findings ordered by severity with file and line references before any brief summary, or state explicitly if no issues were found.
29
35
  - Do not dump large files into the conversation; refer to their paths.
30
36
  - Use plain text with short sections only when they improve scanability.
31
37
 
32
38
  ## Working principles
33
39
 
34
- - Actively establish the user's current context rather than relying on stale assumptions or prior context. Before committing to an approach that could materially shape the outcome or direction of the work, state the intended path and align it with the user; clarify any material uncertainty first. Then pursue the user's goal through the clearest, most effective path.
40
+ - Actively establish the user's current context from the repository rather than relying on stale assumptions. Execute tasks directly through implementation and verification using the clearest, most effective path; ask the user only when a user-owned choice or external/destructive action cannot be resolved by inspection.
35
41
  - 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
42
  - Solve problems by thinking from first principles and at a higher level.
37
43
  `;
38
44
  /** Default deployment Persona template used by the Codex preset. */
39
- export const DEFAULT_CODEX_PERSONA = String.raw `You are Codex, a coding agent based on the {{model}} model. Your working directory is {{cwd}}.`;
45
+ export const DEFAULT_CODEX_PERSONA = String.raw `You are Codex, a coding agent based on the {{model}} model.`;
40
46
  /** Default DSH Core source-checkout guidance template. */
41
- export const DEFAULT_DSH_CORE_SOURCE_PROMPT = String.raw `The DeepSeek Harness implementation checkout is at {{sourceRoot}}. The checkout location and current working directory are separate values and may differ; never infer the working directory from this path. Use pwd to determine the current working directory. Use this checkout only to inspect or extend DSH itself.`;
47
+ export const DEFAULT_DSH_CORE_SOURCE_PROMPT = String.raw `The DeepSeek Harness implementation checkout is at {{sourceRoot}}. The checkout location and current working directory are separate values and may differ; never infer the working directory from this path. Use pwd to determine the current working directory. Use this checkout only to inspect or extend DSH itself. If the supplied path is inside app.asar, treat it as a packaged runtime rather than a source checkout. Discover the installed packageDir via Inspect and read its README and package.json exports; do not assume src or individual lib/types filenames exist. Use Host file-read tools for app.asar; native shell search and glob cannot traverse it.`;
42
48
  /** Default DSH Web runtime guidance template. */
43
49
  export const DEFAULT_DSH_CORE_WEB_PROMPT = [
44
50
  'You are interacting with the user through the DeepSeek Harness Web GUI at {{webUrl}}.',
@@ -1,4 +1,5 @@
1
- /** Shared host-side Codex settings contract. */
1
+ /** Shared host-side Codex settings contract, Host reader, and GPT route matcher. */
2
+ import type { Context } from '@deepseek-ai/cordis';
2
3
  import z from '@deepseek-ai/schemastery';
3
4
  import type { SettingsNamespace } from '@deepseek-ai/dsh-settings';
4
5
  /** Live Codex controls shared by the Web UI and agent layer. */
@@ -8,6 +9,8 @@ export interface CodexSettings {
8
9
  fast: boolean;
9
10
  /** Show the Fast mode switch in the conversation composer. */
10
11
  fastModeControlEnabled: boolean;
12
+ /** Show the quick context-window control in the conversation composer. */
13
+ contextWindowControlEnabled: boolean;
11
14
  /** Optional context capacity override, in tokens. */
12
15
  contextWindow?: number;
13
16
  /** Deployment Persona template; supports the host's prompt variables. */
@@ -20,11 +23,11 @@ export interface CodexSettings {
20
23
  systemPrompt?: string;
21
24
  /** Inject the plugin-owned Codex operating prompt. */
22
25
  promptEnabled: boolean;
23
- /** Expose exec_command and write_stdin. */
26
+ /** Deprecated compatibility baseline, snapshotted into future Agent tool plans. */
24
27
  terminalToolsEnabled: boolean;
25
- /** Expose apply_patch. */
28
+ /** Deprecated tool baseline; also retains the legacy JSON/custom wire-format preference. */
26
29
  patchToolEnabled: boolean;
27
- /** Expose update_plan. */
30
+ /** Deprecated compatibility baseline, not a live veto of a compiled plan. */
28
31
  planToolEnabled: boolean;
29
32
  /** Upgrade local web_search declarations to the hosted Responses tool. */
30
33
  hostedWebSearchEnabled: boolean;
@@ -36,4 +39,8 @@ export interface CodexSettings {
36
39
  /** Default settings exposed even before a Codex session is opened. */
37
40
  export declare const CODEX_SETTINGS_ENTRY: CodexSettings;
38
41
  export declare const CODEX_SETTINGS_SCHEMA: z<CodexSettings>;
42
+ /** Host-only reads: never expose the unredacted provider configuration to clients. */
43
+ export declare function readHostSettings<T>(ctx: Context, namespace: string): T | undefined;
44
+ /** Match GPT / ChatGPT model ids that consume Codex wire & capacity extensions. */
45
+ export declare function isGptModel(model: unknown): model is string;
39
46
  //# sourceMappingURL=settings.d.ts.map