@shuind/dsh-codex-harness 0.2.20 → 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 +1663 -119
  10. package/lib/compaction.js +17 -2
  11. package/lib/index.js +801 -190
  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 +52 -45
  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 +183 -70
  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 +368 -292
  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
package/lib/client.js CHANGED
@@ -71,7 +71,15 @@ window.__ModuleLoader__.load({
71
71
  };
72
72
  }
73
73
  //#endregion
74
- //#region node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/core.js
74
+ //#region lib/types/client/session.js
75
+ /** Preset identity moved from the legacy summary field to projectionValues. */
76
+ function agentPresetFromSession(summary) {
77
+ const projections = summary?.projectionValues;
78
+ const value = projections !== void 0 && Object.hasOwn(projections, "agentPreset") ? projections.agentPreset : summary?.agentPreset;
79
+ return typeof value === "string" ? value : void 0;
80
+ }
81
+ //#endregion
82
+ //#region node_modules/zod/v4/core/core.js
75
83
  var _a$1;
76
84
  function $constructor(name, initializer, params) {
77
85
  function init(inst, def) {
@@ -130,7 +138,7 @@ window.__ModuleLoader__.load({
130
138
  return globalConfig;
131
139
  }
132
140
  //#endregion
133
- //#region node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/util.js
141
+ //#region node_modules/zod/v4/core/util.js
134
142
  function getEnumValues(entries) {
135
143
  const numericValues = Object.values(entries).filter((v) => typeof v === "number");
136
144
  return Object.entries(entries).filter(([k, _]) => numericValues.indexOf(+k) === -1).map(([_, v]) => v);
@@ -444,7 +452,7 @@ window.__ModuleLoader__.load({
444
452
  return { ...iss };
445
453
  }
446
454
  //#endregion
447
- //#region node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/errors.js
455
+ //#region node_modules/zod/v4/core/errors.js
448
456
  const initializer$1 = (inst, def) => {
449
457
  inst.name = "$ZodError";
450
458
  Object.defineProperty(inst, "_zod", {
@@ -504,7 +512,7 @@ window.__ModuleLoader__.load({
504
512
  return fieldErrors;
505
513
  }
506
514
  //#endregion
507
- //#region node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/parse.js
515
+ //#region node_modules/zod/v4/core/parse.js
508
516
  const _parse = (_Err) => (schema, value, _ctx, _params) => {
509
517
  const ctx = _ctx ? {
510
518
  ..._ctx,
@@ -618,7 +626,7 @@ window.__ModuleLoader__.load({
618
626
  return _safeParseAsync(_Err)(schema, value, _ctx);
619
627
  };
620
628
  //#endregion
621
- //#region node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/regexes.js
629
+ //#region node_modules/zod/v4/core/regexes.js
622
630
  /**
623
631
  * @deprecated CUID v1 is deprecated by its authors due to information leakage
624
632
  * (timestamps embedded in the id). Use {@link cuid2} instead.
@@ -682,7 +690,7 @@ window.__ModuleLoader__.load({
682
690
  const lowercase = /^[^A-Z]*$/;
683
691
  const uppercase = /^[^a-z]*$/;
684
692
  //#endregion
685
- //#region node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/checks.js
693
+ //#region node_modules/zod/v4/core/checks.js
686
694
  const $ZodCheck = /*@__PURE__*/ $constructor("$ZodCheck", (inst, def) => {
687
695
  var _a;
688
696
  inst._zod ?? (inst._zod = {});
@@ -1044,7 +1052,7 @@ window.__ModuleLoader__.load({
1044
1052
  };
1045
1053
  });
1046
1054
  //#endregion
1047
- //#region node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/doc.js
1055
+ //#region node_modules/zod/v4/core/doc.js
1048
1056
  var Doc = class {
1049
1057
  constructor(args = []) {
1050
1058
  this.content = [];
@@ -1075,14 +1083,14 @@ window.__ModuleLoader__.load({
1075
1083
  }
1076
1084
  };
1077
1085
  //#endregion
1078
- //#region node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/versions.js
1086
+ //#region node_modules/zod/v4/core/versions.js
1079
1087
  const version = {
1080
1088
  major: 4,
1081
1089
  minor: 4,
1082
1090
  patch: 3
1083
1091
  };
1084
1092
  //#endregion
1085
- //#region node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/schemas.js
1093
+ //#region node_modules/zod/v4/core/schemas.js
1086
1094
  const $ZodType = /*@__PURE__*/ $constructor("$ZodType", (inst, def) => {
1087
1095
  var _a;
1088
1096
  inst ?? (inst = {});
@@ -1956,6 +1964,24 @@ window.__ModuleLoader__.load({
1956
1964
  return payload;
1957
1965
  };
1958
1966
  });
1967
+ const $ZodLiteral = /*@__PURE__*/ $constructor("$ZodLiteral", (inst, def) => {
1968
+ $ZodType.init(inst, def);
1969
+ if (def.values.length === 0) throw new Error("Cannot create literal schema with no valid values");
1970
+ const values = new Set(def.values);
1971
+ inst._zod.values = values;
1972
+ inst._zod.pattern = new RegExp(`^(${def.values.map((o) => typeof o === "string" ? escapeRegex(o) : o ? escapeRegex(o.toString()) : String(o)).join("|")})$`);
1973
+ inst._zod.parse = (payload, _ctx) => {
1974
+ const input = payload.value;
1975
+ if (values.has(input)) return payload;
1976
+ payload.issues.push({
1977
+ code: "invalid_value",
1978
+ values: def.values,
1979
+ input,
1980
+ inst
1981
+ });
1982
+ return payload;
1983
+ };
1984
+ });
1959
1985
  const $ZodTransform = /*@__PURE__*/ $constructor("$ZodTransform", (inst, def) => {
1960
1986
  $ZodType.init(inst, def);
1961
1987
  inst._zod.optin = "optional";
@@ -2185,7 +2211,7 @@ window.__ModuleLoader__.load({
2185
2211
  }
2186
2212
  }
2187
2213
  //#endregion
2188
- //#region node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/registries.js
2214
+ //#region node_modules/zod/v4/core/registries.js
2189
2215
  var _a;
2190
2216
  var $ZodRegistry = class {
2191
2217
  constructor() {
@@ -2232,7 +2258,7 @@ window.__ModuleLoader__.load({
2232
2258
  (_a = globalThis).__zod_globalRegistry ?? (_a.__zod_globalRegistry = registry());
2233
2259
  const globalRegistry = globalThis.__zod_globalRegistry;
2234
2260
  //#endregion
2235
- //#region node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/api.js
2261
+ //#region node_modules/zod/v4/core/api.js
2236
2262
  // @__NO_SIDE_EFFECTS__
2237
2263
  function _string(Class, params) {
2238
2264
  return new Class({
@@ -2737,7 +2763,7 @@ window.__ModuleLoader__.load({
2737
2763
  return ch;
2738
2764
  }
2739
2765
  //#endregion
2740
- //#region node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/to-json-schema.js
2766
+ //#region node_modules/zod/v4/core/to-json-schema.js
2741
2767
  function initializeContext(params) {
2742
2768
  let target = params?.target ?? "draft-2020-12";
2743
2769
  if (target === "draft-4") target = "draft-04";
@@ -3032,7 +3058,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
3032
3058
  return finalize(ctx, schema);
3033
3059
  };
3034
3060
  //#endregion
3035
- //#region node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/json-schema-processors.js
3061
+ //#region node_modules/zod/v4/core/json-schema-processors.js
3036
3062
  const formatMap = {
3037
3063
  guid: "uuid",
3038
3064
  url: "uri",
@@ -3096,6 +3122,28 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
3096
3122
  if (values.every((v) => typeof v === "string")) json.type = "string";
3097
3123
  json.enum = values;
3098
3124
  };
3125
+ const literalProcessor = (schema, ctx, json, _params) => {
3126
+ const def = schema._zod.def;
3127
+ const vals = [];
3128
+ for (const val of def.values) if (val === void 0) {
3129
+ if (ctx.unrepresentable === "throw") throw new Error("Literal `undefined` cannot be represented in JSON Schema");
3130
+ } else if (typeof val === "bigint") {
3131
+ if (ctx.unrepresentable === "throw") throw new Error("BigInt literals cannot be represented in JSON Schema");
3132
+ else vals.push(Number(val));
3133
+ } else vals.push(val);
3134
+ if (vals.length === 0) {} else if (vals.length === 1) {
3135
+ const val = vals[0];
3136
+ json.type = val === null ? "null" : typeof val;
3137
+ if (ctx.target === "draft-04" || ctx.target === "openapi-3.0") json.enum = [val];
3138
+ else json.const = val;
3139
+ } else {
3140
+ if (vals.every((v) => typeof v === "number")) json.type = "number";
3141
+ if (vals.every((v) => typeof v === "string")) json.type = "string";
3142
+ if (vals.every((v) => typeof v === "boolean")) json.type = "boolean";
3143
+ if (vals.every((v) => v === null)) json.type = "null";
3144
+ json.enum = vals;
3145
+ }
3146
+ };
3099
3147
  const customProcessor = (_schema, ctx, _json, _params) => {
3100
3148
  if (ctx.unrepresentable === "throw") throw new Error("Custom types cannot be represented in JSON Schema");
3101
3149
  };
@@ -3242,7 +3290,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
3242
3290
  seen.ref = def.innerType;
3243
3291
  };
3244
3292
  //#endregion
3245
- //#region node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/classic/iso.js
3293
+ //#region node_modules/zod/v4/classic/iso.js
3246
3294
  const ZodISODateTime = /*@__PURE__*/ $constructor("ZodISODateTime", (inst, def) => {
3247
3295
  $ZodISODateTime.init(inst, def);
3248
3296
  ZodStringFormat.init(inst, def);
@@ -3272,7 +3320,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
3272
3320
  return /* @__PURE__ */ _isoDuration(ZodISODuration, params);
3273
3321
  }
3274
3322
  //#endregion
3275
- //#region node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/classic/errors.js
3323
+ //#region node_modules/zod/v4/classic/errors.js
3276
3324
  const initializer = (inst, issues) => {
3277
3325
  $ZodError.init(inst, issues);
3278
3326
  inst.name = "ZodError";
@@ -3294,7 +3342,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
3294
3342
  };
3295
3343
  const ZodRealError = /*@__PURE__*/ $constructor("ZodError", initializer, { Parent: Error });
3296
3344
  //#endregion
3297
- //#region node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/classic/parse.js
3345
+ //#region node_modules/zod/v4/classic/parse.js
3298
3346
  const parse = /* @__PURE__ */ _parse(ZodRealError);
3299
3347
  const parseAsync = /* @__PURE__ */ _parseAsync(ZodRealError);
3300
3348
  const safeParse = /* @__PURE__ */ _safeParse(ZodRealError);
@@ -3308,7 +3356,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
3308
3356
  const safeEncodeAsync = /* @__PURE__ */ _safeEncodeAsync(ZodRealError);
3309
3357
  const safeDecodeAsync = /* @__PURE__ */ _safeDecodeAsync(ZodRealError);
3310
3358
  //#endregion
3311
- //#region node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/classic/schemas.js
3359
+ //#region node_modules/zod/v4/classic/schemas.js
3312
3360
  const _installedGroups = /* @__PURE__ */ new WeakMap();
3313
3361
  function _installLazyMethods(inst, group, methods) {
3314
3362
  const proto = Object.getPrototypeOf(inst);
@@ -3899,6 +3947,23 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
3899
3947
  ...normalizeParams(params)
3900
3948
  });
3901
3949
  }
3950
+ const ZodLiteral = /*@__PURE__*/ $constructor("ZodLiteral", (inst, def) => {
3951
+ $ZodLiteral.init(inst, def);
3952
+ ZodType.init(inst, def);
3953
+ inst._zod.processJSONSchema = (ctx, json, params) => literalProcessor(inst, ctx, json, params);
3954
+ inst.values = new Set(def.values);
3955
+ Object.defineProperty(inst, "value", { get() {
3956
+ if (def.values.length > 1) throw new Error("This schema contains multiple valid literal values. Use `.values` instead.");
3957
+ return def.values[0];
3958
+ } });
3959
+ });
3960
+ function literal(value, params) {
3961
+ return new ZodLiteral({
3962
+ type: "literal",
3963
+ values: Array.isArray(value) ? value : [value],
3964
+ ...normalizeParams(params)
3965
+ });
3966
+ }
3902
3967
  const ZodTransform = /*@__PURE__*/ $constructor("ZodTransform", (inst, def) => {
3903
3968
  $ZodTransform.init(inst, def);
3904
3969
  ZodType.init(inst, def);
@@ -4065,6 +4130,54 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
4065
4130
  return /* @__PURE__ */ _superRefine(fn, params);
4066
4131
  }
4067
4132
  //#endregion
4133
+ //#region lib/types/preset-tool-catalog-schema.js
4134
+ /** Shared wire codec; no Host service or browser side effects. */
4135
+ const presetToolCatalogSchema = object({
4136
+ preset: string(),
4137
+ registeredOnly: literal(true),
4138
+ legacyCapabilities: object({
4139
+ terminalToolsEnabled: boolean().optional(),
4140
+ planToolEnabled: boolean().optional(),
4141
+ patchToolEnabled: boolean().optional()
4142
+ }).optional(),
4143
+ tools: array(object({
4144
+ name: string(),
4145
+ description: string(),
4146
+ conditional: boolean(),
4147
+ codexTool: object({
4148
+ capability: _enum([
4149
+ "terminalToolsEnabled",
4150
+ "planToolEnabled",
4151
+ "patchToolEnabled"
4152
+ ]),
4153
+ presetEnabled: boolean(),
4154
+ presetOverridesLegacy: boolean().optional()
4155
+ }).optional(),
4156
+ replacements: array(object({
4157
+ action: _enum(["codex-exec", "codex-plan"]),
4158
+ tools: array(string()),
4159
+ available: boolean(),
4160
+ reason: _enum(["conditional", "target-exists"]).optional()
4161
+ }))
4162
+ }))
4163
+ });
4164
+ //#endregion
4165
+ //#region lib/types/preset-prompt-catalog-schema.js
4166
+ /** Same strict codec for current and legacy Remote contracts. */
4167
+ const presetPromptCatalogSchema = object({
4168
+ preset: string(),
4169
+ sections: array(object({
4170
+ name: string(),
4171
+ label: string(),
4172
+ text: string().max(1e6),
4173
+ editable: boolean(),
4174
+ order: number().finite().optional(),
4175
+ complete: boolean().optional(),
4176
+ interpolate: boolean().optional(),
4177
+ reason: string().optional()
4178
+ })).max(200)
4179
+ });
4180
+ //#endregion
4068
4181
  //#region lib/types/preset-editor-remote.js
4069
4182
  const promptSections = array(object({
4070
4183
  id: string(),
@@ -4124,13 +4237,15 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
4124
4237
  codec: {
4125
4238
  mode: "strict",
4126
4239
  typeSymbol: `${id}:${parameter}`,
4127
- schema: input
4240
+ schema: input,
4241
+ create: () => input
4128
4242
  }
4129
4243
  }] : [],
4130
4244
  result: {
4131
4245
  mode: "strict",
4132
4246
  typeSymbol: `${id}:result`,
4133
- schema: output
4247
+ schema: output,
4248
+ create: () => output
4134
4249
  }
4135
4250
  };
4136
4251
  }
@@ -4138,6 +4253,8 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
4138
4253
  package: "@shuind/dsh-codex-harness",
4139
4254
  descriptors: [
4140
4255
  descriptor("catalog", void 0, unknown(), catalog),
4256
+ descriptor("tools", "id", string().min(1).max(256), presetToolCatalogSchema),
4257
+ descriptor("prompts", "id", string().min(1).max(256), presetPromptCatalogSchema),
4141
4258
  descriptor("read", "id", string(), document$1),
4142
4259
  descriptor("update", "rawInput", object({
4143
4260
  ...fields,
@@ -4163,7 +4280,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
4163
4280
  /** Default plugin-owned Codex operating prompt. */
4164
4281
  const DEFAULT_CODEX_SYSTEM_PROMPT = String.raw`## General
4165
4282
 
4166
- - When searching for text or files, prefer using rg or rg --files respectively because rg is much faster than alternatives like grep. If rg is not available, use the next best alternative.
4283
+ - Follow the current tool catalog, not assumptions from another Codex client. For unknown paths, use the available list/search tools instead of guessing and reuse the returned paths. If only shell search is available, prefer rg or rg --files.
4167
4284
 
4168
4285
  ## Editing constraints
4169
4286
 
@@ -4179,6 +4296,8 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
4179
4296
  ## dsh session
4180
4297
 
4181
4298
  - The user and you share one workspace. Inspect the repository and every applicable AGENTS.md before editing.
4299
+ - For Harness APIs, first load the relevant Harness skill. When Inspect tools are available, start with cordis_inspect_list, then query the provider's directory before an exact Service contract. Reuse returned names; Inspect is read-only.
4300
+ - A not-found path or unknown Service is a discovery error: check the file list or Service directory before retrying. Preserve actual failures; do not hide them or bypass permission denials.
4182
4301
 
4183
4302
  ## Task execution
4184
4303
 
@@ -4198,7 +4317,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
4198
4317
  - Solve problems by thinking from first principles and at a higher level.
4199
4318
  `;
4200
4319
  String.raw`You are Codex, a coding agent based on the {{model}} model. Your working directory is {{cwd}}.`;
4201
- String.raw`The DeepSeek Harness implementation checkout is at {{sourceRoot}}. The checkout location and current working directory are separate values and may differ; never infer the working directory from this path. Use pwd to determine the current working directory. Use this checkout only to inspect or extend DSH itself.`;
4320
+ String.raw`The DeepSeek Harness implementation checkout is at {{sourceRoot}}. The checkout location and current working directory are separate values and may differ; never infer the working directory from this path. Use pwd to determine the current working directory. Use this checkout only to inspect or extend DSH itself. If the supplied path is inside app.asar, treat it as a packaged runtime rather than a source checkout. Discover the installed packageDir via Inspect and read its README and package.json exports; do not assume src or individual lib/types filenames exist. Use Host file-read tools for app.asar; native shell search and glob cannot traverse it.`;
4202
4321
  [
4203
4322
  "You are interacting with the user through the DeepSeek Harness Web GUI at {{webUrl}}.",
4204
4323
  "When the user refers to \"this page\", \"this GUI\", or \"this app\" without naming another target, they mean this GUI.",
@@ -4211,6 +4330,94 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
4211
4330
  ].join(" ");
4212
4331
  //#endregion
4213
4332
  //#region lib/types/client/preset-requests.js
4333
+ const catalogs = /* @__PURE__ */ new WeakMap();
4334
+ const catalogRequests = /* @__PURE__ */ new WeakMap();
4335
+ function cachedPresetCatalog(manager) {
4336
+ return catalogs.get(manager);
4337
+ }
4338
+ function cachePresetCatalog(manager, catalog) {
4339
+ catalogs.set(manager, catalog);
4340
+ }
4341
+ /** One cache and one in-flight catalog read for every surface using this manager. */
4342
+ function requestPresetCatalog(manager, refresh = false) {
4343
+ const pending = catalogRequests.get(manager);
4344
+ if (pending !== void 0) return pending;
4345
+ const cached = catalogs.get(manager);
4346
+ if (!refresh && cached !== void 0) return Promise.resolve(cached);
4347
+ const request = (async () => {
4348
+ await manager.ready;
4349
+ const result = await manager.remote.codexPresetEditor.catalog();
4350
+ if (!result.ok) throw new Error(result.error.message ?? "preset-catalog-unavailable");
4351
+ catalogs.set(manager, result.value);
4352
+ return result.value;
4353
+ })();
4354
+ catalogRequests.set(manager, request);
4355
+ request.finally(() => {
4356
+ if (catalogRequests.get(manager) === request) catalogRequests.delete(manager);
4357
+ }).catch(() => {});
4358
+ return request;
4359
+ }
4360
+ const toolCatalogs = /* @__PURE__ */ new WeakMap();
4361
+ const toolRequests = /* @__PURE__ */ new WeakMap();
4362
+ function cachedPresetTools(manager, id) {
4363
+ return toolCatalogs.get(manager)?.get(id);
4364
+ }
4365
+ /** The requested preset owns this snapshot; never substitute current-Agent tools. */
4366
+ function requestPresetTools(manager, id, refresh = false) {
4367
+ const pending = toolRequests.get(manager)?.get(id);
4368
+ if (pending !== void 0) return pending;
4369
+ const cached = cachedPresetTools(manager, id);
4370
+ if (!refresh && cached !== void 0) return Promise.resolve(cached);
4371
+ const requests = toolRequests.get(manager) ?? /* @__PURE__ */ new Map();
4372
+ toolRequests.set(manager, requests);
4373
+ const request = (async () => {
4374
+ await manager.ready;
4375
+ const remote = manager.remote.codexPresetEditor;
4376
+ if (typeof remote.tools !== "function") throw new Error("preset-tools-unavailable");
4377
+ const result = await remote.tools(id);
4378
+ if (!result.ok) throw new Error(result.error.message ?? "preset-tools-unavailable");
4379
+ if (result.value.preset !== id || result.value.registeredOnly !== true || !Array.isArray(result.value.tools)) throw new Error("preset-tools-mismatched-snapshot");
4380
+ const catalogs = toolCatalogs.get(manager) ?? /* @__PURE__ */ new Map();
4381
+ catalogs.set(id, result.value);
4382
+ toolCatalogs.set(manager, catalogs);
4383
+ return result.value;
4384
+ })();
4385
+ requests.set(id, request);
4386
+ request.finally(() => {
4387
+ if (requests.get(id) === request) requests.delete(id);
4388
+ }).catch(() => {});
4389
+ return request;
4390
+ }
4391
+ const promptCatalogs = /* @__PURE__ */ new WeakMap();
4392
+ const promptRequests = /* @__PURE__ */ new WeakMap();
4393
+ function cachedPresetPrompts(manager, id) {
4394
+ return promptCatalogs.get(manager)?.get(id);
4395
+ }
4396
+ function requestPresetPrompts(manager, id, refresh = false) {
4397
+ const pending = promptRequests.get(manager)?.get(id);
4398
+ if (pending !== void 0) return pending;
4399
+ const cached = cachedPresetPrompts(manager, id);
4400
+ if (!refresh && cached !== void 0) return Promise.resolve(cached);
4401
+ const requests = promptRequests.get(manager) ?? /* @__PURE__ */ new Map();
4402
+ promptRequests.set(manager, requests);
4403
+ const request = (async () => {
4404
+ await manager.ready;
4405
+ const remote = manager.remote.codexPresetEditor;
4406
+ if (typeof remote.prompts !== "function") throw new Error("preset-prompts-unavailable");
4407
+ const result = await remote.prompts(id);
4408
+ if (!result.ok) throw new Error(result.error.message ?? "preset-prompts-unavailable");
4409
+ if (result.value.preset !== id || !Array.isArray(result.value.sections)) throw new Error("preset-prompts-mismatched-snapshot");
4410
+ const catalogs = promptCatalogs.get(manager) ?? /* @__PURE__ */ new Map();
4411
+ catalogs.set(id, result.value);
4412
+ promptCatalogs.set(manager, catalogs);
4413
+ return result.value;
4414
+ })();
4415
+ requests.set(id, request);
4416
+ request.finally(() => {
4417
+ if (requests.get(id) === request) requests.delete(id);
4418
+ }).catch(() => {});
4419
+ return request;
4420
+ }
4214
4421
  /** Only transport failures from a read can be retried without duplicating writes. */
4215
4422
  function isPresetConnectionError(error) {
4216
4423
  const message = error instanceof Error ? error.message : String(error);
@@ -4228,7 +4435,6 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
4228
4435
  }
4229
4436
  //#endregion
4230
4437
  //#region lib/types/client/preset-manager.js
4231
- const catalogCache = /* @__PURE__ */ new WeakMap();
4232
4438
  const documentCache = /* @__PURE__ */ new WeakMap();
4233
4439
  const CODEX_DEFAULT_ID = "codex-collaboration";
4234
4440
  function unwrap(result) {
@@ -4243,15 +4449,15 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
4243
4449
  .codex-preset-editor { display:grid; gap:12px; min-width:0; font-size:13px; }
4244
4450
  .codex-preset-editor label { display:grid; gap:6px; }
4245
4451
  .codex-preset-editor .pe-row { display:flex; align-items:center; gap:10px; flex-wrap:wrap; }
4246
- .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; }
4452
+ .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; }
4247
4453
  .codex-preset-editor textarea { resize:vertical; line-height:1.5; }
4248
- .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; }
4454
+ .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; }
4249
4455
  .codex-preset-editor button:disabled { opacity:.5; cursor:default; }
4250
- .codex-preset-editor .pe-primary { background:#425ce5; border-color:#425ce5; color:white; }
4456
+ .codex-preset-editor .pe-primary { background:var(--dsw-alias-label-primary); border-color:var(--dsw-alias-label-primary); color:var(--dsw-alias-bg-base); }
4251
4457
  .codex-preset-editor .pe-block { display:grid; gap:9px; padding-top:12px; border-top:1px solid var(--dsw-alias-border-l2); }
4252
4458
  .codex-preset-editor .pe-toggle { display:flex; align-items:flex-start; gap:9px; }
4253
4459
  .codex-preset-editor .pe-toggle span { display:grid; gap:2px; }
4254
- .codex-preset-editor p { margin:0; font-size:12px; line-height:1.55; color:var(--dsw-alias-label-tertiary); }
4460
+ .codex-preset-editor p { margin:0; font-size:12px; line-height:1.55; color:var(--dsw-alias-label-secondary); }
4255
4461
  `;
4256
4462
  function optionToggle(key, label, hint, options, setOptions, disabled) {
4257
4463
  return (0, react_jsx_runtime.jsxs)("label", {
@@ -4268,8 +4474,8 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
4268
4474
  }, key);
4269
4475
  }
4270
4476
  /** Presets are peers: choose one to edit, or make an editable copy first. */
4271
- function PresetManagerCard({ presetManager, t }) {
4272
- const [catalog, setCatalog] = (0, react.useState)(() => catalogCache.get(presetManager));
4477
+ function PresetManagerCard({ presetManager, t, readOnly: inspectOnly = false }) {
4478
+ const [catalog, setCatalog] = (0, react.useState)(() => cachedPresetCatalog(presetManager));
4273
4479
  const [selectedId, setSelectedId] = (0, react.useState)("");
4274
4480
  const [original, setOriginal] = (0, react.useState)();
4275
4481
  const [draft, setDraft] = (0, react.useState)();
@@ -4339,18 +4545,23 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
4339
4545
  }
4340
4546
  }
4341
4547
  async function refresh() {
4342
- setErrorAction("read");
4343
- const value = await readPresetWithRetry(() => remote.catalog().then(unwrap), () => alive.current);
4548
+ setErrorAction("catalog");
4549
+ const value = await readPresetWithRetry(() => requestPresetCatalog(presetManager, true), () => alive.current);
4344
4550
  if (!alive.current) return;
4345
- catalogCache.set(presetManager, value);
4346
4551
  setCatalog(value);
4347
- const current = selectedId || (value.presets.some((row) => row.id === CODEX_DEFAULT_ID) ? CODEX_DEFAULT_ID : value.presets[0]?.id ?? "");
4348
- if (current && current !== selectedId) await load(current, false);
4552
+ const current = value.presets.some((row) => row.id === selectedId) ? selectedId : value.presets.some((row) => row.id === CODEX_DEFAULT_ID) ? CODEX_DEFAULT_ID : value.presets[0]?.id ?? "";
4553
+ if (current) await load(current, false);
4554
+ else {
4555
+ setSelectedId("");
4556
+ setOriginal(void 0);
4557
+ setDraft(void 0);
4558
+ }
4349
4559
  }
4350
4560
  (0, react.useEffect)(() => {
4351
4561
  alive.current = true;
4352
- if (!catalogCache.has(presetManager)) run(refresh);
4353
- else if (!selectedId) load(catalogCache.get(presetManager)?.presets.some((row) => row.id === CODEX_DEFAULT_ID) ? CODEX_DEFAULT_ID : catalogCache.get(presetManager)?.presets[0]?.id ?? "", false);
4562
+ const cached = cachedPresetCatalog(presetManager);
4563
+ if (cached === void 0) run(refresh);
4564
+ else if (!selectedId) load(cached.presets.some((row) => row.id === CODEX_DEFAULT_ID) ? CODEX_DEFAULT_ID : cached.presets[0]?.id ?? "", false);
4354
4565
  return () => {
4355
4566
  alive.current = false;
4356
4567
  };
@@ -4371,7 +4582,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
4371
4582
  });
4372
4583
  }
4373
4584
  function beginCopy() {
4374
- if (!draft || !sourceId) return;
4585
+ if (inspectOnly || !draft || !sourceId) return;
4375
4586
  setCopyMode(true);
4376
4587
  setCodexEnabled(draft.codex);
4377
4588
  setOriginal({ ...draft });
@@ -4384,7 +4595,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
4384
4595
  });
4385
4596
  }
4386
4597
  function save() {
4387
- if (!draft || busy || !draft.name.trim()) return;
4598
+ if (inspectOnly || !draft || busy || !draft.name.trim()) return;
4388
4599
  setErrorAction("save");
4389
4600
  run(async () => {
4390
4601
  const options = codexEnabled ? draft.codexOptions : void 0;
@@ -4426,7 +4637,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
4426
4637
  isDefault: catalog.presets.find((item) => item.id === value.id)?.isDefault ?? false
4427
4638
  };
4428
4639
  const presets = catalog.presets.some((item) => item.id === value.id) ? catalog.presets.map((item) => item.id === value.id ? row : item) : [...catalog.presets, row];
4429
- catalogCache.set(presetManager, {
4640
+ cachePresetCatalog(presetManager, {
4430
4641
  ...catalog,
4431
4642
  presets
4432
4643
  });
@@ -4438,7 +4649,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
4438
4649
  });
4439
4650
  }
4440
4651
  const selectedRow = catalog?.presets.find((row) => row.id === selectedId);
4441
- const readOnly = !!draft && !draft.editable && !copyMode;
4652
+ const readOnly = inspectOnly || !!draft && !draft.editable && !copyMode;
4442
4653
  const options = draft?.codexOptions;
4443
4654
  return (0, react_jsx_runtime.jsxs)("section", {
4444
4655
  className: "codex-preset-editor",
@@ -4455,10 +4666,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
4455
4666
  onClick: () => {
4456
4667
  if (dirty && !window.confirm(t("pmDiscard"))) return;
4457
4668
  cache.clear();
4458
- run(async () => {
4459
- await refresh();
4460
- if (selectedId) await load(selectedId, false);
4461
- });
4669
+ run(refresh);
4462
4670
  },
4463
4671
  children: t("pmRefresh")
4464
4672
  })]
@@ -4478,21 +4686,22 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
4478
4686
  children: [row.name, row.editable ? "" : ` · ${t("pmBuiltIn")}`]
4479
4687
  }, row.id))]
4480
4688
  })] }),
4481
- selectedRow && (0, react_jsx_runtime.jsx)("p", { children: selectedRow.editable ? t("peEditable") : t("peBuiltinEdit") }),
4689
+ selectedRow && (0, react_jsx_runtime.jsx)("p", { children: selectedRow.editable ? t("peEditable") : t(catalog?.authorable ? "peBuiltinEdit" : "pmRegistryReadOnly") }),
4482
4690
  error && (0, react_jsx_runtime.jsxs)("div", {
4483
4691
  role: "alert",
4484
4692
  children: [
4485
- (0, react_jsx_runtime.jsx)("p", { children: errorAction === "read" ? t(isPresetConnectionError(error) ? "peConnectionError" : "peReadError") : error.includes("preset-conflict") ? t("pmConflict") : error.includes("invalid-preset-yaml") ? t("pmYamlError") : t("pmSaveError") }),
4486
- errorAction === "read" && (0, react_jsx_runtime.jsxs)("div", {
4693
+ (0, react_jsx_runtime.jsx)("p", { children: errorAction !== "save" ? t(isPresetConnectionError(error) ? "peConnectionError" : "peReadError") : error.includes("preset-conflict") ? t("pmConflict") : error.includes("invalid-preset-yaml") ? t("pmYamlError") : t("pmSaveError") }),
4694
+ errorAction !== "save" && (0, react_jsx_runtime.jsxs)("div", {
4487
4695
  className: "pe-row",
4488
4696
  children: [(0, react_jsx_runtime.jsx)("button", {
4489
4697
  type: "button",
4490
4698
  disabled: busy,
4491
4699
  onClick: () => {
4492
- if (selectedId) {
4700
+ if (errorAction === "catalog" || !selectedId) run(refresh);
4701
+ else {
4493
4702
  cache.delete(selectedId);
4494
4703
  load(selectedId, false);
4495
- } else run(refresh);
4704
+ }
4496
4705
  },
4497
4706
  children: t("peRetryRead")
4498
4707
  }), !draft && isPresetConnectionError(error) && (0, react_jsx_runtime.jsx)("button", {
@@ -4528,9 +4737,9 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
4528
4737
  disabled: busy || readOnly,
4529
4738
  onChange: (event) => patch({ description: event.target.value })
4530
4739
  })] }),
4531
- !copyMode && (0, react_jsx_runtime.jsx)("button", {
4740
+ !inspectOnly && !copyMode && catalog?.authorable && (0, react_jsx_runtime.jsx)("button", {
4532
4741
  type: "button",
4533
- disabled: busy || !catalog?.authorable,
4742
+ disabled: busy,
4534
4743
  onClick: beginCopy,
4535
4744
  children: t("peCreateCopy")
4536
4745
  }),
@@ -4646,9 +4855,91 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
4646
4855
  ]
4647
4856
  });
4648
4857
  }
4858
+ /** A fixed-ID declaration viewer: no second picker and no write/copy actions. */
4859
+ function PresetDefinitionCard({ presetManager, id, t }) {
4860
+ const [value, setValue] = (0, react.useState)();
4861
+ const [loading, setLoading] = (0, react.useState)(true);
4862
+ const [error, setError] = (0, react.useState)("");
4863
+ const request = (0, react.useRef)(0);
4864
+ const alive = (0, react.useRef)(true);
4865
+ async function load(refresh = false) {
4866
+ const ticket = ++request.current;
4867
+ setLoading(true);
4868
+ setError("");
4869
+ try {
4870
+ await presetManager.ready;
4871
+ const cache = documentCache.get(presetManager) ?? /* @__PURE__ */ new Map();
4872
+ documentCache.set(presetManager, cache);
4873
+ const cached = cache.get(id);
4874
+ const document = !refresh && cached && Date.now() - cached.time < 6e4 ? cached.value : await readPresetWithRetry(() => presetManager.remote.codexPresetEditor.read(id).then(unwrap), () => alive.current && ticket === request.current);
4875
+ if (document.id !== id) throw new Error("preset-document-mismatch");
4876
+ cache.set(id, {
4877
+ value: document,
4878
+ time: Date.now()
4879
+ });
4880
+ if (alive.current && ticket === request.current) setValue(document);
4881
+ } catch (cause) {
4882
+ if (alive.current && ticket === request.current) setError(cause instanceof Error ? cause.message : String(cause));
4883
+ } finally {
4884
+ if (alive.current && ticket === request.current) setLoading(false);
4885
+ }
4886
+ }
4887
+ (0, react.useEffect)(() => {
4888
+ alive.current = true;
4889
+ load();
4890
+ return () => {
4891
+ alive.current = false;
4892
+ request.current++;
4893
+ };
4894
+ }, [presetManager, id]);
4895
+ const shown = value?.id === id ? value : void 0;
4896
+ return (0, react_jsx_runtime.jsxs)("section", {
4897
+ className: "codex-preset-editor",
4898
+ "aria-label": t("settingsDefinition"),
4899
+ "aria-busy": loading,
4900
+ children: [
4901
+ (0, react_jsx_runtime.jsx)("style", { children: styles }),
4902
+ (0, react_jsx_runtime.jsx)("h3", { children: t("settingsDefinition") }),
4903
+ (0, react_jsx_runtime.jsx)("code", { children: id }),
4904
+ (0, react_jsx_runtime.jsx)("button", {
4905
+ type: "button",
4906
+ disabled: loading,
4907
+ onClick: () => {
4908
+ load(true);
4909
+ },
4910
+ children: t("pmRefresh")
4911
+ }),
4912
+ loading && !shown && (0, react_jsx_runtime.jsx)("p", {
4913
+ role: "status",
4914
+ children: t("peLoading")
4915
+ }),
4916
+ error && (0, react_jsx_runtime.jsx)("p", {
4917
+ role: "alert",
4918
+ children: t("peReadError")
4919
+ }),
4920
+ shown && (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
4921
+ (0, react_jsx_runtime.jsx)("strong", { children: shown.name }),
4922
+ (0, react_jsx_runtime.jsx)("p", { children: shown.description }),
4923
+ (0, react_jsx_runtime.jsx)("pre", {
4924
+ style: {
4925
+ whiteSpace: "pre-wrap",
4926
+ overflowWrap: "anywhere",
4927
+ margin: 0
4928
+ },
4929
+ children: shown.composition || JSON.stringify({
4930
+ id: shown.id,
4931
+ name: shown.name,
4932
+ promptSections: shown.promptSections
4933
+ }, null, 2)
4934
+ })
4935
+ ] })
4936
+ ]
4937
+ });
4938
+ }
4649
4939
  //#endregion
4650
4940
  //#region lib/types/client/preset-copy.js
4651
4941
  const presetEn = {
4942
+ pmRegistryReadOnly: "This host exposes read-only preset declarations. Edit global Codex settings below; creating editable preset copies is not supported here.",
4652
4943
  peConnectionError: "Could not connect to the local service. Retry loading; if the connection still fails, reconnect the page.",
4653
4944
  peReadError: "Could not read this preset. Retry loading or refresh the preset list.",
4654
4945
  peRetryRead: "Retry loading",
@@ -4689,6 +4980,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
4689
4980
  pmSave: "Save changes"
4690
4981
  };
4691
4982
  const presetZh = {
4983
+ pmRegistryReadOnly: "This host exposes read-only preset declarations. Edit global Codex settings below; creating editable preset copies is not supported here.",
4692
4984
  peConnectionError: "未能连接本地服务。请重试读取;如果仍然失败,请重新连接页面。",
4693
4985
  peReadError: "无法读取这个预设,请重试读取或刷新预设列表。",
4694
4986
  peRetryRead: "重试读取",
@@ -4729,6 +5021,985 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
4729
5021
  pmSave: "保存修改"
4730
5022
  };
4731
5023
  //#endregion
5024
+ //#region lib/types/preset-prompt-contract.js
5025
+ /** Client-safe current-preset prompt catalog; editable targets have reviewed native contracts. */
5026
+ const PRESET_PROMPT_NAMES = [
5027
+ "deployment:persona-prefix",
5028
+ "deployment:persona-suffix",
5029
+ "codex:base"
5030
+ ];
5031
+ //#endregion
5032
+ //#region lib/types/tool-policy-contract.js
5033
+ /** Legacy configuration remains a baseline, never a live second veto of an explicit choice. */
5034
+ function legacyToolAction(rule, name, context = {}) {
5035
+ let action = "keep";
5036
+ if (rule !== void 0) {
5037
+ if (rule.allow !== void 0 && !rule.allow.includes(name) || rule.deny?.includes(name)) return "hide";
5038
+ if ((name === "bash" || name === "pwsh") && rule.replaceShell !== false) action = "codex-exec";
5039
+ if (name === "todo_write" && rule.replacePlan !== false) action = "codex-plan";
5040
+ }
5041
+ const capability = context.codexTool?.capability ?? (action === "codex-exec" ? "terminalToolsEnabled" : action === "codex-plan" ? "planToolEnabled" : void 0);
5042
+ if (!(context.codexTool?.presetOverridesLegacy === true && context.codexTool.presetEnabled) && capability !== void 0 && context.legacyCapabilities?.[capability] === false) return "hide";
5043
+ return action;
5044
+ }
5045
+ /** Policy action only: `keep` still respects the original preset's local enablement. */
5046
+ function effectiveToolAction(rule, name, context = {}) {
5047
+ return rule?.tools?.find((tool) => tool.name === name)?.action ?? legacyToolAction(rule, name, context);
5048
+ }
5049
+ //#endregion
5050
+ //#region lib/types/client/policy-drafts.js
5051
+ function canonical(value) {
5052
+ if (Array.isArray(value)) return value.map(canonical);
5053
+ if (value !== null && typeof value === "object") return Object.fromEntries(Object.entries(value).filter(([, item]) => item !== void 0).sort(([a], [b]) => a.localeCompare(b)).map(([key, item]) => [key, canonical(item)]));
5054
+ return value;
5055
+ }
5056
+ const sameRules = (a, b) => JSON.stringify(canonical(a)) === JSON.stringify(canonical(b));
5057
+ const presetRules = (rules, preset) => rules.filter((rule) => rule.preset === preset);
5058
+ function editPresetDraft(drafts, preset, accepted, change) {
5059
+ const previous = drafts.get(preset);
5060
+ const next = new Map(drafts);
5061
+ next.set(preset, {
5062
+ preset,
5063
+ revision: previous === void 0 ? accepted.revision : previous.revision,
5064
+ baseline: previous?.baseline ?? accepted.rules,
5065
+ rules: change(previous?.rules ?? presetRules(accepted.rules, preset))
5066
+ });
5067
+ return next;
5068
+ }
5069
+ /** Replace just this source target, preserving all accepted other targets/order. */
5070
+ function mergePresetRules(accepted, preset, replacement) {
5071
+ const first = accepted.findIndex((rule) => rule.preset === preset);
5072
+ if (first < 0) return [...accepted, ...replacement];
5073
+ return [
5074
+ ...accepted.slice(0, first),
5075
+ ...replacement,
5076
+ ...accepted.slice(first).filter((rule) => rule.preset !== preset)
5077
+ ];
5078
+ }
5079
+ function preparePresetSave(draft, accepted) {
5080
+ if (draft.revision !== accepted.revision || !sameRules(draft.baseline, accepted.rules)) throw new Error("policy-draft-conflict");
5081
+ return {
5082
+ draft,
5083
+ before: accepted,
5084
+ revision: draft.revision,
5085
+ rules: mergePresetRules(accepted.rules, draft.preset, draft.rules)
5086
+ };
5087
+ }
5088
+ function acceptPresetSave(drafts, saved, accepted) {
5089
+ const next = new Map(drafts);
5090
+ if (next.get(saved.draft.preset) === saved.draft) next.delete(saved.draft.preset);
5091
+ if (!sameRules(accepted.rules, saved.rules)) return next;
5092
+ for (const [preset, draft] of next) {
5093
+ if (draft.revision !== saved.before.revision || !sameRules(draft.baseline, saved.before.rules)) continue;
5094
+ if (!sameRules(presetRules(saved.before.rules, preset), presetRules(accepted.rules, preset))) continue;
5095
+ next.set(preset, {
5096
+ ...draft,
5097
+ revision: accepted.revision,
5098
+ baseline: accepted.rules
5099
+ });
5100
+ }
5101
+ return next;
5102
+ }
5103
+ //#endregion
5104
+ //#region lib/types/client/tool-policy.js
5105
+ /** One target at a time, with independent revision-fenced drafts. */
5106
+ const TOOL_POLICY_NAMESPACE = "codex-tool-policy";
5107
+ function bindToolPolicy(ctx, forms) {
5108
+ let form;
5109
+ const listeners = /* @__PURE__ */ new Set();
5110
+ const publish = (next) => {
5111
+ form = next;
5112
+ for (const listener of [...listeners]) listener();
5113
+ };
5114
+ ctx.effect(() => forms.whileServed([TOOL_POLICY_NAMESPACE], () => {
5115
+ publish(forms.get(TOOL_POLICY_NAMESPACE));
5116
+ return () => publish(void 0);
5117
+ }), "codex client: tool-policy availability");
5118
+ return {
5119
+ getSnapshot: () => form,
5120
+ subscribe: (listener) => {
5121
+ listeners.add(listener);
5122
+ return () => {
5123
+ listeners.delete(listener);
5124
+ };
5125
+ }
5126
+ };
5127
+ }
5128
+ const toolPolicyEn = {
5129
+ settingsTabLabel: "Codex Harness",
5130
+ settingsToolsPage: "Tool plans",
5131
+ settingsRuntimePage: "Runtime preferences",
5132
+ settingsAdvanced: "Advanced…",
5133
+ settingsAdvancedTools: "Individual tools",
5134
+ settingsPresetPrompts: "Preset prompts",
5135
+ settingsDefinition: "Original preset definition (read-only)",
5136
+ settingsPreferHostedSearch: "Prefer model-hosted search",
5137
+ settingsPreferRemoteCompaction: "Prefer remote compaction",
5138
+ settingsSharedFailed: "Not saved; this page’s draft is kept. Shared settings may have changed—discard this page’s draft to reload.",
5139
+ settingsRuntimeScope: "Shared in this environment",
5140
+ settingsSaveRuntime: "Save runtime preferences",
5141
+ settingsBundleSummary: "Configure Codex Harness in its dedicated Settings tab.",
5142
+ settingsBundlePath: "Settings → Plugins → Codex Harness",
5143
+ settingsDefinitionAbsent: "Choose a preset on Tool plans first.",
5144
+ globalGroupRequest: "Model requests",
5145
+ globalGroupTools: "Tools",
5146
+ globalGroupDisplay: "Display",
5147
+ globalPrompts: "Prompts",
5148
+ globalPending: "Unsaved",
5149
+ presetSourcesDetails: "Original preset definition (read-only)",
5150
+ toolPolicyTitle: "Tool plan",
5151
+ toolPolicyPresetChoice: "Preset",
5152
+ toolPolicyInvalidEntry: "Empty preset ID",
5153
+ toolPolicyTiming: "Applies: new/reloaded session",
5154
+ presetPromptsLoading: "Loading prompts…",
5155
+ presetPromptsFailed: "Prompts unavailable.",
5156
+ presetPromptsEmpty: "No prompt sections.",
5157
+ presetPromptsReload: "Reload prompts",
5158
+ presetPromptRestore: "Restore original",
5159
+ presetPromptReadOnly: "Read-only",
5160
+ presetPromptOverride: "Override",
5161
+ presetSummaryTools: "Tools",
5162
+ presetSummaryPrompts: "Prompts",
5163
+ toolPolicyDraftSummary: "Changes for this save",
5164
+ toolPolicyRuleChanged: "Preset changes",
5165
+ toolPolicyNoToolDelta: "No pending changes",
5166
+ toolPolicySearch: "Search all tools",
5167
+ toolPolicyFilter: "Tool filter",
5168
+ toolPolicyAll: "All",
5169
+ toolPolicyModified: "Customized",
5170
+ toolPolicyReplaceable: "Replaceable",
5171
+ toolPolicyAction: "Tool action",
5172
+ toolPolicyKeep: "Do not change",
5173
+ toolPolicyHide: "Hide",
5174
+ toolPolicyRestoreChoice: "Restore inherited choice",
5175
+ toolPolicyUnsupported: "Saved replacement unavailable",
5176
+ toolPolicyConditional: "Conditional",
5177
+ toolPolicyTargetExists: "Replacement target already exists",
5178
+ toolPolicyPresetDisabled: "Not enabled by the original preset",
5179
+ toolPolicyCommandGroup: "Commands",
5180
+ toolPolicyPlanGroup: "Planning",
5181
+ toolPolicyFileGroup: "Files",
5182
+ toolPolicyOtherGroup: "Other tools",
5183
+ toolPolicyCustomized: "customized",
5184
+ toolLabelPwsh: "PowerShell commands",
5185
+ toolLabelBash: "Shell commands",
5186
+ toolLabelExec: "Run commands",
5187
+ toolLabelStdin: "Continue an interactive command",
5188
+ toolLabelPlan: "Task planning",
5189
+ toolLabelRead: "Read files",
5190
+ toolLabelWrite: "Write files",
5191
+ toolLabelEdit: "Edit files",
5192
+ toolLabelPatch: "Patch files",
5193
+ toolLabelGlob: "Find files",
5194
+ toolLabelGrep: "Search file contents",
5195
+ toolLabelImage: "View images",
5196
+ toolLabelOther: "Other tool",
5197
+ toolPolicyToolsLoading: "Loading tools…",
5198
+ toolPolicyToolsEmpty: "No registered tools.",
5199
+ toolPolicyNoMatches: "No matching tools.",
5200
+ toolPolicyToolsFailed: "Tool list unavailable. Saved rules are kept.",
5201
+ toolPolicyToolsRefresh: "Refresh tools",
5202
+ toolPolicyCatalogLoading: "Loading presets…",
5203
+ toolPolicyCatalogEmpty: "No presets found.",
5204
+ toolPolicyCatalogFailed: "Preset list unavailable. Saved IDs remain selectable.",
5205
+ toolPolicyCatalogRetry: "Reload presets",
5206
+ toolPolicyEmpty: "Choose a preset",
5207
+ toolPolicySave: "Save this preset",
5208
+ toolPolicySaving: "Saving…",
5209
+ toolPolicyDiscard: "Discard this preset’s draft",
5210
+ toolPolicySaved: "This preset was saved.",
5211
+ toolPolicyInvalidPreset: "An empty preset ID cannot be saved.",
5212
+ toolPolicyDuplicatePreset: "Duplicate preset IDs cannot be saved.",
5213
+ toolPolicyRefused: "Not saved. This draft started from older settings; discard only this preset’s draft to reload.",
5214
+ toolPolicyFailed: "Save failed. This preset’s draft is kept.",
5215
+ toolPolicyReadOnly: "These settings are read-only."
5216
+ };
5217
+ const toolPolicyZh = {
5218
+ settingsTabLabel: "Codex Harness",
5219
+ settingsToolsPage: "工具方案",
5220
+ settingsRuntimePage: "运行偏好",
5221
+ settingsAdvanced: "高级…",
5222
+ settingsAdvancedTools: "逐项工具",
5223
+ settingsPresetPrompts: "预设提示词",
5224
+ settingsDefinition: "原始预设定义(只读)",
5225
+ settingsPreferHostedSearch: "优先使用模型托管搜索",
5226
+ settingsPreferRemoteCompaction: "优先使用远程压缩",
5227
+ settingsSharedFailed: "未保存,本页草稿已保留。共享设置可能已更新,请放弃本页草稿后重新读取。",
5228
+ settingsRuntimeScope: "本环境共享",
5229
+ settingsSaveRuntime: "保存运行偏好",
5230
+ settingsBundleSummary: "请在独立的 Codex Harness 设置页配置。",
5231
+ settingsBundlePath: "设置 → 内置插件 → Codex Harness",
5232
+ settingsDefinitionAbsent: "请先在工具方案页选择预设。",
5233
+ globalGroupRequest: "模型请求",
5234
+ globalGroupTools: "工具",
5235
+ globalGroupDisplay: "界面",
5236
+ globalPrompts: "提示词",
5237
+ globalPending: "未保存",
5238
+ presetSourcesDetails: "原始预设定义(只读)",
5239
+ toolPolicyTitle: "工具方案",
5240
+ toolPolicyPresetChoice: "预设",
5241
+ toolPolicyInvalidEntry: "空预设 ID",
5242
+ toolPolicyTiming: "生效:新建/重载会话",
5243
+ presetPromptsLoading: "正在读取提示词…",
5244
+ presetPromptsFailed: "提示词暂不可用。",
5245
+ presetPromptsEmpty: "没有提示词段落。",
5246
+ presetPromptsReload: "重新读取提示词",
5247
+ presetPromptRestore: "恢复原始",
5248
+ presetPromptReadOnly: "只读",
5249
+ presetPromptOverride: "覆盖",
5250
+ presetSummaryTools: "工具",
5251
+ presetSummaryPrompts: "提示词",
5252
+ toolPolicyDraftSummary: "本次修改",
5253
+ toolPolicyRuleChanged: "预设方案调整",
5254
+ toolPolicyNoToolDelta: "没有待保存变化",
5255
+ toolPolicySearch: "搜索全部工具",
5256
+ toolPolicyFilter: "工具筛选",
5257
+ toolPolicyAll: "全部",
5258
+ toolPolicyModified: "已自定义",
5259
+ toolPolicyReplaceable: "可替换",
5260
+ toolPolicyAction: "工具操作",
5261
+ toolPolicyKeep: "不改动",
5262
+ toolPolicyHide: "隐藏",
5263
+ toolPolicyRestoreChoice: "恢复继承选择",
5264
+ toolPolicyUnsupported: "已保存的替换当前不可用",
5265
+ toolPolicyConditional: "按条件可用",
5266
+ toolPolicyTargetExists: "替换目标已存在",
5267
+ toolPolicyPresetDisabled: "原预设未启用",
5268
+ toolPolicyCommandGroup: "命令执行",
5269
+ toolPolicyPlanGroup: "任务计划",
5270
+ toolPolicyFileGroup: "文件操作",
5271
+ toolPolicyOtherGroup: "其它工具",
5272
+ toolPolicyCustomized: "项自定义",
5273
+ toolLabelPwsh: "PowerShell 命令",
5274
+ toolLabelBash: "Shell 命令",
5275
+ toolLabelExec: "运行命令",
5276
+ toolLabelStdin: "继续交互式命令",
5277
+ toolLabelPlan: "任务计划",
5278
+ toolLabelRead: "读取文件",
5279
+ toolLabelWrite: "写入文件",
5280
+ toolLabelEdit: "修改文件",
5281
+ toolLabelPatch: "补丁修改",
5282
+ toolLabelGlob: "查找文件",
5283
+ toolLabelGrep: "搜索文件内容",
5284
+ toolLabelImage: "查看图片",
5285
+ toolLabelOther: "其它工具",
5286
+ toolPolicyToolsLoading: "正在读取工具…",
5287
+ toolPolicyToolsEmpty: "没有已注册工具。",
5288
+ toolPolicyNoMatches: "没有匹配工具。",
5289
+ toolPolicyToolsFailed: "工具目录不可用,已保存规则仍保留。",
5290
+ toolPolicyToolsRefresh: "刷新工具",
5291
+ toolPolicyCatalogLoading: "正在读取预设…",
5292
+ toolPolicyCatalogEmpty: "没有可选预设。",
5293
+ toolPolicyCatalogFailed: "预设列表不可用,仍可选择已保存 ID。",
5294
+ toolPolicyCatalogRetry: "重新读取预设",
5295
+ toolPolicyEmpty: "请选择预设",
5296
+ toolPolicySave: "保存此预设",
5297
+ toolPolicySaving: "正在保存…",
5298
+ toolPolicyDiscard: "放弃此预设草稿",
5299
+ toolPolicySaved: "此预设已保存。",
5300
+ toolPolicyInvalidPreset: "预设 ID 为空,无法保存。",
5301
+ toolPolicyDuplicatePreset: "预设 ID 重复,无法保存。",
5302
+ toolPolicyRefused: "未保存,草稿基于旧设置。请仅放弃此预设草稿后重新读取。",
5303
+ toolPolicyFailed: "保存失败,此预设草稿已保留。",
5304
+ toolPolicyReadOnly: "当前设置为只读。"
5305
+ };
5306
+ function validateToolPolicyRules(rules) {
5307
+ const ids = /* @__PURE__ */ new Set();
5308
+ for (const rule of rules) {
5309
+ const id = rule.preset.trim();
5310
+ if (!id) return "toolPolicyInvalidPreset";
5311
+ if (ids.has(id)) return "toolPolicyDuplicatePreset";
5312
+ ids.add(id);
5313
+ }
5314
+ }
5315
+ function withToolAction(rule, name, action, context = {}) {
5316
+ const next = { ...rule };
5317
+ const tools = [...rule.tools ?? []].filter((tool) => tool.name !== name);
5318
+ if (action !== legacyToolAction(rule, name, context)) tools.push({
5319
+ name,
5320
+ action
5321
+ });
5322
+ if (tools.length) next.tools = tools;
5323
+ else delete next.tools;
5324
+ return next;
5325
+ }
5326
+ function saveToolPolicy(form, rules, revision) {
5327
+ const value = rules.map((rule) => {
5328
+ const row = { preset: rule.preset };
5329
+ if (rule.allow !== void 0) row.allow = [...rule.allow];
5330
+ if (rule.deny !== void 0) row.deny = [...rule.deny];
5331
+ if (rule.replaceShell !== void 0) row.replaceShell = rule.replaceShell;
5332
+ if (rule.replacePlan !== void 0) row.replacePlan = rule.replacePlan;
5333
+ if (rule.tools !== void 0) row.tools = rule.tools.map((tool) => ({ ...tool }));
5334
+ if (rule.promptOverrides !== void 0) row.promptOverrides = rule.promptOverrides.map((override) => ({
5335
+ name: override.name,
5336
+ text: override.text
5337
+ }));
5338
+ return row;
5339
+ });
5340
+ return form.mutate([{
5341
+ op: "set",
5342
+ path: ["rules"],
5343
+ value
5344
+ }], revision);
5345
+ }
5346
+ const isPromptName = (name) => PRESET_PROMPT_NAMES.includes(name);
5347
+ const fileNames = /* @__PURE__ */ new Set([
5348
+ "read",
5349
+ "write",
5350
+ "edit",
5351
+ "apply_patch",
5352
+ "glob",
5353
+ "grep",
5354
+ "read_image"
5355
+ ]);
5356
+ function groupOf(tool) {
5357
+ if ([
5358
+ "bash",
5359
+ "pwsh",
5360
+ "exec_command",
5361
+ "write_stdin"
5362
+ ].includes(tool.name) || tool.replacements.some((item) => item.action === "codex-exec")) return "command";
5363
+ if (["todo_write", "update_plan"].includes(tool.name) || tool.replacements.some((item) => item.action === "codex-plan")) return "plan";
5364
+ return fileNames.has(tool.name) ? "file" : "other";
5365
+ }
5366
+ const humanLabels = {
5367
+ pwsh: "toolLabelPwsh",
5368
+ bash: "toolLabelBash",
5369
+ exec_command: "toolLabelExec",
5370
+ write_stdin: "toolLabelStdin",
5371
+ todo_write: "toolLabelPlan",
5372
+ update_plan: "toolLabelPlan",
5373
+ read: "toolLabelRead",
5374
+ write: "toolLabelWrite",
5375
+ edit: "toolLabelEdit",
5376
+ apply_patch: "toolLabelPatch",
5377
+ glob: "toolLabelGlob",
5378
+ grep: "toolLabelGrep",
5379
+ read_image: "toolLabelImage"
5380
+ };
5381
+ const policyStyles = `
5382
+ .codex-tool-policy { min-width:0; font-size:14px; color:var(--dsw-alias-label-primary); }
5383
+ .codex-tool-policy p, .codex-tool-policy h3 { margin:0; }
5384
+ .codex-tool-policy h3 { font-size:14px; }
5385
+ .codex-tool-policy .codex-tool-policy-note, .codex-tool-policy code { color:var(--dsw-alias-label-secondary); font-size:12px; line-height:1.5; }
5386
+ .codex-tool-policy form, .codex-tool-policy fieldset { min-width:0; margin:0; padding:0; border:0; }
5387
+ .codex-tool-policy .codex-tool-policy-head { display:grid; gap:12px; margin-bottom:16px; }
5388
+ .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; }
5389
+ .codex-tool-policy .codex-tool-policy-field { display:grid; gap:8px; min-width:0; }
5390
+ .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; }
5391
+ .codex-tool-policy input[type=text], .codex-tool-policy select { width:100%; }
5392
+ .codex-tool-policy button { cursor:pointer; }
5393
+ .codex-tool-policy button:disabled { opacity:.5; cursor:default; }
5394
+ .codex-tool-policy :is(input,select,button,summary):focus-visible { outline:2px solid var(--dsw-alias-brand-primary); outline-offset:2px; }
5395
+ .codex-tool-policy .codex-tool-policy-table { max-height:360px; overflow:auto; }
5396
+ .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); }
5397
+ .codex-tool-policy .codex-tool-policy-name { min-width:0; display:grid; gap:4px; overflow-wrap:anywhere; }
5398
+ .codex-tool-policy .codex-tool-policy-identifier { font-size:14px; font-weight:600; color:var(--dsw-alias-label-primary); }
5399
+ .codex-tool-policy .codex-tool-policy-description { font-size:12px; line-height:1.5; color:var(--dsw-alias-label-secondary); }
5400
+ .codex-tool-policy .codex-tool-policy-action { min-width:0; display:flex; gap:8px; align-items:center; }
5401
+ .codex-tool-policy .codex-tool-policy-action select { min-width:0; flex:1; }
5402
+ .codex-tool-policy .codex-tool-policy-primary { background:var(--dsw-alias-label-primary); color:var(--dsw-alias-bg-base); }
5403
+ .codex-tool-policy details { border-top:1px solid var(--dsw-alias-border-l1); padding:12px 0; }
5404
+ .codex-tool-policy summary { cursor:pointer; }
5405
+ .codex-tool-policy summary .codex-tool-policy-note { margin-left:8px; }
5406
+ .codex-tool-policy .codex-tool-policy-actions { display:flex; gap:8px; align-items:center; flex-wrap:wrap; margin-top:16px; }
5407
+ .codex-tool-policy .codex-tool-policy-warning { color:var(--dsw-alias-state-warn-primary); font-size:12px; }
5408
+ .codex-tool-policy .codex-tool-policy-error { color:var(--dsw-alias-state-error-primary); font-size:12px; }
5409
+ .codex-tool-policy .codex-tool-policy-prompts { display:grid; gap:16px; }
5410
+ .codex-tool-policy .codex-tool-policy-prompt { display:grid; gap:8px; padding:12px 0; border-top:1px solid var(--dsw-alias-border-l1); }
5411
+ .codex-tool-policy .codex-tool-policy-prompt h4 { margin:0; font-size:14px; font-weight:600; }
5412
+ .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; }
5413
+ .codex-tool-policy textarea:focus-visible { outline:2px solid var(--dsw-alias-brand-primary); outline-offset:2px; }
5414
+ .codex-tool-policy .codex-tool-policy-prompt pre { margin:0; max-height:240px; overflow:auto; white-space:pre-wrap; overflow-wrap:anywhere; font:inherit; }
5415
+ @media (max-width:480px) { .codex-tool-policy .codex-tool-policy-tool { grid-template-columns:minmax(0,1fr); gap:8px; } }
5416
+ `;
5417
+ function ToolPolicySection({ binding, ...props }) {
5418
+ const form = (0, react.useSyncExternalStore)(binding.subscribe, binding.getSnapshot, binding.getSnapshot);
5419
+ return form === void 0 ? null : (0, react_jsx_runtime.jsx)(ToolPolicySettingsCard, {
5420
+ form,
5421
+ ...props
5422
+ });
5423
+ }
5424
+ function ToolPolicySettingsCard({ form, presetManager, mode = "tools", t }) {
5425
+ const snapshot = (0, react.useSyncExternalStore)((listener) => form.subscribe(listener), () => form.getSnapshot(), () => form.getSnapshot());
5426
+ const [drafts, setDrafts] = (0, react.useState)(() => /* @__PURE__ */ new Map());
5427
+ const [saving, setSaving] = (0, react.useState)(false);
5428
+ const [error, setError] = (0, react.useState)("");
5429
+ const [notice, setNotice] = (0, react.useState)("");
5430
+ const [selection, setSelection] = (0, react.useState)();
5431
+ const [query, setQuery] = (0, react.useState)("");
5432
+ const [filter, setFilter] = (0, react.useState)("all");
5433
+ const [groupOpen, setGroupOpen] = (0, react.useState)(() => /* @__PURE__ */ new Map());
5434
+ const [toolsView, setToolsView] = (0, react.useState)();
5435
+ const [promptsView, setPromptsView] = (0, react.useState)();
5436
+ const alive = (0, react.useRef)(true);
5437
+ const catalogRequest = (0, react.useRef)(0);
5438
+ const toolsRequest = (0, react.useRef)(0);
5439
+ const promptsRequest = (0, react.useRef)(0);
5440
+ const [catalog, setCatalog] = (0, react.useState)(() => presetManager === void 0 ? void 0 : cachedPresetCatalog(presetManager));
5441
+ const [catalogState, setCatalogState] = (0, react.useState)(() => catalog ? "ready" : presetManager ? "loading" : "error");
5442
+ function loadCatalog(refresh = false) {
5443
+ const ticket = ++catalogRequest.current;
5444
+ if (presetManager === void 0) {
5445
+ setCatalogState("error");
5446
+ return;
5447
+ }
5448
+ setCatalogState("loading");
5449
+ requestPresetCatalog(presetManager, refresh).then((value) => {
5450
+ if (alive.current && ticket === catalogRequest.current) {
5451
+ setCatalog(value);
5452
+ setCatalogState("ready");
5453
+ }
5454
+ }).catch(() => {
5455
+ if (alive.current && ticket === catalogRequest.current) setCatalogState("error");
5456
+ });
5457
+ }
5458
+ (0, react.useEffect)(() => {
5459
+ alive.current = true;
5460
+ loadCatalog();
5461
+ return () => {
5462
+ alive.current = false;
5463
+ catalogRequest.current++;
5464
+ toolsRequest.current++;
5465
+ promptsRequest.current++;
5466
+ };
5467
+ }, [presetManager]);
5468
+ const acceptedRules = snapshot.value?.rules ?? [];
5469
+ const ids = [.../* @__PURE__ */ new Set([
5470
+ ...catalog?.presets.map((preset) => preset.id) ?? [],
5471
+ ...acceptedRules.map((rule) => rule.preset),
5472
+ ...drafts.keys()
5473
+ ])].filter((id) => id.trim());
5474
+ const selectedId = selection ?? ids[0] ?? "";
5475
+ const currentDraft = drafts.get(selectedId);
5476
+ const currentRules = currentDraft?.rules ?? presetRules(acceptedRules, selectedId);
5477
+ const rule = currentRules[0];
5478
+ const duplicate = currentRules.length > 1;
5479
+ const presetLabel = catalog?.presets.find((preset) => preset.id === selectedId)?.name ?? selectedId;
5480
+ function loadTools(refresh = false) {
5481
+ const ticket = ++toolsRequest.current;
5482
+ if (!selectedId || presetManager === void 0) {
5483
+ setToolsView({
5484
+ preset: selectedId,
5485
+ status: "error"
5486
+ });
5487
+ return;
5488
+ }
5489
+ setToolsView({
5490
+ preset: selectedId,
5491
+ status: "loading"
5492
+ });
5493
+ requestPresetTools(presetManager, selectedId, refresh).then((value) => {
5494
+ if (alive.current && ticket === toolsRequest.current) setToolsView({
5495
+ preset: selectedId,
5496
+ status: "ready",
5497
+ value
5498
+ });
5499
+ }).catch(() => {
5500
+ if (alive.current && ticket === toolsRequest.current) setToolsView({
5501
+ preset: selectedId,
5502
+ status: "error"
5503
+ });
5504
+ });
5505
+ }
5506
+ (0, react.useEffect)(() => {
5507
+ loadTools();
5508
+ return () => {
5509
+ toolsRequest.current++;
5510
+ };
5511
+ }, [presetManager, selectedId]);
5512
+ const cached = presetManager && selectedId ? cachedPresetTools(presetManager, selectedId) : void 0;
5513
+ const inventory = toolsView?.preset === selectedId && toolsView.status === "error" ? void 0 : toolsView?.preset === selectedId && toolsView.status === "ready" ? toolsView.value : cached;
5514
+ const toolsStatus = inventory ? "ready" : toolsView?.preset === selectedId ? toolsView.status : selectedId ? "loading" : "error";
5515
+ function loadPrompts(refresh = false) {
5516
+ const ticket = ++promptsRequest.current;
5517
+ if (!selectedId || presetManager === void 0) {
5518
+ setPromptsView({
5519
+ preset: selectedId,
5520
+ status: "error"
5521
+ });
5522
+ return;
5523
+ }
5524
+ setPromptsView({
5525
+ preset: selectedId,
5526
+ status: "loading"
5527
+ });
5528
+ requestPresetPrompts(presetManager, selectedId, refresh).then((value) => {
5529
+ if (alive.current && ticket === promptsRequest.current) setPromptsView({
5530
+ preset: selectedId,
5531
+ status: "ready",
5532
+ value
5533
+ });
5534
+ }).catch(() => {
5535
+ if (alive.current && ticket === promptsRequest.current) setPromptsView({
5536
+ preset: selectedId,
5537
+ status: "error"
5538
+ });
5539
+ });
5540
+ }
5541
+ (0, react.useEffect)(() => {
5542
+ if (mode === "prompts") loadPrompts();
5543
+ return () => {
5544
+ promptsRequest.current++;
5545
+ };
5546
+ }, [
5547
+ presetManager,
5548
+ selectedId,
5549
+ mode === "prompts"
5550
+ ]);
5551
+ const cachedPrompts = presetManager && selectedId ? cachedPresetPrompts(presetManager, selectedId) : void 0;
5552
+ const promptCatalog = promptsView?.preset === selectedId && promptsView.status === "error" ? void 0 : promptsView?.preset === selectedId && promptsView.status === "ready" ? promptsView.value : cachedPrompts;
5553
+ const promptsStatus = promptCatalog ? "ready" : promptsView?.preset === selectedId ? promptsView.status : selectedId ? "loading" : "error";
5554
+ const contextFor = (tool) => ({
5555
+ ...inventory?.legacyCapabilities === void 0 ? {} : { legacyCapabilities: inventory.legacyCapabilities },
5556
+ ...tool.codexTool === void 0 ? {} : { codexTool: tool.codexTool }
5557
+ });
5558
+ const chosen = (tool) => effectiveToolAction(rule, tool.name, contextFor(tool));
5559
+ const customized = (tool) => chosen(tool) !== effectiveToolAction(void 0, tool.name, contextFor(tool)) || !!rule?.tools?.some((choice) => choice.name === tool.name);
5560
+ const inventoryNames = new Set(inventory?.tools.map((tool) => tool.name) ?? []);
5561
+ const stage = (change) => {
5562
+ if (snapshot.status !== "ready" || !snapshot.writable || saving) return;
5563
+ const latest = form.getSnapshot();
5564
+ setError("");
5565
+ setNotice("");
5566
+ setDrafts((previous) => editPresetDraft(previous, selectedId, {
5567
+ revision: latest.revision,
5568
+ rules: latest.value?.rules ?? []
5569
+ }, change));
5570
+ };
5571
+ const editRule = (change) => stage((previous) => {
5572
+ const next = change(previous[0] ?? {
5573
+ preset: selectedId,
5574
+ replaceShell: false,
5575
+ replacePlan: false
5576
+ });
5577
+ if (presetRules(currentDraft?.baseline ?? acceptedRules, selectedId).length === 0 && !next.tools?.length && !next.promptOverrides?.length && next.allow === void 0 && !next.deny?.length && next.replaceShell === false && next.replacePlan === false) return [];
5578
+ if (previous.length === 0) return [next];
5579
+ return previous.map((value, position) => position === 0 ? next : value);
5580
+ });
5581
+ const chooseAction = (tool, action) => {
5582
+ if (duplicate || !selectedId || action !== "keep" && action !== "hide" && action !== "codex-exec" && action !== "codex-plan") return;
5583
+ if (action !== "keep" && action !== "hide" && !tool.replacements.some((replacement) => replacement.action === action && replacement.available)) return;
5584
+ const context = contextFor(tool);
5585
+ if (rule === void 0 && action === legacyToolAction(void 0, tool.name, context)) return;
5586
+ editRule((value) => withToolAction(value, tool.name, action, context));
5587
+ };
5588
+ const removeChoice = (name) => editRule((value) => {
5589
+ const next = { ...value };
5590
+ const tools = (value.tools ?? []).filter((choice) => choice.name !== name);
5591
+ if (tools.length) next.tools = tools;
5592
+ else delete next.tools;
5593
+ return next;
5594
+ });
5595
+ const changePrompt = (section, text) => {
5596
+ if (duplicate || !section.editable || !isPromptName(section.name) || promptCatalog?.preset !== selectedId) return;
5597
+ const name = section.name;
5598
+ editRule((value) => ({
5599
+ ...value,
5600
+ promptOverrides: [...(value.promptOverrides ?? []).filter((entry) => entry.name !== name), {
5601
+ name,
5602
+ text
5603
+ }]
5604
+ }));
5605
+ };
5606
+ const restorePrompt = (section) => {
5607
+ if (duplicate || !section.editable || !isPromptName(section.name) || promptCatalog?.preset !== selectedId) return;
5608
+ editRule((value) => {
5609
+ const next = { ...value };
5610
+ const remaining = (value.promptOverrides ?? []).filter((entry) => entry.name !== section.name);
5611
+ if (remaining.length) next.promptOverrides = remaining;
5612
+ else delete next.promptOverrides;
5613
+ return next;
5614
+ });
5615
+ };
5616
+ const saveCurrent = () => {
5617
+ if (!currentDraft || saving || !snapshot.writable || snapshot.status !== "ready") return;
5618
+ const latest = form.getSnapshot();
5619
+ const target = selectedId;
5620
+ const targetName = presetLabel && presetLabel !== target ? `${presetLabel} (${target})` : target || t("toolPolicyInvalidEntry");
5621
+ const message = (key) => `${targetName}: ${t(key)}`;
5622
+ let prepared;
5623
+ try {
5624
+ prepared = preparePresetSave(currentDraft, {
5625
+ revision: latest.revision,
5626
+ rules: latest.value?.rules ?? []
5627
+ });
5628
+ const invalid = validateToolPolicyRules(currentDraft.rules);
5629
+ const otherIds = new Set((latest.value?.rules ?? []).filter((value) => value.preset !== selectedId).map((value) => value.preset.trim()));
5630
+ if (invalid || currentDraft.rules.some((value) => otherIds.has(value.preset.trim()))) {
5631
+ setError(message(invalid ?? "toolPolicyDuplicatePreset"));
5632
+ return;
5633
+ }
5634
+ } catch {
5635
+ setError(message("toolPolicyRefused"));
5636
+ return;
5637
+ }
5638
+ setSaving(true);
5639
+ setError("");
5640
+ setNotice("");
5641
+ saveToolPolicy(form, prepared.rules, prepared.revision).then((accepted) => {
5642
+ if (!alive.current) return;
5643
+ if (!accepted) {
5644
+ setError(message("toolPolicyRefused"));
5645
+ return;
5646
+ }
5647
+ const after = form.getSnapshot();
5648
+ setDrafts((previous) => acceptPresetSave(previous, prepared, {
5649
+ revision: after.revision,
5650
+ rules: after.value?.rules ?? []
5651
+ }));
5652
+ setNotice(message("toolPolicySaved"));
5653
+ }).catch(() => {
5654
+ if (alive.current) setError(message("toolPolicyFailed"));
5655
+ }).finally(() => {
5656
+ if (alive.current) setSaving(false);
5657
+ });
5658
+ };
5659
+ const human = (tool) => {
5660
+ const key = humanLabels[tool.name];
5661
+ return key ? t(key) : tool.description.split(/[\n。.!]/u)[0]?.trim().slice(0, 60) || t("toolLabelOther");
5662
+ };
5663
+ const beforeTarget = currentDraft ? presetRules(currentDraft.baseline, selectedId) : [];
5664
+ const beforeRule = beforeTarget[0];
5665
+ const choiceFor = (value, name) => value?.tools?.find((choice) => choice.name === name);
5666
+ const changedNames = currentDraft ? [.../* @__PURE__ */ new Set([...inventory?.tools.filter((tool) => effectiveToolAction(beforeRule, tool.name, contextFor(tool)) !== chosen(tool) || JSON.stringify(choiceFor(beforeRule, tool.name)) !== JSON.stringify(choiceFor(rule, tool.name))).map((tool) => tool.name) ?? [], ...[...beforeRule?.tools ?? [], ...rule?.tools ?? []].filter((choice) => !inventoryNames.has(choice.name) && JSON.stringify(choiceFor(beforeRule, choice.name)) !== JSON.stringify(choiceFor(rule, choice.name))).map((choice) => choice.name)])] : [];
5667
+ const changedPrompts = currentDraft ? [...new Set([...beforeRule?.promptOverrides ?? [], ...rule?.promptOverrides ?? []].map((entry) => entry.name))].filter((name) => JSON.stringify(beforeRule?.promptOverrides?.find((entry) => entry.name === name)) !== JSON.stringify(rule?.promptOverrides?.find((entry) => entry.name === name))) : [];
5668
+ const changeSummary = [...changedNames.length ? [`${t("presetSummaryTools")}: ${changedNames.slice(0, 4).join(", ")}${changedNames.length > 4 ? ` (+${changedNames.length - 4})` : ""}`] : [], ...changedPrompts.length ? [`${t("presetSummaryPrompts")}: ${changedPrompts.map((name) => promptCatalog?.sections.find((section) => section.name === name)?.label || name).join(", ")}`] : []].join(" · ") || t(currentDraft && !sameRules(beforeTarget, currentDraft.rules) ? "toolPolicyRuleChanged" : "toolPolicyNoToolDelta");
5669
+ const unavailable = (reason) => t(reason === "conditional" ? "toolPolicyConditional" : reason === "target-exists" ? "toolPolicyTargetExists" : "toolPolicyUnsupported");
5670
+ const rows = (tools) => (0, react_jsx_runtime.jsxs)("div", {
5671
+ className: "codex-tool-policy-table",
5672
+ role: "table",
5673
+ "aria-label": t("toolPolicyTitle"),
5674
+ children: [tools.map((tool) => {
5675
+ const action = chosen(tool);
5676
+ const supported = action === "keep" || action === "hide" || tool.replacements.some((option) => option.action === action);
5677
+ return (0, react_jsx_runtime.jsxs)("div", {
5678
+ role: "row",
5679
+ className: "codex-tool-policy-tool",
5680
+ "data-tool-name": tool.name,
5681
+ children: [(0, react_jsx_runtime.jsxs)("div", {
5682
+ role: "cell",
5683
+ className: "codex-tool-policy-name",
5684
+ children: [
5685
+ (0, react_jsx_runtime.jsx)("code", {
5686
+ className: "codex-tool-policy-identifier",
5687
+ children: tool.name
5688
+ }),
5689
+ (0, react_jsx_runtime.jsx)("span", {
5690
+ className: "codex-tool-policy-description",
5691
+ title: tool.description,
5692
+ children: human(tool)
5693
+ }),
5694
+ tool.codexTool?.presetEnabled === false && (0, react_jsx_runtime.jsx)("span", {
5695
+ className: "codex-tool-policy-note",
5696
+ children: t("toolPolicyPresetDisabled")
5697
+ }),
5698
+ tool.conditional && (0, react_jsx_runtime.jsx)("span", {
5699
+ className: "codex-tool-policy-note",
5700
+ children: t("toolPolicyConditional")
5701
+ })
5702
+ ]
5703
+ }), (0, react_jsx_runtime.jsxs)("div", {
5704
+ role: "cell",
5705
+ className: "codex-tool-policy-action",
5706
+ children: [(0, react_jsx_runtime.jsxs)("select", {
5707
+ "aria-label": `${t("toolPolicyAction")} ${tool.name}`,
5708
+ value: action,
5709
+ disabled: duplicate,
5710
+ onChange: (event) => chooseAction(tool, event.target.value),
5711
+ children: [
5712
+ (0, react_jsx_runtime.jsx)("option", {
5713
+ value: "keep",
5714
+ children: t("toolPolicyKeep")
5715
+ }),
5716
+ (0, react_jsx_runtime.jsx)("option", {
5717
+ value: "hide",
5718
+ children: t("toolPolicyHide")
5719
+ }),
5720
+ tool.replacements.map((option) => (0, react_jsx_runtime.jsxs)("option", {
5721
+ value: option.action,
5722
+ disabled: !option.available,
5723
+ title: !option.available ? unavailable(option.reason) : void 0,
5724
+ children: [option.tools.join(" + "), option.available ? "" : ` · ${unavailable(option.reason)}`]
5725
+ }, option.action)),
5726
+ !supported && (0, react_jsx_runtime.jsxs)("option", {
5727
+ value: action,
5728
+ disabled: true,
5729
+ children: [
5730
+ t("toolPolicyUnsupported"),
5731
+ " (",
5732
+ action,
5733
+ ")"
5734
+ ]
5735
+ })
5736
+ ]
5737
+ }), rule?.tools?.some((choice) => choice.name === tool.name) && (0, react_jsx_runtime.jsx)("button", {
5738
+ type: "button",
5739
+ "aria-label": `${t("toolPolicyRestoreChoice")} ${tool.name}`,
5740
+ title: t("toolPolicyRestoreChoice"),
5741
+ onClick: () => removeChoice(tool.name),
5742
+ children: "↶"
5743
+ })]
5744
+ })]
5745
+ }, tool.name);
5746
+ }), tools.length === 0 && (0, react_jsx_runtime.jsx)("p", {
5747
+ className: "codex-tool-policy-note",
5748
+ children: t("toolPolicyNoMatches")
5749
+ })]
5750
+ });
5751
+ if (snapshot.status !== "ready" || snapshot.value === void 0 || mode === "inactive") return null;
5752
+ if (mode === "definition") return !selectedId || presetManager === void 0 ? (0, react_jsx_runtime.jsx)("p", { children: t("settingsDefinitionAbsent") }) : (0, react_jsx_runtime.jsx)(PresetDefinitionCard, {
5753
+ presetManager,
5754
+ id: selectedId,
5755
+ t
5756
+ });
5757
+ const isDetails = mode === "details";
5758
+ const text = query.trim().toLowerCase();
5759
+ const shown = (inventory?.tools ?? []).filter((tool) => (!text || `${human(tool)} ${tool.name} ${tool.description}`.toLowerCase().includes(text)) && (filter !== "modified" || customized(tool)) && (filter !== "replaceable" || tool.replacements.some((replacement) => replacement.available)));
5760
+ return (0, react_jsx_runtime.jsxs)("section", {
5761
+ className: "codex-tool-policy",
5762
+ "aria-label": t(mode === "prompts" ? "settingsPresetPrompts" : "toolPolicyTitle"),
5763
+ children: [
5764
+ (0, react_jsx_runtime.jsx)("style", { children: policyStyles }),
5765
+ (0, react_jsx_runtime.jsxs)("div", {
5766
+ className: "codex-tool-policy-head",
5767
+ children: [
5768
+ mode === "prompts" && (0, react_jsx_runtime.jsxs)("h3", { children: [presetLabel || t("toolPolicyInvalidEntry"), (0, react_jsx_runtime.jsxs)("span", {
5769
+ className: "codex-tool-policy-note",
5770
+ children: [" · ", t("settingsPresetPrompts")]
5771
+ })] }),
5772
+ mode === "tools" || mode === "prompts" ? (0, react_jsx_runtime.jsxs)("div", {
5773
+ className: "codex-tool-policy-picker",
5774
+ children: [(0, react_jsx_runtime.jsxs)("label", {
5775
+ className: "codex-tool-policy-field",
5776
+ children: [(0, react_jsx_runtime.jsx)("span", { children: t("toolPolicyPresetChoice") }), (0, react_jsx_runtime.jsxs)("select", {
5777
+ "aria-label": t("toolPolicyPresetChoice"),
5778
+ value: selectedId,
5779
+ onChange: (event) => {
5780
+ setSelection(event.target.value);
5781
+ setError("");
5782
+ setNotice("");
5783
+ },
5784
+ children: [!ids.length && (0, react_jsx_runtime.jsx)("option", {
5785
+ value: "",
5786
+ children: t("toolPolicyEmpty")
5787
+ }), ids.map((id) => (0, react_jsx_runtime.jsxs)("option", {
5788
+ value: id,
5789
+ "data-preset-id": id,
5790
+ children: [catalog?.presets.find((preset) => preset.id === id)?.name ?? id, drafts.has(id) ? ` · ${t("globalPending")}` : ""]
5791
+ }, id))]
5792
+ })]
5793
+ }), presetManager && (0, react_jsx_runtime.jsx)("button", {
5794
+ type: "button",
5795
+ disabled: catalogState === "loading",
5796
+ onClick: () => loadCatalog(true),
5797
+ children: t("toolPolicyCatalogRetry")
5798
+ })]
5799
+ }) : (0, react_jsx_runtime.jsxs)("h3", { children: [
5800
+ presetLabel || t("toolPolicyInvalidEntry"),
5801
+ " ",
5802
+ (0, react_jsx_runtime.jsx)("code", { children: selectedId })
5803
+ ] }),
5804
+ (mode === "tools" || mode === "prompts") && (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [catalogState !== "ready" && (0, react_jsx_runtime.jsx)("p", {
5805
+ className: "codex-tool-policy-note",
5806
+ role: "status",
5807
+ children: t(catalogState === "loading" ? "toolPolicyCatalogLoading" : "toolPolicyCatalogFailed")
5808
+ }), catalogState === "ready" && !ids.length && (0, react_jsx_runtime.jsx)("p", {
5809
+ className: "codex-tool-policy-note",
5810
+ children: t("toolPolicyCatalogEmpty")
5811
+ })] }),
5812
+ isDetails && (0, react_jsx_runtime.jsxs)("div", {
5813
+ className: "codex-tool-policy-filters",
5814
+ children: [(0, react_jsx_runtime.jsx)("input", {
5815
+ type: "text",
5816
+ "aria-label": t("toolPolicySearch"),
5817
+ placeholder: t("toolPolicySearch"),
5818
+ value: query,
5819
+ onChange: (event) => setQuery(event.target.value)
5820
+ }), (0, react_jsx_runtime.jsxs)("select", {
5821
+ "aria-label": t("toolPolicyFilter"),
5822
+ value: filter,
5823
+ onChange: (event) => setFilter(event.target.value),
5824
+ children: [
5825
+ (0, react_jsx_runtime.jsx)("option", {
5826
+ value: "all",
5827
+ children: t("toolPolicyAll")
5828
+ }),
5829
+ (0, react_jsx_runtime.jsx)("option", {
5830
+ value: "modified",
5831
+ children: t("toolPolicyModified")
5832
+ }),
5833
+ (0, react_jsx_runtime.jsx)("option", {
5834
+ value: "replaceable",
5835
+ children: t("toolPolicyReplaceable")
5836
+ })
5837
+ ]
5838
+ })]
5839
+ }),
5840
+ mode !== "prompts" && toolsStatus !== "ready" && (0, react_jsx_runtime.jsx)("p", {
5841
+ className: "codex-tool-policy-note",
5842
+ role: "status",
5843
+ children: t(toolsStatus === "loading" ? "toolPolicyToolsLoading" : "toolPolicyToolsFailed")
5844
+ }),
5845
+ mode !== "prompts" && inventory?.tools.length === 0 && (0, react_jsx_runtime.jsx)("p", {
5846
+ className: "codex-tool-policy-note",
5847
+ role: "status",
5848
+ children: t("toolPolicyToolsEmpty")
5849
+ }),
5850
+ mode === "prompts" && (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
5851
+ presetManager && selectedId && (0, react_jsx_runtime.jsx)("button", {
5852
+ type: "button",
5853
+ disabled: promptsStatus === "loading",
5854
+ onClick: () => loadPrompts(true),
5855
+ children: t("presetPromptsReload")
5856
+ }),
5857
+ promptsStatus !== "ready" && (0, react_jsx_runtime.jsx)("p", {
5858
+ className: "codex-tool-policy-note",
5859
+ role: "status",
5860
+ children: t(promptsStatus === "loading" ? "presetPromptsLoading" : "presetPromptsFailed")
5861
+ }),
5862
+ promptCatalog?.sections.length === 0 && (0, react_jsx_runtime.jsx)("p", {
5863
+ className: "codex-tool-policy-note",
5864
+ children: t("presetPromptsEmpty")
5865
+ })
5866
+ ] }),
5867
+ isDetails && presetManager && selectedId && (0, react_jsx_runtime.jsx)("button", {
5868
+ type: "button",
5869
+ disabled: toolsStatus === "loading",
5870
+ onClick: () => loadTools(true),
5871
+ children: t("toolPolicyToolsRefresh")
5872
+ }),
5873
+ duplicate && (0, react_jsx_runtime.jsx)("p", {
5874
+ className: "codex-tool-policy-warning",
5875
+ children: t("toolPolicyDuplicatePreset")
5876
+ })
5877
+ ]
5878
+ }),
5879
+ (0, react_jsx_runtime.jsx)("form", {
5880
+ onSubmit: (event) => {
5881
+ event.preventDefault();
5882
+ saveCurrent();
5883
+ },
5884
+ children: (0, react_jsx_runtime.jsxs)("fieldset", {
5885
+ disabled: !snapshot.writable || saving,
5886
+ children: [
5887
+ mode === "tools" && inventory && !duplicate && [
5888
+ "command",
5889
+ "plan",
5890
+ "file",
5891
+ "other"
5892
+ ].map((group) => {
5893
+ const tools = inventory.tools.filter((tool) => groupOf(tool) === group);
5894
+ if (!tools.length) return null;
5895
+ const changes = tools.filter(customized).length;
5896
+ const key = `${selectedId}/${group}`;
5897
+ return (0, react_jsx_runtime.jsxs)("details", {
5898
+ "data-tool-group": group,
5899
+ open: groupOpen.get(key) ?? (group === "command" || group === "plan" || changes > 0),
5900
+ onToggle: (event) => {
5901
+ const open = event.currentTarget.open;
5902
+ setGroupOpen((previous) => new Map(previous).set(key, open));
5903
+ },
5904
+ children: [(0, react_jsx_runtime.jsxs)("summary", { children: [t(group === "command" ? "toolPolicyCommandGroup" : group === "plan" ? "toolPolicyPlanGroup" : group === "file" ? "toolPolicyFileGroup" : "toolPolicyOtherGroup"), (0, react_jsx_runtime.jsxs)("span", {
5905
+ className: "codex-tool-policy-note",
5906
+ children: [tools.length, changes ? ` · ${changes} ${t("toolPolicyCustomized")}` : ""]
5907
+ })] }), rows(tools)]
5908
+ }, group);
5909
+ }),
5910
+ isDetails && inventory && !duplicate && rows(shown),
5911
+ mode === "prompts" && promptCatalog && (0, react_jsx_runtime.jsx)("div", {
5912
+ className: "codex-tool-policy-prompts",
5913
+ children: promptCatalog.sections.map((section) => {
5914
+ const editable = section.editable && isPromptName(section.name);
5915
+ const override = rule?.promptOverrides?.find((entry) => entry.name === section.name);
5916
+ return (0, react_jsx_runtime.jsxs)("section", {
5917
+ className: "codex-tool-policy-prompt",
5918
+ "data-prompt-section": section.name,
5919
+ children: [
5920
+ (0, react_jsx_runtime.jsx)("h4", { children: section.label || section.name }),
5921
+ (0, react_jsx_runtime.jsx)("code", { children: section.name }),
5922
+ editable ? (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [(0, react_jsx_runtime.jsx)("textarea", {
5923
+ "aria-label": `${t("settingsPresetPrompts")} ${section.name}`,
5924
+ rows: 6,
5925
+ maxLength: 1e6,
5926
+ disabled: duplicate || !snapshot.writable || saving,
5927
+ value: override?.text ?? section.text,
5928
+ onChange: (event) => changePrompt(section, event.target.value)
5929
+ }), (0, react_jsx_runtime.jsx)("button", {
5930
+ type: "button",
5931
+ "aria-label": `${t("presetPromptRestore")} ${section.name}`,
5932
+ disabled: !override || duplicate || !snapshot.writable || saving,
5933
+ onClick: () => restorePrompt(section),
5934
+ children: t("presetPromptRestore")
5935
+ })] }) : (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [(0, react_jsx_runtime.jsx)("span", {
5936
+ className: "codex-tool-policy-note",
5937
+ title: section.reason,
5938
+ children: t("presetPromptReadOnly")
5939
+ }), (0, react_jsx_runtime.jsx)("pre", { children: section.text })] })
5940
+ ]
5941
+ }, section.name);
5942
+ })
5943
+ }),
5944
+ currentDraft && (0, react_jsx_runtime.jsxs)("p", {
5945
+ className: "codex-tool-policy-note",
5946
+ "aria-label": t("toolPolicyDraftSummary"),
5947
+ children: [
5948
+ t("toolPolicyDraftSummary"),
5949
+ ": ",
5950
+ changeSummary
5951
+ ]
5952
+ }),
5953
+ (0, react_jsx_runtime.jsxs)("div", {
5954
+ className: "codex-tool-policy-actions",
5955
+ children: [
5956
+ (0, react_jsx_runtime.jsx)("button", {
5957
+ className: "codex-tool-policy-primary",
5958
+ type: "submit",
5959
+ disabled: !currentDraft,
5960
+ children: t(saving ? "toolPolicySaving" : "toolPolicySave")
5961
+ }),
5962
+ (0, react_jsx_runtime.jsx)("button", {
5963
+ type: "button",
5964
+ disabled: !currentDraft,
5965
+ onClick: () => {
5966
+ setDrafts((previous) => {
5967
+ const next = new Map(previous);
5968
+ next.delete(selectedId);
5969
+ return next;
5970
+ });
5971
+ setError("");
5972
+ setNotice("");
5973
+ },
5974
+ children: t("toolPolicyDiscard")
5975
+ }),
5976
+ (0, react_jsx_runtime.jsx)("span", {
5977
+ className: "codex-tool-policy-note",
5978
+ children: t("toolPolicyTiming")
5979
+ })
5980
+ ]
5981
+ })
5982
+ ]
5983
+ })
5984
+ }),
5985
+ !snapshot.writable && (0, react_jsx_runtime.jsx)("p", {
5986
+ className: "codex-tool-policy-note",
5987
+ children: t("toolPolicyReadOnly")
5988
+ }),
5989
+ error && (0, react_jsx_runtime.jsx)("p", {
5990
+ className: "codex-tool-policy-error",
5991
+ role: "alert",
5992
+ children: error
5993
+ }),
5994
+ notice && (0, react_jsx_runtime.jsx)("p", {
5995
+ className: "codex-tool-policy-note",
5996
+ role: "status",
5997
+ children: notice
5998
+ })
5999
+ ]
6000
+ });
6001
+ }
6002
+ //#endregion
4732
6003
  //#region lib/types/client/index.js
4733
6004
  /** Browser controls for Codex requests and the editable operating prompt. */
4734
6005
  const NS = "codex";
@@ -4739,7 +6010,9 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
4739
6010
  const DEFAULT_CONTEXT_WINDOW = 262144;
4740
6011
  const en = {
4741
6012
  ...presetEn,
6013
+ ...toolPolicyEn,
4742
6014
  fast: "Fast mode",
6015
+ fastModeControl: "Show fast mode control",
4743
6016
  fastOn: "Fast mode on (priority tier)",
4744
6017
  fastOff: "Fast mode off",
4745
6018
  fastStateOn: "On",
@@ -4768,23 +6041,8 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
4768
6041
  capabilityCompactionHint: "Prefer the provider Responses compact endpoint before local compaction.",
4769
6042
  capabilityActivity: "Activity indicator",
4770
6043
  capabilityActivityHint: "Show request, reply, and compaction status beside the conversation.",
4771
- promptCustomizationLabel: "Prompt customization",
4772
- personaLabel: "Persona",
4773
- personaHint: "Deployment identity and role. Supports {{model}} and {{cwd}}.",
4774
- sourcePromptLabel: "DSH Core source instructions",
4775
- sourcePromptHint: "Guidance about the DSH checkout and working directory. Supports {{sourceRoot}}.",
4776
- webPromptLabel: "DSH Core Web instructions",
4777
- webPromptHint: "Guidance about this Web GUI, HMR, builds, and verification. Supports {{webUrl}}.",
4778
- promptRestoreAll: "Restore all prompt defaults",
4779
- promptLabel: "Codex operating prompt",
4780
- promptHint: "This is the Codex operating prompt. Persona and DSH Core instructions are edited separately above.",
4781
- promptUnsaved: "Unsaved",
4782
6044
  promptDiscard: "Discard",
4783
- promptSave: "Save",
4784
6045
  promptSaving: "Saving...",
4785
- promptSaveFailed: "Could not save the prompt.",
4786
- promptExpand: "Expand settings",
4787
- promptCollapse: "Collapse settings",
4788
6046
  promptReadOnly: "This settings document is read-only.",
4789
6047
  activityCompacting: "Compacting context...",
4790
6048
  activityRequestingModel: "Requesting model...",
@@ -4792,6 +6050,8 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
4792
6050
  };
4793
6051
  const zh = {
4794
6052
  ...presetZh,
6053
+ ...toolPolicyZh,
6054
+ fastModeControl: "Show fast mode control",
4795
6055
  fast: "Fast",
4796
6056
  fastOn: "Fast mode on (priority tier)",
4797
6057
  fastOff: "Fast mode off",
@@ -4821,23 +6081,8 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
4821
6081
  capabilityCompactionHint: "优先调用提供商的 Responses compact 端点,失败时回退本地压缩。",
4822
6082
  capabilityActivity: "活动状态",
4823
6083
  capabilityActivityHint: "在对话旁显示请求、回复和压缩状态。",
4824
- promptCustomizationLabel: "提示词定制",
4825
- personaLabel: "Persona",
4826
- personaHint: "定义 Agent 的身份与角色,支持 {{model}} 和 {{cwd}}。",
4827
- sourcePromptLabel: "DSH Core 源码说明",
4828
- sourcePromptHint: "说明 DSH 源码检出目录与工作目录,支持 {{sourceRoot}}。",
4829
- webPromptLabel: "DSH Core Web 说明",
4830
- webPromptHint: "说明 Web GUI、HMR、构建与验证,支持 {{webUrl}}。",
4831
- promptRestoreAll: "恢复所有提示词默认值",
4832
- promptLabel: "Codex 操作提示词",
4833
- promptHint: "这是 Codex 操作提示词。Persona 和 DSH Core 说明在上方分别编辑。",
4834
- promptUnsaved: "未保存",
4835
6084
  promptDiscard: "放弃",
4836
- promptSave: "保存",
4837
6085
  promptSaving: "保存中...",
4838
- promptSaveFailed: "提示词保存失败。",
4839
- promptExpand: "展开设置",
4840
- promptCollapse: "收起设置",
4841
6086
  promptReadOnly: "当前设置文件为只读。",
4842
6087
  activityCompacting: "正在压缩上下文...",
4843
6088
  activityRequestingModel: "请求中...",
@@ -4867,7 +6112,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
4867
6112
  children: label
4868
6113
  }), (0, react_jsx_runtime.jsx)("span", {
4869
6114
  style: {
4870
- color: "var(--dsw-alias-label-tertiary)",
6115
+ color: "var(--dsw-alias-label-secondary)",
4871
6116
  fontSize: 12,
4872
6117
  lineHeight: 1.45
4873
6118
  },
@@ -4995,7 +6240,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
4995
6240
  },
4996
6241
  children: [(0, react_jsx_runtime.jsx)("span", { children: t("fast") }), (0, react_jsx_runtime.jsx)("span", {
4997
6242
  style: {
4998
- color: "var(--dsw-alias-label-tertiary)",
6243
+ color: "var(--dsw-alias-label-secondary)",
4999
6244
  fontSize: 11
5000
6245
  },
5001
6246
  children: fast ? t("fastStateOn") : t("fastStateOff")
@@ -5108,7 +6353,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
5108
6353
  })]
5109
6354
  }), (0, react_jsx_runtime.jsx)("span", {
5110
6355
  style: {
5111
- color: "var(--dsw-alias-label-tertiary)",
6356
+ color: "var(--dsw-alias-label-secondary)",
5112
6357
  fontSize: 11,
5113
6358
  lineHeight: "16px"
5114
6359
  },
@@ -5161,7 +6406,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
5161
6406
  }
5162
6407
  /** Keep context configuration reachable before the host has a pressure meter. */
5163
6408
  function ContextSizeFallback({ sessionId, useSessions, useProjection, useSettings, setSetting, unsetSetting, t }) {
5164
- const agentPreset = useSessions((state) => state.byId[sessionId]?.agentPreset);
6409
+ const agentPreset = useSessions((state) => agentPresetFromSession(state.byId[sessionId]));
5165
6410
  const hostMeter = useHostContextMeter();
5166
6411
  const contextWindow = contextWindowFromProjection(useProjection);
5167
6412
  const snapshot = useSettings((state) => state);
@@ -5316,7 +6561,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
5316
6561
  position: "fixed",
5317
6562
  left: position.left,
5318
6563
  top: position.top,
5319
- zIndex: 100,
6564
+ zIndex: 0,
5320
6565
  pointerEvents: "none"
5321
6566
  }
5322
6567
  },
@@ -5334,7 +6579,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
5334
6579
  }),
5335
6580
  (0, react_jsx_runtime.jsx)("span", { children: label }),
5336
6581
  (0, react_jsx_runtime.jsxs)("span", {
5337
- style: { color: "var(--dsw-alias-label-tertiary)" },
6582
+ style: { color: "var(--dsw-alias-label-secondary)" },
5338
6583
  children: [
5339
6584
  "·",
5340
6585
  " ",
@@ -5379,27 +6624,43 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
5379
6624
  setPosition(null);
5380
6625
  return;
5381
6626
  }
6627
+ let frame;
6628
+ let previous = null;
5382
6629
  const update = () => {
5383
- if (!target.isConnected) {
5384
- setPosition(null);
5385
- return;
5386
- }
6630
+ if (!target.isConnected) return;
5387
6631
  const rect = target.getBoundingClientRect();
5388
6632
  if (rect.width === 0 && rect.height === 0) {
5389
- setPosition(null);
6633
+ if (previous !== null) {
6634
+ previous = null;
6635
+ setPosition(null);
6636
+ }
5390
6637
  return;
5391
6638
  }
5392
- setPosition({
6639
+ const next = {
5393
6640
  left: Math.round(rect.right + 10),
5394
6641
  top: Math.round(rect.top + (rect.height - 26) / 2)
5395
- });
6642
+ };
6643
+ if (previous?.left === next.left && previous.top === next.top) return;
6644
+ previous = next;
6645
+ setPosition(next);
6646
+ };
6647
+ const track = () => {
6648
+ if (!target.isConnected) {
6649
+ previous = null;
6650
+ setPosition(null);
6651
+ return;
6652
+ }
6653
+ update();
6654
+ frame = window.requestAnimationFrame(track);
5396
6655
  };
5397
6656
  update();
6657
+ frame = window.requestAnimationFrame(track);
5398
6658
  window.addEventListener("resize", update);
5399
6659
  window.addEventListener("scroll", update, true);
5400
6660
  const observer = typeof ResizeObserver === "undefined" ? void 0 : new ResizeObserver(update);
5401
6661
  observer?.observe(target);
5402
6662
  return () => {
6663
+ if (frame !== void 0) window.cancelAnimationFrame(frame);
5403
6664
  window.removeEventListener("resize", update);
5404
6665
  window.removeEventListener("scroll", update, true);
5405
6666
  observer?.disconnect();
@@ -5457,16 +6718,6 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
5457
6718
  position: turnStatusPosition
5458
6719
  }), document.body, "codex-activity")] });
5459
6720
  }
5460
- const inject = [
5461
- "commandUi",
5462
- "sessions",
5463
- "slots",
5464
- "locale",
5465
- "settingsScope",
5466
- "remote",
5467
- "remote.agentPresets",
5468
- "remote.settings"
5469
- ];
5470
6721
  function createPresetManager(ctx) {
5471
6722
  const remote = ctx.remote;
5472
6723
  const ready = remote === void 0 ? Promise.resolve() : remote.$mount(preset_editor_remote_default).then((dispose) => {
@@ -5504,8 +6755,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
5504
6755
  })
5505
6756
  }, PromptSettingsCard));
5506
6757
  }
5507
- /** Mount request controls and the plugin settings card through shared slots. */
5508
- function apply(ctx) {
6758
+ function applyWithSettingsApi(ctx, api) {
5509
6759
  ctx.effect(() => ctx.locale.register(NS, {
5510
6760
  en,
5511
6761
  zh
@@ -5537,7 +6787,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
5537
6787
  }
5538
6788
  }
5539
6789
  }), "codex client: /compact mode picker");
5540
- const settings = ctx.settingsScope.bind({ namespace: SETTINGS_NAMESPACE });
6790
+ const settings = api.bind(ctx);
5541
6791
  const presetManager = createPresetManager(ctx);
5542
6792
  const injected = () => ({
5543
6793
  hooks: { settings },
@@ -5566,25 +6816,319 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
5566
6816
  locale: NS,
5567
6817
  inject: injected
5568
6818
  }, LegacyOverlay));
5569
- ctx.inject([
5570
- "remote",
5571
- "remote.agentPresets",
5572
- "remote.settings",
5573
- "remote.codexPresetEditor"
5574
- ], (settingsCtx) => registerPresetSettingsCard(settingsCtx, settings, presetManager));
5575
- }
5576
- var client_default = {
6819
+ ctx.inject(["remote", "remote.codexPresetEditor"], (settingsCtx) => api.register(settingsCtx, settings, presetManager));
6820
+ }
6821
+ function apply$2(ctx) {
6822
+ applyWithSettingsApi(ctx, {
6823
+ bind: (host) => host.settingsScope.bind({ namespace: SETTINGS_NAMESPACE }),
6824
+ register: registerPresetSettingsCard
6825
+ });
6826
+ }
6827
+ //#endregion
6828
+ //#region lib/types/client/desktop.js
6829
+ /** A single Settings workspace; the bundle page is only a signpost. */
6830
+ function adaptConfigForm(form) {
6831
+ const accepted = async (result) => {
6832
+ if (!await result) throw new Error("The host did not accept the settings change.");
6833
+ };
6834
+ return {
6835
+ getSnapshot: () => form.getSnapshot(),
6836
+ subscribe: (listener) => form.subscribe(listener),
6837
+ set: (field, value) => accepted(form.set(field, value)),
6838
+ unset: (field) => accepted(form.unset(field))
6839
+ };
6840
+ }
6841
+ async function saveDesktopSettings(form, edits, expectedRevision) {
6842
+ const ops = Object.entries(edits).map(([field, value]) => value === void 0 ? {
6843
+ op: "unset",
6844
+ path: [field]
6845
+ } : {
6846
+ op: "set",
6847
+ path: [field],
6848
+ value
6849
+ });
6850
+ if (!ops.length) return;
6851
+ if (!(expectedRevision === void 0 ? await form.mutate(ops) : await form.mutate(ops, expectedRevision))) throw new Error("The host did not accept the settings change.");
6852
+ }
6853
+ const desktopStyles = `
6854
+ .codex-harness-settings { min-width:0; font-size:14px; color:var(--dsw-alias-label-primary); }
6855
+ .codex-harness-settings h3 { font-size:14px; margin:0 0 12px; }
6856
+ .codex-harness-settings .codex-harness-nav { display:flex; align-items:center; gap:8px; flex-wrap:wrap; margin-bottom:16px; border-bottom:1px solid var(--dsw-alias-border-l1); padding-bottom:8px; }
6857
+ .codex-harness-settings button, .codex-harness-settings input[type=number], .codex-harness-settings textarea { box-sizing:border-box; min-width:0; max-width:100%; font:inherit; color:inherit; background:var(--dsw-alias-bg-layer-2); border:1px solid var(--dsw-alias-border-l2); border-radius:8px; padding:7px 12px; }
6858
+ .codex-harness-settings button { cursor:pointer; }
6859
+ .codex-harness-settings button:disabled { opacity:.5; cursor:default; }
6860
+ .codex-harness-settings .codex-harness-nav button { border:0; background:none; }
6861
+ .codex-harness-settings .codex-harness-nav button[aria-pressed=true] { background:var(--dsw-alias-label-primary); color:var(--dsw-alias-bg-base); }
6862
+ .codex-harness-settings .codex-harness-quiet { color:var(--dsw-alias-label-secondary); background:none; border:0; }
6863
+ .codex-harness-settings .codex-harness-advanced-link { margin-left:auto; }
6864
+ .codex-harness-settings :is(input,textarea,button,summary):focus-visible { outline:2px solid var(--dsw-alias-brand-primary); outline-offset:2px; }
6865
+ .codex-harness-settings fieldset { min-width:0; border:0; padding:0; margin:0; }
6866
+ .codex-harness-settings .codex-harness-grid { display:grid; grid-template-columns:repeat(auto-fit,minmax(min(100%,220px),1fr)); gap:16px; }
6867
+ .codex-harness-settings .codex-harness-group h4 { margin:0 0 8px; font-size:12px; font-weight:500; color:var(--dsw-alias-label-secondary); }
6868
+ .codex-harness-settings .codex-harness-setting-row { min-width:0; display:flex; gap:12px; justify-content:space-between; align-items:center; padding:8px 0; }
6869
+ .codex-harness-settings input[type=number] { width:140px; }
6870
+ .codex-harness-settings textarea { display:block; width:100%; margin-top:8px; resize:vertical; }
6871
+ .codex-harness-settings .codex-harness-note { margin:0 0 16px; color:var(--dsw-alias-label-secondary); font-size:12px; line-height:1.5; }
6872
+ .codex-harness-settings .codex-harness-actions { display:flex; gap:8px; flex-wrap:wrap; margin-top:16px; }
6873
+ .codex-harness-settings .codex-harness-primary { background:var(--dsw-alias-label-primary); color:var(--dsw-alias-bg-base); }
6874
+ .codex-harness-settings input[role=switch] { appearance:none; width:32px; height:20px; border:1px solid var(--dsw-alias-border-l2); border-radius:16px; background:var(--dsw-alias-bg-layer-2); position:relative; cursor:pointer; flex-shrink:0; margin:0; }
6875
+ .codex-harness-settings input[role=switch]:before { content:''; position:absolute; width:12px; height:12px; top:3px; left:3px; border-radius:50%; background:var(--dsw-alias-label-secondary); }
6876
+ .codex-harness-settings input[role=switch]:checked { background:var(--dsw-alias-label-primary); }
6877
+ .codex-harness-settings input[role=switch]:checked:before { left:15px; background:var(--dsw-alias-bg-base); }
6878
+ `;
6879
+ /** There is intentionally no second editable form on a bundle detail page. */
6880
+ function DesktopSettingsCard({ t }) {
6881
+ return (0, react_jsx_runtime.jsxs)("section", { children: [(0, react_jsx_runtime.jsx)("p", { children: t("settingsBundleSummary") }), (0, react_jsx_runtime.jsx)("p", { children: t("settingsBundlePath") })] });
6882
+ }
6883
+ /** Kept mounted while inactive, so switching pages preserves runtime drafts. */
6884
+ function RuntimeSettingsEditor({ active, ...props }) {
6885
+ const { useSettings, saveSettings, t } = props;
6886
+ const snapshot = useSettings((state) => state);
6887
+ const [draft, setDraft] = (0, react.useState)();
6888
+ const [saving, setSaving] = (0, react.useState)(false);
6889
+ const [error, setError] = (0, react.useState)("");
6890
+ const edits = draft?.edits ?? {};
6891
+ const value = (field) => Object.hasOwn(edits, field) ? edits[field] === void 0 ? snapshot.base?.[field] : edits[field] : snapshot.value?.[field];
6892
+ const edit = (field, next) => {
6893
+ setError("");
6894
+ setDraft((current) => ({
6895
+ edits: {
6896
+ ...current?.edits,
6897
+ [field]: next
6898
+ },
6899
+ revision: current === void 0 ? snapshot.revision : current.revision
6900
+ }));
6901
+ };
6902
+ const groups = [{
6903
+ label: "globalGroupRequest",
6904
+ fields: [
6905
+ ["fast", "fast"],
6906
+ ["hostedWebSearchEnabled", "settingsPreferHostedSearch"],
6907
+ ["remoteCompactionEnabled", "settingsPreferRemoteCompaction"]
6908
+ ]
6909
+ }, {
6910
+ label: "globalGroupDisplay",
6911
+ fields: [["fastModeControlEnabled", "fastModeControl"], ["activityIndicatorEnabled", "capabilityActivity"]]
6912
+ }];
6913
+ if (!active) return null;
6914
+ return (0, react_jsx_runtime.jsxs)("section", {
6915
+ "aria-label": t("settingsRuntimePage"),
6916
+ children: [
6917
+ (0, react_jsx_runtime.jsxs)("h3", { children: [t("settingsRuntimePage"), (0, react_jsx_runtime.jsxs)("span", {
6918
+ className: "codex-harness-note",
6919
+ children: [" · ", t("settingsRuntimeScope")]
6920
+ })] }),
6921
+ (0, react_jsx_runtime.jsx)("form", {
6922
+ onSubmit: (event) => {
6923
+ event.preventDefault();
6924
+ if (saving || draft === void 0 || !snapshot.writable || snapshot.status !== "ready") return;
6925
+ setSaving(true);
6926
+ setError("");
6927
+ const submitted = draft;
6928
+ saveSettings(submitted.edits, submitted.revision).then(() => setDraft((current) => current === submitted ? void 0 : current)).catch(() => setError(t("settingsSharedFailed"))).finally(() => setSaving(false));
6929
+ },
6930
+ children: (0, react_jsx_runtime.jsxs)("fieldset", {
6931
+ disabled: !snapshot.writable || snapshot.status !== "ready" || saving,
6932
+ children: [
6933
+ (0, react_jsx_runtime.jsx)("div", {
6934
+ className: "codex-harness-grid",
6935
+ children: groups.map((group) => (0, react_jsx_runtime.jsxs)("div", {
6936
+ className: "codex-harness-group",
6937
+ children: [(0, react_jsx_runtime.jsx)("h4", { children: t(group.label) }), group.fields.map(([field, label]) => (0, react_jsx_runtime.jsxs)("label", {
6938
+ className: "codex-harness-setting-row",
6939
+ children: [(0, react_jsx_runtime.jsx)("span", { children: t(label) }), (0, react_jsx_runtime.jsx)("input", {
6940
+ type: "checkbox",
6941
+ role: "switch",
6942
+ "aria-label": t(label),
6943
+ "aria-checked": Boolean(value(field) ?? field !== "fast"),
6944
+ checked: Boolean(value(field) ?? field !== "fast"),
6945
+ onChange: (event) => edit(field, event.target.checked)
6946
+ })]
6947
+ }, field))]
6948
+ }, group.label))
6949
+ }),
6950
+ (0, react_jsx_runtime.jsxs)("label", {
6951
+ className: "codex-harness-setting-row",
6952
+ children: [
6953
+ t("contextSize"),
6954
+ " (tokens)",
6955
+ (0, react_jsx_runtime.jsx)("input", {
6956
+ type: "number",
6957
+ min: 1,
6958
+ max: CODEX_CONTEXT_MAX,
6959
+ step: 1,
6960
+ value: String(value("contextWindow") ?? ""),
6961
+ onChange: (event) => edit("contextWindow", event.target.value === "" ? void 0 : Number(event.target.value))
6962
+ })
6963
+ ]
6964
+ }),
6965
+ (0, react_jsx_runtime.jsxs)("div", {
6966
+ className: "codex-harness-actions",
6967
+ children: [(0, react_jsx_runtime.jsx)("button", {
6968
+ className: "codex-harness-primary",
6969
+ type: "submit",
6970
+ disabled: !Object.keys(edits).length,
6971
+ children: t(saving ? "promptSaving" : "settingsSaveRuntime")
6972
+ }), (0, react_jsx_runtime.jsx)("button", {
6973
+ type: "button",
6974
+ disabled: draft === void 0,
6975
+ onClick: () => {
6976
+ setDraft(void 0);
6977
+ setError("");
6978
+ },
6979
+ children: t("promptDiscard")
6980
+ })]
6981
+ })
6982
+ ]
6983
+ })
6984
+ }),
6985
+ !snapshot.writable && (0, react_jsx_runtime.jsx)("p", {
6986
+ className: "codex-harness-note",
6987
+ children: t("promptReadOnly")
6988
+ }),
6989
+ error && (0, react_jsx_runtime.jsx)("p", {
6990
+ role: "alert",
6991
+ children: error
6992
+ })
6993
+ ]
6994
+ });
6995
+ }
6996
+ function CodexSettingsTab(props) {
6997
+ const { toolPolicy, presetManager, t } = props;
6998
+ const [page, setPage] = (0, react.useState)(props.initialPage ?? "tools");
6999
+ const [advanced, setAdvanced] = (0, react.useState)("details");
7000
+ const mode = page === "tools" ? "tools" : page === "advanced" ? advanced : "inactive";
7001
+ return (0, react_jsx_runtime.jsxs)("section", {
7002
+ className: "codex-harness-settings",
7003
+ children: [
7004
+ (0, react_jsx_runtime.jsx)("style", { children: desktopStyles }),
7005
+ (0, react_jsx_runtime.jsxs)("nav", {
7006
+ className: "codex-harness-nav",
7007
+ "aria-label": t("settingsTabLabel"),
7008
+ children: [(0, react_jsx_runtime.jsxs)("div", { children: [(0, react_jsx_runtime.jsx)("button", {
7009
+ type: "button",
7010
+ "aria-pressed": page === "tools",
7011
+ onClick: () => setPage("tools"),
7012
+ children: t("settingsToolsPage")
7013
+ }), (0, react_jsx_runtime.jsx)("button", {
7014
+ type: "button",
7015
+ "aria-pressed": page === "runtime",
7016
+ onClick: () => setPage("runtime"),
7017
+ children: t("settingsRuntimePage")
7018
+ })] }), (0, react_jsx_runtime.jsx)("button", {
7019
+ className: "codex-harness-quiet codex-harness-advanced-link",
7020
+ type: "button",
7021
+ onClick: () => setPage("advanced"),
7022
+ children: t("settingsAdvanced")
7023
+ })]
7024
+ }),
7025
+ page === "advanced" && (0, react_jsx_runtime.jsx)("nav", {
7026
+ className: "codex-harness-nav",
7027
+ "aria-label": t("settingsAdvanced"),
7028
+ children: [
7029
+ "details",
7030
+ "prompts",
7031
+ "definition"
7032
+ ].map((section) => (0, react_jsx_runtime.jsx)("button", {
7033
+ type: "button",
7034
+ "aria-pressed": advanced === section,
7035
+ onClick: () => setAdvanced(section),
7036
+ children: t(section === "details" ? "settingsAdvancedTools" : section === "prompts" ? "settingsPresetPrompts" : "settingsDefinition")
7037
+ }, section))
7038
+ }),
7039
+ toolPolicy !== void 0 && (0, react_jsx_runtime.jsx)(ToolPolicySection, {
7040
+ binding: toolPolicy,
7041
+ presetManager,
7042
+ mode,
7043
+ t
7044
+ }),
7045
+ (0, react_jsx_runtime.jsx)(RuntimeSettingsEditor, {
7046
+ ...props,
7047
+ active: page === "runtime"
7048
+ })
7049
+ ]
7050
+ });
7051
+ }
7052
+ function apply$1(ctx) {
7053
+ let form;
7054
+ applyWithSettingsApi(ctx, {
7055
+ bind: (host) => {
7056
+ form = host.configForms.get("codex");
7057
+ return adaptConfigForm(form);
7058
+ },
7059
+ register: (host, settings, manager) => {
7060
+ const desktop = host;
7061
+ const presetManager = {
7062
+ ...manager,
7063
+ remote: host.remote
7064
+ };
7065
+ const t = host.locale.bind("codex");
7066
+ const toolPolicy = bindToolPolicy(host, host.configForms);
7067
+ const injected = () => ({
7068
+ hooks: { settings },
7069
+ setSetting: (field, value) => settings.set(field, value),
7070
+ unsetSetting: (field) => settings.unset(field),
7071
+ presetManager,
7072
+ toolPolicy,
7073
+ saveSettings: (edits, revision) => saveDesktopSettings(form, edits, revision)
7074
+ });
7075
+ return desktop.configForms.whileServed(["codex"], () => {
7076
+ const disposers = [];
7077
+ const dispose = () => {
7078
+ for (const off of disposers.splice(0).reverse()) off();
7079
+ };
7080
+ try {
7081
+ disposers.push(host.slots.inject("settings.plugins.tab", () => host.slots.register({
7082
+ name: "settings.plugins.tab",
7083
+ id: "codex-harness",
7084
+ order: 30,
7085
+ label: () => t("settingsTabLabel"),
7086
+ locale: "codex",
7087
+ inject: injected
7088
+ }, CodexSettingsTab)));
7089
+ disposers.push(host.slots.inject("plugins.item", () => host.slots.spec?.("plugins.bundle.config") !== void 0 ? host.slots.register({
7090
+ name: "plugins.bundle.config",
7091
+ key: "@shuind/dsh-codex-harness",
7092
+ locale: "codex",
7093
+ inject: injected
7094
+ }, DesktopSettingsCard) : host.slots.register({
7095
+ name: "plugins.item",
7096
+ id: "codex",
7097
+ order: 30,
7098
+ label: () => t("promptCardTitle"),
7099
+ locale: "codex",
7100
+ inject: injected
7101
+ }, DesktopSettingsCard)));
7102
+ return dispose;
7103
+ } catch (error) {
7104
+ dispose();
7105
+ throw error;
7106
+ }
7107
+ });
7108
+ }
7109
+ });
7110
+ }
7111
+ //#endregion
7112
+ //#region lib/types/client/entry.js
7113
+ const inject = [
7114
+ "commandUi",
7115
+ "sessions",
7116
+ "slots",
7117
+ "locale",
7118
+ "remote"
7119
+ ];
7120
+ function apply(ctx) {
7121
+ ctx.inject(["configForms"], (host) => apply$1(host));
7122
+ ctx.inject(["settingsScope"], (host) => apply$2(host));
7123
+ }
7124
+ var entry_default = {
5577
7125
  inject,
5578
7126
  apply
5579
7127
  };
5580
7128
  //#endregion
5581
- exports.ActivityLine = ActivityLine;
5582
- exports.PromptSettingsCard = PromptSettingsCard;
5583
7129
  exports.apply = apply;
5584
- exports.default = client_default;
7130
+ exports.default = entry_default;
5585
7131
  exports.inject = inject;
5586
- exports.resolveActivity = resolveActivity;
5587
- exports.selectTurnStatus = selectTurnStatus;
5588
7132
  return module.exports;
5589
7133
  }
5590
7134
  });