@shuind/dsh-codex-harness 0.2.5 → 0.2.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/client.js CHANGED
@@ -141,6 +141,12 @@ window.__ModuleLoader__.load({
141
141
  otherCapabilitiesLabel: "Additional capabilities",
142
142
  capabilityPrompt: "Codex operating prompt",
143
143
  capabilityPromptHint: "Inject the editable instructions and persona-first prompt layout.",
144
+ capabilityFast: "Fast mode control",
145
+ capabilityFastHint: "Show the Fast mode switch beside the conversation composer.",
146
+ compactRemote: "Remote compaction",
147
+ compactRemoteHint: "Use the provider remote compaction endpoint first.",
148
+ compactLocal: "Local compaction",
149
+ compactLocalHint: "Use the DSH text-summary compaction engine directly.",
144
150
  capabilityTerminal: "Terminal tools",
145
151
  capabilityTerminalHint: "Expose exec_command and write_stdin.",
146
152
  capabilityPatch: "Patch tool",
@@ -190,6 +196,12 @@ window.__ModuleLoader__.load({
190
196
  otherCapabilitiesLabel: "其他能力",
191
197
  capabilityPrompt: "Codex 操作提示词",
192
198
  capabilityPromptHint: "注入可编辑指令,并将 Persona 放在提示词首位。",
199
+ capabilityFast: "显示 Fast 模式",
200
+ capabilityFastHint: "在对话输入区旁显示 Fast 开关。",
201
+ compactRemote: "远程压缩",
202
+ compactRemoteHint: "优先使用提供商的远程压缩端点。",
203
+ compactLocal: "本地压缩",
204
+ compactLocalHint: "直接使用 DSH 文本摘要压缩引擎。",
193
205
  capabilityTerminal: "终端工具",
194
206
  capabilityTerminalHint: "提供 exec_command 和 write_stdin。",
195
207
  capabilityPatch: "补丁工具",
@@ -224,11 +236,6 @@ window.__ModuleLoader__.load({
224
236
  activityRequestingModel: "请求中...",
225
237
  activityModelReply: "回复中..."
226
238
  };
227
- function promptFromLayer(layer) {
228
- if (typeof layer !== "object" || layer === null || Array.isArray(layer)) return void 0;
229
- const value = layer["systemPrompt"];
230
- return typeof value === "string" ? value : void 0;
231
- }
232
239
  function CapabilityToggle({ field, label, hint, enabled, disabled, setSetting }) {
233
240
  return (0, react_jsx_runtime.jsxs)("label", {
234
241
  style: {
@@ -276,38 +283,65 @@ window.__ModuleLoader__.load({
276
283
  });
277
284
  }
278
285
  /** Visually separate capability scope while keeping the host's light settings style. */
279
- function CapabilityGroup({ label, children, accent }) {
286
+ function CapabilityGroup({ id, label, children, accent }) {
287
+ const [open, setOpen] = (0, react.useState)(false);
288
+ const panelId = `${id}-panel`;
280
289
  return (0, react_jsx_runtime.jsxs)("section", {
281
290
  style: {
282
291
  display: "grid",
283
- gap: 4
292
+ gap: open ? 4 : 0
284
293
  },
285
- children: [(0, react_jsx_runtime.jsxs)("div", {
294
+ children: [(0, react_jsx_runtime.jsxs)("button", {
295
+ type: "button",
296
+ "aria-expanded": open,
297
+ "aria-controls": panelId,
298
+ onClick: () => {
299
+ setOpen(!open);
300
+ },
286
301
  style: {
287
302
  display: "flex",
288
303
  alignItems: "center",
289
304
  gap: 7,
290
- paddingLeft: 2
305
+ width: "100%",
306
+ padding: 0,
307
+ border: 0,
308
+ background: "none",
309
+ color: "var(--dsw-alias-label-secondary)",
310
+ font: "inherit",
311
+ textAlign: "left",
312
+ cursor: "pointer"
291
313
  },
292
- children: [(0, react_jsx_runtime.jsx)("span", {
293
- "aria-hidden": "true",
294
- style: {
295
- width: 6,
296
- height: 6,
297
- flex: "0 0 auto",
298
- borderRadius: 999,
299
- background: accent
300
- }
301
- }), (0, react_jsx_runtime.jsx)("strong", {
302
- style: {
303
- color: "var(--dsw-alias-label-secondary)",
304
- fontSize: 14,
305
- fontWeight: 600,
306
- letterSpacing: "0.01em"
307
- },
308
- children: label
309
- })]
310
- }), (0, react_jsx_runtime.jsx)("div", {
314
+ children: [
315
+ (0, react_jsx_runtime.jsx)("span", {
316
+ "aria-hidden": "true",
317
+ style: {
318
+ width: 6,
319
+ height: 6,
320
+ flex: "0 0 auto",
321
+ borderRadius: 999,
322
+ background: accent
323
+ }
324
+ }),
325
+ (0, react_jsx_runtime.jsx)("strong", {
326
+ style: {
327
+ color: "var(--dsw-alias-label-secondary)",
328
+ fontSize: 14,
329
+ fontWeight: 600,
330
+ letterSpacing: "0.01em"
331
+ },
332
+ children: label
333
+ }),
334
+ (0, react_jsx_runtime.jsx)("span", {
335
+ "aria-hidden": "true",
336
+ style: {
337
+ color: "var(--dsw-alias-label-tertiary)",
338
+ fontSize: 16
339
+ },
340
+ children: open ? "-" : "+"
341
+ })
342
+ ]
343
+ }), open && (0, react_jsx_runtime.jsx)("div", {
344
+ id: panelId,
311
345
  style: {
312
346
  display: "grid",
313
347
  marginLeft: 5,
@@ -318,22 +352,57 @@ window.__ModuleLoader__.load({
318
352
  });
319
353
  }
320
354
  function PromptEditor({ id, label, hint, value, writable, saving, minHeight, onChange }) {
355
+ const [open, setOpen] = (0, react.useState)(false);
356
+ const labelId = `${id}-label`;
357
+ const panelId = `${id}-panel`;
321
358
  return (0, react_jsx_runtime.jsxs)("div", {
322
359
  style: {
323
360
  display: "grid",
324
- gap: 5
361
+ gap: open ? 8 : 0
325
362
  },
326
- children: [
327
- (0, react_jsx_runtime.jsx)("label", {
328
- htmlFor: id,
363
+ children: [(0, react_jsx_runtime.jsxs)("button", {
364
+ type: "button",
365
+ "aria-expanded": open,
366
+ "aria-controls": panelId,
367
+ onClick: () => {
368
+ setOpen(!open);
369
+ },
370
+ style: {
371
+ display: "flex",
372
+ alignItems: "center",
373
+ gap: 8,
374
+ width: "100%",
375
+ padding: 0,
376
+ border: 0,
377
+ background: "none",
378
+ color: "var(--dsw-alias-label-primary)",
379
+ font: "inherit",
380
+ fontSize: 13,
381
+ fontWeight: 500,
382
+ textAlign: "left",
383
+ cursor: "pointer"
384
+ },
385
+ children: [(0, react_jsx_runtime.jsx)("span", {
386
+ id: labelId,
387
+ style: { flex: 1 },
388
+ children: label
389
+ }), (0, react_jsx_runtime.jsx)("span", {
390
+ "aria-hidden": "true",
329
391
  style: {
330
- fontSize: 13,
331
- fontWeight: 500
392
+ color: "var(--dsw-alias-label-tertiary)",
393
+ fontSize: 16
332
394
  },
333
- children: label
334
- }),
335
- (0, react_jsx_runtime.jsx)("textarea", {
395
+ children: open ? "-" : "+"
396
+ })]
397
+ }), open && (0, react_jsx_runtime.jsxs)("div", {
398
+ id: panelId,
399
+ style: {
400
+ display: "grid",
401
+ gap: 5
402
+ },
403
+ children: [(0, react_jsx_runtime.jsx)("textarea", {
336
404
  id,
405
+ "aria-labelledby": labelId,
337
406
  value,
338
407
  disabled: !writable || saving,
339
408
  onChange: (event) => {
@@ -354,28 +423,31 @@ window.__ModuleLoader__.load({
354
423
  fontSize: 12,
355
424
  lineHeight: 1.5
356
425
  }
357
- }),
358
- (0, react_jsx_runtime.jsx)("span", {
426
+ }), (0, react_jsx_runtime.jsx)("span", {
359
427
  style: {
360
428
  color: "var(--dsw-alias-label-tertiary)",
361
429
  fontSize: 11,
362
430
  lineHeight: 1.45
363
431
  },
364
432
  children: hint
365
- })
366
- ]
433
+ })]
434
+ })]
367
435
  });
368
436
  }
369
437
  /** Full-prompt editor contributed to Settings > Plugins. */
370
438
  function PromptSettingsCard(props) {
371
- const { useSettings, setSetting, unsetSetting, t } = props;
439
+ const { useSettings, setSetting, t } = props;
372
440
  const snapshot = useSettings((state) => state);
373
441
  const currentPersona = snapshot.value?.persona ?? DEFAULT_CODEX_PERSONA;
374
442
  const currentSourcePrompt = snapshot.value?.harnessSourcePrompt ?? DEFAULT_DSH_CORE_SOURCE_PROMPT;
375
443
  const currentWebPrompt = snapshot.value?.webSurfacePrompt ?? DEFAULT_DSH_CORE_WEB_PROMPT;
376
444
  const current = snapshot.value?.systemPrompt ?? DEFAULT_CODEX_SYSTEM_PROMPT;
377
- const inherited = promptFromLayer(snapshot.base) ?? DEFAULT_CODEX_SYSTEM_PROMPT;
378
445
  const codexOnlyCapabilities = [
446
+ {
447
+ field: "fastModeControlEnabled",
448
+ label: "capabilityFast",
449
+ hint: "capabilityFastHint"
450
+ },
379
451
  {
380
452
  field: "promptEnabled",
381
453
  label: "capabilityPrompt",
@@ -464,12 +536,14 @@ window.__ModuleLoader__.load({
464
536
  setPersonaDraft(DEFAULT_CODEX_PERSONA);
465
537
  setSourcePromptDraft(DEFAULT_DSH_CORE_SOURCE_PROMPT);
466
538
  setWebPromptDraft(DEFAULT_DSH_CORE_WEB_PROMPT);
467
- setDraft(inherited);
539
+ setDraft(DEFAULT_CODEX_SYSTEM_PROMPT);
468
540
  try {
469
- await unsetSetting("systemPrompt");
470
- await unsetSetting("persona");
471
- await unsetSetting("harnessSourcePrompt");
472
- await unsetSetting("webSurfacePrompt");
541
+ await Promise.all([
542
+ setSetting("persona", DEFAULT_CODEX_PERSONA),
543
+ setSetting("harnessSourcePrompt", DEFAULT_DSH_CORE_SOURCE_PROMPT),
544
+ setSetting("webSurfacePrompt", DEFAULT_DSH_CORE_WEB_PROMPT),
545
+ setSetting("systemPrompt", DEFAULT_CODEX_SYSTEM_PROMPT)
546
+ ]);
473
547
  } catch {
474
548
  setFailed(true);
475
549
  setPersonaDraft(currentPersona);
@@ -573,10 +647,12 @@ window.__ModuleLoader__.load({
573
647
  marginBottom: 14
574
648
  },
575
649
  children: [(0, react_jsx_runtime.jsx)(CapabilityGroup, {
650
+ id: "codex-only-capabilities",
576
651
  label: t("codexOnlyCapabilitiesLabel"),
577
652
  accent: "var(--dsw-static-blue-500)",
578
653
  children: codexOnlyCapabilities.map(renderCapability)
579
654
  }), (0, react_jsx_runtime.jsx)(CapabilityGroup, {
655
+ id: "other-capabilities",
580
656
  label: t("otherCapabilitiesLabel"),
581
657
  accent: "var(--dsw-alias-label-tertiary)",
582
658
  children: otherCapabilities.map(renderCapability)
@@ -685,6 +761,9 @@ window.__ModuleLoader__.load({
685
761
  type: "button",
686
762
  disabled: !dirty || saving,
687
763
  onClick: () => {
764
+ setPersonaDraft(currentPersona);
765
+ setSourcePromptDraft(currentSourcePrompt);
766
+ setWebPromptDraft(currentWebPrompt);
688
767
  setDraft(current);
689
768
  setFailed(false);
690
769
  },
@@ -726,7 +805,9 @@ window.__ModuleLoader__.load({
726
805
  function FastModeFallback(props) {
727
806
  const { useSettings, setSetting, t } = props;
728
807
  const snapshot = useSettings((state) => state);
808
+ const visible = snapshot.value?.fastModeControlEnabled ?? true;
729
809
  const fast = snapshot.value?.fast ?? false;
810
+ if (!visible) return null;
730
811
  return (0, react_jsx_runtime.jsxs)("button", {
731
812
  type: "button",
732
813
  role: "switch",
@@ -986,14 +1067,20 @@ window.__ModuleLoader__.load({
986
1067
  }
987
1068
  return null;
988
1069
  }
1070
+ function isTurnStatus(status) {
1071
+ return status.textContent?.includes("Deep diving...") === true || status.className.toString().includes("turnStatus");
1072
+ }
1073
+ function hasLayout(status) {
1074
+ const rect = status.getBoundingClientRect();
1075
+ return rect.width > 0 && rect.height > 0;
1076
+ }
1077
+ /** Prefer the actual Core turn status over unrelated global status nodes. */
1078
+ function selectTurnStatus(statuses) {
1079
+ const preferred = statuses.filter(isTurnStatus);
1080
+ return preferred.findLast(hasLayout) ?? preferred.at(-1) ?? statuses.filter((status) => status.closest("[data-chat-flow]") !== null).findLast(hasLayout) ?? statuses.filter((status) => status.closest("[data-chat-flow]") !== null).at(-1) ?? null;
1081
+ }
989
1082
  function findTurnStatus() {
990
- let fallback = null;
991
- for (const status of document.querySelectorAll("[role=\"status\"]")) {
992
- if (status.closest("[data-chat-flow]") === null) continue;
993
- fallback ??= status;
994
- if (status.textContent?.includes("Deep diving...") === true || status.className.toString().includes("turnStatus")) return status;
995
- }
996
- return fallback;
1083
+ return selectTurnStatus([...document.querySelectorAll("[role=\"status\"]")]);
997
1084
  }
998
1085
  function useTurnStatusPosition(target) {
999
1086
  const [position, setPosition] = (0, react.useState)(null);
@@ -1081,6 +1168,8 @@ window.__ModuleLoader__.load({
1081
1168
  }), document.body, "codex-activity")] });
1082
1169
  }
1083
1170
  const inject = [
1171
+ "commandUi",
1172
+ "sessions",
1084
1173
  "slots",
1085
1174
  "locale",
1086
1175
  "settingsScope"
@@ -1091,6 +1180,33 @@ window.__ModuleLoader__.load({
1091
1180
  en,
1092
1181
  zh
1093
1182
  }), "codex client: dictionaries");
1183
+ const commandUi = ctx.get("commandUi");
1184
+ const sessions = ctx.get("sessions");
1185
+ const t = ctx.locale.bind(NS);
1186
+ const sessionFor = (session) => sessions.binding(session.sessionId)?.session;
1187
+ ctx.effect(() => commandUi.decorate({
1188
+ name: "compact",
1189
+ available: (session) => sessionFor(session) !== void 0,
1190
+ ui: {
1191
+ kind: "popupSelect",
1192
+ options: async () => [{
1193
+ id: "remote",
1194
+ label: t("compactRemote"),
1195
+ detail: t("compactRemoteHint")
1196
+ }, {
1197
+ id: "local",
1198
+ label: t("compactLocal"),
1199
+ detail: t("compactLocalHint")
1200
+ }],
1201
+ onSelect: async (option, session) => {
1202
+ const live = sessionFor(session);
1203
+ if (live === void 0) throw new Error("this session is not materialized yet");
1204
+ const result = await live.command(`/compact ${option.id}`);
1205
+ if (!result.ok) throw new Error(`compact mode switch failed: ${result.error.code}: ${result.error.message}`);
1206
+ if (!result.value.matched) throw new Error("the host offers no /compact command");
1207
+ }
1208
+ }
1209
+ }), "codex client: /compact mode picker");
1094
1210
  const settings = ctx.settingsScope.bind({ namespace: SETTINGS_NAMESPACE });
1095
1211
  const injected = () => ({
1096
1212
  hooks: { settings },
@@ -1129,6 +1245,7 @@ window.__ModuleLoader__.load({
1129
1245
  exports.default = client_default;
1130
1246
  exports.inject = inject;
1131
1247
  exports.resolveActivity = resolveActivity;
1248
+ exports.selectTurnStatus = selectTurnStatus;
1132
1249
  return module.exports;
1133
1250
  }
1134
1251
  });
package/lib/compaction.js CHANGED
@@ -3,6 +3,28 @@ import BasicCompactionEngine from "@deepseek-ai/dsh-compaction-basic";
3
3
  import { settingsNamespace } from "@deepseek-ai/dsh-settings";
4
4
  //#region lib/types/compaction.js
5
5
  /** Codex compaction backend that honors the latest durable request capacity. */
6
+ /**
7
+ * The main plugin entry and the compact-command subpath can be evaluated as
8
+ * separate bundles. Keep their async context carrier on the process global so
9
+ * an explicit command mode reaches the global llm/stream listener.
10
+ */
11
+ const COMPACTION_MODE_KEY = Symbol.for("shuind.dsh-codex-harness.compaction-mode");
12
+ const COMPACTION_MODE = (() => {
13
+ const registry = globalThis;
14
+ const existing = registry[COMPACTION_MODE_KEY];
15
+ if (existing !== void 0) return existing;
16
+ const storage = new AsyncLocalStorage();
17
+ registry[COMPACTION_MODE_KEY] = storage;
18
+ return storage;
19
+ })();
20
+ /** Run one manual compaction with an explicit local/remote preference. */
21
+ function runCodexCompactionMode(mode, task) {
22
+ return COMPACTION_MODE.run(mode, task);
23
+ }
24
+ /** Read the explicit preference for the current compaction stream, if any. */
25
+ function codexCompactionMode() {
26
+ return COMPACTION_MODE.getStore();
27
+ }
6
28
  const CODEX_SETTINGS_NAMESPACE = settingsNamespace("codex");
7
29
  /** Codex context overrides apply only to GPT-compatible model routes. */
8
30
  function isGptModel(model) {
@@ -83,4 +105,4 @@ var CodexCompactionEngine = class extends BasicCompactionEngine {
83
105
  }
84
106
  };
85
107
  //#endregion
86
- export { CodexCompactionEngine as default };
108
+ export { codexCompactionMode, CodexCompactionEngine as default, runCodexCompactionMode };
package/lib/index.js CHANGED
@@ -9,6 +9,7 @@ import { mkdirSync, writeFileSync } from "node:fs";
9
9
  import { homedir } from "node:os";
10
10
  import { isTokenDelta } from "@deepseek-ai/dsh-llm/message";
11
11
  import { z as z$1 } from "zod";
12
+ import BasicCompactionEngine from "@deepseek-ai/dsh-compaction-basic";
12
13
  //#region lib/types/patch.js
13
14
  /** Parser and line-oriented applicator for Codex's `apply_patch` language. */
14
15
  const APPLY_PATCH_DESCRIPTION = "Edits files using Codex patch syntax with Begin/End Patch markers and file update directives. In hunk lines, the first character is the operation marker; repeat a source-leading marker when the source line itself starts with one.";
@@ -535,7 +536,7 @@ function serviceTierOf(options) {
535
536
  const value = options.serviceTier;
536
537
  return typeof value === "string" ? value : void 0;
537
538
  }
538
- function isGptModel$1(model) {
539
+ function isGptModel$2(model) {
539
540
  return typeof model === "string" && /(?:^|\/)(?:gpt|chatgpt)(?:[-_.]|\d|$)/i.test(model);
540
541
  }
541
542
  function settingsOf(ctx) {
@@ -813,11 +814,11 @@ function hasRemoteCompaction(body) {
813
814
  });
814
815
  }
815
816
  function canPatchBody(body, options) {
816
- return isGptModel$1(body.model) && (options.hostedWebSearch !== false && hasWebSearchTool(body) || hasRemoteCompaction(body) || options.customApplyPatch !== false && hasFunctionApplyPatchTool(body) && canRewriteApplyPatchHistory(body));
817
+ return isGptModel$2(body.model) && (options.hostedWebSearch !== false && hasWebSearchTool(body) || hasRemoteCompaction(body) || options.customApplyPatch !== false && hasFunctionApplyPatchTool(body) && canRewriteApplyPatchHistory(body));
817
818
  }
818
819
  /** Add provider options that older pi-ai adapters do not copy themselves. */
819
820
  function applyRequestWireOptions(body, options) {
820
- if (options.serviceTier === void 0 || !isGptModel$1(body.model)) return body;
821
+ if (options.serviceTier === void 0 || !isGptModel$2(body.model)) return body;
821
822
  return {
822
823
  ...body,
823
824
  service_tier: options.serviceTier
@@ -1240,6 +1241,7 @@ const CODEX_SETTINGS_NAMESPACE = settingsNamespace("codex");
1240
1241
  /** Default settings exposed even before a Codex session is opened. */
1241
1242
  const CODEX_SETTINGS_ENTRY = {
1242
1243
  fast: false,
1244
+ fastModeControlEnabled: true,
1243
1245
  persona: DEFAULT_CODEX_PERSONA,
1244
1246
  harnessSourcePrompt: DEFAULT_DSH_CORE_SOURCE_PROMPT,
1245
1247
  webSurfacePrompt: DEFAULT_DSH_CORE_WEB_PROMPT,
@@ -1254,6 +1256,7 @@ const CODEX_SETTINGS_ENTRY = {
1254
1256
  };
1255
1257
  const CODEX_SETTINGS_SCHEMA = z.object({
1256
1258
  fast: z.boolean().default(false),
1259
+ fastModeControlEnabled: z.boolean().default(true),
1257
1260
  contextWindow: z.number().step(1).min(1).max(CODEX_CONTEXT_MAX),
1258
1261
  persona: z.string().default(DEFAULT_CODEX_PERSONA),
1259
1262
  harnessSourcePrompt: z.string().default(DEFAULT_DSH_CORE_SOURCE_PROMPT),
@@ -1268,6 +1271,101 @@ const CODEX_SETTINGS_SCHEMA = z.object({
1268
1271
  activityIndicatorEnabled: z.boolean().default(true)
1269
1272
  });
1270
1273
  //#endregion
1274
+ //#region lib/types/compaction.js
1275
+ /** Codex compaction backend that honors the latest durable request capacity. */
1276
+ /**
1277
+ * The main plugin entry and the compact-command subpath can be evaluated as
1278
+ * separate bundles. Keep their async context carrier on the process global so
1279
+ * an explicit command mode reaches the global llm/stream listener.
1280
+ */
1281
+ const COMPACTION_MODE_KEY = Symbol.for("shuind.dsh-codex-harness.compaction-mode");
1282
+ const COMPACTION_MODE = (() => {
1283
+ const registry = globalThis;
1284
+ const existing = registry[COMPACTION_MODE_KEY];
1285
+ if (existing !== void 0) return existing;
1286
+ const storage = new AsyncLocalStorage();
1287
+ registry[COMPACTION_MODE_KEY] = storage;
1288
+ return storage;
1289
+ })();
1290
+ /** Read the explicit preference for the current compaction stream, if any. */
1291
+ function codexCompactionMode() {
1292
+ return COMPACTION_MODE.getStore();
1293
+ }
1294
+ const CODEX_SETTINGS_NAMESPACE$1 = settingsNamespace("codex");
1295
+ /** Codex context overrides apply only to GPT-compatible model routes. */
1296
+ function isGptModel$1(model) {
1297
+ return /(?:^|\/)(?:gpt|chatgpt)(?:[-_.]|\d|$)/i.test(model);
1298
+ }
1299
+ /** Read the live Codex capacity without requiring a custom LLM service API. */
1300
+ function configuredContextWindow(ctx) {
1301
+ const settings = ctx.get("settings");
1302
+ if (settings?.get === void 0) return { available: false };
1303
+ const value = settings?.get?.(CODEX_SETTINGS_NAMESPACE$1);
1304
+ return {
1305
+ available: true,
1306
+ ...value?.contextWindow !== void 0 && Number.isSafeInteger(value.contextWindow) && value.contextWindow > 0 ? { value: value.contextWindow } : {}
1307
+ };
1308
+ }
1309
+ /** Read an explicit capacity persisted in the request header when settings are unavailable. */
1310
+ function requestContextWindow(session, provider, model) {
1311
+ const config = session.requestHeader()?.config;
1312
+ if (config?.provider !== provider || config.model !== model) return void 0;
1313
+ const value = config.contextWindow;
1314
+ return typeof value === "number" && Number.isSafeInteger(value) && value > 0 ? value : void 0;
1315
+ }
1316
+ /** Resolve the capacity currently in force for an active Codex compaction. */
1317
+ function activeContextWindow(ctx, activeSession, provider, model) {
1318
+ const session = activeSession.getStore();
1319
+ const requestContext = session?.requestContext();
1320
+ const configured = isGptModel$1(model) ? configuredContextWindow(ctx) : { available: false };
1321
+ return configured.available ? configured.value : (session === void 0 ? void 0 : requestContextWindow(session, provider, model)) ?? (requestContext?.provider === provider && requestContext.model === model ? requestContext.contextWindow : void 0);
1322
+ }
1323
+ /** Overlay capacity lookup and auxiliary summary requests for compaction. */
1324
+ function withDurableContextCapacity(llm, ctx, activeSession) {
1325
+ return new Proxy(llm, { get(target, property) {
1326
+ if (property === "resolveModelInfo") return async (provider, model, signal) => {
1327
+ const info = await target.resolveModelInfo(provider, model, signal);
1328
+ const contextWindow = activeContextWindow(ctx, activeSession, provider, model);
1329
+ if (contextWindow === void 0) return info;
1330
+ return {
1331
+ ...info,
1332
+ context: {
1333
+ ...info.context,
1334
+ contextWindow
1335
+ }
1336
+ };
1337
+ };
1338
+ if (property === "stream") return (options) => {
1339
+ const contextWindow = activeContextWindow(ctx, activeSession, options.provider, options.model);
1340
+ if (contextWindow === void 0 || options.contextWindow === contextWindow) return target.stream(options);
1341
+ return target.stream({
1342
+ ...options,
1343
+ contextWindow
1344
+ });
1345
+ };
1346
+ const value = Reflect.get(target, property, target);
1347
+ return typeof value === "function" ? value.bind(target) : value;
1348
+ } });
1349
+ }
1350
+ (class extends BasicCompactionEngine {
1351
+ static inject = BasicCompactionEngine.inject;
1352
+ static Config = BasicCompactionEngine.Config;
1353
+ activeSession;
1354
+ constructor(ctx, config = {}) {
1355
+ const activeSession = new AsyncLocalStorage();
1356
+ const llm = ctx.get("llm");
1357
+ if (llm === void 0) throw new Error("codex compaction requires ctx.llm");
1358
+ super(ctx.extend({ llm: withDurableContextCapacity(llm, ctx, activeSession) }), config);
1359
+ this.activeSession = activeSession;
1360
+ }
1361
+ compactIfNeeded(agent, trigger, signal) {
1362
+ return this.activeSession.run(agent.session, () => super.compactIfNeeded(agent, trigger, signal));
1363
+ }
1364
+ compactNow(agent, signal, sourceCommandId) {
1365
+ return this.activeSession.run(agent.session, () => super.compactNow(agent, signal, sourceCommandId));
1366
+ }
1367
+ });
1368
+ //#endregion
1271
1369
  //#region lib/types/index.js
1272
1370
  /** Codex-compatible prompt overlay and core tools for a dsh agent preset. */
1273
1371
  const name = "codex";
@@ -1507,15 +1605,21 @@ function interpolateCodexPrompt(text, variables) {
1507
1605
  }
1508
1606
  /** Apply user-editable Persona and DSH Core runtime prompt templates. */
1509
1607
  function applyCodexPromptOverrides(assembly, settings) {
1510
- const variables = promptVariables(assembly);
1511
1608
  const overrides = {
1512
1609
  "deployment:persona": settings.persona,
1513
1610
  "harness:source": settings.harnessSourcePrompt,
1514
1611
  "app:web-surface": settings.webSurfacePrompt
1515
1612
  };
1613
+ const defaults = {
1614
+ "deployment:persona": DEFAULT_CODEX_PERSONA,
1615
+ "harness:source": DEFAULT_DSH_CORE_SOURCE_PROMPT,
1616
+ "app:web-surface": DEFAULT_DSH_CORE_WEB_PROMPT
1617
+ };
1618
+ if (!Object.entries(overrides).some(([name, text]) => text !== void 0 && text !== defaults[name])) return assembly;
1619
+ const variables = promptVariables(assembly);
1516
1620
  const sections = assembly.sections.map((section) => {
1517
1621
  const template = overrides[section.name];
1518
- return template === void 0 ? section : {
1622
+ return template === void 0 || template === defaults[section.name] ? section : {
1519
1623
  ...section,
1520
1624
  text: interpolateCodexPrompt(template, variables)
1521
1625
  };
@@ -1955,16 +2059,21 @@ function apply(ctx, config = {}) {
1955
2059
  }
1956
2060
  ctx.on("llm/stream", ((options, next) => {
1957
2061
  const settings = codexSettings.current();
1958
- const legacySafeNext = () => repairLegacyPiAiContextOverflow(next(), options.model, options.contextWindow);
1959
- if (resolved.remoteCompact && settings.remoteCompactionEnabled && options.purpose === "compaction" && isGptModel(options.model)) return remoteCompactStream(ctx, options, legacySafeNext, {
1960
- hostedWebSearch: resolved.hostedWebSearch && settings.hostedWebSearchEnabled,
1961
- customApplyPatch: settings.patchToolEnabled
1962
- });
2062
+ const contextWindow = options.contextWindow ?? settings.contextWindow;
2063
+ const compactionMode = codexCompactionMode();
2064
+ const legacySafeNext = () => repairLegacyPiAiContextOverflow(next(), options.model, contextWindow);
2065
+ if (options.purpose === "compaction" && isGptModel(options.model)) {
2066
+ if (compactionMode === "remote" || compactionMode !== "local" && resolved.remoteCompact && settings.remoteCompactionEnabled) return remoteCompactStream(ctx, options, legacySafeNext, {
2067
+ hostedWebSearch: resolved.hostedWebSearch && settings.hostedWebSearchEnabled,
2068
+ customApplyPatch: settings.patchToolEnabled
2069
+ });
2070
+ return legacySafeNext();
2071
+ }
1963
2072
  if (options.purpose === void 0 && isGptModel(options.model)) return repairLegacyPiAiContextOverflow(hostedWebSearchStream(next, {
1964
2073
  serviceTier: options.serviceTier,
1965
2074
  hostedWebSearch: resolved.hostedWebSearch && settings.hostedWebSearchEnabled,
1966
2075
  customApplyPatch: settings.patchToolEnabled
1967
- }), options.model, options.contextWindow);
2076
+ }), options.model, contextWindow);
1968
2077
  return next();
1969
2078
  }));
1970
2079
  }
package/lib/installer.js CHANGED
@@ -69,6 +69,7 @@ const CODEX_SETTINGS_NAMESPACE = settingsNamespace("codex");
69
69
  /** Default settings exposed even before a Codex session is opened. */
70
70
  const CODEX_SETTINGS_ENTRY = {
71
71
  fast: false,
72
+ fastModeControlEnabled: true,
72
73
  persona: DEFAULT_CODEX_PERSONA,
73
74
  harnessSourcePrompt: DEFAULT_DSH_CORE_SOURCE_PROMPT,
74
75
  webSurfacePrompt: DEFAULT_DSH_CORE_WEB_PROMPT,
@@ -83,6 +84,7 @@ const CODEX_SETTINGS_ENTRY = {
83
84
  };
84
85
  const CODEX_SETTINGS_SCHEMA = z.object({
85
86
  fast: z.boolean().default(false),
87
+ fastModeControlEnabled: z.boolean().default(true),
86
88
  contextWindow: z.number().step(1).min(1).max(CODEX_CONTEXT_MAX),
87
89
  persona: z.string().default(DEFAULT_CODEX_PERSONA),
88
90
  harnessSourcePrompt: z.string().default(DEFAULT_DSH_CORE_SOURCE_PROMPT),
@@ -7,6 +7,7 @@ import { modelActivity } from './activity.ts';
7
7
  declare const LEGACY_OVERLAY_SLOT: "conversation.input.overlay";
8
8
  interface CodexSettings {
9
9
  fast: boolean;
10
+ fastModeControlEnabled: boolean;
10
11
  contextWindow?: number;
11
12
  persona?: string;
12
13
  harnessSourcePrompt?: string;
@@ -36,6 +37,12 @@ declare const en: {
36
37
  readonly otherCapabilitiesLabel: "Additional capabilities";
37
38
  readonly capabilityPrompt: "Codex operating prompt";
38
39
  readonly capabilityPromptHint: "Inject the editable instructions and persona-first prompt layout.";
40
+ readonly capabilityFast: "Fast mode control";
41
+ readonly capabilityFastHint: "Show the Fast mode switch beside the conversation composer.";
42
+ readonly compactRemote: "Remote compaction";
43
+ readonly compactRemoteHint: "Use the provider remote compaction endpoint first.";
44
+ readonly compactLocal: "Local compaction";
45
+ readonly compactLocalHint: "Use the DSH text-summary compaction engine directly.";
39
46
  readonly capabilityTerminal: "Terminal tools";
40
47
  readonly capabilityTerminalHint: "Expose exec_command and write_stdin.";
41
48
  readonly capabilityPatch: "Patch tool";
@@ -110,6 +117,8 @@ export declare function ActivityLine({ sessionId: _sessionId, useSession, useSes
110
117
  top: number;
111
118
  };
112
119
  }): import("react").JSX.Element | null;
120
+ /** Prefer the actual Core turn status over unrelated global status nodes. */
121
+ export declare function selectTurnStatus(statuses: readonly HTMLElement[]): HTMLElement | null;
113
122
  export declare const inject: string[];
114
123
  /** Mount request controls and the plugin settings card through shared slots. */
115
124
  export declare function apply(ctx: Context): void;
@@ -26,6 +26,12 @@ const en = {
26
26
  otherCapabilitiesLabel: 'Additional capabilities',
27
27
  capabilityPrompt: 'Codex operating prompt',
28
28
  capabilityPromptHint: 'Inject the editable instructions and persona-first prompt layout.',
29
+ capabilityFast: 'Fast mode control',
30
+ capabilityFastHint: 'Show the Fast mode switch beside the conversation composer.',
31
+ compactRemote: 'Remote compaction',
32
+ compactRemoteHint: 'Use the provider remote compaction endpoint first.',
33
+ compactLocal: 'Local compaction',
34
+ compactLocalHint: 'Use the DSH text-summary compaction engine directly.',
29
35
  capabilityTerminal: 'Terminal tools',
30
36
  capabilityTerminalHint: 'Expose exec_command and write_stdin.',
31
37
  capabilityPatch: 'Patch tool',
@@ -75,6 +81,12 @@ const zh = {
75
81
  otherCapabilitiesLabel: '\u5176\u4ed6\u80fd\u529b',
76
82
  capabilityPrompt: 'Codex \u64cd\u4f5c\u63d0\u793a\u8bcd',
77
83
  capabilityPromptHint: '\u6ce8\u5165\u53ef\u7f16\u8f91\u6307\u4ee4\uff0c\u5e76\u5c06 Persona \u653e\u5728\u63d0\u793a\u8bcd\u9996\u4f4d\u3002',
84
+ capabilityFast: '\u663e\u793a Fast \u6a21\u5f0f',
85
+ capabilityFastHint: '\u5728\u5bf9\u8bdd\u8f93\u5165\u533a\u65c1\u663e\u793a Fast \u5f00\u5173\u3002',
86
+ compactRemote: '\u8fdc\u7a0b\u538b\u7f29',
87
+ compactRemoteHint: '\u4f18\u5148\u4f7f\u7528\u63d0\u4f9b\u5546\u7684\u8fdc\u7a0b\u538b\u7f29\u7aef\u70b9\u3002',
88
+ compactLocal: '\u672c\u5730\u538b\u7f29',
89
+ compactLocalHint: '\u76f4\u63a5\u4f7f\u7528 DSH \u6587\u672c\u6458\u8981\u538b\u7f29\u5f15\u64ce\u3002',
78
90
  capabilityTerminal: '\u7ec8\u7aef\u5de5\u5177',
79
91
  capabilityTerminalHint: '\u63d0\u4f9b exec_command \u548c write_stdin\u3002',
80
92
  capabilityPatch: '\u8865\u4e01\u5de5\u5177',
@@ -109,12 +121,6 @@ const zh = {
109
121
  activityRequestingModel: '\u8bf7\u6c42\u4e2d...',
110
122
  activityModelReply: '\u56de\u590d\u4e2d...',
111
123
  };
112
- function promptFromLayer(layer) {
113
- if (typeof layer !== 'object' || layer === null || Array.isArray(layer))
114
- return undefined;
115
- const value = layer['systemPrompt'];
116
- return typeof value === 'string' ? value : undefined;
117
- }
118
124
  function CapabilityToggle({ field, label, hint, enabled, disabled, setSetting, }) {
119
125
  return (_jsxs("label", { style: {
120
126
  display: 'flex',
@@ -125,11 +131,25 @@ function CapabilityToggle({ field, label, hint, enabled, disabled, setSetting, }
125
131
  }, children: [_jsxs("span", { style: { flex: 1, minWidth: 0, display: 'grid', gap: 2 }, children: [_jsx("strong", { style: { fontSize: 13, fontWeight: 500 }, children: label }), _jsx("span", { style: { color: 'var(--dsw-alias-label-tertiary)', fontSize: 12, lineHeight: 1.45 }, children: hint })] }), _jsx("input", { type: "checkbox", role: "switch", checked: enabled, disabled: disabled, "aria-label": label, onChange: event => { void setSetting(field, event.target.checked); }, style: { marginTop: 3, accentColor: 'var(--dsw-static-blue-500)' } })] }));
126
132
  }
127
133
  /** Visually separate capability scope while keeping the host's light settings style. */
128
- function CapabilityGroup({ label, children, accent }) {
134
+ function CapabilityGroup({ id, label, children, accent }) {
135
+ const [open, setOpen] = useState(false);
136
+ const panelId = `${id}-panel`;
129
137
  return (_jsxs("section", { style: {
130
138
  display: 'grid',
131
- gap: 4,
132
- }, children: [_jsxs("div", { style: { display: 'flex', alignItems: 'center', gap: 7, paddingLeft: 2 }, children: [_jsx("span", { "aria-hidden": "true", style: {
139
+ gap: open ? 4 : 0,
140
+ }, children: [_jsxs("button", { type: "button", "aria-expanded": open, "aria-controls": panelId, onClick: () => { setOpen(!open); }, style: {
141
+ display: 'flex',
142
+ alignItems: 'center',
143
+ gap: 7,
144
+ width: '100%',
145
+ padding: 0,
146
+ border: 0,
147
+ background: 'none',
148
+ color: 'var(--dsw-alias-label-secondary)',
149
+ font: 'inherit',
150
+ textAlign: 'left',
151
+ cursor: 'pointer',
152
+ }, children: [_jsx("span", { "aria-hidden": "true", style: {
133
153
  width: 6,
134
154
  height: 6,
135
155
  flex: '0 0 auto',
@@ -140,38 +160,55 @@ function CapabilityGroup({ label, children, accent }) {
140
160
  fontSize: 14,
141
161
  fontWeight: 600,
142
162
  letterSpacing: '0.01em',
143
- }, children: label })] }), _jsx("div", { style: {
163
+ }, children: label }), _jsx("span", { "aria-hidden": "true", style: { color: 'var(--dsw-alias-label-tertiary)', fontSize: 16 }, children: open ? '-' : '+' })] }), open && (_jsx("div", { id: panelId, style: {
144
164
  display: 'grid',
145
165
  marginLeft: 5,
146
166
  paddingLeft: 12,
147
- }, children: children })] }));
167
+ }, children: children }))] }));
148
168
  }
149
169
  function PromptEditor({ id, label, hint, value, writable, saving, minHeight, onChange, }) {
150
- return (_jsxs("div", { style: { display: 'grid', gap: 5 }, children: [_jsx("label", { htmlFor: id, style: { fontSize: 13, fontWeight: 500 }, children: label }), _jsx("textarea", { id: id, value: value, disabled: !writable || saving, onChange: event => { onChange(event.target.value); }, spellCheck: false, style: {
151
- boxSizing: 'border-box',
170
+ const [open, setOpen] = useState(false);
171
+ const labelId = `${id}-label`;
172
+ const panelId = `${id}-panel`;
173
+ return (_jsxs("div", { style: { display: 'grid', gap: open ? 8 : 0 }, children: [_jsxs("button", { type: "button", "aria-expanded": open, "aria-controls": panelId, onClick: () => { setOpen(!open); }, style: {
174
+ display: 'flex',
175
+ alignItems: 'center',
176
+ gap: 8,
152
177
  width: '100%',
153
- minHeight,
154
- resize: 'vertical',
155
- padding: 10,
156
- border: '1px solid var(--dsw-alias-border-l2)',
157
- borderRadius: 8,
158
- background: 'var(--dsw-alias-bg-layer-3)',
178
+ padding: 0,
179
+ border: 0,
180
+ background: 'none',
159
181
  color: 'var(--dsw-alias-label-primary)',
160
182
  font: 'inherit',
161
- fontSize: 12,
162
- lineHeight: 1.5,
163
- } }), _jsx("span", { style: { color: 'var(--dsw-alias-label-tertiary)', fontSize: 11, lineHeight: 1.45 }, children: hint })] }));
183
+ fontSize: 13,
184
+ fontWeight: 500,
185
+ textAlign: 'left',
186
+ cursor: 'pointer',
187
+ }, children: [_jsx("span", { id: labelId, style: { flex: 1 }, children: label }), _jsx("span", { "aria-hidden": "true", style: { color: 'var(--dsw-alias-label-tertiary)', fontSize: 16 }, children: open ? '-' : '+' })] }), open && (_jsxs("div", { id: panelId, style: { display: 'grid', gap: 5 }, children: [_jsx("textarea", { id: id, "aria-labelledby": labelId, value: value, disabled: !writable || saving, onChange: event => { onChange(event.target.value); }, spellCheck: false, style: {
188
+ boxSizing: 'border-box',
189
+ width: '100%',
190
+ minHeight,
191
+ resize: 'vertical',
192
+ padding: 10,
193
+ border: '1px solid var(--dsw-alias-border-l2)',
194
+ borderRadius: 8,
195
+ background: 'var(--dsw-alias-bg-layer-3)',
196
+ color: 'var(--dsw-alias-label-primary)',
197
+ font: 'inherit',
198
+ fontSize: 12,
199
+ lineHeight: 1.5,
200
+ } }), _jsx("span", { style: { color: 'var(--dsw-alias-label-tertiary)', fontSize: 11, lineHeight: 1.45 }, children: hint })] }))] }));
164
201
  }
165
202
  /** Full-prompt editor contributed to Settings > Plugins. */
166
203
  export function PromptSettingsCard(props) {
167
- const { useSettings, setSetting, unsetSetting, t } = props;
204
+ const { useSettings, setSetting, t } = props;
168
205
  const snapshot = useSettings(state => state);
169
206
  const currentPersona = snapshot.value?.persona ?? DEFAULT_CODEX_PERSONA;
170
207
  const currentSourcePrompt = snapshot.value?.harnessSourcePrompt ?? DEFAULT_DSH_CORE_SOURCE_PROMPT;
171
208
  const currentWebPrompt = snapshot.value?.webSurfacePrompt ?? DEFAULT_DSH_CORE_WEB_PROMPT;
172
209
  const current = snapshot.value?.systemPrompt ?? DEFAULT_CODEX_SYSTEM_PROMPT;
173
- const inherited = promptFromLayer(snapshot.base) ?? DEFAULT_CODEX_SYSTEM_PROMPT;
174
210
  const codexOnlyCapabilities = [
211
+ { field: 'fastModeControlEnabled', label: 'capabilityFast', hint: 'capabilityFastHint' },
175
212
  { field: 'promptEnabled', label: 'capabilityPrompt', hint: 'capabilityPromptHint' },
176
213
  { field: 'terminalToolsEnabled', label: 'capabilityTerminal', hint: 'capabilityTerminalHint' },
177
214
  { field: 'patchToolEnabled', label: 'capabilityPatch', hint: 'capabilityPatchHint' },
@@ -226,12 +263,14 @@ export function PromptSettingsCard(props) {
226
263
  setPersonaDraft(DEFAULT_CODEX_PERSONA);
227
264
  setSourcePromptDraft(DEFAULT_DSH_CORE_SOURCE_PROMPT);
228
265
  setWebPromptDraft(DEFAULT_DSH_CORE_WEB_PROMPT);
229
- setDraft(inherited);
266
+ setDraft(DEFAULT_CODEX_SYSTEM_PROMPT);
230
267
  try {
231
- await unsetSetting('systemPrompt');
232
- await unsetSetting('persona');
233
- await unsetSetting('harnessSourcePrompt');
234
- await unsetSetting('webSurfacePrompt');
268
+ await Promise.all([
269
+ setSetting('persona', DEFAULT_CODEX_PERSONA),
270
+ setSetting('harnessSourcePrompt', DEFAULT_DSH_CORE_SOURCE_PROMPT),
271
+ setSetting('webSurfacePrompt', DEFAULT_DSH_CORE_WEB_PROMPT),
272
+ setSetting('systemPrompt', DEFAULT_CODEX_SYSTEM_PROMPT),
273
+ ]);
235
274
  }
236
275
  catch {
237
276
  setFailed(true);
@@ -268,7 +307,7 @@ export function PromptSettingsCard(props) {
268
307
  background: 'var(--dsw-alias-bg-module-platform)',
269
308
  color: 'var(--dsw-alias-label-secondary)',
270
309
  fontSize: 11,
271
- }, children: t('promptUnsaved') })), _jsx("span", { "aria-hidden": "true", style: { color: 'var(--dsw-alias-label-tertiary)', fontSize: 16 }, children: open ? '-' : '+' })] }), open && (_jsxs("div", { style: { borderTop: '1px solid var(--dsw-alias-border-l2)', margin: '0 16px', padding: '12px 0' }, children: [!snapshot.writable && (_jsx("p", { style: { margin: '0 0 10px', color: 'var(--dsw-alias-label-tertiary)', fontSize: 12 }, children: t('promptReadOnly') })), _jsxs("div", { style: { display: 'grid', gap: 16, marginBottom: 14 }, children: [_jsx(CapabilityGroup, { label: t('codexOnlyCapabilitiesLabel'), accent: "var(--dsw-static-blue-500)", children: codexOnlyCapabilities.map(renderCapability) }), _jsx(CapabilityGroup, { label: t('otherCapabilitiesLabel'), accent: "var(--dsw-alias-label-tertiary)", children: otherCapabilities.map(renderCapability) })] }), _jsxs("div", { style: {
310
+ }, children: t('promptUnsaved') })), _jsx("span", { "aria-hidden": "true", style: { color: 'var(--dsw-alias-label-tertiary)', fontSize: 16 }, children: open ? '-' : '+' })] }), open && (_jsxs("div", { style: { borderTop: '1px solid var(--dsw-alias-border-l2)', margin: '0 16px', padding: '12px 0' }, children: [!snapshot.writable && (_jsx("p", { style: { margin: '0 0 10px', color: 'var(--dsw-alias-label-tertiary)', fontSize: 12 }, children: t('promptReadOnly') })), _jsxs("div", { style: { display: 'grid', gap: 16, marginBottom: 14 }, children: [_jsx(CapabilityGroup, { id: "codex-only-capabilities", label: t('codexOnlyCapabilitiesLabel'), accent: "var(--dsw-static-blue-500)", children: codexOnlyCapabilities.map(renderCapability) }), _jsx(CapabilityGroup, { id: "other-capabilities", label: t('otherCapabilitiesLabel'), accent: "var(--dsw-alias-label-tertiary)", children: otherCapabilities.map(renderCapability) })] }), _jsxs("div", { style: {
272
311
  display: 'grid',
273
312
  gap: 14,
274
313
  paddingTop: 12,
@@ -280,13 +319,22 @@ export function PromptSettingsCard(props) {
280
319
  gap: 8,
281
320
  paddingTop: 12,
282
321
  borderTop: '1px solid var(--dsw-alias-border-l2)',
283
- }, children: [failed && (_jsx("span", { role: "status", style: { flex: 1, color: 'var(--dsw-alias-label-error)', fontSize: 12 }, children: t('promptSaveFailed') })), _jsx("button", { type: "button", disabled: !dirty || saving, onClick: () => { setDraft(current); setFailed(false); }, style: { border: '1px solid var(--dsw-alias-border-l2)', borderRadius: 8, background: 'none', color: 'inherit', padding: '5px 14px', font: 'inherit', cursor: 'pointer' }, children: t('promptDiscard') }), _jsx("button", { type: "button", disabled: !snapshot.writable || !dirty || saving, onClick: () => { void save(); }, style: { border: 0, borderRadius: 8, background: 'var(--dsw-alias-label-primary)', color: 'var(--dsw-alias-bg-layer-3)', padding: '6px 14px', font: 'inherit', cursor: 'pointer' }, children: saving ? t('promptSaving') : t('promptSave') })] })] }))] }));
322
+ }, children: [failed && (_jsx("span", { role: "status", style: { flex: 1, color: 'var(--dsw-alias-label-error)', fontSize: 12 }, children: t('promptSaveFailed') })), _jsx("button", { type: "button", disabled: !dirty || saving, onClick: () => {
323
+ setPersonaDraft(currentPersona);
324
+ setSourcePromptDraft(currentSourcePrompt);
325
+ setWebPromptDraft(currentWebPrompt);
326
+ setDraft(current);
327
+ setFailed(false);
328
+ }, style: { border: '1px solid var(--dsw-alias-border-l2)', borderRadius: 8, background: 'none', color: 'inherit', padding: '5px 14px', font: 'inherit', cursor: 'pointer' }, children: t('promptDiscard') }), _jsx("button", { type: "button", disabled: !snapshot.writable || !dirty || saving, onClick: () => { void save(); }, style: { border: 0, borderRadius: 8, background: 'var(--dsw-alias-label-primary)', color: 'var(--dsw-alias-bg-layer-3)', padding: '6px 14px', font: 'inherit', cursor: 'pointer' }, children: saving ? t('promptSaving') : t('promptSave') })] })] }))] }));
284
329
  }
285
330
  /** The legacy composer seat is a compact inline row, not a menu panel. */
286
331
  function FastModeFallback(props) {
287
332
  const { useSettings, setSetting, t } = props;
288
333
  const snapshot = useSettings(state => state);
334
+ const visible = snapshot.value?.fastModeControlEnabled ?? true;
289
335
  const fast = snapshot.value?.fast ?? false;
336
+ if (!visible)
337
+ return null;
290
338
  return (_jsxs("button", { type: "button", role: "switch", disabled: snapshot.writable === false, "aria-checked": fast, "aria-label": fast ? t('fastOn') : t('fastOff'), title: fast ? t('fastOn') : t('fastOff'), onClick: () => { void setSetting('fast', !fast); }, style: {
291
339
  boxSizing: 'border-box',
292
340
  display: 'inline-flex',
@@ -441,17 +489,25 @@ function findContextMeterDialog() {
441
489
  }
442
490
  return null;
443
491
  }
492
+ function isTurnStatus(status) {
493
+ return status.textContent?.includes('Deep diving...') === true
494
+ || status.className.toString().includes('turnStatus');
495
+ }
496
+ function hasLayout(status) {
497
+ const rect = status.getBoundingClientRect();
498
+ return rect.width > 0 && rect.height > 0;
499
+ }
500
+ /** Prefer the actual Core turn status over unrelated global status nodes. */
501
+ export function selectTurnStatus(statuses) {
502
+ const preferred = statuses.filter(isTurnStatus);
503
+ return preferred.findLast(hasLayout)
504
+ ?? preferred.at(-1)
505
+ ?? statuses.filter(status => status.closest('[data-chat-flow]') !== null).findLast(hasLayout)
506
+ ?? statuses.filter(status => status.closest('[data-chat-flow]') !== null).at(-1)
507
+ ?? null;
508
+ }
444
509
  function findTurnStatus() {
445
- let fallback = null;
446
- for (const status of document.querySelectorAll('[role="status"]')) {
447
- if (status.closest('[data-chat-flow]') === null)
448
- continue;
449
- fallback ??= status;
450
- if (status.textContent?.includes('Deep diving...') === true
451
- || status.className.toString().includes('turnStatus'))
452
- return status;
453
- }
454
- return fallback;
510
+ return selectTurnStatus([...document.querySelectorAll('[role="status"]')]);
455
511
  }
456
512
  function useTurnStatusPosition(target) {
457
513
  const [position, setPosition] = useState(null);
@@ -521,10 +577,35 @@ function LegacyOverlay(props) {
521
577
  const contextWindow = contextWindowFromProjection(useProjection);
522
578
  return (_jsxs(_Fragment, { children: [contextDialog !== null && createPortal(_jsx(ContextSizeControl, { contextWindow: contextWindow, sessionId: sessionId, useSessions: useSessions, useSettings: useSettings, setSetting: setSetting, unsetSetting: unsetSetting, t: t }), contextDialog, 'codex-context-size'), turnStatusPosition !== null && typeof document !== 'undefined' && document.body !== null && createPortal(_jsx(ActivityLine, { sessionId: sessionId, useSession: useSession, useSessions: useSessions, useProjection: useProjection, useSettings: useSettings, t: t, position: turnStatusPosition }), document.body, 'codex-activity')] }));
523
579
  }
524
- export const inject = ['slots', 'locale', 'settingsScope'];
580
+ export const inject = ['commandUi', 'sessions', 'slots', 'locale', 'settingsScope'];
525
581
  /** Mount request controls and the plugin settings card through shared slots. */
526
582
  export function apply(ctx) {
527
583
  ctx.effect(() => ctx.locale.register(NS, { en, zh }), 'codex client: dictionaries');
584
+ const commandUi = ctx.get('commandUi');
585
+ const sessions = ctx.get('sessions');
586
+ const t = ctx.locale.bind(NS);
587
+ const sessionFor = (session) => sessions.binding(session.sessionId)?.session;
588
+ ctx.effect(() => commandUi.decorate({
589
+ name: 'compact',
590
+ available: session => sessionFor(session) !== undefined,
591
+ ui: {
592
+ kind: 'popupSelect',
593
+ options: async () => [
594
+ { id: 'remote', label: t('compactRemote'), detail: t('compactRemoteHint') },
595
+ { id: 'local', label: t('compactLocal'), detail: t('compactLocalHint') },
596
+ ],
597
+ onSelect: async (option, session) => {
598
+ const live = sessionFor(session);
599
+ if (live === undefined)
600
+ throw new Error('this session is not materialized yet');
601
+ const result = await live.command(`/compact ${option.id}`);
602
+ if (!result.ok)
603
+ throw new Error(`compact mode switch failed: ${result.error.code}: ${result.error.message}`);
604
+ if (!result.value.matched)
605
+ throw new Error('the host offers no /compact command');
606
+ },
607
+ },
608
+ }), 'codex client: /compact mode picker');
528
609
  const settings = ctx.settingsScope.bind({ namespace: SETTINGS_NAMESPACE });
529
610
  const injected = () => ({
530
611
  hooks: { settings },
@@ -0,0 +1,13 @@
1
+ /** Codex-aware `/compact` command with an optional transport preference. */
2
+ import type { Context } from '@deepseek-ai/cordis';
3
+ /** Replace the Core command inside the Codex compaction scope. */
4
+ export declare function apply(ctx: Context): void;
5
+ export declare const name = "compact-command";
6
+ export declare const inject: string[];
7
+ declare const _default: {
8
+ name: string;
9
+ inject: string[];
10
+ apply: typeof apply;
11
+ };
12
+ export default _default;
13
+ //# sourceMappingURL=compact-command.d.ts.map
@@ -0,0 +1,79 @@
1
+ /** Codex-aware `/compact` command with an optional transport preference. */
2
+ import { ManualCompactionError } from '@deepseek-ai/dsh-compaction';
3
+ import { runCodexCompactionMode } from "./compaction.js";
4
+ const USAGE = 'Usage: /compact [remote|local]';
5
+ /** Convert expected backend failures into the same concise command results as DSH Core. */
6
+ function expectedFailure(error) {
7
+ switch (error.code) {
8
+ case 'busy':
9
+ return { kind: 'error', text: 'Compaction is unavailable because this process has an active compaction, or the agent is not idle.' };
10
+ case 'cancelled':
11
+ return { kind: 'error', text: 'Compaction cancelled.' };
12
+ case 'changed':
13
+ return { kind: 'error', text: 'Compaction could not replace the selected history because it changed. The conversation is unchanged.' };
14
+ case 'summary':
15
+ return { kind: 'error', text: 'Compaction could not produce a useful summary. The conversation is unchanged; the attempt is recorded in the session log.' };
16
+ case 'commit':
17
+ return { kind: 'error', text: 'Compaction did not finish cleanly; inspect the current session state before retrying.' };
18
+ case 'persistence':
19
+ return { kind: 'error', text: 'Compaction finished, but the session could not be saved.' };
20
+ default:
21
+ return { kind: 'error', text: `Unknown compaction failure: ${String(error.code)}` };
22
+ }
23
+ }
24
+ function modeOf(rawInput) {
25
+ const value = rawInput.trim().toLowerCase();
26
+ if (value === '')
27
+ return undefined;
28
+ if (value === 'remote' || value === 'local')
29
+ return value;
30
+ return 'invalid';
31
+ }
32
+ async function executeCompact(ctx, invocation) {
33
+ const mode = modeOf(invocation.rawInput);
34
+ if (mode === 'invalid')
35
+ return { kind: 'error', text: USAGE };
36
+ const compact = () => ctx.compaction.compactNow(invocation.agent, invocation.signal, invocation.commandId);
37
+ try {
38
+ const result = mode === undefined ? await compact() : await runCodexCompactionMode(mode, compact);
39
+ if (result === null)
40
+ return { kind: 'success', text: 'No compactable history yet.' };
41
+ return {
42
+ kind: 'success',
43
+ text: `Compacted ${result.shadowedSeqs.length} history items (~${result.shadowedTokenCount} tokens).`,
44
+ sourceEventSeq: result.summarySeq,
45
+ };
46
+ }
47
+ catch (error) {
48
+ if (invocation.signal.aborted)
49
+ return { kind: 'error', text: 'Compaction cancelled.' };
50
+ if (error instanceof ManualCompactionError)
51
+ return expectedFailure(error);
52
+ throw error;
53
+ }
54
+ }
55
+ /** Replace the Core command inside the Codex compaction scope. */
56
+ export function apply(ctx) {
57
+ const commands = ctx.commands;
58
+ const active = new Set();
59
+ const handler = (invocation) => {
60
+ const operation = executeCompact(ctx, invocation);
61
+ active.add(operation);
62
+ const retire = () => { active.delete(operation); };
63
+ operation.then(retire, retire);
64
+ return operation;
65
+ };
66
+ ctx.effect(function* () {
67
+ yield async () => { await Promise.allSettled(active); };
68
+ yield commands.register({
69
+ name: 'compact',
70
+ description: 'Compact older conversation history, optionally using remote or local mode',
71
+ input: { hint: '[remote|local]' },
72
+ handler,
73
+ });
74
+ }, 'codex compact command lifecycle');
75
+ }
76
+ export const name = 'compact-command';
77
+ export const inject = ['commands', 'compaction'];
78
+ export default { name, inject, apply };
79
+ //# sourceMappingURL=compact-command.js.map
@@ -3,6 +3,12 @@ import { Context } from '@deepseek-ai/cordis';
3
3
  import BasicCompactionEngine from '@deepseek-ai/dsh-compaction-basic';
4
4
  import type { CompactionResult, CompactionTrigger } from '@deepseek-ai/dsh-compaction';
5
5
  import type { Agent } from '@deepseek-ai/dsh-agent';
6
+ /** Per-command compaction preference propagated into the LLM stream seam. */
7
+ export type CodexCompactionMode = 'remote' | 'local';
8
+ /** Run one manual compaction with an explicit local/remote preference. */
9
+ export declare function runCodexCompactionMode<T>(mode: CodexCompactionMode, task: () => Promise<T>): Promise<T>;
10
+ /** Read the explicit preference for the current compaction stream, if any. */
11
+ export declare function codexCompactionMode(): CodexCompactionMode | undefined;
6
12
  /**
7
13
  * Keep the upstream compaction policy, retention, overflow recovery, and
8
14
  * transaction implementation intact. The scoped LLM seam changes only the
@@ -2,6 +2,29 @@
2
2
  import { AsyncLocalStorage } from 'node:async_hooks';
3
3
  import BasicCompactionEngine from '@deepseek-ai/dsh-compaction-basic';
4
4
  import { settingsNamespace } from '@deepseek-ai/dsh-settings';
5
+ /**
6
+ * The main plugin entry and the compact-command subpath can be evaluated as
7
+ * separate bundles. Keep their async context carrier on the process global so
8
+ * an explicit command mode reaches the global llm/stream listener.
9
+ */
10
+ const COMPACTION_MODE_KEY = Symbol.for('shuind.dsh-codex-harness.compaction-mode');
11
+ const COMPACTION_MODE = (() => {
12
+ const registry = globalThis;
13
+ const existing = registry[COMPACTION_MODE_KEY];
14
+ if (existing !== undefined)
15
+ return existing;
16
+ const storage = new AsyncLocalStorage();
17
+ registry[COMPACTION_MODE_KEY] = storage;
18
+ return storage;
19
+ })();
20
+ /** Run one manual compaction with an explicit local/remote preference. */
21
+ export function runCodexCompactionMode(mode, task) {
22
+ return COMPACTION_MODE.run(mode, task);
23
+ }
24
+ /** Read the explicit preference for the current compaction stream, if any. */
25
+ export function codexCompactionMode() {
26
+ return COMPACTION_MODE.getStore();
27
+ }
5
28
  const CODEX_SETTINGS_NAMESPACE = settingsNamespace('codex');
6
29
  /** Codex context overrides apply only to GPT-compatible model routes. */
7
30
  function isGptModel(model) {
@@ -8,6 +8,7 @@ import { hostedWebSearchStream, installHostedWebSearch, remoteCompactStream, rep
8
8
  import { registerCodexActivityProjection } from "./activity.js";
9
9
  import { DEFAULT_CODEX_PERSONA, DEFAULT_CODEX_SYSTEM_PROMPT, DEFAULT_DSH_CORE_SOURCE_PROMPT, DEFAULT_DSH_CORE_WEB_PROMPT, resolveCodexSystemPrompt, } from "./prompt.js";
10
10
  import { CODEX_SETTINGS_ENTRY, CODEX_SETTINGS_NAMESPACE, CODEX_SETTINGS_SCHEMA, } from "./settings.js";
11
+ import { codexCompactionMode } from "./compaction.js";
11
12
  export { DEFAULT_CODEX_PERSONA, DEFAULT_CODEX_SYSTEM_PROMPT, DEFAULT_DSH_CORE_SOURCE_PROMPT, DEFAULT_DSH_CORE_WEB_PROMPT, } from "./prompt.js";
12
13
  export { CODEX_SETTINGS_NAMESPACE, CODEX_SETTINGS_SCHEMA } from "./settings.js";
13
14
  export const name = 'codex';
@@ -275,15 +276,23 @@ function interpolateCodexPrompt(text, variables) {
275
276
  }
276
277
  /** Apply user-editable Persona and DSH Core runtime prompt templates. */
277
278
  function applyCodexPromptOverrides(assembly, settings) {
278
- const variables = promptVariables(assembly);
279
279
  const overrides = {
280
280
  'deployment:persona': settings.persona,
281
281
  'harness:source': settings.harnessSourcePrompt,
282
282
  'app:web-surface': settings.webSurfacePrompt,
283
283
  };
284
+ const defaults = {
285
+ 'deployment:persona': DEFAULT_CODEX_PERSONA,
286
+ 'harness:source': DEFAULT_DSH_CORE_SOURCE_PROMPT,
287
+ 'app:web-surface': DEFAULT_DSH_CORE_WEB_PROMPT,
288
+ };
289
+ const hasCustomOverride = Object.entries(overrides).some(([name, text]) => (text !== undefined && text !== defaults[name]));
290
+ if (!hasCustomOverride)
291
+ return assembly;
292
+ const variables = promptVariables(assembly);
284
293
  const sections = assembly.sections.map(section => {
285
294
  const template = overrides[section.name];
286
- return template === undefined
295
+ return template === undefined || template === defaults[section.name]
287
296
  ? section
288
297
  : { ...section, text: interpolateCodexPrompt(template, variables) };
289
298
  });
@@ -611,22 +620,26 @@ export function apply(ctx, config = {}) {
611
620
  }
612
621
  ctx.on('llm/stream', ((options, next) => {
613
622
  const settings = codexSettings.current();
614
- const legacySafeNext = () => repairLegacyPiAiContextOverflow(next(), options.model, options.contextWindow);
615
- if (resolved.remoteCompact
616
- && settings.remoteCompactionEnabled
617
- && options.purpose === 'compaction'
618
- && isGptModel(options.model)) {
619
- return remoteCompactStream(ctx, options, legacySafeNext, {
620
- hostedWebSearch: resolved.hostedWebSearch && settings.hostedWebSearchEnabled,
621
- customApplyPatch: settings.patchToolEnabled,
622
- });
623
+ const contextWindow = options.contextWindow ?? settings.contextWindow;
624
+ const compactionMode = codexCompactionMode();
625
+ const legacySafeNext = () => repairLegacyPiAiContextOverflow(next(), options.model, contextWindow);
626
+ if (options.purpose === 'compaction' && isGptModel(options.model)) {
627
+ const useRemoteCompaction = compactionMode === 'remote'
628
+ || (compactionMode !== 'local' && resolved.remoteCompact && settings.remoteCompactionEnabled);
629
+ if (useRemoteCompaction) {
630
+ return remoteCompactStream(ctx, options, legacySafeNext, {
631
+ hostedWebSearch: resolved.hostedWebSearch && settings.hostedWebSearchEnabled,
632
+ customApplyPatch: settings.patchToolEnabled,
633
+ });
634
+ }
635
+ return legacySafeNext();
623
636
  }
624
637
  if (options.purpose === undefined && isGptModel(options.model)) {
625
638
  return repairLegacyPiAiContextOverflow(hostedWebSearchStream(next, {
626
639
  serviceTier: options.serviceTier,
627
640
  hostedWebSearch: resolved.hostedWebSearch && settings.hostedWebSearchEnabled,
628
641
  customApplyPatch: settings.patchToolEnabled,
629
- }), options.model, options.contextWindow);
642
+ }), options.model, contextWindow);
630
643
  }
631
644
  return next();
632
645
  }));
@@ -5,6 +5,8 @@ export declare const CODEX_SETTINGS_NAMESPACE: Branded<"SettingsNamespace">;
5
5
  export interface CodexSettings {
6
6
  /** Use the Responses priority service tier for GPT requests. */
7
7
  fast: boolean;
8
+ /** Show the Fast mode switch in the conversation composer. */
9
+ fastModeControlEnabled: boolean;
8
10
  /** Optional context capacity override, in tokens. */
9
11
  contextWindow?: number;
10
12
  /** Deployment Persona template; supports the host's prompt variables. */
@@ -8,6 +8,7 @@ export const CODEX_SETTINGS_NAMESPACE = settingsNamespace('codex');
8
8
  /** Default settings exposed even before a Codex session is opened. */
9
9
  export const CODEX_SETTINGS_ENTRY = {
10
10
  fast: false,
11
+ fastModeControlEnabled: true,
11
12
  persona: DEFAULT_CODEX_PERSONA,
12
13
  harnessSourcePrompt: DEFAULT_DSH_CORE_SOURCE_PROMPT,
13
14
  webSurfacePrompt: DEFAULT_DSH_CORE_WEB_PROMPT,
@@ -22,6 +23,7 @@ export const CODEX_SETTINGS_ENTRY = {
22
23
  };
23
24
  export const CODEX_SETTINGS_SCHEMA = z.object({
24
25
  fast: z.boolean().default(false),
26
+ fastModeControlEnabled: z.boolean().default(true),
25
27
  contextWindow: z.number().step(1).min(1).max(CODEX_CONTEXT_MAX),
26
28
  persona: z.string().default(DEFAULT_CODEX_PERSONA),
27
29
  harnessSourcePrompt: z.string().default(DEFAULT_DSH_CORE_SOURCE_PROMPT),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shuind/dsh-codex-harness",
3
- "version": "0.2.5",
3
+ "version": "0.2.7",
4
4
  "description": "Codex coding preset with customizable prompts and tools for DSH.",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
@@ -22,6 +22,10 @@
22
22
  "types": "./lib/types/compaction.d.ts",
23
23
  "default": "./lib/compaction.js"
24
24
  },
25
+ "./compact-command": {
26
+ "types": "./lib/types/compact-command.d.ts",
27
+ "default": "./lib/types/compact-command.js"
28
+ },
25
29
  "./client": {
26
30
  "types": "./lib/types/client/index.d.ts",
27
31
  "default": "./lib/client.js"
@@ -74,6 +78,7 @@
74
78
  "@deepseek-ai/dsh-client-locale",
75
79
  "@deepseek-ai/dsh-client-runtime",
76
80
  "@deepseek-ai/dsh-client-ui-conversation",
81
+ "@deepseek-ai/dsh-client-ui-commands",
77
82
  "@deepseek-ai/dsh-client-ui-settings",
78
83
  "@deepseek-ai/dsh-client-ui-settings-plugins"
79
84
  ],
@@ -90,9 +95,11 @@
90
95
  "@deepseek-ai/dsh-client-locale": ">=0.1.0-rc.8",
91
96
  "@deepseek-ai/dsh-client-runtime": ">=0.1.0-rc.8",
92
97
  "@deepseek-ai/dsh-client-ui-conversation": ">=0.1.0-rc.8",
98
+ "@deepseek-ai/dsh-client-ui-commands": ">=0.1.0-rc.8",
93
99
  "@deepseek-ai/dsh-client-ui-settings": ">=0.1.0-rc.8",
94
100
  "@deepseek-ai/dsh-client-ui-settings-plugins": ">=0.1.0-rc.8",
95
101
  "@deepseek-ai/dsh-client-ui-slots": ">=0.1.0-rc.8",
102
+ "@deepseek-ai/dsh-commands": ">=0.1.0-rc.8",
96
103
  "@deepseek-ai/dsh-compaction": ">=0.1.0-rc.8",
97
104
  "@deepseek-ai/dsh-compaction-basic": ">=0.1.0-rc.8",
98
105
  "@deepseek-ai/dsh-compaction-tool-result-pruner": ">=0.1.0-rc.8",
@@ -131,6 +138,12 @@
131
138
  "@deepseek-ai/dsh-client-ui-conversation": {
132
139
  "optional": true
133
140
  },
141
+ "@deepseek-ai/dsh-client-ui-commands": {
142
+ "optional": true
143
+ },
144
+ "@deepseek-ai/dsh-commands": {
145
+ "optional": true
146
+ },
134
147
  "@deepseek-ai/dsh-client-ui-settings": {
135
148
  "optional": true
136
149
  },
@@ -77,7 +77,7 @@
77
77
  thresholdRatio: 0.95
78
78
 
79
79
  - id: command-compact
80
- name: '@deepseek-ai/dsh-command-compact'
80
+ name: '@shuind/dsh-codex-harness/compact-command'
81
81
 
82
82
  - id: tool-result-pruner
83
83
  name: '@deepseek-ai/dsh-compaction-tool-result-pruner'