@shuind/dsh-codex-harness 0.3.2 → 0.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/README.md +21 -41
  3. package/docs/preset-library.md +2 -2
  4. package/docs/tool-policy.md +1 -1
  5. package/lib/client.js +1826 -545
  6. package/lib/compact-command.js +7 -1
  7. package/lib/compaction.js +7 -1
  8. package/lib/hybrid-executor.js +23 -12
  9. package/lib/index.js +1229 -17
  10. package/lib/preferences.js +21 -2
  11. package/lib/tool-policy.js +11 -2
  12. package/lib/typert.js +42 -1
  13. package/lib/types/client/desktop.d.ts +20 -42
  14. package/lib/types/client/desktop.js +184 -127
  15. package/lib/types/client/index.d.ts +104 -39
  16. package/lib/types/client/index.js +97 -15
  17. package/lib/types/client/policy-drafts.d.ts +18 -0
  18. package/lib/types/client/policy-drafts.js +27 -0
  19. package/lib/types/client/policy-locale.d.ts +81 -32
  20. package/lib/types/client/policy-locale.js +197 -107
  21. package/lib/types/client/preset-manager.d.ts +25 -2
  22. package/lib/types/client/preset-manager.js +89 -5
  23. package/lib/types/client/preset-requests.d.ts +44 -1
  24. package/lib/types/client/preset-requests.js +150 -0
  25. package/lib/types/client/tool-policy.d.ts +6 -15
  26. package/lib/types/client/tool-policy.js +24 -39
  27. package/lib/types/contracts/preset-editor-schema.d.ts +35 -0
  28. package/lib/types/contracts/preset-editor-schema.js +39 -0
  29. package/lib/types/contracts/settings.d.ts +12 -0
  30. package/lib/types/contracts/settings.js +10 -1
  31. package/lib/types/contracts/ui-contracts.d.ts +48 -0
  32. package/lib/types/contracts/ui-contracts.js +58 -0
  33. package/lib/types/contracts/update.d.ts +73 -0
  34. package/lib/types/contracts/update.js +291 -0
  35. package/lib/types/entries/index.js +20 -2
  36. package/lib/types/entries/preferences.d.ts +2 -0
  37. package/lib/types/entries/preferences.js +9 -0
  38. package/lib/types/hybrid/hybrid-sdk.d.ts +1 -1
  39. package/lib/types/hybrid/hybrid-sdk.js +27 -13
  40. package/lib/types/presets/preset-editor.d.ts +13 -1
  41. package/lib/types/presets/preset-editor.js +24 -1
  42. package/lib/types/presets/pro-mode-store.d.ts +13 -0
  43. package/lib/types/presets/pro-mode-store.js +69 -0
  44. package/lib/types/responses/background-sse-codec.d.ts +23 -0
  45. package/lib/types/responses/background-sse-codec.js +230 -0
  46. package/lib/types/responses/background-stream.d.ts +28 -0
  47. package/lib/types/responses/background-stream.js +351 -0
  48. package/lib/types/responses/fetch-transport.js +24 -9
  49. package/lib/types/responses/wire-rewrite.d.ts +4 -0
  50. package/lib/types/responses/wire-rewrite.js +30 -4
  51. package/lib/types/tools/codex-subagent.d.ts +14 -0
  52. package/lib/types/tools/codex-subagent.js +269 -0
  53. package/lib/types/update/checker.d.ts +14 -0
  54. package/lib/types/update/checker.js +166 -0
  55. package/locale/en.json +1 -1
  56. package/locale/hybrid-executor/en.json +1 -1
  57. package/locale/hybrid-executor/zh.json +1 -1
  58. package/locale/zh.json +1 -1
  59. package/package.json +6 -2
  60. package/src/client/desktop.tsx +359 -160
  61. package/src/client/index.tsx +122 -22
  62. package/src/client/policy-drafts.ts +45 -0
  63. package/src/client/policy-locale.ts +198 -106
  64. package/src/client/preset-manager.tsx +125 -4
  65. package/src/client/preset-requests.ts +185 -1
  66. package/src/client/tool-policy.tsx +29 -63
  67. package/src/contracts/preset-editor-schema.ts +44 -0
  68. package/src/contracts/settings.ts +20 -1
  69. package/src/contracts/ui-contracts.ts +87 -0
  70. package/src/contracts/update.ts +307 -0
  71. package/src/entries/index.ts +25 -2
  72. package/src/entries/preferences.ts +9 -0
  73. package/src/hybrid/hybrid-sdk.ts +28 -12
  74. package/src/presets/preset-editor.ts +31 -3
  75. package/src/presets/pro-mode-store.ts +80 -0
  76. package/src/responses/background-sse-codec.ts +237 -0
  77. package/src/responses/background-stream.ts +371 -0
  78. package/src/responses/fetch-transport.ts +28 -9
  79. package/src/responses/wire-rewrite.ts +34 -3
  80. package/src/tools/codex-subagent.ts +290 -0
  81. package/src/update/checker.ts +193 -0
  82. package/tsdown.config.ts +4 -0
@@ -1,4 +1,16 @@
1
- import type { PresetCatalog } from '../contracts/ui-contracts.ts'
1
+ import {
2
+ nextOpenAICodexOverrides,
3
+ OPENAI_CODEX_SETTINGS_NAMESPACE,
4
+ } from '../contracts/ui-contracts.ts'
5
+ import type {
6
+ CodexConnectScope,
7
+ CodexConnectSnapshot,
8
+ CodexSubagentModelCatalog,
9
+ LlmProvidersMap,
10
+ LlmProvidersScope,
11
+ PresetCatalog,
12
+ } from '../contracts/ui-contracts.ts'
13
+ import type { CodexScope, CodexSettingsSnapshot } from './index.tsx'
2
14
  import type { PresetManagerActions } from './preset-manager.tsx'
3
15
  import type { PresetPromptCatalog, PresetToolCatalog } from '../contracts/tool-policy-contract.ts'
4
16
 
@@ -40,6 +52,10 @@ export function cachedPresetTools(manager: PresetManagerActions, id: string): Pr
40
52
  return toolCatalogs.get(manager)?.get(id)
41
53
  }
42
54
 
55
+ export function invalidatePresetTools(manager: PresetManagerActions): void {
56
+ toolCatalogs.delete(manager)
57
+ }
58
+
43
59
  /** The requested preset owns this snapshot; never substitute current-Agent tools. */
44
60
  export function requestPresetTools(manager: PresetManagerActions, id: string, refresh = false): Promise<PresetToolCatalog> {
45
61
  const pending = toolRequests.get(manager)?.get(id)
@@ -111,3 +127,171 @@ export async function readPresetWithRetry<T>(read: () => Promise<T>, active: ()
111
127
  return read()
112
128
  }
113
129
  }
130
+
131
+ const subagentModelRequests = new WeakMap<PresetManagerActions, Promise<CodexSubagentModelCatalog>>()
132
+
133
+ export function requestCodexSubagentModels(manager: PresetManagerActions): Promise<CodexSubagentModelCatalog> {
134
+ const pending = subagentModelRequests.get(manager)
135
+ if (pending !== undefined) return pending
136
+ const request = (async (): Promise<CodexSubagentModelCatalog> => {
137
+ await manager.ready
138
+ const remote = manager.remote.codexPresetEditor
139
+ if (typeof remote.codexSubagentModels !== 'function') throw new Error('codex-subagent-models-unavailable')
140
+ const result = await remote.codexSubagentModels()
141
+ if (!result.ok) throw new Error(result.error.message ?? 'codex-subagent-models-unavailable')
142
+ return result.value
143
+ })()
144
+ subagentModelRequests.set(manager, request)
145
+ void request.finally(() => {
146
+ if (subagentModelRequests.get(manager) === request) subagentModelRequests.delete(manager)
147
+ }).catch(() => {})
148
+ return request
149
+ }
150
+
151
+ export interface DesktopConfigForm extends Pick<CodexScope, 'getSnapshot' | 'subscribe'> {
152
+ set(field: string, value: unknown): Promise<boolean>
153
+ unset(field: string): Promise<boolean>
154
+ mutate(ops: Array<{ op: 'set'; path: string[]; value: unknown } | { op: 'unset'; path: string[] }>, expectedRevision?: number | string): Promise<boolean>
155
+ }
156
+
157
+ interface MirrorNamespaceRow {
158
+ readonly ns: string
159
+ readonly value?: unknown
160
+ readonly base?: unknown
161
+ }
162
+
163
+ interface ConfigMirror {
164
+ getSnapshot(): { readonly status?: string; readonly view?: { readonly writable?: boolean; readonly namespaces?: readonly MirrorNamespaceRow[] } }
165
+ subscribe(listener: () => void): () => void
166
+ ensure?(): unknown
167
+ }
168
+
169
+ export interface DesktopSettingsContext {
170
+ configForms: {
171
+ get(entryId: string): DesktopConfigForm
172
+ describe?(): ConfigMirror
173
+ whileServed(namespaces: string[], register: () => () => void): () => void
174
+ }
175
+ }
176
+
177
+ function asRecord(value: unknown): Record<string, unknown> | undefined {
178
+ return typeof value === 'object' && value !== null && !Array.isArray(value)
179
+ ? value as Record<string, unknown>
180
+ : undefined
181
+ }
182
+
183
+ function asOverrides(value: unknown): Record<string, number | null> | undefined {
184
+ const record = asRecord(value)
185
+ if (record === undefined) return undefined
186
+ const out: Record<string, number | null> = {}
187
+ for (const [k, v] of Object.entries(record)) {
188
+ if (v === null || (typeof v === 'number' && Number.isSafeInteger(v) && v > 0)) out[k] = v
189
+ }
190
+ return out
191
+ }
192
+
193
+ function projectCodexConnectRecord(
194
+ record: Record<string, unknown>,
195
+ baseRecord: Record<string, unknown> | undefined,
196
+ writable: boolean,
197
+ ): CodexConnectSnapshot {
198
+ const searchModel = typeof record.searchModel === 'string' && record.searchModel.trim() ? record.searchModel.trim() : undefined
199
+ const imageModelHint = typeof record.imageModelHint === 'string' ? record.imageModelHint.trim() : undefined
200
+ return {
201
+ status: 'ready',
202
+ writable,
203
+ overrides: asOverrides(record.contextWindowOverrides),
204
+ baseOverrides: asOverrides(baseRecord?.contextWindowOverrides),
205
+ ...(typeof record.enableNativeCompaction === 'boolean' ? { nativeCompaction: record.enableNativeCompaction } : {}),
206
+ ...(typeof record.enableSearch === 'boolean' ? { searchEnabled: record.enableSearch } : {}),
207
+ ...(searchModel !== undefined ? { searchModel } : {}),
208
+ ...(typeof record.enableImageGeneration === 'boolean' ? { imageGenerationEnabled: record.enableImageGeneration } : {}),
209
+ ...(imageModelHint !== undefined ? { imageModelHint } : {}),
210
+ }
211
+ }
212
+
213
+ export function bindCodexConnectScope(configForms: DesktopSettingsContext['configForms']): CodexConnectScope {
214
+ const form = configForms.get(OPENAI_CODEX_SETTINGS_NAMESPACE)
215
+ const mirror = configForms.describe?.()
216
+ void Promise.resolve(mirror?.ensure?.()).catch(() => {})
217
+ let lastFormSnap: unknown
218
+ let lastMirrorSnap: unknown
219
+ let projected: CodexConnectSnapshot = { status: 'loading', writable: false }
220
+ const getSnapshot = (): CodexConnectSnapshot => {
221
+ const formSnap = form.getSnapshot() as CodexSettingsSnapshot & { readonly base?: Record<string, unknown> }
222
+ const mirrorSnap = mirror?.getSnapshot()
223
+ if (formSnap === lastFormSnap && mirrorSnap === lastMirrorSnap) return projected
224
+ lastFormSnap = formSnap
225
+ lastMirrorSnap = mirrorSnap
226
+ const formRecord = formSnap.status === 'ready' ? asRecord(formSnap.value) : undefined
227
+ if (formRecord !== undefined) {
228
+ return projected = projectCodexConnectRecord(formRecord, asRecord(formSnap.base), formSnap.writable)
229
+ }
230
+ const view = mirrorSnap?.view
231
+ if (view !== undefined) {
232
+ const row = view.namespaces?.find(candidate => candidate.ns === OPENAI_CODEX_SETTINGS_NAMESPACE)
233
+ const rowRecord = row === undefined ? undefined : asRecord(row.value)
234
+ if (row === undefined || rowRecord === undefined) return projected = { status: 'unavailable', writable: false }
235
+ return projected = projectCodexConnectRecord(rowRecord, asRecord(row.base), view.writable ?? formSnap.writable)
236
+ }
237
+ return projected = { status: formSnap.status, writable: formSnap.writable }
238
+ }
239
+ return {
240
+ getSnapshot,
241
+ subscribe: listener => {
242
+ const stopForm = form.subscribe(listener)
243
+ const stopMirror = mirror?.subscribe(listener)
244
+ return () => { stopForm(); stopMirror?.() }
245
+ },
246
+ setModelOverride: async (modelId, tokens) => {
247
+ const snap = getSnapshot()
248
+ const next = nextOpenAICodexOverrides(snap.overrides, snap.baseOverrides, modelId, tokens)
249
+ const accepted = next === undefined
250
+ ? await form.unset('contextWindowOverrides')
251
+ : await form.set('contextWindowOverrides', next)
252
+ if (!accepted) throw new Error('The host did not accept the settings change.')
253
+ },
254
+ setNativeCompaction: async enabled => {
255
+ const accepted = await form.set('enableNativeCompaction', enabled)
256
+ if (!accepted) throw new Error('The host did not accept the settings change.')
257
+ },
258
+ setSearchEnabled: async enabled => {
259
+ const accepted = await form.set('enableSearch', enabled)
260
+ if (!accepted) throw new Error('The host did not accept the settings change.')
261
+ },
262
+ setImageGenerationEnabled: async enabled => {
263
+ const accepted = await form.set('enableImageGeneration', enabled)
264
+ if (!accepted) throw new Error('The host did not accept the settings change.')
265
+ },
266
+ }
267
+ }
268
+
269
+ export function bindLlmProvidersScope(configForms: DesktopSettingsContext['configForms']): LlmProvidersScope | undefined {
270
+ const mirror = configForms.describe?.()
271
+ if (mirror === undefined) return undefined
272
+ void Promise.resolve(mirror.ensure?.()).catch(() => {})
273
+ let lastMirrorSnap: unknown
274
+ let projected: LlmProvidersMap | undefined
275
+ const getSnapshot = (): LlmProvidersMap | undefined => {
276
+ const mirrorSnap = mirror.getSnapshot()
277
+ if (mirrorSnap === lastMirrorSnap) return projected
278
+ lastMirrorSnap = mirrorSnap
279
+ const row = mirrorSnap?.view?.namespaces?.find(candidate => candidate.ns === 'llm-pi-ai')
280
+ const providers = asRecord(asRecord(row?.value)?.providers)
281
+ return projected = providers as LlmProvidersMap | undefined
282
+ }
283
+ return { getSnapshot, subscribe: listener => mirror.subscribe(listener) }
284
+ }
285
+
286
+ export function adaptConfigForm(form: Pick<DesktopConfigForm, 'getSnapshot' | 'subscribe' | 'set' | 'unset'>): CodexScope {
287
+ const accepted = async (result: Promise<boolean>) => { if (!await result) throw new Error('The host did not accept the settings change.') }
288
+ return { getSnapshot: () => form.getSnapshot(), subscribe: listener => form.subscribe(listener),
289
+ set: (field, value) => accepted(form.set(field, value)), unset: field => accepted(form.unset(field)) }
290
+ }
291
+
292
+ export async function saveDesktopSettings(form: Pick<DesktopConfigForm, 'mutate'>, edits: Record<string, unknown>, expectedRevision?: number | string): Promise<void> {
293
+ const ops = Object.entries(edits).map(([field, value]) => value === undefined ? { op: 'unset' as const, path: [field] } : { op: 'set' as const, path: [field], value })
294
+ if (!ops.length) return
295
+ const accepted = expectedRevision === undefined ? await form.mutate(ops) : await form.mutate(ops, expectedRevision)
296
+ if (!accepted) throw new Error('The host did not accept the settings change.')
297
+ }
@@ -15,13 +15,13 @@ import type {
15
15
  PresetToolEntry, ToolAction, ToolActionContext, ToolPolicyRule,
16
16
  } from '../contracts/tool-policy-contract.ts'
17
17
  import { PRESET_PROMPT_NAMES } from '../contracts/ui-contracts.ts'
18
- import type { CodexConnectSnapshot } from '../contracts/ui-contracts.ts'
19
- import { acceptPresetSave, editPresetDraft, preparePresetSave, presetRules, sameRules } from './policy-drafts.ts'
20
- import type { PresetDrafts } from './policy-drafts.ts'
18
+ import { acceptPresetSave, editPresetDraft, formatGptImageBadge, preparePresetSave, presetRules, resolveGptCapabilities, sameRules } from './policy-drafts.ts'
19
+ import type { GptCapabilitiesState, PresetDrafts } from './policy-drafts.ts'
21
20
  import { groupOf, humanLabels, policyStyles, toolPolicyEn, toolPolicyZh } from './policy-locale.ts'
22
21
  import type { ToolGroupId } from './policy-locale.ts'
23
22
  export type { ToolPolicyRule } from '../contracts/tool-policy-contract.ts'
24
- export { toolPolicyEn, toolPolicyZh }
23
+ export type { GptCapabilitiesState }
24
+ export { formatGptImageBadge, resolveGptCapabilities, toolPolicyEn, toolPolicyZh }
25
25
 
26
26
  export const TOOL_POLICY_NAMESPACE = 'codex-tool-policy'
27
27
  export interface ToolPolicySettings { readonly rules: readonly ToolPolicyRule[] }
@@ -87,46 +87,13 @@ export function saveToolPolicy(form: ToolPolicyForm, rules: readonly ToolPolicyR
87
87
  return form.mutate([{ op: 'set', path: ['rules'], value }], revision)
88
88
  }
89
89
 
90
- export interface GptCapabilitiesState {
91
- readonly hostedWebSearch: boolean
92
- readonly codexSearch: boolean
93
- readonly codexSearchModel?: string | undefined
94
- readonly remoteCompaction: boolean
95
- readonly imageGeneration: boolean
96
- readonly imageModelHint?: string | undefined
97
- }
98
-
99
- export function resolveGptCapabilities(
100
- codexSettings?: { readonly hostedWebSearchEnabled?: boolean; readonly remoteCompactionEnabled?: boolean } | undefined,
101
- codexConnect?: CodexConnectSnapshot | undefined,
102
- ): GptCapabilitiesState | undefined {
103
- const connectReady = codexConnect?.status === 'ready'
104
- if (codexSettings === undefined && !connectReady) return undefined
105
- return {
106
- hostedWebSearch: codexSettings !== undefined ? (codexSettings.hostedWebSearchEnabled ?? true) : false,
107
- codexSearch: connectReady && codexConnect.searchEnabled === true,
108
- codexSearchModel: connectReady ? codexConnect.searchModel : undefined,
109
- remoteCompaction: (codexSettings !== undefined && (codexSettings.remoteCompactionEnabled ?? true))
110
- || (connectReady && codexConnect.nativeCompaction === true),
111
- imageGeneration: connectReady && codexConnect.imageGenerationEnabled === true,
112
- imageModelHint: connectReady ? codexConnect.imageModelHint : undefined,
113
- }
114
- }
115
-
116
- function formatGptImageBadge(hint: string | undefined): string {
117
- const value = hint?.trim() ?? ''
118
- if (!value || value === 'gpt-image-2.6-sunburst') return 'GPT-Image-2.6 Sunburst'
119
- if (value === 'gpt-image-2.6-flare') return 'GPT-Image-2.6 Flare'
120
- if (value === 'gpt-image-2') return 'GPT-Image-2'
121
- return value
122
- }
123
-
124
90
  export type ToolPolicySubMode = 'tools' | 'prompts' | 'definition'
125
91
  export type ToolPolicyMode = ToolPolicySubMode | 'inactive'
126
92
  type PolicyProps = PropsLocale<'codex'> & {
127
93
  presetManager?: PresetManagerActions | undefined
128
94
  mode?: ToolPolicyMode
129
95
  gptCapabilities?: GptCapabilitiesState | undefined
96
+ toolsVersion?: number | undefined
130
97
  }
131
98
  type ToolsView = { preset: string; status: 'loading' | 'ready' | 'error'; value?: PresetToolCatalog }
132
99
  type PromptsView = { preset: string; status: 'loading' | 'ready' | 'error'; value?: PresetPromptCatalog }
@@ -134,9 +101,8 @@ const isPromptName = (name: string): name is PresetPromptName => (PRESET_PROMPT_
134
101
 
135
102
  const GROUP_META: readonly {
136
103
  id: ToolGroupId
137
- labelKey: 'toolPolicyGptGroup' | 'toolPolicyCommandGroup' | 'toolPolicyFileGroup' | 'toolPolicyPlanGroup' | 'toolPolicyCollabGroup' | 'toolPolicyOtherGroup'
104
+ labelKey: 'toolPolicyCommandGroup' | 'toolPolicyFileGroup' | 'toolPolicyPlanGroup' | 'toolPolicyCollabGroup' | 'toolPolicyOtherGroup'
138
105
  }[] = [
139
- { id: 'gpt', labelKey: 'toolPolicyGptGroup' },
140
106
  { id: 'command', labelKey: 'toolPolicyCommandGroup' },
141
107
  { id: 'file', labelKey: 'toolPolicyFileGroup' },
142
108
  { id: 'plan', labelKey: 'toolPolicyPlanGroup' },
@@ -149,7 +115,7 @@ export function ToolPolicySection({ binding, ...props }: { binding: ToolPolicyBi
149
115
  return form === undefined ? null : <ToolPolicySettingsCard form={form} {...props} />
150
116
  }
151
117
 
152
- export function ToolPolicySettingsCard({ form, presetManager, mode = 'tools', gptCapabilities, t }: { form: ToolPolicyForm } & PolicyProps) {
118
+ export function ToolPolicySettingsCard({ form, presetManager, mode = 'tools', gptCapabilities, toolsVersion = 0, t }: { form: ToolPolicyForm } & PolicyProps) {
153
119
  const snapshot = useSyncExternalStore(listener => form.subscribe(listener), () => form.getSnapshot(), () => form.getSnapshot())
154
120
  const [subMode, setSubMode] = useState<ToolPolicySubMode>(mode === 'prompts' || mode === 'definition' ? mode : 'tools')
155
121
  const prevMode = useRef(mode)
@@ -199,6 +165,13 @@ export function ToolPolicySettingsCard({ form, presetManager, mode = 'tools', gp
199
165
  }).catch(() => { if (alive.current && ticket === toolsRequest.current) setToolsView({ preset: selectedId, status: 'error' }) })
200
166
  }
201
167
  useEffect(() => { loadTools(); return () => { toolsRequest.current++ } }, [presetManager, selectedId])
168
+ const loadedToolsVersion = useRef(toolsVersion)
169
+ useEffect(() => {
170
+ if (mode !== 'inactive' && loadedToolsVersion.current !== toolsVersion) {
171
+ loadedToolsVersion.current = toolsVersion
172
+ loadTools(true)
173
+ }
174
+ }, [mode, toolsVersion, presetManager, selectedId])
202
175
 
203
176
  const cached = presetManager && selectedId ? cachedPresetTools(presetManager, selectedId) : undefined
204
177
  const inventory = toolsView?.preset === selectedId && toolsView.status === 'error' ? undefined : toolsView?.preset === selectedId && toolsView.status === 'ready' ? toolsView.value : cached
@@ -318,8 +291,15 @@ export function ToolPolicySettingsCard({ form, presetManager, mode = 'tools', gp
318
291
 
319
292
  const gptSearchActive = gptCapabilities?.hostedWebSearch === true || gptCapabilities?.codexSearch === true
320
293
  const gptBadgeFor = (tool: PresetToolEntry): { label: string; title: string } | undefined => {
294
+ if (tool.name === 'codex_subagent') {
295
+ const model = gptCapabilities?.codexSubagentModel
296
+ return {
297
+ label: model ? `${t('toolPolicyGptCodexSearch')} · ${model}` : t('toolPolicyGptCodexSearch'),
298
+ title: t('toolPolicyGptSubagentTitle'),
299
+ }
300
+ }
321
301
  if (tool.name === 'codex_connect_image_generate') {
322
- return { label: formatGptImageBadge(gptCapabilities?.imageModelHint), title: t('toolPolicyGptImageTitle') }
302
+ return { label: `${t('toolPolicyGptCodexSearch')} · ${formatGptImageBadge(gptCapabilities?.imageModelHint)}`, title: t('toolPolicyGptImageTitle') }
323
303
  }
324
304
  if (tool.name === 'web_search' && gptSearchActive) {
325
305
  const model = gptCapabilities?.codexSearchModel
@@ -340,7 +320,7 @@ export function ToolPolicySettingsCard({ form, presetManager, mode = 'tools', gp
340
320
  return undefined
341
321
  }
342
322
 
343
- const renderRows = (tools: readonly PresetToolEntry[], includeCompaction = false) => <div className="codex-tool-policy-table" role="table" aria-label={t('toolPolicyTitle')}>
323
+ const renderRows = (tools: readonly PresetToolEntry[]) => <div className="codex-tool-policy-table" role="table" aria-label={t('toolPolicyTitle')}>
344
324
  {tools.map(tool => {
345
325
  const action = chosen(tool); const deferReason = deferUnavailableReason(tool)
346
326
  const supported = action === 'keep' || action === 'hide' || action === 'defer' || tool.replacements.some(option => option.action === action)
@@ -372,17 +352,7 @@ export function ToolPolicySettingsCard({ form, presetManager, mode = 'tools', gp
372
352
  </div>
373
353
  </div>
374
354
  })}
375
- {includeCompaction && <div key="__gpt_compaction__" role="row" className="codex-tool-policy-tool" data-gpt-capability="compaction">
376
- <div role="cell" className="codex-tool-policy-name">
377
- <code className="codex-tool-policy-identifier">/compact</code>
378
- <span className="codex-tool-policy-description">{t('toolPolicyGptCompactionDesc')}</span>
379
- <span className="codex-badge" data-tone="gpt">{t('toolPolicyGptCompactionBadge')}</span>
380
- </div>
381
- <div role="cell" className="codex-tool-policy-action">
382
- <span className="codex-badge">{t('toolPolicyGptCompactionReadOnly')}</span>
383
- </div>
384
- </div>}
385
- {tools.length === 0 && !includeCompaction && <p className="codex-tool-policy-note" style={{ padding: '12px 14px' }}>{t('toolPolicyNoMatches')}</p>}
355
+ {tools.length === 0 && <p className="codex-tool-policy-note" style={{ padding: '12px 14px' }}>{t('toolPolicyNoMatches')}</p>}
386
356
  </div>
387
357
 
388
358
  if (snapshot.status !== 'ready' || snapshot.value === undefined || mode === 'inactive') return null
@@ -396,8 +366,6 @@ export function ToolPolicySettingsCard({ form, presetManager, mode = 'tools', gp
396
366
  return (!text || haystack.includes(text))
397
367
  && (filter === 'all' || (filter === 'modified' ? customized(tool) : filter === 'deferred' ? chosen(tool) === 'defer' : tool.replacements.some(option => option.available)))
398
368
  })
399
- const compactionSearchText = `/compact compaction ${t('toolPolicyGptCompactionDesc')} ${t('toolPolicyGptCompactionBadge')} gpt`.toLowerCase()
400
- const showCompactionRow = gptCapabilities?.remoteCompaction === true && filter === 'all' && (!text || compactionSearchText.includes(text))
401
369
 
402
370
  return <section className="codex-tool-policy" aria-label={t(activeSub === 'prompts' ? 'settingsPresetPrompts' : 'toolPolicyTitle')}>
403
371
  <style>{policyStyles}</style>
@@ -437,18 +405,16 @@ export function ToolPolicySettingsCard({ form, presetManager, mode = 'tools', gp
437
405
  </div>
438
406
  {presetManager && selectedId && <button type="button" className="codex-btn" disabled={toolsStatus === 'loading'} onClick={() => loadTools(true)}>{t('toolPolicyToolsRefresh')}</button>}
439
407
  </div>}
440
- {inventory && !duplicate && (isFiltering && shown.length === 0 && !showCompactionRow
408
+ {inventory && !duplicate && (isFiltering && shown.length === 0
441
409
  ? <div className="codex-card">{renderRows(shown)}</div>
442
410
  : GROUP_META.map(group => {
443
- const tools = shown.filter(tool => groupOf(tool, gptSearchActive) === group.id)
444
- const includeCompaction = group.id === 'gpt' && showCompactionRow
445
- if (!tools.length && !includeCompaction) return null
411
+ const tools = shown.filter(tool => groupOf(tool) === group.id)
412
+ if (!tools.length) return null
446
413
  const changes = tools.filter(customized).length; const key = `${selectedId}/${group.id}`
447
- const count = tools.length + (includeCompaction ? 1 : 0)
448
414
  return <details key={group.id} className="codex-group" data-tool-group={group.id} open={isFiltering ? true : (groupOpen.get(key) ?? true)}
449
415
  onToggle={event => { const open = event.currentTarget.open; setGroupOpen(previous => new Map(previous).set(key, open)) }}>
450
- <summary><span>{t(group.labelKey)}</span><span className="codex-tool-policy-note">{count}{changes ? ` · ${changes} ${t('toolPolicyCustomized')}` : ''}</span></summary>
451
- {renderRows(tools, includeCompaction)}
416
+ <summary><span>{t(group.labelKey)}</span><span className="codex-tool-policy-note">{tools.length}{changes ? ` · ${changes} ${t('toolPolicyCustomized')}` : ''}</span></summary>
417
+ {renderRows(tools)}
452
418
  </details>
453
419
  }))}
454
420
  </>}
@@ -7,6 +7,46 @@ export const PRESET_EDITOR_SERVICE = 'codexPresetEditor'
7
7
 
8
8
  export const presetIdSchema = z.string().min(1).max(256)
9
9
 
10
+ export const proModeSessionIdSchema = z.string().min(1).max(256)
11
+
12
+ export const proModeSetInputSchema = z.object({
13
+ sessionId: proModeSessionIdSchema,
14
+ enabled: z.boolean(),
15
+ })
16
+
17
+ export const proModeStateSchema = z.object({
18
+ enabled: z.boolean(),
19
+ })
20
+
21
+ export const harnessUpdateResultSchema = z.discriminatedUnion('status', [
22
+ z.object({
23
+ status: z.literal('up-to-date'),
24
+ currentVersion: z.string(),
25
+ latestVersion: z.string(),
26
+ }),
27
+ z.object({
28
+ status: z.literal('update-available'),
29
+ currentVersion: z.string(),
30
+ latestVersion: z.string(),
31
+ releaseUrl: z.string(),
32
+ }),
33
+ z.object({
34
+ status: z.literal('unavailable'),
35
+ currentVersion: z.string(),
36
+ reason: z.enum(['invalid-current-version', 'registry-unavailable', 'invalid-registry-response']),
37
+ }),
38
+ ])
39
+
40
+ export const codexSubagentModelsSchema = z.object({
41
+ available: z.boolean(),
42
+ models: z.array(z.object({
43
+ id: z.string(),
44
+ name: z.string(),
45
+ efforts: z.array(z.string()),
46
+ defaultEffort: z.string().optional(),
47
+ })),
48
+ })
49
+
10
50
  export const presetCatalogSchema = z.object({
11
51
  presets: z.array(z.object({
12
52
  id: z.string(),
@@ -99,6 +139,10 @@ export function buildPresetEditorDescriptors(): readonly InvocationDescriptor[]
99
139
  descriptor('tools', 'id', presetIdSchema, presetToolCatalogSchema),
100
140
  descriptor('prompts', 'id', presetIdSchema, presetPromptCatalogSchema),
101
141
  descriptor('read', 'id', presetIdSchema, presetDefinitionSchema),
142
+ descriptor('proModeGet', 'sessionId', proModeSessionIdSchema, proModeStateSchema),
143
+ descriptor('proModeSet', 'input', proModeSetInputSchema, proModeStateSchema),
144
+ descriptor('updateCheck', undefined, z.unknown(), harnessUpdateResultSchema),
145
+ descriptor('codexSubagentModels', undefined, z.unknown(), codexSubagentModelsSchema),
102
146
  ]
103
147
  }
104
148
 
@@ -3,7 +3,8 @@
3
3
  import type { Context } from '@deepseek-ai/cordis'
4
4
  import z from '@deepseek-ai/schemastery'
5
5
  import type { SettingsNamespace } from '@deepseek-ai/dsh-settings'
6
- import { CODEX_CONTEXT_MAX } from './ui-contracts.ts'
6
+ import { CODEX_CONTEXT_MAX, CODEX_SUBAGENT_DEFAULT_PRESET, supportsApiProMode } from './ui-contracts.ts'
7
+ export { supportsApiProMode }
7
8
  import {
8
9
  DEFAULT_CODEX_PERSONA,
9
10
  DEFAULT_CODEX_SYSTEM_PROMPT,
@@ -19,6 +20,8 @@ export interface CodexSettings {
19
20
  fast: boolean
20
21
  /** Show the Fast mode switch in the conversation composer. */
21
22
  fastModeControlEnabled: boolean
23
+ /** Show the ephemeral per-session API Pro mode switch in the conversation composer. */
24
+ proModeControlEnabled: boolean
22
25
  /** Show the quick context-window control in the conversation composer. */
23
26
  contextWindowControlEnabled: boolean
24
27
  /** Optional context capacity override, in tokens. */
@@ -45,12 +48,21 @@ export interface CodexSettings {
45
48
  remoteCompactionEnabled: boolean
46
49
  /** Show the Codex request/compaction activity indicator. */
47
50
  activityIndicatorEnabled: boolean
51
+ /** Globally register codex_subagent backed by the openai-codex subscription provider. */
52
+ codexSubagentEnabled: boolean
53
+ /** Optional openai-codex model id for codex_subagent (blank uses the first enabled model). */
54
+ codexSubagentModel?: string
55
+ /** Optional reasoning effort id for codex_subagent (blank uses the model default). */
56
+ codexSubagentEffort?: string
57
+ /** Preset for codex_subagent children ('codex-hybrid' by default, or 'inherit'). */
58
+ codexSubagentPreset: string
48
59
  }
49
60
 
50
61
  /** Default settings exposed even before a Codex session is opened. */
51
62
  export const CODEX_SETTINGS_ENTRY: CodexSettings = {
52
63
  fast: false,
53
64
  fastModeControlEnabled: true,
65
+ proModeControlEnabled: true,
54
66
  contextWindowControlEnabled: true,
55
67
  persona: DEFAULT_CODEX_PERSONA,
56
68
  harnessSourcePrompt: DEFAULT_DSH_CORE_SOURCE_PROMPT,
@@ -63,11 +75,14 @@ export const CODEX_SETTINGS_ENTRY: CodexSettings = {
63
75
  hostedWebSearchEnabled: true,
64
76
  remoteCompactionEnabled: true,
65
77
  activityIndicatorEnabled: true,
78
+ codexSubagentEnabled: false,
79
+ codexSubagentPreset: CODEX_SUBAGENT_DEFAULT_PRESET,
66
80
  }
67
81
 
68
82
  export const CODEX_SETTINGS_SCHEMA: z<CodexSettings> = z.object({
69
83
  fast: z.boolean().default(false),
70
84
  fastModeControlEnabled: z.boolean().default(true),
85
+ proModeControlEnabled: z.boolean().default(true),
71
86
  contextWindowControlEnabled: z.boolean().default(true),
72
87
  contextWindow: z.number().step(1).min(1).max(CODEX_CONTEXT_MAX).hidden(),
73
88
  persona: z.string().default(DEFAULT_CODEX_PERSONA),
@@ -81,6 +96,10 @@ export const CODEX_SETTINGS_SCHEMA: z<CodexSettings> = z.object({
81
96
  hostedWebSearchEnabled: z.boolean().default(true),
82
97
  remoteCompactionEnabled: z.boolean().default(true),
83
98
  activityIndicatorEnabled: z.boolean().default(true),
99
+ codexSubagentEnabled: z.boolean().default(false),
100
+ codexSubagentModel: z.string(),
101
+ codexSubagentEffort: z.string(),
102
+ codexSubagentPreset: z.string().default(CODEX_SUBAGENT_DEFAULT_PRESET),
84
103
  })
85
104
 
86
105
  interface SettingsReader {
@@ -7,6 +7,91 @@ export const CODEX_CONTEXT_MAX = 1_000_000
7
7
  export const OPENAI_CODEX_PROVIDER = 'openai-codex'
8
8
  export const OPENAI_CODEX_SETTINGS_NAMESPACE = 'llm-openai-codex'
9
9
  export const OPENAI_CODEX_MODEL_CATALOG_PATH = '/plugins/dsh-codex-connect/models'
10
+ export const CODEX_SUBAGENT_TOOL_NAME = 'codex_subagent'
11
+ export const CODEX_SUBAGENT_DEFAULT_PRESET = 'codex-hybrid'
12
+ export const CODEX_SUBAGENT_PRESET_INHERIT = 'inherit'
13
+
14
+ export interface CodexSubagentModelOption {
15
+ readonly id: string
16
+ readonly name: string
17
+ readonly efforts: readonly string[]
18
+ readonly defaultEffort?: string
19
+ }
20
+
21
+ export interface CodexSubagentModelCatalog {
22
+ readonly available: boolean
23
+ readonly models: readonly CodexSubagentModelOption[]
24
+ }
25
+
26
+ const API_PRO_MODE_MODEL = /^gpt-(?:5\.6|[6-9]|\d{2,})(?:[._-]|$)/i
27
+ const LEGACY_PRO_MODEL_SLUG = /(?:^|[-_.])pro(?:$|[-_.])/i
28
+
29
+ /**
30
+ * Models on the OpenAI Responses API that accept `reasoning.mode = "pro"`.
31
+ * Excludes standalone legacy `*-pro` slugs (e.g. `gpt-5.4-pro`, `gpt-5.5-pro`).
32
+ */
33
+ export function supportsApiProMode(model: unknown): model is string {
34
+ if (typeof model !== 'string') return false
35
+ const trimmed = model.trim()
36
+ if (trimmed.length === 0) return false
37
+ const base = trimmed.includes('/') ? trimmed.slice(trimmed.lastIndexOf('/') + 1) : trimmed
38
+ return API_PRO_MODE_MODEL.test(base) && !LEGACY_PRO_MODEL_SLUG.test(base)
39
+ }
40
+
41
+ export interface LlmProviderRouteProfile {
42
+ readonly api?: string | undefined
43
+ readonly baseURL?: string | undefined
44
+ readonly baseUrl?: string | undefined
45
+ readonly models?: readonly { readonly id?: string; readonly api?: string; readonly baseURL?: string; readonly baseUrl?: string }[] | undefined
46
+ readonly modelOverrides?: Readonly<Record<string, { readonly api?: string; readonly baseURL?: string; readonly baseUrl?: string }>> | undefined
47
+ }
48
+
49
+ export type LlmProvidersMap = Readonly<Record<string, LlmProviderRouteProfile>>
50
+
51
+ export interface LlmProvidersScope {
52
+ getSnapshot(): LlmProvidersMap | undefined
53
+ subscribe(listener: () => void): () => void
54
+ }
55
+
56
+ /** True only when `url` is an HTTPS official OpenAI API endpoint (`api.openai.com`). */
57
+ export function isOfficialOpenAiBaseUrl(url: unknown): boolean {
58
+ if (typeof url !== 'string') return false
59
+ const trimmed = url.trim()
60
+ if (trimmed.length === 0) return false
61
+ try {
62
+ const parsed = new URL(trimmed)
63
+ return parsed.protocol === 'https:' && parsed.hostname.toLowerCase() === 'api.openai.com'
64
+ } catch {
65
+ return false
66
+ }
67
+ }
68
+
69
+ /**
70
+ * True only when `(provider, model)` routes to the official OpenAI Responses API
71
+ * (`https://api.openai.com`) on a Pro-capable GPT-5.6 / 6+ model.
72
+ */
73
+ export function isOfficialOpenAiApiRoute(
74
+ provider: string | undefined,
75
+ model: string | undefined,
76
+ providers?: LlmProvidersMap | undefined,
77
+ ): boolean {
78
+ if (typeof provider !== 'string' || provider.length === 0 || provider === OPENAI_CODEX_PROVIDER) return false
79
+ if (!supportsApiProMode(model)) return false
80
+ const profile = providers?.[provider]
81
+ const override = model !== undefined ? profile?.modelOverrides?.[model] : undefined
82
+ const modelEntry = model !== undefined && Array.isArray(profile?.models)
83
+ ? profile.models.find(item => item?.id === model)
84
+ : undefined
85
+ const effectiveApi = override?.api ?? modelEntry?.api ?? profile?.api
86
+ if (effectiveApi !== undefined && effectiveApi !== 'openai-responses') return false
87
+ const effectiveBaseUrl = override?.baseURL ?? override?.baseUrl
88
+ ?? modelEntry?.baseURL ?? modelEntry?.baseUrl
89
+ ?? profile?.baseURL ?? profile?.baseUrl
90
+ if (typeof effectiveBaseUrl === 'string' && effectiveBaseUrl.trim().length > 0) {
91
+ return isOfficialOpenAiBaseUrl(effectiveBaseUrl)
92
+ }
93
+ return provider === 'openai'
94
+ }
10
95
 
11
96
  export interface ContextWindowBounds {
12
97
  readonly defaultTokens?: number
@@ -169,6 +254,8 @@ export interface CodexConnectScope {
169
254
  subscribe(listener: () => void): () => void
170
255
  setModelOverride(modelId: string, tokens: number | undefined): Promise<void>
171
256
  setNativeCompaction?(enabled: boolean): Promise<void>
257
+ setSearchEnabled?(enabled: boolean): Promise<void>
258
+ setImageGenerationEnabled?(enabled: boolean): Promise<void>
172
259
  }
173
260
 
174
261
  export interface PresetPromptCatalog {