hiveagents-runtime 0.0.0-stage → 0.1.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +89 -2
- package/dist/adapter-kit.d.ts +37 -0
- package/dist/adapter-kit.js +34 -0
- package/dist/adapter-kit.js.map +1 -0
- package/dist/agent-Bj5YPrO7.d.ts +169 -0
- package/dist/agent-D6OXR7UF.js +24 -0
- package/dist/agent-D6OXR7UF.js.map +1 -0
- package/dist/agent-readiness-KSGNKTGK.js +19 -0
- package/dist/agent-readiness-KSGNKTGK.js.map +1 -0
- package/dist/capture-runtime-GP6NZ2ee.d.ts +54 -0
- package/dist/chunk-2RK74GCA.js +2397 -0
- package/dist/chunk-2RK74GCA.js.map +1 -0
- package/dist/chunk-3TIYA3K5.js +55 -0
- package/dist/chunk-3TIYA3K5.js.map +1 -0
- package/dist/chunk-6FIXXWNM.js +1 -0
- package/dist/chunk-6FIXXWNM.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-CPN4DOXH.js +115 -0
- package/dist/chunk-CPN4DOXH.js.map +1 -0
- package/dist/chunk-DAXPAV2L.js +810 -0
- package/dist/chunk-DAXPAV2L.js.map +1 -0
- package/dist/chunk-DQEMIGKC.js +291 -0
- package/dist/chunk-DQEMIGKC.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-G6JV7WV6.js +521 -0
- package/dist/chunk-G6JV7WV6.js.map +1 -0
- package/dist/chunk-GFVYNPLS.js +118 -0
- package/dist/chunk-GFVYNPLS.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-RH5A5U7G.js +202 -0
- package/dist/chunk-RH5A5U7G.js.map +1 -0
- package/dist/chunk-RX3XZENU.js +385 -0
- package/dist/chunk-RX3XZENU.js.map +1 -0
- package/dist/chunk-RXU2Q2HF.js +49 -0
- package/dist/chunk-RXU2Q2HF.js.map +1 -0
- package/dist/chunk-TG7NTMTR.js +208 -0
- package/dist/chunk-TG7NTMTR.js.map +1 -0
- package/dist/chunk-TWGEYWMO.js +1217 -0
- package/dist/chunk-TWGEYWMO.js.map +1 -0
- package/dist/chunk-UZPDDQVJ.js +2910 -0
- package/dist/chunk-UZPDDQVJ.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/chunk-WVT5SEKC.js +581 -0
- package/dist/chunk-WVT5SEKC.js.map +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +26 -0
- package/dist/cli.js.map +1 -0
- package/dist/errors-BNHvvjn9.d.ts +98 -0
- package/dist/execution-halt-B8G0fOKS.d.ts +12 -0
- package/dist/execution-types-ClYYqPQP.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 +858 -0
- package/dist/hosted-runtime.js.map +1 -0
- package/dist/index-B86C6VAD.d.ts +41 -0
- package/dist/index.d.ts +344 -0
- package/dist/index.js +8825 -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 +6409 -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-DX5Mf0uq.d.ts +151 -0
- package/dist/routing/index.d.ts +29 -0
- package/dist/routing/index.js +386 -0
- package/dist/routing/index.js.map +1 -0
- package/dist/routing/learning/index.d.ts +433 -0
- package/dist/routing/learning/index.js +2502 -0
- package/dist/routing/learning/index.js.map +1 -0
- package/dist/runtime-BSjrnxeF.d.ts +283 -0
- package/dist/runtime-OISPXS4I.js +19 -0
- package/dist/runtime-OISPXS4I.js.map +1 -0
- package/dist/store-types-2YdceOMy.d.ts +78 -0
- package/dist/types-BB7KqceP.d.ts +52 -0
- package/dist/types-CIqkKXix.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.3.md +13 -0
- package/package.json +114 -4
|
@@ -0,0 +1,581 @@
|
|
|
1
|
+
import {
|
|
2
|
+
buildEnvironment
|
|
3
|
+
} from "./chunk-3TIYA3K5.js";
|
|
4
|
+
import {
|
|
5
|
+
OperationScope,
|
|
6
|
+
PinnedExecAdapter,
|
|
7
|
+
assertRespondAuth,
|
|
8
|
+
assertRespondCompatibility,
|
|
9
|
+
authenticationState,
|
|
10
|
+
controlUnavailableMessage,
|
|
11
|
+
createExecutablePin,
|
|
12
|
+
experimentalGates,
|
|
13
|
+
hasConfirmedSubscription,
|
|
14
|
+
isAuthenticationConfirmed,
|
|
15
|
+
raceExecWork,
|
|
16
|
+
resultUsage,
|
|
17
|
+
settleExecScope,
|
|
18
|
+
streamStepUsage,
|
|
19
|
+
validateSettlementOption
|
|
20
|
+
} from "./chunk-G6JV7WV6.js";
|
|
21
|
+
import {
|
|
22
|
+
freeze
|
|
23
|
+
} from "./chunk-EEUYQFCP.js";
|
|
24
|
+
import {
|
|
25
|
+
validateTimeoutMs
|
|
26
|
+
} from "./chunk-7LDQKJKI.js";
|
|
27
|
+
import {
|
|
28
|
+
CliNotInstalledError,
|
|
29
|
+
NotAuthenticatedError,
|
|
30
|
+
RequiredTransportUnavailableError,
|
|
31
|
+
UnexpectedAuthSourceError,
|
|
32
|
+
UnsupportedCapabilityError,
|
|
33
|
+
UnsupportedCliVersionError
|
|
34
|
+
} from "./chunk-TG7NTMTR.js";
|
|
35
|
+
|
|
36
|
+
// src/public/agent-readiness.ts
|
|
37
|
+
import { types } from "node:util";
|
|
38
|
+
import { realpath } from "node:fs/promises";
|
|
39
|
+
|
|
40
|
+
// src/core/capabilities.ts
|
|
41
|
+
var CONTROL_ONLY = [
|
|
42
|
+
"interactiveApprovals",
|
|
43
|
+
"userInputDuringTurn",
|
|
44
|
+
"steering",
|
|
45
|
+
"inProcessTools",
|
|
46
|
+
"dynamicPermissions",
|
|
47
|
+
"sessionInspection",
|
|
48
|
+
"checkpointOrRollback",
|
|
49
|
+
// Ningún exec CLI confirma un fork sin prompt; exigirlo debe rutear a control
|
|
50
|
+
// en vez de elegir exec y fallar cerrado después.
|
|
51
|
+
"forkWithoutPrompt"
|
|
52
|
+
];
|
|
53
|
+
function controlUnavailable(input, detail) {
|
|
54
|
+
if (input.controlRegistered ?? false) {
|
|
55
|
+
throw new UnsupportedCapabilityError(
|
|
56
|
+
{ provider: input.provider, transport: "control", retryable: false },
|
|
57
|
+
`${detail}; the ${input.provider} control adapter is registered but requires the explicit experimentalControl opt-in`
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
throw new RequiredTransportUnavailableError(
|
|
61
|
+
{ provider: input.provider, transport: "control", retryable: false },
|
|
62
|
+
`${detail}; ${controlUnavailableMessage(input.provider)}`
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
function requiredControlCapabilities(input) {
|
|
66
|
+
const required = CONTROL_ONLY.filter((name) => {
|
|
67
|
+
const value = input.requirements[name];
|
|
68
|
+
return value === true || value === "required";
|
|
69
|
+
});
|
|
70
|
+
const processPersistence = input.requirements.processPersistence;
|
|
71
|
+
if (input.persistence === "process" || processPersistence === true || processPersistence === "required") {
|
|
72
|
+
required.push("processPersistence");
|
|
73
|
+
}
|
|
74
|
+
const deltas = input.requirements.messageDeltas ?? input.requirements.tokenDeltas;
|
|
75
|
+
if ((input.execCapabilities?.messageDeltas === "unsupported" || input.execCapabilities?.tokenDeltas === "unsupported" || input.provider === "codex") && (deltas === true || deltas === "required")) {
|
|
76
|
+
required.push("messageDeltas");
|
|
77
|
+
}
|
|
78
|
+
return [...new Set(required)];
|
|
79
|
+
}
|
|
80
|
+
function selectTransport(input) {
|
|
81
|
+
const requiresControl = requiredControlCapabilities(input);
|
|
82
|
+
if (input.preference === "exec" && requiresControl.length > 0) {
|
|
83
|
+
throw new UnsupportedCapabilityError(
|
|
84
|
+
{ provider: input.provider, transport: "exec", retryable: false },
|
|
85
|
+
`Exec transport cannot provide: ${requiresControl.join(", ")}`
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
if (input.preference === "control") {
|
|
89
|
+
if (!input.controlAvailable) {
|
|
90
|
+
controlUnavailable(input, "Control transport was explicitly requested");
|
|
91
|
+
}
|
|
92
|
+
return "control";
|
|
93
|
+
}
|
|
94
|
+
if (requiresControl.length > 0) {
|
|
95
|
+
if (!input.controlAvailable) {
|
|
96
|
+
controlUnavailable(input, `Capabilities require control transport: ${requiresControl.join(", ")}`);
|
|
97
|
+
}
|
|
98
|
+
return "control";
|
|
99
|
+
}
|
|
100
|
+
return "exec";
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// src/core/subscription-exec.ts
|
|
104
|
+
var SubscriptionExecAdapter = class {
|
|
105
|
+
constructor(inner) {
|
|
106
|
+
this.inner = inner;
|
|
107
|
+
this.id = inner.id;
|
|
108
|
+
const stream = inner.stream?.bind(inner);
|
|
109
|
+
if (stream) {
|
|
110
|
+
const check = this.#check.bind(this);
|
|
111
|
+
this.stream = async function* (request) {
|
|
112
|
+
const scope = new OperationScope({ timeoutMs: request.timeoutMs, ...request.signal ? { signal: request.signal } : {}, context: { provider: inner.id, transport: "exec", retryable: true } });
|
|
113
|
+
let iterator, exhausted = false;
|
|
114
|
+
try {
|
|
115
|
+
await scope.race(() => check(request, scope));
|
|
116
|
+
iterator = stream({ ...request, requireSubscription: true, timeoutMs: scope.remainingMs(), signal: scope.signal })[Symbol.asyncIterator]();
|
|
117
|
+
for (; ; ) {
|
|
118
|
+
const step = await raceExecWork(scope, () => iterator.next(), request.awaitSettlement, streamStepUsage);
|
|
119
|
+
if (step.done) {
|
|
120
|
+
exhausted = true;
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
yield step.value;
|
|
124
|
+
}
|
|
125
|
+
} finally {
|
|
126
|
+
await settleExecScope(scope, request.awaitSettlement, iterator, exhausted);
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
inner;
|
|
132
|
+
id;
|
|
133
|
+
stream;
|
|
134
|
+
detect(env, context) {
|
|
135
|
+
return this.inner.detect(env, context);
|
|
136
|
+
}
|
|
137
|
+
auth(env, context, turn) {
|
|
138
|
+
return this.inner.auth(env, context, turn);
|
|
139
|
+
}
|
|
140
|
+
models() {
|
|
141
|
+
return this.inner.models();
|
|
142
|
+
}
|
|
143
|
+
async compatibility(env, version, context) {
|
|
144
|
+
return this.inner.compatibility?.(env, version, context);
|
|
145
|
+
}
|
|
146
|
+
async execute(request) {
|
|
147
|
+
const scope = new OperationScope({ timeoutMs: request.timeoutMs, ...request.signal ? { signal: request.signal } : {}, context: { provider: this.id, transport: "exec", retryable: true } });
|
|
148
|
+
try {
|
|
149
|
+
await scope.race(() => this.#check(request, scope));
|
|
150
|
+
return await raceExecWork(scope, () => this.inner.execute({ ...request, requireSubscription: true, timeoutMs: scope.remainingMs(), signal: scope.signal }), request.awaitSettlement, resultUsage);
|
|
151
|
+
} finally {
|
|
152
|
+
if (request.awaitSettlement) await scope.drain();
|
|
153
|
+
scope.dispose();
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
async #check(request, scope) {
|
|
157
|
+
const context = { provider: this.id, transport: "exec", retryable: false };
|
|
158
|
+
const auth = await this.inner.auth(request.env, scope, {
|
|
159
|
+
cwd: request.cwd,
|
|
160
|
+
contextArgs: request.contextArgs,
|
|
161
|
+
...request.providerOptions === void 0 ? {} : { providerOptions: request.providerOptions }
|
|
162
|
+
});
|
|
163
|
+
if (!isAuthenticationConfirmed(auth)) throw new NotAuthenticatedError(this.id, context);
|
|
164
|
+
if (auth.source !== "subscription") {
|
|
165
|
+
throw new UnexpectedAuthSourceError(this.id, {
|
|
166
|
+
...context,
|
|
167
|
+
sanitizedDiagnostics: { detectedSource: auth.source }
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
// src/session/negotiation.ts
|
|
174
|
+
var PERMISSION_MODE_CEILINGS = {
|
|
175
|
+
analyze: "plan",
|
|
176
|
+
respond: "default",
|
|
177
|
+
edit: "acceptEdits",
|
|
178
|
+
unrestricted: "bypassPermissions"
|
|
179
|
+
};
|
|
180
|
+
function controlFeatures(registration) {
|
|
181
|
+
const features = Object.fromEntries(Object.entries(registration.capabilityVerdicts).map(([name, support]) => [
|
|
182
|
+
name,
|
|
183
|
+
support === "full" ? "supported" : support === "none" ? "unsupported" : support === "unknown" ? "unverified" : "partial"
|
|
184
|
+
]));
|
|
185
|
+
features.tokenDeltas = features.messageDeltas ?? "unverified";
|
|
186
|
+
return features;
|
|
187
|
+
}
|
|
188
|
+
function statusFromLegacy(support, fingerprint) {
|
|
189
|
+
const normalized = support === "supported" ? "full" : support === "unsupported" ? "none" : support === "unverified" ? "unknown" : "partial";
|
|
190
|
+
return {
|
|
191
|
+
support: normalized,
|
|
192
|
+
evidence: [{ source: "compatibility-manifest", fingerprint }]
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
function negotiateCapabilities(input) {
|
|
196
|
+
const { registration } = input;
|
|
197
|
+
const negotiated = input.transport === "control" && registration ? Object.fromEntries(
|
|
198
|
+
Object.entries(registration.capabilityVerdicts).map(([name, support]) => [
|
|
199
|
+
name,
|
|
200
|
+
{
|
|
201
|
+
support,
|
|
202
|
+
evidence: [{ source: registration.evidenceSource, fingerprint: input.fingerprint }]
|
|
203
|
+
}
|
|
204
|
+
])
|
|
205
|
+
) : Object.fromEntries(
|
|
206
|
+
Object.entries(input.features).map(([name, support]) => [
|
|
207
|
+
name,
|
|
208
|
+
statusFromLegacy(support, input.fingerprint)
|
|
209
|
+
])
|
|
210
|
+
);
|
|
211
|
+
if (negotiated.tokenDeltas && !negotiated.messageDeltas) {
|
|
212
|
+
negotiated.messageDeltas = negotiated.tokenDeltas;
|
|
213
|
+
}
|
|
214
|
+
return negotiated;
|
|
215
|
+
}
|
|
216
|
+
function buildSafetyEnvelope(input) {
|
|
217
|
+
const { permissions } = input;
|
|
218
|
+
return {
|
|
219
|
+
authorityEpoch: crypto.randomUUID(),
|
|
220
|
+
filesystem: {
|
|
221
|
+
readonlyRoots: [input.cwd, ...permissions.additionalDirectories ?? []],
|
|
222
|
+
writableRoots: permissions.mode === "analyze" || permissions.mode === "respond" ? [] : [input.cwd, ...permissions.additionalDirectories ?? []]
|
|
223
|
+
},
|
|
224
|
+
network: permissions.network === "allow" ? [{ protocol: "https", host: "*" }] : [],
|
|
225
|
+
tools: [...input.tools ?? []],
|
|
226
|
+
executables: input.executableRealpath ? [input.executableRealpath] : [],
|
|
227
|
+
mcpServers: [...input.mcpServers ?? []],
|
|
228
|
+
environmentVariables: input.environmentVariables,
|
|
229
|
+
settingsPersistence: "none",
|
|
230
|
+
enforcedBy: input.enforcedBy,
|
|
231
|
+
permissionModeCeiling: PERMISSION_MODE_CEILINGS[permissions.mode],
|
|
232
|
+
modelAllowlist: [input.modelId]
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// src/session/exec-capabilities.ts
|
|
237
|
+
function buildExecFeatures(reported = {}, provider, streaming) {
|
|
238
|
+
const deltas = streaming ? reported.messageDeltas ?? reported.tokenDeltas ?? (provider === "codex" ? "unsupported" : "unverified") : "unsupported";
|
|
239
|
+
return {
|
|
240
|
+
turns: "unverified",
|
|
241
|
+
resume: "unverified",
|
|
242
|
+
forkWithPrompt: "unverified",
|
|
243
|
+
structuredOutput: "unverified",
|
|
244
|
+
...reported,
|
|
245
|
+
tokenDeltas: deltas,
|
|
246
|
+
messageDeltas: deltas,
|
|
247
|
+
forkWithoutPrompt: "unsupported",
|
|
248
|
+
images: "unsupported",
|
|
249
|
+
files: "unsupported",
|
|
250
|
+
interactiveApprovals: "unsupported",
|
|
251
|
+
userInputDuringTurn: "unsupported",
|
|
252
|
+
steering: "unsupported",
|
|
253
|
+
inProcessTools: "unsupported",
|
|
254
|
+
dynamicPermissions: "unsupported",
|
|
255
|
+
sessionInspection: "unsupported",
|
|
256
|
+
checkpointOrRollback: "unsupported",
|
|
257
|
+
processPersistence: "unsupported"
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
// src/session/mcp-envelope.ts
|
|
262
|
+
import { resolve } from "node:path";
|
|
263
|
+
var INLINE_MCP_CONFIG_MARKER = "config:inline";
|
|
264
|
+
var CLAUDE_SETTINGS_MCP_MARKER = "config:claude-settings";
|
|
265
|
+
var CODEX_USER_CONFIG_MARKER = "config:codex-user";
|
|
266
|
+
var CLAUDE_APPLICATION_TOOL_SERVER = "oar_application";
|
|
267
|
+
function envelopeMcpServers(input) {
|
|
268
|
+
const options = input.providerOptions;
|
|
269
|
+
if (input.provider === "claude" && input.transport === "exec") {
|
|
270
|
+
const servers = mcpServersFromClaudeConfigs(options?.mcpConfigs, input.cwd);
|
|
271
|
+
const strict = options?.strictMcpConfig === true || input.permissionArgs.includes("--strict-mcp-config");
|
|
272
|
+
if (!strict && !input.contextArgs.includes("--safe-mode")) servers.push(CLAUDE_SETTINGS_MCP_MARKER);
|
|
273
|
+
return servers;
|
|
274
|
+
}
|
|
275
|
+
if (input.provider === "claude") return input.applicationTools > 0 ? [CLAUDE_APPLICATION_TOOL_SERVER] : [];
|
|
276
|
+
if (input.provider === "codex") {
|
|
277
|
+
const servers = input.transport === "exec" ? mcpServersFromCodexConfig(options?.config) : [];
|
|
278
|
+
const ignored = input.contextArgs.includes("--ignore-user-config") || input.transport === "exec" && options?.ignoreUserConfig === true;
|
|
279
|
+
if (!ignored) servers.push(CODEX_USER_CONFIG_MARKER);
|
|
280
|
+
return servers;
|
|
281
|
+
}
|
|
282
|
+
return [];
|
|
283
|
+
}
|
|
284
|
+
function mcpServersFromClaudeConfigs(configs, cwd) {
|
|
285
|
+
if (!Array.isArray(configs)) return [];
|
|
286
|
+
const servers = /* @__PURE__ */ new Set();
|
|
287
|
+
for (const config of configs) {
|
|
288
|
+
if (typeof config !== "string" || config.trim() === "") continue;
|
|
289
|
+
if (!config.trimStart().startsWith("{")) {
|
|
290
|
+
servers.add(`config:${resolve(cwd, config)}`);
|
|
291
|
+
continue;
|
|
292
|
+
}
|
|
293
|
+
const names = inlineServerNames(config);
|
|
294
|
+
if (names === void 0) servers.add(INLINE_MCP_CONFIG_MARKER);
|
|
295
|
+
else for (const name of names) servers.add(name);
|
|
296
|
+
}
|
|
297
|
+
return [...servers];
|
|
298
|
+
}
|
|
299
|
+
function mcpServersFromCodexConfig(config) {
|
|
300
|
+
if (!isTable(config)) return [];
|
|
301
|
+
const servers = /* @__PURE__ */ new Set();
|
|
302
|
+
for (const [key, value] of Object.entries(config)) {
|
|
303
|
+
if (key === "mcp_servers") {
|
|
304
|
+
if (isTable(value)) for (const name of Object.keys(value)) servers.add(name);
|
|
305
|
+
else servers.add(INLINE_MCP_CONFIG_MARKER);
|
|
306
|
+
} else if (key.startsWith("mcp_servers.")) {
|
|
307
|
+
servers.add(key.split(".")[1]);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
return [...servers];
|
|
311
|
+
}
|
|
312
|
+
function isTable(value) {
|
|
313
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
314
|
+
}
|
|
315
|
+
function inlineServerNames(config) {
|
|
316
|
+
try {
|
|
317
|
+
const parsed = JSON.parse(config);
|
|
318
|
+
const map = isTable(parsed) ? parsed.mcpServers : void 0;
|
|
319
|
+
return isTable(map) ? Object.keys(map) : void 0;
|
|
320
|
+
} catch {
|
|
321
|
+
return void 0;
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
// src/public/agent-readiness.ts
|
|
326
|
+
async function prepareAgent(options, runtime, model, persistence = "provider", scope) {
|
|
327
|
+
const probe = async (work) => scope ? scope.race(work) : work();
|
|
328
|
+
let sessionAdapter;
|
|
329
|
+
const transport = agentTransport(options, runtime, model.provider, persistence);
|
|
330
|
+
runtime.registration(model.provider).validateOptions(options, transport);
|
|
331
|
+
const cwd = await probe(() => realpath(options.cwd ?? process.cwd()));
|
|
332
|
+
const requestedPermissions = options.permissions ?? { mode: "analyze" };
|
|
333
|
+
const directories = requestedPermissions.additionalDirectories;
|
|
334
|
+
const additionalDirectories = directories ? await Promise.all(directories.map((directory) => probe(() => realpath(directory)))) : void 0;
|
|
335
|
+
const permissionsIntent = {
|
|
336
|
+
...requestedPermissions,
|
|
337
|
+
...additionalDirectories === void 0 ? {} : { additionalDirectories }
|
|
338
|
+
};
|
|
339
|
+
const adapter = runtime.adapter(model.provider);
|
|
340
|
+
const env = agentEnvironment(options);
|
|
341
|
+
const installation = await probe(() => adapter.detect(env, scope));
|
|
342
|
+
if (!installation.installed) {
|
|
343
|
+
throw new CliNotInstalledError(model.provider, { retryable: false });
|
|
344
|
+
}
|
|
345
|
+
const providerOptions = model.provider === "claude" ? options.providerOptions?.claude : model.provider === "codex" ? options.providerOptions?.codex : options.providerOptions?.external?.[model.provider];
|
|
346
|
+
const authTurn = options.requireAuth === "subscription" ? {
|
|
347
|
+
cwd,
|
|
348
|
+
contextArgs: runtime.registration(model.provider).translateContext(options.context).args,
|
|
349
|
+
...providerOptions === void 0 ? {} : { providerOptions }
|
|
350
|
+
} : void 0;
|
|
351
|
+
const auth = await probe(() => adapter.auth(env, scope, authTurn));
|
|
352
|
+
if (!isAuthenticationConfirmed(auth) && !(authenticationState(auth) === "unknown" && options.requireAuth !== "subscription")) {
|
|
353
|
+
throw new NotAuthenticatedError(model.provider, {
|
|
354
|
+
retryable: false,
|
|
355
|
+
...installation.version === void 0 ? {} : { cliVersion: installation.version }
|
|
356
|
+
});
|
|
357
|
+
}
|
|
358
|
+
const compatibility = installation.version ? await probe(() => adapter.compatibility?.(env, installation.version, scope)) : void 0;
|
|
359
|
+
if (transport === "exec" && installation.version && compatibility?.features.turns === "unsupported") {
|
|
360
|
+
throw new UnsupportedCliVersionError(model.provider, installation.version, {
|
|
361
|
+
provider: model.provider,
|
|
362
|
+
transport: "exec",
|
|
363
|
+
cliVersion: installation.version,
|
|
364
|
+
retryable: false,
|
|
365
|
+
sanitizedDiagnostics: { missingFlags: compatibility.missingFlags }
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
if (options.requireAuth === "subscription" && !hasConfirmedSubscription(auth)) {
|
|
369
|
+
throw new UnexpectedAuthSourceError(model.provider, {
|
|
370
|
+
retryable: false,
|
|
371
|
+
sanitizedDiagnostics: { detectedSource: auth.source }
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
if (options.effort && model.supportedEffort && !model.supportedEffort.includes(options.effort)) {
|
|
375
|
+
throw new UnsupportedCapabilityError(
|
|
376
|
+
{ provider: model.provider, transport: "exec", retryable: false },
|
|
377
|
+
`Effort "${options.effort}" is not supported by ${model.id}`
|
|
378
|
+
);
|
|
379
|
+
}
|
|
380
|
+
const context = runtime.registration(model.provider).translateContext(options.context);
|
|
381
|
+
const permissions = runtime.registration(model.provider).translatePermissions(
|
|
382
|
+
permissionsIntent,
|
|
383
|
+
transport
|
|
384
|
+
);
|
|
385
|
+
assertRespondCompatibility(options, compatibility);
|
|
386
|
+
const unsupported = [...context.unsupported, ...permissions.report.unsupported];
|
|
387
|
+
if (options.permissions?.strict !== false && unsupported.length > 0) {
|
|
388
|
+
throw new UnsupportedCapabilityError(
|
|
389
|
+
{ provider: model.provider, transport, retryable: false },
|
|
390
|
+
`Requested policy cannot be enforced: ${unsupported.join(", ")}`
|
|
391
|
+
);
|
|
392
|
+
}
|
|
393
|
+
const compatibilityWarnings = compatibility === void 0 ? [{ code: "COMPATIBILITY_NOT_PROBED", message: "CLI help capabilities were not probed" }] : compatibility.evidence === "live-contract" ? [] : [{
|
|
394
|
+
code: compatibility.missingFlags.length > 0 ? "CLI_FLAGS_MISSING" : "HELP_PROBED_ONLY",
|
|
395
|
+
message: compatibility.missingFlags.length > 0 ? `Installed CLI is missing flags: ${compatibility.missingFlags.join(", ")}` : `${model.provider} ${installation.version ?? "unknown"} is help-probed but not live-contract verified`
|
|
396
|
+
}];
|
|
397
|
+
const capabilities = {
|
|
398
|
+
provider: model.provider,
|
|
399
|
+
transport,
|
|
400
|
+
features: buildExecFeatures(compatibility?.features, model.provider, !!adapter.stream),
|
|
401
|
+
unsupported,
|
|
402
|
+
warnings: [
|
|
403
|
+
...auth.state === "unknown" ? [{ code: "AUTH_UNVERIFIED", message: "Authentication is unverified; the requested turn will confirm it" }] : [],
|
|
404
|
+
...context.warnings.map((message) => ({ code: "CONTEXT_PARTIAL", message })),
|
|
405
|
+
...compatibilityWarnings
|
|
406
|
+
],
|
|
407
|
+
contextSources: context.report,
|
|
408
|
+
enforcement: permissions.report
|
|
409
|
+
};
|
|
410
|
+
const executableRealpath = installation.realpath ?? installation.path ?? "";
|
|
411
|
+
const fingerprint = `${model.provider}:${installation.version ?? "unknown"}:${executableRealpath}`;
|
|
412
|
+
const controlRegistration = runtime.controlRegistration(model.provider);
|
|
413
|
+
if (transport === "control" && controlRegistration) capabilities.features = controlFeatures(controlRegistration);
|
|
414
|
+
const negotiatedCapabilities = negotiateCapabilities({
|
|
415
|
+
transport,
|
|
416
|
+
registration: controlRegistration,
|
|
417
|
+
features: capabilities.features,
|
|
418
|
+
fingerprint
|
|
419
|
+
});
|
|
420
|
+
assertRequiredCapabilities(options, model, negotiatedCapabilities, transport);
|
|
421
|
+
const requireSubscription = (exec) => transport === "exec" && options.requireAuth === "subscription" ? new SubscriptionExecAdapter(exec) : exec;
|
|
422
|
+
const pin = await probe(() => createExecutablePin(installation.launchTarget?.command ?? executableRealpath, installation.version, { target: installation.launchTarget, identityFiles: installation.identityFiles }));
|
|
423
|
+
if (pin) {
|
|
424
|
+
const pinnedBase = runtime.adapterWithTarget(model.provider, pin.launchTarget ?? { command: pin.realpath, argsPrefix: [] });
|
|
425
|
+
const reprobe = async (probeEnv, previous, context2) => {
|
|
426
|
+
const probed = await pinnedBase.detect(probeEnv, context2);
|
|
427
|
+
if (!probed.installed) {
|
|
428
|
+
throw new CliNotInstalledError(model.provider, { retryable: false });
|
|
429
|
+
}
|
|
430
|
+
{
|
|
431
|
+
const version = probed.version ?? previous.cliVersion ?? "unknown";
|
|
432
|
+
const reassessed = await pinnedBase.compatibility?.(probeEnv, version, context2);
|
|
433
|
+
assertRespondCompatibility(options, reassessed);
|
|
434
|
+
assertRequiredCapabilities(options, model, negotiateCapabilities({
|
|
435
|
+
transport,
|
|
436
|
+
registration: controlRegistration,
|
|
437
|
+
features: buildExecFeatures(reassessed?.features, model.provider, !!pinnedBase.stream),
|
|
438
|
+
fingerprint
|
|
439
|
+
}), transport);
|
|
440
|
+
if (options.permissions?.mode === "respond") assertRespondAuth(options, await pinnedBase.auth(probeEnv, context2, authTurn));
|
|
441
|
+
if (reassessed?.features.turns === "unsupported") {
|
|
442
|
+
throw new UnsupportedCliVersionError(model.provider, version, {
|
|
443
|
+
provider: model.provider,
|
|
444
|
+
transport: "exec",
|
|
445
|
+
cliVersion: version,
|
|
446
|
+
retryable: false,
|
|
447
|
+
sanitizedDiagnostics: { missingFlags: reassessed.missingFlags }
|
|
448
|
+
});
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
const next = await createExecutablePin(
|
|
452
|
+
probed.launchTarget?.command ?? probed.realpath ?? probed.path ?? previous.realpath,
|
|
453
|
+
probed.version ?? previous.cliVersion,
|
|
454
|
+
{ target: probed.launchTarget ?? previous.launchTarget, identityFiles: probed.identityFiles ?? previous.identityFiles?.map((file) => file.realpath) }
|
|
455
|
+
);
|
|
456
|
+
if (!next) throw new CliNotInstalledError(model.provider, { retryable: false });
|
|
457
|
+
return next;
|
|
458
|
+
};
|
|
459
|
+
sessionAdapter = new PinnedExecAdapter(requireSubscription(pinnedBase), pin, reprobe);
|
|
460
|
+
} else {
|
|
461
|
+
sessionAdapter = requireSubscription(adapter);
|
|
462
|
+
}
|
|
463
|
+
const envelope = buildSafetyEnvelope({
|
|
464
|
+
tools: [
|
|
465
|
+
...permissionsIntent.mode === "respond" ? options.providerOptions?.claude?.tools ?? [] : [],
|
|
466
|
+
...(options.tools ?? []).map((tool) => tool.name)
|
|
467
|
+
],
|
|
468
|
+
mcpServers: envelopeMcpServers({
|
|
469
|
+
provider: model.provider,
|
|
470
|
+
transport,
|
|
471
|
+
cwd,
|
|
472
|
+
providerOptions,
|
|
473
|
+
contextArgs: context.args,
|
|
474
|
+
permissionArgs: permissions.args,
|
|
475
|
+
applicationTools: options.tools?.length ?? 0
|
|
476
|
+
}),
|
|
477
|
+
cwd,
|
|
478
|
+
permissions: permissionsIntent,
|
|
479
|
+
environmentVariables: Object.keys(env),
|
|
480
|
+
executableRealpath,
|
|
481
|
+
modelId: model.id,
|
|
482
|
+
enforcedBy: permissions.report.effective.enforcedBy
|
|
483
|
+
});
|
|
484
|
+
const readiness = {
|
|
485
|
+
ready: true,
|
|
486
|
+
provider: model.provider,
|
|
487
|
+
model,
|
|
488
|
+
installation,
|
|
489
|
+
auth,
|
|
490
|
+
capabilities,
|
|
491
|
+
plan: {
|
|
492
|
+
provider: model.provider,
|
|
493
|
+
transport,
|
|
494
|
+
fingerprint: {
|
|
495
|
+
adapterVersion: transport === "control" && controlRegistration ? controlRegistration.adapterVersion : runtime.registration(model.provider).exec.adapterVersion,
|
|
496
|
+
cliVersion: installation.version ?? "unknown",
|
|
497
|
+
executableRealpath: pin?.realpath ?? executableRealpath,
|
|
498
|
+
...pin === void 0 ? {} : { executableDigest: pin.digest },
|
|
499
|
+
...pin?.launchIdentityDigest === void 0 ? {} : { launchIdentityDigest: pin.launchIdentityDigest },
|
|
500
|
+
...transport === "control" && controlRegistration?.protocolVersion !== void 0 ? { protocolVersion: controlRegistration.protocolVersion } : {},
|
|
501
|
+
...transport === "control" && controlRegistration?.sdkVersion !== void 0 ? { sdkVersion: controlRegistration.sdkVersion } : {}
|
|
502
|
+
},
|
|
503
|
+
capabilities: negotiatedCapabilities,
|
|
504
|
+
envelope,
|
|
505
|
+
warnings: capabilities.warnings
|
|
506
|
+
}
|
|
507
|
+
};
|
|
508
|
+
const launchPlan = freeze(structuredClone(readiness.plan));
|
|
509
|
+
return { cwd, permissions: permissionsIntent, sessionAdapter, launchPlan, readiness: freeze(structuredClone(readiness)) };
|
|
510
|
+
}
|
|
511
|
+
function assertRequiredCapabilities(options, model, negotiated, transport) {
|
|
512
|
+
for (const [name, value] of Object.entries(options.capabilities ?? {})) {
|
|
513
|
+
if (value !== true && value !== "required") continue;
|
|
514
|
+
const key = name === "tokenDeltas" ? "messageDeltas" : name;
|
|
515
|
+
const support = negotiated[key]?.support ?? "unknown";
|
|
516
|
+
if (support === "unknown" || support === "none") {
|
|
517
|
+
throw new UnsupportedCapabilityError(
|
|
518
|
+
{ provider: model.provider, transport, retryable: false },
|
|
519
|
+
`Required capability ${name} is ${support} on the ${transport} transport; unknown evidence does not satisfy a required capability`
|
|
520
|
+
);
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
function agentEnvironment(options) {
|
|
525
|
+
const profile = options.context?.profile ?? "native";
|
|
526
|
+
return buildEnvironment(options.environment ?? { mode: profile === "native" ? "inherit" : "minimal" });
|
|
527
|
+
}
|
|
528
|
+
function agentTransport(options, runtime, provider, persistence = "provider") {
|
|
529
|
+
const controlRegistered = runtime.controlRegistration(provider) !== void 0;
|
|
530
|
+
const preference = options.transport ?? "auto";
|
|
531
|
+
return selectTransport({
|
|
532
|
+
provider,
|
|
533
|
+
preference: options.pinned && preference === "auto" ? "exec" : preference,
|
|
534
|
+
requirements: options.capabilities ?? {},
|
|
535
|
+
persistence,
|
|
536
|
+
controlRegistered,
|
|
537
|
+
controlAvailable: controlRegistered && experimentalGates(options.providerOptions).control,
|
|
538
|
+
execCapabilities: runtime.registration(provider).execCapabilities
|
|
539
|
+
});
|
|
540
|
+
}
|
|
541
|
+
async function freshAgentReadiness(options, runtime, model, readinessOptions) {
|
|
542
|
+
if (!readinessOptions || typeof readinessOptions !== "object" || types.isProxy(readinessOptions) || ![Object.prototype, null].includes(Object.getPrototypeOf(readinessOptions))) {
|
|
543
|
+
throw new TypeError("Readiness options must be a plain object");
|
|
544
|
+
}
|
|
545
|
+
const snapshot = /* @__PURE__ */ Object.create(null);
|
|
546
|
+
for (const key of Reflect.ownKeys(readinessOptions)) {
|
|
547
|
+
const descriptor = Object.getOwnPropertyDescriptor(readinessOptions, key);
|
|
548
|
+
if (typeof key !== "string" || !["signal", "timeoutMs", "awaitSettlement"].includes(key) || !Object.hasOwn(descriptor, "value")) throw new TypeError("Invalid readiness option");
|
|
549
|
+
snapshot[key] = descriptor.value;
|
|
550
|
+
}
|
|
551
|
+
const { signal, timeoutMs, awaitSettlement } = snapshot;
|
|
552
|
+
if (signal !== void 0 && !(signal instanceof AbortSignal)) throw new TypeError("signal must be an AbortSignal");
|
|
553
|
+
if (timeoutMs !== void 0 && typeof timeoutMs !== "number") throw new TypeError("timeoutMs must be a number");
|
|
554
|
+
validateSettlementOption(awaitSettlement);
|
|
555
|
+
const scope = new OperationScope(Object.assign(/* @__PURE__ */ Object.create(null), {
|
|
556
|
+
timeoutMs: validateTimeoutMs(timeoutMs),
|
|
557
|
+
...signal === void 0 ? {} : { signal },
|
|
558
|
+
context: { provider: model.provider, retryable: true }
|
|
559
|
+
}));
|
|
560
|
+
try {
|
|
561
|
+
return (await scope.race(() => prepareAgent(options, runtime, model, "provider", scope))).readiness;
|
|
562
|
+
} finally {
|
|
563
|
+
try {
|
|
564
|
+
if (awaitSettlement) {
|
|
565
|
+
await scope.drain();
|
|
566
|
+
scope.rethrowExecutionHalt();
|
|
567
|
+
}
|
|
568
|
+
} finally {
|
|
569
|
+
scope.dispose();
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
export {
|
|
575
|
+
selectTransport,
|
|
576
|
+
prepareAgent,
|
|
577
|
+
agentEnvironment,
|
|
578
|
+
agentTransport,
|
|
579
|
+
freshAgentReadiness
|
|
580
|
+
};
|
|
581
|
+
//# sourceMappingURL=chunk-WVT5SEKC.js.map
|