@shuind/dsh-codex-harness 0.1.29 → 0.1.31

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
@@ -74,7 +74,6 @@ window.__ModuleLoader__.load({
74
74
  const SETTINGS_NAMESPACE = "codex";
75
75
  const ACTIVITY_FALLBACK_SLOT = "conversation.composer.dock";
76
76
  const FAST_FALLBACK_SLOT = "conversation.input.right";
77
- const CONTEXT_FALLBACK_SLOT = "conversation.input.right";
78
77
  const DEFAULT_CONTEXT_WINDOW = 262144;
79
78
  const en = {
80
79
  fast: "Fast mode",
@@ -277,8 +276,8 @@ window.__ModuleLoader__.load({
277
276
  ]
278
277
  });
279
278
  }
280
- /** Compact trigger used when the host has no ContextMeter settings child slot. */
281
- function LegacyContextSizeControl({ sessionId, useSessions, useProjection, useSettings, setSetting, unsetSetting, t }) {
279
+ /** Compact context-capacity trigger shown beside the bottom activity line. */
280
+ function ContextSizeDock({ sessionId, useSessions, useProjection, useSettings, setSetting, unsetSetting, t }) {
282
281
  const agentPreset = useSessions((state) => state.byId[sessionId]?.agentPreset);
283
282
  const contextWindow = contextWindowFromProjection(useProjection);
284
283
  const snapshot = useSettings((state) => state);
@@ -448,16 +447,17 @@ window.__ModuleLoader__.load({
448
447
  ]
449
448
  });
450
449
  }
451
- /** Preserve the old composer-dock footprint for hosts without the chat status seat. */
450
+ /** Keep the activity status and context control in one compact composer row. */
452
451
  function ActivityDock(props) {
453
- return (0, react_jsx_runtime.jsx)("div", {
452
+ return (0, react_jsx_runtime.jsxs)("div", {
454
453
  style: {
455
454
  display: "flex",
456
455
  alignItems: "center",
456
+ gap: 8,
457
457
  minHeight: 28,
458
458
  padding: "4px 10px"
459
459
  },
460
- children: (0, react_jsx_runtime.jsx)(ActivityLine, { ...props })
460
+ children: [(0, react_jsx_runtime.jsx)(ContextSizeDock, { ...props }), (0, react_jsx_runtime.jsx)(ActivityLine, { ...props })]
461
461
  });
462
462
  }
463
463
  const inject = [
@@ -484,18 +484,12 @@ window.__ModuleLoader__.load({
484
484
  locale: NS,
485
485
  inject: injected
486
486
  }, FastModeFallback));
487
- ctx.slots.inject(CONTEXT_FALLBACK_SLOT, () => ctx.slots.register({
488
- name: CONTEXT_FALLBACK_SLOT,
489
- id: "codex-context-size",
490
- order: 1,
491
- locale: NS,
492
- inject: injected
493
- }, LegacyContextSizeControl));
494
487
  ctx.slots.inject(ACTIVITY_FALLBACK_SLOT, () => ctx.slots.register({
495
488
  name: ACTIVITY_FALLBACK_SLOT,
496
489
  id: "codex-activity",
497
490
  order: 5,
498
- locale: NS
491
+ locale: NS,
492
+ inject: injected
499
493
  }, ActivityDock));
500
494
  }
501
495
  var client_default = {
package/lib/index.js CHANGED
@@ -1200,6 +1200,48 @@ function installCodexSettings(ctx) {
1200
1200
  });
1201
1201
  return { current: () => source() };
1202
1202
  }
1203
+ function hasOpenTurn(session) {
1204
+ const start = session.events.findLast((event) => event.type === "turn/start");
1205
+ const end = session.events.findLast((event) => event.type === "turn/end");
1206
+ return start !== void 0 && (end === void 0 || start.seq > end.seq);
1207
+ }
1208
+ /**
1209
+ * Pair the live Codex capacity with the token-meter context projection.
1210
+ *
1211
+ * The core loop records adapter metadata in `request/context`, while Codex's
1212
+ * setting is a plugin-owned request extension. Appending the override after
1213
+ * the loop's metadata event keeps the official ContextMeter and compaction
1214
+ * engine on the same effective capacity.
1215
+ */
1216
+ function syncCodexContextWindow(session, contextWindow) {
1217
+ if (contextWindow === void 0 || !Number.isSafeInteger(contextWindow) || contextWindow <= 0 || !hasOpenTurn(session)) return;
1218
+ const config = session.requestHeader()?.config;
1219
+ if (typeof config?.provider !== "string" || typeof config.model !== "string" || !isGptModel(config.model)) return;
1220
+ const current = session.requestContext();
1221
+ if (current?.provider === config.provider && current.model === config.model && current.contextWindow === contextWindow) return;
1222
+ session.append("request/context", {
1223
+ provider: config.provider,
1224
+ model: config.model,
1225
+ contextWindow
1226
+ });
1227
+ }
1228
+ /** Keep the official context meter synchronized with a live Codex override. */
1229
+ function installCodexContextProjection(ctx, current) {
1230
+ const sync = (session) => {
1231
+ syncCodexContextWindow(session, current().contextWindow);
1232
+ };
1233
+ const syncAll = () => {
1234
+ const sessions = ctx.get("sessions");
1235
+ for (const session of sessions?.list?.() ?? []) sync(session);
1236
+ };
1237
+ ctx.on("session/event", (session, event) => {
1238
+ if (event.type === "request/header" || event.type === "request/context") sync(session);
1239
+ });
1240
+ ctx.on("settings/document-updated", (ns) => {
1241
+ if (ns === CODEX_SETTINGS_NAMESPACE) syncAll();
1242
+ });
1243
+ syncAll();
1244
+ }
1203
1245
  /** Apply the live Codex controls to one agent request without leaking them to other routes. */
1204
1246
  function applyCodexRequestSettings(request, settings) {
1205
1247
  const { contextWindow: _inheritedContextWindow, serviceTier: _inheritedServiceTier, ...withoutCodexControls } = request;
@@ -1644,6 +1686,7 @@ function apply(ctx, config = {}) {
1644
1686
  watchConfiguredGptModels(ctx);
1645
1687
  registerCodexActivityProjection(ctx);
1646
1688
  const codexSettings = installCodexSettings(ctx);
1689
+ installCodexContextProjection(ctx, codexSettings.current);
1647
1690
  ctx.on("agent/request", async (_payload, next) => {
1648
1691
  return applyCodexRequestSettings(await next(), codexSettings.current());
1649
1692
  });
@@ -1673,4 +1716,4 @@ var types_default = {
1673
1716
  apply
1674
1717
  };
1675
1718
  //#endregion
1676
- export { CODEX_SETTINGS_NAMESPACE, CODEX_SETTINGS_SCHEMA, Config, apply, applyCodexRequestSettings, buildCodexSystemPrompt, types_default as default, enrichCodexModel, inject, name, normalizeCodexPromptAssembly };
1719
+ export { CODEX_SETTINGS_NAMESPACE, CODEX_SETTINGS_SCHEMA, Config, apply, applyCodexRequestSettings, buildCodexSystemPrompt, types_default as default, enrichCodexModel, inject, name, normalizeCodexPromptAssembly, syncCodexContextWindow };
@@ -1,6 +1,12 @@
1
1
  /** Browser controls for the Codex request settings mounted by the Host plugin. */
2
- import type { PropsLocale, PropsRuntime } from '@deepseek-ai/dsh-client-ui-slots';
2
+ import type { HostObservable, InjectFace, PropsLocale, PropsRuntime } from '@deepseek-ai/dsh-client-ui-slots';
3
3
  import type { Context } from '@deepseek-ai/cordis';
4
+ import type { SettingsScope } from '@deepseek-ai/dsh-client-runtime/client';
5
+ interface CodexSettings {
6
+ fast: boolean;
7
+ contextWindow?: number;
8
+ }
9
+ type CodexScope = SettingsScope<CodexSettings>;
4
10
  declare const en: {
5
11
  readonly fast: "Fast mode";
6
12
  readonly fastOn: "Fast mode on (priority tier)";
@@ -20,7 +26,15 @@ declare module '@deepseek-ai/dsh-client-ui-slots' {
20
26
  codex: CodexKey;
21
27
  }
22
28
  }
23
- type ActivityDockProps = PropsRuntime<'conversation.composer.dock'> & PropsLocale<'codex'>;
29
+ interface InputSettingsControlInjected {
30
+ hooks: {
31
+ settings: HostObservable<ReturnType<CodexScope['getSnapshot']>>;
32
+ };
33
+ setSetting: (field: string, value: unknown) => Promise<void>;
34
+ unsetSetting: (field: string) => Promise<void>;
35
+ }
36
+ type ContextDockProps = PropsRuntime<'conversation.composer.dock'> & InjectFace<InputSettingsControlInjected> & PropsLocale<'codex'>;
37
+ type ActivityDockProps = ContextDockProps & PropsLocale<'codex'>;
24
38
  type ActivityProps = ActivityDockProps;
25
39
  export declare function ActivityLine({ sessionId, useSession, useSessions, useProjection, t }: ActivityProps): import("react").JSX.Element | null;
26
40
  export declare const inject: string[];
@@ -7,7 +7,6 @@ const NS = 'codex';
7
7
  const SETTINGS_NAMESPACE = 'codex';
8
8
  const ACTIVITY_FALLBACK_SLOT = 'conversation.composer.dock';
9
9
  const FAST_FALLBACK_SLOT = 'conversation.input.right';
10
- const CONTEXT_FALLBACK_SLOT = 'conversation.input.right';
11
10
  const DEFAULT_CONTEXT_WINDOW = 262_144;
12
11
  const en = {
13
12
  fast: 'Fast mode',
@@ -109,8 +108,8 @@ function ContextSizeControl({ contextWindow, useSettings, setSetting, unsetSetti
109
108
  fontSize: 11,
110
109
  }, children: t('contextRestore') }))] }));
111
110
  }
112
- /** Compact trigger used when the host has no ContextMeter settings child slot. */
113
- function LegacyContextSizeControl({ sessionId, useSessions, useProjection, useSettings, setSetting, unsetSetting, t }) {
111
+ /** Compact context-capacity trigger shown beside the bottom activity line. */
112
+ function ContextSizeDock({ sessionId, useSessions, useProjection, useSettings, setSetting, unsetSetting, t }) {
114
113
  const agentPreset = useSessions(state => state.byId[sessionId]?.agentPreset);
115
114
  const contextWindow = contextWindowFromProjection(useProjection);
116
115
  const snapshot = useSettings(state => state);
@@ -230,9 +229,15 @@ export function ActivityLine({ sessionId, useSession, useSessions, useProjection
230
229
  opacity: 0.55,
231
230
  } }), _jsx("span", { children: label }), _jsxs("span", { style: { color: 'var(--dsw-alias-label-tertiary)' }, children: ["\u00B7 ", elapsedSeconds(activity.startedAt, now), "s"] })] }));
232
231
  }
233
- /** Preserve the old composer-dock footprint for hosts without the chat status seat. */
232
+ /** Keep the activity status and context control in one compact composer row. */
234
233
  function ActivityDock(props) {
235
- return (_jsx("div", { style: { display: 'flex', alignItems: 'center', minHeight: 28, padding: '4px 10px' }, children: _jsx(ActivityLine, { ...props }) }));
234
+ return (_jsxs("div", { style: {
235
+ display: 'flex',
236
+ alignItems: 'center',
237
+ gap: 8,
238
+ minHeight: 28,
239
+ padding: '4px 10px',
240
+ }, children: [_jsx(ContextSizeDock, { ...props }), _jsx(ActivityLine, { ...props })] }));
236
241
  }
237
242
  export const inject = ['slots', 'locale', 'settingsScope'];
238
243
  /** Mount all controls through the official composer seats shared by every DSH release. */
@@ -251,18 +256,12 @@ export function apply(ctx) {
251
256
  locale: NS,
252
257
  inject: injected,
253
258
  }, 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
259
  ctx.slots.inject(ACTIVITY_FALLBACK_SLOT, () => ctx.slots.register({
262
260
  name: ACTIVITY_FALLBACK_SLOT,
263
261
  id: 'codex-activity',
264
262
  order: 5,
265
263
  locale: NS,
264
+ inject: injected,
266
265
  }, ActivityDock));
267
266
  }
268
267
  export default { inject, apply };
@@ -2,6 +2,7 @@
2
2
  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
+ import type { Session } from '@deepseek-ai/dsh-session';
5
6
  import type { PromptAssembly } from '@deepseek-ai/dsh-system-prompt';
6
7
  export declare const name = "codex";
7
8
  export declare const inject: string[];
@@ -48,6 +49,15 @@ export interface CodexModelProfile {
48
49
  }
49
50
  /** Add Codex defaults without overwriting explicit user capabilities. */
50
51
  export declare function enrichCodexModel(model: CodexModelProfile): CodexModelProfile;
52
+ /**
53
+ * Pair the live Codex capacity with the token-meter context projection.
54
+ *
55
+ * The core loop records adapter metadata in `request/context`, while Codex's
56
+ * setting is a plugin-owned request extension. Appending the override after
57
+ * the loop's metadata event keeps the official ContextMeter and compaction
58
+ * engine on the same effective capacity.
59
+ */
60
+ export declare function syncCodexContextWindow(session: Session, contextWindow: number | undefined): void;
51
61
  /** Apply the live Codex controls to one agent request without leaking them to other routes. */
52
62
  export declare function applyCodexRequestSettings(request: CodexRequestConfig, settings: CodexSettings): CodexRequestConfig;
53
63
  /** Put the agent persona first and omit the generic Harness identity opener. */
@@ -128,6 +128,61 @@ function installCodexSettings(ctx) {
128
128
  });
129
129
  return { current: () => source() };
130
130
  }
131
+ function hasOpenTurn(session) {
132
+ const start = session.events.findLast(event => event.type === 'turn/start');
133
+ const end = session.events.findLast(event => event.type === 'turn/end');
134
+ return start !== undefined && (end === undefined || start.seq > end.seq);
135
+ }
136
+ /**
137
+ * Pair the live Codex capacity with the token-meter context projection.
138
+ *
139
+ * The core loop records adapter metadata in `request/context`, while Codex's
140
+ * setting is a plugin-owned request extension. Appending the override after
141
+ * the loop's metadata event keeps the official ContextMeter and compaction
142
+ * engine on the same effective capacity.
143
+ */
144
+ export function syncCodexContextWindow(session, contextWindow) {
145
+ if (contextWindow === undefined
146
+ || !Number.isSafeInteger(contextWindow)
147
+ || contextWindow <= 0
148
+ || !hasOpenTurn(session))
149
+ return;
150
+ const config = session.requestHeader()?.config;
151
+ if (typeof config?.provider !== 'string'
152
+ || typeof config.model !== 'string'
153
+ || !isGptModel(config.model))
154
+ return;
155
+ const current = session.requestContext();
156
+ if (current?.provider === config.provider
157
+ && current.model === config.model
158
+ && current.contextWindow === contextWindow)
159
+ return;
160
+ session.append('request/context', {
161
+ provider: config.provider,
162
+ model: config.model,
163
+ contextWindow,
164
+ });
165
+ }
166
+ /** Keep the official context meter synchronized with a live Codex override. */
167
+ function installCodexContextProjection(ctx, current) {
168
+ const sync = (session) => {
169
+ syncCodexContextWindow(session, current().contextWindow);
170
+ };
171
+ const syncAll = () => {
172
+ const sessions = ctx.get('sessions');
173
+ for (const session of sessions?.list?.() ?? [])
174
+ sync(session);
175
+ };
176
+ ctx.on('session/event', (session, event) => {
177
+ if (event.type === 'request/header' || event.type === 'request/context')
178
+ sync(session);
179
+ });
180
+ ctx.on('settings/document-updated', ns => {
181
+ if (ns === CODEX_SETTINGS_NAMESPACE)
182
+ syncAll();
183
+ });
184
+ syncAll();
185
+ }
131
186
  /** Apply the live Codex controls to one agent request without leaking them to other routes. */
132
187
  export function applyCodexRequestSettings(request, settings) {
133
188
  const { contextWindow: _inheritedContextWindow, serviceTier: _inheritedServiceTier, ...withoutCodexControls } = request;
@@ -465,6 +520,7 @@ export function apply(ctx, config = {}) {
465
520
  watchConfiguredGptModels(ctx);
466
521
  registerCodexActivityProjection(ctx);
467
522
  const codexSettings = installCodexSettings(ctx);
523
+ installCodexContextProjection(ctx, codexSettings.current);
468
524
  // Keep these controls in the request config rather than mutating provider
469
525
  // settings. That makes a change apply to the next step without rebuilding
470
526
  // the user's model catalog, while the LLM service still freezes it per call.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shuind/dsh-codex-harness",
3
- "version": "0.1.29",
3
+ "version": "0.1.31",
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",