@shuind/dsh-codex-harness 0.1.27 → 0.1.28

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
@@ -1,6 +1,6 @@
1
1
  # @shuind/dsh-codex-harness
2
2
 
3
- 在 DSH 中提供 Codex preset:使用精简版 Codex 系统提示词与工具契约,支持图片输入、可选思考强度、Fast 优先级请求、OpenAI Responses 网页搜索与远程压缩,以及在 Web 设置上下文容量;旨在给来源于 Codex 的 token 提供适配 harness,并兼容 DSH 生态。
3
+ 使用精简版 Codex 提示词和工具,以及改善体验的功能。
4
4
 
5
5
  ## 功能
6
6
 
@@ -20,7 +20,7 @@
20
20
  ## 安装
21
21
 
22
22
  ```sh
23
- dsh plugin --profile web add @shuind/dsh-codex-harness@0.1.27
23
+ dsh plugin --profile web add @shuind/dsh-codex-harness@0.1.28
24
24
  ```
25
25
 
26
26
  重启 Web,创建新会话,在模式菜单中选择 **Codex 模式**。
@@ -59,7 +59,7 @@ Fast 设置保存在 `codex` 命名空间,只对 Codex preset 生效。
59
59
 
60
60
  ### 活动状态
61
61
 
62
- Codex 发起模型请求时,Web 会在 `Deep diving...` 右侧显示 `请求模型... · Ns`;收到首个非空模型 token(非流式适配器则收到 `assistant/message`)后切换为 `模型回复... · Ns`。模型回复结束、进入工具调用、压缩结束或下一轮开始后自动隐藏。该状态由 Host 的 `sessionProjections` 投影驱动,因此本地压缩和远程 `/responses/compact` 都会显示同一种状态。
62
+ Codex 发起模型请求时,Web 会在 `Deep diving...` 右侧显示 `请求中... · Ns`;收到首个非空模型 token(非流式适配器则收到 `assistant/message`)后切换为 `回复中... · Ns`。模型回复结束、进入工具调用、压缩结束或下一轮开始后自动隐藏。该状态由 Host 的 `sessionProjections` 投影驱动,因此本地压缩和远程 `/responses/compact` 都会显示同一种状态。
63
63
 
64
64
  如果当前 DSH 组合没有加载 projection 服务,插件会跳过注册,客户端也会自动隐藏这行,不影响普通会话。
65
65
 
@@ -67,8 +67,8 @@ Codex 发起模型请求时,Web 会在 `Deep diving...` 右侧显示 `请求
67
67
 
68
68
  安装插件后,首次启动对应的 DSH profile 时,插件会安装两套随包提供的 preset:
69
69
 
70
- - **Codex 模式**:使用精简版 Codex 提示词。
71
- - **Codex 协作模式**:在精简版 Codex 提示词后追加协作提示词。
70
+ - **Codex 模式**:使用精简版 Codex 提示词和工具,以及改善体验的功能。
71
+ - **Codex 协作模式**:额外加入协作提示词,预期获得更好的体验。
72
72
 
73
73
  它们分别位于 `${DSH_HOME:-$HOME/.dsh}/.agent-presets/codex/` 和 `${DSH_HOME:-$HOME/.dsh}/.agent-presets/codex-collaboration/`。如果对应目录已经存在,插件会保留你的文件,不会覆盖自定义内容。
74
74
 
@@ -123,11 +123,10 @@ order: 10
123
123
  开启后,Codex preset 会在系统提示词中注入以下协作要求:
124
124
 
125
125
  ```text
126
- Ask, align, and clarify first. Try your best to understand the user's full picture.
126
+ Gather enough context from the user then achieve the user's goal through the clearest, most effective path.
127
127
  Keep only the essential logic and core actions. There's no need to explain or test what was removed or why something wasn't done.
128
128
  Convey enough valuable information with as few words as possible. Stay focused on the end goal.
129
129
  Solve problems by thinking from first principles and at a higher level.
130
- Make things as effortless as possible for the user.
131
130
  ```
132
131
 
133
132
  ## 注意事项
package/lib/client.js CHANGED
@@ -72,9 +72,6 @@ window.__ModuleLoader__.load({
72
72
  /** Browser controls for the Codex request settings mounted by the Host plugin. */
73
73
  const NS = "codex";
74
74
  const SETTINGS_NAMESPACE = "codex";
75
- const MODEL_SETTINGS_SLOT = "conversation.input.model.settings";
76
- const CONTEXT_SETTINGS_SLOT = "conversation.input.context.settings";
77
- const ACTIVITY_SLOT = "conversation.chat.status";
78
75
  const ACTIVITY_FALLBACK_SLOT = "conversation.composer.dock";
79
76
  const FAST_FALLBACK_SLOT = "conversation.input.right";
80
77
  const CONTEXT_FALLBACK_SLOT = "conversation.input.right";
@@ -86,7 +83,7 @@ window.__ModuleLoader__.load({
86
83
  fastStateOn: "On",
87
84
  fastStateOff: "Off",
88
85
  contextSize: "Context size",
89
- contextSizeDescription: "Next request capacity in K tokens. The meter above is current.",
86
+ contextSizeDescription: "Next request capacity in K tokens.",
90
87
  contextRestore: "Restore model default",
91
88
  activityCompacting: "Compacting context...",
92
89
  activityRequestingModel: "Requesting model...",
@@ -99,58 +96,12 @@ window.__ModuleLoader__.load({
99
96
  fastStateOn: "开",
100
97
  fastStateOff: "关",
101
98
  contextSize: "上下文大小",
102
- contextSizeDescription: "设置下次请求的上下文容量,单位为 K tokens;上方是当前请求。",
99
+ contextSizeDescription: "设置下次请求的上下文容量,单位为 K tokens。",
103
100
  contextRestore: "恢复模型默认值",
104
101
  activityCompacting: "正在压缩上下文...",
105
- activityRequestingModel: "请求模型...",
106
- activityModelReply: "模型回复..."
102
+ activityRequestingModel: "请求中...",
103
+ activityModelReply: "回复中..."
107
104
  };
108
- function FastModeButton({ sessionId, useSessions, useSettings, setSetting, t }) {
109
- const agentPreset = useSessions((state) => state.byId[sessionId]?.agentPreset);
110
- const snapshot = useSettings((state) => state);
111
- const fast = snapshot.value?.fast ?? false;
112
- if (!isCodexPresetId(agentPreset)) return null;
113
- return (0, react_jsx_runtime.jsxs)("button", {
114
- type: "button",
115
- role: "menuitemcheckbox",
116
- disabled: snapshot.writable === false,
117
- "aria-pressed": fast,
118
- "aria-label": fast ? t("fastOn") : t("fastOff"),
119
- title: fast ? t("fastOn") : t("fastOff"),
120
- onMouseDown: (event) => {
121
- event.preventDefault();
122
- },
123
- onClick: () => {
124
- setSetting("fast", !fast);
125
- },
126
- style: {
127
- boxSizing: "border-box",
128
- display: "flex",
129
- alignItems: "center",
130
- justifyContent: "space-between",
131
- width: "100%",
132
- height: 40,
133
- border: 0,
134
- borderRadius: 10,
135
- padding: "0 10px",
136
- color: fast ? "var(--dsw-static-blue-500)" : "var(--dsw-alias-label-secondary)",
137
- background: fast ? "var(--dsw-alias-interactive-bg-selected)" : "transparent",
138
- cursor: snapshot.writable === false ? "default" : "pointer",
139
- font: "inherit",
140
- fontSize: 14,
141
- lineHeight: "22px",
142
- fontWeight: fast ? 600 : 400,
143
- textAlign: "left"
144
- },
145
- children: [(0, react_jsx_runtime.jsx)("span", { children: t("fast") }), (0, react_jsx_runtime.jsx)("span", {
146
- style: {
147
- color: "var(--dsw-alias-label-tertiary)",
148
- fontSize: 12
149
- },
150
- children: fast ? t("fastStateOn") : t("fastStateOff")
151
- })]
152
- });
153
- }
154
105
  /** The legacy composer seat is a compact inline row, not a menu panel. */
155
106
  function FastModeFallback(props) {
156
107
  const { sessionId, useSessions, useSettings, setSetting, t } = props;
@@ -195,6 +146,11 @@ window.__ModuleLoader__.load({
195
146
  })]
196
147
  });
197
148
  }
149
+ function contextWindowFromProjection(useProjection) {
150
+ const pressure = useProjection("contextPressure");
151
+ return pressure?.contextWindow !== void 0 && pressure.contextWindow > 0 ? pressure.contextWindow : DEFAULT_CONTEXT_WINDOW;
152
+ }
153
+ /** Settings form kept inside the official composer slot's popover. */
198
154
  function ContextSizeControl({ contextWindow, useSettings, setSetting, unsetSetting, t }) {
199
155
  const snapshot = useSettings((state) => state);
200
156
  const configured = snapshot.value?.contextWindow;
@@ -208,9 +164,9 @@ window.__ModuleLoader__.load({
208
164
  };
209
165
  return (0, react_jsx_runtime.jsxs)("div", {
210
166
  style: {
211
- marginTop: 10,
167
+ marginTop: 0,
212
168
  display: "grid",
213
- gap: 5
169
+ gap: 8
214
170
  },
215
171
  children: [
216
172
  (0, react_jsx_runtime.jsxs)("div", {
@@ -223,13 +179,14 @@ window.__ModuleLoader__.load({
223
179
  children: [(0, react_jsx_runtime.jsx)("strong", {
224
180
  style: {
225
181
  color: "var(--dsw-alias-label-primary)",
226
- fontSize: 12
182
+ fontSize: 13
227
183
  },
228
184
  children: t("contextSize")
229
185
  }), (0, react_jsx_runtime.jsxs)("span", {
230
186
  style: {
231
187
  color: "var(--dsw-alias-label-secondary)",
232
- fontSize: 11
188
+ fontSize: 12,
189
+ fontVariantNumeric: "tabular-nums"
233
190
  },
234
191
  children: [valueK, "K"]
235
192
  })]
@@ -244,16 +201,25 @@ window.__ModuleLoader__.load({
244
201
  "aria-label": t("contextSize"),
245
202
  onChange: (event) => {
246
203
  setValueK(Number(event.target.value));
204
+ },
205
+ style: {
206
+ display: "block",
207
+ width: "100%",
208
+ accentColor: "var(--dsw-static-blue-500)"
247
209
  }
248
210
  }),
249
211
  (0, react_jsx_runtime.jsxs)("div", {
250
212
  style: {
251
- display: "flex",
252
- alignItems: "center",
253
- gap: 7
213
+ display: "grid",
214
+ gap: 4
254
215
  },
255
- children: [
256
- (0, react_jsx_runtime.jsx)("input", {
216
+ children: [(0, react_jsx_runtime.jsxs)("div", {
217
+ style: {
218
+ display: "flex",
219
+ alignItems: "center",
220
+ gap: 6
221
+ },
222
+ children: [(0, react_jsx_runtime.jsx)("input", {
257
223
  type: "number",
258
224
  min: 1,
259
225
  max: maxK,
@@ -265,31 +231,31 @@ window.__ModuleLoader__.load({
265
231
  setValueK(Number(event.target.value));
266
232
  },
267
233
  style: {
268
- width: 76,
234
+ width: 68,
269
235
  border: "1px solid var(--dsw-alias-border-primary)",
270
- borderRadius: 5,
271
- padding: "3px 5px",
236
+ borderRadius: 6,
237
+ padding: "4px 6px",
272
238
  color: "var(--dsw-alias-label-primary)",
273
239
  background: "var(--dsw-alias-fill-primary)",
274
240
  font: "inherit",
275
- fontSize: 11
241
+ fontSize: 12,
242
+ fontVariantNumeric: "tabular-nums"
276
243
  }
277
- }),
278
- (0, react_jsx_runtime.jsx)("span", {
244
+ }), (0, react_jsx_runtime.jsx)("span", {
279
245
  style: {
280
246
  color: "var(--dsw-alias-label-secondary)",
281
247
  fontSize: 11
282
248
  },
283
249
  children: "K"
284
- }),
285
- (0, react_jsx_runtime.jsx)("span", {
286
- style: {
287
- color: "var(--dsw-alias-label-secondary)",
288
- fontSize: 11
289
- },
290
- children: t("contextSizeDescription")
291
- })
292
- ]
250
+ })]
251
+ }), (0, react_jsx_runtime.jsx)("span", {
252
+ style: {
253
+ color: "var(--dsw-alias-label-tertiary)",
254
+ fontSize: 11,
255
+ lineHeight: "16px"
256
+ },
257
+ children: t("contextSizeDescription")
258
+ })]
293
259
  }),
294
260
  configured !== void 0 && (0, react_jsx_runtime.jsx)("button", {
295
261
  type: "button",
@@ -311,10 +277,6 @@ window.__ModuleLoader__.load({
311
277
  ]
312
278
  });
313
279
  }
314
- function contextWindowFromProjection(useProjection) {
315
- const pressure = useProjection("contextPressure");
316
- return pressure?.contextWindow !== void 0 && pressure.contextWindow > 0 ? pressure.contextWindow : DEFAULT_CONTEXT_WINDOW;
317
- }
318
280
  /** Compact trigger used when the host has no ContextMeter settings child slot. */
319
281
  function LegacyContextSizeControl({ sessionId, useSessions, useProjection, useSettings, setSetting, unsetSetting, t }) {
320
282
  const agentPreset = useSessions((state) => state.byId[sessionId]?.agentPreset);
@@ -466,11 +428,12 @@ window.__ModuleLoader__.load({
466
428
  (0, react_jsx_runtime.jsx)("span", {
467
429
  "aria-hidden": "true",
468
430
  style: {
469
- width: 7,
470
- height: 7,
431
+ width: 5,
432
+ height: 5,
471
433
  flex: "0 0 auto",
472
434
  borderRadius: "50%",
473
- background: "var(--dsw-static-blue-500)"
435
+ background: "var(--dsw-static-blue-500)",
436
+ opacity: .55
474
437
  }
475
438
  }),
476
439
  (0, react_jsx_runtime.jsx)("span", { children: label }),
@@ -502,25 +465,7 @@ window.__ModuleLoader__.load({
502
465
  "locale",
503
466
  "settingsScope"
504
467
  ];
505
- /** Select a preferred slot when the host declares it, otherwise use a stable legacy composer seat. */
506
- function chooseDeclaredSlot(preferred, fallback, isDeclared) {
507
- return isDeclared(preferred) ? preferred : fallback;
508
- }
509
- function slotIsDeclared(ctx, slot) {
510
- const registry = ctx.slots;
511
- return typeof registry.spec === "function" && registry.spec.call(ctx.slots, slot) !== void 0;
512
- }
513
- /** Register an optional host slot without claiming it in older SlotMap declarations. */
514
- function injectOptionalActivitySlot(ctx, slot) {
515
- const registry = ctx.slots;
516
- registry.inject(slot, () => registry.register({
517
- name: slot,
518
- id: "codex-activity",
519
- order: 5,
520
- locale: NS
521
- }, ActivityLine));
522
- }
523
- /** Mount Codex controls in the newest named seats, with legacy composer fallbacks. */
468
+ /** Mount all controls through the official composer seats shared by every DSH release. */
524
469
  function apply(ctx) {
525
470
  ctx.effect(() => ctx.locale.register(NS, {
526
471
  en,
@@ -532,36 +477,21 @@ window.__ModuleLoader__.load({
532
477
  setSetting: (field, value) => settings.set(field, value),
533
478
  unsetSetting: (field) => settings.unset(field)
534
479
  });
535
- if (chooseDeclaredSlot(MODEL_SETTINGS_SLOT, FAST_FALLBACK_SLOT, (slot) => slotIsDeclared(ctx, slot)) === MODEL_SETTINGS_SLOT) ctx.slots.inject(MODEL_SETTINGS_SLOT, () => ctx.slots.register({
536
- name: MODEL_SETTINGS_SLOT,
537
- id: "codex-fast",
538
- order: 0,
539
- locale: NS,
540
- inject: injected
541
- }, FastModeButton));
542
- else ctx.slots.inject(FAST_FALLBACK_SLOT, () => ctx.slots.register({
480
+ ctx.slots.inject(FAST_FALLBACK_SLOT, () => ctx.slots.register({
543
481
  name: FAST_FALLBACK_SLOT,
544
- id: "codex-fast-fallback",
482
+ id: "codex-fast",
545
483
  order: 0,
546
484
  locale: NS,
547
485
  inject: injected
548
486
  }, FastModeFallback));
549
- if (chooseDeclaredSlot(CONTEXT_SETTINGS_SLOT, CONTEXT_FALLBACK_SLOT, (slot) => slotIsDeclared(ctx, slot)) === CONTEXT_SETTINGS_SLOT) ctx.slots.inject(CONTEXT_SETTINGS_SLOT, () => ctx.slots.register({
550
- name: CONTEXT_SETTINGS_SLOT,
551
- id: "codex-context-size",
552
- order: 0,
553
- locale: NS,
554
- inject: injected
555
- }, ContextSizeControl));
556
- else ctx.slots.inject(CONTEXT_FALLBACK_SLOT, () => ctx.slots.register({
487
+ ctx.slots.inject(CONTEXT_FALLBACK_SLOT, () => ctx.slots.register({
557
488
  name: CONTEXT_FALLBACK_SLOT,
558
- id: "codex-context-size-fallback",
559
- order: 0,
489
+ id: "codex-context-size",
490
+ order: 1,
560
491
  locale: NS,
561
492
  inject: injected
562
493
  }, LegacyContextSizeControl));
563
- if (chooseDeclaredSlot(ACTIVITY_SLOT, ACTIVITY_FALLBACK_SLOT, (slot) => slotIsDeclared(ctx, slot)) === ACTIVITY_SLOT) injectOptionalActivitySlot(ctx, ACTIVITY_SLOT);
564
- else ctx.slots.inject(ACTIVITY_FALLBACK_SLOT, () => ctx.slots.register({
494
+ ctx.slots.inject(ACTIVITY_FALLBACK_SLOT, () => ctx.slots.register({
565
495
  name: ACTIVITY_FALLBACK_SLOT,
566
496
  id: "codex-activity",
567
497
  order: 5,
@@ -575,7 +505,6 @@ window.__ModuleLoader__.load({
575
505
  //#endregion
576
506
  exports.ActivityLine = ActivityLine;
577
507
  exports.apply = apply;
578
- exports.chooseDeclaredSlot = chooseDeclaredSlot;
579
508
  exports.default = client_default;
580
509
  exports.inject = inject;
581
510
  return module.exports;
package/lib/compaction.js CHANGED
@@ -1,19 +1,45 @@
1
1
  import { AsyncLocalStorage } from "node:async_hooks";
2
2
  import BasicCompactionEngine from "@deepseek-ai/dsh-compaction-basic";
3
+ import { settingsNamespace } from "@deepseek-ai/dsh-settings";
3
4
  //#region lib/types/compaction.js
4
5
  /** Codex compaction backend that honors the latest durable request capacity. */
6
+ const CODEX_SETTINGS_NAMESPACE = settingsNamespace("codex");
7
+ /** Codex context overrides apply only to GPT-compatible model routes. */
8
+ function isGptModel(model) {
9
+ return /(?:^|\/)(?:gpt|chatgpt)(?:[-_.]|\d|$)/i.test(model);
10
+ }
11
+ /** Read the live Codex capacity without requiring a custom LLM service API. */
12
+ function configuredContextWindow(ctx) {
13
+ const settings = ctx.get("settings");
14
+ if (settings?.get === void 0) return { available: false };
15
+ const value = settings?.get?.(CODEX_SETTINGS_NAMESPACE);
16
+ return {
17
+ available: true,
18
+ ...value?.contextWindow !== void 0 && Number.isSafeInteger(value.contextWindow) && value.contextWindow > 0 ? { value: value.contextWindow } : {}
19
+ };
20
+ }
21
+ /** Read an explicit capacity persisted in the request header when settings are unavailable. */
22
+ function requestContextWindow(session, provider, model) {
23
+ const config = session.requestHeader()?.config;
24
+ if (config?.provider !== provider || config.model !== model) return void 0;
25
+ const value = config.contextWindow;
26
+ return typeof value === "number" && Number.isSafeInteger(value) && value > 0 ? value : void 0;
27
+ }
5
28
  /** Overlay only the capacity lookup used by pressure compaction. */
6
- function withDurableContextCapacity(llm, activeSession) {
29
+ function withDurableContextCapacity(llm, ctx, activeSession) {
7
30
  return new Proxy(llm, { get(target, property) {
8
31
  if (property === "resolveModelInfo") return async (provider, model, signal) => {
9
32
  const info = await target.resolveModelInfo(provider, model, signal);
10
33
  const requestContext = activeSession.getStore()?.requestContext();
11
- if (requestContext?.provider !== provider || requestContext.model !== model || requestContext.contextWindow === void 0) return info;
34
+ const session = activeSession.getStore();
35
+ const configured = isGptModel(model) ? configuredContextWindow(ctx) : { available: false };
36
+ const contextWindow = configured.available ? configured.value : (session === void 0 ? void 0 : requestContextWindow(session, provider, model)) ?? (requestContext?.provider === provider && requestContext.model === model ? requestContext.contextWindow : void 0);
37
+ if (contextWindow === void 0) return info;
12
38
  return {
13
39
  ...info,
14
40
  context: {
15
41
  ...info.context,
16
- contextWindow: requestContext.contextWindow
42
+ contextWindow
17
43
  }
18
44
  };
19
45
  };
@@ -34,7 +60,7 @@ var CodexCompactionEngine = class extends BasicCompactionEngine {
34
60
  const activeSession = new AsyncLocalStorage();
35
61
  const llm = ctx.get("llm");
36
62
  if (llm === void 0) throw new Error("codex compaction requires ctx.llm");
37
- super(ctx.extend({ llm: withDurableContextCapacity(llm, activeSession) }), config);
63
+ super(ctx.extend({ llm: withDurableContextCapacity(llm, ctx, activeSession) }), config);
38
64
  this.activeSession = activeSession;
39
65
  }
40
66
  compactIfNeeded(agent, trigger, signal) {
package/lib/index.js CHANGED
@@ -530,6 +530,10 @@ const REMOTE_COMPACTION_CLOSE = "</codex-remote-compaction>";
530
530
  const HOSTED_REQUESTS = new AsyncLocalStorage();
531
531
  let hostedPatchUsers = 0;
532
532
  let hostedPatchRestore;
533
+ function serviceTierOf(options) {
534
+ const value = options.serviceTier;
535
+ return typeof value === "string" ? value : void 0;
536
+ }
533
537
  function isGptModel$1(model) {
534
538
  return typeof model === "string" && /(?:^|\/)(?:gpt|chatgpt)(?:[-_.]|\d|$)/i.test(model);
535
539
  }
@@ -750,6 +754,14 @@ function hasRemoteCompaction(body) {
750
754
  function canPatchBody(body) {
751
755
  return isGptModel$1(body.model) && (hasWebSearchTool(body) || hasRemoteCompaction(body) || hasFunctionApplyPatchTool(body) && canRewriteApplyPatchHistory(body));
752
756
  }
757
+ /** Add provider options that older pi-ai adapters do not copy themselves. */
758
+ function applyRequestWireOptions(body, options) {
759
+ if (options.serviceTier === void 0 || !isGptModel$1(body.model)) return body;
760
+ return {
761
+ ...body,
762
+ service_tier: options.serviceTier
763
+ };
764
+ }
753
765
  /**
754
766
  * Install a scoped fetch shim for pi-ai's already-built Responses request.
755
767
  * The generic DSH adapter remains the owner of auth, streaming, replay, and
@@ -759,7 +771,8 @@ function canPatchBody(body) {
759
771
  function installGlobalHostedWebSearchPatch() {
760
772
  const original = globalThis.fetch;
761
773
  const patched = async (input, init) => {
762
- if (!HOSTED_REQUESTS.getStore()) return original(input, init);
774
+ const options = HOSTED_REQUESTS.getStore();
775
+ if (options === void 0) return original(input, init);
763
776
  const request = new Request(input, init);
764
777
  if (!isResponsesRequest(request.url)) return original(input, init);
765
778
  let body;
@@ -768,12 +781,26 @@ function installGlobalHostedWebSearchPatch() {
768
781
  } catch {
769
782
  return original(input, init);
770
783
  }
771
- if (!canPatchBody(body)) return original(input, init);
772
- const fallbackRequest = request.clone();
784
+ const requestBody = applyRequestWireOptions(body, options);
785
+ if (!canPatchBody(requestBody)) {
786
+ if (requestBody === body) return original(input, init);
787
+ const headers = new Headers(request.headers);
788
+ headers.delete("content-length");
789
+ return original(new Request(request, {
790
+ body: JSON.stringify(requestBody),
791
+ headers
792
+ }));
793
+ }
794
+ const fallbackHeaders = new Headers(request.headers);
795
+ fallbackHeaders.delete("content-length");
796
+ const fallbackRequest = requestBody === body ? request.clone() : new Request(request, {
797
+ body: JSON.stringify(requestBody),
798
+ headers: fallbackHeaders
799
+ });
773
800
  const headers = new Headers(request.headers);
774
801
  headers.delete("content-length");
775
802
  const hostedRequest = new Request(request, {
776
- body: JSON.stringify(rewriteCodexResponsesBody(body)),
803
+ body: JSON.stringify(rewriteCodexResponsesBody(requestBody)),
777
804
  headers
778
805
  });
779
806
  try {
@@ -802,13 +829,13 @@ function installHostedWebSearch() {
802
829
  };
803
830
  }
804
831
  /** Iterate an existing DSH stream with the hosted-request context installed. */
805
- function hostedWebSearchStream(next) {
832
+ function hostedWebSearchStream(next, options = {}) {
806
833
  return (async function* () {
807
834
  const iterator = next()[Symbol.asyncIterator]();
808
835
  let completed = false;
809
836
  try {
810
837
  while (true) {
811
- const item = await HOSTED_REQUESTS.run(true, () => iterator.next());
838
+ const item = await HOSTED_REQUESTS.run(options, () => iterator.next());
812
839
  if (item.done) {
813
840
  completed = true;
814
841
  return;
@@ -975,7 +1002,8 @@ function remoteCompactStream(ctx, options, next) {
975
1002
  if (options.signal?.aborted) throw error;
976
1003
  ctx.logger.warn("codex: remote compaction failed; using dsh-compaction-basic fallback");
977
1004
  ctx.logger.warn(error);
978
- yield* hostedWebSearchStream(next);
1005
+ const serviceTier = serviceTierOf(options);
1006
+ yield* hostedWebSearchStream(next, serviceTier === void 0 ? {} : { serviceTier });
979
1007
  }
980
1008
  })();
981
1009
  }
@@ -1208,17 +1236,16 @@ const CODEX_BASE_PROMPT = String.raw`## General
1208
1236
  ## Presenting your work
1209
1237
 
1210
1238
  - Be concise, direct, friendly, and actionable.
1211
- - For substantial work, explain what changed and why, then mention relevant verification and next steps.
1239
+ - For substantial work, explain what changed and why, then briefly note how the work was verified and what comes next.
1212
1240
  - Do not dump large files into the conversation; refer to their paths.
1213
1241
  - Use plain text with short sections only when they improve scanability.
1214
1242
  `;
1215
1243
  const CODEX_COLLABORATION_PROMPT = String.raw`## Collaboration
1216
1244
 
1217
- - Ask, align, and clarify first. Try your best to understand the user's full picture.
1245
+ - Gather enough context from the user then achieve the user's goal through the clearest, most effective path.
1218
1246
  - Keep only the essential logic and core actions. There's no need to explain or test what was removed or why something wasn't done.
1219
1247
  - Convey enough valuable information with as few words as possible. Stay focused on the end goal.
1220
1248
  - Solve problems by thinking from first principles and at a higher level.
1221
- - Make things as effortless as possible for the user.
1222
1249
  `;
1223
1250
  /** Put the agent persona first and omit the generic Harness identity opener. */
1224
1251
  function normalizeCodexPromptAssembly(assembly) {
@@ -1626,7 +1653,7 @@ function apply(ctx, config = {}) {
1626
1653
  }
1627
1654
  ctx.on("llm/stream", ((options, next) => {
1628
1655
  if (resolved.remoteCompact && options.purpose === "compaction" && isGptModel(options.model)) return remoteCompactStream(ctx, options, next);
1629
- if (options.purpose === void 0 && isGptModel(options.model)) return hostedWebSearchStream(next);
1656
+ if (options.purpose === void 0 && isGptModel(options.model)) return hostedWebSearchStream(next, { serviceTier: options.serviceTier });
1630
1657
  return next();
1631
1658
  }));
1632
1659
  ctx.on("system-prompt/assemble", async (_assembly, _context, next) => normalizeCodexPromptAssembly(await next()));
@@ -8,7 +8,7 @@ declare const en: {
8
8
  readonly fastStateOn: "On";
9
9
  readonly fastStateOff: "Off";
10
10
  readonly contextSize: "Context size";
11
- readonly contextSizeDescription: "Next request capacity in K tokens. The meter above is current.";
11
+ readonly contextSizeDescription: "Next request capacity in K tokens.";
12
12
  readonly contextRestore: "Restore model default";
13
13
  readonly activityCompacting: "Compacting context...";
14
14
  readonly activityRequestingModel: "Requesting model...";
@@ -19,27 +19,12 @@ declare module '@deepseek-ai/dsh-client-ui-slots' {
19
19
  interface LocaleNamespaceMap {
20
20
  codex: CodexKey;
21
21
  }
22
- interface SlotMap {
23
- 'conversation.input.model.settings': {
24
- kind: 'list';
25
- scope: 'session';
26
- };
27
- 'conversation.input.context.settings': {
28
- kind: 'list';
29
- scope: 'session';
30
- owner: {
31
- contextWindow: number;
32
- };
33
- };
34
- }
35
22
  }
36
23
  type ActivityDockProps = PropsRuntime<'conversation.composer.dock'> & PropsLocale<'codex'>;
37
24
  type ActivityProps = ActivityDockProps;
38
25
  export declare function ActivityLine({ sessionId, useSession, useSessions, useProjection, t }: ActivityProps): import("react").JSX.Element | null;
39
26
  export declare const inject: string[];
40
- /** Select a preferred slot when the host declares it, otherwise use a stable legacy composer seat. */
41
- export declare function chooseDeclaredSlot(preferred: string, fallback: string, isDeclared: (slot: string) => boolean): string;
42
- /** Mount Codex controls in the newest named seats, with legacy composer fallbacks. */
27
+ /** Mount all controls through the official composer seats shared by every DSH release. */
43
28
  export declare function apply(ctx: Context): void;
44
29
  declare const _default: {
45
30
  inject: string[];
@@ -5,11 +5,6 @@ import { CODEX_CONTEXT_MAX, CODEX_CONTEXT_UNIT, isCodexPresetId } from "../conte
5
5
  import { modelActivity, sameModelActivity } from "./activity.js";
6
6
  const NS = 'codex';
7
7
  const SETTINGS_NAMESPACE = 'codex';
8
- const MODEL_SETTINGS_SLOT = 'conversation.input.model.settings';
9
- const CONTEXT_SETTINGS_SLOT = 'conversation.input.context.settings';
10
- // Prefer a dedicated status seat when a newer host declares it; the current
11
- // conversation contract falls back to the ambient composer dock below.
12
- const ACTIVITY_SLOT = 'conversation.chat.status';
13
8
  const ACTIVITY_FALLBACK_SLOT = 'conversation.composer.dock';
14
9
  const FAST_FALLBACK_SLOT = 'conversation.input.right';
15
10
  const CONTEXT_FALLBACK_SLOT = 'conversation.input.right';
@@ -21,7 +16,7 @@ const en = {
21
16
  fastStateOn: 'On',
22
17
  fastStateOff: 'Off',
23
18
  contextSize: 'Context size',
24
- contextSizeDescription: 'Next request capacity in K tokens. The meter above is current.',
19
+ contextSizeDescription: 'Next request capacity in K tokens.',
25
20
  contextRestore: 'Restore model default',
26
21
  activityCompacting: 'Compacting context...',
27
22
  activityRequestingModel: 'Requesting model...',
@@ -34,38 +29,12 @@ const zh = {
34
29
  fastStateOn: '开',
35
30
  fastStateOff: '关',
36
31
  contextSize: '上下文大小',
37
- contextSizeDescription: '设置下次请求的上下文容量,单位为 K tokens;上方是当前请求。',
32
+ contextSizeDescription: '设置下次请求的上下文容量,单位为 K tokens。',
38
33
  contextRestore: '恢复模型默认值',
39
34
  activityCompacting: '正在压缩上下文...',
40
- activityRequestingModel: '请求模型...',
41
- activityModelReply: '模型回复...',
35
+ activityRequestingModel: '请求中...',
36
+ activityModelReply: '回复中...',
42
37
  };
43
- function FastModeButton({ sessionId, useSessions, useSettings, setSetting, t }) {
44
- const agentPreset = useSessions(state => state.byId[sessionId]?.agentPreset);
45
- const snapshot = useSettings(state => state);
46
- const fast = snapshot.value?.fast ?? false;
47
- if (!isCodexPresetId(agentPreset))
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'), onMouseDown: event => { event.preventDefault(); }, onClick: () => { void setSetting('fast', !fast); }, style: {
50
- boxSizing: 'border-box',
51
- display: 'flex',
52
- alignItems: 'center',
53
- justifyContent: 'space-between',
54
- width: '100%',
55
- height: 40,
56
- border: 0,
57
- borderRadius: 10,
58
- padding: '0 10px',
59
- color: fast ? 'var(--dsw-static-blue-500)' : 'var(--dsw-alias-label-secondary)',
60
- background: fast ? 'var(--dsw-alias-interactive-bg-selected)' : 'transparent',
61
- cursor: snapshot.writable === false ? 'default' : 'pointer',
62
- font: 'inherit',
63
- fontSize: 14,
64
- lineHeight: '22px',
65
- fontWeight: fast ? 600 : 400,
66
- textAlign: 'left',
67
- }, children: [_jsx("span", { children: t('fast') }), _jsx("span", { style: { color: 'var(--dsw-alias-label-tertiary)', fontSize: 12 }, children: fast ? t('fastStateOn') : t('fastStateOff') })] }));
68
- }
69
38
  /** The legacy composer seat is a compact inline row, not a menu panel. */
70
39
  function FastModeFallback(props) {
71
40
  const { sessionId, useSessions, useSettings, setSetting, t } = props;
@@ -93,7 +62,14 @@ function FastModeFallback(props) {
93
62
  whiteSpace: 'nowrap',
94
63
  }, children: [_jsx("span", { children: t('fast') }), _jsx("span", { style: { color: 'var(--dsw-alias-label-tertiary)', fontSize: 11 }, children: fast ? t('fastStateOn') : t('fastStateOff') })] }));
95
64
  }
96
- function ContextSizeControl({ contextWindow, useSettings, setSetting, unsetSetting, t }) {
65
+ function contextWindowFromProjection(useProjection) {
66
+ const pressure = useProjection('contextPressure');
67
+ return pressure?.contextWindow !== undefined && pressure.contextWindow > 0
68
+ ? pressure.contextWindow
69
+ : DEFAULT_CONTEXT_WINDOW;
70
+ }
71
+ /** Settings form kept inside the official composer slot's popover. */
72
+ function ContextSizeControl({ contextWindow, useSettings, setSetting, unsetSetting, t, }) {
97
73
  const snapshot = useSettings(state => state);
98
74
  const configured = snapshot.value?.contextWindow;
99
75
  const maxK = CODEX_CONTEXT_MAX / CODEX_CONTEXT_UNIT;
@@ -108,16 +84,21 @@ function ContextSizeControl({ contextWindow, useSettings, setSetting, unsetSetti
108
84
  else
109
85
  void setSetting('contextWindow', normalized);
110
86
  };
111
- return (_jsxs("div", { style: { marginTop: 10, display: 'grid', gap: 5 }, children: [_jsxs("div", { style: { display: 'flex', alignItems: 'baseline', justifyContent: 'space-between', gap: 12 }, children: [_jsx("strong", { style: { color: 'var(--dsw-alias-label-primary)', fontSize: 12 }, children: t('contextSize') }), _jsxs("span", { style: { color: 'var(--dsw-alias-label-secondary)', fontSize: 11 }, children: [valueK, "K"] })] }), _jsx("input", { type: "range", min: 1, max: maxK, step: 1, value: valueK, disabled: snapshot.writable === false, "aria-label": t('contextSize'), onChange: event => { setValueK(Number(event.target.value)); } }), _jsxs("div", { style: { display: 'flex', alignItems: 'center', gap: 7 }, children: [_jsx("input", { type: "number", min: 1, max: maxK, step: 1, value: valueK, disabled: snapshot.writable === false, "aria-label": t('contextSize'), onChange: event => { setValueK(Number(event.target.value)); }, style: {
112
- width: 76,
113
- border: '1px solid var(--dsw-alias-border-primary)',
114
- borderRadius: 5,
115
- padding: '3px 5px',
116
- color: 'var(--dsw-alias-label-primary)',
117
- background: 'var(--dsw-alias-fill-primary)',
118
- font: 'inherit',
119
- fontSize: 11,
120
- } }), _jsx("span", { style: { color: 'var(--dsw-alias-label-secondary)', fontSize: 11 }, children: "K" }), _jsx("span", { style: { color: 'var(--dsw-alias-label-secondary)', fontSize: 11 }, children: t('contextSizeDescription') })] }), configured !== undefined && (_jsx("button", { type: "button", onClick: () => { void unsetSetting('contextWindow'); }, style: {
87
+ return (_jsxs("div", { style: { marginTop: 0, display: 'grid', gap: 8 }, children: [_jsxs("div", { style: { display: 'flex', alignItems: 'baseline', justifyContent: 'space-between', gap: 12 }, children: [_jsx("strong", { style: { color: 'var(--dsw-alias-label-primary)', fontSize: 13 }, children: t('contextSize') }), _jsxs("span", { style: { color: 'var(--dsw-alias-label-secondary)', fontSize: 12, fontVariantNumeric: 'tabular-nums' }, children: [valueK, "K"] })] }), _jsx("input", { type: "range", min: 1, max: maxK, step: 1, value: valueK, disabled: snapshot.writable === false, "aria-label": t('contextSize'), onChange: event => { setValueK(Number(event.target.value)); }, style: {
88
+ display: 'block',
89
+ width: '100%',
90
+ accentColor: 'var(--dsw-static-blue-500)',
91
+ } }), _jsxs("div", { style: { display: 'grid', gap: 4 }, children: [_jsxs("div", { style: { display: 'flex', alignItems: 'center', gap: 6 }, children: [_jsx("input", { type: "number", min: 1, max: maxK, step: 1, value: valueK, disabled: snapshot.writable === false, "aria-label": t('contextSize'), onChange: event => { setValueK(Number(event.target.value)); }, style: {
92
+ width: 68,
93
+ border: '1px solid var(--dsw-alias-border-primary)',
94
+ borderRadius: 6,
95
+ padding: '4px 6px',
96
+ color: 'var(--dsw-alias-label-primary)',
97
+ background: 'var(--dsw-alias-fill-primary)',
98
+ font: 'inherit',
99
+ fontSize: 12,
100
+ fontVariantNumeric: 'tabular-nums',
101
+ } }), _jsx("span", { style: { color: 'var(--dsw-alias-label-secondary)', fontSize: 11 }, children: "K" })] }), _jsx("span", { style: { color: 'var(--dsw-alias-label-tertiary)', fontSize: 11, lineHeight: '16px' }, children: t('contextSizeDescription') })] }), configured !== undefined && (_jsx("button", { type: "button", onClick: () => { void unsetSetting('contextWindow'); }, style: {
121
102
  justifySelf: 'start',
122
103
  border: 0,
123
104
  padding: 0,
@@ -128,12 +109,6 @@ function ContextSizeControl({ contextWindow, useSettings, setSetting, unsetSetti
128
109
  fontSize: 11,
129
110
  }, children: t('contextRestore') }))] }));
130
111
  }
131
- function contextWindowFromProjection(useProjection) {
132
- const pressure = useProjection('contextPressure');
133
- return pressure?.contextWindow !== undefined && pressure.contextWindow > 0
134
- ? pressure.contextWindow
135
- : DEFAULT_CONTEXT_WINDOW;
136
- }
137
112
  /** Compact trigger used when the host has no ContextMeter settings child slot. */
138
113
  function LegacyContextSizeControl({ sessionId, useSessions, useProjection, useSettings, setSetting, unsetSetting, t }) {
139
114
  const agentPreset = useSessions(state => state.byId[sessionId]?.agentPreset);
@@ -247,11 +222,12 @@ export function ActivityLine({ sessionId, useSession, useSessions, useProjection
247
222
  lineHeight: '20px',
248
223
  whiteSpace: 'nowrap',
249
224
  }, children: [_jsx("span", { "aria-hidden": "true", style: {
250
- width: 7,
251
- height: 7,
225
+ width: 5,
226
+ height: 5,
252
227
  flex: '0 0 auto',
253
228
  borderRadius: '50%',
254
229
  background: 'var(--dsw-static-blue-500)',
230
+ opacity: 0.55,
255
231
  } }), _jsx("span", { children: label }), _jsxs("span", { style: { color: 'var(--dsw-alias-label-tertiary)' }, children: ["\u00B7 ", elapsedSeconds(activity.startedAt, now), "s"] })] }));
256
232
  }
257
233
  /** Preserve the old composer-dock footprint for hosts without the chat status seat. */
@@ -259,25 +235,7 @@ function ActivityDock(props) {
259
235
  return (_jsx("div", { style: { display: 'flex', alignItems: 'center', minHeight: 28, padding: '4px 10px' }, children: _jsx(ActivityLine, { ...props }) }));
260
236
  }
261
237
  export const inject = ['slots', 'locale', 'settingsScope'];
262
- /** Select a preferred slot when the host declares it, otherwise use a stable legacy composer seat. */
263
- export function chooseDeclaredSlot(preferred, fallback, isDeclared) {
264
- return isDeclared(preferred) ? preferred : fallback;
265
- }
266
- function slotIsDeclared(ctx, slot) {
267
- const registry = ctx.slots;
268
- return typeof registry.spec === 'function' && registry.spec.call(ctx.slots, slot) !== undefined;
269
- }
270
- /** Register an optional host slot without claiming it in older SlotMap declarations. */
271
- function injectOptionalActivitySlot(ctx, slot) {
272
- const registry = ctx.slots;
273
- registry.inject(slot, () => registry.register({
274
- name: slot,
275
- id: 'codex-activity',
276
- order: 5,
277
- locale: NS,
278
- }, ActivityLine));
279
- }
280
- /** Mount Codex controls in the newest named seats, with legacy composer fallbacks. */
238
+ /** Mount all controls through the official composer seats shared by every DSH release. */
281
239
  export function apply(ctx) {
282
240
  ctx.effect(() => ctx.locale.register(NS, { en, zh }), 'codex client: dictionaries');
283
241
  const settings = ctx.settingsScope.bind({ namespace: SETTINGS_NAMESPACE });
@@ -286,56 +244,26 @@ export function apply(ctx) {
286
244
  setSetting: (field, value) => settings.set(field, value),
287
245
  unsetSetting: (field) => settings.unset(field),
288
246
  });
289
- const fastSlot = chooseDeclaredSlot(MODEL_SETTINGS_SLOT, FAST_FALLBACK_SLOT, slot => slotIsDeclared(ctx, slot));
290
- if (fastSlot === MODEL_SETTINGS_SLOT) {
291
- ctx.slots.inject(MODEL_SETTINGS_SLOT, () => ctx.slots.register({
292
- name: MODEL_SETTINGS_SLOT,
293
- id: 'codex-fast',
294
- order: 0,
295
- locale: NS,
296
- inject: injected,
297
- }, FastModeButton));
298
- }
299
- else {
300
- ctx.slots.inject(FAST_FALLBACK_SLOT, () => ctx.slots.register({
301
- name: FAST_FALLBACK_SLOT,
302
- id: 'codex-fast-fallback',
303
- order: 0,
304
- locale: NS,
305
- inject: injected,
306
- }, FastModeFallback));
307
- }
308
- const contextSlot = chooseDeclaredSlot(CONTEXT_SETTINGS_SLOT, CONTEXT_FALLBACK_SLOT, slot => slotIsDeclared(ctx, slot));
309
- if (contextSlot === CONTEXT_SETTINGS_SLOT) {
310
- ctx.slots.inject(CONTEXT_SETTINGS_SLOT, () => ctx.slots.register({
311
- name: CONTEXT_SETTINGS_SLOT,
312
- id: 'codex-context-size',
313
- order: 0,
314
- locale: NS,
315
- inject: injected,
316
- }, ContextSizeControl));
317
- }
318
- else {
319
- ctx.slots.inject(CONTEXT_FALLBACK_SLOT, () => ctx.slots.register({
320
- name: CONTEXT_FALLBACK_SLOT,
321
- id: 'codex-context-size-fallback',
322
- order: 0,
323
- locale: NS,
324
- inject: injected,
325
- }, LegacyContextSizeControl));
326
- }
327
- const activitySlot = chooseDeclaredSlot(ACTIVITY_SLOT, ACTIVITY_FALLBACK_SLOT, slot => slotIsDeclared(ctx, slot));
328
- if (activitySlot === ACTIVITY_SLOT) {
329
- injectOptionalActivitySlot(ctx, ACTIVITY_SLOT);
330
- }
331
- else {
332
- ctx.slots.inject(ACTIVITY_FALLBACK_SLOT, () => ctx.slots.register({
333
- name: ACTIVITY_FALLBACK_SLOT,
334
- id: 'codex-activity',
335
- order: 5,
336
- locale: NS,
337
- }, ActivityDock));
338
- }
247
+ ctx.slots.inject(FAST_FALLBACK_SLOT, () => ctx.slots.register({
248
+ name: FAST_FALLBACK_SLOT,
249
+ id: 'codex-fast',
250
+ order: 0,
251
+ locale: NS,
252
+ inject: injected,
253
+ }, FastModeFallback));
254
+ ctx.slots.inject(CONTEXT_FALLBACK_SLOT, () => ctx.slots.register({
255
+ name: CONTEXT_FALLBACK_SLOT,
256
+ id: 'codex-context-size',
257
+ order: 1,
258
+ locale: NS,
259
+ inject: injected,
260
+ }, LegacyContextSizeControl));
261
+ ctx.slots.inject(ACTIVITY_FALLBACK_SLOT, () => ctx.slots.register({
262
+ name: ACTIVITY_FALLBACK_SLOT,
263
+ id: 'codex-activity',
264
+ order: 5,
265
+ locale: NS,
266
+ }, ActivityDock));
339
267
  }
340
268
  export default { inject, apply };
341
269
  //# sourceMappingURL=index.js.map
@@ -1,21 +1,60 @@
1
1
  /** Codex compaction backend that honors the latest durable request capacity. */
2
2
  import { AsyncLocalStorage } from 'node:async_hooks';
3
3
  import BasicCompactionEngine from '@deepseek-ai/dsh-compaction-basic';
4
+ import { settingsNamespace } from '@deepseek-ai/dsh-settings';
5
+ const CODEX_SETTINGS_NAMESPACE = settingsNamespace('codex');
6
+ /** Codex context overrides apply only to GPT-compatible model routes. */
7
+ function isGptModel(model) {
8
+ return /(?:^|\/)(?:gpt|chatgpt)(?:[-_.]|\d|$)/i.test(model);
9
+ }
10
+ /** Read the live Codex capacity without requiring a custom LLM service API. */
11
+ function configuredContextWindow(ctx) {
12
+ const settings = ctx.get('settings');
13
+ if (settings?.get === undefined)
14
+ return { available: false };
15
+ const value = settings?.get?.(CODEX_SETTINGS_NAMESPACE);
16
+ return {
17
+ available: true,
18
+ ...value?.contextWindow !== undefined
19
+ && Number.isSafeInteger(value.contextWindow)
20
+ && value.contextWindow > 0
21
+ ? { value: value.contextWindow }
22
+ : {},
23
+ };
24
+ }
25
+ /** Read an explicit capacity persisted in the request header when settings are unavailable. */
26
+ function requestContextWindow(session, provider, model) {
27
+ const config = session.requestHeader()?.config;
28
+ if (config?.provider !== provider || config.model !== model)
29
+ return undefined;
30
+ const value = config.contextWindow;
31
+ return typeof value === 'number' && Number.isSafeInteger(value) && value > 0 ? value : undefined;
32
+ }
4
33
  /** Overlay only the capacity lookup used by pressure compaction. */
5
- function withDurableContextCapacity(llm, activeSession) {
34
+ function withDurableContextCapacity(llm, ctx, activeSession) {
6
35
  return new Proxy(llm, {
7
36
  get(target, property) {
8
37
  if (property === 'resolveModelInfo') {
9
38
  return async (provider, model, signal) => {
10
39
  const info = await target.resolveModelInfo(provider, model, signal);
11
40
  const requestContext = activeSession.getStore()?.requestContext();
12
- if (requestContext?.provider !== provider
13
- || requestContext.model !== model
14
- || requestContext.contextWindow === undefined)
41
+ const session = activeSession.getStore();
42
+ const configured = isGptModel(model)
43
+ ? configuredContextWindow(ctx)
44
+ : { available: false };
45
+ // A live setting must win before the old request header: automatic
46
+ // pressure runs before the next request rebuilds that header.
47
+ const contextWindow = configured.available
48
+ ? configured.value
49
+ : (session === undefined ? undefined : requestContextWindow(session, provider, model))
50
+ ?? (requestContext?.provider === provider && requestContext.model === model
51
+ ? requestContext.contextWindow
52
+ : undefined);
53
+ if (contextWindow === undefined)
15
54
  return info;
16
55
  return {
17
56
  ...info,
18
- context: { ...info.context, contextWindow: requestContext.contextWindow },
57
+ context: { ...info.context, contextWindow },
19
58
  };
20
59
  };
21
60
  }
@@ -38,7 +77,7 @@ export default class CodexCompactionEngine extends BasicCompactionEngine {
38
77
  const llm = ctx.get('llm');
39
78
  if (llm === undefined)
40
79
  throw new Error('codex compaction requires ctx.llm');
41
- super(ctx.extend({ llm: withDurableContextCapacity(llm, activeSession) }), config);
80
+ super(ctx.extend({ llm: withDurableContextCapacity(llm, ctx, activeSession) }), config);
42
81
  this.activeSession = activeSession;
43
82
  }
44
83
  compactIfNeeded(agent, trigger, signal) {
@@ -3,14 +3,6 @@ import type { Context } from '@deepseek-ai/cordis';
3
3
  import z from '@deepseek-ai/schemastery';
4
4
  import type { LlmCallConfig } from '@deepseek-ai/dsh-llm';
5
5
  import type { PromptAssembly } from '@deepseek-ai/dsh-system-prompt';
6
- declare module '@deepseek-ai/dsh-llm' {
7
- interface LlmCallConfig {
8
- /** Codex request context capacity override, in tokens. */
9
- contextWindow?: number;
10
- /** Provider-facing service tier, for example Responses `priority`. */
11
- serviceTier?: string;
12
- }
13
- }
14
6
  export declare const name = "codex";
15
7
  export declare const inject: string[];
16
8
  /** Configuration for the Codex shell result bridge. */
@@ -40,6 +32,13 @@ export interface CodexSettings {
40
32
  /** Optional context capacity override, in tokens. */
41
33
  contextWindow?: number;
42
34
  }
35
+ /** Plugin-owned extension envelope; official DSH can carry these as unknown fields. */
36
+ export interface CodexRequestConfig extends LlmCallConfig {
37
+ /** Codex request context capacity override, in tokens. */
38
+ contextWindow?: number;
39
+ /** Provider-facing service tier, for example Responses `priority`. */
40
+ serviceTier?: string;
41
+ }
43
42
  export declare const CODEX_SETTINGS_SCHEMA: z<CodexSettings>;
44
43
  export interface CodexModelProfile {
45
44
  id: string;
@@ -50,7 +49,7 @@ export interface CodexModelProfile {
50
49
  /** Add Codex defaults without overwriting explicit user capabilities. */
51
50
  export declare function enrichCodexModel(model: CodexModelProfile): CodexModelProfile;
52
51
  /** Apply the live Codex controls to one agent request without leaking them to other routes. */
53
- export declare function applyCodexRequestSettings(request: LlmCallConfig, settings: CodexSettings): LlmCallConfig;
52
+ export declare function applyCodexRequestSettings(request: CodexRequestConfig, settings: CodexSettings): CodexRequestConfig;
54
53
  /** Put the agent persona first and omit the generic Harness identity opener. */
55
54
  export declare function normalizeCodexPromptAssembly(assembly: PromptAssembly): PromptAssembly;
56
55
  /** Build the Codex operating prompt with optional, user-enabled collaboration guidance. */
@@ -166,17 +166,16 @@ const CODEX_BASE_PROMPT = String.raw `## General
166
166
  ## Presenting your work
167
167
 
168
168
  - Be concise, direct, friendly, and actionable.
169
- - For substantial work, explain what changed and why, then mention relevant verification and next steps.
169
+ - For substantial work, explain what changed and why, then briefly note how the work was verified and what comes next.
170
170
  - Do not dump large files into the conversation; refer to their paths.
171
171
  - Use plain text with short sections only when they improve scanability.
172
172
  `;
173
173
  const CODEX_COLLABORATION_PROMPT = String.raw `## Collaboration
174
174
 
175
- - Ask, align, and clarify first. Try your best to understand the user's full picture.
175
+ - Gather enough context from the user then achieve the user's goal through the clearest, most effective path.
176
176
  - Keep only the essential logic and core actions. There's no need to explain or test what was removed or why something wasn't done.
177
177
  - Convey enough valuable information with as few words as possible. Stay focused on the end goal.
178
178
  - Solve problems by thinking from first principles and at a higher level.
179
- - Make things as effortless as possible for the user.
180
179
  `;
181
180
  /** Put the agent persona first and omit the generic Harness identity opener. */
182
181
  export function normalizeCodexPromptAssembly(assembly) {
@@ -485,7 +484,7 @@ export function apply(ctx, config = {}) {
485
484
  // scope so apply_patch can use the same wire bridge even when hosted search
486
485
  // and remote compaction are disabled.
487
486
  if (options.purpose === undefined && isGptModel(options.model)) {
488
- return hostedWebSearchStream(next);
487
+ return hostedWebSearchStream(next, { serviceTier: options.serviceTier });
489
488
  }
490
489
  return next();
491
490
  }));
@@ -7,6 +7,10 @@ export interface RemoteCodexConfig {
7
7
  interface JsonObject {
8
8
  [key: string]: unknown;
9
9
  }
10
+ interface CodexRequestWireOptions {
11
+ /** Provider-facing request option preserved by older DSH LLM adapters. */
12
+ serviceTier?: string;
13
+ }
10
14
  /** Replace DSH's JSON function declaration with the Responses custom grammar tool. */
11
15
  export declare function addCodexApplyPatch(body: JsonObject): JsonObject;
12
16
  /** Replay apply_patch calls as custom tool items after pi-ai's generic conversion. */
@@ -20,7 +24,7 @@ export declare function replaceRemoteCompactions(body: JsonObject): JsonObject;
20
24
  /** Enable the transport patch for this Codex plugin scope only. */
21
25
  export declare function installHostedWebSearch(): () => void;
22
26
  /** Iterate an existing DSH stream with the hosted-request context installed. */
23
- export declare function hostedWebSearchStream(next: () => AsyncIterable<StreamChunk>): AsyncIterable<StreamChunk>;
27
+ export declare function hostedWebSearchStream(next: () => AsyncIterable<StreamChunk>, options?: CodexRequestWireOptions): AsyncIterable<StreamChunk>;
24
28
  /** Remote-first compaction waterfall with the existing DSH path as fallback. */
25
29
  export declare function remoteCompactStream(ctx: Context, options: GenerateOptions, next: () => AsyncIterable<StreamChunk>): AsyncIterable<StreamChunk>;
26
30
  export {};
@@ -7,6 +7,10 @@ const REMOTE_COMPACTION_CLOSE = '</codex-remote-compaction>';
7
7
  const HOSTED_REQUESTS = new AsyncLocalStorage();
8
8
  let hostedPatchUsers = 0;
9
9
  let hostedPatchRestore;
10
+ function serviceTierOf(options) {
11
+ const value = options.serviceTier;
12
+ return typeof value === 'string' ? value : undefined;
13
+ }
10
14
  function isGptModel(model) {
11
15
  return typeof model === 'string' && /(?:^|\/)(?:gpt|chatgpt)(?:[-_.]|\d|$)/i.test(model);
12
16
  }
@@ -268,6 +272,12 @@ function canPatchBody(body) {
268
272
  || hasRemoteCompaction(body)
269
273
  || (hasFunctionApplyPatchTool(body) && canRewriteApplyPatchHistory(body)));
270
274
  }
275
+ /** Add provider options that older pi-ai adapters do not copy themselves. */
276
+ function applyRequestWireOptions(body, options) {
277
+ if (options.serviceTier === undefined || !isGptModel(body.model))
278
+ return body;
279
+ return { ...body, service_tier: options.serviceTier };
280
+ }
271
281
  /**
272
282
  * Install a scoped fetch shim for pi-ai's already-built Responses request.
273
283
  * The generic DSH adapter remains the owner of auth, streaming, replay, and
@@ -277,7 +287,8 @@ function canPatchBody(body) {
277
287
  function installGlobalHostedWebSearchPatch() {
278
288
  const original = globalThis.fetch;
279
289
  const patched = async (input, init) => {
280
- if (!HOSTED_REQUESTS.getStore())
290
+ const options = HOSTED_REQUESTS.getStore();
291
+ if (options === undefined)
281
292
  return original(input, init);
282
293
  const request = new Request(input, init);
283
294
  if (!isResponsesRequest(request.url))
@@ -289,13 +300,29 @@ function installGlobalHostedWebSearchPatch() {
289
300
  catch {
290
301
  return original(input, init);
291
302
  }
292
- if (!canPatchBody(body))
293
- return original(input, init);
294
- const fallbackRequest = request.clone();
303
+ const requestBody = applyRequestWireOptions(body, options);
304
+ if (!canPatchBody(requestBody)) {
305
+ if (requestBody === body)
306
+ return original(input, init);
307
+ const headers = new Headers(request.headers);
308
+ headers.delete('content-length');
309
+ return original(new Request(request, {
310
+ body: JSON.stringify(requestBody),
311
+ headers,
312
+ }));
313
+ }
314
+ const fallbackHeaders = new Headers(request.headers);
315
+ fallbackHeaders.delete('content-length');
316
+ const fallbackRequest = requestBody === body
317
+ ? request.clone()
318
+ : new Request(request, {
319
+ body: JSON.stringify(requestBody),
320
+ headers: fallbackHeaders,
321
+ });
295
322
  const headers = new Headers(request.headers);
296
323
  headers.delete('content-length');
297
324
  const hostedRequest = new Request(request, {
298
- body: JSON.stringify(rewriteCodexResponsesBody(body)),
325
+ body: JSON.stringify(rewriteCodexResponsesBody(requestBody)),
299
326
  headers,
300
327
  });
301
328
  try {
@@ -331,13 +358,13 @@ export function installHostedWebSearch() {
331
358
  };
332
359
  }
333
360
  /** Iterate an existing DSH stream with the hosted-request context installed. */
334
- export function hostedWebSearchStream(next) {
361
+ export function hostedWebSearchStream(next, options = {}) {
335
362
  return (async function* () {
336
363
  const iterator = next()[Symbol.asyncIterator]();
337
364
  let completed = false;
338
365
  try {
339
366
  while (true) {
340
- const item = await HOSTED_REQUESTS.run(true, () => iterator.next());
367
+ const item = await HOSTED_REQUESTS.run(options, () => iterator.next());
341
368
  if (item.done) {
342
369
  completed = true;
343
370
  return;
@@ -509,7 +536,8 @@ export function remoteCompactStream(ctx, options, next) {
509
536
  ctx.logger.warn(error);
510
537
  // The local fallback still replays the marker through a later GPT
511
538
  // Responses request, so it needs the same scoped wire context.
512
- yield* hostedWebSearchStream(next);
539
+ const serviceTier = serviceTierOf(options);
540
+ yield* hostedWebSearchStream(next, serviceTier === undefined ? {} : { serviceTier });
513
541
  }
514
542
  })();
515
543
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shuind/dsh-codex-harness",
3
- "version": "0.1.27",
3
+ "version": "0.1.28",
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",
@@ -92,8 +92,9 @@
92
92
  "@deepseek-ai/dsh-client-ui-conversation": ">=0.1.0-rc.8",
93
93
  "@deepseek-ai/dsh-client-ui-settings": ">=0.1.0-rc.8",
94
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",
95
+ "@deepseek-ai/dsh-compaction": ">=0.1.0-rc.8",
96
+ "@deepseek-ai/dsh-compaction-basic": ">=0.1.0-rc.8",
97
+ "@deepseek-ai/dsh-compaction-tool-result-pruner": ">=0.1.0-rc.8",
97
98
  "@deepseek-ai/dsh-credentials": ">=0.1.0-rc.8",
98
99
  "@deepseek-ai/dsh-fs": ">=0.0.1-rc.1",
99
100
  "@deepseek-ai/dsh-invariants": ">=0.0.1-rc.1",
@@ -102,7 +103,7 @@
102
103
  "@deepseek-ai/dsh-settings": ">=0.1.0-rc.8",
103
104
  "@deepseek-ai/dsh-sandbox": ">=0.0.1-rc.1",
104
105
  "@deepseek-ai/dsh-sandbox-policy": ">=0.0.1-rc.1",
105
- "@deepseek-ai/dsh-session": ">=0.1.1-rc.2",
106
+ "@deepseek-ai/dsh-session": ">=0.1.0-rc.8",
106
107
  "@deepseek-ai/dsh-shell": ">=0.0.1-rc.5",
107
108
  "@deepseek-ai/dsh-shell-env": ">=0.0.1-rc.3",
108
109
  "@deepseek-ai/dsh-system-prompt": ">=0.0.1-rc.1",
@@ -110,7 +111,7 @@
110
111
  "@deepseek-ai/dsh-tool-todo": ">=0.0.1-rc.1",
111
112
  "@deepseek-ai/dsh-terminal": ">=0.0.1-rc.3",
112
113
  "@deepseek-ai/dsh-tool-jobs": ">=0.1.0-rc.8",
113
- "@deepseek-ai/dsh-token-meter": ">=0.1.1-rc.2",
114
+ "@deepseek-ai/dsh-token-meter": ">=0.1.0-rc.8",
114
115
  "@deepseek-ai/dsh-tools": ">=0.0.1-rc.1"
115
116
  },
116
117
  "peerDependenciesMeta": {
@@ -141,6 +142,9 @@
141
142
  "@deepseek-ai/dsh-compaction-basic": {
142
143
  "optional": true
143
144
  },
145
+ "@deepseek-ai/dsh-compaction-tool-result-pruner": {
146
+ "optional": true
147
+ },
144
148
  "@deepseek-ai/dsh-credentials": {
145
149
  "optional": true
146
150
  },
@@ -1,3 +1,3 @@
1
1
  name: Codex 模式
2
- description: 使用精简版 Codex 提示词、统一执行工具、后台任务控制和 dsh Skills。
2
+ description: 使用精简版 Codex 提示词和工具,以及改善体验的功能。
3
3
  order: 5
@@ -1,5 +1,5 @@
1
- # The Codex collaboration preset. It shares the standard Codex composition
2
- # while enabling the optional collaboration guidance in the prompt layer.
1
+ # The Codex agent preset. The bundle installs this file into the DSH user
2
+ # preset root on first boot; the tool row is deliberately not global.
3
3
 
4
4
  - id: persona
5
5
  name: '@deepseek-ai/dsh-persona'
@@ -14,8 +14,8 @@
14
14
  config:
15
15
  maxBytes: 65536
16
16
 
17
- # The collaboration variant only changes this flag; execution remains
18
- # delegated to the same dsh Codex tool layer.
17
+ # This is the complete model-facing Codex layer. It owns the prompt overlay
18
+ # and the four Codex core tool names; execution remains delegated to dsh.
19
19
  - id: codex-tools
20
20
  name: '@shuind/dsh-codex-harness'
21
21
  config:
@@ -1,3 +1,3 @@
1
1
  name: Codex 协作模式
2
- description: 使用精简版 Codex 提示词,并加入协作提示词、统一执行工具、后台任务控制和 dsh Skills。
2
+ description: 额外加入协作提示词,预期获得更好的体验。
3
3
  order: 6