@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,276 @@
1
+ /** A single Settings workspace; the bundle page is only a signpost. */
2
+ import { useState } from 'react'
3
+ import type { Context } from '@deepseek-ai/cordis'
4
+ import type { InjectFace, PropsLocale } from '@deepseek-ai/dsh-client-ui-slots'
5
+ import type {} from '@deepseek-ai/dsh-client-ui-plugin-manager/client'
6
+ import { applyWithSettingsApi } from './index.tsx'
7
+ import type {
8
+ CodexConnectScope,
9
+ CodexConnectSnapshot,
10
+ CodexScope,
11
+ CodexSettings,
12
+ CodexSettingsSnapshot,
13
+ InputSettingsControlInjected,
14
+ } from './index.tsx'
15
+ import {
16
+ nextOpenAICodexOverrides,
17
+ OPENAI_CODEX_SETTINGS_NAMESPACE,
18
+ } from '../contracts/ui-contracts.ts'
19
+ import type { PresetClientRemote } from './preset-manager.tsx'
20
+ import { bindToolPolicy, ToolPolicySection } from './tool-policy.tsx'
21
+ import type { ToolPolicyBinding, ToolPolicyMode } from './tool-policy.tsx'
22
+
23
+ export interface DesktopConfigForm extends Pick<CodexScope, 'getSnapshot' | 'subscribe'> {
24
+ set(field: string, value: unknown): Promise<boolean>
25
+ unset(field: string): Promise<boolean>
26
+ mutate(ops: Array<{ op: 'set'; path: string[]; value: unknown } | { op: 'unset'; path: string[] }>, expectedRevision?: number | string): Promise<boolean>
27
+ }
28
+ interface DesktopSettingsActions extends InputSettingsControlInjected {
29
+ saveSettings(edits: Record<string, unknown>, expectedRevision?: number | string): Promise<void>
30
+ toolPolicy?: ToolPolicyBinding
31
+ }
32
+ interface MirrorNamespaceRow {
33
+ readonly ns: string
34
+ readonly value?: unknown
35
+ readonly base?: unknown
36
+ }
37
+ interface ConfigMirror {
38
+ getSnapshot(): { readonly status?: string; readonly view?: { readonly writable?: boolean; readonly namespaces?: readonly MirrorNamespaceRow[] } }
39
+ subscribe(listener: () => void): () => void
40
+ ensure?(): unknown
41
+ }
42
+ interface DesktopSettingsContext {
43
+ configForms: {
44
+ get(entryId: string): DesktopConfigForm
45
+ describe?(): ConfigMirror
46
+ whileServed(namespaces: string[], register: () => () => void): () => void
47
+ }
48
+ }
49
+ function asRecord(value: unknown): Record<string, unknown> | undefined {
50
+ return typeof value === 'object' && value !== null && !Array.isArray(value)
51
+ ? value as Record<string, unknown>
52
+ : undefined
53
+ }
54
+ function asOverrides(value: unknown): Record<string, number | null> | undefined {
55
+ const record = asRecord(value)
56
+ if (record === undefined) return undefined
57
+ const out: Record<string, number | null> = {}
58
+ for (const [k, v] of Object.entries(record)) {
59
+ if (v === null || (typeof v === 'number' && Number.isSafeInteger(v) && v > 0)) out[k] = v
60
+ }
61
+ return out
62
+ }
63
+ export function bindCodexConnectScope(configForms: DesktopSettingsContext['configForms']): CodexConnectScope {
64
+ const form = configForms.get(OPENAI_CODEX_SETTINGS_NAMESPACE)
65
+ const mirror = configForms.describe?.()
66
+ void Promise.resolve(mirror?.ensure?.()).catch(() => {})
67
+ let lastFormSnap: unknown
68
+ let lastMirrorSnap: unknown
69
+ let projected: CodexConnectSnapshot = { status: 'loading', writable: false }
70
+ const getSnapshot = (): CodexConnectSnapshot => {
71
+ const formSnap = form.getSnapshot() as CodexSettingsSnapshot & { readonly base?: Record<string, unknown> }
72
+ const mirrorSnap = mirror?.getSnapshot()
73
+ if (formSnap === lastFormSnap && mirrorSnap === lastMirrorSnap) return projected
74
+ lastFormSnap = formSnap
75
+ lastMirrorSnap = mirrorSnap
76
+ const formRecord = formSnap.status === 'ready' ? asRecord(formSnap.value) : undefined
77
+ if (formRecord !== undefined) {
78
+ return projected = {
79
+ status: 'ready',
80
+ writable: formSnap.writable,
81
+ overrides: asOverrides(formRecord.contextWindowOverrides),
82
+ baseOverrides: asOverrides(asRecord(formSnap.base)?.contextWindowOverrides),
83
+ ...(typeof formRecord.enableNativeCompaction === 'boolean'
84
+ ? { nativeCompaction: formRecord.enableNativeCompaction }
85
+ : {}),
86
+ }
87
+ }
88
+ const view = mirrorSnap?.view
89
+ if (view !== undefined) {
90
+ const row = view.namespaces?.find(candidate => candidate.ns === OPENAI_CODEX_SETTINGS_NAMESPACE)
91
+ const rowRecord = row === undefined ? undefined : asRecord(row.value)
92
+ if (row === undefined || rowRecord === undefined) return projected = { status: 'unavailable', writable: false }
93
+ return projected = {
94
+ status: 'ready',
95
+ writable: view.writable ?? formSnap.writable,
96
+ overrides: asOverrides(rowRecord.contextWindowOverrides),
97
+ baseOverrides: asOverrides(asRecord(row.base)?.contextWindowOverrides),
98
+ ...(typeof rowRecord.enableNativeCompaction === 'boolean'
99
+ ? { nativeCompaction: rowRecord.enableNativeCompaction }
100
+ : {}),
101
+ }
102
+ }
103
+ return projected = { status: formSnap.status, writable: formSnap.writable }
104
+ }
105
+ return {
106
+ getSnapshot,
107
+ subscribe: listener => {
108
+ const stopForm = form.subscribe(listener)
109
+ const stopMirror = mirror?.subscribe(listener)
110
+ return () => { stopForm(); stopMirror?.() }
111
+ },
112
+ setModelOverride: async (modelId, tokens) => {
113
+ const snap = getSnapshot()
114
+ const next = nextOpenAICodexOverrides(snap.overrides, snap.baseOverrides, modelId, tokens)
115
+ const accepted = next === undefined
116
+ ? await form.unset('contextWindowOverrides')
117
+ : await form.set('contextWindowOverrides', next)
118
+ if (!accepted) throw new Error('The host did not accept the settings change.')
119
+ },
120
+ setNativeCompaction: async enabled => {
121
+ const accepted = await form.set('enableNativeCompaction', enabled)
122
+ if (!accepted) throw new Error('The host did not accept the settings change.')
123
+ },
124
+ }
125
+ }
126
+ export function adaptConfigForm(form: Pick<DesktopConfigForm, 'getSnapshot' | 'subscribe' | 'set' | 'unset'>): CodexScope {
127
+ const accepted = async (result: Promise<boolean>) => { if (!await result) throw new Error('The host did not accept the settings change.') }
128
+ return { getSnapshot: () => form.getSnapshot(), subscribe: listener => form.subscribe(listener),
129
+ set: (field, value) => accepted(form.set(field, value)), unset: field => accepted(form.unset(field)) }
130
+ }
131
+ export async function saveDesktopSettings(form: Pick<DesktopConfigForm, 'mutate'>, edits: Record<string, unknown>, expectedRevision?: number | string): Promise<void> {
132
+ const ops = Object.entries(edits).map(([field, value]) => value === undefined ? { op: 'unset' as const, path: [field] } : { op: 'set' as const, path: [field], value })
133
+ if (!ops.length) return
134
+ const accepted = expectedRevision === undefined ? await form.mutate(ops) : await form.mutate(ops, expectedRevision)
135
+ if (!accepted) throw new Error('The host did not accept the settings change.')
136
+ }
137
+
138
+ type DesktopSettingsProps = InjectFace<DesktopSettingsActions> & PropsLocale<'codex'>
139
+ type SettingsPage = 'tools' | 'runtime'
140
+ const desktopStyles = `
141
+ .codex-harness-settings { max-width:760px; min-width:0; font-size:13px; color:var(--dsw-alias-label-primary); }
142
+ .codex-harness-settings h3 { font-size:14px; margin:0 0 10px; }
143
+ .codex-harness-settings .codex-harness-nav { display:flex; align-items:flex-end; gap:20px; margin-bottom:14px; border-bottom:0.5px solid var(--dsw-alias-border-l2); }
144
+ .codex-harness-settings .codex-harness-nav button { position:relative; border:0; padding:7px 1px 9px; background:transparent; color:var(--dsw-alias-label-tertiary, var(--dsw-alias-label-secondary)); font:inherit; font-size:13px; line-height:20px; cursor:pointer; }
145
+ .codex-harness-settings .codex-harness-nav button[aria-pressed=true] { color:var(--dsw-alias-label-primary); font-weight:500; }
146
+ .codex-harness-settings .codex-harness-nav button[aria-pressed=true]::after { position:absolute; right:0; bottom:-1px; left:0; height:2px; border-radius:2px 2px 0 0; background:var(--dsw-alias-label-primary); content:''; }
147
+ .codex-harness-settings button { box-sizing:border-box; min-width:0; max-width:100%; font:inherit; color:inherit; }
148
+ .codex-harness-settings .codex-harness-btn { background:var(--dsw-alias-bg-layer-2); border:0.5px solid var(--dsw-alias-border-l3, var(--dsw-alias-border-l2)); border-radius:var(--dsw-radius-md, 8px); padding:6px 12px; font-size:12px; cursor:pointer; }
149
+ .codex-harness-settings .codex-harness-btn:disabled { opacity:.48; cursor:default; }
150
+ .codex-harness-settings .codex-harness-primary { background:var(--dsw-alias-label-primary); color:var(--dsw-alias-bg-base); border-color:transparent; font-weight:500; }
151
+ .codex-harness-settings :is(input,button):focus-visible { outline:2px solid var(--dsw-focus-ring-color, var(--dsw-alias-brand-primary)); outline-offset:2px; }
152
+ .codex-harness-settings fieldset { min-width:0; border:0; padding:0; margin:0; display:flex; flex-direction:column; gap:12px; }
153
+ .codex-harness-settings .codex-harness-grid { display:grid; grid-template-columns:repeat(auto-fit,minmax(min(100%,260px),1fr)); gap:12px; }
154
+ .codex-harness-settings .codex-harness-card { border:0.5px solid var(--dsw-alias-settings-card-stroke, var(--dsw-alias-border-l2)); border-radius:var(--dsw-radius-xl, 12px); background:var(--dsw-alias-settings-card-fill, var(--dsw-alias-bg-layer-1)); padding:12px 16px; }
155
+ .codex-harness-settings .codex-harness-group h4 { margin:0 0 6px; font-size:12px; font-weight:600; color:var(--dsw-alias-label-secondary); }
156
+ .codex-harness-settings .codex-harness-setting-row { min-width:0; display:flex; gap:12px; justify-content:space-between; align-items:center; padding:8px 0; border-bottom:0.5px solid var(--dsw-alias-border-l1); }
157
+ .codex-harness-settings .codex-harness-setting-row:last-child { border-bottom:0; }
158
+ .codex-harness-settings .codex-harness-note { margin:0 0 12px; color:var(--dsw-alias-label-secondary); font-size:12px; line-height:1.5; }
159
+ .codex-harness-settings .codex-harness-actions { display:flex; gap:8px; flex-wrap:wrap; margin-top:4px; }
160
+ .codex-harness-settings input[role=switch] { appearance:none; width:34px; height:20px; border:0.5px solid var(--dsw-alias-border-l3, var(--dsw-alias-border-l2)); border-radius:16px; background:var(--dsw-alias-bg-layer-2); position:relative; cursor:pointer; flex-shrink:0; margin:0; transition:background .15s; }
161
+ .codex-harness-settings input[role=switch]:before { content:''; position:absolute; width:14px; height:14px; top:2.5px; left:2.5px; border-radius:50%; background:var(--dsw-alias-label-secondary); transition:left .15s, background .15s; }
162
+ .codex-harness-settings input[role=switch]:checked { background:var(--dsw-alias-label-primary); border-color:transparent; }
163
+ .codex-harness-settings input[role=switch]:checked:before { left:16.5px; background:var(--dsw-alias-bg-base); }
164
+ `
165
+
166
+ /** There is intentionally no second editable form on a bundle detail page. */
167
+ export function DesktopSettingsCard({ t }: DesktopSettingsProps & { view: 'summary' | 'page' }) {
168
+ return <section><p>{t('settingsBundleSummary')}</p><p>{t('settingsBundlePath')}</p></section>
169
+ }
170
+
171
+ /** Kept mounted while inactive, so switching pages preserves runtime drafts. */
172
+ export function RuntimeSettingsEditor({ active, ...props }: DesktopSettingsProps & { active: boolean }) {
173
+ const { useSettings, saveSettings, t } = props
174
+ const snapshot = useSettings(state => state)
175
+ const [draft, setDraft] = useState<{ edits: Record<string, unknown>; revision: number | string | undefined }>()
176
+ const [saving, setSaving] = useState(false)
177
+ const [error, setError] = useState('')
178
+ const edits = draft?.edits ?? {}
179
+ const value = (field: keyof CodexSettings) => Object.hasOwn(edits, field) ? edits[field] === undefined ? snapshot.base?.[field] : edits[field] : snapshot.value?.[field]
180
+ const edit = (field: string, next: unknown) => {
181
+ setError(''); setDraft(current => ({ edits: { ...current?.edits, [field]: next }, revision: current === undefined ? snapshot.revision : current.revision }))
182
+ }
183
+ const groups = [
184
+ { label: 'globalGroupRequest', fields: [['fast', 'fast'], ['hostedWebSearchEnabled', 'settingsPreferHostedSearch'], ['remoteCompactionEnabled', 'settingsPreferRemoteCompaction']] },
185
+ { label: 'globalGroupDisplay', fields: [['contextWindowControlEnabled', 'contextWindowControl'], ['fastModeControlEnabled', 'fastModeControl'], ['activityIndicatorEnabled', 'capabilityActivity']] },
186
+ ] as const
187
+ if (!active) return null
188
+ return <section aria-label={t('settingsRuntimePage')}>
189
+ <h3>{t('settingsRuntimePage')}<span className="codex-harness-note"> · {t('settingsRuntimeScope')}</span></h3>
190
+ <form onSubmit={event => {
191
+ event.preventDefault(); if (saving || draft === undefined || !snapshot.writable || snapshot.status !== 'ready') return
192
+ setSaving(true); setError(''); const submitted = draft
193
+ void saveSettings(submitted.edits, submitted.revision).then(() => setDraft(current => current === submitted ? undefined : current))
194
+ .catch(() => setError(t('settingsSharedFailed'))).finally(() => setSaving(false))
195
+ }}>
196
+ <fieldset disabled={!snapshot.writable || snapshot.status !== 'ready' || saving}>
197
+ <div className="codex-harness-grid">{groups.map(group => <div key={group.label} className="codex-harness-card codex-harness-group">
198
+ <h4>{t(group.label)}</h4>{group.fields.map(([field, label]) => <label key={field} className="codex-harness-setting-row">
199
+ <span>{t(label)}</span><input type="checkbox" role="switch" aria-label={t(label)} aria-checked={Boolean(value(field) ?? (field !== 'fast'))}
200
+ checked={Boolean(value(field) ?? (field !== 'fast'))} onChange={event => edit(field, event.target.checked)} />
201
+ </label>)}
202
+ </div>)}</div>
203
+ <div className="codex-harness-actions">
204
+ <button className="codex-harness-btn codex-harness-primary" type="submit" disabled={!Object.keys(edits).length}>{t(saving ? 'promptSaving' : 'settingsSaveRuntime')}</button>
205
+ <button className="codex-harness-btn" type="button" disabled={draft === undefined} onClick={() => { setDraft(undefined); setError('') }}>{t('promptDiscard')}</button>
206
+ </div>
207
+ </fieldset>
208
+ </form>
209
+ {!snapshot.writable && <p className="codex-harness-note">{t('promptReadOnly')}</p>}{error && <p role="alert">{error}</p>}
210
+ </section>
211
+ }
212
+
213
+ export function CodexSettingsTab(props: DesktopSettingsProps & { initialPage?: SettingsPage }) {
214
+ const { toolPolicy, presetManager, t } = props
215
+ const [page, setPage] = useState<SettingsPage>(props.initialPage ?? 'tools')
216
+ const mode: ToolPolicyMode = page === 'tools' ? 'tools' : 'inactive'
217
+ return <section className="codex-harness-settings">
218
+ <style>{desktopStyles}</style>
219
+ <nav className="codex-harness-nav" aria-label={t('settingsTabLabel')}>
220
+ <button type="button" aria-pressed={page === 'tools'} onClick={() => setPage('tools')}>{t('settingsToolsPage')}</button>
221
+ <button type="button" aria-pressed={page === 'runtime'} onClick={() => setPage('runtime')}>{t('settingsRuntimePage')}</button>
222
+ </nav>
223
+ {toolPolicy !== undefined && <ToolPolicySection binding={toolPolicy} presetManager={presetManager} mode={mode} t={t} />}
224
+ <RuntimeSettingsEditor {...props} active={page === 'runtime'} />
225
+ </section>
226
+ }
227
+
228
+ export const inject = ['commandUi', 'sessions', 'slots', 'locale', 'configForms', 'remote']
229
+ export function apply(ctx: Context): void {
230
+ let form: DesktopConfigForm
231
+ let connectScope: CodexConnectScope | undefined
232
+ const getCodexConnectScope = (): CodexConnectScope | undefined => {
233
+ try { return connectScope ??= bindCodexConnectScope((ctx as unknown as DesktopSettingsContext).configForms) }
234
+ catch { return undefined }
235
+ }
236
+ applyWithSettingsApi(ctx, {
237
+ bind: host => { form = (host as unknown as DesktopSettingsContext).configForms.get('codex'); return adaptConfigForm(form) },
238
+ getCodexConnectScope,
239
+ register: (host, settings, manager) => {
240
+ const desktop = host as unknown as DesktopSettingsContext
241
+ const presetManager = { ...manager, remote: (host as unknown as { remote: PresetClientRemote }).remote }
242
+ const t = host.locale.bind('codex'); const toolPolicy = bindToolPolicy(host, host.configForms)
243
+ const injected = (): DesktopSettingsActions => ({
244
+ hooks: { settings },
245
+ setSetting: (field, value) => settings.set(field, value),
246
+ unsetSetting: field => settings.unset(field),
247
+ presetManager,
248
+ toolPolicy,
249
+ saveSettings: async (edits, revision) => {
250
+ await saveDesktopSettings(form, edits, revision)
251
+ if (typeof edits.remoteCompactionEnabled === 'boolean') {
252
+ const scope = getCodexConnectScope()
253
+ if (scope?.setNativeCompaction !== undefined && scope.getSnapshot().writable) {
254
+ await scope.setNativeCompaction(edits.remoteCompactionEnabled).catch(() => {})
255
+ }
256
+ }
257
+ },
258
+ })
259
+ return desktop.configForms.whileServed(['codex'], () => {
260
+ const disposers: Array<() => void> = []; const dispose = () => { for (const off of disposers.splice(0).reverse()) off() }
261
+ try {
262
+ disposers.push(host.slots.inject('settings.plugins.tab', () => host.slots.register({ name: 'settings.plugins.tab', id: 'codex-harness', order: 30,
263
+ label: () => t('settingsTabLabel'), locale: 'codex', inject: injected }, CodexSettingsTab)))
264
+ disposers.push(host.slots.inject('plugins.bundle.config', () => host.slots.register({
265
+ name: 'plugins.bundle.config',
266
+ key: '@shuind/dsh-codex-harness',
267
+ locale: 'codex',
268
+ inject: injected,
269
+ }, DesktopSettingsCard)))
270
+ return dispose
271
+ } catch (error) { dispose(); throw error }
272
+ })
273
+ },
274
+ })
275
+ }
276
+ export default { inject, apply }
@@ -0,0 +1,391 @@
1
+ /** Browser controls, /compact decorator, and live activity line for Codex Harness. */
2
+
3
+ import { useEffect, useState } from 'react'
4
+ import type { HostObservable, InjectFace, PropsLocale, PropsRuntime } from '@deepseek-ai/dsh-client-ui-slots'
5
+ import type { Context } from '@deepseek-ai/cordis'
6
+ import type {} from '@deepseek-ai/dsh-client-locale/client'
7
+ import type {} from '@deepseek-ai/dsh-client-ui-conversation/client'
8
+ import type {} from '@deepseek-ai/dsh-client-ui-settings/client'
9
+ import type {} from '@deepseek-ai/dsh-client-ui-renderer/client'
10
+ import type {} from '@deepseek-ai/dsh-client-ui-session/client'
11
+ import type {} from '@deepseek-ai/dsh-api-remotes/client'
12
+ import type { TypertClientRemote } from '@deepseek-ai/dsh-typert-protocol'
13
+ import { OPENAI_CODEX_PROVIDER } from '../contracts/ui-contracts.ts'
14
+ import type {
15
+ CodexActivity,
16
+ CodexConnectScope,
17
+ CodexConnectSnapshot,
18
+ ModelDirectorySnapshot,
19
+ ModelDirectoryStore,
20
+ } from '../contracts/ui-contracts.ts'
21
+ import { modelActivity, sameModelActivity } from './activity.ts'
22
+ import presetEditorRemote from '../contracts/preset-editor-schema.ts'
23
+ import { toolPolicyEn, toolPolicyZh } from './tool-policy.tsx'
24
+ import { ContextWindowControl, isGptModelName, pillStyle, useModelDirectory } from './preset-manager.tsx'
25
+ import type { PresetClientRemote, PresetManagerActions } from './preset-manager.tsx'
26
+ export { ContextWindowControl }
27
+ export type { CodexConnectScope, CodexConnectSnapshot, ModelDirectorySnapshot, ModelDirectoryStore }
28
+
29
+ interface CompactCommandOption {
30
+ id: string
31
+ label: string
32
+ detail?: string
33
+ }
34
+
35
+ interface CompactCommandSession {
36
+ command(line: string): Promise<{
37
+ ok: true
38
+ value: { matched: boolean }
39
+ } | {
40
+ ok: false
41
+ error: { code: string; message: string }
42
+ }>
43
+ }
44
+
45
+ interface CompactCommandUi {
46
+ decorate(decoration: {
47
+ name: string
48
+ available(session: { sessionId: string }): boolean
49
+ ui: {
50
+ kind: 'popupSelect'
51
+ options(session: { sessionId: string }, signal: AbortSignal): Promise<readonly CompactCommandOption[]>
52
+ onSelect(option: CompactCommandOption, session: { sessionId: string }): void | Promise<void>
53
+ }
54
+ }): () => void
55
+ }
56
+
57
+ interface CompactCommandSessions {
58
+ binding(sessionId: string): { session: CompactCommandSession } | undefined
59
+ scope?(sessionId: string): {
60
+ get?(name: string): {
61
+ input?: {
62
+ for?(actx: unknown): { notify?(level: 'error' | 'info' | 'warning', text: string): void }
63
+ }
64
+ } | undefined
65
+ } | undefined
66
+ }
67
+
68
+ function notifyCompactError(sessions: CompactCommandSessions, sessionId: string, text: string): void {
69
+ const actx = sessions.scope?.(sessionId)
70
+ actx?.get?.('conversation')?.input?.for?.(actx)?.notify?.('error', text)
71
+ }
72
+
73
+ const NS = 'codex' as const
74
+ const FAST_FALLBACK_SLOT = 'conversation.input.right' as const
75
+
76
+ export interface CodexSettings {
77
+ fast: boolean
78
+ fastModeControlEnabled: boolean
79
+ contextWindowControlEnabled: boolean
80
+ contextWindow?: number
81
+ persona?: string
82
+ harnessSourcePrompt?: string
83
+ webSurfacePrompt?: string
84
+ systemPrompt?: string
85
+ promptEnabled: boolean
86
+ terminalToolsEnabled: boolean
87
+ patchToolEnabled: boolean
88
+ planToolEnabled: boolean
89
+ hostedWebSearchEnabled: boolean
90
+ remoteCompactionEnabled: boolean
91
+ activityIndicatorEnabled: boolean
92
+ }
93
+
94
+ /** Observable ConfigForms settings snapshot shared with the desktop adapter. */
95
+ export interface CodexSettingsSnapshot {
96
+ readonly status: string
97
+ readonly value?: CodexSettings | undefined
98
+ readonly base?: Partial<CodexSettings> | undefined
99
+ readonly user?: Partial<CodexSettings> | undefined
100
+ readonly revision?: number | string | undefined
101
+ readonly writable: boolean
102
+ }
103
+
104
+ export interface CodexScope extends HostObservable<CodexSettingsSnapshot> {
105
+ set(field: string, value: unknown): Promise<void>
106
+ unset(field: string): Promise<void>
107
+ }
108
+
109
+ const en = {
110
+ ...toolPolicyEn,
111
+ fast: 'Fast mode',
112
+ fastModeControl: 'Show fast mode control',
113
+ contextWindowControl: 'Show context window control',
114
+ fastOn: 'Fast mode on (priority tier)',
115
+ fastOff: 'Fast mode off',
116
+ fastStateOn: 'On',
117
+ fastStateOff: 'Off',
118
+ contextSize: 'Context size',
119
+ contextShortDefault: 'Ctx',
120
+ contextDefaultOption: 'Default',
121
+ contextCustomPlaceholder: '≥16k (e.g. 64)',
122
+ contextApply: 'Set',
123
+ compactRemote: 'Remote compaction',
124
+ compactRemoteHint: 'Use the provider remote compaction endpoint first.',
125
+ compactLocal: 'Local compaction',
126
+ compactLocalHint: 'Use the DSH text-summary compaction engine directly.',
127
+ capabilityActivity: 'Activity indicator',
128
+ promptDiscard: 'Discard',
129
+ promptSaving: 'Saving...',
130
+ promptReadOnly: 'This settings document is read-only.',
131
+ activityCompacting: 'Compacting context...',
132
+ activityRequestingModel: 'Requesting model...',
133
+ activityModelReply: 'Model replying...',
134
+ } as const
135
+
136
+ const zh: Record<keyof typeof en, string> = {
137
+ ...toolPolicyZh,
138
+ fastModeControl: '显示快速模式开关',
139
+ contextWindowControl: '显示上下文大小快捷按钮',
140
+ fast: '快速模式',
141
+ fastOn: '快速模式已开启(优先通道)',
142
+ fastOff: '快速模式已关闭',
143
+ fastStateOn: '开',
144
+ fastStateOff: '关',
145
+ contextSize: '上下文大小',
146
+ contextShortDefault: '上下文',
147
+ contextDefaultOption: '默认',
148
+ contextCustomPlaceholder: '≥16k (如 64)',
149
+ contextApply: '确定',
150
+ compactRemote: '远程压缩',
151
+ compactRemoteHint: '优先使用提供商的远程压缩端点。',
152
+ compactLocal: '本地压缩',
153
+ compactLocalHint: '直接使用 DSH 文本摘要压缩引擎。',
154
+ capabilityActivity: '活动状态',
155
+ promptDiscard: '放弃',
156
+ promptSaving: '保存中...',
157
+ promptReadOnly: '当前设置文件为只读。',
158
+ activityCompacting: '正在压缩上下文...',
159
+ activityRequestingModel: '请求中...',
160
+ activityModelReply: '回复中...',
161
+ }
162
+
163
+ type CodexKey = keyof typeof en
164
+
165
+ declare module '@deepseek-ai/dsh-client-ui-slots' {
166
+ interface LocaleNamespaceMap {
167
+ codex: CodexKey
168
+ }
169
+ }
170
+
171
+ interface ModelDirectoriesService {
172
+ directoryFor(sessionId: unknown): { readonly store?: ModelDirectoryStore } | undefined
173
+ }
174
+
175
+ /** Show the fallback Fast toggle only when the session uses a non-Codex-Connect GPT model. */
176
+ export function isFallbackFastEligible(snapshot: ModelDirectorySnapshot | undefined, hasDirectory: boolean): boolean {
177
+ if (!hasDirectory) return true
178
+ if (snapshot?.status !== 'ready' || snapshot.current === undefined) return false
179
+ return snapshot.current.provider !== OPENAI_CODEX_PROVIDER && isGptModelName(snapshot.current.model)
180
+ }
181
+
182
+ export interface InputSettingsControlInjected {
183
+ hooks: { settings: HostObservable<ReturnType<CodexScope['getSnapshot']>> }
184
+ setSetting: (field: string, value: unknown) => Promise<void>
185
+ unsetSetting: (field: string) => Promise<void>
186
+ presetManager: PresetManagerActions
187
+ modelDirectory?: ModelDirectoryStore | undefined
188
+ getCodexConnectScope?: (() => CodexConnectScope | undefined) | undefined
189
+ }
190
+
191
+ type InputRightProps = Pick<PropsRuntime<'conversation.input.right'>, 'sessionId' | 'useSessions'>
192
+ & InjectFace<InputSettingsControlInjected>
193
+ & PropsLocale<'codex'>
194
+
195
+ export function FastModeFallback(props: InputRightProps) {
196
+ const { useSettings, setSetting, modelDirectory, t } = props
197
+ const dirSnapshot = useModelDirectory(modelDirectory)
198
+ const snapshot = useSettings(state => state as { value?: CodexSettings; writable: boolean })
199
+ const visible = snapshot.value?.fastModeControlEnabled ?? true
200
+ const fast = snapshot.value?.fast ?? false
201
+ if (!visible || !isFallbackFastEligible(dirSnapshot, modelDirectory !== undefined)) return null
202
+ return (
203
+ <button
204
+ type="button" role="switch" disabled={snapshot.writable === false} aria-checked={fast}
205
+ aria-label={fast ? t('fastOn') : t('fastOff')} title={fast ? t('fastOn') : t('fastOff')}
206
+ onClick={() => { void setSetting('fast', !fast) }}
207
+ style={pillStyle(fast, snapshot.writable !== false)}
208
+ >
209
+ <span>{t('fast')}</span>
210
+ <span style={{ color: 'var(--dsw-alias-label-secondary)', fontSize: 11 }}>{fast ? t('fastStateOn') : t('fastStateOff')}</span>
211
+ </button>
212
+ )
213
+ }
214
+
215
+ export function ComposerControls(props: InputRightProps) {
216
+ return <><ContextWindowControl {...props} /><FastModeFallback {...props} /></>
217
+ }
218
+
219
+ type ActivityProps = PropsRuntime<'conversation.input.dock'>
220
+ & InjectFace<InputSettingsControlInjected>
221
+ & PropsLocale<'codex'>
222
+
223
+ type CodexActivityReader = (key: 'codexActivity') => CodexActivity | null | undefined
224
+ type ActivityFallback = ReturnType<typeof modelActivity>
225
+
226
+ function elapsedSeconds(startedAt: number, now: number): number {
227
+ return Math.max(0, Math.floor((now - startedAt) / 1_000))
228
+ }
229
+
230
+ /** Prefer the session snapshot when a projection has not emitted an open phase yet. */
231
+ export function resolveActivity(
232
+ projectedActivity: CodexActivity | null | undefined,
233
+ fallbackActivity: ActivityFallback,
234
+ ): CodexActivity | null {
235
+ if (projectedActivity === null) return fallbackActivity ?? null
236
+ return projectedActivity ?? fallbackActivity ?? null
237
+ }
238
+
239
+ export function ActivityLine({
240
+ sessionId: _sessionId, useSession, useSessions: _useSessions, useProjection, useSettings, t,
241
+ }: ActivityProps) {
242
+ const settings = useSettings(state => state as { value?: CodexSettings })
243
+ const enabled = settings.value?.activityIndicatorEnabled ?? true
244
+ const projectedActivity = (useProjection as unknown as CodexActivityReader)('codexActivity')
245
+ const fallbackActivity = useSession(modelActivity, sameModelActivity)
246
+ const activity = resolveActivity(projectedActivity, fallbackActivity)
247
+ const [now, setNow] = useState(() => Date.now())
248
+
249
+ useEffect(() => {
250
+ if (!enabled || activity === undefined || activity === null) return undefined
251
+ setNow(Date.now())
252
+ const timer = setInterval(() => { setNow(Date.now()) }, 1_000)
253
+ return () => clearInterval(timer)
254
+ }, [enabled, activity?.activity, activity?.startedAt])
255
+
256
+ if (!enabled || activity === undefined || activity === null) return null
257
+ const label = activity.activity === 'compaction'
258
+ ? t('activityCompacting')
259
+ : activity.activity === 'model-reply'
260
+ ? t('activityModelReply')
261
+ : t('activityRequestingModel')
262
+
263
+ return (
264
+ <span
265
+ data-codex-activity
266
+ aria-live="polite"
267
+ style={{
268
+ boxSizing: 'border-box',
269
+ display: 'flex',
270
+ alignItems: 'center',
271
+ flex: 'none',
272
+ gap: 6,
273
+ width: 'calc(100% - 2 * var(--dsh-composer-side-clearance, 16px) - 4 * var(--dsh-composer-dock-inset, 8px))',
274
+ maxWidth: 'calc(var(--dsh-composer-card-max-width, 952px) - 4 * var(--dsh-composer-dock-inset, 8px))',
275
+ minWidth: 0,
276
+ minHeight: 22,
277
+ margin: '0 auto',
278
+ padding: '0 4px',
279
+ color: 'var(--dsw-alias-label-secondary)',
280
+ fontSize: 12,
281
+ lineHeight: '20px',
282
+ whiteSpace: 'nowrap',
283
+ pointerEvents: 'none',
284
+ }}
285
+ >
286
+ <span
287
+ aria-hidden="true"
288
+ style={{
289
+ width: 5,
290
+ height: 5,
291
+ flex: '0 0 auto',
292
+ borderRadius: '50%',
293
+ background: 'var(--dsw-alias-brand-primary)',
294
+ opacity: 0.55,
295
+ }}
296
+ />
297
+ <span style={{ minWidth: 0, overflow: 'hidden', textOverflow: 'ellipsis' }}>{label}</span>
298
+ <span aria-hidden="true" style={{ flex: '0 0 auto', fontVariantNumeric: 'tabular-nums' }}>
299
+ {'\u00b7'} {elapsedSeconds(activity.startedAt, now)}s
300
+ </span>
301
+ </span>
302
+ )
303
+ }
304
+
305
+ function createPresetManager(ctx: Context): PresetManagerActions {
306
+ const remote = (ctx as unknown as { remote?: TypertClientRemote }).remote
307
+ const ready: Promise<void> = remote === undefined
308
+ ? Promise.resolve()
309
+ : remote.$mount(presetEditorRemote).then(dispose => {
310
+ ctx.effect(() => () => { void dispose() }, 'codex client: preset editor remote')
311
+ })
312
+ void ready.catch(() => {})
313
+ return {
314
+ remote: remote as unknown as PresetClientRemote,
315
+ ready,
316
+ }
317
+ }
318
+
319
+ /** Mount request controls and the plugin settings card through shared slots. */
320
+ export interface ClientSettingsApi {
321
+ bind(ctx: Context): CodexScope
322
+ getCodexConnectScope?: () => CodexConnectScope | undefined
323
+ register(ctx: Context, settings: CodexScope, manager: PresetManagerActions): () => void
324
+ }
325
+
326
+ export function applyWithSettingsApi(ctx: Context, api: ClientSettingsApi): void {
327
+ ctx.effect(() => ctx.locale.register(NS, { en, zh }), 'codex client: dictionaries')
328
+ const commandUi = ctx.get('commandUi') as CompactCommandUi
329
+ const sessions = ctx.get('sessions') as unknown as CompactCommandSessions
330
+ const t = ctx.locale.bind(NS)
331
+ const sessionFor = (session: { sessionId: string }): CompactCommandSession | undefined =>
332
+ sessions.binding(session.sessionId)?.session
333
+ ctx.effect(() => commandUi.decorate({
334
+ name: 'compact',
335
+ available: session => sessionFor(session) !== undefined,
336
+ ui: {
337
+ kind: 'popupSelect',
338
+ options: async () => [
339
+ { id: 'remote', label: t('compactRemote'), detail: t('compactRemoteHint') },
340
+ { id: 'local', label: t('compactLocal'), detail: t('compactLocalHint') },
341
+ ],
342
+ onSelect: (option, session) => {
343
+ const live = sessionFor(session)
344
+ if (live === undefined) throw new Error('this session is not materialized yet')
345
+ void live.command(`/compact ${option.id}`).then(result => {
346
+ if (!result.ok) {
347
+ notifyCompactError(sessions, session.sessionId, `compact failed: ${result.error.code}: ${result.error.message}`)
348
+ return
349
+ }
350
+ if (!result.value.matched) {
351
+ notifyCompactError(sessions, session.sessionId, 'the host offers no /compact command')
352
+ }
353
+ }, error => {
354
+ notifyCompactError(sessions, session.sessionId, error instanceof Error ? error.message : String(error))
355
+ })
356
+ },
357
+ },
358
+ }), 'codex client: /compact mode picker')
359
+ const settings = api.bind(ctx)
360
+ const presetManager = createPresetManager(ctx)
361
+ const injected = () => ({
362
+ hooks: { settings },
363
+ setSetting: (field: string, value: unknown) => settings.set(field, value),
364
+ unsetSetting: (field: string) => settings.unset(field),
365
+ presetManager,
366
+ })
367
+ ctx.slots.inject(FAST_FALLBACK_SLOT, () => ctx.slots.register({
368
+ name: FAST_FALLBACK_SLOT,
369
+ id: 'codex-fast',
370
+ order: 0,
371
+ locale: NS,
372
+ inject: (sessionId?: unknown) => ({
373
+ ...injected(),
374
+ getCodexConnectScope: api.getCodexConnectScope,
375
+ modelDirectory: sessionId === undefined
376
+ ? undefined
377
+ : ((ctx as unknown as { get(key: string): ModelDirectoriesService | undefined }).get('modelDirectories'))?.directoryFor(sessionId)?.store,
378
+ }),
379
+ }, ComposerControls))
380
+ ctx.slots.inject('conversation.input.dock', () => ctx.slots.register({
381
+ name: 'conversation.input.dock',
382
+ id: 'codex-activity',
383
+ order: -100,
384
+ locale: NS,
385
+ inject: injected,
386
+ }, ActivityLine))
387
+ ctx.inject(
388
+ ['remote', 'remote.codexPresetEditor'],
389
+ settingsCtx => api.register(settingsCtx, settings, presetManager),
390
+ )
391
+ }