@usepowerplant/cli 0.4.26 → 0.4.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/main.js +643 -2232
- package/dist/menubar/Powerplant.app.zip +0 -0
- package/package.json +1 -1
package/dist/main.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="
|
|
2
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="d3cdc2c4-688f-5244-bc1d-b1fd4151981c")}catch(e){}}();
|
|
3
3
|
import { createRequire as __cliCreateRequire } from 'node:module';
|
|
4
4
|
const require = __cliCreateRequire(import.meta.url);
|
|
5
5
|
var __create = Object.create;
|
|
@@ -20448,19 +20448,19 @@ var require_round_robin_pool = __commonJS({
|
|
|
20448
20448
|
this[kAddClient](dispatcher);
|
|
20449
20449
|
return dispatcher;
|
|
20450
20450
|
}
|
|
20451
|
-
let
|
|
20452
|
-
while (
|
|
20451
|
+
let checked2 = 0;
|
|
20452
|
+
while (checked2 < clientsLength) {
|
|
20453
20453
|
this[kIndex] = (this[kIndex] + 1) % clientsLength;
|
|
20454
20454
|
const client = this[kClients][this[kIndex]];
|
|
20455
20455
|
if (clientTtlOption != null && clientTtlOption > 0 && client.ttl && Date.now() - client.ttl > clientTtlOption) {
|
|
20456
20456
|
this[kRemoveClient](client);
|
|
20457
|
-
|
|
20457
|
+
checked2++;
|
|
20458
20458
|
continue;
|
|
20459
20459
|
}
|
|
20460
20460
|
if (!client[kNeedDrain]) {
|
|
20461
20461
|
return client;
|
|
20462
20462
|
}
|
|
20463
|
-
|
|
20463
|
+
checked2++;
|
|
20464
20464
|
}
|
|
20465
20465
|
if (!this[kConnections] || clientsLength < this[kConnections]) {
|
|
20466
20466
|
const dispatcher = this[kFactory](this[kUrl], this[kOptions]);
|
|
@@ -56526,18 +56526,6 @@ function harnessFromLegacySessionSource(source) {
|
|
|
56526
56526
|
if (source === "github-pr") return { kind: "not-harness", source };
|
|
56527
56527
|
return { kind: "harness", harness: SESSION_SOURCE_HARNESSES[source] };
|
|
56528
56528
|
}
|
|
56529
|
-
var LEGACY_SESSION_SOURCE_BY_HARNESS = {
|
|
56530
|
-
"claude-local": "claude-code",
|
|
56531
|
-
"claude-cloud": "claude-cloud",
|
|
56532
|
-
"codex-local": "codex",
|
|
56533
|
-
"codex-cloud": null,
|
|
56534
|
-
"cursor-local": "cursor",
|
|
56535
|
-
"cursor-cloud": "cursor-cloud"
|
|
56536
|
-
};
|
|
56537
|
-
function legacySessionSourceFromHarness(harness) {
|
|
56538
|
-
const source = LEGACY_SESSION_SOURCE_BY_HARNESS[harness];
|
|
56539
|
-
return source === null ? { kind: "unsupported", harness } : { kind: "supported", source };
|
|
56540
|
-
}
|
|
56541
56529
|
|
|
56542
56530
|
// ../core/src/sessionIngest.ts
|
|
56543
56531
|
var LEGACY_SESSION_SOURCES = [
|
|
@@ -56555,24 +56543,13 @@ function isLegacySessionSource(source) {
|
|
|
56555
56543
|
}
|
|
56556
56544
|
var SESSION_ACTIVE_WINDOW_MS = 30 * 60 * 1e3;
|
|
56557
56545
|
var LEGACY_COLLECTOR_SESSION_SOURCES = ["claude-code", "codex", "cursor"];
|
|
56558
|
-
var LEGACY_PREVIEW_REGISTRABLE_SOURCES = [
|
|
56559
|
-
...LEGACY_COLLECTOR_SESSION_SOURCES,
|
|
56560
|
-
"cursor-cloud"
|
|
56561
|
-
];
|
|
56562
56546
|
var COLLECTOR_SESSION_HARNESSES = [
|
|
56563
56547
|
"claude-local",
|
|
56564
56548
|
"codex-local",
|
|
56565
56549
|
"cursor-local"
|
|
56566
56550
|
];
|
|
56567
|
-
var PREVIEW_REGISTRABLE_HARNESSES = [
|
|
56568
|
-
...COLLECTOR_SESSION_HARNESSES,
|
|
56569
|
-
"cursor-cloud"
|
|
56570
|
-
];
|
|
56571
56551
|
var MAX_INGEST_BATCH = 500;
|
|
56572
56552
|
var MAX_RAW_UPLOAD_BYTES = 256 * 1024 * 1024;
|
|
56573
|
-
var MAX_PREVIEW_URL_LENGTH = 2e3;
|
|
56574
|
-
var MAX_REGISTERED_PREVIEWS = 10;
|
|
56575
|
-
var MAX_PREVIEW_LABEL_LENGTH = 60;
|
|
56576
56553
|
var MAX_BRANCH_FACTS = 50;
|
|
56577
56554
|
|
|
56578
56555
|
// ../core/src/menubarAnalytics.ts
|
|
@@ -56587,46 +56564,6 @@ var menubarEventSchema = external_exports.discriminatedUnion("event", [
|
|
|
56587
56564
|
mcpWarningDismissalSchema.extend({ event: external_exports.literal(MENUBAR_MCP_WARNING_REMOVE) })
|
|
56588
56565
|
]);
|
|
56589
56566
|
|
|
56590
|
-
// ../core/src/messageOrigin.ts
|
|
56591
|
-
var CLAUDE_CODE_NATIVE_ORIGINS = /* @__PURE__ */ new Set(["human", "agent", "harness", "tool"]);
|
|
56592
|
-
var CLAUDE_CODE_TASK_NOTIFICATION_ORIGIN = "task-notification";
|
|
56593
|
-
var SYSTEM_REMINDER = /<system-reminder(?:\s|>)/u;
|
|
56594
|
-
function claudeCodeMessageOrigin(facts, text) {
|
|
56595
|
-
let origin = !facts.originRecorded && facts.recordType === "assistant" && facts.role === "assistant" ? "agent" : "unknown";
|
|
56596
|
-
if (facts.nativeOrigin !== null && CLAUDE_CODE_NATIVE_ORIGINS.has(facts.nativeOrigin)) {
|
|
56597
|
-
origin = facts.nativeOrigin;
|
|
56598
|
-
}
|
|
56599
|
-
if (facts.nativeOrigin === CLAUDE_CODE_TASK_NOTIFICATION_ORIGIN || facts.commandMode === CLAUDE_CODE_TASK_NOTIFICATION_ORIGIN || facts.isMeta === true || facts.isCompactSummary === true || facts.model === "<synthetic>") {
|
|
56600
|
-
origin = "harness";
|
|
56601
|
-
}
|
|
56602
|
-
return origin === "human" && SYSTEM_REMINDER.test(text) ? "mixed" : origin;
|
|
56603
|
-
}
|
|
56604
|
-
var CODEX_USER_MESSAGE_MARKER = "## My request for Codex:";
|
|
56605
|
-
var CODEX_MARKER_LINE = /^## My request for Codex:/mu;
|
|
56606
|
-
var CODEX_CONTEXT_BLOCK = /^<[a-z_]+>/i;
|
|
56607
|
-
var CODEX_AGENTS_MD_BLOCK = /^#+ AGENTS\.md instructions/;
|
|
56608
|
-
var CODEX_CONTEXT_WINDOW_OPEN = "<context_window>";
|
|
56609
|
-
var CODEX_CONTEXT_WINDOW_CLOSE = "</context_window>";
|
|
56610
|
-
function isCodexMarkerPrefix(prefix) {
|
|
56611
|
-
const trimmed = prefix.trim();
|
|
56612
|
-
if (trimmed === "") return true;
|
|
56613
|
-
return trimmed.startsWith(CODEX_CONTEXT_WINDOW_OPEN) && trimmed.endsWith(CODEX_CONTEXT_WINDOW_CLOSE) && trimmed.indexOf(CODEX_CONTEXT_WINDOW_CLOSE) === trimmed.length - CODEX_CONTEXT_WINDOW_CLOSE.length;
|
|
56614
|
-
}
|
|
56615
|
-
function codexPromptBlock(text) {
|
|
56616
|
-
const trimmed = text.trim();
|
|
56617
|
-
if (trimmed === "" || CODEX_AGENTS_MD_BLOCK.test(trimmed)) return { origin: "harness", ask: null };
|
|
56618
|
-
const marker = CODEX_MARKER_LINE.exec(text);
|
|
56619
|
-
if (marker !== null && isCodexMarkerPrefix(text.slice(0, marker.index))) {
|
|
56620
|
-
return { origin: "human", ask: text.slice(marker.index + CODEX_USER_MESSAGE_MARKER.length).trim() };
|
|
56621
|
-
}
|
|
56622
|
-
if (CODEX_CONTEXT_BLOCK.test(trimmed)) return { origin: "harness", ask: null };
|
|
56623
|
-
return { origin: "unknown", ask: trimmed };
|
|
56624
|
-
}
|
|
56625
|
-
function codexPromptOrigin(keptBlockOrigins) {
|
|
56626
|
-
if (keptBlockOrigins.length === 0) return "unknown";
|
|
56627
|
-
return keptBlockOrigins.every((origin) => origin === "human") ? "human" : "unknown";
|
|
56628
|
-
}
|
|
56629
|
-
|
|
56630
56567
|
// ../core/src/rawTranscriptBundle.ts
|
|
56631
56568
|
var RAW_TRANSCRIPT_BUNDLE_CONTENT_TYPE = "application/vnd.powerplant.raw-transcript-bundle";
|
|
56632
56569
|
var RAW_TRANSCRIPT_PART_PATTERN = /^[A-Za-z0-9_-]{1,128}$/;
|
|
@@ -56871,15 +56808,6 @@ function describeImageBlock(block2) {
|
|
|
56871
56808
|
}
|
|
56872
56809
|
return { mediaType, bytes: null };
|
|
56873
56810
|
}
|
|
56874
|
-
function describeImageUrl(url2) {
|
|
56875
|
-
if (typeof url2 !== "string") return { mediaType: null, bytes: null };
|
|
56876
|
-
const dataUri = IMAGE_DATA_URI_RE.exec(url2);
|
|
56877
|
-
if (dataUri) {
|
|
56878
|
-
const [, mediaType = "", data = ""] = dataUri;
|
|
56879
|
-
return { mediaType, bytes: base64ByteLength(data) };
|
|
56880
|
-
}
|
|
56881
|
-
return { mediaType: null, bytes: null };
|
|
56882
|
-
}
|
|
56883
56811
|
function imageLabel(image) {
|
|
56884
56812
|
const detail = [image.mediaType, image.bytes === null ? null : formatByteSize(image.bytes)].filter((part) => part !== null).join(", ");
|
|
56885
56813
|
return detail === "" ? "[image]" : `[image: ${detail}]`;
|
|
@@ -57179,532 +57107,8 @@ function boundText(redacted, maxBytes) {
|
|
|
57179
57107
|
return { text: cut, truncated: true, originalBytes: bytes.length };
|
|
57180
57108
|
}
|
|
57181
57109
|
|
|
57182
|
-
// ../core/src/codeHost.ts
|
|
57183
|
-
function pullRequestId(ref) {
|
|
57184
|
-
return `${repositoryId(ref.host, ref.repository)}#${ref.number}`;
|
|
57185
|
-
}
|
|
57186
|
-
function repositoryId(host, repository) {
|
|
57187
|
-
return `${host}:${repository}`;
|
|
57188
|
-
}
|
|
57189
|
-
var REMOTE_SCHEME = /^(?:https?|ssh|git):\/\//;
|
|
57190
|
-
var REMOTE_USER = /^[^/@\s]+@/;
|
|
57191
|
-
var REMOTE_PORT = /^:\d+\//;
|
|
57192
|
-
var REMOTE_PATH_SEGMENT = /^[\w.-]+$/;
|
|
57193
|
-
function githubRepositoryOfRemote(url2) {
|
|
57194
|
-
const hasScheme = REMOTE_SCHEME.test(url2);
|
|
57195
|
-
const afterUser = url2.replace(REMOTE_SCHEME, "").replace(REMOTE_USER, "");
|
|
57196
|
-
const host = afterUser.startsWith("ssh.") ? afterUser.slice("ssh.".length) : afterUser;
|
|
57197
|
-
if (!host.startsWith("github.com")) return null;
|
|
57198
|
-
let path55 = host.slice("github.com".length);
|
|
57199
|
-
const port = hasScheme ? REMOTE_PORT.exec(path55) : null;
|
|
57200
|
-
if (port !== null) path55 = path55.slice(port[0].length);
|
|
57201
|
-
else if (path55.startsWith("/") || path55.startsWith(":")) path55 = path55.slice(1);
|
|
57202
|
-
else return null;
|
|
57203
|
-
if (path55.endsWith("/")) path55 = path55.slice(0, -1);
|
|
57204
|
-
if (path55.endsWith(".git")) path55 = path55.slice(0, -".git".length);
|
|
57205
|
-
const segments = path55.split("/");
|
|
57206
|
-
if (segments.length !== 2 || !segments.every((segment) => REMOTE_PATH_SEGMENT.test(segment))) return null;
|
|
57207
|
-
return path55;
|
|
57208
|
-
}
|
|
57209
|
-
var PUSH_DESTINATION = /\bTo\s+([^\s\\"]+)/g;
|
|
57210
|
-
function pushDestinationsInText(text) {
|
|
57211
|
-
const repositories = [];
|
|
57212
|
-
for (const match of text.matchAll(PUSH_DESTINATION)) {
|
|
57213
|
-
const repository = githubRepositoryOfRemote(match[1]);
|
|
57214
|
-
if (repository !== null) repositories.push(repositoryId("github", repository));
|
|
57215
|
-
}
|
|
57216
|
-
return repositories;
|
|
57217
|
-
}
|
|
57218
|
-
var GITHUB_PULL_URL = /https:\/\/github\.com\/([\w.-]+\/[\w.-]+)\/pull\/(\d+)(?!\d)/g;
|
|
57219
|
-
function pullRequestRefsInText(text) {
|
|
57220
|
-
const refs = [];
|
|
57221
|
-
const seen = /* @__PURE__ */ new Set();
|
|
57222
|
-
for (const match of text.matchAll(GITHUB_PULL_URL)) {
|
|
57223
|
-
const ref = { host: "github", repository: match[1], number: Number(match[2]) };
|
|
57224
|
-
const id = pullRequestId(ref);
|
|
57225
|
-
if (seen.has(id)) continue;
|
|
57226
|
-
seen.add(id);
|
|
57227
|
-
refs.push(ref);
|
|
57228
|
-
}
|
|
57229
|
-
return refs;
|
|
57230
|
-
}
|
|
57231
|
-
var PULL_REQUEST_ALREADY_EXISTS = /a pull request for branch \S+ into branch \S+ already exists:/;
|
|
57232
|
-
function pullRequestAlreadyExistsInText(text) {
|
|
57233
|
-
return PULL_REQUEST_ALREADY_EXISTS.test(text);
|
|
57234
|
-
}
|
|
57235
|
-
function pullRequestRefFromUrl(url2) {
|
|
57236
|
-
return pullRequestRefsInText(url2)[0] ?? null;
|
|
57237
|
-
}
|
|
57238
|
-
var MAY_TOUCH_HOST = /\b(?:git|gh)\b/;
|
|
57239
|
-
function readCodeHostCommands(command, currentBranch) {
|
|
57240
|
-
return readCommands(command, currentBranch, 0);
|
|
57241
|
-
}
|
|
57242
|
-
var SUBSTITUTION_DEPTH_MAX = 4;
|
|
57243
|
-
function readCommands(command, currentBranch, depth) {
|
|
57244
|
-
const result = { pushes: [], pullRequestCreates: [] };
|
|
57245
|
-
if (!MAY_TOUCH_HOST.test(command)) return result;
|
|
57246
|
-
const chain = shellCommands(command);
|
|
57247
|
-
let branch = currentBranch;
|
|
57248
|
-
chain.forEach((simple, i) => {
|
|
57249
|
-
const program = programOf(simple.words);
|
|
57250
|
-
if (program === null) {
|
|
57251
|
-
if (depth >= SUBSTITUTION_DEPTH_MAX) return;
|
|
57252
|
-
const alone = simple.words.length === 1 && simple.next === null;
|
|
57253
|
-
for (const substituted of simple.assignedSubstitutions) {
|
|
57254
|
-
for (const create of readCommands(substituted, branch, depth + 1).pullRequestCreates) {
|
|
57255
|
-
result.pullRequestCreates.push({ ...create, ownExitStatus: create.ownExitStatus && alone });
|
|
57256
|
-
}
|
|
57257
|
-
}
|
|
57258
|
-
return;
|
|
57259
|
-
}
|
|
57260
|
-
if (program.name === "git") {
|
|
57261
|
-
const git = gitSubcommand(program.args);
|
|
57262
|
-
if (git === null) return;
|
|
57263
|
-
if (git.name === "push") {
|
|
57264
|
-
const ownExitStatus = exitStatusIsOwn(chain, i);
|
|
57265
|
-
const { remote, branches } = pushedBranches(git.args, branch);
|
|
57266
|
-
result.pushes.push(...branches.map((pushed) => ({ remote, branch: pushed, ownExitStatus })));
|
|
57267
|
-
} else if (git.name === "checkout" || git.name === "switch") {
|
|
57268
|
-
const target = checkoutTarget(git.args);
|
|
57269
|
-
if (target !== void 0) branch = target;
|
|
57270
|
-
}
|
|
57271
|
-
} else if (program.name === "gh") {
|
|
57272
|
-
const args = ghSubcommandArgs(program.args);
|
|
57273
|
-
if (args[0] === "pr" && args[1] === "create") {
|
|
57274
|
-
const head = optionValue(args.slice(2), ["--head", "-H"]);
|
|
57275
|
-
result.pullRequestCreates.push({ head: head ?? branch, ownExitStatus: chain[i].next === null });
|
|
57276
|
-
}
|
|
57277
|
-
}
|
|
57278
|
-
});
|
|
57279
|
-
return result;
|
|
57280
|
-
}
|
|
57281
|
-
var REJECTED_REF = /!\s+\[(?:remote )?rejected\]\s+\S+\s+->\s+([A-Za-z0-9._/-]+)/g;
|
|
57282
|
-
var UPDATED_REF = /(?:\*\s+\[new branch\]|\+?\s*[0-9a-f]{6,}\.{2,3}[0-9a-f]{6,})\s+\S+\s+->\s+([A-Za-z0-9._/-]+)/g;
|
|
57283
|
-
function pushOutcomeInText(text, branch) {
|
|
57284
|
-
const rejected = [...text.matchAll(REJECTED_REF)].map((match) => match[1]);
|
|
57285
|
-
if (rejected.includes(branch)) return false;
|
|
57286
|
-
const updated = [...text.matchAll(UPDATED_REF)].map((match) => match[1]);
|
|
57287
|
-
if (updated.includes(branch)) return true;
|
|
57288
|
-
if (rejected.length > 0 || /error: failed to push some refs/.test(text)) return false;
|
|
57289
|
-
return /Everything up-to-date/.test(text) ? true : null;
|
|
57290
|
-
}
|
|
57291
|
-
var ENV_ASSIGNMENT = /^[A-Za-z_][A-Za-z0-9_]*=/;
|
|
57292
|
-
var ASSIGNMENT_NAME = /^[A-Za-z_][A-Za-z0-9_]*=$/;
|
|
57293
|
-
function programOf(words) {
|
|
57294
|
-
let i = 0;
|
|
57295
|
-
while (i < words.length && (ENV_ASSIGNMENT.test(words[i]) || words[i] === "env")) i += 1;
|
|
57296
|
-
const program = words[i];
|
|
57297
|
-
if (program === void 0) return null;
|
|
57298
|
-
return { name: program.slice(program.lastIndexOf("/") + 1), args: words.slice(i + 1) };
|
|
57299
|
-
}
|
|
57300
|
-
var GIT_GLOBAL_VALUE_OPTIONS = /* @__PURE__ */ new Set(["-C", "-c", "--git-dir", "--work-tree", "--namespace", "--exec-path"]);
|
|
57301
|
-
function gitSubcommand(args) {
|
|
57302
|
-
for (let i = 0; i < args.length; i++) {
|
|
57303
|
-
const arg = args[i];
|
|
57304
|
-
if (arg.startsWith("-")) {
|
|
57305
|
-
if (GIT_GLOBAL_VALUE_OPTIONS.has(arg)) i += 1;
|
|
57306
|
-
continue;
|
|
57307
|
-
}
|
|
57308
|
-
return { name: arg, args: args.slice(i + 1) };
|
|
57309
|
-
}
|
|
57310
|
-
return null;
|
|
57311
|
-
}
|
|
57312
|
-
var GH_GLOBAL_VALUE_OPTIONS = /* @__PURE__ */ new Set(["-R", "--repo"]);
|
|
57313
|
-
function ghSubcommandArgs(args) {
|
|
57314
|
-
for (let i = 0; i < args.length; i++) {
|
|
57315
|
-
const arg = args[i];
|
|
57316
|
-
if (!arg.startsWith("-")) return args.slice(i);
|
|
57317
|
-
if (GH_GLOBAL_VALUE_OPTIONS.has(arg)) i += 1;
|
|
57318
|
-
}
|
|
57319
|
-
return [];
|
|
57320
|
-
}
|
|
57321
|
-
var PUSH_VALUE_OPTIONS = /* @__PURE__ */ new Set(["-o", "--push-option", "--receive-pack", "--exec", "--repo"]);
|
|
57322
|
-
var PUSH_WITHOUT_BRANCH = /* @__PURE__ */ new Set(["--all", "--branches", "--mirror", "--tags", "-d", "--delete", "-n", "--dry-run"]);
|
|
57323
|
-
var REF_NAME = /^[A-Za-z0-9][A-Za-z0-9._/-]*$/;
|
|
57324
|
-
function pushedBranches(args, currentBranch) {
|
|
57325
|
-
const positional = [];
|
|
57326
|
-
for (let i = 0; i < args.length; i++) {
|
|
57327
|
-
const arg = args[i];
|
|
57328
|
-
if (arg === "--") {
|
|
57329
|
-
positional.push(...args.slice(i + 1));
|
|
57330
|
-
break;
|
|
57331
|
-
}
|
|
57332
|
-
if (PUSH_WITHOUT_BRANCH.has(arg)) return { remote: null, branches: [] };
|
|
57333
|
-
if (arg.startsWith("-")) {
|
|
57334
|
-
if (PUSH_VALUE_OPTIONS.has(arg)) i += 1;
|
|
57335
|
-
continue;
|
|
57336
|
-
}
|
|
57337
|
-
positional.push(arg);
|
|
57338
|
-
}
|
|
57339
|
-
const remote = positional[0] ?? null;
|
|
57340
|
-
const refspecs = positional.slice(1);
|
|
57341
|
-
if (refspecs.length === 0) return { remote, branches: [currentBranch] };
|
|
57342
|
-
const branches = [];
|
|
57343
|
-
for (const refspec of refspecs) {
|
|
57344
|
-
const branch = refspecBranch(refspec, currentBranch);
|
|
57345
|
-
if (branch !== void 0) branches.push(branch);
|
|
57346
|
-
}
|
|
57347
|
-
return { remote, branches };
|
|
57348
|
-
}
|
|
57349
|
-
function refspecBranch(refspec, currentBranch) {
|
|
57350
|
-
const spec = refspec.startsWith("+") ? refspec.slice(1) : refspec;
|
|
57351
|
-
if (spec.startsWith(":")) return void 0;
|
|
57352
|
-
const colon = spec.indexOf(":");
|
|
57353
|
-
const destination = colon === -1 ? spec : spec.slice(colon + 1);
|
|
57354
|
-
if (destination === "HEAD") return currentBranch;
|
|
57355
|
-
if (destination.startsWith("refs/heads/")) return destination.slice("refs/heads/".length);
|
|
57356
|
-
if (destination.startsWith("refs/")) return void 0;
|
|
57357
|
-
return REF_NAME.test(destination) ? destination : void 0;
|
|
57358
|
-
}
|
|
57359
|
-
function checkoutTarget(args) {
|
|
57360
|
-
const created = optionValue(args, ["-b", "-B", "-c", "-C"]);
|
|
57361
|
-
if (created !== null) return REF_NAME.test(created) ? created : null;
|
|
57362
|
-
if (args.includes("--")) return void 0;
|
|
57363
|
-
if (args.includes("-") || args.includes("--detach") || args.includes("-d")) return null;
|
|
57364
|
-
const positional = args.filter((arg) => !arg.startsWith("-"));
|
|
57365
|
-
if (positional.length !== 1) return void 0;
|
|
57366
|
-
return REF_NAME.test(positional[0]) ? positional[0] : null;
|
|
57367
|
-
}
|
|
57368
|
-
function optionValue(args, names) {
|
|
57369
|
-
for (let i = 0; i < args.length; i++) {
|
|
57370
|
-
const arg = args[i];
|
|
57371
|
-
for (const name of names) {
|
|
57372
|
-
if (arg === name) return args[i + 1] ?? null;
|
|
57373
|
-
if (name.startsWith("--") && arg.startsWith(`${name}=`)) return arg.slice(name.length + 1);
|
|
57374
|
-
}
|
|
57375
|
-
}
|
|
57376
|
-
return null;
|
|
57377
|
-
}
|
|
57378
|
-
function exitStatusIsOwn(chain, index) {
|
|
57379
|
-
for (let i = index; i < chain.length; i++) {
|
|
57380
|
-
const next = chain[i].next;
|
|
57381
|
-
if (next === null) return true;
|
|
57382
|
-
if (next !== "&&") return false;
|
|
57383
|
-
}
|
|
57384
|
-
return true;
|
|
57385
|
-
}
|
|
57386
|
-
function shellCommands(text) {
|
|
57387
|
-
const commands = [];
|
|
57388
|
-
let words = [];
|
|
57389
|
-
let assignedSubstitutions = [];
|
|
57390
|
-
let word = "";
|
|
57391
|
-
let inWord = false;
|
|
57392
|
-
let quote = null;
|
|
57393
|
-
let heredocs = [];
|
|
57394
|
-
const endWord = () => {
|
|
57395
|
-
if (inWord) words.push(word);
|
|
57396
|
-
word = "";
|
|
57397
|
-
inWord = false;
|
|
57398
|
-
};
|
|
57399
|
-
const endCommand = (next) => {
|
|
57400
|
-
endWord();
|
|
57401
|
-
if (words.length > 0) commands.push({ words: withoutRedirections(words), assignedSubstitutions, next });
|
|
57402
|
-
words = [];
|
|
57403
|
-
assignedSubstitutions = [];
|
|
57404
|
-
};
|
|
57405
|
-
for (let i = 0; i < text.length; i++) {
|
|
57406
|
-
const ch = text[i];
|
|
57407
|
-
if (quote !== null) {
|
|
57408
|
-
if (ch === quote) {
|
|
57409
|
-
quote = null;
|
|
57410
|
-
} else if (quote === '"' && ch === "\\" && i + 1 < text.length) {
|
|
57411
|
-
word += text[++i];
|
|
57412
|
-
} else {
|
|
57413
|
-
word += ch;
|
|
57414
|
-
}
|
|
57415
|
-
inWord = true;
|
|
57416
|
-
continue;
|
|
57417
|
-
}
|
|
57418
|
-
if (ch === "'" || ch === '"') {
|
|
57419
|
-
quote = ch;
|
|
57420
|
-
inWord = true;
|
|
57421
|
-
} else if (ch === "$" && text[i + 1] === "(" || ch === "`") {
|
|
57422
|
-
const end = substitutionEnd(text, i);
|
|
57423
|
-
const after = text[end + 1];
|
|
57424
|
-
const endsWord = after === void 0 || /[\s;&|)]/.test(after);
|
|
57425
|
-
if (ch === "$" && text[end] === ")" && ASSIGNMENT_NAME.test(word) && endsWord) {
|
|
57426
|
-
assignedSubstitutions.push(text.slice(i + 2, end));
|
|
57427
|
-
}
|
|
57428
|
-
word += text.slice(i, end + 1);
|
|
57429
|
-
inWord = true;
|
|
57430
|
-
i = end;
|
|
57431
|
-
} else if (ch === "\\") {
|
|
57432
|
-
const next = text[i + 1];
|
|
57433
|
-
i += 1;
|
|
57434
|
-
if (next !== void 0 && next !== "\n") {
|
|
57435
|
-
word += next;
|
|
57436
|
-
inWord = true;
|
|
57437
|
-
}
|
|
57438
|
-
} else if (ch === "#" && !inWord) {
|
|
57439
|
-
i = lineEnd(text, i) - 1;
|
|
57440
|
-
} else if (ch === "<" && text[i + 1] === "<" && text[i + 2] !== "<") {
|
|
57441
|
-
endWord();
|
|
57442
|
-
const heredoc = heredocDelimiter(text, i + 2);
|
|
57443
|
-
heredocs.push(heredoc.delimiter);
|
|
57444
|
-
i = heredoc.end;
|
|
57445
|
-
} else if (ch === "&" && text[i + 1] === "&") {
|
|
57446
|
-
endCommand("&&");
|
|
57447
|
-
i += 1;
|
|
57448
|
-
} else if (ch === "|" && text[i + 1] === "|") {
|
|
57449
|
-
endCommand("||");
|
|
57450
|
-
i += 1;
|
|
57451
|
-
} else if (ch === "&" && (word.endsWith(">") || word.endsWith("<") || text[i + 1] === ">")) {
|
|
57452
|
-
word += ch;
|
|
57453
|
-
inWord = true;
|
|
57454
|
-
} else if (ch === "|" || ch === "&" || ch === ";") {
|
|
57455
|
-
endCommand(ch);
|
|
57456
|
-
} else if (ch === "\n") {
|
|
57457
|
-
endCommand("\n");
|
|
57458
|
-
if (heredocs.length > 0) {
|
|
57459
|
-
i = heredocBodiesEnd(text, i + 1, heredocs) - 1;
|
|
57460
|
-
heredocs = [];
|
|
57461
|
-
}
|
|
57462
|
-
} else if (/\s/.test(ch) || ch === "(" || ch === ")") {
|
|
57463
|
-
endWord();
|
|
57464
|
-
} else {
|
|
57465
|
-
word += ch;
|
|
57466
|
-
inWord = true;
|
|
57467
|
-
}
|
|
57468
|
-
}
|
|
57469
|
-
endCommand(null);
|
|
57470
|
-
return commands;
|
|
57471
|
-
}
|
|
57472
|
-
function lineEnd(text, from) {
|
|
57473
|
-
const end = text.indexOf("\n", from);
|
|
57474
|
-
return end === -1 ? text.length : end;
|
|
57475
|
-
}
|
|
57476
|
-
function heredocDelimiter(text, from) {
|
|
57477
|
-
let i = from;
|
|
57478
|
-
if (text[i] === "-") i += 1;
|
|
57479
|
-
while (i < text.length && (text[i] === " " || text[i] === " ")) i += 1;
|
|
57480
|
-
const quote = text[i];
|
|
57481
|
-
if (quote === "'" || quote === '"') {
|
|
57482
|
-
const close2 = text.indexOf(quote, i + 1);
|
|
57483
|
-
const end2 = close2 === -1 ? text.length - 1 : close2;
|
|
57484
|
-
return { delimiter: text.slice(i + 1, end2), end: end2 };
|
|
57485
|
-
}
|
|
57486
|
-
let end = i;
|
|
57487
|
-
while (end < text.length && !/[\s;|&<>()]/.test(text[end])) end += 1;
|
|
57488
|
-
return { delimiter: text.slice(i, end), end: end - 1 };
|
|
57489
|
-
}
|
|
57490
|
-
function heredocBodiesEnd(text, from, delimiters) {
|
|
57491
|
-
let i = from;
|
|
57492
|
-
for (const delimiter of delimiters) {
|
|
57493
|
-
for (; ; ) {
|
|
57494
|
-
if (i >= text.length) return text.length;
|
|
57495
|
-
const end = lineEnd(text, i);
|
|
57496
|
-
const line = text.slice(i, end).trim();
|
|
57497
|
-
i = end + 1;
|
|
57498
|
-
if (line === delimiter) break;
|
|
57499
|
-
}
|
|
57500
|
-
}
|
|
57501
|
-
return Math.min(i, text.length);
|
|
57502
|
-
}
|
|
57503
|
-
function substitutionEnd(text, start) {
|
|
57504
|
-
if (text[start] === "`") {
|
|
57505
|
-
const close2 = text.indexOf("`", start + 1);
|
|
57506
|
-
return close2 === -1 ? text.length - 1 : close2;
|
|
57507
|
-
}
|
|
57508
|
-
let depth = 0;
|
|
57509
|
-
for (let i = start + 1; i < text.length; i++) {
|
|
57510
|
-
if (text[i] === "(") depth += 1;
|
|
57511
|
-
else if (text[i] === ")" && --depth === 0) return i;
|
|
57512
|
-
}
|
|
57513
|
-
return text.length - 1;
|
|
57514
|
-
}
|
|
57515
|
-
var REDIRECTION_ALONE = /^\d*&?[<>]{1,3}$/;
|
|
57516
|
-
var REDIRECTION_WITH_TARGET = /^\d*&?[<>]{1,3}\S/;
|
|
57517
|
-
function withoutRedirections(words) {
|
|
57518
|
-
const kept = [];
|
|
57519
|
-
for (let i = 0; i < words.length; i++) {
|
|
57520
|
-
const word = words[i];
|
|
57521
|
-
if (REDIRECTION_ALONE.test(word)) {
|
|
57522
|
-
i += 1;
|
|
57523
|
-
continue;
|
|
57524
|
-
}
|
|
57525
|
-
if (REDIRECTION_WITH_TARGET.test(word)) continue;
|
|
57526
|
-
kept.push(word);
|
|
57527
|
-
}
|
|
57528
|
-
return kept;
|
|
57529
|
-
}
|
|
57530
|
-
|
|
57531
|
-
// ../core/src/prEvidence.ts
|
|
57532
|
-
var WATCHED_CALLS_MAX = 32;
|
|
57533
|
-
var PUSH_EVIDENCE_MAX = 50;
|
|
57534
|
-
var PrEvidenceCollector = class {
|
|
57535
|
-
evidence = [];
|
|
57536
|
-
seen = /* @__PURE__ */ new Set();
|
|
57537
|
-
watched = /* @__PURE__ */ new Map();
|
|
57538
|
-
/** By process id: what a watched call left unsettled when its result said
|
|
57539
|
-
* the process still runs. */
|
|
57540
|
-
running = /* @__PURE__ */ new Map();
|
|
57541
|
-
dropped = 0;
|
|
57542
|
-
/** The harness recorded the pull request for this session. Repeats (a
|
|
57543
|
-
* record per turn while a PR stays bound) keep the first time. */
|
|
57544
|
-
linked(ref, at, line) {
|
|
57545
|
-
this.add({ kind: "pull-request-linked", at, prId: pullRequestId(ref), repository: null, branch: null, line });
|
|
57546
|
-
}
|
|
57547
|
-
/** A shell command the session ran: watched until its result arrives when
|
|
57548
|
-
* it pushes a branch or creates a pull request, ignored otherwise. */
|
|
57549
|
-
command(callId, command, currentBranch, startedAt = null) {
|
|
57550
|
-
this.watch(callId, readCodeHostCommands(command, currentBranch), startedAt);
|
|
57551
|
-
}
|
|
57552
|
-
/** A tool call that would push or create a pull request, in the code host
|
|
57553
|
-
* adapter's terms (a harness's own pull request tool, for example). */
|
|
57554
|
-
watch(callId, commands, startedAt = null) {
|
|
57555
|
-
if (commands.pushes.length === 0 && commands.pullRequestCreates.length === 0) return;
|
|
57556
|
-
keepBounded(this.watched, callId, { ...commands, startedAt });
|
|
57557
|
-
}
|
|
57558
|
-
/** A call that reads more output of a running process (Codex's
|
|
57559
|
-
* write_stdin poll; Claude Code's TaskOutput, or a read of a background
|
|
57560
|
-
* task's output file): its result is read as the rest of the watched call
|
|
57561
|
-
* that started the process. */
|
|
57562
|
-
follow(callId, process2) {
|
|
57563
|
-
const unsettled = this.running.get(process2);
|
|
57564
|
-
if (unsettled === void 0) return;
|
|
57565
|
-
this.running.delete(process2);
|
|
57566
|
-
this.watch(callId, unsettled, unsettled.startedAt);
|
|
57567
|
-
}
|
|
57568
|
-
/** Whether any process is followed, so a parser reads an unwatched
|
|
57569
|
-
* call's output only while it could matter. */
|
|
57570
|
-
following() {
|
|
57571
|
-
return this.running.size > 0;
|
|
57572
|
-
}
|
|
57573
|
-
/** Another call now runs a process under this id: a later poll of the id
|
|
57574
|
-
* is no longer the rest of the watched call that left it running. */
|
|
57575
|
-
forget(process2) {
|
|
57576
|
-
this.running.delete(process2);
|
|
57577
|
-
}
|
|
57578
|
-
/** Watches several watched calls as one, in the order given: the parts of
|
|
57579
|
-
* a call whose output cannot be told apart, read once as a whole. The
|
|
57580
|
-
* parts are one call's, so they started together and the first part's
|
|
57581
|
-
* time is the whole's. */
|
|
57582
|
-
merge(callIds, into) {
|
|
57583
|
-
const parts = callIds.flatMap((callId) => this.watched.get(callId) ?? []);
|
|
57584
|
-
for (const callId of callIds) this.watched.delete(callId);
|
|
57585
|
-
this.watch(
|
|
57586
|
-
into,
|
|
57587
|
-
{
|
|
57588
|
-
pushes: parts.flatMap((part) => part.pushes),
|
|
57589
|
-
pullRequestCreates: parts.flatMap((part) => part.pullRequestCreates)
|
|
57590
|
-
},
|
|
57591
|
-
parts[0]?.startedAt ?? null
|
|
57592
|
-
);
|
|
57593
|
-
}
|
|
57594
|
-
watching(callId) {
|
|
57595
|
-
return this.watched.has(callId);
|
|
57596
|
-
}
|
|
57597
|
-
/**
|
|
57598
|
-
* A watched call's result. A push counts when git's output reports the
|
|
57599
|
-
* branch updated (or already current), or, when the output says nothing
|
|
57600
|
-
* about it, when the call succeeded and that status is the push's own.
|
|
57601
|
-
* Its repository is the `To <url>` git printed: a chain's pushes pair
|
|
57602
|
-
* with the `To` lines in order, or all take the one repository the text
|
|
57603
|
-
* names when they all name one remote (a retry that printed
|
|
57604
|
-
* `Everything up-to-date` prints no `To`); otherwise the repository is
|
|
57605
|
-
* unknown, never a guess. A creation counts when the
|
|
57606
|
-
* result names the pull request: gh prints the created PR's URL last, so
|
|
57607
|
-
* a call with one creation takes the last URL and a call with several
|
|
57608
|
-
* only when the text names exactly as many; a failed call whose status
|
|
57609
|
-
* is the creation's own counts nothing, and neither does a call whose
|
|
57610
|
-
* text carries gh's refusal because the pull request exists (the URL it
|
|
57611
|
-
* prints is that pull request's, and a result read from a file states no
|
|
57612
|
-
* status). A text cut to the URL alone (`| tail -1`, a `grep` of the
|
|
57613
|
-
* output file) hides the refusal, and the URL then counts.
|
|
57614
|
-
*
|
|
57615
|
-
* When the result says one process still runs, whatever it settled
|
|
57616
|
-
* neither way waits for that process's later output (`follow`). A push
|
|
57617
|
-
* git rejected, or a command whose own status failed, is settled: a
|
|
57618
|
-
* later output never revives it.
|
|
57619
|
-
*/
|
|
57620
|
-
result(callId, outcome) {
|
|
57621
|
-
const commands = this.watched.get(callId);
|
|
57622
|
-
if (commands === void 0) return;
|
|
57623
|
-
this.watched.delete(callId);
|
|
57624
|
-
const destinations = pushDestinationsInText(outcome.text);
|
|
57625
|
-
const oneRemote = new Set(commands.pushes.map((push) => push.remote)).size === 1;
|
|
57626
|
-
const shared = oneRemote && new Set(destinations).size === 1 ? destinations[0] : null;
|
|
57627
|
-
const unsettled = { pushes: [], pullRequestCreates: [], startedAt: commands.startedAt };
|
|
57628
|
-
for (const [i, push] of commands.pushes.entries()) {
|
|
57629
|
-
if (push.branch === null) continue;
|
|
57630
|
-
const pushed = pushOutcomeInText(outcome.text, push.branch) ?? (push.ownExitStatus ? outcome.succeeded : null);
|
|
57631
|
-
if (pushed === null) unsettled.pushes.push(push);
|
|
57632
|
-
if (pushed !== true) continue;
|
|
57633
|
-
const repository = destinations.length === commands.pushes.length ? destinations[i] : shared;
|
|
57634
|
-
this.addPush({ kind: "branch-pushed", at: outcome.at, prId: null, repository, branch: push.branch, line: outcome.line });
|
|
57635
|
-
}
|
|
57636
|
-
const creates = commands.pullRequestCreates;
|
|
57637
|
-
const refs = pullRequestRefsInText(outcome.text);
|
|
57638
|
-
const paired = creates.length === 1 ? [refs.at(-1)] : refs.length === creates.length ? refs : [];
|
|
57639
|
-
const refused = pullRequestAlreadyExistsInText(outcome.text);
|
|
57640
|
-
creates.forEach((create, i) => {
|
|
57641
|
-
const ref = paired[i];
|
|
57642
|
-
if (refused || outcome.succeeded === false && create.ownExitStatus) return;
|
|
57643
|
-
if (ref === void 0) {
|
|
57644
|
-
unsettled.pullRequestCreates.push(create);
|
|
57645
|
-
return;
|
|
57646
|
-
}
|
|
57647
|
-
this.add({
|
|
57648
|
-
kind: "pull-request-created",
|
|
57649
|
-
at: outcome.at,
|
|
57650
|
-
prId: pullRequestId(ref),
|
|
57651
|
-
repository: null,
|
|
57652
|
-
branch: create.head,
|
|
57653
|
-
line: outcome.line,
|
|
57654
|
-
commandStartedAt: commands.startedAt
|
|
57655
|
-
});
|
|
57656
|
-
});
|
|
57657
|
-
if (outcome.running === null || unsettled.pushes.length === 0 && unsettled.pullRequestCreates.length === 0) return;
|
|
57658
|
-
keepBounded(this.running, outcome.running, unsettled);
|
|
57659
|
-
}
|
|
57660
|
-
/** The evidence collected, in transcript order, with pushes past the cap
|
|
57661
|
-
* dropped oldest first. Calls still watched and processes still followed
|
|
57662
|
-
* are dropped: their results never arrived. */
|
|
57663
|
-
finish() {
|
|
57664
|
-
this.watched.clear();
|
|
57665
|
-
this.running.clear();
|
|
57666
|
-
const pushes = this.evidence.filter((item) => item.kind === "branch-pushed");
|
|
57667
|
-
if (pushes.length <= PUSH_EVIDENCE_MAX) return this.evidence;
|
|
57668
|
-
const cut = new Set(pushes.slice(0, pushes.length - PUSH_EVIDENCE_MAX));
|
|
57669
|
-
this.dropped = cut.size;
|
|
57670
|
-
return this.evidence.filter((item) => !cut.has(item));
|
|
57671
|
-
}
|
|
57672
|
-
/** Pushes the cap dropped (the oldest first), so a session that pushed
|
|
57673
|
-
* more than PUSH_EVIDENCE_MAX times is reported, not silently cut. */
|
|
57674
|
-
droppedPushes() {
|
|
57675
|
-
return this.dropped;
|
|
57676
|
-
}
|
|
57677
|
-
/** A link is one fact per pull request, and so is a creation per command:
|
|
57678
|
-
* repeats keep the first. Two commands that each named the pull request
|
|
57679
|
-
* are two facts (a refused retry read before the first command's own
|
|
57680
|
-
* output), because the match keeps only the one whose command can have
|
|
57681
|
-
* opened it. */
|
|
57682
|
-
add(item) {
|
|
57683
|
-
const key = `${item.kind}|${item.prId ?? ""}|${item.branch ?? ""}|${item.commandStartedAt ?? ""}`;
|
|
57684
|
-
if (this.seen.has(key)) return;
|
|
57685
|
-
this.seen.add(key);
|
|
57686
|
-
this.evidence.push(item);
|
|
57687
|
-
}
|
|
57688
|
-
/** Every push is kept with its own time; only an exact repeat (one chain
|
|
57689
|
-
* pushing the same branch twice, reported on the same line) is one fact. */
|
|
57690
|
-
addPush(item) {
|
|
57691
|
-
const key = `${item.kind}|${item.repository ?? ""}|${item.branch ?? ""}|${item.at ?? ""}|${item.line}`;
|
|
57692
|
-
if (this.seen.has(key)) return;
|
|
57693
|
-
this.seen.add(key);
|
|
57694
|
-
this.evidence.push(item);
|
|
57695
|
-
}
|
|
57696
|
-
};
|
|
57697
|
-
function keepBounded(map2, key, value) {
|
|
57698
|
-
map2.delete(key);
|
|
57699
|
-
map2.set(key, value);
|
|
57700
|
-
if (map2.size > WATCHED_CALLS_MAX) map2.delete(map2.keys().next().value);
|
|
57701
|
-
}
|
|
57702
|
-
|
|
57703
57110
|
// ../core/src/digest.ts
|
|
57704
57111
|
var TOOL_CALL_INPUT_MAX_BYTES = 65536;
|
|
57705
|
-
function boundedToolInput(value) {
|
|
57706
|
-
return boundRedactedText(JSON.stringify(value), TOOL_CALL_INPUT_MAX_BYTES);
|
|
57707
|
-
}
|
|
57708
57112
|
var tokenCount = external_exports.number().nonnegative();
|
|
57709
57113
|
var costStateSchema = external_exports.object({
|
|
57710
57114
|
sessionId: external_exports.string(),
|
|
@@ -57721,389 +57125,6 @@ var costStateSchema = external_exports.object({
|
|
|
57721
57125
|
})
|
|
57722
57126
|
)
|
|
57723
57127
|
});
|
|
57724
|
-
function runCostOf(record2) {
|
|
57725
|
-
const parsed = costStateSchema.safeParse(record2);
|
|
57726
|
-
if (!parsed.success) return null;
|
|
57727
|
-
const runStartedAt = new Date(parsed.data.startTime);
|
|
57728
|
-
if (Number.isNaN(runStartedAt.getTime())) return null;
|
|
57729
|
-
return {
|
|
57730
|
-
sessionId: parsed.data.sessionId,
|
|
57731
|
-
runStartedAt: runStartedAt.toISOString(),
|
|
57732
|
-
// Claude Code's own restore reads a missing flag as false.
|
|
57733
|
-
unknownModelCost: parsed.data.hasUnknownModelCost ?? false,
|
|
57734
|
-
byModel: Object.entries(parsed.data.modelUsage).map(([model, usage]) => ({
|
|
57735
|
-
model,
|
|
57736
|
-
costUsd: usage.costUSD,
|
|
57737
|
-
tokens: {
|
|
57738
|
-
inputTokens: usage.inputTokens,
|
|
57739
|
-
outputTokens: usage.outputTokens,
|
|
57740
|
-
cacheReadTokens: usage.cacheReadInputTokens,
|
|
57741
|
-
cacheWriteTokens: usage.cacheCreationInputTokens
|
|
57742
|
-
}
|
|
57743
|
-
})).sort((a, b2) => a.model < b2.model ? -1 : a.model > b2.model ? 1 : 0)
|
|
57744
|
-
};
|
|
57745
|
-
}
|
|
57746
|
-
function createDigestTurnParser(options = {}) {
|
|
57747
|
-
const turns = [];
|
|
57748
|
-
let pendingTools = [];
|
|
57749
|
-
let pendingUsage = null;
|
|
57750
|
-
let pendingAt = null;
|
|
57751
|
-
let currentId = null;
|
|
57752
|
-
let currentCarrier = null;
|
|
57753
|
-
let currentBase = null;
|
|
57754
|
-
let currentCounted = false;
|
|
57755
|
-
const countedEnvelopes = /* @__PURE__ */ new Map();
|
|
57756
|
-
let currentReplay = null;
|
|
57757
|
-
let transcriptStartedAt = null;
|
|
57758
|
-
let transcriptSessionId = null;
|
|
57759
|
-
let lastRecordAt = null;
|
|
57760
|
-
let runCost = null;
|
|
57761
|
-
let recordedThrough = null;
|
|
57762
|
-
let laterEnvelopes = [];
|
|
57763
|
-
let laterSet = /* @__PURE__ */ new Set();
|
|
57764
|
-
let usageRevisedAfter = false;
|
|
57765
|
-
const envelopes = [];
|
|
57766
|
-
let pendingEnvelopes = [];
|
|
57767
|
-
let currentEnvelope = null;
|
|
57768
|
-
const evidence = new PrEvidenceCollector();
|
|
57769
|
-
const backgroundTasks = { started: /* @__PURE__ */ new Map(), reads: /* @__PURE__ */ new Map() };
|
|
57770
|
-
let line = -1;
|
|
57771
|
-
const resum = (envelope) => {
|
|
57772
|
-
const landed = envelope.turn === -1 ? pendingEnvelopes : envelopes.filter((e) => e.turn === envelope.turn);
|
|
57773
|
-
const usage = landed.reduce((sum2, e) => mergeUsage(sum2, e.usage), null);
|
|
57774
|
-
if (envelope.turn === -1) pendingUsage = usage;
|
|
57775
|
-
else turns[envelope.turn].usage = usage;
|
|
57776
|
-
};
|
|
57777
|
-
const noteRevision = (envelope, recorded, at) => {
|
|
57778
|
-
if (sameUsage(recorded, envelope.usage)) return;
|
|
57779
|
-
const time3 = at === null ? Number.NaN : Date.parse(at);
|
|
57780
|
-
if (Number.isNaN(time3)) envelope.revisedAt = null;
|
|
57781
|
-
else if (envelope.revisedAt !== null && (envelope.revisedAt === void 0 || Date.parse(envelope.revisedAt) < time3)) {
|
|
57782
|
-
envelope.revisedAt = at;
|
|
57783
|
-
}
|
|
57784
|
-
if (runCost !== null && !laterSet.has(envelope)) usageRevisedAfter = true;
|
|
57785
|
-
};
|
|
57786
|
-
const landPending = (turn) => {
|
|
57787
|
-
for (const envelope of pendingEnvelopes) {
|
|
57788
|
-
envelope.turn = turn;
|
|
57789
|
-
envelopes.push(envelope);
|
|
57790
|
-
}
|
|
57791
|
-
pendingEnvelopes = [];
|
|
57792
|
-
};
|
|
57793
|
-
return {
|
|
57794
|
-
pushLine(raw) {
|
|
57795
|
-
line += 1;
|
|
57796
|
-
const trimmed = raw.trim();
|
|
57797
|
-
if (trimmed === "") return;
|
|
57798
|
-
let record2;
|
|
57799
|
-
try {
|
|
57800
|
-
const parsed = JSON.parse(trimmed);
|
|
57801
|
-
if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) return;
|
|
57802
|
-
record2 = parsed;
|
|
57803
|
-
} catch {
|
|
57804
|
-
return;
|
|
57805
|
-
}
|
|
57806
|
-
transcriptStartedAt ??= recordTime(record2);
|
|
57807
|
-
if (record2.type === "cost-state") {
|
|
57808
|
-
runCost = runCostOf(record2);
|
|
57809
|
-
recordedThrough = lastRecordAt;
|
|
57810
|
-
laterEnvelopes = [];
|
|
57811
|
-
laterSet = /* @__PURE__ */ new Set();
|
|
57812
|
-
usageRevisedAfter = false;
|
|
57813
|
-
return;
|
|
57814
|
-
}
|
|
57815
|
-
if (typeof record2.sessionId === "string") transcriptSessionId ??= record2.sessionId;
|
|
57816
|
-
const recordAt = recordTime(record2);
|
|
57817
|
-
if (recordAt !== null && (lastRecordAt === null || Date.parse(recordAt) > Date.parse(lastRecordAt))) lastRecordAt = recordAt;
|
|
57818
|
-
if (record2.type === "pr-link") {
|
|
57819
|
-
const ref = pullRequestRefFromUrl(typeof record2.prUrl === "string" ? record2.prUrl : "");
|
|
57820
|
-
if (ref !== null) evidence.linked(ref, recordTime(record2), line);
|
|
57821
|
-
return;
|
|
57822
|
-
}
|
|
57823
|
-
if (record2.isMeta === true) return;
|
|
57824
|
-
const at = recordTime(record2);
|
|
57825
|
-
if (record2.type === "user") {
|
|
57826
|
-
toolResults(record2, evidence, backgroundTasks, line);
|
|
57827
|
-
const text = userText(record2);
|
|
57828
|
-
if (text) {
|
|
57829
|
-
const origin = claudeCodeMessageOrigin(originFacts(record2), text);
|
|
57830
|
-
turns.push({ kind: "human_prompt", text, origin, toolCalls: [], usage: null, at });
|
|
57831
|
-
}
|
|
57832
|
-
return;
|
|
57833
|
-
}
|
|
57834
|
-
if (record2.type !== "assistant") return;
|
|
57835
|
-
const message2 = record2.message;
|
|
57836
|
-
if (!message2 || message2.model === "<synthetic>" || !Array.isArray(message2.content)) return;
|
|
57837
|
-
pendingAt ??= at;
|
|
57838
|
-
const id = messageIdOf(record2, message2);
|
|
57839
|
-
if (id === null || id !== currentId) {
|
|
57840
|
-
currentId = id;
|
|
57841
|
-
currentCarrier = null;
|
|
57842
|
-
currentBase = pendingUsage;
|
|
57843
|
-
currentReplay = id === null ? null : countedEnvelopes.get(id) ?? null;
|
|
57844
|
-
currentCounted = currentReplay !== null;
|
|
57845
|
-
}
|
|
57846
|
-
const parsedUsage = recordTurnUsage(message2);
|
|
57847
|
-
if (parsedUsage) {
|
|
57848
|
-
if (currentReplay) {
|
|
57849
|
-
const recorded = currentReplay.usage;
|
|
57850
|
-
keepRecordedFacts(parsedUsage, recorded, message2.usage?.inference_geo);
|
|
57851
|
-
currentReplay.usage = parsedUsage;
|
|
57852
|
-
noteRevision(currentReplay, recorded, at);
|
|
57853
|
-
resum(currentReplay);
|
|
57854
|
-
} else if (currentCounted) {
|
|
57855
|
-
const recorded = currentEnvelope?.usage;
|
|
57856
|
-
if (recorded !== void 0) keepRecordedFacts(parsedUsage, recorded, message2.usage?.inference_geo);
|
|
57857
|
-
const updated = mergeUsage(currentBase, parsedUsage);
|
|
57858
|
-
if (currentCarrier) currentCarrier.usage = updated;
|
|
57859
|
-
else pendingUsage = updated;
|
|
57860
|
-
if (currentEnvelope !== null && recorded !== void 0) {
|
|
57861
|
-
currentEnvelope.usage = parsedUsage;
|
|
57862
|
-
noteRevision(currentEnvelope, recorded, at);
|
|
57863
|
-
}
|
|
57864
|
-
} else if (currentCarrier) {
|
|
57865
|
-
currentCarrier.usage = mergeUsage(currentCarrier.usage, parsedUsage);
|
|
57866
|
-
currentCounted = true;
|
|
57867
|
-
currentEnvelope = { turn: turns.indexOf(currentCarrier), at, usage: parsedUsage, branch: recordBranch(record2) };
|
|
57868
|
-
envelopes.push(currentEnvelope);
|
|
57869
|
-
laterEnvelopes.push(currentEnvelope);
|
|
57870
|
-
laterSet.add(currentEnvelope);
|
|
57871
|
-
if (id !== null) countedEnvelopes.set(id, currentEnvelope);
|
|
57872
|
-
} else {
|
|
57873
|
-
pendingUsage = mergeUsage(pendingUsage, parsedUsage);
|
|
57874
|
-
currentCounted = true;
|
|
57875
|
-
currentEnvelope = { turn: -1, at, usage: parsedUsage, branch: recordBranch(record2) };
|
|
57876
|
-
pendingEnvelopes.push(currentEnvelope);
|
|
57877
|
-
laterEnvelopes.push(currentEnvelope);
|
|
57878
|
-
laterSet.add(currentEnvelope);
|
|
57879
|
-
if (id !== null) countedEnvelopes.set(id, currentEnvelope);
|
|
57880
|
-
}
|
|
57881
|
-
}
|
|
57882
|
-
const model = typeof message2.model === "string" ? message2.model : null;
|
|
57883
|
-
const facts = originFacts(record2);
|
|
57884
|
-
for (const block2 of message2.content) {
|
|
57885
|
-
const part = block2;
|
|
57886
|
-
if (part.type === "tool_use" && typeof part.name === "string") {
|
|
57887
|
-
const call = { name: part.name, ...toolFilePath(part.input) };
|
|
57888
|
-
if (options.keepToolInputs === true && isRecord(part.input)) {
|
|
57889
|
-
call.input = boundedToolInput(part.input);
|
|
57890
|
-
}
|
|
57891
|
-
pendingTools.push(call);
|
|
57892
|
-
if (part.name === "Bash" && typeof part.id === "string" && typeof part.input?.command === "string") {
|
|
57893
|
-
evidence.command(part.id, part.input.command, recordBranch(record2), at);
|
|
57894
|
-
}
|
|
57895
|
-
if (typeof part.id === "string") followBackgroundTask(part.id, part.name, part.input, evidence, backgroundTasks);
|
|
57896
|
-
}
|
|
57897
|
-
if (part.type === "text" && typeof part.text === "string" && part.text.trim() !== "") {
|
|
57898
|
-
const origin = claudeCodeMessageOrigin(facts, part.text);
|
|
57899
|
-
if (currentCarrier === null) {
|
|
57900
|
-
const turn = {
|
|
57901
|
-
kind: "agent_text",
|
|
57902
|
-
text: part.text,
|
|
57903
|
-
origin,
|
|
57904
|
-
toolCalls: pendingTools,
|
|
57905
|
-
// A message written again carries zero of its own: its money
|
|
57906
|
-
// landed where it was first counted.
|
|
57907
|
-
usage: pendingUsage ?? (currentReplay ? zeroUsage(model) : null),
|
|
57908
|
-
at: pendingAt
|
|
57909
|
-
};
|
|
57910
|
-
turns.push(turn);
|
|
57911
|
-
currentCarrier = turn;
|
|
57912
|
-
pendingUsage = null;
|
|
57913
|
-
landPending(turns.length - 1);
|
|
57914
|
-
} else {
|
|
57915
|
-
turns.push({
|
|
57916
|
-
kind: "agent_text",
|
|
57917
|
-
text: part.text,
|
|
57918
|
-
origin,
|
|
57919
|
-
toolCalls: pendingTools,
|
|
57920
|
-
usage: currentCounted ? zeroUsage(model) : null,
|
|
57921
|
-
// A sibling block of the same record began when the record did.
|
|
57922
|
-
at: pendingAt ?? at
|
|
57923
|
-
});
|
|
57924
|
-
}
|
|
57925
|
-
pendingTools = [];
|
|
57926
|
-
pendingAt = null;
|
|
57927
|
-
}
|
|
57928
|
-
}
|
|
57929
|
-
},
|
|
57930
|
-
finish() {
|
|
57931
|
-
if (pendingTools.length > 0 || pendingUsage !== null) {
|
|
57932
|
-
turns.push({ kind: "agent_text", text: "", origin: "agent", toolCalls: pendingTools, usage: pendingUsage, at: pendingAt });
|
|
57933
|
-
landPending(turns.length - 1);
|
|
57934
|
-
pendingTools = [];
|
|
57935
|
-
pendingUsage = null;
|
|
57936
|
-
pendingAt = null;
|
|
57937
|
-
}
|
|
57938
|
-
return turns;
|
|
57939
|
-
},
|
|
57940
|
-
usageEnvelopes() {
|
|
57941
|
-
return envelopes;
|
|
57942
|
-
},
|
|
57943
|
-
harnessCost() {
|
|
57944
|
-
if (runCost === null || runCost.sessionId !== transcriptSessionId) return null;
|
|
57945
|
-
const { runStartedAt, unknownModelCost, byModel } = runCost;
|
|
57946
|
-
const laterUsage = laterEnvelopes.map((envelope) => envelope.usage);
|
|
57947
|
-
return { runStartedAt, transcriptStartedAt, recordedThrough, unknownModelCost, byModel, usageRevisedAfter, laterUsage };
|
|
57948
|
-
},
|
|
57949
|
-
prEvidence() {
|
|
57950
|
-
return evidence.finish();
|
|
57951
|
-
},
|
|
57952
|
-
prEvidenceDroppedPushes() {
|
|
57953
|
-
return evidence.droppedPushes();
|
|
57954
|
-
}
|
|
57955
|
-
};
|
|
57956
|
-
}
|
|
57957
|
-
function originFacts(record2) {
|
|
57958
|
-
const message2 = isRecord(record2.message) ? record2.message : null;
|
|
57959
|
-
const origin = isRecord(record2.origin) ? record2.origin : null;
|
|
57960
|
-
const recordType = typeof record2.type === "string" ? record2.type : null;
|
|
57961
|
-
return {
|
|
57962
|
-
recordType,
|
|
57963
|
-
role: typeof message2?.role === "string" ? message2.role : recordType,
|
|
57964
|
-
originRecorded: record2.origin !== void 0,
|
|
57965
|
-
nativeOrigin: typeof origin?.kind === "string" ? origin.kind : null,
|
|
57966
|
-
isMeta: typeof record2.isMeta === "boolean" ? record2.isMeta : null,
|
|
57967
|
-
isCompactSummary: typeof record2.isCompactSummary === "boolean" ? record2.isCompactSummary : null,
|
|
57968
|
-
model: typeof message2?.model === "string" ? message2.model : null,
|
|
57969
|
-
commandMode: null
|
|
57970
|
-
};
|
|
57971
|
-
}
|
|
57972
|
-
function recordTime(record2) {
|
|
57973
|
-
return typeof record2.timestamp === "string" && record2.timestamp !== "" ? record2.timestamp : null;
|
|
57974
|
-
}
|
|
57975
|
-
function isRecord(value) {
|
|
57976
|
-
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
57977
|
-
}
|
|
57978
|
-
function recordBranch(record2) {
|
|
57979
|
-
return typeof record2.gitBranch === "string" && record2.gitBranch !== "" ? record2.gitBranch : null;
|
|
57980
|
-
}
|
|
57981
|
-
function followBackgroundTask(callId, tool, input2, evidence, tasks) {
|
|
57982
|
-
if (tasks.started.size === 0 || evidence.watching(callId)) return;
|
|
57983
|
-
const named = tool === "TaskOutput" ? input2?.task_id : tool === "Read" ? input2?.file_path : tool === "Bash" ? input2?.command : void 0;
|
|
57984
|
-
if (typeof named !== "string" || tool === "Bash" && RUNS_GH.test(named)) return;
|
|
57985
|
-
const read = new Set(
|
|
57986
|
-
[...tasks.started].filter(([task]) => tool === "TaskOutput" ? named === task : named.includes(`/${task}.output`)).map(([, followed2]) => followed2)
|
|
57987
|
-
);
|
|
57988
|
-
if (read.size !== 1) return;
|
|
57989
|
-
const [followed] = read;
|
|
57990
|
-
evidence.follow(callId, followed);
|
|
57991
|
-
if (evidence.watching(callId)) keepBounded(tasks.reads, callId, followed);
|
|
57992
|
-
}
|
|
57993
|
-
var RUNS_GH = /(?:^|[\s;&|(])gh\s/;
|
|
57994
|
-
function toolResults(record2, evidence, tasks, line) {
|
|
57995
|
-
const content = isRecord(record2.message) ? record2.message.content : void 0;
|
|
57996
|
-
if (!Array.isArray(content)) return;
|
|
57997
|
-
const result = isRecord(record2.toolUseResult) ? record2.toolUseResult : {};
|
|
57998
|
-
const file2 = isRecord(result.file) ? result.file : {};
|
|
57999
|
-
const task = isRecord(result.task) ? result.task : {};
|
|
58000
|
-
for (const block2 of content) {
|
|
58001
|
-
if (!isRecord(block2) || block2.type !== "tool_result" || typeof block2.tool_use_id !== "string") continue;
|
|
58002
|
-
if (!evidence.watching(block2.tool_use_id)) continue;
|
|
58003
|
-
const reads = tasks.reads.get(block2.tool_use_id);
|
|
58004
|
-
tasks.reads.delete(block2.tool_use_id);
|
|
58005
|
-
const started = typeof result.backgroundTaskId === "string" ? result.backgroundTaskId : null;
|
|
58006
|
-
if (started !== null) keepBounded(tasks.started, started, reads ?? started);
|
|
58007
|
-
const failed2 = block2.is_error === true || result.interrupted === true;
|
|
58008
|
-
const taskExited = typeof task.exitCode === "number" && task.task_id === reads;
|
|
58009
|
-
const status = reads !== void 0 ? { succeeded: taskExited ? task.exitCode === 0 : null, running: taskExited ? null : reads } : { succeeded: failed2 ? false : started !== null ? null : true, running: started };
|
|
58010
|
-
evidence.result(block2.tool_use_id, {
|
|
58011
|
-
...status,
|
|
58012
|
-
text: [result.stdout, result.stderr, file2.content, task.output].filter((part) => typeof part === "string").concat(contentText(block2.content)).join("\n"),
|
|
58013
|
-
at: recordTime(record2),
|
|
58014
|
-
line
|
|
58015
|
-
});
|
|
58016
|
-
}
|
|
58017
|
-
}
|
|
58018
|
-
function contentText(content) {
|
|
58019
|
-
if (typeof content === "string") return content;
|
|
58020
|
-
if (!Array.isArray(content)) return "";
|
|
58021
|
-
return content.map((block2) => isRecord(block2) && typeof block2.text === "string" ? block2.text : "").join("\n");
|
|
58022
|
-
}
|
|
58023
|
-
function messageIdOf(record2, message2) {
|
|
58024
|
-
if (typeof message2.id === "string") return message2.id;
|
|
58025
|
-
if (typeof record2.requestId === "string") return record2.requestId;
|
|
58026
|
-
if (typeof record2.uuid === "string") return record2.uuid;
|
|
58027
|
-
return null;
|
|
58028
|
-
}
|
|
58029
|
-
function keepRecordedFacts(later, recorded, laterGeo) {
|
|
58030
|
-
if ((later.serviceTier === void 0 || later.serviceTier === "unknown") && recorded.serviceTier !== void 0) {
|
|
58031
|
-
later.serviceTier = recorded.serviceTier;
|
|
58032
|
-
}
|
|
58033
|
-
if (later.cacheWrite1hTokens === null && recorded.cacheWriteTokens === later.cacheWriteTokens) {
|
|
58034
|
-
later.cacheWrite1hTokens = recorded.cacheWrite1hTokens;
|
|
58035
|
-
}
|
|
58036
|
-
if (GEOGRAPHY_SAYS_NOTHING.has(laterGeo) && recorded.usOnlyInference === true) later.usOnlyInference = true;
|
|
58037
|
-
}
|
|
58038
|
-
var GEOGRAPHY_SAYS_NOTHING = /* @__PURE__ */ new Set([void 0, null, "not_available"]);
|
|
58039
|
-
function recordTurnUsage(message2) {
|
|
58040
|
-
const usage = message2.usage;
|
|
58041
|
-
if (!usage || typeof usage !== "object") return null;
|
|
58042
|
-
const count3 = (v) => typeof v === "number" && Number.isFinite(v) ? v : null;
|
|
58043
|
-
const input2 = count3(usage.input_tokens);
|
|
58044
|
-
const output2 = count3(usage.output_tokens);
|
|
58045
|
-
if (input2 === null && output2 === null) return null;
|
|
58046
|
-
const cacheCreation = isRecord(usage.cache_creation) ? usage.cache_creation : null;
|
|
58047
|
-
const speed = usage.speed;
|
|
58048
|
-
return {
|
|
58049
|
-
inputTokens: input2 ?? 0,
|
|
58050
|
-
outputTokens: output2 ?? 0,
|
|
58051
|
-
cacheReadTokens: count3(usage.cache_read_input_tokens),
|
|
58052
|
-
cacheWriteTokens: count3(usage.cache_creation_input_tokens),
|
|
58053
|
-
cacheWrite1hTokens: cacheCreation === null ? null : count3(cacheCreation.ephemeral_1h_input_tokens),
|
|
58054
|
-
model: typeof message2.model === "string" ? message2.model : null,
|
|
58055
|
-
// The same speed values the collector reads for the session's Fast
|
|
58056
|
-
// split; a speed it does not recognize is unknown (standard rate), and
|
|
58057
|
-
// a null speed is no speed, as the collector reads it.
|
|
58058
|
-
...speed !== void 0 && speed !== null && {
|
|
58059
|
-
serviceTier: speed === "fast" || speed === "standard" ? speed : "unknown"
|
|
58060
|
-
},
|
|
58061
|
-
...usage.inference_geo === "us" && { usOnlyInference: true }
|
|
58062
|
-
};
|
|
58063
|
-
}
|
|
58064
|
-
function zeroUsage(model) {
|
|
58065
|
-
return { inputTokens: 0, outputTokens: 0, cacheReadTokens: 0, cacheWriteTokens: 0, cacheWrite1hTokens: 0, model };
|
|
58066
|
-
}
|
|
58067
|
-
function sameUsage(a, b2) {
|
|
58068
|
-
return a.inputTokens === b2.inputTokens && a.outputTokens === b2.outputTokens && a.cacheReadTokens === b2.cacheReadTokens && a.cacheWriteTokens === b2.cacheWriteTokens && a.cacheWrite1hTokens === b2.cacheWrite1hTokens && a.model === b2.model && a.serviceTier === b2.serviceTier && a.usOnlyInference === b2.usOnlyInference;
|
|
58069
|
-
}
|
|
58070
|
-
function mergeUsage(a, b2) {
|
|
58071
|
-
if (!a) return b2;
|
|
58072
|
-
if (!b2) return a;
|
|
58073
|
-
const cache = (x, y) => x === null || y === null ? null : x + y;
|
|
58074
|
-
const serviceTier = a.serviceTier === b2.serviceTier ? a.serviceTier : "unknown";
|
|
58075
|
-
return {
|
|
58076
|
-
inputTokens: a.inputTokens + b2.inputTokens,
|
|
58077
|
-
outputTokens: a.outputTokens + b2.outputTokens,
|
|
58078
|
-
cacheReadTokens: cache(a.cacheReadTokens, b2.cacheReadTokens),
|
|
58079
|
-
cacheWriteTokens: cache(a.cacheWriteTokens, b2.cacheWriteTokens),
|
|
58080
|
-
cacheWrite1hTokens: cache(a.cacheWrite1hTokens, b2.cacheWrite1hTokens),
|
|
58081
|
-
model: a.model ?? b2.model,
|
|
58082
|
-
...serviceTier !== void 0 && { serviceTier },
|
|
58083
|
-
...a.usOnlyInference === true && b2.usOnlyInference === true && { usOnlyInference: true }
|
|
58084
|
-
};
|
|
58085
|
-
}
|
|
58086
|
-
function userText(record2) {
|
|
58087
|
-
const message2 = record2.message;
|
|
58088
|
-
const content = message2?.content;
|
|
58089
|
-
if (typeof content === "string") return content.trim() === "" ? null : content;
|
|
58090
|
-
if (!Array.isArray(content)) return null;
|
|
58091
|
-
const parts = [];
|
|
58092
|
-
for (const block2 of content) {
|
|
58093
|
-
if (!isRecord(block2)) continue;
|
|
58094
|
-
if (block2.type === "text" && typeof block2.text === "string" && block2.text.trim() !== "") {
|
|
58095
|
-
parts.push(block2.text);
|
|
58096
|
-
continue;
|
|
58097
|
-
}
|
|
58098
|
-
const image = describeImageBlock(block2);
|
|
58099
|
-
if (image) parts.push(imageLabel(image));
|
|
58100
|
-
}
|
|
58101
|
-
return parts.length > 0 ? parts.join("\n") : null;
|
|
58102
|
-
}
|
|
58103
|
-
function toolFilePath(input2) {
|
|
58104
|
-
const candidate = input2?.file_path ?? input2?.path ?? input2?.notebook_path;
|
|
58105
|
-
return typeof candidate === "string" ? { filePath: candidate } : {};
|
|
58106
|
-
}
|
|
58107
57128
|
|
|
58108
57129
|
// ../core/src/collectorDiagnostics.ts
|
|
58109
57130
|
var count = external_exports.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER);
|
|
@@ -58176,6 +57197,8 @@ var collectorPassDiagnosticSchema = external_exports.strictObject({
|
|
|
58176
57197
|
"codex",
|
|
58177
57198
|
"cursor",
|
|
58178
57199
|
"metadata",
|
|
57200
|
+
// Sent only by collectors released before preview registration was
|
|
57201
|
+
// removed. Accepted until the supported-version floor passes them.
|
|
58179
57202
|
"previews",
|
|
58180
57203
|
"raw",
|
|
58181
57204
|
"complete"
|
|
@@ -58304,7 +57327,7 @@ function excludeImageCarriers(record2) {
|
|
|
58304
57327
|
return withoutImages(item, itemPath);
|
|
58305
57328
|
});
|
|
58306
57329
|
}
|
|
58307
|
-
if (!
|
|
57330
|
+
if (!isRecord(value)) return value;
|
|
58308
57331
|
const kept = [];
|
|
58309
57332
|
for (const [key, item] of Object.entries(value)) {
|
|
58310
57333
|
const keyPath = path55 === "" ? key : `${path55}.${key}`;
|
|
@@ -58346,64 +57369,14 @@ function retainFieldsBounded(record2, maxBytes) {
|
|
|
58346
57369
|
function nativeTypeLabel(value) {
|
|
58347
57370
|
return typeof value === "string" && /^[A-Za-z0-9_.:/-]{1,64}$/.test(value) ? value : void 0;
|
|
58348
57371
|
}
|
|
58349
|
-
function
|
|
58350
|
-
const turns = [];
|
|
58351
|
-
let pendingTools = [];
|
|
58352
|
-
let pendingAt = null;
|
|
58353
|
-
const flushPendingTools = () => {
|
|
58354
|
-
if (pendingTools.length === 0) return;
|
|
58355
|
-
turns.push({ kind: "agent_text", text: "", origin: "agent", toolCalls: pendingTools, usage: null, at: pendingAt });
|
|
58356
|
-
pendingTools = [];
|
|
58357
|
-
pendingAt = null;
|
|
58358
|
-
};
|
|
58359
|
-
return {
|
|
58360
|
-
pushLine(line) {
|
|
58361
|
-
const trimmed = line.trim();
|
|
58362
|
-
if (trimmed === "") return;
|
|
58363
|
-
let record2;
|
|
58364
|
-
try {
|
|
58365
|
-
const parsed = JSON.parse(trimmed);
|
|
58366
|
-
if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) return;
|
|
58367
|
-
record2 = parsed;
|
|
58368
|
-
} catch {
|
|
58369
|
-
return;
|
|
58370
|
-
}
|
|
58371
|
-
const at = typeof record2.createdAt === "string" && record2.createdAt !== "" ? record2.createdAt : null;
|
|
58372
|
-
if (record2.type === "user" && typeof record2.text === "string" && record2.text.trim() !== "") {
|
|
58373
|
-
flushPendingTools();
|
|
58374
|
-
turns.push({ kind: "human_prompt", text: record2.text, origin: "unknown", toolCalls: [], usage: null, at });
|
|
58375
|
-
return;
|
|
58376
|
-
}
|
|
58377
|
-
if (record2.type === "tool" && typeof record2.name === "string") {
|
|
58378
|
-
const call = { name: record2.name };
|
|
58379
|
-
if (typeof record2.filePath === "string") call.filePath = record2.filePath;
|
|
58380
|
-
if (options.keepToolInputs === true && isRecord2(record2.args)) {
|
|
58381
|
-
call.input = boundedToolInput(record2.args);
|
|
58382
|
-
}
|
|
58383
|
-
pendingTools.push(call);
|
|
58384
|
-
pendingAt ??= at;
|
|
58385
|
-
return;
|
|
58386
|
-
}
|
|
58387
|
-
if (record2.type === "agent" && typeof record2.text === "string" && record2.text.trim() !== "") {
|
|
58388
|
-
turns.push({ kind: "agent_text", text: record2.text, origin: "agent", toolCalls: pendingTools, usage: null, at: pendingAt ?? at });
|
|
58389
|
-
pendingTools = [];
|
|
58390
|
-
pendingAt = null;
|
|
58391
|
-
}
|
|
58392
|
-
},
|
|
58393
|
-
finish() {
|
|
58394
|
-
flushPendingTools();
|
|
58395
|
-
return turns;
|
|
58396
|
-
}
|
|
58397
|
-
};
|
|
58398
|
-
}
|
|
58399
|
-
function isRecord2(value) {
|
|
57372
|
+
function isRecord(value) {
|
|
58400
57373
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
58401
57374
|
}
|
|
58402
57375
|
|
|
58403
57376
|
// ../core/src/codexResponseUsage.ts
|
|
58404
57377
|
var count2 = (value) => typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : null;
|
|
58405
57378
|
function readTotals(value) {
|
|
58406
|
-
if (!
|
|
57379
|
+
if (!isRecord(value)) return null;
|
|
58407
57380
|
const inputTokens = count2(value.input_tokens);
|
|
58408
57381
|
const outputTokens = count2(value.output_tokens);
|
|
58409
57382
|
if (inputTokens === null || outputTokens === null) return null;
|
|
@@ -58486,11 +57459,11 @@ function createCodexUsageReader(options = {}) {
|
|
|
58486
57459
|
return {
|
|
58487
57460
|
startPage,
|
|
58488
57461
|
pushRecord(record2) {
|
|
58489
|
-
if (!
|
|
58490
|
-
const payload =
|
|
57462
|
+
if (!isRecord(record2) || typeof record2.type !== "string") return;
|
|
57463
|
+
const payload = isRecord(record2.payload) ? record2.payload : null;
|
|
58491
57464
|
const at = typeof record2.timestamp === "string" && record2.timestamp !== "" ? record2.timestamp : null;
|
|
58492
57465
|
if (record2.type === "session_meta") {
|
|
58493
|
-
if (payload !== null &&
|
|
57466
|
+
if (payload !== null && isRecord(payload.history_base)) startPage();
|
|
58494
57467
|
return;
|
|
58495
57468
|
}
|
|
58496
57469
|
if (payload === null) return;
|
|
@@ -58521,7 +57494,7 @@ function createCodexUsageReader(options = {}) {
|
|
|
58521
57494
|
}
|
|
58522
57495
|
if (record2.type !== "event_msg") return;
|
|
58523
57496
|
if (payload.type === "thread_settings_applied") {
|
|
58524
|
-
const settings =
|
|
57497
|
+
const settings = isRecord(payload.thread_settings) ? payload.thread_settings : null;
|
|
58525
57498
|
if (settings !== null && settings.service_tier !== void 0) {
|
|
58526
57499
|
tier = codexServiceTier(settings.service_tier) ?? "unknown";
|
|
58527
57500
|
nativeTier = typeof settings.service_tier === "string" ? settings.service_tier : null;
|
|
@@ -58531,7 +57504,7 @@ function createCodexUsageReader(options = {}) {
|
|
|
58531
57504
|
}
|
|
58532
57505
|
if (payload.type !== "token_count") return;
|
|
58533
57506
|
if (payload.info === null || payload.info === void 0) return;
|
|
58534
|
-
if (!
|
|
57507
|
+
if (!isRecord(payload.info)) {
|
|
58535
57508
|
summary.malformedRecords += 1;
|
|
58536
57509
|
return;
|
|
58537
57510
|
}
|
|
@@ -58560,17 +57533,6 @@ function createCodexUsageReader(options = {}) {
|
|
|
58560
57533
|
}
|
|
58561
57534
|
};
|
|
58562
57535
|
}
|
|
58563
|
-
function codexResponseTurnUsage(entry) {
|
|
58564
|
-
return {
|
|
58565
|
-
inputTokens: Math.max(0, entry.counts.inputTokens - entry.counts.cachedInputTokens),
|
|
58566
|
-
outputTokens: entry.counts.outputTokens,
|
|
58567
|
-
cacheReadTokens: entry.counts.cachedInputTokens,
|
|
58568
|
-
cacheWriteTokens: null,
|
|
58569
|
-
cacheWrite1hTokens: null,
|
|
58570
|
-
model: entry.model,
|
|
58571
|
-
serviceTier: entry.serviceTier
|
|
58572
|
-
};
|
|
58573
|
-
}
|
|
58574
57536
|
function codexPageTotals(read) {
|
|
58575
57537
|
if (read.entries.length === 0 && read.uncounted.length === 0) return null;
|
|
58576
57538
|
const totals = { input: 0, cached: 0, output: 0 };
|
|
@@ -58616,39 +57578,6 @@ var MACHINE_ENROLL_CALLBACK_PORT = 41999;
|
|
|
58616
57578
|
var MACHINE_ENROLL_CALLBACK_PATH = "/callback";
|
|
58617
57579
|
var MACHINE_ENROLL_CALLBACK_URL = `http://127.0.0.1:${MACHINE_ENROLL_CALLBACK_PORT}${MACHINE_ENROLL_CALLBACK_PATH}`;
|
|
58618
57580
|
|
|
58619
|
-
// ../core/src/sessionRooms.ts
|
|
58620
|
-
var RECENT_ACTIVITY_WINDOW_MS = 5 * 24 * 36e5;
|
|
58621
|
-
function capturedSessionEvents(turns, anchor2) {
|
|
58622
|
-
const events = [];
|
|
58623
|
-
const base = {
|
|
58624
|
-
actor: null,
|
|
58625
|
-
member: null,
|
|
58626
|
-
deliveryState: null,
|
|
58627
|
-
occurredAt: null,
|
|
58628
|
-
observedAt: anchor2.observedAt
|
|
58629
|
-
};
|
|
58630
|
-
turns.forEach((turn, index) => {
|
|
58631
|
-
turn.toolCalls.forEach((call, callIndex) => {
|
|
58632
|
-
events.push({
|
|
58633
|
-
...base,
|
|
58634
|
-
id: `${anchor2.sessionId}:${index}:tool:${callIndex}`,
|
|
58635
|
-
kind: "tool_activity",
|
|
58636
|
-
text: null,
|
|
58637
|
-
toolName: call.name
|
|
58638
|
-
});
|
|
58639
|
-
});
|
|
58640
|
-
if (turn.text.trim() === "") return;
|
|
58641
|
-
events.push({
|
|
58642
|
-
...base,
|
|
58643
|
-
id: `${anchor2.sessionId}:${index}:${turn.kind}`,
|
|
58644
|
-
kind: turn.kind === "human_prompt" ? "agent_prompt" : "agent_response",
|
|
58645
|
-
text: turn.text,
|
|
58646
|
-
toolName: null
|
|
58647
|
-
});
|
|
58648
|
-
});
|
|
58649
|
-
return events;
|
|
58650
|
-
}
|
|
58651
|
-
|
|
58652
57581
|
// ../core/src/workspaceClaims.ts
|
|
58653
57582
|
function workspaceClaimsRepo(repoFullName, policy) {
|
|
58654
57583
|
const repo = repoFullName.toLowerCase();
|
|
@@ -58660,716 +57589,8 @@ function workspaceClaimsAnyRepo(policy) {
|
|
|
58660
57589
|
return policy.repos !== null ? policy.repos.length > 0 : policy.owners.length > 0;
|
|
58661
57590
|
}
|
|
58662
57591
|
|
|
58663
|
-
// ../core/src/codexRollout.ts
|
|
58664
|
-
function toolCallName(item) {
|
|
58665
|
-
switch (item.type) {
|
|
58666
|
-
case "function_call":
|
|
58667
|
-
case "custom_tool_call":
|
|
58668
|
-
return typeof item.name === "string" ? item.name : null;
|
|
58669
|
-
case "local_shell_call":
|
|
58670
|
-
return "shell";
|
|
58671
|
-
case "web_search_call":
|
|
58672
|
-
return "web_search";
|
|
58673
|
-
default:
|
|
58674
|
-
return null;
|
|
58675
|
-
}
|
|
58676
|
-
}
|
|
58677
|
-
function toolCallArguments(item) {
|
|
58678
|
-
switch (item.type) {
|
|
58679
|
-
case "function_call": {
|
|
58680
|
-
if (typeof item.arguments !== "string") return null;
|
|
58681
|
-
const parsed = safeJsonRecord(item.arguments);
|
|
58682
|
-
return parsed ?? { arguments: item.arguments };
|
|
58683
|
-
}
|
|
58684
|
-
case "custom_tool_call":
|
|
58685
|
-
return typeof item.input === "string" ? { input: item.input } : null;
|
|
58686
|
-
case "local_shell_call":
|
|
58687
|
-
case "web_search_call":
|
|
58688
|
-
return asRecord2(item.action);
|
|
58689
|
-
default:
|
|
58690
|
-
return null;
|
|
58691
|
-
}
|
|
58692
|
-
}
|
|
58693
|
-
function asRecord2(value) {
|
|
58694
|
-
return value !== null && typeof value === "object" && !Array.isArray(value) ? value : null;
|
|
58695
|
-
}
|
|
58696
|
-
function safeJsonRecord(text) {
|
|
58697
|
-
try {
|
|
58698
|
-
return asRecord2(JSON.parse(text));
|
|
58699
|
-
} catch {
|
|
58700
|
-
return null;
|
|
58701
|
-
}
|
|
58702
|
-
}
|
|
58703
|
-
function outputTextBlocks(content) {
|
|
58704
|
-
if (!Array.isArray(content)) return [];
|
|
58705
|
-
return content.filter(
|
|
58706
|
-
(block2) => typeof block2 === "object" && block2 !== null && block2.type === "output_text" && typeof block2.text === "string"
|
|
58707
|
-
).map((block2) => block2.text);
|
|
58708
|
-
}
|
|
58709
|
-
function promptText(content) {
|
|
58710
|
-
if (!Array.isArray(content)) return null;
|
|
58711
|
-
const kept = [];
|
|
58712
|
-
const textOrigins = [];
|
|
58713
|
-
for (const raw of content) {
|
|
58714
|
-
const block2 = asRecord2(raw);
|
|
58715
|
-
if (!block2) continue;
|
|
58716
|
-
if (block2.type === "input_image") {
|
|
58717
|
-
kept.push(imageLabel(describeImageUrl(block2.image_url)));
|
|
58718
|
-
continue;
|
|
58719
|
-
}
|
|
58720
|
-
if (block2.type !== "input_text" || typeof block2.text !== "string") continue;
|
|
58721
|
-
const parsed = codexPromptBlock(block2.text);
|
|
58722
|
-
if (parsed.origin === "harness") continue;
|
|
58723
|
-
textOrigins.push(parsed.origin);
|
|
58724
|
-
if (parsed.ask !== "") kept.push(parsed.ask);
|
|
58725
|
-
}
|
|
58726
|
-
return kept.length === 0 ? null : { text: kept.join("\n"), origin: codexPromptOrigin(textOrigins) };
|
|
58727
|
-
}
|
|
58728
|
-
function createCodexTurnParser(options = {}) {
|
|
58729
|
-
const turns = [];
|
|
58730
|
-
let pendingTools = [];
|
|
58731
|
-
let pendingAt = null;
|
|
58732
|
-
const evidence = new PrEvidenceCollector();
|
|
58733
|
-
const scripts = /* @__PURE__ */ new Map();
|
|
58734
|
-
const runningScripts = /* @__PURE__ */ new Map();
|
|
58735
|
-
let line = -1;
|
|
58736
|
-
const envelopes = [];
|
|
58737
|
-
let pendingEnvelopes = [];
|
|
58738
|
-
let turnsAtLastEntry = 0;
|
|
58739
|
-
const landPending = (turnIndex) => {
|
|
58740
|
-
const turn = turns[turnIndex];
|
|
58741
|
-
for (const envelope of pendingEnvelopes) {
|
|
58742
|
-
envelope.turn = turnIndex;
|
|
58743
|
-
envelopes.push(envelope);
|
|
58744
|
-
turn.usage = mergeUsage(turn.usage, envelope.usage);
|
|
58745
|
-
}
|
|
58746
|
-
pendingEnvelopes = [];
|
|
58747
|
-
};
|
|
58748
|
-
const usage = createCodexUsageReader({
|
|
58749
|
-
keepEntries: false,
|
|
58750
|
-
onEntry(entry) {
|
|
58751
|
-
const turnUsage = codexResponseTurnUsage(entry);
|
|
58752
|
-
const newest = turns.length - 1;
|
|
58753
|
-
const fresh = turns.length > turnsAtLastEntry;
|
|
58754
|
-
turnsAtLastEntry = turns.length;
|
|
58755
|
-
if (fresh && newest >= 0 && turns[newest].kind === "agent_text") {
|
|
58756
|
-
turns[newest].usage = mergeUsage(turns[newest].usage, turnUsage);
|
|
58757
|
-
envelopes.push({ turn: newest, at: entry.at, usage: turnUsage, branch: null });
|
|
58758
|
-
return;
|
|
58759
|
-
}
|
|
58760
|
-
pendingEnvelopes.push({ turn: -1, at: entry.at, usage: turnUsage, branch: null });
|
|
58761
|
-
}
|
|
58762
|
-
});
|
|
58763
|
-
const pushAgentTurn = (turn) => {
|
|
58764
|
-
turns.push(turn);
|
|
58765
|
-
if (pendingEnvelopes.length > 0) landPending(turns.length - 1);
|
|
58766
|
-
};
|
|
58767
|
-
const flushPendingTools = () => {
|
|
58768
|
-
if (pendingTools.length === 0) return;
|
|
58769
|
-
pushAgentTurn({ kind: "agent_text", text: "", origin: "agent", toolCalls: pendingTools, usage: null, at: pendingAt });
|
|
58770
|
-
pendingTools = [];
|
|
58771
|
-
pendingAt = null;
|
|
58772
|
-
};
|
|
58773
|
-
return {
|
|
58774
|
-
pushLine(raw) {
|
|
58775
|
-
line += 1;
|
|
58776
|
-
const trimmed = raw.trim();
|
|
58777
|
-
if (trimmed === "") return;
|
|
58778
|
-
let record2;
|
|
58779
|
-
try {
|
|
58780
|
-
const parsed = JSON.parse(trimmed);
|
|
58781
|
-
if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) return;
|
|
58782
|
-
record2 = parsed;
|
|
58783
|
-
} catch {
|
|
58784
|
-
return;
|
|
58785
|
-
}
|
|
58786
|
-
usage.pushRecord(record2);
|
|
58787
|
-
if (record2.type !== "response_item") return;
|
|
58788
|
-
const at = typeof record2.timestamp === "string" && record2.timestamp !== "" ? record2.timestamp : null;
|
|
58789
|
-
const item = record2.payload;
|
|
58790
|
-
if (item === null || typeof item !== "object" || Array.isArray(item)) return;
|
|
58791
|
-
const responseItem = item;
|
|
58792
|
-
const callId = typeof responseItem.call_id === "string" ? responseItem.call_id : null;
|
|
58793
|
-
if (callId !== null && isToolOutput(responseItem)) {
|
|
58794
|
-
const script = scripts.get(callId);
|
|
58795
|
-
scripts.delete(callId);
|
|
58796
|
-
if (script !== void 0) {
|
|
58797
|
-
const [header = "", ...blocks] = outputBlocks(responseItem.output);
|
|
58798
|
-
const cell = SCRIPT_STILL_RUNNING.exec(header)?.[1];
|
|
58799
|
-
if (cell === void 0) scriptResult(evidence, script, header, blocks, at, line);
|
|
58800
|
-
else keepBounded(runningScripts, cell, script);
|
|
58801
|
-
} else if (evidence.watching(callId)) {
|
|
58802
|
-
const text2 = contentText(responseItem.output);
|
|
58803
|
-
evidence.result(callId, { succeeded: codexExitStatus(text2), text: text2, running: codexRunningProcess(text2), at, line });
|
|
58804
|
-
} else if (runningScripts.size > 0 || evidence.following()) {
|
|
58805
|
-
const [header = "", ...blocks] = outputBlocks(responseItem.output);
|
|
58806
|
-
const cell = SCRIPT_STILL_RUNNING.exec(header)?.[1];
|
|
58807
|
-
if (cell !== void 0) runningScripts.delete(cell);
|
|
58808
|
-
for (const text2 of [header, ...blocks]) {
|
|
58809
|
-
const process2 = codexRunningProcess(text2);
|
|
58810
|
-
if (process2 !== null) evidence.forget(process2);
|
|
58811
|
-
}
|
|
58812
|
-
}
|
|
58813
|
-
return;
|
|
58814
|
-
}
|
|
58815
|
-
const tool = toolCallName(responseItem);
|
|
58816
|
-
if (tool !== null) {
|
|
58817
|
-
const call = { name: tool };
|
|
58818
|
-
if (options.keepToolInputs === true) {
|
|
58819
|
-
const args = toolCallArguments(responseItem);
|
|
58820
|
-
if (args !== null) call.input = boundedToolInput(args);
|
|
58821
|
-
}
|
|
58822
|
-
pendingTools.push(call);
|
|
58823
|
-
pendingAt ??= at;
|
|
58824
|
-
if (callId !== null) {
|
|
58825
|
-
const script = watchCodexCall(evidence, callId, responseItem, at, runningScripts);
|
|
58826
|
-
if (script !== null) keepBounded(scripts, callId, script);
|
|
58827
|
-
}
|
|
58828
|
-
return;
|
|
58829
|
-
}
|
|
58830
|
-
if (responseItem.type !== "message") return;
|
|
58831
|
-
if (responseItem.role === "user") {
|
|
58832
|
-
const prompt = promptText(responseItem.content);
|
|
58833
|
-
if (prompt !== null) {
|
|
58834
|
-
flushPendingTools();
|
|
58835
|
-
turns.push({ kind: "human_prompt", text: prompt.text, origin: prompt.origin, toolCalls: [], usage: null, at });
|
|
58836
|
-
}
|
|
58837
|
-
return;
|
|
58838
|
-
}
|
|
58839
|
-
if (responseItem.role !== "assistant") return;
|
|
58840
|
-
const text = outputTextBlocks(responseItem.content).join("\n");
|
|
58841
|
-
if (text.trim() === "") return;
|
|
58842
|
-
pushAgentTurn({ kind: "agent_text", text, origin: "agent", toolCalls: pendingTools, usage: null, at: pendingAt ?? at });
|
|
58843
|
-
pendingTools = [];
|
|
58844
|
-
pendingAt = null;
|
|
58845
|
-
},
|
|
58846
|
-
finish() {
|
|
58847
|
-
flushPendingTools();
|
|
58848
|
-
if (pendingEnvelopes.length > 0) {
|
|
58849
|
-
const lastAgentTurn = turns.findLastIndex((turn) => turn.kind === "agent_text");
|
|
58850
|
-
if (lastAgentTurn === -1) {
|
|
58851
|
-
turns.push({ kind: "agent_text", text: "", origin: "agent", toolCalls: [], usage: null, at: pendingEnvelopes[0].at });
|
|
58852
|
-
landPending(turns.length - 1);
|
|
58853
|
-
} else {
|
|
58854
|
-
landPending(lastAgentTurn);
|
|
58855
|
-
}
|
|
58856
|
-
}
|
|
58857
|
-
return turns;
|
|
58858
|
-
},
|
|
58859
|
-
usageEnvelopes() {
|
|
58860
|
-
return envelopes;
|
|
58861
|
-
},
|
|
58862
|
-
prEvidence() {
|
|
58863
|
-
return evidence.finish();
|
|
58864
|
-
},
|
|
58865
|
-
prEvidenceDroppedPushes() {
|
|
58866
|
-
return evidence.droppedPushes();
|
|
58867
|
-
}
|
|
58868
|
-
};
|
|
58869
|
-
}
|
|
58870
|
-
var stepKey = (callId, step) => `${callId}#${step}`;
|
|
58871
|
-
function watchCodexCall(evidence, callId, item, at, runningScripts) {
|
|
58872
|
-
if (item.type === "custom_tool_call" && item.name === "exec" && typeof item.input === "string") {
|
|
58873
|
-
const steps = execScriptSteps(item.input);
|
|
58874
|
-
const commands = [];
|
|
58875
|
-
let seen = { pushes: 0, pullRequestCreates: 0 };
|
|
58876
|
-
steps.forEach((step, i) => {
|
|
58877
|
-
if (step.polls !== null) evidence.follow(stepKey(callId, i), step.polls);
|
|
58878
|
-
if (step.command === null) return;
|
|
58879
|
-
commands.push(step.command);
|
|
58880
|
-
const read = readCodeHostCommands(commands.join("\n"), null);
|
|
58881
|
-
evidence.watch(
|
|
58882
|
-
stepKey(callId, i),
|
|
58883
|
-
{
|
|
58884
|
-
pushes: read.pushes.slice(seen.pushes),
|
|
58885
|
-
pullRequestCreates: read.pullRequestCreates.slice(seen.pullRequestCreates)
|
|
58886
|
-
},
|
|
58887
|
-
at
|
|
58888
|
-
);
|
|
58889
|
-
seen = { pushes: read.pushes.length, pullRequestCreates: read.pullRequestCreates.length };
|
|
58890
|
-
});
|
|
58891
|
-
const watched = steps.some((_, i) => evidence.watching(stepKey(callId, i)));
|
|
58892
|
-
return watched ? { callId, polls: steps.map((step) => step.polls), printsEachStep: printsEachStep(item.input, steps) } : null;
|
|
58893
|
-
}
|
|
58894
|
-
if (item.type === "local_shell_call") {
|
|
58895
|
-
const command = argvCommand(asRecord2(item.action)?.command);
|
|
58896
|
-
if (command !== null) evidence.command(callId, command, null, at);
|
|
58897
|
-
return null;
|
|
58898
|
-
}
|
|
58899
|
-
if (item.type !== "function_call" || typeof item.arguments !== "string") return null;
|
|
58900
|
-
const args = safeJsonRecord(item.arguments);
|
|
58901
|
-
if (item.name === "exec_command" && typeof args?.cmd === "string") {
|
|
58902
|
-
evidence.command(callId, args.cmd, null, at);
|
|
58903
|
-
} else if (item.name === "shell") {
|
|
58904
|
-
const command = argvCommand(args?.command);
|
|
58905
|
-
if (command !== null) evidence.command(callId, command, null, at);
|
|
58906
|
-
} else if (item.name === "write_stdin" && typeof args?.session_id === "number") {
|
|
58907
|
-
evidence.follow(callId, String(args.session_id));
|
|
58908
|
-
} else if (item.name === "wait" && (typeof args?.cell_id === "string" || typeof args?.cell_id === "number")) {
|
|
58909
|
-
const script = runningScripts.get(String(args.cell_id)) ?? null;
|
|
58910
|
-
runningScripts.delete(String(args.cell_id));
|
|
58911
|
-
return script;
|
|
58912
|
-
} else if (item.name === "_create_pull_request") {
|
|
58913
|
-
const head = typeof args?.head === "string" ? args.head : null;
|
|
58914
|
-
evidence.watch(callId, { pushes: [], pullRequestCreates: [{ head, ownExitStatus: true }] }, at);
|
|
58915
|
-
}
|
|
58916
|
-
return null;
|
|
58917
|
-
}
|
|
58918
|
-
function scriptResult(evidence, script, header, blocks, at, line) {
|
|
58919
|
-
const paired = script.printsEachStep && blocks.length === script.polls.length;
|
|
58920
|
-
const keys = script.polls.map((_, i) => stepKey(script.callId, i));
|
|
58921
|
-
if (!paired) {
|
|
58922
|
-
evidence.merge(keys.filter((_, i) => script.polls[i] === null), script.callId);
|
|
58923
|
-
evidence.result(script.callId, { succeeded: null, text: [header, ...blocks].join("\n"), running: null, at, line });
|
|
58924
|
-
}
|
|
58925
|
-
script.polls.forEach((polls, i) => {
|
|
58926
|
-
if (!evidence.watching(keys[i])) return;
|
|
58927
|
-
const text = paired ? blocks[i] : "";
|
|
58928
|
-
const succeeded = paired ? codexExitStatus(text) : null;
|
|
58929
|
-
const running = (paired ? codexRunningProcess(text) : null) ?? (succeeded === null ? polls : null);
|
|
58930
|
-
evidence.result(keys[i], { succeeded, text, running, at, line });
|
|
58931
|
-
});
|
|
58932
|
-
}
|
|
58933
|
-
function outputBlocks(output2) {
|
|
58934
|
-
if (typeof output2 === "string") return [output2];
|
|
58935
|
-
if (!Array.isArray(output2)) return [];
|
|
58936
|
-
return output2.map((block2) => {
|
|
58937
|
-
const text = asRecord2(block2)?.text;
|
|
58938
|
-
return typeof text === "string" ? text : "";
|
|
58939
|
-
});
|
|
58940
|
-
}
|
|
58941
|
-
function argvCommand(argv) {
|
|
58942
|
-
if (typeof argv === "string") return argv;
|
|
58943
|
-
if (!Array.isArray(argv) || !argv.every((word) => typeof word === "string")) return null;
|
|
58944
|
-
const [shell, flag, script] = argv;
|
|
58945
|
-
if (argv.length === 3 && /(?:^|\/)(?:ba|z|da|k)?sh$/.test(shell) && /^-[a-z]*c[a-z]*$/.test(flag)) return script;
|
|
58946
|
-
return argv.map((word) => /^[A-Za-z0-9._/:=@+-]+$/.test(word) ? word : `'${word.replaceAll("'", "'\\''")}'`).join(" ");
|
|
58947
|
-
}
|
|
58948
|
-
var SCRIPT_TOOL_CALL = /tools\.(\w+)\(/g;
|
|
58949
|
-
var COMMAND_ARGUMENT = /\{\s*"?cmd"?\s*:\s*("(?:[^"\\]|\\.)*")/y;
|
|
58950
|
-
var SESSION_ARGUMENT = /\{\s*"?session_id"?\s*:\s*(\d+)/y;
|
|
58951
|
-
function execScriptSteps(script) {
|
|
58952
|
-
const steps = [];
|
|
58953
|
-
const call = new RegExp(SCRIPT_TOOL_CALL);
|
|
58954
|
-
for (let match = call.exec(script); match !== null; match = call.exec(script)) {
|
|
58955
|
-
const argument = match[1] === "exec_command" ? COMMAND_ARGUMENT : match[1] === "write_stdin" ? SESSION_ARGUMENT : null;
|
|
58956
|
-
if (argument !== null) argument.lastIndex = call.lastIndex;
|
|
58957
|
-
const value = argument?.exec(script) ?? null;
|
|
58958
|
-
if (value !== null) call.lastIndex += value[0].length;
|
|
58959
|
-
steps.push({
|
|
58960
|
-
command: value !== null && match[1] === "exec_command" ? jsonString(value[1]) : null,
|
|
58961
|
-
polls: value !== null && match[1] === "write_stdin" ? value[1] : null
|
|
58962
|
-
});
|
|
58963
|
-
}
|
|
58964
|
-
return steps;
|
|
58965
|
-
}
|
|
58966
|
-
var STRING_LITERAL = /"(?:[^"\\]|\\.)*"/g;
|
|
58967
|
-
var TEXT_CALL = /\btext\(/g;
|
|
58968
|
-
var TEXT_OF_TOOL_CALL = /\btext\(\s*await\s+tools\.\w+\(/g;
|
|
58969
|
-
var DEFERRED_CODE = /\bfunction\b|=>|\.then\(/;
|
|
58970
|
-
function printsEachStep(script, steps) {
|
|
58971
|
-
if (steps.length === 1) return true;
|
|
58972
|
-
const code = script.replace(STRING_LITERAL, '""');
|
|
58973
|
-
if (DEFERRED_CODE.test(code)) return false;
|
|
58974
|
-
const printed = [...code.matchAll(TEXT_OF_TOOL_CALL)].length;
|
|
58975
|
-
return printed === steps.length && [...code.matchAll(TEXT_CALL)].length === steps.length;
|
|
58976
|
-
}
|
|
58977
|
-
function jsonString(literal2) {
|
|
58978
|
-
try {
|
|
58979
|
-
const parsed = JSON.parse(literal2);
|
|
58980
|
-
return typeof parsed === "string" ? parsed : null;
|
|
58981
|
-
} catch {
|
|
58982
|
-
return null;
|
|
58983
|
-
}
|
|
58984
|
-
}
|
|
58985
|
-
function isToolOutput(item) {
|
|
58986
|
-
return item.type === "custom_tool_call_output" || item.type === "function_call_output" || item.type === "local_shell_call_output";
|
|
58987
|
-
}
|
|
58988
|
-
var SCRIPT_STILL_RUNNING = /^Script running with cell ID (\d+)/;
|
|
58989
|
-
var RUNNING_CHUNK = /^\s*\{[^\n]*?"session_id"\s*:\s*(\d+)/;
|
|
58990
|
-
var RUNNING_PROCESS_LINE = /^Process running with session ID (\d+)$/m;
|
|
58991
|
-
function codexRunningProcess(output2) {
|
|
58992
|
-
const chunk = RUNNING_CHUNK.exec(output2);
|
|
58993
|
-
if (chunk !== null) return chunk[1];
|
|
58994
|
-
const outputLine = output2.search(/^Output:/m);
|
|
58995
|
-
const header = outputLine === -1 ? output2 : output2.slice(0, outputLine);
|
|
58996
|
-
return RUNNING_PROCESS_LINE.exec(header)?.[1] ?? null;
|
|
58997
|
-
}
|
|
58998
|
-
var EXIT_STATUS = /"exit_code"\s*:\s*(\d+)|Process exited with code (\d+)/g;
|
|
58999
|
-
function codexExitStatus(output2) {
|
|
59000
|
-
const codes = [...output2.matchAll(EXIT_STATUS)].map((match) => Number(match[1] ?? match[2]));
|
|
59001
|
-
if (codes.length === 0) return null;
|
|
59002
|
-
return codes.every((code) => code === 0);
|
|
59003
|
-
}
|
|
59004
|
-
|
|
59005
|
-
// ../core/src/cursorRunEvents.ts
|
|
59006
|
-
var API_TOOL_NAMES = {
|
|
59007
|
-
read_file: "Read",
|
|
59008
|
-
run_terminal_cmd: "Shell",
|
|
59009
|
-
grep_search: "Grep",
|
|
59010
|
-
edit_file: "StrReplace",
|
|
59011
|
-
get_mcp_tools: "GetMcpTools",
|
|
59012
|
-
mcp: "CallMcpTool",
|
|
59013
|
-
await: "Await",
|
|
59014
|
-
pr_management: "ManagePullRequest",
|
|
59015
|
-
file_search: "Glob",
|
|
59016
|
-
task: "Subagent",
|
|
59017
|
-
todo_write: "TodoWrite"
|
|
59018
|
-
};
|
|
59019
|
-
var READ_TOOLS = /* @__PURE__ */ new Set(["Read", "ReadFile"]);
|
|
59020
|
-
var ARTIFACT_PATH_RE = /(^|\/)(agent-tools\/[0-9a-f-]{8,}|terminals\/\d+)\.txt$/;
|
|
59021
|
-
function primaryArg(args) {
|
|
59022
|
-
for (const key of ["path", "command", "query", "pattern"]) {
|
|
59023
|
-
const v = args[key];
|
|
59024
|
-
if (typeof v === "string" && v.length > 0) return v;
|
|
59025
|
-
}
|
|
59026
|
-
const firstString = Object.values(args).find((v) => typeof v === "string" && v.length > 0);
|
|
59027
|
-
return firstString ?? null;
|
|
59028
|
-
}
|
|
59029
|
-
function readFilePath(name, primary) {
|
|
59030
|
-
if (!primary || !READ_TOOLS.has(name)) return null;
|
|
59031
|
-
if (ARTIFACT_PATH_RE.test(primary)) return null;
|
|
59032
|
-
const path55 = primary.startsWith("/workspace/") ? primary.slice("/workspace/".length) : primary;
|
|
59033
|
-
return path55.length > 0 ? path55 : null;
|
|
59034
|
-
}
|
|
59035
|
-
function asRecord3(value) {
|
|
59036
|
-
return value !== null && typeof value === "object" && !Array.isArray(value) ? value : null;
|
|
59037
|
-
}
|
|
59038
|
-
function stringField(value, key) {
|
|
59039
|
-
const v = value?.[key];
|
|
59040
|
-
return typeof v === "string" && v.length > 0 ? v : null;
|
|
59041
|
-
}
|
|
59042
|
-
function asRawEvent(value) {
|
|
59043
|
-
const record2 = asRecord3(value);
|
|
59044
|
-
const event = stringField(record2, "event");
|
|
59045
|
-
return event ? { event, data: record2?.data } : null;
|
|
59046
|
-
}
|
|
59047
|
-
function parseCursorRunEvents(runs, options = {}) {
|
|
59048
|
-
return parseCursorRunEventsDetailed(runs, options).turns;
|
|
59049
|
-
}
|
|
59050
|
-
function parseCursorRunEventsDetailed(runs, options = {}) {
|
|
59051
|
-
const turns = [];
|
|
59052
|
-
const turnTokens = [];
|
|
59053
|
-
let pendingTools = [];
|
|
59054
|
-
let pendingTokens = 0;
|
|
59055
|
-
let text = "";
|
|
59056
|
-
const flush2 = () => {
|
|
59057
|
-
if (text !== "" || pendingTools.length > 0 || pendingTokens > 0) {
|
|
59058
|
-
turns.push({ kind: "agent_text", text, origin: "agent", toolCalls: pendingTools, usage: null, at: null });
|
|
59059
|
-
turnTokens.push(pendingTokens);
|
|
59060
|
-
}
|
|
59061
|
-
text = "";
|
|
59062
|
-
pendingTools = [];
|
|
59063
|
-
pendingTokens = 0;
|
|
59064
|
-
};
|
|
59065
|
-
for (const run2 of runs) {
|
|
59066
|
-
const openCalls = /* @__PURE__ */ new Map();
|
|
59067
|
-
for (const raw of run2.events) {
|
|
59068
|
-
const evt = asRawEvent(raw);
|
|
59069
|
-
if (!evt) continue;
|
|
59070
|
-
if (evt.event === "tool_call") {
|
|
59071
|
-
const call = asRecord3(evt.data);
|
|
59072
|
-
const callId = stringField(call, "callId");
|
|
59073
|
-
const rawName = stringField(call, "name");
|
|
59074
|
-
if (!callId || !rawName) continue;
|
|
59075
|
-
let entry = openCalls.get(callId);
|
|
59076
|
-
if (!entry) {
|
|
59077
|
-
if (text !== "") flush2();
|
|
59078
|
-
entry = { name: API_TOOL_NAMES[rawName] ?? rawName };
|
|
59079
|
-
openCalls.set(callId, entry);
|
|
59080
|
-
pendingTools.push(entry);
|
|
59081
|
-
}
|
|
59082
|
-
const args = asRecord3(call?.args);
|
|
59083
|
-
if (args) {
|
|
59084
|
-
const filePath = readFilePath(entry.name, primaryArg(args));
|
|
59085
|
-
if (filePath) entry.filePath = filePath;
|
|
59086
|
-
else delete entry.filePath;
|
|
59087
|
-
if (options.keepToolInputs === true) entry.input = boundedToolInput(args);
|
|
59088
|
-
}
|
|
59089
|
-
continue;
|
|
59090
|
-
}
|
|
59091
|
-
if (evt.event === "thinking" || evt.event === "assistant") {
|
|
59092
|
-
const delta = stringField(asRecord3(evt.data), "text");
|
|
59093
|
-
if (delta) text += delta;
|
|
59094
|
-
continue;
|
|
59095
|
-
}
|
|
59096
|
-
if (evt.event === "interaction_update") {
|
|
59097
|
-
const data = asRecord3(evt.data);
|
|
59098
|
-
const type = stringField(data, "type");
|
|
59099
|
-
if (type === "token-delta") {
|
|
59100
|
-
const tokens = Number(data?.tokens);
|
|
59101
|
-
if (Number.isFinite(tokens) && tokens > 0) pendingTokens += tokens;
|
|
59102
|
-
continue;
|
|
59103
|
-
}
|
|
59104
|
-
if (type !== "user-message-appended") continue;
|
|
59105
|
-
const prompt = stringField(asRecord3(data?.userMessage), "text");
|
|
59106
|
-
if (!prompt) continue;
|
|
59107
|
-
if (text !== "") flush2();
|
|
59108
|
-
turns.push({ kind: "human_prompt", text: prompt, origin: "unknown", toolCalls: [], usage: null, at: null });
|
|
59109
|
-
turnTokens.push(0);
|
|
59110
|
-
continue;
|
|
59111
|
-
}
|
|
59112
|
-
}
|
|
59113
|
-
}
|
|
59114
|
-
flush2();
|
|
59115
|
-
return { turns, turnTokens };
|
|
59116
|
-
}
|
|
59117
|
-
|
|
59118
|
-
// ../core/src/cursorRunRedaction.ts
|
|
59119
|
-
var REDACTED2 = "[REDACTED]";
|
|
59120
|
-
var SECRET_REST = /^[^\s\\"',;]+/;
|
|
59121
|
-
var CUT_PRIVATE_KEY_BODY = /\[REDACTED\][A-Za-z0-9+/=\s\\]*-----END [A-Z0-9 ]*PRIVATE KEY-----/g;
|
|
59122
|
-
function asRecord4(value) {
|
|
59123
|
-
return value !== null && typeof value === "object" && !Array.isArray(value) ? value : null;
|
|
59124
|
-
}
|
|
59125
|
-
function nonEmptyString(value) {
|
|
59126
|
-
return typeof value === "string" && value !== "";
|
|
59127
|
-
}
|
|
59128
|
-
function streamedText(event) {
|
|
59129
|
-
const data = asRecord4(event.data);
|
|
59130
|
-
if (data === null) return null;
|
|
59131
|
-
if (event.event === "assistant" || event.event === "thinking") {
|
|
59132
|
-
if (typeof data.text !== "string") return null;
|
|
59133
|
-
return {
|
|
59134
|
-
stream: event.event,
|
|
59135
|
-
served: true,
|
|
59136
|
-
text: data.text,
|
|
59137
|
-
withText: (text) => ({ ...event, data: { ...data, text } })
|
|
59138
|
-
};
|
|
59139
|
-
}
|
|
59140
|
-
if (event.event !== "interaction_update") return null;
|
|
59141
|
-
if (data.type === "text-delta" || data.type === "thinking-delta") {
|
|
59142
|
-
if (typeof data.text !== "string") return null;
|
|
59143
|
-
return {
|
|
59144
|
-
stream: data.type,
|
|
59145
|
-
served: false,
|
|
59146
|
-
text: data.text,
|
|
59147
|
-
withText: (text) => ({ ...event, data: { ...data, text } })
|
|
59148
|
-
};
|
|
59149
|
-
}
|
|
59150
|
-
const update = asRecord4(data.taskUpdate);
|
|
59151
|
-
if (data.type !== "tool-call-delta" || !nonEmptyString(data.callId) || update?.type !== "text-delta" && update?.type !== "thinking-delta" || typeof update.text !== "string") {
|
|
59152
|
-
return null;
|
|
59153
|
-
}
|
|
59154
|
-
return {
|
|
59155
|
-
stream: `${data.callId}/${update.type}`,
|
|
59156
|
-
served: false,
|
|
59157
|
-
text: update.text,
|
|
59158
|
-
withText: (text) => ({ ...event, data: { ...data, taskUpdate: { ...update, text } } })
|
|
59159
|
-
};
|
|
59160
|
-
}
|
|
59161
|
-
function endsTurnText(event, callIds) {
|
|
59162
|
-
const data = asRecord4(event.data);
|
|
59163
|
-
if (event.event === "tool_call") {
|
|
59164
|
-
if (!nonEmptyString(data?.callId) || !nonEmptyString(data.name) || callIds.has(data.callId)) return false;
|
|
59165
|
-
callIds.add(data.callId);
|
|
59166
|
-
return true;
|
|
59167
|
-
}
|
|
59168
|
-
return event.event === "interaction_update" && data?.type === "user-message-appended" && nonEmptyString(asRecord4(data.userMessage)?.text);
|
|
59169
|
-
}
|
|
59170
|
-
function splitLikeParts(parts, redacted) {
|
|
59171
|
-
const joined = parts.join("");
|
|
59172
|
-
if (joined === redacted) return [...parts];
|
|
59173
|
-
const shorter = Math.min(joined.length, redacted.length);
|
|
59174
|
-
let start = 0;
|
|
59175
|
-
while (start < shorter && joined[start] === redacted[start]) start += 1;
|
|
59176
|
-
let same = 0;
|
|
59177
|
-
while (same < shorter - start && joined.at(-1 - same) === redacted.at(-1 - same)) same += 1;
|
|
59178
|
-
const changedEnd = joined.length - same;
|
|
59179
|
-
const changed = redacted.slice(start, redacted.length - same);
|
|
59180
|
-
let at = 0;
|
|
59181
|
-
let placed = false;
|
|
59182
|
-
return parts.map((part, index) => {
|
|
59183
|
-
const end = at + part.length;
|
|
59184
|
-
let text = joined.slice(at, Math.min(end, start));
|
|
59185
|
-
if (!placed && (end > start || index === parts.length - 1)) {
|
|
59186
|
-
text += changed;
|
|
59187
|
-
placed = true;
|
|
59188
|
-
}
|
|
59189
|
-
text += joined.slice(Math.max(at, changedEnd), end);
|
|
59190
|
-
at = end;
|
|
59191
|
-
return text;
|
|
59192
|
-
});
|
|
59193
|
-
}
|
|
59194
|
-
function removeCutSecretRests(texts) {
|
|
59195
|
-
let cut = false;
|
|
59196
|
-
return texts.map((text) => {
|
|
59197
|
-
const part = cut ? text.replace(SECRET_REST, "") : text;
|
|
59198
|
-
if (part !== "") cut = part.endsWith(REDACTED2);
|
|
59199
|
-
return part;
|
|
59200
|
-
});
|
|
59201
|
-
}
|
|
59202
|
-
function keepTextAfterRedactions(parts) {
|
|
59203
|
-
const out = [...parts];
|
|
59204
|
-
let open3 = null;
|
|
59205
|
-
for (const k2 of out.keys()) {
|
|
59206
|
-
if (open3 !== null) {
|
|
59207
|
-
const rest = SECRET_REST.exec(out[k2])?.[0] ?? "";
|
|
59208
|
-
out[open3] += rest;
|
|
59209
|
-
out[k2] = out[k2].slice(rest.length);
|
|
59210
|
-
if (out[k2] === "") continue;
|
|
59211
|
-
}
|
|
59212
|
-
open3 = out[k2].endsWith(REDACTED2) ? k2 : null;
|
|
59213
|
-
}
|
|
59214
|
-
return out;
|
|
59215
|
-
}
|
|
59216
|
-
function redactStreamTexts(texts) {
|
|
59217
|
-
const parts = removeCutSecretRests(texts);
|
|
59218
|
-
const joined = parts.join("");
|
|
59219
|
-
const redacted = redactText(joined.replace(CUT_PRIVATE_KEY_BODY, REDACTED2));
|
|
59220
|
-
const alone = redacted === joined ? parts : parts.map(redactText);
|
|
59221
|
-
const split = alone.join("") === redacted ? alone : splitLikeParts(parts, redacted);
|
|
59222
|
-
return keepTextAfterRedactions(split);
|
|
59223
|
-
}
|
|
59224
|
-
function mapStreams(events, servedOnly, map2) {
|
|
59225
|
-
const out = [...events];
|
|
59226
|
-
const callIds = /* @__PURE__ */ new Set();
|
|
59227
|
-
let streams = /* @__PURE__ */ new Map();
|
|
59228
|
-
const mapStreamsSoFar = () => {
|
|
59229
|
-
for (const indices of streams.values()) {
|
|
59230
|
-
const deltas = indices.map((index) => streamedText(out[index]));
|
|
59231
|
-
const texts = map2(deltas.map((delta) => delta.text));
|
|
59232
|
-
for (const [k2, delta] of deltas.entries()) {
|
|
59233
|
-
if (texts[k2] !== delta.text) out[indices[k2]] = delta.withText(texts[k2]);
|
|
59234
|
-
}
|
|
59235
|
-
}
|
|
59236
|
-
streams = /* @__PURE__ */ new Map();
|
|
59237
|
-
};
|
|
59238
|
-
for (const [index, event] of events.entries()) {
|
|
59239
|
-
if (endsTurnText(event, callIds)) mapStreamsSoFar();
|
|
59240
|
-
const delta = streamedText(event);
|
|
59241
|
-
if (delta === null || servedOnly && !delta.served) continue;
|
|
59242
|
-
const indices = streams.get(delta.stream);
|
|
59243
|
-
if (indices) indices.push(index);
|
|
59244
|
-
else streams.set(delta.stream, [index]);
|
|
59245
|
-
}
|
|
59246
|
-
mapStreamsSoFar();
|
|
59247
|
-
return out;
|
|
59248
|
-
}
|
|
59249
|
-
function redactCursorRunEvents(events, { servedOnly = false } = {}) {
|
|
59250
|
-
return mapStreams(events, servedOnly, redactStreamTexts);
|
|
59251
|
-
}
|
|
59252
|
-
|
|
59253
|
-
// ../core/src/previewLinks.ts
|
|
59254
|
-
var SKILL_LINE = /^(?:[-*+]\s+)?[*`]*PREVIEW:\s+(\S+)\s+(https?:\/\/\S+)\s*$/gm;
|
|
59255
|
-
var MARKDOWN_LINE = (
|
|
59256
|
-
// eslint-disable-next-line security/detect-unsafe-regex
|
|
59257
|
-
/\*\*([^*]{1,60})\*\*:?\s*:?\s*(https?:\/\/[\w.:-]+(?:\/[\w./\-~%]*)?(?:\?[\w./\-~%&=+]*)?)/g
|
|
59258
|
-
);
|
|
59259
|
-
function extractPreviewLinks(events, kinds = ["agent_response"], options) {
|
|
59260
|
-
let guardIndex = -1;
|
|
59261
|
-
if (options?.unsettledTail === true) {
|
|
59262
|
-
for (let index = events.length - 1; index >= 0; index -= 1) {
|
|
59263
|
-
const event = events[index];
|
|
59264
|
-
if (kinds.includes(event.kind) && event.text) {
|
|
59265
|
-
guardIndex = index;
|
|
59266
|
-
break;
|
|
59267
|
-
}
|
|
59268
|
-
}
|
|
59269
|
-
}
|
|
59270
|
-
const byUrl = /* @__PURE__ */ new Map();
|
|
59271
|
-
for (const [index, event] of events.entries()) {
|
|
59272
|
-
if (!kinds.includes(event.kind)) continue;
|
|
59273
|
-
const text = event.text;
|
|
59274
|
-
if (!text) continue;
|
|
59275
|
-
const guardTail = index === guardIndex;
|
|
59276
|
-
for (const pattern of [SKILL_LINE, MARKDOWN_LINE]) {
|
|
59277
|
-
pattern.lastIndex = 0;
|
|
59278
|
-
for (const match of text.matchAll(pattern)) {
|
|
59279
|
-
const matchEnd = match.index + match[0].replace(/\s+$/, "").length;
|
|
59280
|
-
if (guardTail && matchEnd === text.length) continue;
|
|
59281
|
-
const raw = match[1].trim().replace(/[:*]+$/, "").trim();
|
|
59282
|
-
const url2 = normalizeUrl(match[2]);
|
|
59283
|
-
const building = /\(building\)$/i.test(raw);
|
|
59284
|
-
const label2 = building ? raw.replace(/\s*\(building\)$/i, "").trim() : raw;
|
|
59285
|
-
if (!url2 || label2 === "") continue;
|
|
59286
|
-
byUrl.set(trimTrailingSlash(url2), building ? { label: label2, url: url2, building } : { label: label2, url: url2 });
|
|
59287
|
-
}
|
|
59288
|
-
}
|
|
59289
|
-
}
|
|
59290
|
-
return [...byUrl.values()];
|
|
59291
|
-
}
|
|
59292
|
-
var trimTrailingSlash = (url2) => url2.replace(/\/+$/, "");
|
|
59293
|
-
function normalizeUrl(raw) {
|
|
59294
|
-
const trimmed = raw.replace(/[.,)\]`*]+$/, "");
|
|
59295
|
-
return /^https?:\/\/[\w.-]+(:\d+)?(\/[\w./\-~%]*)?(\?[\w./\-~%&=+]*)?$/.test(trimmed) ? trimmed : null;
|
|
59296
|
-
}
|
|
59297
|
-
|
|
59298
|
-
// ../core/src/sessionTurns.ts
|
|
59299
|
-
function parseSessionTurns(source, transcript, options = {}) {
|
|
59300
|
-
return parseSessionTurnsDetailed(source, transcript, options).turns;
|
|
59301
|
-
}
|
|
59302
|
-
function parseSessionTurnsDetailed(source, transcript, options = {}) {
|
|
59303
|
-
if (source === "cursor-cloud") {
|
|
59304
|
-
return {
|
|
59305
|
-
turns: parseCursorRunEvents(envelopeRuns(transcript), options),
|
|
59306
|
-
envelopes: [],
|
|
59307
|
-
prEvidence: [],
|
|
59308
|
-
droppedPushes: 0
|
|
59309
|
-
};
|
|
59310
|
-
}
|
|
59311
|
-
const parser = createSessionTurnParser(source, options);
|
|
59312
|
-
for (const line of transcript.split("\n")) parser.pushLine(line);
|
|
59313
|
-
const turns = parser.finish();
|
|
59314
|
-
return {
|
|
59315
|
-
turns,
|
|
59316
|
-
envelopes: parser.usageEnvelopes?.() ?? [],
|
|
59317
|
-
prEvidence: parser.prEvidence?.() ?? [],
|
|
59318
|
-
droppedPushes: parser.prEvidenceDroppedPushes?.() ?? 0
|
|
59319
|
-
};
|
|
59320
|
-
}
|
|
59321
|
-
function createSessionTurnParser(source, options = {}) {
|
|
59322
|
-
if (source === "codex") return createCodexTurnParser(options);
|
|
59323
|
-
if (source === "cursor") return createCursorTurnParser(options);
|
|
59324
|
-
return createDigestTurnParser(options);
|
|
59325
|
-
}
|
|
59326
|
-
function announcedPreviewsFromEvents(events) {
|
|
59327
|
-
return extractPreviewLinks(events, ["agent_prompt", "agent_response"]);
|
|
59328
|
-
}
|
|
59329
|
-
function announcedPreviewsFromTurns(turns) {
|
|
59330
|
-
return announcedPreviewsFromEvents(
|
|
59331
|
-
capturedSessionEvents(turns, { sessionId: "announced", observedAt: "" })
|
|
59332
|
-
);
|
|
59333
|
-
}
|
|
59334
|
-
function parseSseEvents(text) {
|
|
59335
|
-
const events = [];
|
|
59336
|
-
let type = "";
|
|
59337
|
-
let dataLines = [];
|
|
59338
|
-
const flush2 = () => {
|
|
59339
|
-
if (dataLines.length === 0) return;
|
|
59340
|
-
events.push({ event: type, data: safeJson(dataLines.join("\n")) });
|
|
59341
|
-
type = "";
|
|
59342
|
-
dataLines = [];
|
|
59343
|
-
};
|
|
59344
|
-
for (const line of text.split("\n")) {
|
|
59345
|
-
if (line.startsWith("event:")) type = line.slice("event:".length).trim();
|
|
59346
|
-
else if (line.startsWith("data:")) dataLines.push(line.slice("data:".length).trimStart());
|
|
59347
|
-
else if (line.trim() === "") flush2();
|
|
59348
|
-
}
|
|
59349
|
-
flush2();
|
|
59350
|
-
return events;
|
|
59351
|
-
}
|
|
59352
|
-
function envelopeRuns(transcript) {
|
|
59353
|
-
const parsed = safeJson(transcript);
|
|
59354
|
-
if (!parsed || !Array.isArray(parsed.runs)) return [];
|
|
59355
|
-
const runs = [];
|
|
59356
|
-
for (const item of parsed.runs) {
|
|
59357
|
-
const run2 = item;
|
|
59358
|
-
if (typeof run2?.runId !== "string" || typeof run2.sse !== "string") continue;
|
|
59359
|
-
runs.push({ runId: run2.runId, events: redactCursorRunEvents(parseSseEvents(run2.sse), { servedOnly: true }) });
|
|
59360
|
-
}
|
|
59361
|
-
return runs;
|
|
59362
|
-
}
|
|
59363
|
-
function safeJson(text) {
|
|
59364
|
-
try {
|
|
59365
|
-
return JSON.parse(text);
|
|
59366
|
-
} catch {
|
|
59367
|
-
return null;
|
|
59368
|
-
}
|
|
59369
|
-
}
|
|
59370
|
-
|
|
59371
57592
|
// ../core/src/scrubSentryEvent.ts
|
|
59372
|
-
var
|
|
57593
|
+
var REDACTED2 = "[Filtered]";
|
|
59373
57594
|
var SECRET_KEY_PATTERN = /^(?:authorization|proxy-authorization|cookie|set-cookie|x-api-key|x-auth-token|x-csrf-token|x-supabase-auth|api[_-]?key|access[_-]?token|refresh[_-]?token|id[_-]?token|session[_-]?token|client[_-]?secret|password|passwd|secret|signature|token|jwt)$/i;
|
|
59374
57595
|
var SECRET_QUERY_PARAM_PATTERN = /^(?:token|access_token|refresh_token|id_token|api_key|apikey|key|code|signature|password|secret|client_secret|state)$/i;
|
|
59375
57596
|
var BEARER_TOKEN_PATTERN = /\bBearer\s+[\w\-._~+/=]+/gi;
|
|
@@ -59444,7 +57665,7 @@ var OUTGOING_URL_FIELD_NAMES = ["url", "url.full", "http.url"];
|
|
|
59444
57665
|
var OUTGOING_PATH_FIELD_NAMES = ["url.path", "http.target"];
|
|
59445
57666
|
var MAX_DEPTH = 10;
|
|
59446
57667
|
function scrubString(value) {
|
|
59447
|
-
return scrubUserInfo(value).replace(POWERPLANT_TOKEN_PATTERN,
|
|
57668
|
+
return scrubUserInfo(value).replace(POWERPLANT_TOKEN_PATTERN, REDACTED2).replace(BEARER_TOKEN_PATTERN, `Bearer ${REDACTED2}`).replace(JWT_PATTERN, REDACTED2).replace(EMBEDDED_QUERY_SECRET_PATTERN, `$1${REDACTED2}`);
|
|
59448
57669
|
}
|
|
59449
57670
|
function scrubUrl(url2) {
|
|
59450
57671
|
const scrubbed = scrubUserInfo(url2);
|
|
@@ -59452,11 +57673,11 @@ function scrubUrl(url2) {
|
|
|
59452
57673
|
return queryStart === -1 ? scrubbed : scrubbed.slice(0, queryStart);
|
|
59453
57674
|
}
|
|
59454
57675
|
function scrubUserInfo(value) {
|
|
59455
|
-
return value.replace(URL_USER_INFO_PATTERN, `$1${
|
|
57676
|
+
return value.replace(URL_USER_INFO_PATTERN, `$1${REDACTED2}@`);
|
|
59456
57677
|
}
|
|
59457
57678
|
function scrubOutgoingUrl(url2) {
|
|
59458
57679
|
const parts = URL_PARTS.exec(url2);
|
|
59459
|
-
if (!parts) return
|
|
57680
|
+
if (!parts) return REDACTED2;
|
|
59460
57681
|
const [, scheme = "", authority = "", path55 = ""] = parts;
|
|
59461
57682
|
const host = authority.slice(authority.lastIndexOf("@") + 1);
|
|
59462
57683
|
const origin = `${scheme}${host}`;
|
|
@@ -59483,7 +57704,7 @@ function scrubValue(value, depth = 0) {
|
|
|
59483
57704
|
for (const [key, child] of Object.entries(value)) {
|
|
59484
57705
|
const name = key.toLowerCase();
|
|
59485
57706
|
if (SECRET_KEY_PATTERN.test(key) || SECRET_QUERY_PARAM_PATTERN.test(key) || HTTP_ATTRIBUTE_PREFIX.test(name) && !KEPT_HTTP_ATTRIBUTES.has(name)) {
|
|
59486
|
-
out[key] =
|
|
57707
|
+
out[key] = REDACTED2;
|
|
59487
57708
|
} else if (URL_FIELD_NAMES.has(name) && typeof child === "string") {
|
|
59488
57709
|
out[key] = scrubUrl(child);
|
|
59489
57710
|
} else {
|
|
@@ -59498,20 +57719,20 @@ function scrubSentryEvent(event) {
|
|
|
59498
57719
|
event.request.url = scrubUrl(event.request.url);
|
|
59499
57720
|
}
|
|
59500
57721
|
if (event.request.query_string !== void 0) {
|
|
59501
|
-
event.request.query_string =
|
|
57722
|
+
event.request.query_string = REDACTED2;
|
|
59502
57723
|
}
|
|
59503
57724
|
if (event.request.headers) {
|
|
59504
57725
|
const headers = Object.entries(event.request.headers).map(([name, value]) => [
|
|
59505
57726
|
name,
|
|
59506
|
-
KEPT_HEADER_NAMES.has(name.toLowerCase()) ? value :
|
|
57727
|
+
KEPT_HEADER_NAMES.has(name.toLowerCase()) ? value : REDACTED2
|
|
59507
57728
|
]);
|
|
59508
57729
|
event.request.headers = scrubValue(Object.fromEntries(headers));
|
|
59509
57730
|
}
|
|
59510
57731
|
if (event.request.cookies !== void 0) {
|
|
59511
|
-
event.request.cookies =
|
|
57732
|
+
event.request.cookies = REDACTED2;
|
|
59512
57733
|
}
|
|
59513
57734
|
if (event.request.data !== void 0) {
|
|
59514
|
-
event.request.data =
|
|
57735
|
+
event.request.data = REDACTED2;
|
|
59515
57736
|
}
|
|
59516
57737
|
}
|
|
59517
57738
|
if (event.exception?.values) {
|
|
@@ -59560,7 +57781,7 @@ function scrubOutgoingRequestSpan(span) {
|
|
|
59560
57781
|
if (typeof value === "string") data[name] = scrubOutgoingUrl(value);
|
|
59561
57782
|
}
|
|
59562
57783
|
for (const name of OUTGOING_PATH_FIELD_NAMES) {
|
|
59563
|
-
if (name in data) data[name] =
|
|
57784
|
+
if (name in data) data[name] = REDACTED2;
|
|
59564
57785
|
}
|
|
59565
57786
|
}
|
|
59566
57787
|
function scrubBreadcrumb(breadcrumb) {
|
|
@@ -59576,6 +57797,13 @@ function scrubBreadcrumb(breadcrumb) {
|
|
|
59576
57797
|
return breadcrumb;
|
|
59577
57798
|
}
|
|
59578
57799
|
|
|
57800
|
+
// ../core/src/htmlErrorPage.ts
|
|
57801
|
+
var HTML_PAGE_TITLE_MAX_CHARS = 80;
|
|
57802
|
+
function htmlPageTitle(page) {
|
|
57803
|
+
const title = /<title>([^<]*)<\/title>/i.exec(page)?.[1]?.replace(/\s+/g, " ").trim();
|
|
57804
|
+
return title ? title.slice(0, HTML_PAGE_TITLE_MAX_CHARS).trimEnd() : null;
|
|
57805
|
+
}
|
|
57806
|
+
|
|
59579
57807
|
// ../core/src/freshness.ts
|
|
59580
57808
|
function describeDataAge(generatedAt, now) {
|
|
59581
57809
|
const ageMs = now.getTime() - generatedAt.getTime();
|
|
@@ -86632,8 +84860,169 @@ function _init2(options = {}, getDefaultIntegrationsImpl) {
|
|
|
86632
84860
|
return client;
|
|
86633
84861
|
}
|
|
86634
84862
|
|
|
84863
|
+
// ../../apps/syncservice/src/http.ts
|
|
84864
|
+
import tls2 from "node:tls";
|
|
84865
|
+
var import_undici = __toESM(require_undici(), 1);
|
|
84866
|
+
var CLI_VERSION_HEADER = "x-powerplant-cli-version";
|
|
84867
|
+
var cliVersion = true ? "0.4.28" : "0.0.0-checkout";
|
|
84868
|
+
function cliVersionHeaders() {
|
|
84869
|
+
return { [CLI_VERSION_HEADER]: cliVersion, "user-agent": `powerplant-cli/${cliVersion}` };
|
|
84870
|
+
}
|
|
84871
|
+
function withVersionHeader(init3) {
|
|
84872
|
+
const headers = new Headers(init3?.headers);
|
|
84873
|
+
for (const [name, value] of Object.entries(cliVersionHeaders())) headers.set(name, value);
|
|
84874
|
+
return { ...init3, headers };
|
|
84875
|
+
}
|
|
84876
|
+
function installHttpTransport(env, certificates = tls2) {
|
|
84877
|
+
trustSystemCertificates(certificates);
|
|
84878
|
+
const { ignored, ...settings } = proxySettings(env);
|
|
84879
|
+
(0, import_undici.setGlobalDispatcher)(new import_undici.EnvHttpProxyAgent({ allowH2: false, ...settings }));
|
|
84880
|
+
if (ignored.length === 0) return null;
|
|
84881
|
+
return `Powerplant ignores ${ignored.join(" and ")}. It can use only an address like http://user:password@proxy.example.com:8080. Write a % in a password as %25.`;
|
|
84882
|
+
}
|
|
84883
|
+
function trustSystemCertificates(store) {
|
|
84884
|
+
const { getCACertificates, setDefaultCACertificates } = store;
|
|
84885
|
+
if (getCACertificates === void 0 || setDefaultCACertificates === void 0) return;
|
|
84886
|
+
const defaults = getCACertificates("default");
|
|
84887
|
+
const current = new Set(defaults);
|
|
84888
|
+
if (!getCACertificates("bundled").every((root) => current.has(root))) return;
|
|
84889
|
+
setDefaultCACertificates([...defaults, ...getCACertificates("system")]);
|
|
84890
|
+
}
|
|
84891
|
+
function proxySettings(env) {
|
|
84892
|
+
const ignored = [];
|
|
84893
|
+
const address = (name) => {
|
|
84894
|
+
const found = environmentVariable(env, name);
|
|
84895
|
+
if (found === void 0) return "";
|
|
84896
|
+
const value = /^[a-z][a-z\d+.-]*:\/\//i.test(found.value) ? found.value : `http://${found.value}`;
|
|
84897
|
+
const url2 = URL.canParse(value) ? new URL(value) : null;
|
|
84898
|
+
const usable = url2 !== null && ["http:", "https:"].includes(url2.protocol) && url2.username === "" === (url2.password === "") && undiciAccepts(value);
|
|
84899
|
+
if (usable) return value;
|
|
84900
|
+
ignored.push(found.name);
|
|
84901
|
+
return "";
|
|
84902
|
+
};
|
|
84903
|
+
return {
|
|
84904
|
+
httpProxy: address("http_proxy"),
|
|
84905
|
+
httpsProxy: address("https_proxy"),
|
|
84906
|
+
noProxy: environmentVariable(env, "no_proxy")?.value ?? "",
|
|
84907
|
+
ignored
|
|
84908
|
+
};
|
|
84909
|
+
}
|
|
84910
|
+
function undiciAccepts(address) {
|
|
84911
|
+
try {
|
|
84912
|
+
void new import_undici.ProxyAgent(address).close();
|
|
84913
|
+
return true;
|
|
84914
|
+
} catch {
|
|
84915
|
+
return false;
|
|
84916
|
+
}
|
|
84917
|
+
}
|
|
84918
|
+
function environmentVariable(env, name) {
|
|
84919
|
+
const listed = Object.keys(env);
|
|
84920
|
+
for (const key of [name, name.toUpperCase()]) {
|
|
84921
|
+
const value = env[key]?.trim();
|
|
84922
|
+
if (!value) continue;
|
|
84923
|
+
const listedName = listed.includes(key) ? key : listed.find((set2) => set2.toLowerCase() === name);
|
|
84924
|
+
return { name: listedName ?? key, value };
|
|
84925
|
+
}
|
|
84926
|
+
return void 0;
|
|
84927
|
+
}
|
|
84928
|
+
async function fetchWithRetry(operation, url2, init3, options = {}) {
|
|
84929
|
+
const settled = (status) => status < 500 || status === 503 && options.treat503AsFinal === true;
|
|
84930
|
+
const wrapped = (cause) => new ApiRequestError(
|
|
84931
|
+
`${operation}: couldn't reach ${new URL(url2).host}, ${describeFetchFailure(cause)}`,
|
|
84932
|
+
operation,
|
|
84933
|
+
null,
|
|
84934
|
+
{ cause }
|
|
84935
|
+
);
|
|
84936
|
+
const request2 = withVersionHeader(init3);
|
|
84937
|
+
const answered = (response) => {
|
|
84938
|
+
responseOperations.set(response, operation);
|
|
84939
|
+
return response;
|
|
84940
|
+
};
|
|
84941
|
+
const delaysMs = options.retry === false ? [] : [250, 1e3];
|
|
84942
|
+
for (const delayMs of delaysMs) {
|
|
84943
|
+
try {
|
|
84944
|
+
const response = await fetch(url2, request2);
|
|
84945
|
+
if (settled(response.status)) return answered(response);
|
|
84946
|
+
} catch (cause) {
|
|
84947
|
+
if (isPoisonedHttp2Session(cause)) throw wrapped(cause);
|
|
84948
|
+
}
|
|
84949
|
+
await new Promise((resolve2) => setTimeout(resolve2, delayMs));
|
|
84950
|
+
}
|
|
84951
|
+
try {
|
|
84952
|
+
return answered(await fetch(url2, request2));
|
|
84953
|
+
} catch (cause) {
|
|
84954
|
+
throw wrapped(cause);
|
|
84955
|
+
}
|
|
84956
|
+
}
|
|
84957
|
+
var responseOperations = /* @__PURE__ */ new WeakMap();
|
|
84958
|
+
function responseOperation(response) {
|
|
84959
|
+
return responseOperations.get(response) ?? null;
|
|
84960
|
+
}
|
|
84961
|
+
var ApiRequestError = class extends Error {
|
|
84962
|
+
constructor(message2, operation, status, options) {
|
|
84963
|
+
super(message2, options);
|
|
84964
|
+
this.operation = operation;
|
|
84965
|
+
this.status = status;
|
|
84966
|
+
this.name = "ApiRequestError";
|
|
84967
|
+
}
|
|
84968
|
+
operation;
|
|
84969
|
+
status;
|
|
84970
|
+
};
|
|
84971
|
+
var RateLimitedError = class extends ApiRequestError {
|
|
84972
|
+
constructor(message2, retryAfterMs2, operation) {
|
|
84973
|
+
super(message2, operation, 429);
|
|
84974
|
+
this.retryAfterMs = retryAfterMs2;
|
|
84975
|
+
this.name = "RateLimitedError";
|
|
84976
|
+
}
|
|
84977
|
+
retryAfterMs;
|
|
84978
|
+
};
|
|
84979
|
+
function retryAfterMs(error63) {
|
|
84980
|
+
for (let cause = error63; cause instanceof Error; cause = cause.cause) {
|
|
84981
|
+
if (cause instanceof RateLimitedError) return cause.retryAfterMs;
|
|
84982
|
+
}
|
|
84983
|
+
return null;
|
|
84984
|
+
}
|
|
84985
|
+
function responseRequestId(response) {
|
|
84986
|
+
const parsed = apiRequestIdSchema.safeParse(response.headers.get("x-request-id"));
|
|
84987
|
+
return parsed.success ? parsed.data : null;
|
|
84988
|
+
}
|
|
84989
|
+
var failureRequestIds = /* @__PURE__ */ new WeakMap();
|
|
84990
|
+
function withRequestId(error63, response) {
|
|
84991
|
+
const requestId = responseRequestId(response);
|
|
84992
|
+
if (requestId !== null) failureRequestIds.set(error63, requestId);
|
|
84993
|
+
return error63;
|
|
84994
|
+
}
|
|
84995
|
+
function failureRequestId(error63) {
|
|
84996
|
+
for (let cause = error63; cause instanceof Error; cause = cause.cause) {
|
|
84997
|
+
const requestId = failureRequestIds.get(cause);
|
|
84998
|
+
if (requestId !== void 0) return requestId;
|
|
84999
|
+
}
|
|
85000
|
+
return null;
|
|
85001
|
+
}
|
|
85002
|
+
function parseRetryAfter(response) {
|
|
85003
|
+
const header = response.headers.get("retry-after");
|
|
85004
|
+
if (header === null) return null;
|
|
85005
|
+
const seconds = Number(header);
|
|
85006
|
+
return Number.isFinite(seconds) && seconds >= 0 ? seconds * 1e3 : null;
|
|
85007
|
+
}
|
|
85008
|
+
function zodIssueSummary(error63) {
|
|
85009
|
+
return error63.issues.map((issue2) => `${issue2.path.join(".") || "(root)"}: ${issue2.code}`).join("; ");
|
|
85010
|
+
}
|
|
85011
|
+
function describeFetchFailure(error63) {
|
|
85012
|
+
if (!(error63 instanceof Error)) return String(error63);
|
|
85013
|
+
return error63.cause instanceof Error && error63.cause.message ? error63.cause.message : error63.message;
|
|
85014
|
+
}
|
|
85015
|
+
function isPoisonedHttp2Session(error63) {
|
|
85016
|
+
let cursor = error63;
|
|
85017
|
+
for (let depth = 0; depth < 5 && cursor instanceof Error; depth += 1) {
|
|
85018
|
+
if (/session has been destroyed/i.test(cursor.message)) return true;
|
|
85019
|
+
cursor = cursor.cause;
|
|
85020
|
+
}
|
|
85021
|
+
return false;
|
|
85022
|
+
}
|
|
85023
|
+
|
|
86635
85024
|
// ../../apps/syncservice/src/reporting.ts
|
|
86636
|
-
function initCollectorReporting(appEnv, release2) {
|
|
85025
|
+
function initCollectorReporting(appEnv, release2, command) {
|
|
86637
85026
|
const dsn = process.env.SENTRY_DSN;
|
|
86638
85027
|
if (!dsn) return;
|
|
86639
85028
|
init2({
|
|
@@ -86648,6 +85037,7 @@ function initCollectorReporting(appEnv, release2) {
|
|
|
86648
85037
|
beforeBreadcrumb: (breadcrumb) => scrubBreadcrumb(breadcrumb)
|
|
86649
85038
|
});
|
|
86650
85039
|
setTag("service", "collector");
|
|
85040
|
+
if (command !== void 0) setTag("command", command);
|
|
86651
85041
|
}
|
|
86652
85042
|
var fetchTransport = (options) => createTransport(
|
|
86653
85043
|
options,
|
|
@@ -86668,6 +85058,45 @@ function tagReportingIdentity(identity) {
|
|
|
86668
85058
|
if (identity.orgId) setTag("org_id", identity.orgId);
|
|
86669
85059
|
}
|
|
86670
85060
|
var REPORT_AFTER_CONSECUTIVE_FAILURES = 3;
|
|
85061
|
+
var STREAK_REREPORT_INTERVAL_MS = 60 * 6e4;
|
|
85062
|
+
function failureStreak(report, now = Date.now, minDurationMs = 0) {
|
|
85063
|
+
let failures = 0;
|
|
85064
|
+
let firstAt = null;
|
|
85065
|
+
let reportedAt = -Infinity;
|
|
85066
|
+
return {
|
|
85067
|
+
failed(error63) {
|
|
85068
|
+
const at = now();
|
|
85069
|
+
firstAt ??= at;
|
|
85070
|
+
failures += 1;
|
|
85071
|
+
if (failures < REPORT_AFTER_CONSECUTIVE_FAILURES || at - firstAt < minDurationMs || at - reportedAt < STREAK_REREPORT_INTERVAL_MS) return;
|
|
85072
|
+
reportedAt = at;
|
|
85073
|
+
report(error63, { consecutiveFailures: failures });
|
|
85074
|
+
},
|
|
85075
|
+
succeeded() {
|
|
85076
|
+
failures = 0;
|
|
85077
|
+
firstAt = null;
|
|
85078
|
+
reportedAt = -Infinity;
|
|
85079
|
+
}
|
|
85080
|
+
};
|
|
85081
|
+
}
|
|
85082
|
+
function createRawUploadFailures(report, now = Date.now) {
|
|
85083
|
+
const failures = /* @__PURE__ */ new Map();
|
|
85084
|
+
return {
|
|
85085
|
+
failed(key, error63) {
|
|
85086
|
+
const streak = failures.get(key) ?? failureStreak(report, now, 6e4);
|
|
85087
|
+
failures.delete(key);
|
|
85088
|
+
failures.set(key, streak);
|
|
85089
|
+
if (failures.size > 1e3) {
|
|
85090
|
+
const oldest = failures.keys().next().value;
|
|
85091
|
+
if (oldest !== void 0) failures.delete(oldest);
|
|
85092
|
+
}
|
|
85093
|
+
streak.failed(error63);
|
|
85094
|
+
},
|
|
85095
|
+
succeeded(key) {
|
|
85096
|
+
failures.delete(key);
|
|
85097
|
+
}
|
|
85098
|
+
};
|
|
85099
|
+
}
|
|
86671
85100
|
var ExpectedCliError = class extends Error {
|
|
86672
85101
|
};
|
|
86673
85102
|
var OFFLINE_ERROR_PATTERN = /couldn't reach|fetch failed|ENOTFOUND|ECONNREFUSED|ECONNRESET|ETIMEDOUT|EAI_AGAIN|ENETDOWN|ENETUNREACH|EHOSTUNREACH|headers timeout|socket hang up|session has been destroyed|other side closed/i;
|
|
@@ -86677,15 +85106,46 @@ function isOfflineError(error63) {
|
|
|
86677
85106
|
}
|
|
86678
85107
|
return false;
|
|
86679
85108
|
}
|
|
86680
|
-
function reportCollectorError(error63, operation, context2, level = "error") {
|
|
85109
|
+
function reportCollectorError(error63, operation, context2, level = "error", fingerprint) {
|
|
86681
85110
|
if (error63 instanceof ExpectedCliError) return;
|
|
86682
85111
|
const err = error63 instanceof Error ? error63 : new Error(String(error63));
|
|
85112
|
+
const request2 = apiRequestFailure(err);
|
|
85113
|
+
const requestId = failureRequestId(err);
|
|
85114
|
+
const grouping = fingerprint ?? (request2 === null ? void 0 : [
|
|
85115
|
+
"collector-api",
|
|
85116
|
+
request2.operation,
|
|
85117
|
+
request2.group,
|
|
85118
|
+
...operation === "stuck-transcript-upload" ? ["persistent"] : [],
|
|
85119
|
+
...request2.kind === "server-error" && requestId === null ? ["proxy"] : []
|
|
85120
|
+
]);
|
|
85121
|
+
const actionable = operation === "stuck-transcript-upload" || (request2 === null ? !isOfflineError(err) : request2.kind === "rejected" || request2.group === "http2-pool-poisoned" || request2.kind === "server-error" && requestId === null);
|
|
86683
85122
|
captureException(err, {
|
|
86684
|
-
|
|
86685
|
-
|
|
85123
|
+
// A known request failure is classed by its kind, not its text: "capture-policy
|
|
85124
|
+
// fetch failed (400)" also matches the offline pattern.
|
|
85125
|
+
level: level === "warning" || (request2 === null ? isOfflineError(err) : request2.kind !== "rejected") ? "warning" : "error",
|
|
85126
|
+
tags: {
|
|
85127
|
+
service: "collector",
|
|
85128
|
+
operation,
|
|
85129
|
+
actionable,
|
|
85130
|
+
...requestId === null ? {} : { request_id: requestId }
|
|
85131
|
+
},
|
|
85132
|
+
...grouping === void 0 ? {} : { fingerprint: grouping },
|
|
86686
85133
|
...context2 ? { extra: context2 } : {}
|
|
86687
85134
|
});
|
|
86688
85135
|
}
|
|
85136
|
+
function apiRequestFailure(error63) {
|
|
85137
|
+
for (let cause = error63; cause instanceof Error; cause = cause.cause) {
|
|
85138
|
+
if (!(cause instanceof ApiRequestError)) continue;
|
|
85139
|
+
if (cause.status === null) {
|
|
85140
|
+
const group = isPoisonedHttp2Session(cause) ? "http2-pool-poisoned" : "unreachable";
|
|
85141
|
+
return { operation: cause.operation, kind: "unreachable", group };
|
|
85142
|
+
}
|
|
85143
|
+
if (cause.status >= 500) return { operation: cause.operation, kind: "server-error", group: "server-error" };
|
|
85144
|
+
if (cause.status === 429) return { operation: cause.operation, kind: "rate-limited", group: "429" };
|
|
85145
|
+
return { operation: cause.operation, kind: "rejected", group: String(cause.status) };
|
|
85146
|
+
}
|
|
85147
|
+
return null;
|
|
85148
|
+
}
|
|
86689
85149
|
var REPORT_REPEAT_MS = 24 * 60 * 6e4;
|
|
86690
85150
|
function dailyReporter(deps) {
|
|
86691
85151
|
const sentAt = readMarker(deps.markerFile, deps.readTextFile, deps.now);
|
|
@@ -86910,148 +85370,6 @@ function readRecord(recordPath, roots) {
|
|
|
86910
85370
|
|
|
86911
85371
|
// ../../apps/syncservice/src/diagnostics.ts
|
|
86912
85372
|
import { createHmac } from "node:crypto";
|
|
86913
|
-
|
|
86914
|
-
// ../../apps/syncservice/src/http.ts
|
|
86915
|
-
import tls2 from "node:tls";
|
|
86916
|
-
var import_undici = __toESM(require_undici(), 1);
|
|
86917
|
-
var CLI_VERSION_HEADER = "x-powerplant-cli-version";
|
|
86918
|
-
var cliVersion = true ? "0.4.26" : "0.0.0-checkout";
|
|
86919
|
-
function cliVersionHeaders() {
|
|
86920
|
-
return { [CLI_VERSION_HEADER]: cliVersion, "user-agent": `powerplant-cli/${cliVersion}` };
|
|
86921
|
-
}
|
|
86922
|
-
function withVersionHeader(init3) {
|
|
86923
|
-
const headers = new Headers(init3?.headers);
|
|
86924
|
-
for (const [name, value] of Object.entries(cliVersionHeaders())) headers.set(name, value);
|
|
86925
|
-
return { ...init3, headers };
|
|
86926
|
-
}
|
|
86927
|
-
function installHttpTransport(env, certificates = tls2) {
|
|
86928
|
-
trustSystemCertificates(certificates);
|
|
86929
|
-
const { ignored, ...settings } = proxySettings(env);
|
|
86930
|
-
(0, import_undici.setGlobalDispatcher)(new import_undici.EnvHttpProxyAgent({ allowH2: false, ...settings }));
|
|
86931
|
-
if (ignored.length === 0) return null;
|
|
86932
|
-
return `Powerplant ignores ${ignored.join(" and ")}. It can use only an address like http://user:password@proxy.example.com:8080. Write a % in a password as %25.`;
|
|
86933
|
-
}
|
|
86934
|
-
function trustSystemCertificates(store) {
|
|
86935
|
-
const { getCACertificates, setDefaultCACertificates } = store;
|
|
86936
|
-
if (getCACertificates === void 0 || setDefaultCACertificates === void 0) return;
|
|
86937
|
-
const defaults = getCACertificates("default");
|
|
86938
|
-
const current = new Set(defaults);
|
|
86939
|
-
if (!getCACertificates("bundled").every((root) => current.has(root))) return;
|
|
86940
|
-
setDefaultCACertificates([...defaults, ...getCACertificates("system")]);
|
|
86941
|
-
}
|
|
86942
|
-
function proxySettings(env) {
|
|
86943
|
-
const ignored = [];
|
|
86944
|
-
const address = (name) => {
|
|
86945
|
-
const found = environmentVariable(env, name);
|
|
86946
|
-
if (found === void 0) return "";
|
|
86947
|
-
const value = /^[a-z][a-z\d+.-]*:\/\//i.test(found.value) ? found.value : `http://${found.value}`;
|
|
86948
|
-
const url2 = URL.canParse(value) ? new URL(value) : null;
|
|
86949
|
-
const usable = url2 !== null && ["http:", "https:"].includes(url2.protocol) && url2.username === "" === (url2.password === "") && undiciAccepts(value);
|
|
86950
|
-
if (usable) return value;
|
|
86951
|
-
ignored.push(found.name);
|
|
86952
|
-
return "";
|
|
86953
|
-
};
|
|
86954
|
-
return {
|
|
86955
|
-
httpProxy: address("http_proxy"),
|
|
86956
|
-
httpsProxy: address("https_proxy"),
|
|
86957
|
-
noProxy: environmentVariable(env, "no_proxy")?.value ?? "",
|
|
86958
|
-
ignored
|
|
86959
|
-
};
|
|
86960
|
-
}
|
|
86961
|
-
function undiciAccepts(address) {
|
|
86962
|
-
try {
|
|
86963
|
-
void new import_undici.ProxyAgent(address).close();
|
|
86964
|
-
return true;
|
|
86965
|
-
} catch {
|
|
86966
|
-
return false;
|
|
86967
|
-
}
|
|
86968
|
-
}
|
|
86969
|
-
function environmentVariable(env, name) {
|
|
86970
|
-
const listed = Object.keys(env);
|
|
86971
|
-
for (const key of [name, name.toUpperCase()]) {
|
|
86972
|
-
const value = env[key]?.trim();
|
|
86973
|
-
if (!value) continue;
|
|
86974
|
-
const listedName = listed.includes(key) ? key : listed.find((set2) => set2.toLowerCase() === name);
|
|
86975
|
-
return { name: listedName ?? key, value };
|
|
86976
|
-
}
|
|
86977
|
-
return void 0;
|
|
86978
|
-
}
|
|
86979
|
-
async function fetchWithRetry(operation, url2, init3, options = {}) {
|
|
86980
|
-
const settled = (status) => status < 500 || status === 503 && options.treat503AsFinal === true;
|
|
86981
|
-
const wrapped = (cause) => new Error(`${operation}: couldn't reach ${new URL(url2).host}, ${describeFetchFailure(cause)}`, {
|
|
86982
|
-
cause
|
|
86983
|
-
});
|
|
86984
|
-
const request2 = withVersionHeader(init3);
|
|
86985
|
-
const delaysMs = options.retry === false ? [] : [250, 1e3];
|
|
86986
|
-
for (const delayMs of delaysMs) {
|
|
86987
|
-
try {
|
|
86988
|
-
const response = await fetch(url2, request2);
|
|
86989
|
-
if (settled(response.status)) return response;
|
|
86990
|
-
} catch (cause) {
|
|
86991
|
-
if (isPoisonedHttp2Session(cause)) throw wrapped(cause);
|
|
86992
|
-
}
|
|
86993
|
-
await new Promise((resolve2) => setTimeout(resolve2, delayMs));
|
|
86994
|
-
}
|
|
86995
|
-
try {
|
|
86996
|
-
return await fetch(url2, request2);
|
|
86997
|
-
} catch (cause) {
|
|
86998
|
-
throw wrapped(cause);
|
|
86999
|
-
}
|
|
87000
|
-
}
|
|
87001
|
-
var RateLimitedError = class extends Error {
|
|
87002
|
-
constructor(message2, retryAfterMs2) {
|
|
87003
|
-
super(message2);
|
|
87004
|
-
this.retryAfterMs = retryAfterMs2;
|
|
87005
|
-
this.name = "RateLimitedError";
|
|
87006
|
-
}
|
|
87007
|
-
retryAfterMs;
|
|
87008
|
-
};
|
|
87009
|
-
function retryAfterMs(error63) {
|
|
87010
|
-
for (let cause = error63; cause instanceof Error; cause = cause.cause) {
|
|
87011
|
-
if (cause instanceof RateLimitedError) return cause.retryAfterMs;
|
|
87012
|
-
}
|
|
87013
|
-
return null;
|
|
87014
|
-
}
|
|
87015
|
-
function responseRequestId(response) {
|
|
87016
|
-
const parsed = apiRequestIdSchema.safeParse(response.headers.get("x-request-id"));
|
|
87017
|
-
return parsed.success ? parsed.data : null;
|
|
87018
|
-
}
|
|
87019
|
-
var failureRequestIds = /* @__PURE__ */ new WeakMap();
|
|
87020
|
-
function withRequestId(error63, response) {
|
|
87021
|
-
const requestId = responseRequestId(response);
|
|
87022
|
-
if (requestId !== null) failureRequestIds.set(error63, requestId);
|
|
87023
|
-
return error63;
|
|
87024
|
-
}
|
|
87025
|
-
function failureRequestId(error63) {
|
|
87026
|
-
for (let cause = error63; cause instanceof Error; cause = cause.cause) {
|
|
87027
|
-
const requestId = failureRequestIds.get(cause);
|
|
87028
|
-
if (requestId !== void 0) return requestId;
|
|
87029
|
-
}
|
|
87030
|
-
return null;
|
|
87031
|
-
}
|
|
87032
|
-
function parseRetryAfter(response) {
|
|
87033
|
-
const header = response.headers.get("retry-after");
|
|
87034
|
-
if (header === null) return null;
|
|
87035
|
-
const seconds = Number(header);
|
|
87036
|
-
return Number.isFinite(seconds) && seconds >= 0 ? seconds * 1e3 : null;
|
|
87037
|
-
}
|
|
87038
|
-
function zodIssueSummary(error63) {
|
|
87039
|
-
return error63.issues.map((issue2) => `${issue2.path.join(".") || "(root)"}: ${issue2.code}`).join("; ");
|
|
87040
|
-
}
|
|
87041
|
-
function describeFetchFailure(error63) {
|
|
87042
|
-
if (!(error63 instanceof Error)) return String(error63);
|
|
87043
|
-
return error63.cause instanceof Error && error63.cause.message ? error63.cause.message : error63.message;
|
|
87044
|
-
}
|
|
87045
|
-
function isPoisonedHttp2Session(error63) {
|
|
87046
|
-
let cursor = error63;
|
|
87047
|
-
for (let depth = 0; depth < 5 && cursor instanceof Error; depth += 1) {
|
|
87048
|
-
if (/session has been destroyed/i.test(cursor.message)) return true;
|
|
87049
|
-
cursor = cursor.cause;
|
|
87050
|
-
}
|
|
87051
|
-
return false;
|
|
87052
|
-
}
|
|
87053
|
-
|
|
87054
|
-
// ../../apps/syncservice/src/diagnostics.ts
|
|
87055
85373
|
function observeFileDiagnostic(observer, file2) {
|
|
87056
85374
|
try {
|
|
87057
85375
|
observer?.(file2);
|
|
@@ -88014,10 +86332,10 @@ function readFirstSessionMeta(rolloutPath) {
|
|
|
88014
86332
|
} catch {
|
|
88015
86333
|
record2 = void 0;
|
|
88016
86334
|
}
|
|
88017
|
-
if (!
|
|
86335
|
+
if (!isRecord(record2)) {
|
|
88018
86336
|
return first.complete ? { state: "fault", reason: "the first line is not a JSON object (expected a session_meta record)" } : { state: "pending" };
|
|
88019
86337
|
}
|
|
88020
|
-
if (record2.type !== "session_meta" || !
|
|
86338
|
+
if (record2.type !== "session_meta" || !isRecord(record2.payload)) {
|
|
88021
86339
|
return { state: "fault", reason: "the first record is not a session_meta record with a payload object" };
|
|
88022
86340
|
}
|
|
88023
86341
|
return { state: "session_meta", timestamp: record2.timestamp, meta: record2.payload };
|
|
@@ -88026,7 +86344,7 @@ function rolloutLocation(rolloutPath, first = readFirstSessionMeta(rolloutPath))
|
|
|
88026
86344
|
const unknown2 = { kind: "session", codexClient: "unknown", totals: null, fastTotals: null };
|
|
88027
86345
|
if (first.state === "session_meta") return locationOf(first.timestamp, first.meta);
|
|
88028
86346
|
if (first.state === "pending") return unknown2;
|
|
88029
|
-
const record2 = readFirstRecord(rolloutPath, (candidate) => candidate.type === "session_meta" &&
|
|
86347
|
+
const record2 = readFirstRecord(rolloutPath, (candidate) => candidate.type === "session_meta" && isRecord(candidate.payload));
|
|
88030
86348
|
return record2 === null ? unknown2 : locationOf(record2.timestamp, record2.payload);
|
|
88031
86349
|
}
|
|
88032
86350
|
function locationOf(startedAt, meta3) {
|
|
@@ -89042,10 +87360,10 @@ async function openLocalDatabase(dbPath) {
|
|
|
89042
87360
|
const sqlite = await loadSqlite();
|
|
89043
87361
|
return new sqlite.DatabaseSync(dbPath, { readOnly: true });
|
|
89044
87362
|
}
|
|
89045
|
-
function
|
|
87363
|
+
function safeJsonRecord(text) {
|
|
89046
87364
|
try {
|
|
89047
87365
|
const parsed = JSON.parse(text);
|
|
89048
|
-
return
|
|
87366
|
+
return isRecord(parsed) ? parsed : null;
|
|
89049
87367
|
} catch {
|
|
89050
87368
|
return null;
|
|
89051
87369
|
}
|
|
@@ -89080,7 +87398,7 @@ function workspaceFolderOf(cursorUserDir, workspaceId) {
|
|
|
89080
87398
|
}
|
|
89081
87399
|
const text = readIfExists(path6.join(cursorUserDir, "workspaceStorage", workspaceId, "workspace.json"));
|
|
89082
87400
|
if (text === null) return void 0;
|
|
89083
|
-
const record2 =
|
|
87401
|
+
const record2 = safeJsonRecord(text);
|
|
89084
87402
|
const folder = record2?.folder;
|
|
89085
87403
|
if (typeof folder !== "string") return void 0;
|
|
89086
87404
|
try {
|
|
@@ -89090,19 +87408,19 @@ function workspaceFolderOf(cursorUserDir, workspaceId) {
|
|
|
89090
87408
|
}
|
|
89091
87409
|
}
|
|
89092
87410
|
function headerFactsOf(value) {
|
|
89093
|
-
const location =
|
|
89094
|
-
const workspaceUri =
|
|
87411
|
+
const location = isRecord(value.agentLocation) ? value.agentLocation : null;
|
|
87412
|
+
const workspaceUri = isRecord(value.workspaceIdentifier) ? value.workspaceIdentifier.uri : void 0;
|
|
89095
87413
|
const repos = Array.isArray(value.trackedGitRepos) ? value.trackedGitRepos : [];
|
|
89096
87414
|
const branchStamps = [];
|
|
89097
87415
|
let repoPath;
|
|
89098
87416
|
for (const repo of repos) {
|
|
89099
|
-
if (!
|
|
87417
|
+
if (!isRecord(repo)) continue;
|
|
89100
87418
|
if (repoPath === void 0 && typeof repo.repoPath === "string" && repo.repoPath !== "") {
|
|
89101
87419
|
repoPath = repo.repoPath;
|
|
89102
87420
|
}
|
|
89103
87421
|
if (!Array.isArray(repo.branches)) continue;
|
|
89104
87422
|
for (const branch of repo.branches) {
|
|
89105
|
-
if (!
|
|
87423
|
+
if (!isRecord(branch) || typeof branch.branchName !== "string" || branch.branchName === "")
|
|
89106
87424
|
continue;
|
|
89107
87425
|
branchStamps.push({
|
|
89108
87426
|
name: branch.branchName,
|
|
@@ -89232,7 +87550,7 @@ function unfamiliarLine(fields, position, recorder) {
|
|
|
89232
87550
|
function promptContext(context2, recorder) {
|
|
89233
87551
|
const present = Object.entries(context2).filter(([, value]) => {
|
|
89234
87552
|
if (Array.isArray(value)) return value.length > 0;
|
|
89235
|
-
if (
|
|
87553
|
+
if (isRecord(value)) return Object.keys(value).length > 0;
|
|
89236
87554
|
return value !== void 0 && value !== null;
|
|
89237
87555
|
});
|
|
89238
87556
|
const { kept, excludedKeys, omitted } = retainFieldsBounded(Object.fromEntries(present), PROMPT_CONTEXT_MAX_BYTES);
|
|
@@ -89247,7 +87565,7 @@ function promptContext(context2, recorder) {
|
|
|
89247
87565
|
function boundedJsonText(raw, maxBytes) {
|
|
89248
87566
|
const bytes = Buffer.byteLength(raw);
|
|
89249
87567
|
if (bytes > maxBytes) return { kind: "over", bytes };
|
|
89250
|
-
const value =
|
|
87568
|
+
const value = safeJsonRecord(raw);
|
|
89251
87569
|
return value === null ? { kind: "text", bytes } : { kind: "object", value };
|
|
89252
87570
|
}
|
|
89253
87571
|
var TOOL_JSON_TEXT_FIELDS = ["rawArgs", "params", "result"];
|
|
@@ -89256,7 +87574,7 @@ function hasCallEvidence(tool) {
|
|
|
89256
87574
|
}
|
|
89257
87575
|
function retainedCallField(key, value) {
|
|
89258
87576
|
if (!TOOL_JSON_TEXT_FIELDS.includes(key) || typeof value !== "string") return value;
|
|
89259
|
-
return
|
|
87577
|
+
return safeJsonRecord(value) ?? value;
|
|
89260
87578
|
}
|
|
89261
87579
|
function toolLine(tool, recorder, formatVersion) {
|
|
89262
87580
|
const rawArgs = typeof tool.rawArgs === "string" && tool.rawArgs !== "" ? tool.rawArgs : typeof tool.params === "string" ? tool.params : "";
|
|
@@ -89265,7 +87583,7 @@ function toolLine(tool, recorder, formatVersion) {
|
|
|
89265
87583
|
if (args?.kind === "over") recorder.count("truncated");
|
|
89266
87584
|
const result = typeof tool.result === "string" ? boundedJsonText(tool.result, TOOL_RESULT_MAX_BYTES) : null;
|
|
89267
87585
|
if (result?.kind === "over") recorder.count("truncated");
|
|
89268
|
-
const parsedArgs = args?.kind === "object" ? args.value : args?.kind === "over" ?
|
|
87586
|
+
const parsedArgs = args?.kind === "object" ? args.value : args?.kind === "over" ? safeJsonRecord(rawArgs) : null;
|
|
89269
87587
|
const filePath = parsedArgs === null ? void 0 : toolFilePathOf(parsedArgs);
|
|
89270
87588
|
return {
|
|
89271
87589
|
name: tool.name,
|
|
@@ -89311,13 +87629,13 @@ function bubbleLines(bubble, at, recorder) {
|
|
|
89311
87629
|
const text = typeof bubble.text === "string" ? bubble.text : "";
|
|
89312
87630
|
if (bubble.type === 1) {
|
|
89313
87631
|
collectUnfamiliar(bubble, USER_BUBBLE_FIELDS, BUBBLE_FIELDS_EXCLUDED, "", unfamiliar, recorder, formatVersion);
|
|
89314
|
-
const context2 =
|
|
87632
|
+
const context2 = isRecord(bubble.context) ? promptContext(bubble.context, recorder) : {};
|
|
89315
87633
|
if (text.trim() !== "" || Object.keys(context2).length > 0) {
|
|
89316
87634
|
lines.push({ type: "user", text, ...createdAt, ...context2, ...position });
|
|
89317
87635
|
}
|
|
89318
87636
|
} else {
|
|
89319
87637
|
collectUnfamiliar(bubble, ASSISTANT_BUBBLE_FIELDS, BUBBLE_FIELDS_EXCLUDED, "", unfamiliar, recorder, formatVersion);
|
|
89320
|
-
const tool =
|
|
87638
|
+
const tool = isRecord(bubble.toolFormerData) ? bubble.toolFormerData : null;
|
|
89321
87639
|
if (tool !== null) {
|
|
89322
87640
|
collectUnfamiliar(tool, TOOL_FIELDS_INTERPRETED, TOOL_FIELDS_EXCLUDED, "toolFormerData", unfamiliar, recorder, formatVersion);
|
|
89323
87641
|
if (typeof tool.name === "string" && tool.name !== "") {
|
|
@@ -89330,7 +87648,7 @@ function bubbleLines(bubble, at, recorder) {
|
|
|
89330
87648
|
}
|
|
89331
87649
|
}
|
|
89332
87650
|
if (bubble.thinking !== void 0 && bubble.thinking !== null) {
|
|
89333
|
-
if (
|
|
87651
|
+
if (isRecord(bubble.thinking)) {
|
|
89334
87652
|
collectUnfamiliar(bubble.thinking, THINKING_FIELDS_INTERPRETED, THINKING_FIELDS_EXCLUDED, "thinking", unfamiliar, recorder, formatVersion);
|
|
89335
87653
|
}
|
|
89336
87654
|
const thinkingText = cursorThinkingText(bubble.thinking);
|
|
@@ -89342,7 +87660,7 @@ function bubbleLines(bubble, at, recorder) {
|
|
|
89342
87660
|
...position
|
|
89343
87661
|
});
|
|
89344
87662
|
}
|
|
89345
|
-
const modelInfo =
|
|
87663
|
+
const modelInfo = isRecord(bubble.modelInfo) ? bubble.modelInfo : null;
|
|
89346
87664
|
if (modelInfo !== null) {
|
|
89347
87665
|
collectUnfamiliar(modelInfo, MODEL_INFO_FIELDS_INTERPRETED, /* @__PURE__ */ new Set(), "modelInfo", unfamiliar, recorder, formatVersion);
|
|
89348
87666
|
}
|
|
@@ -89371,8 +87689,8 @@ var CONTENT_LINE_TYPES = /* @__PURE__ */ new Set([
|
|
|
89371
87689
|
function extractTranscript(db, composerId, maxBytes) {
|
|
89372
87690
|
const valueByKey = db.prepare("select value from cursorDiskKV where key = ?");
|
|
89373
87691
|
const dataRow = valueByKey.get(`composerData:${composerId}`);
|
|
89374
|
-
const dataText =
|
|
89375
|
-
const data = dataText === null ? null :
|
|
87692
|
+
const dataText = isRecord(dataRow) && typeof dataRow.value === "string" ? dataRow.value : null;
|
|
87693
|
+
const data = dataText === null ? null : safeJsonRecord(dataText);
|
|
89376
87694
|
const spine = Array.isArray(data?.fullConversationHeadersOnly) ? data.fullConversationHeadersOnly : [];
|
|
89377
87695
|
if (spine.length === 0) return null;
|
|
89378
87696
|
const recorder = createOmissionRecorder();
|
|
@@ -89386,14 +87704,14 @@ function extractTranscript(db, composerId, maxBytes) {
|
|
|
89386
87704
|
for (const [spineIndex, entry] of spine.entries()) {
|
|
89387
87705
|
const entryRecorder = createOmissionRecorder();
|
|
89388
87706
|
let bubbleLinesOut;
|
|
89389
|
-
if (!
|
|
89390
|
-
entryRecorder.note("malformed", "spine[]", jsonValueType(
|
|
87707
|
+
if (!isRecord(entry) || typeof entry.bubbleId !== "string") {
|
|
87708
|
+
entryRecorder.note("malformed", "spine[]", jsonValueType(isRecord(entry) ? entry.bubbleId : entry));
|
|
89391
87709
|
bubbleLinesOut = [{ type: "malformed", spineIndex, bytes: Buffer.byteLength(JSON.stringify(entry) ?? "") }];
|
|
89392
87710
|
} else {
|
|
89393
87711
|
const at = { spineIndex, bubbleId: entry.bubbleId };
|
|
89394
87712
|
const row = valueByKey.get(`bubbleId:${composerId}:${entry.bubbleId}`);
|
|
89395
|
-
const text =
|
|
89396
|
-
const bubble = text === null ? null :
|
|
87713
|
+
const text = isRecord(row) && typeof row.value === "string" ? row.value : null;
|
|
87714
|
+
const bubble = text === null ? null : safeJsonRecord(text);
|
|
89397
87715
|
if (text === null) {
|
|
89398
87716
|
entryRecorder.note("unavailable", "bubble", "missing");
|
|
89399
87717
|
bubbleLinesOut = [{ type: "unavailable", ...at }];
|
|
@@ -89475,7 +87793,7 @@ function collectFromStore(db, userDir, options, result, knownIds) {
|
|
|
89475
87793
|
const maxBytes = options.maxTranscriptBytes ?? MAX_TRANSCRIPT_FILE_BYTES;
|
|
89476
87794
|
let extractedTranscriptsDirReady = false;
|
|
89477
87795
|
const columns = new Set(
|
|
89478
|
-
db.prepare("pragma table_info(composerHeaders)").all().map((row) =>
|
|
87796
|
+
db.prepare("pragma table_info(composerHeaders)").all().map((row) => isRecord(row) ? row.name : void 0)
|
|
89479
87797
|
);
|
|
89480
87798
|
const archiveColumn = columns.has("isArchived") ? "isArchived, " : "";
|
|
89481
87799
|
const headerRows = db.prepare(
|
|
@@ -89483,11 +87801,11 @@ function collectFromStore(db, userDir, options, result, knownIds) {
|
|
|
89483
87801
|
).all(options.sinceMs ?? 0);
|
|
89484
87802
|
for (const raw of headerRows) {
|
|
89485
87803
|
try {
|
|
89486
|
-
if (!
|
|
87804
|
+
if (!isRecord(raw) || typeof raw.composerId !== "string" || raw.composerId === "") continue;
|
|
89487
87805
|
knownIds.add(raw.composerId);
|
|
89488
87806
|
const lastUpdatedAt = typeof raw.lastUpdatedAt === "number" ? raw.lastUpdatedAt : typeof raw.createdAt === "number" ? raw.createdAt : null;
|
|
89489
87807
|
if (lastUpdatedAt === null) continue;
|
|
89490
|
-
const value = typeof raw.value === "string" ?
|
|
87808
|
+
const value = typeof raw.value === "string" ? safeJsonRecord(raw.value) : null;
|
|
89491
87809
|
if (value === null) {
|
|
89492
87810
|
result.skippedUnreadable += 1;
|
|
89493
87811
|
continue;
|
|
@@ -89662,7 +87980,7 @@ function parseCursorTranscriptFile(text) {
|
|
|
89662
87980
|
} catch {
|
|
89663
87981
|
value = void 0;
|
|
89664
87982
|
}
|
|
89665
|
-
if (!
|
|
87983
|
+
if (!isRecord(value)) {
|
|
89666
87984
|
lines.push({ type: "malformed", recordIndex, bytes: Buffer.byteLength(row) });
|
|
89667
87985
|
recorder.note("malformed", "record", jsonValueType(value));
|
|
89668
87986
|
return;
|
|
@@ -89681,7 +87999,7 @@ function parseCursorTranscriptFile(text) {
|
|
|
89681
87999
|
const role = record2.data.role;
|
|
89682
88000
|
record2.data.message.content.forEach((content, blockIndex) => {
|
|
89683
88001
|
const at = { recordIndex, blockIndex };
|
|
89684
|
-
if (!
|
|
88002
|
+
if (!isRecord(content)) {
|
|
89685
88003
|
lines.push({ type: "malformed", ...at, bytes: Buffer.byteLength(JSON.stringify(content)) });
|
|
89686
88004
|
recorder.note("malformed", "message.content[]", jsonValueType(content));
|
|
89687
88005
|
return;
|
|
@@ -90332,8 +88650,9 @@ function nativeHarnessName(harness) {
|
|
|
90332
88650
|
throw new Error(`unsupported hook harness: ${String(harness)}`);
|
|
90333
88651
|
}
|
|
90334
88652
|
}
|
|
88653
|
+
var CODEX_EVENTS = ["SessionStart", "SessionEnd", "Stop"];
|
|
90335
88654
|
function harnessEvents(harness) {
|
|
90336
|
-
return nativeHarnessName(harness) === "cursor" ? ["sessionStart", "sessionEnd", "stop"] :
|
|
88655
|
+
return nativeHarnessName(harness) === "cursor" ? ["sessionStart", "sessionEnd", "stop"] : CODEX_EVENTS;
|
|
90337
88656
|
}
|
|
90338
88657
|
function harnessHookConfigPath(harness, home) {
|
|
90339
88658
|
const nativeName = nativeHarnessName(harness);
|
|
@@ -90371,15 +88690,19 @@ function isOurHook2(hook) {
|
|
|
90371
88690
|
if (runsPowerplantHook(commandWords(command) ?? [])) return true;
|
|
90372
88691
|
return /['"]$/.test(command) && OUR_LEGACY_SCRIPTS.includes(command.slice(0, -1).split(/[\\/]/).pop());
|
|
90373
88692
|
}
|
|
90374
|
-
var
|
|
90375
|
-
|
|
88693
|
+
var CODEX_HOOK_NAMES = {
|
|
88694
|
+
SessionStart: "Powerplant: Session Start",
|
|
88695
|
+
Stop: "Powerplant: Turn End",
|
|
88696
|
+
SessionEnd: "Powerplant: Session End"
|
|
88697
|
+
};
|
|
88698
|
+
function codexHandler(event, command, entries, kept) {
|
|
90376
88699
|
const last = entries.at(-1);
|
|
90377
88700
|
const inPlace = last !== void 0 && kept.length === entries.length - 1 && Object.keys(last).length === 1 ? external_exports.array(jsonObject).parse(last.hooks) : [];
|
|
90378
88701
|
const current = inPlace.length === 1 ? inPlace[0] : void 0;
|
|
90379
88702
|
if (current !== void 0 && current.type === "command" && current.command === command && current.timeout === 2 && Object.keys(current).every((key) => ["type", "command", "timeout", "statusMessage"].includes(key))) {
|
|
90380
88703
|
return current;
|
|
90381
88704
|
}
|
|
90382
|
-
return { type: "command", command, timeout: 2, statusMessage:
|
|
88705
|
+
return { type: "command", command, timeout: 2, statusMessage: CODEX_HOOK_NAMES[event] };
|
|
90383
88706
|
}
|
|
90384
88707
|
function mergeHarnessHooks(harness, text, command) {
|
|
90385
88708
|
try {
|
|
@@ -90409,7 +88732,7 @@ function mergeHarnessHooks(harness, text, command) {
|
|
|
90409
88732
|
else hooks[event] = kept;
|
|
90410
88733
|
continue;
|
|
90411
88734
|
}
|
|
90412
|
-
const handler = nativeName === "cursor" ? { command, timeout: 2 } : codexHandler(command, entries, kept);
|
|
88735
|
+
const handler = nativeName === "cursor" ? { command, timeout: 2 } : codexHandler(event, command, entries, kept);
|
|
90413
88736
|
hooks[event] = [...kept, nativeName === "cursor" ? handler : { hooks: [handler] }];
|
|
90414
88737
|
}
|
|
90415
88738
|
const next = { ...settings, ...nativeName === "cursor" && command !== null ? { version: 1 } : {}, hooks };
|
|
@@ -90721,7 +89044,8 @@ function createHookHealthTracker(deps) {
|
|
|
90721
89044
|
installedAt: new Date(installedAtMs).toISOString(),
|
|
90722
89045
|
sessionStartedAfterInstallMs: Date.parse(candidate.startedAt) - installedAtMs
|
|
90723
89046
|
},
|
|
90724
|
-
"warning"
|
|
89047
|
+
"warning",
|
|
89048
|
+
["collector-hook-silent", harness, silence.kind]
|
|
90725
89049
|
);
|
|
90726
89050
|
}
|
|
90727
89051
|
return true;
|
|
@@ -91437,9 +89761,10 @@ function readServiceProcess(appEnv) {
|
|
|
91437
89761
|
});
|
|
91438
89762
|
} catch (cause) {
|
|
91439
89763
|
const status = cause instanceof Error && "status" in cause ? cause.status : void 0;
|
|
89764
|
+
const timedOut = cause instanceof Error && "code" in cause && cause.code === "ETIMEDOUT";
|
|
91440
89765
|
if (status === 112) return { kind: "domain-missing" };
|
|
91441
89766
|
if (status === 113) return { kind: "absent" };
|
|
91442
|
-
throw new Error(`Could not verify the background sync process: ${typeof status === "number" ? describeLaunchctlExit(status) : "launchctl failed or timed out"}`);
|
|
89767
|
+
throw new Error(`Could not verify the background sync process: ${timedOut ? "launchctl did not answer within 3 s" : typeof status === "number" ? describeLaunchctlExit(status) : "launchctl failed or timed out"}`);
|
|
91443
89768
|
}
|
|
91444
89769
|
const match = /^\s*pid = (\d+)\s*$/m.exec(output2);
|
|
91445
89770
|
return { kind: "loaded", pid: match ? Number(match[1]) : null };
|
|
@@ -91456,7 +89781,7 @@ function refuseStaleAppEnvLauncher(env, readLauncher = readLauncherIfExists) {
|
|
|
91456
89781
|
const script = readLauncher(launcherPath(appEnv));
|
|
91457
89782
|
if (script === null || !script.includes("APP_ENV=") || script.includes("POWERPLANT_ENV=")) return;
|
|
91458
89783
|
throw new ExpectedCliError(
|
|
91459
|
-
`This background service was installed before the POWERPLANT_ENV rename and is no longer supported.
|
|
89784
|
+
`This background service was installed before the POWERPLANT_ENV rename and is no longer supported. ` + (appEnv === "production" ? "Remove it with: powerplant uninstall, then powerplant init reinstalls it." : `Remove it with: powerplant uninstall --env ${appEnv}, then powerplant init --env ${appEnv} reinstalls it if you still need it.`)
|
|
91460
89785
|
);
|
|
91461
89786
|
}
|
|
91462
89787
|
function readLauncherIfExists(launcherFile) {
|
|
@@ -91692,11 +90017,11 @@ function readInstallRecord(file2) {
|
|
|
91692
90017
|
return { kind: "found", record: parsed.data };
|
|
91693
90018
|
}
|
|
91694
90019
|
function writeInstallRecord(file2, record2) {
|
|
91695
|
-
const
|
|
90020
|
+
const checked2 = installRecordSchema.parse(record2);
|
|
91696
90021
|
const temporary = `${file2}.${process.pid}.tmp`;
|
|
91697
90022
|
try {
|
|
91698
90023
|
mkdirSync8(path16.dirname(file2), { recursive: true });
|
|
91699
|
-
writeFileSync7(temporary, `${JSON.stringify(
|
|
90024
|
+
writeFileSync7(temporary, `${JSON.stringify(checked2, null, 2)}
|
|
91700
90025
|
`);
|
|
91701
90026
|
renameSync6(temporary, file2);
|
|
91702
90027
|
} catch (error63) {
|
|
@@ -91821,8 +90146,9 @@ var EncryptedCredentialStore = class {
|
|
|
91821
90146
|
};
|
|
91822
90147
|
function unreadableCredentials(appEnv, reason) {
|
|
91823
90148
|
const powerplant = typedPowerplantCommand(appEnv);
|
|
90149
|
+
const env = appEnv === "production" ? "" : ` --env ${appEnv}`;
|
|
91824
90150
|
return new ExpectedCliError(
|
|
91825
|
-
`Stored sync service credentials for ${appEnv} cannot be read: ${reason}. Run ${powerplant} uninstall --forget
|
|
90151
|
+
`Stored sync service credentials for ${appEnv} cannot be read: ${reason}. Run ${powerplant} uninstall --forget${env}, then ${powerplant} init${env} to re-enroll.`
|
|
91826
90152
|
);
|
|
91827
90153
|
}
|
|
91828
90154
|
function writeNewFile(file2, content) {
|
|
@@ -92385,22 +90711,38 @@ var DELETE_CODES = /* @__PURE__ */ new Set([...LOCKED_CODES, "ENOTEMPTY", "EMFIL
|
|
|
92385
90711
|
var RETRY_LIMIT_MS = 5e3;
|
|
92386
90712
|
var FIRST_WAIT_MS = 50;
|
|
92387
90713
|
var LONGEST_WAIT_MS = 1e3;
|
|
90714
|
+
var LOCK_WAIT_LABEL = "Waiting for Windows to release Powerplant's files\u2026";
|
|
92388
90715
|
var sleeper = new Int32Array(new SharedArrayBuffer(4));
|
|
92389
90716
|
var systemClock = { now: () => performance.now(), sleep: (ms) => void Atomics.wait(sleeper, 0, 0, ms) };
|
|
92390
90717
|
function retryWhileLocked(what, change, retry, codes = LOCKED_CODES) {
|
|
92391
90718
|
const clock = retry.clock ?? systemClock;
|
|
92392
90719
|
const started = clock.now();
|
|
92393
90720
|
let first = null;
|
|
92394
|
-
|
|
92395
|
-
|
|
92396
|
-
|
|
92397
|
-
|
|
92398
|
-
|
|
92399
|
-
|
|
92400
|
-
|
|
92401
|
-
|
|
92402
|
-
|
|
90721
|
+
let stopWaiting = null;
|
|
90722
|
+
try {
|
|
90723
|
+
for (let wait = FIRST_WAIT_MS; ; wait = Math.min(wait * 2, LONGEST_WAIT_MS)) {
|
|
90724
|
+
try {
|
|
90725
|
+
return change();
|
|
90726
|
+
} catch (error63) {
|
|
90727
|
+
first ??= { error: error63 };
|
|
90728
|
+
const code = errorCode(error63, codes);
|
|
90729
|
+
const waited = clock.now() - started;
|
|
90730
|
+
if (code === null || waited + wait > RETRY_LIMIT_MS) {
|
|
90731
|
+
if (stopWaiting !== null) {
|
|
90732
|
+
stopWaiting();
|
|
90733
|
+
stopWaiting = null;
|
|
90734
|
+
const reason = code === null ? "a retry failed another way" : `Windows still held the file (${code})`;
|
|
90735
|
+
retry.log(`${what}: gave up after ${Math.round(waited)} ms of retries: ${reason}`);
|
|
90736
|
+
}
|
|
90737
|
+
throw first.error;
|
|
90738
|
+
}
|
|
90739
|
+
stopWaiting ??= retry.waiting?.(LOCK_WAIT_LABEL) ?? (() => {
|
|
90740
|
+
});
|
|
90741
|
+
clock.sleep(wait);
|
|
90742
|
+
}
|
|
92403
90743
|
}
|
|
90744
|
+
} finally {
|
|
90745
|
+
stopWaiting?.();
|
|
92404
90746
|
}
|
|
92405
90747
|
}
|
|
92406
90748
|
function errorCode(error63, codes) {
|
|
@@ -92442,6 +90784,7 @@ var TaskSchedulerService = class {
|
|
|
92442
90784
|
this.homeDir = homeDir;
|
|
92443
90785
|
this.env = deps.env ?? process.env;
|
|
92444
90786
|
this.runPowerShell = deps.runPowerShell ?? runWindowsPowerShell;
|
|
90787
|
+
this.runPowerShellAsync = deps.runPowerShellAsync ?? runWindowsPowerShellAsync;
|
|
92445
90788
|
this.endProcess = deps.endProcess ?? endProcessIfRunning;
|
|
92446
90789
|
this.isElevated = deps.isElevated ?? (() => windowsProcessIsElevated(this.env.SystemRoot ?? "C:\\Windows"));
|
|
92447
90790
|
this.taskNameInput = { taskBaseName: serviceDisplayName(appEnv), profilePath: homeDir };
|
|
@@ -92457,6 +90800,7 @@ var TaskSchedulerService = class {
|
|
|
92457
90800
|
definitionPath;
|
|
92458
90801
|
env;
|
|
92459
90802
|
runPowerShell;
|
|
90803
|
+
runPowerShellAsync;
|
|
92460
90804
|
endProcess;
|
|
92461
90805
|
/** The input every script builds the task name from (TASK_NAME_PRELUDE). */
|
|
92462
90806
|
taskNameInput;
|
|
@@ -92468,9 +90812,15 @@ var TaskSchedulerService = class {
|
|
|
92468
90812
|
* way. */
|
|
92469
90813
|
state() {
|
|
92470
90814
|
if (!existsSync8(this.definitionPath)) return "not-installed";
|
|
92471
|
-
|
|
92472
|
-
|
|
92473
|
-
|
|
90815
|
+
return taskState(this.describe(null).task);
|
|
90816
|
+
}
|
|
90817
|
+
/** state() without blocking, so status and doctor can ask Task Scheduler
|
|
90818
|
+
* while they unlock the credentials and wait for the network. */
|
|
90819
|
+
async stateAsync() {
|
|
90820
|
+
if (!existsSync8(this.definitionPath)) return "not-installed";
|
|
90821
|
+
const record2 = readSupervisorRecord(this.recordPath);
|
|
90822
|
+
const result = await this.runPowerShellAsync(DESCRIBE_SCRIPT, JSON.stringify(this.describeInput(null, record2)));
|
|
90823
|
+
return taskState(this.described(record2, checked("read the task", result)).task);
|
|
92474
90824
|
}
|
|
92475
90825
|
/** Registered with this command and this definition, and running. */
|
|
92476
90826
|
upToDate(command) {
|
|
@@ -92628,12 +90978,17 @@ var TaskSchedulerService = class {
|
|
|
92628
90978
|
* recorded program. */
|
|
92629
90979
|
describe(action) {
|
|
92630
90980
|
const record2 = readSupervisorRecord(this.recordPath);
|
|
90981
|
+
return this.described(record2, this.run("read the task", DESCRIBE_SCRIPT, this.describeInput(action, record2)));
|
|
90982
|
+
}
|
|
90983
|
+
describeInput(action, record2) {
|
|
92631
90984
|
const expected = action === null ? null : { ...action, description: this.description() };
|
|
92632
|
-
|
|
90985
|
+
return {
|
|
92633
90986
|
...this.taskNameInput,
|
|
92634
90987
|
expected,
|
|
92635
90988
|
supervisor: record2 === null ? null : { pid: record2.pid, executable: record2.executable }
|
|
92636
|
-
}
|
|
90989
|
+
};
|
|
90990
|
+
}
|
|
90991
|
+
described(record2, result) {
|
|
92637
90992
|
const parsed = describeOutputSchema.safeParse(parseJson(result.stdout));
|
|
92638
90993
|
if (!parsed.success) throw new Error("Task Scheduler returned an answer this version cannot read");
|
|
92639
90994
|
const running = parsed.data.supervisor;
|
|
@@ -92653,11 +91008,17 @@ var TaskSchedulerService = class {
|
|
|
92653
91008
|
if (described.supervisorPid !== null) this.endProcess(described.supervisorPid);
|
|
92654
91009
|
}
|
|
92655
91010
|
run(step, script, input2) {
|
|
92656
|
-
|
|
92657
|
-
if (result.status !== 0) throw new Error(`Task Scheduler could not ${step}: ${powerShellError(result)}`);
|
|
92658
|
-
return result;
|
|
91011
|
+
return checked(step, this.runPowerShell(script, JSON.stringify(input2)));
|
|
92659
91012
|
}
|
|
92660
91013
|
};
|
|
91014
|
+
function checked(step, result) {
|
|
91015
|
+
if (result.status !== 0) throw new Error(`Task Scheduler could not ${step}: ${powerShellError(result)}`);
|
|
91016
|
+
return result;
|
|
91017
|
+
}
|
|
91018
|
+
function taskState(task) {
|
|
91019
|
+
if (task === null) return "not-installed";
|
|
91020
|
+
return task.state === "Running" ? "loaded" : "not-loaded";
|
|
91021
|
+
}
|
|
92661
91022
|
var describeOutputSchema = external_exports.object({
|
|
92662
91023
|
taskName: external_exports.string(),
|
|
92663
91024
|
task: external_exports.object({ state: external_exports.string(), current: external_exports.boolean() }).nullable(),
|
|
@@ -92936,7 +91297,7 @@ function listNames(dir) {
|
|
|
92936
91297
|
}
|
|
92937
91298
|
async function installRelease(options) {
|
|
92938
91299
|
const { location, recordFile } = options;
|
|
92939
|
-
const retry = { log: options.log, ...options.clock !== void 0 && { clock: options.clock } };
|
|
91300
|
+
const retry = { log: options.log, waiting: options.waiting, ...options.clock !== void 0 && { clock: options.clock } };
|
|
92940
91301
|
const record2 = readRecordForInstall(recordFile);
|
|
92941
91302
|
const running = versionHolding(location, options.runningProgram);
|
|
92942
91303
|
const keep = record2 === null ? listNames(location) : [record2.version, record2.previousVersion, running].filter((version2) => version2 !== null);
|
|
@@ -93755,14 +92116,19 @@ async function errorDetail(response) {
|
|
|
93755
92116
|
}
|
|
93756
92117
|
const parsed = errorDetailSchema.safeParse(body);
|
|
93757
92118
|
const trimmed = text.trim();
|
|
93758
|
-
const detail = parsed.success ? parsed.data.error : trimmed === "" ? "no detail" : trimmed.slice(0, 200);
|
|
92119
|
+
const detail = parsed.success ? parsed.data.error : trimmed === "" ? "no detail" : trimmed.startsWith("<") ? htmlPageDetail(trimmed) : trimmed.slice(0, 200);
|
|
93759
92120
|
const requestId = responseRequestId(response) ?? (parsed.success ? parsed.data.meta?.requestId : void 0);
|
|
93760
92121
|
return requestId === void 0 ? detail : `${detail} [request ${requestId}]`;
|
|
93761
92122
|
}
|
|
92123
|
+
function htmlPageDetail(page) {
|
|
92124
|
+
const title = htmlPageTitle(page);
|
|
92125
|
+
return `the server sent an error page${title ? ` ("${title}")` : ""}`;
|
|
92126
|
+
}
|
|
93762
92127
|
async function failedResponse(label2, response) {
|
|
93763
92128
|
const message2 = `${label2} (${response.status}): ${await errorDetail(response)}`;
|
|
92129
|
+
const operation = responseOperation(response) ?? label2;
|
|
93764
92130
|
return withRequestId(
|
|
93765
|
-
response.status === 429 ? new RateLimitedError(message2, parseRetryAfter(response)) : new
|
|
92131
|
+
response.status === 429 ? new RateLimitedError(message2, parseRetryAfter(response), operation) : new ApiRequestError(message2, operation, response.status),
|
|
93766
92132
|
response
|
|
93767
92133
|
);
|
|
93768
92134
|
}
|
|
@@ -93899,22 +92265,6 @@ async function uploadBranchFacts(apiUrl, machineToken, facts) {
|
|
|
93899
92265
|
}
|
|
93900
92266
|
return { recorded };
|
|
93901
92267
|
}
|
|
93902
|
-
async function uploadPreviewRegistration(apiUrl, machineToken, registration) {
|
|
93903
|
-
const response = await fetchWithRetry("registering previews", `${apiUrl}/api/ingest/previews`, {
|
|
93904
|
-
method: "POST",
|
|
93905
|
-
headers: { authorization: `Bearer ${machineToken}`, "content-type": "application/json" },
|
|
93906
|
-
body: JSON.stringify(registration)
|
|
93907
|
-
});
|
|
93908
|
-
if (response.status === 401) {
|
|
93909
|
-
throw tokenRejected("The ingest API", response);
|
|
93910
|
-
}
|
|
93911
|
-
if (response.status === 403) return "foreign-owner";
|
|
93912
|
-
if (response.status === 423) return "previews-off";
|
|
93913
|
-
if (!response.ok) {
|
|
93914
|
-
throw await failedResponse("preview registration failed", response);
|
|
93915
|
-
}
|
|
93916
|
-
return "registered";
|
|
93917
|
-
}
|
|
93918
92268
|
var gzipAsync = promisify2(gzip);
|
|
93919
92269
|
var REDACT_SLICE_CHARS = 64 * 1024;
|
|
93920
92270
|
async function encodeRawTranscript(text) {
|
|
@@ -94068,12 +92418,10 @@ async function uploadRawSessions(apiUrl, machineToken, transcriptUploadSources,
|
|
|
94068
92418
|
summary.outcomes.set(key, "missing-metadata");
|
|
94069
92419
|
continue;
|
|
94070
92420
|
}
|
|
94071
|
-
if (response.status === 429) {
|
|
94072
|
-
throw await failedResponse("raw transcript upload failed", response);
|
|
94073
|
-
}
|
|
94074
92421
|
if (!response.ok) {
|
|
94075
|
-
throw
|
|
92422
|
+
throw await failedResponse("raw transcript upload failed", response);
|
|
94076
92423
|
}
|
|
92424
|
+
progress?.failures?.succeeded(key);
|
|
94077
92425
|
summary.uploaded += 1;
|
|
94078
92426
|
summary.skippedSubagentFiles += skippedSubagentFiles;
|
|
94079
92427
|
summary.outcomes.set(key, "uploaded");
|
|
@@ -94089,8 +92437,10 @@ async function uploadRawSessions(apiUrl, machineToken, transcriptUploadSources,
|
|
|
94089
92437
|
summary.outcomes.set(key, "changed-since-read");
|
|
94090
92438
|
continue;
|
|
94091
92439
|
}
|
|
92440
|
+
progress?.failures?.failed(key, error63);
|
|
94092
92441
|
summary.outcomes.set(key, "failed");
|
|
94093
92442
|
if (error63 instanceof RateLimitedError) rateLimited ??= error63;
|
|
92443
|
+
summary.firstFailure ??= error63;
|
|
94094
92444
|
summary.failed.push(
|
|
94095
92445
|
`${session.item.harnessSessionId}: ${error63 instanceof Error ? error63.message : String(error63)}`
|
|
94096
92446
|
);
|
|
@@ -94165,7 +92515,9 @@ async function runEnrollment(config2, options) {
|
|
|
94165
92515
|
email: options.email,
|
|
94166
92516
|
password: options.password,
|
|
94167
92517
|
capture: { mode: captureMode, folderCount: scopePaths.length },
|
|
94168
|
-
log: log3
|
|
92518
|
+
log: log3,
|
|
92519
|
+
confirmOpen: options.confirmOpen,
|
|
92520
|
+
onWaiting: options.onWaiting
|
|
94169
92521
|
});
|
|
94170
92522
|
let orgPolicy = captureMode === "org-repos" ? await fetchCapturePolicy(config2.apiUrl, result.token) : void 0;
|
|
94171
92523
|
const anyWorkspaceClaims = (orgPolicy?.workspaces ?? []).some(workspaceClaimsAnyRepo);
|
|
@@ -94241,7 +92593,13 @@ async function enroll(config2, options, createAuthClient = gotrueAuthClient, lis
|
|
|
94241
92593
|
capture: options.capture
|
|
94242
92594
|
}),
|
|
94243
92595
|
state,
|
|
94244
|
-
{
|
|
92596
|
+
{
|
|
92597
|
+
...listener,
|
|
92598
|
+
log: options.log,
|
|
92599
|
+
confirmOpen: options.confirmOpen,
|
|
92600
|
+
onWaiting: options.onWaiting,
|
|
92601
|
+
redeem: (code) => redeemApproval(config2.apiUrl, code, verifier)
|
|
92602
|
+
}
|
|
94245
92603
|
);
|
|
94246
92604
|
}
|
|
94247
92605
|
var challengeFor = (verifier) => createHash7("sha256").update(verifier).digest("hex");
|
|
@@ -94282,7 +92640,11 @@ async function redeemApproval(apiUrl, code, verifier) {
|
|
|
94282
92640
|
}
|
|
94283
92641
|
async function readEnrollmentResponse(response) {
|
|
94284
92642
|
if (response.status !== 201) {
|
|
94285
|
-
throw new
|
|
92643
|
+
throw withRequestId(new ApiRequestError(
|
|
92644
|
+
`enrollment failed (${response.status}): ${await errorDetail(response)}`,
|
|
92645
|
+
responseOperation(response) ?? "enrolling this machine",
|
|
92646
|
+
response.status
|
|
92647
|
+
), response);
|
|
94286
92648
|
}
|
|
94287
92649
|
const body = await response.json().catch(() => null);
|
|
94288
92650
|
const enrollment = body?.data;
|
|
@@ -94319,7 +92681,9 @@ function waitForApproval(approvalUrl, state, options) {
|
|
|
94319
92681
|
port = MACHINE_ENROLL_CALLBACK_PORT,
|
|
94320
92682
|
onListening,
|
|
94321
92683
|
timeoutMs = APPROVAL_TIMEOUT_MS,
|
|
94322
|
-
log: log3 = console.log
|
|
92684
|
+
log: log3 = console.log,
|
|
92685
|
+
confirmOpen,
|
|
92686
|
+
onWaiting
|
|
94323
92687
|
} = options;
|
|
94324
92688
|
const open3 = options.open ?? ((url2) => openUrl(url2, (reason) => log3(`Could not open a browser (${reason}). Open the link above to approve.`)));
|
|
94325
92689
|
return new Promise((resolve2, reject) => {
|
|
@@ -94386,18 +92750,35 @@ function waitForApproval(approvalUrl, state, options) {
|
|
|
94386
92750
|
)
|
|
94387
92751
|
);
|
|
94388
92752
|
});
|
|
94389
|
-
|
|
94390
|
-
|
|
94391
|
-
|
|
94392
|
-
|
|
94393
|
-
|
|
94394
|
-
|
|
94395
|
-
|
|
94396
|
-
|
|
94397
|
-
|
|
94398
|
-
|
|
92753
|
+
let timeout;
|
|
92754
|
+
const settled = new AbortController();
|
|
92755
|
+
const startWaiting = () => {
|
|
92756
|
+
if (settled.signal.aborted) return;
|
|
92757
|
+
if (!redeeming) {
|
|
92758
|
+
timeout = setTimeout(
|
|
92759
|
+
() => finish(
|
|
92760
|
+
() => reject(
|
|
92761
|
+
new ExpectedCliError(
|
|
92762
|
+
"enrollment approval timed out after 5 minutes, run the same command again to retry"
|
|
92763
|
+
)
|
|
92764
|
+
)
|
|
92765
|
+
),
|
|
92766
|
+
timeoutMs
|
|
92767
|
+
);
|
|
92768
|
+
}
|
|
92769
|
+
onWaiting?.();
|
|
92770
|
+
};
|
|
92771
|
+
const presentPage = async () => {
|
|
92772
|
+
if (confirmOpen === void 0) {
|
|
92773
|
+
log3(`Opening approval page\u2026 ${approvalUrl}`);
|
|
92774
|
+
open3(approvalUrl);
|
|
92775
|
+
return;
|
|
92776
|
+
}
|
|
92777
|
+
if (await confirmOpen(approvalUrl, settled.signal)) open3(approvalUrl);
|
|
92778
|
+
};
|
|
94399
92779
|
const finish = (settle2) => {
|
|
94400
92780
|
clearTimeout(timeout);
|
|
92781
|
+
settled.abort();
|
|
94401
92782
|
server.close();
|
|
94402
92783
|
server.closeAllConnections();
|
|
94403
92784
|
settle2();
|
|
@@ -94406,8 +92787,10 @@ function waitForApproval(approvalUrl, state, options) {
|
|
|
94406
92787
|
server.listen(port, "127.0.0.1", () => {
|
|
94407
92788
|
const address = server.address();
|
|
94408
92789
|
if (onListening && address !== null && typeof address === "object") onListening(address.port);
|
|
94409
|
-
|
|
94410
|
-
|
|
92790
|
+
presentPage().then(
|
|
92791
|
+
startWaiting,
|
|
92792
|
+
(cause) => finish(() => reject(cause instanceof Error ? cause : new Error(String(cause))))
|
|
92793
|
+
);
|
|
94411
92794
|
});
|
|
94412
92795
|
});
|
|
94413
92796
|
}
|
|
@@ -96090,6 +94473,11 @@ function requireBackgroundService(service) {
|
|
|
96090
94473
|
function serviceState2(config2) {
|
|
96091
94474
|
return hostBackgroundService(config2.appEnv)?.state() ?? "unsupported";
|
|
96092
94475
|
}
|
|
94476
|
+
async function serviceStateAsync(config2) {
|
|
94477
|
+
const service = hostBackgroundService(config2.appEnv);
|
|
94478
|
+
if (service === null) return "unsupported";
|
|
94479
|
+
return service.stateAsync === void 0 ? service.state() : service.stateAsync();
|
|
94480
|
+
}
|
|
96093
94481
|
function serviceUpToDate2(config2, command) {
|
|
96094
94482
|
return hostBackgroundService(config2.appEnv)?.upToDate(command) ?? false;
|
|
96095
94483
|
}
|
|
@@ -96229,68 +94617,6 @@ function readIfExists2(p) {
|
|
|
96229
94617
|
}
|
|
96230
94618
|
}
|
|
96231
94619
|
|
|
96232
|
-
// ../../apps/syncservice/src/previewRegistration.ts
|
|
96233
|
-
import { setImmediate as yieldToEventLoop4 } from "node:timers/promises";
|
|
96234
|
-
async function registerAnnouncedPreviews(apiUrl, machineToken, collected, memo2, deps = {}) {
|
|
96235
|
-
const readTranscript = deps.readTranscript ?? readIfExists;
|
|
96236
|
-
const upload = deps.upload ?? uploadPreviewRegistration;
|
|
96237
|
-
const summary = {
|
|
96238
|
-
registered: 0,
|
|
96239
|
-
foreignOwned: [],
|
|
96240
|
-
previewsOff: [],
|
|
96241
|
-
failed: []
|
|
96242
|
-
};
|
|
96243
|
-
for (const session of collected) {
|
|
96244
|
-
if (session.item.status !== "active") continue;
|
|
96245
|
-
const key = sessionKey(session.item);
|
|
96246
|
-
const state = memo2.get(key);
|
|
96247
|
-
if (state?.foreignOwner || state?.previewsOff) continue;
|
|
96248
|
-
if (state?.examinedMtimeMs === session.mtimeMs) continue;
|
|
96249
|
-
await yieldToEventLoop4();
|
|
96250
|
-
try {
|
|
96251
|
-
const text = readTranscript(session.transcriptPath);
|
|
96252
|
-
if (text === null) continue;
|
|
96253
|
-
const legacyIdentity = legacySessionSourceFromHarness(session.item.harness);
|
|
96254
|
-
if (legacyIdentity.kind === "unsupported") {
|
|
96255
|
-
throw new Error(`Transcript parsing does not support ${session.item.harness}`);
|
|
96256
|
-
}
|
|
96257
|
-
const previews = announcedPreviewsFromTurns(parseSessionTurns(legacyIdentity.source, text)).filter(
|
|
96258
|
-
(preview) => preview.url.length <= MAX_PREVIEW_URL_LENGTH && redactText(preview.url) === preview.url
|
|
96259
|
-
).slice(-MAX_REGISTERED_PREVIEWS).map((preview) => ({
|
|
96260
|
-
...preview,
|
|
96261
|
-
label: redactText(preview.label).slice(0, MAX_PREVIEW_LABEL_LENGTH)
|
|
96262
|
-
}));
|
|
96263
|
-
const registeredJson = JSON.stringify(previews);
|
|
96264
|
-
if (previews.length === 0 || state?.registeredJson === registeredJson) {
|
|
96265
|
-
memo2.set(key, { ...state, examinedMtimeMs: session.mtimeMs });
|
|
96266
|
-
continue;
|
|
96267
|
-
}
|
|
96268
|
-
const outcome = await upload(apiUrl, machineToken, {
|
|
96269
|
-
harness: session.item.harness,
|
|
96270
|
-
harnessSessionId: session.item.harnessSessionId,
|
|
96271
|
-
previews
|
|
96272
|
-
});
|
|
96273
|
-
if (outcome === "foreign-owner") {
|
|
96274
|
-
memo2.set(key, { examinedMtimeMs: session.mtimeMs, foreignOwner: true });
|
|
96275
|
-
summary.foreignOwned.push(session.item.harnessSessionId);
|
|
96276
|
-
continue;
|
|
96277
|
-
}
|
|
96278
|
-
if (outcome === "previews-off") {
|
|
96279
|
-
memo2.set(key, { examinedMtimeMs: session.mtimeMs, previewsOff: true });
|
|
96280
|
-
summary.previewsOff.push(session.item.harnessSessionId);
|
|
96281
|
-
continue;
|
|
96282
|
-
}
|
|
96283
|
-
memo2.set(key, { examinedMtimeMs: session.mtimeMs, registeredJson });
|
|
96284
|
-
summary.registered += 1;
|
|
96285
|
-
} catch (error63) {
|
|
96286
|
-
summary.failed.push(
|
|
96287
|
-
`${session.item.harnessSessionId}: ${error63 instanceof Error ? error63.message : String(error63)}`
|
|
96288
|
-
);
|
|
96289
|
-
}
|
|
96290
|
-
}
|
|
96291
|
-
return summary;
|
|
96292
|
-
}
|
|
96293
|
-
|
|
96294
94620
|
// ../../apps/syncservice/src/sync.ts
|
|
96295
94621
|
var RecordTurns = class {
|
|
96296
94622
|
last = Promise.resolve();
|
|
@@ -96578,26 +94904,6 @@ async function runSyncPassInternal(config2, options, diagnostic, turn) {
|
|
|
96578
94904
|
);
|
|
96579
94905
|
}
|
|
96580
94906
|
if (options.isNewSession) return { sessions: collected, upserted };
|
|
96581
|
-
diagnostic.stage = "previews";
|
|
96582
|
-
const registerPreviews = options.registerPreviews ?? registerAnnouncedPreviews;
|
|
96583
|
-
const previewSummary = await registerPreviews(
|
|
96584
|
-
credentials.apiUrl,
|
|
96585
|
-
credentials.token,
|
|
96586
|
-
writable,
|
|
96587
|
-
options.previewRegistrations ?? /* @__PURE__ */ new Map()
|
|
96588
|
-
);
|
|
96589
|
-
if (previewSummary.registered > 0) {
|
|
96590
|
-
log3(`Previews: ${previewSummary.registered} registration(s) updated.`);
|
|
96591
|
-
}
|
|
96592
|
-
for (const externalId of previewSummary.foreignOwned) {
|
|
96593
|
-
log3(
|
|
96594
|
-
`Previews for ${externalId} are registered by another machine, leaving its list in place.`
|
|
96595
|
-
);
|
|
96596
|
-
}
|
|
96597
|
-
for (const externalId of previewSummary.previewsOff) {
|
|
96598
|
-
log3(`Previews for ${externalId} refused, this organization has previews switched off.`);
|
|
96599
|
-
}
|
|
96600
|
-
for (const failure2 of previewSummary.failed) log3(` preview registration failed, ${failure2}`);
|
|
96601
94907
|
try {
|
|
96602
94908
|
const observe = options.observeBranch ? options.observeBranch() : branchObserver({ allowedProtectedRoots: credentials.repoDiscoveryRoots ?? [] });
|
|
96603
94909
|
const facts = branchFactsOf(writable, observe);
|
|
@@ -96623,7 +94929,8 @@ async function runSyncPassInternal(config2, options, diagnostic, turn) {
|
|
|
96623
94929
|
options.rawShipped,
|
|
96624
94930
|
{
|
|
96625
94931
|
beforeUpload: options.beforeRawUpload ? () => options.beforeRawUpload(collected) : void 0,
|
|
96626
|
-
onUploaded: options.onRawUploaded
|
|
94932
|
+
onUploaded: options.onRawUploaded,
|
|
94933
|
+
failures: options.rawUploadFailures
|
|
96627
94934
|
}
|
|
96628
94935
|
);
|
|
96629
94936
|
const givenUp = options.codexThreadLinks?.settleRecoveries((session) => {
|
|
@@ -96670,7 +94977,9 @@ async function runSyncPassInternal(config2, options, diagnostic, turn) {
|
|
|
96670
94977
|
}
|
|
96671
94978
|
const nothingElseAccountedFor = raw.skippedUnchanged === 0 && raw.skippedTooLarge === 0 && rawWindowSkipped === 0 && raw.missingMetadata === 0 && raw.changedSinceRead === 0;
|
|
96672
94979
|
if (raw.uploaded === 0 && (raw.failed.length > 1 || raw.failed.length === 1 && nothingElseAccountedFor)) {
|
|
96673
|
-
throw new Error(`all ${raw.failed.length} raw upload(s) failed this pass, ${raw.failed[0]}
|
|
94980
|
+
throw new Error(`all ${raw.failed.length} raw upload(s) failed this pass, ${raw.failed[0]}`, {
|
|
94981
|
+
cause: raw.firstFailure
|
|
94982
|
+
});
|
|
96674
94983
|
}
|
|
96675
94984
|
if (deferred > 0 || claimsUnresolved) {
|
|
96676
94985
|
if (window2.deepSweep) {
|
|
@@ -97168,7 +95477,6 @@ var NARROW_OVERLAP_MS = 6e4;
|
|
|
97168
95477
|
var WATCHER_RETRY_MS = 6e4;
|
|
97169
95478
|
var FAILED_PASS_RETRY_MS = 6e4;
|
|
97170
95479
|
var FAILED_PASS_BACKOFF_CAP_MS = 15 * 6e4;
|
|
97171
|
-
var STREAK_REREPORT_INTERVAL_MS = 60 * 6e4;
|
|
97172
95480
|
var VERSION_NOTICE_INTERVAL_MS = 60 * 6e4;
|
|
97173
95481
|
var COMPLETION_SLACK_MS = 3e4;
|
|
97174
95482
|
function createWatchLoop(deps) {
|
|
@@ -97524,6 +95832,7 @@ function watchSessionStores(roots, onEvent, onLost) {
|
|
|
97524
95832
|
}
|
|
97525
95833
|
function newSessionSyncOptions(shared, sinceMs, isNew) {
|
|
97526
95834
|
return {
|
|
95835
|
+
rawUploadFailures: shared.rawUploadFailures,
|
|
97527
95836
|
lifecycleJournal: shared.lifecycleJournal,
|
|
97528
95837
|
log: shared.log,
|
|
97529
95838
|
enrollCommand: shared.enrollCommand,
|
|
@@ -97703,19 +96012,24 @@ function startWatch(config2, homeDir, runtime = { version: "checkout" }) {
|
|
|
97703
96012
|
onChecked: () => menu?.changed()
|
|
97704
96013
|
});
|
|
97705
96014
|
const rawShipped = /* @__PURE__ */ new Map();
|
|
97706
|
-
const
|
|
96015
|
+
const rawUploadFailures = createRawUploadFailures(
|
|
96016
|
+
(error63, context2) => reportCollectorError(error63, "stuck-transcript-upload", context2)
|
|
96017
|
+
);
|
|
97707
96018
|
const codexThreadLinks = new CodexThreadLinks();
|
|
97708
96019
|
const codexThreadReads = new CodexThreadReads();
|
|
97709
96020
|
const recordTurns = new RecordTurns();
|
|
96021
|
+
const catchUpFailures = failureStreak(
|
|
96022
|
+
(error63, context2) => reportCollectorError(error63, "recent-session-catchup", context2)
|
|
96023
|
+
);
|
|
97710
96024
|
const loop = createWatchLoop({
|
|
97711
96025
|
runPass: async (options) => {
|
|
97712
96026
|
let uploaded = 0;
|
|
97713
96027
|
let activeSinceMs = Infinity;
|
|
97714
96028
|
const activeSessions = /* @__PURE__ */ new Set();
|
|
97715
|
-
let
|
|
96029
|
+
let catchUpFailedThisPass = false;
|
|
97716
96030
|
const shared = {
|
|
97717
96031
|
rawShipped,
|
|
97718
|
-
|
|
96032
|
+
rawUploadFailures,
|
|
97719
96033
|
codexThreadLinks,
|
|
97720
96034
|
codexThreadReads,
|
|
97721
96035
|
lifecycleJournal: journal,
|
|
@@ -97738,6 +96052,7 @@ function startWatch(config2, homeDir, runtime = { version: "checkout" }) {
|
|
|
97738
96052
|
Math.min(narrowSinceMs, activeSinceMs),
|
|
97739
96053
|
{ sinceMs: narrowSinceMs, sessions: activeSessions }
|
|
97740
96054
|
));
|
|
96055
|
+
catchUpFailures.succeeded();
|
|
97741
96056
|
activeSinceMs = recentCatchupFloor(activeSinceMs, recent.sessions);
|
|
97742
96057
|
for (const session of recent.sessions) {
|
|
97743
96058
|
if (session.item.status === "active") activeSessions.add(sessionKey(session.item));
|
|
@@ -97757,10 +96072,8 @@ function startWatch(config2, homeDir, runtime = { version: "checkout" }) {
|
|
|
97757
96072
|
await catchUp();
|
|
97758
96073
|
} catch (error63) {
|
|
97759
96074
|
log3(`Recent session catch-up failed, history continues: ${describeError(error63)}`);
|
|
97760
|
-
if (
|
|
97761
|
-
|
|
97762
|
-
reportCollectorError(error63, "recent-session-catchup");
|
|
97763
|
-
}
|
|
96075
|
+
if (!catchUpFailedThisPass) catchUpFailures.failed(error63);
|
|
96076
|
+
catchUpFailedThisPass = true;
|
|
97764
96077
|
}
|
|
97765
96078
|
return uploaded - beforeCatchup;
|
|
97766
96079
|
}
|
|
@@ -97774,6 +96087,7 @@ function startWatch(config2, homeDir, runtime = { version: "checkout" }) {
|
|
|
97774
96087
|
return summary;
|
|
97775
96088
|
},
|
|
97776
96089
|
runNewSessionPass: ({ sinceMs, isNew }) => runSyncPass(config2, newSessionSyncOptions({
|
|
96090
|
+
rawUploadFailures,
|
|
97777
96091
|
lifecycleJournal: journal,
|
|
97778
96092
|
log: log3,
|
|
97779
96093
|
enrollCommand: runtime.enrollCommand,
|
|
@@ -98506,7 +96820,7 @@ import { accessSync, constants as constants4, readFileSync as readFileSync22 } f
|
|
|
98506
96820
|
import path42 from "node:path";
|
|
98507
96821
|
|
|
98508
96822
|
// src/version.ts
|
|
98509
|
-
var CLI_VERSION = true ? "0.4.
|
|
96823
|
+
var CLI_VERSION = true ? "0.4.28" : "0.0.0-checkout";
|
|
98510
96824
|
var CLI_RELEASE_BUILD = true ? true : false;
|
|
98511
96825
|
var CLI_PACKAGE_NAME = "@usepowerplant/cli";
|
|
98512
96826
|
|
|
@@ -99705,7 +98019,7 @@ function cursorAppVersion(applicationsDirs, seams) {
|
|
|
99705
98019
|
}
|
|
99706
98020
|
return newest?.text ?? null;
|
|
99707
98021
|
}
|
|
99708
|
-
function runConnect(clients, deps) {
|
|
98022
|
+
async function runConnect(clients, deps) {
|
|
99709
98023
|
const agents = groupByAgent(clients);
|
|
99710
98024
|
const outcome = {
|
|
99711
98025
|
found: agents.size,
|
|
@@ -99721,9 +98035,10 @@ function runConnect(clients, deps) {
|
|
|
99721
98035
|
return outcome;
|
|
99722
98036
|
}
|
|
99723
98037
|
for (const [agent, candidates] of agents) {
|
|
99724
|
-
const results = [
|
|
99725
|
-
|
|
99726
|
-
|
|
98038
|
+
const results = [];
|
|
98039
|
+
for (const targetCandidates of groupByConnectionTarget(candidates).values()) {
|
|
98040
|
+
results.push(await connectTarget(agent, targetCandidates, clients, deps));
|
|
98041
|
+
}
|
|
99727
98042
|
const result = aggregateConnectionTargets(results);
|
|
99728
98043
|
outcome[result.state] += 1;
|
|
99729
98044
|
if (result.unchanged) outcome.unchanged += 1;
|
|
@@ -99753,7 +98068,7 @@ function aggregateConnectionTargets(results) {
|
|
|
99753
98068
|
const state = results.some((result) => result.state === "failed") ? "failed" : results.some((result) => result.state === "pending") ? "pending" : results.some((result) => result.state === "configured") ? "configured" : "connected";
|
|
99754
98069
|
return { state, unchanged: results.every((result) => result.unchanged) };
|
|
99755
98070
|
}
|
|
99756
|
-
function connectTarget(agent, candidates, all, deps) {
|
|
98071
|
+
async function connectTarget(agent, candidates, all, deps) {
|
|
99757
98072
|
let last = failed("no installation to try");
|
|
99758
98073
|
for (const [index, candidate] of candidates.entries()) {
|
|
99759
98074
|
const name = displayName(candidate, all);
|
|
@@ -99762,7 +98077,7 @@ function connectTarget(agent, candidates, all, deps) {
|
|
|
99762
98077
|
const tooOld = refusal === null ? belowVersionFloor(candidate.client, deps.agentVersion(candidate)) : null;
|
|
99763
98078
|
last = refusal !== null ? failed(refusal) : tooOld !== null ? failed(
|
|
99764
98079
|
`version ${tooOld.version} is older than ${tooOld.floor}, the oldest ${AGENT_DISPLAY_NAMES[agent]} Powerplant supports. Update it, then re-run ${deps.connectCommand}.`
|
|
99765
|
-
) : connectCandidate(candidate, name, deps);
|
|
98080
|
+
) : await connectCandidate(candidate, name, deps);
|
|
99766
98081
|
} catch (error63) {
|
|
99767
98082
|
last = failed(error63 instanceof Error ? error63.message : String(error63));
|
|
99768
98083
|
}
|
|
@@ -99908,7 +98223,7 @@ function claudeAddArgs(deps) {
|
|
|
99908
98223
|
function claudeEnv(client) {
|
|
99909
98224
|
return { CLAUDE_CONFIG_DIR: client.configDir };
|
|
99910
98225
|
}
|
|
99911
|
-
function connectClaude(client, name, deps) {
|
|
98226
|
+
async function connectClaude(client, name, deps) {
|
|
99912
98227
|
const { bin } = client;
|
|
99913
98228
|
const env = claudeEnv(client);
|
|
99914
98229
|
const probe = parseClaudeProbe(deps.run(bin, ["mcp", "get", deps.serverName], env));
|
|
@@ -100109,7 +98424,7 @@ function connectInCodexHome(install, deps) {
|
|
|
100109
98424
|
runInteractive: (bin, args, overrides) => deps.runInteractive(bin, args, env(overrides))
|
|
100110
98425
|
};
|
|
100111
98426
|
}
|
|
100112
|
-
function connectCodex(install, name, unscoped) {
|
|
98427
|
+
async function connectCodex(install, name, unscoped) {
|
|
100113
98428
|
const { bin } = install;
|
|
100114
98429
|
const deps = connectInCodexHome(install, unscoped);
|
|
100115
98430
|
healOrphanCodexOauthTable(name, deps);
|
|
@@ -100124,7 +98439,7 @@ function connectCodex(install, name, unscoped) {
|
|
|
100124
98439
|
if (wrongUrl) deps.log(`${name} was registered against ${registeredUrl}, re-registering for ${deps.mcpUrl}.`);
|
|
100125
98440
|
if (codexAddLogsIn(bin, deps)) {
|
|
100126
98441
|
ensureCodexCallbackPort(name, deps);
|
|
100127
|
-
const outcome = login(bin, name, codexAddArgs(deps, { withOfficialClientId: true }), deps);
|
|
98442
|
+
const outcome = await login(bin, name, codexAddArgs(deps, { withOfficialClientId: true }), deps);
|
|
100128
98443
|
if (outcome.state === "connected") ensureCodexOfficialClient(name, deps);
|
|
100129
98444
|
return outcome;
|
|
100130
98445
|
}
|
|
@@ -100171,7 +98486,7 @@ function ensureCodexOfficialClient(name, deps) {
|
|
|
100171
98486
|
)
|
|
100172
98487
|
);
|
|
100173
98488
|
}
|
|
100174
|
-
function connectCursor(mcpJsonPath, name, deps) {
|
|
98489
|
+
async function connectCursor(mcpJsonPath, name, deps) {
|
|
100175
98490
|
const official = deps.officialClients?.cursor;
|
|
100176
98491
|
const patch = patchCursorMcpJson(
|
|
100177
98492
|
deps.readTextFile(mcpJsonPath),
|
|
@@ -100185,6 +98500,7 @@ function connectCursor(mcpJsonPath, name, deps) {
|
|
|
100185
98500
|
);
|
|
100186
98501
|
}
|
|
100187
98502
|
if (patch.changed) deps.writeTextFile(mcpJsonPath, patch.content);
|
|
98503
|
+
await deps.pressEnter?.("open Cursor");
|
|
100188
98504
|
if (deps.openUrl(cursorInstallDeeplink(deps.serverName, patch.entry))) {
|
|
100189
98505
|
deps.log(`\u2192 ${name}: approve inside Cursor when it asks`);
|
|
100190
98506
|
return { state: "configured", unchanged: !patch.changed };
|
|
@@ -100194,8 +98510,9 @@ function connectCursor(mcpJsonPath, name, deps) {
|
|
|
100194
98510
|
);
|
|
100195
98511
|
return { state: "pending", unchanged: false };
|
|
100196
98512
|
}
|
|
100197
|
-
function login(bin, name, args, deps, env) {
|
|
100198
|
-
deps.
|
|
98513
|
+
async function login(bin, name, args, deps, env) {
|
|
98514
|
+
if (deps.pressEnter) await deps.pressEnter(`sign in to ${name} in your browser`);
|
|
98515
|
+
else deps.log(`\u2192 ${name}: approve in your browser\u2026`);
|
|
100199
98516
|
const status = deps.runInteractive(bin, args, env);
|
|
100200
98517
|
if (status === 0) {
|
|
100201
98518
|
deps.log(`\u2713 ${name}: MCP connected`);
|
|
@@ -101365,6 +99682,14 @@ function initExitCode(summary) {
|
|
|
101365
99682
|
function enrolledLine(credentials) {
|
|
101366
99683
|
return `\u2713 ${credentials.machineName} enrolled${credentials.orgName ? ` in ${credentials.orgName}` : ""}`;
|
|
101367
99684
|
}
|
|
99685
|
+
async function waitForEnrollment(output2, enroll2) {
|
|
99686
|
+
let startSpinner = () => {
|
|
99687
|
+
};
|
|
99688
|
+
const waiting = new Promise((resolve2) => startSpinner = resolve2);
|
|
99689
|
+
const enrolling = enroll2(startSpinner);
|
|
99690
|
+
await Promise.race([waiting, enrolling]);
|
|
99691
|
+
return output2.activity("Waiting for approval in your browser\u2026", () => enrolling);
|
|
99692
|
+
}
|
|
101368
99693
|
async function runInit(deps) {
|
|
101369
99694
|
if (deps.setupRefusal !== null) throw new ExpectedCliError(deps.setupRefusal);
|
|
101370
99695
|
const { command, stage } = deps.terminal;
|
|
@@ -101381,7 +99706,7 @@ async function runInit(deps) {
|
|
|
101381
99706
|
);
|
|
101382
99707
|
credentials = existing;
|
|
101383
99708
|
} else {
|
|
101384
|
-
credentials = await stage
|
|
99709
|
+
credentials = await waitForEnrollment(stage, deps.enroll);
|
|
101385
99710
|
stage.log(enrolledLine(credentials));
|
|
101386
99711
|
enrolled = true;
|
|
101387
99712
|
}
|
|
@@ -101583,6 +99908,25 @@ function logProtectedSessionsStayLocal(stage, found) {
|
|
|
101583
99908
|
);
|
|
101584
99909
|
stage.detail("Sessions outside folders you explicitly added will stay local.");
|
|
101585
99910
|
}
|
|
99911
|
+
function realPressEnter(question, signal) {
|
|
99912
|
+
return new Promise((resolve2) => {
|
|
99913
|
+
const prompt = createInterface2({ input: process.stdin, output: process.stdout });
|
|
99914
|
+
let interrupted = false;
|
|
99915
|
+
prompt.once("SIGINT", () => {
|
|
99916
|
+
interrupted = true;
|
|
99917
|
+
prompt.close();
|
|
99918
|
+
process.stdout.write("\n");
|
|
99919
|
+
process.kill(process.pid, "SIGINT");
|
|
99920
|
+
});
|
|
99921
|
+
prompt.question(question, signal ? { signal } : {}).then(
|
|
99922
|
+
() => resolve2(true),
|
|
99923
|
+
() => {
|
|
99924
|
+
if (interrupted) return;
|
|
99925
|
+
resolve2(!(signal?.aborted ?? false));
|
|
99926
|
+
}
|
|
99927
|
+
).finally(() => prompt.close());
|
|
99928
|
+
});
|
|
99929
|
+
}
|
|
101586
99930
|
async function realPromptLine(question) {
|
|
101587
99931
|
const prompt = createInterface2({ input: process.stdin, output: process.stdout });
|
|
101588
99932
|
try {
|
|
@@ -101808,12 +100152,12 @@ function mcpBlock(i, connection) {
|
|
|
101808
100152
|
const name = `${AGENT_DISPLAY_NAMES[connection.client]}${connection.target ? ` (${connection.target})` : ""}`;
|
|
101809
100153
|
const fix = `Run ${run(i, `connect --client ${connection.client}`)}.`;
|
|
101810
100154
|
const current = connectionIsCurrent(connection, i.now);
|
|
101811
|
-
const
|
|
100155
|
+
const checked2 = current ? "" : `, checked ${ago(i.now - Date.parse(connection.checkedAt))}`;
|
|
101812
100156
|
switch (connection.state) {
|
|
101813
100157
|
case "signed-in":
|
|
101814
|
-
return block(`${current ? "\u2713 " : ""}${name}: MCP connected${
|
|
100158
|
+
return block(`${current ? "\u2713 " : ""}${name}: MCP connected${checked2}`);
|
|
101815
100159
|
case "sign-in-needed":
|
|
101816
|
-
return block(`! ${name}: MCP sign-in needed${
|
|
100160
|
+
return block(`! ${name}: MCP sign-in needed${checked2}`, fix);
|
|
101817
100161
|
case "different-url":
|
|
101818
100162
|
return block(
|
|
101819
100163
|
`! ${name}: MCP points at a different Powerplant${connection.registeredUrl ? `, ${connection.registeredUrl}` : ""}`,
|
|
@@ -101915,6 +100259,11 @@ async function fetchNewestRelease(packageName, fetchImpl = fetch) {
|
|
|
101915
100259
|
function releaseSource(appEnv) {
|
|
101916
100260
|
return appEnv === "production" ? "promoted" : "npm";
|
|
101917
100261
|
}
|
|
100262
|
+
function fetchVersionFacts(appEnv, credentials, packageName, fetchImpl = fetch) {
|
|
100263
|
+
const policy = credentials === null ? Promise.resolve(null) : fetchVersionPolicy(credentials.apiUrl, credentials.token, fetchImpl);
|
|
100264
|
+
const latest2 = releaseSource(appEnv) === "npm" ? fetchNewestRelease(packageName, fetchImpl) : policy.then((found) => found?.promotedVersion ?? null);
|
|
100265
|
+
return Promise.all([latest2, policy.then((found) => found?.oldestSupportedVersion ?? null)]);
|
|
100266
|
+
}
|
|
101918
100267
|
|
|
101919
100268
|
// src/terminal.ts
|
|
101920
100269
|
var ANSI = {
|
|
@@ -101960,6 +100309,13 @@ function styleUrls(line) {
|
|
|
101960
100309
|
function styleCommands(line) {
|
|
101961
100310
|
return line.replace(/`([^`]+)`/g, (_, command) => `${ANSI.bold}${command}${ANSI.resetDim}`);
|
|
101962
100311
|
}
|
|
100312
|
+
function ignoreClosedOutput(streams) {
|
|
100313
|
+
for (const stream of streams) {
|
|
100314
|
+
stream.on("error", (error63) => {
|
|
100315
|
+
if (error63.code !== "EPIPE") throw error63;
|
|
100316
|
+
});
|
|
100317
|
+
}
|
|
100318
|
+
}
|
|
101963
100319
|
function dim(line) {
|
|
101964
100320
|
return `${ANSI.dim}${line}${ANSI.resetDim}`;
|
|
101965
100321
|
}
|
|
@@ -101986,7 +100342,6 @@ function createTerminalOutput(options) {
|
|
|
101986
100342
|
let activityLabel = null;
|
|
101987
100343
|
let activityIndent = "";
|
|
101988
100344
|
let frameIndex = 0;
|
|
101989
|
-
let timer = null;
|
|
101990
100345
|
const renderActivity = () => {
|
|
101991
100346
|
if (activityLabel === null) return;
|
|
101992
100347
|
const frame = SPINNER_FRAMES[frameIndex % SPINNER_FRAMES.length];
|
|
@@ -102004,25 +100359,31 @@ function createTerminalOutput(options) {
|
|
|
102004
100359
|
`);
|
|
102005
100360
|
if (rerender) renderActivity();
|
|
102006
100361
|
};
|
|
102007
|
-
const
|
|
100362
|
+
const startActivity = (place, label2) => {
|
|
102008
100363
|
const indent = " ".repeat(COLUMNS[place.level].line);
|
|
102009
100364
|
if (!interactive) {
|
|
102010
100365
|
log3(`${indent}\u2026 ${label2}`, place);
|
|
102011
|
-
return
|
|
100366
|
+
return () => {
|
|
100367
|
+
};
|
|
102012
100368
|
}
|
|
102013
100369
|
activityLabel = label2;
|
|
102014
100370
|
activityIndent = indent;
|
|
102015
100371
|
frameIndex = 0;
|
|
102016
100372
|
renderActivity();
|
|
102017
|
-
timer = setInterval(renderActivity, 80);
|
|
100373
|
+
const timer = setInterval(renderActivity, 80);
|
|
102018
100374
|
timer.unref();
|
|
100375
|
+
return () => {
|
|
100376
|
+
clearInterval(timer);
|
|
100377
|
+
clearActivity();
|
|
100378
|
+
activityLabel = null;
|
|
100379
|
+
};
|
|
100380
|
+
};
|
|
100381
|
+
const activity = async (place, label2, work) => {
|
|
100382
|
+
const stop = startActivity(place, label2);
|
|
102019
100383
|
try {
|
|
102020
100384
|
return await work();
|
|
102021
100385
|
} finally {
|
|
102022
|
-
|
|
102023
|
-
timer = null;
|
|
102024
|
-
clearActivity();
|
|
102025
|
-
activityLabel = null;
|
|
100386
|
+
stop();
|
|
102026
100387
|
}
|
|
102027
100388
|
};
|
|
102028
100389
|
const writer = (level) => {
|
|
@@ -102036,7 +100397,9 @@ function createTerminalOutput(options) {
|
|
|
102036
100397
|
// A blank line separates stages; it carries no indentation.
|
|
102037
100398
|
log: (text) => log3(text === "" ? "" : `${indent}${text}`, line),
|
|
102038
100399
|
detail: (text) => log3(`${detailIndent}${text}`, detail),
|
|
102039
|
-
activity: (label2, work) => activity(line, label2, work)
|
|
100400
|
+
activity: (label2, work) => activity(line, label2, work),
|
|
100401
|
+
startActivity: (label2) => startActivity(line, label2),
|
|
100402
|
+
pressEnterPrompt: (action) => color ? `${indent}${ANSI.bold}Press Enter${ANSI.resetDim} to ${styleUrls(action)}\u2026 ` : `${indent}Press Enter to ${action}\u2026 `
|
|
102040
100403
|
};
|
|
102041
100404
|
};
|
|
102042
100405
|
return { command: writer("command"), stage: writer("stage") };
|
|
@@ -102124,7 +100487,8 @@ async function runWindowsUpdate(run2) {
|
|
|
102124
100487
|
await handOff(newCopy);
|
|
102125
100488
|
},
|
|
102126
100489
|
pointServiceAt: run2.pointServiceAt,
|
|
102127
|
-
log: run2.log
|
|
100490
|
+
log: run2.log,
|
|
100491
|
+
waiting: run2.waiting
|
|
102128
100492
|
});
|
|
102129
100493
|
try {
|
|
102130
100494
|
write("up-to-date", installed.version, { finishedAt: new Date(run2.now()).toISOString() });
|
|
@@ -102310,7 +100674,7 @@ async function runInstallRelease(appEnv, options, env = process.env, isProcessAl
|
|
|
102310
100674
|
setupRefusal: () => setupRefusal(retry)
|
|
102311
100675
|
});
|
|
102312
100676
|
if (!ownersLock && lock === null) {
|
|
102313
|
-
if (askService !== void 0) return askService({ file: path50.resolve(tarball), sha256: sha2562 });
|
|
100677
|
+
if (askService !== void 0) return { line: `\u2713 ${(await askService({ file: path50.resolve(tarball), sha256: sha2562 })).replace(/\.$/, "")}`, details: [] };
|
|
102314
100678
|
throw new ExpectedCliError("Another Powerplant install or update is running on this computer. Run the installer again after it finishes.");
|
|
102315
100679
|
}
|
|
102316
100680
|
const service = options.update === true ? hostBackgroundService(appEnv) : null;
|
|
@@ -102333,19 +100697,19 @@ async function runInstallRelease(appEnv, options, env = process.env, isProcessAl
|
|
|
102333
100697
|
healthCheck: (command, version2) => checkNewVersionStarts(command, version2, { appEnv }),
|
|
102334
100698
|
pointServiceAt: (command) => service?.pointAt?.({ appEnv, command })
|
|
102335
100699
|
},
|
|
102336
|
-
log: console.log
|
|
100700
|
+
log: console.log,
|
|
100701
|
+
waiting: options.waiting
|
|
102337
100702
|
});
|
|
102338
|
-
|
|
102339
|
-
The current folder could not be pointed at it (${installed.currentError}). Run the installer again.`;
|
|
102340
|
-
if (typeof installed.path === "object") {
|
|
102341
|
-
return `Installed Powerplant ${installed.version}.${current}
|
|
102342
|
-
${installed.path.failed} To run Powerplant, use "${installed.command[0]}".`;
|
|
102343
|
-
}
|
|
102344
|
-
return `Installed Powerplant ${installed.version}.${current}`;
|
|
100703
|
+
return installedResult(installed, windowsInstallCommand(appEnv));
|
|
102345
100704
|
} finally {
|
|
102346
100705
|
lock?.release();
|
|
102347
100706
|
}
|
|
102348
100707
|
}
|
|
100708
|
+
function installedResult(installed, installCommand) {
|
|
100709
|
+
const pathFailed = typeof installed.path === "object" ? installed.path.failed : null;
|
|
100710
|
+
const details = installed.currentError !== void 0 ? [`The current folder could not be pointed at it (${installed.currentError}). Run \`${installCommand}\` again.`, ...pathFailed === null ? [] : [pathFailed]] : pathFailed === null ? [] : [`${pathFailed} To run Powerplant, use \`& "${installed.command[0]}"\`.`];
|
|
100711
|
+
return { line: `${details.length === 0 ? "\u2713" : "!"} Installed Powerplant ${installed.version}`, details };
|
|
100712
|
+
}
|
|
102349
100713
|
function processIsAlive(pid) {
|
|
102350
100714
|
try {
|
|
102351
100715
|
process.kill(pid, 0);
|
|
@@ -102436,7 +100800,8 @@ async function installPerUserCopy(deps, fetched) {
|
|
|
102436
100800
|
run: (program, args) => deps.runNewCopy(program, args, deps.log),
|
|
102437
100801
|
args: ["--env", deps.appEnv]
|
|
102438
100802
|
}),
|
|
102439
|
-
log: deps.log
|
|
100803
|
+
log: deps.log,
|
|
100804
|
+
waiting: deps.waiting
|
|
102440
100805
|
});
|
|
102441
100806
|
if (installed.currentError !== void 0) {
|
|
102442
100807
|
deps.log(`! The current folder could not be pointed at Powerplant ${installed.version} (${installed.currentError}). Hooks and PATH use it, so fix it and run \`${deps.retryCommand}\` again.`);
|
|
@@ -103039,6 +101404,7 @@ function parseCliArgs() {
|
|
|
103039
101404
|
});
|
|
103040
101405
|
}
|
|
103041
101406
|
async function main() {
|
|
101407
|
+
ignoreClosedOutput([process.stdout, process.stderr]);
|
|
103042
101408
|
if (isNpmCopyOnWindows(process.platform, entryPath())) {
|
|
103043
101409
|
const { values: values2 } = parseArgs({ strict: false, allowPositionals: true, options: { env: { type: "string" } } });
|
|
103044
101410
|
const config3 = resolveCliConfig(process.env, typeof values2.env === "string" ? values2.env : void 0);
|
|
@@ -103081,7 +101447,7 @@ ${USAGE}`);
|
|
|
103081
101447
|
}
|
|
103082
101448
|
const dsn = reportingDsn(process.env, config2, CLI_RELEASE_BUILD);
|
|
103083
101449
|
if (dsn !== void 0) process.env.SENTRY_DSN = dsn;
|
|
103084
|
-
initCollectorReporting(config2.appEnv, CLI_VERSION);
|
|
101450
|
+
initCollectorReporting(config2.appEnv, CLI_VERSION, CLI_COMMANDS.has(cliCommand) ? cliCommand : "unknown");
|
|
103085
101451
|
const proxyNotice = installHttpTransport(process.env);
|
|
103086
101452
|
if (proxyNotice !== null) console.error(styledFor(process.stderr)(proxyNotice));
|
|
103087
101453
|
const menuStages = menuStageClock();
|
|
@@ -103134,14 +101500,6 @@ ${USAGE}`);
|
|
|
103134
101500
|
}
|
|
103135
101501
|
}
|
|
103136
101502
|
const withEnv = (cmd) => config2.appEnv === "production" ? cmd : `${cmd} --env ${config2.appEnv}`;
|
|
103137
|
-
const enroll2 = (log3) => runEnrollment(config2, {
|
|
103138
|
-
name: values.name,
|
|
103139
|
-
email: values.email,
|
|
103140
|
-
password: values.password,
|
|
103141
|
-
scope: values.scope,
|
|
103142
|
-
enrollCommand: withEnv("powerplant enroll"),
|
|
103143
|
-
log: log3
|
|
103144
|
-
});
|
|
103145
101503
|
const connectCommand = withEnv("powerplant connect");
|
|
103146
101504
|
const disconnectCommand = withEnv("powerplant disconnect");
|
|
103147
101505
|
const clientFilter = parseClientFilter(values.client);
|
|
@@ -103150,6 +101508,19 @@ ${USAGE}`);
|
|
|
103150
101508
|
stdinIsTty: process.stdin.isTTY === true,
|
|
103151
101509
|
stdoutIsTty: process.stdout.isTTY === true
|
|
103152
101510
|
});
|
|
101511
|
+
const pressEnter = (output2, action, signal) => pickerOn ? realPressEnter(output2.pressEnterPrompt(action), signal) : Promise.resolve(true);
|
|
101512
|
+
const enroll2 = (output2, onWaiting) => runEnrollment(config2, {
|
|
101513
|
+
name: values.name,
|
|
101514
|
+
email: values.email,
|
|
101515
|
+
password: values.password,
|
|
101516
|
+
scope: values.scope,
|
|
101517
|
+
enrollCommand: withEnv("powerplant enroll"),
|
|
101518
|
+
log: output2.detail,
|
|
101519
|
+
...pickerOn && {
|
|
101520
|
+
confirmOpen: (url2, signal) => pressEnter(output2, `open ${url2} in your browser`, signal)
|
|
101521
|
+
},
|
|
101522
|
+
onWaiting
|
|
101523
|
+
});
|
|
103153
101524
|
const pause = realPauseDeps(config2.appEnv, withEnv("powerplant resume"), realPromptLine);
|
|
103154
101525
|
const terminalEffects = terminalUsesEffects(process.stdout.isTTY === true, process.env);
|
|
103155
101526
|
const terminal = createTerminalOutput({
|
|
@@ -103233,6 +101604,7 @@ ${USAGE}`);
|
|
|
103233
101604
|
url2,
|
|
103234
101605
|
(reason) => log3(`! Cursor: could not open Cursor (${reason}), enable the ${mcpServerNameFor(config2.appEnv)} server in Cursor's MCP settings and sign in`)
|
|
103235
101606
|
),
|
|
101607
|
+
pressEnter: pickerOn ? (action) => pressEnter(output2, action) : null,
|
|
103236
101608
|
codexConfigPath: codexConfigPath({}),
|
|
103237
101609
|
verifySignature: verifyBundleSignatureSync
|
|
103238
101610
|
}),
|
|
@@ -103243,7 +101615,7 @@ ${USAGE}`);
|
|
|
103243
101615
|
case "init": {
|
|
103244
101616
|
const setupRefusal = hostBackgroundService(config2.appEnv)?.setupRefusal?.("init") ?? null;
|
|
103245
101617
|
if (isNpmCopyOnWindows(process.platform, entryPath())) {
|
|
103246
|
-
const code = await initFromNpmCopy({ ...npmInitDeps(config2), args: process.argv.slice(2), entryPath: entryPath(), setupRefusal });
|
|
101618
|
+
const code = await initFromNpmCopy({ ...npmInitDeps(config2, terminal.command), args: process.argv.slice(2), entryPath: entryPath(), setupRefusal });
|
|
103247
101619
|
if (code !== null) {
|
|
103248
101620
|
process.exitCode = code;
|
|
103249
101621
|
return;
|
|
@@ -103255,7 +101627,7 @@ ${USAGE}`);
|
|
|
103255
101627
|
// Enrollment's own lines (approval URL, token location) are detail
|
|
103256
101628
|
// lines under stage 1's spinner; init prints the result line, and
|
|
103257
101629
|
// stage 2 states the capture boundary.
|
|
103258
|
-
enroll: () => enroll2(terminal.stage
|
|
101630
|
+
enroll: (onWaiting) => enroll2(terminal.stage, onWaiting),
|
|
103259
101631
|
// Discovery may read a worktree pointer under a root the store
|
|
103260
101632
|
// already allows, so a revoked checkout root still surfaces.
|
|
103261
101633
|
findProtectedSessions: () => findRecentProtectedSessions({
|
|
@@ -103336,9 +101708,9 @@ The access you granted these agents stays on your Powerplant account until you r
|
|
|
103336
101708
|
return;
|
|
103337
101709
|
}
|
|
103338
101710
|
case "enroll": {
|
|
103339
|
-
const credentials = await
|
|
103340
|
-
|
|
103341
|
-
() => enroll2(terminal.command
|
|
101711
|
+
const credentials = await waitForEnrollment(
|
|
101712
|
+
terminal.command,
|
|
101713
|
+
(onWaiting) => enroll2(terminal.command, onWaiting)
|
|
103342
101714
|
);
|
|
103343
101715
|
terminal.command.log(enrolledLine(credentials));
|
|
103344
101716
|
terminal.command.detail(`Syncing: ${describeStoredCapture(credentials)}`);
|
|
@@ -103347,28 +101719,33 @@ The access you granted these agents stays on your Powerplant account until you r
|
|
|
103347
101719
|
return;
|
|
103348
101720
|
}
|
|
103349
101721
|
case "status": {
|
|
103350
|
-
const
|
|
103351
|
-
|
|
103352
|
-
|
|
103353
|
-
|
|
103354
|
-
|
|
103355
|
-
|
|
103356
|
-
|
|
103357
|
-
|
|
103358
|
-
|
|
103359
|
-
|
|
103360
|
-
|
|
101722
|
+
const read = async () => {
|
|
101723
|
+
const service = readServiceSafelyAsync(config2);
|
|
101724
|
+
const stored = loadCredentialsSafely(config2);
|
|
101725
|
+
const credentials = stored.credentials;
|
|
101726
|
+
const [[latestVersion, oldestSupportedVersion], protectedSessions, serviceRead] = await Promise.all([
|
|
101727
|
+
fetchVersionFacts(config2.appEnv, credentials, CLI_PACKAGE_NAME),
|
|
101728
|
+
process.platform === "darwin" && credentials ? findRecentProtectedSessions({
|
|
101729
|
+
environment: { allowedProtectedRoots: credentials.repoDiscoveryRoots ?? [] }
|
|
101730
|
+
}).then(
|
|
101731
|
+
(found2) => found2.filter((entry) => protectedRootReview(credentials, entry.root) !== "allowed")
|
|
101732
|
+
) : [],
|
|
101733
|
+
service
|
|
101734
|
+
]);
|
|
101735
|
+
return { stored, latestVersion, oldestSupportedVersion, protectedSessions, serviceRead };
|
|
101736
|
+
};
|
|
101737
|
+
const found = values.json ? await read() : await terminal.command.activity("Checking sync status\u2026", read);
|
|
103361
101738
|
const inputs = {
|
|
103362
101739
|
config: config2,
|
|
103363
101740
|
cliVersion: CLI_VERSION,
|
|
103364
|
-
...stored,
|
|
103365
|
-
...
|
|
101741
|
+
...found.stored,
|
|
101742
|
+
...found.serviceRead,
|
|
103366
101743
|
...readCredentialStoreSafely(config2),
|
|
103367
101744
|
daemon: describeDaemonState(readCollectorStatus(config2.appEnv)),
|
|
103368
101745
|
control: readCollectorControl(config2.appEnv),
|
|
103369
|
-
latestVersion,
|
|
103370
|
-
oldestSupportedVersion,
|
|
103371
|
-
protectedSessions,
|
|
101746
|
+
latestVersion: found.latestVersion,
|
|
101747
|
+
oldestSupportedVersion: found.oldestSupportedVersion,
|
|
101748
|
+
protectedSessions: found.protectedSessions,
|
|
103372
101749
|
connections: readHarnessConnections(config2.appEnv, realReadTextFile),
|
|
103373
101750
|
...readMcpPreferencesForMenu(config2.appEnv),
|
|
103374
101751
|
now: Date.now()
|
|
@@ -103378,22 +101755,26 @@ The access you granted these agents stays on your Powerplant account until you r
|
|
|
103378
101755
|
return;
|
|
103379
101756
|
}
|
|
103380
101757
|
case "doctor": {
|
|
103381
|
-
const
|
|
103382
|
-
|
|
103383
|
-
|
|
103384
|
-
|
|
103385
|
-
|
|
101758
|
+
const found = await terminal.command.activity("Collecting diagnostics\u2026", async () => {
|
|
101759
|
+
const service = readServiceSafelyAsync(config2);
|
|
101760
|
+
const stored = loadCredentialsSafely(config2);
|
|
101761
|
+
const [[latestVersion, oldestSupportedVersion], serviceRead] = await Promise.all([
|
|
101762
|
+
fetchVersionFacts(config2.appEnv, stored.credentials, CLI_PACKAGE_NAME),
|
|
101763
|
+
service
|
|
101764
|
+
]);
|
|
101765
|
+
return { stored, latestVersion, oldestSupportedVersion, serviceRead };
|
|
101766
|
+
});
|
|
103386
101767
|
console.log(
|
|
103387
101768
|
renderDoctorReport({
|
|
103388
101769
|
config: config2,
|
|
103389
101770
|
cliVersion: CLI_VERSION,
|
|
103390
|
-
latestVersion,
|
|
103391
|
-
oldestSupportedVersion,
|
|
101771
|
+
latestVersion: found.latestVersion,
|
|
101772
|
+
oldestSupportedVersion: found.oldestSupportedVersion,
|
|
103392
101773
|
nodeVersion: process.version,
|
|
103393
101774
|
platform: `${process.platform} ${process.arch}`,
|
|
103394
101775
|
install: inspectThisInstall(config2),
|
|
103395
|
-
...stored,
|
|
103396
|
-
...
|
|
101776
|
+
...found.stored,
|
|
101777
|
+
...found.serviceRead,
|
|
103397
101778
|
...readCredentialStoreSafely(config2),
|
|
103398
101779
|
daemon: describeDaemonState(readCollectorStatus(config2.appEnv)),
|
|
103399
101780
|
control: readCollectorControl(config2.appEnv),
|
|
@@ -103494,13 +101875,13 @@ The access you granted these agents stays on your Powerplant account until you r
|
|
|
103494
101875
|
}
|
|
103495
101876
|
const windowsInstall = thisWindowsInstall(config2);
|
|
103496
101877
|
if (windowsInstall !== null) {
|
|
103497
|
-
await updateWindowsInstall(config2, windowsInstall, values.background === true, tarballOption(values.tarball, values.sha256));
|
|
101878
|
+
await updateWindowsInstall(config2, terminal.command, windowsInstall, values.background === true, tarballOption(values.tarball, values.sha256));
|
|
103498
101879
|
return;
|
|
103499
101880
|
}
|
|
103500
101881
|
if (values.tarball !== void 0) throw new ExpectedCliError("--tarball updates a per-user Windows install only.");
|
|
103501
101882
|
if (isNpmCopyOnWindows(process.platform, entryPath()) && values.background !== true) {
|
|
103502
101883
|
await updateFromNpmCopy({
|
|
103503
|
-
...npmInitDeps(config2),
|
|
101884
|
+
...npmInitDeps(config2, terminal.command),
|
|
103504
101885
|
retryCommand: withEnv("powerplant update"),
|
|
103505
101886
|
setupRefusal: hostBackgroundService(config2.appEnv)?.setupRefusal?.("update") ?? null,
|
|
103506
101887
|
cliVersion: CLI_VERSION,
|
|
@@ -103554,15 +101935,15 @@ The access you granted these agents stays on your Powerplant account until you r
|
|
|
103554
101935
|
if (process.platform !== "win32") {
|
|
103555
101936
|
throw new ExpectedCliError("powerplant install-release installs the Windows release of Powerplant, so it runs only on Windows.");
|
|
103556
101937
|
}
|
|
103557
|
-
|
|
103558
|
-
|
|
103559
|
-
|
|
103560
|
-
|
|
103561
|
-
|
|
103562
|
-
|
|
103563
|
-
(tarball) => updateThroughService(serviceUpdateDeps(config2, tarball), true).then((line) => line ?? "")
|
|
103564
|
-
)
|
|
101938
|
+
const installed = await runInstallRelease(
|
|
101939
|
+
config2.appEnv,
|
|
101940
|
+
{ tarball: values.tarball, sha256: values.sha256, update: values.update, waiting: (label2) => terminal.command.startActivity(label2) },
|
|
101941
|
+
process.env,
|
|
101942
|
+
processIsAlive2,
|
|
101943
|
+
(tarball) => updateThroughService(serviceUpdateDeps(config2, tarball), true).then((line) => line ?? "")
|
|
103565
101944
|
);
|
|
101945
|
+
terminal.command.log(installed.line);
|
|
101946
|
+
for (const detail of installed.details) terminal.command.detail(detail);
|
|
103566
101947
|
return;
|
|
103567
101948
|
}
|
|
103568
101949
|
case "restart": {
|
|
@@ -103702,9 +102083,15 @@ function readServiceSafely(config2) {
|
|
|
103702
102083
|
try {
|
|
103703
102084
|
return { service: serviceState2(config2) };
|
|
103704
102085
|
} catch (error63) {
|
|
103705
|
-
return
|
|
102086
|
+
return unreadService(error63);
|
|
103706
102087
|
}
|
|
103707
102088
|
}
|
|
102089
|
+
function readServiceSafelyAsync(config2) {
|
|
102090
|
+
return serviceStateAsync(config2).then((service) => ({ service }), unreadService);
|
|
102091
|
+
}
|
|
102092
|
+
function unreadService(error63) {
|
|
102093
|
+
return { service: "unavailable", serviceError: error63 instanceof Error ? error63.message : "Could not read background sync status" };
|
|
102094
|
+
}
|
|
103708
102095
|
function readCredentialStoreSafely(config2) {
|
|
103709
102096
|
const migration = describeCredentialMigration(config2.appEnv);
|
|
103710
102097
|
const facts = migration === null ? {} : { credentialMigration: migration };
|
|
@@ -103739,13 +102126,13 @@ function watchCommand(config2) {
|
|
|
103739
102126
|
function thisWindowsInstall(config2) {
|
|
103740
102127
|
return windowsInstallOwning(readInstallRecord(installRecordPath(config2.appEnv)), process.execPath);
|
|
103741
102128
|
}
|
|
103742
|
-
function npmInitDeps(config2) {
|
|
102129
|
+
function npmInitDeps(config2, terminal) {
|
|
103743
102130
|
const localAppData = process.env.LOCALAPPDATA;
|
|
103744
102131
|
if (localAppData === void 0 || localAppData === "") {
|
|
103745
102132
|
throw new ExpectedCliError("LOCALAPPDATA is not set, so Powerplant cannot find your program folder.");
|
|
103746
102133
|
}
|
|
103747
102134
|
return {
|
|
103748
|
-
...windowsUpdateContext(config2,
|
|
102135
|
+
...windowsUpdateContext(config2, terminal),
|
|
103749
102136
|
location: windowsInstallFolder(config2.appEnv, localAppData),
|
|
103750
102137
|
lockFile: installLockPath(config2.appEnv),
|
|
103751
102138
|
// Only production goes on PATH, so a typed `powerplant` is always production.
|
|
@@ -103754,7 +102141,7 @@ function npmInitDeps(config2) {
|
|
|
103754
102141
|
retryCommand: ["powerplant init", ...envArgsFor(config2)].join(" ")
|
|
103755
102142
|
};
|
|
103756
102143
|
}
|
|
103757
|
-
function windowsUpdateContext(config2,
|
|
102144
|
+
function windowsUpdateContext(config2, output2) {
|
|
103758
102145
|
return {
|
|
103759
102146
|
appEnv: config2.appEnv,
|
|
103760
102147
|
apiUrl: config2.apiUrl,
|
|
@@ -103763,7 +102150,8 @@ function windowsUpdateContext(config2, newCopyOutput) {
|
|
|
103763
102150
|
tar: path54.join(process.env.SystemRoot ?? "C:\\Windows", "System32", "tar.exe"),
|
|
103764
102151
|
signedByPowerplant: (file2) => verifyBundleSignatureSync(file2, POWERPLANT_SIGNER),
|
|
103765
102152
|
reportedVersion: programVersion,
|
|
103766
|
-
runNewCopy: startNewCopy(
|
|
102153
|
+
runNewCopy: startNewCopy(output2 === "log" ? "log" : "terminal"),
|
|
102154
|
+
waiting: output2 === "log" ? void 0 : (label2) => output2.startActivity(label2),
|
|
103767
102155
|
progress: updateProgress,
|
|
103768
102156
|
now: Date.now,
|
|
103769
102157
|
pid: process.pid
|
|
@@ -103799,7 +102187,7 @@ function tarballOption(tarball, sha2562) {
|
|
|
103799
102187
|
}
|
|
103800
102188
|
return { file: path54.resolve(tarball), sha256: sha2562 };
|
|
103801
102189
|
}
|
|
103802
|
-
async function updateWindowsInstall(config2, install, background, tarball) {
|
|
102190
|
+
async function updateWindowsInstall(config2, terminal, install, background, tarball) {
|
|
103803
102191
|
const lock = lockInstallForChange(changeLockDeps(config2, install.location));
|
|
103804
102192
|
if (lock === null) {
|
|
103805
102193
|
if (!background) console.log("Background sync is installing the update\u2026");
|
|
@@ -103814,7 +102202,7 @@ async function updateWindowsInstall(config2, install, background, tarball) {
|
|
|
103814
102202
|
}
|
|
103815
102203
|
try {
|
|
103816
102204
|
await runWindowsUpdate({
|
|
103817
|
-
...windowsUpdateContext(config2,
|
|
102205
|
+
...windowsUpdateContext(config2, terminal),
|
|
103818
102206
|
record: install,
|
|
103819
102207
|
target: null,
|
|
103820
102208
|
tarball,
|
|
@@ -103969,6 +102357,29 @@ function entryPath() {
|
|
|
103969
102357
|
}
|
|
103970
102358
|
}
|
|
103971
102359
|
var cliCommand = "none";
|
|
102360
|
+
var CLI_COMMANDS = /* @__PURE__ */ new Set([
|
|
102361
|
+
"init",
|
|
102362
|
+
"connect",
|
|
102363
|
+
"disconnect",
|
|
102364
|
+
"enroll",
|
|
102365
|
+
"status",
|
|
102366
|
+
"doctor",
|
|
102367
|
+
"menu",
|
|
102368
|
+
"report-agent-click",
|
|
102369
|
+
"dismiss-codex-hook-warning",
|
|
102370
|
+
"dismiss-mcp-warning",
|
|
102371
|
+
"workspace",
|
|
102372
|
+
"resume-session",
|
|
102373
|
+
"update",
|
|
102374
|
+
"restart",
|
|
102375
|
+
"pause",
|
|
102376
|
+
"resume",
|
|
102377
|
+
"sync",
|
|
102378
|
+
"folders",
|
|
102379
|
+
"watch",
|
|
102380
|
+
"uninstall",
|
|
102381
|
+
"install-release"
|
|
102382
|
+
]);
|
|
103972
102383
|
var MENU_QUIET_COMMANDS = /* @__PURE__ */ new Set(["menu", "watch", "report-agent-click", "status", "doctor", "none", "help"]);
|
|
103973
102384
|
async function wakeMenus() {
|
|
103974
102385
|
if (MENU_QUIET_COMMANDS.has(cliCommand)) return;
|
|
@@ -104001,4 +102412,4 @@ undici/lib/web/websocket/frame.js:
|
|
|
104001
102412
|
(*! ws. MIT License. Einar Otto Stangvik <einaros@gmail.com> *)
|
|
104002
102413
|
*/
|
|
104003
102414
|
|
|
104004
|
-
//# debugId=
|
|
102415
|
+
//# debugId=d3cdc2c4-688f-5244-bc1d-b1fd4151981c
|