orkestrator 2.36.4-beta → 2.36.5-beta
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/client.js +11962 -10260
- package/dist/main.js +5058 -2903
- package/package.json +3 -3
- package/resources/acp-bridge/dist/index.js +884 -48
- package/resources/claude-bridge/dist/index.js +1177 -183
- package/resources/codex-bridge/dist/index.js +999 -161
- package/resources/cursor-bridge/dist/index.js +876 -40
- package/resources/cursor-bridge/runtime/install.json +1 -1
- package/resources/pi-bridge/dist/index.js +890 -52
- package/resources/pi-bridge/runtime/install.json +1 -1
|
@@ -829,6 +829,8 @@ var LOGGING_LOG_AREAS = defineLogAreas({
|
|
|
829
829
|
},
|
|
830
830
|
"essential.write-failed": "Writing the essential log failed. Its entries are counted, and a marker reports them at the next write that works.",
|
|
831
831
|
"policy.changed": "The logging settings changed: saving, retention and levels, with no content.",
|
|
832
|
+
"policy.detail-expired": "Raised log detail reached its expiry, so the backend set its raised levels back to info. Saving is unchanged.",
|
|
833
|
+
"policy.expiry-failed": "Checking or applying the log detail expiry failed; the next check, a minute later, tries again.",
|
|
832
834
|
"policy.bridge-predates-route": "A running bridge has no logging settings route; it applies them at its next start.",
|
|
833
835
|
"policy.push-failed": "A running bridge did not take the logging settings after retries; its next start resends them.",
|
|
834
836
|
"prune.failed": "Removing expired log files failed; the next sweep retries.",
|
|
@@ -836,6 +838,23 @@ var LOGGING_LOG_AREAS = defineLogAreas({
|
|
|
836
838
|
"unknown-area": "Code outside the type checker asked for an area that is not listed.",
|
|
837
839
|
...THROTTLE_LOG_EVENTS
|
|
838
840
|
}
|
|
841
|
+
},
|
|
842
|
+
"renderer-errors": {
|
|
843
|
+
description: "Renderer failures a desktop window reported from its error ring: class, boundary, surface, count and fingerprint, never a message or stack.",
|
|
844
|
+
events: {
|
|
845
|
+
"error.recorded": {
|
|
846
|
+
description: "A renderer reported `count` new occurrences of one failure since its last report.",
|
|
847
|
+
essential: true,
|
|
848
|
+
fields: {
|
|
849
|
+
errorClass: "label",
|
|
850
|
+
boundary: "label",
|
|
851
|
+
route: "label",
|
|
852
|
+
fingerprint: "label",
|
|
853
|
+
count: "number"
|
|
854
|
+
}
|
|
855
|
+
},
|
|
856
|
+
"report.rate-limited": "Renderer error entries arrived faster than the backend records them, so `dropped` were counted and not written."
|
|
857
|
+
}
|
|
839
858
|
}
|
|
840
859
|
});
|
|
841
860
|
|
|
@@ -893,6 +912,8 @@ var NATIVE_AGENT_LOG_AREAS = defineLogAreas({
|
|
|
893
912
|
"usage-limit.notice-failed": "A usage-limit stop's outcome could not be read for its notice.",
|
|
894
913
|
"usage-limit.resend-failed": "Resending after a usage limit failed. An unknown send stays in the journal.",
|
|
895
914
|
"title.strategy-failed": "A session title strategy failed, so the next is tried. Content-free: the error can quote the prompt.",
|
|
915
|
+
"steer.qualification-failed": "A bridge's steer qualification failed or answered non-OK, so steering is not offered. Agent and status code or error class only.",
|
|
916
|
+
"steer.capability-cleared": "A projection cleared `actions.steer` because its bridge did not qualify. Identifiers and turn status only.",
|
|
896
917
|
...THROTTLE_LOG_EVENTS
|
|
897
918
|
}
|
|
898
919
|
},
|
|
@@ -993,6 +1014,9 @@ var RUNTIME_LOG_AREAS = defineLogAreas({
|
|
|
993
1014
|
essential: true,
|
|
994
1015
|
fields: { origin: "label", ...ESSENTIAL_ERROR_FIELDS }
|
|
995
1016
|
},
|
|
1017
|
+
"child.reaped": "A macOS child whose exit Bun lost was reaped after its command settled, so it no longer waits as a zombie.",
|
|
1018
|
+
"child.reap-abandoned": "A child whose exit Bun lost was left unreaped: `reason` says whether it was never seen as a zombie (`not-a-zombie`), too many were pending (`capacity`), or `waitpid` failed.",
|
|
1019
|
+
"child.reap-unavailable": "waitpid could not be loaded, so children whose exit Bun lost stay zombies until this process exits.",
|
|
996
1020
|
...THROTTLE_LOG_EVENTS
|
|
997
1021
|
}
|
|
998
1022
|
}
|
|
@@ -1399,6 +1423,13 @@ var COORDINATOR_LOG_AREAS = defineLogAreas({
|
|
|
1399
1423
|
"store.workflows-cleared": "The workflow store was full, so a batch of its oldest finished records was removed.",
|
|
1400
1424
|
"store.workflows-in-use": "The workflow store was full and every record was still in use, so new work was refused.",
|
|
1401
1425
|
"remote-worker.settle-failed": "A remote worker could not be settled.",
|
|
1426
|
+
"node-release.failed": "Work on a node that was forgotten or handed over could not be closed; the sweep's registry check retries.",
|
|
1427
|
+
"node-release.reconcile-failed": "The sweep could not check records against the node registry; the next sweep retries.",
|
|
1428
|
+
"node-release.unregistered": "Records named a node the registry no longer holds, so their work was closed here.",
|
|
1429
|
+
"node-release.notice-failed": "The notice for work closed on a released node could not be sent; it stays owed and the sweep retries.",
|
|
1430
|
+
"node-release.no-coordinator": "Work closed on a released node belonged to a coordinator that no longer exists, so nobody was told.",
|
|
1431
|
+
"node-offline.notice-failed": "The notice that a node has been unreachable for a day could not be sent; the next failed read retries.",
|
|
1432
|
+
"node-offline.check-failed": "Whether a long-unreachable node's coordinators were told could not be checked; the next read retries.",
|
|
1402
1433
|
"checkout.merge-followed": "After an environment's PR merged, the project checkout was fast-forwarded, or `outcome` says why not.",
|
|
1403
1434
|
"checkout.merge-follow-failed": "Fast-forwarding the project checkout failed, after an environment's PR merged or before mail woke the main coordinator.",
|
|
1404
1435
|
"checkout.mail-follow": "Before mail woke the main coordinator, the project checkout was fast-forwarded (`fast-forwarded-fetched` when the fetch was slow or failed and the upstream commit already fetched was merged), or `outcome` says why not (`timed-out`, `failed`).",
|
|
@@ -1495,6 +1526,7 @@ var DOCKER_LOG_AREAS = defineLogAreas({
|
|
|
1495
1526
|
events: {
|
|
1496
1527
|
"portable-inputs.relay-missing": "Docker is rootless and the image predates the staged-input relay, so the container cannot read them until rebuilt.",
|
|
1497
1528
|
"git-mirror.mount-unavailable": "A new container gets no project Git mirror, so its clone goes to the remote.",
|
|
1529
|
+
"git-mirror.mount-withheld": "A new restricted container gets no project Git mirror because its firewall would not let it reach the project's remote, so it cannot read what the remote serves through the mirror either.",
|
|
1498
1530
|
"git-mirror.refreshed": "A project's Git mirror was built or updated.",
|
|
1499
1531
|
"git-mirror.seeded": "A project's Git mirror was built from its host checkout and only what the remote added to it.",
|
|
1500
1532
|
"git-mirror.seed-skipped": "A project's host checkout could not seed its Git mirror, so the build downloads everything.",
|
|
@@ -1671,6 +1703,7 @@ var NODES_LOG_AREAS = defineLogAreas({
|
|
|
1671
1703
|
"verification.record-failed": "A node verification could not be recorded.",
|
|
1672
1704
|
"profile.record-failed": "A node profile could not be recorded.",
|
|
1673
1705
|
"detach.unconfirmed": "A forgotten node has not confirmed the detach yet.",
|
|
1706
|
+
"grant.revocation-listener-failed": "A connection could not be told its client grant was removed; the grant is still gone.",
|
|
1674
1707
|
"handover.recovery-pending": "Command handover recovery is still pending.",
|
|
1675
1708
|
"ticket-sync.work-record-failed": "A remote build started but its ticket work location could not be saved.",
|
|
1676
1709
|
"ticket-sync.failed": "A Kanban sync with a node failed; it is retried.",
|
|
@@ -1723,7 +1756,9 @@ var HOST_LOG_AREAS = defineLogAreas({
|
|
|
1723
1756
|
"tool.missing": "A host tool was not found.",
|
|
1724
1757
|
"maintenance.listener-failed": "A host maintenance listener threw; the others still run.",
|
|
1725
1758
|
"suspend.reconcile-failed": "Reconciling due work after a host suspension failed.",
|
|
1726
|
-
"load.sample-failed": "Sampling machine load failed; the next sample retries."
|
|
1759
|
+
"load.sample-failed": "Sampling machine load failed; the next sample retries.",
|
|
1760
|
+
"usage.source-stalled": "A usage source (scope: disk or gpu-sysfs) did not answer in time; its figure is missing from the sample until it does.",
|
|
1761
|
+
...THROTTLE_LOG_EVENTS
|
|
1727
1762
|
}
|
|
1728
1763
|
}
|
|
1729
1764
|
});
|
|
@@ -36348,7 +36383,7 @@ var STRUCTURED_OUTPUT_FAILURE_CODES = new Set([
|
|
|
36348
36383
|
]);
|
|
36349
36384
|
|
|
36350
36385
|
// ../../bridges/cursor-bridge/src/prompt.ts
|
|
36351
|
-
import { randomUUID as
|
|
36386
|
+
import { randomUUID as randomUUID4 } from "node:crypto";
|
|
36352
36387
|
|
|
36353
36388
|
// ../../bridges/cursor-bridge/src/command-changes.ts
|
|
36354
36389
|
import { resolve as resolve5 } from "node:path";
|
|
@@ -36378,12 +36413,823 @@ function isFileEditToolName(toolName) {
|
|
|
36378
36413
|
}
|
|
36379
36414
|
|
|
36380
36415
|
// ../protocol/src/node/workspace-change-probe.ts
|
|
36381
|
-
import {
|
|
36382
|
-
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
36416
|
+
import { randomUUID as randomUUID3 } from "node:crypto";
|
|
36383
36417
|
import { rmSync } from "node:fs";
|
|
36384
36418
|
import { copyFile, lstat, mkdtemp, rm as rm2 } from "node:fs/promises";
|
|
36385
36419
|
import { tmpdir } from "node:os";
|
|
36386
36420
|
import { delimiter, isAbsolute as isAbsolute4, join as join8, resolve as resolve4 } from "node:path";
|
|
36421
|
+
|
|
36422
|
+
// ../protocol/src/node/command-capture.ts
|
|
36423
|
+
import { spawn } from "node:child_process";
|
|
36424
|
+
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
36425
|
+
import { constants as fsConstants } from "node:fs";
|
|
36426
|
+
import * as captureFs from "node:fs";
|
|
36427
|
+
import os from "node:os";
|
|
36428
|
+
import path from "node:path";
|
|
36429
|
+
import { inspect } from "node:util";
|
|
36430
|
+
|
|
36431
|
+
// ../protocol/src/node/command-failure-reason.ts
|
|
36432
|
+
var MAX_MATCHED_CHARS = 16 * 1024;
|
|
36433
|
+
var SIGNAL_PATTERN = /^SIG[A-Z0-9]{1,16}$/;
|
|
36434
|
+
var TOOL_RULES = {
|
|
36435
|
+
git: [
|
|
36436
|
+
["branch-exists", /a branch named .* already exists/i],
|
|
36437
|
+
["ref-conflict", /exists; cannot create|cannot lock ref .* is at .* but expected/i],
|
|
36438
|
+
["lock-held", /could not lock config file [^\n]*: File exists/i],
|
|
36439
|
+
["lock-held", /(?:unable to create '[^\n]*\.lock'|cannot lock ref)[^\n]*: File exists/i],
|
|
36440
|
+
["lock-held", /another git process/i],
|
|
36441
|
+
["worktree-conflict", /already (?:checked out|used by worktree)|used by worktree at/i],
|
|
36442
|
+
["invalid-ref", /not a valid (?:branch name|object name)|bad (?:revision|object)/i],
|
|
36443
|
+
["invalid-ref", /unknown revision|ambiguous argument|invalid reference/i],
|
|
36444
|
+
["branch-not-found", /no branch named|refname .* not found|branch '.*' not found/i],
|
|
36445
|
+
["branch-not-found", /did not match any file\(s\) known to git/i],
|
|
36446
|
+
["dubious-ownership", /detected dubious ownership/i],
|
|
36447
|
+
["no-remote", /does not appear to be a git repository|no such remote/i],
|
|
36448
|
+
["no-remote", /repository (?:.* )?not found/i],
|
|
36449
|
+
["not-a-repository", /not a git repository/i],
|
|
36450
|
+
["remote-ref-missing", /could(?:n't| not) find remote ref|not our ref/i],
|
|
36451
|
+
["merge-conflict", /\bCONFLICT \(|merge conflict|could not apply|unmerged files/i],
|
|
36452
|
+
["dirty-worktree", /local changes .* would be overwritten|commit your changes or stash/i],
|
|
36453
|
+
["nothing-to-commit", /nothing to commit|no changes added to commit/i],
|
|
36454
|
+
["push-rejected", /\[(?:remote )?rejected\]|non-fast-forward/i],
|
|
36455
|
+
["identity-unknown", /please tell me who you are|unable to auto-detect email/i],
|
|
36456
|
+
[
|
|
36457
|
+
"worktree-has-changes",
|
|
36458
|
+
/^fatal: [^\n]*['"] contains modified or untracked files(?:, use --force to delete it)?\.?\s*$/im
|
|
36459
|
+
],
|
|
36460
|
+
["not-a-worktree", /^fatal: [^\n]*['"] is not a working tree\.?\s*$/im],
|
|
36461
|
+
["branch-not-merged", /^(?:error|fatal): [^\n]*['"] is not fully merged\.?\s*$/im]
|
|
36462
|
+
],
|
|
36463
|
+
gh: [
|
|
36464
|
+
["pull-request-exists", /a pull request for branch .* already exists/i],
|
|
36465
|
+
["no-pull-request", /no (?:pull requests? (?:found|match)|open pull requests?\b)/i],
|
|
36466
|
+
["rate-limited", /rate limit|http 429/i],
|
|
36467
|
+
["forbidden", /http 403|resource not accessible/i],
|
|
36468
|
+
["resource-not-found", /http 404|could not resolve to a/i],
|
|
36469
|
+
["server-error", /http 5\d\d/i]
|
|
36470
|
+
],
|
|
36471
|
+
docker: [
|
|
36472
|
+
["daemon-unavailable", /cannot connect to the docker daemon|error during connect/i],
|
|
36473
|
+
[
|
|
36474
|
+
"daemon-unavailable",
|
|
36475
|
+
/is the docker daemon running|docker desktop is (?:not running|unable)/i
|
|
36476
|
+
],
|
|
36477
|
+
["container-not-found", /no such container/i],
|
|
36478
|
+
["container-not-running", /container .* is (?:not running|paused|restarting)/i],
|
|
36479
|
+
["container-name-conflict", /name .* is already in use/i],
|
|
36480
|
+
["image-not-found", /no such image|pull access denied|manifest .* not found/i],
|
|
36481
|
+
["image-not-found", /manifest unknown|repository does not exist/i],
|
|
36482
|
+
["removal-in-progress", /removal of container .* is already in progress/i],
|
|
36483
|
+
[
|
|
36484
|
+
"image-in-use",
|
|
36485
|
+
/image is (?:being used|referenced)|unable to (?:remove|delete) .*must be forced/i
|
|
36486
|
+
],
|
|
36487
|
+
["volume-in-use", /volume is in use/i],
|
|
36488
|
+
["volume-not-found", /no such volume/i],
|
|
36489
|
+
["network-in-use", /has active endpoints/i],
|
|
36490
|
+
["network-not-found", /network .* not found/i]
|
|
36491
|
+
],
|
|
36492
|
+
tmux: [
|
|
36493
|
+
["session-exists", /duplicate session/i],
|
|
36494
|
+
[
|
|
36495
|
+
"server-not-running",
|
|
36496
|
+
/no server running|failed to connect to server|no sessions|server exited|lost server/i
|
|
36497
|
+
],
|
|
36498
|
+
[
|
|
36499
|
+
"server-not-running",
|
|
36500
|
+
/error connecting to \/[^\n]* \((?:No such file or directory|Connection refused)\)/i
|
|
36501
|
+
],
|
|
36502
|
+
["session-not-found", /can't find (?:session|window|pane)|session not found/i]
|
|
36503
|
+
]
|
|
36504
|
+
};
|
|
36505
|
+
var ALL_TOOLS = Object.keys(TOOL_RULES);
|
|
36506
|
+
var SHARED_RULES = [
|
|
36507
|
+
["disk-full", /no space left|enospc|disk quota exceeded/i],
|
|
36508
|
+
["auth-failed", /authentication (?:failed|required)|could not read (?:username|password)/i],
|
|
36509
|
+
["auth-failed", /terminal prompts disabled|invalid username or password|bad credentials/i],
|
|
36510
|
+
["auth-failed", /permission denied \(|permission to \S+ denied|host key verification failed/i],
|
|
36511
|
+
["auth-failed", /gh auth login|not logged in|unauthorized|http 401|returned error: 40[13]/i],
|
|
36512
|
+
["network-failed", /could not resolve host|connection (?:timed out|refused|reset)/i],
|
|
36513
|
+
["network-failed", /network is unreachable|no route to host|temporary failure in name/i],
|
|
36514
|
+
["network-failed", /early eof|failed to connect|remote end hung up/i],
|
|
36515
|
+
["network-failed", /unable to access ['"]?https?:\/\//i],
|
|
36516
|
+
["network-failed", /tls handshake|i\/o timeout/i],
|
|
36517
|
+
[
|
|
36518
|
+
"network-failed",
|
|
36519
|
+
/error connecting to (?:https?:\/\/)?[a-z0-9](?:[a-z0-9.-]*[a-z0-9])?(?::\d+)?(?:[\s/:]|$)/i
|
|
36520
|
+
],
|
|
36521
|
+
["port-in-use", /port is already allocated|address already in use/i],
|
|
36522
|
+
["permission-denied", /permission denied|operation not permitted|read-only file system/i],
|
|
36523
|
+
["command-not-found", /command not found/i],
|
|
36524
|
+
["path-not-found", /no such file or directory/i],
|
|
36525
|
+
["invalid-usage", /^usage: |unknown (?:option|flag|command|shorthand flag)|invalid option/im]
|
|
36526
|
+
];
|
|
36527
|
+
var TOOL_EXIT_CODES = {
|
|
36528
|
+
git: { 129: "invalid-usage" },
|
|
36529
|
+
gh: { 2: "aborted", 4: "auth-failed" },
|
|
36530
|
+
docker: { 125: "daemon-error" },
|
|
36531
|
+
tmux: {}
|
|
36532
|
+
};
|
|
36533
|
+
var SHARED_EXIT_CODES = {
|
|
36534
|
+
124: "timed-out",
|
|
36535
|
+
126: "not-executable",
|
|
36536
|
+
127: "command-not-found",
|
|
36537
|
+
137: "killed",
|
|
36538
|
+
143: "killed"
|
|
36539
|
+
};
|
|
36540
|
+
function read2(target, key) {
|
|
36541
|
+
return target[key];
|
|
36542
|
+
}
|
|
36543
|
+
function boundedForMatching(text) {
|
|
36544
|
+
if (text.length <= MAX_MATCHED_CHARS)
|
|
36545
|
+
return text;
|
|
36546
|
+
const half = MAX_MATCHED_CHARS / 2;
|
|
36547
|
+
return `${text.slice(0, half)}
|
|
36548
|
+
${text.slice(-half)}`;
|
|
36549
|
+
}
|
|
36550
|
+
function failureText(error) {
|
|
36551
|
+
const stderr = read2(error, "stderr");
|
|
36552
|
+
if (Buffer.isBuffer(stderr) && stderr.length > 0) {
|
|
36553
|
+
return boundedForMatching(stderr.subarray(-MAX_MATCHED_CHARS).toString());
|
|
36554
|
+
}
|
|
36555
|
+
if (typeof stderr === "string" && stderr.length > 0)
|
|
36556
|
+
return boundedForMatching(stderr);
|
|
36557
|
+
const message = read2(error, "message");
|
|
36558
|
+
if (typeof message !== "string")
|
|
36559
|
+
return "";
|
|
36560
|
+
return message.startsWith("Command failed") ? "" : boundedForMatching(message);
|
|
36561
|
+
}
|
|
36562
|
+
function isRawSpawnEnoent(error) {
|
|
36563
|
+
const syscall = read2(error, "syscall");
|
|
36564
|
+
return read2(error, "code") === "ENOENT" && typeof syscall === "string" && /^(?:spawn(?:Sync)?(?:\s|$)|posix_spawnp?$)/.test(syscall);
|
|
36565
|
+
}
|
|
36566
|
+
function classifiedReason(error, exitCode, signal, options) {
|
|
36567
|
+
if (read2(error, "aborted") === true)
|
|
36568
|
+
return "aborted";
|
|
36569
|
+
if (read2(error, "outputLimitExceeded") === true)
|
|
36570
|
+
return "output-too-large";
|
|
36571
|
+
if (read2(error, "timedOut") === true)
|
|
36572
|
+
return "timed-out";
|
|
36573
|
+
if (read2(error, "executableMissing") === true || isRawSpawnEnoent(error)) {
|
|
36574
|
+
return "executable-missing";
|
|
36575
|
+
}
|
|
36576
|
+
const named = exitCode === null ? undefined : options.exitCodes?.[exitCode];
|
|
36577
|
+
if (named)
|
|
36578
|
+
return named;
|
|
36579
|
+
if (signal)
|
|
36580
|
+
return "killed";
|
|
36581
|
+
const text = failureText(error);
|
|
36582
|
+
for (const tool of options.tools ?? ALL_TOOLS) {
|
|
36583
|
+
for (const [reason, pattern] of TOOL_RULES[tool]) {
|
|
36584
|
+
if (pattern.test(text))
|
|
36585
|
+
return reason;
|
|
36586
|
+
}
|
|
36587
|
+
}
|
|
36588
|
+
for (const [reason, pattern] of SHARED_RULES) {
|
|
36589
|
+
if (pattern.test(text))
|
|
36590
|
+
return reason;
|
|
36591
|
+
}
|
|
36592
|
+
if (exitCode !== null) {
|
|
36593
|
+
for (const tool of options.tools ?? []) {
|
|
36594
|
+
const reason = TOOL_EXIT_CODES[tool][exitCode];
|
|
36595
|
+
if (reason)
|
|
36596
|
+
return reason;
|
|
36597
|
+
}
|
|
36598
|
+
const reason = SHARED_EXIT_CODES[exitCode];
|
|
36599
|
+
if (reason)
|
|
36600
|
+
return reason;
|
|
36601
|
+
}
|
|
36602
|
+
return "unclassified";
|
|
36603
|
+
}
|
|
36604
|
+
function numericExitCode(error) {
|
|
36605
|
+
for (const key of ["exitCode", "code"]) {
|
|
36606
|
+
const value = read2(error, key);
|
|
36607
|
+
if (typeof value === "number" && Number.isFinite(value))
|
|
36608
|
+
return value;
|
|
36609
|
+
}
|
|
36610
|
+
return null;
|
|
36611
|
+
}
|
|
36612
|
+
function classifyCommandFailure(error, options = {}) {
|
|
36613
|
+
if (typeof error !== "object" || error === null) {
|
|
36614
|
+
return { reason: "unclassified", exitCode: null, signal: null };
|
|
36615
|
+
}
|
|
36616
|
+
try {
|
|
36617
|
+
const exitCode = numericExitCode(error);
|
|
36618
|
+
const rawSignal = read2(error, "signal");
|
|
36619
|
+
const signal = typeof rawSignal === "string" && SIGNAL_PATTERN.test(rawSignal) ? rawSignal : null;
|
|
36620
|
+
return { reason: classifiedReason(error, exitCode, signal, options), exitCode, signal };
|
|
36621
|
+
} catch {
|
|
36622
|
+
return { reason: "unclassified", exitCode: null, signal: null };
|
|
36623
|
+
}
|
|
36624
|
+
}
|
|
36625
|
+
|
|
36626
|
+
// ../protocol/src/node/lost-exit-reaper.ts
|
|
36627
|
+
import { createRequire as createRequire2 } from "node:module";
|
|
36628
|
+
|
|
36629
|
+
// ../protocol/src/node/shell-process-state.ts
|
|
36630
|
+
import { readdirSync as readdirSync3, readFileSync as readFileSync3 } from "node:fs";
|
|
36631
|
+
import { constants as osConstants } from "node:os";
|
|
36632
|
+
var PROCESS_INSPECTION_OPTIONS = {
|
|
36633
|
+
timeout: 100,
|
|
36634
|
+
killSignal: "SIGKILL",
|
|
36635
|
+
maxBuffer: 1024 * 1024
|
|
36636
|
+
};
|
|
36637
|
+
function bunRuntime() {
|
|
36638
|
+
return globalThis.Bun;
|
|
36639
|
+
}
|
|
36640
|
+
function decodeWaitStatus(status) {
|
|
36641
|
+
const signalNumber = status & 127;
|
|
36642
|
+
if (signalNumber === 0)
|
|
36643
|
+
return { code: status >> 8 & 255, signal: null };
|
|
36644
|
+
const name = Object.entries(osConstants.signals).find(([, value]) => value === signalNumber)?.[0];
|
|
36645
|
+
return { code: null, signal: name ?? "SIGKILL" };
|
|
36646
|
+
}
|
|
36647
|
+
function readZombieExit(pid) {
|
|
36648
|
+
try {
|
|
36649
|
+
const result = bunRuntime()?.spawnSync(["/bin/ps", "-o", "stat=,xstat=", "-p", String(pid)], PROCESS_INSPECTION_OPTIONS);
|
|
36650
|
+
if (!result?.success)
|
|
36651
|
+
return;
|
|
36652
|
+
const { stdout } = result;
|
|
36653
|
+
const match = /^Z\S*\s+([0-9a-f]+)\s*$/i.exec(stdout.toString().trim());
|
|
36654
|
+
return match ? decodeWaitStatus(Number.parseInt(match[1], 16)) : undefined;
|
|
36655
|
+
} catch {
|
|
36656
|
+
return;
|
|
36657
|
+
}
|
|
36658
|
+
}
|
|
36659
|
+
var EXIT_WATCH_MS = 1000;
|
|
36660
|
+
var EXIT_WATCH_MAX_MS = 16000;
|
|
36661
|
+
function watchForLostExit(pid, onExit) {
|
|
36662
|
+
if (process.platform !== "darwin" || pid === undefined || !bunRuntime())
|
|
36663
|
+
return () => {
|
|
36664
|
+
return;
|
|
36665
|
+
};
|
|
36666
|
+
let timer;
|
|
36667
|
+
const watch = (delayMs) => {
|
|
36668
|
+
timer = setTimeout(() => {
|
|
36669
|
+
const exit = readZombieExit(pid);
|
|
36670
|
+
if (exit)
|
|
36671
|
+
onExit(exit);
|
|
36672
|
+
else
|
|
36673
|
+
watch(Math.min(delayMs * 2, EXIT_WATCH_MAX_MS));
|
|
36674
|
+
}, delayMs);
|
|
36675
|
+
};
|
|
36676
|
+
watch(EXIT_WATCH_MS);
|
|
36677
|
+
return () => clearTimeout(timer);
|
|
36678
|
+
}
|
|
36679
|
+
function isLiveMember(state, groupId, pgid) {
|
|
36680
|
+
return Number(groupId) === pgid && state !== undefined && !/^[ZX]/.test(state);
|
|
36681
|
+
}
|
|
36682
|
+
function linuxGroupHasLiveMember(pgid) {
|
|
36683
|
+
for (const entry of readdirSync3("/proc")) {
|
|
36684
|
+
if (!/^\d+$/.test(entry))
|
|
36685
|
+
continue;
|
|
36686
|
+
let stat;
|
|
36687
|
+
try {
|
|
36688
|
+
stat = readFileSync3(`/proc/${entry}/stat`, "latin1");
|
|
36689
|
+
} catch {
|
|
36690
|
+
continue;
|
|
36691
|
+
}
|
|
36692
|
+
const [state, , groupId] = stat.slice(stat.lastIndexOf(")") + 2).split(" ");
|
|
36693
|
+
if (isLiveMember(state, groupId, pgid))
|
|
36694
|
+
return true;
|
|
36695
|
+
}
|
|
36696
|
+
return false;
|
|
36697
|
+
}
|
|
36698
|
+
function psGroupHasLiveMember(pgid) {
|
|
36699
|
+
const result = bunRuntime()?.spawnSync(["/bin/ps", "-A", "-o", "pgid=,stat="], PROCESS_INSPECTION_OPTIONS);
|
|
36700
|
+
if (!result?.success)
|
|
36701
|
+
return true;
|
|
36702
|
+
return result.stdout.toString().split(`
|
|
36703
|
+
`).some((line) => {
|
|
36704
|
+
const [groupId, state] = line.trim().split(/\s+/);
|
|
36705
|
+
return isLiveMember(state, groupId, pgid);
|
|
36706
|
+
});
|
|
36707
|
+
}
|
|
36708
|
+
function groupHasLiveMember(pgid) {
|
|
36709
|
+
try {
|
|
36710
|
+
return process.platform === "linux" ? linuxGroupHasLiveMember(pgid) : psGroupHasLiveMember(pgid);
|
|
36711
|
+
} catch {
|
|
36712
|
+
return true;
|
|
36713
|
+
}
|
|
36714
|
+
}
|
|
36715
|
+
|
|
36716
|
+
// ../protocol/src/node/lost-exit-reaper.ts
|
|
36717
|
+
var log7 = createLogger("process");
|
|
36718
|
+
var REAP_GRACE_MS = 2000;
|
|
36719
|
+
var REAP_MAX_CHECK_MS = 30000;
|
|
36720
|
+
var REAP_MAX_CHECKS = 12;
|
|
36721
|
+
var REAP_MAX_PENDING = 256;
|
|
36722
|
+
function createLostExitReaper(options) {
|
|
36723
|
+
const { system } = options;
|
|
36724
|
+
const graceMs = options.graceMs ?? REAP_GRACE_MS;
|
|
36725
|
+
const maxCheckMs = options.maxCheckMs ?? REAP_MAX_CHECK_MS;
|
|
36726
|
+
const maxChecks = options.maxChecks ?? REAP_MAX_CHECKS;
|
|
36727
|
+
const maxPending = options.maxPending ?? REAP_MAX_PENDING;
|
|
36728
|
+
const pending = new Map;
|
|
36729
|
+
let reaped = 0;
|
|
36730
|
+
let abandoned = 0;
|
|
36731
|
+
const abandon = (pid, reason) => {
|
|
36732
|
+
abandoned += 1;
|
|
36733
|
+
log7.warn("child.reap-abandoned", { pid, reason });
|
|
36734
|
+
};
|
|
36735
|
+
const check = (pid, reported, startedAt) => {
|
|
36736
|
+
if (reported())
|
|
36737
|
+
return false;
|
|
36738
|
+
const found = system.inspect(pid);
|
|
36739
|
+
if (found === undefined)
|
|
36740
|
+
return true;
|
|
36741
|
+
if (found === "gone" || found.ppid !== system.selfPid)
|
|
36742
|
+
return false;
|
|
36743
|
+
if (!found.state.startsWith("Z"))
|
|
36744
|
+
return true;
|
|
36745
|
+
const result = system.waitNoHang(pid);
|
|
36746
|
+
if (result === pid) {
|
|
36747
|
+
reaped += 1;
|
|
36748
|
+
log7.info("child.reaped", { pid, waitedMs: Date.now() - startedAt });
|
|
36749
|
+
return false;
|
|
36750
|
+
}
|
|
36751
|
+
if (result === 0)
|
|
36752
|
+
return true;
|
|
36753
|
+
abandon(pid, "waitpid-failed");
|
|
36754
|
+
return false;
|
|
36755
|
+
};
|
|
36756
|
+
const schedule = (pid, reported, startedAt, delayMs, checks) => {
|
|
36757
|
+
const timer = setTimeout(() => {
|
|
36758
|
+
pending.delete(pid);
|
|
36759
|
+
let again;
|
|
36760
|
+
try {
|
|
36761
|
+
again = check(pid, reported, startedAt);
|
|
36762
|
+
} catch {
|
|
36763
|
+
again = true;
|
|
36764
|
+
}
|
|
36765
|
+
if (!again)
|
|
36766
|
+
return;
|
|
36767
|
+
if (checks + 1 >= maxChecks) {
|
|
36768
|
+
abandon(pid, "not-a-zombie");
|
|
36769
|
+
return;
|
|
36770
|
+
}
|
|
36771
|
+
schedule(pid, reported, startedAt, Math.min(delayMs * 2, maxCheckMs), checks + 1);
|
|
36772
|
+
}, delayMs);
|
|
36773
|
+
timer.unref?.();
|
|
36774
|
+
pending.set(pid, timer);
|
|
36775
|
+
};
|
|
36776
|
+
return {
|
|
36777
|
+
reap(pid, reported) {
|
|
36778
|
+
if (!Number.isSafeInteger(pid) || pid <= 1 || pid === system.selfPid)
|
|
36779
|
+
return;
|
|
36780
|
+
if (pending.has(pid) || reported())
|
|
36781
|
+
return;
|
|
36782
|
+
if (pending.size >= maxPending) {
|
|
36783
|
+
abandon(pid, "capacity");
|
|
36784
|
+
return;
|
|
36785
|
+
}
|
|
36786
|
+
schedule(pid, reported, Date.now(), graceMs, 0);
|
|
36787
|
+
},
|
|
36788
|
+
stats: () => ({ pending: pending.size, reaped, abandoned }),
|
|
36789
|
+
stop() {
|
|
36790
|
+
for (const timer of pending.values())
|
|
36791
|
+
clearTimeout(timer);
|
|
36792
|
+
pending.clear();
|
|
36793
|
+
}
|
|
36794
|
+
};
|
|
36795
|
+
}
|
|
36796
|
+
var WNOHANG = 1;
|
|
36797
|
+
function loadDarwinWaitpid(loadFfi = () => createRequire2(import.meta.url)("bun:ffi")) {
|
|
36798
|
+
try {
|
|
36799
|
+
const { dlopen, FFIType } = loadFfi();
|
|
36800
|
+
const libSystem = dlopen("/usr/lib/libSystem.B.dylib", {
|
|
36801
|
+
waitpid: { args: [FFIType.i32, FFIType.ptr, FFIType.i32], returns: FFIType.i32 }
|
|
36802
|
+
});
|
|
36803
|
+
const status = new Int32Array(1);
|
|
36804
|
+
return (pid) => libSystem.symbols.waitpid(pid, status, WNOHANG);
|
|
36805
|
+
} catch {
|
|
36806
|
+
return;
|
|
36807
|
+
}
|
|
36808
|
+
}
|
|
36809
|
+
function darwinReaperSystem(loadFfi) {
|
|
36810
|
+
const waitNoHang = loadDarwinWaitpid(loadFfi);
|
|
36811
|
+
if (!waitNoHang)
|
|
36812
|
+
return;
|
|
36813
|
+
return {
|
|
36814
|
+
selfPid: process.pid,
|
|
36815
|
+
inspect(pid) {
|
|
36816
|
+
const result = bunRuntime()?.spawnSync(["/bin/ps", "-o", "ppid=,stat=", "-p", String(pid)], PROCESS_INSPECTION_OPTIONS);
|
|
36817
|
+
if (!result)
|
|
36818
|
+
return;
|
|
36819
|
+
const output = result.stdout.toString().trim();
|
|
36820
|
+
if (!result.success)
|
|
36821
|
+
return result.exitCode === 1 && output === "" ? "gone" : undefined;
|
|
36822
|
+
const match = /^(\d+)\s+(\S+)$/.exec(output);
|
|
36823
|
+
return match ? { ppid: Number(match[1]), state: match[2] } : undefined;
|
|
36824
|
+
},
|
|
36825
|
+
waitNoHang
|
|
36826
|
+
};
|
|
36827
|
+
}
|
|
36828
|
+
var defaultReaper;
|
|
36829
|
+
function createDarwinLostExitReaper(loadFfi) {
|
|
36830
|
+
const system = darwinReaperSystem(loadFfi);
|
|
36831
|
+
if (!system)
|
|
36832
|
+
log7.warn("child.reap-unavailable");
|
|
36833
|
+
return system ? createLostExitReaper({ system }) : null;
|
|
36834
|
+
}
|
|
36835
|
+
function sharedReaper() {
|
|
36836
|
+
if (defaultReaper === undefined) {
|
|
36837
|
+
defaultReaper = createDarwinLostExitReaper();
|
|
36838
|
+
}
|
|
36839
|
+
return defaultReaper ?? undefined;
|
|
36840
|
+
}
|
|
36841
|
+
function reapAfterLostExit(pid, reported) {
|
|
36842
|
+
if (process.platform !== "darwin" || pid === undefined || !bunRuntime())
|
|
36843
|
+
return;
|
|
36844
|
+
sharedReaper()?.reap(pid, reported);
|
|
36845
|
+
}
|
|
36846
|
+
|
|
36847
|
+
// ../protocol/src/node/command-capture.ts
|
|
36848
|
+
class CommandFailedError extends Error {
|
|
36849
|
+
stdout;
|
|
36850
|
+
stdoutBytes;
|
|
36851
|
+
stderr;
|
|
36852
|
+
timedOut;
|
|
36853
|
+
outputCloseTimedOut;
|
|
36854
|
+
executableMissing;
|
|
36855
|
+
aborted;
|
|
36856
|
+
outputLimitExceeded;
|
|
36857
|
+
exitCode;
|
|
36858
|
+
signal;
|
|
36859
|
+
constructor(message, details = {}) {
|
|
36860
|
+
super(message);
|
|
36861
|
+
this.name = "CommandFailedError";
|
|
36862
|
+
this.stdout = details.stdout ?? "";
|
|
36863
|
+
this.stdoutBytes = details.stdoutBytes ?? Buffer.alloc(0);
|
|
36864
|
+
this.stderr = details.stderr ?? "";
|
|
36865
|
+
this.timedOut = details.timedOut ?? false;
|
|
36866
|
+
this.outputCloseTimedOut = details.outputCloseTimedOut ?? false;
|
|
36867
|
+
this.executableMissing = details.executableMissing ?? false;
|
|
36868
|
+
this.aborted = details.aborted ?? false;
|
|
36869
|
+
this.outputLimitExceeded = details.outputLimitExceeded ?? false;
|
|
36870
|
+
this.exitCode = details.exitCode ?? null;
|
|
36871
|
+
this.signal = details.signal ?? null;
|
|
36872
|
+
}
|
|
36873
|
+
toJSON() {
|
|
36874
|
+
return { ...formatLogError(this), ...classifyCommandFailure(this) };
|
|
36875
|
+
}
|
|
36876
|
+
[inspect.custom]() {
|
|
36877
|
+
const { name, reason, exitCode, signal, stack } = this.toJSON();
|
|
36878
|
+
const frames = stack?.length ? ` | ${stack.join(" | ")}` : "";
|
|
36879
|
+
return `${name} reason=${reason} exitCode=${exitCode} signal=${signal} outputOmitted=true${frames}`;
|
|
36880
|
+
}
|
|
36881
|
+
}
|
|
36882
|
+
function redactCommandValues(value, redactValues) {
|
|
36883
|
+
const secrets = Array.from(new Set((redactValues ?? []).filter((secret) => typeof secret === "string" && secret.length > 0))).sort((left, right) => right.length - left.length);
|
|
36884
|
+
return secrets.reduce((redacted, secret) => redacted.split(secret).join("[REDACTED]"), value);
|
|
36885
|
+
}
|
|
36886
|
+
var COMMAND_ABORTED_MESSAGE = "Command aborted";
|
|
36887
|
+
var OUTPUT_LIMIT_MESSAGE = "maxBuffer length exceeded";
|
|
36888
|
+
function commandFailureOutcome(error) {
|
|
36889
|
+
const details = error ?? {};
|
|
36890
|
+
const message = typeof details.message === "string" ? details.message : "";
|
|
36891
|
+
return {
|
|
36892
|
+
timedOut: details.killed === true,
|
|
36893
|
+
executableMissing: details.code === "ENOENT",
|
|
36894
|
+
aborted: message === COMMAND_ABORTED_MESSAGE,
|
|
36895
|
+
outputLimitExceeded: details.outputLimitExceeded === true,
|
|
36896
|
+
exitCode: typeof details.code === "number" ? details.code : null,
|
|
36897
|
+
signal: details.signal ?? null
|
|
36898
|
+
};
|
|
36899
|
+
}
|
|
36900
|
+
var commandInvocations = new Map;
|
|
36901
|
+
var commandCaptureMetrics;
|
|
36902
|
+
var commandObservers = new Map;
|
|
36903
|
+
function nonInteractiveGitEnv(env) {
|
|
36904
|
+
const merged = { ...env ?? process.env };
|
|
36905
|
+
merged.GIT_TERMINAL_PROMPT ??= "0";
|
|
36906
|
+
if (process.platform !== "win32") {
|
|
36907
|
+
merged.SSH_ASKPASS ??= "/usr/bin/false";
|
|
36908
|
+
merged.SSH_ASKPASS_REQUIRE ??= "force";
|
|
36909
|
+
}
|
|
36910
|
+
return merged;
|
|
36911
|
+
}
|
|
36912
|
+
var MAX_COMMAND_OUTPUT_BYTES = 50 * 1024 * 1024;
|
|
36913
|
+
var COMMAND_KILL_GRACE_MS = 100;
|
|
36914
|
+
var COMMAND_OUTPUT_CHECK_MS = 100;
|
|
36915
|
+
var COMMAND_GROUP_POLL_MS = 5;
|
|
36916
|
+
var COMMAND_GROUP_POLL_MAX_MS = 200;
|
|
36917
|
+
function openCaptureFile() {
|
|
36918
|
+
const filePath = path.join(os.tmpdir(), `orkestrator-capture-${randomUUID2()}`);
|
|
36919
|
+
const fd = captureFs.openSync(filePath, fsConstants.O_CREAT | fsConstants.O_EXCL | fsConstants.O_RDWR | fsConstants.O_APPEND, 384);
|
|
36920
|
+
try {
|
|
36921
|
+
captureFs.unlinkSync(filePath);
|
|
36922
|
+
return fd;
|
|
36923
|
+
} catch (error) {
|
|
36924
|
+
captureFs.closeSync(fd);
|
|
36925
|
+
throw error;
|
|
36926
|
+
}
|
|
36927
|
+
}
|
|
36928
|
+
function readCaptureFile(fd, limit) {
|
|
36929
|
+
const size = Math.min(captureFs.fstatSync(fd).size, limit);
|
|
36930
|
+
const buffer = Buffer.allocUnsafe(size);
|
|
36931
|
+
let offset = 0;
|
|
36932
|
+
while (offset < size) {
|
|
36933
|
+
const bytesRead = captureFs.readSync(fd, buffer, offset, size - offset, offset);
|
|
36934
|
+
if (bytesRead === 0)
|
|
36935
|
+
break;
|
|
36936
|
+
offset += bytesRead;
|
|
36937
|
+
}
|
|
36938
|
+
return buffer.subarray(0, offset);
|
|
36939
|
+
}
|
|
36940
|
+
function spawnCaptured(command, args, options, stdoutFd, stderrFd) {
|
|
36941
|
+
const payload = options.stdin?.length ? Buffer.from(options.stdin) : undefined;
|
|
36942
|
+
const env = command === "git" ? nonInteractiveGitEnv(options.env) : options.env ?? process.env;
|
|
36943
|
+
const detached = process.platform !== "win32";
|
|
36944
|
+
const bun = bunRuntime();
|
|
36945
|
+
if (bun) {
|
|
36946
|
+
const child = bun.spawn([command, ...args], {
|
|
36947
|
+
cwd: options.cwd,
|
|
36948
|
+
env,
|
|
36949
|
+
detached,
|
|
36950
|
+
windowsHide: true,
|
|
36951
|
+
stdin: payload ?? "pipe",
|
|
36952
|
+
stdout: stdoutFd,
|
|
36953
|
+
stderr: stderrFd
|
|
36954
|
+
});
|
|
36955
|
+
if (!payload)
|
|
36956
|
+
closeStdin(child.stdin);
|
|
36957
|
+
const current = () => ({ code: child.exitCode, signal: child.signalCode });
|
|
36958
|
+
return {
|
|
36959
|
+
pid: child.pid,
|
|
36960
|
+
exited: child.exited.then(current),
|
|
36961
|
+
current,
|
|
36962
|
+
kill: (signal) => child.kill(signal)
|
|
36963
|
+
};
|
|
36964
|
+
}
|
|
36965
|
+
const child = spawn(command, args, {
|
|
36966
|
+
cwd: options.cwd,
|
|
36967
|
+
env,
|
|
36968
|
+
detached,
|
|
36969
|
+
windowsHide: true,
|
|
36970
|
+
stdio: [payload ? "pipe" : "ignore", stdoutFd, stderrFd]
|
|
36971
|
+
});
|
|
36972
|
+
if (payload) {
|
|
36973
|
+
child.stdin?.on("error", () => {
|
|
36974
|
+
return;
|
|
36975
|
+
});
|
|
36976
|
+
child.stdin?.end(payload);
|
|
36977
|
+
}
|
|
36978
|
+
return {
|
|
36979
|
+
pid: child.pid,
|
|
36980
|
+
exited: new Promise((resolve, reject) => {
|
|
36981
|
+
child.once("exit", (code, signal) => resolve({ code, signal }));
|
|
36982
|
+
child.once("error", reject);
|
|
36983
|
+
}),
|
|
36984
|
+
current: () => ({ code: child.exitCode, signal: child.signalCode }),
|
|
36985
|
+
kill: (signal) => {
|
|
36986
|
+
child.kill(signal);
|
|
36987
|
+
}
|
|
36988
|
+
};
|
|
36989
|
+
}
|
|
36990
|
+
function closeStdin(stdin) {
|
|
36991
|
+
try {
|
|
36992
|
+
Promise.resolve(stdin.end()).catch(() => {
|
|
36993
|
+
return;
|
|
36994
|
+
});
|
|
36995
|
+
} catch {}
|
|
36996
|
+
}
|
|
36997
|
+
function exitReported(child) {
|
|
36998
|
+
const { code, signal } = child.current();
|
|
36999
|
+
return code !== null || signal !== null;
|
|
37000
|
+
}
|
|
37001
|
+
function signalCommand(child, signal) {
|
|
37002
|
+
if (child.pid === undefined)
|
|
37003
|
+
return;
|
|
37004
|
+
try {
|
|
37005
|
+
if (process.platform !== "win32") {
|
|
37006
|
+
process.kill(-child.pid, signal);
|
|
37007
|
+
} else {
|
|
37008
|
+
child.kill(signal);
|
|
37009
|
+
}
|
|
37010
|
+
} catch {}
|
|
37011
|
+
}
|
|
37012
|
+
function commandGroupAlive(child) {
|
|
37013
|
+
if (process.platform === "win32" || child.pid === undefined)
|
|
37014
|
+
return false;
|
|
37015
|
+
try {
|
|
37016
|
+
process.kill(-child.pid, 0);
|
|
37017
|
+
} catch (error) {
|
|
37018
|
+
if (error.code === "ESRCH")
|
|
37019
|
+
return false;
|
|
37020
|
+
}
|
|
37021
|
+
return groupHasLiveMember(child.pid);
|
|
37022
|
+
}
|
|
37023
|
+
function executeCommandBytes(command, args, options, timeoutMs, outputLimit, stderrLimit) {
|
|
37024
|
+
return new Promise((resolve, reject) => {
|
|
37025
|
+
if (options.signal?.aborted) {
|
|
37026
|
+
reject(Object.assign(new Error(COMMAND_ABORTED_MESSAGE), { killed: true }));
|
|
37027
|
+
return;
|
|
37028
|
+
}
|
|
37029
|
+
const captureFds = [];
|
|
37030
|
+
const releaseCaptureFds = () => {
|
|
37031
|
+
for (const fd of captureFds.splice(0)) {
|
|
37032
|
+
try {
|
|
37033
|
+
captureFs.closeSync(fd);
|
|
37034
|
+
} catch {}
|
|
37035
|
+
}
|
|
37036
|
+
};
|
|
37037
|
+
try {
|
|
37038
|
+
captureFds.push(openCaptureFile());
|
|
37039
|
+
captureFds.push(openCaptureFile());
|
|
37040
|
+
} catch (error) {
|
|
37041
|
+
releaseCaptureFds();
|
|
37042
|
+
const code = error.code ?? "unknown";
|
|
37043
|
+
reject(new Error(`Could not open a command output file in the temporary directory: ${code}`));
|
|
37044
|
+
return;
|
|
37045
|
+
}
|
|
37046
|
+
const [stdoutFd, stderrFd] = captureFds;
|
|
37047
|
+
let child;
|
|
37048
|
+
try {
|
|
37049
|
+
child = spawnCaptured(command, args, options, stdoutFd, stderrFd);
|
|
37050
|
+
} catch (error) {
|
|
37051
|
+
releaseCaptureFds();
|
|
37052
|
+
reject(error);
|
|
37053
|
+
return;
|
|
37054
|
+
}
|
|
37055
|
+
let settled = false;
|
|
37056
|
+
let timedOut = false;
|
|
37057
|
+
let timeoutTimer;
|
|
37058
|
+
let groupTimer;
|
|
37059
|
+
let limitTimer;
|
|
37060
|
+
let stopExitWatch = () => {};
|
|
37061
|
+
let commandExit;
|
|
37062
|
+
const finishCapture = () => {
|
|
37063
|
+
settled = true;
|
|
37064
|
+
clearTimeout(timeoutTimer);
|
|
37065
|
+
clearTimeout(groupTimer);
|
|
37066
|
+
clearInterval(limitTimer);
|
|
37067
|
+
stopExitWatch();
|
|
37068
|
+
options.signal?.removeEventListener("abort", abort);
|
|
37069
|
+
if (!exitReported(child))
|
|
37070
|
+
reapAfterLostExit(child.pid, () => exitReported(child));
|
|
37071
|
+
try {
|
|
37072
|
+
return {
|
|
37073
|
+
stdout: readCaptureFile(stdoutFd, outputLimit),
|
|
37074
|
+
stderr: readCaptureFile(stderrFd, stderrLimit)
|
|
37075
|
+
};
|
|
37076
|
+
} catch (error) {
|
|
37077
|
+
reject(error);
|
|
37078
|
+
return;
|
|
37079
|
+
} finally {
|
|
37080
|
+
releaseCaptureFds();
|
|
37081
|
+
}
|
|
37082
|
+
};
|
|
37083
|
+
const fail = (error) => {
|
|
37084
|
+
if (settled)
|
|
37085
|
+
return;
|
|
37086
|
+
const output = finishCapture();
|
|
37087
|
+
if (output)
|
|
37088
|
+
reject(Object.assign(error, { ...output, killed: timedOut }));
|
|
37089
|
+
};
|
|
37090
|
+
const abort = () => {
|
|
37091
|
+
timedOut = true;
|
|
37092
|
+
signalCommand(child, "SIGKILL");
|
|
37093
|
+
fail(new Error(COMMAND_ABORTED_MESSAGE));
|
|
37094
|
+
};
|
|
37095
|
+
options.signal?.addEventListener("abort", abort, { once: true });
|
|
37096
|
+
const checkOutputLimit = () => {
|
|
37097
|
+
const stream = captureFs.fstatSync(stdoutFd).size > outputLimit ? "stdout" : captureFs.fstatSync(stderrFd).size > stderrLimit ? "stderr" : undefined;
|
|
37098
|
+
if (stream === undefined)
|
|
37099
|
+
return false;
|
|
37100
|
+
signalCommand(child, "SIGKILL");
|
|
37101
|
+
fail(Object.assign(new Error(`${stream} ${OUTPUT_LIMIT_MESSAGE}`), {
|
|
37102
|
+
outputLimitExceeded: true
|
|
37103
|
+
}));
|
|
37104
|
+
return true;
|
|
37105
|
+
};
|
|
37106
|
+
const failIfOverLimit = () => {
|
|
37107
|
+
try {
|
|
37108
|
+
return checkOutputLimit();
|
|
37109
|
+
} catch (error) {
|
|
37110
|
+
signalCommand(child, "SIGKILL");
|
|
37111
|
+
fail(error instanceof Error ? error : new Error(String(error)));
|
|
37112
|
+
return true;
|
|
37113
|
+
}
|
|
37114
|
+
};
|
|
37115
|
+
limitTimer = setInterval(() => {
|
|
37116
|
+
if (!settled && !timedOut)
|
|
37117
|
+
failIfOverLimit();
|
|
37118
|
+
}, COMMAND_OUTPUT_CHECK_MS);
|
|
37119
|
+
const settleOnExit = () => {
|
|
37120
|
+
if (settled || timedOut || failIfOverLimit())
|
|
37121
|
+
return;
|
|
37122
|
+
if (commandExit?.code !== 0 || commandExit.signal !== null) {
|
|
37123
|
+
fail(Object.assign(new Error(`Command failed: ${[command, ...args].join(" ")}`), {
|
|
37124
|
+
code: commandExit?.code,
|
|
37125
|
+
signal: commandExit?.signal
|
|
37126
|
+
}));
|
|
37127
|
+
return;
|
|
37128
|
+
}
|
|
37129
|
+
const output = finishCapture();
|
|
37130
|
+
if (output)
|
|
37131
|
+
resolve(output);
|
|
37132
|
+
};
|
|
37133
|
+
const awaitGroupExit = (delayMs) => {
|
|
37134
|
+
if (settled || timedOut)
|
|
37135
|
+
return;
|
|
37136
|
+
if (commandGroupAlive(child)) {
|
|
37137
|
+
groupTimer = setTimeout(awaitGroupExit, delayMs, Math.min(delayMs * 2, COMMAND_GROUP_POLL_MAX_MS));
|
|
37138
|
+
return;
|
|
37139
|
+
}
|
|
37140
|
+
settleOnExit();
|
|
37141
|
+
};
|
|
37142
|
+
const onCommandExit = (exit) => {
|
|
37143
|
+
if (commandExit)
|
|
37144
|
+
return;
|
|
37145
|
+
commandExit = exit;
|
|
37146
|
+
stopExitWatch();
|
|
37147
|
+
if (options.waitForDescendants)
|
|
37148
|
+
awaitGroupExit(COMMAND_GROUP_POLL_MS);
|
|
37149
|
+
else
|
|
37150
|
+
settleOnExit();
|
|
37151
|
+
};
|
|
37152
|
+
child.exited.then(onCommandExit, (error) => fail(error instanceof Error ? error : new Error(String(error))));
|
|
37153
|
+
stopExitWatch = watchForLostExit(child.pid, (exit) => {
|
|
37154
|
+
if (!settled && !timedOut)
|
|
37155
|
+
onCommandExit(exit);
|
|
37156
|
+
});
|
|
37157
|
+
if (timeoutMs > 0) {
|
|
37158
|
+
timeoutTimer = setTimeout(() => {
|
|
37159
|
+
timedOut = true;
|
|
37160
|
+
signalCommand(child, "SIGTERM");
|
|
37161
|
+
timeoutTimer = setTimeout(() => {
|
|
37162
|
+
signalCommand(child, "SIGKILL");
|
|
37163
|
+
fail(Object.assign(new Error(`Command timed out after ${timeoutMs} ms`), {
|
|
37164
|
+
code: child.current().code,
|
|
37165
|
+
signal: child.current().signal
|
|
37166
|
+
}));
|
|
37167
|
+
}, COMMAND_KILL_GRACE_MS);
|
|
37168
|
+
}, timeoutMs);
|
|
37169
|
+
}
|
|
37170
|
+
});
|
|
37171
|
+
}
|
|
37172
|
+
async function runCommandBytes(command, args = [], options = {}) {
|
|
37173
|
+
const timeoutMs = options.timeoutMs ?? 60000;
|
|
37174
|
+
if (!Number.isSafeInteger(timeoutMs) || timeoutMs < 0 || timeoutMs > 2147483647) {
|
|
37175
|
+
throw new RangeError("timeoutMs must be an integer between 0 and 2147483647");
|
|
37176
|
+
}
|
|
37177
|
+
const outputLimit = options.maxOutputBytes ?? MAX_COMMAND_OUTPUT_BYTES;
|
|
37178
|
+
if (!Number.isSafeInteger(outputLimit) || outputLimit <= 0) {
|
|
37179
|
+
throw new RangeError("maxOutputBytes must be a positive integer");
|
|
37180
|
+
}
|
|
37181
|
+
const stderrLimit = options.maxStderrBytes ?? outputLimit;
|
|
37182
|
+
if (!Number.isSafeInteger(stderrLimit) || stderrLimit <= 0) {
|
|
37183
|
+
throw new RangeError("maxStderrBytes must be a positive integer");
|
|
37184
|
+
}
|
|
37185
|
+
if (commandInvocations.size < 64 || commandInvocations.has(command)) {
|
|
37186
|
+
commandInvocations.set(command, (commandInvocations.get(command) ?? 0) + 1);
|
|
37187
|
+
}
|
|
37188
|
+
for (const observer of commandObservers.get(command) ?? [])
|
|
37189
|
+
observer(args);
|
|
37190
|
+
commandCaptureMetrics?.started(command, args);
|
|
37191
|
+
try {
|
|
37192
|
+
const { stdout, stderr } = await executeCommandBytes(command, args, options, timeoutMs, outputLimit, stderrLimit);
|
|
37193
|
+
commandCaptureMetrics?.capturedBytes(stdout.length);
|
|
37194
|
+
return {
|
|
37195
|
+
stdout: Buffer.isBuffer(stdout) ? stdout : Buffer.from(stdout),
|
|
37196
|
+
stderr: Buffer.isBuffer(stderr) ? stderr : Buffer.from(stderr)
|
|
37197
|
+
};
|
|
37198
|
+
} catch (error) {
|
|
37199
|
+
const outcome = commandFailureOutcome(error);
|
|
37200
|
+
const redacting = options.redactValues?.some((value) => typeof value === "string" && value.length > 0);
|
|
37201
|
+
if (error && typeof error === "object" && "stdout" in error && "stderr" in error) {
|
|
37202
|
+
const withOutput = error;
|
|
37203
|
+
const stderr = withOutput.stderr?.toString() ?? "";
|
|
37204
|
+
const stdout = withOutput.stdout?.toString() ?? "";
|
|
37205
|
+
const message = (stderr || stdout || withOutput.message || "Command failed").trim();
|
|
37206
|
+
throw new CommandFailedError(redactCommandValues(message, options.redactValues), {
|
|
37207
|
+
...outcome,
|
|
37208
|
+
stdout: redactCommandValues(stdout, options.redactValues),
|
|
37209
|
+
stderr: redactCommandValues(stderr, options.redactValues),
|
|
37210
|
+
...!redacting && Buffer.isBuffer(withOutput.stdout) ? { stdoutBytes: withOutput.stdout } : {}
|
|
37211
|
+
});
|
|
37212
|
+
}
|
|
37213
|
+
if (redacting) {
|
|
37214
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
37215
|
+
throw new CommandFailedError(redactCommandValues(message || "Command failed", options.redactValues), outcome);
|
|
37216
|
+
}
|
|
37217
|
+
if (outcome.timedOut || outcome.executableMissing) {
|
|
37218
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
37219
|
+
throw new CommandFailedError(message || "Command failed", outcome);
|
|
37220
|
+
}
|
|
37221
|
+
throw error;
|
|
37222
|
+
}
|
|
37223
|
+
}
|
|
37224
|
+
async function runCommand(command, args = [], options = {}) {
|
|
37225
|
+
const { stdout, stderr } = await runCommandBytes(command, args, options);
|
|
37226
|
+
return {
|
|
37227
|
+
stdout: redactCommandValues(stdout.toString(), options.redactValues),
|
|
37228
|
+
stderr: redactCommandValues(stderr.toString(), options.redactValues)
|
|
37229
|
+
};
|
|
37230
|
+
}
|
|
37231
|
+
|
|
37232
|
+
// ../protocol/src/node/workspace-change-probe.ts
|
|
36387
37233
|
var DEFAULT_MAX_UNTRACKED_FILE_BYTES = 2 * 1024 * 1024;
|
|
36388
37234
|
var DEFAULT_MAX_UNTRACKED_FILES = 5000;
|
|
36389
37235
|
var DEFAULT_SLOW_SNAPSHOT_MS = 500;
|
|
@@ -36401,27 +37247,16 @@ process.once("exit", () => {
|
|
|
36401
37247
|
} catch {}
|
|
36402
37248
|
}
|
|
36403
37249
|
});
|
|
36404
|
-
var runGit = (args, options) =>
|
|
36405
|
-
const
|
|
36406
|
-
|
|
36407
|
-
|
|
36408
|
-
|
|
36409
|
-
|
|
36410
|
-
|
|
36411
|
-
let stdout = "";
|
|
36412
|
-
let stdoutBytes = 0;
|
|
36413
|
-
child.stdout.setEncoding("utf8");
|
|
36414
|
-
child.stdout.on("data", (chunk) => {
|
|
36415
|
-
stdoutBytes += chunk.length;
|
|
36416
|
-
if (stdoutBytes <= GIT_MAX_BUFFER)
|
|
36417
|
-
stdout += chunk;
|
|
37250
|
+
var runGit = async (args, options) => {
|
|
37251
|
+
const { stdout } = await runCommand("git", args, {
|
|
37252
|
+
cwd: options.cwd,
|
|
37253
|
+
env: { ...process.env, ...options.env, GIT_OPTIONAL_LOCKS: "0" },
|
|
37254
|
+
timeoutMs: GIT_TIMEOUT_MS,
|
|
37255
|
+
maxOutputBytes: GIT_MAX_BUFFER,
|
|
37256
|
+
...options.stdin === undefined ? {} : { stdin: options.stdin }
|
|
36418
37257
|
});
|
|
36419
|
-
|
|
36420
|
-
|
|
36421
|
-
child.on("close", (code) => code === 0 ? resolvePromise({ stdout }) : reject(new Error(`git exited with ${code}`)));
|
|
36422
|
-
child.stdin.on("error", () => {});
|
|
36423
|
-
child.stdin.end(options.stdin);
|
|
36424
|
-
});
|
|
37258
|
+
return { stdout };
|
|
37259
|
+
};
|
|
36425
37260
|
|
|
36426
37261
|
class WorkspaceChangeProbe {
|
|
36427
37262
|
git;
|
|
@@ -36709,7 +37544,7 @@ class WorkspaceChangeProbe {
|
|
|
36709
37544
|
return;
|
|
36710
37545
|
const { root, indexPath } = repo.location;
|
|
36711
37546
|
const started = this.now();
|
|
36712
|
-
const tempIndex = join8(this.tempDir, `orkestrator-probe-${
|
|
37547
|
+
const tempIndex = join8(this.tempDir, `orkestrator-probe-${randomUUID3()}.index`);
|
|
36713
37548
|
const objectDirectory = await mkdtemp(join8(this.tempDir, "orkestrator-probe-objects-"));
|
|
36714
37549
|
temporaryObjectDirectories.add(objectDirectory);
|
|
36715
37550
|
let retained = false;
|
|
@@ -36972,7 +37807,7 @@ function classify(toolCall) {
|
|
|
36972
37807
|
return;
|
|
36973
37808
|
}
|
|
36974
37809
|
// ../../bridges/cursor-bridge/src/prompt.ts
|
|
36975
|
-
var
|
|
37810
|
+
var log8 = createLogger("bridge.cursor");
|
|
36976
37811
|
var STRUCTURED_PROMPT_INSTRUCTION_PREFIX = "End your turn with exactly one JSON value";
|
|
36977
37812
|
function structuredPromptInstruction(schema) {
|
|
36978
37813
|
return `${STRUCTURED_PROMPT_INSTRUCTION_PREFIX} matching this JSON Schema. That final message must be the JSON value alone, with no Markdown fence and no commentary around it.
|
|
@@ -37010,7 +37845,7 @@ async function dispatchPrompt(state, agent, input) {
|
|
|
37010
37845
|
const promptSequence = state.promptSequence;
|
|
37011
37846
|
const diagnostics = createRunDiagnostics(state);
|
|
37012
37847
|
const evidence = trackTurnEvidence(state.id, {
|
|
37013
|
-
turnId: input.requestId ?? `cursor-turn:${
|
|
37848
|
+
turnId: input.requestId ?? `cursor-turn:${randomUUID4()}`,
|
|
37014
37849
|
mode: "live"
|
|
37015
37850
|
});
|
|
37016
37851
|
const commandChanges = trackCommandChanges(state, evidence);
|
|
@@ -37174,7 +38009,7 @@ async function followRun(state, run, promptSequence, input, timeoutMs = PROMPT_T
|
|
|
37174
38009
|
}) : undefined;
|
|
37175
38010
|
if (!turnStillOwned(state, promptSequence))
|
|
37176
38011
|
return await closedTurnStopped();
|
|
37177
|
-
|
|
38012
|
+
log8.warn("turn.timed-out", { sessionId: state.id });
|
|
37178
38013
|
state.error = error.message;
|
|
37179
38014
|
state.revision += 1;
|
|
37180
38015
|
schedulePersist();
|
|
@@ -37243,7 +38078,7 @@ function finishTurn(state, result, input, streamed) {
|
|
|
37243
38078
|
}
|
|
37244
38079
|
function failTurn(state, error, input, result, streamed = {}) {
|
|
37245
38080
|
if (state.turnCancelRequested !== true) {
|
|
37246
|
-
|
|
38081
|
+
log8.warn("turn.failed", {
|
|
37247
38082
|
sessionId: state.id,
|
|
37248
38083
|
error: formatLogError(error, { message: false })
|
|
37249
38084
|
});
|
|
@@ -38065,6 +38900,7 @@ function effectiveLogLevel(detail, area) {
|
|
|
38065
38900
|
return detail.level;
|
|
38066
38901
|
}
|
|
38067
38902
|
}
|
|
38903
|
+
var LOG_DETAIL_EXPIRY_MS = 24 * 60 * 60 * 1000;
|
|
38068
38904
|
function logDetailEnablesBridgeDiagnostics(detail) {
|
|
38069
38905
|
return LEVEL_DETAIL[effectiveLogLevel(detail, BRIDGE_DIAGNOSTICS_LOG_AREA)] >= LEVEL_DETAIL.debug;
|
|
38070
38906
|
}
|
|
@@ -39252,7 +40088,7 @@ async function answerSessionActivityBatch(body, read, options = {}) {
|
|
|
39252
40088
|
}
|
|
39253
40089
|
|
|
39254
40090
|
// ../../bridges/cursor-bridge/src/http.ts
|
|
39255
|
-
var
|
|
40091
|
+
var log9 = createLogger("bridge.cursor");
|
|
39256
40092
|
|
|
39257
40093
|
class HttpError extends Error {
|
|
39258
40094
|
status;
|
|
@@ -39296,7 +40132,7 @@ async function route(request, response, clientSignal) {
|
|
|
39296
40132
|
if (error instanceof HttpError)
|
|
39297
40133
|
return json(response, error.status, { error: error.message });
|
|
39298
40134
|
if (error instanceof PolicyWideningRefusedError) {
|
|
39299
|
-
|
|
40135
|
+
log9.warn("session.policy-widening-refused", { widened: error.widened.join(",") });
|
|
39300
40136
|
return json(response, 403, error.refusal());
|
|
39301
40137
|
}
|
|
39302
40138
|
if (error instanceof CredentialError) {
|
|
@@ -39321,7 +40157,7 @@ async function route(request, response, clientSignal) {
|
|
|
39321
40157
|
if (error instanceof PromptAttachmentError) {
|
|
39322
40158
|
return json(response, 400, { error: error.message });
|
|
39323
40159
|
}
|
|
39324
|
-
|
|
40160
|
+
log9.error("http.route-failed");
|
|
39325
40161
|
return json(response, 500, { error: "Internal bridge error" });
|
|
39326
40162
|
}
|
|
39327
40163
|
}
|
|
@@ -40023,7 +40859,7 @@ async function dispatchClaimedPrompt(response, state, input) {
|
|
|
40023
40859
|
userMessageId
|
|
40024
40860
|
});
|
|
40025
40861
|
} catch (error) {
|
|
40026
|
-
|
|
40862
|
+
log9.warn("turn.send-failed", {
|
|
40027
40863
|
sessionId: state.id,
|
|
40028
40864
|
error: formatLogError(error, { message: false })
|
|
40029
40865
|
});
|
|
@@ -40317,7 +41153,7 @@ function startParentWatchdog(options) {
|
|
|
40317
41153
|
}
|
|
40318
41154
|
|
|
40319
41155
|
// ../protocol/src/bridge-lifecycle.ts
|
|
40320
|
-
var
|
|
41156
|
+
var log10 = createLogger("bridge.lifecycle");
|
|
40321
41157
|
var TERMINATION_SIGNALS = ["SIGTERM", "SIGINT"];
|
|
40322
41158
|
function errorKind(error) {
|
|
40323
41159
|
if (error instanceof Error)
|
|
@@ -40371,7 +41207,7 @@ class BridgeLifecycle {
|
|
|
40371
41207
|
}
|
|
40372
41208
|
requestExit() {
|
|
40373
41209
|
this.#exit ??= this.shutdown().then(() => this.#options.exit(0), (error) => {
|
|
40374
|
-
|
|
41210
|
+
log10.error("shutdown.failed", {
|
|
40375
41211
|
bridge: this.#options.label,
|
|
40376
41212
|
errorClass: errorKind(error)
|
|
40377
41213
|
});
|
|
@@ -40388,7 +41224,7 @@ class BridgeLifecycle {
|
|
|
40388
41224
|
try {
|
|
40389
41225
|
idleSweep.run();
|
|
40390
41226
|
} catch (error) {
|
|
40391
|
-
|
|
41227
|
+
log10.warn("idle-sweep.failed", {
|
|
40392
41228
|
bridge: this.#options.label,
|
|
40393
41229
|
errorClass: errorKind(error)
|
|
40394
41230
|
});
|
|
@@ -40460,7 +41296,7 @@ async function settleIdleDetaches() {
|
|
|
40460
41296
|
}
|
|
40461
41297
|
|
|
40462
41298
|
// ../../bridges/cursor-bridge/src/server.ts
|
|
40463
|
-
var
|
|
41299
|
+
var log11 = createLogger("bridge.cursor");
|
|
40464
41300
|
var IDLE_SWEEP_MS = 60 * 1000;
|
|
40465
41301
|
var lifecycle;
|
|
40466
41302
|
var server = createServer((request, response) => {
|
|
@@ -40495,7 +41331,7 @@ function lifecycleFor(listenPort, options) {
|
|
|
40495
41331
|
applyWorkingDirectory();
|
|
40496
41332
|
await loadPersistedState();
|
|
40497
41333
|
finishRestoredTombstones().catch(() => {
|
|
40498
|
-
|
|
41334
|
+
log11.warn("startup.closes-failed");
|
|
40499
41335
|
});
|
|
40500
41336
|
await new Promise((resolve) => server.listen(listenPort, hostname, resolve));
|
|
40501
41337
|
},
|
|
@@ -40661,9 +41497,9 @@ function installFatalRejectionGuard(options) {
|
|
|
40661
41497
|
}
|
|
40662
41498
|
|
|
40663
41499
|
// ../protocol/src/node/process-failure-log.ts
|
|
40664
|
-
var
|
|
41500
|
+
var log12 = createLogger("process");
|
|
40665
41501
|
function logUnhandledRejection(reason) {
|
|
40666
|
-
|
|
41502
|
+
log12.throttled("error", "rejection.unhandled", {
|
|
40667
41503
|
error: reason,
|
|
40668
41504
|
fields: () => ({ error: formatLogError(reason, { message: false }) })
|
|
40669
41505
|
});
|