@shuind/dsh-codex-harness 0.2.2 → 0.2.4
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/cordis.patch.yml +6 -5
- package/lib/client.js +150 -23
- package/lib/index.js +217 -53
- 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/index.d.ts +6 -0
- package/lib/types/index.js +92 -43
- package/lib/types/installer.js +1 -0
- package/lib/types/remote.d.ts +11 -2
- package/lib/types/remote.js +160 -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,8 @@ 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 CONTEXT_WINDOW_EXCEEDED_CODE = "CONTEXT_WINDOW_EXCEEDED";
|
|
530
|
+
const CODEX_ERROR_DIRECTORY = ["diagnostics", "openai-codex-errors"];
|
|
527
531
|
const HOSTED_REQUESTS = new AsyncLocalStorage();
|
|
528
532
|
let hostedPatchUsers = 0;
|
|
529
533
|
let hostedPatchRestore;
|
|
@@ -568,6 +572,66 @@ function isResponsesRequest(url) {
|
|
|
568
572
|
return url.replace(/\/+$/, "").endsWith("/responses");
|
|
569
573
|
}
|
|
570
574
|
}
|
|
575
|
+
function diagnosticsDirectory() {
|
|
576
|
+
const configured = process.env["DSH_HOME"]?.trim();
|
|
577
|
+
const expanded = configured === void 0 || configured.length === 0 ? join(homedir(), ".dsh") : configured === "~" ? homedir() : configured.startsWith("~/") || configured.startsWith("~\\") ? join(homedir(), configured.slice(2)) : configured;
|
|
578
|
+
return join(resolve(expanded), ...CODEX_ERROR_DIRECTORY);
|
|
579
|
+
}
|
|
580
|
+
function saveCodexErrorPayload(payload) {
|
|
581
|
+
const directory = diagnosticsDirectory();
|
|
582
|
+
mkdirSync(directory, {
|
|
583
|
+
recursive: true,
|
|
584
|
+
mode: 448
|
|
585
|
+
});
|
|
586
|
+
const filename = `${Date.now()}-${randomUUID()}.json`;
|
|
587
|
+
writeFileSync(join(directory, filename), `${payload}\n`, {
|
|
588
|
+
flag: "wx",
|
|
589
|
+
mode: 384
|
|
590
|
+
});
|
|
591
|
+
}
|
|
592
|
+
function errorPayloadFromSseFrame(frame) {
|
|
593
|
+
const data = frame.split(/\r?\n/u).filter((line) => line.startsWith("data:")).map((line) => line.slice(5).trimStart()).join("\n").trim();
|
|
594
|
+
if (data.length === 0 || data === "[DONE]") return void 0;
|
|
595
|
+
try {
|
|
596
|
+
const payload = JSON.parse(data);
|
|
597
|
+
return payload.type === "error" || payload.type === "response.failed" ? data : void 0;
|
|
598
|
+
} catch {
|
|
599
|
+
return;
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
async function captureCodexErrorPayloads(response) {
|
|
603
|
+
if (response.body === null) return;
|
|
604
|
+
const reader = response.body.getReader();
|
|
605
|
+
const decoder = new TextDecoder();
|
|
606
|
+
let buffer = "";
|
|
607
|
+
try {
|
|
608
|
+
while (true) {
|
|
609
|
+
const { done, value } = await reader.read();
|
|
610
|
+
buffer += decoder.decode(value, { stream: !done });
|
|
611
|
+
while (true) {
|
|
612
|
+
const delimiter = /\r?\n\r?\n/u.exec(buffer);
|
|
613
|
+
if (delimiter?.index === void 0) break;
|
|
614
|
+
const frame = buffer.slice(0, delimiter.index);
|
|
615
|
+
buffer = buffer.slice(delimiter.index + delimiter[0].length);
|
|
616
|
+
const payload = errorPayloadFromSseFrame(frame);
|
|
617
|
+
if (payload === void 0) continue;
|
|
618
|
+
try {
|
|
619
|
+
saveCodexErrorPayload(payload);
|
|
620
|
+
} catch {}
|
|
621
|
+
}
|
|
622
|
+
if (done) return;
|
|
623
|
+
}
|
|
624
|
+
} finally {
|
|
625
|
+
reader.releaseLock();
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
function captureCodexErrors(response) {
|
|
629
|
+
if (!response.headers.get("content-type")?.toLowerCase().includes("text/event-stream")) return response;
|
|
630
|
+
try {
|
|
631
|
+
captureCodexErrorPayloads(response.clone()).catch(() => {});
|
|
632
|
+
} catch {}
|
|
633
|
+
return response;
|
|
634
|
+
}
|
|
571
635
|
function isWebSearchTool(tool) {
|
|
572
636
|
if (typeof tool !== "object" || tool === null) return false;
|
|
573
637
|
const value = tool;
|
|
@@ -696,11 +760,11 @@ function rewriteCodexApplyPatchHistory(body) {
|
|
|
696
760
|
} : body;
|
|
697
761
|
}
|
|
698
762
|
/** Compose the plugin-only Responses rewrites without changing DSH's tool API. */
|
|
699
|
-
function rewriteCodexResponsesBody(body) {
|
|
763
|
+
function rewriteCodexResponsesBody(body, options = {}) {
|
|
700
764
|
let next = body;
|
|
701
|
-
if (hasWebSearchTool(next)) next = addHostedWebSearch(next);
|
|
765
|
+
if (options.hostedWebSearch !== false && hasWebSearchTool(next)) next = addHostedWebSearch(next);
|
|
702
766
|
else if (hasRemoteCompaction(next)) next = replaceRemoteCompactions(next);
|
|
703
|
-
if (hasFunctionApplyPatchTool(next) && canRewriteApplyPatchHistory(next)) {
|
|
767
|
+
if (options.customApplyPatch !== false && hasFunctionApplyPatchTool(next) && canRewriteApplyPatchHistory(next)) {
|
|
704
768
|
next = addCodexApplyPatch(next);
|
|
705
769
|
next = rewriteCodexApplyPatchHistory(next);
|
|
706
770
|
}
|
|
@@ -748,8 +812,8 @@ function hasRemoteCompaction(body) {
|
|
|
748
812
|
return Array.isArray(content) && content.some((part) => typeof part === "object" && part !== null && typeof part.text === "string" && String(part.text).includes(REMOTE_COMPACTION_OPEN));
|
|
749
813
|
});
|
|
750
814
|
}
|
|
751
|
-
function canPatchBody(body) {
|
|
752
|
-
return isGptModel$1(body.model) && (hasWebSearchTool(body) || hasRemoteCompaction(body) || hasFunctionApplyPatchTool(body) && canRewriteApplyPatchHistory(body));
|
|
815
|
+
function canPatchBody(body, options) {
|
|
816
|
+
return isGptModel$1(body.model) && (options.hostedWebSearch !== false && hasWebSearchTool(body) || hasRemoteCompaction(body) || options.customApplyPatch !== false && hasFunctionApplyPatchTool(body) && canRewriteApplyPatchHistory(body));
|
|
753
817
|
}
|
|
754
818
|
/** Add provider options that older pi-ai adapters do not copy themselves. */
|
|
755
819
|
function applyRequestWireOptions(body, options) {
|
|
@@ -772,18 +836,19 @@ function installGlobalHostedWebSearchPatch() {
|
|
|
772
836
|
if (options === void 0) return original(input, init);
|
|
773
837
|
const request = new Request(input, init);
|
|
774
838
|
if (!isResponsesRequest(request.url)) return original(input, init);
|
|
839
|
+
const requestAndCapture = async (target, requestInit) => captureCodexErrors(await original(target, requestInit));
|
|
775
840
|
let body;
|
|
776
841
|
try {
|
|
777
842
|
body = JSON.parse(await request.clone().text());
|
|
778
843
|
} catch {
|
|
779
|
-
return
|
|
844
|
+
return requestAndCapture(input, init);
|
|
780
845
|
}
|
|
781
846
|
const requestBody = applyRequestWireOptions(body, options);
|
|
782
|
-
if (!canPatchBody(requestBody)) {
|
|
783
|
-
if (requestBody === body) return
|
|
847
|
+
if (!canPatchBody(requestBody, options)) {
|
|
848
|
+
if (requestBody === body) return requestAndCapture(input, init);
|
|
784
849
|
const headers = new Headers(request.headers);
|
|
785
850
|
headers.delete("content-length");
|
|
786
|
-
return
|
|
851
|
+
return requestAndCapture(new Request(request, {
|
|
787
852
|
body: JSON.stringify(requestBody),
|
|
788
853
|
headers
|
|
789
854
|
}));
|
|
@@ -797,15 +862,15 @@ function installGlobalHostedWebSearchPatch() {
|
|
|
797
862
|
const headers = new Headers(request.headers);
|
|
798
863
|
headers.delete("content-length");
|
|
799
864
|
const hostedRequest = new Request(request, {
|
|
800
|
-
body: JSON.stringify(rewriteCodexResponsesBody(requestBody)),
|
|
865
|
+
body: JSON.stringify(rewriteCodexResponsesBody(requestBody, options)),
|
|
801
866
|
headers
|
|
802
867
|
});
|
|
803
868
|
try {
|
|
804
|
-
const hostedResponse = await
|
|
805
|
-
if (!hostedResponse.ok) return
|
|
869
|
+
const hostedResponse = await requestAndCapture(hostedRequest);
|
|
870
|
+
if (!hostedResponse.ok) return requestAndCapture(fallbackRequest);
|
|
806
871
|
return hostedResponse;
|
|
807
872
|
} catch {
|
|
808
|
-
return
|
|
873
|
+
return requestAndCapture(fallbackRequest);
|
|
809
874
|
}
|
|
810
875
|
};
|
|
811
876
|
globalThis.fetch = patched;
|
|
@@ -844,6 +909,38 @@ function hostedWebSearchStream(next, options = {}) {
|
|
|
844
909
|
}
|
|
845
910
|
})();
|
|
846
911
|
}
|
|
912
|
+
function contextTokens(usage) {
|
|
913
|
+
const fields = [
|
|
914
|
+
usage.inputTokens,
|
|
915
|
+
usage.outputTokens,
|
|
916
|
+
usage.cacheReadTokens ?? 0,
|
|
917
|
+
usage.cacheWriteTokens ?? 0
|
|
918
|
+
];
|
|
919
|
+
if (fields.some((value) => !Number.isSafeInteger(value) || value < 0)) return void 0;
|
|
920
|
+
const total = fields.reduce((sum, value) => sum + value, 0);
|
|
921
|
+
return Number.isSafeInteger(total) ? total : void 0;
|
|
922
|
+
}
|
|
923
|
+
/**
|
|
924
|
+
* Correct the usage-only overflow verdict emitted by pi-ai adapters that do
|
|
925
|
+
* not yet consume the request-scoped Codex capacity.
|
|
926
|
+
*/
|
|
927
|
+
function repairLegacyPiAiContextOverflow(stream, model, contextWindow) {
|
|
928
|
+
return (async function* () {
|
|
929
|
+
let usage;
|
|
930
|
+
for await (const chunk of stream) {
|
|
931
|
+
if (chunk.type === "usage") usage = chunk.usage;
|
|
932
|
+
const usedTokens = usage === void 0 ? void 0 : contextTokens(usage);
|
|
933
|
+
if (chunk.type === "finish" && chunk.reason.kind === "error" && chunk.reason.failure.code === CONTEXT_WINDOW_EXCEEDED_CODE && chunk.reason.failure.message === `pi-ai detected context overflow for model "${model}"` && typeof contextWindow === "number" && Number.isSafeInteger(contextWindow) && contextWindow > 0 && usage !== void 0 && usage.outputTokens > 0 && usedTokens !== void 0 && usedTokens <= contextWindow) {
|
|
934
|
+
yield {
|
|
935
|
+
...chunk,
|
|
936
|
+
reason: { kind: "stop" }
|
|
937
|
+
};
|
|
938
|
+
continue;
|
|
939
|
+
}
|
|
940
|
+
yield chunk;
|
|
941
|
+
}
|
|
942
|
+
})();
|
|
943
|
+
}
|
|
847
944
|
function textOf(message) {
|
|
848
945
|
return message.content.filter((block) => block.type === "text").map((block) => block.text).join("");
|
|
849
946
|
}
|
|
@@ -897,7 +994,7 @@ function responsesTools(tools) {
|
|
|
897
994
|
parameters: tool.parameters
|
|
898
995
|
}));
|
|
899
996
|
}
|
|
900
|
-
function compactBody(options) {
|
|
997
|
+
function compactBody(options, wireOptions = {}) {
|
|
901
998
|
const tools = responsesTools(options.tools);
|
|
902
999
|
const compacted = replaceRemoteCompactions({
|
|
903
1000
|
model: options.model,
|
|
@@ -907,7 +1004,7 @@ function compactBody(options) {
|
|
|
907
1004
|
...options.maxTokens === void 0 ? {} : { max_output_tokens: options.maxTokens },
|
|
908
1005
|
...options.reasoningEffort === void 0 ? {} : { reasoning: { effort: options.reasoningEffort } }
|
|
909
1006
|
});
|
|
910
|
-
return options.tools?.some((tool) => tool.name === "web_search") ? addHostedWebSearch(compacted) : compacted;
|
|
1007
|
+
return wireOptions.hostedWebSearch !== false && options.tools?.some((tool) => tool.name === "web_search") ? addHostedWebSearch(compacted) : compacted;
|
|
911
1008
|
}
|
|
912
1009
|
function compactText(body) {
|
|
913
1010
|
const output = Array.isArray(body.output) ? body.output : [];
|
|
@@ -943,7 +1040,7 @@ function compactUsage(body) {
|
|
|
943
1040
|
...cacheWriteTokens !== void 0 && cacheWriteTokens > 0 ? { cacheWriteTokens } : {}
|
|
944
1041
|
};
|
|
945
1042
|
}
|
|
946
|
-
async function remoteCompact(ctx, options) {
|
|
1043
|
+
async function remoteCompact(ctx, options, wireOptions = {}) {
|
|
947
1044
|
const profile = profileOf(ctx, options.provider);
|
|
948
1045
|
if (!supportsResponses(profile, options.provider) || profile?.baseURL === void 0) throw new Error("Codex remote compaction requires an OpenAI Responses provider with baseURL");
|
|
949
1046
|
const headers = await apiHeaders(ctx, profile);
|
|
@@ -951,7 +1048,7 @@ async function remoteCompact(ctx, options) {
|
|
|
951
1048
|
const response = await fetch(responsesEndpoint(profile.baseURL, "responses/compact"), {
|
|
952
1049
|
method: "POST",
|
|
953
1050
|
headers,
|
|
954
|
-
body: JSON.stringify(compactBody(options)),
|
|
1051
|
+
body: JSON.stringify(compactBody(options, wireOptions)),
|
|
955
1052
|
...options.signal === void 0 ? {} : { signal: options.signal }
|
|
956
1053
|
});
|
|
957
1054
|
if (!response.ok) throw new Error(`remote compaction returned HTTP ${response.status}`);
|
|
@@ -965,10 +1062,10 @@ async function remoteCompact(ctx, options) {
|
|
|
965
1062
|
};
|
|
966
1063
|
}
|
|
967
1064
|
/** Remote-first compaction waterfall with the existing DSH path as fallback. */
|
|
968
|
-
function remoteCompactStream(ctx, options, next) {
|
|
1065
|
+
function remoteCompactStream(ctx, options, next, wireOptions = {}) {
|
|
969
1066
|
return (async function* () {
|
|
970
1067
|
try {
|
|
971
|
-
const result = await remoteCompact(ctx, options);
|
|
1068
|
+
const result = await remoteCompact(ctx, options, wireOptions);
|
|
972
1069
|
yield {
|
|
973
1070
|
type: "block-start",
|
|
974
1071
|
index: 0,
|
|
@@ -1000,7 +1097,10 @@ function remoteCompactStream(ctx, options, next) {
|
|
|
1000
1097
|
ctx.logger.warn("codex: remote compaction failed; using dsh-compaction-basic fallback");
|
|
1001
1098
|
ctx.logger.warn(error);
|
|
1002
1099
|
const serviceTier = serviceTierOf(options);
|
|
1003
|
-
yield* hostedWebSearchStream(next,
|
|
1100
|
+
yield* hostedWebSearchStream(next, {
|
|
1101
|
+
...wireOptions,
|
|
1102
|
+
...serviceTier === void 0 ? {} : { serviceTier }
|
|
1103
|
+
});
|
|
1004
1104
|
}
|
|
1005
1105
|
})();
|
|
1006
1106
|
}
|
|
@@ -1125,12 +1225,26 @@ const CODEX_SETTINGS_NAMESPACE = settingsNamespace("codex");
|
|
|
1125
1225
|
/** Default settings exposed even before a Codex session is opened. */
|
|
1126
1226
|
const CODEX_SETTINGS_ENTRY = {
|
|
1127
1227
|
fast: false,
|
|
1128
|
-
systemPrompt: DEFAULT_CODEX_SYSTEM_PROMPT
|
|
1228
|
+
systemPrompt: DEFAULT_CODEX_SYSTEM_PROMPT,
|
|
1229
|
+
promptEnabled: true,
|
|
1230
|
+
terminalToolsEnabled: true,
|
|
1231
|
+
patchToolEnabled: true,
|
|
1232
|
+
planToolEnabled: true,
|
|
1233
|
+
hostedWebSearchEnabled: true,
|
|
1234
|
+
remoteCompactionEnabled: true,
|
|
1235
|
+
activityIndicatorEnabled: true
|
|
1129
1236
|
};
|
|
1130
1237
|
const CODEX_SETTINGS_SCHEMA = z.object({
|
|
1131
1238
|
fast: z.boolean().default(false),
|
|
1132
1239
|
contextWindow: z.number().step(1).min(1).max(CODEX_CONTEXT_MAX),
|
|
1133
|
-
systemPrompt: z.string().default(DEFAULT_CODEX_SYSTEM_PROMPT)
|
|
1240
|
+
systemPrompt: z.string().default(DEFAULT_CODEX_SYSTEM_PROMPT),
|
|
1241
|
+
promptEnabled: z.boolean().default(true),
|
|
1242
|
+
terminalToolsEnabled: z.boolean().default(true),
|
|
1243
|
+
patchToolEnabled: z.boolean().default(true),
|
|
1244
|
+
planToolEnabled: z.boolean().default(true),
|
|
1245
|
+
hostedWebSearchEnabled: z.boolean().default(true),
|
|
1246
|
+
remoteCompactionEnabled: z.boolean().default(true),
|
|
1247
|
+
activityIndicatorEnabled: z.boolean().default(true)
|
|
1134
1248
|
});
|
|
1135
1249
|
//#endregion
|
|
1136
1250
|
//#region lib/types/index.js
|
|
@@ -1148,6 +1262,8 @@ const inject = [
|
|
|
1148
1262
|
const DEFAULT_MAX_OUTPUT_BYTES = 1048576;
|
|
1149
1263
|
/** Runtime configuration schema for the Codex tool bridge. */
|
|
1150
1264
|
const Config = z.object({
|
|
1265
|
+
globalEnhancements: z.boolean().default(true),
|
|
1266
|
+
codexCore: z.boolean().default(true),
|
|
1151
1267
|
defaultYieldTimeMs: z.number().step(1).min(0).default(1e4),
|
|
1152
1268
|
pollYieldTimeMs: z.number().step(1).min(0).default(5e3),
|
|
1153
1269
|
writeYieldTimeMs: z.number().step(1).min(0).default(250),
|
|
@@ -1246,8 +1362,12 @@ function installCodexSettings(ctx, systemPrompt) {
|
|
|
1246
1362
|
...CODEX_SETTINGS_ENTRY,
|
|
1247
1363
|
systemPrompt
|
|
1248
1364
|
};
|
|
1365
|
+
const withDefaults = (value) => ({
|
|
1366
|
+
...entry,
|
|
1367
|
+
...value
|
|
1368
|
+
});
|
|
1249
1369
|
const settings = ctx.get("settings");
|
|
1250
|
-
if (settings?.get(CODEX_SETTINGS_NAMESPACE) !== void 0) return { current: () => settings.get(CODEX_SETTINGS_NAMESPACE)
|
|
1370
|
+
if (settings?.get(CODEX_SETTINGS_NAMESPACE) !== void 0) return { current: () => withDefaults(settings.get(CODEX_SETTINGS_NAMESPACE)) };
|
|
1251
1371
|
let source = () => entry;
|
|
1252
1372
|
installSettingsSection(ctx, CODEX_SETTINGS_NAMESPACE, CODEX_SETTINGS_SCHEMA, entry, {
|
|
1253
1373
|
setSource: (current) => {
|
|
@@ -1255,7 +1375,7 @@ function installCodexSettings(ctx, systemPrompt) {
|
|
|
1255
1375
|
},
|
|
1256
1376
|
onChange: () => {}
|
|
1257
1377
|
});
|
|
1258
|
-
return { current: () => source() };
|
|
1378
|
+
return { current: () => withDefaults(source()) };
|
|
1259
1379
|
}
|
|
1260
1380
|
function hasOpenTurn(session) {
|
|
1261
1381
|
const start = session.events.findLast((event) => event.type === "turn/start");
|
|
@@ -1340,6 +1460,24 @@ function normalizeCodexPromptAssembly(assembly) {
|
|
|
1340
1460
|
sections: [persona, ...sections.filter((section) => section.name !== "deployment:persona")]
|
|
1341
1461
|
};
|
|
1342
1462
|
}
|
|
1463
|
+
const CODEX_TOOL_NAMES = {
|
|
1464
|
+
terminalToolsEnabled: /* @__PURE__ */ new Set(["exec_command", "write_stdin"]),
|
|
1465
|
+
patchToolEnabled: /* @__PURE__ */ new Set(["apply_patch"]),
|
|
1466
|
+
planToolEnabled: /* @__PURE__ */ new Set(["update_plan"])
|
|
1467
|
+
};
|
|
1468
|
+
/** Remove disabled Codex capabilities from the next model-visible assembly. */
|
|
1469
|
+
function applyCodexCapabilitySettings(assembly, settings) {
|
|
1470
|
+
const disabled = /* @__PURE__ */ new Set();
|
|
1471
|
+
for (const [setting, names] of Object.entries(CODEX_TOOL_NAMES)) {
|
|
1472
|
+
if (settings[setting]) continue;
|
|
1473
|
+
for (const name of names) disabled.add(name);
|
|
1474
|
+
}
|
|
1475
|
+
const filtered = disabled.size === 0 ? assembly : {
|
|
1476
|
+
...assembly,
|
|
1477
|
+
tools: assembly.tools.filter((tool) => !disabled.has(tool.name))
|
|
1478
|
+
};
|
|
1479
|
+
return settings.promptEnabled ? normalizeCodexPromptAssembly(filtered) : filtered;
|
|
1480
|
+
}
|
|
1343
1481
|
/** Build the complete plugin-owned prompt, preserving an intentional empty value. */
|
|
1344
1482
|
function buildCodexSystemPrompt(config = {}) {
|
|
1345
1483
|
return resolveCodexSystemPrompt(config.systemPrompt);
|
|
@@ -1352,6 +1490,9 @@ const PLAN_STATUSES = [
|
|
|
1352
1490
|
"in_progress",
|
|
1353
1491
|
"completed"
|
|
1354
1492
|
];
|
|
1493
|
+
function assertCapabilityEnabled(current, setting, toolName) {
|
|
1494
|
+
if (!current()[setting]) throw new Error(`${toolName}: disabled in Codex Harness plugin settings`);
|
|
1495
|
+
}
|
|
1355
1496
|
function sessionCwd(exec) {
|
|
1356
1497
|
return exec.agent?.session.header.cwd;
|
|
1357
1498
|
}
|
|
@@ -1538,6 +1679,7 @@ function registerExecTools(ctx, config) {
|
|
|
1538
1679
|
}]
|
|
1539
1680
|
},
|
|
1540
1681
|
async execute(args, exec) {
|
|
1682
|
+
assertCapabilityEnabled(config.currentSettings, "terminalToolsEnabled", "exec_command");
|
|
1541
1683
|
return runExecCommand(ctx, args, exec, config);
|
|
1542
1684
|
},
|
|
1543
1685
|
presentCall: (args) => ({
|
|
@@ -1593,11 +1735,12 @@ function registerExecTools(ctx, config) {
|
|
|
1593
1735
|
}]
|
|
1594
1736
|
},
|
|
1595
1737
|
async execute(args, exec) {
|
|
1738
|
+
assertCapabilityEnabled(config.currentSettings, "terminalToolsEnabled", "write_stdin");
|
|
1596
1739
|
return runWriteStdin(ctx, args, exec, config);
|
|
1597
1740
|
}
|
|
1598
1741
|
}));
|
|
1599
1742
|
}
|
|
1600
|
-
function registerPatchTool(ctx) {
|
|
1743
|
+
function registerPatchTool(ctx, currentSettings) {
|
|
1601
1744
|
ctx.tools.register(defineTool({
|
|
1602
1745
|
name: "apply_patch",
|
|
1603
1746
|
description: APPLY_PATCH_DESCRIPTION,
|
|
@@ -1642,6 +1785,7 @@ function registerPatchTool(ctx) {
|
|
|
1642
1785
|
}]
|
|
1643
1786
|
},
|
|
1644
1787
|
async execute(args, exec) {
|
|
1788
|
+
assertCapabilityEnabled(currentSettings, "patchToolEnabled", "apply_patch");
|
|
1645
1789
|
const files = parsePatch(args.input);
|
|
1646
1790
|
const policy = resolvePolicy(ctx, exec);
|
|
1647
1791
|
const applied = [];
|
|
@@ -1658,7 +1802,7 @@ function registerPatchTool(ctx) {
|
|
|
1658
1802
|
}
|
|
1659
1803
|
}));
|
|
1660
1804
|
}
|
|
1661
|
-
function registerPlanTool(ctx) {
|
|
1805
|
+
function registerPlanTool(ctx, currentSettings) {
|
|
1662
1806
|
ctx.tools.register(defineTool({
|
|
1663
1807
|
name: "update_plan",
|
|
1664
1808
|
description: UPDATE_PLAN_DESCRIPTION,
|
|
@@ -1702,6 +1846,7 @@ function registerPlanTool(ctx) {
|
|
|
1702
1846
|
}]
|
|
1703
1847
|
},
|
|
1704
1848
|
execute(args, exec) {
|
|
1849
|
+
assertCapabilityEnabled(currentSettings, "planToolEnabled", "update_plan");
|
|
1705
1850
|
const agent = exec.agent;
|
|
1706
1851
|
if (agent === void 0) throw new Error("update_plan requires an owning agent session");
|
|
1707
1852
|
agent.session.append("todo/write", { todos: planTodos(args) });
|
|
@@ -1712,6 +1857,8 @@ function registerPlanTool(ctx) {
|
|
|
1712
1857
|
/** Mount the Codex prompt/tool layer inside one fixed agent preset. */
|
|
1713
1858
|
function apply(ctx, config = {}) {
|
|
1714
1859
|
const resolved = {
|
|
1860
|
+
globalEnhancements: config.globalEnhancements ?? true,
|
|
1861
|
+
codexCore: config.codexCore ?? true,
|
|
1715
1862
|
defaultYieldTimeMs: config.defaultYieldTimeMs ?? 1e4,
|
|
1716
1863
|
pollYieldTimeMs: config.pollYieldTimeMs ?? 5e3,
|
|
1717
1864
|
writeYieldTimeMs: config.writeYieldTimeMs ?? 250,
|
|
@@ -1720,32 +1867,49 @@ function apply(ctx, config = {}) {
|
|
|
1720
1867
|
remoteCompact: config.remoteCompact ?? true,
|
|
1721
1868
|
systemPrompt: config.systemPrompt ?? DEFAULT_CODEX_SYSTEM_PROMPT
|
|
1722
1869
|
};
|
|
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);
|
|
1870
|
+
if (resolved.codexCore && ctx.fs.sandboxMode !== void 0 && ctx.get("sandboxPolicy") === void 0) throw new Error("codex: a sandboxing filesystem requires ctx.sandboxPolicy");
|
|
1726
1871
|
const codexSettings = installCodexSettings(ctx, resolved.systemPrompt);
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
}
|
|
1731
|
-
if (
|
|
1732
|
-
|
|
1733
|
-
ctx
|
|
1872
|
+
const execConfig = {
|
|
1873
|
+
...resolved,
|
|
1874
|
+
currentSettings: codexSettings.current
|
|
1875
|
+
};
|
|
1876
|
+
if (resolved.globalEnhancements) {
|
|
1877
|
+
watchConfiguredGptModels(ctx);
|
|
1878
|
+
registerCodexActivityProjection(ctx);
|
|
1879
|
+
installCodexContextProjection(ctx, codexSettings.current);
|
|
1880
|
+
ctx.on("agent/request", async (_payload, next) => {
|
|
1881
|
+
return applyCodexRequestSettings(await next(), codexSettings.current());
|
|
1882
|
+
});
|
|
1883
|
+
if (typeof ctx.effect === "function") {
|
|
1884
|
+
const disposeHostedWebSearch = installHostedWebSearch();
|
|
1885
|
+
ctx.effect(() => disposeHostedWebSearch, "codex: Responses transport wrapper");
|
|
1886
|
+
}
|
|
1887
|
+
ctx.on("llm/stream", ((options, next) => {
|
|
1888
|
+
const settings = codexSettings.current();
|
|
1889
|
+
const legacySafeNext = () => repairLegacyPiAiContextOverflow(next(), options.model, options.contextWindow);
|
|
1890
|
+
if (resolved.remoteCompact && settings.remoteCompactionEnabled && options.purpose === "compaction" && isGptModel(options.model)) return remoteCompactStream(ctx, options, legacySafeNext, {
|
|
1891
|
+
hostedWebSearch: resolved.hostedWebSearch && settings.hostedWebSearchEnabled,
|
|
1892
|
+
customApplyPatch: settings.patchToolEnabled
|
|
1893
|
+
});
|
|
1894
|
+
if (options.purpose === void 0 && isGptModel(options.model)) return repairLegacyPiAiContextOverflow(hostedWebSearchStream(next, {
|
|
1895
|
+
serviceTier: options.serviceTier,
|
|
1896
|
+
hostedWebSearch: resolved.hostedWebSearch && settings.hostedWebSearchEnabled,
|
|
1897
|
+
customApplyPatch: settings.patchToolEnabled
|
|
1898
|
+
}), options.model, options.contextWindow);
|
|
1899
|
+
return next();
|
|
1900
|
+
}));
|
|
1901
|
+
}
|
|
1902
|
+
if (resolved.codexCore) {
|
|
1903
|
+
ctx.on("system-prompt/assemble", async (_assembly, _context, next) => applyCodexCapabilitySettings(await next(), codexSettings.current()));
|
|
1904
|
+
ctx.systemPrompt.section({
|
|
1905
|
+
name: "codex:base",
|
|
1906
|
+
order: 10,
|
|
1907
|
+
text: () => codexSettings.current().promptEnabled ? resolveCodexSystemPrompt(codexSettings.current().systemPrompt) : ""
|
|
1908
|
+
});
|
|
1909
|
+
registerExecTools(ctx, execConfig);
|
|
1910
|
+
registerPatchTool(ctx, codexSettings.current);
|
|
1911
|
+
registerPlanTool(ctx, codexSettings.current);
|
|
1734
1912
|
}
|
|
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
1913
|
}
|
|
1750
1914
|
var types_default = {
|
|
1751
1915
|
name,
|
|
@@ -1754,4 +1918,4 @@ var types_default = {
|
|
|
1754
1918
|
apply
|
|
1755
1919
|
};
|
|
1756
1920
|
//#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 };
|
|
1921
|
+
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;
|