@shuind/dsh-codex-harness 0.2.6 → 0.2.8

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
@@ -236,11 +236,6 @@ window.__ModuleLoader__.load({
236
236
  activityRequestingModel: "请求中...",
237
237
  activityModelReply: "回复中..."
238
238
  };
239
- function promptFromLayer(layer) {
240
- if (typeof layer !== "object" || layer === null || Array.isArray(layer)) return void 0;
241
- const value = layer["systemPrompt"];
242
- return typeof value === "string" ? value : void 0;
243
- }
244
239
  function CapabilityToggle({ field, label, hint, enabled, disabled, setSetting }) {
245
240
  return (0, react_jsx_runtime.jsxs)("label", {
246
241
  style: {
@@ -441,13 +436,12 @@ window.__ModuleLoader__.load({
441
436
  }
442
437
  /** Full-prompt editor contributed to Settings > Plugins. */
443
438
  function PromptSettingsCard(props) {
444
- const { useSettings, setSetting, unsetSetting, t } = props;
439
+ const { useSettings, setSetting, t } = props;
445
440
  const snapshot = useSettings((state) => state);
446
441
  const currentPersona = snapshot.value?.persona ?? DEFAULT_CODEX_PERSONA;
447
442
  const currentSourcePrompt = snapshot.value?.harnessSourcePrompt ?? DEFAULT_DSH_CORE_SOURCE_PROMPT;
448
443
  const currentWebPrompt = snapshot.value?.webSurfacePrompt ?? DEFAULT_DSH_CORE_WEB_PROMPT;
449
444
  const current = snapshot.value?.systemPrompt ?? DEFAULT_CODEX_SYSTEM_PROMPT;
450
- const inherited = promptFromLayer(snapshot.base) ?? DEFAULT_CODEX_SYSTEM_PROMPT;
451
445
  const codexOnlyCapabilities = [
452
446
  {
453
447
  field: "fastModeControlEnabled",
@@ -512,6 +506,7 @@ window.__ModuleLoader__.load({
512
506
  ]);
513
507
  if (snapshot.status === "unavailable") return null;
514
508
  const dirty = personaDraft !== currentPersona || sourcePromptDraft !== currentSourcePrompt || webPromptDraft !== currentWebPrompt || draft !== current;
509
+ const canRestore = dirty || currentPersona !== DEFAULT_CODEX_PERSONA || currentSourcePrompt !== DEFAULT_DSH_CORE_SOURCE_PROMPT || currentWebPrompt !== DEFAULT_DSH_CORE_WEB_PROMPT || current !== DEFAULT_CODEX_SYSTEM_PROMPT;
515
510
  const renderCapability = (capability) => (0, react_jsx_runtime.jsx)(CapabilityToggle, {
516
511
  field: capability.field,
517
512
  label: t(capability.label),
@@ -542,12 +537,14 @@ window.__ModuleLoader__.load({
542
537
  setPersonaDraft(DEFAULT_CODEX_PERSONA);
543
538
  setSourcePromptDraft(DEFAULT_DSH_CORE_SOURCE_PROMPT);
544
539
  setWebPromptDraft(DEFAULT_DSH_CORE_WEB_PROMPT);
545
- setDraft(inherited);
540
+ setDraft(DEFAULT_CODEX_SYSTEM_PROMPT);
546
541
  try {
547
- await unsetSetting("systemPrompt");
548
- await unsetSetting("persona");
549
- await unsetSetting("harnessSourcePrompt");
550
- await unsetSetting("webSurfacePrompt");
542
+ await Promise.all([
543
+ setSetting("persona", DEFAULT_CODEX_PERSONA),
544
+ setSetting("harnessSourcePrompt", DEFAULT_DSH_CORE_SOURCE_PROMPT),
545
+ setSetting("webSurfacePrompt", DEFAULT_DSH_CORE_WEB_PROMPT),
546
+ setSetting("systemPrompt", DEFAULT_CODEX_SYSTEM_PROMPT)
547
+ ]);
551
548
  } catch {
552
549
  setFailed(true);
553
550
  setPersonaDraft(currentPersona);
@@ -684,7 +681,7 @@ window.__ModuleLoader__.load({
684
681
  children: t("promptCustomizationLabel")
685
682
  }), (0, react_jsx_runtime.jsx)("button", {
686
683
  type: "button",
687
- disabled: !snapshot.writable || saving || !dirty,
684
+ disabled: !snapshot.writable || saving || !canRestore,
688
685
  onClick: () => {
689
686
  reset();
690
687
  },
@@ -765,6 +762,9 @@ window.__ModuleLoader__.load({
765
762
  type: "button",
766
763
  disabled: !dirty || saving,
767
764
  onClick: () => {
765
+ setPersonaDraft(currentPersona);
766
+ setSourcePromptDraft(currentSourcePrompt);
767
+ setWebPromptDraft(currentWebPrompt);
768
768
  setDraft(current);
769
769
  setFailed(false);
770
770
  },
@@ -1068,14 +1068,20 @@ window.__ModuleLoader__.load({
1068
1068
  }
1069
1069
  return null;
1070
1070
  }
1071
+ function isTurnStatus(status) {
1072
+ return status.textContent?.includes("Deep diving...") === true || status.className.toString().includes("turnStatus");
1073
+ }
1074
+ function hasLayout(status) {
1075
+ const rect = status.getBoundingClientRect();
1076
+ return rect.width > 0 && rect.height > 0;
1077
+ }
1078
+ /** Prefer the actual Core turn status over unrelated global status nodes. */
1079
+ function selectTurnStatus(statuses) {
1080
+ const preferred = statuses.filter(isTurnStatus);
1081
+ 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;
1082
+ }
1071
1083
  function findTurnStatus() {
1072
- let fallback = null;
1073
- for (const status of document.querySelectorAll("[role=\"status\"]")) {
1074
- if (status.closest("[data-chat-flow]") === null) continue;
1075
- fallback ??= status;
1076
- if (status.textContent?.includes("Deep diving...") === true || status.className.toString().includes("turnStatus")) return status;
1077
- }
1078
- return fallback;
1084
+ return selectTurnStatus([...document.querySelectorAll("[role=\"status\"]")]);
1079
1085
  }
1080
1086
  function useTurnStatusPosition(target) {
1081
1087
  const [position, setPosition] = (0, react.useState)(null);
@@ -1240,6 +1246,7 @@ window.__ModuleLoader__.load({
1240
1246
  exports.default = client_default;
1241
1247
  exports.inject = inject;
1242
1248
  exports.resolveActivity = resolveActivity;
1249
+ exports.selectTurnStatus = selectTurnStatus;
1243
1250
  return module.exports;
1244
1251
  }
1245
1252
  });
package/lib/compaction.js CHANGED
@@ -3,7 +3,20 @@ 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
- const COMPACTION_MODE = new AsyncLocalStorage();
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
+ })();
7
20
  /** Run one manual compaction with an explicit local/remote preference. */
8
21
  function runCodexCompactionMode(mode, task) {
9
22
  return COMPACTION_MODE.run(mode, task);
package/lib/index.js CHANGED
@@ -1273,7 +1273,20 @@ const CODEX_SETTINGS_SCHEMA = z.object({
1273
1273
  //#endregion
1274
1274
  //#region lib/types/compaction.js
1275
1275
  /** Codex compaction backend that honors the latest durable request capacity. */
1276
- const COMPACTION_MODE = new AsyncLocalStorage();
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
+ })();
1277
1290
  /** Read the explicit preference for the current compaction stream, if any. */
1278
1291
  function codexCompactionMode() {
1279
1292
  return COMPACTION_MODE.getStore();
@@ -117,6 +117,8 @@ export declare function ActivityLine({ sessionId: _sessionId, useSession, useSes
117
117
  top: number;
118
118
  };
119
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;
120
122
  export declare const inject: string[];
121
123
  /** Mount request controls and the plugin settings card through shared slots. */
122
124
  export declare function apply(ctx: Context): void;
@@ -121,12 +121,6 @@ const zh = {
121
121
  activityRequestingModel: '\u8bf7\u6c42\u4e2d...',
122
122
  activityModelReply: '\u56de\u590d\u4e2d...',
123
123
  };
124
- function promptFromLayer(layer) {
125
- if (typeof layer !== 'object' || layer === null || Array.isArray(layer))
126
- return undefined;
127
- const value = layer['systemPrompt'];
128
- return typeof value === 'string' ? value : undefined;
129
- }
130
124
  function CapabilityToggle({ field, label, hint, enabled, disabled, setSetting, }) {
131
125
  return (_jsxs("label", { style: {
132
126
  display: 'flex',
@@ -207,13 +201,12 @@ function PromptEditor({ id, label, hint, value, writable, saving, minHeight, onC
207
201
  }
208
202
  /** Full-prompt editor contributed to Settings > Plugins. */
209
203
  export function PromptSettingsCard(props) {
210
- const { useSettings, setSetting, unsetSetting, t } = props;
204
+ const { useSettings, setSetting, t } = props;
211
205
  const snapshot = useSettings(state => state);
212
206
  const currentPersona = snapshot.value?.persona ?? DEFAULT_CODEX_PERSONA;
213
207
  const currentSourcePrompt = snapshot.value?.harnessSourcePrompt ?? DEFAULT_DSH_CORE_SOURCE_PROMPT;
214
208
  const currentWebPrompt = snapshot.value?.webSurfacePrompt ?? DEFAULT_DSH_CORE_WEB_PROMPT;
215
209
  const current = snapshot.value?.systemPrompt ?? DEFAULT_CODEX_SYSTEM_PROMPT;
216
- const inherited = promptFromLayer(snapshot.base) ?? DEFAULT_CODEX_SYSTEM_PROMPT;
217
210
  const codexOnlyCapabilities = [
218
211
  { field: 'fastModeControlEnabled', label: 'capabilityFast', hint: 'capabilityFastHint' },
219
212
  { field: 'promptEnabled', label: 'capabilityPrompt', hint: 'capabilityPromptHint' },
@@ -245,6 +238,11 @@ export function PromptSettingsCard(props) {
245
238
  || sourcePromptDraft !== currentSourcePrompt
246
239
  || webPromptDraft !== currentWebPrompt
247
240
  || draft !== current;
241
+ const canRestore = dirty
242
+ || currentPersona !== DEFAULT_CODEX_PERSONA
243
+ || currentSourcePrompt !== DEFAULT_DSH_CORE_SOURCE_PROMPT
244
+ || currentWebPrompt !== DEFAULT_DSH_CORE_WEB_PROMPT
245
+ || current !== DEFAULT_CODEX_SYSTEM_PROMPT;
248
246
  const renderCapability = (capability) => (_jsx(CapabilityToggle, { field: capability.field, label: t(capability.label), hint: t(capability.hint), enabled: snapshot.value?.[capability.field] ?? true, disabled: !snapshot.writable || saving, setSetting: setSetting }, capability.field));
249
247
  const save = async () => {
250
248
  setSaving(true);
@@ -270,12 +268,14 @@ export function PromptSettingsCard(props) {
270
268
  setPersonaDraft(DEFAULT_CODEX_PERSONA);
271
269
  setSourcePromptDraft(DEFAULT_DSH_CORE_SOURCE_PROMPT);
272
270
  setWebPromptDraft(DEFAULT_DSH_CORE_WEB_PROMPT);
273
- setDraft(inherited);
271
+ setDraft(DEFAULT_CODEX_SYSTEM_PROMPT);
274
272
  try {
275
- await unsetSetting('systemPrompt');
276
- await unsetSetting('persona');
277
- await unsetSetting('harnessSourcePrompt');
278
- await unsetSetting('webSurfacePrompt');
273
+ await Promise.all([
274
+ setSetting('persona', DEFAULT_CODEX_PERSONA),
275
+ setSetting('harnessSourcePrompt', DEFAULT_DSH_CORE_SOURCE_PROMPT),
276
+ setSetting('webSurfacePrompt', DEFAULT_DSH_CORE_WEB_PROMPT),
277
+ setSetting('systemPrompt', DEFAULT_CODEX_SYSTEM_PROMPT),
278
+ ]);
279
279
  }
280
280
  catch {
281
281
  setFailed(true);
@@ -317,14 +317,20 @@ export function PromptSettingsCard(props) {
317
317
  gap: 14,
318
318
  paddingTop: 12,
319
319
  borderTop: '1px solid var(--dsw-alias-border-l2)',
320
- }, children: [_jsxs("div", { style: { display: 'flex', alignItems: 'center', gap: 8 }, children: [_jsx("strong", { style: { flex: 1, fontSize: 13 }, children: t('promptCustomizationLabel') }), _jsx("button", { type: "button", disabled: !snapshot.writable || saving || !dirty, onClick: () => { void reset(); }, style: { border: 0, padding: 0, background: 'none', color: 'var(--dsw-alias-label-secondary)', font: 'inherit', fontSize: 11, cursor: 'pointer' }, children: t('promptRestoreAll') })] }), _jsx(PromptEditor, { id: "codex-persona", label: t('personaLabel'), hint: t('personaHint'), value: personaDraft, writable: snapshot.writable, saving: saving, minHeight: 84, onChange: setPersonaDraft }), _jsx(PromptEditor, { id: "codex-harness-source-prompt", label: t('sourcePromptLabel'), hint: t('sourcePromptHint'), value: sourcePromptDraft, writable: snapshot.writable, saving: saving, minHeight: 100, onChange: setSourcePromptDraft }), _jsx(PromptEditor, { id: "codex-web-surface-prompt", label: t('webPromptLabel'), hint: t('webPromptHint'), value: webPromptDraft, writable: snapshot.writable, saving: saving, minHeight: 120, onChange: setWebPromptDraft }), _jsx(PromptEditor, { id: "codex-system-prompt", label: t('promptLabel'), hint: t('promptHint'), value: draft, writable: snapshot.writable, saving: saving, minHeight: 320, onChange: setDraft })] }), _jsxs("div", { style: {
320
+ }, children: [_jsxs("div", { style: { display: 'flex', alignItems: 'center', gap: 8 }, children: [_jsx("strong", { style: { flex: 1, fontSize: 13 }, children: t('promptCustomizationLabel') }), _jsx("button", { type: "button", disabled: !snapshot.writable || saving || !canRestore, onClick: () => { void reset(); }, style: { border: 0, padding: 0, background: 'none', color: 'var(--dsw-alias-label-secondary)', font: 'inherit', fontSize: 11, cursor: 'pointer' }, children: t('promptRestoreAll') })] }), _jsx(PromptEditor, { id: "codex-persona", label: t('personaLabel'), hint: t('personaHint'), value: personaDraft, writable: snapshot.writable, saving: saving, minHeight: 84, onChange: setPersonaDraft }), _jsx(PromptEditor, { id: "codex-harness-source-prompt", label: t('sourcePromptLabel'), hint: t('sourcePromptHint'), value: sourcePromptDraft, writable: snapshot.writable, saving: saving, minHeight: 100, onChange: setSourcePromptDraft }), _jsx(PromptEditor, { id: "codex-web-surface-prompt", label: t('webPromptLabel'), hint: t('webPromptHint'), value: webPromptDraft, writable: snapshot.writable, saving: saving, minHeight: 120, onChange: setWebPromptDraft }), _jsx(PromptEditor, { id: "codex-system-prompt", label: t('promptLabel'), hint: t('promptHint'), value: draft, writable: snapshot.writable, saving: saving, minHeight: 320, onChange: setDraft })] }), _jsxs("div", { style: {
321
321
  display: 'flex',
322
322
  justifyContent: 'flex-end',
323
323
  alignItems: 'center',
324
324
  gap: 8,
325
325
  paddingTop: 12,
326
326
  borderTop: '1px solid var(--dsw-alias-border-l2)',
327
- }, 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') })] })] }))] }));
327
+ }, 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: () => {
328
+ setPersonaDraft(currentPersona);
329
+ setSourcePromptDraft(currentSourcePrompt);
330
+ setWebPromptDraft(currentWebPrompt);
331
+ setDraft(current);
332
+ setFailed(false);
333
+ }, 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') })] })] }))] }));
328
334
  }
329
335
  /** The legacy composer seat is a compact inline row, not a menu panel. */
330
336
  function FastModeFallback(props) {
@@ -488,17 +494,25 @@ function findContextMeterDialog() {
488
494
  }
489
495
  return null;
490
496
  }
497
+ function isTurnStatus(status) {
498
+ return status.textContent?.includes('Deep diving...') === true
499
+ || status.className.toString().includes('turnStatus');
500
+ }
501
+ function hasLayout(status) {
502
+ const rect = status.getBoundingClientRect();
503
+ return rect.width > 0 && rect.height > 0;
504
+ }
505
+ /** Prefer the actual Core turn status over unrelated global status nodes. */
506
+ export function selectTurnStatus(statuses) {
507
+ const preferred = statuses.filter(isTurnStatus);
508
+ return preferred.findLast(hasLayout)
509
+ ?? preferred.at(-1)
510
+ ?? statuses.filter(status => status.closest('[data-chat-flow]') !== null).findLast(hasLayout)
511
+ ?? statuses.filter(status => status.closest('[data-chat-flow]') !== null).at(-1)
512
+ ?? null;
513
+ }
491
514
  function findTurnStatus() {
492
- let fallback = null;
493
- for (const status of document.querySelectorAll('[role="status"]')) {
494
- if (status.closest('[data-chat-flow]') === null)
495
- continue;
496
- fallback ??= status;
497
- if (status.textContent?.includes('Deep diving...') === true
498
- || status.className.toString().includes('turnStatus'))
499
- return status;
500
- }
501
- return fallback;
515
+ return selectTurnStatus([...document.querySelectorAll('[role="status"]')]);
502
516
  }
503
517
  function useTurnStatusPosition(target) {
504
518
  const [position, setPosition] = useState(null);
@@ -2,7 +2,21 @@
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
- const COMPACTION_MODE = new AsyncLocalStorage();
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
+ })();
6
20
  /** Run one manual compaction with an explicit local/remote preference. */
7
21
  export function runCodexCompactionMode(mode, task) {
8
22
  return COMPACTION_MODE.run(mode, task);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shuind/dsh-codex-harness",
3
- "version": "0.2.6",
3
+ "version": "0.2.8",
4
4
  "description": "Codex coding preset with customizable prompts and tools for DSH.",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",