hiveagents-runtime 0.0.0-stage → 0.1.0-beta.1
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/LICENSE +202 -0
- package/README.md +85 -2
- package/dist/adapter-kit.d.ts +37 -0
- package/dist/adapter-kit.js +33 -0
- package/dist/adapter-kit.js.map +1 -0
- package/dist/agent-D0HS38G3.d.ts +169 -0
- package/dist/agent-OLSXNGNN.js +23 -0
- package/dist/agent-OLSXNGNN.js.map +1 -0
- package/dist/agent-readiness-V36OJME4.js +19 -0
- package/dist/agent-readiness-V36OJME4.js.map +1 -0
- package/dist/capture-runtime-GP6NZ2ee.d.ts +54 -0
- package/dist/chunk-2RUEC63U.js +1217 -0
- package/dist/chunk-2RUEC63U.js.map +1 -0
- package/dist/chunk-3B3JW4U3.js +291 -0
- package/dist/chunk-3B3JW4U3.js.map +1 -0
- package/dist/chunk-3TIYA3K5.js +55 -0
- package/dist/chunk-3TIYA3K5.js.map +1 -0
- package/dist/chunk-6XIJW65Q.js +52 -0
- package/dist/chunk-6XIJW65Q.js.map +1 -0
- package/dist/chunk-7LDQKJKI.js +248 -0
- package/dist/chunk-7LDQKJKI.js.map +1 -0
- package/dist/chunk-ALLOMOUN.js +810 -0
- package/dist/chunk-ALLOMOUN.js.map +1 -0
- package/dist/chunk-C2DN6KL4.js +853 -0
- package/dist/chunk-C2DN6KL4.js.map +1 -0
- package/dist/chunk-COKYQUTK.js +581 -0
- package/dist/chunk-COKYQUTK.js.map +1 -0
- package/dist/chunk-CPN4DOXH.js +115 -0
- package/dist/chunk-CPN4DOXH.js.map +1 -0
- package/dist/chunk-DBFXFWQZ.js +385 -0
- package/dist/chunk-DBFXFWQZ.js.map +1 -0
- package/dist/chunk-DZFFGUIA.js +81 -0
- package/dist/chunk-DZFFGUIA.js.map +1 -0
- package/dist/chunk-EEUYQFCP.js +106 -0
- package/dist/chunk-EEUYQFCP.js.map +1 -0
- package/dist/chunk-GFVYNPLS.js +118 -0
- package/dist/chunk-GFVYNPLS.js.map +1 -0
- package/dist/chunk-GJ4FTDBJ.js +2910 -0
- package/dist/chunk-GJ4FTDBJ.js.map +1 -0
- package/dist/chunk-GS5U3KUN.js +201 -0
- package/dist/chunk-GS5U3KUN.js.map +1 -0
- package/dist/chunk-HB7FBSH2.js +960 -0
- package/dist/chunk-HB7FBSH2.js.map +1 -0
- package/dist/chunk-HZFZX5A3.js +21 -0
- package/dist/chunk-HZFZX5A3.js.map +1 -0
- package/dist/chunk-J7VAYJKM.js +595 -0
- package/dist/chunk-J7VAYJKM.js.map +1 -0
- package/dist/chunk-NCNSHOF7.js +52 -0
- package/dist/chunk-NCNSHOF7.js.map +1 -0
- package/dist/chunk-RXU2Q2HF.js +49 -0
- package/dist/chunk-RXU2Q2HF.js.map +1 -0
- package/dist/chunk-SRJUZJKV.js +521 -0
- package/dist/chunk-SRJUZJKV.js.map +1 -0
- package/dist/chunk-TG7NTMTR.js +208 -0
- package/dist/chunk-TG7NTMTR.js.map +1 -0
- package/dist/chunk-TIZKGD4R.js +202 -0
- package/dist/chunk-TIZKGD4R.js.map +1 -0
- package/dist/chunk-WMKO5XOE.js +601 -0
- package/dist/chunk-WMKO5XOE.js.map +1 -0
- package/dist/chunk-WOQBVJH5.js +175 -0
- package/dist/chunk-WOQBVJH5.js.map +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +25 -0
- package/dist/cli.js.map +1 -0
- package/dist/errors-DgehLwqI.d.ts +98 -0
- package/dist/execution-halt-CW0Oi9s9.d.ts +12 -0
- package/dist/execution-types-UJ6gAF48.d.ts +239 -0
- package/dist/host-ledger-VPRWVVOS.js +25 -0
- package/dist/host-ledger-VPRWVVOS.js.map +1 -0
- package/dist/hosted-runtime.d.ts +168 -0
- package/dist/hosted-runtime.js +857 -0
- package/dist/hosted-runtime.js.map +1 -0
- package/dist/index-B86C6VAD.d.ts +41 -0
- package/dist/index.d.ts +327 -0
- package/dist/index.js +8818 -0
- package/dist/index.js.map +1 -0
- package/dist/memory-items-BSTC0_R0.d.ts +28 -0
- package/dist/memory-tools.d.ts +222 -0
- package/dist/memory-tools.js +923 -0
- package/dist/memory-tools.js.map +1 -0
- package/dist/orchestration/dynamic.d.ts +854 -0
- package/dist/orchestration/dynamic.js +3150 -0
- package/dist/orchestration/dynamic.js.map +1 -0
- package/dist/orchestration/graph.d.ts +11 -0
- package/dist/orchestration/graph.js +9 -0
- package/dist/orchestration/graph.js.map +1 -0
- package/dist/orchestration/index.d.ts +2385 -0
- package/dist/orchestration/index.js +6403 -0
- package/dist/orchestration/index.js.map +1 -0
- package/dist/orchestration/log.d.ts +301 -0
- package/dist/orchestration/log.js +3058 -0
- package/dist/orchestration/log.js.map +1 -0
- package/dist/orchestration/memory.d.ts +711 -0
- package/dist/orchestration/memory.js +27 -0
- package/dist/orchestration/memory.js.map +1 -0
- package/dist/provider-XCpWjJ6a.d.ts +151 -0
- package/dist/routing/index.d.ts +29 -0
- package/dist/routing/index.js +385 -0
- package/dist/routing/index.js.map +1 -0
- package/dist/routing/learning/index.d.ts +433 -0
- package/dist/routing/learning/index.js +2501 -0
- package/dist/routing/learning/index.js.map +1 -0
- package/dist/runtime-C6Cu2fvw.d.ts +283 -0
- package/dist/runtime-Y72XJFFO.js +18 -0
- package/dist/runtime-Y72XJFFO.js.map +1 -0
- package/dist/store-types-2YdceOMy.d.ts +78 -0
- package/dist/types-BB7KqceP.d.ts +52 -0
- package/dist/types-BBRKjIc7.d.ts +86 -0
- package/dist/types-DTFc1qO6.d.ts +1065 -0
- package/dist/types-DYex3p7_.d.ts +88 -0
- package/docs/licenses/ruflo-memory-MIT.txt +21 -0
- package/docs/releases/0.1.0-beta.1.md +13 -0
- package/package.json +114 -4
|
@@ -0,0 +1,1217 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ExecDiscovery,
|
|
3
|
+
IncrementalLineDecoder,
|
|
4
|
+
ProtocolResultAccumulator,
|
|
5
|
+
confirmedUsageRetryAt,
|
|
6
|
+
guardJsonlFrames,
|
|
7
|
+
jsonlFrames,
|
|
8
|
+
readProviderRateLimits,
|
|
9
|
+
resolveProviderRateLimits
|
|
10
|
+
} from "./chunk-DBFXFWQZ.js";
|
|
11
|
+
import {
|
|
12
|
+
runProcess
|
|
13
|
+
} from "./chunk-7LDQKJKI.js";
|
|
14
|
+
import {
|
|
15
|
+
AbortError,
|
|
16
|
+
AgentRuntimeError,
|
|
17
|
+
AmbiguousModelError,
|
|
18
|
+
ModelProviderMismatchError,
|
|
19
|
+
OutputLimitError,
|
|
20
|
+
ProtocolError,
|
|
21
|
+
TimeoutError,
|
|
22
|
+
UnknownModelError,
|
|
23
|
+
UnknownProviderError,
|
|
24
|
+
UnsupportedCapabilityError
|
|
25
|
+
} from "./chunk-TG7NTMTR.js";
|
|
26
|
+
|
|
27
|
+
// src/adapters/provider.ts
|
|
28
|
+
function isSafeSessionId(id) {
|
|
29
|
+
return typeof id === "string" && /^(?!.*\.jsonl$)[A-Za-z0-9][A-Za-z0-9._-]{0,511}$/i.test(id);
|
|
30
|
+
}
|
|
31
|
+
function parseObject(line) {
|
|
32
|
+
const trimmed = line.trim();
|
|
33
|
+
if (!trimmed.startsWith("{")) return void 0;
|
|
34
|
+
try {
|
|
35
|
+
const value = JSON.parse(trimmed);
|
|
36
|
+
if (typeof value === "object" && value !== null && !Array.isArray(value)) {
|
|
37
|
+
return value;
|
|
38
|
+
}
|
|
39
|
+
} catch {
|
|
40
|
+
}
|
|
41
|
+
return void 0;
|
|
42
|
+
}
|
|
43
|
+
function stringValue(value) {
|
|
44
|
+
return typeof value === "string" ? value : void 0;
|
|
45
|
+
}
|
|
46
|
+
function numberValue(value) {
|
|
47
|
+
return typeof value === "number" && Number.isFinite(value) ? value : void 0;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// src/compatibility/catalog.ts
|
|
51
|
+
var COMPATIBILITY_MODELS = [
|
|
52
|
+
{
|
|
53
|
+
id: "claude-opus-5",
|
|
54
|
+
provider: "claude",
|
|
55
|
+
aliases: ["opus", "opus-5"],
|
|
56
|
+
source: "compatibility-catalog",
|
|
57
|
+
availability: "unverified",
|
|
58
|
+
displayName: "Claude Opus 5",
|
|
59
|
+
supportedEffort: ["low", "medium", "high", "xhigh", "max"]
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
id: "claude-sonnet-5",
|
|
63
|
+
provider: "claude",
|
|
64
|
+
aliases: ["sonnet", "sonnet-5"],
|
|
65
|
+
source: "compatibility-catalog",
|
|
66
|
+
availability: "unverified",
|
|
67
|
+
displayName: "Claude Sonnet 5",
|
|
68
|
+
supportedEffort: ["low", "medium", "high", "xhigh", "max"]
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
id: "claude-haiku-4-5",
|
|
72
|
+
provider: "claude",
|
|
73
|
+
aliases: ["haiku", "haiku-4.5"],
|
|
74
|
+
source: "compatibility-catalog",
|
|
75
|
+
availability: "unverified",
|
|
76
|
+
displayName: "Claude Haiku 4.5"
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
id: "gpt-5.6-sol",
|
|
80
|
+
provider: "codex",
|
|
81
|
+
aliases: ["sol"],
|
|
82
|
+
source: "compatibility-catalog",
|
|
83
|
+
availability: "unverified",
|
|
84
|
+
displayName: "GPT-5.6 Sol",
|
|
85
|
+
supportedEffort: ["minimal", "low", "medium", "high", "xhigh"]
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
id: "gpt-5.6-terra",
|
|
89
|
+
provider: "codex",
|
|
90
|
+
aliases: ["terra"],
|
|
91
|
+
source: "compatibility-catalog",
|
|
92
|
+
availability: "unverified",
|
|
93
|
+
displayName: "GPT-5.6 Terra",
|
|
94
|
+
supportedEffort: ["minimal", "low", "medium", "high", "xhigh"]
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
id: "gpt-5.6-luna",
|
|
98
|
+
provider: "codex",
|
|
99
|
+
aliases: ["luna"],
|
|
100
|
+
source: "compatibility-catalog",
|
|
101
|
+
availability: "unverified",
|
|
102
|
+
displayName: "GPT-5.6 Luna",
|
|
103
|
+
supportedEffort: ["minimal", "low", "medium", "high", "xhigh"]
|
|
104
|
+
}
|
|
105
|
+
];
|
|
106
|
+
|
|
107
|
+
// src/core/models.ts
|
|
108
|
+
var AMBIGUOUS = /* @__PURE__ */ new Set(["best", "default"]);
|
|
109
|
+
function inferredProvider(id) {
|
|
110
|
+
if (id.startsWith("claude-")) return "claude";
|
|
111
|
+
if (id.startsWith("gpt-") || /^o\d/.test(id)) return "codex";
|
|
112
|
+
return void 0;
|
|
113
|
+
}
|
|
114
|
+
function distance(a, b) {
|
|
115
|
+
const row = Array.from({ length: b.length + 1 }, (_, index) => index);
|
|
116
|
+
for (let i = 1; i <= a.length; i += 1) {
|
|
117
|
+
let previous = row[0] ?? 0;
|
|
118
|
+
row[0] = i;
|
|
119
|
+
for (let j = 1; j <= b.length; j += 1) {
|
|
120
|
+
const saved = row[j] ?? 0;
|
|
121
|
+
row[j] = Math.min(
|
|
122
|
+
(row[j] ?? 0) + 1,
|
|
123
|
+
(row[j - 1] ?? 0) + 1,
|
|
124
|
+
previous + (a[i - 1] === b[j - 1] ? 0 : 1)
|
|
125
|
+
);
|
|
126
|
+
previous = saved;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return row[b.length] ?? Math.max(a.length, b.length);
|
|
130
|
+
}
|
|
131
|
+
function suggestionsFor(requested) {
|
|
132
|
+
const candidates = COMPATIBILITY_MODELS.flatMap((model) => [model.id, ...model.aliases]);
|
|
133
|
+
return [...new Set(candidates)].map((candidate) => ({ candidate, score: distance(requested, candidate) })).sort((a, b) => a.score - b.score).slice(0, 3).map(({ candidate }) => candidate);
|
|
134
|
+
}
|
|
135
|
+
function resolveModel(requested) {
|
|
136
|
+
const normalized = requested.trim().toLowerCase();
|
|
137
|
+
if (!normalized) throw new UnknownModelError(requested);
|
|
138
|
+
const slash = normalized.indexOf("/");
|
|
139
|
+
if (slash > 0) {
|
|
140
|
+
const prefix = normalized.slice(0, slash);
|
|
141
|
+
const id = normalized.slice(slash + 1);
|
|
142
|
+
if (prefix !== "claude" && prefix !== "codex" || !id) {
|
|
143
|
+
throw new UnknownModelError(requested, suggestionsFor(normalized));
|
|
144
|
+
}
|
|
145
|
+
const provider2 = prefix;
|
|
146
|
+
const inferred = inferredProvider(id);
|
|
147
|
+
if (inferred && inferred !== provider2) {
|
|
148
|
+
throw new ModelProviderMismatchError(requested, provider2, inferred);
|
|
149
|
+
}
|
|
150
|
+
const known2 = COMPATIBILITY_MODELS.find(
|
|
151
|
+
(model) => model.provider === provider2 && (model.id === id || model.aliases.includes(id))
|
|
152
|
+
);
|
|
153
|
+
return known2 ? { ...known2, aliases: [...known2.aliases] } : {
|
|
154
|
+
id,
|
|
155
|
+
provider: provider2,
|
|
156
|
+
aliases: [],
|
|
157
|
+
source: "explicit",
|
|
158
|
+
availability: "unverified"
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
if (AMBIGUOUS.has(normalized)) {
|
|
162
|
+
throw new AmbiguousModelError(requested, ["claude", "codex"]);
|
|
163
|
+
}
|
|
164
|
+
const known = COMPATIBILITY_MODELS.find(
|
|
165
|
+
(model) => model.id === normalized || model.aliases.includes(normalized)
|
|
166
|
+
);
|
|
167
|
+
if (known) return { ...known, aliases: [...known.aliases] };
|
|
168
|
+
const provider = inferredProvider(normalized);
|
|
169
|
+
if (provider) {
|
|
170
|
+
return {
|
|
171
|
+
id: normalized,
|
|
172
|
+
provider,
|
|
173
|
+
aliases: [],
|
|
174
|
+
source: "explicit",
|
|
175
|
+
availability: "unverified"
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
throw new UnknownModelError(requested, suggestionsFor(normalized));
|
|
179
|
+
}
|
|
180
|
+
function compatibilityModels(provider) {
|
|
181
|
+
return COMPATIBILITY_MODELS.filter((model) => provider === void 0 || model.provider === provider).map((model) => ({ ...model, aliases: [...model.aliases] }));
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// src/compatibility/version-range.ts
|
|
185
|
+
var PART = "(0|[1-9]\\d{0,8})";
|
|
186
|
+
var VERSION = new RegExp(`^${PART}\\.${PART}\\.${PART}$`);
|
|
187
|
+
var INTERVAL = /^>=(\S+) <(\S+)$/;
|
|
188
|
+
function parseCliVersion(text) {
|
|
189
|
+
const match = VERSION.exec(text);
|
|
190
|
+
if (!match) return void 0;
|
|
191
|
+
return [Number(match[1]), Number(match[2]), Number(match[3])];
|
|
192
|
+
}
|
|
193
|
+
function compareCliVersions(a, b) {
|
|
194
|
+
return a[0] - b[0] || a[1] - b[1] || a[2] - b[2];
|
|
195
|
+
}
|
|
196
|
+
function requireVersion(text, range) {
|
|
197
|
+
const version = parseCliVersion(text);
|
|
198
|
+
if (!version) throw new TypeError(`Malformed compatibility range ${JSON.stringify(range)}: ${JSON.stringify(text)} is not MAJOR.MINOR.PATCH`);
|
|
199
|
+
return version;
|
|
200
|
+
}
|
|
201
|
+
function parseCliVersionRange(range) {
|
|
202
|
+
if (typeof range !== "string") throw new TypeError("A compatibility range must be a string");
|
|
203
|
+
const interval = INTERVAL.exec(range);
|
|
204
|
+
if (!interval) {
|
|
205
|
+
const exact = requireVersion(range, range);
|
|
206
|
+
return { source: range, kind: "exact", low: exact, high: exact };
|
|
207
|
+
}
|
|
208
|
+
const low = requireVersion(interval[1], range);
|
|
209
|
+
const high = requireVersion(interval[2], range);
|
|
210
|
+
if (compareCliVersions(low, high) >= 0) {
|
|
211
|
+
throw new TypeError(`Malformed compatibility range ${JSON.stringify(range)}: the lower bound must be below the upper bound`);
|
|
212
|
+
}
|
|
213
|
+
return { source: range, kind: "interval", low, high };
|
|
214
|
+
}
|
|
215
|
+
function rangeIncludes(range, version) {
|
|
216
|
+
if (range.kind === "exact") return compareCliVersions(range.low, version) === 0;
|
|
217
|
+
return compareCliVersions(range.low, version) <= 0 && compareCliVersions(version, range.high) < 0;
|
|
218
|
+
}
|
|
219
|
+
function rangesConflict(a, b) {
|
|
220
|
+
if (a.kind !== b.kind) return false;
|
|
221
|
+
if (a.kind === "exact") return compareCliVersions(a.low, b.low) === 0;
|
|
222
|
+
return compareCliVersions(a.low, b.high) < 0 && compareCliVersions(b.low, a.high) < 0;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// src/compatibility/manifest.ts
|
|
226
|
+
var REQUIRED_FLAGS = {
|
|
227
|
+
claude: {
|
|
228
|
+
turns: { surface: "main", flags: ["--print", "--output-format", "--model", "--session-id", "--verbose"] },
|
|
229
|
+
resume: { surface: "main", flags: ["--resume"] },
|
|
230
|
+
forkWithPrompt: { surface: "main", flags: ["--fork-session"] },
|
|
231
|
+
structuredOutput: { surface: "main", flags: ["--json-schema"] },
|
|
232
|
+
tokenDeltas: { surface: "main", flags: ["--include-partial-messages"] },
|
|
233
|
+
cleanContext: { surface: "main", flags: ["--safe-mode"] },
|
|
234
|
+
permissions: { surface: "main", flags: ["--permission-mode"] }
|
|
235
|
+
},
|
|
236
|
+
codex: {
|
|
237
|
+
turns: { surface: "main", flags: ["--json", "--model"] },
|
|
238
|
+
resume: { surface: "resume", flags: ["--json", "--model"] },
|
|
239
|
+
forkWithPrompt: { surface: "fork", flags: ["--json", "--model"] },
|
|
240
|
+
structuredOutput: { surface: "main", flags: ["--output-schema"] },
|
|
241
|
+
cleanContext: { surface: "main", flags: ["--ignore-user-config", "--ignore-rules"] },
|
|
242
|
+
permissions: { surface: "main", flags: ["--sandbox"] }
|
|
243
|
+
}
|
|
244
|
+
};
|
|
245
|
+
function definedFlags(help) {
|
|
246
|
+
const flags = /* @__PURE__ */ new Set();
|
|
247
|
+
for (const line of help.split(/\r?\n/)) {
|
|
248
|
+
if (!/^\s*-/.test(line)) continue;
|
|
249
|
+
const definition = line.trimStart().split(/ {2,}|\t/)[0] ?? "";
|
|
250
|
+
for (const match of definition.matchAll(/(?:^|[\s,[])(--[\w-]+)/g)) flags.add(match[1]);
|
|
251
|
+
}
|
|
252
|
+
return flags;
|
|
253
|
+
}
|
|
254
|
+
function hasFlag(help, flag) {
|
|
255
|
+
return help ? definedFlags(help).has(flag) : false;
|
|
256
|
+
}
|
|
257
|
+
function assessCliCompatibility(provider, cliVersion, help) {
|
|
258
|
+
if (provider !== "claude" && provider !== "codex") throw new UnknownProviderError(provider);
|
|
259
|
+
const manifest = findCompatibilityEntry(provider, "exec", cliVersion);
|
|
260
|
+
const features = manifest ? { ...manifest.features } : {};
|
|
261
|
+
const missingFlags = [];
|
|
262
|
+
for (const [feature, requirement] of Object.entries(REQUIRED_FLAGS[provider])) {
|
|
263
|
+
const missing = requirement.flags.filter((flag) => !hasFlag(help[requirement.surface], flag));
|
|
264
|
+
if (missing.length > 0) {
|
|
265
|
+
features[feature] = "unsupported";
|
|
266
|
+
missingFlags.push(...missing);
|
|
267
|
+
} else if (!manifest || manifest.evidence !== "live-contract") {
|
|
268
|
+
if (features[feature] === void 0 || features[feature] === "supported") features[feature] = "unverified";
|
|
269
|
+
} else if (features[feature] === void 0) {
|
|
270
|
+
features[feature] = "supported";
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
if (provider === "codex") features.tokenDeltas = "unsupported";
|
|
274
|
+
const responseMissing = provider === "claude" ? ["--system-prompt", "--safe-mode", "--tools", "--allowed-tools", "--strict-mcp-config", "--permission-mode"].filter((flag) => !hasFlag(help.main, flag)) : [];
|
|
275
|
+
if (provider === "claude" && !/\bdontAsk\b/.test(help.main)) responseMissing.push("permission-mode.dontAsk");
|
|
276
|
+
return {
|
|
277
|
+
...provider === "claude" ? { responsePolicy: { supported: responseMissing.length === 0, missing: responseMissing } } : {},
|
|
278
|
+
provider,
|
|
279
|
+
cliVersion,
|
|
280
|
+
transport: "exec",
|
|
281
|
+
evidence: manifest && missingFlags.length === 0 ? manifest.evidence : "help-probe",
|
|
282
|
+
features,
|
|
283
|
+
missingFlags: [...new Set(missingFlags)],
|
|
284
|
+
knownIssues: manifest?.knownIssues ?? ["CLI version is outside the exact tested manifest"]
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
function findCompatibilityEntry(provider, transport, cliVersion, manifest = COMPATIBILITY_MANIFEST) {
|
|
288
|
+
const version = parseCliVersion(cliVersion);
|
|
289
|
+
if (!version) return void 0;
|
|
290
|
+
const matches = manifest.filter((entry) => entry.provider === provider && entry.transport === transport).map((entry) => ({ entry, range: parseCliVersionRange(entry.cliRange) })).filter(({ range }) => rangeIncludes(range, version));
|
|
291
|
+
const exact = matches.filter(({ range }) => range.kind === "exact");
|
|
292
|
+
const best = exact.length > 0 ? exact : matches;
|
|
293
|
+
if (best.length > 1) {
|
|
294
|
+
throw new Error(`Compatibility manifest is ambiguous for ${provider} ${transport} ${cliVersion}: ${best.map(({ range }) => range.source).join(", ")}`);
|
|
295
|
+
}
|
|
296
|
+
return best[0]?.entry;
|
|
297
|
+
}
|
|
298
|
+
function validateCompatibilityManifest(manifest) {
|
|
299
|
+
const parsed = [];
|
|
300
|
+
for (const entry of manifest) {
|
|
301
|
+
const range = parseCliVersionRange(entry.cliRange);
|
|
302
|
+
for (const other of parsed) {
|
|
303
|
+
if (other.entry.provider === entry.provider && other.entry.transport === entry.transport && rangesConflict(other.range, range)) {
|
|
304
|
+
throw new Error(`Compatibility ranges overlap for ${entry.provider} ${entry.transport}: ${other.range.source} and ${range.source}`);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
if (entry.evidence !== "live-contract") {
|
|
308
|
+
const claimed = Object.entries(entry.features).filter(([, support]) => support === "supported").map(([name]) => name);
|
|
309
|
+
if (claimed.length > 0) {
|
|
310
|
+
throw new Error(`${entry.provider} ${entry.cliRange} has ${entry.evidence} evidence but declares supported: ${claimed.join(", ")}`);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
parsed.push({ entry, range });
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
var COMPATIBILITY_MANIFEST = [
|
|
317
|
+
{
|
|
318
|
+
provider: "claude",
|
|
319
|
+
cliRange: "2.1.251",
|
|
320
|
+
transport: "exec",
|
|
321
|
+
evidence: "live-contract",
|
|
322
|
+
features: {
|
|
323
|
+
resume: "supported",
|
|
324
|
+
forkWithPrompt: "supported",
|
|
325
|
+
forkWithoutPrompt: "unsupported",
|
|
326
|
+
structuredOutput: "supported",
|
|
327
|
+
tokenDeltas: "supported",
|
|
328
|
+
cleanContext: "supported"
|
|
329
|
+
},
|
|
330
|
+
knownIssues: [
|
|
331
|
+
"Exit code 0 can contain an is_error result envelope",
|
|
332
|
+
"Promptless fork is not a verified exec semantic"
|
|
333
|
+
]
|
|
334
|
+
},
|
|
335
|
+
{
|
|
336
|
+
provider: "claude",
|
|
337
|
+
cliRange: "2.1.228",
|
|
338
|
+
transport: "exec",
|
|
339
|
+
evidence: "live-contract",
|
|
340
|
+
features: {
|
|
341
|
+
resume: "supported",
|
|
342
|
+
forkWithPrompt: "supported",
|
|
343
|
+
forkWithoutPrompt: "unsupported",
|
|
344
|
+
structuredOutput: "supported",
|
|
345
|
+
tokenDeltas: "supported",
|
|
346
|
+
cleanContext: "supported"
|
|
347
|
+
},
|
|
348
|
+
knownIssues: ["Promptless fork is not supported by print mode even though --fork-session exists"]
|
|
349
|
+
},
|
|
350
|
+
{
|
|
351
|
+
provider: "codex",
|
|
352
|
+
cliRange: "0.149.0",
|
|
353
|
+
transport: "exec",
|
|
354
|
+
evidence: "live-contract",
|
|
355
|
+
features: {
|
|
356
|
+
resume: "supported",
|
|
357
|
+
forkWithPrompt: "supported",
|
|
358
|
+
forkWithoutPrompt: "unsupported",
|
|
359
|
+
structuredOutput: "supported",
|
|
360
|
+
tokenDeltas: "unsupported",
|
|
361
|
+
cleanContext: "partial"
|
|
362
|
+
},
|
|
363
|
+
knownIssues: [
|
|
364
|
+
"Exit code 0 can contain error events without turn.completed",
|
|
365
|
+
"Error items may also be recoverable when followed by turn.completed",
|
|
366
|
+
"Promptless exec fork rejects empty stdin"
|
|
367
|
+
]
|
|
368
|
+
},
|
|
369
|
+
{
|
|
370
|
+
// Evidence: `codex --version` = codex-cli 0.153.4 and `codex --help`, `codex exec --help`, `codex exec resume
|
|
371
|
+
// --help`, `codex exec fork --help` on 2026-11-14. Every flag the exec adapter emits is defined on the surface
|
|
372
|
+
// where the adapter places it. No turn ran for this entry, so nothing here is 'supported': visible flags stay
|
|
373
|
+
// 'unverified', and only known limits are stated. 0.153.0-0.153.3 were never observed and stay outside.
|
|
374
|
+
provider: "codex",
|
|
375
|
+
cliRange: ">=0.153.4 <0.154.0",
|
|
376
|
+
transport: "exec",
|
|
377
|
+
evidence: "help-probe",
|
|
378
|
+
features: {
|
|
379
|
+
forkWithoutPrompt: "unsupported",
|
|
380
|
+
tokenDeltas: "unsupported",
|
|
381
|
+
cleanContext: "partial"
|
|
382
|
+
},
|
|
383
|
+
knownIssues: [
|
|
384
|
+
"Help-probed only: no live contract turn backs this range",
|
|
385
|
+
"--ask-for-approval is defined by top-level codex --help, not by codex exec --help, which is the only main surface probed"
|
|
386
|
+
]
|
|
387
|
+
}
|
|
388
|
+
];
|
|
389
|
+
|
|
390
|
+
// src/adapters/codex/exec-adapter.ts
|
|
391
|
+
import { mkdtemp, rm, writeFile } from "node:fs/promises";
|
|
392
|
+
import { tmpdir } from "node:os";
|
|
393
|
+
import { join } from "node:path";
|
|
394
|
+
|
|
395
|
+
// src/control/bounded-queue.ts
|
|
396
|
+
function defaultMeasure(value) {
|
|
397
|
+
try {
|
|
398
|
+
const serialized = typeof value === "string" ? value : JSON.stringify(value);
|
|
399
|
+
return Buffer.byteLength(serialized ?? "", "utf8");
|
|
400
|
+
} catch {
|
|
401
|
+
return Number.POSITIVE_INFINITY;
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
var BoundedQueue = class {
|
|
405
|
+
#values = [];
|
|
406
|
+
#waiters = [];
|
|
407
|
+
#producers = [];
|
|
408
|
+
#closed = false;
|
|
409
|
+
#failure;
|
|
410
|
+
#queuedBytes = 0;
|
|
411
|
+
#maxItems;
|
|
412
|
+
#maxBytes;
|
|
413
|
+
#overflow;
|
|
414
|
+
#maxPendingProducers;
|
|
415
|
+
#measure;
|
|
416
|
+
constructor(options = {}) {
|
|
417
|
+
this.#maxItems = options.maxItems ?? 1024;
|
|
418
|
+
this.#maxBytes = options.maxBytes ?? 16 * 1024 * 1024;
|
|
419
|
+
this.#overflow = options.overflow ?? "fail";
|
|
420
|
+
this.#maxPendingProducers = options.maxPendingProducers === void 0 ? 1 : options.maxPendingProducers;
|
|
421
|
+
if (!Number.isSafeInteger(this.#maxPendingProducers) || this.#maxPendingProducers < 1) {
|
|
422
|
+
throw new RangeError("maxPendingProducers must be a positive safe integer");
|
|
423
|
+
}
|
|
424
|
+
this.#measure = options.measure ?? defaultMeasure;
|
|
425
|
+
}
|
|
426
|
+
get size() {
|
|
427
|
+
return this.#values.length;
|
|
428
|
+
}
|
|
429
|
+
get bufferedBytes() {
|
|
430
|
+
return this.#queuedBytes;
|
|
431
|
+
}
|
|
432
|
+
#hasCapacity(bytes) {
|
|
433
|
+
return this.#values.length < this.#maxItems && this.#queuedBytes + bytes <= this.#maxBytes;
|
|
434
|
+
}
|
|
435
|
+
#overflowError() {
|
|
436
|
+
return new OutputLimitError(
|
|
437
|
+
{ retryable: false },
|
|
438
|
+
`Async queue exceeded ${this.#maxItems} items or ${this.#maxBytes} bytes`
|
|
439
|
+
);
|
|
440
|
+
}
|
|
441
|
+
#accept(entry) {
|
|
442
|
+
const waiter = this.#waiters.shift();
|
|
443
|
+
if (waiter) {
|
|
444
|
+
waiter.resolve({ done: false, value: entry.value });
|
|
445
|
+
return;
|
|
446
|
+
}
|
|
447
|
+
this.#values.push(entry);
|
|
448
|
+
this.#queuedBytes += entry.bytes;
|
|
449
|
+
}
|
|
450
|
+
push(value) {
|
|
451
|
+
if (this.#closed) return;
|
|
452
|
+
const bytes = this.#measure(value);
|
|
453
|
+
if (this.#waiters.length === 0 && !this.#hasCapacity(bytes)) throw this.#overflowError();
|
|
454
|
+
this.#accept({ value, bytes });
|
|
455
|
+
}
|
|
456
|
+
async enqueue(value) {
|
|
457
|
+
if (this.#closed) {
|
|
458
|
+
if (this.#failure !== void 0) throw this.#failure;
|
|
459
|
+
return;
|
|
460
|
+
}
|
|
461
|
+
const bytes = this.#measure(value);
|
|
462
|
+
if (bytes > this.#maxBytes) throw this.#overflowError();
|
|
463
|
+
if (this.#waiters.length > 0 || this.#hasCapacity(bytes)) {
|
|
464
|
+
this.#accept({ value, bytes });
|
|
465
|
+
return;
|
|
466
|
+
}
|
|
467
|
+
if (this.#overflow === "fail") throw this.#overflowError();
|
|
468
|
+
if (this.#producers.length >= this.#maxPendingProducers) {
|
|
469
|
+
throw new OutputLimitError(
|
|
470
|
+
{
|
|
471
|
+
retryable: false,
|
|
472
|
+
sanitizedDiagnostics: { maxPendingProducers: this.#maxPendingProducers }
|
|
473
|
+
},
|
|
474
|
+
`Async queue exceeded ${this.#maxPendingProducers} pending producers`
|
|
475
|
+
);
|
|
476
|
+
}
|
|
477
|
+
return new Promise((resolve, reject) => {
|
|
478
|
+
this.#producers.push({ entry: { value, bytes }, resolve, reject });
|
|
479
|
+
});
|
|
480
|
+
}
|
|
481
|
+
#admitProducers() {
|
|
482
|
+
while (this.#producers.length > 0) {
|
|
483
|
+
const head = this.#producers[0];
|
|
484
|
+
if (head === void 0) return;
|
|
485
|
+
if (this.#waiters.length === 0 && !this.#hasCapacity(head.entry.bytes)) return;
|
|
486
|
+
this.#producers.shift();
|
|
487
|
+
this.#accept(head.entry);
|
|
488
|
+
head.resolve();
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
close() {
|
|
492
|
+
if (this.#closed) return;
|
|
493
|
+
this.#closed = true;
|
|
494
|
+
for (const waiter of this.#waiters.splice(0)) {
|
|
495
|
+
waiter.resolve({ done: true, value: void 0 });
|
|
496
|
+
}
|
|
497
|
+
for (const producer of this.#producers.splice(0)) producer.resolve();
|
|
498
|
+
}
|
|
499
|
+
fail(error) {
|
|
500
|
+
if (this.#closed) return;
|
|
501
|
+
this.#failure = error;
|
|
502
|
+
this.#closed = true;
|
|
503
|
+
for (const waiter of this.#waiters.splice(0)) waiter.reject(error);
|
|
504
|
+
for (const producer of this.#producers.splice(0)) producer.reject(error);
|
|
505
|
+
}
|
|
506
|
+
[Symbol.asyncIterator]() {
|
|
507
|
+
return {
|
|
508
|
+
next: async () => {
|
|
509
|
+
const entry = this.#values.shift();
|
|
510
|
+
if (entry !== void 0) {
|
|
511
|
+
this.#queuedBytes = Math.max(0, this.#queuedBytes - entry.bytes);
|
|
512
|
+
this.#admitProducers();
|
|
513
|
+
return { done: false, value: entry.value };
|
|
514
|
+
}
|
|
515
|
+
if (this.#failure !== void 0) throw this.#failure;
|
|
516
|
+
if (this.#closed) return { done: true, value: void 0 };
|
|
517
|
+
return new Promise((resolve, reject) => {
|
|
518
|
+
this.#waiters.push({ resolve, reject });
|
|
519
|
+
this.#admitProducers();
|
|
520
|
+
});
|
|
521
|
+
}
|
|
522
|
+
};
|
|
523
|
+
}
|
|
524
|
+
};
|
|
525
|
+
|
|
526
|
+
// src/process/exec-stream-pump.ts
|
|
527
|
+
var ExecStreamPump = class {
|
|
528
|
+
#queue = new BoundedQueue({ overflow: "wait", maxPendingProducers: 1 });
|
|
529
|
+
#decoder = new IncrementalLineDecoder();
|
|
530
|
+
#accumulator = new ProtocolResultAccumulator();
|
|
531
|
+
#stop = new AbortController();
|
|
532
|
+
signal;
|
|
533
|
+
#parseLine;
|
|
534
|
+
#parseFinal;
|
|
535
|
+
#announcedSession;
|
|
536
|
+
#mode;
|
|
537
|
+
#delivering = false;
|
|
538
|
+
#failed = false;
|
|
539
|
+
#failure;
|
|
540
|
+
#finished = false;
|
|
541
|
+
#terminal;
|
|
542
|
+
#usage;
|
|
543
|
+
constructor(signal, parseLine, parseFinal) {
|
|
544
|
+
this.signal = signal ? AbortSignal.any([signal, this.#stop.signal]) : this.#stop.signal;
|
|
545
|
+
this.#parseLine = parseLine;
|
|
546
|
+
this.#parseFinal = parseFinal;
|
|
547
|
+
this.signal.addEventListener("abort", this.#onAbort, { once: true });
|
|
548
|
+
if (this.signal.aborted) this.#onAbort();
|
|
549
|
+
}
|
|
550
|
+
#onAbort = () => this.fail(new AbortError({ retryable: true }));
|
|
551
|
+
#check(mode) {
|
|
552
|
+
if (this.#failed) throw this.#failure;
|
|
553
|
+
if (this.#finished || mode && this.#mode && mode !== this.#mode) {
|
|
554
|
+
throw new ProtocolError({ retryable: false }, "Invalid exec output delivery sequence");
|
|
555
|
+
}
|
|
556
|
+
if (mode) this.#mode = mode;
|
|
557
|
+
}
|
|
558
|
+
*#items(line) {
|
|
559
|
+
const parsed = this.#parseLine(line);
|
|
560
|
+
this.#rememberUsage(parsed.usage);
|
|
561
|
+
this.#accumulator.observe(line, parsed);
|
|
562
|
+
if (parsed.sessionId && parsed.sessionId !== this.#announcedSession) {
|
|
563
|
+
this.#announcedSession = parsed.sessionId;
|
|
564
|
+
yield { kind: "session", sessionId: parsed.sessionId };
|
|
565
|
+
}
|
|
566
|
+
for (const event of parsed.events) yield { kind: "event", event };
|
|
567
|
+
}
|
|
568
|
+
/** Legacy runners keep synchronous bounded overflow rather than spawning waiting promises. */
|
|
569
|
+
onStdout = (chunk) => {
|
|
570
|
+
try {
|
|
571
|
+
this.#check("sync");
|
|
572
|
+
for (const line of this.#decoder.push(chunk)) for (const item of this.#items(line)) this.#queue.push(item);
|
|
573
|
+
} catch (error) {
|
|
574
|
+
this.fail(error);
|
|
575
|
+
throw error;
|
|
576
|
+
}
|
|
577
|
+
};
|
|
578
|
+
onStdoutAsync = (chunk, signal = this.signal) => {
|
|
579
|
+
const work = this.#deliver(chunk, signal);
|
|
580
|
+
void work.catch(() => void 0);
|
|
581
|
+
return work;
|
|
582
|
+
};
|
|
583
|
+
async #deliver(chunk, signal) {
|
|
584
|
+
let ownsDelivery = false;
|
|
585
|
+
const abort = () => this.fail(signal.reason instanceof Error ? signal.reason : new AbortError({ retryable: true }));
|
|
586
|
+
try {
|
|
587
|
+
this.#check("async");
|
|
588
|
+
if (this.#delivering) throw new ProtocolError({ retryable: false }, "Exec runner ignored output acknowledgment");
|
|
589
|
+
this.#delivering = true;
|
|
590
|
+
ownsDelivery = true;
|
|
591
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
592
|
+
if (signal.aborted) abort();
|
|
593
|
+
this.#check();
|
|
594
|
+
for (const line of this.#decoder.push(chunk)) {
|
|
595
|
+
for (const item of this.#items(line)) await this.#queue.enqueue(item);
|
|
596
|
+
}
|
|
597
|
+
} catch (error) {
|
|
598
|
+
this.fail(error);
|
|
599
|
+
throw error;
|
|
600
|
+
} finally {
|
|
601
|
+
if (ownsDelivery) {
|
|
602
|
+
signal.removeEventListener("abort", abort);
|
|
603
|
+
this.#delivering = false;
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
async finish(project) {
|
|
608
|
+
this.#check();
|
|
609
|
+
if (this.#delivering) throw new ProtocolError({ retryable: false }, "Exec runner completed before output acknowledgment");
|
|
610
|
+
for (const line of this.#decoder.finish()) {
|
|
611
|
+
for (const item of this.#items(line)) await this.#queue.enqueue(item);
|
|
612
|
+
}
|
|
613
|
+
this.#check();
|
|
614
|
+
this.#terminal = project(this.#accumulator.finish(this.#parseFinal));
|
|
615
|
+
this.#rememberUsage(this.#terminal.usage);
|
|
616
|
+
this.#finished = true;
|
|
617
|
+
this.#queue.close();
|
|
618
|
+
}
|
|
619
|
+
fail(error) {
|
|
620
|
+
if (error instanceof AgentRuntimeError) this.#rememberUsage(error.context.observedUsage);
|
|
621
|
+
if (this.#failed) return;
|
|
622
|
+
this.#failed = true;
|
|
623
|
+
this.#failure = error === void 0 ? new ProtocolError({ retryable: false }, "Exec runner failed without a cause") : error;
|
|
624
|
+
this.#queue.fail(this.#failure);
|
|
625
|
+
}
|
|
626
|
+
#rememberUsage(usage) {
|
|
627
|
+
if (usage !== void 0) {
|
|
628
|
+
try {
|
|
629
|
+
this.#usage = structuredClone(usage);
|
|
630
|
+
} catch {
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
/** Called only after opted-in actual execution settles; no text or identity is adopted. */
|
|
635
|
+
afterSettlement(primary) {
|
|
636
|
+
if (!(primary instanceof AbortError || primary instanceof TimeoutError) || this.#usage === void 0) return primary;
|
|
637
|
+
const context = { ...primary.context, observedUsage: structuredClone(this.#usage) };
|
|
638
|
+
const message = primary.message;
|
|
639
|
+
const enriched = primary instanceof TimeoutError ? new TimeoutError(context, message) : new AbortError(context, message);
|
|
640
|
+
if (primary.stack !== void 0) enriched.stack = primary.stack;
|
|
641
|
+
if (Object.hasOwn(primary, "cause")) Object.defineProperty(enriched, "cause", Object.getOwnPropertyDescriptor(primary, "cause"));
|
|
642
|
+
return enriched;
|
|
643
|
+
}
|
|
644
|
+
async *items() {
|
|
645
|
+
yield* this.#queue;
|
|
646
|
+
if (this.#failed) throw this.#failure;
|
|
647
|
+
if (this.#terminal) yield { kind: "result", result: this.#terminal };
|
|
648
|
+
}
|
|
649
|
+
cancel() {
|
|
650
|
+
this.#stop.abort();
|
|
651
|
+
this.signal.removeEventListener("abort", this.#onAbort);
|
|
652
|
+
}
|
|
653
|
+
};
|
|
654
|
+
|
|
655
|
+
// src/adapters/failure-classification.ts
|
|
656
|
+
function nativeFailureReason(message, code) {
|
|
657
|
+
if (/too long|context (?:window|length)|invalid_request|\b400\b|polic(?:y|ies)|flagged|content filter|safety/i.test(message)) return "request-rejected";
|
|
658
|
+
if (["error_max_turns", "error_max_budget_usd", "error_max_structured_output_retries"].includes(code ?? "")) return "execution-limit";
|
|
659
|
+
if (/overloaded|\b529\b|\b503\b|service unavailable/i.test(message)) return "provider-overloaded";
|
|
660
|
+
if (/exited with code|\b5\d\d\b|\bECONN\w*|\bETIMEDOUT\b|\bEPIPE\b|socket hang up|stream (?:ended|closed|disconnected)|disconnected|timed? ?out connecting|connection (?:reset|refused|closed)|bad gateway|internal server error/i.test(message)) return "transport";
|
|
661
|
+
return void 0;
|
|
662
|
+
}
|
|
663
|
+
var nativeUsageLimit = (message) => /\b(?:usage|rate|weekly|daily|session|monthly)[ -]limit|\bhit your (?:\w+ )?limit|\blimit reached|\bquota(?: exceeded)?\b/i.test(message);
|
|
664
|
+
function classifyClaudeFailure(event) {
|
|
665
|
+
const errors = Array.isArray(event.errors) ? event.errors.filter((item) => typeof item === "string").join(" | ") : "";
|
|
666
|
+
const message = stringValue(event.result) ?? (errors || "Claude turn failed");
|
|
667
|
+
const rawCode = stringValue(event.terminal_reason) ?? stringValue(event.subtype);
|
|
668
|
+
const base = { message, ...rawCode === void 0 ? {} : { rawCode } };
|
|
669
|
+
const reason = nativeFailureReason(message, rawCode);
|
|
670
|
+
if (reason === "request-rejected" || reason === "execution-limit") return { kind: "provider-unavailable", reason, ...base };
|
|
671
|
+
if (/no conversation found/i.test(message)) return { kind: "session-not-found", ...base };
|
|
672
|
+
if (/not logged in|please run \/login|unauthenticated/i.test(message)) return { kind: "not-authenticated", ...base };
|
|
673
|
+
if (/unrecognized.model|unknown.model|model.*not found/i.test(message)) return { kind: "unknown-model", ...base };
|
|
674
|
+
if (/model.*(?:unavailable|access|plan|tier)/i.test(message)) return { kind: "model-unavailable", ...base };
|
|
675
|
+
if (nativeUsageLimit(message)) return { kind: "usage-limit", ...base };
|
|
676
|
+
return { kind: "provider-unavailable", ...base, ...reason === void 0 ? {} : { reason } };
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
// src/adapters/codex/protocol.ts
|
|
680
|
+
function classifyCodexFailure(messages) {
|
|
681
|
+
const message = messages.join(" | ") || "Codex turn failed";
|
|
682
|
+
const normalized = message.toLowerCase();
|
|
683
|
+
if (/not (?:inside|in) a (?:trusted )?(?:git )?(?:repository|directory)|untrusted (?:repository|workspace|directory)|git repository.*required/.test(normalized)) {
|
|
684
|
+
return {
|
|
685
|
+
kind: "untrusted-workspace",
|
|
686
|
+
message: `${message} (remediation: run inside a trusted git repository or set providerOptions.codex.skipGitRepoCheck)`
|
|
687
|
+
};
|
|
688
|
+
}
|
|
689
|
+
const reason = nativeFailureReason(message);
|
|
690
|
+
if (reason === "request-rejected" || reason === "execution-limit") return { kind: "provider-unavailable", message, reason };
|
|
691
|
+
if (/no rollout found/.test(normalized)) return { kind: "session-not-found", message };
|
|
692
|
+
if (/not logged in|run codex login|codex login|authentication failed|invalid (?:api key|credentials)|token (?:has )?expired/.test(normalized)) {
|
|
693
|
+
return { kind: "not-authenticated", message };
|
|
694
|
+
}
|
|
695
|
+
if (/unknown model|model.*not found/.test(normalized)) return { kind: "unknown-model", message };
|
|
696
|
+
if (/model.*(?:unavailable|access|plan|tier)|not supported when using codex with a chatgpt/.test(normalized)) {
|
|
697
|
+
return { kind: "model-unavailable", message };
|
|
698
|
+
}
|
|
699
|
+
if (nativeUsageLimit(message)) return { kind: "usage-limit", message };
|
|
700
|
+
return { kind: "provider-unavailable", message, ...reason === void 0 ? {} : { reason } };
|
|
701
|
+
}
|
|
702
|
+
function parseUsage(value) {
|
|
703
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) return void 0;
|
|
704
|
+
const raw = value;
|
|
705
|
+
const usage = { costMeaning: "unavailable" };
|
|
706
|
+
const inputTokens = numberValue(raw.input_tokens);
|
|
707
|
+
const outputTokens = numberValue(raw.output_tokens);
|
|
708
|
+
const cachedInputTokens = numberValue(raw.cached_input_tokens);
|
|
709
|
+
const cacheWriteInputTokens = numberValue(raw.cache_write_input_tokens);
|
|
710
|
+
if (inputTokens !== void 0) usage.inputTokens = inputTokens;
|
|
711
|
+
if (outputTokens !== void 0) usage.outputTokens = outputTokens;
|
|
712
|
+
if (cachedInputTokens !== void 0) usage.cachedInputTokens = cachedInputTokens;
|
|
713
|
+
if (cacheWriteInputTokens !== void 0) usage.cacheCreationTokens = cacheWriteInputTokens;
|
|
714
|
+
return usage;
|
|
715
|
+
}
|
|
716
|
+
function itemId(item, index) {
|
|
717
|
+
return stringValue(item.id) ?? `codex-item-${index}`;
|
|
718
|
+
}
|
|
719
|
+
function toolName(item) {
|
|
720
|
+
const type = stringValue(item.type);
|
|
721
|
+
if (type === "command_execution") return "shell";
|
|
722
|
+
if (type === "mcp_tool_call") return stringValue(item.tool) ?? "mcp";
|
|
723
|
+
return type ?? "unknown";
|
|
724
|
+
}
|
|
725
|
+
function parseCodexJsonl(raw, state = { itemIndex: 0 }) {
|
|
726
|
+
const events = [];
|
|
727
|
+
const nativeEvents = [];
|
|
728
|
+
const errorMessages = [];
|
|
729
|
+
let sessionId;
|
|
730
|
+
let turnId;
|
|
731
|
+
let text = "";
|
|
732
|
+
let usage;
|
|
733
|
+
let terminalEvent;
|
|
734
|
+
let structuredThrottle = false;
|
|
735
|
+
let structuredQuota = false;
|
|
736
|
+
for (const line of jsonlFrames(raw)) {
|
|
737
|
+
if (!line.trim()) continue;
|
|
738
|
+
const event = parseObject(line);
|
|
739
|
+
if (!event) {
|
|
740
|
+
events.push({ type: "provider.event", provider: "codex", event: { type: "non-json-output", line } });
|
|
741
|
+
continue;
|
|
742
|
+
}
|
|
743
|
+
nativeEvents.push(event);
|
|
744
|
+
const limits = resolveProviderRateLimits(readProviderRateLimits("codex", event));
|
|
745
|
+
if (limits) {
|
|
746
|
+
events.push({ type: "provider.event", provider: "codex", event: limits });
|
|
747
|
+
if (limits.source === "codex-usage-error") {
|
|
748
|
+
structuredQuota = true;
|
|
749
|
+
errorMessages.push("Usage limit reached");
|
|
750
|
+
}
|
|
751
|
+
continue;
|
|
752
|
+
}
|
|
753
|
+
const type = stringValue(event.type);
|
|
754
|
+
if (type === "thread.started") {
|
|
755
|
+
sessionId = stringValue(event.thread_id) ?? sessionId;
|
|
756
|
+
} else if (type === "turn.started") {
|
|
757
|
+
turnId = stringValue(event.turn_id) ?? turnId;
|
|
758
|
+
events.push(turnId === void 0 ? { type: "turn.started" } : { type: "turn.started", turnId });
|
|
759
|
+
} else if (type === "item.started" || type === "item.updated" || type === "item.completed") {
|
|
760
|
+
const item = event.item;
|
|
761
|
+
if (typeof item !== "object" || item === null || Array.isArray(item)) continue;
|
|
762
|
+
const value = item;
|
|
763
|
+
const id = itemId(value, state.itemIndex++);
|
|
764
|
+
const itemType = stringValue(value.type);
|
|
765
|
+
if (itemType === "agent_message" && type === "item.completed") {
|
|
766
|
+
text = stringValue(value.text) ?? text;
|
|
767
|
+
events.push({ type: "message.completed", text });
|
|
768
|
+
} else if (itemType === "error") {
|
|
769
|
+
const message = stringValue(value.message) ?? "Codex item error";
|
|
770
|
+
errorMessages.push(message);
|
|
771
|
+
events.push({ type: "provider.event", provider: "codex", event });
|
|
772
|
+
} else if (["command_execution", "mcp_tool_call", "file_change", "patch_apply", "web_search"].includes(itemType ?? "")) {
|
|
773
|
+
if (type === "item.started") {
|
|
774
|
+
events.push({ type: "tool.started", id, name: toolName(value), input: value });
|
|
775
|
+
} else if (type === "item.updated") {
|
|
776
|
+
events.push({ type: "tool.updated", id, update: value });
|
|
777
|
+
} else {
|
|
778
|
+
events.push({ type: "tool.completed", id, output: value });
|
|
779
|
+
}
|
|
780
|
+
} else {
|
|
781
|
+
events.push({ type: "provider.event", provider: "codex", event });
|
|
782
|
+
}
|
|
783
|
+
} else if (type === "turn.completed") {
|
|
784
|
+
terminalEvent = event;
|
|
785
|
+
usage = parseUsage(event.usage);
|
|
786
|
+
} else if (type === "turn.failed") {
|
|
787
|
+
terminalEvent = event;
|
|
788
|
+
errorMessages.push(stringValue(event.message) ?? "turn.failed");
|
|
789
|
+
} else if (type === "error") {
|
|
790
|
+
const code = typeof event.error === "object" && event.error !== null ? event.error.type ?? event.error.code : void 0;
|
|
791
|
+
if (code === "rate_limit_exceeded") {
|
|
792
|
+
structuredThrottle = true;
|
|
793
|
+
errorMessages.push("Provider request throttled");
|
|
794
|
+
} else errorMessages.push(stringValue(event.message) ?? "Codex error event");
|
|
795
|
+
events.push({ type: "provider.event", provider: "codex", event });
|
|
796
|
+
} else {
|
|
797
|
+
events.push({ type: "provider.event", provider: "codex", event });
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
let failure;
|
|
801
|
+
if (terminalEvent?.type === "turn.failed") {
|
|
802
|
+
failure = classifyCodexFailure(errorMessages);
|
|
803
|
+
} else if (!terminalEvent && errorMessages.length > 0) {
|
|
804
|
+
failure = classifyCodexFailure(errorMessages);
|
|
805
|
+
} else if (!terminalEvent) {
|
|
806
|
+
failure = { kind: "protocol", message: "Codex stream ended without turn.completed or turn.failed" };
|
|
807
|
+
}
|
|
808
|
+
const retryAt = confirmedUsageRetryAt(events);
|
|
809
|
+
if (failure && structuredThrottle && !structuredQuota) failure = { kind: "provider-unavailable", message: "Provider request throttled" };
|
|
810
|
+
if (failure?.kind === "usage-limit" && retryAt !== void 0) failure = { ...failure, retryAt };
|
|
811
|
+
return {
|
|
812
|
+
completed: terminalEvent?.type === "turn.completed" && failure === void 0,
|
|
813
|
+
failed: failure !== void 0,
|
|
814
|
+
refused: false,
|
|
815
|
+
...sessionId === void 0 ? {} : { sessionId },
|
|
816
|
+
...turnId === void 0 ? {} : { turnId },
|
|
817
|
+
text,
|
|
818
|
+
...usage === void 0 ? {} : { usage },
|
|
819
|
+
events,
|
|
820
|
+
...failure === void 0 ? {} : { failure },
|
|
821
|
+
...terminalEvent === void 0 ? {} : { terminalEvent },
|
|
822
|
+
nativeEvents
|
|
823
|
+
};
|
|
824
|
+
}
|
|
825
|
+
|
|
826
|
+
// src/adapters/codex/exec-adapter.ts
|
|
827
|
+
function withStructuredOutput(result, requested) {
|
|
828
|
+
if (!requested || result.failure || result.output !== void 0) return result;
|
|
829
|
+
try {
|
|
830
|
+
return { ...result, output: JSON.parse(result.text) };
|
|
831
|
+
} catch {
|
|
832
|
+
return { ...result, output: result.text };
|
|
833
|
+
}
|
|
834
|
+
}
|
|
835
|
+
function jsonType(value) {
|
|
836
|
+
if (value === null) return "null";
|
|
837
|
+
if (Array.isArray(value)) return "array";
|
|
838
|
+
if (typeof value === "object") return "object";
|
|
839
|
+
if (["string", "number", "boolean"].includes(typeof value)) return typeof value;
|
|
840
|
+
return void 0;
|
|
841
|
+
}
|
|
842
|
+
var SCHEMA_MAP_KEYS = /* @__PURE__ */ new Set(["properties", "patternProperties", "definitions", "$defs"]);
|
|
843
|
+
var LITERAL_KEYS = /* @__PURE__ */ new Set(["const", "enum", "default", "examples"]);
|
|
844
|
+
function normalizeCodexSchema(value) {
|
|
845
|
+
if (Array.isArray(value)) return value.map(normalizeCodexSchema);
|
|
846
|
+
if (typeof value !== "object" || value === null) return value;
|
|
847
|
+
const normalized = Object.fromEntries(
|
|
848
|
+
Object.entries(value).map(([key, child]) => {
|
|
849
|
+
if (LITERAL_KEYS.has(key)) return [key, child];
|
|
850
|
+
if (SCHEMA_MAP_KEYS.has(key) && typeof child === "object" && child !== null && !Array.isArray(child)) {
|
|
851
|
+
return [key, Object.fromEntries(
|
|
852
|
+
Object.entries(child).map(([name, schema]) => [name, normalizeCodexSchema(schema)])
|
|
853
|
+
)];
|
|
854
|
+
}
|
|
855
|
+
return [key, normalizeCodexSchema(child)];
|
|
856
|
+
})
|
|
857
|
+
);
|
|
858
|
+
if (normalized.type === void 0 && Object.hasOwn(normalized, "const")) {
|
|
859
|
+
const inferred = jsonType(normalized.const);
|
|
860
|
+
if (inferred) normalized.type = inferred;
|
|
861
|
+
}
|
|
862
|
+
return normalized;
|
|
863
|
+
}
|
|
864
|
+
function tomlString(value) {
|
|
865
|
+
for (let i = 0; i < value.length; i++) {
|
|
866
|
+
const unit = value.charCodeAt(i);
|
|
867
|
+
if (unit >= 55296 && unit <= 56319) {
|
|
868
|
+
const next = value.charCodeAt(++i);
|
|
869
|
+
if (!(next >= 56320 && next <= 57343)) throw new TypeError("Codex config requires valid Unicode.");
|
|
870
|
+
} else if (unit >= 56320 && unit <= 57343) throw new TypeError("Codex config requires valid Unicode.");
|
|
871
|
+
}
|
|
872
|
+
return JSON.stringify(value).replace(/\u007f/g, "\\u007f");
|
|
873
|
+
}
|
|
874
|
+
function tomlValue(value, ancestors = /* @__PURE__ */ new Set(), depth = 0) {
|
|
875
|
+
if (depth > 16) throw new TypeError("Codex config nesting exceeds 16 levels.");
|
|
876
|
+
if (typeof value === "string") return tomlString(value);
|
|
877
|
+
if (typeof value === "boolean") return String(value);
|
|
878
|
+
if (typeof value === "number" && Number.isFinite(value) && (!Number.isInteger(value) || Number.isSafeInteger(value))) return Object.is(value, -0) ? "-0.0" : String(value);
|
|
879
|
+
if (value === null || typeof value !== "object") throw new TypeError("Codex config contains an unsupported TOML value.");
|
|
880
|
+
if (ancestors.has(value)) throw new TypeError("Codex config contains a cycle.");
|
|
881
|
+
ancestors.add(value);
|
|
882
|
+
try {
|
|
883
|
+
if (Array.isArray(value)) return `[${Array.from(value, (item) => tomlValue(item, ancestors, depth + 1)).join(", ")}]`;
|
|
884
|
+
if (Object.getPrototypeOf(value) !== Object.prototype && Object.getPrototypeOf(value) !== null) {
|
|
885
|
+
throw new TypeError("Codex config requires plain objects.");
|
|
886
|
+
}
|
|
887
|
+
return `{ ${Object.entries(value).map(([key, child]) => `${tomlString(key)} = ${tomlValue(child, ancestors, depth + 1)}`).join(", ")} }`;
|
|
888
|
+
} finally {
|
|
889
|
+
ancestors.delete(value);
|
|
890
|
+
}
|
|
891
|
+
}
|
|
892
|
+
function codexConfigArgs(config) {
|
|
893
|
+
if (config === void 0) return [];
|
|
894
|
+
if (config === null || typeof config !== "object" || Array.isArray(config) || ![Object.prototype, null].includes(Object.getPrototypeOf(config))) {
|
|
895
|
+
throw new TypeError("Codex config must be a plain object.");
|
|
896
|
+
}
|
|
897
|
+
const args = [];
|
|
898
|
+
for (const [key, value] of Object.entries(config)) {
|
|
899
|
+
if (!/^[A-Za-z0-9_-]+(?:\.[A-Za-z0-9_-]+)*$/.test(key)) throw new TypeError("Codex config keys must be dotted TOML identifiers.");
|
|
900
|
+
const entry = `${key}=${tomlValue(value)}`;
|
|
901
|
+
if (Buffer.byteLength(entry) > 65536) throw new TypeError("A Codex config entry exceeds 64 KiB.");
|
|
902
|
+
args.push("--config", entry);
|
|
903
|
+
}
|
|
904
|
+
if (Buffer.byteLength(args.join("\n")) > 262144) throw new TypeError("Codex config exceeds 256 KiB.");
|
|
905
|
+
return args;
|
|
906
|
+
}
|
|
907
|
+
function tomlAsciiString(value) {
|
|
908
|
+
let out = '"';
|
|
909
|
+
for (let i = 0; i < value.length; i++) {
|
|
910
|
+
const unit = value.charCodeAt(i);
|
|
911
|
+
if (unit >= 55296 && unit <= 56319) {
|
|
912
|
+
const next = value.charCodeAt(i + 1);
|
|
913
|
+
if (!(next >= 56320 && next <= 57343)) throw new TypeError("Codex config requires valid Unicode.");
|
|
914
|
+
out += `\\U${value.codePointAt(i).toString(16).padStart(8, "0")}`;
|
|
915
|
+
i++;
|
|
916
|
+
} else if (unit >= 56320 && unit <= 57343) throw new TypeError("Codex config requires valid Unicode.");
|
|
917
|
+
else if (unit === 34) out += '\\"';
|
|
918
|
+
else if (unit === 92) out += "\\\\";
|
|
919
|
+
else if (unit === 8) out += "\\b";
|
|
920
|
+
else if (unit === 9) out += "\\t";
|
|
921
|
+
else if (unit === 10) out += "\\n";
|
|
922
|
+
else if (unit === 12) out += "\\f";
|
|
923
|
+
else if (unit === 13) out += "\\r";
|
|
924
|
+
else if (unit >= 32 && unit < 127) out += value[i];
|
|
925
|
+
else out += `\\u${unit.toString(16).padStart(4, "0")}`;
|
|
926
|
+
}
|
|
927
|
+
return out + '"';
|
|
928
|
+
}
|
|
929
|
+
function developerInstructionArgs(request) {
|
|
930
|
+
if (!request.instructions) return [];
|
|
931
|
+
if (request.mode === "resume" || request.mode === "fork") {
|
|
932
|
+
throw new UnsupportedCapabilityError(
|
|
933
|
+
{ provider: "codex", transport: "exec", retryable: false },
|
|
934
|
+
"Codex exec resume and fork replay the developer instructions the session started with; new instructions would not be sent"
|
|
935
|
+
);
|
|
936
|
+
}
|
|
937
|
+
const config = request.providerOptions?.config;
|
|
938
|
+
if (config !== null && typeof config === "object" && Object.hasOwn(config, "developer_instructions")) {
|
|
939
|
+
throw new TypeError("Pass Codex developer instructions either as instructions or as config.developer_instructions, not both.");
|
|
940
|
+
}
|
|
941
|
+
const entry = codexDeveloperInstructionsEntry(request.instructions);
|
|
942
|
+
if (Buffer.byteLength(entry) > 65536) throw new TypeError("A Codex config entry exceeds 64 KiB.");
|
|
943
|
+
return ["--config", entry];
|
|
944
|
+
}
|
|
945
|
+
function codexDeveloperInstructionsEntry(text) {
|
|
946
|
+
return `developer_instructions=${tomlAsciiString(text)}`;
|
|
947
|
+
}
|
|
948
|
+
var CLOSING_FLAGS = [["ignoreUserConfig", "--ignore-user-config"], ["ignoreRules", "--ignore-rules"], ["ephemeral", "--ephemeral"]];
|
|
949
|
+
function closingArgs(request) {
|
|
950
|
+
const args = [];
|
|
951
|
+
for (const [option, flag] of CLOSING_FLAGS) {
|
|
952
|
+
const value = request.providerOptions?.[option];
|
|
953
|
+
if (value !== void 0 && typeof value !== "boolean") throw new TypeError(`providerOptions.codex.${option} must be true or false`);
|
|
954
|
+
if (value && !request.contextArgs.includes(flag)) args.push(flag);
|
|
955
|
+
}
|
|
956
|
+
return args;
|
|
957
|
+
}
|
|
958
|
+
var CODEX_LOGIN_PROVIDER_ARGS = ["--config", 'model_provider="openai"'];
|
|
959
|
+
function buildCodexExecArgs(request, schemaPath) {
|
|
960
|
+
if ((request.mode === "resume" || request.mode === "fork") && !request.sessionId) {
|
|
961
|
+
throw new TypeError(`${request.mode} requires a sessionId`);
|
|
962
|
+
}
|
|
963
|
+
if ((request.mode === "resume" || request.mode === "fork") && !isSafeSessionId(request.sessionId)) {
|
|
964
|
+
throw new TypeError("sessionId is not a safe CLI argument");
|
|
965
|
+
}
|
|
966
|
+
const args = [
|
|
967
|
+
"--model",
|
|
968
|
+
request.modelId,
|
|
969
|
+
"--cd",
|
|
970
|
+
request.cwd,
|
|
971
|
+
...request.permissionArgs,
|
|
972
|
+
...codexConfigArgs(request.providerOptions?.config),
|
|
973
|
+
...developerInstructionArgs(request),
|
|
974
|
+
...request.requireSubscription ? CODEX_LOGIN_PROVIDER_ARGS : []
|
|
975
|
+
];
|
|
976
|
+
if (request.effort) {
|
|
977
|
+
if (!/^[a-z][a-z0-9-]*$/i.test(request.effort)) {
|
|
978
|
+
throw new UnsupportedCapabilityError(
|
|
979
|
+
{ provider: "codex", transport: "exec", retryable: false },
|
|
980
|
+
`Unsupported effort value: ${JSON.stringify(request.effort)}`
|
|
981
|
+
);
|
|
982
|
+
}
|
|
983
|
+
args.push("--config", `model_reasoning_effort="${request.effort}"`);
|
|
984
|
+
}
|
|
985
|
+
args.push("exec");
|
|
986
|
+
if (request.mode === "resume" || request.mode === "fork") args.push(request.mode);
|
|
987
|
+
args.push("--json", ...request.contextArgs, ...closingArgs(request));
|
|
988
|
+
if (schemaPath) args.push("--output-schema", schemaPath);
|
|
989
|
+
const skipGitRepoCheck = request.providerOptions?.skipGitRepoCheck === true;
|
|
990
|
+
if (skipGitRepoCheck) args.push("--skip-git-repo-check");
|
|
991
|
+
if (request.mode === "resume" || request.mode === "fork") args.push(request.sessionId);
|
|
992
|
+
args.push("-");
|
|
993
|
+
return args;
|
|
994
|
+
}
|
|
995
|
+
function parseCodexAuth(outcome, env) {
|
|
996
|
+
const text = `${outcome.stdout}
|
|
997
|
+
${outcome.stderr}`.trim().toLowerCase();
|
|
998
|
+
const authenticated = outcome.code === 0 && !/not logged in|no credentials|please.*login/.test(text);
|
|
999
|
+
const source = !authenticated ? "unknown" : text.includes("chatgpt") ? env.CODEX_API_KEY ? "api-key" : "subscription" : text.includes("api key") ? "api-key" : text.includes("ollama") || text.includes("lmstudio") ? "oss" : "unknown";
|
|
1000
|
+
return { authenticated, source };
|
|
1001
|
+
}
|
|
1002
|
+
var CodexExecAdapter = class {
|
|
1003
|
+
id = "codex";
|
|
1004
|
+
#runner;
|
|
1005
|
+
#probeRunner;
|
|
1006
|
+
#discovery;
|
|
1007
|
+
constructor(options = {}) {
|
|
1008
|
+
this.#runner = options.runner ?? runProcess;
|
|
1009
|
+
this.#probeRunner = options.probeRunner ?? this.#runner;
|
|
1010
|
+
this.#discovery = new ExecDiscovery("codex", this.#probeRunner, options.target);
|
|
1011
|
+
}
|
|
1012
|
+
#target(env) {
|
|
1013
|
+
return this.#discovery.target(env);
|
|
1014
|
+
}
|
|
1015
|
+
async detect(env, context) {
|
|
1016
|
+
return this.#discovery.detect(env, context);
|
|
1017
|
+
}
|
|
1018
|
+
async auth(env, context) {
|
|
1019
|
+
const target = this.#target(env);
|
|
1020
|
+
if (!target) return { authenticated: false, source: "unknown" };
|
|
1021
|
+
const outcome = await this.#probeRunner({
|
|
1022
|
+
command: target.command,
|
|
1023
|
+
args: [...target.argsPrefix, "login", "status"],
|
|
1024
|
+
cwd: process.cwd(),
|
|
1025
|
+
env,
|
|
1026
|
+
stdin: "",
|
|
1027
|
+
timeoutMs: Math.min(15e3, context?.remainingMs() ?? 15e3),
|
|
1028
|
+
...context ? { signal: context.signal } : {},
|
|
1029
|
+
maxOutputBytes: 64 * 1024
|
|
1030
|
+
});
|
|
1031
|
+
return parseCodexAuth(outcome, env);
|
|
1032
|
+
}
|
|
1033
|
+
async models() {
|
|
1034
|
+
return compatibilityModels("codex");
|
|
1035
|
+
}
|
|
1036
|
+
async compatibility(env, version, context) {
|
|
1037
|
+
const target = this.#target(env);
|
|
1038
|
+
if (!target) return void 0;
|
|
1039
|
+
const probe = async (args) => this.#probeRunner({
|
|
1040
|
+
command: target.command,
|
|
1041
|
+
args: [...target.argsPrefix, ...args],
|
|
1042
|
+
cwd: process.cwd(),
|
|
1043
|
+
env,
|
|
1044
|
+
stdin: "",
|
|
1045
|
+
timeoutMs: Math.min(15e3, context?.remainingMs() ?? 15e3),
|
|
1046
|
+
...context ? { signal: context.signal } : {},
|
|
1047
|
+
maxOutputBytes: 256 * 1024
|
|
1048
|
+
});
|
|
1049
|
+
const [main, resume, fork] = await Promise.all([
|
|
1050
|
+
probe(["exec", "--help"]),
|
|
1051
|
+
probe(["exec", "resume", "--help"]),
|
|
1052
|
+
probe(["exec", "fork", "--help"])
|
|
1053
|
+
]);
|
|
1054
|
+
const assessment = assessCliCompatibility("codex", version, {
|
|
1055
|
+
main: `${main.stdout}
|
|
1056
|
+
${main.stderr}`,
|
|
1057
|
+
resume: `${resume.stdout}
|
|
1058
|
+
${resume.stderr}`,
|
|
1059
|
+
fork: `${fork.stdout}
|
|
1060
|
+
${fork.stderr}`
|
|
1061
|
+
});
|
|
1062
|
+
return { ...assessment, features: { ...assessment.features, refusalDetection: "unsupported" } };
|
|
1063
|
+
}
|
|
1064
|
+
async execute(request) {
|
|
1065
|
+
const target = this.#target(request.env);
|
|
1066
|
+
if (!target) {
|
|
1067
|
+
return {
|
|
1068
|
+
completed: false,
|
|
1069
|
+
failed: true,
|
|
1070
|
+
refused: false,
|
|
1071
|
+
text: "",
|
|
1072
|
+
events: [],
|
|
1073
|
+
failure: { kind: "provider-unavailable", message: "Codex CLI not found" },
|
|
1074
|
+
nativeEvents: []
|
|
1075
|
+
};
|
|
1076
|
+
}
|
|
1077
|
+
let temporaryDirectory;
|
|
1078
|
+
try {
|
|
1079
|
+
let schemaPath;
|
|
1080
|
+
if (request.outputSchema) {
|
|
1081
|
+
temporaryDirectory = await mkdtemp(join(tmpdir(), "hiveagents-runtime-"));
|
|
1082
|
+
schemaPath = join(temporaryDirectory, "schema.json");
|
|
1083
|
+
await writeFile(schemaPath, JSON.stringify(normalizeCodexSchema(request.outputSchema)), {
|
|
1084
|
+
encoding: "utf8",
|
|
1085
|
+
mode: 384
|
|
1086
|
+
});
|
|
1087
|
+
}
|
|
1088
|
+
const outcome = await guardJsonlFrames((onStdout) => this.#runner({
|
|
1089
|
+
command: target.command,
|
|
1090
|
+
args: [...target.argsPrefix, ...buildCodexExecArgs(request, schemaPath)],
|
|
1091
|
+
cwd: request.cwd,
|
|
1092
|
+
env: request.env,
|
|
1093
|
+
stdin: request.prompt,
|
|
1094
|
+
timeoutMs: request.timeoutMs,
|
|
1095
|
+
maxOutputBytes: request.maxOutputBytes,
|
|
1096
|
+
onStdout,
|
|
1097
|
+
...request.signal === void 0 ? {} : { signal: request.signal }
|
|
1098
|
+
}));
|
|
1099
|
+
const result = withStructuredOutput(parseCodexJsonl(outcome.stdout), request.outputSchema !== void 0);
|
|
1100
|
+
if (outcome.code !== 0 && result.failure?.kind === "protocol") {
|
|
1101
|
+
return {
|
|
1102
|
+
...result,
|
|
1103
|
+
failure: classifyCodexFailure([
|
|
1104
|
+
outcome.stderr.trim() || `Codex exited with code ${outcome.code}`
|
|
1105
|
+
])
|
|
1106
|
+
};
|
|
1107
|
+
}
|
|
1108
|
+
return result;
|
|
1109
|
+
} finally {
|
|
1110
|
+
if (temporaryDirectory) {
|
|
1111
|
+
await rm(temporaryDirectory, { recursive: true, force: true }).catch(() => void 0);
|
|
1112
|
+
}
|
|
1113
|
+
}
|
|
1114
|
+
}
|
|
1115
|
+
async *stream(request) {
|
|
1116
|
+
const target = this.#target(request.env);
|
|
1117
|
+
if (!target) {
|
|
1118
|
+
yield {
|
|
1119
|
+
kind: "result",
|
|
1120
|
+
result: {
|
|
1121
|
+
completed: false,
|
|
1122
|
+
failed: true,
|
|
1123
|
+
refused: false,
|
|
1124
|
+
text: "",
|
|
1125
|
+
events: [],
|
|
1126
|
+
failure: { kind: "provider-unavailable", message: "Codex CLI not found" },
|
|
1127
|
+
nativeEvents: []
|
|
1128
|
+
}
|
|
1129
|
+
};
|
|
1130
|
+
return;
|
|
1131
|
+
}
|
|
1132
|
+
let temporaryDirectory;
|
|
1133
|
+
let schemaPath;
|
|
1134
|
+
let args;
|
|
1135
|
+
try {
|
|
1136
|
+
if (request.outputSchema) {
|
|
1137
|
+
temporaryDirectory = await mkdtemp(join(tmpdir(), "hiveagents-runtime-"));
|
|
1138
|
+
schemaPath = join(temporaryDirectory, "schema.json");
|
|
1139
|
+
await writeFile(schemaPath, JSON.stringify(normalizeCodexSchema(request.outputSchema)), {
|
|
1140
|
+
encoding: "utf8",
|
|
1141
|
+
mode: 384
|
|
1142
|
+
});
|
|
1143
|
+
}
|
|
1144
|
+
args = buildCodexExecArgs(request, schemaPath);
|
|
1145
|
+
} catch (error) {
|
|
1146
|
+
if (temporaryDirectory) {
|
|
1147
|
+
await rm(temporaryDirectory, { recursive: true, force: true }).catch(() => void 0);
|
|
1148
|
+
}
|
|
1149
|
+
throw error;
|
|
1150
|
+
}
|
|
1151
|
+
const parseState = { itemIndex: 0 };
|
|
1152
|
+
const pump = new ExecStreamPump(request.signal, (line) => parseCodexJsonl(line, parseState), parseCodexJsonl);
|
|
1153
|
+
const execution = this.#runner({
|
|
1154
|
+
command: target.command,
|
|
1155
|
+
args: [...target.argsPrefix, ...args],
|
|
1156
|
+
cwd: request.cwd,
|
|
1157
|
+
env: request.env,
|
|
1158
|
+
stdin: request.prompt,
|
|
1159
|
+
timeoutMs: request.timeoutMs,
|
|
1160
|
+
maxOutputBytes: request.maxOutputBytes,
|
|
1161
|
+
captureStdout: false,
|
|
1162
|
+
// The pump retains the incremental result; legacy runners still receive onStdout.
|
|
1163
|
+
signal: pump.signal,
|
|
1164
|
+
onStdout: pump.onStdout,
|
|
1165
|
+
onStdoutAsync: pump.onStdoutAsync,
|
|
1166
|
+
onFailure: (error) => pump.fail(error)
|
|
1167
|
+
}).then((outcome) => pump.finish((parsed) => {
|
|
1168
|
+
let result = withStructuredOutput(parsed, request.outputSchema !== void 0);
|
|
1169
|
+
if (outcome.code !== 0 && result.failure?.kind === "protocol") {
|
|
1170
|
+
result = {
|
|
1171
|
+
...result,
|
|
1172
|
+
failure: classifyCodexFailure([
|
|
1173
|
+
outcome.stderr.trim() || `Codex exited with code ${outcome.code}`
|
|
1174
|
+
])
|
|
1175
|
+
};
|
|
1176
|
+
}
|
|
1177
|
+
return result;
|
|
1178
|
+
})).catch((error) => pump.fail(error)).finally(async () => {
|
|
1179
|
+
if (temporaryDirectory) {
|
|
1180
|
+
await rm(temporaryDirectory, { recursive: true, force: true }).catch(() => void 0);
|
|
1181
|
+
}
|
|
1182
|
+
});
|
|
1183
|
+
try {
|
|
1184
|
+
yield* pump.items();
|
|
1185
|
+
} catch (error) {
|
|
1186
|
+
pump.cancel();
|
|
1187
|
+
if (request.awaitSettlement) {
|
|
1188
|
+
await execution;
|
|
1189
|
+
throw pump.afterSettlement(error);
|
|
1190
|
+
}
|
|
1191
|
+
throw error;
|
|
1192
|
+
} finally {
|
|
1193
|
+
pump.cancel();
|
|
1194
|
+
if (request.awaitSettlement) await execution;
|
|
1195
|
+
}
|
|
1196
|
+
}
|
|
1197
|
+
};
|
|
1198
|
+
|
|
1199
|
+
export {
|
|
1200
|
+
isSafeSessionId,
|
|
1201
|
+
parseObject,
|
|
1202
|
+
stringValue,
|
|
1203
|
+
numberValue,
|
|
1204
|
+
resolveModel,
|
|
1205
|
+
compatibilityModels,
|
|
1206
|
+
classifyClaudeFailure,
|
|
1207
|
+
assessCliCompatibility,
|
|
1208
|
+
findCompatibilityEntry,
|
|
1209
|
+
validateCompatibilityManifest,
|
|
1210
|
+
COMPATIBILITY_MANIFEST,
|
|
1211
|
+
BoundedQueue,
|
|
1212
|
+
ExecStreamPump,
|
|
1213
|
+
codexDeveloperInstructionsEntry,
|
|
1214
|
+
CODEX_LOGIN_PROVIDER_ARGS,
|
|
1215
|
+
CodexExecAdapter
|
|
1216
|
+
};
|
|
1217
|
+
//# sourceMappingURL=chunk-2RUEC63U.js.map
|