@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.
- package/CHANGELOG.md +185 -0
- package/README.md +38 -50
- package/RELEASE.md +61 -0
- package/assets/codex.svg +5 -0
- package/cordis.patch.yml +181 -6
- package/docs/preset-library.md +33 -23
- package/docs/tool-policy-benchmark.json +310 -0
- package/docs/tool-policy.md +148 -0
- package/lib/client.js +4774 -2416
- package/lib/compact-command.js +416 -0
- package/lib/compaction.js +141 -12
- package/lib/hybrid-executor.js +1196 -0
- package/lib/index.js +3658 -2334
- package/lib/preferences.js +117 -0
- package/lib/tool-policy.js +2422 -0
- package/lib/typert.js +86 -79
- package/lib/types/client/activity.d.ts +33 -9
- package/lib/types/client/activity.js +4 -3
- package/lib/types/client/desktop.d.ts +67 -0
- package/lib/types/client/desktop.js +229 -0
- package/lib/types/client/index.d.ts +207 -110
- package/lib/types/client/index.js +99 -492
- package/lib/types/client/policy-drafts.d.ts +25 -0
- package/lib/types/client/policy-drafts.js +47 -0
- package/lib/types/client/policy-locale.d.ts +260 -0
- package/lib/types/client/policy-locale.js +357 -0
- package/lib/types/client/preset-manager.d.ts +38 -10
- package/lib/types/client/preset-manager.js +235 -185
- package/lib/types/client/preset-requests.d.ts +12 -0
- package/lib/types/client/preset-requests.js +101 -0
- package/lib/types/client/tool-policy.d.ts +33 -0
- package/lib/types/client/tool-policy.js +336 -0
- package/lib/types/contracts/preset-editor-schema.d.ts +78 -0
- package/lib/types/contracts/preset-editor-schema.js +95 -0
- package/lib/types/{prompt.js → contracts/prompt.js} +13 -7
- package/lib/types/{settings.d.ts → contracts/settings.d.ts} +11 -4
- package/lib/types/{settings.js → contracts/settings.js} +22 -6
- package/lib/types/contracts/tool-policy-contract.d.ts +63 -0
- package/lib/types/contracts/tool-policy-contract.js +33 -0
- package/lib/types/contracts/ui-contracts.d.ts +92 -0
- package/lib/types/contracts/ui-contracts.js +83 -0
- package/lib/types/entries/client.d.ts +10 -0
- package/lib/types/entries/client.js +10 -0
- package/lib/types/{compact-command.d.ts → entries/compact-command.d.ts} +2 -0
- package/lib/types/entries/compact-command.js +176 -0
- package/lib/types/{compaction.d.ts → entries/compaction.d.ts} +15 -3
- package/lib/types/{compaction.js → entries/compaction.js} +47 -11
- package/lib/types/entries/hybrid-executor.d.ts +19 -0
- package/lib/types/entries/hybrid-executor.js +57 -0
- package/lib/types/entries/index.d.ts +66 -0
- package/lib/types/entries/index.js +192 -0
- package/lib/types/entries/preferences.d.ts +11 -0
- package/lib/types/entries/preferences.js +16 -0
- package/lib/types/entries/tool-policy.d.ts +97 -0
- package/lib/types/entries/tool-policy.js +158 -0
- package/lib/types/entries/typert.host.d.ts +23 -0
- package/lib/types/entries/typert.host.js +24 -0
- package/lib/types/hybrid/codex-hybrid-executor.d.ts +44 -0
- package/lib/types/hybrid/codex-hybrid-executor.js +257 -0
- package/lib/types/hybrid/hybrid-sdk.d.ts +13 -0
- package/lib/types/hybrid/hybrid-sdk.js +196 -0
- package/lib/types/hybrid/program-calls.d.ts +28 -0
- package/lib/types/hybrid/program-calls.js +193 -0
- package/lib/types/hybrid/subcall-scheduler.d.ts +90 -0
- package/lib/types/hybrid/subcall-scheduler.js +343 -0
- package/lib/types/policy/deferred-tools.d.ts +42 -0
- package/lib/types/policy/deferred-tools.js +264 -0
- package/lib/types/policy/overlay-installer.d.ts +12 -0
- package/lib/types/policy/overlay-installer.js +179 -0
- package/lib/types/policy/rule-resolver.d.ts +94 -0
- package/lib/types/policy/rule-resolver.js +114 -0
- package/lib/types/policy/tool-capabilities.d.ts +33 -0
- package/lib/types/policy/tool-capabilities.js +46 -0
- package/lib/types/{activity.d.ts → presets/activity.d.ts} +3 -5
- package/lib/types/{activity.js → presets/activity.js} +51 -27
- package/lib/types/presets/desktop-preset.d.ts +22 -0
- package/lib/types/presets/desktop-preset.js +43 -0
- package/lib/types/presets/preset-editor.d.ts +47 -0
- package/lib/types/presets/preset-editor.js +81 -0
- package/lib/types/presets/preset-prompt-catalog.d.ts +23 -0
- package/lib/types/presets/preset-prompt-catalog.js +215 -0
- package/lib/types/presets/preset-tool-catalog.d.ts +5 -0
- package/lib/types/presets/preset-tool-catalog.js +58 -0
- package/lib/types/presets/runtime-enhancements.d.ts +45 -0
- package/lib/types/presets/runtime-enhancements.js +349 -0
- package/lib/types/presets/small-window-compaction.d.ts +15 -0
- package/lib/types/presets/small-window-compaction.js +121 -0
- package/lib/types/responses/compact-checkpoint.d.ts +27 -0
- package/lib/types/responses/compact-checkpoint.js +257 -0
- package/lib/types/responses/fetch-transport.d.ts +16 -0
- package/lib/types/responses/fetch-transport.js +257 -0
- package/lib/types/responses/remote-compact.d.ts +13 -0
- package/lib/types/responses/remote-compact.js +319 -0
- package/lib/types/responses/sse-diagnostics.d.ts +9 -0
- package/lib/types/responses/sse-diagnostics.js +157 -0
- package/lib/types/responses/wire-rewrite.d.ts +35 -0
- package/lib/types/responses/wire-rewrite.js +237 -0
- package/lib/types/tools/exec-output.d.ts +58 -0
- package/lib/types/tools/exec-output.js +173 -0
- package/lib/types/tools/exec-plan-tools.d.ts +37 -0
- package/lib/types/tools/exec-plan-tools.js +265 -0
- package/lib/types/tools/exec-runner.d.ts +21 -0
- package/lib/types/tools/exec-runner.js +385 -0
- package/lib/types/tools/patch-tool.d.ts +16 -0
- package/lib/types/tools/patch-tool.js +258 -0
- package/lib/types/{patch.d.ts → tools/patch.d.ts} +1 -1
- package/lib/types/{patch.js → tools/patch.js} +96 -21
- package/locale/en.json +6 -0
- package/locale/hybrid-executor/en.json +6 -0
- package/locale/hybrid-executor/zh.json +6 -0
- package/locale/tool-policy/en.json +6 -0
- package/locale/tool-policy/zh.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +297 -299
- package/presets/{codex-collaboration → codex-hybrid}/agent.cordis.yml +45 -48
- package/presets/codex-hybrid/preset.yml +3 -0
- package/scripts/benchmark-tool-policy.mjs +186 -0
- package/scripts/build-preset.mjs +19 -0
- package/scripts/clean-build.mjs +11 -0
- package/src/client/activity.ts +83 -0
- package/src/client/desktop.tsx +276 -0
- package/src/client/index.tsx +391 -0
- package/src/client/policy-drafts.ts +56 -0
- package/src/client/policy-locale.ts +362 -0
- package/src/client/preset-manager.tsx +376 -0
- package/src/client/preset-requests.ts +113 -0
- package/src/client/tool-policy.tsx +402 -0
- package/src/contracts/preset-editor-schema.ts +110 -0
- package/src/contracts/prompt.ts +66 -0
- package/src/contracts/settings.ts +103 -0
- package/src/contracts/tool-policy-contract.ts +93 -0
- package/src/contracts/ui-contracts.ts +173 -0
- package/src/entries/client.tsx +14 -0
- package/src/entries/compact-command.ts +256 -0
- package/src/entries/compaction.ts +218 -0
- package/src/entries/hybrid-executor.ts +76 -0
- package/src/entries/index.ts +298 -0
- package/src/entries/preferences.ts +17 -0
- package/src/entries/tool-policy.ts +162 -0
- package/src/entries/typert.host.ts +29 -0
- package/src/hybrid/codex-hybrid-executor.ts +310 -0
- package/src/hybrid/hybrid-sdk.ts +217 -0
- package/src/hybrid/program-calls.ts +202 -0
- package/src/hybrid/subcall-scheduler.ts +446 -0
- package/src/policy/deferred-tools.ts +331 -0
- package/src/policy/overlay-installer.ts +191 -0
- package/src/policy/rule-resolver.ts +128 -0
- package/src/policy/tool-capabilities.ts +88 -0
- package/src/presets/activity.ts +146 -0
- package/src/presets/desktop-preset.ts +60 -0
- package/src/presets/preset-editor.ts +101 -0
- package/src/presets/preset-prompt-catalog.ts +221 -0
- package/src/presets/preset-tool-catalog.ts +58 -0
- package/src/presets/runtime-enhancements.ts +415 -0
- package/src/presets/small-window-compaction.ts +166 -0
- package/src/responses/compact-checkpoint.ts +264 -0
- package/src/responses/fetch-transport.ts +290 -0
- package/src/responses/remote-compact.ts +393 -0
- package/src/responses/sse-diagnostics.ts +156 -0
- package/src/responses/wire-rewrite.ts +261 -0
- package/src/tools/exec-output.ts +211 -0
- package/src/tools/exec-plan-tools.ts +307 -0
- package/src/tools/exec-runner.ts +445 -0
- package/src/tools/patch-tool.ts +331 -0
- package/src/tools/patch.ts +328 -0
- package/tsconfig.json +29 -0
- package/tsdown.config.ts +110 -0
- package/lib/installer.js +0 -237
- package/lib/invariant.js +0 -23
- package/lib/types/activity-types.d.ts +0 -6
- package/lib/types/activity-types.js +0 -3
- package/lib/types/client/preset-copy.d.ts +0 -42
- package/lib/types/client/preset-copy.js +0 -81
- package/lib/types/compact-command.js +0 -79
- package/lib/types/context.d.ts +0 -8
- package/lib/types/context.js +0 -14
- package/lib/types/exec.d.ts +0 -46
- package/lib/types/exec.js +0 -365
- package/lib/types/index.d.ts +0 -95
- package/lib/types/index.js +0 -738
- package/lib/types/installer.d.ts +0 -27
- package/lib/types/installer.js +0 -146
- package/lib/types/invariant.d.ts +0 -16
- package/lib/types/invariant.js +0 -22
- package/lib/types/preset-contract.d.ts +0 -69
- package/lib/types/preset-contract.js +0 -22
- package/lib/types/preset-editor-remote.d.ts +0 -30
- package/lib/types/preset-editor-remote.js +0 -37
- package/lib/types/preset-editor.d.ts +0 -69
- package/lib/types/preset-editor.js +0 -557
- package/lib/types/preset-templates.d.ts +0 -36
- package/lib/types/preset-templates.js +0 -12
- package/lib/types/prompt-sections.d.ts +0 -15
- package/lib/types/prompt-sections.js +0 -23
- package/lib/types/remote.d.ts +0 -40
- package/lib/types/remote.js +0 -683
- package/lib/types/typert.host.d.ts +0 -47
- package/lib/types/typert.host.js +0 -99
- package/presets/codex-collaboration/preset.yml +0 -3
- /package/lib/types/{prompt.d.ts → contracts/prompt.d.ts} +0 -0
|
@@ -0,0 +1,402 @@
|
|
|
1
|
+
/** Unified preset plan editor: 1-click segmented tool actions, prompt overrides, and YAML inspector. */
|
|
2
|
+
import { useEffect, useRef, useState, useSyncExternalStore } from 'react'
|
|
3
|
+
import type { Context } from '@deepseek-ai/cordis'
|
|
4
|
+
import type { HostObservable, PropsLocale } from '@deepseek-ai/dsh-client-ui-slots'
|
|
5
|
+
import type { ConfigForm } from '@deepseek-ai/dsh-client-ui-settings/client'
|
|
6
|
+
import { PresetDefinitionCard } from './preset-manager.tsx'
|
|
7
|
+
import type { PresetManagerActions } from './preset-manager.tsx'
|
|
8
|
+
import {
|
|
9
|
+
cachedPresetCatalog, cachedPresetPrompts, cachedPresetTools,
|
|
10
|
+
requestPresetCatalog, requestPresetPrompts, requestPresetTools,
|
|
11
|
+
} from './preset-requests.ts'
|
|
12
|
+
import { effectiveToolAction, legacyToolAction } from '../contracts/tool-policy-contract.ts'
|
|
13
|
+
import type {
|
|
14
|
+
PresetPromptCatalog, PresetPromptEntry, PresetPromptName, PresetToolCatalog,
|
|
15
|
+
PresetToolEntry, ToolAction, ToolActionContext, ToolPolicyRule,
|
|
16
|
+
} from '../contracts/tool-policy-contract.ts'
|
|
17
|
+
import { PRESET_PROMPT_NAMES } from '../contracts/ui-contracts.ts'
|
|
18
|
+
import { acceptPresetSave, editPresetDraft, preparePresetSave, presetRules, sameRules } from './policy-drafts.ts'
|
|
19
|
+
import type { PresetDrafts } from './policy-drafts.ts'
|
|
20
|
+
import { groupOf, humanLabels, policyStyles, toolPolicyEn, toolPolicyZh } from './policy-locale.ts'
|
|
21
|
+
import type { ToolGroupId } from './policy-locale.ts'
|
|
22
|
+
export type { ToolPolicyRule } from '../contracts/tool-policy-contract.ts'
|
|
23
|
+
export { toolPolicyEn, toolPolicyZh }
|
|
24
|
+
|
|
25
|
+
export const TOOL_POLICY_NAMESPACE = 'codex-tool-policy'
|
|
26
|
+
export interface ToolPolicySettings { readonly rules: readonly ToolPolicyRule[] }
|
|
27
|
+
export type ObservableConfigForm<T> = Pick<ConfigForm<T>, 'getSnapshot' | 'subscribe' | 'mutate'>
|
|
28
|
+
export type ToolPolicyForm = ObservableConfigForm<ToolPolicySettings>
|
|
29
|
+
export type ToolPolicyBinding = HostObservable<ToolPolicyForm | undefined>
|
|
30
|
+
type PolicyForms = Pick<Context['configForms'], 'get' | 'whileServed'>
|
|
31
|
+
|
|
32
|
+
export function bindToolPolicy(ctx: Pick<Context, 'effect'>, forms: PolicyForms): ToolPolicyBinding {
|
|
33
|
+
let form: ToolPolicyForm | undefined
|
|
34
|
+
const listeners = new Set<() => void>()
|
|
35
|
+
const publish = (next: ToolPolicyForm | undefined) => {
|
|
36
|
+
form = next
|
|
37
|
+
for (const listener of [...listeners]) listener()
|
|
38
|
+
}
|
|
39
|
+
ctx.effect(
|
|
40
|
+
() => forms.whileServed([TOOL_POLICY_NAMESPACE], () => {
|
|
41
|
+
publish(forms.get<ToolPolicySettings>(TOOL_POLICY_NAMESPACE))
|
|
42
|
+
return () => publish(undefined)
|
|
43
|
+
}),
|
|
44
|
+
'codex client: tool-policy availability',
|
|
45
|
+
)
|
|
46
|
+
return {
|
|
47
|
+
getSnapshot: () => form,
|
|
48
|
+
subscribe: listener => { listeners.add(listener); return () => { listeners.delete(listener) } },
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
type MutableRule = { -readonly [Key in keyof ToolPolicyRule]: ToolPolicyRule[Key] }
|
|
53
|
+
|
|
54
|
+
export function validateToolPolicyRules(rules: readonly ToolPolicyRule[]): 'toolPolicyInvalidPreset' | 'toolPolicyDuplicatePreset' | undefined {
|
|
55
|
+
const ids = new Set<string>()
|
|
56
|
+
for (const rule of rules) {
|
|
57
|
+
const id = rule.preset.trim()
|
|
58
|
+
if (!id) return 'toolPolicyInvalidPreset'
|
|
59
|
+
if (ids.has(id)) return 'toolPolicyDuplicatePreset'
|
|
60
|
+
ids.add(id)
|
|
61
|
+
}
|
|
62
|
+
return undefined
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function withToolAction(rule: ToolPolicyRule, name: string, action: ToolAction, context: ToolActionContext = {}): ToolPolicyRule {
|
|
66
|
+
const next: MutableRule = { ...rule }
|
|
67
|
+
const tools = [...(rule.tools ?? [])].filter(tool => tool.name !== name)
|
|
68
|
+
if (action !== legacyToolAction(rule, name, context)) tools.push({ name, action })
|
|
69
|
+
if (tools.length) next.tools = tools
|
|
70
|
+
else delete next.tools
|
|
71
|
+
return next
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export function saveToolPolicy(form: ToolPolicyForm, rules: readonly ToolPolicyRule[], revision: number | undefined): Promise<boolean> {
|
|
75
|
+
const value = rules.map(rule => {
|
|
76
|
+
const row: Record<string, string | boolean | string[] | Array<{ name: string; action: string }> | Array<{ name: string; text: string }>> = { preset: rule.preset }
|
|
77
|
+
if (rule.allow !== undefined) row.allow = [...rule.allow]
|
|
78
|
+
if (rule.deny !== undefined) row.deny = [...rule.deny]
|
|
79
|
+
if (rule.replaceShell !== undefined) row.replaceShell = rule.replaceShell
|
|
80
|
+
if (rule.replacePlan !== undefined) row.replacePlan = rule.replacePlan
|
|
81
|
+
if (rule.replacePatch !== undefined) row.replacePatch = rule.replacePatch
|
|
82
|
+
if (rule.tools !== undefined) row.tools = rule.tools.map(tool => ({ ...tool }))
|
|
83
|
+
if (rule.promptOverrides !== undefined) row.promptOverrides = rule.promptOverrides.map(override => ({ name: override.name, text: override.text }))
|
|
84
|
+
return row
|
|
85
|
+
})
|
|
86
|
+
return form.mutate([{ op: 'set', path: ['rules'], value }], revision)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export type ToolPolicySubMode = 'tools' | 'prompts' | 'definition'
|
|
90
|
+
export type ToolPolicyMode = ToolPolicySubMode | 'inactive'
|
|
91
|
+
type PolicyProps = PropsLocale<'codex'> & { presetManager?: PresetManagerActions | undefined; mode?: ToolPolicyMode }
|
|
92
|
+
type ToolsView = { preset: string; status: 'loading' | 'ready' | 'error'; value?: PresetToolCatalog }
|
|
93
|
+
type PromptsView = { preset: string; status: 'loading' | 'ready' | 'error'; value?: PresetPromptCatalog }
|
|
94
|
+
const isPromptName = (name: string): name is PresetPromptName => (PRESET_PROMPT_NAMES as readonly string[]).includes(name)
|
|
95
|
+
|
|
96
|
+
const GROUP_META: readonly { id: ToolGroupId; labelKey: 'toolPolicyCommandGroup' | 'toolPolicyFileGroup' | 'toolPolicyPlanGroup' | 'toolPolicyCollabGroup' | 'toolPolicyOtherGroup' }[] = [
|
|
97
|
+
{ id: 'command', labelKey: 'toolPolicyCommandGroup' },
|
|
98
|
+
{ id: 'file', labelKey: 'toolPolicyFileGroup' },
|
|
99
|
+
{ id: 'plan', labelKey: 'toolPolicyPlanGroup' },
|
|
100
|
+
{ id: 'collab', labelKey: 'toolPolicyCollabGroup' },
|
|
101
|
+
{ id: 'other', labelKey: 'toolPolicyOtherGroup' },
|
|
102
|
+
]
|
|
103
|
+
|
|
104
|
+
export function ToolPolicySection({ binding, ...props }: { binding: ToolPolicyBinding } & PolicyProps) {
|
|
105
|
+
const form = useSyncExternalStore(binding.subscribe, binding.getSnapshot, binding.getSnapshot)
|
|
106
|
+
return form === undefined ? null : <ToolPolicySettingsCard form={form} {...props} />
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export function ToolPolicySettingsCard({ form, presetManager, mode = 'tools', t }: { form: ToolPolicyForm } & PolicyProps) {
|
|
110
|
+
const snapshot = useSyncExternalStore(listener => form.subscribe(listener), () => form.getSnapshot(), () => form.getSnapshot())
|
|
111
|
+
const [subMode, setSubMode] = useState<ToolPolicySubMode>(mode === 'prompts' || mode === 'definition' ? mode : 'tools')
|
|
112
|
+
const prevMode = useRef(mode)
|
|
113
|
+
const modeChanged = prevMode.current !== mode
|
|
114
|
+
prevMode.current = mode
|
|
115
|
+
const activeSub: ToolPolicySubMode = modeChanged && (mode === 'tools' || mode === 'prompts' || mode === 'definition') ? mode : subMode
|
|
116
|
+
const [drafts, setDrafts] = useState<PresetDrafts>(() => new Map())
|
|
117
|
+
const [saving, setSaving] = useState(false); const [error, setError] = useState(''); const [notice, setNotice] = useState('')
|
|
118
|
+
const [selection, setSelection] = useState<string>()
|
|
119
|
+
const [query, setQuery] = useState(''); const [filter, setFilter] = useState<'all' | 'modified' | 'deferred' | 'replaceable'>('all')
|
|
120
|
+
const [groupOpen, setGroupOpen] = useState<ReadonlyMap<string, boolean>>(() => new Map())
|
|
121
|
+
const [toolsView, setToolsView] = useState<ToolsView>()
|
|
122
|
+
const [promptsView, setPromptsView] = useState<PromptsView>()
|
|
123
|
+
const alive = useRef(true); const catalogRequest = useRef(0); const toolsRequest = useRef(0); const promptsRequest = useRef(0)
|
|
124
|
+
const [catalog, setCatalog] = useState(() => presetManager === undefined ? undefined : cachedPresetCatalog(presetManager))
|
|
125
|
+
const [catalogState, setCatalogState] = useState<'loading' | 'ready' | 'error'>(() => catalog ? 'ready' : presetManager ? 'loading' : 'error')
|
|
126
|
+
|
|
127
|
+
useEffect(() => {
|
|
128
|
+
if (subMode !== activeSub) setSubMode(activeSub)
|
|
129
|
+
}, [activeSub])
|
|
130
|
+
|
|
131
|
+
function loadCatalog(refresh = false): void {
|
|
132
|
+
const ticket = ++catalogRequest.current
|
|
133
|
+
if (presetManager === undefined) { setCatalogState('error'); return }
|
|
134
|
+
setCatalogState('loading')
|
|
135
|
+
void requestPresetCatalog(presetManager, refresh).then(value => {
|
|
136
|
+
if (alive.current && ticket === catalogRequest.current) { setCatalog(value); setCatalogState('ready') }
|
|
137
|
+
}).catch(() => { if (alive.current && ticket === catalogRequest.current) setCatalogState('error') })
|
|
138
|
+
}
|
|
139
|
+
useEffect(() => { alive.current = true; loadCatalog(); return () => { alive.current = false; catalogRequest.current++; toolsRequest.current++; promptsRequest.current++ } }, [presetManager])
|
|
140
|
+
|
|
141
|
+
const acceptedRules = snapshot.value?.rules ?? []
|
|
142
|
+
const ids = [...new Set([...(catalog?.presets.map(preset => preset.id) ?? []), ...acceptedRules.map(rule => rule.preset), ...drafts.keys()])].filter(id => id.trim())
|
|
143
|
+
const selectedId = selection ?? ids[0] ?? ''
|
|
144
|
+
const currentDraft = drafts.get(selectedId)
|
|
145
|
+
const currentRules = currentDraft?.rules ?? presetRules(acceptedRules, selectedId)
|
|
146
|
+
const rule = currentRules[0]
|
|
147
|
+
const duplicate = currentRules.length > 1
|
|
148
|
+
const presetLabel = catalog?.presets.find(preset => preset.id === selectedId)?.name ?? selectedId
|
|
149
|
+
|
|
150
|
+
function loadTools(refresh = false): void {
|
|
151
|
+
const ticket = ++toolsRequest.current
|
|
152
|
+
if (!selectedId || presetManager === undefined) { setToolsView({ preset: selectedId, status: 'error' }); return }
|
|
153
|
+
setToolsView({ preset: selectedId, status: 'loading' })
|
|
154
|
+
void requestPresetTools(presetManager, selectedId, refresh).then(value => {
|
|
155
|
+
if (alive.current && ticket === toolsRequest.current) setToolsView({ preset: selectedId, status: 'ready', value })
|
|
156
|
+
}).catch(() => { if (alive.current && ticket === toolsRequest.current) setToolsView({ preset: selectedId, status: 'error' }) })
|
|
157
|
+
}
|
|
158
|
+
useEffect(() => { loadTools(); return () => { toolsRequest.current++ } }, [presetManager, selectedId])
|
|
159
|
+
|
|
160
|
+
const cached = presetManager && selectedId ? cachedPresetTools(presetManager, selectedId) : undefined
|
|
161
|
+
const inventory = toolsView?.preset === selectedId && toolsView.status === 'error' ? undefined : toolsView?.preset === selectedId && toolsView.status === 'ready' ? toolsView.value : cached
|
|
162
|
+
const toolsStatus = inventory ? 'ready' : toolsView?.preset === selectedId ? toolsView.status : selectedId ? 'loading' : 'error'
|
|
163
|
+
|
|
164
|
+
function loadPrompts(refresh = false): void {
|
|
165
|
+
const ticket = ++promptsRequest.current
|
|
166
|
+
if (!selectedId || presetManager === undefined) { setPromptsView({ preset: selectedId, status: 'error' }); return }
|
|
167
|
+
setPromptsView({ preset: selectedId, status: 'loading' })
|
|
168
|
+
void requestPresetPrompts(presetManager, selectedId, refresh).then(value => {
|
|
169
|
+
if (alive.current && ticket === promptsRequest.current) setPromptsView({ preset: selectedId, status: 'ready', value })
|
|
170
|
+
}).catch(() => { if (alive.current && ticket === promptsRequest.current) setPromptsView({ preset: selectedId, status: 'error' }) })
|
|
171
|
+
}
|
|
172
|
+
useEffect(() => {
|
|
173
|
+
if (activeSub === 'prompts') loadPrompts()
|
|
174
|
+
return () => { promptsRequest.current++ }
|
|
175
|
+
}, [presetManager, selectedId, activeSub === 'prompts'])
|
|
176
|
+
|
|
177
|
+
const cachedPrompts = presetManager && selectedId ? cachedPresetPrompts(presetManager, selectedId) : undefined
|
|
178
|
+
const promptCatalog = promptsView?.preset === selectedId && promptsView.status === 'error' ? undefined
|
|
179
|
+
: promptsView?.preset === selectedId && promptsView.status === 'ready' ? promptsView.value : cachedPrompts
|
|
180
|
+
const promptsStatus = promptCatalog ? 'ready' : promptsView?.preset === selectedId ? promptsView.status : selectedId ? 'loading' : 'error'
|
|
181
|
+
|
|
182
|
+
const inventoryNames = new Set(inventory?.tools.map(tool => tool.name) ?? [])
|
|
183
|
+
const contextFor = (tool: PresetToolEntry): ToolActionContext => ({
|
|
184
|
+
...(inventory?.legacyCapabilities === undefined ? {} : { legacyCapabilities: inventory.legacyCapabilities }),
|
|
185
|
+
...(tool.codexTool === undefined ? {} : { codexTool: tool.codexTool }),
|
|
186
|
+
...(tool.defaultDeferred === true ? { defaultDeferred: true } : {}),
|
|
187
|
+
})
|
|
188
|
+
const deferUnavailableReason = (tool: PresetToolEntry): 'conditional' | 'target-exists' | undefined =>
|
|
189
|
+
tool.conditional ? 'conditional' : (tool.name === 'activate_tools' || inventoryNames.has('activate_tools')) ? 'target-exists' : undefined
|
|
190
|
+
const chosen = (tool: PresetToolEntry) => effectiveToolAction(rule, tool.name, contextFor(tool))
|
|
191
|
+
const customized = (tool: PresetToolEntry) => chosen(tool) !== effectiveToolAction(undefined, tool.name, contextFor(tool)) || !!rule?.tools?.some(choice => choice.name === tool.name)
|
|
192
|
+
|
|
193
|
+
const stage = (change: (rules: readonly ToolPolicyRule[]) => readonly ToolPolicyRule[]): void => {
|
|
194
|
+
if (snapshot.status !== 'ready' || !snapshot.writable || saving) return
|
|
195
|
+
const latest = form.getSnapshot(); setError(''); setNotice('')
|
|
196
|
+
setDrafts(previous => editPresetDraft(previous, selectedId, { revision: latest.revision, rules: latest.value?.rules ?? [] }, change))
|
|
197
|
+
}
|
|
198
|
+
const editRule = (change: (value: ToolPolicyRule) => ToolPolicyRule): void => stage(previous => {
|
|
199
|
+
const base = previous[0] ?? { preset: selectedId, replaceShell: false, replacePlan: false }
|
|
200
|
+
const next = change(base)
|
|
201
|
+
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
|
|
202
|
+
if (neutralNew) return []
|
|
203
|
+
return previous.length === 0 ? [next] : previous.map((value, position) => position === 0 ? next : value)
|
|
204
|
+
})
|
|
205
|
+
const chooseAction = (tool: PresetToolEntry, action: string): void => {
|
|
206
|
+
if (duplicate || !selectedId || (action !== 'keep' && action !== 'hide' && action !== 'defer' && action !== 'codex-exec' && action !== 'codex-plan' && action !== 'codex-patch')) return
|
|
207
|
+
if (action === 'defer' && deferUnavailableReason(tool) !== undefined) return
|
|
208
|
+
if (action !== 'keep' && action !== 'hide' && action !== 'defer' && !tool.replacements.some(replacement => replacement.action === action && replacement.available)) return
|
|
209
|
+
const context = contextFor(tool)
|
|
210
|
+
if (rule === undefined && action === legacyToolAction(undefined, tool.name, context)) return
|
|
211
|
+
editRule(value => withToolAction(value, tool.name, action, context))
|
|
212
|
+
}
|
|
213
|
+
const removeChoice = (name: string): void => editRule(value => {
|
|
214
|
+
const next: MutableRule = { ...value }; const tools = (value.tools ?? []).filter(choice => choice.name !== name)
|
|
215
|
+
if (tools.length) next.tools = tools; else delete next.tools; return next
|
|
216
|
+
})
|
|
217
|
+
const changePrompt = (section: PresetPromptEntry, text: string): void => {
|
|
218
|
+
if (duplicate || !section.editable || !isPromptName(section.name) || promptCatalog?.preset !== selectedId) return
|
|
219
|
+
const name = section.name
|
|
220
|
+
editRule(value => ({ ...value, promptOverrides: [...(value.promptOverrides ?? []).filter(entry => entry.name !== name), { name, text }] }))
|
|
221
|
+
}
|
|
222
|
+
const restorePrompt = (section: PresetPromptEntry): void => {
|
|
223
|
+
if (duplicate || !section.editable || !isPromptName(section.name) || promptCatalog?.preset !== selectedId) return
|
|
224
|
+
editRule(value => {
|
|
225
|
+
const next: MutableRule = { ...value }; const remaining = (value.promptOverrides ?? []).filter(entry => entry.name !== section.name)
|
|
226
|
+
if (remaining.length) next.promptOverrides = remaining; else delete next.promptOverrides; return next
|
|
227
|
+
})
|
|
228
|
+
}
|
|
229
|
+
const saveCurrent = (): void => {
|
|
230
|
+
if (!currentDraft || saving || !snapshot.writable || snapshot.status !== 'ready') return
|
|
231
|
+
const latest = form.getSnapshot(); const target = selectedId
|
|
232
|
+
const targetName = presetLabel && presetLabel !== target ? `${presetLabel} (${target})` : target || t('toolPolicyInvalidEntry')
|
|
233
|
+
const message = (key: 'toolPolicyInvalidPreset' | 'toolPolicyDuplicatePreset' | 'toolPolicyRefused' | 'toolPolicyFailed' | 'toolPolicySaved') => `${targetName}: ${t(key)}`
|
|
234
|
+
let prepared: ReturnType<typeof preparePresetSave>
|
|
235
|
+
try {
|
|
236
|
+
prepared = preparePresetSave(currentDraft, { revision: latest.revision, rules: latest.value?.rules ?? [] })
|
|
237
|
+
const invalid = validateToolPolicyRules(currentDraft.rules)
|
|
238
|
+
const otherIds = new Set((latest.value?.rules ?? []).filter(value => value.preset !== selectedId).map(value => value.preset.trim()))
|
|
239
|
+
if (invalid || currentDraft.rules.some(value => otherIds.has(value.preset.trim()))) { setError(message(invalid ?? 'toolPolicyDuplicatePreset')); return }
|
|
240
|
+
} catch { setError(message('toolPolicyRefused')); return }
|
|
241
|
+
setSaving(true); setError(''); setNotice('')
|
|
242
|
+
void saveToolPolicy(form, prepared.rules, prepared.revision).then(accepted => {
|
|
243
|
+
if (!alive.current) return
|
|
244
|
+
if (!accepted) { setError(message('toolPolicyRefused')); return }
|
|
245
|
+
const after = form.getSnapshot()
|
|
246
|
+
setDrafts(previous => acceptPresetSave(previous, prepared, { revision: after.revision, rules: after.value?.rules ?? [] }))
|
|
247
|
+
setNotice(message('toolPolicySaved'))
|
|
248
|
+
}).catch(() => { if (alive.current) setError(message('toolPolicyFailed')) }).finally(() => { if (alive.current) setSaving(false) })
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
const human = (tool: PresetToolEntry): string => {
|
|
252
|
+
const key = humanLabels[tool.name as keyof typeof humanLabels]
|
|
253
|
+
if (key !== undefined) return t(key)
|
|
254
|
+
const mcp = /^mcp__([^_]+(?:_[^_]+)*)__(.+)$/.exec(tool.name)
|
|
255
|
+
if (mcp !== null) return `${t('toolLabelMcpDynamic')} (${mcp[1]} · ${mcp[2]})`
|
|
256
|
+
return tool.description.split(/[\n。.!]/u)[0]?.trim() || t('toolLabelOther')
|
|
257
|
+
}
|
|
258
|
+
const beforeTarget = currentDraft ? presetRules(currentDraft.baseline, selectedId) : []
|
|
259
|
+
const beforeRule = beforeTarget[0]
|
|
260
|
+
const choiceFor = (value: ToolPolicyRule | undefined, name: string) => value?.tools?.find(choice => choice.name === name)
|
|
261
|
+
const changedNames = currentDraft ? [...new Set([
|
|
262
|
+
...(inventory?.tools.filter(tool => effectiveToolAction(beforeRule, tool.name, contextFor(tool)) !== chosen(tool)
|
|
263
|
+
|| JSON.stringify(choiceFor(beforeRule, tool.name)) !== JSON.stringify(choiceFor(rule, tool.name))).map(tool => tool.name) ?? []),
|
|
264
|
+
...[...(beforeRule?.tools ?? []), ...(rule?.tools ?? [])].filter(choice => !inventoryNames.has(choice.name)
|
|
265
|
+
&& JSON.stringify(choiceFor(beforeRule, choice.name)) !== JSON.stringify(choiceFor(rule, choice.name))).map(choice => choice.name),
|
|
266
|
+
])] : []
|
|
267
|
+
const changedPrompts = currentDraft ? [...new Set([...(beforeRule?.promptOverrides ?? []), ...(rule?.promptOverrides ?? [])].map(entry => entry.name))]
|
|
268
|
+
.filter(name => JSON.stringify(beforeRule?.promptOverrides?.find(entry => entry.name === name)) !== JSON.stringify(rule?.promptOverrides?.find(entry => entry.name === name))) : []
|
|
269
|
+
const summaryParts = [
|
|
270
|
+
...(changedNames.length ? [`${t('presetSummaryTools')}: ${changedNames.slice(0, 4).join(', ')}${changedNames.length > 4 ? ` (+${changedNames.length - 4})` : ''}`] : []),
|
|
271
|
+
...(changedPrompts.length ? [`${t('presetSummaryPrompts')}: ${changedPrompts.map(name => promptCatalog?.sections.find(section => section.name === name)?.label || name).join(', ')}`] : []),
|
|
272
|
+
]
|
|
273
|
+
const changeSummary = summaryParts.join(' · ') || t(currentDraft && !sameRules(beforeTarget, currentDraft.rules) ? 'toolPolicyRuleChanged' : 'toolPolicyNoToolDelta')
|
|
274
|
+
const unavailable = (reason: 'conditional' | 'target-exists' | undefined) => t(reason === 'conditional' ? 'toolPolicyConditional' : reason === 'target-exists' ? 'toolPolicyTargetExists' : 'toolPolicyUnsupported')
|
|
275
|
+
|
|
276
|
+
const renderRows = (tools: readonly PresetToolEntry[]) => <div className="codex-tool-policy-table" role="table" aria-label={t('toolPolicyTitle')}>
|
|
277
|
+
{tools.map(tool => {
|
|
278
|
+
const action = chosen(tool); const deferReason = deferUnavailableReason(tool)
|
|
279
|
+
const supported = action === 'keep' || action === 'hide' || action === 'defer' || tool.replacements.some(option => option.action === action)
|
|
280
|
+
const custom = customized(tool); const hasOverride = !!rule?.tools?.some(choice => choice.name === tool.name)
|
|
281
|
+
return <div key={tool.name} role="row" className="codex-tool-policy-tool" data-tool-name={tool.name} data-tool-action={action}>
|
|
282
|
+
<div role="cell" className="codex-tool-policy-name">
|
|
283
|
+
<code className="codex-tool-policy-identifier">{tool.name}</code>
|
|
284
|
+
<span className="codex-tool-policy-description" title={tool.description}>{human(tool)}</span>
|
|
285
|
+
{tool.defaultDeferred && !custom && <span className="codex-badge" data-tone="blue">{t('toolPolicyDefaultDeferred')}</span>}
|
|
286
|
+
{custom && <span className="codex-badge" data-tone="blue">{t('toolPolicyModified')}</span>}
|
|
287
|
+
{tool.codexTool?.presetEnabled === false && <span className="codex-badge" data-tone="warn">{t('toolPolicyPresetDisabled')}</span>}
|
|
288
|
+
{tool.conditional && tool.codexTool === undefined && <span className="codex-badge">{t('toolPolicyConditional')}</span>}
|
|
289
|
+
</div>
|
|
290
|
+
<div role="cell" className="codex-tool-policy-action">
|
|
291
|
+
<div className="codex-seg" role="group" aria-label={`${t('toolPolicyAction')} ${tool.name}`}>
|
|
292
|
+
<button type="button" data-action="keep" aria-pressed={action === 'keep'} disabled={duplicate} onClick={() => chooseAction(tool, 'keep')}>{t('toolPolicyKeep')}</button>
|
|
293
|
+
{tool.replacements.map(option => <button type="button" key={option.action} data-action={option.action} aria-pressed={action === option.action}
|
|
294
|
+
disabled={duplicate || !option.available} title={option.available ? option.tools.join(' + ') : `${option.tools.join(' + ')} · ${unavailable(option.reason)}`}
|
|
295
|
+
onClick={() => chooseAction(tool, option.action)}>{t('toolPolicyReplaceShort')}</button>)}
|
|
296
|
+
<button type="button" data-action="defer" aria-pressed={action === 'defer'} disabled={duplicate || deferReason !== undefined}
|
|
297
|
+
title={deferReason !== undefined ? unavailable(deferReason) : t('toolPolicyDeferHint')} onClick={() => chooseAction(tool, 'defer')}>{t('toolPolicyDefer')}</button>
|
|
298
|
+
<button type="button" data-action="hide" aria-pressed={action === 'hide'} disabled={duplicate} onClick={() => chooseAction(tool, 'hide')}>{t('toolPolicyHide')}</button>
|
|
299
|
+
</div>
|
|
300
|
+
{!supported && <span className="codex-tool-policy-warning">{t('toolPolicyUnsupported')} ({action})</span>}
|
|
301
|
+
{hasOverride && <button type="button" className="codex-btn" aria-label={`${t('toolPolicyRestoreChoice')} ${tool.name}`}
|
|
302
|
+
title={t('toolPolicyRestoreChoice')} onClick={() => removeChoice(tool.name)}>↶</button>}
|
|
303
|
+
</div>
|
|
304
|
+
</div>
|
|
305
|
+
})}
|
|
306
|
+
{tools.length === 0 && <p className="codex-tool-policy-note" style={{ padding: '12px 14px' }}>{t('toolPolicyNoMatches')}</p>}
|
|
307
|
+
</div>
|
|
308
|
+
|
|
309
|
+
if (snapshot.status !== 'ready' || snapshot.value === undefined || mode === 'inactive') return null
|
|
310
|
+
const text = query.trim().toLowerCase()
|
|
311
|
+
const isFiltering = text.length > 0 || filter !== 'all'
|
|
312
|
+
const allTools = inventory?.tools ?? []
|
|
313
|
+
const hasReplaceable = allTools.some(tool => tool.replacements.some(option => option.available))
|
|
314
|
+
const shown = allTools.filter(tool => (!text || `${human(tool)} ${tool.name} ${tool.description}`.toLowerCase().includes(text))
|
|
315
|
+
&& (filter === 'all' || (filter === 'modified' ? customized(tool) : filter === 'deferred' ? chosen(tool) === 'defer' : tool.replacements.some(option => option.available))))
|
|
316
|
+
|
|
317
|
+
return <section className="codex-tool-policy" aria-label={t(activeSub === 'prompts' ? 'settingsPresetPrompts' : 'toolPolicyTitle')}>
|
|
318
|
+
<style>{policyStyles}</style>
|
|
319
|
+
<div className="codex-card codex-preset-bar">
|
|
320
|
+
<label className="codex-preset-select-wrap">
|
|
321
|
+
<span className="codex-tool-policy-note">{t('toolPolicyPresetChoice')}</span>
|
|
322
|
+
<select aria-label={t('toolPolicyPresetChoice')} value={selectedId} onChange={event => { setSelection(event.target.value); setError(''); setNotice('') }}>
|
|
323
|
+
{!ids.length && <option value="">{t('toolPolicyEmpty')}</option>}
|
|
324
|
+
{ids.map(id => <option key={id} value={id} data-preset-id={id}>{catalog?.presets.find(preset => preset.id === id)?.name ?? id}{drafts.has(id) ? ` · ${t('globalPending')}` : ''}</option>)}
|
|
325
|
+
</select>
|
|
326
|
+
</label>
|
|
327
|
+
<div className="codex-tool-policy-action">
|
|
328
|
+
<div className="codex-seg" role="group" aria-label={t('settingsTabLabel')}>
|
|
329
|
+
{([['tools', 'settingsSubTools'], ['prompts', 'settingsPresetPrompts'], ['definition', 'settingsDefinition']] as const).map(([key, labelKey]) => (
|
|
330
|
+
<button type="button" key={key} data-submode={key} aria-pressed={activeSub === key} onClick={() => setSubMode(key)}>{t(labelKey)}</button>
|
|
331
|
+
))}
|
|
332
|
+
</div>
|
|
333
|
+
{presetManager && <button type="button" className="codex-btn" disabled={catalogState === 'loading'} onClick={() => loadCatalog(true)}>{t('toolPolicyCatalogRetry')}</button>}
|
|
334
|
+
</div>
|
|
335
|
+
</div>
|
|
336
|
+
{catalogState !== 'ready' && <p className="codex-tool-policy-note" role="status">{t(catalogState === 'loading' ? 'toolPolicyCatalogLoading' : 'toolPolicyCatalogFailed')}</p>}
|
|
337
|
+
{catalogState === 'ready' && !ids.length && <p className="codex-tool-policy-note">{t('toolPolicyCatalogEmpty')}</p>}
|
|
338
|
+
{duplicate && <p className="codex-tool-policy-warning">{t('toolPolicyDuplicatePreset')}</p>}
|
|
339
|
+
{activeSub === 'definition' && (!selectedId || presetManager === undefined ? <p className="codex-tool-policy-note">{t('settingsDefinitionAbsent')}</p> : <PresetDefinitionCard presetManager={presetManager} id={selectedId} t={t} />)}
|
|
340
|
+
{activeSub !== 'definition' && <form onSubmit={event => { event.preventDefault(); saveCurrent() }}><fieldset disabled={!snapshot.writable || saving}>
|
|
341
|
+
{activeSub === 'tools' && <>
|
|
342
|
+
{toolsStatus !== 'ready' && <p className="codex-tool-policy-note" role="status">{t(toolsStatus === 'loading' ? 'toolPolicyToolsLoading' : 'toolPolicyToolsFailed')}</p>}
|
|
343
|
+
{inventory?.tools.length === 0 && <p className="codex-tool-policy-note" role="status">{t('toolPolicyToolsEmpty')}</p>}
|
|
344
|
+
{inventory && !duplicate && inventory.tools.length > 0 && <div className="codex-toolbar">
|
|
345
|
+
<input type="text" aria-label={t('toolPolicySearch')} placeholder={t('toolPolicySearch')} value={query} onChange={event => setQuery(event.target.value)} />
|
|
346
|
+
<div className="codex-seg" role="group" aria-label={t('toolPolicyFilter')}>
|
|
347
|
+
{(['all', 'deferred', 'modified', ...(hasReplaceable ? ['replaceable'] as const : [])] as const).map(item => (
|
|
348
|
+
<button type="button" key={item} data-filter={item} aria-pressed={filter === item} onClick={() => setFilter(item)}>
|
|
349
|
+
{t(item === 'all' ? 'toolPolicyAll' : item === 'modified' ? 'toolPolicyModified' : item === 'deferred' ? 'toolPolicyDeferredFilter' : 'toolPolicyReplaceable')}
|
|
350
|
+
</button>
|
|
351
|
+
))}
|
|
352
|
+
</div>
|
|
353
|
+
{presetManager && selectedId && <button type="button" className="codex-btn" disabled={toolsStatus === 'loading'} onClick={() => loadTools(true)}>{t('toolPolicyToolsRefresh')}</button>}
|
|
354
|
+
</div>}
|
|
355
|
+
{inventory && !duplicate && (isFiltering && shown.length === 0
|
|
356
|
+
? <div className="codex-card">{renderRows(shown)}</div>
|
|
357
|
+
: GROUP_META.map(group => {
|
|
358
|
+
const tools = shown.filter(tool => groupOf(tool) === group.id); if (!tools.length) return null
|
|
359
|
+
const changes = tools.filter(customized).length; const key = `${selectedId}/${group.id}`
|
|
360
|
+
return <details key={group.id} className="codex-group" data-tool-group={group.id} open={isFiltering ? true : (groupOpen.get(key) ?? true)}
|
|
361
|
+
onToggle={event => { const open = event.currentTarget.open; setGroupOpen(previous => new Map(previous).set(key, open)) }}>
|
|
362
|
+
<summary><span>{t(group.labelKey)}</span><span className="codex-tool-policy-note">{tools.length}{changes ? ` · ${changes} ${t('toolPolicyCustomized')}` : ''}</span></summary>
|
|
363
|
+
{renderRows(tools)}
|
|
364
|
+
</details>
|
|
365
|
+
}))}
|
|
366
|
+
</>}
|
|
367
|
+
{activeSub === 'prompts' && <>
|
|
368
|
+
{presetManager && selectedId && <div className="codex-toolbar"><button type="button" className="codex-btn" disabled={promptsStatus === 'loading'} onClick={() => loadPrompts(true)}>{t('presetPromptsReload')}</button></div>}
|
|
369
|
+
{promptsStatus !== 'ready' && <p className="codex-tool-policy-note" role="status">{t(promptsStatus === 'loading' ? 'presetPromptsLoading' : 'presetPromptsFailed')}</p>}
|
|
370
|
+
{promptCatalog?.sections.length === 0 && <p className="codex-tool-policy-note">{t('presetPromptsEmpty')}</p>}
|
|
371
|
+
{promptCatalog && <div className="codex-tool-policy-prompts">
|
|
372
|
+
{promptCatalog.sections.map(section => {
|
|
373
|
+
const editable = section.editable && isPromptName(section.name)
|
|
374
|
+
const override = rule?.promptOverrides?.find(entry => entry.name === section.name)
|
|
375
|
+
return <section key={section.name} className="codex-card codex-tool-policy-prompt" data-prompt-section={section.name}>
|
|
376
|
+
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', gap: 8 }}>
|
|
377
|
+
<h4>{section.label || section.name}</h4><code>{section.name}</code>
|
|
378
|
+
</div>
|
|
379
|
+
{editable ? <>
|
|
380
|
+
<textarea aria-label={`${t('settingsPresetPrompts')} ${section.name}`} rows={5} maxLength={1_000_000}
|
|
381
|
+
disabled={duplicate || !snapshot.writable || saving} value={override?.text ?? section.text} onChange={event => changePrompt(section, event.target.value)} />
|
|
382
|
+
<button type="button" className="codex-btn" style={{ justifySelf: 'start' }} aria-label={`${t('presetPromptRestore')} ${section.name}`}
|
|
383
|
+
disabled={!override || duplicate || !snapshot.writable || saving} onClick={() => restorePrompt(section)}>{t('presetPromptRestore')}</button>
|
|
384
|
+
</> : <><span className="codex-tool-policy-note" title={section.reason}>{t('presetPromptReadOnly')}</span><pre>{section.text}</pre></>}
|
|
385
|
+
</section>
|
|
386
|
+
})}
|
|
387
|
+
</div>}
|
|
388
|
+
</>}
|
|
389
|
+
<div className="codex-save-bar" data-dirty={Boolean(currentDraft)}>
|
|
390
|
+
{currentDraft ? <span className="codex-tool-policy-note" aria-label={t('toolPolicyDraftSummary')}>{t('toolPolicyDraftSummary')}: {changeSummary}</span>
|
|
391
|
+
: <span className="codex-tool-policy-note">{t('toolPolicyTiming')}</span>}
|
|
392
|
+
<div className="codex-save-buttons">
|
|
393
|
+
<button type="button" className="codex-btn" disabled={!currentDraft} onClick={() => { setDrafts(previous => { const next = new Map(previous); next.delete(selectedId); return next }); setError(''); setNotice('') }}>{t('toolPolicyDiscard')}</button>
|
|
394
|
+
<button className="codex-btn codex-btn-primary" type="submit" disabled={!currentDraft}>{t(saving ? 'toolPolicySaving' : 'toolPolicySave')}</button>
|
|
395
|
+
</div>
|
|
396
|
+
</div>
|
|
397
|
+
</fieldset></form>}
|
|
398
|
+
{!snapshot.writable && <p className="codex-tool-policy-note">{t('toolPolicyReadOnly')}</p>}
|
|
399
|
+
{error && <p className="codex-tool-policy-error" role="alert">{error}</p>}
|
|
400
|
+
{notice && <p className="codex-tool-policy-note" role="status">{notice}</p>}
|
|
401
|
+
</section>
|
|
402
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/** Shared wire codecs and RPC descriptors for Host/Client preset inspection. */
|
|
2
|
+
import { z } from 'zod'
|
|
3
|
+
import type { InvocationDescriptor, TypertRemoteContribution } from '@deepseek-ai/dsh-typert-protocol'
|
|
4
|
+
|
|
5
|
+
export const PRESET_EDITOR_PACKAGE = '@shuind/dsh-codex-harness'
|
|
6
|
+
export const PRESET_EDITOR_SERVICE = 'codexPresetEditor'
|
|
7
|
+
|
|
8
|
+
export const presetIdSchema = z.string().min(1).max(256)
|
|
9
|
+
|
|
10
|
+
export const presetCatalogSchema = z.object({
|
|
11
|
+
presets: z.array(z.object({
|
|
12
|
+
id: z.string(),
|
|
13
|
+
name: z.string(),
|
|
14
|
+
description: z.string(),
|
|
15
|
+
isDefault: z.boolean(),
|
|
16
|
+
})),
|
|
17
|
+
excludedCount: z.number(),
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
export const presetDefinitionSchema = z.object({
|
|
21
|
+
id: z.string(),
|
|
22
|
+
name: z.string(),
|
|
23
|
+
description: z.string(),
|
|
24
|
+
composition: z.string(),
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
export const presetToolCatalogSchema = z.object({
|
|
28
|
+
preset: z.string(),
|
|
29
|
+
registeredOnly: z.literal(true),
|
|
30
|
+
legacyCapabilities: z.object({
|
|
31
|
+
terminalToolsEnabled: z.boolean().optional(),
|
|
32
|
+
planToolEnabled: z.boolean().optional(),
|
|
33
|
+
patchToolEnabled: z.boolean().optional(),
|
|
34
|
+
}).optional(),
|
|
35
|
+
tools: z.array(z.object({
|
|
36
|
+
name: z.string(),
|
|
37
|
+
description: z.string(),
|
|
38
|
+
conditional: z.boolean(),
|
|
39
|
+
defaultDeferred: z.boolean().optional(),
|
|
40
|
+
codexTool: z.object({
|
|
41
|
+
capability: z.enum(['terminalToolsEnabled', 'planToolEnabled', 'patchToolEnabled']),
|
|
42
|
+
presetEnabled: z.boolean(),
|
|
43
|
+
presetOverridesLegacy: z.boolean().optional(),
|
|
44
|
+
}).optional(),
|
|
45
|
+
replacements: z.array(z.object({
|
|
46
|
+
action: z.enum(['codex-exec', 'codex-plan', 'codex-patch']),
|
|
47
|
+
tools: z.array(z.string()),
|
|
48
|
+
available: z.boolean(),
|
|
49
|
+
reason: z.enum(['conditional', 'target-exists']).optional(),
|
|
50
|
+
})),
|
|
51
|
+
})),
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
export const presetPromptCatalogSchema = z.object({
|
|
55
|
+
preset: z.string(),
|
|
56
|
+
sections: z.array(z.object({
|
|
57
|
+
name: z.string(),
|
|
58
|
+
label: z.string(),
|
|
59
|
+
text: z.string().max(1_000_000),
|
|
60
|
+
editable: z.boolean(),
|
|
61
|
+
order: z.number().finite().optional(),
|
|
62
|
+
complete: z.boolean().optional(),
|
|
63
|
+
interpolate: z.boolean().optional(),
|
|
64
|
+
reason: z.string().optional(),
|
|
65
|
+
})).max(200),
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
function descriptor(
|
|
69
|
+
method: string,
|
|
70
|
+
parameter: string | undefined,
|
|
71
|
+
input: z.ZodType,
|
|
72
|
+
output: z.ZodType,
|
|
73
|
+
): InvocationDescriptor {
|
|
74
|
+
const id = `${PRESET_EDITOR_PACKAGE}#${PRESET_EDITOR_SERVICE}/${method}`
|
|
75
|
+
const strictCodec = (typeSymbol: string, schema: z.ZodType) => ({
|
|
76
|
+
mode: 'strict' as const,
|
|
77
|
+
typeSymbol,
|
|
78
|
+
create: () => schema,
|
|
79
|
+
})
|
|
80
|
+
return {
|
|
81
|
+
id,
|
|
82
|
+
service: PRESET_EDITOR_SERVICE,
|
|
83
|
+
namespace: PRESET_EDITOR_SERVICE,
|
|
84
|
+
method,
|
|
85
|
+
invocation: { kind: 'direct' as const },
|
|
86
|
+
parameters: parameter === undefined ? [] : [{
|
|
87
|
+
name: parameter,
|
|
88
|
+
wire: parameter,
|
|
89
|
+
source: 'json' as const,
|
|
90
|
+
codec: strictCodec(`${id}:${parameter}`, input),
|
|
91
|
+
}],
|
|
92
|
+
result: strictCodec(`${id}:result`, output),
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export function buildPresetEditorDescriptors(): readonly InvocationDescriptor[] {
|
|
97
|
+
return [
|
|
98
|
+
descriptor('catalog', undefined, z.unknown(), presetCatalogSchema),
|
|
99
|
+
descriptor('tools', 'id', presetIdSchema, presetToolCatalogSchema),
|
|
100
|
+
descriptor('prompts', 'id', presetIdSchema, presetPromptCatalogSchema),
|
|
101
|
+
descriptor('read', 'id', presetIdSchema, presetDefinitionSchema),
|
|
102
|
+
]
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export const presetEditorRemote = {
|
|
106
|
+
package: PRESET_EDITOR_PACKAGE,
|
|
107
|
+
descriptors: buildPresetEditorDescriptors(),
|
|
108
|
+
} satisfies TypertRemoteContribution
|
|
109
|
+
|
|
110
|
+
export default presetEditorRemote
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/** Default plugin-owned Codex operating prompt. */
|
|
2
|
+
export const DEFAULT_CODEX_SYSTEM_PROMPT = String.raw`## General
|
|
3
|
+
|
|
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
|
+
|
|
6
|
+
## Editing constraints
|
|
7
|
+
|
|
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.
|
|
10
|
+
- Add succinct code comments that explain non-obvious code. Do not add comments that merely narrate assignments or control flow.
|
|
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.
|
|
12
|
+
|
|
13
|
+
## Planning
|
|
14
|
+
|
|
15
|
+
- Use update_plan for work with multiple meaningful steps. Keep the plan current as the task progresses.
|
|
16
|
+
- Do not use a plan for a trivial one-step request.
|
|
17
|
+
|
|
18
|
+
## dsh session
|
|
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.
|
|
23
|
+
|
|
24
|
+
## Task execution
|
|
25
|
+
|
|
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.
|
|
29
|
+
|
|
30
|
+
## Presenting your work
|
|
31
|
+
|
|
32
|
+
- Be concise, direct, friendly, and actionable, and lead with the result.
|
|
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.
|
|
35
|
+
- Do not dump large files into the conversation; refer to their paths.
|
|
36
|
+
- Use plain text with short sections only when they improve scanability.
|
|
37
|
+
|
|
38
|
+
## Working principles
|
|
39
|
+
|
|
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.
|
|
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.
|
|
42
|
+
- Solve problems by thinking from first principles and at a higher level.
|
|
43
|
+
`
|
|
44
|
+
|
|
45
|
+
/** Default deployment Persona template used by the Codex preset. */
|
|
46
|
+
export const DEFAULT_CODEX_PERSONA = String.raw`You are Codex, a coding agent based on the {{model}} model.`
|
|
47
|
+
|
|
48
|
+
/** Default DSH Core source-checkout guidance template. */
|
|
49
|
+
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.`
|
|
50
|
+
|
|
51
|
+
/** Default DSH Web runtime guidance template. */
|
|
52
|
+
export const DEFAULT_DSH_CORE_WEB_PROMPT = [
|
|
53
|
+
'You are interacting with the user through the DeepSeek Harness Web GUI at {{webUrl}}.',
|
|
54
|
+
'When the user refers to "this page", "this GUI", or "this app" without naming another target, they mean this GUI.',
|
|
55
|
+
'The browser provides no implicit DOM, route, or screenshot context.',
|
|
56
|
+
'The client-plugin HMR receiver is active, but client-plugin changes reload without a refresh only while `pnpm run dev:web` is also running from this same checkout to rebuild their bundles; verify that watcher before promising automatic updates.',
|
|
57
|
+
'Every other change - the apps/web shell and plain packages - requires rebuilding the affected Web artifacts and verifying this existing URL after a page refresh.',
|
|
58
|
+
'Starting another server does not update this GUI.',
|
|
59
|
+
'The apps/web Vite entry builds the shell but is not a standalone application because only dsh web injects window.__DSH_BOOT__.',
|
|
60
|
+
'Do not start a replacement server unless the user asks; if one is needed, use a managed background job and verify its exact URL.',
|
|
61
|
+
].join(' ')
|
|
62
|
+
|
|
63
|
+
/** Resolve the full plugin-owned prompt, preserving intentional empty overrides. */
|
|
64
|
+
export function resolveCodexSystemPrompt(systemPrompt?: string): string {
|
|
65
|
+
return systemPrompt ?? DEFAULT_CODEX_SYSTEM_PROMPT
|
|
66
|
+
}
|