@shuind/dsh-codex-harness 0.2.1 → 0.2.3
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 +1 -1
- package/cordis.patch.yml +6 -5
- package/lib/client.js +150 -23
- package/lib/compaction.js +20 -5
- package/lib/index.js +186 -56
- package/lib/installer.js +18 -3
- package/lib/types/client/index.d.ts +26 -4
- package/lib/types/client/index.js +70 -25
- package/lib/types/compaction.d.ts +1 -0
- package/lib/types/compaction.js +30 -14
- package/lib/types/index.d.ts +11 -5
- package/lib/types/index.js +93 -45
- package/lib/types/installer.js +1 -0
- package/lib/types/remote.d.ts +6 -2
- package/lib/types/remote.js +118 -21
- package/lib/types/settings.d.ts +14 -0
- package/lib/types/settings.js +14 -0
- package/package.json +1 -1
- package/presets/codex-collaboration/agent.cordis.yml +8 -4
package/lib/index.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import z from "@deepseek-ai/schemastery";
|
|
2
2
|
import { installSettingsSection, settingsNamespace } from "@deepseek-ai/dsh-settings";
|
|
3
3
|
import { defineTool } from "@deepseek-ai/dsh-tools";
|
|
4
|
-
import { randomBytes } from "node:crypto";
|
|
5
|
-
import { resolve } from "node:path";
|
|
4
|
+
import { randomBytes, randomUUID } from "node:crypto";
|
|
5
|
+
import { join, resolve } from "node:path";
|
|
6
6
|
import { credentialRef } from "@deepseek-ai/dsh-credentials";
|
|
7
7
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
8
|
+
import { mkdirSync, writeFileSync } from "node:fs";
|
|
9
|
+
import { homedir } from "node:os";
|
|
8
10
|
import { isTokenDelta } from "@deepseek-ai/dsh-llm/message";
|
|
9
11
|
import { z as z$1 } from "zod";
|
|
10
12
|
//#region lib/types/patch.js
|
|
@@ -524,6 +526,7 @@ async function runWriteStdin(ctx, args, exec, config) {
|
|
|
524
526
|
const SETTINGS_NAMESPACE = "llm-pi-ai";
|
|
525
527
|
const REMOTE_COMPACTION_OPEN = "<codex-remote-compaction>";
|
|
526
528
|
const REMOTE_COMPACTION_CLOSE = "</codex-remote-compaction>";
|
|
529
|
+
const CODEX_ERROR_DIRECTORY = ["diagnostics", "openai-codex-errors"];
|
|
527
530
|
const HOSTED_REQUESTS = new AsyncLocalStorage();
|
|
528
531
|
let hostedPatchUsers = 0;
|
|
529
532
|
let hostedPatchRestore;
|
|
@@ -568,6 +571,66 @@ function isResponsesRequest(url) {
|
|
|
568
571
|
return url.replace(/\/+$/, "").endsWith("/responses");
|
|
569
572
|
}
|
|
570
573
|
}
|
|
574
|
+
function diagnosticsDirectory() {
|
|
575
|
+
const configured = process.env["DSH_HOME"]?.trim();
|
|
576
|
+
const expanded = configured === void 0 || configured.length === 0 ? join(homedir(), ".dsh") : configured === "~" ? homedir() : configured.startsWith("~/") || configured.startsWith("~\\") ? join(homedir(), configured.slice(2)) : configured;
|
|
577
|
+
return join(resolve(expanded), ...CODEX_ERROR_DIRECTORY);
|
|
578
|
+
}
|
|
579
|
+
function saveCodexErrorPayload(payload) {
|
|
580
|
+
const directory = diagnosticsDirectory();
|
|
581
|
+
mkdirSync(directory, {
|
|
582
|
+
recursive: true,
|
|
583
|
+
mode: 448
|
|
584
|
+
});
|
|
585
|
+
const filename = `${Date.now()}-${randomUUID()}.json`;
|
|
586
|
+
writeFileSync(join(directory, filename), `${payload}\n`, {
|
|
587
|
+
flag: "wx",
|
|
588
|
+
mode: 384
|
|
589
|
+
});
|
|
590
|
+
}
|
|
591
|
+
function errorPayloadFromSseFrame(frame) {
|
|
592
|
+
const data = frame.split(/\r?\n/u).filter((line) => line.startsWith("data:")).map((line) => line.slice(5).trimStart()).join("\n").trim();
|
|
593
|
+
if (data.length === 0 || data === "[DONE]") return void 0;
|
|
594
|
+
try {
|
|
595
|
+
const payload = JSON.parse(data);
|
|
596
|
+
return payload.type === "error" || payload.type === "response.failed" ? data : void 0;
|
|
597
|
+
} catch {
|
|
598
|
+
return;
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
async function captureCodexErrorPayloads(response) {
|
|
602
|
+
if (response.body === null) return;
|
|
603
|
+
const reader = response.body.getReader();
|
|
604
|
+
const decoder = new TextDecoder();
|
|
605
|
+
let buffer = "";
|
|
606
|
+
try {
|
|
607
|
+
while (true) {
|
|
608
|
+
const { done, value } = await reader.read();
|
|
609
|
+
buffer += decoder.decode(value, { stream: !done });
|
|
610
|
+
while (true) {
|
|
611
|
+
const delimiter = /\r?\n\r?\n/u.exec(buffer);
|
|
612
|
+
if (delimiter?.index === void 0) break;
|
|
613
|
+
const frame = buffer.slice(0, delimiter.index);
|
|
614
|
+
buffer = buffer.slice(delimiter.index + delimiter[0].length);
|
|
615
|
+
const payload = errorPayloadFromSseFrame(frame);
|
|
616
|
+
if (payload === void 0) continue;
|
|
617
|
+
try {
|
|
618
|
+
saveCodexErrorPayload(payload);
|
|
619
|
+
} catch {}
|
|
620
|
+
}
|
|
621
|
+
if (done) return;
|
|
622
|
+
}
|
|
623
|
+
} finally {
|
|
624
|
+
reader.releaseLock();
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
function captureCodexErrors(response) {
|
|
628
|
+
if (!response.headers.get("content-type")?.toLowerCase().includes("text/event-stream")) return response;
|
|
629
|
+
try {
|
|
630
|
+
captureCodexErrorPayloads(response.clone()).catch(() => {});
|
|
631
|
+
} catch {}
|
|
632
|
+
return response;
|
|
633
|
+
}
|
|
571
634
|
function isWebSearchTool(tool) {
|
|
572
635
|
if (typeof tool !== "object" || tool === null) return false;
|
|
573
636
|
const value = tool;
|
|
@@ -696,11 +759,11 @@ function rewriteCodexApplyPatchHistory(body) {
|
|
|
696
759
|
} : body;
|
|
697
760
|
}
|
|
698
761
|
/** Compose the plugin-only Responses rewrites without changing DSH's tool API. */
|
|
699
|
-
function rewriteCodexResponsesBody(body) {
|
|
762
|
+
function rewriteCodexResponsesBody(body, options = {}) {
|
|
700
763
|
let next = body;
|
|
701
|
-
if (hasWebSearchTool(next)) next = addHostedWebSearch(next);
|
|
764
|
+
if (options.hostedWebSearch !== false && hasWebSearchTool(next)) next = addHostedWebSearch(next);
|
|
702
765
|
else if (hasRemoteCompaction(next)) next = replaceRemoteCompactions(next);
|
|
703
|
-
if (hasFunctionApplyPatchTool(next) && canRewriteApplyPatchHistory(next)) {
|
|
766
|
+
if (options.customApplyPatch !== false && hasFunctionApplyPatchTool(next) && canRewriteApplyPatchHistory(next)) {
|
|
704
767
|
next = addCodexApplyPatch(next);
|
|
705
768
|
next = rewriteCodexApplyPatchHistory(next);
|
|
706
769
|
}
|
|
@@ -748,8 +811,8 @@ function hasRemoteCompaction(body) {
|
|
|
748
811
|
return Array.isArray(content) && content.some((part) => typeof part === "object" && part !== null && typeof part.text === "string" && String(part.text).includes(REMOTE_COMPACTION_OPEN));
|
|
749
812
|
});
|
|
750
813
|
}
|
|
751
|
-
function canPatchBody(body) {
|
|
752
|
-
return isGptModel$1(body.model) && (hasWebSearchTool(body) || hasRemoteCompaction(body) || hasFunctionApplyPatchTool(body) && canRewriteApplyPatchHistory(body));
|
|
814
|
+
function canPatchBody(body, options) {
|
|
815
|
+
return isGptModel$1(body.model) && (options.hostedWebSearch !== false && hasWebSearchTool(body) || hasRemoteCompaction(body) || options.customApplyPatch !== false && hasFunctionApplyPatchTool(body) && canRewriteApplyPatchHistory(body));
|
|
753
816
|
}
|
|
754
817
|
/** Add provider options that older pi-ai adapters do not copy themselves. */
|
|
755
818
|
function applyRequestWireOptions(body, options) {
|
|
@@ -772,18 +835,19 @@ function installGlobalHostedWebSearchPatch() {
|
|
|
772
835
|
if (options === void 0) return original(input, init);
|
|
773
836
|
const request = new Request(input, init);
|
|
774
837
|
if (!isResponsesRequest(request.url)) return original(input, init);
|
|
838
|
+
const requestAndCapture = async (target, requestInit) => captureCodexErrors(await original(target, requestInit));
|
|
775
839
|
let body;
|
|
776
840
|
try {
|
|
777
841
|
body = JSON.parse(await request.clone().text());
|
|
778
842
|
} catch {
|
|
779
|
-
return
|
|
843
|
+
return requestAndCapture(input, init);
|
|
780
844
|
}
|
|
781
845
|
const requestBody = applyRequestWireOptions(body, options);
|
|
782
|
-
if (!canPatchBody(requestBody)) {
|
|
783
|
-
if (requestBody === body) return
|
|
846
|
+
if (!canPatchBody(requestBody, options)) {
|
|
847
|
+
if (requestBody === body) return requestAndCapture(input, init);
|
|
784
848
|
const headers = new Headers(request.headers);
|
|
785
849
|
headers.delete("content-length");
|
|
786
|
-
return
|
|
850
|
+
return requestAndCapture(new Request(request, {
|
|
787
851
|
body: JSON.stringify(requestBody),
|
|
788
852
|
headers
|
|
789
853
|
}));
|
|
@@ -797,15 +861,15 @@ function installGlobalHostedWebSearchPatch() {
|
|
|
797
861
|
const headers = new Headers(request.headers);
|
|
798
862
|
headers.delete("content-length");
|
|
799
863
|
const hostedRequest = new Request(request, {
|
|
800
|
-
body: JSON.stringify(rewriteCodexResponsesBody(requestBody)),
|
|
864
|
+
body: JSON.stringify(rewriteCodexResponsesBody(requestBody, options)),
|
|
801
865
|
headers
|
|
802
866
|
});
|
|
803
867
|
try {
|
|
804
|
-
const hostedResponse = await
|
|
805
|
-
if (!hostedResponse.ok) return
|
|
868
|
+
const hostedResponse = await requestAndCapture(hostedRequest);
|
|
869
|
+
if (!hostedResponse.ok) return requestAndCapture(fallbackRequest);
|
|
806
870
|
return hostedResponse;
|
|
807
871
|
} catch {
|
|
808
|
-
return
|
|
872
|
+
return requestAndCapture(fallbackRequest);
|
|
809
873
|
}
|
|
810
874
|
};
|
|
811
875
|
globalThis.fetch = patched;
|
|
@@ -897,7 +961,7 @@ function responsesTools(tools) {
|
|
|
897
961
|
parameters: tool.parameters
|
|
898
962
|
}));
|
|
899
963
|
}
|
|
900
|
-
function compactBody(options) {
|
|
964
|
+
function compactBody(options, wireOptions = {}) {
|
|
901
965
|
const tools = responsesTools(options.tools);
|
|
902
966
|
const compacted = replaceRemoteCompactions({
|
|
903
967
|
model: options.model,
|
|
@@ -907,7 +971,7 @@ function compactBody(options) {
|
|
|
907
971
|
...options.maxTokens === void 0 ? {} : { max_output_tokens: options.maxTokens },
|
|
908
972
|
...options.reasoningEffort === void 0 ? {} : { reasoning: { effort: options.reasoningEffort } }
|
|
909
973
|
});
|
|
910
|
-
return options.tools?.some((tool) => tool.name === "web_search") ? addHostedWebSearch(compacted) : compacted;
|
|
974
|
+
return wireOptions.hostedWebSearch !== false && options.tools?.some((tool) => tool.name === "web_search") ? addHostedWebSearch(compacted) : compacted;
|
|
911
975
|
}
|
|
912
976
|
function compactText(body) {
|
|
913
977
|
const output = Array.isArray(body.output) ? body.output : [];
|
|
@@ -943,7 +1007,7 @@ function compactUsage(body) {
|
|
|
943
1007
|
...cacheWriteTokens !== void 0 && cacheWriteTokens > 0 ? { cacheWriteTokens } : {}
|
|
944
1008
|
};
|
|
945
1009
|
}
|
|
946
|
-
async function remoteCompact(ctx, options) {
|
|
1010
|
+
async function remoteCompact(ctx, options, wireOptions = {}) {
|
|
947
1011
|
const profile = profileOf(ctx, options.provider);
|
|
948
1012
|
if (!supportsResponses(profile, options.provider) || profile?.baseURL === void 0) throw new Error("Codex remote compaction requires an OpenAI Responses provider with baseURL");
|
|
949
1013
|
const headers = await apiHeaders(ctx, profile);
|
|
@@ -951,7 +1015,7 @@ async function remoteCompact(ctx, options) {
|
|
|
951
1015
|
const response = await fetch(responsesEndpoint(profile.baseURL, "responses/compact"), {
|
|
952
1016
|
method: "POST",
|
|
953
1017
|
headers,
|
|
954
|
-
body: JSON.stringify(compactBody(options)),
|
|
1018
|
+
body: JSON.stringify(compactBody(options, wireOptions)),
|
|
955
1019
|
...options.signal === void 0 ? {} : { signal: options.signal }
|
|
956
1020
|
});
|
|
957
1021
|
if (!response.ok) throw new Error(`remote compaction returned HTTP ${response.status}`);
|
|
@@ -965,10 +1029,10 @@ async function remoteCompact(ctx, options) {
|
|
|
965
1029
|
};
|
|
966
1030
|
}
|
|
967
1031
|
/** Remote-first compaction waterfall with the existing DSH path as fallback. */
|
|
968
|
-
function remoteCompactStream(ctx, options, next) {
|
|
1032
|
+
function remoteCompactStream(ctx, options, next, wireOptions = {}) {
|
|
969
1033
|
return (async function* () {
|
|
970
1034
|
try {
|
|
971
|
-
const result = await remoteCompact(ctx, options);
|
|
1035
|
+
const result = await remoteCompact(ctx, options, wireOptions);
|
|
972
1036
|
yield {
|
|
973
1037
|
type: "block-start",
|
|
974
1038
|
index: 0,
|
|
@@ -1000,7 +1064,10 @@ function remoteCompactStream(ctx, options, next) {
|
|
|
1000
1064
|
ctx.logger.warn("codex: remote compaction failed; using dsh-compaction-basic fallback");
|
|
1001
1065
|
ctx.logger.warn(error);
|
|
1002
1066
|
const serviceTier = serviceTierOf(options);
|
|
1003
|
-
yield* hostedWebSearchStream(next,
|
|
1067
|
+
yield* hostedWebSearchStream(next, {
|
|
1068
|
+
...wireOptions,
|
|
1069
|
+
...serviceTier === void 0 ? {} : { serviceTier }
|
|
1070
|
+
});
|
|
1004
1071
|
}
|
|
1005
1072
|
})();
|
|
1006
1073
|
}
|
|
@@ -1125,12 +1192,26 @@ const CODEX_SETTINGS_NAMESPACE = settingsNamespace("codex");
|
|
|
1125
1192
|
/** Default settings exposed even before a Codex session is opened. */
|
|
1126
1193
|
const CODEX_SETTINGS_ENTRY = {
|
|
1127
1194
|
fast: false,
|
|
1128
|
-
systemPrompt: DEFAULT_CODEX_SYSTEM_PROMPT
|
|
1195
|
+
systemPrompt: DEFAULT_CODEX_SYSTEM_PROMPT,
|
|
1196
|
+
promptEnabled: true,
|
|
1197
|
+
terminalToolsEnabled: true,
|
|
1198
|
+
patchToolEnabled: true,
|
|
1199
|
+
planToolEnabled: true,
|
|
1200
|
+
hostedWebSearchEnabled: true,
|
|
1201
|
+
remoteCompactionEnabled: true,
|
|
1202
|
+
activityIndicatorEnabled: true
|
|
1129
1203
|
};
|
|
1130
1204
|
const CODEX_SETTINGS_SCHEMA = z.object({
|
|
1131
1205
|
fast: z.boolean().default(false),
|
|
1132
1206
|
contextWindow: z.number().step(1).min(1).max(CODEX_CONTEXT_MAX),
|
|
1133
|
-
systemPrompt: z.string().default(DEFAULT_CODEX_SYSTEM_PROMPT)
|
|
1207
|
+
systemPrompt: z.string().default(DEFAULT_CODEX_SYSTEM_PROMPT),
|
|
1208
|
+
promptEnabled: z.boolean().default(true),
|
|
1209
|
+
terminalToolsEnabled: z.boolean().default(true),
|
|
1210
|
+
patchToolEnabled: z.boolean().default(true),
|
|
1211
|
+
planToolEnabled: z.boolean().default(true),
|
|
1212
|
+
hostedWebSearchEnabled: z.boolean().default(true),
|
|
1213
|
+
remoteCompactionEnabled: z.boolean().default(true),
|
|
1214
|
+
activityIndicatorEnabled: z.boolean().default(true)
|
|
1134
1215
|
});
|
|
1135
1216
|
//#endregion
|
|
1136
1217
|
//#region lib/types/index.js
|
|
@@ -1148,6 +1229,8 @@ const inject = [
|
|
|
1148
1229
|
const DEFAULT_MAX_OUTPUT_BYTES = 1048576;
|
|
1149
1230
|
/** Runtime configuration schema for the Codex tool bridge. */
|
|
1150
1231
|
const Config = z.object({
|
|
1232
|
+
globalEnhancements: z.boolean().default(true),
|
|
1233
|
+
codexCore: z.boolean().default(true),
|
|
1151
1234
|
defaultYieldTimeMs: z.number().step(1).min(0).default(1e4),
|
|
1152
1235
|
pollYieldTimeMs: z.number().step(1).min(0).default(5e3),
|
|
1153
1236
|
writeYieldTimeMs: z.number().step(1).min(0).default(250),
|
|
@@ -1246,8 +1329,12 @@ function installCodexSettings(ctx, systemPrompt) {
|
|
|
1246
1329
|
...CODEX_SETTINGS_ENTRY,
|
|
1247
1330
|
systemPrompt
|
|
1248
1331
|
};
|
|
1332
|
+
const withDefaults = (value) => ({
|
|
1333
|
+
...entry,
|
|
1334
|
+
...value
|
|
1335
|
+
});
|
|
1249
1336
|
const settings = ctx.get("settings");
|
|
1250
|
-
if (settings?.get(CODEX_SETTINGS_NAMESPACE) !== void 0) return { current: () => settings.get(CODEX_SETTINGS_NAMESPACE)
|
|
1337
|
+
if (settings?.get(CODEX_SETTINGS_NAMESPACE) !== void 0) return { current: () => withDefaults(settings.get(CODEX_SETTINGS_NAMESPACE)) };
|
|
1251
1338
|
let source = () => entry;
|
|
1252
1339
|
installSettingsSection(ctx, CODEX_SETTINGS_NAMESPACE, CODEX_SETTINGS_SCHEMA, entry, {
|
|
1253
1340
|
setSource: (current) => {
|
|
@@ -1255,7 +1342,7 @@ function installCodexSettings(ctx, systemPrompt) {
|
|
|
1255
1342
|
},
|
|
1256
1343
|
onChange: () => {}
|
|
1257
1344
|
});
|
|
1258
|
-
return { current: () => source() };
|
|
1345
|
+
return { current: () => withDefaults(source()) };
|
|
1259
1346
|
}
|
|
1260
1347
|
function hasOpenTurn(session) {
|
|
1261
1348
|
const start = session.events.findLast((event) => event.type === "turn/start");
|
|
@@ -1266,9 +1353,9 @@ function hasOpenTurn(session) {
|
|
|
1266
1353
|
* Pair the live Codex capacity with the token-meter context projection.
|
|
1267
1354
|
*
|
|
1268
1355
|
* The core loop records adapter metadata in `request/context`, while Codex's
|
|
1269
|
-
* setting is a
|
|
1270
|
-
*
|
|
1271
|
-
*
|
|
1356
|
+
* setting is a request-scoped LLM capacity. Appending the override after the
|
|
1357
|
+
* loop's metadata event keeps the official ContextMeter and compaction engine
|
|
1358
|
+
* on the same effective capacity.
|
|
1272
1359
|
*/
|
|
1273
1360
|
function syncCodexContextWindow(session, contextWindow) {
|
|
1274
1361
|
if (contextWindow === void 0 || !Number.isSafeInteger(contextWindow) || contextWindow <= 0 || !hasOpenTurn(session)) return;
|
|
@@ -1340,6 +1427,24 @@ function normalizeCodexPromptAssembly(assembly) {
|
|
|
1340
1427
|
sections: [persona, ...sections.filter((section) => section.name !== "deployment:persona")]
|
|
1341
1428
|
};
|
|
1342
1429
|
}
|
|
1430
|
+
const CODEX_TOOL_NAMES = {
|
|
1431
|
+
terminalToolsEnabled: /* @__PURE__ */ new Set(["exec_command", "write_stdin"]),
|
|
1432
|
+
patchToolEnabled: /* @__PURE__ */ new Set(["apply_patch"]),
|
|
1433
|
+
planToolEnabled: /* @__PURE__ */ new Set(["update_plan"])
|
|
1434
|
+
};
|
|
1435
|
+
/** Remove disabled Codex capabilities from the next model-visible assembly. */
|
|
1436
|
+
function applyCodexCapabilitySettings(assembly, settings) {
|
|
1437
|
+
const disabled = /* @__PURE__ */ new Set();
|
|
1438
|
+
for (const [setting, names] of Object.entries(CODEX_TOOL_NAMES)) {
|
|
1439
|
+
if (settings[setting]) continue;
|
|
1440
|
+
for (const name of names) disabled.add(name);
|
|
1441
|
+
}
|
|
1442
|
+
const filtered = disabled.size === 0 ? assembly : {
|
|
1443
|
+
...assembly,
|
|
1444
|
+
tools: assembly.tools.filter((tool) => !disabled.has(tool.name))
|
|
1445
|
+
};
|
|
1446
|
+
return settings.promptEnabled ? normalizeCodexPromptAssembly(filtered) : filtered;
|
|
1447
|
+
}
|
|
1343
1448
|
/** Build the complete plugin-owned prompt, preserving an intentional empty value. */
|
|
1344
1449
|
function buildCodexSystemPrompt(config = {}) {
|
|
1345
1450
|
return resolveCodexSystemPrompt(config.systemPrompt);
|
|
@@ -1352,6 +1457,9 @@ const PLAN_STATUSES = [
|
|
|
1352
1457
|
"in_progress",
|
|
1353
1458
|
"completed"
|
|
1354
1459
|
];
|
|
1460
|
+
function assertCapabilityEnabled(current, setting, toolName) {
|
|
1461
|
+
if (!current()[setting]) throw new Error(`${toolName}: disabled in Codex Harness plugin settings`);
|
|
1462
|
+
}
|
|
1355
1463
|
function sessionCwd(exec) {
|
|
1356
1464
|
return exec.agent?.session.header.cwd;
|
|
1357
1465
|
}
|
|
@@ -1538,6 +1646,7 @@ function registerExecTools(ctx, config) {
|
|
|
1538
1646
|
}]
|
|
1539
1647
|
},
|
|
1540
1648
|
async execute(args, exec) {
|
|
1649
|
+
assertCapabilityEnabled(config.currentSettings, "terminalToolsEnabled", "exec_command");
|
|
1541
1650
|
return runExecCommand(ctx, args, exec, config);
|
|
1542
1651
|
},
|
|
1543
1652
|
presentCall: (args) => ({
|
|
@@ -1593,11 +1702,12 @@ function registerExecTools(ctx, config) {
|
|
|
1593
1702
|
}]
|
|
1594
1703
|
},
|
|
1595
1704
|
async execute(args, exec) {
|
|
1705
|
+
assertCapabilityEnabled(config.currentSettings, "terminalToolsEnabled", "write_stdin");
|
|
1596
1706
|
return runWriteStdin(ctx, args, exec, config);
|
|
1597
1707
|
}
|
|
1598
1708
|
}));
|
|
1599
1709
|
}
|
|
1600
|
-
function registerPatchTool(ctx) {
|
|
1710
|
+
function registerPatchTool(ctx, currentSettings) {
|
|
1601
1711
|
ctx.tools.register(defineTool({
|
|
1602
1712
|
name: "apply_patch",
|
|
1603
1713
|
description: APPLY_PATCH_DESCRIPTION,
|
|
@@ -1642,6 +1752,7 @@ function registerPatchTool(ctx) {
|
|
|
1642
1752
|
}]
|
|
1643
1753
|
},
|
|
1644
1754
|
async execute(args, exec) {
|
|
1755
|
+
assertCapabilityEnabled(currentSettings, "patchToolEnabled", "apply_patch");
|
|
1645
1756
|
const files = parsePatch(args.input);
|
|
1646
1757
|
const policy = resolvePolicy(ctx, exec);
|
|
1647
1758
|
const applied = [];
|
|
@@ -1658,7 +1769,7 @@ function registerPatchTool(ctx) {
|
|
|
1658
1769
|
}
|
|
1659
1770
|
}));
|
|
1660
1771
|
}
|
|
1661
|
-
function registerPlanTool(ctx) {
|
|
1772
|
+
function registerPlanTool(ctx, currentSettings) {
|
|
1662
1773
|
ctx.tools.register(defineTool({
|
|
1663
1774
|
name: "update_plan",
|
|
1664
1775
|
description: UPDATE_PLAN_DESCRIPTION,
|
|
@@ -1702,6 +1813,7 @@ function registerPlanTool(ctx) {
|
|
|
1702
1813
|
}]
|
|
1703
1814
|
},
|
|
1704
1815
|
execute(args, exec) {
|
|
1816
|
+
assertCapabilityEnabled(currentSettings, "planToolEnabled", "update_plan");
|
|
1705
1817
|
const agent = exec.agent;
|
|
1706
1818
|
if (agent === void 0) throw new Error("update_plan requires an owning agent session");
|
|
1707
1819
|
agent.session.append("todo/write", { todos: planTodos(args) });
|
|
@@ -1712,6 +1824,8 @@ function registerPlanTool(ctx) {
|
|
|
1712
1824
|
/** Mount the Codex prompt/tool layer inside one fixed agent preset. */
|
|
1713
1825
|
function apply(ctx, config = {}) {
|
|
1714
1826
|
const resolved = {
|
|
1827
|
+
globalEnhancements: config.globalEnhancements ?? true,
|
|
1828
|
+
codexCore: config.codexCore ?? true,
|
|
1715
1829
|
defaultYieldTimeMs: config.defaultYieldTimeMs ?? 1e4,
|
|
1716
1830
|
pollYieldTimeMs: config.pollYieldTimeMs ?? 5e3,
|
|
1717
1831
|
writeYieldTimeMs: config.writeYieldTimeMs ?? 250,
|
|
@@ -1720,32 +1834,48 @@ function apply(ctx, config = {}) {
|
|
|
1720
1834
|
remoteCompact: config.remoteCompact ?? true,
|
|
1721
1835
|
systemPrompt: config.systemPrompt ?? DEFAULT_CODEX_SYSTEM_PROMPT
|
|
1722
1836
|
};
|
|
1723
|
-
if (ctx.fs.sandboxMode !== void 0 && ctx.get("sandboxPolicy") === void 0) throw new Error("codex: a sandboxing filesystem requires ctx.sandboxPolicy");
|
|
1724
|
-
watchConfiguredGptModels(ctx);
|
|
1725
|
-
registerCodexActivityProjection(ctx);
|
|
1837
|
+
if (resolved.codexCore && ctx.fs.sandboxMode !== void 0 && ctx.get("sandboxPolicy") === void 0) throw new Error("codex: a sandboxing filesystem requires ctx.sandboxPolicy");
|
|
1726
1838
|
const codexSettings = installCodexSettings(ctx, resolved.systemPrompt);
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
}
|
|
1731
|
-
if (
|
|
1732
|
-
|
|
1733
|
-
ctx
|
|
1839
|
+
const execConfig = {
|
|
1840
|
+
...resolved,
|
|
1841
|
+
currentSettings: codexSettings.current
|
|
1842
|
+
};
|
|
1843
|
+
if (resolved.globalEnhancements) {
|
|
1844
|
+
watchConfiguredGptModels(ctx);
|
|
1845
|
+
registerCodexActivityProjection(ctx);
|
|
1846
|
+
installCodexContextProjection(ctx, codexSettings.current);
|
|
1847
|
+
ctx.on("agent/request", async (_payload, next) => {
|
|
1848
|
+
return applyCodexRequestSettings(await next(), codexSettings.current());
|
|
1849
|
+
});
|
|
1850
|
+
if (typeof ctx.effect === "function") {
|
|
1851
|
+
const disposeHostedWebSearch = installHostedWebSearch();
|
|
1852
|
+
ctx.effect(() => disposeHostedWebSearch, "codex: Responses transport wrapper");
|
|
1853
|
+
}
|
|
1854
|
+
ctx.on("llm/stream", ((options, next) => {
|
|
1855
|
+
const settings = codexSettings.current();
|
|
1856
|
+
if (resolved.remoteCompact && settings.remoteCompactionEnabled && options.purpose === "compaction" && isGptModel(options.model)) return remoteCompactStream(ctx, options, next, {
|
|
1857
|
+
hostedWebSearch: resolved.hostedWebSearch && settings.hostedWebSearchEnabled,
|
|
1858
|
+
customApplyPatch: settings.patchToolEnabled
|
|
1859
|
+
});
|
|
1860
|
+
if (options.purpose === void 0 && isGptModel(options.model)) return hostedWebSearchStream(next, {
|
|
1861
|
+
serviceTier: options.serviceTier,
|
|
1862
|
+
hostedWebSearch: resolved.hostedWebSearch && settings.hostedWebSearchEnabled,
|
|
1863
|
+
customApplyPatch: settings.patchToolEnabled
|
|
1864
|
+
});
|
|
1865
|
+
return next();
|
|
1866
|
+
}));
|
|
1867
|
+
}
|
|
1868
|
+
if (resolved.codexCore) {
|
|
1869
|
+
ctx.on("system-prompt/assemble", async (_assembly, _context, next) => applyCodexCapabilitySettings(await next(), codexSettings.current()));
|
|
1870
|
+
ctx.systemPrompt.section({
|
|
1871
|
+
name: "codex:base",
|
|
1872
|
+
order: 10,
|
|
1873
|
+
text: () => codexSettings.current().promptEnabled ? resolveCodexSystemPrompt(codexSettings.current().systemPrompt) : ""
|
|
1874
|
+
});
|
|
1875
|
+
registerExecTools(ctx, execConfig);
|
|
1876
|
+
registerPatchTool(ctx, codexSettings.current);
|
|
1877
|
+
registerPlanTool(ctx, codexSettings.current);
|
|
1734
1878
|
}
|
|
1735
|
-
ctx.on("llm/stream", ((options, next) => {
|
|
1736
|
-
if (resolved.remoteCompact && options.purpose === "compaction" && isGptModel(options.model)) return remoteCompactStream(ctx, options, next);
|
|
1737
|
-
if (options.purpose === void 0 && isGptModel(options.model)) return hostedWebSearchStream(next, { serviceTier: options.serviceTier });
|
|
1738
|
-
return next();
|
|
1739
|
-
}));
|
|
1740
|
-
ctx.on("system-prompt/assemble", async (_assembly, _context, next) => normalizeCodexPromptAssembly(await next()));
|
|
1741
|
-
ctx.systemPrompt.section({
|
|
1742
|
-
name: "codex:base",
|
|
1743
|
-
order: 10,
|
|
1744
|
-
text: () => resolveCodexSystemPrompt(codexSettings.current().systemPrompt)
|
|
1745
|
-
});
|
|
1746
|
-
registerExecTools(ctx, resolved);
|
|
1747
|
-
registerPatchTool(ctx);
|
|
1748
|
-
registerPlanTool(ctx);
|
|
1749
1879
|
}
|
|
1750
1880
|
var types_default = {
|
|
1751
1881
|
name,
|
|
@@ -1754,4 +1884,4 @@ var types_default = {
|
|
|
1754
1884
|
apply
|
|
1755
1885
|
};
|
|
1756
1886
|
//#endregion
|
|
1757
|
-
export { CODEX_SETTINGS_NAMESPACE, CODEX_SETTINGS_SCHEMA, Config, DEFAULT_CODEX_SYSTEM_PROMPT, apply, applyCodexRequestSettings, buildCodexSystemPrompt, types_default as default, enrichCodexModel, inject, name, normalizeCodexPromptAssembly, syncCodexContextWindow };
|
|
1887
|
+
export { CODEX_SETTINGS_NAMESPACE, CODEX_SETTINGS_SCHEMA, Config, DEFAULT_CODEX_SYSTEM_PROMPT, apply, applyCodexCapabilitySettings, applyCodexRequestSettings, buildCodexSystemPrompt, types_default as default, enrichCodexModel, inject, name, normalizeCodexPromptAssembly, syncCodexContextWindow };
|
package/lib/installer.js
CHANGED
|
@@ -54,12 +54,26 @@ const CODEX_SETTINGS_NAMESPACE = settingsNamespace("codex");
|
|
|
54
54
|
/** Default settings exposed even before a Codex session is opened. */
|
|
55
55
|
const CODEX_SETTINGS_ENTRY = {
|
|
56
56
|
fast: false,
|
|
57
|
-
systemPrompt: DEFAULT_CODEX_SYSTEM_PROMPT
|
|
57
|
+
systemPrompt: DEFAULT_CODEX_SYSTEM_PROMPT,
|
|
58
|
+
promptEnabled: true,
|
|
59
|
+
terminalToolsEnabled: true,
|
|
60
|
+
patchToolEnabled: true,
|
|
61
|
+
planToolEnabled: true,
|
|
62
|
+
hostedWebSearchEnabled: true,
|
|
63
|
+
remoteCompactionEnabled: true,
|
|
64
|
+
activityIndicatorEnabled: true
|
|
58
65
|
};
|
|
59
66
|
const CODEX_SETTINGS_SCHEMA = z.object({
|
|
60
67
|
fast: z.boolean().default(false),
|
|
61
68
|
contextWindow: z.number().step(1).min(1).max(CODEX_CONTEXT_MAX),
|
|
62
|
-
systemPrompt: z.string().default(DEFAULT_CODEX_SYSTEM_PROMPT)
|
|
69
|
+
systemPrompt: z.string().default(DEFAULT_CODEX_SYSTEM_PROMPT),
|
|
70
|
+
promptEnabled: z.boolean().default(true),
|
|
71
|
+
terminalToolsEnabled: z.boolean().default(true),
|
|
72
|
+
patchToolEnabled: z.boolean().default(true),
|
|
73
|
+
planToolEnabled: z.boolean().default(true),
|
|
74
|
+
hostedWebSearchEnabled: z.boolean().default(true),
|
|
75
|
+
remoteCompactionEnabled: z.boolean().default(true),
|
|
76
|
+
activityIndicatorEnabled: z.boolean().default(true)
|
|
63
77
|
});
|
|
64
78
|
//#endregion
|
|
65
79
|
//#region lib/types/installer.js
|
|
@@ -83,7 +97,8 @@ const BUNDLED_PRESET_SIGNATURES = /* @__PURE__ */ new Set([
|
|
|
83
97
|
"2a7ef181266e69275d25091adc74dd619af7c7d3577573887aaaecd2663e13c8",
|
|
84
98
|
"d1de30f5c13049621b1c1ae3fb22d35b031797a4762638265822b0ff62749854",
|
|
85
99
|
"b50e1d616f9b4188a33c0da0fe355478b7b75b615f3792c094e2b67995622cf4",
|
|
86
|
-
"6132523d92893f6ae9214b30105e9cc1ba64854df6ca8a84213069eb6c38d286"
|
|
100
|
+
"6132523d92893f6ae9214b30105e9cc1ba64854df6ca8a84213069eb6c38d286",
|
|
101
|
+
"7957bc5e9b0f2fa0b74d2d8bae0d4ee153a2ba7bb430f5a848e700386cc7ce3f"
|
|
87
102
|
]);
|
|
88
103
|
function dshHomePath(...segments) {
|
|
89
104
|
const configured = process.env.DSH_HOME?.trim();
|
|
@@ -9,6 +9,13 @@ interface CodexSettings {
|
|
|
9
9
|
fast: boolean;
|
|
10
10
|
contextWindow?: number;
|
|
11
11
|
systemPrompt?: string;
|
|
12
|
+
promptEnabled: boolean;
|
|
13
|
+
terminalToolsEnabled: boolean;
|
|
14
|
+
patchToolEnabled: boolean;
|
|
15
|
+
planToolEnabled: boolean;
|
|
16
|
+
hostedWebSearchEnabled: boolean;
|
|
17
|
+
remoteCompactionEnabled: boolean;
|
|
18
|
+
activityIndicatorEnabled: boolean;
|
|
12
19
|
}
|
|
13
20
|
type CodexScope = SettingsScope<CodexSettings>;
|
|
14
21
|
declare const en: {
|
|
@@ -21,7 +28,22 @@ declare const en: {
|
|
|
21
28
|
readonly contextSizeDescription: "Next request capacity in K tokens.";
|
|
22
29
|
readonly contextRestore: "Restore model default";
|
|
23
30
|
readonly promptCardTitle: "Codex Harness";
|
|
24
|
-
readonly promptCardDescription: "
|
|
31
|
+
readonly promptCardDescription: "Choose Codex capabilities and customize the operating prompt.";
|
|
32
|
+
readonly capabilitiesLabel: "Codex mode capabilities";
|
|
33
|
+
readonly capabilityPrompt: "Codex operating prompt";
|
|
34
|
+
readonly capabilityPromptHint: "Inject the editable instructions and persona-first prompt layout in Codex mode.";
|
|
35
|
+
readonly capabilityTerminal: "Terminal tools";
|
|
36
|
+
readonly capabilityTerminalHint: "Expose exec_command and write_stdin in Codex mode.";
|
|
37
|
+
readonly capabilityPatch: "Patch tool";
|
|
38
|
+
readonly capabilityPatchHint: "Expose apply_patch in Codex mode, using the native Responses grammar when supported.";
|
|
39
|
+
readonly capabilityPlan: "Plan tool";
|
|
40
|
+
readonly capabilityPlanHint: "Expose update_plan for implementation task tracking in Codex mode.";
|
|
41
|
+
readonly capabilityWebSearch: "Hosted web search";
|
|
42
|
+
readonly capabilityWebSearchHint: "Use the provider-native Responses web_search tool when available.";
|
|
43
|
+
readonly capabilityCompaction: "Remote compaction";
|
|
44
|
+
readonly capabilityCompactionHint: "Prefer the provider Responses compact endpoint before local compaction.";
|
|
45
|
+
readonly capabilityActivity: "Activity indicator";
|
|
46
|
+
readonly capabilityActivityHint: "Show request, reply, and compaction status beside the conversation.";
|
|
25
47
|
readonly promptLabel: "System prompt";
|
|
26
48
|
readonly promptHint: "This is the full prompt owned by this plugin. Persona and DSH tool guidance stay dynamic.";
|
|
27
49
|
readonly promptOverridden: "Overridden";
|
|
@@ -68,11 +90,11 @@ interface InputSettingsControlInjected {
|
|
|
68
90
|
/** Full-prompt editor contributed to Settings > Plugins. */
|
|
69
91
|
export declare function PromptSettingsCard(props: PropsRuntime<'settings.plugin.item'> & InjectFace<InputSettingsControlInjected> & PropsLocale<'codex'>): import("react").JSX.Element | null;
|
|
70
92
|
type LegacyOverlayProps = PropsRuntime<typeof LEGACY_OVERLAY_SLOT> & InjectFace<InputSettingsControlInjected> & PropsLocale<'codex'>;
|
|
71
|
-
type ActivityProps = Pick<LegacyOverlayProps, 'sessionId' | 'useSession' | 'useSessions' | 'useProjection' | 't'>;
|
|
93
|
+
type ActivityProps = Pick<LegacyOverlayProps, 'sessionId' | 'useSession' | 'useSessions' | 'useProjection' | 'useSettings' | 't'>;
|
|
72
94
|
type ActivityFallback = ReturnType<typeof modelActivity>;
|
|
73
95
|
/** Prefer the session snapshot when an older projection host only exposes null. */
|
|
74
|
-
export declare function resolveActivity(
|
|
75
|
-
export declare function ActivityLine({ sessionId, useSession, useSessions, useProjection, t, position, }: ActivityProps & {
|
|
96
|
+
export declare function resolveActivity(projectedActivity: CodexActivity | null | undefined, fallbackActivity: ActivityFallback): CodexActivity | null;
|
|
97
|
+
export declare function ActivityLine({ sessionId: _sessionId, useSession, useSessions: _useSessions, useProjection, useSettings, t, position, }: ActivityProps & {
|
|
76
98
|
position?: {
|
|
77
99
|
left: number;
|
|
78
100
|
top: number;
|