@shuind/dsh-codex-harness 0.1.25 → 0.1.27

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/README.md CHANGED
@@ -9,17 +9,18 @@
9
9
  - **后台任务**:`exec_command` 支持 `run_in_background: true`,立即返回 DSH `job_id`;使用 `job_output` 读取输出、`job_kill` 停止任务。任务完成时,忙碌中的 agent 会在下一步收到 inbox 注入;空闲 agent 默认保持安静,等下一次唤醒时再处理完成消息。
10
10
  - **GPT 能力补全**:为 GPT 系列模型补充图片输入和思考强度选项;不会覆盖用户已有的显式配置。
11
11
  - **Fast**:仅在 Codex preset 的模型选择菜单中显示,开启后向 Responses 请求发送 `service_tier: "priority"`。
12
- - **旧版 Web 兼容**:在未提供新版模型设置/上下文设置 slot 的 DSH Web 中,Fast 和上下文容量会自动回退到旧版 composer slot;client 注入不依赖纯类型 slot 包。
12
+ - **旧版 Web 兼容**:在未提供新版模型设置/上下文设置 slot 的 DSH Web 中,Fast 和上下文容量会自动回退到旧版 composer inline slot;上下文容量使用紧凑按钮和弹层,不占用整行;client 注入不依赖纯类型 slot 包。
13
13
  - **Responses 原生 apply_patch**:在 GPT Responses 请求的插件传输边界,把普通 JSON function tool 改写为 `type: "custom"` + OpenAI `lark` grammar;下一轮历史同步改写为 `custom_tool_call`。如果中转站拒绝 custom tool,则自动回退到普通 function tool,不改变 DSH 工具执行器。
14
14
  - **远程搜索与压缩**:OpenAI Responses 请求默认优先使用 hosted `web_search` 和 `/responses/compact`;失败时回退到 DSH 的本地实现。
15
15
  - **远程压缩用量**:`/responses/compact` 返回标准 `usage` 时,插件会把 `input_tokens`、缓存读写和 `output_tokens` 原样拆分为 DSH 的用量字段;不再把远程压缩伪造成 `0`。中转站缺失或返回不一致的 usage 时,插件不会编造数字。
16
16
  - **上下文容量**:在 Web 中设置 `1K`–`1000K` tokens,设置值作用于下一次请求。
17
+ - **自动压缩阈值**:Codex preset 的自动压缩会读取最新请求持久化的有效上下文容量;例如设置 `400K` 时,默认 `80%` pressure threshold 是 `320K`,不会错误地按适配器默认 `262,144` 在约 `210K` 提前触发。
17
18
  - **活动状态**:Codex 请求模型、接收模型回复或进行上下文压缩时,在 `Deep diving...` 右侧显示对应阶段和耗时,让长时间 Deep Diving 不再像卡住。
18
19
 
19
20
  ## 安装
20
21
 
21
22
  ```sh
22
- dsh plugin --profile web add @shuind/dsh-codex-harness@0.1.24
23
+ dsh plugin --profile web add @shuind/dsh-codex-harness@0.1.27
23
24
  ```
24
25
 
25
26
  重启 Web,创建新会话,在模式菜单中选择 **Codex 模式**。
@@ -52,7 +53,7 @@ Fast 设置保存在 `codex` 命名空间,只对 Codex preset 生效。
52
53
 
53
54
  ### 上下文容量
54
55
 
55
- 点击 Web 顶部的上下文使用量指示器,可以设置下一次请求的上下文容量。上方 meter 显示当前请求的实际容量;修改设置后,需要发送下一次请求才会更新。
56
+ 点击 Web 顶部的上下文使用量指示器,可以设置下一次请求的上下文容量。上方 meter 显示当前请求的实际容量;修改设置后,需要发送下一次请求才会更新。Codex preset 的自动压缩也使用这个已经持久化的有效容量。
56
57
 
57
58
  上下文容量使用整数 K tokens,范围为 `1K` 到 `1000K`。实际可用上限仍取决于模型和中转站支持情况。
58
59
 
@@ -106,7 +107,7 @@ description: 使用 Codex 工具并开启可选协作提示词。
106
107
  order: 10
107
108
  ```
108
109
 
109
- 然后在 Web 的 **Agent 预设** 中选择 `My Codex`,再新建会话。这个 preset 会加载 Codex 工具,并开启协作提示词;网页搜索、远程压缩、后台任务控制和 Skills 等其他功能需要在同一个 `agent.cordis.yml` 中按需添加。
110
+ 然后在 Web 的 **Agent 预设** 中选择 `My Codex`,再新建会话。这个 preset 会加载 Codex 工具,并开启协作提示词;网页搜索、远程压缩、后台任务控制和 Skills 等其他功能需要在同一个 `agent.cordis.yml` 中按需添加。若希望自定义 preset 也修正自动压缩阈值,请在 compaction 隔离组中使用 `@shuind/dsh-codex-harness/compaction` 替代 `@deepseek-ai/dsh-compaction-basic`。
110
111
 
111
112
  ### 可选协作提示词(私货)
112
113
 
package/lib/client.js CHANGED
@@ -21,6 +21,10 @@ window.__ModuleLoader__.load({
21
21
  //#endregion
22
22
  //#region lib/types/client/activity.js
23
23
  /** Client-only inference used while the host activity projection frame is in flight. */
24
+ /** Equality for selector hooks, whose default is reference identity. */
25
+ function sameModelActivity(left, right) {
26
+ return left?.activity === right?.activity && left?.startedAt === right?.startedAt;
27
+ }
24
28
  /** Infer the request-phase clock from the existing conversation snapshot. */
25
29
  function awaitingModelStartedAt(snapshot) {
26
30
  if (!snapshot.running || snapshot.runningCalls.length > 0) return void 0;
@@ -73,7 +77,7 @@ window.__ModuleLoader__.load({
73
77
  const ACTIVITY_SLOT = "conversation.chat.status";
74
78
  const ACTIVITY_FALLBACK_SLOT = "conversation.composer.dock";
75
79
  const FAST_FALLBACK_SLOT = "conversation.input.right";
76
- const CONTEXT_FALLBACK_SLOT = "conversation.input.dock";
80
+ const CONTEXT_FALLBACK_SLOT = "conversation.input.right";
77
81
  const DEFAULT_CONTEXT_WINDOW = 262144;
78
82
  const en = {
79
83
  fast: "Fast mode",
@@ -113,6 +117,9 @@ window.__ModuleLoader__.load({
113
117
  "aria-pressed": fast,
114
118
  "aria-label": fast ? t("fastOn") : t("fastOff"),
115
119
  title: fast ? t("fastOn") : t("fastOff"),
120
+ onMouseDown: (event) => {
121
+ event.preventDefault();
122
+ },
116
123
  onClick: () => {
117
124
  setSetting("fast", !fast);
118
125
  },
@@ -167,9 +174,9 @@ window.__ModuleLoader__.load({
167
174
  alignItems: "center",
168
175
  gap: 5,
169
176
  height: 28,
170
- border: "1px solid var(--dsw-alias-border-primary)",
177
+ border: 0,
171
178
  borderRadius: 7,
172
- padding: "0 8px",
179
+ padding: "0 6px",
173
180
  color: fast ? "var(--dsw-static-blue-500)" : "var(--dsw-alias-label-secondary)",
174
181
  background: fast ? "var(--dsw-alias-interactive-bg-selected)" : "transparent",
175
182
  cursor: snapshot.writable === false ? "default" : "pointer",
@@ -308,10 +315,110 @@ window.__ModuleLoader__.load({
308
315
  const pressure = useProjection("contextPressure");
309
316
  return pressure?.contextWindow !== void 0 && pressure.contextWindow > 0 ? pressure.contextWindow : DEFAULT_CONTEXT_WINDOW;
310
317
  }
311
- function LegacyContextSizeControl({ useProjection, ...props }) {
312
- return (0, react_jsx_runtime.jsx)(ContextSizeControl, {
313
- ...props,
314
- contextWindow: contextWindowFromProjection(useProjection)
318
+ /** Compact trigger used when the host has no ContextMeter settings child slot. */
319
+ function LegacyContextSizeControl({ sessionId, useSessions, useProjection, useSettings, setSetting, unsetSetting, t }) {
320
+ const agentPreset = useSessions((state) => state.byId[sessionId]?.agentPreset);
321
+ const contextWindow = contextWindowFromProjection(useProjection);
322
+ const snapshot = useSettings((state) => state);
323
+ const configured = snapshot.value?.contextWindow;
324
+ const valueK = Math.min(CODEX_CONTEXT_MAX / CODEX_CONTEXT_UNIT, Math.max(1, Math.round((configured ?? contextWindow) / CODEX_CONTEXT_UNIT)));
325
+ const [open, setOpen] = (0, react.useState)(false);
326
+ const rootRef = (0, react.useRef)(null);
327
+ (0, react.useEffect)(() => {
328
+ if (!open) return void 0;
329
+ const onPointerDown = (event) => {
330
+ if (event.target instanceof Node && rootRef.current?.contains(event.target) === true) return;
331
+ setOpen(false);
332
+ };
333
+ const onKeyDown = (event) => {
334
+ if (event.key === "Escape") setOpen(false);
335
+ };
336
+ document.addEventListener("pointerdown", onPointerDown);
337
+ document.addEventListener("keydown", onKeyDown);
338
+ return () => {
339
+ document.removeEventListener("pointerdown", onPointerDown);
340
+ document.removeEventListener("keydown", onKeyDown);
341
+ };
342
+ }, [open]);
343
+ if (!isCodexPresetId(agentPreset)) return null;
344
+ return (0, react_jsx_runtime.jsxs)("span", {
345
+ ref: rootRef,
346
+ style: {
347
+ position: "relative",
348
+ display: "inline-flex",
349
+ alignItems: "center"
350
+ },
351
+ children: [(0, react_jsx_runtime.jsxs)("button", {
352
+ type: "button",
353
+ "aria-label": `${t("contextSize")}: ${valueK}K`,
354
+ "aria-haspopup": "dialog",
355
+ "aria-expanded": open,
356
+ disabled: snapshot.writable === false,
357
+ title: t("contextSize"),
358
+ onMouseDown: (event) => {
359
+ event.preventDefault();
360
+ },
361
+ onClick: () => {
362
+ setOpen((value) => !value);
363
+ },
364
+ style: {
365
+ boxSizing: "border-box",
366
+ display: "inline-flex",
367
+ alignItems: "center",
368
+ gap: 3,
369
+ height: 28,
370
+ border: 0,
371
+ borderRadius: 7,
372
+ padding: "0 6px",
373
+ color: configured === void 0 ? "var(--dsw-alias-label-secondary)" : "var(--dsw-static-blue-500)",
374
+ background: open ? "var(--dsw-alias-interactive-bg-hover)" : "transparent",
375
+ cursor: snapshot.writable === false ? "default" : "pointer",
376
+ font: "inherit",
377
+ fontSize: 12,
378
+ lineHeight: "20px",
379
+ fontWeight: configured === void 0 ? 400 : 600,
380
+ whiteSpace: "nowrap"
381
+ },
382
+ children: [(0, react_jsx_runtime.jsxs)("span", { children: [valueK, "K"] }), (0, react_jsx_runtime.jsx)("svg", {
383
+ viewBox: "0 0 12 12",
384
+ width: "12",
385
+ height: "12",
386
+ "aria-hidden": true,
387
+ children: (0, react_jsx_runtime.jsx)("path", {
388
+ d: "M3 4.5 6 7.5 9 4.5",
389
+ fill: "none",
390
+ stroke: "currentColor",
391
+ strokeWidth: "1.25",
392
+ strokeLinecap: "round",
393
+ strokeLinejoin: "round"
394
+ })
395
+ })]
396
+ }), open && (0, react_jsx_runtime.jsx)("div", {
397
+ role: "dialog",
398
+ "aria-label": t("contextSize"),
399
+ style: {
400
+ position: "absolute",
401
+ right: 0,
402
+ bottom: "calc(100% + 8px)",
403
+ zIndex: 20,
404
+ boxSizing: "border-box",
405
+ width: 300,
406
+ maxWidth: "calc(100vw - 24px)",
407
+ padding: "10px 12px 12px",
408
+ border: "1px solid var(--dsw-alias-border-l2)",
409
+ borderRadius: 10,
410
+ color: "var(--dsw-alias-label-primary)",
411
+ background: "var(--dsw-alias-bg-base)",
412
+ boxShadow: "var(--dsw-shadow-lv2)"
413
+ },
414
+ children: (0, react_jsx_runtime.jsx)(ContextSizeControl, {
415
+ contextWindow,
416
+ useSettings,
417
+ setSetting,
418
+ unsetSetting,
419
+ t
420
+ })
421
+ })]
315
422
  });
316
423
  }
317
424
  function elapsedSeconds(startedAt, now) {
@@ -320,7 +427,7 @@ window.__ModuleLoader__.load({
320
427
  function ActivityLine({ sessionId, useSession, useSessions, useProjection, t }) {
321
428
  const agentPreset = useSessions((state) => state.byId[sessionId]?.agentPreset);
322
429
  const projectedActivity = useProjection("codexActivity");
323
- const fallbackActivity = useSession((snapshot) => modelActivity(snapshot));
430
+ const fallbackActivity = useSession(modelActivity, sameModelActivity);
324
431
  const normalizedProjectedActivity = projectedActivity?.activity === "awaiting-model" ? {
325
432
  activity: fallbackActivity?.activity ?? "requesting-model",
326
433
  startedAt: fallbackActivity?.startedAt ?? projectedActivity.startedAt
@@ -0,0 +1,45 @@
1
+ import { AsyncLocalStorage } from "node:async_hooks";
2
+ import BasicCompactionEngine from "@deepseek-ai/dsh-compaction-basic";
3
+ //#region lib/types/compaction.js
4
+ /** Codex compaction backend that honors the latest durable request capacity. */
5
+ /** Overlay only the capacity lookup used by pressure compaction. */
6
+ function withDurableContextCapacity(llm, activeSession) {
7
+ return new Proxy(llm, { get(target, property) {
8
+ if (property === "resolveModelInfo") return async (provider, model, signal) => {
9
+ const info = await target.resolveModelInfo(provider, model, signal);
10
+ const requestContext = activeSession.getStore()?.requestContext();
11
+ if (requestContext?.provider !== provider || requestContext.model !== model || requestContext.contextWindow === void 0) return info;
12
+ return {
13
+ ...info,
14
+ context: {
15
+ ...info.context,
16
+ contextWindow: requestContext.contextWindow
17
+ }
18
+ };
19
+ };
20
+ const value = Reflect.get(target, property, target);
21
+ return typeof value === "function" ? value.bind(target) : value;
22
+ } });
23
+ }
24
+ /**
25
+ * Keep the upstream compaction policy, retention, overflow recovery, and
26
+ * transaction implementation intact. The scoped LLM seam changes only the
27
+ * context metadata returned during a pressure check.
28
+ */
29
+ var CodexCompactionEngine = class extends BasicCompactionEngine {
30
+ static inject = BasicCompactionEngine.inject;
31
+ static Config = BasicCompactionEngine.Config;
32
+ activeSession;
33
+ constructor(ctx, config = {}) {
34
+ const activeSession = new AsyncLocalStorage();
35
+ const llm = ctx.get("llm");
36
+ if (llm === void 0) throw new Error("codex compaction requires ctx.llm");
37
+ super(ctx.extend({ llm: withDurableContextCapacity(llm, activeSession) }), config);
38
+ this.activeSession = activeSession;
39
+ }
40
+ compactIfNeeded(agent, trigger, signal) {
41
+ return this.activeSession.run(agent.session, () => super.compactIfNeeded(agent, trigger, signal));
42
+ }
43
+ };
44
+ //#endregion
45
+ export { CodexCompactionEngine as default };
@@ -8,6 +8,8 @@ export type CodexModelActivity = {
8
8
  activity: 'requesting-model' | 'model-reply';
9
9
  startedAt: number;
10
10
  };
11
+ /** Equality for selector hooks, whose default is reference identity. */
12
+ export declare function sameModelActivity(left: CodexModelActivity | undefined, right: CodexModelActivity | undefined): boolean;
11
13
  /** Infer the request-phase clock from the existing conversation snapshot. */
12
14
  export declare function awaitingModelStartedAt(snapshot: ActivitySessionSnapshot): number | undefined;
13
15
  /** Infer the first non-empty model token timestamp from the current snapshot. */
@@ -1,4 +1,8 @@
1
1
  /** Client-only inference used while the host activity projection frame is in flight. */
2
+ /** Equality for selector hooks, whose default is reference identity. */
3
+ export function sameModelActivity(left, right) {
4
+ return left?.activity === right?.activity && left?.startedAt === right?.startedAt;
5
+ }
2
6
  /** Infer the request-phase clock from the existing conversation snapshot. */
3
7
  export function awaitingModelStartedAt(snapshot) {
4
8
  if (!snapshot.running || snapshot.runningCalls.length > 0)
@@ -1,8 +1,8 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  /** Browser controls for the Codex request settings mounted by the Host plugin. */
3
- import { useEffect, useState } from 'react';
3
+ import { useEffect, useRef, useState } from 'react';
4
4
  import { CODEX_CONTEXT_MAX, CODEX_CONTEXT_UNIT, isCodexPresetId } from "../context.js";
5
- import { modelActivity } from "./activity.js";
5
+ import { modelActivity, sameModelActivity } from "./activity.js";
6
6
  const NS = 'codex';
7
7
  const SETTINGS_NAMESPACE = 'codex';
8
8
  const MODEL_SETTINGS_SLOT = 'conversation.input.model.settings';
@@ -12,7 +12,7 @@ const CONTEXT_SETTINGS_SLOT = 'conversation.input.context.settings';
12
12
  const ACTIVITY_SLOT = 'conversation.chat.status';
13
13
  const ACTIVITY_FALLBACK_SLOT = 'conversation.composer.dock';
14
14
  const FAST_FALLBACK_SLOT = 'conversation.input.right';
15
- const CONTEXT_FALLBACK_SLOT = 'conversation.input.dock';
15
+ const CONTEXT_FALLBACK_SLOT = 'conversation.input.right';
16
16
  const DEFAULT_CONTEXT_WINDOW = 262_144;
17
17
  const en = {
18
18
  fast: 'Fast mode',
@@ -46,7 +46,7 @@ function FastModeButton({ sessionId, useSessions, useSettings, setSetting, t })
46
46
  const fast = snapshot.value?.fast ?? false;
47
47
  if (!isCodexPresetId(agentPreset))
48
48
  return null;
49
- return (_jsxs("button", { type: "button", role: "menuitemcheckbox", disabled: snapshot.writable === false, "aria-pressed": fast, "aria-label": fast ? t('fastOn') : t('fastOff'), title: fast ? t('fastOn') : t('fastOff'), onClick: () => { void setSetting('fast', !fast); }, style: {
49
+ return (_jsxs("button", { type: "button", role: "menuitemcheckbox", disabled: snapshot.writable === false, "aria-pressed": fast, "aria-label": fast ? t('fastOn') : t('fastOff'), title: fast ? t('fastOn') : t('fastOff'), onMouseDown: event => { event.preventDefault(); }, onClick: () => { void setSetting('fast', !fast); }, style: {
50
50
  boxSizing: 'border-box',
51
51
  display: 'flex',
52
52
  alignItems: 'center',
@@ -80,9 +80,9 @@ function FastModeFallback(props) {
80
80
  alignItems: 'center',
81
81
  gap: 5,
82
82
  height: 28,
83
- border: '1px solid var(--dsw-alias-border-primary)',
83
+ border: 0,
84
84
  borderRadius: 7,
85
- padding: '0 8px',
85
+ padding: '0 6px',
86
86
  color: fast ? 'var(--dsw-static-blue-500)' : 'var(--dsw-alias-label-secondary)',
87
87
  background: fast ? 'var(--dsw-alias-interactive-bg-selected)' : 'transparent',
88
88
  cursor: snapshot.writable === false ? 'default' : 'pointer',
@@ -134,8 +134,70 @@ function contextWindowFromProjection(useProjection) {
134
134
  ? pressure.contextWindow
135
135
  : DEFAULT_CONTEXT_WINDOW;
136
136
  }
137
- function LegacyContextSizeControl({ useProjection, ...props }) {
138
- return _jsx(ContextSizeControl, { ...props, contextWindow: contextWindowFromProjection(useProjection) });
137
+ /** Compact trigger used when the host has no ContextMeter settings child slot. */
138
+ function LegacyContextSizeControl({ sessionId, useSessions, useProjection, useSettings, setSetting, unsetSetting, t }) {
139
+ const agentPreset = useSessions(state => state.byId[sessionId]?.agentPreset);
140
+ const contextWindow = contextWindowFromProjection(useProjection);
141
+ const snapshot = useSettings(state => state);
142
+ const configured = snapshot.value?.contextWindow;
143
+ const valueK = Math.min(CODEX_CONTEXT_MAX / CODEX_CONTEXT_UNIT, Math.max(1, Math.round((configured ?? contextWindow) / CODEX_CONTEXT_UNIT)));
144
+ const [open, setOpen] = useState(false);
145
+ const rootRef = useRef(null);
146
+ useEffect(() => {
147
+ if (!open)
148
+ return undefined;
149
+ const onPointerDown = (event) => {
150
+ if (event.target instanceof Node && rootRef.current?.contains(event.target) === true)
151
+ return;
152
+ setOpen(false);
153
+ };
154
+ const onKeyDown = (event) => {
155
+ if (event.key === 'Escape')
156
+ setOpen(false);
157
+ };
158
+ document.addEventListener('pointerdown', onPointerDown);
159
+ document.addEventListener('keydown', onKeyDown);
160
+ return () => {
161
+ document.removeEventListener('pointerdown', onPointerDown);
162
+ document.removeEventListener('keydown', onKeyDown);
163
+ };
164
+ }, [open]);
165
+ if (!isCodexPresetId(agentPreset))
166
+ return null;
167
+ return (_jsxs("span", { ref: rootRef, style: { position: 'relative', display: 'inline-flex', alignItems: 'center' }, children: [_jsxs("button", { type: "button", "aria-label": `${t('contextSize')}: ${valueK}K`, "aria-haspopup": "dialog", "aria-expanded": open, disabled: snapshot.writable === false, title: t('contextSize'), onMouseDown: event => { event.preventDefault(); }, onClick: () => { setOpen(value => !value); }, style: {
168
+ boxSizing: 'border-box',
169
+ display: 'inline-flex',
170
+ alignItems: 'center',
171
+ gap: 3,
172
+ height: 28,
173
+ border: 0,
174
+ borderRadius: 7,
175
+ padding: '0 6px',
176
+ color: configured === undefined
177
+ ? 'var(--dsw-alias-label-secondary)'
178
+ : 'var(--dsw-static-blue-500)',
179
+ background: open ? 'var(--dsw-alias-interactive-bg-hover)' : 'transparent',
180
+ cursor: snapshot.writable === false ? 'default' : 'pointer',
181
+ font: 'inherit',
182
+ fontSize: 12,
183
+ lineHeight: '20px',
184
+ fontWeight: configured === undefined ? 400 : 600,
185
+ whiteSpace: 'nowrap',
186
+ }, children: [_jsxs("span", { children: [valueK, "K"] }), _jsx("svg", { viewBox: "0 0 12 12", width: "12", height: "12", "aria-hidden": true, children: _jsx("path", { d: "M3 4.5 6 7.5 9 4.5", fill: "none", stroke: "currentColor", strokeWidth: "1.25", strokeLinecap: "round", strokeLinejoin: "round" }) })] }), open && (_jsx("div", { role: "dialog", "aria-label": t('contextSize'), style: {
187
+ position: 'absolute',
188
+ right: 0,
189
+ bottom: 'calc(100% + 8px)',
190
+ zIndex: 20,
191
+ boxSizing: 'border-box',
192
+ width: 300,
193
+ maxWidth: 'calc(100vw - 24px)',
194
+ padding: '10px 12px 12px',
195
+ border: '1px solid var(--dsw-alias-border-l2)',
196
+ borderRadius: 10,
197
+ color: 'var(--dsw-alias-label-primary)',
198
+ background: 'var(--dsw-alias-bg-base)',
199
+ boxShadow: 'var(--dsw-shadow-lv2)',
200
+ }, children: _jsx(ContextSizeControl, { contextWindow: contextWindow, useSettings: useSettings, setSetting: setSetting, unsetSetting: unsetSetting, t: t }) }))] }));
139
201
  }
140
202
  function elapsedSeconds(startedAt, now) {
141
203
  return Math.max(0, Math.floor((now - startedAt) / 1_000));
@@ -148,7 +210,7 @@ export function ActivityLine({ sessionId, useSession, useSessions, useProjection
148
210
  // The projection is the authoritative phase and clock. The session snapshot
149
211
  // fallback only covers the short wire gap before the next projection frame;
150
212
  // tool calls intentionally remain silent because their cards own the status.
151
- const fallbackActivity = useSession((snapshot) => modelActivity(snapshot));
213
+ const fallbackActivity = useSession(modelActivity, sameModelActivity);
152
214
  // `undefined` means the key has not arrived yet; `null` is an authoritative
153
215
  // clear and must not be resurrected by the local snapshot fallback.
154
216
  const normalizedProjectedActivity = projectedActivity?.activity === 'awaiting-model'
@@ -0,0 +1,18 @@
1
+ /** Codex compaction backend that honors the latest durable request capacity. */
2
+ import { Context } from '@deepseek-ai/cordis';
3
+ import BasicCompactionEngine from '@deepseek-ai/dsh-compaction-basic';
4
+ import type { CompactionResult, CompactionTrigger } from '@deepseek-ai/dsh-compaction';
5
+ import type { Agent } from '@deepseek-ai/dsh-agent';
6
+ /**
7
+ * Keep the upstream compaction policy, retention, overflow recovery, and
8
+ * transaction implementation intact. The scoped LLM seam changes only the
9
+ * context metadata returned during a pressure check.
10
+ */
11
+ export default class CodexCompactionEngine extends BasicCompactionEngine {
12
+ static inject: string[];
13
+ static Config: import("@deepseek-ai/schemastery").default<import("@deepseek-ai/dsh-compaction-basic").BasicCompactionConfig>;
14
+ private readonly activeSession;
15
+ constructor(ctx: Context, config?: ConstructorParameters<typeof BasicCompactionEngine>[1]);
16
+ compactIfNeeded(agent: Agent, trigger: CompactionTrigger, signal: AbortSignal): Promise<CompactionResult | null>;
17
+ }
18
+ //# sourceMappingURL=compaction.d.ts.map
@@ -0,0 +1,48 @@
1
+ /** Codex compaction backend that honors the latest durable request capacity. */
2
+ import { AsyncLocalStorage } from 'node:async_hooks';
3
+ import BasicCompactionEngine from '@deepseek-ai/dsh-compaction-basic';
4
+ /** Overlay only the capacity lookup used by pressure compaction. */
5
+ function withDurableContextCapacity(llm, activeSession) {
6
+ return new Proxy(llm, {
7
+ get(target, property) {
8
+ if (property === 'resolveModelInfo') {
9
+ return async (provider, model, signal) => {
10
+ const info = await target.resolveModelInfo(provider, model, signal);
11
+ const requestContext = activeSession.getStore()?.requestContext();
12
+ if (requestContext?.provider !== provider
13
+ || requestContext.model !== model
14
+ || requestContext.contextWindow === undefined)
15
+ return info;
16
+ return {
17
+ ...info,
18
+ context: { ...info.context, contextWindow: requestContext.contextWindow },
19
+ };
20
+ };
21
+ }
22
+ const value = Reflect.get(target, property, target);
23
+ return typeof value === 'function' ? value.bind(target) : value;
24
+ },
25
+ });
26
+ }
27
+ /**
28
+ * Keep the upstream compaction policy, retention, overflow recovery, and
29
+ * transaction implementation intact. The scoped LLM seam changes only the
30
+ * context metadata returned during a pressure check.
31
+ */
32
+ export default class CodexCompactionEngine extends BasicCompactionEngine {
33
+ static inject = BasicCompactionEngine.inject;
34
+ static Config = BasicCompactionEngine.Config;
35
+ activeSession;
36
+ constructor(ctx, config = {}) {
37
+ const activeSession = new AsyncLocalStorage();
38
+ const llm = ctx.get('llm');
39
+ if (llm === undefined)
40
+ throw new Error('codex compaction requires ctx.llm');
41
+ super(ctx.extend({ llm: withDurableContextCapacity(llm, activeSession) }), config);
42
+ this.activeSession = activeSession;
43
+ }
44
+ compactIfNeeded(agent, trigger, signal) {
45
+ return this.activeSession.run(agent.session, () => super.compactIfNeeded(agent, trigger, signal));
46
+ }
47
+ }
48
+ //# sourceMappingURL=compaction.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shuind/dsh-codex-harness",
3
- "version": "0.1.25",
3
+ "version": "0.1.27",
4
4
  "description": "A Codex harness with a streamlined system prompt for GPT models that do not fit DSH's native interface, while remaining compatible with the DSH plugin ecosystem.",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
@@ -18,6 +18,10 @@
18
18
  "types": "./lib/types/installer.d.ts",
19
19
  "default": "./lib/installer.js"
20
20
  },
21
+ "./compaction": {
22
+ "types": "./lib/types/compaction.d.ts",
23
+ "default": "./lib/compaction.js"
24
+ },
21
25
  "./client": {
22
26
  "types": "./lib/types/client/index.d.ts",
23
27
  "default": "./lib/client.js"
@@ -30,6 +34,7 @@
30
34
  "lib/index.js",
31
35
  "lib/invariant.js",
32
36
  "lib/installer.js",
37
+ "lib/compaction.js",
33
38
  "lib/types/**/*.js",
34
39
  "lib/types/**/*.d.ts",
35
40
  "lib/client.js",
@@ -87,6 +92,8 @@
87
92
  "@deepseek-ai/dsh-client-ui-conversation": ">=0.1.0-rc.8",
88
93
  "@deepseek-ai/dsh-client-ui-settings": ">=0.1.0-rc.8",
89
94
  "@deepseek-ai/dsh-client-ui-slots": ">=0.1.0-rc.8",
95
+ "@deepseek-ai/dsh-compaction": ">=0.1.1-rc.2",
96
+ "@deepseek-ai/dsh-compaction-basic": ">=0.1.1-rc.2",
90
97
  "@deepseek-ai/dsh-credentials": ">=0.1.0-rc.8",
91
98
  "@deepseek-ai/dsh-fs": ">=0.0.1-rc.1",
92
99
  "@deepseek-ai/dsh-invariants": ">=0.0.1-rc.1",
@@ -95,6 +102,7 @@
95
102
  "@deepseek-ai/dsh-settings": ">=0.1.0-rc.8",
96
103
  "@deepseek-ai/dsh-sandbox": ">=0.0.1-rc.1",
97
104
  "@deepseek-ai/dsh-sandbox-policy": ">=0.0.1-rc.1",
105
+ "@deepseek-ai/dsh-session": ">=0.1.1-rc.2",
98
106
  "@deepseek-ai/dsh-shell": ">=0.0.1-rc.5",
99
107
  "@deepseek-ai/dsh-shell-env": ">=0.0.1-rc.3",
100
108
  "@deepseek-ai/dsh-system-prompt": ">=0.0.1-rc.1",
@@ -102,6 +110,7 @@
102
110
  "@deepseek-ai/dsh-tool-todo": ">=0.0.1-rc.1",
103
111
  "@deepseek-ai/dsh-terminal": ">=0.0.1-rc.3",
104
112
  "@deepseek-ai/dsh-tool-jobs": ">=0.1.0-rc.8",
113
+ "@deepseek-ai/dsh-token-meter": ">=0.1.1-rc.2",
105
114
  "@deepseek-ai/dsh-tools": ">=0.0.1-rc.1"
106
115
  },
107
116
  "peerDependenciesMeta": {
@@ -126,6 +135,12 @@
126
135
  "@deepseek-ai/dsh-client-ui-slots": {
127
136
  "optional": true
128
137
  },
138
+ "@deepseek-ai/dsh-compaction": {
139
+ "optional": true
140
+ },
141
+ "@deepseek-ai/dsh-compaction-basic": {
142
+ "optional": true
143
+ },
129
144
  "@deepseek-ai/dsh-credentials": {
130
145
  "optional": true
131
146
  },
@@ -150,6 +165,9 @@
150
165
  "@deepseek-ai/dsh-sandbox-policy": {
151
166
  "optional": true
152
167
  },
168
+ "@deepseek-ai/dsh-session": {
169
+ "optional": true
170
+ },
153
171
  "@deepseek-ai/dsh-shell": {
154
172
  "optional": true
155
173
  },
@@ -171,18 +189,25 @@
171
189
  "@deepseek-ai/dsh-tool-jobs": {
172
190
  "optional": true
173
191
  },
192
+ "@deepseek-ai/dsh-token-meter": {
193
+ "optional": true
194
+ },
174
195
  "@deepseek-ai/dsh-tools": {
175
196
  "optional": true
176
197
  }
177
198
  },
178
199
  "devDependencies": {
179
200
  "@deepseek-ai/cordis": "4.0.1",
201
+ "@deepseek-ai/cordis-plugin-include": "1.0.6",
202
+ "@deepseek-ai/cordis-plugin-loader": "1.0.2",
180
203
  "@deepseek-ai/dsh-agent": "0.1.0-rc.6",
181
204
  "@deepseek-ai/dsh-client-locale": "0.1.0-rc.8",
182
205
  "@deepseek-ai/dsh-client-runtime": "0.1.0-rc.8",
183
206
  "@deepseek-ai/dsh-client-ui-conversation": "0.1.0-rc.8",
184
207
  "@deepseek-ai/dsh-client-ui-settings": "0.1.0-rc.8",
185
208
  "@deepseek-ai/dsh-client-ui-slots": "0.1.0-rc.8",
209
+ "@deepseek-ai/dsh-compaction": "0.1.1-rc.2",
210
+ "@deepseek-ai/dsh-compaction-basic": "0.1.1-rc.2",
186
211
  "@deepseek-ai/dsh-credentials": "0.1.0-rc.8",
187
212
  "@deepseek-ai/dsh-fs": "0.1.0-rc.6",
188
213
  "@deepseek-ai/dsh-invariants": "0.1.0-rc.6",
@@ -191,6 +216,7 @@
191
216
  "@deepseek-ai/dsh-settings": "0.1.0-rc.8",
192
217
  "@deepseek-ai/dsh-sandbox": "0.1.0-rc.6",
193
218
  "@deepseek-ai/dsh-sandbox-policy": "0.1.0-rc.6",
219
+ "@deepseek-ai/dsh-session": "0.1.1-rc.2",
194
220
  "@deepseek-ai/dsh-shell": "0.1.0-rc.6",
195
221
  "@deepseek-ai/dsh-shell-env": "0.1.0-rc.6",
196
222
  "@deepseek-ai/dsh-system-prompt": "0.1.0-rc.6",
@@ -198,6 +224,7 @@
198
224
  "@deepseek-ai/dsh-tool-todo": "0.1.0-rc.6",
199
225
  "@deepseek-ai/dsh-terminal": "0.1.0-rc.6",
200
226
  "@deepseek-ai/dsh-tool-jobs": "0.1.0-rc.8",
227
+ "@deepseek-ai/dsh-token-meter": "0.1.1-rc.2",
201
228
  "@deepseek-ai/dsh-tools": "0.1.0-rc.6",
202
229
  "@types/node": "^22.20.0",
203
230
  "@types/react": "~18.3.1",
@@ -70,7 +70,7 @@
70
70
  toolResultPruner: true
71
71
  config:
72
72
  - id: compaction-basic
73
- name: '@deepseek-ai/dsh-compaction-basic'
73
+ name: '@shuind/dsh-codex-harness/compaction'
74
74
 
75
75
  - id: command-compact
76
76
  name: '@deepseek-ai/dsh-command-compact'
@@ -70,7 +70,7 @@
70
70
  toolResultPruner: true
71
71
  config:
72
72
  - id: compaction-basic
73
- name: '@deepseek-ai/dsh-compaction-basic'
73
+ name: '@shuind/dsh-codex-harness/compaction'
74
74
 
75
75
  - id: command-compact
76
76
  name: '@deepseek-ai/dsh-command-compact'