@shuind/dsh-codex-harness 0.2.21 → 0.2.32-dsh-v0.2.2-rc.1
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 +121 -0
- package/README.md +48 -38
- package/RELEASE.md +61 -0
- package/assets/codex.svg +5 -0
- package/cordis.patch.yml +150 -6
- package/docs/preset-library.md +39 -23
- package/docs/tool-policy-benchmark.json +310 -0
- package/docs/tool-policy.md +144 -0
- package/lib/client.js +1639 -111
- package/lib/compaction.js +17 -2
- package/lib/index.js +799 -188
- package/lib/installer.js +50 -6
- package/lib/preferences.js +111 -0
- package/lib/tool-policy.js +2235 -0
- package/lib/typert.js +57 -10
- package/lib/types/activity.d.ts +1 -1
- package/lib/types/activity.js +50 -14
- package/lib/types/client/activity.d.ts +33 -9
- package/lib/types/client/desktop.d.ts +43 -0
- package/lib/types/client/desktop.js +121 -0
- package/lib/types/client/entry.d.ts +10 -0
- package/lib/types/client/entry.js +12 -0
- package/lib/types/client/index.d.ts +109 -19
- package/lib/types/client/index.js +21 -40
- package/lib/types/client/policy-drafts.d.ts +25 -0
- package/lib/types/client/policy-drafts.js +47 -0
- package/lib/types/client/preset-copy.d.ts +1 -0
- package/lib/types/client/preset-copy.js +2 -0
- package/lib/types/client/preset-manager.d.ts +12 -2
- package/lib/types/client/preset-manager.js +70 -25
- package/lib/types/client/preset-requests.d.ts +12 -0
- package/lib/types/client/preset-requests.js +101 -0
- package/lib/types/client/session.d.ts +6 -0
- package/lib/types/client/session.js +9 -0
- package/lib/types/client/tool-policy.d.ts +120 -0
- package/lib/types/client/tool-policy.js +394 -0
- package/lib/types/compaction.d.ts +3 -3
- package/lib/types/compaction.js +6 -2
- package/lib/types/desktop-preset.d.ts +20 -0
- package/lib/types/desktop-preset.js +39 -0
- package/lib/types/exec.d.ts +4 -0
- package/lib/types/exec.js +192 -66
- package/lib/types/host-settings.d.ts +4 -0
- package/lib/types/host-settings.js +13 -0
- package/lib/types/index.d.ts +20 -2
- package/lib/types/index.js +181 -68
- package/lib/types/installer.js +11 -2
- package/lib/types/preferences.d.ts +11 -0
- package/lib/types/preferences.js +16 -0
- package/lib/types/preset-editor-remote.d.ts +2 -0
- package/lib/types/preset-editor-remote.js +6 -2
- package/lib/types/preset-editor.d.ts +12 -7
- package/lib/types/preset-editor.js +43 -13
- package/lib/types/preset-prompt-catalog-schema.d.ts +16 -0
- package/lib/types/preset-prompt-catalog-schema.js +11 -0
- package/lib/types/preset-prompt-catalog.d.ts +21 -0
- package/lib/types/preset-prompt-catalog.js +192 -0
- package/lib/types/preset-prompt-contract.d.ts +22 -0
- package/lib/types/preset-prompt-contract.js +3 -0
- package/lib/types/preset-tool-catalog-schema.d.ts +38 -0
- package/lib/types/preset-tool-catalog-schema.js +28 -0
- package/lib/types/preset-tool-catalog.d.ts +5 -0
- package/lib/types/preset-tool-catalog.js +51 -0
- package/lib/types/prompt-sections.d.ts +1 -1
- package/lib/types/prompt-sections.js +9 -3
- package/lib/types/prompt.js +4 -2
- package/lib/types/remote.js +23 -8
- package/lib/types/settings.d.ts +3 -3
- package/lib/types/settings.js +3 -3
- package/lib/types/tool-capabilities.d.ts +32 -0
- package/lib/types/tool-capabilities.js +42 -0
- package/lib/types/tool-policy-contract.d.ts +60 -0
- package/lib/types/tool-policy-contract.js +26 -0
- package/lib/types/tool-policy.d.ts +171 -0
- package/lib/types/tool-policy.js +367 -0
- package/lib/types/typert.host.d.ts +2 -2
- package/lib/types/typert.host.js +12 -2
- package/locale/en.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 +375 -299
- package/scripts/benchmark-tool-policy.mjs +186 -0
- package/scripts/build-preset.mjs +19 -0
- package/scripts/clean-build.mjs +11 -0
- package/src/activity-types.ts +7 -0
- package/src/activity.ts +158 -0
- package/src/client/activity.ts +82 -0
- package/src/client/desktop.tsx +162 -0
- package/src/client/entry.tsx +16 -0
- package/src/client/index.tsx +972 -0
- package/src/client/policy-drafts.ts +56 -0
- package/src/client/preset-copy.ts +83 -0
- package/src/client/preset-manager.tsx +281 -0
- package/src/client/preset-requests.ts +113 -0
- package/src/client/session.ts +11 -0
- package/src/client/tool-policy.tsx +380 -0
- package/src/compact-command.ts +112 -0
- package/src/compaction.ts +190 -0
- package/src/context.ts +15 -0
- package/src/desktop-preset.ts +55 -0
- package/src/exec.ts +570 -0
- package/src/host-settings.ts +17 -0
- package/src/index.ts +1097 -0
- package/src/installer.ts +172 -0
- package/src/invariant.ts +34 -0
- package/src/patch.ts +258 -0
- package/src/preferences.ts +17 -0
- package/src/preset-contract.ts +85 -0
- package/src/preset-editor-remote.ts +41 -0
- package/src/preset-editor.ts +502 -0
- package/src/preset-prompt-catalog-schema.ts +10 -0
- package/src/preset-prompt-catalog.ts +191 -0
- package/src/preset-prompt-contract.ts +21 -0
- package/src/preset-tool-catalog-schema.ts +28 -0
- package/src/preset-tool-catalog.ts +51 -0
- package/src/prompt-sections.ts +33 -0
- package/src/prompt.ts +62 -0
- package/src/remote.ts +748 -0
- package/src/settings.ts +79 -0
- package/src/tool-capabilities.ts +76 -0
- package/src/tool-policy-contract.ts +76 -0
- package/src/tool-policy.ts +388 -0
- package/src/typert.host.ts +119 -0
- package/tsconfig.json +29 -0
- package/tsdown.config.ts +110 -0
- package/lib/types/preset-templates.d.ts +0 -36
- package/lib/types/preset-templates.js +0 -12
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
2
|
+
import type { HostObservable, PropsLocale } from '@deepseek-ai/dsh-client-ui-slots';
|
|
3
|
+
import type { ConfigForm } from '@deepseek-ai/dsh-client-ui-settings/client';
|
|
4
|
+
import type { PresetManagerActions } from './preset-manager.tsx';
|
|
5
|
+
import type { ToolAction, ToolActionContext, ToolPolicyRule } from '../tool-policy-contract.ts';
|
|
6
|
+
export type { ToolPolicyRule } from '../tool-policy-contract.ts';
|
|
7
|
+
export declare const TOOL_POLICY_NAMESPACE = "codex-tool-policy";
|
|
8
|
+
export interface ToolPolicySettings {
|
|
9
|
+
readonly rules: readonly ToolPolicyRule[];
|
|
10
|
+
}
|
|
11
|
+
export type ObservableConfigForm<T> = Pick<ConfigForm<T>, 'getSnapshot' | 'subscribe' | 'mutate'>;
|
|
12
|
+
export type ToolPolicyForm = ObservableConfigForm<ToolPolicySettings>;
|
|
13
|
+
export type ToolPolicyBinding = HostObservable<ToolPolicyForm | undefined>;
|
|
14
|
+
type PolicyForms = Pick<Context['configForms'], 'get' | 'whileServed'>;
|
|
15
|
+
export declare function bindToolPolicy(ctx: Pick<Context, 'effect'>, forms: PolicyForms): ToolPolicyBinding;
|
|
16
|
+
export declare const toolPolicyEn: {
|
|
17
|
+
readonly settingsTabLabel: "Codex Harness";
|
|
18
|
+
readonly settingsToolsPage: "Tool plans";
|
|
19
|
+
readonly settingsRuntimePage: "Runtime preferences";
|
|
20
|
+
readonly settingsAdvanced: "Advanced…";
|
|
21
|
+
readonly settingsAdvancedTools: "Individual tools";
|
|
22
|
+
readonly settingsPresetPrompts: "Preset prompts";
|
|
23
|
+
readonly settingsDefinition: "Original preset definition (read-only)";
|
|
24
|
+
readonly settingsPreferHostedSearch: "Prefer model-hosted search";
|
|
25
|
+
readonly settingsPreferRemoteCompaction: "Prefer remote compaction";
|
|
26
|
+
readonly settingsSharedFailed: "Not saved; this page’s draft is kept. Shared settings may have changed—discard this page’s draft to reload.";
|
|
27
|
+
readonly settingsRuntimeScope: "Shared in this environment";
|
|
28
|
+
readonly settingsSaveRuntime: "Save runtime preferences";
|
|
29
|
+
readonly settingsBundleSummary: "Configure Codex Harness in its dedicated Settings tab.";
|
|
30
|
+
readonly settingsBundlePath: "Settings → Plugins → Codex Harness";
|
|
31
|
+
readonly settingsDefinitionAbsent: "Choose a preset on Tool plans first.";
|
|
32
|
+
readonly globalGroupRequest: "Model requests";
|
|
33
|
+
readonly globalGroupTools: "Tools";
|
|
34
|
+
readonly globalGroupDisplay: "Display";
|
|
35
|
+
readonly globalPrompts: "Prompts";
|
|
36
|
+
readonly globalPending: "Unsaved";
|
|
37
|
+
readonly presetSourcesDetails: "Original preset definition (read-only)";
|
|
38
|
+
readonly toolPolicyTitle: "Tool plan";
|
|
39
|
+
readonly toolPolicyPresetChoice: "Preset";
|
|
40
|
+
readonly toolPolicyInvalidEntry: "Empty preset ID";
|
|
41
|
+
readonly toolPolicyTiming: "Applies: new/reloaded session";
|
|
42
|
+
readonly presetPromptsLoading: "Loading prompts…";
|
|
43
|
+
readonly presetPromptsFailed: "Prompts unavailable.";
|
|
44
|
+
readonly presetPromptsEmpty: "No prompt sections.";
|
|
45
|
+
readonly presetPromptsReload: "Reload prompts";
|
|
46
|
+
readonly presetPromptRestore: "Restore original";
|
|
47
|
+
readonly presetPromptReadOnly: "Read-only";
|
|
48
|
+
readonly presetPromptOverride: "Override";
|
|
49
|
+
readonly presetSummaryTools: "Tools";
|
|
50
|
+
readonly presetSummaryPrompts: "Prompts";
|
|
51
|
+
readonly toolPolicyDraftSummary: "Changes for this save";
|
|
52
|
+
readonly toolPolicyRuleChanged: "Preset changes";
|
|
53
|
+
readonly toolPolicyNoToolDelta: "No pending changes";
|
|
54
|
+
readonly toolPolicySearch: "Search all tools";
|
|
55
|
+
readonly toolPolicyFilter: "Tool filter";
|
|
56
|
+
readonly toolPolicyAll: "All";
|
|
57
|
+
readonly toolPolicyModified: "Customized";
|
|
58
|
+
readonly toolPolicyReplaceable: "Replaceable";
|
|
59
|
+
readonly toolPolicyAction: "Tool action";
|
|
60
|
+
readonly toolPolicyKeep: "Do not change";
|
|
61
|
+
readonly toolPolicyHide: "Hide";
|
|
62
|
+
readonly toolPolicyRestoreChoice: "Restore inherited choice";
|
|
63
|
+
readonly toolPolicyUnsupported: "Saved replacement unavailable";
|
|
64
|
+
readonly toolPolicyConditional: "Conditional";
|
|
65
|
+
readonly toolPolicyTargetExists: "Replacement target already exists";
|
|
66
|
+
readonly toolPolicyPresetDisabled: "Not enabled by the original preset";
|
|
67
|
+
readonly toolPolicyCommandGroup: "Commands";
|
|
68
|
+
readonly toolPolicyPlanGroup: "Planning";
|
|
69
|
+
readonly toolPolicyFileGroup: "Files";
|
|
70
|
+
readonly toolPolicyOtherGroup: "Other tools";
|
|
71
|
+
readonly toolPolicyCustomized: "customized";
|
|
72
|
+
readonly toolLabelPwsh: "PowerShell commands";
|
|
73
|
+
readonly toolLabelBash: "Shell commands";
|
|
74
|
+
readonly toolLabelExec: "Run commands";
|
|
75
|
+
readonly toolLabelStdin: "Continue an interactive command";
|
|
76
|
+
readonly toolLabelPlan: "Task planning";
|
|
77
|
+
readonly toolLabelRead: "Read files";
|
|
78
|
+
readonly toolLabelWrite: "Write files";
|
|
79
|
+
readonly toolLabelEdit: "Edit files";
|
|
80
|
+
readonly toolLabelPatch: "Patch files";
|
|
81
|
+
readonly toolLabelGlob: "Find files";
|
|
82
|
+
readonly toolLabelGrep: "Search file contents";
|
|
83
|
+
readonly toolLabelImage: "View images";
|
|
84
|
+
readonly toolLabelOther: "Other tool";
|
|
85
|
+
readonly toolPolicyToolsLoading: "Loading tools…";
|
|
86
|
+
readonly toolPolicyToolsEmpty: "No registered tools.";
|
|
87
|
+
readonly toolPolicyNoMatches: "No matching tools.";
|
|
88
|
+
readonly toolPolicyToolsFailed: "Tool list unavailable. Saved rules are kept.";
|
|
89
|
+
readonly toolPolicyToolsRefresh: "Refresh tools";
|
|
90
|
+
readonly toolPolicyCatalogLoading: "Loading presets…";
|
|
91
|
+
readonly toolPolicyCatalogEmpty: "No presets found.";
|
|
92
|
+
readonly toolPolicyCatalogFailed: "Preset list unavailable. Saved IDs remain selectable.";
|
|
93
|
+
readonly toolPolicyCatalogRetry: "Reload presets";
|
|
94
|
+
readonly toolPolicyEmpty: "Choose a preset";
|
|
95
|
+
readonly toolPolicySave: "Save this preset";
|
|
96
|
+
readonly toolPolicySaving: "Saving…";
|
|
97
|
+
readonly toolPolicyDiscard: "Discard this preset’s draft";
|
|
98
|
+
readonly toolPolicySaved: "This preset was saved.";
|
|
99
|
+
readonly toolPolicyInvalidPreset: "An empty preset ID cannot be saved.";
|
|
100
|
+
readonly toolPolicyDuplicatePreset: "Duplicate preset IDs cannot be saved.";
|
|
101
|
+
readonly toolPolicyRefused: "Not saved. This draft started from older settings; discard only this preset’s draft to reload.";
|
|
102
|
+
readonly toolPolicyFailed: "Save failed. This preset’s draft is kept.";
|
|
103
|
+
readonly toolPolicyReadOnly: "These settings are read-only.";
|
|
104
|
+
};
|
|
105
|
+
export declare const toolPolicyZh: Record<keyof typeof toolPolicyEn, string>;
|
|
106
|
+
export declare function validateToolPolicyRules(rules: readonly ToolPolicyRule[]): 'toolPolicyInvalidPreset' | 'toolPolicyDuplicatePreset' | undefined;
|
|
107
|
+
export declare function withToolAction(rule: ToolPolicyRule, name: string, action: ToolAction, context?: ToolActionContext): ToolPolicyRule;
|
|
108
|
+
export declare function saveToolPolicy(form: ToolPolicyForm, rules: readonly ToolPolicyRule[], revision: number | undefined): Promise<boolean>;
|
|
109
|
+
export type ToolPolicyMode = 'tools' | 'details' | 'prompts' | 'definition' | 'inactive';
|
|
110
|
+
type PolicyProps = PropsLocale<'codex'> & {
|
|
111
|
+
presetManager?: PresetManagerActions | undefined;
|
|
112
|
+
mode?: ToolPolicyMode;
|
|
113
|
+
};
|
|
114
|
+
export declare function ToolPolicySection({ binding, ...props }: {
|
|
115
|
+
binding: ToolPolicyBinding;
|
|
116
|
+
} & PolicyProps): import("react").JSX.Element | null;
|
|
117
|
+
export declare function ToolPolicySettingsCard({ form, presetManager, mode, t }: {
|
|
118
|
+
form: ToolPolicyForm;
|
|
119
|
+
} & PolicyProps): import("react").JSX.Element | null;
|
|
120
|
+
//# sourceMappingURL=tool-policy.d.ts.map
|
|
@@ -0,0 +1,394 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
/** One target at a time, with independent revision-fenced drafts. */
|
|
3
|
+
import { useEffect, useRef, useState, useSyncExternalStore } from 'react';
|
|
4
|
+
import { PresetDefinitionCard } from "./preset-manager.js";
|
|
5
|
+
import { cachedPresetCatalog, cachedPresetPrompts, cachedPresetTools, requestPresetCatalog, requestPresetPrompts, requestPresetTools } from "./preset-requests.js";
|
|
6
|
+
import { effectiveToolAction, legacyToolAction, PRESET_PROMPT_NAMES } from "../tool-policy-contract.js";
|
|
7
|
+
import { acceptPresetSave, editPresetDraft, preparePresetSave, presetRules, sameRules } from "./policy-drafts.js";
|
|
8
|
+
export const TOOL_POLICY_NAMESPACE = 'codex-tool-policy';
|
|
9
|
+
export function bindToolPolicy(ctx, forms) {
|
|
10
|
+
let form;
|
|
11
|
+
const listeners = new Set();
|
|
12
|
+
const publish = (next) => { form = next; for (const listener of [...listeners])
|
|
13
|
+
listener(); };
|
|
14
|
+
ctx.effect(() => forms.whileServed([TOOL_POLICY_NAMESPACE], () => { publish(forms.get(TOOL_POLICY_NAMESPACE)); return () => publish(undefined); }), 'codex client: tool-policy availability');
|
|
15
|
+
return { getSnapshot: () => form, subscribe: listener => { listeners.add(listener); return () => { listeners.delete(listener); }; } };
|
|
16
|
+
}
|
|
17
|
+
export const toolPolicyEn = {
|
|
18
|
+
settingsTabLabel: 'Codex Harness', settingsToolsPage: 'Tool plans', settingsRuntimePage: 'Runtime preferences', settingsAdvanced: 'Advanced…',
|
|
19
|
+
settingsAdvancedTools: 'Individual tools', settingsPresetPrompts: 'Preset prompts', settingsDefinition: 'Original preset definition (read-only)',
|
|
20
|
+
settingsPreferHostedSearch: 'Prefer model-hosted search', settingsPreferRemoteCompaction: 'Prefer remote compaction',
|
|
21
|
+
settingsSharedFailed: 'Not saved; this page’s draft is kept. Shared settings may have changed—discard this page’s draft to reload.',
|
|
22
|
+
settingsRuntimeScope: 'Shared in this environment',
|
|
23
|
+
settingsSaveRuntime: 'Save runtime preferences', settingsBundleSummary: 'Configure Codex Harness in its dedicated Settings tab.',
|
|
24
|
+
settingsBundlePath: 'Settings → Plugins → Codex Harness', settingsDefinitionAbsent: 'Choose a preset on Tool plans first.',
|
|
25
|
+
globalGroupRequest: 'Model requests', globalGroupTools: 'Tools', globalGroupDisplay: 'Display', globalPrompts: 'Prompts', globalPending: 'Unsaved',
|
|
26
|
+
presetSourcesDetails: 'Original preset definition (read-only)', toolPolicyTitle: 'Tool plan', toolPolicyPresetChoice: 'Preset', toolPolicyInvalidEntry: 'Empty preset ID',
|
|
27
|
+
toolPolicyTiming: 'Applies: new/reloaded session',
|
|
28
|
+
presetPromptsLoading: 'Loading prompts…', presetPromptsFailed: 'Prompts unavailable.', presetPromptsEmpty: 'No prompt sections.', presetPromptsReload: 'Reload prompts',
|
|
29
|
+
presetPromptRestore: 'Restore original', presetPromptReadOnly: 'Read-only', presetPromptOverride: 'Override',
|
|
30
|
+
presetSummaryTools: 'Tools', presetSummaryPrompts: 'Prompts',
|
|
31
|
+
toolPolicyDraftSummary: 'Changes for this save', toolPolicyRuleChanged: 'Preset changes', toolPolicyNoToolDelta: 'No pending changes',
|
|
32
|
+
toolPolicySearch: 'Search all tools', toolPolicyFilter: 'Tool filter', toolPolicyAll: 'All', toolPolicyModified: 'Customized', toolPolicyReplaceable: 'Replaceable',
|
|
33
|
+
toolPolicyAction: 'Tool action', toolPolicyKeep: 'Do not change', toolPolicyHide: 'Hide', toolPolicyRestoreChoice: 'Restore inherited choice', toolPolicyUnsupported: 'Saved replacement unavailable',
|
|
34
|
+
toolPolicyConditional: 'Conditional', toolPolicyTargetExists: 'Replacement target already exists', toolPolicyPresetDisabled: 'Not enabled by the original preset',
|
|
35
|
+
toolPolicyCommandGroup: 'Commands', toolPolicyPlanGroup: 'Planning', toolPolicyFileGroup: 'Files', toolPolicyOtherGroup: 'Other tools', toolPolicyCustomized: 'customized',
|
|
36
|
+
toolLabelPwsh: 'PowerShell commands', toolLabelBash: 'Shell commands', toolLabelExec: 'Run commands', toolLabelStdin: 'Continue an interactive command',
|
|
37
|
+
toolLabelPlan: 'Task planning', toolLabelRead: 'Read files', toolLabelWrite: 'Write files', toolLabelEdit: 'Edit files', toolLabelPatch: 'Patch files',
|
|
38
|
+
toolLabelGlob: 'Find files', toolLabelGrep: 'Search file contents', toolLabelImage: 'View images', toolLabelOther: 'Other tool',
|
|
39
|
+
toolPolicyToolsLoading: 'Loading tools…', toolPolicyToolsEmpty: 'No registered tools.', toolPolicyNoMatches: 'No matching tools.', toolPolicyToolsFailed: 'Tool list unavailable. Saved rules are kept.', toolPolicyToolsRefresh: 'Refresh tools',
|
|
40
|
+
toolPolicyCatalogLoading: 'Loading presets…', toolPolicyCatalogEmpty: 'No presets found.', toolPolicyCatalogFailed: 'Preset list unavailable. Saved IDs remain selectable.', toolPolicyCatalogRetry: 'Reload presets',
|
|
41
|
+
toolPolicyEmpty: 'Choose a preset', toolPolicySave: 'Save this preset', toolPolicySaving: 'Saving…', toolPolicyDiscard: 'Discard this preset’s draft', toolPolicySaved: 'This preset was saved.',
|
|
42
|
+
toolPolicyInvalidPreset: 'An empty preset ID cannot be saved.', toolPolicyDuplicatePreset: 'Duplicate preset IDs cannot be saved.',
|
|
43
|
+
toolPolicyRefused: 'Not saved. This draft started from older settings; discard only this preset’s draft to reload.', toolPolicyFailed: 'Save failed. This preset’s draft is kept.', toolPolicyReadOnly: 'These settings are read-only.',
|
|
44
|
+
};
|
|
45
|
+
export const toolPolicyZh = {
|
|
46
|
+
settingsTabLabel: 'Codex Harness', settingsToolsPage: '工具方案', settingsRuntimePage: '运行偏好', settingsAdvanced: '高级…',
|
|
47
|
+
settingsAdvancedTools: '逐项工具', settingsPresetPrompts: '预设提示词', settingsDefinition: '原始预设定义(只读)',
|
|
48
|
+
settingsPreferHostedSearch: '优先使用模型托管搜索', settingsPreferRemoteCompaction: '优先使用远程压缩',
|
|
49
|
+
settingsSharedFailed: '未保存,本页草稿已保留。共享设置可能已更新,请放弃本页草稿后重新读取。',
|
|
50
|
+
settingsRuntimeScope: '本环境共享',
|
|
51
|
+
settingsSaveRuntime: '保存运行偏好', settingsBundleSummary: '请在独立的 Codex Harness 设置页配置。',
|
|
52
|
+
settingsBundlePath: '设置 → 内置插件 → Codex Harness', settingsDefinitionAbsent: '请先在工具方案页选择预设。',
|
|
53
|
+
globalGroupRequest: '模型请求', globalGroupTools: '工具', globalGroupDisplay: '界面', globalPrompts: '提示词', globalPending: '未保存',
|
|
54
|
+
presetSourcesDetails: '原始预设定义(只读)', toolPolicyTitle: '工具方案', toolPolicyPresetChoice: '预设', toolPolicyInvalidEntry: '空预设 ID',
|
|
55
|
+
toolPolicyTiming: '生效:新建/重载会话',
|
|
56
|
+
presetPromptsLoading: '正在读取提示词…', presetPromptsFailed: '提示词暂不可用。', presetPromptsEmpty: '没有提示词段落。', presetPromptsReload: '重新读取提示词',
|
|
57
|
+
presetPromptRestore: '恢复原始', presetPromptReadOnly: '只读', presetPromptOverride: '覆盖',
|
|
58
|
+
presetSummaryTools: '工具', presetSummaryPrompts: '提示词',
|
|
59
|
+
toolPolicyDraftSummary: '本次修改', toolPolicyRuleChanged: '预设方案调整', toolPolicyNoToolDelta: '没有待保存变化',
|
|
60
|
+
toolPolicySearch: '搜索全部工具', toolPolicyFilter: '工具筛选', toolPolicyAll: '全部', toolPolicyModified: '已自定义', toolPolicyReplaceable: '可替换',
|
|
61
|
+
toolPolicyAction: '工具操作', toolPolicyKeep: '不改动', toolPolicyHide: '隐藏', toolPolicyRestoreChoice: '恢复继承选择', toolPolicyUnsupported: '已保存的替换当前不可用',
|
|
62
|
+
toolPolicyConditional: '按条件可用', toolPolicyTargetExists: '替换目标已存在', toolPolicyPresetDisabled: '原预设未启用',
|
|
63
|
+
toolPolicyCommandGroup: '命令执行', toolPolicyPlanGroup: '任务计划', toolPolicyFileGroup: '文件操作', toolPolicyOtherGroup: '其它工具', toolPolicyCustomized: '项自定义',
|
|
64
|
+
toolLabelPwsh: 'PowerShell 命令', toolLabelBash: 'Shell 命令', toolLabelExec: '运行命令', toolLabelStdin: '继续交互式命令',
|
|
65
|
+
toolLabelPlan: '任务计划', toolLabelRead: '读取文件', toolLabelWrite: '写入文件', toolLabelEdit: '修改文件', toolLabelPatch: '补丁修改',
|
|
66
|
+
toolLabelGlob: '查找文件', toolLabelGrep: '搜索文件内容', toolLabelImage: '查看图片', toolLabelOther: '其它工具',
|
|
67
|
+
toolPolicyToolsLoading: '正在读取工具…', toolPolicyToolsEmpty: '没有已注册工具。', toolPolicyNoMatches: '没有匹配工具。', toolPolicyToolsFailed: '工具目录不可用,已保存规则仍保留。', toolPolicyToolsRefresh: '刷新工具',
|
|
68
|
+
toolPolicyCatalogLoading: '正在读取预设…', toolPolicyCatalogEmpty: '没有可选预设。', toolPolicyCatalogFailed: '预设列表不可用,仍可选择已保存 ID。', toolPolicyCatalogRetry: '重新读取预设',
|
|
69
|
+
toolPolicyEmpty: '请选择预设', toolPolicySave: '保存此预设', toolPolicySaving: '正在保存…', toolPolicyDiscard: '放弃此预设草稿', toolPolicySaved: '此预设已保存。',
|
|
70
|
+
toolPolicyInvalidPreset: '预设 ID 为空,无法保存。', toolPolicyDuplicatePreset: '预设 ID 重复,无法保存。',
|
|
71
|
+
toolPolicyRefused: '未保存,草稿基于旧设置。请仅放弃此预设草稿后重新读取。', toolPolicyFailed: '保存失败,此预设草稿已保留。', toolPolicyReadOnly: '当前设置为只读。',
|
|
72
|
+
};
|
|
73
|
+
export function validateToolPolicyRules(rules) {
|
|
74
|
+
const ids = new Set();
|
|
75
|
+
for (const rule of rules) {
|
|
76
|
+
const id = rule.preset.trim();
|
|
77
|
+
if (!id)
|
|
78
|
+
return 'toolPolicyInvalidPreset';
|
|
79
|
+
if (ids.has(id))
|
|
80
|
+
return 'toolPolicyDuplicatePreset';
|
|
81
|
+
ids.add(id);
|
|
82
|
+
}
|
|
83
|
+
return undefined;
|
|
84
|
+
}
|
|
85
|
+
export function withToolAction(rule, name, action, context = {}) {
|
|
86
|
+
const next = { ...rule };
|
|
87
|
+
const tools = [...(rule.tools ?? [])].filter(tool => tool.name !== name);
|
|
88
|
+
if (action !== legacyToolAction(rule, name, context))
|
|
89
|
+
tools.push({ name, action });
|
|
90
|
+
if (tools.length)
|
|
91
|
+
next.tools = tools;
|
|
92
|
+
else
|
|
93
|
+
delete next.tools;
|
|
94
|
+
return next;
|
|
95
|
+
}
|
|
96
|
+
export function saveToolPolicy(form, rules, revision) {
|
|
97
|
+
const value = rules.map(rule => {
|
|
98
|
+
const row = { preset: rule.preset };
|
|
99
|
+
if (rule.allow !== undefined)
|
|
100
|
+
row.allow = [...rule.allow];
|
|
101
|
+
if (rule.deny !== undefined)
|
|
102
|
+
row.deny = [...rule.deny];
|
|
103
|
+
if (rule.replaceShell !== undefined)
|
|
104
|
+
row.replaceShell = rule.replaceShell;
|
|
105
|
+
if (rule.replacePlan !== undefined)
|
|
106
|
+
row.replacePlan = rule.replacePlan;
|
|
107
|
+
if (rule.tools !== undefined)
|
|
108
|
+
row.tools = rule.tools.map(tool => ({ ...tool }));
|
|
109
|
+
if (rule.promptOverrides !== undefined)
|
|
110
|
+
row.promptOverrides = rule.promptOverrides.map(override => ({ name: override.name, text: override.text }));
|
|
111
|
+
return row;
|
|
112
|
+
});
|
|
113
|
+
return form.mutate([{ op: 'set', path: ['rules'], value }], revision);
|
|
114
|
+
}
|
|
115
|
+
const isPromptName = (name) => PRESET_PROMPT_NAMES.includes(name);
|
|
116
|
+
const fileNames = new Set(['read', 'write', 'edit', 'apply_patch', 'glob', 'grep', 'read_image']);
|
|
117
|
+
function groupOf(tool) {
|
|
118
|
+
if (['bash', 'pwsh', 'exec_command', 'write_stdin'].includes(tool.name) || tool.replacements.some(item => item.action === 'codex-exec'))
|
|
119
|
+
return 'command';
|
|
120
|
+
if (['todo_write', 'update_plan'].includes(tool.name) || tool.replacements.some(item => item.action === 'codex-plan'))
|
|
121
|
+
return 'plan';
|
|
122
|
+
return fileNames.has(tool.name) ? 'file' : 'other';
|
|
123
|
+
}
|
|
124
|
+
const humanLabels = { pwsh: 'toolLabelPwsh', bash: 'toolLabelBash', exec_command: 'toolLabelExec', write_stdin: 'toolLabelStdin', todo_write: 'toolLabelPlan', update_plan: 'toolLabelPlan',
|
|
125
|
+
read: 'toolLabelRead', write: 'toolLabelWrite', edit: 'toolLabelEdit', apply_patch: 'toolLabelPatch', glob: 'toolLabelGlob', grep: 'toolLabelGrep', read_image: 'toolLabelImage' };
|
|
126
|
+
const policyStyles = `
|
|
127
|
+
.codex-tool-policy { min-width:0; font-size:14px; color:var(--dsw-alias-label-primary); }
|
|
128
|
+
.codex-tool-policy p, .codex-tool-policy h3 { margin:0; }
|
|
129
|
+
.codex-tool-policy h3 { font-size:14px; }
|
|
130
|
+
.codex-tool-policy .codex-tool-policy-note, .codex-tool-policy code { color:var(--dsw-alias-label-secondary); font-size:12px; line-height:1.5; }
|
|
131
|
+
.codex-tool-policy form, .codex-tool-policy fieldset { min-width:0; margin:0; padding:0; border:0; }
|
|
132
|
+
.codex-tool-policy .codex-tool-policy-head { display:grid; gap:12px; margin-bottom:16px; }
|
|
133
|
+
.codex-tool-policy .codex-tool-policy-picker, .codex-tool-policy .codex-tool-policy-filters { display:grid; grid-template-columns:minmax(0,1fr) auto; align-items:end; gap:8px; }
|
|
134
|
+
.codex-tool-policy .codex-tool-policy-field { display:grid; gap:8px; min-width:0; }
|
|
135
|
+
.codex-tool-policy input[type=text], .codex-tool-policy select, .codex-tool-policy button { box-sizing:border-box; min-width:0; max-width:100%; padding:7px 12px; border:1px solid var(--dsw-alias-border-l2); border-radius:8px; background:var(--dsw-alias-bg-layer-2); color:inherit; font:inherit; }
|
|
136
|
+
.codex-tool-policy input[type=text], .codex-tool-policy select { width:100%; }
|
|
137
|
+
.codex-tool-policy button { cursor:pointer; }
|
|
138
|
+
.codex-tool-policy button:disabled { opacity:.5; cursor:default; }
|
|
139
|
+
.codex-tool-policy :is(input,select,button,summary):focus-visible { outline:2px solid var(--dsw-alias-brand-primary); outline-offset:2px; }
|
|
140
|
+
.codex-tool-policy .codex-tool-policy-table { max-height:360px; overflow:auto; }
|
|
141
|
+
.codex-tool-policy .codex-tool-policy-tool { display:grid; grid-template-columns:minmax(0,1fr) minmax(160px,280px); gap:12px; align-items:center; padding:8px 0; border-bottom:1px solid var(--dsw-alias-border-l1); }
|
|
142
|
+
.codex-tool-policy .codex-tool-policy-name { min-width:0; display:grid; gap:4px; overflow-wrap:anywhere; }
|
|
143
|
+
.codex-tool-policy .codex-tool-policy-identifier { font-size:14px; font-weight:600; color:var(--dsw-alias-label-primary); }
|
|
144
|
+
.codex-tool-policy .codex-tool-policy-description { font-size:12px; line-height:1.5; color:var(--dsw-alias-label-secondary); }
|
|
145
|
+
.codex-tool-policy .codex-tool-policy-action { min-width:0; display:flex; gap:8px; align-items:center; }
|
|
146
|
+
.codex-tool-policy .codex-tool-policy-action select { min-width:0; flex:1; }
|
|
147
|
+
.codex-tool-policy .codex-tool-policy-primary { background:var(--dsw-alias-label-primary); color:var(--dsw-alias-bg-base); }
|
|
148
|
+
.codex-tool-policy details { border-top:1px solid var(--dsw-alias-border-l1); padding:12px 0; }
|
|
149
|
+
.codex-tool-policy summary { cursor:pointer; }
|
|
150
|
+
.codex-tool-policy summary .codex-tool-policy-note { margin-left:8px; }
|
|
151
|
+
.codex-tool-policy .codex-tool-policy-actions { display:flex; gap:8px; align-items:center; flex-wrap:wrap; margin-top:16px; }
|
|
152
|
+
.codex-tool-policy .codex-tool-policy-warning { color:var(--dsw-alias-state-warn-primary); font-size:12px; }
|
|
153
|
+
.codex-tool-policy .codex-tool-policy-error { color:var(--dsw-alias-state-error-primary); font-size:12px; }
|
|
154
|
+
.codex-tool-policy .codex-tool-policy-prompts { display:grid; gap:16px; }
|
|
155
|
+
.codex-tool-policy .codex-tool-policy-prompt { display:grid; gap:8px; padding:12px 0; border-top:1px solid var(--dsw-alias-border-l1); }
|
|
156
|
+
.codex-tool-policy .codex-tool-policy-prompt h4 { margin:0; font-size:14px; font-weight:600; }
|
|
157
|
+
.codex-tool-policy textarea { box-sizing:border-box; width:100%; min-width:0; resize:vertical; padding:8px 12px; border:1px solid var(--dsw-alias-border-l2); border-radius:8px; background:var(--dsw-alias-bg-layer-2); color:inherit; font:inherit; }
|
|
158
|
+
.codex-tool-policy textarea:focus-visible { outline:2px solid var(--dsw-alias-brand-primary); outline-offset:2px; }
|
|
159
|
+
.codex-tool-policy .codex-tool-policy-prompt pre { margin:0; max-height:240px; overflow:auto; white-space:pre-wrap; overflow-wrap:anywhere; font:inherit; }
|
|
160
|
+
@media (max-width:480px) { .codex-tool-policy .codex-tool-policy-tool { grid-template-columns:minmax(0,1fr); gap:8px; } }
|
|
161
|
+
`;
|
|
162
|
+
export function ToolPolicySection({ binding, ...props }) {
|
|
163
|
+
const form = useSyncExternalStore(binding.subscribe, binding.getSnapshot, binding.getSnapshot);
|
|
164
|
+
return form === undefined ? null : _jsx(ToolPolicySettingsCard, { form: form, ...props });
|
|
165
|
+
}
|
|
166
|
+
export function ToolPolicySettingsCard({ form, presetManager, mode = 'tools', t }) {
|
|
167
|
+
const snapshot = useSyncExternalStore(listener => form.subscribe(listener), () => form.getSnapshot(), () => form.getSnapshot());
|
|
168
|
+
const [drafts, setDrafts] = useState(() => new Map());
|
|
169
|
+
const [saving, setSaving] = useState(false);
|
|
170
|
+
const [error, setError] = useState('');
|
|
171
|
+
const [notice, setNotice] = useState('');
|
|
172
|
+
const [selection, setSelection] = useState();
|
|
173
|
+
const [query, setQuery] = useState('');
|
|
174
|
+
const [filter, setFilter] = useState('all');
|
|
175
|
+
const [groupOpen, setGroupOpen] = useState(() => new Map());
|
|
176
|
+
const [toolsView, setToolsView] = useState();
|
|
177
|
+
const [promptsView, setPromptsView] = useState();
|
|
178
|
+
const alive = useRef(true);
|
|
179
|
+
const catalogRequest = useRef(0);
|
|
180
|
+
const toolsRequest = useRef(0);
|
|
181
|
+
const promptsRequest = useRef(0);
|
|
182
|
+
const [catalog, setCatalog] = useState(() => presetManager === undefined ? undefined : cachedPresetCatalog(presetManager));
|
|
183
|
+
const [catalogState, setCatalogState] = useState(() => catalog ? 'ready' : presetManager ? 'loading' : 'error');
|
|
184
|
+
function loadCatalog(refresh = false) {
|
|
185
|
+
const ticket = ++catalogRequest.current;
|
|
186
|
+
if (presetManager === undefined) {
|
|
187
|
+
setCatalogState('error');
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
setCatalogState('loading');
|
|
191
|
+
void requestPresetCatalog(presetManager, refresh).then(value => {
|
|
192
|
+
if (alive.current && ticket === catalogRequest.current) {
|
|
193
|
+
setCatalog(value);
|
|
194
|
+
setCatalogState('ready');
|
|
195
|
+
}
|
|
196
|
+
}).catch(() => { if (alive.current && ticket === catalogRequest.current)
|
|
197
|
+
setCatalogState('error'); });
|
|
198
|
+
}
|
|
199
|
+
useEffect(() => { alive.current = true; loadCatalog(); return () => { alive.current = false; catalogRequest.current++; toolsRequest.current++; promptsRequest.current++; }; }, [presetManager]);
|
|
200
|
+
const acceptedRules = snapshot.value?.rules ?? [];
|
|
201
|
+
const ids = [...new Set([...(catalog?.presets.map(preset => preset.id) ?? []), ...acceptedRules.map(rule => rule.preset), ...drafts.keys()])].filter(id => id.trim());
|
|
202
|
+
const selectedId = selection ?? ids[0] ?? '';
|
|
203
|
+
const currentDraft = drafts.get(selectedId);
|
|
204
|
+
const currentRules = currentDraft?.rules ?? presetRules(acceptedRules, selectedId);
|
|
205
|
+
const rule = currentRules[0];
|
|
206
|
+
const duplicate = currentRules.length > 1;
|
|
207
|
+
const presetLabel = catalog?.presets.find(preset => preset.id === selectedId)?.name ?? selectedId;
|
|
208
|
+
function loadTools(refresh = false) {
|
|
209
|
+
const ticket = ++toolsRequest.current;
|
|
210
|
+
if (!selectedId || presetManager === undefined) {
|
|
211
|
+
setToolsView({ preset: selectedId, status: 'error' });
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
setToolsView({ preset: selectedId, status: 'loading' });
|
|
215
|
+
void requestPresetTools(presetManager, selectedId, refresh).then(value => {
|
|
216
|
+
if (alive.current && ticket === toolsRequest.current)
|
|
217
|
+
setToolsView({ preset: selectedId, status: 'ready', value });
|
|
218
|
+
}).catch(() => { if (alive.current && ticket === toolsRequest.current)
|
|
219
|
+
setToolsView({ preset: selectedId, status: 'error' }); });
|
|
220
|
+
}
|
|
221
|
+
useEffect(() => { loadTools(); return () => { toolsRequest.current++; }; }, [presetManager, selectedId]);
|
|
222
|
+
const cached = presetManager && selectedId ? cachedPresetTools(presetManager, selectedId) : undefined;
|
|
223
|
+
const inventory = toolsView?.preset === selectedId && toolsView.status === 'error' ? undefined : toolsView?.preset === selectedId && toolsView.status === 'ready' ? toolsView.value : cached;
|
|
224
|
+
const toolsStatus = inventory ? 'ready' : toolsView?.preset === selectedId ? toolsView.status : selectedId ? 'loading' : 'error';
|
|
225
|
+
function loadPrompts(refresh = false) {
|
|
226
|
+
const ticket = ++promptsRequest.current;
|
|
227
|
+
if (!selectedId || presetManager === undefined) {
|
|
228
|
+
setPromptsView({ preset: selectedId, status: 'error' });
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
setPromptsView({ preset: selectedId, status: 'loading' });
|
|
232
|
+
void requestPresetPrompts(presetManager, selectedId, refresh).then(value => {
|
|
233
|
+
if (alive.current && ticket === promptsRequest.current)
|
|
234
|
+
setPromptsView({ preset: selectedId, status: 'ready', value });
|
|
235
|
+
}).catch(() => { if (alive.current && ticket === promptsRequest.current)
|
|
236
|
+
setPromptsView({ preset: selectedId, status: 'error' }); });
|
|
237
|
+
}
|
|
238
|
+
useEffect(() => {
|
|
239
|
+
if (mode === 'prompts')
|
|
240
|
+
loadPrompts();
|
|
241
|
+
return () => { promptsRequest.current++; };
|
|
242
|
+
}, [presetManager, selectedId, mode === 'prompts']);
|
|
243
|
+
const cachedPrompts = presetManager && selectedId ? cachedPresetPrompts(presetManager, selectedId) : undefined;
|
|
244
|
+
const promptCatalog = promptsView?.preset === selectedId && promptsView.status === 'error' ? undefined
|
|
245
|
+
: promptsView?.preset === selectedId && promptsView.status === 'ready' ? promptsView.value : cachedPrompts;
|
|
246
|
+
const promptsStatus = promptCatalog ? 'ready' : promptsView?.preset === selectedId ? promptsView.status : selectedId ? 'loading' : 'error';
|
|
247
|
+
const contextFor = (tool) => ({ ...(inventory?.legacyCapabilities === undefined ? {} : { legacyCapabilities: inventory.legacyCapabilities }), ...(tool.codexTool === undefined ? {} : { codexTool: tool.codexTool }) });
|
|
248
|
+
const chosen = (tool) => effectiveToolAction(rule, tool.name, contextFor(tool));
|
|
249
|
+
const customized = (tool) => chosen(tool) !== effectiveToolAction(undefined, tool.name, contextFor(tool)) || !!rule?.tools?.some(choice => choice.name === tool.name);
|
|
250
|
+
const inventoryNames = new Set(inventory?.tools.map(tool => tool.name) ?? []);
|
|
251
|
+
const stage = (change) => {
|
|
252
|
+
if (snapshot.status !== 'ready' || !snapshot.writable || saving)
|
|
253
|
+
return;
|
|
254
|
+
const latest = form.getSnapshot();
|
|
255
|
+
setError('');
|
|
256
|
+
setNotice('');
|
|
257
|
+
setDrafts(previous => editPresetDraft(previous, selectedId, { revision: latest.revision, rules: latest.value?.rules ?? [] }, change));
|
|
258
|
+
};
|
|
259
|
+
const editRule = (change) => stage(previous => {
|
|
260
|
+
const base = previous[0] ?? { preset: selectedId, replaceShell: false, replacePlan: false };
|
|
261
|
+
const next = change(base);
|
|
262
|
+
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;
|
|
263
|
+
if (neutralNew)
|
|
264
|
+
return [];
|
|
265
|
+
if (previous.length === 0)
|
|
266
|
+
return [next];
|
|
267
|
+
return previous.map((value, position) => position === 0 ? next : value);
|
|
268
|
+
});
|
|
269
|
+
const chooseAction = (tool, action) => {
|
|
270
|
+
if (duplicate || !selectedId || (action !== 'keep' && action !== 'hide' && action !== 'codex-exec' && action !== 'codex-plan'))
|
|
271
|
+
return;
|
|
272
|
+
if (action !== 'keep' && action !== 'hide' && !tool.replacements.some(replacement => replacement.action === action && replacement.available))
|
|
273
|
+
return;
|
|
274
|
+
const context = contextFor(tool);
|
|
275
|
+
if (rule === undefined && action === legacyToolAction(undefined, tool.name, context))
|
|
276
|
+
return;
|
|
277
|
+
editRule(value => withToolAction(value, tool.name, action, context));
|
|
278
|
+
};
|
|
279
|
+
const removeChoice = (name) => editRule(value => {
|
|
280
|
+
const next = { ...value };
|
|
281
|
+
const tools = (value.tools ?? []).filter(choice => choice.name !== name);
|
|
282
|
+
if (tools.length)
|
|
283
|
+
next.tools = tools;
|
|
284
|
+
else
|
|
285
|
+
delete next.tools;
|
|
286
|
+
return next;
|
|
287
|
+
});
|
|
288
|
+
const changePrompt = (section, text) => {
|
|
289
|
+
if (duplicate || !section.editable || !isPromptName(section.name) || promptCatalog?.preset !== selectedId)
|
|
290
|
+
return;
|
|
291
|
+
const name = section.name;
|
|
292
|
+
editRule(value => ({ ...value, promptOverrides: [...(value.promptOverrides ?? []).filter(entry => entry.name !== name), { name, text }] }));
|
|
293
|
+
};
|
|
294
|
+
const restorePrompt = (section) => {
|
|
295
|
+
if (duplicate || !section.editable || !isPromptName(section.name) || promptCatalog?.preset !== selectedId)
|
|
296
|
+
return;
|
|
297
|
+
editRule(value => {
|
|
298
|
+
const next = { ...value };
|
|
299
|
+
const remaining = (value.promptOverrides ?? []).filter(entry => entry.name !== section.name);
|
|
300
|
+
if (remaining.length)
|
|
301
|
+
next.promptOverrides = remaining;
|
|
302
|
+
else
|
|
303
|
+
delete next.promptOverrides;
|
|
304
|
+
return next;
|
|
305
|
+
});
|
|
306
|
+
};
|
|
307
|
+
const saveCurrent = () => {
|
|
308
|
+
if (!currentDraft || saving || !snapshot.writable || snapshot.status !== 'ready')
|
|
309
|
+
return;
|
|
310
|
+
const latest = form.getSnapshot();
|
|
311
|
+
const target = selectedId;
|
|
312
|
+
const targetName = presetLabel && presetLabel !== target ? `${presetLabel} (${target})` : target || t('toolPolicyInvalidEntry');
|
|
313
|
+
const message = (key) => `${targetName}: ${t(key)}`;
|
|
314
|
+
let prepared;
|
|
315
|
+
try {
|
|
316
|
+
prepared = preparePresetSave(currentDraft, { revision: latest.revision, rules: latest.value?.rules ?? [] });
|
|
317
|
+
const invalid = validateToolPolicyRules(currentDraft.rules);
|
|
318
|
+
const otherIds = new Set((latest.value?.rules ?? []).filter(value => value.preset !== selectedId).map(value => value.preset.trim()));
|
|
319
|
+
if (invalid || currentDraft.rules.some(value => otherIds.has(value.preset.trim()))) {
|
|
320
|
+
setError(message(invalid ?? 'toolPolicyDuplicatePreset'));
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
catch {
|
|
325
|
+
setError(message('toolPolicyRefused'));
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
328
|
+
setSaving(true);
|
|
329
|
+
setError('');
|
|
330
|
+
setNotice('');
|
|
331
|
+
void saveToolPolicy(form, prepared.rules, prepared.revision).then(accepted => {
|
|
332
|
+
if (!alive.current)
|
|
333
|
+
return;
|
|
334
|
+
if (!accepted) {
|
|
335
|
+
setError(message('toolPolicyRefused'));
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
338
|
+
const after = form.getSnapshot();
|
|
339
|
+
setDrafts(previous => acceptPresetSave(previous, prepared, { revision: after.revision, rules: after.value?.rules ?? [] }));
|
|
340
|
+
setNotice(message('toolPolicySaved'));
|
|
341
|
+
}).catch(() => { if (alive.current)
|
|
342
|
+
setError(message('toolPolicyFailed')); }).finally(() => { if (alive.current)
|
|
343
|
+
setSaving(false); });
|
|
344
|
+
};
|
|
345
|
+
const human = (tool) => {
|
|
346
|
+
const key = humanLabels[tool.name];
|
|
347
|
+
return key ? t(key) : tool.description.split(/[\n。.!]/u)[0]?.trim().slice(0, 60) || t('toolLabelOther');
|
|
348
|
+
};
|
|
349
|
+
const beforeTarget = currentDraft ? presetRules(currentDraft.baseline, selectedId) : [];
|
|
350
|
+
const beforeRule = beforeTarget[0];
|
|
351
|
+
const choiceFor = (value, name) => value?.tools?.find(choice => choice.name === name);
|
|
352
|
+
const changedNames = currentDraft ? [...new Set([
|
|
353
|
+
...(inventory?.tools.filter(tool => effectiveToolAction(beforeRule, tool.name, contextFor(tool)) !== chosen(tool)
|
|
354
|
+
|| JSON.stringify(choiceFor(beforeRule, tool.name)) !== JSON.stringify(choiceFor(rule, tool.name))).map(tool => tool.name) ?? []),
|
|
355
|
+
...[...(beforeRule?.tools ?? []), ...(rule?.tools ?? [])].filter(choice => !inventoryNames.has(choice.name)
|
|
356
|
+
&& JSON.stringify(choiceFor(beforeRule, choice.name)) !== JSON.stringify(choiceFor(rule, choice.name))).map(choice => choice.name),
|
|
357
|
+
])] : [];
|
|
358
|
+
const changedPrompts = currentDraft ? [...new Set([...(beforeRule?.promptOverrides ?? []), ...(rule?.promptOverrides ?? [])].map(entry => entry.name))]
|
|
359
|
+
.filter(name => JSON.stringify(beforeRule?.promptOverrides?.find(entry => entry.name === name)) !== JSON.stringify(rule?.promptOverrides?.find(entry => entry.name === name))) : [];
|
|
360
|
+
const summaryParts = [
|
|
361
|
+
...(changedNames.length ? [`${t('presetSummaryTools')}: ${changedNames.slice(0, 4).join(', ')}${changedNames.length > 4 ? ` (+${changedNames.length - 4})` : ''}`] : []),
|
|
362
|
+
...(changedPrompts.length ? [`${t('presetSummaryPrompts')}: ${changedPrompts.map(name => promptCatalog?.sections.find(section => section.name === name)?.label || name).join(', ')}`] : []),
|
|
363
|
+
];
|
|
364
|
+
const changeSummary = summaryParts.join(' · ') || t(currentDraft && !sameRules(beforeTarget, currentDraft.rules) ? 'toolPolicyRuleChanged' : 'toolPolicyNoToolDelta');
|
|
365
|
+
const unavailable = (reason) => t(reason === 'conditional' ? 'toolPolicyConditional' : reason === 'target-exists' ? 'toolPolicyTargetExists' : 'toolPolicyUnsupported');
|
|
366
|
+
const rows = (tools) => _jsxs("div", { className: "codex-tool-policy-table", role: "table", "aria-label": t('toolPolicyTitle'), children: [tools.map(tool => {
|
|
367
|
+
const action = chosen(tool);
|
|
368
|
+
const supported = action === 'keep' || action === 'hide' || tool.replacements.some(option => option.action === action);
|
|
369
|
+
return _jsxs("div", { role: "row", className: "codex-tool-policy-tool", "data-tool-name": tool.name, children: [_jsxs("div", { role: "cell", className: "codex-tool-policy-name", children: [_jsx("code", { className: "codex-tool-policy-identifier", children: tool.name }), _jsx("span", { className: "codex-tool-policy-description", title: tool.description, children: human(tool) }), tool.codexTool?.presetEnabled === false && _jsx("span", { className: "codex-tool-policy-note", children: t('toolPolicyPresetDisabled') }), tool.conditional && _jsx("span", { className: "codex-tool-policy-note", children: t('toolPolicyConditional') })] }), _jsxs("div", { role: "cell", className: "codex-tool-policy-action", children: [_jsxs("select", { "aria-label": `${t('toolPolicyAction')} ${tool.name}`, value: action, disabled: duplicate, onChange: event => chooseAction(tool, event.target.value), children: [_jsx("option", { value: "keep", children: t('toolPolicyKeep') }), _jsx("option", { value: "hide", children: t('toolPolicyHide') }), tool.replacements.map(option => _jsxs("option", { value: option.action, disabled: !option.available, title: !option.available ? unavailable(option.reason) : undefined, children: [option.tools.join(' + '), option.available ? '' : ` · ${unavailable(option.reason)}`] }, option.action)), !supported && _jsxs("option", { value: action, disabled: true, children: [t('toolPolicyUnsupported'), " (", action, ")"] })] }), rule?.tools?.some(choice => choice.name === tool.name) && _jsx("button", { type: "button", "aria-label": `${t('toolPolicyRestoreChoice')} ${tool.name}`, title: t('toolPolicyRestoreChoice'), onClick: () => removeChoice(tool.name), children: "\u21B6" })] })] }, tool.name);
|
|
370
|
+
}), tools.length === 0 && _jsx("p", { className: "codex-tool-policy-note", children: t('toolPolicyNoMatches') })] });
|
|
371
|
+
if (snapshot.status !== 'ready' || snapshot.value === undefined || mode === 'inactive')
|
|
372
|
+
return null;
|
|
373
|
+
if (mode === 'definition')
|
|
374
|
+
return !selectedId || presetManager === undefined ? _jsx("p", { children: t('settingsDefinitionAbsent') })
|
|
375
|
+
: _jsx(PresetDefinitionCard, { presetManager: presetManager, id: selectedId, t: t });
|
|
376
|
+
const isDetails = mode === 'details';
|
|
377
|
+
const text = query.trim().toLowerCase();
|
|
378
|
+
const shown = (inventory?.tools ?? []).filter(tool => (!text || `${human(tool)} ${tool.name} ${tool.description}`.toLowerCase().includes(text))
|
|
379
|
+
&& (filter !== 'modified' || customized(tool)) && (filter !== 'replaceable' || tool.replacements.some(replacement => replacement.available)));
|
|
380
|
+
return _jsxs("section", { className: "codex-tool-policy", "aria-label": t(mode === 'prompts' ? 'settingsPresetPrompts' : 'toolPolicyTitle'), children: [_jsx("style", { children: policyStyles }), _jsxs("div", { className: "codex-tool-policy-head", children: [mode === 'prompts' && _jsxs("h3", { children: [presetLabel || t('toolPolicyInvalidEntry'), _jsxs("span", { className: "codex-tool-policy-note", children: [" \u00B7 ", t('settingsPresetPrompts')] })] }), mode === 'tools' || mode === 'prompts' ? _jsxs("div", { className: "codex-tool-policy-picker", children: [_jsxs("label", { className: "codex-tool-policy-field", children: [_jsx("span", { children: t('toolPolicyPresetChoice') }), _jsxs("select", { "aria-label": t('toolPolicyPresetChoice'), value: selectedId, onChange: event => { setSelection(event.target.value); setError(''); setNotice(''); }, children: [!ids.length && _jsx("option", { value: "", children: t('toolPolicyEmpty') }), ids.map(id => _jsxs("option", { value: id, "data-preset-id": id, children: [catalog?.presets.find(preset => preset.id === id)?.name ?? id, drafts.has(id) ? ` · ${t('globalPending')}` : ''] }, id))] })] }), presetManager && _jsx("button", { type: "button", disabled: catalogState === 'loading', onClick: () => loadCatalog(true), children: t('toolPolicyCatalogRetry') })] })
|
|
381
|
+
: _jsxs("h3", { children: [presetLabel || t('toolPolicyInvalidEntry'), " ", _jsx("code", { children: selectedId })] }), (mode === 'tools' || mode === 'prompts') && _jsxs(_Fragment, { children: [catalogState !== 'ready' && _jsx("p", { className: "codex-tool-policy-note", role: "status", children: t(catalogState === 'loading' ? 'toolPolicyCatalogLoading' : 'toolPolicyCatalogFailed') }), catalogState === 'ready' && !ids.length && _jsx("p", { className: "codex-tool-policy-note", children: t('toolPolicyCatalogEmpty') })] }), isDetails && _jsxs("div", { className: "codex-tool-policy-filters", children: [_jsx("input", { type: "text", "aria-label": t('toolPolicySearch'), placeholder: t('toolPolicySearch'), value: query, onChange: event => setQuery(event.target.value) }), _jsxs("select", { "aria-label": t('toolPolicyFilter'), value: filter, onChange: event => setFilter(event.target.value), children: [_jsx("option", { value: "all", children: t('toolPolicyAll') }), _jsx("option", { value: "modified", children: t('toolPolicyModified') }), _jsx("option", { value: "replaceable", children: t('toolPolicyReplaceable') })] })] }), mode !== 'prompts' && toolsStatus !== 'ready' && _jsx("p", { className: "codex-tool-policy-note", role: "status", children: t(toolsStatus === 'loading' ? 'toolPolicyToolsLoading' : 'toolPolicyToolsFailed') }), mode !== 'prompts' && inventory?.tools.length === 0 && _jsx("p", { className: "codex-tool-policy-note", role: "status", children: t('toolPolicyToolsEmpty') }), mode === 'prompts' && _jsxs(_Fragment, { children: [presetManager && selectedId && _jsx("button", { type: "button", disabled: promptsStatus === 'loading', onClick: () => loadPrompts(true), children: t('presetPromptsReload') }), promptsStatus !== 'ready' && _jsx("p", { className: "codex-tool-policy-note", role: "status", children: t(promptsStatus === 'loading' ? 'presetPromptsLoading' : 'presetPromptsFailed') }), promptCatalog?.sections.length === 0 && _jsx("p", { className: "codex-tool-policy-note", children: t('presetPromptsEmpty') })] }), isDetails && presetManager && selectedId && _jsx("button", { type: "button", disabled: toolsStatus === 'loading', onClick: () => loadTools(true), children: t('toolPolicyToolsRefresh') }), duplicate && _jsx("p", { className: "codex-tool-policy-warning", children: t('toolPolicyDuplicatePreset') })] }), _jsx("form", { onSubmit: event => { event.preventDefault(); saveCurrent(); }, children: _jsxs("fieldset", { disabled: !snapshot.writable || saving, children: [mode === 'tools' && inventory && !duplicate && ['command', 'plan', 'file', 'other'].map(group => {
|
|
382
|
+
const tools = inventory.tools.filter(tool => groupOf(tool) === group);
|
|
383
|
+
if (!tools.length)
|
|
384
|
+
return null;
|
|
385
|
+
const changes = tools.filter(customized).length;
|
|
386
|
+
const key = `${selectedId}/${group}`;
|
|
387
|
+
return _jsxs("details", { "data-tool-group": group, open: groupOpen.get(key) ?? (group === 'command' || group === 'plan' || changes > 0), onToggle: event => { const open = event.currentTarget.open; setGroupOpen(previous => new Map(previous).set(key, open)); }, children: [_jsxs("summary", { children: [t(group === 'command' ? 'toolPolicyCommandGroup' : group === 'plan' ? 'toolPolicyPlanGroup' : group === 'file' ? 'toolPolicyFileGroup' : 'toolPolicyOtherGroup'), _jsxs("span", { className: "codex-tool-policy-note", children: [tools.length, changes ? ` · ${changes} ${t('toolPolicyCustomized')}` : ''] })] }), rows(tools)] }, group);
|
|
388
|
+
}), isDetails && inventory && !duplicate && rows(shown), mode === 'prompts' && promptCatalog && _jsx("div", { className: "codex-tool-policy-prompts", children: promptCatalog.sections.map(section => {
|
|
389
|
+
const editable = section.editable && isPromptName(section.name);
|
|
390
|
+
const override = rule?.promptOverrides?.find(entry => entry.name === section.name);
|
|
391
|
+
return _jsxs("section", { className: "codex-tool-policy-prompt", "data-prompt-section": section.name, children: [_jsx("h4", { children: section.label || section.name }), _jsx("code", { children: section.name }), editable ? _jsxs(_Fragment, { children: [_jsx("textarea", { "aria-label": `${t('settingsPresetPrompts')} ${section.name}`, rows: 6, maxLength: 1_000_000, disabled: duplicate || !snapshot.writable || saving, value: override?.text ?? section.text, onChange: event => changePrompt(section, event.target.value) }), _jsx("button", { type: "button", "aria-label": `${t('presetPromptRestore')} ${section.name}`, disabled: !override || duplicate || !snapshot.writable || saving, onClick: () => restorePrompt(section), children: t('presetPromptRestore') })] }) : _jsxs(_Fragment, { children: [_jsx("span", { className: "codex-tool-policy-note", title: section.reason, children: t('presetPromptReadOnly') }), _jsx("pre", { children: section.text })] })] }, section.name);
|
|
392
|
+
}) }), currentDraft && _jsxs("p", { className: "codex-tool-policy-note", "aria-label": t('toolPolicyDraftSummary'), children: [t('toolPolicyDraftSummary'), ": ", changeSummary] }), _jsxs("div", { className: "codex-tool-policy-actions", children: [_jsx("button", { className: "codex-tool-policy-primary", type: "submit", disabled: !currentDraft, children: t(saving ? 'toolPolicySaving' : 'toolPolicySave') }), _jsx("button", { type: "button", disabled: !currentDraft, onClick: () => { setDrafts(previous => { const next = new Map(previous); next.delete(selectedId); return next; }); setError(''); setNotice(''); }, children: t('toolPolicyDiscard') }), _jsx("span", { className: "codex-tool-policy-note", children: t('toolPolicyTiming') })] })] }) }), !snapshot.writable && _jsx("p", { className: "codex-tool-policy-note", children: t('toolPolicyReadOnly') }), error && _jsx("p", { className: "codex-tool-policy-error", role: "alert", children: error }), notice && _jsx("p", { className: "codex-tool-policy-note", role: "status", children: notice })] });
|
|
393
|
+
}
|
|
394
|
+
//# sourceMappingURL=tool-policy.js.map
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
import { Context } from '@deepseek-ai/cordis';
|
|
3
3
|
import BasicCompactionEngine from '@deepseek-ai/dsh-compaction-basic';
|
|
4
4
|
import type { CompactionResult, CompactionTrigger } from '@deepseek-ai/dsh-compaction';
|
|
5
|
-
import type { Agent } from '@deepseek-ai/dsh-agent';
|
|
6
5
|
/** Per-command compaction preference propagated into the LLM stream seam. */
|
|
7
6
|
export type CodexCompactionMode = 'remote' | 'local';
|
|
8
7
|
/** Run one manual compaction with an explicit local/remote preference. */
|
|
@@ -19,7 +18,8 @@ export default class CodexCompactionEngine extends BasicCompactionEngine {
|
|
|
19
18
|
static Config: import("@deepseek-ai/schemastery").default<import("@deepseek-ai/dsh-compaction-basic").BasicCompactionConfig>;
|
|
20
19
|
private readonly activeSession;
|
|
21
20
|
constructor(ctx: Context, config?: ConstructorParameters<typeof BasicCompactionEngine>[1]);
|
|
22
|
-
compactIfNeeded(agent:
|
|
23
|
-
|
|
21
|
+
compactIfNeeded(agent: Parameters<BasicCompactionEngine['compactIfNeeded']>[0], trigger: CompactionTrigger, signal: AbortSignal): Promise<CompactionResult | null>;
|
|
22
|
+
compactRegion(...args: Parameters<BasicCompactionEngine['compactRegion']>): Promise<CompactionResult>;
|
|
23
|
+
compactNow(agent: Parameters<BasicCompactionEngine['compactNow']>[0], signal: AbortSignal, sourceCommandId?: Parameters<BasicCompactionEngine['compactNow']>[2]): Promise<CompactionResult | null>;
|
|
24
24
|
}
|
|
25
25
|
//# sourceMappingURL=compaction.d.ts.map
|
package/lib/types/compaction.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/** Codex compaction backend that honors the latest durable request capacity. */
|
|
2
2
|
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
3
3
|
import BasicCompactionEngine from '@deepseek-ai/dsh-compaction-basic';
|
|
4
|
+
import { readHostSettings } from "./host-settings.js";
|
|
4
5
|
/**
|
|
5
6
|
* The main plugin entry and the compact-command subpath can be evaluated as
|
|
6
7
|
* separate bundles. Keep their async context carrier on the process global so
|
|
@@ -32,9 +33,9 @@ function isGptModel(model) {
|
|
|
32
33
|
/** Read the live Codex capacity without requiring a custom LLM service API. */
|
|
33
34
|
function configuredContextWindow(ctx) {
|
|
34
35
|
const settings = ctx.get('settings');
|
|
35
|
-
if (settings?.get === undefined)
|
|
36
|
+
if (settings?.get === undefined && settings?.describe === undefined)
|
|
36
37
|
return { available: false };
|
|
37
|
-
const value =
|
|
38
|
+
const value = readHostSettings(ctx, CODEX_SETTINGS_NAMESPACE);
|
|
38
39
|
return {
|
|
39
40
|
available: true,
|
|
40
41
|
...value?.contextWindow !== undefined
|
|
@@ -118,6 +119,9 @@ export default class CodexCompactionEngine extends BasicCompactionEngine {
|
|
|
118
119
|
compactIfNeeded(agent, trigger, signal) {
|
|
119
120
|
return this.activeSession.run(agent.session, () => super.compactIfNeeded(agent, trigger, signal));
|
|
120
121
|
}
|
|
122
|
+
compactRegion(...args) {
|
|
123
|
+
return this.activeSession.run(args[2].session, () => super.compactRegion(...args));
|
|
124
|
+
}
|
|
121
125
|
compactNow(agent, signal, sourceCommandId) {
|
|
122
126
|
return this.activeSession.run(agent.session, () => super.compactNow(agent, signal, sourceCommandId));
|
|
123
127
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export interface DesktopPresetRow {
|
|
2
|
+
id: string;
|
|
3
|
+
name: string;
|
|
4
|
+
group?: boolean;
|
|
5
|
+
disabled?: boolean | {
|
|
6
|
+
__jsExpr: string;
|
|
7
|
+
};
|
|
8
|
+
config?: Record<string, unknown> | DesktopPresetRow[];
|
|
9
|
+
isolate?: Record<string, boolean>;
|
|
10
|
+
}
|
|
11
|
+
export interface DesktopPresetDefinition {
|
|
12
|
+
id: string;
|
|
13
|
+
name?: string;
|
|
14
|
+
description?: string;
|
|
15
|
+
order?: number;
|
|
16
|
+
plugins: DesktopPresetRow[];
|
|
17
|
+
}
|
|
18
|
+
/** Convert the legacy file composition to Harness 0.2.2's declarative preset APIs. */
|
|
19
|
+
export declare function desktopCodexPreset(sourceDirectory: string): DesktopPresetDefinition;
|
|
20
|
+
//# sourceMappingURL=desktop-preset.d.ts.map
|