claude-use 11.90.0 → 12.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/cli.cjs +1058 -620
- package/dist/index.cjs +1091 -780
- package/dist/index.mjs +1060 -748
- package/dist/types/index.d.ts +152 -42
- package/package.json +1 -1
package/dist/cli.cjs
CHANGED
|
@@ -31153,19 +31153,19 @@ function createFileCapture(file2, now = () => /* @__PURE__ */ new Date()) {
|
|
|
31153
31153
|
if (budget <= 0) {
|
|
31154
31154
|
return;
|
|
31155
31155
|
}
|
|
31156
|
-
const
|
|
31157
|
-
stored2[direction] +=
|
|
31158
|
-
const text5 =
|
|
31159
|
-
const faithful = Buffer.from(text5, "utf8").equals(
|
|
31156
|
+
const excerpt = chunk2.subarray(0, Math.min(CHUNK_LOG_CAP_BYTES, budget));
|
|
31157
|
+
stored2[direction] += excerpt.length;
|
|
31158
|
+
const text5 = excerpt.toString("utf8");
|
|
31159
|
+
const faithful = Buffer.from(text5, "utf8").equals(excerpt);
|
|
31160
31160
|
append({
|
|
31161
31161
|
kind: "stream-chunk",
|
|
31162
31162
|
id: id2,
|
|
31163
31163
|
dir: direction,
|
|
31164
31164
|
seq: sequences[direction],
|
|
31165
31165
|
bytes: chunk2.length,
|
|
31166
|
-
stored:
|
|
31167
|
-
truncated:
|
|
31168
|
-
...faithful ? { body: redactText(text5) } : { b64:
|
|
31166
|
+
stored: excerpt.length,
|
|
31167
|
+
truncated: excerpt.length < chunk2.length,
|
|
31168
|
+
...faithful ? { body: redactText(text5) } : { b64: excerpt.toString("base64") }
|
|
31169
31169
|
});
|
|
31170
31170
|
},
|
|
31171
31171
|
onEnd: () => {
|
|
@@ -31185,16 +31185,16 @@ function createFileCapture(file2, now = () => /* @__PURE__ */ new Date()) {
|
|
|
31185
31185
|
if (budget <= 0) {
|
|
31186
31186
|
return;
|
|
31187
31187
|
}
|
|
31188
|
-
const
|
|
31189
|
-
logged[direction] +=
|
|
31188
|
+
const excerpt = incoming.subarray(0, Math.min(CHUNK_LOG_CAP_BYTES, budget));
|
|
31189
|
+
logged[direction] += excerpt.length;
|
|
31190
31190
|
append({
|
|
31191
31191
|
kind: `${direction}-chunk`,
|
|
31192
31192
|
id: id2,
|
|
31193
31193
|
seq: sequences[direction],
|
|
31194
31194
|
bytes: incoming.length,
|
|
31195
|
-
stored:
|
|
31196
|
-
truncated:
|
|
31197
|
-
body: redactBody(
|
|
31195
|
+
stored: excerpt.length,
|
|
31196
|
+
truncated: excerpt.length < incoming.length,
|
|
31197
|
+
body: redactBody(excerpt)
|
|
31198
31198
|
});
|
|
31199
31199
|
};
|
|
31200
31200
|
return {
|
|
@@ -32078,6 +32078,9 @@ async function realRunningAmong(pids, psTimeoutMs = PS_TIMEOUT_MS) {
|
|
|
32078
32078
|
const states = await readProcessStates(existing, psTimeoutMs);
|
|
32079
32079
|
return new Set(existing.filter((pid) => states.get(pid)?.startsWith("Z") !== true));
|
|
32080
32080
|
}
|
|
32081
|
+
function definedEntries(env) {
|
|
32082
|
+
return Object.fromEntries(Object.entries(env).filter((entry) => entry[1] !== void 0));
|
|
32083
|
+
}
|
|
32081
32084
|
function realRunAsyncWithin(timeoutMs) {
|
|
32082
32085
|
return async (command, args) => await new Promise((resolve3) => {
|
|
32083
32086
|
(0, import_node_child_process3.execFile)(command, [...args], { encoding: "utf8", timeout: timeoutMs }, (error63, stdout2, stderr) => {
|
|
@@ -32543,8 +32546,14 @@ var init_realPorts = __esm({
|
|
|
32543
32546
|
BYTES_PER_MIB2 = 1048576;
|
|
32544
32547
|
RUN_OUTPUT_LIMIT_BYTES = RUN_OUTPUT_LIMIT_MIB * BYTES_PER_MIB2;
|
|
32545
32548
|
realRunPort = {
|
|
32546
|
-
run(command, args, input2) {
|
|
32547
|
-
const result = spawnSyncBlocking("an external command", command, args, {
|
|
32549
|
+
run(command, args, input2, options) {
|
|
32550
|
+
const result = spawnSyncBlocking("an external command", command, args, {
|
|
32551
|
+
encoding: "utf8",
|
|
32552
|
+
maxBuffer: RUN_OUTPUT_LIMIT_BYTES,
|
|
32553
|
+
...input2 === void 0 ? {} : { input: input2 },
|
|
32554
|
+
...options?.env === void 0 ? {} : { env: definedEntries(options.env) },
|
|
32555
|
+
...options?.timeoutMs === void 0 ? {} : { timeout: options.timeoutMs }
|
|
32556
|
+
});
|
|
32548
32557
|
return { status: result.status, stdout: result.stdout, stderr: result.stderr };
|
|
32549
32558
|
}
|
|
32550
32559
|
};
|
|
@@ -35040,9 +35049,224 @@ var init_identityToken = __esm({
|
|
|
35040
35049
|
}
|
|
35041
35050
|
});
|
|
35042
35051
|
|
|
35052
|
+
// src/headroom/headers.ts
|
|
35053
|
+
function mergeAnthropicCustomHeaders(existing, additions) {
|
|
35054
|
+
const merged = /* @__PURE__ */ new Map();
|
|
35055
|
+
for (const block2 of existing) {
|
|
35056
|
+
if (block2 === void 0) {
|
|
35057
|
+
continue;
|
|
35058
|
+
}
|
|
35059
|
+
for (const line of block2.split("\n")) {
|
|
35060
|
+
const entry = parseCustomHeaderLine(line);
|
|
35061
|
+
if (entry === void 0) {
|
|
35062
|
+
continue;
|
|
35063
|
+
}
|
|
35064
|
+
merged.set(entry.name, entry.value);
|
|
35065
|
+
}
|
|
35066
|
+
}
|
|
35067
|
+
for (const entry of additions) {
|
|
35068
|
+
merged.set(entry.name, entry.value);
|
|
35069
|
+
}
|
|
35070
|
+
return [...merged].map(([name, value3]) => `${name}: ${value3}`).join("\n");
|
|
35071
|
+
}
|
|
35072
|
+
function parseAnthropicCustomHeaders(block2) {
|
|
35073
|
+
return block2.split("\n").flatMap((line) => {
|
|
35074
|
+
const entry = parseCustomHeaderLine(line);
|
|
35075
|
+
return entry === void 0 ? [] : [entry];
|
|
35076
|
+
});
|
|
35077
|
+
}
|
|
35078
|
+
function withoutAnthropicCustomHeaders(block2, remove) {
|
|
35079
|
+
const lines = block2.split("\n");
|
|
35080
|
+
const kept = lines.filter((line) => {
|
|
35081
|
+
const entry = parseCustomHeaderLine(line);
|
|
35082
|
+
return entry === void 0 || !remove(entry);
|
|
35083
|
+
});
|
|
35084
|
+
return kept.length === lines.length ? block2 : kept.join("\n");
|
|
35085
|
+
}
|
|
35086
|
+
function parseCustomHeaderLine(line) {
|
|
35087
|
+
const trimmed = line.trim();
|
|
35088
|
+
if (trimmed === "") {
|
|
35089
|
+
return void 0;
|
|
35090
|
+
}
|
|
35091
|
+
const colon = trimmed.indexOf(":");
|
|
35092
|
+
if (colon <= 0) {
|
|
35093
|
+
return void 0;
|
|
35094
|
+
}
|
|
35095
|
+
return { name: trimmed.slice(0, colon).trim(), value: trimmed.slice(colon + 1).trim() };
|
|
35096
|
+
}
|
|
35097
|
+
var init_headers = __esm({
|
|
35098
|
+
"src/headroom/headers.ts"() {
|
|
35099
|
+
"use strict";
|
|
35100
|
+
}
|
|
35101
|
+
});
|
|
35102
|
+
|
|
35103
|
+
// src/launcher/injected.ts
|
|
35104
|
+
function listKey(list2) {
|
|
35105
|
+
return `${list2},appended`;
|
|
35106
|
+
}
|
|
35107
|
+
function digest(value3) {
|
|
35108
|
+
return (0, import_node_crypto5.createHash)("sha256").update(value3).digest("hex");
|
|
35109
|
+
}
|
|
35110
|
+
function recordedDigests(env) {
|
|
35111
|
+
const raw = env[INJECTED_ENV];
|
|
35112
|
+
if (raw === void 0 || raw === "") {
|
|
35113
|
+
return {};
|
|
35114
|
+
}
|
|
35115
|
+
let parsed;
|
|
35116
|
+
try {
|
|
35117
|
+
parsed = JSON.parse(raw);
|
|
35118
|
+
} catch {
|
|
35119
|
+
return {};
|
|
35120
|
+
}
|
|
35121
|
+
const result = InjectedSchema.safeParse(parsed);
|
|
35122
|
+
return result.success ? result.data : {};
|
|
35123
|
+
}
|
|
35124
|
+
function recordInjections(base) {
|
|
35125
|
+
const env = { ...base };
|
|
35126
|
+
const digests = new Map(Object.entries(recordedDigests(env)));
|
|
35127
|
+
return {
|
|
35128
|
+
env,
|
|
35129
|
+
set: (name, value3) => {
|
|
35130
|
+
env[name] = value3;
|
|
35131
|
+
digests.set(name, digest(value3));
|
|
35132
|
+
},
|
|
35133
|
+
unset: (name) => {
|
|
35134
|
+
env[name] = void 0;
|
|
35135
|
+
digests.delete(name);
|
|
35136
|
+
},
|
|
35137
|
+
recordHeaders: (names) => {
|
|
35138
|
+
const block2 = env[CUSTOM_HEADERS_ENV];
|
|
35139
|
+
for (const entry of block2 === void 0 ? [] : parseAnthropicCustomHeaders(block2)) {
|
|
35140
|
+
if (names.includes(entry.name)) {
|
|
35141
|
+
digests.set(`${HEADER_KEY_PREFIX}${entry.name.toLowerCase()}`, digest(entry.value));
|
|
35142
|
+
}
|
|
35143
|
+
}
|
|
35144
|
+
},
|
|
35145
|
+
recordBypassHosts: (list2, hosts) => {
|
|
35146
|
+
const recordedHosts = [.../* @__PURE__ */ new Set([...digests.get(listKey(list2))?.split(",") ?? [], ...hosts.map((host) => host.trim().toLowerCase()).filter((host) => host !== "")])];
|
|
35147
|
+
if (recordedHosts.length > 0) {
|
|
35148
|
+
digests.set(listKey(list2), recordedHosts.join(","));
|
|
35149
|
+
}
|
|
35150
|
+
},
|
|
35151
|
+
finish: () => {
|
|
35152
|
+
if (digests.size > 0) {
|
|
35153
|
+
env[INJECTED_ENV] = JSON.stringify(Object.fromEntries(digests));
|
|
35154
|
+
}
|
|
35155
|
+
}
|
|
35156
|
+
};
|
|
35157
|
+
}
|
|
35158
|
+
function withoutRecordedHosts(list2, value3, digests) {
|
|
35159
|
+
const recordedHosts = new Set(digests[listKey(list2)]?.split(","));
|
|
35160
|
+
const entries = value3.split(",");
|
|
35161
|
+
const kept = entries.filter((entry) => !recordedHosts.has(entry.trim().toLowerCase()));
|
|
35162
|
+
return kept.length === entries.length ? value3 : kept.join(",");
|
|
35163
|
+
}
|
|
35164
|
+
function launchEnvironment(env, configDirEscapeHatch) {
|
|
35165
|
+
return configDirEscapeHatch ? env : withoutInjected(env);
|
|
35166
|
+
}
|
|
35167
|
+
function withoutInjected(env) {
|
|
35168
|
+
const digests = recordedDigests(env);
|
|
35169
|
+
const entries = Object.entries(env).flatMap(([name, value3]) => {
|
|
35170
|
+
if (name === INJECTED_ENV) {
|
|
35171
|
+
return [];
|
|
35172
|
+
}
|
|
35173
|
+
if (value3 === void 0) {
|
|
35174
|
+
return [[name, value3]];
|
|
35175
|
+
}
|
|
35176
|
+
if (name === CUSTOM_HEADERS_ENV) {
|
|
35177
|
+
const remaining = withoutAnthropicCustomHeaders(value3, (entry) => digests[`${HEADER_KEY_PREFIX}${entry.name.toLowerCase()}`] === digest(entry.value));
|
|
35178
|
+
return remaining !== value3 && remaining.trim() === "" ? [] : [[name, remaining]];
|
|
35179
|
+
}
|
|
35180
|
+
if (name === "NO_PROXY" || name === "no_proxy") {
|
|
35181
|
+
const remaining = withoutRecordedHosts(name, value3, digests);
|
|
35182
|
+
return remaining !== value3 && remaining.split(",").every((entry) => entry.trim() === "") ? [] : [[name, remaining]];
|
|
35183
|
+
}
|
|
35184
|
+
return digests[name] === digest(value3) ? [] : [[name, value3]];
|
|
35185
|
+
});
|
|
35186
|
+
return Object.fromEntries(entries);
|
|
35187
|
+
}
|
|
35188
|
+
var import_node_crypto5, INJECTED_ENV, CUSTOM_HEADERS_ENV, HEADER_KEY_PREFIX, InjectedSchema;
|
|
35189
|
+
var init_injected = __esm({
|
|
35190
|
+
"src/launcher/injected.ts"() {
|
|
35191
|
+
"use strict";
|
|
35192
|
+
import_node_crypto5 = require("node:crypto");
|
|
35193
|
+
init_zod();
|
|
35194
|
+
init_headers();
|
|
35195
|
+
INJECTED_ENV = "AGENT_SHIM_INJECTED";
|
|
35196
|
+
CUSTOM_HEADERS_ENV = "ANTHROPIC_CUSTOM_HEADERS";
|
|
35197
|
+
HEADER_KEY_PREFIX = `${CUSTOM_HEADERS_ENV}:`;
|
|
35198
|
+
InjectedSchema = external_exports.record(external_exports.string(), external_exports.string());
|
|
35199
|
+
}
|
|
35200
|
+
});
|
|
35201
|
+
|
|
35202
|
+
// src/launcher/guard.ts
|
|
35203
|
+
function detectAmbientCredential(env, injected) {
|
|
35204
|
+
for (const variable of AMBIENT_CREDENTIAL_VARS) {
|
|
35205
|
+
const value3 = env[variable];
|
|
35206
|
+
if (value3 === void 0 || value3 === "") {
|
|
35207
|
+
continue;
|
|
35208
|
+
}
|
|
35209
|
+
if (injected?.variable === variable && value3 === injected.token) {
|
|
35210
|
+
continue;
|
|
35211
|
+
}
|
|
35212
|
+
return { variable };
|
|
35213
|
+
}
|
|
35214
|
+
return void 0;
|
|
35215
|
+
}
|
|
35216
|
+
function formatAmbientCredentialGuardMessage(variable, identityName) {
|
|
35217
|
+
const identitySetCommand = identityName === void 0 ? "agent-shim identity set <name> --allow-ambient-credential" : `agent-shim identity set ${identityName} --allow-ambient-credential`;
|
|
35218
|
+
return [
|
|
35219
|
+
`error: ${variable} is set in the environment. This identity's isolated`,
|
|
35220
|
+
"credential would be bypassed \u2014 every identity authenticates as this same key",
|
|
35221
|
+
"while it's set. Unset it, or if this is deliberate, opt in per-launch with",
|
|
35222
|
+
"AGENT_SHIM_ALLOW_AMBIENT_CREDENTIAL=1, or persistently for this identity with",
|
|
35223
|
+
`\`${identitySetCommand}\`.`
|
|
35224
|
+
].join("\n");
|
|
35225
|
+
}
|
|
35226
|
+
function evaluateAmbientCredentialGuard(params) {
|
|
35227
|
+
const detected = detectAmbientCredential(params.env, params.injectedCredential);
|
|
35228
|
+
if (detected === void 0) {
|
|
35229
|
+
return { ok: true };
|
|
35230
|
+
}
|
|
35231
|
+
if (params.allowAmbientCredentialOverride || params.allowAmbientCredential || params.providerSelected === true) {
|
|
35232
|
+
return { ok: true };
|
|
35233
|
+
}
|
|
35234
|
+
return {
|
|
35235
|
+
ok: false,
|
|
35236
|
+
variable: detected.variable,
|
|
35237
|
+
message: formatAmbientCredentialGuardMessage(detected.variable, params.identityName)
|
|
35238
|
+
};
|
|
35239
|
+
}
|
|
35240
|
+
function ambientCredentialFinding(env) {
|
|
35241
|
+
const named = detectAmbientCredential(launchEnvironment(env, false));
|
|
35242
|
+
if (named !== void 0) {
|
|
35243
|
+
return { severity: "warn", message: formatAmbientCredentialGuardMessage(named.variable) };
|
|
35244
|
+
}
|
|
35245
|
+
const bare = env.CLAUDE_CONFIG_DIR === void 0 || env.CLAUDE_CONFIG_DIR === "" ? void 0 : detectAmbientCredential(env);
|
|
35246
|
+
if (bare !== void 0) {
|
|
35247
|
+
return { severity: "warn", message: `${bare.variable} was set in this session by the launcher that started it. A launch that names an identity drops it, but a launch naming none keeps the session's CLAUDE_CONFIG_DIR and environment and is refused. Name an identity, as in \`claude @<name>\`.` };
|
|
35248
|
+
}
|
|
35249
|
+
return { severity: "pass", message: "No ambient-credential environment variable is set." };
|
|
35250
|
+
}
|
|
35251
|
+
var AMBIENT_CREDENTIAL_VARS;
|
|
35252
|
+
var init_guard = __esm({
|
|
35253
|
+
"src/launcher/guard.ts"() {
|
|
35254
|
+
"use strict";
|
|
35255
|
+
init_injected();
|
|
35256
|
+
AMBIENT_CREDENTIAL_VARS = [
|
|
35257
|
+
"ANTHROPIC_API_KEY",
|
|
35258
|
+
"ANTHROPIC_AUTH_TOKEN",
|
|
35259
|
+
"CLAUDE_CODE_OAUTH_TOKEN",
|
|
35260
|
+
"CLAUDE_CODE_USE_BEDROCK",
|
|
35261
|
+
"CLAUDE_CODE_USE_VERTEX",
|
|
35262
|
+
"CLAUDE_CODE_USE_FOUNDRY"
|
|
35263
|
+
];
|
|
35264
|
+
}
|
|
35265
|
+
});
|
|
35266
|
+
|
|
35043
35267
|
// src/usage/signIn.ts
|
|
35044
35268
|
function claudeCodeKeychainService(configDir) {
|
|
35045
|
-
return `${KEYCHAIN_SERVICE_PREFIX}-${(0,
|
|
35269
|
+
return `${KEYCHAIN_SERVICE_PREFIX}-${(0, import_node_crypto6.createHash)("sha256").update(configDir).digest("hex").slice(0, KEYCHAIN_SERVICE_HASH_DIGITS)}`;
|
|
35046
35270
|
}
|
|
35047
35271
|
function keychainHasItem(run, configDir) {
|
|
35048
35272
|
return run.run("security", ["find-generic-password", "-s", claudeCodeKeychainService(configDir)]).status === 0;
|
|
@@ -35075,15 +35299,35 @@ function identitySignIn(fs37, probe, identity) {
|
|
|
35075
35299
|
platform: probe.platform
|
|
35076
35300
|
});
|
|
35077
35301
|
}
|
|
35078
|
-
|
|
35302
|
+
function storedLoginUsable(run, claudeBin, configDir, env) {
|
|
35303
|
+
const childEnv = { ...env, CLAUDE_CONFIG_DIR: configDir };
|
|
35304
|
+
for (const variable of AMBIENT_CREDENTIAL_VARS) {
|
|
35305
|
+
childEnv[variable] = void 0;
|
|
35306
|
+
}
|
|
35307
|
+
const result = run.run(claudeBin, ["auth", "status"], void 0, { env: childEnv, timeoutMs: AUTH_STATUS_TIMEOUT_MS });
|
|
35308
|
+
if (result.status === null) {
|
|
35309
|
+
return void 0;
|
|
35310
|
+
}
|
|
35311
|
+
try {
|
|
35312
|
+
const status = JSON.parse(result.stdout);
|
|
35313
|
+
if (typeof status === "object" && status !== null && "loggedIn" in status && typeof status.loggedIn === "boolean") {
|
|
35314
|
+
return status.loggedIn;
|
|
35315
|
+
}
|
|
35316
|
+
} catch {
|
|
35317
|
+
}
|
|
35318
|
+
return void 0;
|
|
35319
|
+
}
|
|
35320
|
+
var import_node_crypto6, import_node_path19, CREDENTIALS_FILE, KEYCHAIN_SERVICE_PREFIX, KEYCHAIN_SERVICE_HASH_DIGITS, AUTH_STATUS_TIMEOUT_MS;
|
|
35079
35321
|
var init_signIn = __esm({
|
|
35080
35322
|
"src/usage/signIn.ts"() {
|
|
35081
35323
|
"use strict";
|
|
35082
|
-
|
|
35324
|
+
import_node_crypto6 = require("node:crypto");
|
|
35083
35325
|
import_node_path19 = __toESM(require("node:path"), 1);
|
|
35326
|
+
init_guard();
|
|
35084
35327
|
CREDENTIALS_FILE = ".credentials.json";
|
|
35085
35328
|
KEYCHAIN_SERVICE_PREFIX = "Claude Code-credentials";
|
|
35086
35329
|
KEYCHAIN_SERVICE_HASH_DIGITS = 8;
|
|
35330
|
+
AUTH_STATUS_TIMEOUT_MS = 1e4;
|
|
35087
35331
|
}
|
|
35088
35332
|
});
|
|
35089
35333
|
|
|
@@ -35302,7 +35546,7 @@ function serialisedFor(entry, owner) {
|
|
|
35302
35546
|
return JSON.stringify({ owner, ...withoutOwner(entry) });
|
|
35303
35547
|
}
|
|
35304
35548
|
function tempPathFor(target) {
|
|
35305
|
-
return import_node_path20.default.join(import_node_path20.default.dirname(target), `${TEMP_PREFIX}${String(process.pid)}-${(0,
|
|
35549
|
+
return import_node_path20.default.join(import_node_path20.default.dirname(target), `${TEMP_PREFIX}${String(process.pid)}-${(0, import_node_crypto7.randomUUID)()}`);
|
|
35306
35550
|
}
|
|
35307
35551
|
function processRuns(pid) {
|
|
35308
35552
|
try {
|
|
@@ -35505,12 +35749,12 @@ function createAsyncRealCredentialCache(root) {
|
|
|
35505
35749
|
function realAsyncCredentialCacheEnv(paths) {
|
|
35506
35750
|
return { port: createAsyncRealCredentialCache(paths.root), platform: process.platform, now: () => Date.now() };
|
|
35507
35751
|
}
|
|
35508
|
-
var import_node_child_process4,
|
|
35752
|
+
var import_node_child_process4, import_node_crypto7, import_node_fs9, import_node_path20, CACHE_DIR_MODE, CACHE_FILE_MODE, TEMP_PREFIX, TEMP_NAME, RELEASED_TEMP_NAME;
|
|
35509
35753
|
var init_realCredentialCache = __esm({
|
|
35510
35754
|
"src/realCredentialCache.ts"() {
|
|
35511
35755
|
"use strict";
|
|
35512
35756
|
import_node_child_process4 = require("node:child_process");
|
|
35513
|
-
|
|
35757
|
+
import_node_crypto7 = require("node:crypto");
|
|
35514
35758
|
import_node_fs9 = __toESM(require("node:fs"), 1);
|
|
35515
35759
|
import_node_path20 = __toESM(require("node:path"), 1);
|
|
35516
35760
|
init_blockingSpawn();
|
|
@@ -35557,7 +35801,7 @@ function acquireIdentityLock(params) {
|
|
|
35557
35801
|
const staleAfterMs = params.staleAfterMs ?? DEFAULT_STALE_AFTER_MS;
|
|
35558
35802
|
const retryDelayMs = params.retryDelayMs ?? DEFAULT_RETRY_DELAY_MS;
|
|
35559
35803
|
const maxAttempts = params.maxAttempts ?? DEFAULT_MAX_ATTEMPTS;
|
|
35560
|
-
const token = (0,
|
|
35804
|
+
const token = (0, import_node_crypto8.randomUUID)();
|
|
35561
35805
|
if (params.fs.lstat(params.dir) === void 0) {
|
|
35562
35806
|
params.fs.mkdirp(params.dir);
|
|
35563
35807
|
}
|
|
@@ -35613,11 +35857,11 @@ function acquireIdentityLock(params) {
|
|
|
35613
35857
|
}
|
|
35614
35858
|
throw new IdentityLockBusyError(params.identity, lockPath, lastHolderPid);
|
|
35615
35859
|
}
|
|
35616
|
-
var
|
|
35860
|
+
var import_node_crypto8, import_node_path21, DEFAULT_STALE_AFTER_MS, DEFAULT_RETRY_DELAY_MS, DEFAULT_MAX_ATTEMPTS, IdentityLockLostError, IdentityLockBusyError;
|
|
35617
35861
|
var init_lock = __esm({
|
|
35618
35862
|
"src/launcher/lock.ts"() {
|
|
35619
35863
|
"use strict";
|
|
35620
|
-
|
|
35864
|
+
import_node_crypto8 = require("node:crypto");
|
|
35621
35865
|
import_node_path21 = __toESM(require("node:path"), 1);
|
|
35622
35866
|
init_cliError();
|
|
35623
35867
|
DEFAULT_STALE_AFTER_MS = 12e4;
|
|
@@ -37346,7 +37590,7 @@ function renameJournalFile(directory, from, to2) {
|
|
|
37346
37590
|
return import_node_path24.default.join(directory, renamePairFileName(from, to2, JOURNAL_SUFFIX));
|
|
37347
37591
|
}
|
|
37348
37592
|
function renamePairFileName(from, to2, suffix) {
|
|
37349
|
-
return `${(0,
|
|
37593
|
+
return `${(0, import_node_crypto9.createHash)("sha256").update(`${from}\0${to2}`).digest("hex").slice(0, FILE_NAME_HASH_DIGITS)}${suffix}`;
|
|
37350
37594
|
}
|
|
37351
37595
|
function readRenameJournal(fs37, file2) {
|
|
37352
37596
|
const raw = fs37.readFileUtf8(file2);
|
|
@@ -37442,11 +37686,11 @@ function requireNameFreeOfUnfinishedRename(fs37, directory, name, action, sameNa
|
|
|
37442
37686
|
throw new NameHeldByUnfinishedRenameError(action, name, held, finishabilityOf(held, exists));
|
|
37443
37687
|
}
|
|
37444
37688
|
}
|
|
37445
|
-
var
|
|
37689
|
+
var import_node_crypto9, import_node_path24, RenameJournalSchema, FILE_NAME_HASH_DIGITS, JOURNAL_SUFFIX, RenameJournalUnreadableError, NameHeldByUnfinishedRenameError;
|
|
37446
37690
|
var init_identityRenameJournal = __esm({
|
|
37447
37691
|
"src/identityRenameJournal.ts"() {
|
|
37448
37692
|
"use strict";
|
|
37449
|
-
|
|
37693
|
+
import_node_crypto9 = require("node:crypto");
|
|
37450
37694
|
import_node_path24 = __toESM(require("node:path"), 1);
|
|
37451
37695
|
init_zod();
|
|
37452
37696
|
init_cliError();
|
|
@@ -37614,7 +37858,7 @@ var init_identityNameRenameRecord = __esm({
|
|
|
37614
37858
|
|
|
37615
37859
|
// src/launcher/launchRecords.ts
|
|
37616
37860
|
function recordFile2(directory, pid) {
|
|
37617
|
-
return import_node_path26.default.join(directory, `${String(pid)}.${(0,
|
|
37861
|
+
return import_node_path26.default.join(directory, `${String(pid)}.${(0, import_node_crypto10.randomUUID)()}${RECORD_SUFFIX2}`);
|
|
37618
37862
|
}
|
|
37619
37863
|
function readRecord(fs37, directory, name) {
|
|
37620
37864
|
if (!name.endsWith(RECORD_SUFFIX2)) {
|
|
@@ -37655,12 +37899,12 @@ function liveLaunchesOn(fs37, directory, identity, isRunning) {
|
|
|
37655
37899
|
return record3?.identity === identity && isRunning(record3.pid) ? [record3.pid] : [];
|
|
37656
37900
|
}).sort((left, right) => left - right);
|
|
37657
37901
|
}
|
|
37658
|
-
var import_node_path26,
|
|
37902
|
+
var import_node_path26, import_node_crypto10, LaunchRecordSchema, RECORD_SUFFIX2;
|
|
37659
37903
|
var init_launchRecords = __esm({
|
|
37660
37904
|
"src/launcher/launchRecords.ts"() {
|
|
37661
37905
|
"use strict";
|
|
37662
37906
|
import_node_path26 = __toESM(require("node:path"), 1);
|
|
37663
|
-
|
|
37907
|
+
import_node_crypto10 = require("node:crypto");
|
|
37664
37908
|
init_zod();
|
|
37665
37909
|
LaunchRecordSchema = external_exports.strictObject({
|
|
37666
37910
|
/** The launcher's process id, which is what tells a launch in progress from a record a crashed launcher left behind. */
|
|
@@ -40205,7 +40449,7 @@ function ipBytes(address) {
|
|
|
40205
40449
|
return bytes;
|
|
40206
40450
|
}
|
|
40207
40451
|
function keyIdentifier(publicKey) {
|
|
40208
|
-
return (0,
|
|
40452
|
+
return (0, import_node_crypto11.createHash)("sha1").update(publicKey.export({ type: "pkcs1", format: "der" })).digest();
|
|
40209
40453
|
}
|
|
40210
40454
|
function readElement(buffer2, offset) {
|
|
40211
40455
|
const tag = buffer2[offset];
|
|
@@ -40251,7 +40495,7 @@ ${body.join("\n")}
|
|
|
40251
40495
|
`;
|
|
40252
40496
|
}
|
|
40253
40497
|
function randomSerial() {
|
|
40254
|
-
const bytes = (0,
|
|
40498
|
+
const bytes = (0, import_node_crypto11.randomBytes)(SERIAL_NUMBER_BYTES);
|
|
40255
40499
|
bytes[0] = (bytes[0] ?? 0) & BASE_128_PAYLOAD_MASK | HIGH_BIT >> 1;
|
|
40256
40500
|
return bytes;
|
|
40257
40501
|
}
|
|
@@ -40266,7 +40510,7 @@ function assemble(spec) {
|
|
|
40266
40510
|
spec.subjectPublicKey.export({ type: "spki", format: "der" }),
|
|
40267
40511
|
tlv(TAG_EXTENSIONS, sequence(...spec.extensions))
|
|
40268
40512
|
);
|
|
40269
|
-
const signature = (0,
|
|
40513
|
+
const signature = (0, import_node_crypto11.sign)("sha256", tbs, spec.signingKey);
|
|
40270
40514
|
return sequence(tbs, SIGNATURE_ALGORITHM, wholeBitString(signature));
|
|
40271
40515
|
}
|
|
40272
40516
|
function subjectKeyIdentifierExtension(publicKey) {
|
|
@@ -40276,7 +40520,7 @@ function basicConstraintsExtension(isCa) {
|
|
|
40276
40520
|
return extension(OID_BASIC_CONSTRAINTS, true, sequence(...isCa ? [boolean4(true)] : []));
|
|
40277
40521
|
}
|
|
40278
40522
|
function rsaKeyPair() {
|
|
40279
|
-
return (0,
|
|
40523
|
+
return (0, import_node_crypto11.generateKeyPairSync)("rsa", { modulusLength: RSA_MODULUS_BITS });
|
|
40280
40524
|
}
|
|
40281
40525
|
function keyPem(privateKey) {
|
|
40282
40526
|
return privateKey.export({ type: "pkcs8", format: "pem" });
|
|
@@ -40300,8 +40544,8 @@ function issueLeafCertificate(ca2, names, notBefore, notAfter) {
|
|
|
40300
40544
|
if (commonName === void 0) {
|
|
40301
40545
|
throw new Error("a leaf certificate needs at least one name");
|
|
40302
40546
|
}
|
|
40303
|
-
const caCertificate = new
|
|
40304
|
-
const caPrivateKey = (0,
|
|
40547
|
+
const caCertificate = new import_node_crypto11.X509Certificate(ca2.certPem);
|
|
40548
|
+
const caPrivateKey = (0, import_node_crypto11.createPrivateKey)(ca2.keyPem);
|
|
40305
40549
|
const { publicKey, privateKey } = rsaKeyPair();
|
|
40306
40550
|
const generalNames = names.map((name) => import_node_net.default.isIP(name) === 0 ? tlv(TAG_GENERAL_NAME_DNS, Buffer.from(name, "ascii")) : tlv(TAG_GENERAL_NAME_IP, ipBytes(name)));
|
|
40307
40551
|
const der = assemble({
|
|
@@ -40322,11 +40566,11 @@ function issueLeafCertificate(ca2, names, notBefore, notAfter) {
|
|
|
40322
40566
|
});
|
|
40323
40567
|
return { certPem: toPem("CERTIFICATE", der), keyPem: keyPem(privateKey) };
|
|
40324
40568
|
}
|
|
40325
|
-
var
|
|
40569
|
+
var import_node_crypto11, import_node_net, TAG_BOOLEAN, TAG_INTEGER, TAG_BIT_STRING, TAG_OCTET_STRING, TAG_NULL, TAG_OID, TAG_UTF8_STRING, TAG_UTC_TIME, TAG_GENERALIZED_TIME, TAG_SEQUENCE, TAG_SET, TAG_VERSION, TAG_EXTENSIONS, TAG_GENERAL_NAME_DNS, TAG_GENERAL_NAME_IP, TAG_KEY_IDENTIFIER, OID_COMMON_NAME, OID_SHA256_WITH_RSA, OID_SUBJECT_KEY_IDENTIFIER, OID_KEY_USAGE, OID_SUBJECT_ALT_NAME, OID_BASIC_CONSTRAINTS, OID_AUTHORITY_KEY_IDENTIFIER, OID_EXT_KEY_USAGE, OID_SERVER_AUTH, VERSION_3, SERIAL_NUMBER_BYTES, RSA_MODULUS_BITS, BITS_PER_BYTE, BYTE_MASK, HIGH_BIT, BASE_128_PAYLOAD_MASK, FIRST_ARC_WEIGHT, SHORT_FORM_MAX_LENGTH, MS_PER_SECOND6, UTC_TIME_LAST_YEAR, YEAR_DIGITS, TWO_DIGIT_YEAR_DIGITS, COMPACT_TIME_DIGITS, KEY_USAGE, SIGNATURE_ALGORITHM, IPV6_GROUPS, HEX_RADIX, BYTES_PER_IPV6_GROUP;
|
|
40326
40570
|
var init_x509 = __esm({
|
|
40327
40571
|
"src/frontdoor/x509.ts"() {
|
|
40328
40572
|
"use strict";
|
|
40329
|
-
|
|
40573
|
+
import_node_crypto11 = require("node:crypto");
|
|
40330
40574
|
import_node_net = __toESM(require("node:net"), 1);
|
|
40331
40575
|
TAG_BOOLEAN = 1;
|
|
40332
40576
|
TAG_INTEGER = 2;
|
|
@@ -40449,23 +40693,23 @@ function capabilityFromProxyAuthorization(value3) {
|
|
|
40449
40693
|
const password = userPass.slice(colon + 1);
|
|
40450
40694
|
return password === "" ? void 0 : password;
|
|
40451
40695
|
}
|
|
40452
|
-
function
|
|
40453
|
-
return (0,
|
|
40696
|
+
function digest2(token) {
|
|
40697
|
+
return (0, import_node_crypto12.createHash)("sha256").update(token, "utf8").digest();
|
|
40454
40698
|
}
|
|
40455
40699
|
function isLiveCapability(presented, live) {
|
|
40456
|
-
const presentedDigest =
|
|
40700
|
+
const presentedDigest = digest2(presented);
|
|
40457
40701
|
let matched = false;
|
|
40458
40702
|
for (const token of live) {
|
|
40459
|
-
const equal = (0,
|
|
40703
|
+
const equal = (0, import_node_crypto12.timingSafeEqual)(presentedDigest, digest2(token));
|
|
40460
40704
|
matched = equal || matched;
|
|
40461
40705
|
}
|
|
40462
40706
|
return matched;
|
|
40463
40707
|
}
|
|
40464
|
-
var
|
|
40708
|
+
var import_node_crypto12, CONNECT_PROXY_USER, CONNECT_PROXY_REALM, BASIC_SCHEME;
|
|
40465
40709
|
var init_capability = __esm({
|
|
40466
40710
|
"src/frontdoor/capability.ts"() {
|
|
40467
40711
|
"use strict";
|
|
40468
|
-
|
|
40712
|
+
import_node_crypto12 = require("node:crypto");
|
|
40469
40713
|
CONNECT_PROXY_USER = "agent-shim";
|
|
40470
40714
|
CONNECT_PROXY_REALM = "agent-shim front door";
|
|
40471
40715
|
BASIC_SCHEME = "basic";
|
|
@@ -40815,8 +41059,8 @@ function ensureCa(store, generate) {
|
|
|
40815
41059
|
}
|
|
40816
41060
|
function caParses(ca2) {
|
|
40817
41061
|
try {
|
|
40818
|
-
new
|
|
40819
|
-
(0,
|
|
41062
|
+
new import_node_crypto13.X509Certificate(ca2.certPem);
|
|
41063
|
+
(0, import_node_crypto13.createPrivateKey)(ca2.keyPem);
|
|
40820
41064
|
return true;
|
|
40821
41065
|
} catch {
|
|
40822
41066
|
return false;
|
|
@@ -41153,11 +41397,11 @@ function realConnectCertStore(paths) {
|
|
|
41153
41397
|
}
|
|
41154
41398
|
};
|
|
41155
41399
|
}
|
|
41156
|
-
var
|
|
41400
|
+
var import_node_crypto13, fs14, CONNECT_INTERCEPT_HOST, CONNECT_INTERCEPT_HOSTS, CONNECT_TAP_HOSTS, ROUTED_PATH_PREFIX, HTTPS_PORT, HTTP_BAD_GATEWAY, CA_KEY_FILE_MODE, CONNECT_LINE_TOKENS, HEAD_TERMINATOR, MAX_CONNECT_HEAD_BYTES, CONNECT_ESTABLISHED, REFUSAL, CONNECT_LIMITS, CA_VALIDITY_DAYS, LEAF_VALIDITY_DAYS, CA_SUBJECT_COMMON_NAME, MS_PER_DAY2, HOP_BY_HOP_HEADERS, LOOPBACK_LEAF_NAMES, TAP_ALPN_PROTOCOLS;
|
|
41157
41401
|
var init_connect = __esm({
|
|
41158
41402
|
"src/frontdoor/connect.ts"() {
|
|
41159
41403
|
"use strict";
|
|
41160
|
-
|
|
41404
|
+
import_node_crypto13 = require("node:crypto");
|
|
41161
41405
|
fs14 = __toESM(require("node:fs"), 1);
|
|
41162
41406
|
init_x509();
|
|
41163
41407
|
init_tap();
|
|
@@ -41989,7 +42233,7 @@ var init_package = __esm({
|
|
|
41989
42233
|
"package.json"() {
|
|
41990
42234
|
package_default = {
|
|
41991
42235
|
name: "claude-use",
|
|
41992
|
-
version: "
|
|
42236
|
+
version: "12.0.1",
|
|
41993
42237
|
description: "A profile manager and launcher for Claude Code that lets one person run multiple logins from one machine while controlling what gets shared between them.",
|
|
41994
42238
|
license: "MIT",
|
|
41995
42239
|
author: "Joseph Mearman <joseph@mearman.co.uk>",
|
|
@@ -42162,221 +42406,6 @@ var init_claudeVersion = __esm({
|
|
|
42162
42406
|
}
|
|
42163
42407
|
});
|
|
42164
42408
|
|
|
42165
|
-
// src/headroom/headers.ts
|
|
42166
|
-
function mergeAnthropicCustomHeaders(existing, additions) {
|
|
42167
|
-
const merged = /* @__PURE__ */ new Map();
|
|
42168
|
-
for (const block2 of existing) {
|
|
42169
|
-
if (block2 === void 0) {
|
|
42170
|
-
continue;
|
|
42171
|
-
}
|
|
42172
|
-
for (const line of block2.split("\n")) {
|
|
42173
|
-
const entry = parseCustomHeaderLine(line);
|
|
42174
|
-
if (entry === void 0) {
|
|
42175
|
-
continue;
|
|
42176
|
-
}
|
|
42177
|
-
merged.set(entry.name, entry.value);
|
|
42178
|
-
}
|
|
42179
|
-
}
|
|
42180
|
-
for (const entry of additions) {
|
|
42181
|
-
merged.set(entry.name, entry.value);
|
|
42182
|
-
}
|
|
42183
|
-
return [...merged].map(([name, value3]) => `${name}: ${value3}`).join("\n");
|
|
42184
|
-
}
|
|
42185
|
-
function parseAnthropicCustomHeaders(block2) {
|
|
42186
|
-
return block2.split("\n").flatMap((line) => {
|
|
42187
|
-
const entry = parseCustomHeaderLine(line);
|
|
42188
|
-
return entry === void 0 ? [] : [entry];
|
|
42189
|
-
});
|
|
42190
|
-
}
|
|
42191
|
-
function withoutAnthropicCustomHeaders(block2, remove) {
|
|
42192
|
-
const lines = block2.split("\n");
|
|
42193
|
-
const kept = lines.filter((line) => {
|
|
42194
|
-
const entry = parseCustomHeaderLine(line);
|
|
42195
|
-
return entry === void 0 || !remove(entry);
|
|
42196
|
-
});
|
|
42197
|
-
return kept.length === lines.length ? block2 : kept.join("\n");
|
|
42198
|
-
}
|
|
42199
|
-
function parseCustomHeaderLine(line) {
|
|
42200
|
-
const trimmed = line.trim();
|
|
42201
|
-
if (trimmed === "") {
|
|
42202
|
-
return void 0;
|
|
42203
|
-
}
|
|
42204
|
-
const colon = trimmed.indexOf(":");
|
|
42205
|
-
if (colon <= 0) {
|
|
42206
|
-
return void 0;
|
|
42207
|
-
}
|
|
42208
|
-
return { name: trimmed.slice(0, colon).trim(), value: trimmed.slice(colon + 1).trim() };
|
|
42209
|
-
}
|
|
42210
|
-
var init_headers = __esm({
|
|
42211
|
-
"src/headroom/headers.ts"() {
|
|
42212
|
-
"use strict";
|
|
42213
|
-
}
|
|
42214
|
-
});
|
|
42215
|
-
|
|
42216
|
-
// src/launcher/injected.ts
|
|
42217
|
-
function listKey(list2) {
|
|
42218
|
-
return `${list2},appended`;
|
|
42219
|
-
}
|
|
42220
|
-
function digest2(value3) {
|
|
42221
|
-
return (0, import_node_crypto13.createHash)("sha256").update(value3).digest("hex");
|
|
42222
|
-
}
|
|
42223
|
-
function recordedDigests(env) {
|
|
42224
|
-
const raw = env[INJECTED_ENV];
|
|
42225
|
-
if (raw === void 0 || raw === "") {
|
|
42226
|
-
return {};
|
|
42227
|
-
}
|
|
42228
|
-
let parsed;
|
|
42229
|
-
try {
|
|
42230
|
-
parsed = JSON.parse(raw);
|
|
42231
|
-
} catch {
|
|
42232
|
-
return {};
|
|
42233
|
-
}
|
|
42234
|
-
const result = InjectedSchema.safeParse(parsed);
|
|
42235
|
-
return result.success ? result.data : {};
|
|
42236
|
-
}
|
|
42237
|
-
function recordInjections(base) {
|
|
42238
|
-
const env = { ...base };
|
|
42239
|
-
const digests = new Map(Object.entries(recordedDigests(env)));
|
|
42240
|
-
return {
|
|
42241
|
-
env,
|
|
42242
|
-
set: (name, value3) => {
|
|
42243
|
-
env[name] = value3;
|
|
42244
|
-
digests.set(name, digest2(value3));
|
|
42245
|
-
},
|
|
42246
|
-
unset: (name) => {
|
|
42247
|
-
env[name] = void 0;
|
|
42248
|
-
digests.delete(name);
|
|
42249
|
-
},
|
|
42250
|
-
recordHeaders: (names) => {
|
|
42251
|
-
const block2 = env[CUSTOM_HEADERS_ENV];
|
|
42252
|
-
for (const entry of block2 === void 0 ? [] : parseAnthropicCustomHeaders(block2)) {
|
|
42253
|
-
if (names.includes(entry.name)) {
|
|
42254
|
-
digests.set(`${HEADER_KEY_PREFIX}${entry.name.toLowerCase()}`, digest2(entry.value));
|
|
42255
|
-
}
|
|
42256
|
-
}
|
|
42257
|
-
},
|
|
42258
|
-
recordBypassHosts: (list2, hosts) => {
|
|
42259
|
-
const recordedHosts = [.../* @__PURE__ */ new Set([...digests.get(listKey(list2))?.split(",") ?? [], ...hosts.map((host) => host.trim().toLowerCase()).filter((host) => host !== "")])];
|
|
42260
|
-
if (recordedHosts.length > 0) {
|
|
42261
|
-
digests.set(listKey(list2), recordedHosts.join(","));
|
|
42262
|
-
}
|
|
42263
|
-
},
|
|
42264
|
-
finish: () => {
|
|
42265
|
-
if (digests.size > 0) {
|
|
42266
|
-
env[INJECTED_ENV] = JSON.stringify(Object.fromEntries(digests));
|
|
42267
|
-
}
|
|
42268
|
-
}
|
|
42269
|
-
};
|
|
42270
|
-
}
|
|
42271
|
-
function withoutRecordedHosts(list2, value3, digests) {
|
|
42272
|
-
const recordedHosts = new Set(digests[listKey(list2)]?.split(","));
|
|
42273
|
-
const entries = value3.split(",");
|
|
42274
|
-
const kept = entries.filter((entry) => !recordedHosts.has(entry.trim().toLowerCase()));
|
|
42275
|
-
return kept.length === entries.length ? value3 : kept.join(",");
|
|
42276
|
-
}
|
|
42277
|
-
function launchEnvironment(env, configDirEscapeHatch) {
|
|
42278
|
-
return configDirEscapeHatch ? env : withoutInjected(env);
|
|
42279
|
-
}
|
|
42280
|
-
function withoutInjected(env) {
|
|
42281
|
-
const digests = recordedDigests(env);
|
|
42282
|
-
const entries = Object.entries(env).flatMap(([name, value3]) => {
|
|
42283
|
-
if (name === INJECTED_ENV) {
|
|
42284
|
-
return [];
|
|
42285
|
-
}
|
|
42286
|
-
if (value3 === void 0) {
|
|
42287
|
-
return [[name, value3]];
|
|
42288
|
-
}
|
|
42289
|
-
if (name === CUSTOM_HEADERS_ENV) {
|
|
42290
|
-
const remaining = withoutAnthropicCustomHeaders(value3, (entry) => digests[`${HEADER_KEY_PREFIX}${entry.name.toLowerCase()}`] === digest2(entry.value));
|
|
42291
|
-
return remaining !== value3 && remaining.trim() === "" ? [] : [[name, remaining]];
|
|
42292
|
-
}
|
|
42293
|
-
if (name === "NO_PROXY" || name === "no_proxy") {
|
|
42294
|
-
const remaining = withoutRecordedHosts(name, value3, digests);
|
|
42295
|
-
return remaining !== value3 && remaining.split(",").every((entry) => entry.trim() === "") ? [] : [[name, remaining]];
|
|
42296
|
-
}
|
|
42297
|
-
return digests[name] === digest2(value3) ? [] : [[name, value3]];
|
|
42298
|
-
});
|
|
42299
|
-
return Object.fromEntries(entries);
|
|
42300
|
-
}
|
|
42301
|
-
var import_node_crypto13, INJECTED_ENV, CUSTOM_HEADERS_ENV, HEADER_KEY_PREFIX, InjectedSchema;
|
|
42302
|
-
var init_injected = __esm({
|
|
42303
|
-
"src/launcher/injected.ts"() {
|
|
42304
|
-
"use strict";
|
|
42305
|
-
import_node_crypto13 = require("node:crypto");
|
|
42306
|
-
init_zod();
|
|
42307
|
-
init_headers();
|
|
42308
|
-
INJECTED_ENV = "AGENT_SHIM_INJECTED";
|
|
42309
|
-
CUSTOM_HEADERS_ENV = "ANTHROPIC_CUSTOM_HEADERS";
|
|
42310
|
-
HEADER_KEY_PREFIX = `${CUSTOM_HEADERS_ENV}:`;
|
|
42311
|
-
InjectedSchema = external_exports.record(external_exports.string(), external_exports.string());
|
|
42312
|
-
}
|
|
42313
|
-
});
|
|
42314
|
-
|
|
42315
|
-
// src/launcher/guard.ts
|
|
42316
|
-
function detectAmbientCredential(env, injected) {
|
|
42317
|
-
for (const variable of AMBIENT_CREDENTIAL_VARS) {
|
|
42318
|
-
const value3 = env[variable];
|
|
42319
|
-
if (value3 === void 0 || value3 === "") {
|
|
42320
|
-
continue;
|
|
42321
|
-
}
|
|
42322
|
-
if (injected?.variable === variable && value3 === injected.token) {
|
|
42323
|
-
continue;
|
|
42324
|
-
}
|
|
42325
|
-
return { variable };
|
|
42326
|
-
}
|
|
42327
|
-
return void 0;
|
|
42328
|
-
}
|
|
42329
|
-
function formatAmbientCredentialGuardMessage(variable, identityName) {
|
|
42330
|
-
const identitySetCommand = identityName === void 0 ? "agent-shim identity set <name> --allow-ambient-credential" : `agent-shim identity set ${identityName} --allow-ambient-credential`;
|
|
42331
|
-
return [
|
|
42332
|
-
`error: ${variable} is set in the environment. This identity's isolated`,
|
|
42333
|
-
"credential would be bypassed \u2014 every identity authenticates as this same key",
|
|
42334
|
-
"while it's set. Unset it, or if this is deliberate, opt in per-launch with",
|
|
42335
|
-
"AGENT_SHIM_ALLOW_AMBIENT_CREDENTIAL=1, or persistently for this identity with",
|
|
42336
|
-
`\`${identitySetCommand}\`.`
|
|
42337
|
-
].join("\n");
|
|
42338
|
-
}
|
|
42339
|
-
function evaluateAmbientCredentialGuard(params) {
|
|
42340
|
-
const detected = detectAmbientCredential(params.env, params.injectedCredential);
|
|
42341
|
-
if (detected === void 0) {
|
|
42342
|
-
return { ok: true };
|
|
42343
|
-
}
|
|
42344
|
-
if (params.allowAmbientCredentialOverride || params.allowAmbientCredential || params.providerSelected === true) {
|
|
42345
|
-
return { ok: true };
|
|
42346
|
-
}
|
|
42347
|
-
return {
|
|
42348
|
-
ok: false,
|
|
42349
|
-
variable: detected.variable,
|
|
42350
|
-
message: formatAmbientCredentialGuardMessage(detected.variable, params.identityName)
|
|
42351
|
-
};
|
|
42352
|
-
}
|
|
42353
|
-
function ambientCredentialFinding(env) {
|
|
42354
|
-
const named = detectAmbientCredential(launchEnvironment(env, false));
|
|
42355
|
-
if (named !== void 0) {
|
|
42356
|
-
return { severity: "warn", message: formatAmbientCredentialGuardMessage(named.variable) };
|
|
42357
|
-
}
|
|
42358
|
-
const bare = env.CLAUDE_CONFIG_DIR === void 0 || env.CLAUDE_CONFIG_DIR === "" ? void 0 : detectAmbientCredential(env);
|
|
42359
|
-
if (bare !== void 0) {
|
|
42360
|
-
return { severity: "warn", message: `${bare.variable} was set in this session by the launcher that started it. A launch that names an identity drops it, but a launch naming none keeps the session's CLAUDE_CONFIG_DIR and environment and is refused. Name an identity, as in \`claude @<name>\`.` };
|
|
42361
|
-
}
|
|
42362
|
-
return { severity: "pass", message: "No ambient-credential environment variable is set." };
|
|
42363
|
-
}
|
|
42364
|
-
var AMBIENT_CREDENTIAL_VARS;
|
|
42365
|
-
var init_guard = __esm({
|
|
42366
|
-
"src/launcher/guard.ts"() {
|
|
42367
|
-
"use strict";
|
|
42368
|
-
init_injected();
|
|
42369
|
-
AMBIENT_CREDENTIAL_VARS = [
|
|
42370
|
-
"ANTHROPIC_API_KEY",
|
|
42371
|
-
"ANTHROPIC_AUTH_TOKEN",
|
|
42372
|
-
"CLAUDE_CODE_OAUTH_TOKEN",
|
|
42373
|
-
"CLAUDE_CODE_USE_BEDROCK",
|
|
42374
|
-
"CLAUDE_CODE_USE_VERTEX",
|
|
42375
|
-
"CLAUDE_CODE_USE_FOUNDRY"
|
|
42376
|
-
];
|
|
42377
|
-
}
|
|
42378
|
-
});
|
|
42379
|
-
|
|
42380
42409
|
// node_modules/.pnpm/undici@7.30.1/node_modules/undici/lib/core/symbols.js
|
|
42381
42410
|
var require_symbols = __commonJS({
|
|
42382
42411
|
"node_modules/.pnpm/undici@7.30.1/node_modules/undici/lib/core/symbols.js"(exports2, module2) {
|
|
@@ -73234,10 +73263,22 @@ function decideLaunch(params, readOnly, onRecorded) {
|
|
|
73234
73263
|
...parsedArgv.delay === void 0 ? {} : { delay: parsedArgv.delay }
|
|
73235
73264
|
}
|
|
73236
73265
|
});
|
|
73237
|
-
const loginlessProvider =
|
|
73266
|
+
const loginlessProvider = (() => {
|
|
73267
|
+
if (!requestedFlags.remoteControl || selectedProvider === void 0 || farmIdentity === void 0 || identityDecision.name === void 0) {
|
|
73268
|
+
return void 0;
|
|
73269
|
+
}
|
|
73270
|
+
const stored2 = params.hasStoredLogin?.(farmIdentity);
|
|
73271
|
+
if (stored2 === false) {
|
|
73272
|
+
return { identity: identityDecision.name, provider: selectedProvider.name, why: "has no stored login" };
|
|
73273
|
+
}
|
|
73274
|
+
if (stored2 === true && params.hasUsableLogin?.(farmIdentity, discovered.path) === false) {
|
|
73275
|
+
return { identity: identityDecision.name, provider: selectedProvider.name, why: "has a stored login that is no longer usable" };
|
|
73276
|
+
}
|
|
73277
|
+
return void 0;
|
|
73278
|
+
})();
|
|
73238
73279
|
const notes = [];
|
|
73239
73280
|
if (loginlessProvider !== void 0) {
|
|
73240
|
-
notes.push(`${loginlessProvider.identity}
|
|
73281
|
+
notes.push(`${loginlessProvider.identity} ${loginlessProvider.why}, so Remote Control is off; provider ${loginlessProvider.provider} runs without it`);
|
|
73241
73282
|
}
|
|
73242
73283
|
const flags = loginlessProvider === void 0 ? requestedFlags : { ...requestedFlags, remoteControl: false };
|
|
73243
73284
|
const globalModels = loadConfigFile(paths.globalConfigFile, GlobalConfigSchema, params.fs.readConfigFile)?.config.models;
|
|
@@ -73700,6 +73741,7 @@ function realPrepareLaunchParams(paths, options) {
|
|
|
73700
73741
|
credentials: { ...realCredentialPort, cache: realCredentialCacheEnv(paths) },
|
|
73701
73742
|
hold: realHoldPort,
|
|
73702
73743
|
hasStoredLogin: (identity) => identitySignIn(realFarmFs, { platform: process.platform, run: options.run ?? realRunPort }, { farmRoot: import_node_path59.default.join(paths.identitiesDir, identity), hasCredentialBlock: false, provider: void 0 }).state !== "signed-out",
|
|
73744
|
+
hasUsableLogin: (identity, claudeBin) => storedLoginUsable(options.run ?? realRunPort, claudeBin, import_node_path59.default.join(paths.identitiesDir, identity), options.proc.env),
|
|
73703
73745
|
...farm.directoryIdentity === void 0 ? {} : { directoryPinnedIdentity: farm.directoryIdentity },
|
|
73704
73746
|
...farm.directoryConfigProfile === void 0 ? {} : { directoryRuleConfigProfile: farm.directoryConfigProfile },
|
|
73705
73747
|
...farm.globalDefaultConfigProfile === void 0 ? {} : { globalDefaultConfigProfile: farm.globalDefaultConfigProfile },
|
|
@@ -125524,7 +125566,7 @@ function registerCodexCommand(program2, deps) {
|
|
|
125524
125566
|
}
|
|
125525
125567
|
|
|
125526
125568
|
// src/frontdoor/commands.ts
|
|
125527
|
-
var
|
|
125569
|
+
var import_node_crypto32 = require("node:crypto");
|
|
125528
125570
|
var import_node_os19 = __toESM(require("node:os"), 1);
|
|
125529
125571
|
init_catalogueCredential();
|
|
125530
125572
|
var import_node_path73 = __toESM(require("node:path"), 1);
|
|
@@ -127123,6 +127165,9 @@ var net3 = __toESM(require("node:net"), 1);
|
|
|
127123
127165
|
var tls = __toESM(require("node:tls"), 1);
|
|
127124
127166
|
init_connect();
|
|
127125
127167
|
|
|
127168
|
+
// src/frontdoor/rcSessions.ts
|
|
127169
|
+
var import_node_crypto27 = require("node:crypto");
|
|
127170
|
+
|
|
127126
127171
|
// src/agents/liveTasks.ts
|
|
127127
127172
|
init_zod();
|
|
127128
127173
|
var LIVE_TASK_CAP = 512;
|
|
@@ -127288,6 +127333,125 @@ function mergeLiveTasks(tree, live) {
|
|
|
127288
127333
|
return { ...tree, agents, remoteSessions, liveOnly };
|
|
127289
127334
|
}
|
|
127290
127335
|
|
|
127336
|
+
// src/frontdoor/rcQuestions.ts
|
|
127337
|
+
var RC_QUESTION_TOOL_NAME = "AskUserQuestion";
|
|
127338
|
+
var RC_QUESTIONS_MAX = 16;
|
|
127339
|
+
var RC_QUESTION_OPTIONS_MAX = 16;
|
|
127340
|
+
var RC_QUESTION_FIELD_MAX_CHARS = 1024;
|
|
127341
|
+
var MULTI_SELECT_SEPARATOR = ", ";
|
|
127342
|
+
function isRecord11(value3) {
|
|
127343
|
+
return typeof value3 === "object" && value3 !== null && !Array.isArray(value3);
|
|
127344
|
+
}
|
|
127345
|
+
function fits(value3) {
|
|
127346
|
+
return value3 === void 0 || value3.length <= RC_QUESTION_FIELD_MAX_CHARS;
|
|
127347
|
+
}
|
|
127348
|
+
function optionOf(value3) {
|
|
127349
|
+
if (!isRecord11(value3) || typeof value3.label !== "string" || value3.label === "") {
|
|
127350
|
+
return "an option names no label";
|
|
127351
|
+
}
|
|
127352
|
+
const description = typeof value3.description === "string" && value3.description !== "" ? value3.description : void 0;
|
|
127353
|
+
if (!fits(value3.label) || !fits(description)) {
|
|
127354
|
+
return `an option is past ${String(RC_QUESTION_FIELD_MAX_CHARS)} characters`;
|
|
127355
|
+
}
|
|
127356
|
+
return description === void 0 ? { label: value3.label } : { label: value3.label, description };
|
|
127357
|
+
}
|
|
127358
|
+
function questionOf(value3) {
|
|
127359
|
+
if (!isRecord11(value3) || typeof value3.question !== "string" || value3.question === "" || !Array.isArray(value3.options) || value3.options.length === 0) {
|
|
127360
|
+
return "a question has no text or no options";
|
|
127361
|
+
}
|
|
127362
|
+
if (value3.options.length > RC_QUESTION_OPTIONS_MAX) {
|
|
127363
|
+
return `a question has more than ${String(RC_QUESTION_OPTIONS_MAX)} options`;
|
|
127364
|
+
}
|
|
127365
|
+
const options = [];
|
|
127366
|
+
for (const candidate of value3.options) {
|
|
127367
|
+
const option = optionOf(candidate);
|
|
127368
|
+
if (typeof option === "string") {
|
|
127369
|
+
return option;
|
|
127370
|
+
}
|
|
127371
|
+
if (options.some((existing) => existing.label === option.label)) {
|
|
127372
|
+
return `a question lists the option ${JSON.stringify(option.label)} twice`;
|
|
127373
|
+
}
|
|
127374
|
+
options.push(option);
|
|
127375
|
+
}
|
|
127376
|
+
const header = typeof value3.header === "string" && value3.header !== "" ? value3.header : void 0;
|
|
127377
|
+
if (!fits(value3.question) || !fits(header)) {
|
|
127378
|
+
return `a question is past ${String(RC_QUESTION_FIELD_MAX_CHARS)} characters`;
|
|
127379
|
+
}
|
|
127380
|
+
return { question: value3.question, ...header === void 0 ? {} : { header }, multiSelect: value3.multiSelect === true, options };
|
|
127381
|
+
}
|
|
127382
|
+
function rcQuestionsOfToolRequest(toolName, input2) {
|
|
127383
|
+
if (toolName !== RC_QUESTION_TOOL_NAME) {
|
|
127384
|
+
return void 0;
|
|
127385
|
+
}
|
|
127386
|
+
if (!isRecord11(input2) || !Array.isArray(input2.questions) || input2.questions.length === 0) {
|
|
127387
|
+
return { unanswerable: "the request names no questions" };
|
|
127388
|
+
}
|
|
127389
|
+
if (input2.questions.length > RC_QUESTIONS_MAX) {
|
|
127390
|
+
return { unanswerable: `the request asks more than ${String(RC_QUESTIONS_MAX)} questions` };
|
|
127391
|
+
}
|
|
127392
|
+
const questions = [];
|
|
127393
|
+
for (const candidate of input2.questions) {
|
|
127394
|
+
const question = questionOf(candidate);
|
|
127395
|
+
if (typeof question === "string") {
|
|
127396
|
+
return { unanswerable: question };
|
|
127397
|
+
}
|
|
127398
|
+
if (questions.some((existing) => existing.question === question.question)) {
|
|
127399
|
+
return { unanswerable: `the request asks ${JSON.stringify(question.question)} twice` };
|
|
127400
|
+
}
|
|
127401
|
+
questions.push(question);
|
|
127402
|
+
}
|
|
127403
|
+
return { questions };
|
|
127404
|
+
}
|
|
127405
|
+
function resolveSelection(question, questionNumber, selection) {
|
|
127406
|
+
if (typeof selection === "number") {
|
|
127407
|
+
const option = Number.isInteger(selection) ? question.options[selection - 1] : void 0;
|
|
127408
|
+
return option === void 0 ? { error: `question ${String(questionNumber)} has no option ${String(selection)}: its options are numbered 1 to ${String(question.options.length)}` } : { text: option.label };
|
|
127409
|
+
}
|
|
127410
|
+
if (typeof selection === "object") {
|
|
127411
|
+
const text5 = selection.text.trim();
|
|
127412
|
+
return text5 === "" ? { error: `question ${String(questionNumber)}'s free-text answer is empty` } : { text: text5 };
|
|
127413
|
+
}
|
|
127414
|
+
const exact = question.options.find((option) => option.label === selection);
|
|
127415
|
+
if (exact !== void 0) {
|
|
127416
|
+
return { text: exact.label };
|
|
127417
|
+
}
|
|
127418
|
+
const folded = question.options.filter((option) => option.label.toLowerCase() === selection.toLowerCase());
|
|
127419
|
+
const [only] = folded;
|
|
127420
|
+
if (only !== void 0 && folded.length === 1) {
|
|
127421
|
+
return { text: only.label };
|
|
127422
|
+
}
|
|
127423
|
+
return { error: `question ${String(questionNumber)} has no option labelled ${JSON.stringify(selection)}: its options are ${question.options.map((option) => JSON.stringify(option.label)).join(", ")}` };
|
|
127424
|
+
}
|
|
127425
|
+
function resolveRcQuestionAnswers(questions, choices) {
|
|
127426
|
+
if (choices.length !== questions.length) {
|
|
127427
|
+
return { error: `the request asks ${String(questions.length)} question(s), so the answer must choose for each of them in order, but it chose for ${String(choices.length)}` };
|
|
127428
|
+
}
|
|
127429
|
+
const answers = {};
|
|
127430
|
+
for (const [index, question] of questions.entries()) {
|
|
127431
|
+
const questionNumber = index + 1;
|
|
127432
|
+
const selections = choices[index] ?? [];
|
|
127433
|
+
if (selections.length === 0) {
|
|
127434
|
+
return { error: `question ${String(questionNumber)} has no selection` };
|
|
127435
|
+
}
|
|
127436
|
+
if (!question.multiSelect && selections.length > 1) {
|
|
127437
|
+
return { error: `question ${String(questionNumber)} takes one option, but ${String(selections.length)} were chosen` };
|
|
127438
|
+
}
|
|
127439
|
+
const texts = [];
|
|
127440
|
+
for (const selection of selections) {
|
|
127441
|
+
const resolved = resolveSelection(question, questionNumber, selection);
|
|
127442
|
+
if ("error" in resolved) {
|
|
127443
|
+
return resolved;
|
|
127444
|
+
}
|
|
127445
|
+
if (texts.includes(resolved.text)) {
|
|
127446
|
+
return { error: `question ${String(questionNumber)} chose ${JSON.stringify(resolved.text)} twice` };
|
|
127447
|
+
}
|
|
127448
|
+
texts.push(resolved.text);
|
|
127449
|
+
}
|
|
127450
|
+
answers[question.question] = texts.join(MULTI_SELECT_SEPARATOR);
|
|
127451
|
+
}
|
|
127452
|
+
return { answers };
|
|
127453
|
+
}
|
|
127454
|
+
|
|
127291
127455
|
// src/frontdoor/rcSessions.ts
|
|
127292
127456
|
var RC_SESSIONS_PATH_PREFIX = "/v1/code/sessions";
|
|
127293
127457
|
function pathnameOf(url2) {
|
|
@@ -127302,7 +127466,12 @@ var RC_IDLE_EXPIRY_MS = 45e3;
|
|
|
127302
127466
|
var RC_CREATE_RESPONSE_CAP_BYTES = 8192;
|
|
127303
127467
|
var CONFLICT_REASON_HEADER = "x-ccr-conflict-reason";
|
|
127304
127468
|
var RC_STREAM_WORKER_SOURCE = "worker";
|
|
127305
|
-
var
|
|
127469
|
+
var HIGH_SURROGATE_FIRST = 55296;
|
|
127470
|
+
var HIGH_SURROGATE_LAST = 56319;
|
|
127471
|
+
var RC_WORKER_IDLE = "idle";
|
|
127472
|
+
var RC_PENDING_PER_SESSION_MAX = 64;
|
|
127473
|
+
var RC_REQUEST_ID_MAX_CHARS = 128;
|
|
127474
|
+
var RC_RETIRED_TOMBSTONES_MAX = 2 * RC_PENDING_PER_SESSION_MAX;
|
|
127306
127475
|
var RC_REQUEST_PARSE_CAP_BYTES = 262144;
|
|
127307
127476
|
var RC_PENDING_SUMMARY_EXCERPT_CHARS = 300;
|
|
127308
127477
|
var SUCCESS_STATUS_MAX_EXCLUSIVE = 300;
|
|
@@ -127335,7 +127504,7 @@ function sessionCreateId(body) {
|
|
|
127335
127504
|
const id2 = session.id;
|
|
127336
127505
|
return typeof id2 === "string" && id2.startsWith(RC_SESSION_ID_PREFIX) ? id2 : void 0;
|
|
127337
127506
|
}
|
|
127338
|
-
function
|
|
127507
|
+
function isRecord12(value3) {
|
|
127339
127508
|
return typeof value3 === "object" && value3 !== null && !Array.isArray(value3);
|
|
127340
127509
|
}
|
|
127341
127510
|
function parseJsonObject(body) {
|
|
@@ -127345,7 +127514,7 @@ function parseJsonObject(body) {
|
|
|
127345
127514
|
} catch {
|
|
127346
127515
|
return void 0;
|
|
127347
127516
|
}
|
|
127348
|
-
return
|
|
127517
|
+
return isRecord12(parsed) ? parsed : void 0;
|
|
127349
127518
|
}
|
|
127350
127519
|
function nonEmptyString(record3, field) {
|
|
127351
127520
|
const value3 = record3 === void 0 ? void 0 : record3[field];
|
|
@@ -127355,8 +127524,16 @@ function finiteNumber(record3, field) {
|
|
|
127355
127524
|
const value3 = record3 === void 0 ? void 0 : record3[field];
|
|
127356
127525
|
return typeof value3 === "number" && Number.isFinite(value3) ? value3 : void 0;
|
|
127357
127526
|
}
|
|
127358
|
-
function
|
|
127359
|
-
|
|
127527
|
+
function rcExcerpt(text5) {
|
|
127528
|
+
if (text5.length <= RC_PENDING_SUMMARY_EXCERPT_CHARS) {
|
|
127529
|
+
return text5;
|
|
127530
|
+
}
|
|
127531
|
+
const cut = text5.slice(0, RC_PENDING_SUMMARY_EXCERPT_CHARS);
|
|
127532
|
+
const last = cut.charCodeAt(cut.length - 1);
|
|
127533
|
+
return `${isHighSurrogate(last) ? cut.slice(0, -1) : cut}...`;
|
|
127534
|
+
}
|
|
127535
|
+
function isHighSurrogate(unit) {
|
|
127536
|
+
return unit >= HIGH_SURROGATE_FIRST && unit <= HIGH_SURROGATE_LAST;
|
|
127360
127537
|
}
|
|
127361
127538
|
function payloadEventsOf(body) {
|
|
127362
127539
|
const parsed = parseJsonObject(body);
|
|
@@ -127366,11 +127543,11 @@ function payloadEventsOf(body) {
|
|
|
127366
127543
|
}
|
|
127367
127544
|
const payloads = [];
|
|
127368
127545
|
for (const event of events) {
|
|
127369
|
-
if (!
|
|
127546
|
+
if (!isRecord12(event)) {
|
|
127370
127547
|
continue;
|
|
127371
127548
|
}
|
|
127372
127549
|
const payload = event.payload;
|
|
127373
|
-
if (!
|
|
127550
|
+
if (!isRecord12(payload)) {
|
|
127374
127551
|
continue;
|
|
127375
127552
|
}
|
|
127376
127553
|
payloads.push(payload);
|
|
@@ -127378,6 +127555,14 @@ function payloadEventsOf(body) {
|
|
|
127378
127555
|
return payloads;
|
|
127379
127556
|
}
|
|
127380
127557
|
function pendingOfControlRequestPayload(payload) {
|
|
127558
|
+
const parsed = fullPendingOfControlRequestPayload(payload);
|
|
127559
|
+
const isQuestion = parsed !== void 0 && (parsed.questions !== void 0 || parsed.unanswerable !== void 0);
|
|
127560
|
+
if (parsed === void 0 || !isQuestion || Buffer.byteLength(JSON.stringify(payload), "utf8") <= RC_REQUEST_PARSE_CAP_BYTES) {
|
|
127561
|
+
return parsed;
|
|
127562
|
+
}
|
|
127563
|
+
return { ...parsed, questions: void 0, toolInput: void 0, oversized: true, unanswerable: parsed.unanswerable ?? `the request is past the door's parse cap of ${String(RC_REQUEST_PARSE_CAP_BYTES)} bytes` };
|
|
127564
|
+
}
|
|
127565
|
+
function fullPendingOfControlRequestPayload(payload) {
|
|
127381
127566
|
if (payload.type !== "control_request") {
|
|
127382
127567
|
return void 0;
|
|
127383
127568
|
}
|
|
@@ -127385,24 +127570,41 @@ function pendingOfControlRequestPayload(payload) {
|
|
|
127385
127570
|
if (requestId === void 0) {
|
|
127386
127571
|
return void 0;
|
|
127387
127572
|
}
|
|
127388
|
-
const request7 =
|
|
127573
|
+
const request7 = isRecord12(payload.request) ? payload.request : void 0;
|
|
127389
127574
|
const subtype = nonEmptyString(request7, "subtype");
|
|
127390
127575
|
const type2 = subtype ?? "control_request";
|
|
127391
127576
|
let summary = "";
|
|
127577
|
+
let questions;
|
|
127578
|
+
let unanswerable;
|
|
127579
|
+
let toolInput;
|
|
127392
127580
|
if (subtype === "can_use_tool") {
|
|
127393
|
-
const toolName = nonEmptyString(request7, "tool_name")
|
|
127581
|
+
const toolName = nonEmptyString(request7, "tool_name");
|
|
127394
127582
|
const input2 = request7 === void 0 ? void 0 : request7.input;
|
|
127395
|
-
summary = input2 === void 0 ? toolName : `${toolName} ${
|
|
127583
|
+
summary = input2 === void 0 ? toolName ?? "unknown tool" : `${toolName ?? "unknown tool"} ${rcExcerpt(JSON.stringify(input2))}`;
|
|
127584
|
+
const parsedQuestions = rcQuestionsOfToolRequest(toolName, input2);
|
|
127585
|
+
if (parsedQuestions !== void 0 && "questions" in parsedQuestions) {
|
|
127586
|
+
questions = parsedQuestions.questions;
|
|
127587
|
+
toolInput = isRecord12(input2) ? input2 : void 0;
|
|
127588
|
+
} else if (parsedQuestions !== void 0) {
|
|
127589
|
+
unanswerable = parsedQuestions.unanswerable;
|
|
127590
|
+
}
|
|
127396
127591
|
} else if (request7 !== void 0) {
|
|
127397
|
-
summary =
|
|
127592
|
+
summary = rcExcerpt(JSON.stringify(request7));
|
|
127593
|
+
}
|
|
127594
|
+
return { requestId, type: type2, summary, questions, unanswerable, toolInput, oversized: false };
|
|
127595
|
+
}
|
|
127596
|
+
function withdrawnRequestIdsOfControlCancelPayload(payload) {
|
|
127597
|
+
if (payload.type !== "control_cancel_request") {
|
|
127598
|
+
return [];
|
|
127398
127599
|
}
|
|
127399
|
-
|
|
127600
|
+
const id2 = nonEmptyString(payload, "request_id");
|
|
127601
|
+
return id2 === void 0 ? [] : [id2];
|
|
127400
127602
|
}
|
|
127401
127603
|
function answeredRequestIdsOfControlResponsePayload(payload) {
|
|
127402
127604
|
if (payload.type !== "control_response") {
|
|
127403
127605
|
return [];
|
|
127404
127606
|
}
|
|
127405
|
-
const response =
|
|
127607
|
+
const response = isRecord12(payload.response) ? payload.response : void 0;
|
|
127406
127608
|
const id2 = nonEmptyString(response, "request_id") ?? nonEmptyString(payload, "request_id") ?? nonEmptyString(payload, "uuid");
|
|
127407
127609
|
return id2 === void 0 ? [] : [id2];
|
|
127408
127610
|
}
|
|
@@ -127414,44 +127616,74 @@ function initFactsOfPayload(payload) {
|
|
|
127414
127616
|
}
|
|
127415
127617
|
function parseRcRequestBody(kind, body) {
|
|
127416
127618
|
if (kind === "heartbeat") {
|
|
127417
|
-
return { controlRequests: [], answeredRequestIds: [], idleSeconds: finiteNumber(parseJsonObject(body), "idle_seconds"), workerStatus: void 0, payloads: [] };
|
|
127619
|
+
return { controlRequests: [], answeredRequestIds: [], withdrawnRequestIds: [], idleSeconds: finiteNumber(parseJsonObject(body), "idle_seconds"), workerStatus: void 0, workerEpoch: void 0, payloads: [] };
|
|
127418
127620
|
}
|
|
127419
127621
|
if (kind === "worker-registration") {
|
|
127420
127622
|
const registration = parseJsonObject(body);
|
|
127421
|
-
const metadata = registration === void 0 || !
|
|
127623
|
+
const metadata = registration === void 0 || !isRecord12(registration.external_metadata) ? void 0 : registration.external_metadata;
|
|
127422
127624
|
const model = nonEmptyString(metadata, "model");
|
|
127423
|
-
return { controlRequests: [], answeredRequestIds: [], idleSeconds: void 0, workerStatus: nonEmptyString(registration, "worker_status"), payloads: [], ...model === void 0 ? {} : { model } };
|
|
127625
|
+
return { controlRequests: [], answeredRequestIds: [], withdrawnRequestIds: [], idleSeconds: void 0, workerStatus: nonEmptyString(registration, "worker_status"), workerEpoch: finiteNumber(registration, "worker_epoch"), payloads: [], ...model === void 0 ? {} : { model } };
|
|
127424
127626
|
}
|
|
127425
127627
|
const controlRequests = [];
|
|
127426
127628
|
const answeredRequestIds = [];
|
|
127629
|
+
const withdrawnRequestIds = [];
|
|
127427
127630
|
const payloads = payloadEventsOf(body);
|
|
127428
127631
|
for (const payload of payloads) {
|
|
127429
127632
|
const pending = pendingOfControlRequestPayload(payload);
|
|
127430
127633
|
if (pending !== void 0) {
|
|
127431
|
-
controlRequests.push(
|
|
127634
|
+
controlRequests.push(pending);
|
|
127432
127635
|
continue;
|
|
127433
127636
|
}
|
|
127434
127637
|
answeredRequestIds.push(...answeredRequestIdsOfControlResponsePayload(payload));
|
|
127638
|
+
if (kind === "worker-events") {
|
|
127639
|
+
withdrawnRequestIds.push(...withdrawnRequestIdsOfControlCancelPayload(payload));
|
|
127640
|
+
}
|
|
127641
|
+
}
|
|
127642
|
+
return { controlRequests, answeredRequestIds, withdrawnRequestIds, idleSeconds: void 0, workerStatus: void 0, workerEpoch: void 0, payloads };
|
|
127643
|
+
}
|
|
127644
|
+
function rememberBounded(record3, key) {
|
|
127645
|
+
record3.delete(key);
|
|
127646
|
+
record3.add(key);
|
|
127647
|
+
if (record3.size > RC_RETIRED_TOMBSTONES_MAX) {
|
|
127648
|
+
const [oldest] = record3;
|
|
127649
|
+
if (oldest !== void 0) {
|
|
127650
|
+
record3.delete(oldest);
|
|
127651
|
+
}
|
|
127435
127652
|
}
|
|
127436
|
-
|
|
127653
|
+
}
|
|
127654
|
+
function droppedKeyOf(requestId) {
|
|
127655
|
+
return requestId.length <= RC_REQUEST_ID_MAX_CHARS ? requestId : (0, import_node_crypto27.createHash)("sha256").update(requestId).digest("hex");
|
|
127437
127656
|
}
|
|
127438
127657
|
function createRcSessionTracker(deps) {
|
|
127439
127658
|
const entries = /* @__PURE__ */ new Map();
|
|
127659
|
+
let observationSequence = 0;
|
|
127660
|
+
const rememberRetired = (entry, requestId) => {
|
|
127661
|
+
rememberBounded(entry.retired, requestId);
|
|
127662
|
+
};
|
|
127440
127663
|
const retirePending = (entry, requestId, reason) => {
|
|
127441
127664
|
if (entry.pending.delete(requestId)) {
|
|
127442
|
-
entry
|
|
127665
|
+
rememberRetired(entry, requestId);
|
|
127443
127666
|
deps.onTransition?.({ kind: "pending-retired", session: entry.id, requestId, reason, at: deps.now() });
|
|
127444
127667
|
}
|
|
127445
127668
|
};
|
|
127446
|
-
const addPending = (entry,
|
|
127447
|
-
|
|
127669
|
+
const addPending = (entry, request7, now) => {
|
|
127670
|
+
const droppedKey = droppedKeyOf(request7.requestId);
|
|
127671
|
+
if (entry.retired.has(request7.requestId) || entry.dropped.has(droppedKey)) {
|
|
127448
127672
|
return;
|
|
127449
127673
|
}
|
|
127450
|
-
const
|
|
127451
|
-
|
|
127452
|
-
|
|
127453
|
-
|
|
127674
|
+
const already = entry.pending.get(request7.requestId);
|
|
127675
|
+
if (already !== void 0) {
|
|
127676
|
+
entry.pending.set(request7.requestId, { ...already, ...request7, observedAt: already.observedAt });
|
|
127677
|
+
return;
|
|
127454
127678
|
}
|
|
127679
|
+
if (request7.requestId.length > RC_REQUEST_ID_MAX_CHARS || entry.pending.size >= RC_PENDING_PER_SESSION_MAX) {
|
|
127680
|
+
entry.droppedPending += 1;
|
|
127681
|
+
rememberBounded(entry.dropped, droppedKey);
|
|
127682
|
+
return;
|
|
127683
|
+
}
|
|
127684
|
+
observationSequence += 1;
|
|
127685
|
+
entry.pending.set(request7.requestId, { sessionId: entry.id, ...request7, observedAt: now, observedSequence: observationSequence });
|
|
127686
|
+
deps.onTransition?.({ kind: "pending-born", session: entry.id, requestId: request7.requestId, type: request7.type, summary: request7.summary, at: now });
|
|
127455
127687
|
};
|
|
127456
127688
|
const expire = (id2, reason) => {
|
|
127457
127689
|
const entry = entries.get(id2);
|
|
@@ -127464,31 +127696,17 @@ function createRcSessionTracker(deps) {
|
|
|
127464
127696
|
entries.delete(id2);
|
|
127465
127697
|
deps.onTransition?.({ kind: "session-ended", session: id2, reason, at: deps.now() });
|
|
127466
127698
|
};
|
|
127467
|
-
const expirePendings = (entry, now) => {
|
|
127468
|
-
for (const [requestId, pending] of entry.pending) {
|
|
127469
|
-
if (now - pending.observedAt >= RC_PENDING_DEADLINE_MS) {
|
|
127470
|
-
retirePending(entry, requestId, "expired");
|
|
127471
|
-
}
|
|
127472
|
-
}
|
|
127473
|
-
for (const [requestId, retiredAt] of entry.retired) {
|
|
127474
|
-
if (now - retiredAt >= RC_PENDING_DEADLINE_MS) {
|
|
127475
|
-
entry.retired.delete(requestId);
|
|
127476
|
-
}
|
|
127477
|
-
}
|
|
127478
|
-
};
|
|
127479
127699
|
const sweep = () => {
|
|
127480
127700
|
for (const [id2, entry] of entries) {
|
|
127481
127701
|
if (deps.now() - entry.lastSeenAt >= deps.idleMs) {
|
|
127482
127702
|
expire(id2, "expired");
|
|
127483
|
-
continue;
|
|
127484
127703
|
}
|
|
127485
|
-
expirePendings(entry, deps.now());
|
|
127486
127704
|
}
|
|
127487
127705
|
};
|
|
127488
|
-
const timer = setInterval(sweep,
|
|
127706
|
+
const timer = setInterval(sweep, deps.idleMs);
|
|
127489
127707
|
timer.unref();
|
|
127490
127708
|
const birth = (id2, facts) => {
|
|
127491
|
-
const record3 = { id: id2, createdAt: deps.now(), lastSeenAt: deps.now(), ...facts, pending: /* @__PURE__ */ new Map(), retired: /* @__PURE__ */ new
|
|
127709
|
+
const record3 = { id: id2, createdAt: deps.now(), lastSeenAt: deps.now(), ...facts, pending: /* @__PURE__ */ new Map(), retired: /* @__PURE__ */ new Set(), dropped: /* @__PURE__ */ new Set(), workerState: void 0, workerIdleSeconds: void 0, model: void 0, cwd: void 0, sequenceNum: void 0, liveTasks: /* @__PURE__ */ new Map(), workerEpoch: void 0, droppedPending: 0, answering: /* @__PURE__ */ new Set() };
|
|
127492
127710
|
entries.set(id2, record3);
|
|
127493
127711
|
deps.onTransition?.({ kind: "session-appeared", session: id2, at: record3.createdAt });
|
|
127494
127712
|
return record3;
|
|
@@ -127519,6 +127737,7 @@ function createRcSessionTracker(deps) {
|
|
|
127519
127737
|
return void 0;
|
|
127520
127738
|
}
|
|
127521
127739
|
const tail = pathnameOf(request7.url).slice(RC_SESSIONS_PATH_PREFIX.length);
|
|
127740
|
+
const startedAtSequence = observationSequence;
|
|
127522
127741
|
const facts = {
|
|
127523
127742
|
oauthAuthorization: oauthAuthorizationOf(request7.headers),
|
|
127524
127743
|
anthropicVersion: singleHeader(request7.headers, "anthropic-version"),
|
|
@@ -127592,11 +127811,14 @@ function createRcSessionTracker(deps) {
|
|
|
127592
127811
|
}
|
|
127593
127812
|
const now = deps.now();
|
|
127594
127813
|
for (const controlRequest of factsOfBody.controlRequests) {
|
|
127595
|
-
addPending(entryNow,
|
|
127814
|
+
addPending(entryNow, controlRequest, now);
|
|
127596
127815
|
}
|
|
127597
127816
|
for (const requestId of factsOfBody.answeredRequestIds) {
|
|
127598
127817
|
retirePending(entryNow, requestId, "answered");
|
|
127599
127818
|
}
|
|
127819
|
+
for (const requestId of factsOfBody.withdrawnRequestIds) {
|
|
127820
|
+
retirePending(entryNow, requestId, "withdrawn");
|
|
127821
|
+
}
|
|
127600
127822
|
for (const payload of factsOfBody.payloads) {
|
|
127601
127823
|
entryNow.liveTasks = applyAgentTaskEvent(entryNow.liveTasks, id2, payload, now);
|
|
127602
127824
|
noteInit(entryNow, payload);
|
|
@@ -127612,6 +127834,17 @@ function createRcSessionTracker(deps) {
|
|
|
127612
127834
|
deps.onTransition?.({ kind: "worker-state", session: id2, state: factsOfBody.workerStatus, ...previous === void 0 ? {} : { previous }, at: now });
|
|
127613
127835
|
}
|
|
127614
127836
|
}
|
|
127837
|
+
const epochChanged = factsOfBody.workerEpoch !== void 0 && entryNow.workerEpoch !== void 0 && factsOfBody.workerEpoch !== entryNow.workerEpoch;
|
|
127838
|
+
if (factsOfBody.workerEpoch !== void 0) {
|
|
127839
|
+
entryNow.workerEpoch = factsOfBody.workerEpoch;
|
|
127840
|
+
}
|
|
127841
|
+
if (epochChanged || factsOfBody.workerStatus === RC_WORKER_IDLE) {
|
|
127842
|
+
for (const [requestId, pending] of entryNow.pending) {
|
|
127843
|
+
if (pending.observedSequence <= startedAtSequence) {
|
|
127844
|
+
retirePending(entryNow, requestId, "worker-stopped");
|
|
127845
|
+
}
|
|
127846
|
+
}
|
|
127847
|
+
}
|
|
127615
127848
|
};
|
|
127616
127849
|
const archiving = method === "POST" && rest === `${id2}/archive`;
|
|
127617
127850
|
return {
|
|
@@ -127651,7 +127884,7 @@ function createRcSessionTracker(deps) {
|
|
|
127651
127884
|
};
|
|
127652
127885
|
};
|
|
127653
127886
|
const summaryOf2 = ({ id: id2, createdAt, lastSeenAt }) => ({ id: id2, createdAt, lastSeenAt });
|
|
127654
|
-
const pendingSummaryOf = ({ sessionId, requestId, type: type2, summary, observedAt: observedAt2 }) => ({ sessionId, requestId, type: type2, summary, observedAt: observedAt2 });
|
|
127887
|
+
const pendingSummaryOf = ({ sessionId, requestId, type: type2, summary, questions, unanswerable, oversized, observedAt: observedAt2 }) => ({ sessionId, requestId, type: type2, summary, ...questions === void 0 ? {} : { questions }, ...oversized ? { oversized: true } : {}, ...unanswerable === void 0 ? {} : { unanswerable }, observedAt: observedAt2 });
|
|
127655
127888
|
const sortedEntries = () => [...entries.values()].sort((left, right) => left.createdAt - right.createdAt || (left.id < right.id ? -1 : 1));
|
|
127656
127889
|
const pendingSorted = (entry) => [...entry.pending.values()].sort((left, right) => left.observedAt - right.observedAt || (left.requestId < right.requestId ? -1 : 1)).map(pendingSummaryOf);
|
|
127657
127890
|
return {
|
|
@@ -127669,7 +127902,8 @@ function createRcSessionTracker(deps) {
|
|
|
127669
127902
|
pending: pendingSorted(entry),
|
|
127670
127903
|
...entry.identity === void 0 ? {} : { identity: entry.identity },
|
|
127671
127904
|
...entry.model === void 0 ? {} : { model: entry.model },
|
|
127672
|
-
...entry.cwd === void 0 ? {} : { cwd: entry.cwd }
|
|
127905
|
+
...entry.cwd === void 0 ? {} : { cwd: entry.cwd },
|
|
127906
|
+
...entry.droppedPending === 0 ? {} : { pendingDropped: entry.droppedPending }
|
|
127673
127907
|
}));
|
|
127674
127908
|
},
|
|
127675
127909
|
pendingOf: (sessionId) => {
|
|
@@ -127707,7 +127941,7 @@ function createRcSessionTracker(deps) {
|
|
|
127707
127941
|
return;
|
|
127708
127942
|
}
|
|
127709
127943
|
entry.sequenceNum = entry.sequenceNum === void 0 || event.sequence_num > entry.sequenceNum ? event.sequence_num : entry.sequenceNum;
|
|
127710
|
-
if (!
|
|
127944
|
+
if (!isRecord12(event.payload)) {
|
|
127711
127945
|
return;
|
|
127712
127946
|
}
|
|
127713
127947
|
entry.liveTasks = applyAgentTaskEvent(entry.liveTasks, sessionId, event.payload, deps.now());
|
|
@@ -127715,13 +127949,18 @@ function createRcSessionTracker(deps) {
|
|
|
127715
127949
|
const pending = pendingOfControlRequestPayload(event.payload);
|
|
127716
127950
|
if (pending !== void 0) {
|
|
127717
127951
|
if (event.source === RC_STREAM_WORKER_SOURCE) {
|
|
127718
|
-
addPending(entry,
|
|
127952
|
+
addPending(entry, pending, deps.now());
|
|
127719
127953
|
}
|
|
127720
127954
|
return;
|
|
127721
127955
|
}
|
|
127722
127956
|
for (const requestId of answeredRequestIdsOfControlResponsePayload(event.payload)) {
|
|
127723
127957
|
retirePending(entry, requestId, "answered");
|
|
127724
127958
|
}
|
|
127959
|
+
if (event.source === RC_STREAM_WORKER_SOURCE) {
|
|
127960
|
+
for (const requestId of withdrawnRequestIdsOfControlCancelPayload(event.payload)) {
|
|
127961
|
+
retirePending(entry, requestId, "withdrawn");
|
|
127962
|
+
}
|
|
127963
|
+
}
|
|
127725
127964
|
},
|
|
127726
127965
|
liveTasksOf: (sessionId) => {
|
|
127727
127966
|
sweep();
|
|
@@ -127733,6 +127972,17 @@ function createRcSessionTracker(deps) {
|
|
|
127733
127972
|
retirePending(entry, requestId, "answered");
|
|
127734
127973
|
}
|
|
127735
127974
|
},
|
|
127975
|
+
claimPending: (sessionId, requestId) => {
|
|
127976
|
+
const entry = entries.get(sessionId);
|
|
127977
|
+
if (entry === void 0 || !entry.pending.has(requestId) || entry.answering.has(requestId)) {
|
|
127978
|
+
return void 0;
|
|
127979
|
+
}
|
|
127980
|
+
entry.answering.add(requestId);
|
|
127981
|
+
return () => {
|
|
127982
|
+
entry.answering.delete(requestId);
|
|
127983
|
+
};
|
|
127984
|
+
},
|
|
127985
|
+
pendingToolInputOf: (sessionId, requestId) => entries.get(sessionId)?.pending.get(requestId)?.toolInput,
|
|
127736
127986
|
close: () => {
|
|
127737
127987
|
clearInterval(timer);
|
|
127738
127988
|
deps.onClose?.();
|
|
@@ -127878,8 +128128,8 @@ async function injectRcUserMessage(deps, sessionId, text5) {
|
|
|
127878
128128
|
}
|
|
127879
128129
|
return result;
|
|
127880
128130
|
}
|
|
127881
|
-
function buildRcControlResponsePayload(requestId, decision) {
|
|
127882
|
-
const result = decision.approve ? { behavior: "allow" } : { behavior: "deny", message: decision.message ?? "" };
|
|
128131
|
+
function buildRcControlResponsePayload(requestId, decision, updatedInput) {
|
|
128132
|
+
const result = decision.approve ? { behavior: "allow", ...updatedInput === void 0 ? {} : { updatedInput } } : { behavior: "deny", message: decision.message ?? "" };
|
|
127883
128133
|
return { type: "control_response", response: { subtype: "success", request_id: requestId, response: result } };
|
|
127884
128134
|
}
|
|
127885
128135
|
var RC_PERMISSION_MODES = ["default", "acceptEdits", "bypassPermissions", "plan", "dontAsk", "auto"];
|
|
@@ -127936,6 +128186,27 @@ function buildRcMcpOAuthCallbackUrlPayload(requestId, serverName, callbackUrl) {
|
|
|
127936
128186
|
function buildRcKeepAlivePayload() {
|
|
127937
128187
|
return { type: "keep_alive" };
|
|
127938
128188
|
}
|
|
128189
|
+
function questionAnswerInput(deps, sessionId, pending, decision) {
|
|
128190
|
+
const { questions, unanswerable } = pending;
|
|
128191
|
+
if (questions === void 0 && unanswerable === void 0) {
|
|
128192
|
+
return decision.choices === void 0 ? void 0 : { error: `control request ${pending.requestId} is not a question (it is ${pending.type}${pending.summary === "" ? "" : `: ${pending.summary}`}), so it has no options to choose; approve or deny it instead` };
|
|
128193
|
+
}
|
|
128194
|
+
if (!decision.approve) {
|
|
128195
|
+
return decision.choices === void 0 ? void 0 : { error: "a denial dismisses the question and carries no choices; choose options to answer it, or deny it without them" };
|
|
128196
|
+
}
|
|
128197
|
+
if (questions === void 0) {
|
|
128198
|
+
return { error: `control request ${pending.requestId} is a question the door cannot answer (${String(unanswerable)}), so it cannot write an answer the worker would read correctly; answer it in the session itself, or deny it to dismiss it` };
|
|
128199
|
+
}
|
|
128200
|
+
if (decision.choices === void 0) {
|
|
128201
|
+
return { error: `control request ${pending.requestId} is a question, so answering it means choosing an option for each of its ${String(questions.length)} question(s); deny it to dismiss it` };
|
|
128202
|
+
}
|
|
128203
|
+
const input2 = deps.pendingToolInputOf(sessionId, pending.requestId);
|
|
128204
|
+
if (input2 === void 0) {
|
|
128205
|
+
return { error: `the front door holds no input for question ${pending.requestId} on session ${sessionId}, so it cannot write the answer the worker expects` };
|
|
128206
|
+
}
|
|
128207
|
+
const resolved = resolveRcQuestionAnswers(questions, decision.choices);
|
|
128208
|
+
return "error" in resolved ? resolved : { input: { ...input2, answers: resolved.answers } };
|
|
128209
|
+
}
|
|
127939
128210
|
async function answerRcControlRequest(deps, sessionId, requestId, decision) {
|
|
127940
128211
|
const credential = deps.credentialOf(sessionId);
|
|
127941
128212
|
if (credential === void 0) {
|
|
@@ -127944,15 +128215,26 @@ async function answerRcControlRequest(deps, sessionId, requestId, decision) {
|
|
|
127944
128215
|
if (credential.authorization === void 0) {
|
|
127945
128216
|
return noOAuthCredentialResult(sessionId);
|
|
127946
128217
|
}
|
|
127947
|
-
|
|
127948
|
-
|
|
128218
|
+
const pending = deps.pendingOf(sessionId).find((candidate) => candidate.requestId === requestId);
|
|
128219
|
+
if (pending === void 0) {
|
|
128220
|
+
return { ok: false, message: `the front door has not observed control request ${requestId} pending on session ${sessionId}: it was answered already (by this door, by an attached client or in the session's own terminal), the worker withdrew it, or it never passed through this door` };
|
|
128221
|
+
}
|
|
128222
|
+
const updatedInput = questionAnswerInput(deps, sessionId, pending, decision);
|
|
128223
|
+
if (updatedInput !== void 0 && "error" in updatedInput) {
|
|
128224
|
+
return { ok: false, message: updatedInput.error };
|
|
127949
128225
|
}
|
|
127950
|
-
const
|
|
128226
|
+
const release = deps.claimPending(sessionId, requestId);
|
|
128227
|
+
if (release === void 0) {
|
|
128228
|
+
return { ok: false, message: `another answer to control request ${requestId} on session ${sessionId} is being written right now; the worker takes only one, so this one was not sent` };
|
|
128229
|
+
}
|
|
128230
|
+
const body = JSON.stringify(buildRcEventWriteBody(buildRcControlResponsePayload(requestId, decision, updatedInput?.input)));
|
|
127951
128231
|
let answer;
|
|
127952
128232
|
try {
|
|
127953
128233
|
answer = await deps.dial.writeEvents(sessionId, rcWriteHeaders(credential), body);
|
|
127954
128234
|
} catch (error63) {
|
|
127955
128235
|
return { ok: false, message: `the door could not reach the API host to answer on session ${sessionId}: ${error63 instanceof Error ? error63.message : String(error63)}` };
|
|
128236
|
+
} finally {
|
|
128237
|
+
release();
|
|
127956
128238
|
}
|
|
127957
128239
|
const result = rcEventWriteResultFromAnswer(answer);
|
|
127958
128240
|
if (result.ok) {
|
|
@@ -128096,6 +128378,198 @@ function readMachineLoad() {
|
|
|
128096
128378
|
// src/frontdoor/rcControl.ts
|
|
128097
128379
|
var https = __toESM(require("node:https"), 1);
|
|
128098
128380
|
init_capability();
|
|
128381
|
+
|
|
128382
|
+
// src/frontdoor/rcSchemas.ts
|
|
128383
|
+
init_zod();
|
|
128384
|
+
var RcPermissionModeSchema = external_exports.enum(RC_PERMISSION_MODES);
|
|
128385
|
+
var RcSessionSummarySchema = external_exports.strictObject({
|
|
128386
|
+
id: external_exports.string(),
|
|
128387
|
+
createdAt: external_exports.number(),
|
|
128388
|
+
lastSeenAt: external_exports.number()
|
|
128389
|
+
});
|
|
128390
|
+
function workerFactSchema(value3) {
|
|
128391
|
+
return external_exports.strictObject({ value: value3, observedAt: external_exports.number() });
|
|
128392
|
+
}
|
|
128393
|
+
var RcQuestionOptionSchema = external_exports.strictObject({
|
|
128394
|
+
label: external_exports.string(),
|
|
128395
|
+
description: external_exports.string().optional()
|
|
128396
|
+
});
|
|
128397
|
+
var RcPendingQuestionSchema = external_exports.strictObject({
|
|
128398
|
+
question: external_exports.string(),
|
|
128399
|
+
header: external_exports.string().optional(),
|
|
128400
|
+
multiSelect: external_exports.boolean(),
|
|
128401
|
+
options: external_exports.readonly(external_exports.array(RcQuestionOptionSchema))
|
|
128402
|
+
});
|
|
128403
|
+
var RcPendingRequestSummarySchema = external_exports.strictObject({
|
|
128404
|
+
sessionId: external_exports.string(),
|
|
128405
|
+
requestId: external_exports.string(),
|
|
128406
|
+
type: external_exports.string(),
|
|
128407
|
+
summary: external_exports.string(),
|
|
128408
|
+
questions: external_exports.readonly(external_exports.array(RcPendingQuestionSchema)).optional(),
|
|
128409
|
+
oversized: external_exports.literal(true).optional(),
|
|
128410
|
+
unanswerable: external_exports.string().optional(),
|
|
128411
|
+
observedAt: external_exports.number()
|
|
128412
|
+
});
|
|
128413
|
+
var RcSessionStatusSchema = external_exports.strictObject({
|
|
128414
|
+
...RcSessionSummarySchema.shape,
|
|
128415
|
+
workerState: workerFactSchema(external_exports.string()).optional(),
|
|
128416
|
+
workerIdleSeconds: workerFactSchema(external_exports.number()).optional(),
|
|
128417
|
+
pending: external_exports.readonly(external_exports.array(RcPendingRequestSummarySchema)),
|
|
128418
|
+
/** The identity the session runs as, when known; absent otherwise. */
|
|
128419
|
+
identity: external_exports.string().optional(),
|
|
128420
|
+
/** The model the session last stated, when the door saw one. */
|
|
128421
|
+
model: external_exports.string().optional(),
|
|
128422
|
+
/** The session's name from the Claude Code session registry, when the registry holds it. */
|
|
128423
|
+
name: external_exports.string().optional(),
|
|
128424
|
+
/** The session process's id from the registry. */
|
|
128425
|
+
pid: external_exports.number().optional(),
|
|
128426
|
+
/** The session's working directory, from its init event or the registry. */
|
|
128427
|
+
cwd: external_exports.string().optional(),
|
|
128428
|
+
pendingDropped: external_exports.int().positive().optional()
|
|
128429
|
+
});
|
|
128430
|
+
var RcStreamEnvelopeSchema = external_exports.looseObject({
|
|
128431
|
+
/** The envelope's own event id, when the host sent one. */
|
|
128432
|
+
event_id: external_exports.string().optional(),
|
|
128433
|
+
/** The envelope's event type, the discriminator a consumer switches on (`control_request`, `user`, and kin). */
|
|
128434
|
+
event_type: external_exports.string(),
|
|
128435
|
+
/** The sequence number the host assigned, the value a resume continues after. */
|
|
128436
|
+
sequence_num: external_exports.int(),
|
|
128437
|
+
/** Who emitted the event (`worker` for the CLI's half, a client id for a client's). */
|
|
128438
|
+
source: external_exports.string(),
|
|
128439
|
+
/** The event's payload, carried verbatim: its shape is the payload family's, narrowed by whichever consumer needs it. Optional in the schema's own type because the door forwards the host's envelope as it arrived, asserting only the fields it relies on itself. */
|
|
128440
|
+
payload: external_exports.unknown().optional(),
|
|
128441
|
+
/** When the host created the event; the protocol's own type for this field is not established here, so it is forwarded rather than asserted. */
|
|
128442
|
+
created_at: external_exports.unknown().optional()
|
|
128443
|
+
});
|
|
128444
|
+
var RcStreamEventSchema = external_exports.strictObject({
|
|
128445
|
+
session: external_exports.string(),
|
|
128446
|
+
envelope: RcStreamEnvelopeSchema
|
|
128447
|
+
});
|
|
128448
|
+
var RcRateLimitWindowSchema = external_exports.looseObject({
|
|
128449
|
+
/** The fraction of the window used, usually between 0 and 1, above 1 when usage legitimately runs past the window's cap (the CLI's own field description states both). */
|
|
128450
|
+
utilization: external_exports.number().optional(),
|
|
128451
|
+
/** When the window resets, in unix epoch seconds: the unit is the CLI's own field description, stated in the 2.1.289 bundle's schema. */
|
|
128452
|
+
resetsAt: external_exports.number().optional()
|
|
128453
|
+
});
|
|
128454
|
+
var RcRateLimitInfoSchema = external_exports.looseObject({
|
|
128455
|
+
/** The limiting window's own status (`allowed`, `allowed_warning`, `rejected`), asserted only as a string because the vocabulary grows with the CLI. */
|
|
128456
|
+
status: external_exports.string(),
|
|
128457
|
+
/** When the limiting window resets, in unix epoch seconds. */
|
|
128458
|
+
resetsAt: external_exports.number().optional(),
|
|
128459
|
+
/** Which window the top-level fields describe (`five_hour`, `seven_day`, and kin), the payload's own name for it. */
|
|
128460
|
+
rateLimitType: external_exports.string().optional(),
|
|
128461
|
+
/** The fraction of the limiting window used, on the same scale the per-window utilizations carry. */
|
|
128462
|
+
utilization: external_exports.number().optional(),
|
|
128463
|
+
/** Whether usage beyond the plan (extra usage) is currently covering the overflow, the payload's own flag for it. */
|
|
128464
|
+
isUsingOverage: external_exports.boolean().optional(),
|
|
128465
|
+
/** The overage's own status, the same vocabulary the limiting window's `status` carries. */
|
|
128466
|
+
overageStatus: external_exports.string().optional(),
|
|
128467
|
+
/** When the overage window resets, in unix epoch seconds. */
|
|
128468
|
+
overageResetsAt: external_exports.number().optional(),
|
|
128469
|
+
/** Each subscription window the account's response headers carried: the session (five-hour), weekly (seven-day), and overage-included weekly windows, each present only when the account's responses carry it. */
|
|
128470
|
+
unifiedWindows: external_exports.looseObject({ five_hour: RcRateLimitWindowSchema.optional(), seven_day: RcRateLimitWindowSchema.optional(), seven_day_overage_included: RcRateLimitWindowSchema.optional() }).optional()
|
|
128471
|
+
});
|
|
128472
|
+
var RcLiveRateLimitSchema = external_exports.strictObject({
|
|
128473
|
+
session: external_exports.string(),
|
|
128474
|
+
observedAt: external_exports.number(),
|
|
128475
|
+
rateLimit: RcRateLimitInfoSchema
|
|
128476
|
+
});
|
|
128477
|
+
var RcSessionQuerySchema = external_exports.strictObject({
|
|
128478
|
+
session: external_exports.string().min(1).optional()
|
|
128479
|
+
});
|
|
128480
|
+
var RcSendInputSchema = external_exports.strictObject({
|
|
128481
|
+
session: external_exports.string().min(1),
|
|
128482
|
+
text: external_exports.string().min(1)
|
|
128483
|
+
});
|
|
128484
|
+
var RcQuestionSelectionSchema = external_exports.union([external_exports.string().min(1), external_exports.int().positive(), external_exports.strictObject({ text: external_exports.string().refine((text5) => text5.trim() !== "", { message: "free text must not be blank" }) })]);
|
|
128485
|
+
var RcQuestionChoicesSchema = external_exports.array(external_exports.array(RcQuestionSelectionSchema).min(1)).min(1);
|
|
128486
|
+
var RcAnswerInputSchema = external_exports.strictObject({
|
|
128487
|
+
session: external_exports.string().min(1),
|
|
128488
|
+
request: external_exports.string().min(1),
|
|
128489
|
+
approve: external_exports.boolean(),
|
|
128490
|
+
text: external_exports.string().optional(),
|
|
128491
|
+
choices: RcQuestionChoicesSchema.optional()
|
|
128492
|
+
}).refine((input2) => !input2.approve || input2.text === void 0 || input2.text === "", { message: "an approval carries no text (the protocol's allow result has no message field); text is the denial message" }).refine((input2) => input2.approve || input2.choices === void 0, { message: "choices answer a question, so they come with approve: true; a denial dismisses the question" });
|
|
128493
|
+
var RcInterruptInputSchema = external_exports.strictObject({
|
|
128494
|
+
session: external_exports.string().min(1)
|
|
128495
|
+
});
|
|
128496
|
+
var RcSetModelInputSchema = external_exports.strictObject({
|
|
128497
|
+
session: external_exports.string().min(1),
|
|
128498
|
+
model: external_exports.string().min(1)
|
|
128499
|
+
});
|
|
128500
|
+
var RcSetPermissionModeInputSchema = external_exports.strictObject({
|
|
128501
|
+
session: external_exports.string().min(1),
|
|
128502
|
+
mode: RcPermissionModeSchema
|
|
128503
|
+
});
|
|
128504
|
+
var RcEndSessionInputSchema = external_exports.strictObject({
|
|
128505
|
+
session: external_exports.string().min(1),
|
|
128506
|
+
reason: external_exports.string().min(1).optional()
|
|
128507
|
+
});
|
|
128508
|
+
var RcGetUsageInputSchema = external_exports.strictObject({
|
|
128509
|
+
session: external_exports.string().min(1),
|
|
128510
|
+
skipBehaviors: external_exports.boolean().optional()
|
|
128511
|
+
});
|
|
128512
|
+
var RcGetContextUsageInputSchema = external_exports.strictObject({
|
|
128513
|
+
session: external_exports.string().min(1),
|
|
128514
|
+
detail: external_exports.enum(RC_CONTEXT_USAGE_DETAILS).optional()
|
|
128515
|
+
});
|
|
128516
|
+
var RcReadFileInputSchema = external_exports.strictObject({
|
|
128517
|
+
session: external_exports.string().min(1),
|
|
128518
|
+
path: external_exports.string().min(1),
|
|
128519
|
+
maxBytes: external_exports.number().int().positive().optional(),
|
|
128520
|
+
encoding: external_exports.enum(RC_READ_FILE_ENCODINGS).optional()
|
|
128521
|
+
});
|
|
128522
|
+
var RcFileSuggestionsInputSchema = external_exports.strictObject({
|
|
128523
|
+
session: external_exports.string().min(1),
|
|
128524
|
+
query: external_exports.string()
|
|
128525
|
+
});
|
|
128526
|
+
var RcKeepAliveInputSchema = external_exports.strictObject({
|
|
128527
|
+
session: external_exports.string().min(1)
|
|
128528
|
+
});
|
|
128529
|
+
var RcMcpStatusInputSchema = external_exports.strictObject({
|
|
128530
|
+
session: external_exports.string().min(1)
|
|
128531
|
+
});
|
|
128532
|
+
var RcMcpReconnectInputSchema = external_exports.strictObject({
|
|
128533
|
+
session: external_exports.string().min(1),
|
|
128534
|
+
serverName: external_exports.string().min(1)
|
|
128535
|
+
});
|
|
128536
|
+
var RcMcpAuthenticateInputSchema = external_exports.strictObject({
|
|
128537
|
+
session: external_exports.string().min(1),
|
|
128538
|
+
serverName: external_exports.string().min(1),
|
|
128539
|
+
redirectUri: external_exports.string().min(1)
|
|
128540
|
+
});
|
|
128541
|
+
var RcMcpOAuthCallbackUrlInputSchema = external_exports.strictObject({
|
|
128542
|
+
session: external_exports.string().min(1),
|
|
128543
|
+
serverName: external_exports.string().min(1),
|
|
128544
|
+
callbackUrl: external_exports.string().min(1)
|
|
128545
|
+
});
|
|
128546
|
+
var RcTeleportInputSchema = external_exports.strictObject({
|
|
128547
|
+
session: external_exports.string().min(1),
|
|
128548
|
+
marker: external_exports.string().min(1)
|
|
128549
|
+
});
|
|
128550
|
+
var RcListOutputSchema = external_exports.strictObject({ sessions: external_exports.readonly(external_exports.array(RcSessionSummarySchema)) });
|
|
128551
|
+
var RcStatusOutputSchema = external_exports.strictObject({ statuses: external_exports.readonly(external_exports.array(RcSessionStatusSchema)) });
|
|
128552
|
+
var RcPendingOutputSchema = external_exports.strictObject({
|
|
128553
|
+
pending: external_exports.readonly(external_exports.array(RcPendingRequestSummarySchema)),
|
|
128554
|
+
/** The sessions that had requests the door did not list (past the per-session cap, or with an id the protocol does not mint), each with how many: a question the caller expects may be among them. Absent when none did. */
|
|
128555
|
+
dropped: external_exports.readonly(external_exports.array(external_exports.strictObject({ sessionId: external_exports.string(), count: external_exports.int().positive() }))).optional()
|
|
128556
|
+
});
|
|
128557
|
+
var RcWriteOutputSchema = external_exports.strictObject({
|
|
128558
|
+
session: external_exports.string(),
|
|
128559
|
+
sequenceNums: external_exports.readonly(external_exports.array(external_exports.number()))
|
|
128560
|
+
});
|
|
128561
|
+
var RcControlWriteOutputSchema = external_exports.strictObject({
|
|
128562
|
+
session: external_exports.string(),
|
|
128563
|
+
request: external_exports.string(),
|
|
128564
|
+
sequenceNums: external_exports.readonly(external_exports.array(external_exports.number()))
|
|
128565
|
+
});
|
|
128566
|
+
var RcAnswerOutputSchema = external_exports.strictObject({
|
|
128567
|
+
session: external_exports.string(),
|
|
128568
|
+
request: external_exports.string(),
|
|
128569
|
+
sequenceNums: external_exports.readonly(external_exports.array(external_exports.number()))
|
|
128570
|
+
});
|
|
128571
|
+
|
|
128572
|
+
// src/frontdoor/rcControl.ts
|
|
128099
128573
|
var RC_PERMISSION_MODE_LIST = RC_PERMISSION_MODES.join(", ");
|
|
128100
128574
|
var CONTROL_PATH_PREFIX = "/__agent-shim/rc";
|
|
128101
128575
|
var CONTROL_BODY_CAP_BYTES = 10485760;
|
|
@@ -128352,11 +128826,20 @@ function createRcControlHandler(deps) {
|
|
|
128352
128826
|
return;
|
|
128353
128827
|
}
|
|
128354
128828
|
const text5 = "text" in parsed && typeof parsed.text === "string" ? parsed.text : void 0;
|
|
128829
|
+
const choices = "choices" in parsed ? RcQuestionChoicesSchema.safeParse(parsed.choices) : void 0;
|
|
128830
|
+
if (choices !== void 0 && !choices.success) {
|
|
128831
|
+
answerJson(response, HTTP_STATUS.badRequest, { error: 'choices must be one non-empty list per question of selections, each an option label, a one-based option number or {"text": ...}' });
|
|
128832
|
+
return;
|
|
128833
|
+
}
|
|
128834
|
+
if (choices !== void 0 && !parsed.approve) {
|
|
128835
|
+
answerJson(response, HTTP_STATUS.badRequest, { error: "choices answer a question, so they come with approve: true; a denial dismisses the question" });
|
|
128836
|
+
return;
|
|
128837
|
+
}
|
|
128355
128838
|
if (parsed.approve && text5 !== void 0 && text5 !== "") {
|
|
128356
128839
|
answerJson(response, HTTP_STATUS.badRequest, { error: "an approval carries no text (the protocol's allow result has no message field); text is the denial message" });
|
|
128357
128840
|
return;
|
|
128358
128841
|
}
|
|
128359
|
-
const result = await deps.answer(parsed.session, parsed.request, { approve: parsed.approve, message: parsed.approve ? void 0 : text5 });
|
|
128842
|
+
const result = await deps.answer(parsed.session, parsed.request, { approve: parsed.approve, message: parsed.approve ? void 0 : text5, ...choices === void 0 ? {} : { choices: choices.data } });
|
|
128360
128843
|
if (result.ok) {
|
|
128361
128844
|
answerJson(response, HTTP_STATUS.ok, { session: parsed.session, request: parsed.request, sequenceNums: result.sequenceNums });
|
|
128362
128845
|
return;
|
|
@@ -128478,6 +128961,9 @@ function isRcSessionStatus(value3) {
|
|
|
128478
128961
|
if ("workerState" in value3 && value3.workerState !== void 0 && !isRcWorkerFact(value3.workerState, (candidate) => typeof candidate === "string")) {
|
|
128479
128962
|
return false;
|
|
128480
128963
|
}
|
|
128964
|
+
if ("pendingDropped" in value3 && value3.pendingDropped !== void 0 && typeof value3.pendingDropped !== "number") {
|
|
128965
|
+
return false;
|
|
128966
|
+
}
|
|
128481
128967
|
if ("workerIdleSeconds" in value3 && value3.workerIdleSeconds !== void 0 && !isRcWorkerFact(value3.workerIdleSeconds, (candidate) => typeof candidate === "number")) {
|
|
128482
128968
|
return false;
|
|
128483
128969
|
}
|
|
@@ -128487,13 +128973,7 @@ function isRcSessionStatus(value3) {
|
|
|
128487
128973
|
return value3.pending.every((candidate) => isRcPendingRequestSummary(candidate));
|
|
128488
128974
|
}
|
|
128489
128975
|
function isRcPendingRequestSummary(value3) {
|
|
128490
|
-
|
|
128491
|
-
return false;
|
|
128492
|
-
}
|
|
128493
|
-
if (!("sessionId" in value3) || !("requestId" in value3) || !("type" in value3) || !("summary" in value3) || !("observedAt" in value3)) {
|
|
128494
|
-
return false;
|
|
128495
|
-
}
|
|
128496
|
-
return typeof value3.sessionId === "string" && typeof value3.requestId === "string" && typeof value3.type === "string" && typeof value3.summary === "string" && typeof value3.observedAt === "number";
|
|
128976
|
+
return RcPendingRequestSummarySchema.safeParse(value3).success;
|
|
128497
128977
|
}
|
|
128498
128978
|
function sequenceNumsOfBody(body) {
|
|
128499
128979
|
let parsed;
|
|
@@ -128629,7 +129109,7 @@ function frontDoorRcControl(transport, token) {
|
|
|
128629
129109
|
sendPrompt: async (sessionId, text5) => await writeOf(`${CONTROL_PATH_PREFIX}/inject`, JSON.stringify({ session: sessionId, text: text5 }), (status, message) => `injecting into ${sessionId} failed (HTTP ${String(status)}): ${message}`),
|
|
128630
129110
|
answerRequest: async (sessionId, requestId, decision) => await writeOf(
|
|
128631
129111
|
`${CONTROL_PATH_PREFIX}/answer`,
|
|
128632
|
-
JSON.stringify({ session: sessionId, request: requestId, approve: decision.approve, ...decision.approve || decision.message === void 0 ? {} : { text: decision.message } }),
|
|
129112
|
+
JSON.stringify({ session: sessionId, request: requestId, approve: decision.approve, ...decision.approve || decision.message === void 0 ? {} : { text: decision.message }, ...decision.choices === void 0 ? {} : { choices: decision.choices } }),
|
|
128633
129113
|
(status, message) => `answering control request ${requestId} on ${sessionId} failed (HTTP ${String(status)}): ${message}`
|
|
128634
129114
|
),
|
|
128635
129115
|
interruptSession: async (sessionId) => await writeOf(`${CONTROL_PATH_PREFIX}/interrupt`, JSON.stringify({ session: sessionId }), (status, message) => `interrupting ${sessionId} failed (HTTP ${String(status)}): ${message}`),
|
|
@@ -134534,7 +135014,7 @@ function getOpenAPIMeta(procedureOrLazy) {
|
|
|
134534
135014
|
// node_modules/.pnpm/@openapi-spec+downgrader@0.3.0/node_modules/@openapi-spec/downgrader/dist/shared/downgrader.DqoV5gJe.mjs
|
|
134535
135015
|
var DROP = /* @__PURE__ */ Symbol("drop");
|
|
134536
135016
|
var HTTP_METHODS = ["get", "put", "post", "delete", "options", "head", "patch", "trace"];
|
|
134537
|
-
function
|
|
135017
|
+
function isRecord13(value3) {
|
|
134538
135018
|
if (typeof value3 !== "object" || value3 === null || Array.isArray(value3)) {
|
|
134539
135019
|
return false;
|
|
134540
135020
|
}
|
|
@@ -134552,10 +135032,10 @@ function defineFields(table) {
|
|
|
134552
135032
|
return new Map(Object.entries(table));
|
|
134553
135033
|
}
|
|
134554
135034
|
function clone3(value3) {
|
|
134555
|
-
return Array.isArray(value3) ||
|
|
135035
|
+
return Array.isArray(value3) || isRecord13(value3) ? copy(value3, /* @__PURE__ */ new Map()) : value3;
|
|
134556
135036
|
}
|
|
134557
135037
|
function copy(value3, copies) {
|
|
134558
|
-
if (!(Array.isArray(value3) ||
|
|
135038
|
+
if (!(Array.isArray(value3) || isRecord13(value3))) {
|
|
134559
135039
|
return value3;
|
|
134560
135040
|
}
|
|
134561
135041
|
const known = copies.get(value3);
|
|
@@ -134580,7 +135060,7 @@ function copy(value3, copies) {
|
|
|
134580
135060
|
return out;
|
|
134581
135061
|
}
|
|
134582
135062
|
function convertObject(value3, ctx, fields, finish) {
|
|
134583
|
-
if (!
|
|
135063
|
+
if (!isRecord13(value3)) {
|
|
134584
135064
|
return clone3(value3);
|
|
134585
135065
|
}
|
|
134586
135066
|
let seen = ctx.seen.get(fields);
|
|
@@ -134609,7 +135089,7 @@ function convertObject(value3, ctx, fields, finish) {
|
|
|
134609
135089
|
}
|
|
134610
135090
|
function map2(convert, isEntry = () => true) {
|
|
134611
135091
|
return (value3, ctx) => {
|
|
134612
|
-
if (!
|
|
135092
|
+
if (!isRecord13(value3)) {
|
|
134613
135093
|
return clone3(value3);
|
|
134614
135094
|
}
|
|
134615
135095
|
const out = [];
|
|
@@ -134635,7 +135115,7 @@ function hasType(type2, name) {
|
|
|
134635
135115
|
return type2 === name || Array.isArray(type2) && type2.includes(name);
|
|
134636
135116
|
}
|
|
134637
135117
|
function getRef(value3) {
|
|
134638
|
-
return
|
|
135118
|
+
return isRecord13(value3) && typeof value3.$ref === "string" ? value3.$ref : void 0;
|
|
134639
135119
|
}
|
|
134640
135120
|
function find(root, ref) {
|
|
134641
135121
|
if (!ref.startsWith("#")) {
|
|
@@ -134653,7 +135133,7 @@ function find(root, ref) {
|
|
|
134653
135133
|
let target = root;
|
|
134654
135134
|
for (const token of pointer.split("/").slice(1)) {
|
|
134655
135135
|
const key = token.replaceAll("~1", "/").replaceAll("~0", "~");
|
|
134656
|
-
if (!(
|
|
135136
|
+
if (!(isRecord13(target) || Array.isArray(target)) || !Object.hasOwn(target, key)) {
|
|
134657
135137
|
return void 0;
|
|
134658
135138
|
}
|
|
134659
135139
|
target = target[key];
|
|
@@ -134935,7 +135415,7 @@ function losesRestriction(key, schema, exactTuple) {
|
|
|
134935
135415
|
return !exactTuple;
|
|
134936
135416
|
case "propertyNames": {
|
|
134937
135417
|
const names = schema.propertyNames;
|
|
134938
|
-
return !(names === true ||
|
|
135418
|
+
return !(names === true || isRecord13(names) && Object.entries(names).every(([name, item]) => name === "type" && item === "string"));
|
|
134939
135419
|
}
|
|
134940
135420
|
case "unevaluatedProperties":
|
|
134941
135421
|
return !(schema.additionalProperties !== void 0 || isUnevaluatedAdditional(schema));
|
|
@@ -134959,7 +135439,7 @@ function loosen(out, schema, exactTuple) {
|
|
|
134959
135439
|
delete out.oneOf;
|
|
134960
135440
|
loose = true;
|
|
134961
135441
|
}
|
|
134962
|
-
return loose || isLoose(out.items) || isLoose(out.additionalProperties) ||
|
|
135442
|
+
return loose || isLoose(out.items) || isLoose(out.additionalProperties) || isRecord13(out.properties) && Object.values(out.properties).some(isLoose) || Array.isArray(out.allOf) && out.allOf.some(isLoose) || Array.isArray(out.anyOf) && out.anyOf.some(isLoose);
|
|
134963
135443
|
}
|
|
134964
135444
|
function convertType(out, type2) {
|
|
134965
135445
|
if (typeof type2 === "string" && type2 !== "null") {
|
|
@@ -135092,7 +135572,7 @@ function convertOperation(value3, ctx) {
|
|
|
135092
135572
|
}
|
|
135093
135573
|
function finishMergedPathItem(out, pathItem, ctx) {
|
|
135094
135574
|
const target = inline(pathItem.$ref, ctx, convertPathItem);
|
|
135095
|
-
if (
|
|
135575
|
+
if (isRecord13(target)) {
|
|
135096
135576
|
for (const [key, item] of Object.entries(target)) {
|
|
135097
135577
|
out[key] ??= item;
|
|
135098
135578
|
}
|
|
@@ -135105,17 +135585,17 @@ function convertPathItem(value3, ctx) {
|
|
|
135105
135585
|
function schemeType(scheme, ctx) {
|
|
135106
135586
|
const ref = getRef(scheme);
|
|
135107
135587
|
const target = ref === void 0 ? scheme : resolve2(ref, ctx);
|
|
135108
|
-
return
|
|
135588
|
+
return isRecord13(target) ? target.type : void 0;
|
|
135109
135589
|
}
|
|
135110
135590
|
function convertSecurity(value3, ctx) {
|
|
135111
135591
|
if (!Array.isArray(value3)) {
|
|
135112
135592
|
return clone3(value3);
|
|
135113
135593
|
}
|
|
135114
135594
|
const schemes = resolvePointer("#/components/securitySchemes", ctx);
|
|
135115
|
-
const typeOf = (name) =>
|
|
135595
|
+
const typeOf = (name) => isRecord13(schemes) && Object.hasOwn(schemes, name) ? schemeType(schemes[name], ctx) : void 0;
|
|
135116
135596
|
const out = [];
|
|
135117
135597
|
for (const requirement of value3) {
|
|
135118
|
-
if (!
|
|
135598
|
+
if (!isRecord13(requirement)) {
|
|
135119
135599
|
out.push(clone3(requirement));
|
|
135120
135600
|
continue;
|
|
135121
135601
|
}
|
|
@@ -135254,7 +135734,7 @@ function convertSchema3(value3, ctx) {
|
|
|
135254
135734
|
return convertObject(value3, ctx, SCHEMA_FIELDS2);
|
|
135255
135735
|
}
|
|
135256
135736
|
function convertXml(value3, _ctx, schema) {
|
|
135257
|
-
if (!
|
|
135737
|
+
if (!isRecord13(value3)) {
|
|
135258
135738
|
return clone3(value3);
|
|
135259
135739
|
}
|
|
135260
135740
|
const { nodeType, ...out } = clone3(value3);
|
|
@@ -135288,7 +135768,7 @@ function convertExample(value3, ctx) {
|
|
|
135288
135768
|
return convertObject(value3, ctx, EXAMPLE_FIELDS, finishExample);
|
|
135289
135769
|
}
|
|
135290
135770
|
function isQuerystring(parameter) {
|
|
135291
|
-
return
|
|
135771
|
+
return isRecord13(parameter) && parameter.in === "querystring";
|
|
135292
135772
|
}
|
|
135293
135773
|
function finishParameter(out, parameter) {
|
|
135294
135774
|
if (parameter.content !== void 0) {
|
|
@@ -137578,177 +138058,6 @@ var ResetScheduleSchema = external_exports.strictObject({ resets: external_expor
|
|
|
137578
138058
|
var import_node_path64 = __toESM(require("node:path"), 1);
|
|
137579
138059
|
init_zod();
|
|
137580
138060
|
init_schema2();
|
|
137581
|
-
|
|
137582
|
-
// src/frontdoor/rcSchemas.ts
|
|
137583
|
-
init_zod();
|
|
137584
|
-
var RcPermissionModeSchema = external_exports.enum(RC_PERMISSION_MODES);
|
|
137585
|
-
var RcSessionSummarySchema = external_exports.strictObject({
|
|
137586
|
-
id: external_exports.string(),
|
|
137587
|
-
createdAt: external_exports.number(),
|
|
137588
|
-
lastSeenAt: external_exports.number()
|
|
137589
|
-
});
|
|
137590
|
-
function workerFactSchema(value3) {
|
|
137591
|
-
return external_exports.strictObject({ value: value3, observedAt: external_exports.number() });
|
|
137592
|
-
}
|
|
137593
|
-
var RcPendingRequestSummarySchema = external_exports.strictObject({
|
|
137594
|
-
sessionId: external_exports.string(),
|
|
137595
|
-
requestId: external_exports.string(),
|
|
137596
|
-
type: external_exports.string(),
|
|
137597
|
-
summary: external_exports.string(),
|
|
137598
|
-
observedAt: external_exports.number()
|
|
137599
|
-
});
|
|
137600
|
-
var RcSessionStatusSchema = external_exports.strictObject({
|
|
137601
|
-
...RcSessionSummarySchema.shape,
|
|
137602
|
-
workerState: workerFactSchema(external_exports.string()).optional(),
|
|
137603
|
-
workerIdleSeconds: workerFactSchema(external_exports.number()).optional(),
|
|
137604
|
-
pending: external_exports.readonly(external_exports.array(RcPendingRequestSummarySchema)),
|
|
137605
|
-
/** The identity the session runs as, when known; absent otherwise. */
|
|
137606
|
-
identity: external_exports.string().optional(),
|
|
137607
|
-
/** The model the session last stated, when the door saw one. */
|
|
137608
|
-
model: external_exports.string().optional(),
|
|
137609
|
-
/** The session's name from the Claude Code session registry, when the registry holds it. */
|
|
137610
|
-
name: external_exports.string().optional(),
|
|
137611
|
-
/** The session process's id from the registry. */
|
|
137612
|
-
pid: external_exports.number().optional(),
|
|
137613
|
-
/** The session's working directory, from its init event or the registry. */
|
|
137614
|
-
cwd: external_exports.string().optional()
|
|
137615
|
-
});
|
|
137616
|
-
var RcStreamEnvelopeSchema = external_exports.looseObject({
|
|
137617
|
-
/** The envelope's own event id, when the host sent one. */
|
|
137618
|
-
event_id: external_exports.string().optional(),
|
|
137619
|
-
/** The envelope's event type, the discriminator a consumer switches on (`control_request`, `user`, and kin). */
|
|
137620
|
-
event_type: external_exports.string(),
|
|
137621
|
-
/** The sequence number the host assigned, the value a resume continues after. */
|
|
137622
|
-
sequence_num: external_exports.int(),
|
|
137623
|
-
/** Who emitted the event (`worker` for the CLI's half, a client id for a client's). */
|
|
137624
|
-
source: external_exports.string(),
|
|
137625
|
-
/** The event's payload, carried verbatim: its shape is the payload family's, narrowed by whichever consumer needs it. Optional in the schema's own type because the door forwards the host's envelope as it arrived, asserting only the fields it relies on itself. */
|
|
137626
|
-
payload: external_exports.unknown().optional(),
|
|
137627
|
-
/** When the host created the event; the protocol's own type for this field is not established here, so it is forwarded rather than asserted. */
|
|
137628
|
-
created_at: external_exports.unknown().optional()
|
|
137629
|
-
});
|
|
137630
|
-
var RcStreamEventSchema = external_exports.strictObject({
|
|
137631
|
-
session: external_exports.string(),
|
|
137632
|
-
envelope: RcStreamEnvelopeSchema
|
|
137633
|
-
});
|
|
137634
|
-
var RcRateLimitWindowSchema = external_exports.looseObject({
|
|
137635
|
-
/** The fraction of the window used, usually between 0 and 1, above 1 when usage legitimately runs past the window's cap (the CLI's own field description states both). */
|
|
137636
|
-
utilization: external_exports.number().optional(),
|
|
137637
|
-
/** When the window resets, in unix epoch seconds: the unit is the CLI's own field description, stated in the 2.1.289 bundle's schema. */
|
|
137638
|
-
resetsAt: external_exports.number().optional()
|
|
137639
|
-
});
|
|
137640
|
-
var RcRateLimitInfoSchema = external_exports.looseObject({
|
|
137641
|
-
/** The limiting window's own status (`allowed`, `allowed_warning`, `rejected`), asserted only as a string because the vocabulary grows with the CLI. */
|
|
137642
|
-
status: external_exports.string(),
|
|
137643
|
-
/** When the limiting window resets, in unix epoch seconds. */
|
|
137644
|
-
resetsAt: external_exports.number().optional(),
|
|
137645
|
-
/** Which window the top-level fields describe (`five_hour`, `seven_day`, and kin), the payload's own name for it. */
|
|
137646
|
-
rateLimitType: external_exports.string().optional(),
|
|
137647
|
-
/** The fraction of the limiting window used, on the same scale the per-window utilizations carry. */
|
|
137648
|
-
utilization: external_exports.number().optional(),
|
|
137649
|
-
/** Whether usage beyond the plan (extra usage) is currently covering the overflow, the payload's own flag for it. */
|
|
137650
|
-
isUsingOverage: external_exports.boolean().optional(),
|
|
137651
|
-
/** The overage's own status, the same vocabulary the limiting window's `status` carries. */
|
|
137652
|
-
overageStatus: external_exports.string().optional(),
|
|
137653
|
-
/** When the overage window resets, in unix epoch seconds. */
|
|
137654
|
-
overageResetsAt: external_exports.number().optional(),
|
|
137655
|
-
/** Each subscription window the account's response headers carried: the session (five-hour), weekly (seven-day), and overage-included weekly windows, each present only when the account's responses carry it. */
|
|
137656
|
-
unifiedWindows: external_exports.looseObject({ five_hour: RcRateLimitWindowSchema.optional(), seven_day: RcRateLimitWindowSchema.optional(), seven_day_overage_included: RcRateLimitWindowSchema.optional() }).optional()
|
|
137657
|
-
});
|
|
137658
|
-
var RcLiveRateLimitSchema = external_exports.strictObject({
|
|
137659
|
-
session: external_exports.string(),
|
|
137660
|
-
observedAt: external_exports.number(),
|
|
137661
|
-
rateLimit: RcRateLimitInfoSchema
|
|
137662
|
-
});
|
|
137663
|
-
var RcSessionQuerySchema = external_exports.strictObject({
|
|
137664
|
-
session: external_exports.string().min(1).optional()
|
|
137665
|
-
});
|
|
137666
|
-
var RcSendInputSchema = external_exports.strictObject({
|
|
137667
|
-
session: external_exports.string().min(1),
|
|
137668
|
-
text: external_exports.string().min(1)
|
|
137669
|
-
});
|
|
137670
|
-
var RcAnswerInputSchema = external_exports.strictObject({
|
|
137671
|
-
session: external_exports.string().min(1),
|
|
137672
|
-
request: external_exports.string().min(1),
|
|
137673
|
-
approve: external_exports.boolean(),
|
|
137674
|
-
text: external_exports.string().optional()
|
|
137675
|
-
}).refine((input2) => !input2.approve || input2.text === void 0 || input2.text === "", { message: "an approval carries no text (the protocol's allow result has no message field); text is the denial message" });
|
|
137676
|
-
var RcInterruptInputSchema = external_exports.strictObject({
|
|
137677
|
-
session: external_exports.string().min(1)
|
|
137678
|
-
});
|
|
137679
|
-
var RcSetModelInputSchema = external_exports.strictObject({
|
|
137680
|
-
session: external_exports.string().min(1),
|
|
137681
|
-
model: external_exports.string().min(1)
|
|
137682
|
-
});
|
|
137683
|
-
var RcSetPermissionModeInputSchema = external_exports.strictObject({
|
|
137684
|
-
session: external_exports.string().min(1),
|
|
137685
|
-
mode: RcPermissionModeSchema
|
|
137686
|
-
});
|
|
137687
|
-
var RcEndSessionInputSchema = external_exports.strictObject({
|
|
137688
|
-
session: external_exports.string().min(1),
|
|
137689
|
-
reason: external_exports.string().min(1).optional()
|
|
137690
|
-
});
|
|
137691
|
-
var RcGetUsageInputSchema = external_exports.strictObject({
|
|
137692
|
-
session: external_exports.string().min(1),
|
|
137693
|
-
skipBehaviors: external_exports.boolean().optional()
|
|
137694
|
-
});
|
|
137695
|
-
var RcGetContextUsageInputSchema = external_exports.strictObject({
|
|
137696
|
-
session: external_exports.string().min(1),
|
|
137697
|
-
detail: external_exports.enum(RC_CONTEXT_USAGE_DETAILS).optional()
|
|
137698
|
-
});
|
|
137699
|
-
var RcReadFileInputSchema = external_exports.strictObject({
|
|
137700
|
-
session: external_exports.string().min(1),
|
|
137701
|
-
path: external_exports.string().min(1),
|
|
137702
|
-
maxBytes: external_exports.number().int().positive().optional(),
|
|
137703
|
-
encoding: external_exports.enum(RC_READ_FILE_ENCODINGS).optional()
|
|
137704
|
-
});
|
|
137705
|
-
var RcFileSuggestionsInputSchema = external_exports.strictObject({
|
|
137706
|
-
session: external_exports.string().min(1),
|
|
137707
|
-
query: external_exports.string()
|
|
137708
|
-
});
|
|
137709
|
-
var RcKeepAliveInputSchema = external_exports.strictObject({
|
|
137710
|
-
session: external_exports.string().min(1)
|
|
137711
|
-
});
|
|
137712
|
-
var RcMcpStatusInputSchema = external_exports.strictObject({
|
|
137713
|
-
session: external_exports.string().min(1)
|
|
137714
|
-
});
|
|
137715
|
-
var RcMcpReconnectInputSchema = external_exports.strictObject({
|
|
137716
|
-
session: external_exports.string().min(1),
|
|
137717
|
-
serverName: external_exports.string().min(1)
|
|
137718
|
-
});
|
|
137719
|
-
var RcMcpAuthenticateInputSchema = external_exports.strictObject({
|
|
137720
|
-
session: external_exports.string().min(1),
|
|
137721
|
-
serverName: external_exports.string().min(1),
|
|
137722
|
-
redirectUri: external_exports.string().min(1)
|
|
137723
|
-
});
|
|
137724
|
-
var RcMcpOAuthCallbackUrlInputSchema = external_exports.strictObject({
|
|
137725
|
-
session: external_exports.string().min(1),
|
|
137726
|
-
serverName: external_exports.string().min(1),
|
|
137727
|
-
callbackUrl: external_exports.string().min(1)
|
|
137728
|
-
});
|
|
137729
|
-
var RcTeleportInputSchema = external_exports.strictObject({
|
|
137730
|
-
session: external_exports.string().min(1),
|
|
137731
|
-
marker: external_exports.string().min(1)
|
|
137732
|
-
});
|
|
137733
|
-
var RcListOutputSchema = external_exports.strictObject({ sessions: external_exports.readonly(external_exports.array(RcSessionSummarySchema)) });
|
|
137734
|
-
var RcStatusOutputSchema = external_exports.strictObject({ statuses: external_exports.readonly(external_exports.array(RcSessionStatusSchema)) });
|
|
137735
|
-
var RcPendingOutputSchema = external_exports.strictObject({ pending: external_exports.readonly(external_exports.array(RcPendingRequestSummarySchema)) });
|
|
137736
|
-
var RcWriteOutputSchema = external_exports.strictObject({
|
|
137737
|
-
session: external_exports.string(),
|
|
137738
|
-
sequenceNums: external_exports.readonly(external_exports.array(external_exports.number()))
|
|
137739
|
-
});
|
|
137740
|
-
var RcControlWriteOutputSchema = external_exports.strictObject({
|
|
137741
|
-
session: external_exports.string(),
|
|
137742
|
-
request: external_exports.string(),
|
|
137743
|
-
sequenceNums: external_exports.readonly(external_exports.array(external_exports.number()))
|
|
137744
|
-
});
|
|
137745
|
-
var RcAnswerOutputSchema = external_exports.strictObject({
|
|
137746
|
-
session: external_exports.string(),
|
|
137747
|
-
request: external_exports.string(),
|
|
137748
|
-
sequenceNums: external_exports.readonly(external_exports.array(external_exports.number()))
|
|
137749
|
-
});
|
|
137750
|
-
|
|
137751
|
-
// src/frontdoor/controlSchemas.ts
|
|
137752
138061
|
init_state();
|
|
137753
138062
|
var UsageListOutputSchema = external_exports.strictObject({ snapshots: external_exports.readonly(external_exports.array(UsageSnapshotSchema)) });
|
|
137754
138063
|
var UsageWindowsInputSchema = external_exports.strictObject({
|
|
@@ -140983,7 +141292,7 @@ init_zod();
|
|
|
140983
141292
|
var import_promises21 = require("node:timers/promises");
|
|
140984
141293
|
|
|
140985
141294
|
// src/supervise/sessionControl.ts
|
|
140986
|
-
var
|
|
141295
|
+
var import_node_crypto28 = require("node:crypto");
|
|
140987
141296
|
var import_node_fs27 = require("node:fs");
|
|
140988
141297
|
var import_node_path65 = __toESM(require("node:path"), 1);
|
|
140989
141298
|
var import_promises20 = require("node:timers/promises");
|
|
@@ -141002,7 +141311,7 @@ function sessionControlVersion(plugin) {
|
|
|
141002
141311
|
}
|
|
141003
141312
|
var REQUEST_INSTANT_DIGITS = String(Number.MAX_SAFE_INTEGER).length;
|
|
141004
141313
|
function requestIdOf(nowMs) {
|
|
141005
|
-
return `${String(nowMs).padStart(REQUEST_INSTANT_DIGITS, "0")}-${(0,
|
|
141314
|
+
return `${String(nowMs).padStart(REQUEST_INSTANT_DIGITS, "0")}-${(0, import_node_crypto28.randomUUID)()}`;
|
|
141006
141315
|
}
|
|
141007
141316
|
function removeOrphanResults(plugin) {
|
|
141008
141317
|
const results = (0, import_node_fs27.readdirSync)(plugin.results);
|
|
@@ -141119,26 +141428,26 @@ async function writeRcPersonMessage(deps, sessionId, text5) {
|
|
|
141119
141428
|
}
|
|
141120
141429
|
return result;
|
|
141121
141430
|
}
|
|
141122
|
-
function
|
|
141431
|
+
function isRecord14(value3) {
|
|
141123
141432
|
return typeof value3 === "object" && value3 !== null && !Array.isArray(value3);
|
|
141124
141433
|
}
|
|
141125
141434
|
function rcLocalCommandAnswerOf(event, command, args) {
|
|
141126
141435
|
const payload = event.envelope.payload;
|
|
141127
|
-
if (!
|
|
141436
|
+
if (!isRecord14(payload) || payload.type !== "assistant" || !isRecord14(payload.local_command_run) || payload.local_command_run.command !== command || payload.local_command_run.args !== args) {
|
|
141128
141437
|
return void 0;
|
|
141129
141438
|
}
|
|
141130
141439
|
const message = payload.message;
|
|
141131
|
-
if (!
|
|
141440
|
+
if (!isRecord14(message) || !Array.isArray(message.content)) {
|
|
141132
141441
|
return void 0;
|
|
141133
141442
|
}
|
|
141134
141443
|
const blocks = message.content;
|
|
141135
|
-
const text5 = blocks.flatMap((block2) =>
|
|
141136
|
-
const outcome =
|
|
141444
|
+
const text5 = blocks.flatMap((block2) => isRecord14(block2) && block2.type === "text" && typeof block2.text === "string" ? [block2.text] : []).join("\n");
|
|
141445
|
+
const outcome = isRecord14(payload.local_command_outcome) && typeof payload.local_command_outcome.kind === "string" ? payload.local_command_outcome.kind : void 0;
|
|
141137
141446
|
return { text: text5, outcome };
|
|
141138
141447
|
}
|
|
141139
141448
|
function rcManualCompactBoundaryOf(event) {
|
|
141140
141449
|
const payload = event.envelope.payload;
|
|
141141
|
-
if (!
|
|
141450
|
+
if (!isRecord14(payload) || payload.type !== "system" || payload.subtype !== "compact_boundary" || !isRecord14(payload.compact_metadata)) {
|
|
141142
141451
|
return void 0;
|
|
141143
141452
|
}
|
|
141144
141453
|
const metadata = payload.compact_metadata;
|
|
@@ -141149,7 +141458,7 @@ function rcManualCompactBoundaryOf(event) {
|
|
|
141149
141458
|
}
|
|
141150
141459
|
function isPeerDelivery(event, text5) {
|
|
141151
141460
|
const payload = event.envelope.payload;
|
|
141152
|
-
if (!
|
|
141461
|
+
if (!isRecord14(payload) || payload.type !== "user" || !isRecord14(payload.origin) || payload.origin.kind !== "peer" || !isRecord14(payload.message)) {
|
|
141153
141462
|
return false;
|
|
141154
141463
|
}
|
|
141155
141464
|
return typeof payload.message.content === "string" && payload.message.content.includes(text5);
|
|
@@ -141266,7 +141575,7 @@ function createRcClaudeCodeVersions(fanout) {
|
|
|
141266
141575
|
const versions = /* @__PURE__ */ new Map();
|
|
141267
141576
|
fanout.subscribe(void 0, (event) => {
|
|
141268
141577
|
const payload = event.envelope.payload;
|
|
141269
|
-
if (event.envelope.source === "worker" &&
|
|
141578
|
+
if (event.envelope.source === "worker" && isRecord14(payload) && payload.type === "system" && payload.subtype === "init" && typeof payload.claude_code_version === "string") {
|
|
141270
141579
|
versions.set(event.session, payload.claude_code_version);
|
|
141271
141580
|
}
|
|
141272
141581
|
});
|
|
@@ -141572,14 +141881,16 @@ function createRcApiRouter(deps) {
|
|
|
141572
141881
|
}),
|
|
141573
141882
|
pending: authed.meta(openapi({ method: "GET", path: "/rest/rc/pending", summary: "Read the control requests awaiting an answer", tags: [RC_API_TAG] })).input(RcSessionQuerySchema).output(RcPendingOutputSchema).handler(({ input: input2 }) => {
|
|
141574
141883
|
const pending = deps.pendingOf(input2.session);
|
|
141575
|
-
|
|
141884
|
+
const statuses = deps.statusOf(input2.session);
|
|
141885
|
+
if (input2.session !== void 0 && statuses.length === 0) {
|
|
141576
141886
|
throw new ORPCError("NOT_FOUND", { message: rcSessionNotObservedMessage(input2.session) });
|
|
141577
141887
|
}
|
|
141578
|
-
|
|
141888
|
+
const dropped = statuses.flatMap((status) => status.pendingDropped === void 0 ? [] : [{ sessionId: status.id, count: status.pendingDropped }]);
|
|
141889
|
+
return { pending, ...dropped.length === 0 ? {} : { dropped } };
|
|
141579
141890
|
}),
|
|
141580
141891
|
send: authed.meta(openapi({ method: "POST", path: "/rest/rc/send", summary: "Send one message into a session", tags: [RC_API_TAG] })).input(RcSendInputSchema).output(RcWriteOutputSchema).handler(async ({ input: input2 }) => ({ session: input2.session, sequenceNums: delivered(input2.session, await deps.inject(input2.session, input2.text)) })),
|
|
141581
|
-
answer: authed.meta(openapi({ method: "POST", path: "/rest/rc/answer", summary: "Answer one pending control request", tags: [RC_API_TAG] })).input(RcAnswerInputSchema).output(RcAnswerOutputSchema).handler(async ({ input: input2 }) => {
|
|
141582
|
-
const decision = { approve: input2.approve, message: input2.approve || input2.text === void 0 ? void 0 : input2.text };
|
|
141892
|
+
answer: authed.meta(openapi({ method: "POST", path: "/rest/rc/answer", summary: "Answer one pending control request: approve or deny it, or choose the options of a pending question", tags: [RC_API_TAG] })).input(RcAnswerInputSchema).output(RcAnswerOutputSchema).handler(async ({ input: input2 }) => {
|
|
141893
|
+
const decision = { approve: input2.approve, message: input2.approve || input2.text === void 0 ? void 0 : input2.text, ...input2.choices === void 0 ? {} : { choices: input2.choices } };
|
|
141583
141894
|
return { session: input2.session, request: input2.request, sequenceNums: delivered(input2.session, await deps.answer(input2.session, input2.request, decision)) };
|
|
141584
141895
|
}),
|
|
141585
141896
|
interrupt: authed.meta(openapi({ method: "POST", path: "/rest/rc/interrupt", summary: "Interrupt a session's running turn", tags: [RC_API_TAG] })).input(RcInterruptInputSchema).output(RcControlWriteOutputSchema).handler(async ({ input: input2 }) => ({ session: input2.session, ...deliveredControl(input2.session, await deps.interrupt(input2.session)) })),
|
|
@@ -142673,8 +142984,8 @@ function rcFanoutOnDoorHub(fanout, hub) {
|
|
|
142673
142984
|
|
|
142674
142985
|
// src/frontdoor/rcEventLog.ts
|
|
142675
142986
|
var RC_SESSION_EVENT_TOKEN_MAX_CHARS = 255;
|
|
142676
|
-
var
|
|
142677
|
-
var
|
|
142987
|
+
var HIGH_SURROGATE_FIRST2 = 55296;
|
|
142988
|
+
var HIGH_SURROGATE_LAST2 = 56319;
|
|
142678
142989
|
var LOW_SURROGATE_FIRST = 56320;
|
|
142679
142990
|
var LOW_SURROGATE_LAST = 57343;
|
|
142680
142991
|
var CUT_MARKER = "...";
|
|
@@ -142685,7 +142996,7 @@ var NUMBER_BYTES = Float64Array.BYTES_PER_ELEMENT;
|
|
|
142685
142996
|
var NUMBER_FIELDS = ["at", "sequence"].length;
|
|
142686
142997
|
var BYTES_PER_CODE_UNIT = Uint16Array.BYTES_PER_ELEMENT;
|
|
142687
142998
|
var RC_SESSION_END_REASONS = ["expired", "archived", "conflict"];
|
|
142688
|
-
var RC_PENDING_RETIRE_REASONS = ["answered", "
|
|
142999
|
+
var RC_PENDING_RETIRE_REASONS = ["answered", "withdrawn", "worker-stopped", "session-ended"];
|
|
142689
143000
|
var transitionBase = { session: external_exports.string(), at: external_exports.number() };
|
|
142690
143001
|
var cursorFields = { cursor: external_exports.string(), sequence: external_exports.int().positive() };
|
|
142691
143002
|
var sessionAppearedShape = { kind: external_exports.literal("session-appeared"), ...transitionBase };
|
|
@@ -142746,7 +143057,7 @@ function parseCursor(cursor3) {
|
|
|
142746
143057
|
function codePointBoundary(text5, at2) {
|
|
142747
143058
|
const before = text5.charCodeAt(at2 - 1);
|
|
142748
143059
|
const after = text5.charCodeAt(at2);
|
|
142749
|
-
const isHigh = before >=
|
|
143060
|
+
const isHigh = before >= HIGH_SURROGATE_FIRST2 && before <= HIGH_SURROGATE_LAST2;
|
|
142750
143061
|
const isLow = after >= LOW_SURROGATE_FIRST && after <= LOW_SURROGATE_LAST;
|
|
142751
143062
|
return isHigh && isLow ? at2 - 1 : at2;
|
|
142752
143063
|
}
|
|
@@ -143215,7 +143526,7 @@ init_connect();
|
|
|
143215
143526
|
init_route();
|
|
143216
143527
|
|
|
143217
143528
|
// src/frontdoor/lineage.ts
|
|
143218
|
-
var
|
|
143529
|
+
var import_node_crypto29 = require("node:crypto");
|
|
143219
143530
|
var CACHE_MARKER_KEY = '"cache_control"';
|
|
143220
143531
|
var THREAD_MEMBER_KEYS = /* @__PURE__ */ new Set(['"model"', '"system"', '"tools"']);
|
|
143221
143532
|
var MESSAGES_KEY = '"messages"';
|
|
@@ -143292,8 +143603,8 @@ function nextToken(body, from) {
|
|
|
143292
143603
|
return SCALAR;
|
|
143293
143604
|
}
|
|
143294
143605
|
function walk2(body, hashing, parentAfter) {
|
|
143295
|
-
const thread = (0,
|
|
143296
|
-
const messages = (0,
|
|
143606
|
+
const thread = (0, import_node_crypto29.createHash)("sha256");
|
|
143607
|
+
const messages = (0, import_node_crypto29.createHash)("sha256");
|
|
143297
143608
|
let parentDigest;
|
|
143298
143609
|
let elements = 0;
|
|
143299
143610
|
let depth = 0;
|
|
@@ -143414,7 +143725,7 @@ function lineageOf(body) {
|
|
|
143414
143725
|
}
|
|
143415
143726
|
const parentAfter = counted3.elements > MESSAGES_PER_TURN ? counted3.elements - MESSAGES_PER_TURN : void 0;
|
|
143416
143727
|
const hashed = walk2(body, true, parentAfter);
|
|
143417
|
-
const combine = (messagesDigest) => (0,
|
|
143728
|
+
const combine = (messagesDigest) => (0, import_node_crypto29.createHash)("sha256").update(hashed.threadDigest).update(messagesDigest).digest("hex");
|
|
143418
143729
|
return { ownKey: combine(hashed.messagesDigest), parentKey: hashed.parentDigest === void 0 ? void 0 : combine(hashed.parentDigest) };
|
|
143419
143730
|
}
|
|
143420
143731
|
|
|
@@ -144532,7 +144843,7 @@ function createCodexRouteMount(ports, upstreamBase, provider) {
|
|
|
144532
144843
|
}
|
|
144533
144844
|
|
|
144534
144845
|
// src/antigravity/route.ts
|
|
144535
|
-
var
|
|
144846
|
+
var import_node_crypto30 = require("node:crypto");
|
|
144536
144847
|
init_route();
|
|
144537
144848
|
init_anthropic();
|
|
144538
144849
|
|
|
@@ -144875,7 +145186,7 @@ var AcpStreamMessageSchema = external_exports.looseObject({
|
|
|
144875
145186
|
chunk: external_exports.looseObject({}).optional()
|
|
144876
145187
|
}).optional()
|
|
144877
145188
|
});
|
|
144878
|
-
function
|
|
145189
|
+
function isRecord15(value3) {
|
|
144879
145190
|
return typeof value3 === "object" && value3 !== null && !Array.isArray(value3);
|
|
144880
145191
|
}
|
|
144881
145192
|
function normalizeFinishReason(reason) {
|
|
@@ -144900,7 +145211,7 @@ function parseJsonRecord(raw) {
|
|
|
144900
145211
|
}
|
|
144901
145212
|
try {
|
|
144902
145213
|
const parsed = JSON.parse(raw);
|
|
144903
|
-
if (
|
|
145214
|
+
if (isRecord15(parsed)) {
|
|
144904
145215
|
return parsed;
|
|
144905
145216
|
}
|
|
144906
145217
|
} catch {
|
|
@@ -144996,7 +145307,7 @@ function exhaustedMessage(exhaustion) {
|
|
|
144996
145307
|
return `Antigravity ${window} limit reached; it resets at ${new Date(exhaustion.resetSec * MS_PER_SECOND13).toISOString()}.`;
|
|
144997
145308
|
}
|
|
144998
145309
|
function createAntigravityRoute(ports) {
|
|
144999
|
-
const fallbackId = ports.fallbackId ?? (() => (0,
|
|
145310
|
+
const fallbackId = ports.fallbackId ?? (() => (0, import_node_crypto30.randomUUID)());
|
|
145000
145311
|
const lastRouted = ports.lastRouted ?? /* @__PURE__ */ new Map();
|
|
145001
145312
|
const exhaustedModels = ports.exhaustedModels ?? /* @__PURE__ */ new Map();
|
|
145002
145313
|
const liveQuota = (nowMs) => {
|
|
@@ -146124,7 +146435,7 @@ function predecessorOfThisProcess() {
|
|
|
146124
146435
|
init_realFrontDoorPort();
|
|
146125
146436
|
|
|
146126
146437
|
// src/frontdoor/rcCommands.ts
|
|
146127
|
-
var
|
|
146438
|
+
var import_node_crypto31 = require("node:crypto");
|
|
146128
146439
|
init_commandDeps();
|
|
146129
146440
|
init_cliError();
|
|
146130
146441
|
init_realPorts();
|
|
@@ -146264,15 +146575,15 @@ function registerRcEventsCommand(rc, paths) {
|
|
|
146264
146575
|
|
|
146265
146576
|
// src/frontdoor/rcLiveUsage.ts
|
|
146266
146577
|
var RC_RATE_LIMIT_EVENT_TYPE = "rate_limit_event";
|
|
146267
|
-
function
|
|
146578
|
+
function isRecord16(value3) {
|
|
146268
146579
|
return typeof value3 === "object" && value3 !== null && !Array.isArray(value3);
|
|
146269
146580
|
}
|
|
146270
146581
|
function rcRateLimitInfoOf(event) {
|
|
146271
146582
|
const payload = event.envelope.payload;
|
|
146272
|
-
if (!
|
|
146583
|
+
if (!isRecord16(payload) || payload.type !== RC_RATE_LIMIT_EVENT_TYPE) {
|
|
146273
146584
|
return void 0;
|
|
146274
146585
|
}
|
|
146275
|
-
if (!
|
|
146586
|
+
if (!isRecord16(payload.rate_limit_info)) {
|
|
146276
146587
|
return void 0;
|
|
146277
146588
|
}
|
|
146278
146589
|
const parsed = RcRateLimitInfoSchema.safeParse(payload.rate_limit_info);
|
|
@@ -146309,7 +146620,7 @@ var RC_SELF_HOST_SCOPE_LIST = ["user:profile", "user:inference", "user:sessions:
|
|
|
146309
146620
|
var RC_SELF_HOST_OAUTH_TOKEN_TTL_SECONDS = 3600;
|
|
146310
146621
|
var MS_PER_SECOND14 = 1e3;
|
|
146311
146622
|
var HTTP_SERVICE_UNAVAILABLE = 503;
|
|
146312
|
-
function
|
|
146623
|
+
function isRecord17(value3) {
|
|
146313
146624
|
return typeof value3 === "object" && value3 !== null && !Array.isArray(value3);
|
|
146314
146625
|
}
|
|
146315
146626
|
function parseJsonObject2(body) {
|
|
@@ -146319,7 +146630,7 @@ function parseJsonObject2(body) {
|
|
|
146319
146630
|
} catch {
|
|
146320
146631
|
return void 0;
|
|
146321
146632
|
}
|
|
146322
|
-
return
|
|
146633
|
+
return isRecord17(parsed) ? parsed : void 0;
|
|
146323
146634
|
}
|
|
146324
146635
|
function growthBookFeatures() {
|
|
146325
146636
|
return {
|
|
@@ -146413,7 +146724,7 @@ var RC_SELF_HOST_RECORD_DIR = "rc-selfhost";
|
|
|
146413
146724
|
var RC_SELF_HOST_RECORD_FILE = "credential.json";
|
|
146414
146725
|
var SELF_HOST_EMAIL = "selfhost@agent-shim.invalid";
|
|
146415
146726
|
var SELF_HOST_SUBSCRIPTION_TYPE = "max";
|
|
146416
|
-
function
|
|
146727
|
+
function isRecord18(value3) {
|
|
146417
146728
|
return typeof value3 === "object" && value3 !== null && !Array.isArray(value3);
|
|
146418
146729
|
}
|
|
146419
146730
|
function readJsonObject(fs37, file2) {
|
|
@@ -146427,7 +146738,7 @@ function readJsonObject(fs37, file2) {
|
|
|
146427
146738
|
} catch {
|
|
146428
146739
|
return void 0;
|
|
146429
146740
|
}
|
|
146430
|
-
return
|
|
146741
|
+
return isRecord18(parsed) ? parsed : void 0;
|
|
146431
146742
|
}
|
|
146432
146743
|
function readRcSelfHostRecord(fs37, frontdoorDir) {
|
|
146433
146744
|
const parsed = readJsonObject(fs37, import_node_path69.default.join(frontdoorDir, RC_SELF_HOST_RECORD_DIR, RC_SELF_HOST_RECORD_FILE));
|
|
@@ -146455,7 +146766,7 @@ function mintRcSelfHostCredential(deps) {
|
|
|
146455
146766
|
const recordFile3 = import_node_path69.default.join(recordDir, RC_SELF_HOST_RECORD_FILE);
|
|
146456
146767
|
const previousRecord = readRcSelfHostRecord(deps.fs, deps.frontdoorDir);
|
|
146457
146768
|
const existingCredentials = readJsonObject(deps.fs, credentialsFile);
|
|
146458
|
-
const existingOauth =
|
|
146769
|
+
const existingOauth = isRecord18(existingCredentials?.claudeAiOauth) ? existingCredentials.claudeAiOauth : void 0;
|
|
146459
146770
|
const existingToken = typeof existingOauth?.accessToken === "string" && existingOauth.accessToken !== "" ? existingOauth.accessToken : void 0;
|
|
146460
146771
|
const existingIsOwn = existingToken !== void 0 && previousRecord?.accessToken === existingToken;
|
|
146461
146772
|
if (existingToken !== void 0 && !existingIsOwn && !deps.force) {
|
|
@@ -146472,7 +146783,7 @@ function mintRcSelfHostCredential(deps) {
|
|
|
146472
146783
|
deps.fs.writeFilePrivate(credentialsFile, `${JSON.stringify({ ...existingCredentials, claudeAiOauth: { accessToken, refreshToken, expiresAt: null, scopes: [...RC_SELF_HOST_SCOPE_LIST], subscriptionType: SELF_HOST_SUBSCRIPTION_TYPE, rateLimitTier: null } }, null, 2)}
|
|
146473
146784
|
`);
|
|
146474
146785
|
const claudeJson = readJsonObject(deps.fs, claudeJsonFile) ?? {};
|
|
146475
|
-
const existingBlock = (value3) =>
|
|
146786
|
+
const existingBlock = (value3) => isRecord18(value3) ? value3 : {};
|
|
146476
146787
|
deps.fs.writeFilePrivate(claudeJsonFile, `${JSON.stringify({
|
|
146477
146788
|
...claudeJson,
|
|
146478
146789
|
oauthAccount: {
|
|
@@ -146548,6 +146859,9 @@ function formatRcSessionStatus(statuses) {
|
|
|
146548
146859
|
lines.push(...formatRcPendingList([pending]).map((line) => ` ${line}`));
|
|
146549
146860
|
}
|
|
146550
146861
|
}
|
|
146862
|
+
if (status.pendingDropped !== void 0) {
|
|
146863
|
+
lines.push(` pending dropped: ${String(status.pendingDropped)} request(s) not listed (the per-session cap, or an id the protocol does not mint)`);
|
|
146864
|
+
}
|
|
146551
146865
|
}
|
|
146552
146866
|
return lines;
|
|
146553
146867
|
}
|
|
@@ -146555,10 +146869,50 @@ function formatRcPendingList(pending) {
|
|
|
146555
146869
|
if (pending.length === 0) {
|
|
146556
146870
|
return ["no pending control requests observed"];
|
|
146557
146871
|
}
|
|
146558
|
-
return pending.
|
|
146872
|
+
return pending.flatMap((request7) => {
|
|
146873
|
+
const observed = `observed ${new Date(request7.observedAt).toISOString()}`;
|
|
146874
|
+
if (request7.questions === void 0) {
|
|
146875
|
+
const mark = request7.unanswerable !== void 0 ? ` [a question the door cannot answer: ${request7.unanswerable}; answer it in the session]` : request7.oversized === true ? " [oversized: only this summary is held; answer it in the session]" : "";
|
|
146876
|
+
return [`${request7.sessionId} ${request7.requestId} ${request7.type}${request7.summary === "" ? "" : ` ${request7.summary}`} ${observed}${mark}`];
|
|
146877
|
+
}
|
|
146878
|
+
return [
|
|
146879
|
+
`${request7.sessionId} ${request7.requestId} question ${observed}`,
|
|
146880
|
+
...request7.questions.flatMap((question, index) => [
|
|
146881
|
+
` ${String(index + 1)}. ${question.header === void 0 ? "" : `[${question.header}] `}${question.question}${question.multiSelect ? " (choose one or more)" : " (choose one)"}`,
|
|
146882
|
+
...question.options.map((option, optionIndex) => ` ${String(optionIndex + 1)}) ${option.label}${option.description === void 0 ? "" : `: ${option.description}`}`)
|
|
146883
|
+
])
|
|
146884
|
+
];
|
|
146885
|
+
});
|
|
146886
|
+
}
|
|
146887
|
+
function formatRcDroppedPending(dropped) {
|
|
146888
|
+
return dropped.map((entry) => `${entry.sessionId} ${String(entry.count)} request(s) not listed: past the per-session cap of ${String(RC_PENDING_PER_SESSION_MAX)}, or an id the protocol does not mint; answer them in the session`);
|
|
146559
146889
|
}
|
|
146560
|
-
|
|
146561
|
-
|
|
146890
|
+
var CHOICE_FLAG_SEPARATOR = ":";
|
|
146891
|
+
var OPTION_NUMBER = /^\d+$/;
|
|
146892
|
+
function parseRcChoiceFlags(choose, other) {
|
|
146893
|
+
const byQuestion = /* @__PURE__ */ new Map();
|
|
146894
|
+
const entries = [...choose.map((value3) => ({ flag: "--choose", value: value3 })), ...other.map((value3) => ({ flag: "--other", value: value3 }))];
|
|
146895
|
+
for (const { flag, value: value3 } of entries) {
|
|
146896
|
+
const at2 = value3.indexOf(CHOICE_FLAG_SEPARATOR);
|
|
146897
|
+
const questionText = at2 === -1 ? "" : value3.slice(0, at2);
|
|
146898
|
+
const selectionText = at2 === -1 ? "" : value3.slice(at2 + 1);
|
|
146899
|
+
const question = Number(questionText);
|
|
146900
|
+
if (!OPTION_NUMBER.test(questionText) || question < 1 || selectionText === "") {
|
|
146901
|
+
return { error: `${flag} ${JSON.stringify(value3)} must be <question number>${CHOICE_FLAG_SEPARATOR}<${flag === "--choose" ? "option label or number" : "text"}>, with questions numbered from 1 as \`frontdoor rc pending\` lists them` };
|
|
146902
|
+
}
|
|
146903
|
+
const selection = flag === "--other" ? { text: selectionText } : OPTION_NUMBER.test(selectionText) ? Number(selectionText) : selectionText;
|
|
146904
|
+
byQuestion.set(question, [...byQuestion.get(question) ?? [], selection]);
|
|
146905
|
+
}
|
|
146906
|
+
const highest = Math.max(...byQuestion.keys());
|
|
146907
|
+
const choices = [];
|
|
146908
|
+
for (let question = 1; question <= highest; question += 1) {
|
|
146909
|
+
const selections = byQuestion.get(question);
|
|
146910
|
+
if (selections === void 0) {
|
|
146911
|
+
return { error: `question ${String(question)} has no --choose or --other, but question ${String(highest)} does: answer every question` };
|
|
146912
|
+
}
|
|
146913
|
+
choices.push(selections);
|
|
146914
|
+
}
|
|
146915
|
+
return { choices };
|
|
146562
146916
|
}
|
|
146563
146917
|
var PERCENT_SCALE = 100;
|
|
146564
146918
|
var MS_PER_SECOND15 = 1e3;
|
|
@@ -146607,7 +146961,7 @@ function formatRcRateLimitInfo(info) {
|
|
|
146607
146961
|
function formatRcStreamEvent(event) {
|
|
146608
146962
|
const { envelope: envelope2 } = event;
|
|
146609
146963
|
const rateLimit = rcRateLimitInfoOf(event);
|
|
146610
|
-
const sketch = rateLimit !== void 0 ? ` ${formatRcRateLimitInfo(rateLimit)}` : envelope2.payload === void 0 ? "" : ` ${
|
|
146964
|
+
const sketch = rateLimit !== void 0 ? ` ${formatRcRateLimitInfo(rateLimit)}` : envelope2.payload === void 0 ? "" : ` ${rcExcerpt(JSON.stringify(envelope2.payload))}`;
|
|
146611
146965
|
return `${event.session} ${envelope2.event_type} sequence_num ${String(envelope2.sequence_num)} source ${envelope2.source}${sketch}`;
|
|
146612
146966
|
}
|
|
146613
146967
|
function formatRcSelfHostMint(result) {
|
|
@@ -146660,12 +147014,14 @@ function registerRcCommand(frontdoor, paths) {
|
|
|
146660
147014
|
);
|
|
146661
147015
|
withExamples(
|
|
146662
147016
|
rc.command("pending").description("List the control requests (tool and plan approvals above all) the front door has observed and that are still awaiting an answer. Read-only.").argument("[session]", "One cse_ session id, as `frontdoor rc list` shows it; every observed session when omitted.").option("--json", "Print the pending requests as JSON.").action(async (session, options) => {
|
|
146663
|
-
const
|
|
147017
|
+
const control = frontDoorRcControlFromState(realFarmFs, paths);
|
|
147018
|
+
const pending = await control.pendingOf(session);
|
|
147019
|
+
const dropped = (await control.statusOf(session)).flatMap((status) => status.pendingDropped === void 0 ? [] : [{ sessionId: status.id, count: status.pendingDropped }]);
|
|
146664
147020
|
if (options.json === true) {
|
|
146665
|
-
printJson({ pending });
|
|
147021
|
+
printJson({ pending, ...dropped.length === 0 ? {} : { dropped } });
|
|
146666
147022
|
return;
|
|
146667
147023
|
}
|
|
146668
|
-
for (const line of formatRcPendingList(pending)) {
|
|
147024
|
+
for (const line of [...formatRcPendingList(pending), ...formatRcDroppedPending(dropped)]) {
|
|
146669
147025
|
console.log(line);
|
|
146670
147026
|
}
|
|
146671
147027
|
}),
|
|
@@ -146686,14 +147042,19 @@ function registerRcCommand(frontdoor, paths) {
|
|
|
146686
147042
|
['agent-shim frontdoor rc send --session cse_00000000-0000-4000-8000-000000000000 --text "run the tests"']
|
|
146687
147043
|
);
|
|
146688
147044
|
withExamples(
|
|
146689
|
-
rc.command("answer").description("Answer one pending control request on an observed session, approving or denying it as an attached client's approval would.").requiredOption("--session <id>", "The cse_ session id, as `frontdoor rc list` shows it.").requiredOption("--request <id>", "The control request's id, as `frontdoor rc pending` shows it.").option("--approve", "Approve the request.").option("--deny", "Deny the request.").option("--text <text>", "The denial message the worker sees; applies to --deny only.").option("--json", "Print the delivery result as JSON.").action(async (options) => {
|
|
146690
|
-
|
|
146691
|
-
|
|
147045
|
+
rc.command("answer").description("Answer one pending control request on an observed session, approving or denying it as an attached client's approval would, or answering a pending question by choosing its options (--choose and --other, which approve it; --deny dismisses it).").requiredOption("--session <id>", "The cse_ session id, as `frontdoor rc list` shows it.").requiredOption("--request <id>", "The control request's id, as `frontdoor rc pending` shows it.").option("--approve", "Approve the request.").option("--deny", "Deny the request.").option("--text <text>", "The denial message the worker sees; applies to --deny only.").option("--choose <question:option>", "Answer a pending question: choose an option of one question, naming the question by its number in `frontdoor rc pending` and the option by its label or number (repeat for each question, and for each option of a multi-select question).", collectRepeated, []).option("--other <question:text>", "Answer one question of a pending question with free text in place of an option.", collectRepeated, []).option("--json", "Print the delivery result as JSON.").action(async (options) => {
|
|
147046
|
+
const choosing = options.choose.length > 0 || options.other.length > 0;
|
|
147047
|
+
if ([options.approve === true, options.deny === true, choosing].filter(Boolean).length !== 1) {
|
|
147048
|
+
throw new UsageError("answer exactly one way: pass --approve, --deny, or the --choose and --other selections of a question");
|
|
146692
147049
|
}
|
|
146693
|
-
if (options.
|
|
147050
|
+
if (options.deny !== true && options.text !== void 0) {
|
|
146694
147051
|
throw new UsageError("--text is the denial message; an approval carries no text (the protocol's allow result has no message field)");
|
|
146695
147052
|
}
|
|
146696
|
-
const
|
|
147053
|
+
const choices = choosing ? parseRcChoiceFlags(options.choose, options.other) : void 0;
|
|
147054
|
+
if (choices !== void 0 && "error" in choices) {
|
|
147055
|
+
throw new UsageError(choices.error);
|
|
147056
|
+
}
|
|
147057
|
+
const result = await frontDoorRcControlFromState(realFarmFs, paths).answerRequest(options.session, options.request, { approve: options.deny !== true, message: options.deny === true ? options.text : void 0, ...choices === void 0 ? {} : { choices: choices.choices } });
|
|
146697
147058
|
if (!result.ok) {
|
|
146698
147059
|
throw new Error(result.message);
|
|
146699
147060
|
}
|
|
@@ -146701,11 +147062,13 @@ function registerRcCommand(frontdoor, paths) {
|
|
|
146701
147062
|
printJson({ session: options.session, request: options.request, sequenceNums: result.sequenceNums });
|
|
146702
147063
|
return;
|
|
146703
147064
|
}
|
|
146704
|
-
console.log(`${options.approve === true ? "approved" : "denied"} ${options.request} on ${options.session}: sequence_num ${result.sequenceNums.join(", ")}`);
|
|
147065
|
+
console.log(`${choosing ? "answered" : options.approve === true ? "approved" : "denied"} ${options.request} on ${options.session}: sequence_num ${result.sequenceNums.join(", ")}`);
|
|
146705
147066
|
}),
|
|
146706
147067
|
[
|
|
146707
147068
|
"agent-shim frontdoor rc answer --session cse_00000000-0000-4000-8000-000000000000 --request req_00000000-0000-4000-8000-000000000000 --approve",
|
|
146708
|
-
'agent-shim frontdoor rc answer --session cse_00000000-0000-4000-8000-000000000000 --request req_00000000-0000-4000-8000-000000000000 --deny --text "not today"'
|
|
147069
|
+
'agent-shim frontdoor rc answer --session cse_00000000-0000-4000-8000-000000000000 --request req_00000000-0000-4000-8000-000000000000 --deny --text "not today"',
|
|
147070
|
+
"agent-shim frontdoor rc answer --session cse_00000000-0000-4000-8000-000000000000 --request req_00000000-0000-4000-8000-000000000000 --choose 1:SQLite --choose 2:lint --choose 2:3",
|
|
147071
|
+
"agent-shim frontdoor rc answer --session cse_00000000-0000-4000-8000-000000000000 --request req_00000000-0000-4000-8000-000000000000 --choose 1:2 --other 2:fmt"
|
|
146709
147072
|
]
|
|
146710
147073
|
);
|
|
146711
147074
|
withExamples(
|
|
@@ -146911,8 +147274,8 @@ last check: ${answer.goal.lastCheck}`}`);
|
|
|
146911
147274
|
identitiesDir: paths.identitiesDir,
|
|
146912
147275
|
frontdoorDir: paths.frontdoorDir,
|
|
146913
147276
|
identity,
|
|
146914
|
-
newUuid:
|
|
146915
|
-
randomToken: () => (0,
|
|
147277
|
+
newUuid: import_node_crypto31.randomUUID,
|
|
147278
|
+
randomToken: () => (0, import_node_crypto31.randomBytes)(MINTED_TOKEN_RANDOM_BYTES).toString("base64url"),
|
|
146916
147279
|
force: options.force === true,
|
|
146917
147280
|
now: () => Date.now()
|
|
146918
147281
|
});
|
|
@@ -146933,11 +147296,11 @@ var import_node_path70 = __toESM(require("node:path"), 1);
|
|
|
146933
147296
|
function isSafeSessionId(sessionId) {
|
|
146934
147297
|
return /^[A-Za-z0-9_-]+$/.test(sessionId);
|
|
146935
147298
|
}
|
|
146936
|
-
function
|
|
147299
|
+
function isRecord19(value3) {
|
|
146937
147300
|
return typeof value3 === "object" && value3 !== null && !Array.isArray(value3);
|
|
146938
147301
|
}
|
|
146939
147302
|
function credentialOfJson(parsed) {
|
|
146940
|
-
if (!
|
|
147303
|
+
if (!isRecord19(parsed)) {
|
|
146941
147304
|
return void 0;
|
|
146942
147305
|
}
|
|
146943
147306
|
const { authorization, anthropicVersion, anthropicClientPlatform } = parsed;
|
|
@@ -146967,7 +147330,7 @@ function createRcCredentialStore(fs37, dir) {
|
|
|
146967
147330
|
} catch {
|
|
146968
147331
|
return void 0;
|
|
146969
147332
|
}
|
|
146970
|
-
return
|
|
147333
|
+
return isRecord19(parsed) ? parsed : void 0;
|
|
146971
147334
|
};
|
|
146972
147335
|
return {
|
|
146973
147336
|
read: (sessionId) => {
|
|
@@ -147206,41 +147569,114 @@ function selectSession(id) {
|
|
|
147206
147569
|
};
|
|
147207
147570
|
}
|
|
147208
147571
|
|
|
147209
|
-
|
|
147572
|
+
// The identity of one pending list as the page draws it: the request ids in order. The poll redraws the list only when this changes, so a half-made choice (a picked radio button, a typed message) survives every refresh of the same requests.
|
|
147573
|
+
function pendingKey(pending, dropped) {
|
|
147574
|
+
return pending.map(function (request) { return request.sessionId + '/' + request.requestId; }).concat(dropped.map(function (entry) { return entry.sessionId + '#' + String(entry.count); })).join(' ');
|
|
147575
|
+
}
|
|
147576
|
+
|
|
147577
|
+
// Turns what one question card holds into the answer's choices: per question, the picked labels in option order and the typed free text when there is any (the dialog's own "Type something" row), which joins the picks of a multi-select question and replaces the pick of a single-select one, since that takes one answer. Returns the choices, or the refusal naming the first question left without a selection.
|
|
147578
|
+
function answerChoices(picked, typed, multiSelect) {
|
|
147579
|
+
var choices = [];
|
|
147580
|
+
for (var q = 0; q < picked.length; q++) {
|
|
147581
|
+
var text = typed[q] === undefined ? '' : typed[q].trim();
|
|
147582
|
+
var chosen = text !== '' && multiSelect[q] !== true ? [] : picked[q].slice();
|
|
147583
|
+
if (text !== '') { chosen.push({ text: text }); }
|
|
147584
|
+
if (chosen.length === 0) { return { error: 'choose an option for question ' + String(q + 1) + ', or type an answer' }; }
|
|
147585
|
+
choices.push(chosen);
|
|
147586
|
+
}
|
|
147587
|
+
return { choices: choices };
|
|
147588
|
+
}
|
|
147589
|
+
|
|
147590
|
+
function renderPending(pending, dropped) {
|
|
147210
147591
|
if (ui === null) { return; }
|
|
147592
|
+
var key = pendingKey(pending, dropped);
|
|
147593
|
+
if (ui.pendingKey === key) { return; }
|
|
147594
|
+
ui.pendingKey = key;
|
|
147211
147595
|
var list = ui.pendingList;
|
|
147212
147596
|
list.textContent = '';
|
|
147213
|
-
|
|
147597
|
+
// A session whose requests the door did not list (past its cap) is said so first: a question the user expects may be among them, to be answered in the session itself.
|
|
147598
|
+
for (var d = 0; d < dropped.length; d++) {
|
|
147599
|
+
list.appendChild(el('div', 'event dim', shortId(dropped[d].sessionId) + ' ' + String(dropped[d].count) + ' request(s) not listed; answer them in the session'));
|
|
147600
|
+
}
|
|
147601
|
+
if (pending.length === 0 && dropped.length === 0) {
|
|
147214
147602
|
list.appendChild(el('div', 'event dim', 'no control requests awaiting an answer'));
|
|
147215
147603
|
return;
|
|
147216
147604
|
}
|
|
147217
147605
|
for (var i = 0; i < pending.length; i++) {
|
|
147218
147606
|
var request = pending[i];
|
|
147219
147607
|
var card = el('div', 'card');
|
|
147220
|
-
|
|
147608
|
+
var answerable = Array.isArray(request.questions);
|
|
147609
|
+
// A question the door lists without its questions (malformed, past a bound, or past the parse cap) carries its reason instead, and can only be dismissed here.
|
|
147610
|
+
var isQuestion = answerable || request.unanswerable !== undefined;
|
|
147611
|
+
card.appendChild(el('div', null, isQuestion ? 'question' : request.type + ' ' + (request.summary === '' ? shortId(request.requestId) : request.summary)));
|
|
147221
147612
|
card.appendChild(el('div', 'dim', shortId(request.sessionId) + ' ' + shortId(request.requestId) + ' observed ' + new Date(request.observedAt).toLocaleTimeString()));
|
|
147613
|
+
if (isQuestion && !answerable) {
|
|
147614
|
+
card.appendChild(el('div', 'dim', 'the door cannot answer this question (' + request.unanswerable + '); answer it in the session, or dismiss it'));
|
|
147615
|
+
}
|
|
147616
|
+
var pickers = answerable ? renderQuestions(card, request) : null;
|
|
147222
147617
|
var row = el('div', 'row');
|
|
147223
147618
|
var denial = el('input');
|
|
147224
147619
|
denial.type = 'text';
|
|
147225
|
-
denial.placeholder = 'denial message (optional)';
|
|
147226
|
-
var approve = el('button', null, 'Approve');
|
|
147227
|
-
var deny = el('button', 'secondary', 'Deny');
|
|
147228
|
-
approve.addEventListener('click', answerRequest(request, true, denial));
|
|
147229
|
-
deny.addEventListener('click', answerRequest(request, false, denial));
|
|
147620
|
+
denial.placeholder = isQuestion ? 'dismissal message (optional)' : 'denial message (optional)';
|
|
147621
|
+
var approve = el('button', null, isQuestion ? 'Answer' : 'Approve');
|
|
147622
|
+
var deny = el('button', 'secondary', isQuestion ? 'Dismiss' : 'Deny');
|
|
147623
|
+
approve.addEventListener('click', answerRequest(request, true, denial, pickers));
|
|
147624
|
+
deny.addEventListener('click', answerRequest(request, false, denial, null));
|
|
147230
147625
|
row.appendChild(denial);
|
|
147231
|
-
row.appendChild(approve);
|
|
147626
|
+
if (!isQuestion || answerable) { row.appendChild(approve); }
|
|
147232
147627
|
row.appendChild(deny);
|
|
147233
147628
|
card.appendChild(row);
|
|
147234
147629
|
list.appendChild(card);
|
|
147235
147630
|
}
|
|
147236
147631
|
}
|
|
147237
147632
|
|
|
147238
|
-
|
|
147633
|
+
// Draws each question of a pending question request with one input per option (radio buttons for a single-select question, checkboxes for a multi-select one) and a free-text box, and returns a reader of the answer's choices built by answerChoices.
|
|
147634
|
+
function renderQuestions(card, request) {
|
|
147635
|
+
var groups = [];
|
|
147636
|
+
for (var q = 0; q < request.questions.length; q++) {
|
|
147637
|
+
var question = request.questions[q];
|
|
147638
|
+
var block = el('div', 'question');
|
|
147639
|
+
block.appendChild(el('div', null, (question.header === undefined ? '' : '[' + question.header + '] ') + question.question + (question.multiSelect ? ' (choose one or more)' : '')));
|
|
147640
|
+
var inputs = [];
|
|
147641
|
+
for (var o = 0; o < question.options.length; o++) {
|
|
147642
|
+
var option = question.options[o];
|
|
147643
|
+
var label = el('label', 'option');
|
|
147644
|
+
var box = el('input');
|
|
147645
|
+
box.type = question.multiSelect ? 'checkbox' : 'radio';
|
|
147646
|
+
box.name = request.requestId + '-' + String(q);
|
|
147647
|
+
box.value = option.label;
|
|
147648
|
+
label.appendChild(box);
|
|
147649
|
+
label.appendChild(document.createTextNode(' ' + option.label + (option.description === undefined ? '' : ': ' + option.description)));
|
|
147650
|
+
block.appendChild(label);
|
|
147651
|
+
inputs.push(box);
|
|
147652
|
+
}
|
|
147653
|
+
var other = el('input');
|
|
147654
|
+
other.type = 'text';
|
|
147655
|
+
other.placeholder = question.multiSelect ? 'or add your own answer' : 'or type your own answer';
|
|
147656
|
+
block.appendChild(other);
|
|
147657
|
+
groups.push({ inputs: inputs, other: other });
|
|
147658
|
+
card.appendChild(block);
|
|
147659
|
+
}
|
|
147660
|
+
return function () {
|
|
147661
|
+
return answerChoices(
|
|
147662
|
+
groups.map(function (group) { return group.inputs.filter(function (box) { return box.checked; }).map(function (box) { return box.value; }); }),
|
|
147663
|
+
groups.map(function (group) { return group.other.value; }),
|
|
147664
|
+
request.questions.map(function (question) { return question.multiSelect === true; })
|
|
147665
|
+
);
|
|
147666
|
+
};
|
|
147667
|
+
}
|
|
147668
|
+
|
|
147669
|
+
function answerRequest(request, approve, denialInput, pickers) {
|
|
147239
147670
|
return function () {
|
|
147240
147671
|
var input = { session: request.sessionId, request: request.requestId, approve: approve };
|
|
147241
147672
|
if (!approve && denialInput.value !== '') { input.text = denialInput.value; }
|
|
147673
|
+
if (approve && pickers !== null) {
|
|
147674
|
+
var built = pickers();
|
|
147675
|
+
if (built.error !== undefined) { window.alert(built.error); return; }
|
|
147676
|
+
input.choices = built.choices;
|
|
147677
|
+
}
|
|
147242
147678
|
rpc('rc/answer', input).then(function () {
|
|
147243
|
-
renderEvent({ source: 'page', sequence: 0, payload: { note: (approve ? 'approved' : 'denied') + ' ' + request.requestId } }, 0);
|
|
147679
|
+
renderEvent({ source: 'page', sequence: 0, payload: { note: (pickers !== null ? 'answered' : approve ? 'approved' : 'denied') + ' ' + request.requestId } }, 0);
|
|
147244
147680
|
refreshPending();
|
|
147245
147681
|
}, function (error) { window.alert('answer failed: ' + error.message); });
|
|
147246
147682
|
};
|
|
@@ -147262,7 +147698,7 @@ function refreshSessions() {
|
|
|
147262
147698
|
}
|
|
147263
147699
|
|
|
147264
147700
|
function refreshPending() {
|
|
147265
|
-
rpc('rc/pending', ui !== null && ui.selected !== null ? { session: ui.selected } : {}).then(function (result) { renderPending(result.pending); }, authOrReport('rc/pending'));
|
|
147701
|
+
rpc('rc/pending', ui !== null && ui.selected !== null ? { session: ui.selected } : {}).then(function (result) { renderPending(result.pending, result.dropped === undefined ? [] : result.dropped); }, authOrReport('rc/pending'));
|
|
147266
147702
|
}
|
|
147267
147703
|
|
|
147268
147704
|
// The header's quota span, fed by the door's live read on the same refresh cycle as the session and pending lists: the freshest rate-limit observation any session's stream has filed, with its observation time so its freshness reads at a glance.
|
|
@@ -147442,6 +147878,8 @@ var RC_CLIENT_PAGE_HTML = `<!doctype html>
|
|
|
147442
147878
|
.row { display: flex; gap: 8px; margin: 6px 0; align-items: center; }
|
|
147443
147879
|
.card { border: 1px solid #3d6ea5; border-radius: 4px; padding: 8px; margin: 6px 0; background: #17222e; }
|
|
147444
147880
|
.card .dim { color: #8b98a5; }
|
|
147881
|
+
.card .question { margin: 6px 0; }
|
|
147882
|
+
.card .option { display: block; margin-left: 12px; }
|
|
147445
147883
|
#token-form { max-width: 480px; margin: 48px auto; }
|
|
147446
147884
|
#token-form p { color: #8b98a5; }
|
|
147447
147885
|
.hidden { display: none !important; }
|
|
@@ -147541,7 +147979,7 @@ function withClientPlatform(payload, headers) {
|
|
|
147541
147979
|
const platform = headers[CLIENT_PLATFORM_HEADER];
|
|
147542
147980
|
return typeof platform === "string" && platform !== "" ? { ...rest, client_platform: platform } : rest;
|
|
147543
147981
|
}
|
|
147544
|
-
function
|
|
147982
|
+
function isRecord20(value3) {
|
|
147545
147983
|
return typeof value3 === "object" && value3 !== null && !Array.isArray(value3);
|
|
147546
147984
|
}
|
|
147547
147985
|
function parseJsonObject3(body) {
|
|
@@ -147551,7 +147989,7 @@ function parseJsonObject3(body) {
|
|
|
147551
147989
|
} catch {
|
|
147552
147990
|
return void 0;
|
|
147553
147991
|
}
|
|
147554
|
-
return
|
|
147992
|
+
return isRecord20(parsed) ? parsed : void 0;
|
|
147555
147993
|
}
|
|
147556
147994
|
function nonEmptyString2(record3, field) {
|
|
147557
147995
|
const value3 = record3 === void 0 ? void 0 : record3[field];
|
|
@@ -147625,7 +148063,7 @@ async function serveRcClientChannels(ctx, tail, method, maxBatchEvents) {
|
|
|
147625
148063
|
}
|
|
147626
148064
|
const results = [];
|
|
147627
148065
|
for (const event of events) {
|
|
147628
|
-
if (!
|
|
148066
|
+
if (!isRecord20(event) || !isRecord20(event.payload)) {
|
|
147629
148067
|
await ctx.answerJson(response, HTTP_STATUS.badRequest, { type: "error", error: { type: "invalid_request_error", message: "every event in a teleport write is an object carrying one payload object" } });
|
|
147630
148068
|
return true;
|
|
147631
148069
|
}
|
|
@@ -147725,7 +148163,7 @@ async function serveRcCompatSessions(ctx, pathname, compatPath) {
|
|
|
147725
148163
|
// src/frontdoor/rcSelfHostConversations.ts
|
|
147726
148164
|
var RC_CONVERSATIONS_PATH_PREFIX = "/v1/code/conversations";
|
|
147727
148165
|
var RC_CONVERSATION_ID_PREFIX = "conv_";
|
|
147728
|
-
function
|
|
148166
|
+
function isRecord21(value3) {
|
|
147729
148167
|
return typeof value3 === "object" && value3 !== null && !Array.isArray(value3);
|
|
147730
148168
|
}
|
|
147731
148169
|
function parseJsonObject4(body) {
|
|
@@ -147735,7 +148173,7 @@ function parseJsonObject4(body) {
|
|
|
147735
148173
|
} catch {
|
|
147736
148174
|
return void 0;
|
|
147737
148175
|
}
|
|
147738
|
-
return
|
|
148176
|
+
return isRecord21(parsed) ? parsed : void 0;
|
|
147739
148177
|
}
|
|
147740
148178
|
function nonEmptyString3(record3, field) {
|
|
147741
148179
|
const value3 = record3 === void 0 ? void 0 : record3[field];
|
|
@@ -147789,7 +148227,7 @@ async function serveRcConversations(ctx, pathname, method) {
|
|
|
147789
148227
|
}
|
|
147790
148228
|
const results = [];
|
|
147791
148229
|
for (const event of events) {
|
|
147792
|
-
if (!
|
|
148230
|
+
if (!isRecord21(event) || !isRecord21(event.payload)) {
|
|
147793
148231
|
await ctx.answerJson(response, HTTP_STATUS.badRequest, { type: "error", error: { type: "invalid_request_error", message: "every event in a write is an object carrying one payload object" } });
|
|
147794
148232
|
return;
|
|
147795
148233
|
}
|
|
@@ -148082,7 +148520,7 @@ var RC_SELF_HOST_WORKER_EPOCH = 1;
|
|
|
148082
148520
|
var RC_STREAM_EVENT_NAME = "client_event";
|
|
148083
148521
|
var CONFLICT_REASON_HEADER2 = "x-ccr-conflict-reason";
|
|
148084
148522
|
var CONFLICT_REASON_EPOCH_STALE = "epoch_stale";
|
|
148085
|
-
function
|
|
148523
|
+
function isRecord22(value3) {
|
|
148086
148524
|
return typeof value3 === "object" && value3 !== null && !Array.isArray(value3);
|
|
148087
148525
|
}
|
|
148088
148526
|
function isWebSearchRefusal(value3) {
|
|
@@ -148166,7 +148604,7 @@ function parseJsonObject5(body) {
|
|
|
148166
148604
|
} catch {
|
|
148167
148605
|
return void 0;
|
|
148168
148606
|
}
|
|
148169
|
-
return
|
|
148607
|
+
return isRecord22(parsed) ? parsed : void 0;
|
|
148170
148608
|
}
|
|
148171
148609
|
function mintWorkerJwt(randomToken, issuedAt) {
|
|
148172
148610
|
const encode3 = (value3) => Buffer.from(JSON.stringify(value3), "utf8").toString("base64url");
|
|
@@ -148426,7 +148864,7 @@ data: ${JSON.stringify(envelope2)}
|
|
|
148426
148864
|
if (status !== void 0) {
|
|
148427
148865
|
session.workerStatus = status;
|
|
148428
148866
|
}
|
|
148429
|
-
if (
|
|
148867
|
+
if (isRecord22(body?.external_metadata)) {
|
|
148430
148868
|
session.externalMetadata = body.external_metadata;
|
|
148431
148869
|
}
|
|
148432
148870
|
await answerJson2(response, HTTP_STATUS.ok, {});
|
|
@@ -148456,7 +148894,7 @@ data: ${JSON.stringify(envelope2)}
|
|
|
148456
148894
|
}
|
|
148457
148895
|
const results = [];
|
|
148458
148896
|
for (const event of events) {
|
|
148459
|
-
if (!
|
|
148897
|
+
if (!isRecord22(event) || !isRecord22(event.payload)) {
|
|
148460
148898
|
await answerJson2(response, HTTP_STATUS.badRequest, { type: "error", error: { type: "invalid_request_error", message: "every event in a batch is an object carrying one payload object" } });
|
|
148461
148899
|
return;
|
|
148462
148900
|
}
|
|
@@ -148489,7 +148927,7 @@ data: ${JSON.stringify(envelope2)}
|
|
|
148489
148927
|
return;
|
|
148490
148928
|
}
|
|
148491
148929
|
for (const event of events) {
|
|
148492
|
-
if (
|
|
148930
|
+
if (isRecord22(event)) {
|
|
148493
148931
|
session.internalEvents.push({ eventId: deps.newUuid(), body: event });
|
|
148494
148932
|
}
|
|
148495
148933
|
}
|
|
@@ -148585,7 +149023,7 @@ data: ${JSON.stringify(envelope2)}
|
|
|
148585
149023
|
}
|
|
148586
149024
|
const results = [];
|
|
148587
149025
|
for (const event of events) {
|
|
148588
|
-
if (!
|
|
149026
|
+
if (!isRecord22(event) || !isRecord22(event.payload)) {
|
|
148589
149027
|
await answerJson2(response, HTTP_STATUS.badRequest, { type: "error", error: { type: "invalid_request_error", message: "every event in a write is an object carrying one payload object" } });
|
|
148590
149028
|
return;
|
|
148591
149029
|
}
|
|
@@ -148869,7 +149307,7 @@ init_realPorts();
|
|
|
148869
149307
|
var import_promises22 = require("node:fs/promises");
|
|
148870
149308
|
|
|
148871
149309
|
// src/supervise/sessionGoal.ts
|
|
148872
|
-
function
|
|
149310
|
+
function isRecord23(value3) {
|
|
148873
149311
|
return typeof value3 === "object" && value3 !== null && !Array.isArray(value3);
|
|
148874
149312
|
}
|
|
148875
149313
|
function goalStatusOf(line) {
|
|
@@ -148882,7 +149320,7 @@ function goalStatusOf(line) {
|
|
|
148882
149320
|
} catch {
|
|
148883
149321
|
return void 0;
|
|
148884
149322
|
}
|
|
148885
|
-
if (!
|
|
149323
|
+
if (!isRecord23(row) || row.type !== "attachment" || !isRecord23(row.attachment) || row.attachment.type !== "goal_status" || typeof row.attachment.condition !== "string") {
|
|
148886
149324
|
return void 0;
|
|
148887
149325
|
}
|
|
148888
149326
|
return row.attachment;
|
|
@@ -149197,7 +149635,7 @@ function createSseParser() {
|
|
|
149197
149635
|
}
|
|
149198
149636
|
};
|
|
149199
149637
|
}
|
|
149200
|
-
function
|
|
149638
|
+
function isRecord24(value3) {
|
|
149201
149639
|
return typeof value3 === "object" && value3 !== null && !Array.isArray(value3);
|
|
149202
149640
|
}
|
|
149203
149641
|
function sequenceNumOf(value3) {
|
|
@@ -149219,7 +149657,7 @@ function parseRcStreamEnvelope(parsed) {
|
|
|
149219
149657
|
} catch {
|
|
149220
149658
|
return void 0;
|
|
149221
149659
|
}
|
|
149222
|
-
if (!
|
|
149660
|
+
if (!isRecord24(data)) {
|
|
149223
149661
|
return void 0;
|
|
149224
149662
|
}
|
|
149225
149663
|
const eventType = data.event_type;
|
|
@@ -149911,7 +150349,7 @@ function inheritedControlToken(paths) {
|
|
|
149911
150349
|
return token;
|
|
149912
150350
|
}
|
|
149913
150351
|
function realFrontDoorSupervisorPorts(paths, respawnGeneration, lifecycle, trackTunnels) {
|
|
149914
|
-
const catalogueGeneration = (0,
|
|
150352
|
+
const catalogueGeneration = (0, import_node_crypto32.randomUUID)();
|
|
149915
150353
|
const log = (line) => {
|
|
149916
150354
|
appendDoorLog(paths, `frontdoor ${String(process.pid)}: ${line}`);
|
|
149917
150355
|
};
|
|
@@ -149944,14 +150382,14 @@ function realFrontDoorSupervisorPorts(paths, respawnGeneration, lifecycle, track
|
|
|
149944
150382
|
};
|
|
149945
150383
|
const rcSelfHostSurface = rcSelfHost ? createRcSelfHostSurface({
|
|
149946
150384
|
now: () => Date.now(),
|
|
149947
|
-
newUuid:
|
|
149948
|
-
randomToken: () => (0,
|
|
150385
|
+
newUuid: import_node_crypto32.randomUUID,
|
|
150386
|
+
randomToken: () => (0, import_node_crypto32.randomBytes)(MINTED_TOKEN_RANDOM_BYTES).toString("base64url"),
|
|
149949
150387
|
credentialRecord: () => readRcSelfHostRecord(realFarmFs, paths.frontdoorDir),
|
|
149950
150388
|
webFetch: realRcWebFetch({ allowPrivate: rcWebFetchAllowsPrivateFromEnv(process.env) }),
|
|
149951
150389
|
log
|
|
149952
150390
|
}) : void 0;
|
|
149953
150391
|
const rcCredentialStore = createRcCredentialStore(realFarmFs, paths.frontdoorRcCredentialsDir);
|
|
149954
|
-
const rcSessionEvents = createRcSessionEventLog({ generation: (0,
|
|
150392
|
+
const rcSessionEvents = createRcSessionEventLog({ generation: (0, import_node_crypto32.randomUUID)(), capacity: RC_SESSION_EVENT_LOG_CAPACITY });
|
|
149955
150393
|
const rcTracker = createRcSessionTracker({ now: () => Date.now(), idleMs: RC_IDLE_EXPIRY_MS, credentialStore: rcCredentialStore, onTransition: rcSessionEvents.append, onClose: rcSessionEvents.close });
|
|
149956
150394
|
const doorEvents = createDoorEventHub();
|
|
149957
150395
|
const usagePublisher = doorEvents.publisher(USAGE_EVENT_SOURCE);
|
|
@@ -149979,7 +150417,7 @@ function realFrontDoorSupervisorPorts(paths, respawnGeneration, lifecycle, track
|
|
|
149979
150417
|
saveSequenceNum: rcCredentialStore.writeCursor,
|
|
149980
150418
|
dial: rcSelfHost ? lateRcStreamDial(rcSelfHostDialTarget) : realRcStreamDial(),
|
|
149981
150419
|
fanout: rcFanout,
|
|
149982
|
-
newClientId:
|
|
150420
|
+
newClientId: import_node_crypto32.randomUUID,
|
|
149983
150421
|
backoffMs: RC_STREAM_BACKOFF_MS,
|
|
149984
150422
|
sleep: async (ms) => {
|
|
149985
150423
|
await new Promise((resolve3) => {
|
|
@@ -149992,7 +150430,7 @@ function realFrontDoorSupervisorPorts(paths, respawnGeneration, lifecycle, track
|
|
|
149992
150430
|
});
|
|
149993
150431
|
const observations = createTargetObservationStore(realFarmFs, paths);
|
|
149994
150432
|
const routingSnapshots = /* @__PURE__ */ new Map();
|
|
149995
|
-
const rcControlToken = lifecycle.predecessor === void 0 ? (0,
|
|
150433
|
+
const rcControlToken = lifecycle.predecessor === void 0 ? (0, import_node_crypto32.randomUUID)() : inheritedControlToken(paths);
|
|
149996
150434
|
const sessionRegistry = createLiveSessionRegistry({ fs: realFarmFs, sessionsDir: paths.frontdoorSessionsDir });
|
|
149997
150435
|
const resolveRoute = rcObservingResolver(
|
|
149998
150436
|
createProviderRouteResolver({
|
|
@@ -150170,9 +150608,9 @@ function realFrontDoorSupervisorPorts(paths, respawnGeneration, lifecycle, track
|
|
|
150170
150608
|
now: () => Date.now(),
|
|
150171
150609
|
headroomSocket: () => headroomSocketTarget(realFarmFs, realHeadroomSocketTrust, paths),
|
|
150172
150610
|
// The per-generation capability the direct listener demands: held only in this process's memory, so a loopback process that discovers the direct port still cannot use it.
|
|
150173
|
-
hopSecret: (0,
|
|
150611
|
+
hopSecret: (0, import_node_crypto32.randomUUID)(),
|
|
150174
150612
|
headroomDecision,
|
|
150175
|
-
custody: createCredentialCustody(() => (0,
|
|
150613
|
+
custody: createCredentialCustody(() => (0, import_node_crypto32.randomUUID)()),
|
|
150176
150614
|
log
|
|
150177
150615
|
});
|
|
150178
150616
|
const onListenerError = (name) => (error63) => {
|
|
@@ -150199,9 +150637,9 @@ function realFrontDoorSupervisorPorts(paths, respawnGeneration, lifecycle, track
|
|
|
150199
150637
|
startProviderListener: async (source) => {
|
|
150200
150638
|
const authority = loadCa();
|
|
150201
150639
|
const rcDial = rcSelfHost ? lateRcEventDial(rcSelfHostDialTarget) : realRcEventDial();
|
|
150202
|
-
const rcInject = async (sessionId, text5) => await injectRcUserMessage({ credentialOf: rcTracker.credentialOf, noteSequenceNums: rcTracker.noteSequenceNums, dial: rcDial, newUuid:
|
|
150203
|
-
const rcAnswer = async (sessionId, requestId, decision) => await answerRcControlRequest({ credentialOf: rcTracker.credentialOf, pendingOf: (id2) => rcTracker.pendingOf(id2), completePending: rcTracker.completePending, noteSequenceNums: rcTracker.noteSequenceNums, dial: rcDial }, sessionId, requestId, decision);
|
|
150204
|
-
const rcControlRequestDeps = { credentialOf: rcTracker.credentialOf, noteSequenceNums: rcTracker.noteSequenceNums, dial: rcDial, newUuid:
|
|
150640
|
+
const rcInject = async (sessionId, text5) => await injectRcUserMessage({ credentialOf: rcTracker.credentialOf, noteSequenceNums: rcTracker.noteSequenceNums, dial: rcDial, newUuid: import_node_crypto32.randomUUID }, sessionId, text5);
|
|
150641
|
+
const rcAnswer = async (sessionId, requestId, decision) => await answerRcControlRequest({ credentialOf: rcTracker.credentialOf, pendingOf: (id2) => rcTracker.pendingOf(id2), completePending: rcTracker.completePending, pendingToolInputOf: rcTracker.pendingToolInputOf, claimPending: rcTracker.claimPending, noteSequenceNums: rcTracker.noteSequenceNums, dial: rcDial }, sessionId, requestId, decision);
|
|
150642
|
+
const rcControlRequestDeps = { credentialOf: rcTracker.credentialOf, noteSequenceNums: rcTracker.noteSequenceNums, dial: rcDial, newUuid: import_node_crypto32.randomUUID };
|
|
150205
150643
|
const rcInterrupt = async (sessionId) => await interruptRcSession(rcControlRequestDeps, sessionId);
|
|
150206
150644
|
const rcSetModel = async (sessionId, model) => await setRcSessionModel(rcControlRequestDeps, sessionId, model);
|
|
150207
150645
|
const rcSetPermissionMode = async (sessionId, mode) => await setRcSessionPermissionMode(rcControlRequestDeps, sessionId, mode);
|
|
@@ -150220,7 +150658,7 @@ function realFrontDoorSupervisorPorts(paths, respawnGeneration, lifecycle, track
|
|
|
150220
150658
|
paths,
|
|
150221
150659
|
isTracked: (sessionId) => rcTracker.statusOf(sessionId).length > 0,
|
|
150222
150660
|
selfHost: rcSelfHost ? {
|
|
150223
|
-
personWrite: { credentialOf: rcTracker.credentialOf, noteSequenceNums: rcTracker.noteSequenceNums, newUuid:
|
|
150661
|
+
personWrite: { credentialOf: rcTracker.credentialOf, noteSequenceNums: rcTracker.noteSequenceNums, newUuid: import_node_crypto32.randomUUID, dial: rcSelfHostEventDial(rcSelfHostDialTarget) },
|
|
150224
150662
|
unavailable: () => rcSelfHostDialTarget() === void 0 ? selfHostSurfaceUnboundReason(process.env.AGENT_SHIM_TRANSPARENT_SURFACE) : void 0,
|
|
150225
150663
|
fanout: rcFanout,
|
|
150226
150664
|
versions: rcClaudeCodeVersions
|
|
@@ -150324,7 +150762,7 @@ function realFrontDoorSupervisorPorts(paths, respawnGeneration, lifecycle, track
|
|
|
150324
150762
|
},
|
|
150325
150763
|
startConnectListener: async (source) => {
|
|
150326
150764
|
const wantedTransparentPort = process.env.AGENT_SHIM_TRANSPARENT_SURFACE === void 0 ? void 0 : Number(process.env.AGENT_SHIM_TRANSPARENT_SURFACE);
|
|
150327
|
-
const transparentCapability = wantedTransparentPort === void 0 || Number.isNaN(wantedTransparentPort) ? void 0 : (0,
|
|
150765
|
+
const transparentCapability = wantedTransparentPort === void 0 || Number.isNaN(wantedTransparentPort) ? void 0 : (0, import_node_crypto32.randomUUID)();
|
|
150328
150766
|
if (transparentCapability !== void 0) {
|
|
150329
150767
|
writeFrontDoorSession(realFarmFs, paths.frontdoorSessionsDir, { pid: process.pid, startedAt: Date.now(), token: transparentCapability });
|
|
150330
150768
|
}
|
|
@@ -151916,14 +152354,14 @@ init_zod();
|
|
|
151916
152354
|
init_schema2();
|
|
151917
152355
|
|
|
151918
152356
|
// src/statusline/cacheFile.ts
|
|
151919
|
-
var
|
|
152357
|
+
var import_node_crypto33 = require("node:crypto");
|
|
151920
152358
|
var import_node_path76 = __toESM(require("node:path"), 1);
|
|
151921
152359
|
var SESSION_CACHE_DIRECTORY = "session";
|
|
151922
152360
|
function cacheDirectory(ports) {
|
|
151923
152361
|
return import_node_path76.default.join(ports.stateDirectory, SESSION_CACHE_DIRECTORY);
|
|
151924
152362
|
}
|
|
151925
152363
|
function cacheFileFor(ports, kind, transcriptPath) {
|
|
151926
|
-
return import_node_path76.default.join(cacheDirectory(ports), `${kind}-${(0,
|
|
152364
|
+
return import_node_path76.default.join(cacheDirectory(ports), `${kind}-${(0, import_node_crypto33.createHash)("sha256").update(transcriptPath).digest("hex")}.json`);
|
|
151927
152365
|
}
|
|
151928
152366
|
function transcriptKeyOf(ports, transcriptPath) {
|
|
151929
152367
|
const trimmed = transcriptPath.trim();
|
|
@@ -154223,11 +154661,11 @@ function compactUnits(rows, barCells) {
|
|
|
154223
154661
|
}
|
|
154224
154662
|
|
|
154225
154663
|
// src/statusline/transcript/reader.ts
|
|
154226
|
-
var
|
|
154664
|
+
var import_node_crypto35 = require("node:crypto");
|
|
154227
154665
|
init_zod();
|
|
154228
154666
|
|
|
154229
154667
|
// src/statusline/transcript/activity.ts
|
|
154230
|
-
var
|
|
154668
|
+
var import_node_crypto34 = require("node:crypto");
|
|
154231
154669
|
init_zod();
|
|
154232
154670
|
init_graphemes();
|
|
154233
154671
|
|
|
@@ -154547,7 +154985,7 @@ function foldTodoCall(state, call2) {
|
|
|
154547
154985
|
return { ...state, todos: state.todos.map((item, at2) => at2 === index ? updated : item), todosEdited: true };
|
|
154548
154986
|
}
|
|
154549
154987
|
function digestOf(id2) {
|
|
154550
|
-
return (0,
|
|
154988
|
+
return (0, import_node_crypto34.createHash)("sha256").update(id2).digest("base64url").slice(0, CALL_DIGEST_CHARS);
|
|
154551
154989
|
}
|
|
154552
154990
|
function timeKeyOf(atMs) {
|
|
154553
154991
|
const key = atMs === void 0 || atMs < 0 ? "" : atMs.toString(CALL_TIME_RADIX);
|
|
@@ -154954,7 +155392,7 @@ function foldLines(state, bytes) {
|
|
|
154954
155392
|
}
|
|
154955
155393
|
function fingerprintOf(head) {
|
|
154956
155394
|
const newline = head.subarray(0, FINGERPRINT_BYTES).indexOf(NEWLINE3);
|
|
154957
|
-
return (0,
|
|
155395
|
+
return (0, import_node_crypto35.createHash)("sha256").update(head.subarray(0, newline === -1 ? FINGERPRINT_BYTES : newline + 1)).digest("hex");
|
|
154958
155396
|
}
|
|
154959
155397
|
function factsOf(size, cache, reachedEnd, nowMs, env) {
|
|
154960
155398
|
return { bytes: size, complete: cache.complete && reachedEnd, session: sessionFactsOf(cache.session, cache.newer?.state), tokens: cache.tokens.totals, activity: activityFactsOf(cache.activity, nowMs, { bashMs: bashLiveLimitMs(env) }, cache.newer?.activity) };
|
|
@@ -167704,7 +168142,7 @@ function registerRuleCommand(program2, deps) {
|
|
|
167704
168142
|
}
|
|
167705
168143
|
|
|
167706
168144
|
// src/codex/launch.ts
|
|
167707
|
-
var
|
|
168145
|
+
var import_node_crypto36 = require("node:crypto");
|
|
167708
168146
|
var import_node_fs39 = __toESM(require("node:fs"), 1);
|
|
167709
168147
|
var import_node_os24 = __toESM(require("node:os"), 1);
|
|
167710
168148
|
var import_node_path93 = __toESM(require("node:path"), 1);
|
|
@@ -167908,7 +168346,7 @@ async function runCodex(paths, argv) {
|
|
|
167908
168346
|
}
|
|
167909
168347
|
throw new UsageError("No real Codex CLI found on PATH. Install Codex or set AGENT_SHIM_CODEX_BIN to its executable.");
|
|
167910
168348
|
};
|
|
167911
|
-
const plan = prepareCodexLaunch({ paths, argv, env: process.env, cwd: import_node_fs39.default.realpathSync(process.cwd()), home: import_node_os24.default.homedir(), fs: realFarmFs, read: cosmiconfigReader(), resolveBinary, now: Date.now, pid: process.pid, isRunning: realIsProcessRunning, sleep: realSleepSync, uniqueSuffix: `${String(process.pid)}.${(0,
|
|
168349
|
+
const plan = prepareCodexLaunch({ paths, argv, env: process.env, cwd: import_node_fs39.default.realpathSync(process.cwd()), home: import_node_os24.default.homedir(), fs: realFarmFs, read: cosmiconfigReader(), resolveBinary, now: Date.now, pid: process.pid, isRunning: realIsProcessRunning, sleep: realSleepSync, uniqueSuffix: `${String(process.pid)}.${(0, import_node_crypto36.randomUUID)()}`, warn: (message) => {
|
|
167912
168350
|
console.error(`agent-shim: ${message}`);
|
|
167913
168351
|
}, ...resolveGitBranch(realRunPort, process.cwd()) });
|
|
167914
168352
|
import_node_fs39.default.chmodSync(plan.env.CODEX_HOME ?? "", PRIVATE_DIRECTORY_MODE);
|
|
@@ -168656,7 +169094,7 @@ async function realRefresher(params) {
|
|
|
168656
169094
|
}
|
|
168657
169095
|
|
|
168658
169096
|
// src/supervise/launch.ts
|
|
168659
|
-
var
|
|
169097
|
+
var import_node_crypto37 = require("node:crypto");
|
|
168660
169098
|
var import_node_fs40 = require("node:fs");
|
|
168661
169099
|
var import_node_path99 = __toESM(require("node:path"), 1);
|
|
168662
169100
|
var import_promises23 = require("node:stream/promises");
|
|
@@ -169427,21 +169865,21 @@ async function runSupervised(params) {
|
|
|
169427
169865
|
log.warn(`agent-shim: pool "${pool}" cannot supervise a launch whose extra flags end option parsing`);
|
|
169428
169866
|
return void 0;
|
|
169429
169867
|
}
|
|
169430
|
-
const first = initialConversationOf(params.passthrough, { newId:
|
|
169868
|
+
const first = initialConversationOf(params.passthrough, { newId: import_node_crypto37.randomUUID, latestId: () => latestConversationId(farm.fs, { claudeHome: farm.claudeHome, cwd: farm.cwd }) });
|
|
169431
169869
|
if ("reason" in first) {
|
|
169432
169870
|
log.warn(`agent-shim: pool "${pool}" resumes on a spent quota, but this launch runs unsupervised: ${first.reason}`);
|
|
169433
169871
|
return void 0;
|
|
169434
169872
|
}
|
|
169435
169873
|
let entrypointSha256AtStart;
|
|
169436
169874
|
try {
|
|
169437
|
-
const hash2 = (0,
|
|
169875
|
+
const hash2 = (0, import_node_crypto37.createHash)("sha256");
|
|
169438
169876
|
await (0, import_promises23.pipeline)((0, import_node_fs40.createReadStream)(realContentSourcePath()), hash2);
|
|
169439
169877
|
entrypointSha256AtStart = hash2.digest("hex");
|
|
169440
169878
|
} catch {
|
|
169441
169879
|
entrypointSha256AtStart = null;
|
|
169442
169880
|
log.warn("agent-shim: could not fingerprint the supervisor entrypoint");
|
|
169443
169881
|
}
|
|
169444
|
-
const lifecycle = createLifecycleRecorder({ fs: realFarmFs, logsDir: paths.logsDir, fileId: (0,
|
|
169882
|
+
const lifecycle = createLifecycleRecorder({ fs: realFarmFs, logsDir: paths.logsDir, fileId: (0, import_node_crypto37.randomUUID)(), sessionId: first.sessionId, supervisorPid: farm.lock.pid, supervisorVersion: package_default.version, entrypointSha256AtStart, now: farm.now, log });
|
|
169445
169883
|
let compaction;
|
|
169446
169884
|
const policy = params.pools[pool];
|
|
169447
169885
|
const markSettings = markHooksSettings(selfInvocation([]), paths.root, pool, first.sessionId);
|