@shuind/dsh-codex-harness 0.1.30 → 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/index.js +44 -1
- package/lib/types/index.d.ts +10 -0
- package/lib/types/index.js +56 -0
- package/package.json +1 -1
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 };
|
package/lib/types/index.d.ts
CHANGED
|
@@ -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. */
|
package/lib/types/index.js
CHANGED
|
@@ -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.
|
|
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",
|