claude-use 11.90.0 → 12.0.0
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 +764 -368
- package/dist/index.cjs +771 -502
- package/dist/index.mjs +739 -469
- package/dist/types/index.d.ts +143 -41
- 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 {
|
|
@@ -41989,7 +41989,7 @@ var init_package = __esm({
|
|
|
41989
41989
|
"package.json"() {
|
|
41990
41990
|
package_default = {
|
|
41991
41991
|
name: "claude-use",
|
|
41992
|
-
version: "
|
|
41992
|
+
version: "12.0.0",
|
|
41993
41993
|
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
41994
|
license: "MIT",
|
|
41995
41995
|
author: "Joseph Mearman <joseph@mearman.co.uk>",
|
|
@@ -125524,7 +125524,7 @@ function registerCodexCommand(program2, deps) {
|
|
|
125524
125524
|
}
|
|
125525
125525
|
|
|
125526
125526
|
// src/frontdoor/commands.ts
|
|
125527
|
-
var
|
|
125527
|
+
var import_node_crypto32 = require("node:crypto");
|
|
125528
125528
|
var import_node_os19 = __toESM(require("node:os"), 1);
|
|
125529
125529
|
init_catalogueCredential();
|
|
125530
125530
|
var import_node_path73 = __toESM(require("node:path"), 1);
|
|
@@ -127123,6 +127123,9 @@ var net3 = __toESM(require("node:net"), 1);
|
|
|
127123
127123
|
var tls = __toESM(require("node:tls"), 1);
|
|
127124
127124
|
init_connect();
|
|
127125
127125
|
|
|
127126
|
+
// src/frontdoor/rcSessions.ts
|
|
127127
|
+
var import_node_crypto27 = require("node:crypto");
|
|
127128
|
+
|
|
127126
127129
|
// src/agents/liveTasks.ts
|
|
127127
127130
|
init_zod();
|
|
127128
127131
|
var LIVE_TASK_CAP = 512;
|
|
@@ -127288,6 +127291,125 @@ function mergeLiveTasks(tree, live) {
|
|
|
127288
127291
|
return { ...tree, agents, remoteSessions, liveOnly };
|
|
127289
127292
|
}
|
|
127290
127293
|
|
|
127294
|
+
// src/frontdoor/rcQuestions.ts
|
|
127295
|
+
var RC_QUESTION_TOOL_NAME = "AskUserQuestion";
|
|
127296
|
+
var RC_QUESTIONS_MAX = 16;
|
|
127297
|
+
var RC_QUESTION_OPTIONS_MAX = 16;
|
|
127298
|
+
var RC_QUESTION_FIELD_MAX_CHARS = 1024;
|
|
127299
|
+
var MULTI_SELECT_SEPARATOR = ", ";
|
|
127300
|
+
function isRecord11(value3) {
|
|
127301
|
+
return typeof value3 === "object" && value3 !== null && !Array.isArray(value3);
|
|
127302
|
+
}
|
|
127303
|
+
function fits(value3) {
|
|
127304
|
+
return value3 === void 0 || value3.length <= RC_QUESTION_FIELD_MAX_CHARS;
|
|
127305
|
+
}
|
|
127306
|
+
function optionOf(value3) {
|
|
127307
|
+
if (!isRecord11(value3) || typeof value3.label !== "string" || value3.label === "") {
|
|
127308
|
+
return "an option names no label";
|
|
127309
|
+
}
|
|
127310
|
+
const description = typeof value3.description === "string" && value3.description !== "" ? value3.description : void 0;
|
|
127311
|
+
if (!fits(value3.label) || !fits(description)) {
|
|
127312
|
+
return `an option is past ${String(RC_QUESTION_FIELD_MAX_CHARS)} characters`;
|
|
127313
|
+
}
|
|
127314
|
+
return description === void 0 ? { label: value3.label } : { label: value3.label, description };
|
|
127315
|
+
}
|
|
127316
|
+
function questionOf(value3) {
|
|
127317
|
+
if (!isRecord11(value3) || typeof value3.question !== "string" || value3.question === "" || !Array.isArray(value3.options) || value3.options.length === 0) {
|
|
127318
|
+
return "a question has no text or no options";
|
|
127319
|
+
}
|
|
127320
|
+
if (value3.options.length > RC_QUESTION_OPTIONS_MAX) {
|
|
127321
|
+
return `a question has more than ${String(RC_QUESTION_OPTIONS_MAX)} options`;
|
|
127322
|
+
}
|
|
127323
|
+
const options = [];
|
|
127324
|
+
for (const candidate of value3.options) {
|
|
127325
|
+
const option = optionOf(candidate);
|
|
127326
|
+
if (typeof option === "string") {
|
|
127327
|
+
return option;
|
|
127328
|
+
}
|
|
127329
|
+
if (options.some((existing) => existing.label === option.label)) {
|
|
127330
|
+
return `a question lists the option ${JSON.stringify(option.label)} twice`;
|
|
127331
|
+
}
|
|
127332
|
+
options.push(option);
|
|
127333
|
+
}
|
|
127334
|
+
const header = typeof value3.header === "string" && value3.header !== "" ? value3.header : void 0;
|
|
127335
|
+
if (!fits(value3.question) || !fits(header)) {
|
|
127336
|
+
return `a question is past ${String(RC_QUESTION_FIELD_MAX_CHARS)} characters`;
|
|
127337
|
+
}
|
|
127338
|
+
return { question: value3.question, ...header === void 0 ? {} : { header }, multiSelect: value3.multiSelect === true, options };
|
|
127339
|
+
}
|
|
127340
|
+
function rcQuestionsOfToolRequest(toolName, input2) {
|
|
127341
|
+
if (toolName !== RC_QUESTION_TOOL_NAME) {
|
|
127342
|
+
return void 0;
|
|
127343
|
+
}
|
|
127344
|
+
if (!isRecord11(input2) || !Array.isArray(input2.questions) || input2.questions.length === 0) {
|
|
127345
|
+
return { unanswerable: "the request names no questions" };
|
|
127346
|
+
}
|
|
127347
|
+
if (input2.questions.length > RC_QUESTIONS_MAX) {
|
|
127348
|
+
return { unanswerable: `the request asks more than ${String(RC_QUESTIONS_MAX)} questions` };
|
|
127349
|
+
}
|
|
127350
|
+
const questions = [];
|
|
127351
|
+
for (const candidate of input2.questions) {
|
|
127352
|
+
const question = questionOf(candidate);
|
|
127353
|
+
if (typeof question === "string") {
|
|
127354
|
+
return { unanswerable: question };
|
|
127355
|
+
}
|
|
127356
|
+
if (questions.some((existing) => existing.question === question.question)) {
|
|
127357
|
+
return { unanswerable: `the request asks ${JSON.stringify(question.question)} twice` };
|
|
127358
|
+
}
|
|
127359
|
+
questions.push(question);
|
|
127360
|
+
}
|
|
127361
|
+
return { questions };
|
|
127362
|
+
}
|
|
127363
|
+
function resolveSelection(question, questionNumber, selection) {
|
|
127364
|
+
if (typeof selection === "number") {
|
|
127365
|
+
const option = Number.isInteger(selection) ? question.options[selection - 1] : void 0;
|
|
127366
|
+
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 };
|
|
127367
|
+
}
|
|
127368
|
+
if (typeof selection === "object") {
|
|
127369
|
+
const text5 = selection.text.trim();
|
|
127370
|
+
return text5 === "" ? { error: `question ${String(questionNumber)}'s free-text answer is empty` } : { text: text5 };
|
|
127371
|
+
}
|
|
127372
|
+
const exact = question.options.find((option) => option.label === selection);
|
|
127373
|
+
if (exact !== void 0) {
|
|
127374
|
+
return { text: exact.label };
|
|
127375
|
+
}
|
|
127376
|
+
const folded = question.options.filter((option) => option.label.toLowerCase() === selection.toLowerCase());
|
|
127377
|
+
const [only] = folded;
|
|
127378
|
+
if (only !== void 0 && folded.length === 1) {
|
|
127379
|
+
return { text: only.label };
|
|
127380
|
+
}
|
|
127381
|
+
return { error: `question ${String(questionNumber)} has no option labelled ${JSON.stringify(selection)}: its options are ${question.options.map((option) => JSON.stringify(option.label)).join(", ")}` };
|
|
127382
|
+
}
|
|
127383
|
+
function resolveRcQuestionAnswers(questions, choices) {
|
|
127384
|
+
if (choices.length !== questions.length) {
|
|
127385
|
+
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)}` };
|
|
127386
|
+
}
|
|
127387
|
+
const answers = {};
|
|
127388
|
+
for (const [index, question] of questions.entries()) {
|
|
127389
|
+
const questionNumber = index + 1;
|
|
127390
|
+
const selections = choices[index] ?? [];
|
|
127391
|
+
if (selections.length === 0) {
|
|
127392
|
+
return { error: `question ${String(questionNumber)} has no selection` };
|
|
127393
|
+
}
|
|
127394
|
+
if (!question.multiSelect && selections.length > 1) {
|
|
127395
|
+
return { error: `question ${String(questionNumber)} takes one option, but ${String(selections.length)} were chosen` };
|
|
127396
|
+
}
|
|
127397
|
+
const texts = [];
|
|
127398
|
+
for (const selection of selections) {
|
|
127399
|
+
const resolved = resolveSelection(question, questionNumber, selection);
|
|
127400
|
+
if ("error" in resolved) {
|
|
127401
|
+
return resolved;
|
|
127402
|
+
}
|
|
127403
|
+
if (texts.includes(resolved.text)) {
|
|
127404
|
+
return { error: `question ${String(questionNumber)} chose ${JSON.stringify(resolved.text)} twice` };
|
|
127405
|
+
}
|
|
127406
|
+
texts.push(resolved.text);
|
|
127407
|
+
}
|
|
127408
|
+
answers[question.question] = texts.join(MULTI_SELECT_SEPARATOR);
|
|
127409
|
+
}
|
|
127410
|
+
return { answers };
|
|
127411
|
+
}
|
|
127412
|
+
|
|
127291
127413
|
// src/frontdoor/rcSessions.ts
|
|
127292
127414
|
var RC_SESSIONS_PATH_PREFIX = "/v1/code/sessions";
|
|
127293
127415
|
function pathnameOf(url2) {
|
|
@@ -127302,7 +127424,12 @@ var RC_IDLE_EXPIRY_MS = 45e3;
|
|
|
127302
127424
|
var RC_CREATE_RESPONSE_CAP_BYTES = 8192;
|
|
127303
127425
|
var CONFLICT_REASON_HEADER = "x-ccr-conflict-reason";
|
|
127304
127426
|
var RC_STREAM_WORKER_SOURCE = "worker";
|
|
127305
|
-
var
|
|
127427
|
+
var HIGH_SURROGATE_FIRST = 55296;
|
|
127428
|
+
var HIGH_SURROGATE_LAST = 56319;
|
|
127429
|
+
var RC_WORKER_IDLE = "idle";
|
|
127430
|
+
var RC_PENDING_PER_SESSION_MAX = 64;
|
|
127431
|
+
var RC_REQUEST_ID_MAX_CHARS = 128;
|
|
127432
|
+
var RC_RETIRED_TOMBSTONES_MAX = 2 * RC_PENDING_PER_SESSION_MAX;
|
|
127306
127433
|
var RC_REQUEST_PARSE_CAP_BYTES = 262144;
|
|
127307
127434
|
var RC_PENDING_SUMMARY_EXCERPT_CHARS = 300;
|
|
127308
127435
|
var SUCCESS_STATUS_MAX_EXCLUSIVE = 300;
|
|
@@ -127335,7 +127462,7 @@ function sessionCreateId(body) {
|
|
|
127335
127462
|
const id2 = session.id;
|
|
127336
127463
|
return typeof id2 === "string" && id2.startsWith(RC_SESSION_ID_PREFIX) ? id2 : void 0;
|
|
127337
127464
|
}
|
|
127338
|
-
function
|
|
127465
|
+
function isRecord12(value3) {
|
|
127339
127466
|
return typeof value3 === "object" && value3 !== null && !Array.isArray(value3);
|
|
127340
127467
|
}
|
|
127341
127468
|
function parseJsonObject(body) {
|
|
@@ -127345,7 +127472,7 @@ function parseJsonObject(body) {
|
|
|
127345
127472
|
} catch {
|
|
127346
127473
|
return void 0;
|
|
127347
127474
|
}
|
|
127348
|
-
return
|
|
127475
|
+
return isRecord12(parsed) ? parsed : void 0;
|
|
127349
127476
|
}
|
|
127350
127477
|
function nonEmptyString(record3, field) {
|
|
127351
127478
|
const value3 = record3 === void 0 ? void 0 : record3[field];
|
|
@@ -127355,8 +127482,16 @@ function finiteNumber(record3, field) {
|
|
|
127355
127482
|
const value3 = record3 === void 0 ? void 0 : record3[field];
|
|
127356
127483
|
return typeof value3 === "number" && Number.isFinite(value3) ? value3 : void 0;
|
|
127357
127484
|
}
|
|
127358
|
-
function
|
|
127359
|
-
|
|
127485
|
+
function rcExcerpt(text5) {
|
|
127486
|
+
if (text5.length <= RC_PENDING_SUMMARY_EXCERPT_CHARS) {
|
|
127487
|
+
return text5;
|
|
127488
|
+
}
|
|
127489
|
+
const cut = text5.slice(0, RC_PENDING_SUMMARY_EXCERPT_CHARS);
|
|
127490
|
+
const last = cut.charCodeAt(cut.length - 1);
|
|
127491
|
+
return `${isHighSurrogate(last) ? cut.slice(0, -1) : cut}...`;
|
|
127492
|
+
}
|
|
127493
|
+
function isHighSurrogate(unit) {
|
|
127494
|
+
return unit >= HIGH_SURROGATE_FIRST && unit <= HIGH_SURROGATE_LAST;
|
|
127360
127495
|
}
|
|
127361
127496
|
function payloadEventsOf(body) {
|
|
127362
127497
|
const parsed = parseJsonObject(body);
|
|
@@ -127366,11 +127501,11 @@ function payloadEventsOf(body) {
|
|
|
127366
127501
|
}
|
|
127367
127502
|
const payloads = [];
|
|
127368
127503
|
for (const event of events) {
|
|
127369
|
-
if (!
|
|
127504
|
+
if (!isRecord12(event)) {
|
|
127370
127505
|
continue;
|
|
127371
127506
|
}
|
|
127372
127507
|
const payload = event.payload;
|
|
127373
|
-
if (!
|
|
127508
|
+
if (!isRecord12(payload)) {
|
|
127374
127509
|
continue;
|
|
127375
127510
|
}
|
|
127376
127511
|
payloads.push(payload);
|
|
@@ -127378,6 +127513,14 @@ function payloadEventsOf(body) {
|
|
|
127378
127513
|
return payloads;
|
|
127379
127514
|
}
|
|
127380
127515
|
function pendingOfControlRequestPayload(payload) {
|
|
127516
|
+
const parsed = fullPendingOfControlRequestPayload(payload);
|
|
127517
|
+
const isQuestion = parsed !== void 0 && (parsed.questions !== void 0 || parsed.unanswerable !== void 0);
|
|
127518
|
+
if (parsed === void 0 || !isQuestion || Buffer.byteLength(JSON.stringify(payload), "utf8") <= RC_REQUEST_PARSE_CAP_BYTES) {
|
|
127519
|
+
return parsed;
|
|
127520
|
+
}
|
|
127521
|
+
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` };
|
|
127522
|
+
}
|
|
127523
|
+
function fullPendingOfControlRequestPayload(payload) {
|
|
127381
127524
|
if (payload.type !== "control_request") {
|
|
127382
127525
|
return void 0;
|
|
127383
127526
|
}
|
|
@@ -127385,24 +127528,41 @@ function pendingOfControlRequestPayload(payload) {
|
|
|
127385
127528
|
if (requestId === void 0) {
|
|
127386
127529
|
return void 0;
|
|
127387
127530
|
}
|
|
127388
|
-
const request7 =
|
|
127531
|
+
const request7 = isRecord12(payload.request) ? payload.request : void 0;
|
|
127389
127532
|
const subtype = nonEmptyString(request7, "subtype");
|
|
127390
127533
|
const type2 = subtype ?? "control_request";
|
|
127391
127534
|
let summary = "";
|
|
127535
|
+
let questions;
|
|
127536
|
+
let unanswerable;
|
|
127537
|
+
let toolInput;
|
|
127392
127538
|
if (subtype === "can_use_tool") {
|
|
127393
|
-
const toolName = nonEmptyString(request7, "tool_name")
|
|
127539
|
+
const toolName = nonEmptyString(request7, "tool_name");
|
|
127394
127540
|
const input2 = request7 === void 0 ? void 0 : request7.input;
|
|
127395
|
-
summary = input2 === void 0 ? toolName : `${toolName} ${
|
|
127541
|
+
summary = input2 === void 0 ? toolName ?? "unknown tool" : `${toolName ?? "unknown tool"} ${rcExcerpt(JSON.stringify(input2))}`;
|
|
127542
|
+
const parsedQuestions = rcQuestionsOfToolRequest(toolName, input2);
|
|
127543
|
+
if (parsedQuestions !== void 0 && "questions" in parsedQuestions) {
|
|
127544
|
+
questions = parsedQuestions.questions;
|
|
127545
|
+
toolInput = isRecord12(input2) ? input2 : void 0;
|
|
127546
|
+
} else if (parsedQuestions !== void 0) {
|
|
127547
|
+
unanswerable = parsedQuestions.unanswerable;
|
|
127548
|
+
}
|
|
127396
127549
|
} else if (request7 !== void 0) {
|
|
127397
|
-
summary =
|
|
127550
|
+
summary = rcExcerpt(JSON.stringify(request7));
|
|
127551
|
+
}
|
|
127552
|
+
return { requestId, type: type2, summary, questions, unanswerable, toolInput, oversized: false };
|
|
127553
|
+
}
|
|
127554
|
+
function withdrawnRequestIdsOfControlCancelPayload(payload) {
|
|
127555
|
+
if (payload.type !== "control_cancel_request") {
|
|
127556
|
+
return [];
|
|
127398
127557
|
}
|
|
127399
|
-
|
|
127558
|
+
const id2 = nonEmptyString(payload, "request_id");
|
|
127559
|
+
return id2 === void 0 ? [] : [id2];
|
|
127400
127560
|
}
|
|
127401
127561
|
function answeredRequestIdsOfControlResponsePayload(payload) {
|
|
127402
127562
|
if (payload.type !== "control_response") {
|
|
127403
127563
|
return [];
|
|
127404
127564
|
}
|
|
127405
|
-
const response =
|
|
127565
|
+
const response = isRecord12(payload.response) ? payload.response : void 0;
|
|
127406
127566
|
const id2 = nonEmptyString(response, "request_id") ?? nonEmptyString(payload, "request_id") ?? nonEmptyString(payload, "uuid");
|
|
127407
127567
|
return id2 === void 0 ? [] : [id2];
|
|
127408
127568
|
}
|
|
@@ -127414,44 +127574,74 @@ function initFactsOfPayload(payload) {
|
|
|
127414
127574
|
}
|
|
127415
127575
|
function parseRcRequestBody(kind, body) {
|
|
127416
127576
|
if (kind === "heartbeat") {
|
|
127417
|
-
return { controlRequests: [], answeredRequestIds: [], idleSeconds: finiteNumber(parseJsonObject(body), "idle_seconds"), workerStatus: void 0, payloads: [] };
|
|
127577
|
+
return { controlRequests: [], answeredRequestIds: [], withdrawnRequestIds: [], idleSeconds: finiteNumber(parseJsonObject(body), "idle_seconds"), workerStatus: void 0, workerEpoch: void 0, payloads: [] };
|
|
127418
127578
|
}
|
|
127419
127579
|
if (kind === "worker-registration") {
|
|
127420
127580
|
const registration = parseJsonObject(body);
|
|
127421
|
-
const metadata = registration === void 0 || !
|
|
127581
|
+
const metadata = registration === void 0 || !isRecord12(registration.external_metadata) ? void 0 : registration.external_metadata;
|
|
127422
127582
|
const model = nonEmptyString(metadata, "model");
|
|
127423
|
-
return { controlRequests: [], answeredRequestIds: [], idleSeconds: void 0, workerStatus: nonEmptyString(registration, "worker_status"), payloads: [], ...model === void 0 ? {} : { model } };
|
|
127583
|
+
return { controlRequests: [], answeredRequestIds: [], withdrawnRequestIds: [], idleSeconds: void 0, workerStatus: nonEmptyString(registration, "worker_status"), workerEpoch: finiteNumber(registration, "worker_epoch"), payloads: [], ...model === void 0 ? {} : { model } };
|
|
127424
127584
|
}
|
|
127425
127585
|
const controlRequests = [];
|
|
127426
127586
|
const answeredRequestIds = [];
|
|
127587
|
+
const withdrawnRequestIds = [];
|
|
127427
127588
|
const payloads = payloadEventsOf(body);
|
|
127428
127589
|
for (const payload of payloads) {
|
|
127429
127590
|
const pending = pendingOfControlRequestPayload(payload);
|
|
127430
127591
|
if (pending !== void 0) {
|
|
127431
|
-
controlRequests.push(
|
|
127592
|
+
controlRequests.push(pending);
|
|
127432
127593
|
continue;
|
|
127433
127594
|
}
|
|
127434
127595
|
answeredRequestIds.push(...answeredRequestIdsOfControlResponsePayload(payload));
|
|
127596
|
+
if (kind === "worker-events") {
|
|
127597
|
+
withdrawnRequestIds.push(...withdrawnRequestIdsOfControlCancelPayload(payload));
|
|
127598
|
+
}
|
|
127599
|
+
}
|
|
127600
|
+
return { controlRequests, answeredRequestIds, withdrawnRequestIds, idleSeconds: void 0, workerStatus: void 0, workerEpoch: void 0, payloads };
|
|
127601
|
+
}
|
|
127602
|
+
function rememberBounded(record3, key) {
|
|
127603
|
+
record3.delete(key);
|
|
127604
|
+
record3.add(key);
|
|
127605
|
+
if (record3.size > RC_RETIRED_TOMBSTONES_MAX) {
|
|
127606
|
+
const [oldest] = record3;
|
|
127607
|
+
if (oldest !== void 0) {
|
|
127608
|
+
record3.delete(oldest);
|
|
127609
|
+
}
|
|
127435
127610
|
}
|
|
127436
|
-
|
|
127611
|
+
}
|
|
127612
|
+
function droppedKeyOf(requestId) {
|
|
127613
|
+
return requestId.length <= RC_REQUEST_ID_MAX_CHARS ? requestId : (0, import_node_crypto27.createHash)("sha256").update(requestId).digest("hex");
|
|
127437
127614
|
}
|
|
127438
127615
|
function createRcSessionTracker(deps) {
|
|
127439
127616
|
const entries = /* @__PURE__ */ new Map();
|
|
127617
|
+
let observationSequence = 0;
|
|
127618
|
+
const rememberRetired = (entry, requestId) => {
|
|
127619
|
+
rememberBounded(entry.retired, requestId);
|
|
127620
|
+
};
|
|
127440
127621
|
const retirePending = (entry, requestId, reason) => {
|
|
127441
127622
|
if (entry.pending.delete(requestId)) {
|
|
127442
|
-
entry
|
|
127623
|
+
rememberRetired(entry, requestId);
|
|
127443
127624
|
deps.onTransition?.({ kind: "pending-retired", session: entry.id, requestId, reason, at: deps.now() });
|
|
127444
127625
|
}
|
|
127445
127626
|
};
|
|
127446
|
-
const addPending = (entry,
|
|
127447
|
-
|
|
127627
|
+
const addPending = (entry, request7, now) => {
|
|
127628
|
+
const droppedKey = droppedKeyOf(request7.requestId);
|
|
127629
|
+
if (entry.retired.has(request7.requestId) || entry.dropped.has(droppedKey)) {
|
|
127448
127630
|
return;
|
|
127449
127631
|
}
|
|
127450
|
-
const
|
|
127451
|
-
|
|
127452
|
-
|
|
127453
|
-
|
|
127632
|
+
const already = entry.pending.get(request7.requestId);
|
|
127633
|
+
if (already !== void 0) {
|
|
127634
|
+
entry.pending.set(request7.requestId, { ...already, ...request7, observedAt: already.observedAt });
|
|
127635
|
+
return;
|
|
127636
|
+
}
|
|
127637
|
+
if (request7.requestId.length > RC_REQUEST_ID_MAX_CHARS || entry.pending.size >= RC_PENDING_PER_SESSION_MAX) {
|
|
127638
|
+
entry.droppedPending += 1;
|
|
127639
|
+
rememberBounded(entry.dropped, droppedKey);
|
|
127640
|
+
return;
|
|
127454
127641
|
}
|
|
127642
|
+
observationSequence += 1;
|
|
127643
|
+
entry.pending.set(request7.requestId, { sessionId: entry.id, ...request7, observedAt: now, observedSequence: observationSequence });
|
|
127644
|
+
deps.onTransition?.({ kind: "pending-born", session: entry.id, requestId: request7.requestId, type: request7.type, summary: request7.summary, at: now });
|
|
127455
127645
|
};
|
|
127456
127646
|
const expire = (id2, reason) => {
|
|
127457
127647
|
const entry = entries.get(id2);
|
|
@@ -127464,31 +127654,17 @@ function createRcSessionTracker(deps) {
|
|
|
127464
127654
|
entries.delete(id2);
|
|
127465
127655
|
deps.onTransition?.({ kind: "session-ended", session: id2, reason, at: deps.now() });
|
|
127466
127656
|
};
|
|
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
127657
|
const sweep = () => {
|
|
127480
127658
|
for (const [id2, entry] of entries) {
|
|
127481
127659
|
if (deps.now() - entry.lastSeenAt >= deps.idleMs) {
|
|
127482
127660
|
expire(id2, "expired");
|
|
127483
|
-
continue;
|
|
127484
127661
|
}
|
|
127485
|
-
expirePendings(entry, deps.now());
|
|
127486
127662
|
}
|
|
127487
127663
|
};
|
|
127488
|
-
const timer = setInterval(sweep,
|
|
127664
|
+
const timer = setInterval(sweep, deps.idleMs);
|
|
127489
127665
|
timer.unref();
|
|
127490
127666
|
const birth = (id2, facts) => {
|
|
127491
|
-
const record3 = { id: id2, createdAt: deps.now(), lastSeenAt: deps.now(), ...facts, pending: /* @__PURE__ */ new Map(), retired: /* @__PURE__ */ new
|
|
127667
|
+
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
127668
|
entries.set(id2, record3);
|
|
127493
127669
|
deps.onTransition?.({ kind: "session-appeared", session: id2, at: record3.createdAt });
|
|
127494
127670
|
return record3;
|
|
@@ -127519,6 +127695,7 @@ function createRcSessionTracker(deps) {
|
|
|
127519
127695
|
return void 0;
|
|
127520
127696
|
}
|
|
127521
127697
|
const tail = pathnameOf(request7.url).slice(RC_SESSIONS_PATH_PREFIX.length);
|
|
127698
|
+
const startedAtSequence = observationSequence;
|
|
127522
127699
|
const facts = {
|
|
127523
127700
|
oauthAuthorization: oauthAuthorizationOf(request7.headers),
|
|
127524
127701
|
anthropicVersion: singleHeader(request7.headers, "anthropic-version"),
|
|
@@ -127592,11 +127769,14 @@ function createRcSessionTracker(deps) {
|
|
|
127592
127769
|
}
|
|
127593
127770
|
const now = deps.now();
|
|
127594
127771
|
for (const controlRequest of factsOfBody.controlRequests) {
|
|
127595
|
-
addPending(entryNow,
|
|
127772
|
+
addPending(entryNow, controlRequest, now);
|
|
127596
127773
|
}
|
|
127597
127774
|
for (const requestId of factsOfBody.answeredRequestIds) {
|
|
127598
127775
|
retirePending(entryNow, requestId, "answered");
|
|
127599
127776
|
}
|
|
127777
|
+
for (const requestId of factsOfBody.withdrawnRequestIds) {
|
|
127778
|
+
retirePending(entryNow, requestId, "withdrawn");
|
|
127779
|
+
}
|
|
127600
127780
|
for (const payload of factsOfBody.payloads) {
|
|
127601
127781
|
entryNow.liveTasks = applyAgentTaskEvent(entryNow.liveTasks, id2, payload, now);
|
|
127602
127782
|
noteInit(entryNow, payload);
|
|
@@ -127612,6 +127792,17 @@ function createRcSessionTracker(deps) {
|
|
|
127612
127792
|
deps.onTransition?.({ kind: "worker-state", session: id2, state: factsOfBody.workerStatus, ...previous === void 0 ? {} : { previous }, at: now });
|
|
127613
127793
|
}
|
|
127614
127794
|
}
|
|
127795
|
+
const epochChanged = factsOfBody.workerEpoch !== void 0 && entryNow.workerEpoch !== void 0 && factsOfBody.workerEpoch !== entryNow.workerEpoch;
|
|
127796
|
+
if (factsOfBody.workerEpoch !== void 0) {
|
|
127797
|
+
entryNow.workerEpoch = factsOfBody.workerEpoch;
|
|
127798
|
+
}
|
|
127799
|
+
if (epochChanged || factsOfBody.workerStatus === RC_WORKER_IDLE) {
|
|
127800
|
+
for (const [requestId, pending] of entryNow.pending) {
|
|
127801
|
+
if (pending.observedSequence <= startedAtSequence) {
|
|
127802
|
+
retirePending(entryNow, requestId, "worker-stopped");
|
|
127803
|
+
}
|
|
127804
|
+
}
|
|
127805
|
+
}
|
|
127615
127806
|
};
|
|
127616
127807
|
const archiving = method === "POST" && rest === `${id2}/archive`;
|
|
127617
127808
|
return {
|
|
@@ -127651,7 +127842,7 @@ function createRcSessionTracker(deps) {
|
|
|
127651
127842
|
};
|
|
127652
127843
|
};
|
|
127653
127844
|
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 });
|
|
127845
|
+
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
127846
|
const sortedEntries = () => [...entries.values()].sort((left, right) => left.createdAt - right.createdAt || (left.id < right.id ? -1 : 1));
|
|
127656
127847
|
const pendingSorted = (entry) => [...entry.pending.values()].sort((left, right) => left.observedAt - right.observedAt || (left.requestId < right.requestId ? -1 : 1)).map(pendingSummaryOf);
|
|
127657
127848
|
return {
|
|
@@ -127669,7 +127860,8 @@ function createRcSessionTracker(deps) {
|
|
|
127669
127860
|
pending: pendingSorted(entry),
|
|
127670
127861
|
...entry.identity === void 0 ? {} : { identity: entry.identity },
|
|
127671
127862
|
...entry.model === void 0 ? {} : { model: entry.model },
|
|
127672
|
-
...entry.cwd === void 0 ? {} : { cwd: entry.cwd }
|
|
127863
|
+
...entry.cwd === void 0 ? {} : { cwd: entry.cwd },
|
|
127864
|
+
...entry.droppedPending === 0 ? {} : { pendingDropped: entry.droppedPending }
|
|
127673
127865
|
}));
|
|
127674
127866
|
},
|
|
127675
127867
|
pendingOf: (sessionId) => {
|
|
@@ -127707,7 +127899,7 @@ function createRcSessionTracker(deps) {
|
|
|
127707
127899
|
return;
|
|
127708
127900
|
}
|
|
127709
127901
|
entry.sequenceNum = entry.sequenceNum === void 0 || event.sequence_num > entry.sequenceNum ? event.sequence_num : entry.sequenceNum;
|
|
127710
|
-
if (!
|
|
127902
|
+
if (!isRecord12(event.payload)) {
|
|
127711
127903
|
return;
|
|
127712
127904
|
}
|
|
127713
127905
|
entry.liveTasks = applyAgentTaskEvent(entry.liveTasks, sessionId, event.payload, deps.now());
|
|
@@ -127715,13 +127907,18 @@ function createRcSessionTracker(deps) {
|
|
|
127715
127907
|
const pending = pendingOfControlRequestPayload(event.payload);
|
|
127716
127908
|
if (pending !== void 0) {
|
|
127717
127909
|
if (event.source === RC_STREAM_WORKER_SOURCE) {
|
|
127718
|
-
addPending(entry,
|
|
127910
|
+
addPending(entry, pending, deps.now());
|
|
127719
127911
|
}
|
|
127720
127912
|
return;
|
|
127721
127913
|
}
|
|
127722
127914
|
for (const requestId of answeredRequestIdsOfControlResponsePayload(event.payload)) {
|
|
127723
127915
|
retirePending(entry, requestId, "answered");
|
|
127724
127916
|
}
|
|
127917
|
+
if (event.source === RC_STREAM_WORKER_SOURCE) {
|
|
127918
|
+
for (const requestId of withdrawnRequestIdsOfControlCancelPayload(event.payload)) {
|
|
127919
|
+
retirePending(entry, requestId, "withdrawn");
|
|
127920
|
+
}
|
|
127921
|
+
}
|
|
127725
127922
|
},
|
|
127726
127923
|
liveTasksOf: (sessionId) => {
|
|
127727
127924
|
sweep();
|
|
@@ -127733,6 +127930,17 @@ function createRcSessionTracker(deps) {
|
|
|
127733
127930
|
retirePending(entry, requestId, "answered");
|
|
127734
127931
|
}
|
|
127735
127932
|
},
|
|
127933
|
+
claimPending: (sessionId, requestId) => {
|
|
127934
|
+
const entry = entries.get(sessionId);
|
|
127935
|
+
if (entry === void 0 || !entry.pending.has(requestId) || entry.answering.has(requestId)) {
|
|
127936
|
+
return void 0;
|
|
127937
|
+
}
|
|
127938
|
+
entry.answering.add(requestId);
|
|
127939
|
+
return () => {
|
|
127940
|
+
entry.answering.delete(requestId);
|
|
127941
|
+
};
|
|
127942
|
+
},
|
|
127943
|
+
pendingToolInputOf: (sessionId, requestId) => entries.get(sessionId)?.pending.get(requestId)?.toolInput,
|
|
127736
127944
|
close: () => {
|
|
127737
127945
|
clearInterval(timer);
|
|
127738
127946
|
deps.onClose?.();
|
|
@@ -127878,8 +128086,8 @@ async function injectRcUserMessage(deps, sessionId, text5) {
|
|
|
127878
128086
|
}
|
|
127879
128087
|
return result;
|
|
127880
128088
|
}
|
|
127881
|
-
function buildRcControlResponsePayload(requestId, decision) {
|
|
127882
|
-
const result = decision.approve ? { behavior: "allow" } : { behavior: "deny", message: decision.message ?? "" };
|
|
128089
|
+
function buildRcControlResponsePayload(requestId, decision, updatedInput) {
|
|
128090
|
+
const result = decision.approve ? { behavior: "allow", ...updatedInput === void 0 ? {} : { updatedInput } } : { behavior: "deny", message: decision.message ?? "" };
|
|
127883
128091
|
return { type: "control_response", response: { subtype: "success", request_id: requestId, response: result } };
|
|
127884
128092
|
}
|
|
127885
128093
|
var RC_PERMISSION_MODES = ["default", "acceptEdits", "bypassPermissions", "plan", "dontAsk", "auto"];
|
|
@@ -127936,6 +128144,27 @@ function buildRcMcpOAuthCallbackUrlPayload(requestId, serverName, callbackUrl) {
|
|
|
127936
128144
|
function buildRcKeepAlivePayload() {
|
|
127937
128145
|
return { type: "keep_alive" };
|
|
127938
128146
|
}
|
|
128147
|
+
function questionAnswerInput(deps, sessionId, pending, decision) {
|
|
128148
|
+
const { questions, unanswerable } = pending;
|
|
128149
|
+
if (questions === void 0 && unanswerable === void 0) {
|
|
128150
|
+
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` };
|
|
128151
|
+
}
|
|
128152
|
+
if (!decision.approve) {
|
|
128153
|
+
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" };
|
|
128154
|
+
}
|
|
128155
|
+
if (questions === void 0) {
|
|
128156
|
+
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` };
|
|
128157
|
+
}
|
|
128158
|
+
if (decision.choices === void 0) {
|
|
128159
|
+
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` };
|
|
128160
|
+
}
|
|
128161
|
+
const input2 = deps.pendingToolInputOf(sessionId, pending.requestId);
|
|
128162
|
+
if (input2 === void 0) {
|
|
128163
|
+
return { error: `the front door holds no input for question ${pending.requestId} on session ${sessionId}, so it cannot write the answer the worker expects` };
|
|
128164
|
+
}
|
|
128165
|
+
const resolved = resolveRcQuestionAnswers(questions, decision.choices);
|
|
128166
|
+
return "error" in resolved ? resolved : { input: { ...input2, answers: resolved.answers } };
|
|
128167
|
+
}
|
|
127939
128168
|
async function answerRcControlRequest(deps, sessionId, requestId, decision) {
|
|
127940
128169
|
const credential = deps.credentialOf(sessionId);
|
|
127941
128170
|
if (credential === void 0) {
|
|
@@ -127944,15 +128173,26 @@ async function answerRcControlRequest(deps, sessionId, requestId, decision) {
|
|
|
127944
128173
|
if (credential.authorization === void 0) {
|
|
127945
128174
|
return noOAuthCredentialResult(sessionId);
|
|
127946
128175
|
}
|
|
127947
|
-
|
|
127948
|
-
|
|
128176
|
+
const pending = deps.pendingOf(sessionId).find((candidate) => candidate.requestId === requestId);
|
|
128177
|
+
if (pending === void 0) {
|
|
128178
|
+
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` };
|
|
128179
|
+
}
|
|
128180
|
+
const updatedInput = questionAnswerInput(deps, sessionId, pending, decision);
|
|
128181
|
+
if (updatedInput !== void 0 && "error" in updatedInput) {
|
|
128182
|
+
return { ok: false, message: updatedInput.error };
|
|
127949
128183
|
}
|
|
127950
|
-
const
|
|
128184
|
+
const release = deps.claimPending(sessionId, requestId);
|
|
128185
|
+
if (release === void 0) {
|
|
128186
|
+
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` };
|
|
128187
|
+
}
|
|
128188
|
+
const body = JSON.stringify(buildRcEventWriteBody(buildRcControlResponsePayload(requestId, decision, updatedInput?.input)));
|
|
127951
128189
|
let answer;
|
|
127952
128190
|
try {
|
|
127953
128191
|
answer = await deps.dial.writeEvents(sessionId, rcWriteHeaders(credential), body);
|
|
127954
128192
|
} catch (error63) {
|
|
127955
128193
|
return { ok: false, message: `the door could not reach the API host to answer on session ${sessionId}: ${error63 instanceof Error ? error63.message : String(error63)}` };
|
|
128194
|
+
} finally {
|
|
128195
|
+
release();
|
|
127956
128196
|
}
|
|
127957
128197
|
const result = rcEventWriteResultFromAnswer(answer);
|
|
127958
128198
|
if (result.ok) {
|
|
@@ -128096,6 +128336,198 @@ function readMachineLoad() {
|
|
|
128096
128336
|
// src/frontdoor/rcControl.ts
|
|
128097
128337
|
var https = __toESM(require("node:https"), 1);
|
|
128098
128338
|
init_capability();
|
|
128339
|
+
|
|
128340
|
+
// src/frontdoor/rcSchemas.ts
|
|
128341
|
+
init_zod();
|
|
128342
|
+
var RcPermissionModeSchema = external_exports.enum(RC_PERMISSION_MODES);
|
|
128343
|
+
var RcSessionSummarySchema = external_exports.strictObject({
|
|
128344
|
+
id: external_exports.string(),
|
|
128345
|
+
createdAt: external_exports.number(),
|
|
128346
|
+
lastSeenAt: external_exports.number()
|
|
128347
|
+
});
|
|
128348
|
+
function workerFactSchema(value3) {
|
|
128349
|
+
return external_exports.strictObject({ value: value3, observedAt: external_exports.number() });
|
|
128350
|
+
}
|
|
128351
|
+
var RcQuestionOptionSchema = external_exports.strictObject({
|
|
128352
|
+
label: external_exports.string(),
|
|
128353
|
+
description: external_exports.string().optional()
|
|
128354
|
+
});
|
|
128355
|
+
var RcPendingQuestionSchema = external_exports.strictObject({
|
|
128356
|
+
question: external_exports.string(),
|
|
128357
|
+
header: external_exports.string().optional(),
|
|
128358
|
+
multiSelect: external_exports.boolean(),
|
|
128359
|
+
options: external_exports.readonly(external_exports.array(RcQuestionOptionSchema))
|
|
128360
|
+
});
|
|
128361
|
+
var RcPendingRequestSummarySchema = external_exports.strictObject({
|
|
128362
|
+
sessionId: external_exports.string(),
|
|
128363
|
+
requestId: external_exports.string(),
|
|
128364
|
+
type: external_exports.string(),
|
|
128365
|
+
summary: external_exports.string(),
|
|
128366
|
+
questions: external_exports.readonly(external_exports.array(RcPendingQuestionSchema)).optional(),
|
|
128367
|
+
oversized: external_exports.literal(true).optional(),
|
|
128368
|
+
unanswerable: external_exports.string().optional(),
|
|
128369
|
+
observedAt: external_exports.number()
|
|
128370
|
+
});
|
|
128371
|
+
var RcSessionStatusSchema = external_exports.strictObject({
|
|
128372
|
+
...RcSessionSummarySchema.shape,
|
|
128373
|
+
workerState: workerFactSchema(external_exports.string()).optional(),
|
|
128374
|
+
workerIdleSeconds: workerFactSchema(external_exports.number()).optional(),
|
|
128375
|
+
pending: external_exports.readonly(external_exports.array(RcPendingRequestSummarySchema)),
|
|
128376
|
+
/** The identity the session runs as, when known; absent otherwise. */
|
|
128377
|
+
identity: external_exports.string().optional(),
|
|
128378
|
+
/** The model the session last stated, when the door saw one. */
|
|
128379
|
+
model: external_exports.string().optional(),
|
|
128380
|
+
/** The session's name from the Claude Code session registry, when the registry holds it. */
|
|
128381
|
+
name: external_exports.string().optional(),
|
|
128382
|
+
/** The session process's id from the registry. */
|
|
128383
|
+
pid: external_exports.number().optional(),
|
|
128384
|
+
/** The session's working directory, from its init event or the registry. */
|
|
128385
|
+
cwd: external_exports.string().optional(),
|
|
128386
|
+
pendingDropped: external_exports.int().positive().optional()
|
|
128387
|
+
});
|
|
128388
|
+
var RcStreamEnvelopeSchema = external_exports.looseObject({
|
|
128389
|
+
/** The envelope's own event id, when the host sent one. */
|
|
128390
|
+
event_id: external_exports.string().optional(),
|
|
128391
|
+
/** The envelope's event type, the discriminator a consumer switches on (`control_request`, `user`, and kin). */
|
|
128392
|
+
event_type: external_exports.string(),
|
|
128393
|
+
/** The sequence number the host assigned, the value a resume continues after. */
|
|
128394
|
+
sequence_num: external_exports.int(),
|
|
128395
|
+
/** Who emitted the event (`worker` for the CLI's half, a client id for a client's). */
|
|
128396
|
+
source: external_exports.string(),
|
|
128397
|
+
/** 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. */
|
|
128398
|
+
payload: external_exports.unknown().optional(),
|
|
128399
|
+
/** 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. */
|
|
128400
|
+
created_at: external_exports.unknown().optional()
|
|
128401
|
+
});
|
|
128402
|
+
var RcStreamEventSchema = external_exports.strictObject({
|
|
128403
|
+
session: external_exports.string(),
|
|
128404
|
+
envelope: RcStreamEnvelopeSchema
|
|
128405
|
+
});
|
|
128406
|
+
var RcRateLimitWindowSchema = external_exports.looseObject({
|
|
128407
|
+
/** 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). */
|
|
128408
|
+
utilization: external_exports.number().optional(),
|
|
128409
|
+
/** 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. */
|
|
128410
|
+
resetsAt: external_exports.number().optional()
|
|
128411
|
+
});
|
|
128412
|
+
var RcRateLimitInfoSchema = external_exports.looseObject({
|
|
128413
|
+
/** The limiting window's own status (`allowed`, `allowed_warning`, `rejected`), asserted only as a string because the vocabulary grows with the CLI. */
|
|
128414
|
+
status: external_exports.string(),
|
|
128415
|
+
/** When the limiting window resets, in unix epoch seconds. */
|
|
128416
|
+
resetsAt: external_exports.number().optional(),
|
|
128417
|
+
/** Which window the top-level fields describe (`five_hour`, `seven_day`, and kin), the payload's own name for it. */
|
|
128418
|
+
rateLimitType: external_exports.string().optional(),
|
|
128419
|
+
/** The fraction of the limiting window used, on the same scale the per-window utilizations carry. */
|
|
128420
|
+
utilization: external_exports.number().optional(),
|
|
128421
|
+
/** Whether usage beyond the plan (extra usage) is currently covering the overflow, the payload's own flag for it. */
|
|
128422
|
+
isUsingOverage: external_exports.boolean().optional(),
|
|
128423
|
+
/** The overage's own status, the same vocabulary the limiting window's `status` carries. */
|
|
128424
|
+
overageStatus: external_exports.string().optional(),
|
|
128425
|
+
/** When the overage window resets, in unix epoch seconds. */
|
|
128426
|
+
overageResetsAt: external_exports.number().optional(),
|
|
128427
|
+
/** 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. */
|
|
128428
|
+
unifiedWindows: external_exports.looseObject({ five_hour: RcRateLimitWindowSchema.optional(), seven_day: RcRateLimitWindowSchema.optional(), seven_day_overage_included: RcRateLimitWindowSchema.optional() }).optional()
|
|
128429
|
+
});
|
|
128430
|
+
var RcLiveRateLimitSchema = external_exports.strictObject({
|
|
128431
|
+
session: external_exports.string(),
|
|
128432
|
+
observedAt: external_exports.number(),
|
|
128433
|
+
rateLimit: RcRateLimitInfoSchema
|
|
128434
|
+
});
|
|
128435
|
+
var RcSessionQuerySchema = external_exports.strictObject({
|
|
128436
|
+
session: external_exports.string().min(1).optional()
|
|
128437
|
+
});
|
|
128438
|
+
var RcSendInputSchema = external_exports.strictObject({
|
|
128439
|
+
session: external_exports.string().min(1),
|
|
128440
|
+
text: external_exports.string().min(1)
|
|
128441
|
+
});
|
|
128442
|
+
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" }) })]);
|
|
128443
|
+
var RcQuestionChoicesSchema = external_exports.array(external_exports.array(RcQuestionSelectionSchema).min(1)).min(1);
|
|
128444
|
+
var RcAnswerInputSchema = external_exports.strictObject({
|
|
128445
|
+
session: external_exports.string().min(1),
|
|
128446
|
+
request: external_exports.string().min(1),
|
|
128447
|
+
approve: external_exports.boolean(),
|
|
128448
|
+
text: external_exports.string().optional(),
|
|
128449
|
+
choices: RcQuestionChoicesSchema.optional()
|
|
128450
|
+
}).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" });
|
|
128451
|
+
var RcInterruptInputSchema = external_exports.strictObject({
|
|
128452
|
+
session: external_exports.string().min(1)
|
|
128453
|
+
});
|
|
128454
|
+
var RcSetModelInputSchema = external_exports.strictObject({
|
|
128455
|
+
session: external_exports.string().min(1),
|
|
128456
|
+
model: external_exports.string().min(1)
|
|
128457
|
+
});
|
|
128458
|
+
var RcSetPermissionModeInputSchema = external_exports.strictObject({
|
|
128459
|
+
session: external_exports.string().min(1),
|
|
128460
|
+
mode: RcPermissionModeSchema
|
|
128461
|
+
});
|
|
128462
|
+
var RcEndSessionInputSchema = external_exports.strictObject({
|
|
128463
|
+
session: external_exports.string().min(1),
|
|
128464
|
+
reason: external_exports.string().min(1).optional()
|
|
128465
|
+
});
|
|
128466
|
+
var RcGetUsageInputSchema = external_exports.strictObject({
|
|
128467
|
+
session: external_exports.string().min(1),
|
|
128468
|
+
skipBehaviors: external_exports.boolean().optional()
|
|
128469
|
+
});
|
|
128470
|
+
var RcGetContextUsageInputSchema = external_exports.strictObject({
|
|
128471
|
+
session: external_exports.string().min(1),
|
|
128472
|
+
detail: external_exports.enum(RC_CONTEXT_USAGE_DETAILS).optional()
|
|
128473
|
+
});
|
|
128474
|
+
var RcReadFileInputSchema = external_exports.strictObject({
|
|
128475
|
+
session: external_exports.string().min(1),
|
|
128476
|
+
path: external_exports.string().min(1),
|
|
128477
|
+
maxBytes: external_exports.number().int().positive().optional(),
|
|
128478
|
+
encoding: external_exports.enum(RC_READ_FILE_ENCODINGS).optional()
|
|
128479
|
+
});
|
|
128480
|
+
var RcFileSuggestionsInputSchema = external_exports.strictObject({
|
|
128481
|
+
session: external_exports.string().min(1),
|
|
128482
|
+
query: external_exports.string()
|
|
128483
|
+
});
|
|
128484
|
+
var RcKeepAliveInputSchema = external_exports.strictObject({
|
|
128485
|
+
session: external_exports.string().min(1)
|
|
128486
|
+
});
|
|
128487
|
+
var RcMcpStatusInputSchema = external_exports.strictObject({
|
|
128488
|
+
session: external_exports.string().min(1)
|
|
128489
|
+
});
|
|
128490
|
+
var RcMcpReconnectInputSchema = external_exports.strictObject({
|
|
128491
|
+
session: external_exports.string().min(1),
|
|
128492
|
+
serverName: external_exports.string().min(1)
|
|
128493
|
+
});
|
|
128494
|
+
var RcMcpAuthenticateInputSchema = external_exports.strictObject({
|
|
128495
|
+
session: external_exports.string().min(1),
|
|
128496
|
+
serverName: external_exports.string().min(1),
|
|
128497
|
+
redirectUri: external_exports.string().min(1)
|
|
128498
|
+
});
|
|
128499
|
+
var RcMcpOAuthCallbackUrlInputSchema = external_exports.strictObject({
|
|
128500
|
+
session: external_exports.string().min(1),
|
|
128501
|
+
serverName: external_exports.string().min(1),
|
|
128502
|
+
callbackUrl: external_exports.string().min(1)
|
|
128503
|
+
});
|
|
128504
|
+
var RcTeleportInputSchema = external_exports.strictObject({
|
|
128505
|
+
session: external_exports.string().min(1),
|
|
128506
|
+
marker: external_exports.string().min(1)
|
|
128507
|
+
});
|
|
128508
|
+
var RcListOutputSchema = external_exports.strictObject({ sessions: external_exports.readonly(external_exports.array(RcSessionSummarySchema)) });
|
|
128509
|
+
var RcStatusOutputSchema = external_exports.strictObject({ statuses: external_exports.readonly(external_exports.array(RcSessionStatusSchema)) });
|
|
128510
|
+
var RcPendingOutputSchema = external_exports.strictObject({
|
|
128511
|
+
pending: external_exports.readonly(external_exports.array(RcPendingRequestSummarySchema)),
|
|
128512
|
+
/** 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. */
|
|
128513
|
+
dropped: external_exports.readonly(external_exports.array(external_exports.strictObject({ sessionId: external_exports.string(), count: external_exports.int().positive() }))).optional()
|
|
128514
|
+
});
|
|
128515
|
+
var RcWriteOutputSchema = external_exports.strictObject({
|
|
128516
|
+
session: external_exports.string(),
|
|
128517
|
+
sequenceNums: external_exports.readonly(external_exports.array(external_exports.number()))
|
|
128518
|
+
});
|
|
128519
|
+
var RcControlWriteOutputSchema = external_exports.strictObject({
|
|
128520
|
+
session: external_exports.string(),
|
|
128521
|
+
request: external_exports.string(),
|
|
128522
|
+
sequenceNums: external_exports.readonly(external_exports.array(external_exports.number()))
|
|
128523
|
+
});
|
|
128524
|
+
var RcAnswerOutputSchema = external_exports.strictObject({
|
|
128525
|
+
session: external_exports.string(),
|
|
128526
|
+
request: external_exports.string(),
|
|
128527
|
+
sequenceNums: external_exports.readonly(external_exports.array(external_exports.number()))
|
|
128528
|
+
});
|
|
128529
|
+
|
|
128530
|
+
// src/frontdoor/rcControl.ts
|
|
128099
128531
|
var RC_PERMISSION_MODE_LIST = RC_PERMISSION_MODES.join(", ");
|
|
128100
128532
|
var CONTROL_PATH_PREFIX = "/__agent-shim/rc";
|
|
128101
128533
|
var CONTROL_BODY_CAP_BYTES = 10485760;
|
|
@@ -128352,11 +128784,20 @@ function createRcControlHandler(deps) {
|
|
|
128352
128784
|
return;
|
|
128353
128785
|
}
|
|
128354
128786
|
const text5 = "text" in parsed && typeof parsed.text === "string" ? parsed.text : void 0;
|
|
128787
|
+
const choices = "choices" in parsed ? RcQuestionChoicesSchema.safeParse(parsed.choices) : void 0;
|
|
128788
|
+
if (choices !== void 0 && !choices.success) {
|
|
128789
|
+
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": ...}' });
|
|
128790
|
+
return;
|
|
128791
|
+
}
|
|
128792
|
+
if (choices !== void 0 && !parsed.approve) {
|
|
128793
|
+
answerJson(response, HTTP_STATUS.badRequest, { error: "choices answer a question, so they come with approve: true; a denial dismisses the question" });
|
|
128794
|
+
return;
|
|
128795
|
+
}
|
|
128355
128796
|
if (parsed.approve && text5 !== void 0 && text5 !== "") {
|
|
128356
128797
|
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
128798
|
return;
|
|
128358
128799
|
}
|
|
128359
|
-
const result = await deps.answer(parsed.session, parsed.request, { approve: parsed.approve, message: parsed.approve ? void 0 : text5 });
|
|
128800
|
+
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
128801
|
if (result.ok) {
|
|
128361
128802
|
answerJson(response, HTTP_STATUS.ok, { session: parsed.session, request: parsed.request, sequenceNums: result.sequenceNums });
|
|
128362
128803
|
return;
|
|
@@ -128478,6 +128919,9 @@ function isRcSessionStatus(value3) {
|
|
|
128478
128919
|
if ("workerState" in value3 && value3.workerState !== void 0 && !isRcWorkerFact(value3.workerState, (candidate) => typeof candidate === "string")) {
|
|
128479
128920
|
return false;
|
|
128480
128921
|
}
|
|
128922
|
+
if ("pendingDropped" in value3 && value3.pendingDropped !== void 0 && typeof value3.pendingDropped !== "number") {
|
|
128923
|
+
return false;
|
|
128924
|
+
}
|
|
128481
128925
|
if ("workerIdleSeconds" in value3 && value3.workerIdleSeconds !== void 0 && !isRcWorkerFact(value3.workerIdleSeconds, (candidate) => typeof candidate === "number")) {
|
|
128482
128926
|
return false;
|
|
128483
128927
|
}
|
|
@@ -128487,13 +128931,7 @@ function isRcSessionStatus(value3) {
|
|
|
128487
128931
|
return value3.pending.every((candidate) => isRcPendingRequestSummary(candidate));
|
|
128488
128932
|
}
|
|
128489
128933
|
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";
|
|
128934
|
+
return RcPendingRequestSummarySchema.safeParse(value3).success;
|
|
128497
128935
|
}
|
|
128498
128936
|
function sequenceNumsOfBody(body) {
|
|
128499
128937
|
let parsed;
|
|
@@ -128629,7 +129067,7 @@ function frontDoorRcControl(transport, token) {
|
|
|
128629
129067
|
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
129068
|
answerRequest: async (sessionId, requestId, decision) => await writeOf(
|
|
128631
129069
|
`${CONTROL_PATH_PREFIX}/answer`,
|
|
128632
|
-
JSON.stringify({ session: sessionId, request: requestId, approve: decision.approve, ...decision.approve || decision.message === void 0 ? {} : { text: decision.message } }),
|
|
129070
|
+
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
129071
|
(status, message) => `answering control request ${requestId} on ${sessionId} failed (HTTP ${String(status)}): ${message}`
|
|
128634
129072
|
),
|
|
128635
129073
|
interruptSession: async (sessionId) => await writeOf(`${CONTROL_PATH_PREFIX}/interrupt`, JSON.stringify({ session: sessionId }), (status, message) => `interrupting ${sessionId} failed (HTTP ${String(status)}): ${message}`),
|
|
@@ -134534,7 +134972,7 @@ function getOpenAPIMeta(procedureOrLazy) {
|
|
|
134534
134972
|
// node_modules/.pnpm/@openapi-spec+downgrader@0.3.0/node_modules/@openapi-spec/downgrader/dist/shared/downgrader.DqoV5gJe.mjs
|
|
134535
134973
|
var DROP = /* @__PURE__ */ Symbol("drop");
|
|
134536
134974
|
var HTTP_METHODS = ["get", "put", "post", "delete", "options", "head", "patch", "trace"];
|
|
134537
|
-
function
|
|
134975
|
+
function isRecord13(value3) {
|
|
134538
134976
|
if (typeof value3 !== "object" || value3 === null || Array.isArray(value3)) {
|
|
134539
134977
|
return false;
|
|
134540
134978
|
}
|
|
@@ -134552,10 +134990,10 @@ function defineFields(table) {
|
|
|
134552
134990
|
return new Map(Object.entries(table));
|
|
134553
134991
|
}
|
|
134554
134992
|
function clone3(value3) {
|
|
134555
|
-
return Array.isArray(value3) ||
|
|
134993
|
+
return Array.isArray(value3) || isRecord13(value3) ? copy(value3, /* @__PURE__ */ new Map()) : value3;
|
|
134556
134994
|
}
|
|
134557
134995
|
function copy(value3, copies) {
|
|
134558
|
-
if (!(Array.isArray(value3) ||
|
|
134996
|
+
if (!(Array.isArray(value3) || isRecord13(value3))) {
|
|
134559
134997
|
return value3;
|
|
134560
134998
|
}
|
|
134561
134999
|
const known = copies.get(value3);
|
|
@@ -134580,7 +135018,7 @@ function copy(value3, copies) {
|
|
|
134580
135018
|
return out;
|
|
134581
135019
|
}
|
|
134582
135020
|
function convertObject(value3, ctx, fields, finish) {
|
|
134583
|
-
if (!
|
|
135021
|
+
if (!isRecord13(value3)) {
|
|
134584
135022
|
return clone3(value3);
|
|
134585
135023
|
}
|
|
134586
135024
|
let seen = ctx.seen.get(fields);
|
|
@@ -134609,7 +135047,7 @@ function convertObject(value3, ctx, fields, finish) {
|
|
|
134609
135047
|
}
|
|
134610
135048
|
function map2(convert, isEntry = () => true) {
|
|
134611
135049
|
return (value3, ctx) => {
|
|
134612
|
-
if (!
|
|
135050
|
+
if (!isRecord13(value3)) {
|
|
134613
135051
|
return clone3(value3);
|
|
134614
135052
|
}
|
|
134615
135053
|
const out = [];
|
|
@@ -134635,7 +135073,7 @@ function hasType(type2, name) {
|
|
|
134635
135073
|
return type2 === name || Array.isArray(type2) && type2.includes(name);
|
|
134636
135074
|
}
|
|
134637
135075
|
function getRef(value3) {
|
|
134638
|
-
return
|
|
135076
|
+
return isRecord13(value3) && typeof value3.$ref === "string" ? value3.$ref : void 0;
|
|
134639
135077
|
}
|
|
134640
135078
|
function find(root, ref) {
|
|
134641
135079
|
if (!ref.startsWith("#")) {
|
|
@@ -134653,7 +135091,7 @@ function find(root, ref) {
|
|
|
134653
135091
|
let target = root;
|
|
134654
135092
|
for (const token of pointer.split("/").slice(1)) {
|
|
134655
135093
|
const key = token.replaceAll("~1", "/").replaceAll("~0", "~");
|
|
134656
|
-
if (!(
|
|
135094
|
+
if (!(isRecord13(target) || Array.isArray(target)) || !Object.hasOwn(target, key)) {
|
|
134657
135095
|
return void 0;
|
|
134658
135096
|
}
|
|
134659
135097
|
target = target[key];
|
|
@@ -134935,7 +135373,7 @@ function losesRestriction(key, schema, exactTuple) {
|
|
|
134935
135373
|
return !exactTuple;
|
|
134936
135374
|
case "propertyNames": {
|
|
134937
135375
|
const names = schema.propertyNames;
|
|
134938
|
-
return !(names === true ||
|
|
135376
|
+
return !(names === true || isRecord13(names) && Object.entries(names).every(([name, item]) => name === "type" && item === "string"));
|
|
134939
135377
|
}
|
|
134940
135378
|
case "unevaluatedProperties":
|
|
134941
135379
|
return !(schema.additionalProperties !== void 0 || isUnevaluatedAdditional(schema));
|
|
@@ -134959,7 +135397,7 @@ function loosen(out, schema, exactTuple) {
|
|
|
134959
135397
|
delete out.oneOf;
|
|
134960
135398
|
loose = true;
|
|
134961
135399
|
}
|
|
134962
|
-
return loose || isLoose(out.items) || isLoose(out.additionalProperties) ||
|
|
135400
|
+
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
135401
|
}
|
|
134964
135402
|
function convertType(out, type2) {
|
|
134965
135403
|
if (typeof type2 === "string" && type2 !== "null") {
|
|
@@ -135092,7 +135530,7 @@ function convertOperation(value3, ctx) {
|
|
|
135092
135530
|
}
|
|
135093
135531
|
function finishMergedPathItem(out, pathItem, ctx) {
|
|
135094
135532
|
const target = inline(pathItem.$ref, ctx, convertPathItem);
|
|
135095
|
-
if (
|
|
135533
|
+
if (isRecord13(target)) {
|
|
135096
135534
|
for (const [key, item] of Object.entries(target)) {
|
|
135097
135535
|
out[key] ??= item;
|
|
135098
135536
|
}
|
|
@@ -135105,17 +135543,17 @@ function convertPathItem(value3, ctx) {
|
|
|
135105
135543
|
function schemeType(scheme, ctx) {
|
|
135106
135544
|
const ref = getRef(scheme);
|
|
135107
135545
|
const target = ref === void 0 ? scheme : resolve2(ref, ctx);
|
|
135108
|
-
return
|
|
135546
|
+
return isRecord13(target) ? target.type : void 0;
|
|
135109
135547
|
}
|
|
135110
135548
|
function convertSecurity(value3, ctx) {
|
|
135111
135549
|
if (!Array.isArray(value3)) {
|
|
135112
135550
|
return clone3(value3);
|
|
135113
135551
|
}
|
|
135114
135552
|
const schemes = resolvePointer("#/components/securitySchemes", ctx);
|
|
135115
|
-
const typeOf = (name) =>
|
|
135553
|
+
const typeOf = (name) => isRecord13(schemes) && Object.hasOwn(schemes, name) ? schemeType(schemes[name], ctx) : void 0;
|
|
135116
135554
|
const out = [];
|
|
135117
135555
|
for (const requirement of value3) {
|
|
135118
|
-
if (!
|
|
135556
|
+
if (!isRecord13(requirement)) {
|
|
135119
135557
|
out.push(clone3(requirement));
|
|
135120
135558
|
continue;
|
|
135121
135559
|
}
|
|
@@ -135254,7 +135692,7 @@ function convertSchema3(value3, ctx) {
|
|
|
135254
135692
|
return convertObject(value3, ctx, SCHEMA_FIELDS2);
|
|
135255
135693
|
}
|
|
135256
135694
|
function convertXml(value3, _ctx, schema) {
|
|
135257
|
-
if (!
|
|
135695
|
+
if (!isRecord13(value3)) {
|
|
135258
135696
|
return clone3(value3);
|
|
135259
135697
|
}
|
|
135260
135698
|
const { nodeType, ...out } = clone3(value3);
|
|
@@ -135288,7 +135726,7 @@ function convertExample(value3, ctx) {
|
|
|
135288
135726
|
return convertObject(value3, ctx, EXAMPLE_FIELDS, finishExample);
|
|
135289
135727
|
}
|
|
135290
135728
|
function isQuerystring(parameter) {
|
|
135291
|
-
return
|
|
135729
|
+
return isRecord13(parameter) && parameter.in === "querystring";
|
|
135292
135730
|
}
|
|
135293
135731
|
function finishParameter(out, parameter) {
|
|
135294
135732
|
if (parameter.content !== void 0) {
|
|
@@ -137578,177 +138016,6 @@ var ResetScheduleSchema = external_exports.strictObject({ resets: external_expor
|
|
|
137578
138016
|
var import_node_path64 = __toESM(require("node:path"), 1);
|
|
137579
138017
|
init_zod();
|
|
137580
138018
|
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
138019
|
init_state();
|
|
137753
138020
|
var UsageListOutputSchema = external_exports.strictObject({ snapshots: external_exports.readonly(external_exports.array(UsageSnapshotSchema)) });
|
|
137754
138021
|
var UsageWindowsInputSchema = external_exports.strictObject({
|
|
@@ -140983,7 +141250,7 @@ init_zod();
|
|
|
140983
141250
|
var import_promises21 = require("node:timers/promises");
|
|
140984
141251
|
|
|
140985
141252
|
// src/supervise/sessionControl.ts
|
|
140986
|
-
var
|
|
141253
|
+
var import_node_crypto28 = require("node:crypto");
|
|
140987
141254
|
var import_node_fs27 = require("node:fs");
|
|
140988
141255
|
var import_node_path65 = __toESM(require("node:path"), 1);
|
|
140989
141256
|
var import_promises20 = require("node:timers/promises");
|
|
@@ -141002,7 +141269,7 @@ function sessionControlVersion(plugin) {
|
|
|
141002
141269
|
}
|
|
141003
141270
|
var REQUEST_INSTANT_DIGITS = String(Number.MAX_SAFE_INTEGER).length;
|
|
141004
141271
|
function requestIdOf(nowMs) {
|
|
141005
|
-
return `${String(nowMs).padStart(REQUEST_INSTANT_DIGITS, "0")}-${(0,
|
|
141272
|
+
return `${String(nowMs).padStart(REQUEST_INSTANT_DIGITS, "0")}-${(0, import_node_crypto28.randomUUID)()}`;
|
|
141006
141273
|
}
|
|
141007
141274
|
function removeOrphanResults(plugin) {
|
|
141008
141275
|
const results = (0, import_node_fs27.readdirSync)(plugin.results);
|
|
@@ -141119,26 +141386,26 @@ async function writeRcPersonMessage(deps, sessionId, text5) {
|
|
|
141119
141386
|
}
|
|
141120
141387
|
return result;
|
|
141121
141388
|
}
|
|
141122
|
-
function
|
|
141389
|
+
function isRecord14(value3) {
|
|
141123
141390
|
return typeof value3 === "object" && value3 !== null && !Array.isArray(value3);
|
|
141124
141391
|
}
|
|
141125
141392
|
function rcLocalCommandAnswerOf(event, command, args) {
|
|
141126
141393
|
const payload = event.envelope.payload;
|
|
141127
|
-
if (!
|
|
141394
|
+
if (!isRecord14(payload) || payload.type !== "assistant" || !isRecord14(payload.local_command_run) || payload.local_command_run.command !== command || payload.local_command_run.args !== args) {
|
|
141128
141395
|
return void 0;
|
|
141129
141396
|
}
|
|
141130
141397
|
const message = payload.message;
|
|
141131
|
-
if (!
|
|
141398
|
+
if (!isRecord14(message) || !Array.isArray(message.content)) {
|
|
141132
141399
|
return void 0;
|
|
141133
141400
|
}
|
|
141134
141401
|
const blocks = message.content;
|
|
141135
|
-
const text5 = blocks.flatMap((block2) =>
|
|
141136
|
-
const outcome =
|
|
141402
|
+
const text5 = blocks.flatMap((block2) => isRecord14(block2) && block2.type === "text" && typeof block2.text === "string" ? [block2.text] : []).join("\n");
|
|
141403
|
+
const outcome = isRecord14(payload.local_command_outcome) && typeof payload.local_command_outcome.kind === "string" ? payload.local_command_outcome.kind : void 0;
|
|
141137
141404
|
return { text: text5, outcome };
|
|
141138
141405
|
}
|
|
141139
141406
|
function rcManualCompactBoundaryOf(event) {
|
|
141140
141407
|
const payload = event.envelope.payload;
|
|
141141
|
-
if (!
|
|
141408
|
+
if (!isRecord14(payload) || payload.type !== "system" || payload.subtype !== "compact_boundary" || !isRecord14(payload.compact_metadata)) {
|
|
141142
141409
|
return void 0;
|
|
141143
141410
|
}
|
|
141144
141411
|
const metadata = payload.compact_metadata;
|
|
@@ -141149,7 +141416,7 @@ function rcManualCompactBoundaryOf(event) {
|
|
|
141149
141416
|
}
|
|
141150
141417
|
function isPeerDelivery(event, text5) {
|
|
141151
141418
|
const payload = event.envelope.payload;
|
|
141152
|
-
if (!
|
|
141419
|
+
if (!isRecord14(payload) || payload.type !== "user" || !isRecord14(payload.origin) || payload.origin.kind !== "peer" || !isRecord14(payload.message)) {
|
|
141153
141420
|
return false;
|
|
141154
141421
|
}
|
|
141155
141422
|
return typeof payload.message.content === "string" && payload.message.content.includes(text5);
|
|
@@ -141266,7 +141533,7 @@ function createRcClaudeCodeVersions(fanout) {
|
|
|
141266
141533
|
const versions = /* @__PURE__ */ new Map();
|
|
141267
141534
|
fanout.subscribe(void 0, (event) => {
|
|
141268
141535
|
const payload = event.envelope.payload;
|
|
141269
|
-
if (event.envelope.source === "worker" &&
|
|
141536
|
+
if (event.envelope.source === "worker" && isRecord14(payload) && payload.type === "system" && payload.subtype === "init" && typeof payload.claude_code_version === "string") {
|
|
141270
141537
|
versions.set(event.session, payload.claude_code_version);
|
|
141271
141538
|
}
|
|
141272
141539
|
});
|
|
@@ -141572,14 +141839,16 @@ function createRcApiRouter(deps) {
|
|
|
141572
141839
|
}),
|
|
141573
141840
|
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
141841
|
const pending = deps.pendingOf(input2.session);
|
|
141575
|
-
|
|
141842
|
+
const statuses = deps.statusOf(input2.session);
|
|
141843
|
+
if (input2.session !== void 0 && statuses.length === 0) {
|
|
141576
141844
|
throw new ORPCError("NOT_FOUND", { message: rcSessionNotObservedMessage(input2.session) });
|
|
141577
141845
|
}
|
|
141578
|
-
|
|
141846
|
+
const dropped = statuses.flatMap((status) => status.pendingDropped === void 0 ? [] : [{ sessionId: status.id, count: status.pendingDropped }]);
|
|
141847
|
+
return { pending, ...dropped.length === 0 ? {} : { dropped } };
|
|
141579
141848
|
}),
|
|
141580
141849
|
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 };
|
|
141850
|
+
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 }) => {
|
|
141851
|
+
const decision = { approve: input2.approve, message: input2.approve || input2.text === void 0 ? void 0 : input2.text, ...input2.choices === void 0 ? {} : { choices: input2.choices } };
|
|
141583
141852
|
return { session: input2.session, request: input2.request, sequenceNums: delivered(input2.session, await deps.answer(input2.session, input2.request, decision)) };
|
|
141584
141853
|
}),
|
|
141585
141854
|
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 +142942,8 @@ function rcFanoutOnDoorHub(fanout, hub) {
|
|
|
142673
142942
|
|
|
142674
142943
|
// src/frontdoor/rcEventLog.ts
|
|
142675
142944
|
var RC_SESSION_EVENT_TOKEN_MAX_CHARS = 255;
|
|
142676
|
-
var
|
|
142677
|
-
var
|
|
142945
|
+
var HIGH_SURROGATE_FIRST2 = 55296;
|
|
142946
|
+
var HIGH_SURROGATE_LAST2 = 56319;
|
|
142678
142947
|
var LOW_SURROGATE_FIRST = 56320;
|
|
142679
142948
|
var LOW_SURROGATE_LAST = 57343;
|
|
142680
142949
|
var CUT_MARKER = "...";
|
|
@@ -142685,7 +142954,7 @@ var NUMBER_BYTES = Float64Array.BYTES_PER_ELEMENT;
|
|
|
142685
142954
|
var NUMBER_FIELDS = ["at", "sequence"].length;
|
|
142686
142955
|
var BYTES_PER_CODE_UNIT = Uint16Array.BYTES_PER_ELEMENT;
|
|
142687
142956
|
var RC_SESSION_END_REASONS = ["expired", "archived", "conflict"];
|
|
142688
|
-
var RC_PENDING_RETIRE_REASONS = ["answered", "
|
|
142957
|
+
var RC_PENDING_RETIRE_REASONS = ["answered", "withdrawn", "worker-stopped", "session-ended"];
|
|
142689
142958
|
var transitionBase = { session: external_exports.string(), at: external_exports.number() };
|
|
142690
142959
|
var cursorFields = { cursor: external_exports.string(), sequence: external_exports.int().positive() };
|
|
142691
142960
|
var sessionAppearedShape = { kind: external_exports.literal("session-appeared"), ...transitionBase };
|
|
@@ -142746,7 +143015,7 @@ function parseCursor(cursor3) {
|
|
|
142746
143015
|
function codePointBoundary(text5, at2) {
|
|
142747
143016
|
const before = text5.charCodeAt(at2 - 1);
|
|
142748
143017
|
const after = text5.charCodeAt(at2);
|
|
142749
|
-
const isHigh = before >=
|
|
143018
|
+
const isHigh = before >= HIGH_SURROGATE_FIRST2 && before <= HIGH_SURROGATE_LAST2;
|
|
142750
143019
|
const isLow = after >= LOW_SURROGATE_FIRST && after <= LOW_SURROGATE_LAST;
|
|
142751
143020
|
return isHigh && isLow ? at2 - 1 : at2;
|
|
142752
143021
|
}
|
|
@@ -143215,7 +143484,7 @@ init_connect();
|
|
|
143215
143484
|
init_route();
|
|
143216
143485
|
|
|
143217
143486
|
// src/frontdoor/lineage.ts
|
|
143218
|
-
var
|
|
143487
|
+
var import_node_crypto29 = require("node:crypto");
|
|
143219
143488
|
var CACHE_MARKER_KEY = '"cache_control"';
|
|
143220
143489
|
var THREAD_MEMBER_KEYS = /* @__PURE__ */ new Set(['"model"', '"system"', '"tools"']);
|
|
143221
143490
|
var MESSAGES_KEY = '"messages"';
|
|
@@ -143292,8 +143561,8 @@ function nextToken(body, from) {
|
|
|
143292
143561
|
return SCALAR;
|
|
143293
143562
|
}
|
|
143294
143563
|
function walk2(body, hashing, parentAfter) {
|
|
143295
|
-
const thread = (0,
|
|
143296
|
-
const messages = (0,
|
|
143564
|
+
const thread = (0, import_node_crypto29.createHash)("sha256");
|
|
143565
|
+
const messages = (0, import_node_crypto29.createHash)("sha256");
|
|
143297
143566
|
let parentDigest;
|
|
143298
143567
|
let elements = 0;
|
|
143299
143568
|
let depth = 0;
|
|
@@ -143414,7 +143683,7 @@ function lineageOf(body) {
|
|
|
143414
143683
|
}
|
|
143415
143684
|
const parentAfter = counted3.elements > MESSAGES_PER_TURN ? counted3.elements - MESSAGES_PER_TURN : void 0;
|
|
143416
143685
|
const hashed = walk2(body, true, parentAfter);
|
|
143417
|
-
const combine = (messagesDigest) => (0,
|
|
143686
|
+
const combine = (messagesDigest) => (0, import_node_crypto29.createHash)("sha256").update(hashed.threadDigest).update(messagesDigest).digest("hex");
|
|
143418
143687
|
return { ownKey: combine(hashed.messagesDigest), parentKey: hashed.parentDigest === void 0 ? void 0 : combine(hashed.parentDigest) };
|
|
143419
143688
|
}
|
|
143420
143689
|
|
|
@@ -144532,7 +144801,7 @@ function createCodexRouteMount(ports, upstreamBase, provider) {
|
|
|
144532
144801
|
}
|
|
144533
144802
|
|
|
144534
144803
|
// src/antigravity/route.ts
|
|
144535
|
-
var
|
|
144804
|
+
var import_node_crypto30 = require("node:crypto");
|
|
144536
144805
|
init_route();
|
|
144537
144806
|
init_anthropic();
|
|
144538
144807
|
|
|
@@ -144875,7 +145144,7 @@ var AcpStreamMessageSchema = external_exports.looseObject({
|
|
|
144875
145144
|
chunk: external_exports.looseObject({}).optional()
|
|
144876
145145
|
}).optional()
|
|
144877
145146
|
});
|
|
144878
|
-
function
|
|
145147
|
+
function isRecord15(value3) {
|
|
144879
145148
|
return typeof value3 === "object" && value3 !== null && !Array.isArray(value3);
|
|
144880
145149
|
}
|
|
144881
145150
|
function normalizeFinishReason(reason) {
|
|
@@ -144900,7 +145169,7 @@ function parseJsonRecord(raw) {
|
|
|
144900
145169
|
}
|
|
144901
145170
|
try {
|
|
144902
145171
|
const parsed = JSON.parse(raw);
|
|
144903
|
-
if (
|
|
145172
|
+
if (isRecord15(parsed)) {
|
|
144904
145173
|
return parsed;
|
|
144905
145174
|
}
|
|
144906
145175
|
} catch {
|
|
@@ -144996,7 +145265,7 @@ function exhaustedMessage(exhaustion) {
|
|
|
144996
145265
|
return `Antigravity ${window} limit reached; it resets at ${new Date(exhaustion.resetSec * MS_PER_SECOND13).toISOString()}.`;
|
|
144997
145266
|
}
|
|
144998
145267
|
function createAntigravityRoute(ports) {
|
|
144999
|
-
const fallbackId = ports.fallbackId ?? (() => (0,
|
|
145268
|
+
const fallbackId = ports.fallbackId ?? (() => (0, import_node_crypto30.randomUUID)());
|
|
145000
145269
|
const lastRouted = ports.lastRouted ?? /* @__PURE__ */ new Map();
|
|
145001
145270
|
const exhaustedModels = ports.exhaustedModels ?? /* @__PURE__ */ new Map();
|
|
145002
145271
|
const liveQuota = (nowMs) => {
|
|
@@ -146124,7 +146393,7 @@ function predecessorOfThisProcess() {
|
|
|
146124
146393
|
init_realFrontDoorPort();
|
|
146125
146394
|
|
|
146126
146395
|
// src/frontdoor/rcCommands.ts
|
|
146127
|
-
var
|
|
146396
|
+
var import_node_crypto31 = require("node:crypto");
|
|
146128
146397
|
init_commandDeps();
|
|
146129
146398
|
init_cliError();
|
|
146130
146399
|
init_realPorts();
|
|
@@ -146264,15 +146533,15 @@ function registerRcEventsCommand(rc, paths) {
|
|
|
146264
146533
|
|
|
146265
146534
|
// src/frontdoor/rcLiveUsage.ts
|
|
146266
146535
|
var RC_RATE_LIMIT_EVENT_TYPE = "rate_limit_event";
|
|
146267
|
-
function
|
|
146536
|
+
function isRecord16(value3) {
|
|
146268
146537
|
return typeof value3 === "object" && value3 !== null && !Array.isArray(value3);
|
|
146269
146538
|
}
|
|
146270
146539
|
function rcRateLimitInfoOf(event) {
|
|
146271
146540
|
const payload = event.envelope.payload;
|
|
146272
|
-
if (!
|
|
146541
|
+
if (!isRecord16(payload) || payload.type !== RC_RATE_LIMIT_EVENT_TYPE) {
|
|
146273
146542
|
return void 0;
|
|
146274
146543
|
}
|
|
146275
|
-
if (!
|
|
146544
|
+
if (!isRecord16(payload.rate_limit_info)) {
|
|
146276
146545
|
return void 0;
|
|
146277
146546
|
}
|
|
146278
146547
|
const parsed = RcRateLimitInfoSchema.safeParse(payload.rate_limit_info);
|
|
@@ -146309,7 +146578,7 @@ var RC_SELF_HOST_SCOPE_LIST = ["user:profile", "user:inference", "user:sessions:
|
|
|
146309
146578
|
var RC_SELF_HOST_OAUTH_TOKEN_TTL_SECONDS = 3600;
|
|
146310
146579
|
var MS_PER_SECOND14 = 1e3;
|
|
146311
146580
|
var HTTP_SERVICE_UNAVAILABLE = 503;
|
|
146312
|
-
function
|
|
146581
|
+
function isRecord17(value3) {
|
|
146313
146582
|
return typeof value3 === "object" && value3 !== null && !Array.isArray(value3);
|
|
146314
146583
|
}
|
|
146315
146584
|
function parseJsonObject2(body) {
|
|
@@ -146319,7 +146588,7 @@ function parseJsonObject2(body) {
|
|
|
146319
146588
|
} catch {
|
|
146320
146589
|
return void 0;
|
|
146321
146590
|
}
|
|
146322
|
-
return
|
|
146591
|
+
return isRecord17(parsed) ? parsed : void 0;
|
|
146323
146592
|
}
|
|
146324
146593
|
function growthBookFeatures() {
|
|
146325
146594
|
return {
|
|
@@ -146413,7 +146682,7 @@ var RC_SELF_HOST_RECORD_DIR = "rc-selfhost";
|
|
|
146413
146682
|
var RC_SELF_HOST_RECORD_FILE = "credential.json";
|
|
146414
146683
|
var SELF_HOST_EMAIL = "selfhost@agent-shim.invalid";
|
|
146415
146684
|
var SELF_HOST_SUBSCRIPTION_TYPE = "max";
|
|
146416
|
-
function
|
|
146685
|
+
function isRecord18(value3) {
|
|
146417
146686
|
return typeof value3 === "object" && value3 !== null && !Array.isArray(value3);
|
|
146418
146687
|
}
|
|
146419
146688
|
function readJsonObject(fs37, file2) {
|
|
@@ -146427,7 +146696,7 @@ function readJsonObject(fs37, file2) {
|
|
|
146427
146696
|
} catch {
|
|
146428
146697
|
return void 0;
|
|
146429
146698
|
}
|
|
146430
|
-
return
|
|
146699
|
+
return isRecord18(parsed) ? parsed : void 0;
|
|
146431
146700
|
}
|
|
146432
146701
|
function readRcSelfHostRecord(fs37, frontdoorDir) {
|
|
146433
146702
|
const parsed = readJsonObject(fs37, import_node_path69.default.join(frontdoorDir, RC_SELF_HOST_RECORD_DIR, RC_SELF_HOST_RECORD_FILE));
|
|
@@ -146455,7 +146724,7 @@ function mintRcSelfHostCredential(deps) {
|
|
|
146455
146724
|
const recordFile3 = import_node_path69.default.join(recordDir, RC_SELF_HOST_RECORD_FILE);
|
|
146456
146725
|
const previousRecord = readRcSelfHostRecord(deps.fs, deps.frontdoorDir);
|
|
146457
146726
|
const existingCredentials = readJsonObject(deps.fs, credentialsFile);
|
|
146458
|
-
const existingOauth =
|
|
146727
|
+
const existingOauth = isRecord18(existingCredentials?.claudeAiOauth) ? existingCredentials.claudeAiOauth : void 0;
|
|
146459
146728
|
const existingToken = typeof existingOauth?.accessToken === "string" && existingOauth.accessToken !== "" ? existingOauth.accessToken : void 0;
|
|
146460
146729
|
const existingIsOwn = existingToken !== void 0 && previousRecord?.accessToken === existingToken;
|
|
146461
146730
|
if (existingToken !== void 0 && !existingIsOwn && !deps.force) {
|
|
@@ -146472,7 +146741,7 @@ function mintRcSelfHostCredential(deps) {
|
|
|
146472
146741
|
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
146742
|
`);
|
|
146474
146743
|
const claudeJson = readJsonObject(deps.fs, claudeJsonFile) ?? {};
|
|
146475
|
-
const existingBlock = (value3) =>
|
|
146744
|
+
const existingBlock = (value3) => isRecord18(value3) ? value3 : {};
|
|
146476
146745
|
deps.fs.writeFilePrivate(claudeJsonFile, `${JSON.stringify({
|
|
146477
146746
|
...claudeJson,
|
|
146478
146747
|
oauthAccount: {
|
|
@@ -146548,6 +146817,9 @@ function formatRcSessionStatus(statuses) {
|
|
|
146548
146817
|
lines.push(...formatRcPendingList([pending]).map((line) => ` ${line}`));
|
|
146549
146818
|
}
|
|
146550
146819
|
}
|
|
146820
|
+
if (status.pendingDropped !== void 0) {
|
|
146821
|
+
lines.push(` pending dropped: ${String(status.pendingDropped)} request(s) not listed (the per-session cap, or an id the protocol does not mint)`);
|
|
146822
|
+
}
|
|
146551
146823
|
}
|
|
146552
146824
|
return lines;
|
|
146553
146825
|
}
|
|
@@ -146555,10 +146827,50 @@ function formatRcPendingList(pending) {
|
|
|
146555
146827
|
if (pending.length === 0) {
|
|
146556
146828
|
return ["no pending control requests observed"];
|
|
146557
146829
|
}
|
|
146558
|
-
return pending.
|
|
146830
|
+
return pending.flatMap((request7) => {
|
|
146831
|
+
const observed = `observed ${new Date(request7.observedAt).toISOString()}`;
|
|
146832
|
+
if (request7.questions === void 0) {
|
|
146833
|
+
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]" : "";
|
|
146834
|
+
return [`${request7.sessionId} ${request7.requestId} ${request7.type}${request7.summary === "" ? "" : ` ${request7.summary}`} ${observed}${mark}`];
|
|
146835
|
+
}
|
|
146836
|
+
return [
|
|
146837
|
+
`${request7.sessionId} ${request7.requestId} question ${observed}`,
|
|
146838
|
+
...request7.questions.flatMap((question, index) => [
|
|
146839
|
+
` ${String(index + 1)}. ${question.header === void 0 ? "" : `[${question.header}] `}${question.question}${question.multiSelect ? " (choose one or more)" : " (choose one)"}`,
|
|
146840
|
+
...question.options.map((option, optionIndex) => ` ${String(optionIndex + 1)}) ${option.label}${option.description === void 0 ? "" : `: ${option.description}`}`)
|
|
146841
|
+
])
|
|
146842
|
+
];
|
|
146843
|
+
});
|
|
146844
|
+
}
|
|
146845
|
+
function formatRcDroppedPending(dropped) {
|
|
146846
|
+
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
146847
|
}
|
|
146560
|
-
|
|
146561
|
-
|
|
146848
|
+
var CHOICE_FLAG_SEPARATOR = ":";
|
|
146849
|
+
var OPTION_NUMBER = /^\d+$/;
|
|
146850
|
+
function parseRcChoiceFlags(choose, other) {
|
|
146851
|
+
const byQuestion = /* @__PURE__ */ new Map();
|
|
146852
|
+
const entries = [...choose.map((value3) => ({ flag: "--choose", value: value3 })), ...other.map((value3) => ({ flag: "--other", value: value3 }))];
|
|
146853
|
+
for (const { flag, value: value3 } of entries) {
|
|
146854
|
+
const at2 = value3.indexOf(CHOICE_FLAG_SEPARATOR);
|
|
146855
|
+
const questionText = at2 === -1 ? "" : value3.slice(0, at2);
|
|
146856
|
+
const selectionText = at2 === -1 ? "" : value3.slice(at2 + 1);
|
|
146857
|
+
const question = Number(questionText);
|
|
146858
|
+
if (!OPTION_NUMBER.test(questionText) || question < 1 || selectionText === "") {
|
|
146859
|
+
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` };
|
|
146860
|
+
}
|
|
146861
|
+
const selection = flag === "--other" ? { text: selectionText } : OPTION_NUMBER.test(selectionText) ? Number(selectionText) : selectionText;
|
|
146862
|
+
byQuestion.set(question, [...byQuestion.get(question) ?? [], selection]);
|
|
146863
|
+
}
|
|
146864
|
+
const highest = Math.max(...byQuestion.keys());
|
|
146865
|
+
const choices = [];
|
|
146866
|
+
for (let question = 1; question <= highest; question += 1) {
|
|
146867
|
+
const selections = byQuestion.get(question);
|
|
146868
|
+
if (selections === void 0) {
|
|
146869
|
+
return { error: `question ${String(question)} has no --choose or --other, but question ${String(highest)} does: answer every question` };
|
|
146870
|
+
}
|
|
146871
|
+
choices.push(selections);
|
|
146872
|
+
}
|
|
146873
|
+
return { choices };
|
|
146562
146874
|
}
|
|
146563
146875
|
var PERCENT_SCALE = 100;
|
|
146564
146876
|
var MS_PER_SECOND15 = 1e3;
|
|
@@ -146607,7 +146919,7 @@ function formatRcRateLimitInfo(info) {
|
|
|
146607
146919
|
function formatRcStreamEvent(event) {
|
|
146608
146920
|
const { envelope: envelope2 } = event;
|
|
146609
146921
|
const rateLimit = rcRateLimitInfoOf(event);
|
|
146610
|
-
const sketch = rateLimit !== void 0 ? ` ${formatRcRateLimitInfo(rateLimit)}` : envelope2.payload === void 0 ? "" : ` ${
|
|
146922
|
+
const sketch = rateLimit !== void 0 ? ` ${formatRcRateLimitInfo(rateLimit)}` : envelope2.payload === void 0 ? "" : ` ${rcExcerpt(JSON.stringify(envelope2.payload))}`;
|
|
146611
146923
|
return `${event.session} ${envelope2.event_type} sequence_num ${String(envelope2.sequence_num)} source ${envelope2.source}${sketch}`;
|
|
146612
146924
|
}
|
|
146613
146925
|
function formatRcSelfHostMint(result) {
|
|
@@ -146660,12 +146972,14 @@ function registerRcCommand(frontdoor, paths) {
|
|
|
146660
146972
|
);
|
|
146661
146973
|
withExamples(
|
|
146662
146974
|
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
|
|
146975
|
+
const control = frontDoorRcControlFromState(realFarmFs, paths);
|
|
146976
|
+
const pending = await control.pendingOf(session);
|
|
146977
|
+
const dropped = (await control.statusOf(session)).flatMap((status) => status.pendingDropped === void 0 ? [] : [{ sessionId: status.id, count: status.pendingDropped }]);
|
|
146664
146978
|
if (options.json === true) {
|
|
146665
|
-
printJson({ pending });
|
|
146979
|
+
printJson({ pending, ...dropped.length === 0 ? {} : { dropped } });
|
|
146666
146980
|
return;
|
|
146667
146981
|
}
|
|
146668
|
-
for (const line of formatRcPendingList(pending)) {
|
|
146982
|
+
for (const line of [...formatRcPendingList(pending), ...formatRcDroppedPending(dropped)]) {
|
|
146669
146983
|
console.log(line);
|
|
146670
146984
|
}
|
|
146671
146985
|
}),
|
|
@@ -146686,14 +147000,19 @@ function registerRcCommand(frontdoor, paths) {
|
|
|
146686
147000
|
['agent-shim frontdoor rc send --session cse_00000000-0000-4000-8000-000000000000 --text "run the tests"']
|
|
146687
147001
|
);
|
|
146688
147002
|
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
|
-
|
|
147003
|
+
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) => {
|
|
147004
|
+
const choosing = options.choose.length > 0 || options.other.length > 0;
|
|
147005
|
+
if ([options.approve === true, options.deny === true, choosing].filter(Boolean).length !== 1) {
|
|
147006
|
+
throw new UsageError("answer exactly one way: pass --approve, --deny, or the --choose and --other selections of a question");
|
|
146692
147007
|
}
|
|
146693
|
-
if (options.
|
|
147008
|
+
if (options.deny !== true && options.text !== void 0) {
|
|
146694
147009
|
throw new UsageError("--text is the denial message; an approval carries no text (the protocol's allow result has no message field)");
|
|
146695
147010
|
}
|
|
146696
|
-
const
|
|
147011
|
+
const choices = choosing ? parseRcChoiceFlags(options.choose, options.other) : void 0;
|
|
147012
|
+
if (choices !== void 0 && "error" in choices) {
|
|
147013
|
+
throw new UsageError(choices.error);
|
|
147014
|
+
}
|
|
147015
|
+
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
147016
|
if (!result.ok) {
|
|
146698
147017
|
throw new Error(result.message);
|
|
146699
147018
|
}
|
|
@@ -146701,11 +147020,13 @@ function registerRcCommand(frontdoor, paths) {
|
|
|
146701
147020
|
printJson({ session: options.session, request: options.request, sequenceNums: result.sequenceNums });
|
|
146702
147021
|
return;
|
|
146703
147022
|
}
|
|
146704
|
-
console.log(`${options.approve === true ? "approved" : "denied"} ${options.request} on ${options.session}: sequence_num ${result.sequenceNums.join(", ")}`);
|
|
147023
|
+
console.log(`${choosing ? "answered" : options.approve === true ? "approved" : "denied"} ${options.request} on ${options.session}: sequence_num ${result.sequenceNums.join(", ")}`);
|
|
146705
147024
|
}),
|
|
146706
147025
|
[
|
|
146707
147026
|
"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"'
|
|
147027
|
+
'agent-shim frontdoor rc answer --session cse_00000000-0000-4000-8000-000000000000 --request req_00000000-0000-4000-8000-000000000000 --deny --text "not today"',
|
|
147028
|
+
"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",
|
|
147029
|
+
"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
147030
|
]
|
|
146710
147031
|
);
|
|
146711
147032
|
withExamples(
|
|
@@ -146911,8 +147232,8 @@ last check: ${answer.goal.lastCheck}`}`);
|
|
|
146911
147232
|
identitiesDir: paths.identitiesDir,
|
|
146912
147233
|
frontdoorDir: paths.frontdoorDir,
|
|
146913
147234
|
identity,
|
|
146914
|
-
newUuid:
|
|
146915
|
-
randomToken: () => (0,
|
|
147235
|
+
newUuid: import_node_crypto31.randomUUID,
|
|
147236
|
+
randomToken: () => (0, import_node_crypto31.randomBytes)(MINTED_TOKEN_RANDOM_BYTES).toString("base64url"),
|
|
146916
147237
|
force: options.force === true,
|
|
146917
147238
|
now: () => Date.now()
|
|
146918
147239
|
});
|
|
@@ -146933,11 +147254,11 @@ var import_node_path70 = __toESM(require("node:path"), 1);
|
|
|
146933
147254
|
function isSafeSessionId(sessionId) {
|
|
146934
147255
|
return /^[A-Za-z0-9_-]+$/.test(sessionId);
|
|
146935
147256
|
}
|
|
146936
|
-
function
|
|
147257
|
+
function isRecord19(value3) {
|
|
146937
147258
|
return typeof value3 === "object" && value3 !== null && !Array.isArray(value3);
|
|
146938
147259
|
}
|
|
146939
147260
|
function credentialOfJson(parsed) {
|
|
146940
|
-
if (!
|
|
147261
|
+
if (!isRecord19(parsed)) {
|
|
146941
147262
|
return void 0;
|
|
146942
147263
|
}
|
|
146943
147264
|
const { authorization, anthropicVersion, anthropicClientPlatform } = parsed;
|
|
@@ -146967,7 +147288,7 @@ function createRcCredentialStore(fs37, dir) {
|
|
|
146967
147288
|
} catch {
|
|
146968
147289
|
return void 0;
|
|
146969
147290
|
}
|
|
146970
|
-
return
|
|
147291
|
+
return isRecord19(parsed) ? parsed : void 0;
|
|
146971
147292
|
};
|
|
146972
147293
|
return {
|
|
146973
147294
|
read: (sessionId) => {
|
|
@@ -147206,41 +147527,114 @@ function selectSession(id) {
|
|
|
147206
147527
|
};
|
|
147207
147528
|
}
|
|
147208
147529
|
|
|
147209
|
-
|
|
147530
|
+
// 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.
|
|
147531
|
+
function pendingKey(pending, dropped) {
|
|
147532
|
+
return pending.map(function (request) { return request.sessionId + '/' + request.requestId; }).concat(dropped.map(function (entry) { return entry.sessionId + '#' + String(entry.count); })).join(' ');
|
|
147533
|
+
}
|
|
147534
|
+
|
|
147535
|
+
// 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.
|
|
147536
|
+
function answerChoices(picked, typed, multiSelect) {
|
|
147537
|
+
var choices = [];
|
|
147538
|
+
for (var q = 0; q < picked.length; q++) {
|
|
147539
|
+
var text = typed[q] === undefined ? '' : typed[q].trim();
|
|
147540
|
+
var chosen = text !== '' && multiSelect[q] !== true ? [] : picked[q].slice();
|
|
147541
|
+
if (text !== '') { chosen.push({ text: text }); }
|
|
147542
|
+
if (chosen.length === 0) { return { error: 'choose an option for question ' + String(q + 1) + ', or type an answer' }; }
|
|
147543
|
+
choices.push(chosen);
|
|
147544
|
+
}
|
|
147545
|
+
return { choices: choices };
|
|
147546
|
+
}
|
|
147547
|
+
|
|
147548
|
+
function renderPending(pending, dropped) {
|
|
147210
147549
|
if (ui === null) { return; }
|
|
147550
|
+
var key = pendingKey(pending, dropped);
|
|
147551
|
+
if (ui.pendingKey === key) { return; }
|
|
147552
|
+
ui.pendingKey = key;
|
|
147211
147553
|
var list = ui.pendingList;
|
|
147212
147554
|
list.textContent = '';
|
|
147213
|
-
|
|
147555
|
+
// 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.
|
|
147556
|
+
for (var d = 0; d < dropped.length; d++) {
|
|
147557
|
+
list.appendChild(el('div', 'event dim', shortId(dropped[d].sessionId) + ' ' + String(dropped[d].count) + ' request(s) not listed; answer them in the session'));
|
|
147558
|
+
}
|
|
147559
|
+
if (pending.length === 0 && dropped.length === 0) {
|
|
147214
147560
|
list.appendChild(el('div', 'event dim', 'no control requests awaiting an answer'));
|
|
147215
147561
|
return;
|
|
147216
147562
|
}
|
|
147217
147563
|
for (var i = 0; i < pending.length; i++) {
|
|
147218
147564
|
var request = pending[i];
|
|
147219
147565
|
var card = el('div', 'card');
|
|
147220
|
-
|
|
147566
|
+
var answerable = Array.isArray(request.questions);
|
|
147567
|
+
// 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.
|
|
147568
|
+
var isQuestion = answerable || request.unanswerable !== undefined;
|
|
147569
|
+
card.appendChild(el('div', null, isQuestion ? 'question' : request.type + ' ' + (request.summary === '' ? shortId(request.requestId) : request.summary)));
|
|
147221
147570
|
card.appendChild(el('div', 'dim', shortId(request.sessionId) + ' ' + shortId(request.requestId) + ' observed ' + new Date(request.observedAt).toLocaleTimeString()));
|
|
147571
|
+
if (isQuestion && !answerable) {
|
|
147572
|
+
card.appendChild(el('div', 'dim', 'the door cannot answer this question (' + request.unanswerable + '); answer it in the session, or dismiss it'));
|
|
147573
|
+
}
|
|
147574
|
+
var pickers = answerable ? renderQuestions(card, request) : null;
|
|
147222
147575
|
var row = el('div', 'row');
|
|
147223
147576
|
var denial = el('input');
|
|
147224
147577
|
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));
|
|
147578
|
+
denial.placeholder = isQuestion ? 'dismissal message (optional)' : 'denial message (optional)';
|
|
147579
|
+
var approve = el('button', null, isQuestion ? 'Answer' : 'Approve');
|
|
147580
|
+
var deny = el('button', 'secondary', isQuestion ? 'Dismiss' : 'Deny');
|
|
147581
|
+
approve.addEventListener('click', answerRequest(request, true, denial, pickers));
|
|
147582
|
+
deny.addEventListener('click', answerRequest(request, false, denial, null));
|
|
147230
147583
|
row.appendChild(denial);
|
|
147231
|
-
row.appendChild(approve);
|
|
147584
|
+
if (!isQuestion || answerable) { row.appendChild(approve); }
|
|
147232
147585
|
row.appendChild(deny);
|
|
147233
147586
|
card.appendChild(row);
|
|
147234
147587
|
list.appendChild(card);
|
|
147235
147588
|
}
|
|
147236
147589
|
}
|
|
147237
147590
|
|
|
147238
|
-
|
|
147591
|
+
// 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.
|
|
147592
|
+
function renderQuestions(card, request) {
|
|
147593
|
+
var groups = [];
|
|
147594
|
+
for (var q = 0; q < request.questions.length; q++) {
|
|
147595
|
+
var question = request.questions[q];
|
|
147596
|
+
var block = el('div', 'question');
|
|
147597
|
+
block.appendChild(el('div', null, (question.header === undefined ? '' : '[' + question.header + '] ') + question.question + (question.multiSelect ? ' (choose one or more)' : '')));
|
|
147598
|
+
var inputs = [];
|
|
147599
|
+
for (var o = 0; o < question.options.length; o++) {
|
|
147600
|
+
var option = question.options[o];
|
|
147601
|
+
var label = el('label', 'option');
|
|
147602
|
+
var box = el('input');
|
|
147603
|
+
box.type = question.multiSelect ? 'checkbox' : 'radio';
|
|
147604
|
+
box.name = request.requestId + '-' + String(q);
|
|
147605
|
+
box.value = option.label;
|
|
147606
|
+
label.appendChild(box);
|
|
147607
|
+
label.appendChild(document.createTextNode(' ' + option.label + (option.description === undefined ? '' : ': ' + option.description)));
|
|
147608
|
+
block.appendChild(label);
|
|
147609
|
+
inputs.push(box);
|
|
147610
|
+
}
|
|
147611
|
+
var other = el('input');
|
|
147612
|
+
other.type = 'text';
|
|
147613
|
+
other.placeholder = question.multiSelect ? 'or add your own answer' : 'or type your own answer';
|
|
147614
|
+
block.appendChild(other);
|
|
147615
|
+
groups.push({ inputs: inputs, other: other });
|
|
147616
|
+
card.appendChild(block);
|
|
147617
|
+
}
|
|
147618
|
+
return function () {
|
|
147619
|
+
return answerChoices(
|
|
147620
|
+
groups.map(function (group) { return group.inputs.filter(function (box) { return box.checked; }).map(function (box) { return box.value; }); }),
|
|
147621
|
+
groups.map(function (group) { return group.other.value; }),
|
|
147622
|
+
request.questions.map(function (question) { return question.multiSelect === true; })
|
|
147623
|
+
);
|
|
147624
|
+
};
|
|
147625
|
+
}
|
|
147626
|
+
|
|
147627
|
+
function answerRequest(request, approve, denialInput, pickers) {
|
|
147239
147628
|
return function () {
|
|
147240
147629
|
var input = { session: request.sessionId, request: request.requestId, approve: approve };
|
|
147241
147630
|
if (!approve && denialInput.value !== '') { input.text = denialInput.value; }
|
|
147631
|
+
if (approve && pickers !== null) {
|
|
147632
|
+
var built = pickers();
|
|
147633
|
+
if (built.error !== undefined) { window.alert(built.error); return; }
|
|
147634
|
+
input.choices = built.choices;
|
|
147635
|
+
}
|
|
147242
147636
|
rpc('rc/answer', input).then(function () {
|
|
147243
|
-
renderEvent({ source: 'page', sequence: 0, payload: { note: (approve ? 'approved' : 'denied') + ' ' + request.requestId } }, 0);
|
|
147637
|
+
renderEvent({ source: 'page', sequence: 0, payload: { note: (pickers !== null ? 'answered' : approve ? 'approved' : 'denied') + ' ' + request.requestId } }, 0);
|
|
147244
147638
|
refreshPending();
|
|
147245
147639
|
}, function (error) { window.alert('answer failed: ' + error.message); });
|
|
147246
147640
|
};
|
|
@@ -147262,7 +147656,7 @@ function refreshSessions() {
|
|
|
147262
147656
|
}
|
|
147263
147657
|
|
|
147264
147658
|
function refreshPending() {
|
|
147265
|
-
rpc('rc/pending', ui !== null && ui.selected !== null ? { session: ui.selected } : {}).then(function (result) { renderPending(result.pending); }, authOrReport('rc/pending'));
|
|
147659
|
+
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
147660
|
}
|
|
147267
147661
|
|
|
147268
147662
|
// 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 +147836,8 @@ var RC_CLIENT_PAGE_HTML = `<!doctype html>
|
|
|
147442
147836
|
.row { display: flex; gap: 8px; margin: 6px 0; align-items: center; }
|
|
147443
147837
|
.card { border: 1px solid #3d6ea5; border-radius: 4px; padding: 8px; margin: 6px 0; background: #17222e; }
|
|
147444
147838
|
.card .dim { color: #8b98a5; }
|
|
147839
|
+
.card .question { margin: 6px 0; }
|
|
147840
|
+
.card .option { display: block; margin-left: 12px; }
|
|
147445
147841
|
#token-form { max-width: 480px; margin: 48px auto; }
|
|
147446
147842
|
#token-form p { color: #8b98a5; }
|
|
147447
147843
|
.hidden { display: none !important; }
|
|
@@ -147541,7 +147937,7 @@ function withClientPlatform(payload, headers) {
|
|
|
147541
147937
|
const platform = headers[CLIENT_PLATFORM_HEADER];
|
|
147542
147938
|
return typeof platform === "string" && platform !== "" ? { ...rest, client_platform: platform } : rest;
|
|
147543
147939
|
}
|
|
147544
|
-
function
|
|
147940
|
+
function isRecord20(value3) {
|
|
147545
147941
|
return typeof value3 === "object" && value3 !== null && !Array.isArray(value3);
|
|
147546
147942
|
}
|
|
147547
147943
|
function parseJsonObject3(body) {
|
|
@@ -147551,7 +147947,7 @@ function parseJsonObject3(body) {
|
|
|
147551
147947
|
} catch {
|
|
147552
147948
|
return void 0;
|
|
147553
147949
|
}
|
|
147554
|
-
return
|
|
147950
|
+
return isRecord20(parsed) ? parsed : void 0;
|
|
147555
147951
|
}
|
|
147556
147952
|
function nonEmptyString2(record3, field) {
|
|
147557
147953
|
const value3 = record3 === void 0 ? void 0 : record3[field];
|
|
@@ -147625,7 +148021,7 @@ async function serveRcClientChannels(ctx, tail, method, maxBatchEvents) {
|
|
|
147625
148021
|
}
|
|
147626
148022
|
const results = [];
|
|
147627
148023
|
for (const event of events) {
|
|
147628
|
-
if (!
|
|
148024
|
+
if (!isRecord20(event) || !isRecord20(event.payload)) {
|
|
147629
148025
|
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
148026
|
return true;
|
|
147631
148027
|
}
|
|
@@ -147725,7 +148121,7 @@ async function serveRcCompatSessions(ctx, pathname, compatPath) {
|
|
|
147725
148121
|
// src/frontdoor/rcSelfHostConversations.ts
|
|
147726
148122
|
var RC_CONVERSATIONS_PATH_PREFIX = "/v1/code/conversations";
|
|
147727
148123
|
var RC_CONVERSATION_ID_PREFIX = "conv_";
|
|
147728
|
-
function
|
|
148124
|
+
function isRecord21(value3) {
|
|
147729
148125
|
return typeof value3 === "object" && value3 !== null && !Array.isArray(value3);
|
|
147730
148126
|
}
|
|
147731
148127
|
function parseJsonObject4(body) {
|
|
@@ -147735,7 +148131,7 @@ function parseJsonObject4(body) {
|
|
|
147735
148131
|
} catch {
|
|
147736
148132
|
return void 0;
|
|
147737
148133
|
}
|
|
147738
|
-
return
|
|
148134
|
+
return isRecord21(parsed) ? parsed : void 0;
|
|
147739
148135
|
}
|
|
147740
148136
|
function nonEmptyString3(record3, field) {
|
|
147741
148137
|
const value3 = record3 === void 0 ? void 0 : record3[field];
|
|
@@ -147789,7 +148185,7 @@ async function serveRcConversations(ctx, pathname, method) {
|
|
|
147789
148185
|
}
|
|
147790
148186
|
const results = [];
|
|
147791
148187
|
for (const event of events) {
|
|
147792
|
-
if (!
|
|
148188
|
+
if (!isRecord21(event) || !isRecord21(event.payload)) {
|
|
147793
148189
|
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
148190
|
return;
|
|
147795
148191
|
}
|
|
@@ -148082,7 +148478,7 @@ var RC_SELF_HOST_WORKER_EPOCH = 1;
|
|
|
148082
148478
|
var RC_STREAM_EVENT_NAME = "client_event";
|
|
148083
148479
|
var CONFLICT_REASON_HEADER2 = "x-ccr-conflict-reason";
|
|
148084
148480
|
var CONFLICT_REASON_EPOCH_STALE = "epoch_stale";
|
|
148085
|
-
function
|
|
148481
|
+
function isRecord22(value3) {
|
|
148086
148482
|
return typeof value3 === "object" && value3 !== null && !Array.isArray(value3);
|
|
148087
148483
|
}
|
|
148088
148484
|
function isWebSearchRefusal(value3) {
|
|
@@ -148166,7 +148562,7 @@ function parseJsonObject5(body) {
|
|
|
148166
148562
|
} catch {
|
|
148167
148563
|
return void 0;
|
|
148168
148564
|
}
|
|
148169
|
-
return
|
|
148565
|
+
return isRecord22(parsed) ? parsed : void 0;
|
|
148170
148566
|
}
|
|
148171
148567
|
function mintWorkerJwt(randomToken, issuedAt) {
|
|
148172
148568
|
const encode3 = (value3) => Buffer.from(JSON.stringify(value3), "utf8").toString("base64url");
|
|
@@ -148426,7 +148822,7 @@ data: ${JSON.stringify(envelope2)}
|
|
|
148426
148822
|
if (status !== void 0) {
|
|
148427
148823
|
session.workerStatus = status;
|
|
148428
148824
|
}
|
|
148429
|
-
if (
|
|
148825
|
+
if (isRecord22(body?.external_metadata)) {
|
|
148430
148826
|
session.externalMetadata = body.external_metadata;
|
|
148431
148827
|
}
|
|
148432
148828
|
await answerJson2(response, HTTP_STATUS.ok, {});
|
|
@@ -148456,7 +148852,7 @@ data: ${JSON.stringify(envelope2)}
|
|
|
148456
148852
|
}
|
|
148457
148853
|
const results = [];
|
|
148458
148854
|
for (const event of events) {
|
|
148459
|
-
if (!
|
|
148855
|
+
if (!isRecord22(event) || !isRecord22(event.payload)) {
|
|
148460
148856
|
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
148857
|
return;
|
|
148462
148858
|
}
|
|
@@ -148489,7 +148885,7 @@ data: ${JSON.stringify(envelope2)}
|
|
|
148489
148885
|
return;
|
|
148490
148886
|
}
|
|
148491
148887
|
for (const event of events) {
|
|
148492
|
-
if (
|
|
148888
|
+
if (isRecord22(event)) {
|
|
148493
148889
|
session.internalEvents.push({ eventId: deps.newUuid(), body: event });
|
|
148494
148890
|
}
|
|
148495
148891
|
}
|
|
@@ -148585,7 +148981,7 @@ data: ${JSON.stringify(envelope2)}
|
|
|
148585
148981
|
}
|
|
148586
148982
|
const results = [];
|
|
148587
148983
|
for (const event of events) {
|
|
148588
|
-
if (!
|
|
148984
|
+
if (!isRecord22(event) || !isRecord22(event.payload)) {
|
|
148589
148985
|
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
148986
|
return;
|
|
148591
148987
|
}
|
|
@@ -148869,7 +149265,7 @@ init_realPorts();
|
|
|
148869
149265
|
var import_promises22 = require("node:fs/promises");
|
|
148870
149266
|
|
|
148871
149267
|
// src/supervise/sessionGoal.ts
|
|
148872
|
-
function
|
|
149268
|
+
function isRecord23(value3) {
|
|
148873
149269
|
return typeof value3 === "object" && value3 !== null && !Array.isArray(value3);
|
|
148874
149270
|
}
|
|
148875
149271
|
function goalStatusOf(line) {
|
|
@@ -148882,7 +149278,7 @@ function goalStatusOf(line) {
|
|
|
148882
149278
|
} catch {
|
|
148883
149279
|
return void 0;
|
|
148884
149280
|
}
|
|
148885
|
-
if (!
|
|
149281
|
+
if (!isRecord23(row) || row.type !== "attachment" || !isRecord23(row.attachment) || row.attachment.type !== "goal_status" || typeof row.attachment.condition !== "string") {
|
|
148886
149282
|
return void 0;
|
|
148887
149283
|
}
|
|
148888
149284
|
return row.attachment;
|
|
@@ -149197,7 +149593,7 @@ function createSseParser() {
|
|
|
149197
149593
|
}
|
|
149198
149594
|
};
|
|
149199
149595
|
}
|
|
149200
|
-
function
|
|
149596
|
+
function isRecord24(value3) {
|
|
149201
149597
|
return typeof value3 === "object" && value3 !== null && !Array.isArray(value3);
|
|
149202
149598
|
}
|
|
149203
149599
|
function sequenceNumOf(value3) {
|
|
@@ -149219,7 +149615,7 @@ function parseRcStreamEnvelope(parsed) {
|
|
|
149219
149615
|
} catch {
|
|
149220
149616
|
return void 0;
|
|
149221
149617
|
}
|
|
149222
|
-
if (!
|
|
149618
|
+
if (!isRecord24(data)) {
|
|
149223
149619
|
return void 0;
|
|
149224
149620
|
}
|
|
149225
149621
|
const eventType = data.event_type;
|
|
@@ -149911,7 +150307,7 @@ function inheritedControlToken(paths) {
|
|
|
149911
150307
|
return token;
|
|
149912
150308
|
}
|
|
149913
150309
|
function realFrontDoorSupervisorPorts(paths, respawnGeneration, lifecycle, trackTunnels) {
|
|
149914
|
-
const catalogueGeneration = (0,
|
|
150310
|
+
const catalogueGeneration = (0, import_node_crypto32.randomUUID)();
|
|
149915
150311
|
const log = (line) => {
|
|
149916
150312
|
appendDoorLog(paths, `frontdoor ${String(process.pid)}: ${line}`);
|
|
149917
150313
|
};
|
|
@@ -149944,14 +150340,14 @@ function realFrontDoorSupervisorPorts(paths, respawnGeneration, lifecycle, track
|
|
|
149944
150340
|
};
|
|
149945
150341
|
const rcSelfHostSurface = rcSelfHost ? createRcSelfHostSurface({
|
|
149946
150342
|
now: () => Date.now(),
|
|
149947
|
-
newUuid:
|
|
149948
|
-
randomToken: () => (0,
|
|
150343
|
+
newUuid: import_node_crypto32.randomUUID,
|
|
150344
|
+
randomToken: () => (0, import_node_crypto32.randomBytes)(MINTED_TOKEN_RANDOM_BYTES).toString("base64url"),
|
|
149949
150345
|
credentialRecord: () => readRcSelfHostRecord(realFarmFs, paths.frontdoorDir),
|
|
149950
150346
|
webFetch: realRcWebFetch({ allowPrivate: rcWebFetchAllowsPrivateFromEnv(process.env) }),
|
|
149951
150347
|
log
|
|
149952
150348
|
}) : void 0;
|
|
149953
150349
|
const rcCredentialStore = createRcCredentialStore(realFarmFs, paths.frontdoorRcCredentialsDir);
|
|
149954
|
-
const rcSessionEvents = createRcSessionEventLog({ generation: (0,
|
|
150350
|
+
const rcSessionEvents = createRcSessionEventLog({ generation: (0, import_node_crypto32.randomUUID)(), capacity: RC_SESSION_EVENT_LOG_CAPACITY });
|
|
149955
150351
|
const rcTracker = createRcSessionTracker({ now: () => Date.now(), idleMs: RC_IDLE_EXPIRY_MS, credentialStore: rcCredentialStore, onTransition: rcSessionEvents.append, onClose: rcSessionEvents.close });
|
|
149956
150352
|
const doorEvents = createDoorEventHub();
|
|
149957
150353
|
const usagePublisher = doorEvents.publisher(USAGE_EVENT_SOURCE);
|
|
@@ -149979,7 +150375,7 @@ function realFrontDoorSupervisorPorts(paths, respawnGeneration, lifecycle, track
|
|
|
149979
150375
|
saveSequenceNum: rcCredentialStore.writeCursor,
|
|
149980
150376
|
dial: rcSelfHost ? lateRcStreamDial(rcSelfHostDialTarget) : realRcStreamDial(),
|
|
149981
150377
|
fanout: rcFanout,
|
|
149982
|
-
newClientId:
|
|
150378
|
+
newClientId: import_node_crypto32.randomUUID,
|
|
149983
150379
|
backoffMs: RC_STREAM_BACKOFF_MS,
|
|
149984
150380
|
sleep: async (ms) => {
|
|
149985
150381
|
await new Promise((resolve3) => {
|
|
@@ -149992,7 +150388,7 @@ function realFrontDoorSupervisorPorts(paths, respawnGeneration, lifecycle, track
|
|
|
149992
150388
|
});
|
|
149993
150389
|
const observations = createTargetObservationStore(realFarmFs, paths);
|
|
149994
150390
|
const routingSnapshots = /* @__PURE__ */ new Map();
|
|
149995
|
-
const rcControlToken = lifecycle.predecessor === void 0 ? (0,
|
|
150391
|
+
const rcControlToken = lifecycle.predecessor === void 0 ? (0, import_node_crypto32.randomUUID)() : inheritedControlToken(paths);
|
|
149996
150392
|
const sessionRegistry = createLiveSessionRegistry({ fs: realFarmFs, sessionsDir: paths.frontdoorSessionsDir });
|
|
149997
150393
|
const resolveRoute = rcObservingResolver(
|
|
149998
150394
|
createProviderRouteResolver({
|
|
@@ -150170,9 +150566,9 @@ function realFrontDoorSupervisorPorts(paths, respawnGeneration, lifecycle, track
|
|
|
150170
150566
|
now: () => Date.now(),
|
|
150171
150567
|
headroomSocket: () => headroomSocketTarget(realFarmFs, realHeadroomSocketTrust, paths),
|
|
150172
150568
|
// 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,
|
|
150569
|
+
hopSecret: (0, import_node_crypto32.randomUUID)(),
|
|
150174
150570
|
headroomDecision,
|
|
150175
|
-
custody: createCredentialCustody(() => (0,
|
|
150571
|
+
custody: createCredentialCustody(() => (0, import_node_crypto32.randomUUID)()),
|
|
150176
150572
|
log
|
|
150177
150573
|
});
|
|
150178
150574
|
const onListenerError = (name) => (error63) => {
|
|
@@ -150199,9 +150595,9 @@ function realFrontDoorSupervisorPorts(paths, respawnGeneration, lifecycle, track
|
|
|
150199
150595
|
startProviderListener: async (source) => {
|
|
150200
150596
|
const authority = loadCa();
|
|
150201
150597
|
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:
|
|
150598
|
+
const rcInject = async (sessionId, text5) => await injectRcUserMessage({ credentialOf: rcTracker.credentialOf, noteSequenceNums: rcTracker.noteSequenceNums, dial: rcDial, newUuid: import_node_crypto32.randomUUID }, sessionId, text5);
|
|
150599
|
+
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);
|
|
150600
|
+
const rcControlRequestDeps = { credentialOf: rcTracker.credentialOf, noteSequenceNums: rcTracker.noteSequenceNums, dial: rcDial, newUuid: import_node_crypto32.randomUUID };
|
|
150205
150601
|
const rcInterrupt = async (sessionId) => await interruptRcSession(rcControlRequestDeps, sessionId);
|
|
150206
150602
|
const rcSetModel = async (sessionId, model) => await setRcSessionModel(rcControlRequestDeps, sessionId, model);
|
|
150207
150603
|
const rcSetPermissionMode = async (sessionId, mode) => await setRcSessionPermissionMode(rcControlRequestDeps, sessionId, mode);
|
|
@@ -150220,7 +150616,7 @@ function realFrontDoorSupervisorPorts(paths, respawnGeneration, lifecycle, track
|
|
|
150220
150616
|
paths,
|
|
150221
150617
|
isTracked: (sessionId) => rcTracker.statusOf(sessionId).length > 0,
|
|
150222
150618
|
selfHost: rcSelfHost ? {
|
|
150223
|
-
personWrite: { credentialOf: rcTracker.credentialOf, noteSequenceNums: rcTracker.noteSequenceNums, newUuid:
|
|
150619
|
+
personWrite: { credentialOf: rcTracker.credentialOf, noteSequenceNums: rcTracker.noteSequenceNums, newUuid: import_node_crypto32.randomUUID, dial: rcSelfHostEventDial(rcSelfHostDialTarget) },
|
|
150224
150620
|
unavailable: () => rcSelfHostDialTarget() === void 0 ? selfHostSurfaceUnboundReason(process.env.AGENT_SHIM_TRANSPARENT_SURFACE) : void 0,
|
|
150225
150621
|
fanout: rcFanout,
|
|
150226
150622
|
versions: rcClaudeCodeVersions
|
|
@@ -150324,7 +150720,7 @@ function realFrontDoorSupervisorPorts(paths, respawnGeneration, lifecycle, track
|
|
|
150324
150720
|
},
|
|
150325
150721
|
startConnectListener: async (source) => {
|
|
150326
150722
|
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,
|
|
150723
|
+
const transparentCapability = wantedTransparentPort === void 0 || Number.isNaN(wantedTransparentPort) ? void 0 : (0, import_node_crypto32.randomUUID)();
|
|
150328
150724
|
if (transparentCapability !== void 0) {
|
|
150329
150725
|
writeFrontDoorSession(realFarmFs, paths.frontdoorSessionsDir, { pid: process.pid, startedAt: Date.now(), token: transparentCapability });
|
|
150330
150726
|
}
|
|
@@ -151916,14 +152312,14 @@ init_zod();
|
|
|
151916
152312
|
init_schema2();
|
|
151917
152313
|
|
|
151918
152314
|
// src/statusline/cacheFile.ts
|
|
151919
|
-
var
|
|
152315
|
+
var import_node_crypto33 = require("node:crypto");
|
|
151920
152316
|
var import_node_path76 = __toESM(require("node:path"), 1);
|
|
151921
152317
|
var SESSION_CACHE_DIRECTORY = "session";
|
|
151922
152318
|
function cacheDirectory(ports) {
|
|
151923
152319
|
return import_node_path76.default.join(ports.stateDirectory, SESSION_CACHE_DIRECTORY);
|
|
151924
152320
|
}
|
|
151925
152321
|
function cacheFileFor(ports, kind, transcriptPath) {
|
|
151926
|
-
return import_node_path76.default.join(cacheDirectory(ports), `${kind}-${(0,
|
|
152322
|
+
return import_node_path76.default.join(cacheDirectory(ports), `${kind}-${(0, import_node_crypto33.createHash)("sha256").update(transcriptPath).digest("hex")}.json`);
|
|
151927
152323
|
}
|
|
151928
152324
|
function transcriptKeyOf(ports, transcriptPath) {
|
|
151929
152325
|
const trimmed = transcriptPath.trim();
|
|
@@ -154223,11 +154619,11 @@ function compactUnits(rows, barCells) {
|
|
|
154223
154619
|
}
|
|
154224
154620
|
|
|
154225
154621
|
// src/statusline/transcript/reader.ts
|
|
154226
|
-
var
|
|
154622
|
+
var import_node_crypto35 = require("node:crypto");
|
|
154227
154623
|
init_zod();
|
|
154228
154624
|
|
|
154229
154625
|
// src/statusline/transcript/activity.ts
|
|
154230
|
-
var
|
|
154626
|
+
var import_node_crypto34 = require("node:crypto");
|
|
154231
154627
|
init_zod();
|
|
154232
154628
|
init_graphemes();
|
|
154233
154629
|
|
|
@@ -154547,7 +154943,7 @@ function foldTodoCall(state, call2) {
|
|
|
154547
154943
|
return { ...state, todos: state.todos.map((item, at2) => at2 === index ? updated : item), todosEdited: true };
|
|
154548
154944
|
}
|
|
154549
154945
|
function digestOf(id2) {
|
|
154550
|
-
return (0,
|
|
154946
|
+
return (0, import_node_crypto34.createHash)("sha256").update(id2).digest("base64url").slice(0, CALL_DIGEST_CHARS);
|
|
154551
154947
|
}
|
|
154552
154948
|
function timeKeyOf(atMs) {
|
|
154553
154949
|
const key = atMs === void 0 || atMs < 0 ? "" : atMs.toString(CALL_TIME_RADIX);
|
|
@@ -154954,7 +155350,7 @@ function foldLines(state, bytes) {
|
|
|
154954
155350
|
}
|
|
154955
155351
|
function fingerprintOf(head) {
|
|
154956
155352
|
const newline = head.subarray(0, FINGERPRINT_BYTES).indexOf(NEWLINE3);
|
|
154957
|
-
return (0,
|
|
155353
|
+
return (0, import_node_crypto35.createHash)("sha256").update(head.subarray(0, newline === -1 ? FINGERPRINT_BYTES : newline + 1)).digest("hex");
|
|
154958
155354
|
}
|
|
154959
155355
|
function factsOf(size, cache, reachedEnd, nowMs, env) {
|
|
154960
155356
|
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 +168100,7 @@ function registerRuleCommand(program2, deps) {
|
|
|
167704
168100
|
}
|
|
167705
168101
|
|
|
167706
168102
|
// src/codex/launch.ts
|
|
167707
|
-
var
|
|
168103
|
+
var import_node_crypto36 = require("node:crypto");
|
|
167708
168104
|
var import_node_fs39 = __toESM(require("node:fs"), 1);
|
|
167709
168105
|
var import_node_os24 = __toESM(require("node:os"), 1);
|
|
167710
168106
|
var import_node_path93 = __toESM(require("node:path"), 1);
|
|
@@ -167908,7 +168304,7 @@ async function runCodex(paths, argv) {
|
|
|
167908
168304
|
}
|
|
167909
168305
|
throw new UsageError("No real Codex CLI found on PATH. Install Codex or set AGENT_SHIM_CODEX_BIN to its executable.");
|
|
167910
168306
|
};
|
|
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,
|
|
168307
|
+
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
168308
|
console.error(`agent-shim: ${message}`);
|
|
167913
168309
|
}, ...resolveGitBranch(realRunPort, process.cwd()) });
|
|
167914
168310
|
import_node_fs39.default.chmodSync(plan.env.CODEX_HOME ?? "", PRIVATE_DIRECTORY_MODE);
|
|
@@ -168656,7 +169052,7 @@ async function realRefresher(params) {
|
|
|
168656
169052
|
}
|
|
168657
169053
|
|
|
168658
169054
|
// src/supervise/launch.ts
|
|
168659
|
-
var
|
|
169055
|
+
var import_node_crypto37 = require("node:crypto");
|
|
168660
169056
|
var import_node_fs40 = require("node:fs");
|
|
168661
169057
|
var import_node_path99 = __toESM(require("node:path"), 1);
|
|
168662
169058
|
var import_promises23 = require("node:stream/promises");
|
|
@@ -169427,21 +169823,21 @@ async function runSupervised(params) {
|
|
|
169427
169823
|
log.warn(`agent-shim: pool "${pool}" cannot supervise a launch whose extra flags end option parsing`);
|
|
169428
169824
|
return void 0;
|
|
169429
169825
|
}
|
|
169430
|
-
const first = initialConversationOf(params.passthrough, { newId:
|
|
169826
|
+
const first = initialConversationOf(params.passthrough, { newId: import_node_crypto37.randomUUID, latestId: () => latestConversationId(farm.fs, { claudeHome: farm.claudeHome, cwd: farm.cwd }) });
|
|
169431
169827
|
if ("reason" in first) {
|
|
169432
169828
|
log.warn(`agent-shim: pool "${pool}" resumes on a spent quota, but this launch runs unsupervised: ${first.reason}`);
|
|
169433
169829
|
return void 0;
|
|
169434
169830
|
}
|
|
169435
169831
|
let entrypointSha256AtStart;
|
|
169436
169832
|
try {
|
|
169437
|
-
const hash2 = (0,
|
|
169833
|
+
const hash2 = (0, import_node_crypto37.createHash)("sha256");
|
|
169438
169834
|
await (0, import_promises23.pipeline)((0, import_node_fs40.createReadStream)(realContentSourcePath()), hash2);
|
|
169439
169835
|
entrypointSha256AtStart = hash2.digest("hex");
|
|
169440
169836
|
} catch {
|
|
169441
169837
|
entrypointSha256AtStart = null;
|
|
169442
169838
|
log.warn("agent-shim: could not fingerprint the supervisor entrypoint");
|
|
169443
169839
|
}
|
|
169444
|
-
const lifecycle = createLifecycleRecorder({ fs: realFarmFs, logsDir: paths.logsDir, fileId: (0,
|
|
169840
|
+
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
169841
|
let compaction;
|
|
169446
169842
|
const policy = params.pools[pool];
|
|
169447
169843
|
const markSettings = markHooksSettings(selfInvocation([]), paths.root, pool, first.sessionId);
|