@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.
Files changed (128) hide show
  1. package/CHANGELOG.md +121 -0
  2. package/README.md +48 -38
  3. package/RELEASE.md +61 -0
  4. package/assets/codex.svg +5 -0
  5. package/cordis.patch.yml +150 -6
  6. package/docs/preset-library.md +39 -23
  7. package/docs/tool-policy-benchmark.json +310 -0
  8. package/docs/tool-policy.md +144 -0
  9. package/lib/client.js +1639 -111
  10. package/lib/compaction.js +17 -2
  11. package/lib/index.js +799 -188
  12. package/lib/installer.js +50 -6
  13. package/lib/preferences.js +111 -0
  14. package/lib/tool-policy.js +2235 -0
  15. package/lib/typert.js +57 -10
  16. package/lib/types/activity.d.ts +1 -1
  17. package/lib/types/activity.js +50 -14
  18. package/lib/types/client/activity.d.ts +33 -9
  19. package/lib/types/client/desktop.d.ts +43 -0
  20. package/lib/types/client/desktop.js +121 -0
  21. package/lib/types/client/entry.d.ts +10 -0
  22. package/lib/types/client/entry.js +12 -0
  23. package/lib/types/client/index.d.ts +109 -19
  24. package/lib/types/client/index.js +21 -40
  25. package/lib/types/client/policy-drafts.d.ts +25 -0
  26. package/lib/types/client/policy-drafts.js +47 -0
  27. package/lib/types/client/preset-copy.d.ts +1 -0
  28. package/lib/types/client/preset-copy.js +2 -0
  29. package/lib/types/client/preset-manager.d.ts +12 -2
  30. package/lib/types/client/preset-manager.js +70 -25
  31. package/lib/types/client/preset-requests.d.ts +12 -0
  32. package/lib/types/client/preset-requests.js +101 -0
  33. package/lib/types/client/session.d.ts +6 -0
  34. package/lib/types/client/session.js +9 -0
  35. package/lib/types/client/tool-policy.d.ts +120 -0
  36. package/lib/types/client/tool-policy.js +394 -0
  37. package/lib/types/compaction.d.ts +3 -3
  38. package/lib/types/compaction.js +6 -2
  39. package/lib/types/desktop-preset.d.ts +20 -0
  40. package/lib/types/desktop-preset.js +39 -0
  41. package/lib/types/exec.d.ts +4 -0
  42. package/lib/types/exec.js +192 -66
  43. package/lib/types/host-settings.d.ts +4 -0
  44. package/lib/types/host-settings.js +13 -0
  45. package/lib/types/index.d.ts +20 -2
  46. package/lib/types/index.js +181 -68
  47. package/lib/types/installer.js +11 -2
  48. package/lib/types/preferences.d.ts +11 -0
  49. package/lib/types/preferences.js +16 -0
  50. package/lib/types/preset-editor-remote.d.ts +2 -0
  51. package/lib/types/preset-editor-remote.js +6 -2
  52. package/lib/types/preset-editor.d.ts +12 -7
  53. package/lib/types/preset-editor.js +43 -13
  54. package/lib/types/preset-prompt-catalog-schema.d.ts +16 -0
  55. package/lib/types/preset-prompt-catalog-schema.js +11 -0
  56. package/lib/types/preset-prompt-catalog.d.ts +21 -0
  57. package/lib/types/preset-prompt-catalog.js +192 -0
  58. package/lib/types/preset-prompt-contract.d.ts +22 -0
  59. package/lib/types/preset-prompt-contract.js +3 -0
  60. package/lib/types/preset-tool-catalog-schema.d.ts +38 -0
  61. package/lib/types/preset-tool-catalog-schema.js +28 -0
  62. package/lib/types/preset-tool-catalog.d.ts +5 -0
  63. package/lib/types/preset-tool-catalog.js +51 -0
  64. package/lib/types/prompt-sections.d.ts +1 -1
  65. package/lib/types/prompt-sections.js +9 -3
  66. package/lib/types/prompt.js +4 -2
  67. package/lib/types/remote.js +23 -8
  68. package/lib/types/settings.d.ts +3 -3
  69. package/lib/types/settings.js +3 -3
  70. package/lib/types/tool-capabilities.d.ts +32 -0
  71. package/lib/types/tool-capabilities.js +42 -0
  72. package/lib/types/tool-policy-contract.d.ts +60 -0
  73. package/lib/types/tool-policy-contract.js +26 -0
  74. package/lib/types/tool-policy.d.ts +171 -0
  75. package/lib/types/tool-policy.js +367 -0
  76. package/lib/types/typert.host.d.ts +2 -2
  77. package/lib/types/typert.host.js +12 -2
  78. package/locale/en.json +6 -0
  79. package/locale/tool-policy/en.json +6 -0
  80. package/locale/tool-policy/zh.json +6 -0
  81. package/locale/zh.json +6 -0
  82. package/package.json +375 -299
  83. package/scripts/benchmark-tool-policy.mjs +186 -0
  84. package/scripts/build-preset.mjs +19 -0
  85. package/scripts/clean-build.mjs +11 -0
  86. package/src/activity-types.ts +7 -0
  87. package/src/activity.ts +158 -0
  88. package/src/client/activity.ts +82 -0
  89. package/src/client/desktop.tsx +162 -0
  90. package/src/client/entry.tsx +16 -0
  91. package/src/client/index.tsx +972 -0
  92. package/src/client/policy-drafts.ts +56 -0
  93. package/src/client/preset-copy.ts +83 -0
  94. package/src/client/preset-manager.tsx +281 -0
  95. package/src/client/preset-requests.ts +113 -0
  96. package/src/client/session.ts +11 -0
  97. package/src/client/tool-policy.tsx +380 -0
  98. package/src/compact-command.ts +112 -0
  99. package/src/compaction.ts +190 -0
  100. package/src/context.ts +15 -0
  101. package/src/desktop-preset.ts +55 -0
  102. package/src/exec.ts +570 -0
  103. package/src/host-settings.ts +17 -0
  104. package/src/index.ts +1097 -0
  105. package/src/installer.ts +172 -0
  106. package/src/invariant.ts +34 -0
  107. package/src/patch.ts +258 -0
  108. package/src/preferences.ts +17 -0
  109. package/src/preset-contract.ts +85 -0
  110. package/src/preset-editor-remote.ts +41 -0
  111. package/src/preset-editor.ts +502 -0
  112. package/src/preset-prompt-catalog-schema.ts +10 -0
  113. package/src/preset-prompt-catalog.ts +191 -0
  114. package/src/preset-prompt-contract.ts +21 -0
  115. package/src/preset-tool-catalog-schema.ts +28 -0
  116. package/src/preset-tool-catalog.ts +51 -0
  117. package/src/prompt-sections.ts +33 -0
  118. package/src/prompt.ts +62 -0
  119. package/src/remote.ts +748 -0
  120. package/src/settings.ts +79 -0
  121. package/src/tool-capabilities.ts +76 -0
  122. package/src/tool-policy-contract.ts +76 -0
  123. package/src/tool-policy.ts +388 -0
  124. package/src/typert.host.ts +119 -0
  125. package/tsconfig.json +29 -0
  126. package/tsdown.config.ts +110 -0
  127. package/lib/types/preset-templates.d.ts +0 -36
  128. package/lib/types/preset-templates.js +0 -12
@@ -4,9 +4,11 @@ import { useEffect, useLayoutEffect, useRef, useState } from 'react';
4
4
  import { createPortal } from 'react-dom';
5
5
  import { CODEX_CONTEXT_MAX, CODEX_CONTEXT_UNIT, isCodexPresetId } from "../context.js";
6
6
  import { modelActivity, sameModelActivity } from "./activity.js";
7
+ import { agentPresetFromSession } from "./session.js";
7
8
  import presetEditorRemote from "../preset-editor-remote.js";
8
9
  import { PresetManagerCard } from "./preset-manager.js";
9
10
  import { presetEn, presetZh } from "./preset-copy.js";
11
+ import { toolPolicyEn, toolPolicyZh } from "./tool-policy.js";
10
12
  const NS = 'codex';
11
13
  const SETTINGS_NAMESPACE = 'codex';
12
14
  const FAST_FALLBACK_SLOT = 'conversation.input.right';
@@ -15,7 +17,9 @@ const PLUGIN_SETTINGS_SLOT = 'settings.plugin.item';
15
17
  const DEFAULT_CONTEXT_WINDOW = 262_144;
16
18
  const en = {
17
19
  ...presetEn,
20
+ ...toolPolicyEn,
18
21
  fast: 'Fast mode',
22
+ fastModeControl: 'Show fast mode control',
19
23
  fastOn: 'Fast mode on (priority tier)',
20
24
  fastOff: 'Fast mode off',
21
25
  fastStateOn: 'On',
@@ -44,23 +48,8 @@ const en = {
44
48
  capabilityCompactionHint: 'Prefer the provider Responses compact endpoint before local compaction.',
45
49
  capabilityActivity: 'Activity indicator',
46
50
  capabilityActivityHint: 'Show request, reply, and compaction status beside the conversation.',
47
- promptCustomizationLabel: 'Prompt customization',
48
- personaLabel: 'Persona',
49
- personaHint: 'Deployment identity and role. Supports {{model}} and {{cwd}}.',
50
- sourcePromptLabel: 'DSH Core source instructions',
51
- sourcePromptHint: 'Guidance about the DSH checkout and working directory. Supports {{sourceRoot}}.',
52
- webPromptLabel: 'DSH Core Web instructions',
53
- webPromptHint: 'Guidance about this Web GUI, HMR, builds, and verification. Supports {{webUrl}}.',
54
- promptRestoreAll: 'Restore all prompt defaults',
55
- promptLabel: 'Codex operating prompt',
56
- promptHint: 'This is the Codex operating prompt. Persona and DSH Core instructions are edited separately above.',
57
- promptUnsaved: 'Unsaved',
58
51
  promptDiscard: 'Discard',
59
- promptSave: 'Save',
60
52
  promptSaving: 'Saving...',
61
- promptSaveFailed: 'Could not save the prompt.',
62
- promptExpand: 'Expand settings',
63
- promptCollapse: 'Collapse settings',
64
53
  promptReadOnly: 'This settings document is read-only.',
65
54
  activityCompacting: 'Compacting context...',
66
55
  activityRequestingModel: 'Requesting model...',
@@ -68,6 +57,8 @@ const en = {
68
57
  };
69
58
  const zh = {
70
59
  ...presetZh,
60
+ ...toolPolicyZh,
61
+ fastModeControl: 'Show fast mode control',
71
62
  fast: 'Fast',
72
63
  fastOn: 'Fast mode on (priority tier)',
73
64
  fastOff: 'Fast mode off',
@@ -97,23 +88,8 @@ const zh = {
97
88
  capabilityCompactionHint: '\u4f18\u5148\u8c03\u7528\u63d0\u4f9b\u5546\u7684 Responses compact \u7aef\u70b9\uff0c\u5931\u8d25\u65f6\u56de\u9000\u672c\u5730\u538b\u7f29\u3002',
98
89
  capabilityActivity: '\u6d3b\u52a8\u72b6\u6001',
99
90
  capabilityActivityHint: '\u5728\u5bf9\u8bdd\u65c1\u663e\u793a\u8bf7\u6c42\u3001\u56de\u590d\u548c\u538b\u7f29\u72b6\u6001\u3002',
100
- promptCustomizationLabel: '\u63d0\u793a\u8bcd\u5b9a\u5236',
101
- personaLabel: 'Persona',
102
- personaHint: '\u5b9a\u4e49 Agent \u7684\u8eab\u4efd\u4e0e\u89d2\u8272,\u652f\u6301 {{model}} \u548c {{cwd}}。',
103
- sourcePromptLabel: 'DSH Core \u6e90\u7801\u8bf4\u660e',
104
- sourcePromptHint: '\u8bf4\u660e DSH \u6e90\u7801\u68c0\u51fa\u76ee\u5f55\u4e0e\u5de5\u4f5c\u76ee\u5f55,\u652f\u6301 {{sourceRoot}}。',
105
- webPromptLabel: 'DSH Core Web \u8bf4\u660e',
106
- webPromptHint: '\u8bf4\u660e Web GUI、HMR、\u6784\u5efa\u4e0e\u9a8c\u8bc1,\u652f\u6301 {{webUrl}}。',
107
- promptRestoreAll: '\u6062\u590d\u6240\u6709\u63d0\u793a\u8bcd\u9ed8\u8ba4\u503c',
108
- promptLabel: 'Codex \u64cd\u4f5c\u63d0\u793a\u8bcd',
109
- promptHint: '\u8fd9\u662f Codex \u64cd\u4f5c\u63d0\u793a\u8bcd。Persona \u548c DSH Core \u8bf4\u660e\u5728\u4e0a\u65b9\u5206\u522b\u7f16\u8f91。',
110
- promptUnsaved: '\u672a\u4fdd\u5b58',
111
91
  promptDiscard: '\u653e\u5f03',
112
- promptSave: '\u4fdd\u5b58',
113
92
  promptSaving: '\u4fdd\u5b58\u4e2d...',
114
- promptSaveFailed: '\u63d0\u793a\u8bcd\u4fdd\u5b58\u5931\u8d25。',
115
- promptExpand: '\u5c55\u5f00\u8bbe\u7f6e',
116
- promptCollapse: '\u6536\u8d77\u8bbe\u7f6e',
117
93
  promptReadOnly: '\u5f53\u524d\u8bbe\u7f6e\u6587\u4ef6\u4e3a\u53ea\u8bfb\u3002',
118
94
  activityCompacting: '\u6b63\u5728\u538b\u7f29\u4e0a\u4e0b\u6587...',
119
95
  activityRequestingModel: '\u8bf7\u6c42\u4e2d...',
@@ -126,7 +102,7 @@ function CapabilityToggle({ field, label, hint, enabled, disabled, setSetting, }
126
102
  gap: 12,
127
103
  padding: '9px 0',
128
104
  cursor: disabled ? 'default' : 'pointer',
129
- }, children: [_jsxs("span", { style: { flex: 1, minWidth: 0, display: 'grid', gap: 2 }, children: [_jsx("strong", { style: { fontSize: 13, fontWeight: 500 }, children: label }), _jsx("span", { style: { color: 'var(--dsw-alias-label-tertiary)', fontSize: 12, lineHeight: 1.45 }, children: hint })] }), _jsx("input", { type: "checkbox", role: "switch", checked: enabled, disabled: disabled, "aria-label": label, onChange: event => { void setSetting(field, event.target.checked); }, style: { marginTop: 3, accentColor: 'var(--dsw-static-blue-500)' } })] }));
105
+ }, children: [_jsxs("span", { style: { flex: 1, minWidth: 0, display: 'grid', gap: 2 }, children: [_jsx("strong", { style: { fontSize: 13, fontWeight: 500 }, children: label }), _jsx("span", { style: { color: 'var(--dsw-alias-label-secondary)', fontSize: 12, lineHeight: 1.45 }, children: hint })] }), _jsx("input", { type: "checkbox", role: "switch", checked: enabled, disabled: disabled, "aria-label": label, onChange: event => { void setSetting(field, event.target.checked); }, style: { marginTop: 3, accentColor: 'var(--dsw-static-blue-500)' } })] }));
130
106
  }
131
107
  /** One editor per preset; only display preferences are global. */
132
108
  export function PromptSettingsCard(props) {
@@ -162,7 +138,7 @@ function FastModeFallback(props) {
162
138
  lineHeight: '20px',
163
139
  fontWeight: fast ? 600 : 400,
164
140
  whiteSpace: 'nowrap',
165
- }, children: [_jsx("span", { children: t('fast') }), _jsx("span", { style: { color: 'var(--dsw-alias-label-tertiary)', fontSize: 11 }, children: fast ? t('fastStateOn') : t('fastStateOff') })] }));
141
+ }, children: [_jsx("span", { children: t('fast') }), _jsx("span", { style: { color: 'var(--dsw-alias-label-secondary)', fontSize: 11 }, children: fast ? t('fastStateOn') : t('fastStateOff') })] }));
166
142
  }
167
143
  function contextWindowFromProjection(useProjection) {
168
144
  const pressure = useProjection('contextPressure');
@@ -206,7 +182,7 @@ function ContextSizeControl({ contextWindow, sessionId: _sessionId, useSessions:
206
182
  font: 'inherit',
207
183
  fontSize: 12,
208
184
  fontVariantNumeric: 'tabular-nums',
209
- } }), _jsx("span", { style: { color: 'var(--dsw-alias-label-secondary)', fontSize: 11 }, children: "K" })] }), _jsx("span", { style: { color: 'var(--dsw-alias-label-tertiary)', fontSize: 11, lineHeight: '16px' }, children: t('contextSizeDescription') })] }), configured !== undefined && (_jsx("button", { type: "button", onClick: () => { void unsetSetting('contextWindow'); }, style: {
185
+ } }), _jsx("span", { style: { color: 'var(--dsw-alias-label-secondary)', fontSize: 11 }, children: "K" })] }), _jsx("span", { style: { color: 'var(--dsw-alias-label-secondary)', fontSize: 11, lineHeight: '16px' }, children: t('contextSizeDescription') })] }), configured !== undefined && (_jsx("button", { type: "button", onClick: () => { void unsetSetting('contextWindow'); }, style: {
210
186
  justifySelf: 'start',
211
187
  border: 0,
212
188
  padding: 0,
@@ -244,7 +220,7 @@ function useHostContextMeter() {
244
220
  }
245
221
  /** Keep context configuration reachable before the host has a pressure meter. */
246
222
  function ContextSizeFallback({ sessionId, useSessions, useProjection, useSettings, setSetting, unsetSetting, t, }) {
247
- const agentPreset = useSessions(state => state.byId[sessionId]?.agentPreset);
223
+ const agentPreset = useSessions(state => agentPresetFromSession(state.byId[sessionId]));
248
224
  const hostMeter = useHostContextMeter();
249
225
  const contextWindow = contextWindowFromProjection(useProjection);
250
226
  const snapshot = useSettings(state => state);
@@ -377,7 +353,7 @@ export function ActivityLine({ sessionId: _sessionId, useSession, useSessions: _
377
353
  borderRadius: '50%',
378
354
  background: 'var(--dsw-static-blue-500)',
379
355
  opacity: 0.55,
380
- } }), _jsx("span", { children: label }), _jsxs("span", { style: { color: 'var(--dsw-alias-label-tertiary)' }, children: ['\u00b7', " ", elapsedSeconds(activity.startedAt, now), "s"] })] }));
356
+ } }), _jsx("span", { children: label }), _jsxs("span", { style: { color: 'var(--dsw-alias-label-secondary)' }, children: ['\u00b7', " ", elapsedSeconds(activity.startedAt, now), "s"] })] }));
381
357
  }
382
358
  function findContextMeterDialog() {
383
359
  const buttons = document.querySelectorAll('button[aria-haspopup="dialog"][aria-expanded="true"]');
@@ -506,7 +482,7 @@ function LegacyOverlay(props) {
506
482
  }
507
483
  export const inject = [
508
484
  'commandUi', 'sessions', 'slots', 'locale', 'settingsScope',
509
- 'remote', 'remote.agentPresets', 'remote.settings',
485
+ 'remote',
510
486
  ];
511
487
  function createPresetManager(ctx) {
512
488
  const remote = ctx.remote;
@@ -548,8 +524,7 @@ function registerPresetSettingsCard(ctx, settings, presetManager) {
548
524
  }),
549
525
  }, PromptSettingsCard));
550
526
  }
551
- /** Mount request controls and the plugin settings card through shared slots. */
552
- export function apply(ctx) {
527
+ export function applyWithSettingsApi(ctx, api) {
553
528
  ctx.effect(() => ctx.locale.register(NS, { en, zh }), 'codex client: dictionaries');
554
529
  const commandUi = ctx.get('commandUi');
555
530
  const sessions = ctx.get('sessions');
@@ -576,7 +551,7 @@ export function apply(ctx) {
576
551
  },
577
552
  },
578
553
  }), 'codex client: /compact mode picker');
579
- const settings = ctx.settingsScope.bind({ namespace: SETTINGS_NAMESPACE });
554
+ const settings = api.bind(ctx);
580
555
  const presetManager = createPresetManager(ctx);
581
556
  const injected = () => ({
582
557
  hooks: { settings },
@@ -608,7 +583,13 @@ export function apply(ctx) {
608
583
  // `codexPresetEditor` is mounted by createPresetManager above. Keep its
609
584
  // namespace dependency local to the settings card so the main client entry
610
585
  // can start and perform that mount first.
611
- ctx.inject(['remote', 'remote.agentPresets', 'remote.settings', 'remote.codexPresetEditor'], settingsCtx => registerPresetSettingsCard(settingsCtx, settings, presetManager));
586
+ ctx.inject(['remote', 'remote.codexPresetEditor'], settingsCtx => api.register(settingsCtx, settings, presetManager));
587
+ }
588
+ export function apply(ctx) {
589
+ applyWithSettingsApi(ctx, {
590
+ bind: host => host.settingsScope.bind({ namespace: SETTINGS_NAMESPACE }),
591
+ register: registerPresetSettingsCard,
592
+ });
612
593
  }
613
594
  export default { inject, apply };
614
595
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,25 @@
1
+ import type { ToolPolicyRule } from '../tool-policy-contract.ts';
2
+ /** Ephemeral UI drafts only; accepted ConfigForms values remain authoritative. */
3
+ export interface PresetDraft {
4
+ readonly preset: string;
5
+ readonly revision: number | undefined;
6
+ readonly baseline: readonly ToolPolicyRule[];
7
+ readonly rules: readonly ToolPolicyRule[];
8
+ }
9
+ export type PresetDrafts = ReadonlyMap<string, PresetDraft>;
10
+ export interface PolicySnapshot {
11
+ readonly revision: number | undefined;
12
+ readonly rules: readonly ToolPolicyRule[];
13
+ }
14
+ export interface PreparedPresetSave extends PolicySnapshot {
15
+ readonly draft: PresetDraft;
16
+ readonly before: PolicySnapshot;
17
+ }
18
+ export declare const sameRules: (a: readonly ToolPolicyRule[], b: readonly ToolPolicyRule[]) => boolean;
19
+ export declare const presetRules: (rules: readonly ToolPolicyRule[], preset: string) => readonly ToolPolicyRule[];
20
+ export declare function editPresetDraft(drafts: PresetDrafts, preset: string, accepted: PolicySnapshot, change: (rules: readonly ToolPolicyRule[]) => readonly ToolPolicyRule[]): PresetDrafts;
21
+ /** Replace just this source target, preserving all accepted other targets/order. */
22
+ export declare function mergePresetRules(accepted: readonly ToolPolicyRule[], preset: string, replacement: readonly ToolPolicyRule[]): readonly ToolPolicyRule[];
23
+ export declare function preparePresetSave(draft: PresetDraft, accepted: PolicySnapshot): PreparedPresetSave;
24
+ export declare function acceptPresetSave(drafts: PresetDrafts, saved: PreparedPresetSave, accepted: PolicySnapshot): PresetDrafts;
25
+ //# sourceMappingURL=policy-drafts.d.ts.map
@@ -0,0 +1,47 @@
1
+ function canonical(value) {
2
+ if (Array.isArray(value))
3
+ return value.map(canonical);
4
+ if (value !== null && typeof value === 'object')
5
+ return Object.fromEntries(Object.entries(value)
6
+ .filter(([, item]) => item !== undefined).sort(([a], [b]) => a.localeCompare(b)).map(([key, item]) => [key, canonical(item)]));
7
+ return value;
8
+ }
9
+ export const sameRules = (a, b) => JSON.stringify(canonical(a)) === JSON.stringify(canonical(b));
10
+ export const presetRules = (rules, preset) => rules.filter(rule => rule.preset === preset);
11
+ export function editPresetDraft(drafts, preset, accepted, change) {
12
+ const previous = drafts.get(preset);
13
+ const next = new Map(drafts);
14
+ next.set(preset, { preset, revision: previous === undefined ? accepted.revision : previous.revision,
15
+ baseline: previous?.baseline ?? accepted.rules, rules: change(previous?.rules ?? presetRules(accepted.rules, preset)) });
16
+ return next;
17
+ }
18
+ /** Replace just this source target, preserving all accepted other targets/order. */
19
+ export function mergePresetRules(accepted, preset, replacement) {
20
+ const first = accepted.findIndex(rule => rule.preset === preset);
21
+ if (first < 0)
22
+ return [...accepted, ...replacement];
23
+ return [...accepted.slice(0, first), ...replacement, ...accepted.slice(first).filter(rule => rule.preset !== preset)];
24
+ }
25
+ export function preparePresetSave(draft, accepted) {
26
+ // Never silently rebase an external edit, even if only a different target changed.
27
+ if (draft.revision !== accepted.revision || !sameRules(draft.baseline, accepted.rules))
28
+ throw new Error('policy-draft-conflict');
29
+ return { draft, before: accepted, revision: draft.revision, rules: mergePresetRules(accepted.rules, draft.preset, draft.rules) };
30
+ }
31
+ export function acceptPresetSave(drafts, saved, accepted) {
32
+ const next = new Map(drafts);
33
+ if (next.get(saved.draft.preset) === saved.draft)
34
+ next.delete(saved.draft.preset);
35
+ // A true result is not enough: a later external view may already have arrived.
36
+ if (!sameRules(accepted.rules, saved.rules))
37
+ return next;
38
+ for (const [preset, draft] of next) {
39
+ if (draft.revision !== saved.before.revision || !sameRules(draft.baseline, saved.before.rules))
40
+ continue;
41
+ if (!sameRules(presetRules(saved.before.rules, preset), presetRules(accepted.rules, preset)))
42
+ continue;
43
+ next.set(preset, { ...draft, revision: accepted.revision, baseline: accepted.rules });
44
+ }
45
+ return next;
46
+ }
47
+ //# sourceMappingURL=policy-drafts.js.map
@@ -1,4 +1,5 @@
1
1
  export declare const presetEn: {
2
+ readonly pmRegistryReadOnly: "This host exposes read-only preset declarations. Edit global Codex settings below; creating editable preset copies is not supported here.";
2
3
  readonly peConnectionError: "Could not connect to the local service. Retry loading; if the connection still fails, reconnect the page.";
3
4
  readonly peReadError: "Could not read this preset. Retry loading or refresh the preset list.";
4
5
  readonly peRetryRead: "Retry loading";
@@ -1,4 +1,5 @@
1
1
  export const presetEn = {
2
+ pmRegistryReadOnly: 'This host exposes read-only preset declarations. Edit global Codex settings below; creating editable preset copies is not supported here.',
2
3
  peConnectionError: 'Could not connect to the local service. Retry loading; if the connection still fails, reconnect the page.',
3
4
  peReadError: 'Could not read this preset. Retry loading or refresh the preset list.',
4
5
  peRetryRead: 'Retry loading',
@@ -39,6 +40,7 @@ export const presetEn = {
39
40
  pmSave: 'Save changes',
40
41
  };
41
42
  export const presetZh = {
43
+ pmRegistryReadOnly: 'This host exposes read-only preset declarations. Edit global Codex settings below; creating editable preset copies is not supported here.',
42
44
  peConnectionError: '未能连接本地服务。请重试读取;如果仍然失败,请重新连接页面。',
43
45
  peReadError: '无法读取这个预设,请重试读取或刷新预设列表。',
44
46
  peRetryRead: '重试读取',
@@ -1,9 +1,12 @@
1
1
  import type { InjectFace, PropsLocale } from '@deepseek-ai/dsh-client-ui-slots';
2
2
  import type { RemoteResult, TypertClientRemote } from '@deepseek-ai/dsh-typert-protocol';
3
3
  import type { PresetCatalog, PresetCreateInput, PresetEditorDocument, PresetEditorInput } from '../preset-contract.ts';
4
+ import type { PresetPromptCatalog, PresetToolCatalog } from '../tool-policy-contract.ts';
4
5
  export interface PresetClientRemote extends TypertClientRemote {
5
6
  codexPresetEditor: {
6
7
  catalog(): Promise<RemoteResult<PresetCatalog>>;
8
+ tools?(id: string): Promise<RemoteResult<PresetToolCatalog>>;
9
+ prompts?(id: string): Promise<RemoteResult<PresetPromptCatalog>>;
7
10
  read(id: string): Promise<RemoteResult<PresetEditorDocument>>;
8
11
  update(input: PresetEditorInput): Promise<RemoteResult<PresetEditorDocument>>;
9
12
  create(input: PresetCreateInput): Promise<RemoteResult<PresetEditorDocument>>;
@@ -15,8 +18,15 @@ export interface PresetManagerActions {
15
18
  }
16
19
  type Props = InjectFace<{
17
20
  presetManager: PresetManagerActions;
18
- }> & PropsLocale<'codex'>;
21
+ }> & PropsLocale<'codex'> & {
22
+ readOnly?: boolean;
23
+ };
19
24
  /** Presets are peers: choose one to edit, or make an editable copy first. */
20
- export declare function PresetManagerCard({ presetManager, t }: Props): import("react").JSX.Element;
25
+ export declare function PresetManagerCard({ presetManager, t, readOnly: inspectOnly }: Props): import("react").JSX.Element;
26
+ /** A fixed-ID declaration viewer: no second picker and no write/copy actions. */
27
+ export declare function PresetDefinitionCard({ presetManager, id, t }: {
28
+ presetManager: PresetManagerActions;
29
+ id: string;
30
+ } & PropsLocale<'codex'>): import("react").JSX.Element;
21
31
  export default PresetManagerCard;
22
32
  //# sourceMappingURL=preset-manager.d.ts.map
@@ -1,8 +1,7 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  import { useEffect, useRef, useState } from 'react';
3
3
  import { DEFAULT_CODEX_SYSTEM_PROMPT } from "../prompt.js";
4
- import { isPresetConnectionError, readPresetWithRetry } from "./preset-requests.js";
5
- const catalogCache = new WeakMap();
4
+ import { cachePresetCatalog, cachedPresetCatalog, isPresetConnectionError, readPresetWithRetry, requestPresetCatalog } from "./preset-requests.js";
6
5
  const documentCache = new WeakMap();
7
6
  const CODEX_DEFAULT_ID = 'codex-collaboration';
8
7
  function unwrap(result) {
@@ -22,22 +21,22 @@ const styles = `
22
21
  .codex-preset-editor { display:grid; gap:12px; min-width:0; font-size:13px; }
23
22
  .codex-preset-editor label { display:grid; gap:6px; }
24
23
  .codex-preset-editor .pe-row { display:flex; align-items:center; gap:10px; flex-wrap:wrap; }
25
- .codex-preset-editor input:not([type=checkbox]), .codex-preset-editor textarea, .codex-preset-editor select { box-sizing:border-box; width:100%; padding:8px; border:1px solid var(--dsw-alias-border-l2); border-radius:6px; background:var(--dsw-alias-bg-layer-3); color:inherit; font:inherit; }
24
+ .codex-preset-editor input:not([type=checkbox]), .codex-preset-editor textarea, .codex-preset-editor select { box-sizing:border-box; width:100%; padding:8px; border:1px solid var(--dsw-alias-border-l2); border-radius:6px; background:var(--dsw-alias-bg-layer-2); color:inherit; font:inherit; }
26
25
  .codex-preset-editor textarea { resize:vertical; line-height:1.5; }
27
- .codex-preset-editor button { font:inherit; padding:6px 12px; border:1px solid var(--dsw-alias-border-l2); border-radius:6px; background:var(--dsw-alias-bg-layer-3); color:inherit; cursor:pointer; }
26
+ .codex-preset-editor button { font:inherit; padding:6px 12px; border:1px solid var(--dsw-alias-border-l2); border-radius:6px; background:var(--dsw-alias-bg-layer-2); color:inherit; cursor:pointer; }
28
27
  .codex-preset-editor button:disabled { opacity:.5; cursor:default; }
29
- .codex-preset-editor .pe-primary { background:#425ce5; border-color:#425ce5; color:white; }
28
+ .codex-preset-editor .pe-primary { background:var(--dsw-alias-label-primary); border-color:var(--dsw-alias-label-primary); color:var(--dsw-alias-bg-base); }
30
29
  .codex-preset-editor .pe-block { display:grid; gap:9px; padding-top:12px; border-top:1px solid var(--dsw-alias-border-l2); }
31
30
  .codex-preset-editor .pe-toggle { display:flex; align-items:flex-start; gap:9px; }
32
31
  .codex-preset-editor .pe-toggle span { display:grid; gap:2px; }
33
- .codex-preset-editor p { margin:0; font-size:12px; line-height:1.55; color:var(--dsw-alias-label-tertiary); }
32
+ .codex-preset-editor p { margin:0; font-size:12px; line-height:1.55; color:var(--dsw-alias-label-secondary); }
34
33
  `;
35
34
  function optionToggle(key, label, hint, options, setOptions, disabled) {
36
35
  return _jsxs("label", { className: "pe-toggle", children: [_jsx("input", { type: "checkbox", checked: options[key], disabled: disabled, onChange: event => setOptions({ ...options, [key]: event.target.checked }) }), _jsxs("span", { children: [_jsx("strong", { children: label }), _jsx("small", { children: hint })] })] }, key);
37
36
  }
38
37
  /** Presets are peers: choose one to edit, or make an editable copy first. */
39
- export function PresetManagerCard({ presetManager, t }) {
40
- const [catalog, setCatalog] = useState(() => catalogCache.get(presetManager));
38
+ export function PresetManagerCard({ presetManager, t, readOnly: inspectOnly = false }) {
39
+ const [catalog, setCatalog] = useState(() => cachedPresetCatalog(presetManager));
41
40
  const [selectedId, setSelectedId] = useState('');
42
41
  const [original, setOriginal] = useState();
43
42
  const [draft, setDraft] = useState();
@@ -117,22 +116,28 @@ export function PresetManagerCard({ presetManager, t }) {
117
116
  }
118
117
  }
119
118
  async function refresh() {
120
- setErrorAction('read');
121
- const value = await readPresetWithRetry(() => remote.catalog().then(unwrap), () => alive.current);
119
+ setErrorAction('catalog');
120
+ const value = await readPresetWithRetry(() => requestPresetCatalog(presetManager, true), () => alive.current);
122
121
  if (!alive.current)
123
122
  return;
124
- catalogCache.set(presetManager, value);
125
123
  setCatalog(value);
126
- const current = selectedId || (value.presets.some(row => row.id === CODEX_DEFAULT_ID) ? CODEX_DEFAULT_ID : value.presets[0]?.id ?? '');
127
- if (current && current !== selectedId)
124
+ const current = value.presets.some(row => row.id === selectedId) ? selectedId
125
+ : value.presets.some(row => row.id === CODEX_DEFAULT_ID) ? CODEX_DEFAULT_ID : value.presets[0]?.id ?? '';
126
+ if (current)
128
127
  await load(current, false);
128
+ else {
129
+ setSelectedId('');
130
+ setOriginal(undefined);
131
+ setDraft(undefined);
132
+ }
129
133
  }
130
134
  useEffect(() => {
131
135
  alive.current = true;
132
- if (!catalogCache.has(presetManager))
136
+ const cached = cachedPresetCatalog(presetManager);
137
+ if (cached === undefined)
133
138
  void run(refresh);
134
139
  else if (!selectedId)
135
- void load(catalogCache.get(presetManager)?.presets.some(row => row.id === CODEX_DEFAULT_ID) ? CODEX_DEFAULT_ID : catalogCache.get(presetManager)?.presets[0]?.id ?? '', false);
140
+ void load(cached.presets.some(row => row.id === CODEX_DEFAULT_ID) ? CODEX_DEFAULT_ID : cached.presets[0]?.id ?? '', false);
136
141
  return () => { alive.current = false; };
137
142
  }, [presetManager]);
138
143
  useEffect(() => {
@@ -145,7 +150,7 @@ export function PresetManagerCard({ presetManager, t }) {
145
150
  function patch(value) { if (draft)
146
151
  setDraft({ ...draft, ...value }); }
147
152
  function beginCopy() {
148
- if (!draft || !sourceId)
153
+ if (inspectOnly || !draft || !sourceId)
149
154
  return;
150
155
  setCopyMode(true);
151
156
  setCodexEnabled(draft.codex);
@@ -153,7 +158,7 @@ export function PresetManagerCard({ presetManager, t }) {
153
158
  setDraft({ ...draft, id: '', revision: '', editable: true, name: `${draft.name} · ${t('pmCustom')}` });
154
159
  }
155
160
  function save() {
156
- if (!draft || busy || !draft.name.trim())
161
+ if (inspectOnly || !draft || busy || !draft.name.trim())
157
162
  return;
158
163
  setErrorAction('save');
159
164
  void run(async () => {
@@ -179,24 +184,23 @@ export function PresetManagerCard({ presetManager, t }) {
179
184
  isDefault: catalog.presets.find(item => item.id === value.id)?.isDefault ?? false };
180
185
  const presets = catalog.presets.some(item => item.id === value.id)
181
186
  ? catalog.presets.map(item => item.id === value.id ? row : item) : [...catalog.presets, row];
182
- catalogCache.set(presetManager, { ...catalog, presets });
187
+ cachePresetCatalog(presetManager, { ...catalog, presets });
183
188
  setCatalog({ ...catalog, presets });
184
189
  }
185
190
  });
186
191
  }
187
192
  const selectedRow = catalog?.presets.find(row => row.id === selectedId);
188
- const readOnly = !!draft && !draft.editable && !copyMode;
193
+ const readOnly = inspectOnly || (!!draft && !draft.editable && !copyMode);
189
194
  const options = draft?.codexOptions;
190
195
  return _jsxs("section", { className: "codex-preset-editor", "aria-label": t('peTitle'), "aria-busy": busy, children: [_jsx("style", { children: styles }), _jsxs("div", { className: "pe-row", style: { justifyContent: 'space-between' }, children: [_jsx("strong", { children: t('peTitle') }), _jsx("button", { type: "button", disabled: busy, onClick: () => { if (dirty && !window.confirm(t('pmDiscard')))
191
- return; cache.clear(); void run(async () => { await refresh(); if (selectedId)
192
- await load(selectedId, false); }); }, children: t('pmRefresh') })] }), _jsx("p", { children: t('peHierarchy') }), _jsxs("label", { children: [t('peSelect'), _jsxs("select", { value: selectedId, disabled: busy || !catalog, onChange: event => { void load(event.target.value); }, children: [_jsx("option", { value: "", children: t('peSelectPlaceholder') }), catalog?.presets.map(row => _jsxs("option", { value: row.id, children: [row.name, row.editable ? '' : ` · ${t('pmBuiltIn')}`] }, row.id))] })] }), selectedRow && _jsx("p", { children: selectedRow.editable ? t('peEditable') : t('peBuiltinEdit') }), error && _jsxs("div", { role: "alert", children: [_jsx("p", { children: errorAction === 'read'
196
+ return; cache.clear(); void run(refresh); }, children: t('pmRefresh') })] }), _jsx("p", { children: t('peHierarchy') }), _jsxs("label", { children: [t('peSelect'), _jsxs("select", { value: selectedId, disabled: busy || !catalog, onChange: event => { void load(event.target.value); }, children: [_jsx("option", { value: "", children: t('peSelectPlaceholder') }), catalog?.presets.map(row => _jsxs("option", { value: row.id, children: [row.name, row.editable ? '' : ` · ${t('pmBuiltIn')}`] }, row.id))] })] }), selectedRow && _jsx("p", { children: selectedRow.editable ? t('peEditable') : t(catalog?.authorable ? 'peBuiltinEdit' : 'pmRegistryReadOnly') }), error && _jsxs("div", { role: "alert", children: [_jsx("p", { children: errorAction !== 'save'
193
197
  ? t(isPresetConnectionError(error) ? 'peConnectionError' : 'peReadError')
194
- : error.includes('preset-conflict') ? t('pmConflict') : error.includes('invalid-preset-yaml') ? t('pmYamlError') : t('pmSaveError') }), errorAction === 'read' && _jsxs("div", { className: "pe-row", children: [_jsx("button", { type: "button", disabled: busy, onClick: () => { if (selectedId) {
198
+ : error.includes('preset-conflict') ? t('pmConflict') : error.includes('invalid-preset-yaml') ? t('pmYamlError') : t('pmSaveError') }), errorAction !== 'save' && _jsxs("div", { className: "pe-row", children: [_jsx("button", { type: "button", disabled: busy, onClick: () => { if (errorAction === 'catalog' || !selectedId)
199
+ void run(refresh);
200
+ else {
195
201
  cache.delete(selectedId);
196
202
  void load(selectedId, false);
197
- }
198
- else
199
- void run(refresh); }, children: t('peRetryRead') }), !draft && isPresetConnectionError(error) && _jsx("button", { type: "button", onClick: () => window.location.reload(), children: t('peReconnect') })] }), _jsxs("details", { children: [_jsx("summary", { children: t('pmErrorDetails') }), _jsx("pre", { style: { whiteSpace: 'pre-wrap' }, children: error })] })] }), notice && _jsx("p", { role: "status", children: notice }), busy && !draft && _jsx("p", { role: "status", children: t('peLoading') }), draft && _jsxs(_Fragment, { children: [_jsxs("label", { children: [t('pmName'), _jsx("input", { value: draft.name, maxLength: 200, disabled: busy || readOnly, onChange: event => patch({ name: event.target.value }) })] }), _jsxs("label", { children: [t('pmDescription'), _jsx("input", { value: draft.description, maxLength: 4000, disabled: busy || readOnly, onChange: event => patch({ description: event.target.value }) })] }), !copyMode && _jsx("button", { type: "button", disabled: busy || !catalog?.authorable, onClick: beginCopy, children: t('peCreateCopy') }), _jsxs("div", { className: "pe-block", children: [_jsx("strong", { children: t('peSystemPrompt') }), _jsx("p", { children: t('peSectionsHint') }), draft.promptSections.map(section => _jsxs("details", { children: [_jsxs("summary", { style: { cursor: 'pointer', padding: '6px 0' }, children: [section.label, section.suppressed ? ` · ${t('peSuppressed')}` : ''] }), section.id === 'harness:source' && _jsx("p", { children: t('peDshSourcePrompt') }), section.id === 'app:web-surface' && _jsx("p", { children: t('peDshWebPrompt') }), _jsx("textarea", { "aria-label": section.label, rows: section.id === 'codex:base' ? 12 : 5, value: section.text, disabled: busy || readOnly || !section.editable, onChange: event => patch({ promptSections: draft.promptSections.map(item => item.id === section.id ? { ...item, text: event.target.value } : item),
203
+ } }, children: t('peRetryRead') }), !draft && isPresetConnectionError(error) && _jsx("button", { type: "button", onClick: () => window.location.reload(), children: t('peReconnect') })] }), _jsxs("details", { children: [_jsx("summary", { children: t('pmErrorDetails') }), _jsx("pre", { style: { whiteSpace: 'pre-wrap' }, children: error })] })] }), notice && _jsx("p", { role: "status", children: notice }), busy && !draft && _jsx("p", { role: "status", children: t('peLoading') }), draft && _jsxs(_Fragment, { children: [_jsxs("label", { children: [t('pmName'), _jsx("input", { value: draft.name, maxLength: 200, disabled: busy || readOnly, onChange: event => patch({ name: event.target.value }) })] }), _jsxs("label", { children: [t('pmDescription'), _jsx("input", { value: draft.description, maxLength: 4000, disabled: busy || readOnly, onChange: event => patch({ description: event.target.value }) })] }), !inspectOnly && !copyMode && catalog?.authorable && _jsx("button", { type: "button", disabled: busy, onClick: beginCopy, children: t('peCreateCopy') }), _jsxs("div", { className: "pe-block", children: [_jsx("strong", { children: t('peSystemPrompt') }), _jsx("p", { children: t('peSectionsHint') }), draft.promptSections.map(section => _jsxs("details", { children: [_jsxs("summary", { style: { cursor: 'pointer', padding: '6px 0' }, children: [section.label, section.suppressed ? ` · ${t('peSuppressed')}` : ''] }), section.id === 'harness:source' && _jsx("p", { children: t('peDshSourcePrompt') }), section.id === 'app:web-surface' && _jsx("p", { children: t('peDshWebPrompt') }), _jsx("textarea", { "aria-label": section.label, rows: section.id === 'codex:base' ? 12 : 5, value: section.text, disabled: busy || readOnly || !section.editable, onChange: event => patch({ promptSections: draft.promptSections.map(item => item.id === section.id ? { ...item, text: event.target.value } : item),
200
204
  ...(section.id === 'codex:base' ? { systemPrompt: event.target.value, inheritPrompt: false } : {}) }) }), section.suppressed ? _jsx("p", { children: t('peCompletePersona') }) : !section.editable && _jsx("p", { children: t('peDynamicPrompt') })] }, section.id))] }), !readOnly && _jsxs(_Fragment, { children: [_jsxs("div", { className: "pe-block", children: [_jsx("strong", { children: t('peCodexSection') }), !draft.codex && _jsxs("label", { className: "pe-toggle", children: [_jsx("input", { type: "checkbox", checked: codexEnabled, disabled: busy, onChange: event => {
201
205
  const enabled = event.target.checked;
202
206
  setCodexEnabled(enabled);
@@ -213,5 +217,46 @@ export function PresetManagerCard({ presetManager, t }) {
213
217
  }) });
214
218
  } }), _jsxs("span", { children: [_jsx("strong", { children: t('peAddCodex') }), _jsx("small", { children: t('peAddCodexHint') })] })] }), codexEnabled && options && _jsxs(_Fragment, { children: [optionToggle('hostedWebSearchEnabled', t('capabilityWebSearch'), t('capabilityWebSearchHint'), options, next => patch({ codexOptions: next }), busy), optionToggle('remoteCompactionEnabled', t('capabilityCompaction'), t('capabilityCompactionHint'), options, next => patch({ codexOptions: next }), busy), optionToggle('terminalToolsEnabled', t('capabilityTerminal'), t('capabilityTerminalHint'), options, next => patch({ codexOptions: next }), busy), optionToggle('patchToolEnabled', t('capabilityPatch'), t('capabilityPatchHint'), options, next => patch({ codexOptions: next }), busy), optionToggle('planToolEnabled', t('capabilityPlan'), t('capabilityPlanHint'), options, next => patch({ codexOptions: next }), busy), optionToggle('promptEnabled', t('capabilityPrompt'), t('capabilityPromptHint'), options, next => patch({ codexOptions: next }), busy), _jsx("p", { children: t('peActivityGlobal') })] })] }), _jsxs("div", { className: "pe-row", children: [_jsx("button", { type: "button", className: "pe-primary", disabled: busy || !catalog?.authorable || !draft.name.trim() || !dirty, onClick: save, children: copyMode ? t('peSaveCopy') : t('pmSave') }), copyMode && _jsx("button", { type: "button", disabled: busy, onClick: () => { void load(sourceId, false); }, children: t('pmCancel') }), !copyMode && _jsx("button", { type: "button", disabled: busy, onClick: () => { void load(draft.id, false); }, children: t('pmCancel') })] })] })] })] });
215
219
  }
220
+ /** A fixed-ID declaration viewer: no second picker and no write/copy actions. */
221
+ export function PresetDefinitionCard({ presetManager, id, t }) {
222
+ const [value, setValue] = useState();
223
+ const [loading, setLoading] = useState(true);
224
+ const [error, setError] = useState('');
225
+ const request = useRef(0);
226
+ const alive = useRef(true);
227
+ async function load(refresh = false) {
228
+ const ticket = ++request.current;
229
+ setLoading(true);
230
+ setError('');
231
+ try {
232
+ await presetManager.ready;
233
+ const cache = documentCache.get(presetManager) ?? new Map();
234
+ documentCache.set(presetManager, cache);
235
+ const cached = cache.get(id);
236
+ const document = !refresh && cached && Date.now() - cached.time < 60_000 ? cached.value
237
+ : await readPresetWithRetry(() => presetManager.remote.codexPresetEditor.read(id).then(unwrap), () => alive.current && ticket === request.current);
238
+ if (document.id !== id)
239
+ throw new Error('preset-document-mismatch');
240
+ cache.set(id, { value: document, time: Date.now() });
241
+ if (alive.current && ticket === request.current)
242
+ setValue(document);
243
+ }
244
+ catch (cause) {
245
+ if (alive.current && ticket === request.current)
246
+ setError(cause instanceof Error ? cause.message : String(cause));
247
+ }
248
+ finally {
249
+ if (alive.current && ticket === request.current)
250
+ setLoading(false);
251
+ }
252
+ }
253
+ useEffect(() => {
254
+ alive.current = true;
255
+ void load();
256
+ return () => { alive.current = false; request.current++; };
257
+ }, [presetManager, id]);
258
+ const shown = value?.id === id ? value : undefined;
259
+ return _jsxs("section", { className: "codex-preset-editor", "aria-label": t('settingsDefinition'), "aria-busy": loading, children: [_jsx("style", { children: styles }), _jsx("h3", { children: t('settingsDefinition') }), _jsx("code", { children: id }), _jsx("button", { type: "button", disabled: loading, onClick: () => { void load(true); }, children: t('pmRefresh') }), loading && !shown && _jsx("p", { role: "status", children: t('peLoading') }), error && _jsx("p", { role: "alert", children: t('peReadError') }), shown && _jsxs(_Fragment, { children: [_jsx("strong", { children: shown.name }), _jsx("p", { children: shown.description }), _jsx("pre", { style: { whiteSpace: 'pre-wrap', overflowWrap: 'anywhere', margin: 0 }, children: shown.composition || JSON.stringify({ id: shown.id, name: shown.name, promptSections: shown.promptSections }, null, 2) })] })] });
260
+ }
216
261
  export default PresetManagerCard;
217
262
  //# sourceMappingURL=preset-manager.js.map
@@ -1,3 +1,15 @@
1
+ import type { PresetCatalog } from '../preset-contract.ts';
2
+ import type { PresetManagerActions } from './preset-manager.tsx';
3
+ import type { PresetPromptCatalog, PresetToolCatalog } from '../tool-policy-contract.ts';
4
+ export declare function cachedPresetCatalog(manager: PresetManagerActions): PresetCatalog | undefined;
5
+ export declare function cachePresetCatalog(manager: PresetManagerActions, catalog: PresetCatalog): void;
6
+ /** One cache and one in-flight catalog read for every surface using this manager. */
7
+ export declare function requestPresetCatalog(manager: PresetManagerActions, refresh?: boolean): Promise<PresetCatalog>;
8
+ export declare function cachedPresetTools(manager: PresetManagerActions, id: string): PresetToolCatalog | undefined;
9
+ /** The requested preset owns this snapshot; never substitute current-Agent tools. */
10
+ export declare function requestPresetTools(manager: PresetManagerActions, id: string, refresh?: boolean): Promise<PresetToolCatalog>;
11
+ export declare function cachedPresetPrompts(manager: PresetManagerActions, id: string): PresetPromptCatalog | undefined;
12
+ export declare function requestPresetPrompts(manager: PresetManagerActions, id: string, refresh?: boolean): Promise<PresetPromptCatalog>;
1
13
  /** Only transport failures from a read can be retried without duplicating writes. */
2
14
  export declare function isPresetConnectionError(error: unknown): boolean;
3
15
  export declare function readPresetWithRetry<T>(read: () => Promise<T>, active: () => boolean): Promise<T>;
@@ -1,3 +1,104 @@
1
+ const catalogs = new WeakMap();
2
+ const catalogRequests = new WeakMap();
3
+ export function cachedPresetCatalog(manager) {
4
+ return catalogs.get(manager);
5
+ }
6
+ export function cachePresetCatalog(manager, catalog) {
7
+ catalogs.set(manager, catalog);
8
+ }
9
+ /** One cache and one in-flight catalog read for every surface using this manager. */
10
+ export function requestPresetCatalog(manager, refresh = false) {
11
+ const pending = catalogRequests.get(manager);
12
+ if (pending !== undefined)
13
+ return pending;
14
+ const cached = catalogs.get(manager);
15
+ if (!refresh && cached !== undefined)
16
+ return Promise.resolve(cached);
17
+ const request = (async () => {
18
+ await manager.ready;
19
+ const result = await manager.remote.codexPresetEditor.catalog();
20
+ if (!result.ok)
21
+ throw new Error(result.error.message ?? 'preset-catalog-unavailable');
22
+ catalogs.set(manager, result.value);
23
+ return result.value;
24
+ })();
25
+ catalogRequests.set(manager, request);
26
+ void request.finally(() => {
27
+ if (catalogRequests.get(manager) === request)
28
+ catalogRequests.delete(manager);
29
+ }).catch(() => { });
30
+ return request;
31
+ }
32
+ const toolCatalogs = new WeakMap();
33
+ const toolRequests = new WeakMap();
34
+ export function cachedPresetTools(manager, id) {
35
+ return toolCatalogs.get(manager)?.get(id);
36
+ }
37
+ /** The requested preset owns this snapshot; never substitute current-Agent tools. */
38
+ export function requestPresetTools(manager, id, refresh = false) {
39
+ const pending = toolRequests.get(manager)?.get(id);
40
+ if (pending !== undefined)
41
+ return pending;
42
+ const cached = cachedPresetTools(manager, id);
43
+ if (!refresh && cached !== undefined)
44
+ return Promise.resolve(cached);
45
+ const requests = toolRequests.get(manager) ?? new Map();
46
+ toolRequests.set(manager, requests);
47
+ const request = (async () => {
48
+ await manager.ready;
49
+ const remote = manager.remote.codexPresetEditor;
50
+ if (typeof remote.tools !== 'function')
51
+ throw new Error('preset-tools-unavailable');
52
+ const result = await remote.tools(id);
53
+ if (!result.ok)
54
+ throw new Error(result.error.message ?? 'preset-tools-unavailable');
55
+ if (result.value.preset !== id || result.value.registeredOnly !== true || !Array.isArray(result.value.tools)) {
56
+ throw new Error('preset-tools-mismatched-snapshot');
57
+ }
58
+ const catalogs = toolCatalogs.get(manager) ?? new Map();
59
+ catalogs.set(id, result.value);
60
+ toolCatalogs.set(manager, catalogs);
61
+ return result.value;
62
+ })();
63
+ requests.set(id, request);
64
+ void request.finally(() => { if (requests.get(id) === request)
65
+ requests.delete(id); }).catch(() => { });
66
+ return request;
67
+ }
68
+ const promptCatalogs = new WeakMap();
69
+ const promptRequests = new WeakMap();
70
+ export function cachedPresetPrompts(manager, id) {
71
+ return promptCatalogs.get(manager)?.get(id);
72
+ }
73
+ export function requestPresetPrompts(manager, id, refresh = false) {
74
+ const pending = promptRequests.get(manager)?.get(id);
75
+ if (pending !== undefined)
76
+ return pending;
77
+ const cached = cachedPresetPrompts(manager, id);
78
+ if (!refresh && cached !== undefined)
79
+ return Promise.resolve(cached);
80
+ const requests = promptRequests.get(manager) ?? new Map();
81
+ promptRequests.set(manager, requests);
82
+ const request = (async () => {
83
+ await manager.ready;
84
+ const remote = manager.remote.codexPresetEditor;
85
+ if (typeof remote.prompts !== 'function')
86
+ throw new Error('preset-prompts-unavailable');
87
+ const result = await remote.prompts(id);
88
+ if (!result.ok)
89
+ throw new Error(result.error.message ?? 'preset-prompts-unavailable');
90
+ if (result.value.preset !== id || !Array.isArray(result.value.sections))
91
+ throw new Error('preset-prompts-mismatched-snapshot');
92
+ const catalogs = promptCatalogs.get(manager) ?? new Map();
93
+ catalogs.set(id, result.value);
94
+ promptCatalogs.set(manager, catalogs);
95
+ return result.value;
96
+ })();
97
+ requests.set(id, request);
98
+ void request.finally(() => { if (requests.get(id) === request)
99
+ requests.delete(id); }).catch(() => { });
100
+ return request;
101
+ }
1
102
  /** Only transport failures from a read can be retried without duplicating writes. */
2
103
  export function isPresetConnectionError(error) {
3
104
  const message = error instanceof Error ? error.message : String(error);
@@ -0,0 +1,6 @@
1
+ /** Preset identity moved from the legacy summary field to projectionValues. */
2
+ export declare function agentPresetFromSession(summary: {
3
+ readonly agentPreset?: unknown;
4
+ readonly projectionValues?: Readonly<Record<string, unknown>> | undefined;
5
+ } | undefined): string | undefined;
6
+ //# sourceMappingURL=session.d.ts.map
@@ -0,0 +1,9 @@
1
+ /** Preset identity moved from the legacy summary field to projectionValues. */
2
+ export function agentPresetFromSession(summary) {
3
+ const projections = summary?.projectionValues;
4
+ const value = projections !== undefined && Object.hasOwn(projections, 'agentPreset')
5
+ ? projections.agentPreset
6
+ : summary?.agentPreset;
7
+ return typeof value === 'string' ? value : undefined;
8
+ }
9
+ //# sourceMappingURL=session.js.map