@lichao0223/lobehub-cli 0.0.89 → 0.0.90
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/dist/acceptance-report.html +310 -254
- package/dist/index.js +1131 -602
- package/man/man1/lh.1 +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -110,16 +110,16 @@ var init_escapeRegExp = __esmMin((() => {}));
|
|
|
110
110
|
|
|
111
111
|
//#endregion
|
|
112
112
|
//#region ../../packages/utils/src/object.ts
|
|
113
|
-
var isObjectLike$1, isRecord$
|
|
113
|
+
var isObjectLike$1, isRecord$8, isPlainRecord, toRecord, pickString$1;
|
|
114
114
|
var init_object$1 = __esmMin((() => {
|
|
115
115
|
isObjectLike$1 = (value) => typeof value === "object" && value !== null;
|
|
116
|
-
isRecord$
|
|
116
|
+
isRecord$8 = (value) => isObjectLike$1(value) && !Array.isArray(value);
|
|
117
117
|
isPlainRecord = (value) => {
|
|
118
|
-
if (!isRecord$
|
|
118
|
+
if (!isRecord$8(value)) return false;
|
|
119
119
|
const prototype = Object.getPrototypeOf(value);
|
|
120
120
|
return prototype === Object.prototype || prototype === null;
|
|
121
121
|
};
|
|
122
|
-
toRecord = (value) => isRecord$
|
|
122
|
+
toRecord = (value) => isRecord$8(value) ? value : void 0;
|
|
123
123
|
pickString$1 = (value) => typeof value === "string" ? value : void 0;
|
|
124
124
|
}));
|
|
125
125
|
|
|
@@ -7888,6 +7888,14 @@ var init_agentAccount = __esmMin((() => {
|
|
|
7888
7888
|
AGENT_ACCOUNT_PERSISTED_KINDS = [...AGENT_ACCOUNT_KINDS, "phone"];
|
|
7889
7889
|
}));
|
|
7890
7890
|
|
|
7891
|
+
//#endregion
|
|
7892
|
+
//#region ../../packages/types/src/agentAvailability.ts
|
|
7893
|
+
var init_agentAvailability = __esmMin((() => {}));
|
|
7894
|
+
|
|
7895
|
+
//#endregion
|
|
7896
|
+
//#region ../../packages/types/src/agentDelivery.ts
|
|
7897
|
+
var init_agentDelivery = __esmMin((() => {}));
|
|
7898
|
+
|
|
7891
7899
|
//#endregion
|
|
7892
7900
|
//#region ../../packages/types/src/workingDir.ts
|
|
7893
7901
|
var gitLinkedPullRequestSchema, workingDirConfigSchema;
|
|
@@ -7950,6 +7958,20 @@ var init_device = __esmMin((() => {
|
|
|
7950
7958
|
init_workingDir();
|
|
7951
7959
|
}));
|
|
7952
7960
|
|
|
7961
|
+
//#endregion
|
|
7962
|
+
//#region ../../packages/types/src/heteroPermissionMode.ts
|
|
7963
|
+
var HETERO_PERMISSION_MODES, isHeteroPermissionMode;
|
|
7964
|
+
var init_heteroPermissionMode = __esmMin((() => {
|
|
7965
|
+
HETERO_PERMISSION_MODES = [
|
|
7966
|
+
"default",
|
|
7967
|
+
"acceptEdits",
|
|
7968
|
+
"auto",
|
|
7969
|
+
"plan",
|
|
7970
|
+
"bypassPermissions"
|
|
7971
|
+
];
|
|
7972
|
+
isHeteroPermissionMode = (value) => typeof value === "string" && HETERO_PERMISSION_MODES.includes(value);
|
|
7973
|
+
}));
|
|
7974
|
+
|
|
7953
7975
|
//#endregion
|
|
7954
7976
|
//#region ../../packages/types/src/agentExecution/credentialFacts.ts
|
|
7955
7977
|
var init_credentialFacts = __esmMin((() => {}));
|
|
@@ -7968,10 +7990,16 @@ var initialTopicMetadataSchema;
|
|
|
7968
7990
|
var init_agentExecution = __esmMin((() => {
|
|
7969
7991
|
init_zod$1();
|
|
7970
7992
|
init_device();
|
|
7993
|
+
init_heteroPermissionMode();
|
|
7971
7994
|
init_credentialFacts();
|
|
7972
7995
|
init_initRequest();
|
|
7973
7996
|
init_modelFacts();
|
|
7974
7997
|
initialTopicMetadataSchema = object$1({
|
|
7998
|
+
/**
|
|
7999
|
+
* Claude Code permission mode the composer chip showed (Better Coding
|
|
8000
|
+
* Experience); the topic's first dispatched run starts in it.
|
|
8001
|
+
*/
|
|
8002
|
+
heteroPermissionMode: _enum(HETERO_PERMISSION_MODES).optional(),
|
|
7975
8003
|
repos: array(string()).optional(),
|
|
7976
8004
|
/**
|
|
7977
8005
|
* Cloud-sandbox placement the composer chose before any topic existed — an
|
|
@@ -11014,6 +11042,7 @@ var init_topic$1 = __esmMin((() => {
|
|
|
11014
11042
|
init_aiModel();
|
|
11015
11043
|
init_zod$1();
|
|
11016
11044
|
init_device();
|
|
11045
|
+
init_heteroPermissionMode();
|
|
11017
11046
|
topicScheduledRunClaimSchema = object$1({
|
|
11018
11047
|
claimedAt: string(),
|
|
11019
11048
|
expiresAt: string(),
|
|
@@ -11114,6 +11143,8 @@ var init_topic$1 = __esmMin((() => {
|
|
|
11114
11143
|
heteroSessionBindingKeyByWorkingDirectory: record(string(), string()).optional(),
|
|
11115
11144
|
heteroSessionId: string().optional(),
|
|
11116
11145
|
heteroSessionIdByWorkingDirectory: record(string(), string()).optional(),
|
|
11146
|
+
heteroPermissionMode: _enum(HETERO_PERMISSION_MODES).optional(),
|
|
11147
|
+
heteroPermissionModeFallback: _enum(["outdatedCli", "root"]).nullable().optional(),
|
|
11117
11148
|
heteroSpeed: _enum([
|
|
11118
11149
|
"default",
|
|
11119
11150
|
"normal",
|
|
@@ -12265,6 +12296,8 @@ var init_zustand = __esmMin((() => {}));
|
|
|
12265
12296
|
var init_src$2 = __esmMin((() => {
|
|
12266
12297
|
init_agent();
|
|
12267
12298
|
init_agentAccount();
|
|
12299
|
+
init_agentAvailability();
|
|
12300
|
+
init_agentDelivery();
|
|
12268
12301
|
init_agentExecution();
|
|
12269
12302
|
init_agentGroup();
|
|
12270
12303
|
init_agentHook();
|
|
@@ -12363,6 +12396,7 @@ var init_src$2 = __esmMin((() => {
|
|
|
12363
12396
|
init_artboard();
|
|
12364
12397
|
init_connector();
|
|
12365
12398
|
init_connectorToolIdentifier();
|
|
12399
|
+
init_heteroPermissionMode();
|
|
12366
12400
|
init_inboundWebhook();
|
|
12367
12401
|
init_oauthApp();
|
|
12368
12402
|
init_chat();
|
|
@@ -16297,7 +16331,7 @@ var wrapper_default = import_websocket.default;
|
|
|
16297
16331
|
|
|
16298
16332
|
//#endregion
|
|
16299
16333
|
//#region ../../packages/device-gateway-client/src/endpoint.ts
|
|
16300
|
-
const isRecord$
|
|
16334
|
+
const isRecord$7 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
16301
16335
|
const parseHttpUrl = (value) => {
|
|
16302
16336
|
if (typeof value !== "string") return void 0;
|
|
16303
16337
|
const trimmed = value.trim();
|
|
@@ -16344,7 +16378,7 @@ const toDeviceGatewayWebSocketUrl = (gatewayUrl) => {
|
|
|
16344
16378
|
* (including `null` or an empty string) is `invalid`.
|
|
16345
16379
|
*/
|
|
16346
16380
|
const parseDeviceGatewayDiscovery = (globalConfig) => {
|
|
16347
|
-
if (!isRecord$
|
|
16381
|
+
if (!isRecord$7(globalConfig) || !isRecord$7(globalConfig.serverConfig)) return {
|
|
16348
16382
|
reason: "the server response is not a global config",
|
|
16349
16383
|
status: "failed"
|
|
16350
16384
|
};
|
|
@@ -18180,6 +18214,7 @@ const TRPC_NAMESPACE_API_KEY_RULES = {
|
|
|
18180
18214
|
acceptanceComment: "blocked",
|
|
18181
18215
|
agent: rw("agent:read", "agent:write"),
|
|
18182
18216
|
agentAccount: rw("agent:read", "agent:write"),
|
|
18217
|
+
agentAvailability: rw("agent:read", null),
|
|
18183
18218
|
agentBotProvider: "blocked",
|
|
18184
18219
|
agentBotWake: "blocked",
|
|
18185
18220
|
agentDocument: rw("knowledge:read", "knowledge:write"),
|
|
@@ -24152,7 +24187,7 @@ const GOMS_KLM_TIMING_SECONDS = {
|
|
|
24152
24187
|
};
|
|
24153
24188
|
|
|
24154
24189
|
//#endregion
|
|
24155
|
-
//#region node_modules/.pnpm/@trpc+server@11.29.
|
|
24190
|
+
//#region node_modules/.pnpm/@trpc+server@11.29.5_@types+ws@8.18.2_typescript@6.0.3/node_modules/@trpc/server/dist/observable-CodTG6Sf.mjs
|
|
24156
24191
|
/**
|
|
24157
24192
|
* Creates an observable. `subscribe` runs for each subscriber, and can
|
|
24158
24193
|
* return a function that cleans up when it unsubscribes.
|
|
@@ -24378,7 +24413,7 @@ function observableToAsyncIterable(observable, signal) {
|
|
|
24378
24413
|
}
|
|
24379
24414
|
|
|
24380
24415
|
//#endregion
|
|
24381
|
-
//#region node_modules/.pnpm/@trpc+server@11.29.
|
|
24416
|
+
//#region node_modules/.pnpm/@trpc+server@11.29.5_@types+ws@8.18.2_typescript@6.0.3/node_modules/@trpc/server/dist/observable-BjUZYMQq.mjs
|
|
24382
24417
|
/**
|
|
24383
24418
|
* Shares one subscription to the source between all subscribers. It
|
|
24384
24419
|
* starts with the first subscriber and ends when the last unsubscribes.
|
|
@@ -24504,7 +24539,7 @@ function behaviorSubject(initialValue) {
|
|
|
24504
24539
|
}
|
|
24505
24540
|
|
|
24506
24541
|
//#endregion
|
|
24507
|
-
//#region node_modules/.pnpm/@trpc+client@11.29.
|
|
24542
|
+
//#region node_modules/.pnpm/@trpc+client@11.29.5_@trpc+server@11.29.5_@types+ws@8.18.2_typescript@6.0.3__typescript@6.0.3/node_modules/@trpc/client/dist/splitLink-PFsRy7Mf.mjs
|
|
24508
24543
|
/** @internal */
|
|
24509
24544
|
function createChain(opts) {
|
|
24510
24545
|
return observable$1((observer) => {
|
|
@@ -24523,7 +24558,7 @@ function createChain(opts) {
|
|
|
24523
24558
|
}
|
|
24524
24559
|
|
|
24525
24560
|
//#endregion
|
|
24526
|
-
//#region node_modules/.pnpm/@trpc+client@11.29.
|
|
24561
|
+
//#region node_modules/.pnpm/@trpc+client@11.29.5_@trpc+server@11.29.5_@types+ws@8.18.2_typescript@6.0.3__typescript@6.0.3/node_modules/@trpc/client/dist/objectSpread2-pyA4QVO4.mjs
|
|
24527
24562
|
function _typeof$1(o) {
|
|
24528
24563
|
"@babel/helpers - typeof";
|
|
24529
24564
|
return _typeof$1 = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
@@ -24577,7 +24612,7 @@ function _objectSpread2$1(e) {
|
|
|
24577
24612
|
}
|
|
24578
24613
|
|
|
24579
24614
|
//#endregion
|
|
24580
|
-
//#region node_modules/.pnpm/@trpc+server@11.29.
|
|
24615
|
+
//#region node_modules/.pnpm/@trpc+server@11.29.5_@types+ws@8.18.2_typescript@6.0.3/node_modules/@trpc/server/dist/codes-BCsCCyMj.mjs
|
|
24581
24616
|
/**
|
|
24582
24617
|
* Check that value is object
|
|
24583
24618
|
* @internal
|
|
@@ -24640,7 +24675,7 @@ const retryableRpcCodes = [
|
|
|
24640
24675
|
];
|
|
24641
24676
|
|
|
24642
24677
|
//#endregion
|
|
24643
|
-
//#region node_modules/.pnpm/@trpc+server@11.29.
|
|
24678
|
+
//#region node_modules/.pnpm/@trpc+server@11.29.5_@types+ws@8.18.2_typescript@6.0.3/node_modules/@trpc/server/dist/getErrorShape-CVrl8_-w.mjs
|
|
24644
24679
|
const noop$4 = () => {};
|
|
24645
24680
|
const freezeIfAvailable = (obj) => {
|
|
24646
24681
|
if (Object.freeze) Object.freeze(obj);
|
|
@@ -24745,7 +24780,7 @@ function _objectSpread2(e) {
|
|
|
24745
24780
|
}
|
|
24746
24781
|
|
|
24747
24782
|
//#endregion
|
|
24748
|
-
//#region node_modules/.pnpm/@trpc+server@11.29.
|
|
24783
|
+
//#region node_modules/.pnpm/@trpc+server@11.29.5_@types+ws@8.18.2_typescript@6.0.3/node_modules/@trpc/server/dist/asyncGeneratorDelegate-Bmz6asKS.mjs
|
|
24749
24784
|
/** @internal */
|
|
24750
24785
|
function transformResultInner(response, transformer) {
|
|
24751
24786
|
if ("error" in response) {
|
|
@@ -24851,7 +24886,7 @@ AsyncGenerator$1.prototype["function" == typeof Symbol && Symbol.asyncIterator |
|
|
|
24851
24886
|
};
|
|
24852
24887
|
|
|
24853
24888
|
//#endregion
|
|
24854
|
-
//#region node_modules/.pnpm/@trpc+client@11.29.
|
|
24889
|
+
//#region node_modules/.pnpm/@trpc+client@11.29.5_@trpc+server@11.29.5_@types+ws@8.18.2_typescript@6.0.3__typescript@6.0.3/node_modules/@trpc/client/dist/TRPCClientError-DE6-fd1n.mjs
|
|
24855
24890
|
/**
|
|
24856
24891
|
* Whether a value is a `TRPCClientError`, typed for a router or procedure.
|
|
24857
24892
|
* @see https://trpc.io/docs/client/vanilla/error-handling#catching-a-thrown-error
|
|
@@ -24907,7 +24942,7 @@ var TRPCClientError = class TRPCClientError extends Error {
|
|
|
24907
24942
|
};
|
|
24908
24943
|
|
|
24909
24944
|
//#endregion
|
|
24910
|
-
//#region node_modules/.pnpm/@trpc+client@11.29.
|
|
24945
|
+
//#region node_modules/.pnpm/@trpc+client@11.29.5_@trpc+server@11.29.5_@types+ws@8.18.2_typescript@6.0.3__typescript@6.0.3/node_modules/@trpc/client/dist/unstable-internals.mjs
|
|
24911
24946
|
/**
|
|
24912
24947
|
* @internal
|
|
24913
24948
|
*/
|
|
@@ -24934,7 +24969,7 @@ function getTransformer(transformer) {
|
|
|
24934
24969
|
}
|
|
24935
24970
|
|
|
24936
24971
|
//#endregion
|
|
24937
|
-
//#region node_modules/.pnpm/@trpc+client@11.29.
|
|
24972
|
+
//#region node_modules/.pnpm/@trpc+client@11.29.5_@trpc+server@11.29.5_@types+ws@8.18.2_typescript@6.0.3__typescript@6.0.3/node_modules/@trpc/client/dist/httpUtils-CtMuyl9j.mjs
|
|
24938
24973
|
const isFunction$1 = (fn) => typeof fn === "function";
|
|
24939
24974
|
/**
|
|
24940
24975
|
* The `fetch` to use: `customFetchImpl` if given, or else the global one.
|
|
@@ -25070,7 +25105,7 @@ async function httpRequest(opts) {
|
|
|
25070
25105
|
}
|
|
25071
25106
|
|
|
25072
25107
|
//#endregion
|
|
25073
|
-
//#region node_modules/.pnpm/@trpc+client@11.29.
|
|
25108
|
+
//#region node_modules/.pnpm/@trpc+client@11.29.5_@trpc+server@11.29.5_@types+ws@8.18.2_typescript@6.0.3__typescript@6.0.3/node_modules/@trpc/client/dist/httpLink-B4UwXApa.mjs
|
|
25074
25109
|
/** Whether an input is binary: a `Uint8Array`, `Blob` or `File`. */
|
|
25075
25110
|
function isOctetType(input) {
|
|
25076
25111
|
return input instanceof Uint8Array || input instanceof Blob;
|
|
@@ -25163,7 +25198,7 @@ function httpLink(opts) {
|
|
|
25163
25198
|
}
|
|
25164
25199
|
|
|
25165
25200
|
//#endregion
|
|
25166
|
-
//#region node_modules/.pnpm/@trpc+client@11.29.
|
|
25201
|
+
//#region node_modules/.pnpm/@trpc+client@11.29.5_@trpc+server@11.29.5_@types+ws@8.18.2_typescript@6.0.3__typescript@6.0.3/node_modules/@trpc/client/dist/wsLink-DYx-NUSN.mjs
|
|
25167
25202
|
/**
|
|
25168
25203
|
* Get the result of a value or function that returns a value
|
|
25169
25204
|
* It also optionally accepts typesafe arguments for the function
|
|
@@ -25353,7 +25388,7 @@ var WsConnection = class WsConnection {
|
|
|
25353
25388
|
_defineProperty$1(WsConnection, "connectCount", 0);
|
|
25354
25389
|
|
|
25355
25390
|
//#endregion
|
|
25356
|
-
//#region node_modules/.pnpm/@trpc+client@11.29.
|
|
25391
|
+
//#region node_modules/.pnpm/@trpc+client@11.29.5_@trpc+server@11.29.5_@types+ws@8.18.2_typescript@6.0.3__typescript@6.0.3/node_modules/@trpc/client/dist/index.mjs
|
|
25357
25392
|
const observerKeys = [
|
|
25358
25393
|
"onStarted",
|
|
25359
25394
|
"onData",
|
|
@@ -26498,7 +26533,7 @@ const cliVersion = pkg.version;
|
|
|
26498
26533
|
const cliNodeEngine = pkg.engines?.node;
|
|
26499
26534
|
|
|
26500
26535
|
//#endregion
|
|
26501
|
-
//#region ../../node_modules/.pnpm/@trpc+server@11.29.
|
|
26536
|
+
//#region ../../node_modules/.pnpm/@trpc+server@11.29.5_@types+aws-lambda@8.10.164_@types+express@5.0.6_@types+ws@8.18.2_n_d0ee0c058429d0f6dbf2db4bfd1f1e09/node_modules/@trpc/server/dist/observable-CodTG6Sf.mjs
|
|
26502
26537
|
/**
|
|
26503
26538
|
* Creates an observable. `subscribe` runs for each subscriber, and can
|
|
26504
26539
|
* return a function that cleans up when it unsubscribes.
|
|
@@ -39096,7 +39131,7 @@ async function validateAcceptanceReport(reportDir) {
|
|
|
39096
39131
|
path: issue.path.map((part) => typeof part === "number" ? `[${part}]` : part).join(".").replaceAll(".[", "["),
|
|
39097
39132
|
message: issue.message
|
|
39098
39133
|
});
|
|
39099
|
-
const rawObject = isRecord$
|
|
39134
|
+
const rawObject = isRecord$8(raw) ? raw : void 0;
|
|
39100
39135
|
return {
|
|
39101
39136
|
valid: false,
|
|
39102
39137
|
draft: true,
|
|
@@ -59680,13 +59715,13 @@ const execFilePromise$1 = promisify(execFile);
|
|
|
59680
59715
|
const nonnegative = (value) => typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : null;
|
|
59681
59716
|
/** The native command envelope is distinct from a model response. Fail closed on older CLIs. */
|
|
59682
59717
|
const parseAntigravityQuota = (payload) => {
|
|
59683
|
-
if (!isRecord$
|
|
59718
|
+
if (!isRecord$8(payload) || payload.status !== "SUCCESS" || !isRecord$8(payload.command) || payload.command.name !== "usage" || !isRecord$8(payload.command.data) || !Array.isArray(payload.command.data.groups)) throw new Error("Antigravity did not return a structured usage command result");
|
|
59684
59719
|
return payload.command.data.groups.flatMap((group) => {
|
|
59685
|
-
if (!isRecord$
|
|
59720
|
+
if (!isRecord$8(group) || !pickString$1(group.name) || !Array.isArray(group.buckets)) return [];
|
|
59686
59721
|
const seen = /* @__PURE__ */ new Set();
|
|
59687
59722
|
return [{
|
|
59688
59723
|
buckets: group.buckets.flatMap((bucket) => {
|
|
59689
|
-
if (!isRecord$
|
|
59724
|
+
if (!isRecord$8(bucket)) return [];
|
|
59690
59725
|
const id = pickString$1(bucket.id);
|
|
59691
59726
|
if (!id || seen.has(id)) return [];
|
|
59692
59727
|
seen.add(id);
|
|
@@ -59746,7 +59781,7 @@ const fetchAntigravityQuota = async (params = {}) => {
|
|
|
59746
59781
|
} catch {
|
|
59747
59782
|
return failure("unsupported_client");
|
|
59748
59783
|
}
|
|
59749
|
-
if (isRecord$
|
|
59784
|
+
if (isRecord$8(payload) && payload.status !== "SUCCESS") return failure(typeof payload.error === "string" && isHeterogeneousAgentAuthRequired("antigravity", payload.error) ? "auth_required" : "command_failed");
|
|
59750
59785
|
try {
|
|
59751
59786
|
return {
|
|
59752
59787
|
error: null,
|
|
@@ -59759,7 +59794,7 @@ const fetchAntigravityQuota = async (params = {}) => {
|
|
|
59759
59794
|
return failure("unsupported_client");
|
|
59760
59795
|
}
|
|
59761
59796
|
} catch (error) {
|
|
59762
|
-
const record = isRecord$
|
|
59797
|
+
const record = isRecord$8(error) ? error : {};
|
|
59763
59798
|
const detail = `${record.stderr ?? ""} ${record.message ?? ""}`;
|
|
59764
59799
|
return failure(record.code === "ENOENT" ? "cli_not_found" : record.killed || record.code === "ETIMEDOUT" ? "timeout" : isHeterogeneousAgentAuthRequired("antigravity", detail) ? "auth_required" : "command_failed");
|
|
59765
59800
|
}
|
|
@@ -60849,18 +60884,23 @@ const buildHeterogeneousPrompt = (input) => new HeterogeneousPromptEngine(input)
|
|
|
60849
60884
|
* always a new session by definition — it exists precisely because native
|
|
60850
60885
|
* resume failed and the CLI is starting the agent from scratch — so it carries
|
|
60851
60886
|
* session-scoped context regardless of what the primary attempt got.
|
|
60887
|
+
*
|
|
60888
|
+
* `permissionMode` (Claude Code, Better Coding Experience lab) rides the same
|
|
60889
|
+
* envelope for the same reason: an `lh` that predates it unwraps `content` and
|
|
60890
|
+
* keeps allowing everything, rather than failing on an unknown flag.
|
|
60852
60891
|
*/
|
|
60853
60892
|
const buildHeteroExecStdinPayload = (params) => {
|
|
60854
|
-
const { imageList = [], isNewSession, prompt, resumeFallbackSystemContext, systemContext } = params;
|
|
60893
|
+
const { imageList = [], isNewSession, permissionMode, prompt, resumeFallbackSystemContext, systemContext } = params;
|
|
60855
60894
|
const blocks = buildHeterogeneousPrompt({
|
|
60856
60895
|
imageList,
|
|
60857
60896
|
isNewSession,
|
|
60858
60897
|
prompt,
|
|
60859
60898
|
systemContext
|
|
60860
60899
|
});
|
|
60861
|
-
if (resumeFallbackSystemContext !== void 0) return JSON.stringify({
|
|
60900
|
+
if (resumeFallbackSystemContext !== void 0 || permissionMode) return JSON.stringify({
|
|
60862
60901
|
content: blocks,
|
|
60863
|
-
|
|
60902
|
+
...permissionMode && { permissionMode },
|
|
60903
|
+
resumeFallback: resumeFallbackSystemContext === void 0 ? void 0 : buildHeterogeneousPrompt({
|
|
60864
60904
|
imageList,
|
|
60865
60905
|
isNewSession: true,
|
|
60866
60906
|
prompt,
|
|
@@ -61265,21 +61305,21 @@ const SHELL_POLICY_KEY = "shell_environment_policy";
|
|
|
61265
61305
|
*/
|
|
61266
61306
|
const withCodexThreadEnv = (params, provenance) => {
|
|
61267
61307
|
const config = { ...params.config };
|
|
61268
|
-
const policy = isRecord$
|
|
61308
|
+
const policy = isRecord$8(config[SHELL_POLICY_KEY]) ? structuredClone(config[SHELL_POLICY_KEY]) : {};
|
|
61269
61309
|
delete config[SHELL_POLICY_KEY];
|
|
61270
61310
|
for (const key of Object.keys(config)) {
|
|
61271
61311
|
if (!key.startsWith(`${SHELL_POLICY_KEY}.`)) continue;
|
|
61272
61312
|
const path = key.slice(25).split(".");
|
|
61273
61313
|
let target = policy;
|
|
61274
61314
|
for (const segment of path.slice(0, -1)) {
|
|
61275
|
-
if (!isRecord$
|
|
61315
|
+
if (!isRecord$8(target[segment])) target[segment] = {};
|
|
61276
61316
|
target = target[segment];
|
|
61277
61317
|
}
|
|
61278
61318
|
target[path.at(-1)] = config[key];
|
|
61279
61319
|
delete config[key];
|
|
61280
61320
|
}
|
|
61281
61321
|
policy.set = {
|
|
61282
|
-
...isRecord$
|
|
61322
|
+
...isRecord$8(policy.set) ? policy.set : {},
|
|
61283
61323
|
...Object.fromEntries(CODEX_PROVENANCE_KEYS.map((key) => [key, provenance[key] ?? ""]))
|
|
61284
61324
|
};
|
|
61285
61325
|
config[SHELL_POLICY_KEY] = policy;
|
|
@@ -61587,7 +61627,7 @@ var CodexAppServerClient = class {
|
|
|
61587
61627
|
method,
|
|
61588
61628
|
reject,
|
|
61589
61629
|
resolve: (result) => resolve(result),
|
|
61590
|
-
threadId: isRecord$
|
|
61630
|
+
threadId: isRecord$8(params) ? pickString$1(params.threadId) : void 0,
|
|
61591
61631
|
timeout
|
|
61592
61632
|
};
|
|
61593
61633
|
this.pendingRequests.set(key, pending);
|
|
@@ -61626,8 +61666,8 @@ var CodexAppServerClient = class {
|
|
|
61626
61666
|
}
|
|
61627
61667
|
}
|
|
61628
61668
|
getMessageThreadId(generation, message) {
|
|
61629
|
-
if (!isRecord$
|
|
61630
|
-
if (isRecord$
|
|
61669
|
+
if (!isRecord$8(message)) return;
|
|
61670
|
+
if (isRecord$8(message.params)) {
|
|
61631
61671
|
const threadId = pickString$1(message.params.threadId);
|
|
61632
61672
|
if (threadId) return threadId;
|
|
61633
61673
|
}
|
|
@@ -61638,7 +61678,7 @@ var CodexAppServerClient = class {
|
|
|
61638
61678
|
}
|
|
61639
61679
|
routeMessage(generation, message) {
|
|
61640
61680
|
if (!this.isCurrentGeneration(generation)) return;
|
|
61641
|
-
if (!isRecord$
|
|
61681
|
+
if (!isRecord$8(message)) throw new TypeError("Expected an app-server RPC object");
|
|
61642
61682
|
const method = pickString$1(message.method);
|
|
61643
61683
|
const id = message.id;
|
|
61644
61684
|
if (method) {
|
|
@@ -61652,16 +61692,16 @@ var CodexAppServerClient = class {
|
|
|
61652
61692
|
if (!pending || pending.generation !== generation) return;
|
|
61653
61693
|
this.pendingRequests.delete(key);
|
|
61654
61694
|
clearTimeout(pending.timeout);
|
|
61655
|
-
if (isRecord$
|
|
61695
|
+
if (isRecord$8(message.error)) pending.reject(new CodexAppServerRpcError(pickString$1(message.error.message) ?? `Codex app-server request failed: ${pending.method}`, typeof message.error.code === "number" ? message.error.code : void 0, message.error.data, pending.method));
|
|
61656
61696
|
else pending.resolve(message.result);
|
|
61657
61697
|
}
|
|
61658
61698
|
routeNotification(method, params) {
|
|
61659
|
-
const threadId = isRecord$
|
|
61699
|
+
const threadId = isRecord$8(params) ? pickString$1(params.threadId) : void 0;
|
|
61660
61700
|
if (!threadId) return;
|
|
61661
61701
|
for (const handler of this.notificationHandlers.get(threadId) ?? []) handler(method, params);
|
|
61662
61702
|
}
|
|
61663
61703
|
async routeServerRequest(generation, id, method, params) {
|
|
61664
|
-
const threadId = isRecord$
|
|
61704
|
+
const threadId = isRecord$8(params) ? pickString$1(params.threadId) : void 0;
|
|
61665
61705
|
const handler = (threadId ? this.serverRequestHandlers.get(threadId) : void 0)?.values().next().value;
|
|
61666
61706
|
let response;
|
|
61667
61707
|
try {
|
|
@@ -63234,7 +63274,7 @@ const codexUserInputArguments = (request) => ({ questions: request.questions.map
|
|
|
63234
63274
|
question: question.question
|
|
63235
63275
|
})) });
|
|
63236
63276
|
const codexUserInputResponse = (request, answer) => {
|
|
63237
|
-
if (answer.cancelled || !isRecord$
|
|
63277
|
+
if (answer.cancelled || !isRecord$8(answer.result)) return { answers: {} };
|
|
63238
63278
|
const result = answer.result;
|
|
63239
63279
|
const entries = request.questions.flatMap((question, index) => {
|
|
63240
63280
|
const value = result[question.question];
|
|
@@ -63714,8 +63754,8 @@ var CodexThreadSession = class {
|
|
|
63714
63754
|
await this.emitEvents(events.filter(turnEnded), operationId);
|
|
63715
63755
|
}
|
|
63716
63756
|
isCurrentTurnNotification(method, params, activeTurn) {
|
|
63717
|
-
if (!isRecord$
|
|
63718
|
-
const notificationTurnId = method === "turn/started" || method === "turn/completed" ? isRecord$
|
|
63757
|
+
if (!isRecord$8(params)) return false;
|
|
63758
|
+
const notificationTurnId = method === "turn/started" || method === "turn/completed" ? isRecord$8(params.turn) ? pickString$1(params.turn.id) : void 0 : pickString$1(params.turnId);
|
|
63719
63759
|
if (method === "turn/started" && !activeTurn.turnId && notificationTurnId) activeTurn.turnId = notificationTurnId;
|
|
63720
63760
|
return !activeTurn.turnId || !notificationTurnId || activeTurn.turnId === notificationTurnId;
|
|
63721
63761
|
}
|
|
@@ -64188,7 +64228,7 @@ init_config();
|
|
|
64188
64228
|
const AMP_IDENTIFIER = "amp";
|
|
64189
64229
|
const AMP_DOCS_URL = getHeterogeneousAgentConfigOrThrow(AMP_IDENTIFIER).auth.docsUrl;
|
|
64190
64230
|
const AMP_MISSING_RESULT_MESSAGE = "Amp stream ended without the required terminal `result` event.";
|
|
64191
|
-
const isRecord$
|
|
64231
|
+
const isRecord$6 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
64192
64232
|
const stringifyUnknown$2 = (value) => {
|
|
64193
64233
|
if (typeof value === "string") return value;
|
|
64194
64234
|
if (value === void 0 || value === null) return "";
|
|
@@ -64200,7 +64240,7 @@ const stringifyUnknown$2 = (value) => {
|
|
|
64200
64240
|
};
|
|
64201
64241
|
const toFiniteNumber$4 = (value) => typeof value === "number" && Number.isFinite(value) ? value : void 0;
|
|
64202
64242
|
const toUsageData$4 = (value) => {
|
|
64203
|
-
if (!isRecord$
|
|
64243
|
+
if (!isRecord$6(value)) return;
|
|
64204
64244
|
const usage = value;
|
|
64205
64245
|
const inputCacheMissTokens = toFiniteNumber$4(usage.input_tokens) ?? 0;
|
|
64206
64246
|
const inputCachedTokens = toFiniteNumber$4(usage.cache_read_input_tokens) ?? 0;
|
|
@@ -64236,10 +64276,10 @@ const normalizeToolResult$1 = (value) => {
|
|
|
64236
64276
|
return {
|
|
64237
64277
|
content: value.map((item) => {
|
|
64238
64278
|
if (typeof item === "string") return item;
|
|
64239
|
-
if (!isRecord$
|
|
64279
|
+
if (!isRecord$6(item)) return stringifyUnknown$2(item);
|
|
64240
64280
|
if (item.type === "tool_reference" && typeof item.tool_name === "string") return item.tool_name;
|
|
64241
64281
|
if (item.type === "image") {
|
|
64242
|
-
const source = isRecord$
|
|
64282
|
+
const source = isRecord$6(item.source) ? item.source : void 0;
|
|
64243
64283
|
const mediaType = typeof source?.media_type === "string" ? source.media_type : "image";
|
|
64244
64284
|
if (source?.type === "base64" && typeof source.data === "string") images.push({
|
|
64245
64285
|
data: source.data,
|
|
@@ -64266,7 +64306,7 @@ const toToolPayload$2 = (block) => {
|
|
|
64266
64306
|
};
|
|
64267
64307
|
const getErrorText = (value) => {
|
|
64268
64308
|
if (typeof value === "string" && value.trim()) return value.trim();
|
|
64269
|
-
if (!isRecord$
|
|
64309
|
+
if (!isRecord$6(value)) return;
|
|
64270
64310
|
for (const key of [
|
|
64271
64311
|
"message",
|
|
64272
64312
|
"error",
|
|
@@ -64329,7 +64369,7 @@ var AmpAdapter = class {
|
|
|
64329
64369
|
toolSubagentById = /* @__PURE__ */ new Map();
|
|
64330
64370
|
sessionId;
|
|
64331
64371
|
adapt(raw) {
|
|
64332
|
-
if (!isRecord$
|
|
64372
|
+
if (!isRecord$6(raw)) return [];
|
|
64333
64373
|
this.captureSessionId(raw);
|
|
64334
64374
|
switch (raw.type) {
|
|
64335
64375
|
case "system": return this.handleSystem(raw);
|
|
@@ -64374,7 +64414,7 @@ var AmpAdapter = class {
|
|
|
64374
64414
|
return [this.makeEvent("stream_start", this.getStreamStartData())];
|
|
64375
64415
|
}
|
|
64376
64416
|
handleAssistant(raw) {
|
|
64377
|
-
const message = isRecord$
|
|
64417
|
+
const message = isRecord$6(raw.message) ? raw.message : void 0;
|
|
64378
64418
|
const content = Array.isArray(message?.content) ? message.content : typeof message?.content === "string" ? [{
|
|
64379
64419
|
text: message.content,
|
|
64380
64420
|
type: "text"
|
|
@@ -64384,7 +64424,7 @@ var AmpAdapter = class {
|
|
|
64384
64424
|
const events = this.openMainAssistantTurn();
|
|
64385
64425
|
const turnKey = `main:${this.stepIndex}`;
|
|
64386
64426
|
for (const block of content) {
|
|
64387
|
-
if (!isRecord$
|
|
64427
|
+
if (!isRecord$6(block)) continue;
|
|
64388
64428
|
if (block.type === "thinking" && typeof block.thinking === "string" && block.thinking) {
|
|
64389
64429
|
events.push(this.makeEvent("stream_chunk", {
|
|
64390
64430
|
chunkType: "reasoning",
|
|
@@ -64402,7 +64442,7 @@ var AmpAdapter = class {
|
|
|
64402
64442
|
if (block.type === "tool_use") {
|
|
64403
64443
|
const tool = toToolPayload$2(block);
|
|
64404
64444
|
if (!tool) continue;
|
|
64405
|
-
if (isRecord$
|
|
64445
|
+
if (isRecord$6(block.input)) this.mainToolInputsById.set(tool.id, block.input);
|
|
64406
64446
|
events.push(...this.emitToolCall(tool, turnKey));
|
|
64407
64447
|
}
|
|
64408
64448
|
}
|
|
@@ -64425,7 +64465,7 @@ var AmpAdapter = class {
|
|
|
64425
64465
|
const turnKey = `subagent:${subagentMessageId}`;
|
|
64426
64466
|
const events = [];
|
|
64427
64467
|
for (const block of content) {
|
|
64428
|
-
if (!isRecord$
|
|
64468
|
+
if (!isRecord$6(block)) continue;
|
|
64429
64469
|
if (block.type === "thinking" && typeof block.thinking === "string" && block.thinking) {
|
|
64430
64470
|
events.push(this.makeEvent("stream_chunk", {
|
|
64431
64471
|
chunkType: "reasoning",
|
|
@@ -64459,13 +64499,13 @@ var AmpAdapter = class {
|
|
|
64459
64499
|
return events;
|
|
64460
64500
|
}
|
|
64461
64501
|
handleUser(raw) {
|
|
64462
|
-
const message = isRecord$
|
|
64502
|
+
const message = isRecord$6(raw.message) ? raw.message : void 0;
|
|
64463
64503
|
if (!Array.isArray(message?.content)) return [];
|
|
64464
64504
|
const parentToolCallId = typeof raw.parent_tool_use_id === "string" ? raw.parent_tool_use_id : void 0;
|
|
64465
64505
|
const subagent = parentToolCallId ? { parentToolCallId } : void 0;
|
|
64466
64506
|
const events = [];
|
|
64467
64507
|
for (const block of message.content) {
|
|
64468
|
-
if (!isRecord$
|
|
64508
|
+
if (!isRecord$6(block) || block.type !== "tool_result") continue;
|
|
64469
64509
|
if (typeof block.tool_use_id !== "string") continue;
|
|
64470
64510
|
const toolCallId = block.tool_use_id;
|
|
64471
64511
|
const normalized = normalizeToolResult$1(block.content);
|
|
@@ -64557,7 +64597,7 @@ var AmpAdapter = class {
|
|
|
64557
64597
|
const spawnMetadata = this.buildSpawnMetadata(parentToolCallId);
|
|
64558
64598
|
if (!spawnMetadata) return;
|
|
64559
64599
|
const firstEvent = events[0];
|
|
64560
|
-
const firstSubagent = isRecord$
|
|
64600
|
+
const firstSubagent = isRecord$6(firstEvent.data?.subagent) ? firstEvent.data.subagent : { parentToolCallId };
|
|
64561
64601
|
firstEvent.data = {
|
|
64562
64602
|
...firstEvent.data,
|
|
64563
64603
|
subagent: {
|
|
@@ -64709,7 +64749,7 @@ init_object$1();
|
|
|
64709
64749
|
const IDENTIFIER = "antigravity";
|
|
64710
64750
|
const tokenCount = (value) => typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : 0;
|
|
64711
64751
|
const extractUsage = (raw) => {
|
|
64712
|
-
if (!isRecord$
|
|
64752
|
+
if (!isRecord$8(raw)) return;
|
|
64713
64753
|
const inputCacheMissTokens = tokenCount(raw.input_tokens);
|
|
64714
64754
|
const inputCachedTokens = tokenCount(raw.cache_read_tokens);
|
|
64715
64755
|
const totalOutputTokens = tokenCount(raw.output_tokens);
|
|
@@ -64748,14 +64788,14 @@ var AntigravityAdapter = class {
|
|
|
64748
64788
|
toolSinceResponse = false;
|
|
64749
64789
|
usageByStep = /* @__PURE__ */ new Map();
|
|
64750
64790
|
adapt(raw) {
|
|
64751
|
-
if (this.flushed || this.resultReceived || !isRecord$
|
|
64791
|
+
if (this.flushed || this.resultReceived || !isRecord$8(raw)) return [];
|
|
64752
64792
|
if (raw.event === "init") {
|
|
64753
64793
|
this.sessionId = pickString$1(raw.conversation_id);
|
|
64754
64794
|
this.model = pickString$1(toRecord(raw.init)?.model);
|
|
64755
64795
|
return this.openStream();
|
|
64756
64796
|
}
|
|
64757
|
-
if (raw.event === "result" && isRecord$
|
|
64758
|
-
if (raw.event !== "step_update" || !isRecord$
|
|
64797
|
+
if (raw.event === "result" && isRecord$8(raw.result)) return this.handleResult(raw.result);
|
|
64798
|
+
if (raw.event !== "step_update" || !isRecord$8(raw.step_update)) return [];
|
|
64759
64799
|
const step = raw.step_update;
|
|
64760
64800
|
const index = step.step_index;
|
|
64761
64801
|
if (typeof index !== "number" || !Number.isSafeInteger(index) || index < 0) return [];
|
|
@@ -64781,7 +64821,7 @@ var AntigravityAdapter = class {
|
|
|
64781
64821
|
content: step.text_delta
|
|
64782
64822
|
}));
|
|
64783
64823
|
}
|
|
64784
|
-
} else if (step.step_type === "tool" || isRecord$
|
|
64824
|
+
} else if (step.step_type === "tool" || isRecord$8(step.subagent_info)) events.push(...this.handleTool(index, step));
|
|
64785
64825
|
if (step.state === "DONE") {
|
|
64786
64826
|
this.completedSteps.add(index);
|
|
64787
64827
|
const usage = extractUsage(step.usage);
|
|
@@ -66805,7 +66845,7 @@ const synthesizeFileChangePluginState = (item) => {
|
|
|
66805
66845
|
linesDeleted: item.linesDeleted ?? 0
|
|
66806
66846
|
};
|
|
66807
66847
|
};
|
|
66808
|
-
const isRecord$
|
|
66848
|
+
const isRecord$5 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
66809
66849
|
const stringifyUnknown$1 = (value) => {
|
|
66810
66850
|
if (typeof value === "string") return value;
|
|
66811
66851
|
if (value === void 0 || value === null) return "";
|
|
@@ -66826,7 +66866,7 @@ const getFirstStringFromArray = (value) => {
|
|
|
66826
66866
|
const getWebSearchActionQuery = (action) => getRecordString(action, "query")?.trim() || getFirstStringFromArray(action.queries);
|
|
66827
66867
|
const getWebSearchQuery = (item) => {
|
|
66828
66868
|
if (typeof item.query === "string" && item.query.trim()) return item.query.trim();
|
|
66829
|
-
return isRecord$
|
|
66869
|
+
return isRecord$5(item.action) ? getWebSearchActionQuery(item.action) : void 0;
|
|
66830
66870
|
};
|
|
66831
66871
|
const synthesizeWebSearchPluginState = (item) => {
|
|
66832
66872
|
const query = getWebSearchQuery(item);
|
|
@@ -66838,7 +66878,7 @@ const synthesizeWebSearchPluginState = (item) => {
|
|
|
66838
66878
|
};
|
|
66839
66879
|
};
|
|
66840
66880
|
const unwrapMcpResultEnvelope = (value) => {
|
|
66841
|
-
if (!isRecord$
|
|
66881
|
+
if (!isRecord$5(value)) return value;
|
|
66842
66882
|
if ("Ok" in value) return value.Ok;
|
|
66843
66883
|
if ("Err" in value) return value.Err;
|
|
66844
66884
|
if ("ok" in value) return value.ok;
|
|
@@ -66846,7 +66886,7 @@ const unwrapMcpResultEnvelope = (value) => {
|
|
|
66846
66886
|
};
|
|
66847
66887
|
const getMcpContentItemText = (item) => {
|
|
66848
66888
|
if (typeof item === "string") return item;
|
|
66849
|
-
if (!isRecord$
|
|
66889
|
+
if (!isRecord$5(item)) return stringifyUnknown$1(item);
|
|
66850
66890
|
const text = getRecordString(item, "text") || getRecordString(item, "content");
|
|
66851
66891
|
if (text) return text;
|
|
66852
66892
|
return stringifyUnknown$1(item);
|
|
@@ -66854,7 +66894,7 @@ const getMcpContentItemText = (item) => {
|
|
|
66854
66894
|
const getMcpResultContent = (item) => {
|
|
66855
66895
|
const result = unwrapMcpResultEnvelope(item.result);
|
|
66856
66896
|
if (Array.isArray(result)) return result.map(getMcpContentItemText).filter(Boolean).join("\n\n");
|
|
66857
|
-
if (isRecord$
|
|
66897
|
+
if (isRecord$5(result)) {
|
|
66858
66898
|
if (Array.isArray(result.content)) return result.content.map(getMcpContentItemText).filter(Boolean).join("\n\n");
|
|
66859
66899
|
const text = getRecordString(result, "text") || getRecordString(result, "output");
|
|
66860
66900
|
if (text) return text;
|
|
@@ -66863,16 +66903,16 @@ const getMcpResultContent = (item) => {
|
|
|
66863
66903
|
};
|
|
66864
66904
|
const getMcpErrorContent = (item) => {
|
|
66865
66905
|
const error = item.error || unwrapMcpResultEnvelope(item.result);
|
|
66866
|
-
if (isRecord$
|
|
66906
|
+
if (isRecord$5(error)) return getRecordString(error, "message") || getRecordString(error, "error") || stringifyUnknown$1(error);
|
|
66867
66907
|
return stringifyUnknown$1(error);
|
|
66868
66908
|
};
|
|
66869
66909
|
const hasMcpResultError = (item) => {
|
|
66870
66910
|
if (item.error) return true;
|
|
66871
66911
|
const result = item.result;
|
|
66872
|
-
if (!isRecord$
|
|
66912
|
+
if (!isRecord$5(result)) return false;
|
|
66873
66913
|
if ("Err" in result) return true;
|
|
66874
66914
|
const ok = unwrapMcpResultEnvelope(result);
|
|
66875
|
-
return isRecord$
|
|
66915
|
+
return isRecord$5(ok) && ok.isError === true;
|
|
66876
66916
|
};
|
|
66877
66917
|
const synthesizeMcpToolPluginState = (item) => ({
|
|
66878
66918
|
arguments: item.arguments,
|
|
@@ -67524,10 +67564,10 @@ var AcpStreamLifecycle = class {
|
|
|
67524
67564
|
*/
|
|
67525
67565
|
const acpContentBlockText = (value) => {
|
|
67526
67566
|
if (typeof value === "string") return value;
|
|
67527
|
-
if (!isRecord$
|
|
67567
|
+
if (!isRecord$8(value)) return "";
|
|
67528
67568
|
if (value.type === "text" && typeof value.text === "string") return value.text;
|
|
67529
67569
|
if (typeof value.content === "string") return value.content;
|
|
67530
|
-
if (isRecord$
|
|
67570
|
+
if (isRecord$8(value.content)) return acpContentBlockText(value.content);
|
|
67531
67571
|
if (typeof value.diff === "string") return value.diff;
|
|
67532
67572
|
if (typeof value.output === "string") return value.output;
|
|
67533
67573
|
return "";
|
|
@@ -67773,7 +67813,7 @@ var TraeAcpAdapter = class {
|
|
|
67773
67813
|
* Returns `undefined` when required fields are missing or invalid.
|
|
67774
67814
|
*/
|
|
67775
67815
|
toUsageData(usage) {
|
|
67776
|
-
if (!isRecord$
|
|
67816
|
+
if (!isRecord$8(usage)) return;
|
|
67777
67817
|
const total = toFiniteNumber$2(usage.totalTokens) ?? toFiniteNumber$2(usage.total_tokens);
|
|
67778
67818
|
const input = toFiniteNumber$2(usage.inputTokens) ?? toFiniteNumber$2(usage.input_tokens);
|
|
67779
67819
|
const output = toFiniteNumber$2(usage.outputTokens) ?? toFiniteNumber$2(usage.output_tokens);
|
|
@@ -67804,7 +67844,7 @@ var TraeAcpAdapter = class {
|
|
|
67804
67844
|
extractUsageFromUsageUpdate(_raw) {}
|
|
67805
67845
|
/** Extract a USD cost amount from an ACP `cost` object. */
|
|
67806
67846
|
toCostUsd(cost) {
|
|
67807
|
-
if (!isRecord$
|
|
67847
|
+
if (!isRecord$8(cost)) return;
|
|
67808
67848
|
if (cost.currency !== "USD") return;
|
|
67809
67849
|
const amount = toFiniteNumber$2(cost.amount);
|
|
67810
67850
|
if (amount === void 0 || amount <= 0) return;
|
|
@@ -67861,16 +67901,16 @@ var CopilotAcpAdapter = class extends TraeAcpAdapter {
|
|
|
67861
67901
|
init_config();
|
|
67862
67902
|
const CURSOR_CONFIG = getHeterogeneousAgentConfigOrThrow("cursor");
|
|
67863
67903
|
const INCOMPLETE_TOOL_MESSAGE = "Cursor ended before the tool call completed.";
|
|
67864
|
-
const isRecord$
|
|
67904
|
+
const isRecord$4 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
67865
67905
|
const serialize$1 = (value, fallback = "") => typeof value === "string" ? value : value === void 0 ? fallback : JSON.stringify(value);
|
|
67866
67906
|
const readAssistantText = (message) => {
|
|
67867
|
-
if (!isRecord$
|
|
67868
|
-
return message.content.filter((block) => isRecord$
|
|
67907
|
+
if (!isRecord$4(message) || !Array.isArray(message.content)) return "";
|
|
67908
|
+
return message.content.filter((block) => isRecord$4(block) && block.type === "text" && typeof block.text === "string").map((block) => block.text).join("");
|
|
67869
67909
|
};
|
|
67870
67910
|
const readTool = (value) => {
|
|
67871
|
-
if (!isRecord$
|
|
67911
|
+
if (!isRecord$4(value)) return;
|
|
67872
67912
|
const [apiName, details] = Object.entries(value)[0] ?? [];
|
|
67873
|
-
if (!apiName || !isRecord$
|
|
67913
|
+
if (!apiName || !isRecord$4(details)) return;
|
|
67874
67914
|
if (apiName === "function") return {
|
|
67875
67915
|
apiName: typeof details.name === "string" && details.name ? details.name : "function",
|
|
67876
67916
|
arguments: serialize$1(details.arguments, "{}"),
|
|
@@ -67883,7 +67923,7 @@ const readTool = (value) => {
|
|
|
67883
67923
|
};
|
|
67884
67924
|
};
|
|
67885
67925
|
const readContent = (value) => {
|
|
67886
|
-
if (isRecord$
|
|
67926
|
+
if (isRecord$4(value)) {
|
|
67887
67927
|
if (typeof value.content === "string") return value.content;
|
|
67888
67928
|
if (typeof value.message === "string") return value.message;
|
|
67889
67929
|
if (typeof value.error === "string") return value.error;
|
|
@@ -67891,7 +67931,7 @@ const readContent = (value) => {
|
|
|
67891
67931
|
return serialize$1(value);
|
|
67892
67932
|
};
|
|
67893
67933
|
const readResult = (value) => {
|
|
67894
|
-
if (!isRecord$
|
|
67934
|
+
if (!isRecord$4(value)) return {
|
|
67895
67935
|
content: readContent(value),
|
|
67896
67936
|
isError: false
|
|
67897
67937
|
};
|
|
@@ -67927,7 +67967,7 @@ var CursorAdapter = class {
|
|
|
67927
67967
|
streamOpen = false;
|
|
67928
67968
|
terminal = false;
|
|
67929
67969
|
adapt(raw) {
|
|
67930
|
-
if (!isRecord$
|
|
67970
|
+
if (!isRecord$4(raw) || this.terminal) return [];
|
|
67931
67971
|
if (typeof raw.session_id === "string") this.sessionId = raw.session_id;
|
|
67932
67972
|
if (raw.type === "system" && raw.subtype === "init") {
|
|
67933
67973
|
if (typeof raw.model === "string") this.model = raw.model;
|
|
@@ -68144,7 +68184,7 @@ var DevinAcpAdapter = class extends TraeAcpAdapter {
|
|
|
68144
68184
|
});
|
|
68145
68185
|
}
|
|
68146
68186
|
extractUsageFromUsageUpdate(raw) {
|
|
68147
|
-
const meta = isRecord$
|
|
68187
|
+
const meta = isRecord$8(raw._meta) ? raw._meta : void 0;
|
|
68148
68188
|
if (!meta) return;
|
|
68149
68189
|
const input = toFiniteNumber$1(meta["cognition.ai/inputTokens"]);
|
|
68150
68190
|
const output = toFiniteNumber$1(meta["cognition.ai/outputTokens"]);
|
|
@@ -68203,7 +68243,7 @@ const GROK_BUILD_IDENTIFIER = "grok-build";
|
|
|
68203
68243
|
const GROK_BUILD_AUTH_DOCS_URL = getHeterogeneousAgentConfigOrThrow(GROK_BUILD_IDENTIFIER).auth.docsUrl;
|
|
68204
68244
|
const finiteNumber$2 = (value) => typeof value === "number" && Number.isFinite(value) ? value : 0;
|
|
68205
68245
|
const toUsageData$2 = (usage) => {
|
|
68206
|
-
if (!isRecord$
|
|
68246
|
+
if (!isRecord$8(usage)) return;
|
|
68207
68247
|
const value = usage;
|
|
68208
68248
|
const input = finiteNumber$2(value.inputTokens ?? value.input_tokens);
|
|
68209
68249
|
const output = finiteNumber$2(value.outputTokens ?? value.output_tokens);
|
|
@@ -68252,20 +68292,20 @@ var GrokBuildAdapter = class {
|
|
|
68252
68292
|
toolPayloadById = /* @__PURE__ */ new Map();
|
|
68253
68293
|
toolResultStateById = /* @__PURE__ */ new Map();
|
|
68254
68294
|
adapt(raw) {
|
|
68255
|
-
if (!isRecord$
|
|
68295
|
+
if (!isRecord$8(raw) || isAcpReplayMessage(raw)) return [];
|
|
68256
68296
|
const eventId = acpEventIdOf(raw);
|
|
68257
68297
|
if (eventId) {
|
|
68258
68298
|
if (this.seenEventIds.has(eventId)) return [];
|
|
68259
68299
|
this.seenEventIds.add(eventId);
|
|
68260
68300
|
}
|
|
68261
|
-
if (isRecord$
|
|
68262
|
-
if (isRecord$
|
|
68301
|
+
if (isRecord$8(raw.result) && typeof raw.result.sessionId === "string") this.sessionId = raw.result.sessionId;
|
|
68302
|
+
if (isRecord$8(raw.error)) {
|
|
68263
68303
|
const requestMethod = typeof raw.requestMethod === "string" ? raw.requestMethod : void 0;
|
|
68264
68304
|
return this.handleRpcError(raw.error, requestMethod);
|
|
68265
68305
|
}
|
|
68266
68306
|
if (raw.method === "x.ai/session/prompt_complete") return this.handlePromptComplete(raw.params);
|
|
68267
68307
|
if (raw.method === "session/update" || raw.method === "x.ai/session_notification" || raw.method === "x.ai/session/update" || raw.method === "_x.ai/session/update") return this.handleNotification(raw.params);
|
|
68268
|
-
if (isRecord$
|
|
68308
|
+
if (isRecord$8(raw.result) && typeof raw.result.stopReason === "string") return this.handlePromptResult(raw.result);
|
|
68269
68309
|
return [];
|
|
68270
68310
|
}
|
|
68271
68311
|
flush() {
|
|
@@ -68273,9 +68313,9 @@ var GrokBuildAdapter = class {
|
|
|
68273
68313
|
return this.stream.closeStream();
|
|
68274
68314
|
}
|
|
68275
68315
|
handleNotification(paramsValue) {
|
|
68276
|
-
if (!isRecord$
|
|
68316
|
+
if (!isRecord$8(paramsValue)) return [];
|
|
68277
68317
|
if (typeof paramsValue.sessionId === "string") this.sessionId = paramsValue.sessionId;
|
|
68278
|
-
const update = isRecord$
|
|
68318
|
+
const update = isRecord$8(paramsValue.update) ? paramsValue.update : void 0;
|
|
68279
68319
|
if (!update || typeof update.sessionUpdate !== "string") return [];
|
|
68280
68320
|
switch (update.sessionUpdate) {
|
|
68281
68321
|
case "agent_message_chunk": {
|
|
@@ -68366,7 +68406,7 @@ var GrokBuildAdapter = class {
|
|
|
68366
68406
|
return state;
|
|
68367
68407
|
}
|
|
68368
68408
|
handlePromptComplete(paramsValue) {
|
|
68369
|
-
if (!isRecord$
|
|
68409
|
+
if (!isRecord$8(paramsValue)) return [];
|
|
68370
68410
|
if (typeof paramsValue.sessionId === "string") this.sessionId = paramsValue.sessionId;
|
|
68371
68411
|
return [];
|
|
68372
68412
|
}
|
|
@@ -68388,7 +68428,7 @@ var GrokBuildAdapter = class {
|
|
|
68388
68428
|
handlePromptResult(result) {
|
|
68389
68429
|
if (this.settled) return [];
|
|
68390
68430
|
this.settled = true;
|
|
68391
|
-
const meta = isRecord$
|
|
68431
|
+
const meta = isRecord$8(result._meta) ? result._meta : void 0;
|
|
68392
68432
|
const usage = toUsageData$2(meta?.usage ?? meta);
|
|
68393
68433
|
const model = typeof meta?.modelId === "string" ? meta.modelId : void 0;
|
|
68394
68434
|
const turnUsage = this.lastTurnUsage?.stepIndex === this.stream.stepIndex ? this.lastTurnUsage.usage : void 0;
|
|
@@ -69744,18 +69784,18 @@ const createCodexImageOutputReader = (options) => {
|
|
|
69744
69784
|
};
|
|
69745
69785
|
const readImageOutputs = async (source, startedAt) => {
|
|
69746
69786
|
const records = parseJsonlRecords(await readFile(source, "utf8"));
|
|
69747
|
-
const turnStart = records.findLastIndex((record) => isRecord$
|
|
69787
|
+
const turnStart = records.findLastIndex((record) => isRecord$8(record) && record.type === "event_msg" && isRecord$8(record.payload) && record.payload.type === "task_started");
|
|
69748
69788
|
const timestamp = records[turnStart]?.timestamp;
|
|
69749
69789
|
const turnStartedAt = typeof timestamp === "string" ? Date.parse(timestamp) : NaN;
|
|
69750
69790
|
if (!Number.isFinite(turnStartedAt) || turnStartedAt < startedAt) return [];
|
|
69751
69791
|
const outputs = /* @__PURE__ */ new Map();
|
|
69752
69792
|
for (const record of records.slice(turnStart + 1)) {
|
|
69753
|
-
if (!isRecord$
|
|
69793
|
+
if (!isRecord$8(record)) continue;
|
|
69754
69794
|
const payload = record.payload;
|
|
69755
|
-
if (record.type !== "response_item" || !isRecord$
|
|
69795
|
+
if (record.type !== "response_item" || !isRecord$8(payload) || payload.type !== "custom_tool_call_output" && payload.type !== "function_call_output" || typeof payload.call_id !== "string" || !Array.isArray(payload.output)) continue;
|
|
69756
69796
|
const images = [];
|
|
69757
69797
|
for (const block of payload.output) {
|
|
69758
|
-
if (!isRecord$
|
|
69798
|
+
if (!isRecord$8(block) || block.type !== "input_image" || typeof block.image_url !== "string") continue;
|
|
69759
69799
|
const match = /^data:(image\/[\w.+-]+);base64,([\s\S]+)$/.exec(block.image_url);
|
|
69760
69800
|
if (match) images.push({
|
|
69761
69801
|
data: match[2],
|
|
@@ -70254,9 +70294,9 @@ init_object$1();
|
|
|
70254
70294
|
const DEFAULT_CANCEL_GRACE_MS = 2e3;
|
|
70255
70295
|
/** Parse the `options` array of a `session/request_permission` request. */
|
|
70256
70296
|
const parseAcpPermissionOptions = (params) => {
|
|
70257
|
-
const options = isRecord$
|
|
70297
|
+
const options = isRecord$8(params) ? params.options : void 0;
|
|
70258
70298
|
if (!Array.isArray(options)) return [];
|
|
70259
|
-
return options.flatMap((value) => isRecord$
|
|
70299
|
+
return options.flatMap((value) => isRecord$8(value) ? [value] : []);
|
|
70260
70300
|
};
|
|
70261
70301
|
/**
|
|
70262
70302
|
* Pick a permission option by ordered preference tiers. Returns the winning
|
|
@@ -70539,6 +70579,718 @@ const classifyHeteroProcessFailure = (params) => {
|
|
|
70539
70579
|
});
|
|
70540
70580
|
};
|
|
70541
70581
|
|
|
70582
|
+
//#endregion
|
|
70583
|
+
//#region ../../packages/heterogeneous-agents/src/claudeCodePermission/mode.ts
|
|
70584
|
+
/**
|
|
70585
|
+
* The mode Claude Code can actually run in: as root, `bypassPermissions` falls
|
|
70586
|
+
* back to `acceptEdits`. Pure (the caller says whether it runs as root), so the
|
|
70587
|
+
* browser-safe mode report can use it.
|
|
70588
|
+
*/
|
|
70589
|
+
const resolveClaudeCodePermissionMode = (mode, isRoot = false) => isRoot && mode === "bypassPermissions" ? {
|
|
70590
|
+
fallback: "root",
|
|
70591
|
+
mode: "acceptEdits"
|
|
70592
|
+
} : { mode };
|
|
70593
|
+
|
|
70594
|
+
//#endregion
|
|
70595
|
+
//#region ../../packages/heterogeneous-agents/src/claudeCodePermission/args.ts
|
|
70596
|
+
/**
|
|
70597
|
+
* Tools pre-approved for a root run with the lab off, where nobody can answer a
|
|
70598
|
+
* prompt. Never with a mode: an allow rule outlives a later switch to a
|
|
70599
|
+
* stricter mode (`set_permission_mode` keeps it), so it would silently approve
|
|
70600
|
+
* what the user then asked to be asked about.
|
|
70601
|
+
*/
|
|
70602
|
+
const ROOT_PRE_APPROVED_TOOLS = "Bash,Read,Write,Edit,MultiEdit,WebSearch,mcp__*";
|
|
70603
|
+
/** Claude Code refuses `bypassPermissions` as root (a cloud sandbox). */
|
|
70604
|
+
const isRunningAsRoot = () => process.getuid?.() === 0;
|
|
70605
|
+
/**
|
|
70606
|
+
* Claude Code permission flags for one spawn, shared by every CLI host
|
|
70607
|
+
* (desktop IPC, `lh hetero exec`).
|
|
70608
|
+
*
|
|
70609
|
+
* - No `mode` (Better Coding Experience lab off): every action is allowed, as
|
|
70610
|
+
* before — `bypassPermissions`, or `acceptEdits` with the common tools
|
|
70611
|
+
* pre-approved as root. Nothing asks the host.
|
|
70612
|
+
* - With a `mode`: Claude Code asks the host over stdio
|
|
70613
|
+
* (`--permission-prompt-tool stdio`) whenever the mode wants a decision.
|
|
70614
|
+
* `--allow-dangerously-skip-permissions` only PERMITS a later switch to
|
|
70615
|
+
* `bypassPermissions` (the mode chip, approving a plan with "don't ask
|
|
70616
|
+
* again"): without it Claude Code silently turns that switch into `default`.
|
|
70617
|
+
* Root never gets it, since Claude Code refuses it there; root's stand-in
|
|
70618
|
+
* for `bypassPermissions` is plain `acceptEdits`, asking before commands.
|
|
70619
|
+
* - With a `mode` but no host to answer prompts (`hostPrompts: false`, e.g.
|
|
70620
|
+
* the card bridge failed to start): fail closed. The mode still applies and
|
|
70621
|
+
* print mode denies whatever it would have asked about; it never falls back
|
|
70622
|
+
* to allowing everything.
|
|
70623
|
+
*/
|
|
70624
|
+
const buildClaudeCodePermissionArgs = ({ hostPrompts = true, isRoot = isRunningAsRoot(), mode }) => {
|
|
70625
|
+
if (!mode) return isRoot ? [
|
|
70626
|
+
"--permission-mode",
|
|
70627
|
+
"acceptEdits",
|
|
70628
|
+
"--allowed-tools",
|
|
70629
|
+
ROOT_PRE_APPROVED_TOOLS
|
|
70630
|
+
] : ["--permission-mode", "bypassPermissions"];
|
|
70631
|
+
const resolved = resolveClaudeCodePermissionMode(mode, isRoot);
|
|
70632
|
+
if (!hostPrompts) return ["--permission-mode", resolved.mode];
|
|
70633
|
+
return [
|
|
70634
|
+
"--permission-mode",
|
|
70635
|
+
resolved.mode,
|
|
70636
|
+
"--permission-prompt-tool",
|
|
70637
|
+
"stdio",
|
|
70638
|
+
...isRoot ? [] : ["--allow-dangerously-skip-permissions"]
|
|
70639
|
+
];
|
|
70640
|
+
};
|
|
70641
|
+
|
|
70642
|
+
//#endregion
|
|
70643
|
+
//#region ../../packages/heterogeneous-agents/src/claudeCodePermission/modeReport.ts
|
|
70644
|
+
init_src$2();
|
|
70645
|
+
/** `step_complete` phase carrying the mode Claude Code reports it is in. */
|
|
70646
|
+
const PERMISSION_MODE_PHASE = "permission_mode";
|
|
70647
|
+
/**
|
|
70648
|
+
* The permission mode a Claude Code record reports: `system:init` at each
|
|
70649
|
+
* turn, `system:status` after a switch (the host's, or Claude Code's own when
|
|
70650
|
+
* a plan is approved). A mode not offered here (`dontAsk`) reports nothing.
|
|
70651
|
+
*/
|
|
70652
|
+
const readClaudeCodePermissionMode = (message) => {
|
|
70653
|
+
if (typeof message !== "object" || message === null) return;
|
|
70654
|
+
const record = message;
|
|
70655
|
+
if (record.type !== "system" || record.subtype !== "init" && record.subtype !== "status") return;
|
|
70656
|
+
if (record.parent_tool_use_id) return;
|
|
70657
|
+
return isHeteroPermissionMode(record.permissionMode) ? record.permissionMode : void 0;
|
|
70658
|
+
};
|
|
70659
|
+
/**
|
|
70660
|
+
* Turns Claude Code's mode reports into `step_complete` events, one per
|
|
70661
|
+
* change. Rides `step_complete` like other advisory phases, so the gateway
|
|
70662
|
+
* needs no change and consumers that do not know it ignore it.
|
|
70663
|
+
*/
|
|
70664
|
+
var PermissionModeReporter = class {
|
|
70665
|
+
last;
|
|
70666
|
+
/** Why the session started outside the picked mode; dropped once it leaves that mode. */
|
|
70667
|
+
fallback;
|
|
70668
|
+
constructor(operationId, fallback) {
|
|
70669
|
+
this.operationId = operationId;
|
|
70670
|
+
this.fallback = fallback;
|
|
70671
|
+
}
|
|
70672
|
+
/**
|
|
70673
|
+
* The user switched the running session to `mode`. Reports from now on
|
|
70674
|
+
* explain against that pick: as root a bypass pick runs as `acceptEdits`
|
|
70675
|
+
* with the root fallback, so the topic keeps the pick instead of taking
|
|
70676
|
+
* `acceptEdits`. The next report is emitted even if the mode is unchanged.
|
|
70677
|
+
*/
|
|
70678
|
+
requested(mode, isRoot) {
|
|
70679
|
+
this.fallback = resolveClaudeCodePermissionMode(mode, isRoot).fallback;
|
|
70680
|
+
this.last = void 0;
|
|
70681
|
+
}
|
|
70682
|
+
/** The event for a record that reports a new mode, else undefined. */
|
|
70683
|
+
observe(message, stepIndex = 0) {
|
|
70684
|
+
const mode = readClaudeCodePermissionMode(message);
|
|
70685
|
+
if (!mode || mode === this.last) return;
|
|
70686
|
+
this.last = mode;
|
|
70687
|
+
if (this.fallback === "root" && mode !== "acceptEdits") this.fallback = void 0;
|
|
70688
|
+
return {
|
|
70689
|
+
data: {
|
|
70690
|
+
fallback: this.fallback ?? null,
|
|
70691
|
+
permissionMode: mode,
|
|
70692
|
+
phase: PERMISSION_MODE_PHASE
|
|
70693
|
+
},
|
|
70694
|
+
operationId: this.operationId,
|
|
70695
|
+
stepIndex,
|
|
70696
|
+
timestamp: Date.now(),
|
|
70697
|
+
type: "step_complete"
|
|
70698
|
+
};
|
|
70699
|
+
}
|
|
70700
|
+
};
|
|
70701
|
+
|
|
70702
|
+
//#endregion
|
|
70703
|
+
//#region ../../packages/heterogeneous-agents/src/claudeCodePermission/request.ts
|
|
70704
|
+
const CLAUDE_CODE_PERMISSION_OPTION = {
|
|
70705
|
+
allow: "allow",
|
|
70706
|
+
allowSession: "allow_session",
|
|
70707
|
+
approveAcceptEdits: "approve_accept_edits",
|
|
70708
|
+
approveBypass: "approve_bypass",
|
|
70709
|
+
approveDefault: "approve_default",
|
|
70710
|
+
deny: "deny",
|
|
70711
|
+
keepPlanning: "keep_planning"
|
|
70712
|
+
};
|
|
70713
|
+
/** Answer key for the note a user adds to a denial or to "keep planning". */
|
|
70714
|
+
const CLAUDE_CODE_PERMISSION_NOTE_KEY = "__note";
|
|
70715
|
+
const MAX_PREVIEW_CHARS = 2e3;
|
|
70716
|
+
/** Review surfaces accept at most this much question text. */
|
|
70717
|
+
const MAX_QUESTION_CHARS = 4e3;
|
|
70718
|
+
const OPTION_LABELS = {
|
|
70719
|
+
allow: "Allow",
|
|
70720
|
+
allow_session: "Always allow in this session",
|
|
70721
|
+
approve_accept_edits: "Approve and auto-accept edits",
|
|
70722
|
+
approve_bypass: "Approve and don't ask again",
|
|
70723
|
+
approve_default: "Approve and ask before each edit",
|
|
70724
|
+
deny: "Deny",
|
|
70725
|
+
keep_planning: "Keep planning"
|
|
70726
|
+
};
|
|
70727
|
+
const isRecord$3 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
70728
|
+
const optionalString = (value) => typeof value === "string" && value.length > 0 ? value : void 0;
|
|
70729
|
+
const cut = (text, max) => text.length > max ? `${text.slice(0, max - 1)}…` : text;
|
|
70730
|
+
/** The `can_use_tool` request in a parsed stdout line, if it is one. */
|
|
70731
|
+
const parseClaudeCodePermissionRequest = (message) => {
|
|
70732
|
+
if (!isRecord$3(message) || message.type !== "control_request") return;
|
|
70733
|
+
const request = message.request;
|
|
70734
|
+
if (!isRecord$3(request) || request.subtype !== "can_use_tool") return;
|
|
70735
|
+
if (typeof message.request_id !== "string" || typeof request.tool_name !== "string") return;
|
|
70736
|
+
return fromCanUseTool(message.request_id, request.tool_name, request.input, {
|
|
70737
|
+
blockedPath: request.blocked_path,
|
|
70738
|
+
decisionReason: request.decision_reason,
|
|
70739
|
+
description: request.description,
|
|
70740
|
+
displayName: request.display_name,
|
|
70741
|
+
suggestions: request.permission_suggestions,
|
|
70742
|
+
title: request.title,
|
|
70743
|
+
toolUseId: request.tool_use_id
|
|
70744
|
+
});
|
|
70745
|
+
};
|
|
70746
|
+
/** The same request as the SDK's `canUseTool` callback receives it. */
|
|
70747
|
+
const fromCanUseTool = (requestId, toolName, input, extra) => ({
|
|
70748
|
+
blockedPath: optionalString(extra.blockedPath),
|
|
70749
|
+
decisionReason: optionalString(extra.decisionReason),
|
|
70750
|
+
description: optionalString(extra.description),
|
|
70751
|
+
displayName: optionalString(extra.displayName),
|
|
70752
|
+
input: isRecord$3(input) ? input : {},
|
|
70753
|
+
requestId,
|
|
70754
|
+
suggestions: Array.isArray(extra.suggestions) ? extra.suggestions.filter((entry) => isRecord$3(entry) && typeof entry.type === "string") : void 0,
|
|
70755
|
+
title: optionalString(extra.title),
|
|
70756
|
+
toolName,
|
|
70757
|
+
toolUseId: optionalString(extra.toolUseId)
|
|
70758
|
+
});
|
|
70759
|
+
const classifyClaudeCodePermission = (toolName) => toolName === "ExitPlanMode" ? "exitPlan" : toolName === "EnterPlanMode" ? "enterPlan" : "tool";
|
|
70760
|
+
const previewInput = (input) => Object.fromEntries(Object.entries(input).map(([key, value]) => [key, typeof value === "string" ? cut(value, MAX_PREVIEW_CHARS) : value]));
|
|
70761
|
+
const readAllowedPrompts = (input) => {
|
|
70762
|
+
if (!Array.isArray(input.allowedPrompts)) return;
|
|
70763
|
+
const prompts = input.allowedPrompts.flatMap((entry) => isRecord$3(entry) && typeof entry.prompt === "string" ? [{
|
|
70764
|
+
prompt: entry.prompt,
|
|
70765
|
+
tool: typeof entry.tool === "string" ? entry.tool : "Bash"
|
|
70766
|
+
}] : []);
|
|
70767
|
+
return prompts.length > 0 ? prompts : void 0;
|
|
70768
|
+
};
|
|
70769
|
+
const optionsFor = (kind, request, isRoot) => {
|
|
70770
|
+
const o = CLAUDE_CODE_PERMISSION_OPTION;
|
|
70771
|
+
if (kind === "exitPlan") return [
|
|
70772
|
+
...isRoot ? [] : [o.approveBypass],
|
|
70773
|
+
o.approveAcceptEdits,
|
|
70774
|
+
o.approveDefault,
|
|
70775
|
+
o.keepPlanning
|
|
70776
|
+
];
|
|
70777
|
+
if (kind === "enterPlan") return [o.allow, o.deny];
|
|
70778
|
+
return request.suggestions?.length ? [
|
|
70779
|
+
o.allow,
|
|
70780
|
+
o.allowSession,
|
|
70781
|
+
o.deny
|
|
70782
|
+
] : [o.allow, o.deny];
|
|
70783
|
+
};
|
|
70784
|
+
/** Stable card id per request, distinct from the tool the request is about. */
|
|
70785
|
+
const claudeCodePermissionToolCallId = (requestId) => `cc-permission-${requestId}`;
|
|
70786
|
+
/**
|
|
70787
|
+
* The intervention a request raises: the AskUserQuestion-shaped question every
|
|
70788
|
+
* surface (card, durable review, notification) understands, plus the detail
|
|
70789
|
+
* the dedicated Claude Code card renders.
|
|
70790
|
+
*/
|
|
70791
|
+
const buildClaudeCodePermissionIntervention = (request, { isRoot = false } = {}) => {
|
|
70792
|
+
const kind = classifyClaudeCodePermission(request.toolName);
|
|
70793
|
+
const options = optionsFor(kind, request, isRoot);
|
|
70794
|
+
const plan = kind === "exitPlan" ? optionalString(request.input.plan) : void 0;
|
|
70795
|
+
const toolLabel = request.displayName ?? request.toolName;
|
|
70796
|
+
const question = kind === "exitPlan" ? plan ?? "Claude has finished planning." : kind === "enterPlan" ? "Claude wants to enter plan mode." : request.title ?? `Claude wants to use ${toolLabel}.`;
|
|
70797
|
+
return {
|
|
70798
|
+
arguments: {
|
|
70799
|
+
claudeCodePermission: {
|
|
70800
|
+
allowedPrompts: kind === "exitPlan" ? readAllowedPrompts(request.input) : void 0,
|
|
70801
|
+
blockedPath: request.blockedPath,
|
|
70802
|
+
decisionReason: request.decisionReason,
|
|
70803
|
+
description: request.description,
|
|
70804
|
+
displayName: request.displayName,
|
|
70805
|
+
input: kind === "tool" ? previewInput(request.input) : void 0,
|
|
70806
|
+
kind,
|
|
70807
|
+
options,
|
|
70808
|
+
plan,
|
|
70809
|
+
title: request.title,
|
|
70810
|
+
toolName: request.toolName
|
|
70811
|
+
},
|
|
70812
|
+
questions: [{
|
|
70813
|
+
header: kind === "exitPlan" ? "Review plan" : cut(toolLabel, 200),
|
|
70814
|
+
multiSelect: false,
|
|
70815
|
+
options: options.map((id) => ({
|
|
70816
|
+
id,
|
|
70817
|
+
label: OPTION_LABELS[id]
|
|
70818
|
+
})),
|
|
70819
|
+
question: cut(question, MAX_QUESTION_CHARS)
|
|
70820
|
+
}]
|
|
70821
|
+
},
|
|
70822
|
+
interactionKind: kind === "exitPlan" ? "plan" : "permission",
|
|
70823
|
+
toolCallId: claudeCodePermissionToolCallId(request.requestId)
|
|
70824
|
+
};
|
|
70825
|
+
};
|
|
70826
|
+
const readAnswer = (answer, options) => {
|
|
70827
|
+
if (answer.cancelled || !isRecord$3(answer.result)) return {};
|
|
70828
|
+
const optionId = Object.entries(answer.result).filter(([key]) => key !== CLAUDE_CODE_PERMISSION_NOTE_KEY).flatMap(([, value]) => Array.isArray(value) ? value : [value]).find((value) => typeof value === "string" && options.includes(value));
|
|
70829
|
+
const note = answer.result[CLAUDE_CODE_PERMISSION_NOTE_KEY];
|
|
70830
|
+
return {
|
|
70831
|
+
note: typeof note === "string" && note.trim() ? note.trim() : void 0,
|
|
70832
|
+
optionId
|
|
70833
|
+
};
|
|
70834
|
+
};
|
|
70835
|
+
const setMode = (mode) => ({
|
|
70836
|
+
destination: "session",
|
|
70837
|
+
mode,
|
|
70838
|
+
type: "setMode"
|
|
70839
|
+
});
|
|
70840
|
+
/**
|
|
70841
|
+
* Turn the user's answer into Claude Code's decision.
|
|
70842
|
+
*
|
|
70843
|
+
* - "Always allow in this session" applies Claude Code's own suggestions, kept
|
|
70844
|
+
* to this session whatever destination it proposed.
|
|
70845
|
+
* - A denial without a note interrupts the turn, like "No" in Claude Code's
|
|
70846
|
+
* terminal: the user says what to do next. With a note Claude carries on
|
|
70847
|
+
* with it. "Keep planning" works the same way.
|
|
70848
|
+
* - No answer (the run stopped, the card was dismissed) denies and interrupts.
|
|
70849
|
+
*/
|
|
70850
|
+
const resolveClaudeCodePermissionDecision = (request, answer, { isRoot = false } = {}) => {
|
|
70851
|
+
const o = CLAUDE_CODE_PERMISSION_OPTION;
|
|
70852
|
+
const { note, optionId } = readAnswer(answer, optionsFor(classifyClaudeCodePermission(request.toolName), request, isRoot));
|
|
70853
|
+
const allow = (updatedPermissions) => ({
|
|
70854
|
+
behavior: "allow",
|
|
70855
|
+
updatedInput: request.input,
|
|
70856
|
+
...updatedPermissions?.length ? { updatedPermissions } : {}
|
|
70857
|
+
});
|
|
70858
|
+
switch (optionId) {
|
|
70859
|
+
case o.allow: return allow();
|
|
70860
|
+
case o.allowSession: return allow(request.suggestions?.map((suggestion) => ({
|
|
70861
|
+
...suggestion,
|
|
70862
|
+
destination: "session"
|
|
70863
|
+
})));
|
|
70864
|
+
case o.approveBypass: return allow([setMode("bypassPermissions")]);
|
|
70865
|
+
case o.approveAcceptEdits: return allow([setMode("acceptEdits")]);
|
|
70866
|
+
case o.approveDefault: return allow([setMode("default")]);
|
|
70867
|
+
case o.keepPlanning: return note ? {
|
|
70868
|
+
behavior: "deny",
|
|
70869
|
+
message: `The user wants to keep planning. Revise the plan: ${note}`
|
|
70870
|
+
} : {
|
|
70871
|
+
behavior: "deny",
|
|
70872
|
+
interrupt: true,
|
|
70873
|
+
message: "The user wants to keep planning and will say what to change."
|
|
70874
|
+
};
|
|
70875
|
+
case o.deny: return note ? {
|
|
70876
|
+
behavior: "deny",
|
|
70877
|
+
message: `The user denied this: ${note}`
|
|
70878
|
+
} : {
|
|
70879
|
+
behavior: "deny",
|
|
70880
|
+
interrupt: true,
|
|
70881
|
+
message: "The user denied this."
|
|
70882
|
+
};
|
|
70883
|
+
default: return {
|
|
70884
|
+
behavior: "deny",
|
|
70885
|
+
interrupt: true,
|
|
70886
|
+
message: "The user stopped the run before answering."
|
|
70887
|
+
};
|
|
70888
|
+
}
|
|
70889
|
+
};
|
|
70890
|
+
|
|
70891
|
+
//#endregion
|
|
70892
|
+
//#region ../../packages/heterogeneous-agents/src/spawn/claudeCodeLiveInput.ts
|
|
70893
|
+
/**
|
|
70894
|
+
* How long the session may sit between turns with no stdout before stdin is
|
|
70895
|
+
* closed anyway. Background tasks that stream (sub-agents) keep resetting it;
|
|
70896
|
+
* a silent one (a long background shell) would otherwise hold the process open
|
|
70897
|
+
* forever, since Claude Code's own wind-down ceiling only starts once stdin is
|
|
70898
|
+
* closed.
|
|
70899
|
+
*/
|
|
70900
|
+
const DEFAULT_IDLE_CLOSE_MS = 1800 * 1e3;
|
|
70901
|
+
/**
|
|
70902
|
+
* How long a task that ends between turns may wait for the main-agent turn its
|
|
70903
|
+
* notification wakes. Claude Code opens that turn within milliseconds; the
|
|
70904
|
+
* grace only bounds an end that unexpectedly wakes nothing. A stopped task
|
|
70905
|
+
* never wakes one, so it does not wait (see `observeSystem`).
|
|
70906
|
+
*/
|
|
70907
|
+
const DEFAULT_WAKE_UP_GRACE_MS = 30 * 1e3;
|
|
70908
|
+
const TERMINAL_TASK_STATUSES = new Set([
|
|
70909
|
+
"completed",
|
|
70910
|
+
"failed",
|
|
70911
|
+
"killed"
|
|
70912
|
+
]);
|
|
70913
|
+
const readIdleCloseMs = () => {
|
|
70914
|
+
const value = Number(process.env.LOBE_CLAUDE_CODE_LIVE_INPUT_IDLE_MS);
|
|
70915
|
+
return Number.isFinite(value) && value > 0 ? value : DEFAULT_IDLE_CLOSE_MS;
|
|
70916
|
+
};
|
|
70917
|
+
/** Stamp a stream-json `user` line with the uuid Claude Code replays it under. */
|
|
70918
|
+
const withUserMessageUuid = (stdinLine, uuid) => `${JSON.stringify({
|
|
70919
|
+
...JSON.parse(stdinLine),
|
|
70920
|
+
uuid
|
|
70921
|
+
})}\n`;
|
|
70922
|
+
const isAbortedResult = (message) => !!message.is_error && String(message.terminal_reason ?? "").startsWith("aborted");
|
|
70923
|
+
/**
|
|
70924
|
+
* The runtime end a live session (stdin kept open, see `ClaudeCodeLiveInput`)
|
|
70925
|
+
* reports once, at process exit: complete, or interrupted when its last turn
|
|
70926
|
+
* was stopped. Only a clean exit after a finished turn ends the run here — a
|
|
70927
|
+
* crash after a result is a failure, not a completion. Print mode exits 1 when
|
|
70928
|
+
* its last turn was an error result, which an interrupt is.
|
|
70929
|
+
*
|
|
70930
|
+
* Shared by every host of a live CLI (`lh hetero exec`, the desktop's local
|
|
70931
|
+
* spawn) so they end a run by the same rule.
|
|
70932
|
+
*
|
|
70933
|
+
* @returns the `completeRuntime` data, or undefined when the run does not end here
|
|
70934
|
+
*/
|
|
70935
|
+
const resolveClaudeCodeLiveRuntimeEnd = (lastTurn, exit) => {
|
|
70936
|
+
if (!lastTurn || exit.killedByHost || exit.sawError) return;
|
|
70937
|
+
if (!(exit.code === 0 || lastTurn.aborted && exit.code === 1 && exit.signal === null)) return;
|
|
70938
|
+
return {
|
|
70939
|
+
...lastTurn.aborted ? {
|
|
70940
|
+
kind: "aborted",
|
|
70941
|
+
reason: "interrupted",
|
|
70942
|
+
terminalReason: lastTurn.terminalReason
|
|
70943
|
+
} : { reason: "complete" },
|
|
70944
|
+
transport: "cli-live"
|
|
70945
|
+
};
|
|
70946
|
+
};
|
|
70947
|
+
/**
|
|
70948
|
+
* Key of host-only metadata on a control request (e.g. the mode the user
|
|
70949
|
+
* picked, where the request carries the mode Claude Code can run). Stripped
|
|
70950
|
+
* before the request reaches Claude Code; handed to `onControlRequestSent`.
|
|
70951
|
+
*/
|
|
70952
|
+
const CONTROL_REQUEST_HOST_META = "__host";
|
|
70953
|
+
const SESSION_ENDED = {
|
|
70954
|
+
error: "The session ended before answering",
|
|
70955
|
+
subtype: "error"
|
|
70956
|
+
};
|
|
70957
|
+
/**
|
|
70958
|
+
* Keeps a Claude Code print-mode (`-p --input-format stream-json`) stdin open
|
|
70959
|
+
* for as long as the run can still use input, so the host can deliver a user
|
|
70960
|
+
* message into the running session or interrupt only the current turn.
|
|
70961
|
+
*
|
|
70962
|
+
* Closing stdin early is not neutral: once input is closed, print mode stops
|
|
70963
|
+
* waiting for background tasks after `CLAUDE_CODE_PRINT_BG_WAIT_CEILING_MS`
|
|
70964
|
+
* (10 minutes by default) and kills them. So stdin stays open until the session
|
|
70965
|
+
* is between turns with no running task and no delivered message it has not
|
|
70966
|
+
* picked up yet.
|
|
70967
|
+
*
|
|
70968
|
+
* A task that ends between turns does not make the session idle: its
|
|
70969
|
+
* notification wakes the main agent for a turn, and that turn can start a new
|
|
70970
|
+
* task or resume a finished sub-agent with `SendMessage`. Closing at the end
|
|
70971
|
+
* would put those tasks under the ceiling, so the decision waits for the
|
|
70972
|
+
* wake-up turn's result.
|
|
70973
|
+
*
|
|
70974
|
+
* Requires `--replay-user-messages`: the replayed `uuid` is how a delivered
|
|
70975
|
+
* message is known to have been picked up.
|
|
70976
|
+
*/
|
|
70977
|
+
var ClaudeCodeLiveInput = class {
|
|
70978
|
+
activeTasks = /* @__PURE__ */ new Set();
|
|
70979
|
+
closed = false;
|
|
70980
|
+
idleTimer;
|
|
70981
|
+
idleCloseMs;
|
|
70982
|
+
lastOutcome;
|
|
70983
|
+
lineBuffer = "";
|
|
70984
|
+
listeners = /* @__PURE__ */ new Set();
|
|
70985
|
+
sentListeners = /* @__PURE__ */ new Set();
|
|
70986
|
+
pendingControl = /* @__PURE__ */ new Map();
|
|
70987
|
+
turnOpen = true;
|
|
70988
|
+
unconsumed = /* @__PURE__ */ new Set();
|
|
70989
|
+
wakeUpGraceMs;
|
|
70990
|
+
wakeUpTimer;
|
|
70991
|
+
constructor(stdin, options = {}) {
|
|
70992
|
+
this.stdin = stdin;
|
|
70993
|
+
this.idleCloseMs = options.idleCloseMs ?? readIdleCloseMs();
|
|
70994
|
+
this.wakeUpGraceMs = options.wakeUpGraceMs ?? DEFAULT_WAKE_UP_GRACE_MS;
|
|
70995
|
+
stdin.on("error", () => this.markClosed());
|
|
70996
|
+
stdin.on("close", () => this.markClosed());
|
|
70997
|
+
}
|
|
70998
|
+
get isOpen() {
|
|
70999
|
+
return !this.closed;
|
|
71000
|
+
}
|
|
71001
|
+
/** How the last turn ended; undefined while the session has not finished one. */
|
|
71002
|
+
get lastTurn() {
|
|
71003
|
+
return this.lastOutcome;
|
|
71004
|
+
}
|
|
71005
|
+
/**
|
|
71006
|
+
* Deliver a `user` line into the session; it stays pending until Claude Code
|
|
71007
|
+
* replays it. Returns false once input has closed.
|
|
71008
|
+
*/
|
|
71009
|
+
send(stdinLine, uuid = randomUUID()) {
|
|
71010
|
+
if (this.closed) return false;
|
|
71011
|
+
this.unconsumed.add(uuid);
|
|
71012
|
+
this.clearIdleTimer();
|
|
71013
|
+
this.stdin.write(withUserMessageUuid(stdinLine, uuid));
|
|
71014
|
+
return true;
|
|
71015
|
+
}
|
|
71016
|
+
/** Stop the current turn without ending the process. Returns false once input has closed. */
|
|
71017
|
+
interrupt() {
|
|
71018
|
+
return !!this.sendControlRequest({ subtype: "interrupt" });
|
|
71019
|
+
}
|
|
71020
|
+
/**
|
|
71021
|
+
* Write a stream-json `control_request` into the session — the protocol
|
|
71022
|
+
* Claude Code's SDK uses to steer a live process (interrupt, stop a task,
|
|
71023
|
+
* change the model…).
|
|
71024
|
+
*
|
|
71025
|
+
* @returns the request and its answer, or `undefined` once input has closed
|
|
71026
|
+
*/
|
|
71027
|
+
sendControlRequest(request) {
|
|
71028
|
+
if (this.closed) return;
|
|
71029
|
+
const { [CONTROL_REQUEST_HOST_META]: meta, ...wire } = request;
|
|
71030
|
+
const requestId = randomUUID();
|
|
71031
|
+
const response = new Promise((resolve) => {
|
|
71032
|
+
this.pendingControl.set(requestId, resolve);
|
|
71033
|
+
});
|
|
71034
|
+
this.stdin.write(`${JSON.stringify({
|
|
71035
|
+
request: wire,
|
|
71036
|
+
request_id: requestId,
|
|
71037
|
+
type: "control_request"
|
|
71038
|
+
})}\n`);
|
|
71039
|
+
for (const listener of this.sentListeners) listener(wire, meta);
|
|
71040
|
+
return {
|
|
71041
|
+
requestId,
|
|
71042
|
+
response
|
|
71043
|
+
};
|
|
71044
|
+
}
|
|
71045
|
+
/** Watch every control request the host writes, with its host-only metadata. */
|
|
71046
|
+
onControlRequestSent(listener) {
|
|
71047
|
+
this.sentListeners.add(listener);
|
|
71048
|
+
return () => this.sentListeners.delete(listener);
|
|
71049
|
+
}
|
|
71050
|
+
/**
|
|
71051
|
+
* Answer a control request Claude Code sent the host (`can_use_tool` under
|
|
71052
|
+
* `--permission-prompt-tool stdio`). Returns false once input has closed.
|
|
71053
|
+
*/
|
|
71054
|
+
respondToControlRequest(requestId, response) {
|
|
71055
|
+
if (this.closed) return false;
|
|
71056
|
+
this.stdin.write(`${JSON.stringify({
|
|
71057
|
+
response: {
|
|
71058
|
+
request_id: requestId,
|
|
71059
|
+
response,
|
|
71060
|
+
subtype: "success"
|
|
71061
|
+
},
|
|
71062
|
+
type: "control_response"
|
|
71063
|
+
})}\n`);
|
|
71064
|
+
return true;
|
|
71065
|
+
}
|
|
71066
|
+
/** Watch every record Claude Code writes, as `observe` parses it. */
|
|
71067
|
+
subscribe(listener) {
|
|
71068
|
+
this.listeners.add(listener);
|
|
71069
|
+
return () => this.listeners.delete(listener);
|
|
71070
|
+
}
|
|
71071
|
+
/** Feed raw stdout so the session state tracks what Claude Code reports. */
|
|
71072
|
+
observe(chunk) {
|
|
71073
|
+
this.lineBuffer += chunk.toString();
|
|
71074
|
+
const lines = this.lineBuffer.split("\n");
|
|
71075
|
+
this.lineBuffer = lines.pop() ?? "";
|
|
71076
|
+
for (const line of lines) {
|
|
71077
|
+
if (!line.trim()) continue;
|
|
71078
|
+
try {
|
|
71079
|
+
const message = JSON.parse(line);
|
|
71080
|
+
if (message?.type === "result") this.lastOutcome = {
|
|
71081
|
+
aborted: isAbortedResult(message),
|
|
71082
|
+
terminalReason: message.terminal_reason
|
|
71083
|
+
};
|
|
71084
|
+
this.observeMessage(message);
|
|
71085
|
+
for (const listener of this.listeners) listener(message);
|
|
71086
|
+
} catch {}
|
|
71087
|
+
}
|
|
71088
|
+
if (this.closed) return;
|
|
71089
|
+
if (this.turnOpen) this.clearIdleTimer();
|
|
71090
|
+
else this.armIdleTimer();
|
|
71091
|
+
}
|
|
71092
|
+
/**
|
|
71093
|
+
* stdout ended: take a final record left without a trailing newline, then
|
|
71094
|
+
* close input, since nothing can read it any more.
|
|
71095
|
+
*/
|
|
71096
|
+
finish() {
|
|
71097
|
+
if (this.lineBuffer.trim()) this.observe("\n");
|
|
71098
|
+
this.close();
|
|
71099
|
+
for (const resolve of this.pendingControl.values()) resolve(SESSION_ENDED);
|
|
71100
|
+
this.pendingControl.clear();
|
|
71101
|
+
}
|
|
71102
|
+
close() {
|
|
71103
|
+
if (this.closed) return;
|
|
71104
|
+
this.markClosed();
|
|
71105
|
+
this.stdin.end();
|
|
71106
|
+
}
|
|
71107
|
+
observeMessage(message) {
|
|
71108
|
+
if (message?.type === "control_response") {
|
|
71109
|
+
this.observeControlResponse(message.response);
|
|
71110
|
+
return;
|
|
71111
|
+
}
|
|
71112
|
+
if (message?.parent_tool_use_id && message.type !== "system") return;
|
|
71113
|
+
switch (message?.type) {
|
|
71114
|
+
case "user":
|
|
71115
|
+
if (message.isReplay && typeof message.uuid === "string") {
|
|
71116
|
+
this.unconsumed.delete(message.uuid);
|
|
71117
|
+
this.openTurn();
|
|
71118
|
+
}
|
|
71119
|
+
return;
|
|
71120
|
+
case "assistant":
|
|
71121
|
+
case "stream_event":
|
|
71122
|
+
this.openTurn();
|
|
71123
|
+
return;
|
|
71124
|
+
case "system":
|
|
71125
|
+
this.observeSystem(message);
|
|
71126
|
+
return;
|
|
71127
|
+
case "result":
|
|
71128
|
+
this.turnOpen = false;
|
|
71129
|
+
if (message.is_error && !isAbortedResult(message)) this.close();
|
|
71130
|
+
else this.closeIfIdle();
|
|
71131
|
+
return;
|
|
71132
|
+
}
|
|
71133
|
+
}
|
|
71134
|
+
/** Answers arrive even after input closed, for requests written before. */
|
|
71135
|
+
observeControlResponse(response) {
|
|
71136
|
+
const requestId = response?.request_id;
|
|
71137
|
+
const resolve = typeof requestId === "string" && this.pendingControl.get(requestId);
|
|
71138
|
+
if (!resolve) return;
|
|
71139
|
+
this.pendingControl.delete(requestId);
|
|
71140
|
+
resolve(response.subtype === "success" ? {
|
|
71141
|
+
response: response.response ?? void 0,
|
|
71142
|
+
subtype: "success"
|
|
71143
|
+
} : {
|
|
71144
|
+
error: String(response.error ?? "Control request failed"),
|
|
71145
|
+
subtype: "error"
|
|
71146
|
+
});
|
|
71147
|
+
}
|
|
71148
|
+
observeSystem(message) {
|
|
71149
|
+
if (message.subtype === "init") {
|
|
71150
|
+
this.openTurn();
|
|
71151
|
+
return;
|
|
71152
|
+
}
|
|
71153
|
+
if (message.subtype === "task_started" && message.task_id) {
|
|
71154
|
+
this.activeTasks.add(message.task_id);
|
|
71155
|
+
return;
|
|
71156
|
+
}
|
|
71157
|
+
if ((message.subtype === "task_notification" || message.subtype === "task_updated" && TERMINAL_TASK_STATUSES.has(message.patch?.status)) && message.task_id) {
|
|
71158
|
+
this.activeTasks.delete(message.task_id);
|
|
71159
|
+
if (message.patch?.status === "killed" || message.subtype === "task_notification" && message.status === "stopped") this.closeIfIdle();
|
|
71160
|
+
else this.awaitWakeUpTurn();
|
|
71161
|
+
}
|
|
71162
|
+
}
|
|
71163
|
+
/** A newer turn supersedes how the last one ended until it reports its own. */
|
|
71164
|
+
openTurn() {
|
|
71165
|
+
this.turnOpen = true;
|
|
71166
|
+
this.lastOutcome = void 0;
|
|
71167
|
+
this.clearWakeUpTimer();
|
|
71168
|
+
}
|
|
71169
|
+
closeIfIdle() {
|
|
71170
|
+
if (this.turnOpen || this.activeTasks.size > 0 || this.unconsumed.size > 0) return;
|
|
71171
|
+
this.close();
|
|
71172
|
+
}
|
|
71173
|
+
/**
|
|
71174
|
+
* The last task ended between turns. The turn its notification wakes decides
|
|
71175
|
+
* at its result; close here only if no turn opens within the grace.
|
|
71176
|
+
*/
|
|
71177
|
+
awaitWakeUpTurn() {
|
|
71178
|
+
if (this.closed) return;
|
|
71179
|
+
if (this.turnOpen || this.activeTasks.size > 0 || this.unconsumed.size > 0) return;
|
|
71180
|
+
this.clearWakeUpTimer();
|
|
71181
|
+
this.wakeUpTimer = setTimeout(() => this.closeIfIdle(), this.wakeUpGraceMs);
|
|
71182
|
+
this.wakeUpTimer.unref?.();
|
|
71183
|
+
}
|
|
71184
|
+
clearWakeUpTimer() {
|
|
71185
|
+
if (!this.wakeUpTimer) return;
|
|
71186
|
+
clearTimeout(this.wakeUpTimer);
|
|
71187
|
+
this.wakeUpTimer = void 0;
|
|
71188
|
+
}
|
|
71189
|
+
armIdleTimer() {
|
|
71190
|
+
this.clearIdleTimer();
|
|
71191
|
+
this.idleTimer = setTimeout(() => this.close(), this.idleCloseMs);
|
|
71192
|
+
this.idleTimer.unref?.();
|
|
71193
|
+
}
|
|
71194
|
+
clearIdleTimer() {
|
|
71195
|
+
if (!this.idleTimer) return;
|
|
71196
|
+
clearTimeout(this.idleTimer);
|
|
71197
|
+
this.idleTimer = void 0;
|
|
71198
|
+
}
|
|
71199
|
+
markClosed() {
|
|
71200
|
+
this.closed = true;
|
|
71201
|
+
this.clearIdleTimer();
|
|
71202
|
+
this.clearWakeUpTimer();
|
|
71203
|
+
}
|
|
71204
|
+
};
|
|
71205
|
+
|
|
71206
|
+
//#endregion
|
|
71207
|
+
//#region ../../packages/heterogeneous-agents/src/claudeCodePermission/responder.ts
|
|
71208
|
+
/**
|
|
71209
|
+
* Ask through an `AskUserBridge` without a deadline: a permission request waits
|
|
71210
|
+
* for the user however long it takes (stopping the run ends it).
|
|
71211
|
+
*/
|
|
71212
|
+
const askThroughBridge = (bridge) => (intervention) => bridge.pending(intervention, { timeoutMs: Number.POSITIVE_INFINITY });
|
|
71213
|
+
/**
|
|
71214
|
+
* Answer one permission request: raise its card, wait, and turn the answer into
|
|
71215
|
+
* Claude Code's decision. Shared by the stdio responder and the SDK's
|
|
71216
|
+
* `canUseTool`, so both paths decide alike.
|
|
71217
|
+
*/
|
|
71218
|
+
const decideClaudeCodePermission = async (request, ask, { isRoot = false } = {}) => {
|
|
71219
|
+
const intervention = buildClaudeCodePermissionIntervention(request, { isRoot });
|
|
71220
|
+
let answer;
|
|
71221
|
+
try {
|
|
71222
|
+
answer = await ask(intervention);
|
|
71223
|
+
} catch {
|
|
71224
|
+
answer = {
|
|
71225
|
+
cancelled: true,
|
|
71226
|
+
cancelReason: "session_ended"
|
|
71227
|
+
};
|
|
71228
|
+
}
|
|
71229
|
+
return resolveClaudeCodePermissionDecision(request, answer, { isRoot });
|
|
71230
|
+
};
|
|
71231
|
+
/**
|
|
71232
|
+
* Host side of `--permission-prompt-tool stdio`: answers every `can_use_tool`
|
|
71233
|
+
* control request Claude Code writes to stdout with a `control_response` on
|
|
71234
|
+
* stdin, after the user decides on a card.
|
|
71235
|
+
*
|
|
71236
|
+
* @returns a detach function
|
|
71237
|
+
*/
|
|
71238
|
+
const attachClaudeCodePermissionResponder = (transport, { ask, cancel, isRoot = false }) => transport.subscribe((message) => {
|
|
71239
|
+
const record = message;
|
|
71240
|
+
if (record?.type === "control_cancel_request" && typeof record.request_id === "string") {
|
|
71241
|
+
cancel?.(claudeCodePermissionToolCallId(record.request_id));
|
|
71242
|
+
return;
|
|
71243
|
+
}
|
|
71244
|
+
const request = parseClaudeCodePermissionRequest(message);
|
|
71245
|
+
if (!request) return;
|
|
71246
|
+
decideClaudeCodePermission(request, ask, { isRoot }).then((decision) => {
|
|
71247
|
+
transport.respondToControlRequest(request.requestId, {
|
|
71248
|
+
...decision,
|
|
71249
|
+
...request.toolUseId && { toolUseID: request.toolUseId }
|
|
71250
|
+
});
|
|
71251
|
+
});
|
|
71252
|
+
});
|
|
71253
|
+
/**
|
|
71254
|
+
* The `set_permission_mode` control request for a mode the user picked mid-run,
|
|
71255
|
+
* adjusted to what Claude Code can run (root has no `bypassPermissions`).
|
|
71256
|
+
*/
|
|
71257
|
+
const buildSetPermissionModeRequest = (mode, isRoot) => ({
|
|
71258
|
+
[CONTROL_REQUEST_HOST_META]: { requestedMode: mode },
|
|
71259
|
+
mode: resolveClaudeCodePermissionMode(mode, isRoot).mode,
|
|
71260
|
+
subtype: "set_permission_mode"
|
|
71261
|
+
});
|
|
71262
|
+
/** How long Claude Code gets to confirm a mode switch. */
|
|
71263
|
+
const SET_PERMISSION_MODE_TIMEOUT_MS = 1e4;
|
|
71264
|
+
/**
|
|
71265
|
+
* Switch a live CLI session's mode: write `set_permission_mode` into its stdin
|
|
71266
|
+
* and wait for Claude Code to confirm. The mode report follows on stdout.
|
|
71267
|
+
*
|
|
71268
|
+
* @param send Writes a control request; `undefined` once input has closed.
|
|
71269
|
+
* @returns the mode Claude Code switched to
|
|
71270
|
+
* @throws When input is closed, Claude Code refuses or never answers, or `signal` aborts.
|
|
71271
|
+
*/
|
|
71272
|
+
const setClaudeCodePermissionMode = async (send, mode, { isRoot, signal, timeoutMs = SET_PERMISSION_MODE_TIMEOUT_MS } = {}) => {
|
|
71273
|
+
const request = buildSetPermissionModeRequest(mode, isRoot);
|
|
71274
|
+
const sent = send(request);
|
|
71275
|
+
if (!sent) throw new Error("The Claude Code session no longer takes input");
|
|
71276
|
+
let timer;
|
|
71277
|
+
let onAbort;
|
|
71278
|
+
const cutOff = new Promise((_, reject) => {
|
|
71279
|
+
timer = setTimeout(() => reject(/* @__PURE__ */ new Error("Claude Code did not confirm the mode switch in time")), timeoutMs);
|
|
71280
|
+
onAbort = () => reject(/* @__PURE__ */ new Error("The run ended before Claude Code confirmed the mode"));
|
|
71281
|
+
if (signal?.aborted) onAbort();
|
|
71282
|
+
else signal?.addEventListener("abort", onAbort, { once: true });
|
|
71283
|
+
});
|
|
71284
|
+
try {
|
|
71285
|
+
const answer = await Promise.race([sent.response, cutOff]);
|
|
71286
|
+
if (answer.subtype === "error") throw new Error(answer.error);
|
|
71287
|
+
return request.mode;
|
|
71288
|
+
} finally {
|
|
71289
|
+
clearTimeout(timer);
|
|
71290
|
+
if (onAbort) signal?.removeEventListener("abort", onAbort);
|
|
71291
|
+
}
|
|
71292
|
+
};
|
|
71293
|
+
|
|
70542
71294
|
//#endregion
|
|
70543
71295
|
//#region ../../packages/heterogeneous-agents/src/transcript/rebuildClaudeCode.ts
|
|
70544
71296
|
const MAX_DIR_SLUG = 200;
|
|
@@ -71284,7 +72036,7 @@ var CopilotAcpSession = class CopilotAcpSession extends AcpAgentSession {
|
|
|
71284
72036
|
async settlePrompt(result) {
|
|
71285
72037
|
await this.drainNotifications();
|
|
71286
72038
|
await this.client.drain();
|
|
71287
|
-
const promptResult = isRecord$
|
|
72039
|
+
const promptResult = isRecord$8(result) ? result : void 0;
|
|
71288
72040
|
await this.pushToPipeline({
|
|
71289
72041
|
stopReason: promptResult?.stopReason,
|
|
71290
72042
|
type: "copilot_prompt_completed",
|
|
@@ -71293,7 +72045,7 @@ var CopilotAcpSession = class CopilotAcpSession extends AcpAgentSession {
|
|
|
71293
72045
|
}
|
|
71294
72046
|
async onRunFailure(error) {
|
|
71295
72047
|
this.options.askUserBridge?.cancelAll("session_ended");
|
|
71296
|
-
const detail = error instanceof AcpRpcResponseError && isRecord$
|
|
72048
|
+
const detail = error instanceof AcpRpcResponseError && isRecord$8(error.rpcError.data) && typeof error.rpcError.data.details === "string" && error.rpcError.data.details ? `${error.message}: ${error.rpcError.data.details}` : error.message;
|
|
71297
72049
|
await this.pushToPipeline({
|
|
71298
72050
|
message: detail,
|
|
71299
72051
|
type: "copilot_error"
|
|
@@ -71315,7 +72067,7 @@ var CopilotAcpSession = class CopilotAcpSession extends AcpAgentSession {
|
|
|
71315
72067
|
if (message.method !== "session/update" || !this.acceptUpdates) return;
|
|
71316
72068
|
this.lastSessionUpdateAt = Date.now();
|
|
71317
72069
|
const update = message.params?.update;
|
|
71318
|
-
if (!isRecord$
|
|
72070
|
+
if (!isRecord$8(update)) return;
|
|
71319
72071
|
if (update.sessionUpdate === "config_option_update") {
|
|
71320
72072
|
const catalog = parseCopilotAcpModelCatalog({ configOptions: update.configOptions });
|
|
71321
72073
|
if (catalog?.currentModelId) {
|
|
@@ -71445,7 +72197,7 @@ var CopilotAcpSession = class CopilotAcpSession extends AcpAgentSession {
|
|
|
71445
72197
|
if (!requestedEffort || requestedEffort === "default") return;
|
|
71446
72198
|
const reasoningConfig = getReasoningEffortConfig(configOptions) ?? (!hasSessionConfigOptions && this.options.resumeSessionId ? { id: "reasoning_effort" } : void 0);
|
|
71447
72199
|
if (!reasoningConfig || typeof reasoningConfig.id !== "string" || !reasoningConfig.id) return;
|
|
71448
|
-
const availableValues = Array.isArray(reasoningConfig.options) ? reasoningConfig.options.flatMap((option) => isRecord$
|
|
72200
|
+
const availableValues = Array.isArray(reasoningConfig.options) ? reasoningConfig.options.flatMap((option) => isRecord$8(option) && typeof option.value === "string" && option.value ? [option.value] : []) : [];
|
|
71449
72201
|
const targetValue = availableValues.length === 0 || availableValues.includes(requestedEffort) ? requestedEffort : void 0;
|
|
71450
72202
|
if (!targetValue || hasSessionConfigOptions && reasoningConfig.currentValue === targetValue) return;
|
|
71451
72203
|
await this.client.request("session/set_config_option", {
|
|
@@ -71478,9 +72230,9 @@ var CopilotAcpSession = class CopilotAcpSession extends AcpAgentSession {
|
|
|
71478
72230
|
}
|
|
71479
72231
|
}
|
|
71480
72232
|
parsePermissionRequest(value) {
|
|
71481
|
-
if (!isRecord$
|
|
72233
|
+
if (!isRecord$8(value) || !Array.isArray(value.options) || !isRecord$8(value.toolCall)) throw new AcpServerRequestError(-32602, "Invalid session/request_permission request");
|
|
71482
72234
|
const options = value.options.flatMap((option) => {
|
|
71483
|
-
if (!isRecord$
|
|
72235
|
+
if (!isRecord$8(option) || typeof option.name !== "string" || option.name.length === 0 || option.name.length > 200 || typeof option.optionId !== "string" || option.optionId.length === 0 || option.optionId.length > 200) return [];
|
|
71484
72236
|
return [{
|
|
71485
72237
|
kind: typeof option.kind === "string" && option.kind.length > 0 && option.kind.length <= 1e3 ? option.kind : option.optionId,
|
|
71486
72238
|
name: option.name,
|
|
@@ -71490,7 +72242,7 @@ var CopilotAcpSession = class CopilotAcpSession extends AcpAgentSession {
|
|
|
71490
72242
|
const optionIds = new Set(options.map(({ optionId }) => optionId));
|
|
71491
72243
|
if (options.length !== value.options.length || options.length === 0 || optionIds.size !== options.length || typeof value.toolCall.toolCallId !== "string" || value.toolCall.toolCallId.length === 0) throw new AcpServerRequestError(-32602, "Invalid session/request_permission options");
|
|
71492
72244
|
const rawTitle = typeof value.toolCall.title === "string" ? value.toolCall.title.trim() : "";
|
|
71493
|
-
const rawInput = isRecord$
|
|
72245
|
+
const rawInput = isRecord$8(value.toolCall.rawInput) ? value.toolCall.rawInput : void 0;
|
|
71494
72246
|
const command = typeof rawInput?.command === "string" ? rawInput.command.trim() : "";
|
|
71495
72247
|
return {
|
|
71496
72248
|
options,
|
|
@@ -71543,7 +72295,7 @@ var CopilotAcpSession = class CopilotAcpSession extends AcpAgentSession {
|
|
|
71543
72295
|
return `copilot-permission-${String(message.id)}-${sourceToolCallId}`;
|
|
71544
72296
|
}
|
|
71545
72297
|
getAnswerSelections(answer, question) {
|
|
71546
|
-
if (answer.cancelled || !isRecord$
|
|
72298
|
+
if (answer.cancelled || !isRecord$8(answer.result)) return [];
|
|
71547
72299
|
const rawSelection = answer.result[question];
|
|
71548
72300
|
return (Array.isArray(rawSelection) ? rawSelection : [rawSelection]).flatMap((selection) => typeof selection === "string" ? [selection] : []);
|
|
71549
72301
|
}
|
|
@@ -71703,8 +72455,8 @@ var CursorAcpSession = class extends AcpAgentSession {
|
|
|
71703
72455
|
}
|
|
71704
72456
|
async handleAgentMessage(message) {
|
|
71705
72457
|
if (!this.acceptUpdates || message.method !== "session/update") return;
|
|
71706
|
-
const params = isRecord$
|
|
71707
|
-
if (!isRecord$
|
|
72458
|
+
const params = isRecord$8(message.params) ? message.params : void 0;
|
|
72459
|
+
if (!isRecord$8(params?.update)) return;
|
|
71708
72460
|
await this.pushToPipeline(this.normalizeSessionUpdate(params.update));
|
|
71709
72461
|
}
|
|
71710
72462
|
async handleServerRequest(message) {
|
|
@@ -71764,7 +72516,7 @@ var CursorAcpSession = class extends AcpAgentSession {
|
|
|
71764
72516
|
throw new AcpServerRequestError(-32601, `Unsupported ACP client request: ${message.method}`);
|
|
71765
72517
|
}
|
|
71766
72518
|
normalizeSessionUpdate(update) {
|
|
71767
|
-
if (update.sessionUpdate !== "tool_call" || typeof update.toolCallId !== "string" || !isRecord$
|
|
72519
|
+
if (update.sessionUpdate !== "tool_call" || typeof update.toolCallId !== "string" || !isRecord$8(update.rawInput)) return update;
|
|
71768
72520
|
try {
|
|
71769
72521
|
const request = this.parseAskQuestionRequest({
|
|
71770
72522
|
...update.rawInput,
|
|
@@ -71781,9 +72533,9 @@ var CursorAcpSession = class extends AcpAgentSession {
|
|
|
71781
72533
|
}
|
|
71782
72534
|
}
|
|
71783
72535
|
parsePermissionRequest(value) {
|
|
71784
|
-
if (!isRecord$
|
|
72536
|
+
if (!isRecord$8(value) || !Array.isArray(value.options) || !isRecord$8(value.toolCall)) throw new AcpServerRequestError(-32602, "Invalid session/request_permission request");
|
|
71785
72537
|
const options = value.options.flatMap((option) => {
|
|
71786
|
-
if (!isRecord$
|
|
72538
|
+
if (!isRecord$8(option) || typeof option.kind !== "string" || typeof option.name !== "string" || typeof option.optionId !== "string") return [];
|
|
71787
72539
|
return [{
|
|
71788
72540
|
kind: option.kind,
|
|
71789
72541
|
name: option.name,
|
|
@@ -71800,7 +72552,7 @@ var CursorAcpSession = class extends AcpAgentSession {
|
|
|
71800
72552
|
};
|
|
71801
72553
|
}
|
|
71802
72554
|
parseCreatePlanRequest(value) {
|
|
71803
|
-
if (!isRecord$
|
|
72555
|
+
if (!isRecord$8(value) || typeof value.toolCallId !== "string" || typeof value.plan !== "string") throw new AcpServerRequestError(-32602, "Invalid cursor/create_plan request");
|
|
71804
72556
|
return {
|
|
71805
72557
|
name: typeof value.name === "string" ? value.name : void 0,
|
|
71806
72558
|
overview: typeof value.overview === "string" ? value.overview : void 0,
|
|
@@ -71844,16 +72596,16 @@ var CursorAcpSession = class extends AcpAgentSession {
|
|
|
71844
72596
|
return `cursor-${kind}-${String(message.id)}-${sourceToolCallId}`;
|
|
71845
72597
|
}
|
|
71846
72598
|
getAnswerSelections(answer, question) {
|
|
71847
|
-
if (answer.cancelled || !isRecord$
|
|
72599
|
+
if (answer.cancelled || !isRecord$8(answer.result)) return [];
|
|
71848
72600
|
const rawSelection = answer.result[question];
|
|
71849
72601
|
return (Array.isArray(rawSelection) ? rawSelection : [rawSelection]).flatMap((selection) => typeof selection === "string" ? [selection] : []);
|
|
71850
72602
|
}
|
|
71851
72603
|
parseAskQuestionRequest(value) {
|
|
71852
|
-
if (!isRecord$
|
|
72604
|
+
if (!isRecord$8(value) || typeof value.toolCallId !== "string" || !Array.isArray(value.questions)) throw new AcpServerRequestError(-32602, "Invalid cursor/ask_question request");
|
|
71853
72605
|
const questions = value.questions.flatMap((questionValue) => {
|
|
71854
|
-
if (!isRecord$
|
|
72606
|
+
if (!isRecord$8(questionValue)) return [];
|
|
71855
72607
|
if (typeof questionValue.id !== "string" || typeof questionValue.prompt !== "string" || !Array.isArray(questionValue.options)) return [];
|
|
71856
|
-
const options = questionValue.options.flatMap((optionValue) => isRecord$
|
|
72608
|
+
const options = questionValue.options.flatMap((optionValue) => isRecord$8(optionValue) && typeof optionValue.id === "string" && typeof optionValue.label === "string" ? [{
|
|
71857
72609
|
id: optionValue.id,
|
|
71858
72610
|
label: optionValue.label
|
|
71859
72611
|
}] : []);
|
|
@@ -71874,7 +72626,7 @@ var CursorAcpSession = class extends AcpAgentSession {
|
|
|
71874
72626
|
}
|
|
71875
72627
|
buildQuestionResponse(request, answer) {
|
|
71876
72628
|
if (answer.cancelled) return { outcome: { outcome: "cancelled" } };
|
|
71877
|
-
if (!isRecord$
|
|
72629
|
+
if (!isRecord$8(answer.result)) return { outcome: { outcome: "cancelled" } };
|
|
71878
72630
|
const freeform = answer.result.__freeform__;
|
|
71879
72631
|
if (typeof freeform === "string" && freeform.trim()) return { outcome: {
|
|
71880
72632
|
answers: request.questions.map(({ id }) => ({
|
|
@@ -71914,8 +72666,8 @@ const splitThinkingModel = (model) => {
|
|
|
71914
72666
|
thoughtLevel: match[2].toLowerCase()
|
|
71915
72667
|
} : void 0;
|
|
71916
72668
|
};
|
|
71917
|
-
const getThinkingConfig = (configOptions) => Array.isArray(configOptions) ? configOptions.filter(isRecord$
|
|
71918
|
-
const getModeConfigValue = (configOptions) => Array.isArray(configOptions) ? configOptions.filter(isRecord$
|
|
72669
|
+
const getThinkingConfig = (configOptions) => Array.isArray(configOptions) ? configOptions.filter(isRecord$8).find((option) => option.id === "thought_level") : void 0;
|
|
72670
|
+
const getModeConfigValue = (configOptions) => Array.isArray(configOptions) ? configOptions.filter(isRecord$8).find((option) => option.id === "mode")?.currentValue : void 0;
|
|
71919
72671
|
const buildDevinAcpArgs = (extraArgs = []) => {
|
|
71920
72672
|
const args = [...extraArgs];
|
|
71921
72673
|
let resolvedMode;
|
|
@@ -72013,7 +72765,7 @@ var DevinAcpSession = class extends AcpAgentSession {
|
|
|
72013
72765
|
}
|
|
72014
72766
|
async settlePrompt(result) {
|
|
72015
72767
|
await this.client.drain();
|
|
72016
|
-
const promptResult = isRecord$
|
|
72768
|
+
const promptResult = isRecord$8(result) ? result : void 0;
|
|
72017
72769
|
await this.pushToPipeline({
|
|
72018
72770
|
stopReason: promptResult?.stopReason,
|
|
72019
72771
|
type: "devin_prompt_completed",
|
|
@@ -72036,8 +72788,8 @@ var DevinAcpSession = class extends AcpAgentSession {
|
|
|
72036
72788
|
}
|
|
72037
72789
|
async handleAgentMessage(message) {
|
|
72038
72790
|
if (!this.acceptUpdates || message.method !== "session/update") return;
|
|
72039
|
-
const params = isRecord$
|
|
72040
|
-
if (!isRecord$
|
|
72791
|
+
const params = isRecord$8(message.params) ? message.params : void 0;
|
|
72792
|
+
if (!isRecord$8(params?.update)) return;
|
|
72041
72793
|
const update = this.normalizeSessionUpdate(params.update);
|
|
72042
72794
|
if (update.sessionUpdate === "config_option_update") {
|
|
72043
72795
|
const model = this.resolveCurrentModel(update.configOptions);
|
|
@@ -72095,7 +72847,7 @@ var DevinAcpSession = class extends AcpAgentSession {
|
|
|
72095
72847
|
}
|
|
72096
72848
|
normalizeSessionUpdate(update) {
|
|
72097
72849
|
if (typeof update.name === "string") return update;
|
|
72098
|
-
const inferenceToolName = (isRecord$
|
|
72850
|
+
const inferenceToolName = (isRecord$8(update._meta) ? update._meta : void 0)?.["cognition.ai/inferenceToolName"];
|
|
72099
72851
|
return typeof inferenceToolName === "string" && inferenceToolName ? {
|
|
72100
72852
|
...update,
|
|
72101
72853
|
name: inferenceToolName
|
|
@@ -72130,7 +72882,7 @@ var DevinAcpSession = class extends AcpAgentSession {
|
|
|
72130
72882
|
});
|
|
72131
72883
|
const thinking = getThinkingConfig(result.configOptions);
|
|
72132
72884
|
if (thinking) {
|
|
72133
|
-
if (!Array.isArray(thinking.options) || !thinking.options.some((option) => isRecord$
|
|
72885
|
+
if (!Array.isArray(thinking.options) || !thinking.options.some((option) => isRecord$8(option) && option.value === requestedThinking.thoughtLevel)) throw new Error(`Devin ACP thinking level is unavailable: ${requestedModel}`);
|
|
72134
72886
|
if (thinking.currentValue !== requestedThinking.thoughtLevel) result = await this.client.request("session/set_config_option", {
|
|
72135
72887
|
configId: thinking.id,
|
|
72136
72888
|
sessionId,
|
|
@@ -72155,13 +72907,13 @@ var DevinAcpSession = class extends AcpAgentSession {
|
|
|
72155
72907
|
return value.toLowerCase().replaceAll(/[^a-z0-9]/g, "");
|
|
72156
72908
|
}
|
|
72157
72909
|
parsePermissionRequest(value) {
|
|
72158
|
-
if (!isRecord$
|
|
72159
|
-
const options = value.options.flatMap((option) => isRecord$
|
|
72910
|
+
if (!isRecord$8(value) || !Array.isArray(value.options) || !isRecord$8(value.toolCall)) throw new AcpServerRequestError(-32602, "Invalid session/request_permission request");
|
|
72911
|
+
const options = value.options.flatMap((option) => isRecord$8(option) && typeof option.name === "string" && typeof option.optionId === "string" ? [{
|
|
72160
72912
|
name: option.name,
|
|
72161
72913
|
optionId: option.optionId
|
|
72162
72914
|
}] : []);
|
|
72163
72915
|
if (options.length !== value.options.length || options.length === 0 || typeof value.toolCall.toolCallId !== "string") throw new AcpServerRequestError(-32602, "Invalid session/request_permission options");
|
|
72164
|
-
const editableCommand = (isRecord$
|
|
72916
|
+
const editableCommand = (isRecord$8(value.toolCall._meta) ? value.toolCall._meta : void 0)?.["cognition.ai/editableCommand"];
|
|
72165
72917
|
return {
|
|
72166
72918
|
options,
|
|
72167
72919
|
toolCall: {
|
|
@@ -72204,7 +72956,7 @@ var DevinAcpSession = class extends AcpAgentSession {
|
|
|
72204
72956
|
return request.options.find(({ optionId }) => selections.includes(optionId));
|
|
72205
72957
|
}
|
|
72206
72958
|
getAnswerSelections(answer, question) {
|
|
72207
|
-
if (answer.cancelled || !isRecord$
|
|
72959
|
+
if (answer.cancelled || !isRecord$8(answer.result)) return [];
|
|
72208
72960
|
const selection = answer.result[question];
|
|
72209
72961
|
return (Array.isArray(selection) ? selection : [selection]).flatMap((value) => typeof value === "string" ? [value] : []);
|
|
72210
72962
|
}
|
|
@@ -72422,7 +73174,7 @@ var DroidAcpSession = class DroidAcpSession extends AcpAgentSession {
|
|
|
72422
73174
|
if (message.method !== "session/update" || !this.acceptUpdates) return;
|
|
72423
73175
|
this.lastSessionUpdateAt = Date.now();
|
|
72424
73176
|
const update = message.params?.update;
|
|
72425
|
-
if (!isRecord$
|
|
73177
|
+
if (!isRecord$8(update)) return;
|
|
72426
73178
|
if (update.sessionUpdate === "config_option_update") {
|
|
72427
73179
|
const catalog = parseDroidAcpModelCatalog({ configOptions: update.configOptions });
|
|
72428
73180
|
if (catalog?.currentModelId) {
|
|
@@ -72481,9 +73233,9 @@ var DroidAcpSession = class DroidAcpSession extends AcpAgentSession {
|
|
|
72481
73233
|
}
|
|
72482
73234
|
}
|
|
72483
73235
|
parsePermissionRequest(value) {
|
|
72484
|
-
if (!isRecord$
|
|
73236
|
+
if (!isRecord$8(value) || !Array.isArray(value.options) || !isRecord$8(value.toolCall)) throw new AcpServerRequestError(-32602, "Invalid session/request_permission request");
|
|
72485
73237
|
const options = value.options.flatMap((option) => {
|
|
72486
|
-
if (!isRecord$
|
|
73238
|
+
if (!isRecord$8(option) || typeof option.kind !== "string" || option.kind.length === 0 || option.kind.length > 1e3 || typeof option.name !== "string" || option.name.length === 0 || option.name.length > 200 || typeof option.optionId !== "string" || option.optionId.length === 0 || option.optionId.length > 200) return [];
|
|
72487
73239
|
return [{
|
|
72488
73240
|
kind: option.kind,
|
|
72489
73241
|
name: option.name,
|
|
@@ -72543,7 +73295,7 @@ var DroidAcpSession = class DroidAcpSession extends AcpAgentSession {
|
|
|
72543
73295
|
return `droid-permission-${String(message.id)}-${sourceToolCallId}`;
|
|
72544
73296
|
}
|
|
72545
73297
|
getAnswerSelections(answer, question) {
|
|
72546
|
-
if (answer.cancelled || !isRecord$
|
|
73298
|
+
if (answer.cancelled || !isRecord$8(answer.result)) return [];
|
|
72547
73299
|
const rawSelection = answer.result[question];
|
|
72548
73300
|
return (Array.isArray(rawSelection) ? rawSelection : [rawSelection]).flatMap((selection) => typeof selection === "string" ? [selection] : []);
|
|
72549
73301
|
}
|
|
@@ -72634,7 +73386,7 @@ const DSH_MODEL_CONFIG_ID = "model";
|
|
|
72634
73386
|
const modelChoices = (configOptions) => {
|
|
72635
73387
|
const option = configOptions?.find(({ id }) => id === DSH_MODEL_CONFIG_ID);
|
|
72636
73388
|
const flatten = (entries) => Array.isArray(entries) ? entries.flatMap((entry) => {
|
|
72637
|
-
if (!isRecord$
|
|
73389
|
+
if (!isRecord$8(entry)) return [];
|
|
72638
73390
|
if (Array.isArray(entry.options)) return flatten(entry.options);
|
|
72639
73391
|
return typeof entry.value === "string" ? [{
|
|
72640
73392
|
name: typeof entry.name === "string" ? entry.name : void 0,
|
|
@@ -72750,7 +73502,7 @@ var DshAcpSession = class extends AcpAgentSession {
|
|
|
72750
73502
|
async settlePrompt(result) {
|
|
72751
73503
|
await this.client.drain();
|
|
72752
73504
|
await this.pushToPipeline({
|
|
72753
|
-
stopReason: isRecord$
|
|
73505
|
+
stopReason: isRecord$8(result) ? result.stopReason : void 0,
|
|
72754
73506
|
type: "dsh_prompt_completed"
|
|
72755
73507
|
});
|
|
72756
73508
|
}
|
|
@@ -72764,7 +73516,7 @@ var DshAcpSession = class extends AcpAgentSession {
|
|
|
72764
73516
|
async handleAgentMessage(message) {
|
|
72765
73517
|
if (message.method !== "session/update") return;
|
|
72766
73518
|
const update = message.params?.update;
|
|
72767
|
-
if (isRecord$
|
|
73519
|
+
if (isRecord$8(update)) await this.pushToPipeline(update);
|
|
72768
73520
|
}
|
|
72769
73521
|
/**
|
|
72770
73522
|
* LobeHub runs agents headless. The harness's default `workspace-write`
|
|
@@ -73292,284 +74044,6 @@ const prepareClaudeCodeLobeHubCli = async (prompt, args = [], options = {}) => {
|
|
|
73292
74044
|
};
|
|
73293
74045
|
};
|
|
73294
74046
|
|
|
73295
|
-
//#endregion
|
|
73296
|
-
//#region ../../packages/heterogeneous-agents/src/spawn/claudeCodeLiveInput.ts
|
|
73297
|
-
/**
|
|
73298
|
-
* How long the session may sit between turns with no stdout before stdin is
|
|
73299
|
-
* closed anyway. Background tasks that stream (sub-agents) keep resetting it;
|
|
73300
|
-
* a silent one (a long background shell) would otherwise hold the process open
|
|
73301
|
-
* forever, since Claude Code's own wind-down ceiling only starts once stdin is
|
|
73302
|
-
* closed.
|
|
73303
|
-
*/
|
|
73304
|
-
const DEFAULT_IDLE_CLOSE_MS = 1800 * 1e3;
|
|
73305
|
-
/**
|
|
73306
|
-
* How long a task that ends between turns may wait for the main-agent turn its
|
|
73307
|
-
* notification wakes. Claude Code opens that turn within milliseconds; the
|
|
73308
|
-
* grace only bounds an end that unexpectedly wakes nothing. A stopped task
|
|
73309
|
-
* never wakes one, so it does not wait (see `observeSystem`).
|
|
73310
|
-
*/
|
|
73311
|
-
const DEFAULT_WAKE_UP_GRACE_MS = 30 * 1e3;
|
|
73312
|
-
const TERMINAL_TASK_STATUSES = new Set([
|
|
73313
|
-
"completed",
|
|
73314
|
-
"failed",
|
|
73315
|
-
"killed"
|
|
73316
|
-
]);
|
|
73317
|
-
const readIdleCloseMs = () => {
|
|
73318
|
-
const value = Number(process.env.LOBE_CLAUDE_CODE_LIVE_INPUT_IDLE_MS);
|
|
73319
|
-
return Number.isFinite(value) && value > 0 ? value : DEFAULT_IDLE_CLOSE_MS;
|
|
73320
|
-
};
|
|
73321
|
-
/** Stamp a stream-json `user` line with the uuid Claude Code replays it under. */
|
|
73322
|
-
const withUserMessageUuid = (stdinLine, uuid) => `${JSON.stringify({
|
|
73323
|
-
...JSON.parse(stdinLine),
|
|
73324
|
-
uuid
|
|
73325
|
-
})}\n`;
|
|
73326
|
-
const isAbortedResult = (message) => !!message.is_error && String(message.terminal_reason ?? "").startsWith("aborted");
|
|
73327
|
-
/**
|
|
73328
|
-
* The runtime end a live session (stdin kept open, see `ClaudeCodeLiveInput`)
|
|
73329
|
-
* reports once, at process exit: complete, or interrupted when its last turn
|
|
73330
|
-
* was stopped. Only a clean exit after a finished turn ends the run here — a
|
|
73331
|
-
* crash after a result is a failure, not a completion. Print mode exits 1 when
|
|
73332
|
-
* its last turn was an error result, which an interrupt is.
|
|
73333
|
-
*
|
|
73334
|
-
* Shared by every host of a live CLI (`lh hetero exec`, the desktop's local
|
|
73335
|
-
* spawn) so they end a run by the same rule.
|
|
73336
|
-
*
|
|
73337
|
-
* @returns the `completeRuntime` data, or undefined when the run does not end here
|
|
73338
|
-
*/
|
|
73339
|
-
const resolveClaudeCodeLiveRuntimeEnd = (lastTurn, exit) => {
|
|
73340
|
-
if (!lastTurn || exit.killedByHost || exit.sawError) return;
|
|
73341
|
-
if (!(exit.code === 0 || lastTurn.aborted && exit.code === 1 && exit.signal === null)) return;
|
|
73342
|
-
return {
|
|
73343
|
-
...lastTurn.aborted ? {
|
|
73344
|
-
kind: "aborted",
|
|
73345
|
-
reason: "interrupted",
|
|
73346
|
-
terminalReason: lastTurn.terminalReason
|
|
73347
|
-
} : { reason: "complete" },
|
|
73348
|
-
transport: "cli-live"
|
|
73349
|
-
};
|
|
73350
|
-
};
|
|
73351
|
-
const SESSION_ENDED = {
|
|
73352
|
-
error: "The session ended before answering",
|
|
73353
|
-
subtype: "error"
|
|
73354
|
-
};
|
|
73355
|
-
/**
|
|
73356
|
-
* Keeps a Claude Code print-mode (`-p --input-format stream-json`) stdin open
|
|
73357
|
-
* for as long as the run can still use input, so the host can deliver a user
|
|
73358
|
-
* message into the running session or interrupt only the current turn.
|
|
73359
|
-
*
|
|
73360
|
-
* Closing stdin early is not neutral: once input is closed, print mode stops
|
|
73361
|
-
* waiting for background tasks after `CLAUDE_CODE_PRINT_BG_WAIT_CEILING_MS`
|
|
73362
|
-
* (10 minutes by default) and kills them. So stdin stays open until the session
|
|
73363
|
-
* is between turns with no running task and no delivered message it has not
|
|
73364
|
-
* picked up yet.
|
|
73365
|
-
*
|
|
73366
|
-
* A task that ends between turns does not make the session idle: its
|
|
73367
|
-
* notification wakes the main agent for a turn, and that turn can start a new
|
|
73368
|
-
* task or resume a finished sub-agent with `SendMessage`. Closing at the end
|
|
73369
|
-
* would put those tasks under the ceiling, so the decision waits for the
|
|
73370
|
-
* wake-up turn's result.
|
|
73371
|
-
*
|
|
73372
|
-
* Requires `--replay-user-messages`: the replayed `uuid` is how a delivered
|
|
73373
|
-
* message is known to have been picked up.
|
|
73374
|
-
*/
|
|
73375
|
-
var ClaudeCodeLiveInput = class {
|
|
73376
|
-
activeTasks = /* @__PURE__ */ new Set();
|
|
73377
|
-
closed = false;
|
|
73378
|
-
idleTimer;
|
|
73379
|
-
idleCloseMs;
|
|
73380
|
-
lastOutcome;
|
|
73381
|
-
lineBuffer = "";
|
|
73382
|
-
pendingControl = /* @__PURE__ */ new Map();
|
|
73383
|
-
turnOpen = true;
|
|
73384
|
-
unconsumed = /* @__PURE__ */ new Set();
|
|
73385
|
-
wakeUpGraceMs;
|
|
73386
|
-
wakeUpTimer;
|
|
73387
|
-
constructor(stdin, options = {}) {
|
|
73388
|
-
this.stdin = stdin;
|
|
73389
|
-
this.idleCloseMs = options.idleCloseMs ?? readIdleCloseMs();
|
|
73390
|
-
this.wakeUpGraceMs = options.wakeUpGraceMs ?? DEFAULT_WAKE_UP_GRACE_MS;
|
|
73391
|
-
stdin.on("error", () => this.markClosed());
|
|
73392
|
-
stdin.on("close", () => this.markClosed());
|
|
73393
|
-
}
|
|
73394
|
-
get isOpen() {
|
|
73395
|
-
return !this.closed;
|
|
73396
|
-
}
|
|
73397
|
-
/** How the last turn ended; undefined while the session has not finished one. */
|
|
73398
|
-
get lastTurn() {
|
|
73399
|
-
return this.lastOutcome;
|
|
73400
|
-
}
|
|
73401
|
-
/**
|
|
73402
|
-
* Deliver a `user` line into the session; it stays pending until Claude Code
|
|
73403
|
-
* replays it. Returns false once input has closed.
|
|
73404
|
-
*/
|
|
73405
|
-
send(stdinLine, uuid = randomUUID()) {
|
|
73406
|
-
if (this.closed) return false;
|
|
73407
|
-
this.unconsumed.add(uuid);
|
|
73408
|
-
this.clearIdleTimer();
|
|
73409
|
-
this.stdin.write(withUserMessageUuid(stdinLine, uuid));
|
|
73410
|
-
return true;
|
|
73411
|
-
}
|
|
73412
|
-
/** Stop the current turn without ending the process. Returns false once input has closed. */
|
|
73413
|
-
interrupt() {
|
|
73414
|
-
return !!this.sendControlRequest({ subtype: "interrupt" });
|
|
73415
|
-
}
|
|
73416
|
-
/**
|
|
73417
|
-
* Write a stream-json `control_request` into the session — the protocol
|
|
73418
|
-
* Claude Code's SDK uses to steer a live process (interrupt, stop a task,
|
|
73419
|
-
* change the model…).
|
|
73420
|
-
*
|
|
73421
|
-
* @returns the request and its answer, or `undefined` once input has closed
|
|
73422
|
-
*/
|
|
73423
|
-
sendControlRequest(request) {
|
|
73424
|
-
if (this.closed) return;
|
|
73425
|
-
const requestId = randomUUID();
|
|
73426
|
-
const response = new Promise((resolve) => {
|
|
73427
|
-
this.pendingControl.set(requestId, resolve);
|
|
73428
|
-
});
|
|
73429
|
-
this.stdin.write(`${JSON.stringify({
|
|
73430
|
-
request,
|
|
73431
|
-
request_id: requestId,
|
|
73432
|
-
type: "control_request"
|
|
73433
|
-
})}\n`);
|
|
73434
|
-
return {
|
|
73435
|
-
requestId,
|
|
73436
|
-
response
|
|
73437
|
-
};
|
|
73438
|
-
}
|
|
73439
|
-
/** Feed raw stdout so the session state tracks what Claude Code reports. */
|
|
73440
|
-
observe(chunk) {
|
|
73441
|
-
this.lineBuffer += chunk.toString();
|
|
73442
|
-
const lines = this.lineBuffer.split("\n");
|
|
73443
|
-
this.lineBuffer = lines.pop() ?? "";
|
|
73444
|
-
for (const line of lines) {
|
|
73445
|
-
if (!line.trim()) continue;
|
|
73446
|
-
try {
|
|
73447
|
-
const message = JSON.parse(line);
|
|
73448
|
-
if (message?.type === "result") this.lastOutcome = {
|
|
73449
|
-
aborted: isAbortedResult(message),
|
|
73450
|
-
terminalReason: message.terminal_reason
|
|
73451
|
-
};
|
|
73452
|
-
this.observeMessage(message);
|
|
73453
|
-
} catch {}
|
|
73454
|
-
}
|
|
73455
|
-
if (this.closed) return;
|
|
73456
|
-
if (this.turnOpen) this.clearIdleTimer();
|
|
73457
|
-
else this.armIdleTimer();
|
|
73458
|
-
}
|
|
73459
|
-
/**
|
|
73460
|
-
* stdout ended: take a final record left without a trailing newline, then
|
|
73461
|
-
* close input, since nothing can read it any more.
|
|
73462
|
-
*/
|
|
73463
|
-
finish() {
|
|
73464
|
-
if (this.lineBuffer.trim()) this.observe("\n");
|
|
73465
|
-
this.close();
|
|
73466
|
-
for (const resolve of this.pendingControl.values()) resolve(SESSION_ENDED);
|
|
73467
|
-
this.pendingControl.clear();
|
|
73468
|
-
}
|
|
73469
|
-
close() {
|
|
73470
|
-
if (this.closed) return;
|
|
73471
|
-
this.markClosed();
|
|
73472
|
-
this.stdin.end();
|
|
73473
|
-
}
|
|
73474
|
-
observeMessage(message) {
|
|
73475
|
-
if (message?.type === "control_response") {
|
|
73476
|
-
this.observeControlResponse(message.response);
|
|
73477
|
-
return;
|
|
73478
|
-
}
|
|
73479
|
-
if (message?.parent_tool_use_id && message.type !== "system") return;
|
|
73480
|
-
switch (message?.type) {
|
|
73481
|
-
case "user":
|
|
73482
|
-
if (message.isReplay && typeof message.uuid === "string") {
|
|
73483
|
-
this.unconsumed.delete(message.uuid);
|
|
73484
|
-
this.openTurn();
|
|
73485
|
-
}
|
|
73486
|
-
return;
|
|
73487
|
-
case "assistant":
|
|
73488
|
-
case "stream_event":
|
|
73489
|
-
this.openTurn();
|
|
73490
|
-
return;
|
|
73491
|
-
case "system":
|
|
73492
|
-
this.observeSystem(message);
|
|
73493
|
-
return;
|
|
73494
|
-
case "result":
|
|
73495
|
-
this.turnOpen = false;
|
|
73496
|
-
if (message.is_error && !isAbortedResult(message)) this.close();
|
|
73497
|
-
else this.closeIfIdle();
|
|
73498
|
-
return;
|
|
73499
|
-
}
|
|
73500
|
-
}
|
|
73501
|
-
/** Answers arrive even after input closed, for requests written before. */
|
|
73502
|
-
observeControlResponse(response) {
|
|
73503
|
-
const requestId = response?.request_id;
|
|
73504
|
-
const resolve = typeof requestId === "string" && this.pendingControl.get(requestId);
|
|
73505
|
-
if (!resolve) return;
|
|
73506
|
-
this.pendingControl.delete(requestId);
|
|
73507
|
-
resolve(response.subtype === "success" ? {
|
|
73508
|
-
response: response.response ?? void 0,
|
|
73509
|
-
subtype: "success"
|
|
73510
|
-
} : {
|
|
73511
|
-
error: String(response.error ?? "Control request failed"),
|
|
73512
|
-
subtype: "error"
|
|
73513
|
-
});
|
|
73514
|
-
}
|
|
73515
|
-
observeSystem(message) {
|
|
73516
|
-
if (message.subtype === "init") {
|
|
73517
|
-
this.openTurn();
|
|
73518
|
-
return;
|
|
73519
|
-
}
|
|
73520
|
-
if (message.subtype === "task_started" && message.task_id) {
|
|
73521
|
-
this.activeTasks.add(message.task_id);
|
|
73522
|
-
return;
|
|
73523
|
-
}
|
|
73524
|
-
if ((message.subtype === "task_notification" || message.subtype === "task_updated" && TERMINAL_TASK_STATUSES.has(message.patch?.status)) && message.task_id) {
|
|
73525
|
-
this.activeTasks.delete(message.task_id);
|
|
73526
|
-
if (message.patch?.status === "killed" || message.subtype === "task_notification" && message.status === "stopped") this.closeIfIdle();
|
|
73527
|
-
else this.awaitWakeUpTurn();
|
|
73528
|
-
}
|
|
73529
|
-
}
|
|
73530
|
-
/** A newer turn supersedes how the last one ended until it reports its own. */
|
|
73531
|
-
openTurn() {
|
|
73532
|
-
this.turnOpen = true;
|
|
73533
|
-
this.lastOutcome = void 0;
|
|
73534
|
-
this.clearWakeUpTimer();
|
|
73535
|
-
}
|
|
73536
|
-
closeIfIdle() {
|
|
73537
|
-
if (this.turnOpen || this.activeTasks.size > 0 || this.unconsumed.size > 0) return;
|
|
73538
|
-
this.close();
|
|
73539
|
-
}
|
|
73540
|
-
/**
|
|
73541
|
-
* The last task ended between turns. The turn its notification wakes decides
|
|
73542
|
-
* at its result; close here only if no turn opens within the grace.
|
|
73543
|
-
*/
|
|
73544
|
-
awaitWakeUpTurn() {
|
|
73545
|
-
if (this.closed) return;
|
|
73546
|
-
if (this.turnOpen || this.activeTasks.size > 0 || this.unconsumed.size > 0) return;
|
|
73547
|
-
this.clearWakeUpTimer();
|
|
73548
|
-
this.wakeUpTimer = setTimeout(() => this.closeIfIdle(), this.wakeUpGraceMs);
|
|
73549
|
-
this.wakeUpTimer.unref?.();
|
|
73550
|
-
}
|
|
73551
|
-
clearWakeUpTimer() {
|
|
73552
|
-
if (!this.wakeUpTimer) return;
|
|
73553
|
-
clearTimeout(this.wakeUpTimer);
|
|
73554
|
-
this.wakeUpTimer = void 0;
|
|
73555
|
-
}
|
|
73556
|
-
armIdleTimer() {
|
|
73557
|
-
this.clearIdleTimer();
|
|
73558
|
-
this.idleTimer = setTimeout(() => this.close(), this.idleCloseMs);
|
|
73559
|
-
this.idleTimer.unref?.();
|
|
73560
|
-
}
|
|
73561
|
-
clearIdleTimer() {
|
|
73562
|
-
if (!this.idleTimer) return;
|
|
73563
|
-
clearTimeout(this.idleTimer);
|
|
73564
|
-
this.idleTimer = void 0;
|
|
73565
|
-
}
|
|
73566
|
-
markClosed() {
|
|
73567
|
-
this.closed = true;
|
|
73568
|
-
this.clearIdleTimer();
|
|
73569
|
-
this.clearWakeUpTimer();
|
|
73570
|
-
}
|
|
73571
|
-
};
|
|
73572
|
-
|
|
73573
74047
|
//#endregion
|
|
73574
74048
|
//#region ../../packages/heterogeneous-agents/src/spawn/claudeCodeStopTask.ts
|
|
73575
74049
|
/** How long Claude Code gets to accept a stop before the request is given up. */
|
|
@@ -74025,6 +74499,7 @@ const spawnTraeAcpAgent = async (options) => {
|
|
|
74025
74499
|
|
|
74026
74500
|
//#endregion
|
|
74027
74501
|
//#region ../../packages/heterogeneous-agents/src/spawn/spawnAgent.ts
|
|
74502
|
+
init_src$2();
|
|
74028
74503
|
init_config();
|
|
74029
74504
|
init_cliSpawn();
|
|
74030
74505
|
/**
|
|
@@ -74071,13 +74546,6 @@ const CODEBUDDY_BASE_ARGS = [
|
|
|
74071
74546
|
"--disallowedTools",
|
|
74072
74547
|
CODEBUDDY_DISALLOWED_TOOLS.join(",")
|
|
74073
74548
|
];
|
|
74074
|
-
const isRunningAsRoot = () => process.getuid?.() === 0;
|
|
74075
|
-
const CLAUDE_CODE_PERMISSION_ARGS = () => isRunningAsRoot() ? [
|
|
74076
|
-
"--permission-mode",
|
|
74077
|
-
"acceptEdits",
|
|
74078
|
-
"--allowed-tools",
|
|
74079
|
-
"Bash,Read,Write,Edit,MultiEdit,WebSearch,mcp__*"
|
|
74080
|
-
] : ["--permission-mode", "bypassPermissions"];
|
|
74081
74549
|
const CODEX_REQUIRED_ARGS = ["--json", "--skip-git-repo-check"];
|
|
74082
74550
|
const CODEX_BYPASS_APPROVALS_AND_SANDBOX_ARG = "--dangerously-bypass-approvals-and-sandbox";
|
|
74083
74551
|
const CODEX_DEFAULT_EXECUTION_ARGS = [CODEX_BYPASS_APPROVALS_AND_SANDBOX_ARG];
|
|
@@ -74121,11 +74589,14 @@ const QODER_BASE_ARGS = [
|
|
|
74121
74589
|
"bypass_permissions"
|
|
74122
74590
|
];
|
|
74123
74591
|
const hasAnyFlag = (args, flags) => args.some((arg) => flags.includes(arg));
|
|
74124
|
-
const buildClaudeCodeArgs = ({ extraArgs, includePartialMessages, inputArgs, liveInput, resumeSessionId }) => [
|
|
74592
|
+
const buildClaudeCodeArgs = ({ extraArgs, includePartialMessages, inputArgs, liveInput, permissionMode, permissionPrompts, resumeSessionId }) => [
|
|
74125
74593
|
...CLAUDE_CODE_BASE_ARGS,
|
|
74126
74594
|
...includePartialMessages ? ["--include-partial-messages"] : [],
|
|
74127
74595
|
...liveInput ? ["--replay-user-messages"] : [],
|
|
74128
|
-
...
|
|
74596
|
+
...buildClaudeCodePermissionArgs({
|
|
74597
|
+
hostPrompts: permissionPrompts,
|
|
74598
|
+
mode: permissionMode
|
|
74599
|
+
}),
|
|
74129
74600
|
...resumeSessionId ? ["--resume", resumeSessionId] : [],
|
|
74130
74601
|
...inputArgs,
|
|
74131
74602
|
...extraArgs
|
|
@@ -74269,6 +74740,8 @@ const spawnAgent = async (options) => {
|
|
|
74269
74740
|
/** One-shot JSONL CLI spawn; `spawnAgent` owns the Codex JWT file around it. */
|
|
74270
74741
|
const spawnCliAgent = async (options, command, cwd, inputPlan, childEnv, codexJwtFile) => {
|
|
74271
74742
|
const liveInput = options.agentType === "claude-code" && options.liveInput === true;
|
|
74743
|
+
const permissionMode = options.agentType === "claude-code" ? options.permissionMode : void 0;
|
|
74744
|
+
const permissionPrompts = liveInput && !!options.askUserBridge;
|
|
74272
74745
|
const args = buildSpawnArgs({
|
|
74273
74746
|
agentType: options.agentType,
|
|
74274
74747
|
configArgs: options.agentType === "codex" ? [...buildCodexLobeHubContextArgs(childEnv), ...codexJwtFile?.args ?? []] : void 0,
|
|
@@ -74276,6 +74749,8 @@ const spawnCliAgent = async (options, command, cwd, inputPlan, childEnv, codexJw
|
|
|
74276
74749
|
includePartialMessages: options.includePartialMessages ?? false,
|
|
74277
74750
|
inputArgs: inputPlan.args,
|
|
74278
74751
|
liveInput,
|
|
74752
|
+
permissionMode,
|
|
74753
|
+
permissionPrompts,
|
|
74279
74754
|
resumeSessionId: options.resumeSessionId
|
|
74280
74755
|
});
|
|
74281
74756
|
const initialModel = options.agentType === "codex" ? (await resolveCodexInitialModel({
|
|
@@ -74352,6 +74827,26 @@ const spawnCliAgent = async (options, command, cwd, inputPlan, childEnv, codexJw
|
|
|
74352
74827
|
exit.then(removeJwtFile, removeJwtFile);
|
|
74353
74828
|
}
|
|
74354
74829
|
const live = liveInput && proc.stdin ? new ClaudeCodeLiveInput(proc.stdin) : void 0;
|
|
74830
|
+
if (live && permissionMode && permissionPrompts && options.askUserBridge) {
|
|
74831
|
+
const bridge = options.askUserBridge;
|
|
74832
|
+
const isRoot = isRunningAsRoot();
|
|
74833
|
+
attachClaudeCodePermissionResponder(live, {
|
|
74834
|
+
ask: askThroughBridge(bridge),
|
|
74835
|
+
cancel: (toolCallId) => bridge.cancel(toolCallId, "session_ended"),
|
|
74836
|
+
isRoot
|
|
74837
|
+
});
|
|
74838
|
+
const reporter = new PermissionModeReporter(options.operationId, resolveClaudeCodePermissionMode(permissionMode, isRoot).fallback);
|
|
74839
|
+
live.onControlRequestSent((request, meta) => {
|
|
74840
|
+
const requestedMode = meta?.requestedMode;
|
|
74841
|
+
if (request.subtype === "set_permission_mode" && isHeteroPermissionMode(requestedMode)) reporter.requested(requestedMode, isRoot);
|
|
74842
|
+
});
|
|
74843
|
+
live.subscribe((message) => {
|
|
74844
|
+
const event = reporter.observe(message);
|
|
74845
|
+
if (!event) return;
|
|
74846
|
+
queue.push(event);
|
|
74847
|
+
wake();
|
|
74848
|
+
});
|
|
74849
|
+
}
|
|
74355
74850
|
if (live) live.send(inputPlan.stdin);
|
|
74356
74851
|
else if (proc.stdin) proc.stdin.write(inputPlan.stdin, () => {
|
|
74357
74852
|
proc.stdin?.end();
|
|
@@ -304049,15 +304544,15 @@ const listCodexModels = async ({ args = [], commandPath, cwd, env, timeoutMs })
|
|
|
304049
304544
|
includeHidden: false,
|
|
304050
304545
|
limit: 100
|
|
304051
304546
|
});
|
|
304052
|
-
if (!isRecord$
|
|
304547
|
+
if (!isRecord$8(page) || !Array.isArray(page.data)) throw new Error("Invalid Codex model catalog");
|
|
304053
304548
|
for (const item of page.data) {
|
|
304054
|
-
if (!isRecord$
|
|
304549
|
+
if (!isRecord$8(item) || typeof item.model !== "string" || !item.model.trim()) throw new Error("Invalid Codex model catalog entry");
|
|
304055
304550
|
if (item.hidden === true || models.has(item.model)) continue;
|
|
304056
304551
|
models.set(item.model, {
|
|
304057
304552
|
id: item.model,
|
|
304058
304553
|
...typeof item.displayName === "string" && item.displayName.trim() ? { label: item.displayName } : {},
|
|
304059
304554
|
...typeof item.isDefault === "boolean" ? { isDefault: item.isDefault } : {},
|
|
304060
|
-
...Array.isArray(item.serviceTiers) || Array.isArray(item.additionalSpeedTiers) ? { speedModes: [...new Set(["normal", ...(Array.isArray(item.serviceTiers) ? item.serviceTiers.map((tier) => isRecord$
|
|
304555
|
+
...Array.isArray(item.serviceTiers) || Array.isArray(item.additionalSpeedTiers) ? { speedModes: [...new Set(["normal", ...(Array.isArray(item.serviceTiers) ? item.serviceTiers.map((tier) => isRecord$8(tier) ? tier.id : void 0) : item.additionalSpeedTiers).flatMap((tier) => tier === "fast" || tier === "priority" ? ["fast"] : tier === "ultrafast" ? ["ultrafast"] : [])])] } : {},
|
|
304061
304556
|
modelId: item.model,
|
|
304062
304557
|
providerId: "codex"
|
|
304063
304558
|
});
|
|
@@ -304148,13 +304643,13 @@ const parseDevinModelCatalog = (stdout) => {
|
|
|
304148
304643
|
} catch {
|
|
304149
304644
|
return [];
|
|
304150
304645
|
}
|
|
304151
|
-
if (!isRecord$
|
|
304646
|
+
if (!isRecord$8(result) || !Array.isArray(result.families)) return [];
|
|
304152
304647
|
const seen = /* @__PURE__ */ new Set();
|
|
304153
304648
|
const models = [];
|
|
304154
304649
|
for (const family of result.families) {
|
|
304155
|
-
if (!isRecord$
|
|
304650
|
+
if (!isRecord$8(family) || !Array.isArray(family.variants)) continue;
|
|
304156
304651
|
for (const variant of family.variants) {
|
|
304157
|
-
if (!isRecord$
|
|
304652
|
+
if (!isRecord$8(variant) || typeof variant.model_uid !== "string" || !variant.model_uid) continue;
|
|
304158
304653
|
if (seen.has(variant.model_uid)) continue;
|
|
304159
304654
|
seen.add(variant.model_uid);
|
|
304160
304655
|
models.push({
|
|
@@ -304234,10 +304729,10 @@ const parseKimiCodeModelCatalog = (stdout) => {
|
|
|
304234
304729
|
} catch {
|
|
304235
304730
|
return [];
|
|
304236
304731
|
}
|
|
304237
|
-
if (!isRecord$
|
|
304732
|
+
if (!isRecord$8(result) || !isRecord$8(result.models)) return [];
|
|
304238
304733
|
const models = [];
|
|
304239
304734
|
for (const [alias, entry] of Object.entries(result.models)) {
|
|
304240
|
-
if (!alias || !isRecord$
|
|
304735
|
+
if (!alias || !isRecord$8(entry) || typeof entry.model !== "string" || !entry.model) continue;
|
|
304241
304736
|
const separatorIndex = alias.indexOf("/");
|
|
304242
304737
|
models.push({
|
|
304243
304738
|
id: alias,
|
|
@@ -327615,7 +328110,7 @@ var init_stream = __esmMin((() => {
|
|
|
327615
328110
|
}));
|
|
327616
328111
|
|
|
327617
328112
|
//#endregion
|
|
327618
|
-
//#region node_modules/.pnpm/jose@6.2.
|
|
328113
|
+
//#region node_modules/.pnpm/jose@6.2.18/node_modules/jose/dist/webapi/lib/buffer_utils.js
|
|
327619
328114
|
function concat(...buffers) {
|
|
327620
328115
|
const size = buffers.reduce((acc, { length }) => acc + length, 0), buf = new Uint8Array(size);
|
|
327621
328116
|
let i = 0;
|
|
@@ -327683,7 +328178,7 @@ var init_buffer_utils = __esmMin((() => {
|
|
|
327683
328178
|
}));
|
|
327684
328179
|
|
|
327685
328180
|
//#endregion
|
|
327686
|
-
//#region node_modules/.pnpm/jose@6.2.
|
|
328181
|
+
//#region node_modules/.pnpm/jose@6.2.18/node_modules/jose/dist/webapi/util/errors.js
|
|
327687
328182
|
var errors_exports = /* @__PURE__ */ __exportAll$2({
|
|
327688
328183
|
JOSEAlgNotAllowed: () => JOSEAlgNotAllowed,
|
|
327689
328184
|
JOSEError: () => JOSEError,
|
|
@@ -327805,7 +328300,7 @@ var init_errors = __esmMin((() => {
|
|
|
327805
328300
|
}));
|
|
327806
328301
|
|
|
327807
328302
|
//#endregion
|
|
327808
|
-
//#region node_modules/.pnpm/jose@6.2.
|
|
328303
|
+
//#region node_modules/.pnpm/jose@6.2.18/node_modules/jose/dist/webapi/util/base64url.js
|
|
327809
328304
|
var base64url_exports = /* @__PURE__ */ __exportAll$2({
|
|
327810
328305
|
decode: () => decode$1,
|
|
327811
328306
|
encode: () => encode$1
|
|
@@ -327827,7 +328322,7 @@ var init_base64url = __esmMin((() => {
|
|
|
327827
328322
|
}));
|
|
327828
328323
|
|
|
327829
328324
|
//#endregion
|
|
327830
|
-
//#region node_modules/.pnpm/jose@6.2.
|
|
328325
|
+
//#region node_modules/.pnpm/jose@6.2.18/node_modules/jose/dist/webapi/lib/validate.js
|
|
327831
328326
|
function assertUint8Array(input, label) {
|
|
327832
328327
|
if (!(input instanceof Uint8Array)) throw new TypeError(`${label} must be an instance of Uint8Array`);
|
|
327833
328328
|
}
|
|
@@ -327928,7 +328423,7 @@ var init_validate = __esmMin((() => {
|
|
|
327928
328423
|
}));
|
|
327929
328424
|
|
|
327930
328425
|
//#endregion
|
|
327931
|
-
//#region node_modules/.pnpm/jose@6.2.
|
|
328426
|
+
//#region node_modules/.pnpm/jose@6.2.18/node_modules/jose/dist/webapi/lib/key.js
|
|
327932
328427
|
async function prepareKey(entry, key, usage) {
|
|
327933
328428
|
const { alg, secret } = entry, requiresPrivateKey = usage === "decrypt" || usage === "sign";
|
|
327934
328429
|
if (secret && key instanceof Uint8Array) return key;
|
|
@@ -328043,6 +328538,7 @@ var init_key = __esmMin((() => {
|
|
|
328043
328538
|
const expected = usage === "sign" || usage === "verify" ? "sig" : "enc";
|
|
328044
328539
|
if (key.use !== expected) throw new TypeError(`Invalid key for this operation, its "use" must be "${expected}" when present`);
|
|
328045
328540
|
}
|
|
328541
|
+
if (key.kty === "AKP" && key.alg === void 0) throw new TypeError("missing \"alg\" (Algorithm) Parameter value");
|
|
328046
328542
|
if (key.alg !== void 0 && key.alg !== alg) throw new TypeError(`Invalid key for this operation, its "alg" must be "${alg}" when present`);
|
|
328047
328543
|
if (Array.isArray(key.key_ops)) {
|
|
328048
328544
|
const expectedKeyOp = usage === "encrypt" || usage === "decrypt" ? entry.ops?.[usage === "encrypt" ? 0 : 1] : usage;
|
|
@@ -328069,7 +328565,7 @@ var init_key = __esmMin((() => {
|
|
|
328069
328565
|
}));
|
|
328070
328566
|
|
|
328071
328567
|
//#endregion
|
|
328072
|
-
//#region node_modules/.pnpm/jose@6.2.
|
|
328568
|
+
//#region node_modules/.pnpm/jose@6.2.18/node_modules/jose/dist/webapi/lib/content_encryption.js
|
|
328073
328569
|
function checkCekLength(cek, expected) {
|
|
328074
328570
|
const actual = cek.byteLength << 3;
|
|
328075
328571
|
if (actual !== expected) throw new JWEInvalid(`Invalid Content Encryption Key length. Expected ${expected} bits, got ${actual} bits`);
|
|
@@ -328163,7 +328659,7 @@ var init_content_encryption = __esmMin((() => {
|
|
|
328163
328659
|
}));
|
|
328164
328660
|
|
|
328165
328661
|
//#endregion
|
|
328166
|
-
//#region node_modules/.pnpm/jose@6.2.
|
|
328662
|
+
//#region node_modules/.pnpm/jose@6.2.18/node_modules/jose/dist/webapi/lib/key_descriptor.js
|
|
328167
328663
|
function table(entries) {
|
|
328168
328664
|
const out = { __proto__: null };
|
|
328169
328665
|
for (const alg in entries) out[alg] = {
|
|
@@ -328175,7 +328671,7 @@ function table(entries) {
|
|
|
328175
328671
|
var init_key_descriptor = __esmMin((() => {}));
|
|
328176
328672
|
|
|
328177
328673
|
//#endregion
|
|
328178
|
-
//#region node_modules/.pnpm/jose@6.2.
|
|
328674
|
+
//#region node_modules/.pnpm/jose@6.2.18/node_modules/jose/dist/webapi/lib/jwe_algorithms.js
|
|
328179
328675
|
function rsaes(bits) {
|
|
328180
328676
|
return {
|
|
328181
328677
|
kty: ["RSA"],
|
|
@@ -328298,7 +328794,7 @@ var init_jwe_algorithms = __esmMin((() => {
|
|
|
328298
328794
|
}));
|
|
328299
328795
|
|
|
328300
328796
|
//#endregion
|
|
328301
|
-
//#region node_modules/.pnpm/jose@6.2.
|
|
328797
|
+
//#region node_modules/.pnpm/jose@6.2.18/node_modules/jose/dist/webapi/lib/key_management.js
|
|
328302
328798
|
function checkEcdhCryptoKey(key, usage) {
|
|
328303
328799
|
if (key.algorithm.name !== "ECDH" && key.algorithm.name !== "X25519") throw new TypeError("CryptoKey does not support this operation, its algorithm.name must be ECDH or X25519");
|
|
328304
328800
|
checkUsage(key, usage);
|
|
@@ -328502,7 +328998,7 @@ var init_key_management = __esmMin((() => {
|
|
|
328502
328998
|
}));
|
|
328503
328999
|
|
|
328504
329000
|
//#endregion
|
|
328505
|
-
//#region node_modules/.pnpm/jose@6.2.
|
|
329001
|
+
//#region node_modules/.pnpm/jose@6.2.18/node_modules/jose/dist/webapi/lib/deflate.js
|
|
328506
329002
|
function validateZip(joseHeader, protectedHeader) {
|
|
328507
329003
|
if (joseHeader.zip !== void 0 && joseHeader.zip !== "DEF") throw new JOSENotSupported("Unsupported JWE \"zip\" (Compression Algorithm) Header Parameter value.");
|
|
328508
329004
|
if (joseHeader.zip !== void 0 && !protectedHeader?.zip) throw new JWEInvalid("JWE \"zip\" (Compression Algorithm) Header Parameter MUST be in a protected header.");
|
|
@@ -328535,7 +329031,7 @@ var init_deflate = __esmMin((() => {
|
|
|
328535
329031
|
}));
|
|
328536
329032
|
|
|
328537
329033
|
//#endregion
|
|
328538
|
-
//#region node_modules/.pnpm/jose@6.2.
|
|
329034
|
+
//#region node_modules/.pnpm/jose@6.2.18/node_modules/jose/dist/webapi/lib/jwe_decrypt.js
|
|
328539
329035
|
function snapshotSharedJWE(jwe) {
|
|
328540
329036
|
const { aad, ciphertext, iv, protected: encodedProtected, tag, unprotected } = jwe;
|
|
328541
329037
|
if (iv !== void 0 && (typeof iv != "string" || !iv)) throw new JWEInvalid("JWE Initialization Vector incorrect type");
|
|
@@ -328663,7 +329159,7 @@ async function decryptJWE(jwe, shared, key, token = shareJWE(jwe)) {
|
|
|
328663
329159
|
const decompressionLimit = maxDecompressedLength ?? 25e4;
|
|
328664
329160
|
if (decompressionLimit === 0) throw new JOSENotSupported("JWE \"zip\" (Compression Algorithm) Header Parameter is not supported.");
|
|
328665
329161
|
plaintext = await decompress(plaintext, decompressionLimit).catch((cause) => {
|
|
328666
|
-
throw cause instanceof JWEInvalid ? cause : new JWEInvalid("Failed to decompress plaintext", { cause });
|
|
329162
|
+
throw cause instanceof JWEInvalid || cause instanceof JOSENotSupported ? cause : new JWEInvalid("Failed to decompress plaintext", { cause });
|
|
328667
329163
|
});
|
|
328668
329164
|
}
|
|
328669
329165
|
return {
|
|
@@ -328699,7 +329195,7 @@ var init_jwe_decrypt = __esmMin((() => {
|
|
|
328699
329195
|
}));
|
|
328700
329196
|
|
|
328701
329197
|
//#endregion
|
|
328702
|
-
//#region node_modules/.pnpm/jose@6.2.
|
|
329198
|
+
//#region node_modules/.pnpm/jose@6.2.18/node_modules/jose/dist/webapi/jwe/compact/decrypt.js
|
|
328703
329199
|
async function compactDecrypt(jwe, key, options) {
|
|
328704
329200
|
return decryptCompact(jwe, prepareDecrypt(options), key);
|
|
328705
329201
|
}
|
|
@@ -328708,7 +329204,7 @@ var init_decrypt$3 = __esmMin((() => {
|
|
|
328708
329204
|
}));
|
|
328709
329205
|
|
|
328710
329206
|
//#endregion
|
|
328711
|
-
//#region node_modules/.pnpm/jose@6.2.
|
|
329207
|
+
//#region node_modules/.pnpm/jose@6.2.18/node_modules/jose/dist/webapi/jwe/flattened/decrypt.js
|
|
328712
329208
|
async function flattenedDecrypt(jwe, key, options) {
|
|
328713
329209
|
if (!isObject$1(jwe)) throw new JWEInvalid("Flattened JWE must be an object");
|
|
328714
329210
|
const shared = snapshotSharedJWE(jwe), [recipient, , error] = snapshotRecipientJWE(jwe);
|
|
@@ -328726,7 +329222,7 @@ var init_decrypt$2 = __esmMin((() => {
|
|
|
328726
329222
|
}));
|
|
328727
329223
|
|
|
328728
329224
|
//#endregion
|
|
328729
|
-
//#region node_modules/.pnpm/jose@6.2.
|
|
329225
|
+
//#region node_modules/.pnpm/jose@6.2.18/node_modules/jose/dist/webapi/jwe/general/decrypt.js
|
|
328730
329226
|
async function generalDecrypt(jwe, key, options) {
|
|
328731
329227
|
if (!isObject$1(jwe)) throw new JWEInvalid("General JWE must be an object");
|
|
328732
329228
|
const inputRecipients = jwe.recipients;
|
|
@@ -328763,7 +329259,7 @@ var init_decrypt$1 = __esmMin((() => {
|
|
|
328763
329259
|
}));
|
|
328764
329260
|
|
|
328765
329261
|
//#endregion
|
|
328766
|
-
//#region node_modules/.pnpm/jose@6.2.
|
|
329262
|
+
//#region node_modules/.pnpm/jose@6.2.18/node_modules/jose/dist/webapi/lib/jwe_encrypt.js
|
|
328767
329263
|
function checkDisjoint(protectedHeader, unprotectedHeader, sharedUnprotectedHeader) {
|
|
328768
329264
|
if (!isDisjoint(protectedHeader, unprotectedHeader, sharedUnprotectedHeader)) throw new JWEInvalid("JWE Protected, JWE Shared Unprotected and JWE Per-Recipient Header Parameter names must be disjoint");
|
|
328769
329265
|
}
|
|
@@ -328814,7 +329310,7 @@ async function encryptJWE(input, checked, key) {
|
|
|
328814
329310
|
const encodedProtectedHeader = protectedHeader ? encode$1(JSON.stringify(protectedHeader)) : "", encodedAad = aad?.byteLength ? encode$1(aad) : void 0, additionalAuthenticatedData = encode$2(encodedAad ? `${encodedProtectedHeader}.${encodedAad}` : encodedProtectedHeader);
|
|
328815
329311
|
let plaintext = inputPlaintext;
|
|
328816
329312
|
joseHeader.zip === "DEF" && (plaintext = await compress(plaintext).catch((cause) => {
|
|
328817
|
-
throw new JWEInvalid("Failed to compress plaintext", { cause });
|
|
329313
|
+
throw cause instanceof JOSENotSupported ? cause : new JWEInvalid("Failed to compress plaintext", { cause });
|
|
328818
329314
|
}));
|
|
328819
329315
|
let ciphertext, tag, iv;
|
|
328820
329316
|
algEntry.mode === "integrated-encryption" ? [encryptedKey, ciphertext] = await algEntry.encrypt(cek, plaintext, additionalAuthenticatedData, protectedHeader, joseHeader, keyManagementParameters) : {ciphertext, tag, iv} = await encrypt(encEntry, plaintext, cek, inputIv, additionalAuthenticatedData);
|
|
@@ -328846,7 +329342,7 @@ var init_jwe_encrypt = __esmMin((() => {
|
|
|
328846
329342
|
}));
|
|
328847
329343
|
|
|
328848
329344
|
//#endregion
|
|
328849
|
-
//#region node_modules/.pnpm/jose@6.2.
|
|
329345
|
+
//#region node_modules/.pnpm/jose@6.2.18/node_modules/jose/dist/webapi/jwe/general/encrypt.js
|
|
328850
329346
|
var IndividualRecipient, GeneralEncrypt;
|
|
328851
329347
|
var init_encrypt$3 = __esmMin((() => {
|
|
328852
329348
|
init_validate();
|
|
@@ -328959,7 +329455,7 @@ var init_encrypt$3 = __esmMin((() => {
|
|
|
328959
329455
|
}));
|
|
328960
329456
|
|
|
328961
329457
|
//#endregion
|
|
328962
|
-
//#region node_modules/.pnpm/jose@6.2.
|
|
329458
|
+
//#region node_modules/.pnpm/jose@6.2.18/node_modules/jose/dist/webapi/lib/jws_algorithms.js
|
|
328963
329459
|
function hmac(bits) {
|
|
328964
329460
|
const subtle = {
|
|
328965
329461
|
name: "HMAC",
|
|
@@ -329055,7 +329551,7 @@ var init_jws_algorithms = __esmMin((() => {
|
|
|
329055
329551
|
}));
|
|
329056
329552
|
|
|
329057
329553
|
//#endregion
|
|
329058
|
-
//#region node_modules/.pnpm/jose@6.2.
|
|
329554
|
+
//#region node_modules/.pnpm/jose@6.2.18/node_modules/jose/dist/webapi/lib/jws_verify.js
|
|
329059
329555
|
function snapshotJws(jws, sharedPayload) {
|
|
329060
329556
|
const encodedProtectedHeader = jws.protected, inputHeader = jws.header, header = isObject$1(inputHeader) ? { ...inputHeader } : inputHeader;
|
|
329061
329557
|
let payload = sharedPayload ? sharedPayload[0] : jws.payload;
|
|
@@ -329138,7 +329634,7 @@ var init_jws_verify = __esmMin((() => {
|
|
|
329138
329634
|
}));
|
|
329139
329635
|
|
|
329140
329636
|
//#endregion
|
|
329141
|
-
//#region node_modules/.pnpm/jose@6.2.
|
|
329637
|
+
//#region node_modules/.pnpm/jose@6.2.18/node_modules/jose/dist/webapi/jws/compact/verify.js
|
|
329142
329638
|
async function compactVerify(jws, key, options) {
|
|
329143
329639
|
const [result] = await verifyCompact(jws, prepareVerify(options), key);
|
|
329144
329640
|
return result;
|
|
@@ -329148,7 +329644,7 @@ var init_verify$3 = __esmMin((() => {
|
|
|
329148
329644
|
}));
|
|
329149
329645
|
|
|
329150
329646
|
//#endregion
|
|
329151
|
-
//#region node_modules/.pnpm/jose@6.2.
|
|
329647
|
+
//#region node_modules/.pnpm/jose@6.2.18/node_modules/jose/dist/webapi/jws/flattened/verify.js
|
|
329152
329648
|
async function flattenedVerify(jws, key, options) {
|
|
329153
329649
|
if (!isObject$1(jws)) throw new JWSInvalid("Flattened JWS must be an object");
|
|
329154
329650
|
const [result] = await verifySignature(snapshotJws(jws), prepareVerify(options), key, encodeJsonUnencodedPayload);
|
|
@@ -329161,7 +329657,7 @@ var init_verify$2 = __esmMin((() => {
|
|
|
329161
329657
|
}));
|
|
329162
329658
|
|
|
329163
329659
|
//#endregion
|
|
329164
|
-
//#region node_modules/.pnpm/jose@6.2.
|
|
329660
|
+
//#region node_modules/.pnpm/jose@6.2.18/node_modules/jose/dist/webapi/jws/general/verify.js
|
|
329165
329661
|
function snapshotSignature(signature, payload) {
|
|
329166
329662
|
try {
|
|
329167
329663
|
const jws = snapshotJws(signature, [payload]), protectedHeader = parseProtectedHeader(jws.protected), { b64, crit } = protectedHeader;
|
|
@@ -329197,7 +329693,7 @@ var init_verify$1 = __esmMin((() => {
|
|
|
329197
329693
|
}));
|
|
329198
329694
|
|
|
329199
329695
|
//#endregion
|
|
329200
|
-
//#region node_modules/.pnpm/jose@6.2.
|
|
329696
|
+
//#region node_modules/.pnpm/jose@6.2.18/node_modules/jose/dist/webapi/lib/jwt_claims_set.js
|
|
329201
329697
|
function invalidDuration() {
|
|
329202
329698
|
throw new TypeError("Invalid time period format");
|
|
329203
329699
|
}
|
|
@@ -329206,7 +329702,7 @@ function secs(str) {
|
|
|
329206
329702
|
const matched = REGEX.exec(str);
|
|
329207
329703
|
(!matched || matched[4] && matched[1]) && invalidDuration();
|
|
329208
329704
|
const value = parseFloat(matched[2]), durationSeconds = Math.round(value * multipliers[matched[3][0].toLowerCase()]);
|
|
329209
|
-
return Number.isFinite(durationSeconds) || invalidDuration(), matched[1] === "-" || matched[4] === "ago" ? -durationSeconds : durationSeconds;
|
|
329705
|
+
return Number.isFinite(durationSeconds) || invalidDuration(), matched[1] === "-" || matched[4]?.toLowerCase() === "ago" ? -durationSeconds : durationSeconds;
|
|
329210
329706
|
}
|
|
329211
329707
|
function validateInput(label, input) {
|
|
329212
329708
|
if (!Number.isFinite(input)) throw new TypeError(`Invalid ${label} input`);
|
|
@@ -329332,7 +329828,7 @@ var init_jwt_claims_set = __esmMin((() => {
|
|
|
329332
329828
|
}));
|
|
329333
329829
|
|
|
329334
329830
|
//#endregion
|
|
329335
|
-
//#region node_modules/.pnpm/jose@6.2.
|
|
329831
|
+
//#region node_modules/.pnpm/jose@6.2.18/node_modules/jose/dist/webapi/jwt/verify.js
|
|
329336
329832
|
async function jwtVerify(jwt, key, options) {
|
|
329337
329833
|
const [verified, b64] = await verifyCompact(jwt, prepareVerify(options), key);
|
|
329338
329834
|
if (!b64) throw new JWTInvalid("JWTs MUST NOT use unencoded payload");
|
|
@@ -329349,7 +329845,7 @@ var init_verify = __esmMin((() => {
|
|
|
329349
329845
|
}));
|
|
329350
329846
|
|
|
329351
329847
|
//#endregion
|
|
329352
|
-
//#region node_modules/.pnpm/jose@6.2.
|
|
329848
|
+
//#region node_modules/.pnpm/jose@6.2.18/node_modules/jose/dist/webapi/jwt/decrypt.js
|
|
329353
329849
|
async function jwtDecrypt(jwt, key, options) {
|
|
329354
329850
|
const { plaintext, ...result } = await decryptCompact(jwt, prepareDecrypt(options), key), { protectedHeader } = result, payload = validateClaimsSet(protectedHeader, plaintext, options);
|
|
329355
329851
|
for (const claim of [
|
|
@@ -329369,7 +329865,7 @@ var init_decrypt = __esmMin((() => {
|
|
|
329369
329865
|
}));
|
|
329370
329866
|
|
|
329371
329867
|
//#endregion
|
|
329372
|
-
//#region node_modules/.pnpm/jose@6.2.
|
|
329868
|
+
//#region node_modules/.pnpm/jose@6.2.18/node_modules/jose/dist/webapi/jwe/compact/encrypt.js
|
|
329373
329869
|
var CompactEncrypt;
|
|
329374
329870
|
var init_encrypt$2 = __esmMin((() => {
|
|
329375
329871
|
init_validate();
|
|
@@ -329398,7 +329894,7 @@ var init_encrypt$2 = __esmMin((() => {
|
|
|
329398
329894
|
}));
|
|
329399
329895
|
|
|
329400
329896
|
//#endregion
|
|
329401
|
-
//#region node_modules/.pnpm/jose@6.2.
|
|
329897
|
+
//#region node_modules/.pnpm/jose@6.2.18/node_modules/jose/dist/webapi/jwe/flattened/encrypt.js
|
|
329402
329898
|
var FlattenedEncrypt;
|
|
329403
329899
|
var init_encrypt$1 = __esmMin((() => {
|
|
329404
329900
|
init_validate();
|
|
@@ -329436,7 +329932,7 @@ var init_encrypt$1 = __esmMin((() => {
|
|
|
329436
329932
|
}));
|
|
329437
329933
|
|
|
329438
329934
|
//#endregion
|
|
329439
|
-
//#region node_modules/.pnpm/jose@6.2.
|
|
329935
|
+
//#region node_modules/.pnpm/jose@6.2.18/node_modules/jose/dist/webapi/lib/jws_sign.js
|
|
329440
329936
|
async function createSignature(input, key, rejectUnencoded) {
|
|
329441
329937
|
let [payload, protectedHeader, unprotectedHeader, crit] = input, encodedProtectedHeader = "";
|
|
329442
329938
|
if (protectedHeader !== void 0) {
|
|
@@ -329488,7 +329984,7 @@ var init_jws_sign = __esmMin((() => {
|
|
|
329488
329984
|
}));
|
|
329489
329985
|
|
|
329490
329986
|
//#endregion
|
|
329491
|
-
//#region node_modules/.pnpm/jose@6.2.
|
|
329987
|
+
//#region node_modules/.pnpm/jose@6.2.18/node_modules/jose/dist/webapi/jws/compact/sign.js
|
|
329492
329988
|
var CompactSign;
|
|
329493
329989
|
var init_sign$3 = __esmMin((() => {
|
|
329494
329990
|
init_jws_sign();
|
|
@@ -329511,7 +330007,7 @@ var init_sign$3 = __esmMin((() => {
|
|
|
329511
330007
|
}));
|
|
329512
330008
|
|
|
329513
330009
|
//#endregion
|
|
329514
|
-
//#region node_modules/.pnpm/jose@6.2.
|
|
330010
|
+
//#region node_modules/.pnpm/jose@6.2.18/node_modules/jose/dist/webapi/jws/flattened/sign.js
|
|
329515
330011
|
var FlattenedSign;
|
|
329516
330012
|
var init_sign$2 = __esmMin((() => {
|
|
329517
330013
|
init_jws_sign();
|
|
@@ -329537,7 +330033,7 @@ var init_sign$2 = __esmMin((() => {
|
|
|
329537
330033
|
}));
|
|
329538
330034
|
|
|
329539
330035
|
//#endregion
|
|
329540
|
-
//#region node_modules/.pnpm/jose@6.2.
|
|
330036
|
+
//#region node_modules/.pnpm/jose@6.2.18/node_modules/jose/dist/webapi/jws/general/sign.js
|
|
329541
330037
|
var IndividualSignature, GeneralSign;
|
|
329542
330038
|
var init_sign$1 = __esmMin((() => {
|
|
329543
330039
|
init_jws_sign();
|
|
@@ -329606,7 +330102,7 @@ var init_sign$1 = __esmMin((() => {
|
|
|
329606
330102
|
}));
|
|
329607
330103
|
|
|
329608
330104
|
//#endregion
|
|
329609
|
-
//#region node_modules/.pnpm/jose@6.2.
|
|
330105
|
+
//#region node_modules/.pnpm/jose@6.2.18/node_modules/jose/dist/webapi/jwt/sign.js
|
|
329610
330106
|
var SignJWT_base, SignJWT;
|
|
329611
330107
|
var init_sign = __esmMin((() => {
|
|
329612
330108
|
init_jws_sign();
|
|
@@ -329628,7 +330124,7 @@ var init_sign = __esmMin((() => {
|
|
|
329628
330124
|
}));
|
|
329629
330125
|
|
|
329630
330126
|
//#endregion
|
|
329631
|
-
//#region node_modules/.pnpm/jose@6.2.
|
|
330127
|
+
//#region node_modules/.pnpm/jose@6.2.18/node_modules/jose/dist/webapi/jwt/encrypt.js
|
|
329632
330128
|
var EncryptJWT_base, EncryptJWT;
|
|
329633
330129
|
var init_encrypt = __esmMin((() => {
|
|
329634
330130
|
init_jwe_encrypt();
|
|
@@ -329662,21 +330158,18 @@ var init_encrypt = __esmMin((() => {
|
|
|
329662
330158
|
return this.#replicateAudienceAsHeader = !0, this;
|
|
329663
330159
|
}
|
|
329664
330160
|
async encrypt(key, options) {
|
|
329665
|
-
const plaintext = jwtClaimsSetBytes(this);
|
|
329666
|
-
this.#input[1] && (this.#replicateIssuerAsHeader || this.#replicateSubjectAsHeader || this.#replicateAudienceAsHeader) && (this.#input[1] = {
|
|
329667
|
-
...this.#input[1],
|
|
329668
|
-
iss: this.#replicateIssuerAsHeader ? jwtClaim(this, "iss") : void 0,
|
|
329669
|
-
sub: this.#replicateSubjectAsHeader ? jwtClaim(this, "sub") : void 0,
|
|
329670
|
-
aud: this.#replicateAudienceAsHeader ? jwtClaim(this, "aud") : void 0
|
|
329671
|
-
});
|
|
329672
330161
|
const input = [...this.#input];
|
|
329673
|
-
|
|
330162
|
+
if (input[0] = jwtClaimsSetBytes(this), input[1] && (this.#replicateIssuerAsHeader || this.#replicateSubjectAsHeader || this.#replicateAudienceAsHeader)) {
|
|
330163
|
+
const header = { ...input[1] };
|
|
330164
|
+
this.#replicateIssuerAsHeader && (header.iss = jwtClaim(this, "iss")), this.#replicateSubjectAsHeader && (header.sub = jwtClaim(this, "sub")), this.#replicateAudienceAsHeader && (header.aud = jwtClaim(this, "aud")), input[1] = header;
|
|
330165
|
+
}
|
|
330166
|
+
return compactJWE(await createJWE(input, key, options));
|
|
329674
330167
|
}
|
|
329675
330168
|
};
|
|
329676
330169
|
}));
|
|
329677
330170
|
|
|
329678
330171
|
//#endregion
|
|
329679
|
-
//#region node_modules/.pnpm/jose@6.2.
|
|
330172
|
+
//#region node_modules/.pnpm/jose@6.2.18/node_modules/jose/dist/webapi/lib/key_algorithm.js
|
|
329680
330173
|
function unsupportedAlg(source = "JWK \"alg\" (Algorithm) Parameter") {
|
|
329681
330174
|
throw new JOSENotSupported(`Invalid or unsupported ${source} value`);
|
|
329682
330175
|
}
|
|
@@ -329692,7 +330185,7 @@ var init_key_algorithm = __esmMin((() => {
|
|
|
329692
330185
|
}));
|
|
329693
330186
|
|
|
329694
330187
|
//#endregion
|
|
329695
|
-
//#region node_modules/.pnpm/jose@6.2.
|
|
330188
|
+
//#region node_modules/.pnpm/jose@6.2.18/node_modules/jose/dist/webapi/lib/asn1.js
|
|
329696
330189
|
function parseKeyHeader(state, keyFormat) {
|
|
329697
330190
|
if (expectTag(state, 48, `Invalid ${keyFormat === "spki" ? "SPKI" : "PKCS#8"} structure`), parseLength(state), keyFormat === "pkcs8") {
|
|
329698
330191
|
expectTag(state, 2, "Expected version field");
|
|
@@ -329844,7 +330337,7 @@ ${(b64.match(/.{1,64}/g) || []).join(`
|
|
|
329844
330337
|
}));
|
|
329845
330338
|
|
|
329846
330339
|
//#endregion
|
|
329847
|
-
//#region node_modules/.pnpm/jose@6.2.
|
|
330340
|
+
//#region node_modules/.pnpm/jose@6.2.18/node_modules/jose/dist/webapi/key/export.js
|
|
329848
330341
|
function exportSPKI(key) {
|
|
329849
330342
|
return toSPKI(key);
|
|
329850
330343
|
}
|
|
@@ -329872,7 +330365,7 @@ var init_export = __esmMin((() => {
|
|
|
329872
330365
|
}));
|
|
329873
330366
|
|
|
329874
330367
|
//#endregion
|
|
329875
|
-
//#region node_modules/.pnpm/jose@6.2.
|
|
330368
|
+
//#region node_modules/.pnpm/jose@6.2.18/node_modules/jose/dist/webapi/jwk/thumbprint.js
|
|
329876
330369
|
async function calculateJwkThumbprint(key, digestAlgorithm) {
|
|
329877
330370
|
let jwk;
|
|
329878
330371
|
if (isObject$1(key)) {
|
|
@@ -329942,7 +330435,7 @@ var init_thumbprint = __esmMin((() => {
|
|
|
329942
330435
|
}));
|
|
329943
330436
|
|
|
329944
330437
|
//#endregion
|
|
329945
|
-
//#region node_modules/.pnpm/jose@6.2.
|
|
330438
|
+
//#region node_modules/.pnpm/jose@6.2.18/node_modules/jose/dist/webapi/jwk/embedded.js
|
|
329946
330439
|
async function EmbeddedJWK(protectedHeader, token) {
|
|
329947
330440
|
const joseHeader = {
|
|
329948
330441
|
...protectedHeader,
|
|
@@ -329970,7 +330463,7 @@ var init_embedded = __esmMin((() => {
|
|
|
329970
330463
|
}));
|
|
329971
330464
|
|
|
329972
330465
|
//#endregion
|
|
329973
|
-
//#region node_modules/.pnpm/jose@6.2.
|
|
330466
|
+
//#region node_modules/.pnpm/jose@6.2.18/node_modules/jose/dist/webapi/jwks/local.js
|
|
329974
330467
|
function isUsableJWK(jwk, entry, alg, kid) {
|
|
329975
330468
|
const { kty, key_ops: keyOps, ext, kid: jwkKid, alg: jwkAlg, use, crv } = jwk;
|
|
329976
330469
|
return (ext === void 0 || typeof ext == "boolean") && (keyOps === void 0 || Array.isArray(keyOps) && keyOps.every((operation, index) => typeof operation == "string" && keyOps.indexOf(operation) === index) && keyOps.includes("verify")) && entry.kty.includes(kty) && (kid === void 0 || typeof kid == "string" && kid === jwkKid) && (jwkAlg === void 0 ? kty !== "AKP" : alg === jwkAlg) && (use === void 0 || use === "sig") && (!entry.crv || crv === entry.crv);
|
|
@@ -330027,7 +330520,7 @@ var init_local = __esmMin((() => {
|
|
|
330027
330520
|
}));
|
|
330028
330521
|
|
|
330029
330522
|
//#endregion
|
|
330030
|
-
//#region node_modules/.pnpm/jose@6.2.
|
|
330523
|
+
//#region node_modules/.pnpm/jose@6.2.18/node_modules/jose/dist/webapi/jwks/remote.js
|
|
330031
330524
|
function isCloudflareWorkers() {
|
|
330032
330525
|
return typeof WebSocketPair < "u" || typeof navigator < "u" && navigator.userAgent === "Cloudflare-Workers" || typeof EdgeRuntime < "u" && EdgeRuntime === "vercel";
|
|
330033
330526
|
}
|
|
@@ -330044,7 +330537,7 @@ async function fetchJwks(url, headers, signal, fetchImpl = fetch) {
|
|
|
330044
330537
|
try {
|
|
330045
330538
|
return await response.json();
|
|
330046
330539
|
} catch (cause) {
|
|
330047
|
-
throw new JOSEError("Failed to parse the JSON Web Key Set HTTP response as JSON", { cause });
|
|
330540
|
+
throw signal.aborted ? new JWKSTimeout(void 0, { cause }) : new JOSEError("Failed to parse the JSON Web Key Set HTTP response as JSON", { cause });
|
|
330048
330541
|
}
|
|
330049
330542
|
}
|
|
330050
330543
|
function isFreshFor(timestamp, duration) {
|
|
@@ -330118,13 +330611,13 @@ var init_remote = __esmMin((() => {
|
|
|
330118
330611
|
init_local();
|
|
330119
330612
|
init_validate();
|
|
330120
330613
|
;
|
|
330121
|
-
(typeof navigator > "u" || !navigator.userAgent?.startsWith?.("Mozilla/5.0 ")) && (USER_AGENT = "jose/v6.2.
|
|
330614
|
+
(typeof navigator > "u" || !navigator.userAgent?.startsWith?.("Mozilla/5.0 ")) && (USER_AGENT = "jose/v6.2.18");
|
|
330122
330615
|
customFetch = /* @__PURE__ */ Symbol();
|
|
330123
330616
|
jwksCache = /* @__PURE__ */ Symbol();
|
|
330124
330617
|
}));
|
|
330125
330618
|
|
|
330126
330619
|
//#endregion
|
|
330127
|
-
//#region node_modules/.pnpm/jose@6.2.
|
|
330620
|
+
//#region node_modules/.pnpm/jose@6.2.18/node_modules/jose/dist/webapi/jwt/unsecured.js
|
|
330128
330621
|
var UnsecuredJWT_base, UnsecuredJWT;
|
|
330129
330622
|
var init_unsecured = __esmMin((() => {
|
|
330130
330623
|
init_base64url();
|
|
@@ -330159,7 +330652,7 @@ var init_unsecured = __esmMin((() => {
|
|
|
330159
330652
|
}));
|
|
330160
330653
|
|
|
330161
330654
|
//#endregion
|
|
330162
|
-
//#region node_modules/.pnpm/jose@6.2.
|
|
330655
|
+
//#region node_modules/.pnpm/jose@6.2.18/node_modules/jose/dist/webapi/key/import.js
|
|
330163
330656
|
async function importSPKI(spki, alg, options) {
|
|
330164
330657
|
if (typeof spki != "string" || spki.indexOf("-----BEGIN PUBLIC KEY-----") !== 0) throw new TypeError("\"spki\" must be SPKI formatted string");
|
|
330165
330658
|
return fromSPKI(spki, alg, options);
|
|
@@ -330200,7 +330693,7 @@ var init_import = __esmMin((() => {
|
|
|
330200
330693
|
}));
|
|
330201
330694
|
|
|
330202
330695
|
//#endregion
|
|
330203
|
-
//#region node_modules/.pnpm/jose@6.2.
|
|
330696
|
+
//#region node_modules/.pnpm/jose@6.2.18/node_modules/jose/dist/webapi/util/decode_protected_header.js
|
|
330204
330697
|
function decodeProtectedHeader(token) {
|
|
330205
330698
|
let encodedProtectedHeader;
|
|
330206
330699
|
if (typeof token == "string") {
|
|
@@ -330217,7 +330710,7 @@ var init_decode_protected_header = __esmMin((() => {
|
|
|
330217
330710
|
}));
|
|
330218
330711
|
|
|
330219
330712
|
//#endregion
|
|
330220
|
-
//#region node_modules/.pnpm/jose@6.2.
|
|
330713
|
+
//#region node_modules/.pnpm/jose@6.2.18/node_modules/jose/dist/webapi/util/decode_jwt.js
|
|
330221
330714
|
function decodeJwt(jwt) {
|
|
330222
330715
|
if (typeof jwt != "string") throw new JWTInvalid("JWTs must use Compact JWS serialization, JWT must be a string");
|
|
330223
330716
|
const { 1: encodedPayload, length } = jwt.split(".");
|
|
@@ -330247,7 +330740,7 @@ var init_decode_jwt = __esmMin((() => {
|
|
|
330247
330740
|
}));
|
|
330248
330741
|
|
|
330249
330742
|
//#endregion
|
|
330250
|
-
//#region node_modules/.pnpm/jose@6.2.
|
|
330743
|
+
//#region node_modules/.pnpm/jose@6.2.18/node_modules/jose/dist/webapi/key/generate_key_pair.js
|
|
330251
330744
|
function getModulusLengthOption(options) {
|
|
330252
330745
|
const modulusLength = options?.modulusLength ?? 2048;
|
|
330253
330746
|
if (typeof modulusLength != "number" || !Number.isInteger(modulusLength) || modulusLength < 2048) throw new JOSENotSupported("Invalid or unsupported modulusLength option provided, 2048 bits or larger keys must be used");
|
|
@@ -330283,7 +330776,7 @@ var init_generate_key_pair = __esmMin((() => {
|
|
|
330283
330776
|
}));
|
|
330284
330777
|
|
|
330285
330778
|
//#endregion
|
|
330286
|
-
//#region node_modules/.pnpm/jose@6.2.
|
|
330779
|
+
//#region node_modules/.pnpm/jose@6.2.18/node_modules/jose/dist/webapi/key/generate_secret.js
|
|
330287
330780
|
async function generateSecret(alg, options) {
|
|
330288
330781
|
const extractable = validateExtractableOption(options?.extractable);
|
|
330289
330782
|
let keyLengthBits, algorithm, keyUsages;
|
|
@@ -330329,7 +330822,7 @@ var init_generate_secret = __esmMin((() => {
|
|
|
330329
330822
|
}));
|
|
330330
330823
|
|
|
330331
330824
|
//#endregion
|
|
330332
|
-
//#region node_modules/.pnpm/jose@6.2.
|
|
330825
|
+
//#region node_modules/.pnpm/jose@6.2.18/node_modules/jose/dist/webapi/index.js
|
|
330333
330826
|
var webapi_exports = /* @__PURE__ */ __exportAll$2({
|
|
330334
330827
|
CompactEncrypt: () => CompactEncrypt,
|
|
330335
330828
|
CompactSign: () => CompactSign,
|
|
@@ -553507,6 +554000,7 @@ function startHeteroAgentRun(params, accountEnv, logger) {
|
|
|
553507
554000
|
const stdinPayload = buildHeteroExecStdinPayload({
|
|
553508
554001
|
imageList,
|
|
553509
554002
|
isNewSession: !resumeSessionId,
|
|
554003
|
+
permissionMode: params.permissionMode,
|
|
553510
554004
|
prompt,
|
|
553511
554005
|
resumeFallbackSystemContext,
|
|
553512
554006
|
systemContext
|
|
@@ -555881,6 +556375,7 @@ function bindGatewayClientHandlers(client, ctx, connectionWorkspaceId) {
|
|
|
555881
556375
|
imageList: request.imageList,
|
|
555882
556376
|
jwt: request.jwt,
|
|
555883
556377
|
operationId: request.operationId,
|
|
556378
|
+
permissionMode: request.permissionMode,
|
|
555884
556379
|
prompt: request.prompt,
|
|
555885
556380
|
resumeFallbackSystemContext: request.resumeFallbackSystemContext,
|
|
555886
556381
|
resumeSessionId: request.resumeSessionId,
|
|
@@ -562621,6 +563116,11 @@ const DEFAULT_ASK_USER_TIMEOUT_MS = 600 * 1e3;
|
|
|
562621
563116
|
//#endregion
|
|
562622
563117
|
//#region ../../packages/heterogeneous-agents/src/askUser/AskUserBridge.ts
|
|
562623
563118
|
/**
|
|
563119
|
+
* Wire deadline of a request that never times out: durable review rows need a
|
|
563120
|
+
* finite one, and a year outlives any run.
|
|
563121
|
+
*/
|
|
563122
|
+
const NO_DEADLINE_MS = 365 * 24 * 60 * 60 * 1e3;
|
|
563123
|
+
/**
|
|
562624
563124
|
* Per-operation channel between an MCP tool handler (which awaits the user)
|
|
562625
563125
|
* and the producer's outbound stream (which carries the request to UI and
|
|
562626
563126
|
* receives the user's answer back).
|
|
@@ -562677,9 +563177,10 @@ var AskUserBridge = class {
|
|
|
562677
563177
|
const timeoutMs = options.timeoutMs ?? 6e5;
|
|
562678
563178
|
const progressIntervalMs = options.progressIntervalMs ?? 3e4;
|
|
562679
563179
|
const startedAt = Date.now();
|
|
562680
|
-
const
|
|
563180
|
+
const expires = Number.isFinite(timeoutMs);
|
|
563181
|
+
const deadline = startedAt + (expires ? timeoutMs : NO_DEADLINE_MS);
|
|
562681
563182
|
return new Promise((resolve, reject) => {
|
|
562682
|
-
const
|
|
563183
|
+
const onTimeout = () => {
|
|
562683
563184
|
this.pending_.delete(toolCallId);
|
|
562684
563185
|
clearInterval(progressTimer);
|
|
562685
563186
|
this.emitResponse(toolCallId, {
|
|
@@ -562690,13 +563191,14 @@ var AskUserBridge = class {
|
|
|
562690
563191
|
cancelled: true,
|
|
562691
563192
|
cancelReason: "timeout"
|
|
562692
563193
|
});
|
|
562693
|
-
}
|
|
563194
|
+
};
|
|
563195
|
+
const timeoutTimer = expires ? setTimeout(onTimeout, timeoutMs) : void 0;
|
|
562694
563196
|
const progressTimer = options.onProgress ? setInterval(() => {
|
|
562695
563197
|
const elapsed = Date.now() - startedAt;
|
|
562696
563198
|
Promise.resolve(options.onProgress(elapsed, timeoutMs)).catch(() => {});
|
|
562697
563199
|
}, progressIntervalMs) : void 0;
|
|
562698
563200
|
const cleanup = () => {
|
|
562699
|
-
clearTimeout(timeoutTimer);
|
|
563201
|
+
if (timeoutTimer) clearTimeout(timeoutTimer);
|
|
562700
563202
|
if (progressTimer) clearInterval(progressTimer);
|
|
562701
563203
|
};
|
|
562702
563204
|
this.pending_.set(toolCallId, {
|
|
@@ -582670,6 +583172,26 @@ const dispatchHeteroControl = async (message, context) => {
|
|
|
582670
583172
|
}
|
|
582671
583173
|
};
|
|
582672
583174
|
|
|
583175
|
+
//#endregion
|
|
583176
|
+
//#region src/utils/heteroPermissionMode.ts
|
|
583177
|
+
init_src$2();
|
|
583178
|
+
/** The control command the server queues when the user switches mode mid-run. */
|
|
583179
|
+
const HETERO_SET_PERMISSION_MODE_COMMAND = "set_permission_mode";
|
|
583180
|
+
/**
|
|
583181
|
+
* Switch the running Claude Code session's permission mode (the composer's
|
|
583182
|
+
* mode chip). Reports the mode Claude Code took — `acceptEdits` for
|
|
583183
|
+
* `bypassPermissions` as root; the mode report on the event stream follows.
|
|
583184
|
+
*/
|
|
583185
|
+
const setPermissionModeHandler = async ({ params, sendControlRequest, signal }) => {
|
|
583186
|
+
const mode = params?.mode;
|
|
583187
|
+
if (!isHeteroPermissionMode(mode)) throw new Error("set_permission_mode needs a valid mode");
|
|
583188
|
+
return { mode: await setClaudeCodePermissionMode(sendControlRequest, mode, {
|
|
583189
|
+
isRoot: isRunningAsRoot(),
|
|
583190
|
+
signal
|
|
583191
|
+
}) };
|
|
583192
|
+
};
|
|
583193
|
+
registerHeteroControlHandler(HETERO_SET_PERMISSION_MODE_COMMAND, setPermissionModeHandler);
|
|
583194
|
+
|
|
582673
583195
|
//#endregion
|
|
582674
583196
|
//#region src/utils/heteroStopTask.ts
|
|
582675
583197
|
/** The control command the server queues to stop one background task. */
|
|
@@ -583072,6 +583594,121 @@ const buildExtraArgs = (options) => {
|
|
|
583072
583594
|
return extraArgs.length > 0 ? extraArgs : void 0;
|
|
583073
583595
|
};
|
|
583074
583596
|
|
|
583597
|
+
//#endregion
|
|
583598
|
+
//#region src/commands/hetero/prompt.ts
|
|
583599
|
+
init_src$2();
|
|
583600
|
+
const readStdin = async () => {
|
|
583601
|
+
const chunks = [];
|
|
583602
|
+
for await (const chunk of process.stdin) chunks.push(typeof chunk === "string" ? Buffer.from(chunk) : chunk);
|
|
583603
|
+
return Buffer.concat(chunks).toString("utf8");
|
|
583604
|
+
};
|
|
583605
|
+
/**
|
|
583606
|
+
* Resolve a raw `--input-json` argument: `'-'` (or empty) reads stdin, anything
|
|
583607
|
+
* else is treated as a filesystem path.
|
|
583608
|
+
*/
|
|
583609
|
+
const readInputJson = async (location) => {
|
|
583610
|
+
if (location === "-" || location === "") return readStdin();
|
|
583611
|
+
return readFile(location, "utf8");
|
|
583612
|
+
};
|
|
583613
|
+
const looksLikeJsonInput = (value) => {
|
|
583614
|
+
const trimmed = value.trimStart();
|
|
583615
|
+
return trimmed.startsWith("{") || trimmed.startsWith("[");
|
|
583616
|
+
};
|
|
583617
|
+
/**
|
|
583618
|
+
* Convert an `--image <value>` argument into an image source. Recognized
|
|
583619
|
+
* shapes: `https?://...` URL, `data:` URL, otherwise a filesystem path
|
|
583620
|
+
* resolved relative to the CLI's cwd.
|
|
583621
|
+
*/
|
|
583622
|
+
const parseImageArg = (value) => {
|
|
583623
|
+
if (/^https?:\/\//i.test(value)) return {
|
|
583624
|
+
type: "url",
|
|
583625
|
+
url: value
|
|
583626
|
+
};
|
|
583627
|
+
if (value.startsWith("data:")) {
|
|
583628
|
+
const match = value.match(/^data:([^;,]+);base64,(.+)$/);
|
|
583629
|
+
if (!match) throw new Error(`Invalid data URL for --image: ${value.slice(0, 40)}…`);
|
|
583630
|
+
return {
|
|
583631
|
+
data: match[2],
|
|
583632
|
+
mediaType: match[1],
|
|
583633
|
+
type: "base64"
|
|
583634
|
+
};
|
|
583635
|
+
}
|
|
583636
|
+
return {
|
|
583637
|
+
path: path.resolve(process.cwd(), value),
|
|
583638
|
+
type: "path"
|
|
583639
|
+
};
|
|
583640
|
+
};
|
|
583641
|
+
/**
|
|
583642
|
+
* Best-effort coercion of a JSON-decoded value into an `AgentPromptInput`.
|
|
583643
|
+
* Accepts:
|
|
583644
|
+
* - `'plain text'` → single text block
|
|
583645
|
+
* - `[{ type: 'text', text }, { type: 'image', source }]` → content blocks
|
|
583646
|
+
* - `{ content: [...], resumeFallback?: [...], permissionMode? }` → unwraps the
|
|
583647
|
+
* primary prompt, reserves the fallback for a retry without native resume,
|
|
583648
|
+
* and takes the Claude Code permission mode the run was dispatched with
|
|
583649
|
+
* - `{ type: 'text', ... } | { type: 'image', ... }` → single block
|
|
583650
|
+
*/
|
|
583651
|
+
const coerceJsonPrompt = (parsed) => {
|
|
583652
|
+
if (typeof parsed === "string") return { prompt: parsed };
|
|
583653
|
+
if (Array.isArray(parsed)) return { prompt: parsed };
|
|
583654
|
+
if (parsed && typeof parsed === "object") {
|
|
583655
|
+
const obj = parsed;
|
|
583656
|
+
if (Array.isArray(obj.content)) return {
|
|
583657
|
+
...isHeteroPermissionMode(obj.permissionMode) && { permissionMode: obj.permissionMode },
|
|
583658
|
+
prompt: obj.content,
|
|
583659
|
+
...Array.isArray(obj.resumeFallback) ? { resumeFallbackPrompt: obj.resumeFallback } : {}
|
|
583660
|
+
};
|
|
583661
|
+
if (obj.type === "text" || obj.type === "image") return { prompt: [obj] };
|
|
583662
|
+
}
|
|
583663
|
+
throw new Error("Invalid --input-json shape: expected a string, array of content blocks, or `{ content: [...] }` envelope.");
|
|
583664
|
+
};
|
|
583665
|
+
const buildPromptFromText = (text, images) => {
|
|
583666
|
+
if (images.length === 0) return {
|
|
583667
|
+
describe: () => text.trim(),
|
|
583668
|
+
prompt: text
|
|
583669
|
+
};
|
|
583670
|
+
const blocks = [];
|
|
583671
|
+
if (text.length > 0) blocks.push({
|
|
583672
|
+
text,
|
|
583673
|
+
type: "text"
|
|
583674
|
+
});
|
|
583675
|
+
for (const image of images) blocks.push({
|
|
583676
|
+
source: parseImageArg(image),
|
|
583677
|
+
type: "image"
|
|
583678
|
+
});
|
|
583679
|
+
return {
|
|
583680
|
+
describe: () => blocks.map((b) => b.type === "text" ? b.text.trim() : "[image]").filter(Boolean).join(" ").trim(),
|
|
583681
|
+
prompt: blocks
|
|
583682
|
+
};
|
|
583683
|
+
};
|
|
583684
|
+
/**
|
|
583685
|
+
* Decide which input mode the user requested and produce a unified prompt.
|
|
583686
|
+
*
|
|
583687
|
+
* Mode resolution (mutually exclusive):
|
|
583688
|
+
* 1. `--input-json` → read JSON file or stdin, parse to content blocks
|
|
583689
|
+
* 2. `--prompt` (with optional `--image` flags) → text + images
|
|
583690
|
+
* 3. (default) read stdin: auto-detect JSON vs plain text by first char
|
|
583691
|
+
*/
|
|
583692
|
+
const resolvePrompt = async (options) => {
|
|
583693
|
+
const images = options.image ?? [];
|
|
583694
|
+
if (options.inputJson !== void 0) {
|
|
583695
|
+
if (options.prompt !== void 0) throw new Error("--prompt and --input-json are mutually exclusive.");
|
|
583696
|
+
if (images.length > 0) throw new Error("--image cannot be combined with --input-json (put images in the JSON).");
|
|
583697
|
+
const raw = await readInputJson(options.inputJson);
|
|
583698
|
+
return {
|
|
583699
|
+
describe: () => raw.trim(),
|
|
583700
|
+
...coerceJsonPrompt(JSON.parse(raw))
|
|
583701
|
+
};
|
|
583702
|
+
}
|
|
583703
|
+
if (options.prompt !== void 0 && options.prompt !== "-") return buildPromptFromText(options.prompt, images);
|
|
583704
|
+
const raw = await readStdin();
|
|
583705
|
+
if (looksLikeJsonInput(raw)) return {
|
|
583706
|
+
describe: () => raw.trim(),
|
|
583707
|
+
...coerceJsonPrompt(JSON.parse(raw))
|
|
583708
|
+
};
|
|
583709
|
+
return buildPromptFromText(raw, images);
|
|
583710
|
+
};
|
|
583711
|
+
|
|
583075
583712
|
//#endregion
|
|
583076
583713
|
//#region src/commands/hetero/index.ts
|
|
583077
583714
|
init_resolveCliCommand();
|
|
@@ -583183,122 +583820,13 @@ const RESUME_RETRY_PATTERNS = [
|
|
|
583183
583820
|
];
|
|
583184
583821
|
const looksLikeNeedsRetryWithoutResume = (text) => RESUME_RETRY_PATTERNS.some((p) => p.test(text));
|
|
583185
583822
|
const isMissingGrokResumeSession = (data) => {
|
|
583186
|
-
if (data?.agentType !== "grok-build" || !isRecord$
|
|
583823
|
+
if (data?.agentType !== "grok-build" || !isRecord$8(data.details)) return false;
|
|
583187
583824
|
const { details } = data;
|
|
583188
583825
|
const rpcData = details.data;
|
|
583189
|
-
return details.method === "session/load" && isRecord$
|
|
583826
|
+
return details.method === "session/load" && isRecord$8(rpcData) && rpcData.code === "FS_NOT_FOUND";
|
|
583190
583827
|
};
|
|
583191
583828
|
const collectImage = (value, previous = []) => [...previous, value];
|
|
583192
583829
|
const collectAgentArg = (value, previous = []) => [...previous, value];
|
|
583193
|
-
const readStdin = async () => {
|
|
583194
|
-
const chunks = [];
|
|
583195
|
-
for await (const chunk of process.stdin) chunks.push(typeof chunk === "string" ? Buffer.from(chunk) : chunk);
|
|
583196
|
-
return Buffer.concat(chunks).toString("utf8");
|
|
583197
|
-
};
|
|
583198
|
-
/**
|
|
583199
|
-
* Resolve a raw `--input-json` argument: `'-'` (or empty) reads stdin, anything
|
|
583200
|
-
* else is treated as a filesystem path.
|
|
583201
|
-
*/
|
|
583202
|
-
const readInputJson = async (location) => {
|
|
583203
|
-
if (location === "-" || location === "") return readStdin();
|
|
583204
|
-
return readFile(location, "utf8");
|
|
583205
|
-
};
|
|
583206
|
-
const looksLikeJsonInput = (value) => {
|
|
583207
|
-
const trimmed = value.trimStart();
|
|
583208
|
-
return trimmed.startsWith("{") || trimmed.startsWith("[");
|
|
583209
|
-
};
|
|
583210
|
-
/**
|
|
583211
|
-
* Convert an `--image <value>` argument into an image source. Recognized
|
|
583212
|
-
* shapes: `https?://...` URL, `data:` URL, otherwise a filesystem path
|
|
583213
|
-
* resolved relative to the CLI's cwd.
|
|
583214
|
-
*/
|
|
583215
|
-
const parseImageArg = (value) => {
|
|
583216
|
-
if (/^https?:\/\//i.test(value)) return {
|
|
583217
|
-
type: "url",
|
|
583218
|
-
url: value
|
|
583219
|
-
};
|
|
583220
|
-
if (value.startsWith("data:")) {
|
|
583221
|
-
const match = value.match(/^data:([^;,]+);base64,(.+)$/);
|
|
583222
|
-
if (!match) throw new Error(`Invalid data URL for --image: ${value.slice(0, 40)}…`);
|
|
583223
|
-
return {
|
|
583224
|
-
data: match[2],
|
|
583225
|
-
mediaType: match[1],
|
|
583226
|
-
type: "base64"
|
|
583227
|
-
};
|
|
583228
|
-
}
|
|
583229
|
-
return {
|
|
583230
|
-
path: path.resolve(process.cwd(), value),
|
|
583231
|
-
type: "path"
|
|
583232
|
-
};
|
|
583233
|
-
};
|
|
583234
|
-
/**
|
|
583235
|
-
* Best-effort coercion of a JSON-decoded value into an `AgentPromptInput`.
|
|
583236
|
-
* Accepts:
|
|
583237
|
-
* - `'plain text'` → single text block
|
|
583238
|
-
* - `[{ type: 'text', text }, { type: 'image', source }]` → content blocks
|
|
583239
|
-
* - `{ content: [...], resumeFallback?: [...] }` → unwraps the primary prompt
|
|
583240
|
-
* and reserves the fallback for a retry without native resume
|
|
583241
|
-
* - `{ type: 'text', ... } | { type: 'image', ... }` → single block
|
|
583242
|
-
*/
|
|
583243
|
-
const coerceJsonPrompt = (parsed) => {
|
|
583244
|
-
if (typeof parsed === "string") return { prompt: parsed };
|
|
583245
|
-
if (Array.isArray(parsed)) return { prompt: parsed };
|
|
583246
|
-
if (parsed && typeof parsed === "object") {
|
|
583247
|
-
const obj = parsed;
|
|
583248
|
-
if (Array.isArray(obj.content)) return {
|
|
583249
|
-
prompt: obj.content,
|
|
583250
|
-
...Array.isArray(obj.resumeFallback) ? { resumeFallbackPrompt: obj.resumeFallback } : {}
|
|
583251
|
-
};
|
|
583252
|
-
if (obj.type === "text" || obj.type === "image") return { prompt: [obj] };
|
|
583253
|
-
}
|
|
583254
|
-
throw new Error("Invalid --input-json shape: expected a string, array of content blocks, or `{ content: [...] }` envelope.");
|
|
583255
|
-
};
|
|
583256
|
-
const buildPromptFromText = (text, images) => {
|
|
583257
|
-
if (images.length === 0) return {
|
|
583258
|
-
describe: () => text.trim(),
|
|
583259
|
-
prompt: text
|
|
583260
|
-
};
|
|
583261
|
-
const blocks = [];
|
|
583262
|
-
if (text.length > 0) blocks.push({
|
|
583263
|
-
text,
|
|
583264
|
-
type: "text"
|
|
583265
|
-
});
|
|
583266
|
-
for (const image of images) blocks.push({
|
|
583267
|
-
source: parseImageArg(image),
|
|
583268
|
-
type: "image"
|
|
583269
|
-
});
|
|
583270
|
-
return {
|
|
583271
|
-
describe: () => blocks.map((b) => b.type === "text" ? b.text.trim() : "[image]").filter(Boolean).join(" ").trim(),
|
|
583272
|
-
prompt: blocks
|
|
583273
|
-
};
|
|
583274
|
-
};
|
|
583275
|
-
/**
|
|
583276
|
-
* Decide which input mode the user requested and produce a unified prompt.
|
|
583277
|
-
*
|
|
583278
|
-
* Mode resolution (mutually exclusive):
|
|
583279
|
-
* 1. `--input-json` → read JSON file or stdin, parse to content blocks
|
|
583280
|
-
* 2. `--prompt` (with optional `--image` flags) → text + images
|
|
583281
|
-
* 3. (default) read stdin: auto-detect JSON vs plain text by first char
|
|
583282
|
-
*/
|
|
583283
|
-
const resolvePrompt = async (options) => {
|
|
583284
|
-
const images = options.image ?? [];
|
|
583285
|
-
if (options.inputJson !== void 0) {
|
|
583286
|
-
if (options.prompt !== void 0) throw new Error("--prompt and --input-json are mutually exclusive.");
|
|
583287
|
-
if (images.length > 0) throw new Error("--image cannot be combined with --input-json (put images in the JSON).");
|
|
583288
|
-
const raw = await readInputJson(options.inputJson);
|
|
583289
|
-
return {
|
|
583290
|
-
describe: () => raw.trim(),
|
|
583291
|
-
...coerceJsonPrompt(JSON.parse(raw))
|
|
583292
|
-
};
|
|
583293
|
-
}
|
|
583294
|
-
if (options.prompt !== void 0 && options.prompt !== "-") return buildPromptFromText(options.prompt, images);
|
|
583295
|
-
const raw = await readStdin();
|
|
583296
|
-
if (looksLikeJsonInput(raw)) return {
|
|
583297
|
-
describe: () => raw.trim(),
|
|
583298
|
-
...coerceJsonPrompt(JSON.parse(raw))
|
|
583299
|
-
};
|
|
583300
|
-
return buildPromptFromText(raw, images);
|
|
583301
|
-
};
|
|
583302
583830
|
/**
|
|
583303
583831
|
* Persists the agent process's RAW stdout/stderr — the untouched stream-json,
|
|
583304
583832
|
* BEFORE the adapter — to disk for post-hoc debugging. The adapted/ingested
|
|
@@ -583835,6 +584363,7 @@ const exec = async (options) => {
|
|
|
583835
584363
|
initialModel: usesHeterogeneousSessionInitialModel(options.type) ? options.model : void 0,
|
|
583836
584364
|
liveInput: options.type === "claude-code",
|
|
583837
584365
|
operationId,
|
|
584366
|
+
...options.type === "claude-code" && resolved.permissionMode && { permissionMode: resolved.permissionMode },
|
|
583838
584367
|
uploadImage
|
|
583839
584368
|
};
|
|
583840
584369
|
const first = await runOneAgent({
|