orkestrator 2.37.3-beta → 2.37.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/artifact-runtime/worker-context/Dockerfile +1 -1
- package/dist/artifact-runtime/worker-context/package-lock.json +4 -4
- package/dist/artifact-runtime/worker-context/package.json +1 -1
- package/dist/client.js +397 -24
- package/dist/main.js +112233 -102964
- package/package.json +4 -4
- package/resources/acp-bridge/dist/index.js +218 -123
- package/resources/claude-bridge/dist/index.js +459 -460
- package/resources/codex-bridge/dist/index.js +259 -224
- package/resources/cursor-bridge/dist/index.js +1370 -419
- package/resources/cursor-bridge/runtime/install.json +1 -1
- package/resources/pi-bridge/dist/index.js +374 -162
- package/resources/pi-bridge/runtime/install.json +1 -1
- package/resources/release-runtime/bun.lock +2 -2
- package/resources/release-runtime/package.json +1 -1
|
@@ -436,10 +436,13 @@ var BRIDGE_LOG_AREAS = defineLogAreas({
|
|
|
436
436
|
"prompt.accepted": "The route accepted a prompt and answered 202.",
|
|
437
437
|
"prompt.failed": "A prompt turn failed; the session reports the error.",
|
|
438
438
|
"prompt.processing-failed": "A prompt accepted by the route failed while processing.",
|
|
439
|
+
"prompt.processing-usage-limited": "A prompt accepted by the route ended on a usage limit; the turn already logged prompt.usage-limited.",
|
|
439
440
|
"prompt.received": "A prompt reached the bridge; only its length is logged.",
|
|
440
441
|
"prompt.send-failed": "A prompt request failed; the route answered with an error.",
|
|
442
|
+
"prompt.usage-limited": "A prompt turn ended because the account's plan allowance is used up; the session reports the limit.",
|
|
441
443
|
"query.close-failed": "Stopping the Claude query failed while closing a tab; the close stays pending.",
|
|
442
444
|
"query.failed": "A Claude query ended with an error result.",
|
|
445
|
+
"query.usage-limited": "Claude refused a query because the account's plan allowance is used up; the turn reports the limit.",
|
|
443
446
|
"question.answer-failed": "The answer-question route failed.",
|
|
444
447
|
"question.answering": "Answering a parked question.",
|
|
445
448
|
"question.answers-prepared": "The route prepared a question answer for the session.",
|
|
@@ -638,10 +641,10 @@ var DESKTOP_LOG_AREAS = defineLogAreas({
|
|
|
638
641
|
"dev-mode.ignored-packaged": "A packaged app was launched with ELECTRON_DEV=1 and ignored it; it loads its bundled renderer.",
|
|
639
642
|
"instance.already-running": "Another instance holds this data directory; this one will quit.",
|
|
640
643
|
"main-thread.stalled": {
|
|
641
|
-
description: "A timer fired late, so windows, IPC and the stdout reader waited.",
|
|
644
|
+
description: "A timer fired late, so windows, IPC and the stdout reader waited. `cpuMs` is the CPU time the process used in the window: near `lagMs` the main thread was busy, far below it the thread waited.",
|
|
642
645
|
essential: true,
|
|
643
646
|
minLevel: "error",
|
|
644
|
-
fields: { lagMs: "number", intervalMs: "number" }
|
|
647
|
+
fields: { lagMs: "number", intervalMs: "number", cpuMs: "number" }
|
|
645
648
|
},
|
|
646
649
|
"process-memory": "Development only: working set per Electron process type, sampled on an interval.",
|
|
647
650
|
"process-memory.failed": "Development only: one process memory sample could not be read.",
|
|
@@ -691,12 +694,22 @@ var DESKTOP_LOG_AREAS = defineLogAreas({
|
|
|
691
694
|
denied: "A renderer asked for a permission the policy does not grant."
|
|
692
695
|
}
|
|
693
696
|
},
|
|
697
|
+
"desktop.webrequest": {
|
|
698
|
+
description: "Main-process webRequest listeners on Electron sessions. Listener names only; never a URL, header or error message.",
|
|
699
|
+
events: {
|
|
700
|
+
"listener.failed-closed": "A listener's decision threw or rejected, so it answered with its fail-closed response.",
|
|
701
|
+
"observer.failed": "A listener with no callback (a redirect observer) threw; its fallback ran.",
|
|
702
|
+
"callback.failed": "Electron's webRequest callback threw while a listener answered.",
|
|
703
|
+
...THROTTLE_LOG_EVENTS
|
|
704
|
+
}
|
|
705
|
+
},
|
|
694
706
|
"desktop.dialog": {
|
|
695
707
|
description: "Native dialogs, whose modal loops hold the main thread while they are open.",
|
|
696
708
|
events: {
|
|
697
709
|
"attention-failed": "A dialog could not ask for the user's attention.",
|
|
698
710
|
closed: "A native dialog closed.",
|
|
699
711
|
"hidden-cancelled": "A hidden profile cancelled a dialog without opening native UI.",
|
|
712
|
+
"no-display-cancelled": "A headless Electron with no display cancelled a dialog instead of opening native UI.",
|
|
700
713
|
"open-failed": "A dialog could not open; it was answered as cancelled.",
|
|
701
714
|
opening: "A native dialog is opening.",
|
|
702
715
|
"preview-beforeunload-ignored": "A browser preview's beforeunload handler was ignored.",
|
|
@@ -1052,6 +1065,7 @@ var NATIVE_AGENT_LOG_AREAS = defineLogAreas({
|
|
|
1052
1065
|
"agent-tools.unavailable": "OpenCode agent tools remain unavailable for a session.",
|
|
1053
1066
|
"coordinator-servers.unavailable": "OpenCode coordinator research servers are unavailable.",
|
|
1054
1067
|
"monitor.reconnecting": "The request monitor lost its stream and is reconnecting. Error class only.",
|
|
1068
|
+
"monitor.silent": "The request monitor's stream stopped heartbeating, so it is replaced. `silenceMs` only.",
|
|
1055
1069
|
"worker-limit.reached": "The bounded request workers are full, so the stream restarts and a snapshot reconciles.",
|
|
1056
1070
|
"request.failed": "Handling a request event failed, so the stream restarts. Error class only.",
|
|
1057
1071
|
"credential-plugin.skipped": "A host OpenCode server started without the credential plugin, so its tools inherit its password; `reason` says why.",
|
|
@@ -1074,6 +1088,7 @@ var NATIVE_AGENT_LOG_AREAS = defineLogAreas({
|
|
|
1074
1088
|
"host-server.terminate-failed": "A 2.x server that did not become ready could not be stopped; its process entry is kept for shutdown. Error class only.",
|
|
1075
1089
|
"container-server.launched": "The start script of a container environment's 2.x server was run. Container port only.",
|
|
1076
1090
|
"container-server.ready": "A container environment's 2.x server this backend started answered `/api/info` as 2.x. Environment id only.",
|
|
1091
|
+
"container-server.cleanup-failed": "Cleanup after OpenCode startup failed; step names only, while the original startup error is preserved.",
|
|
1077
1092
|
"container-server.warm-incomplete": "The first workspace request to a container's new 2.x server failed, so its plugins load on the next one. Error class only.",
|
|
1078
1093
|
"resume-list.unavailable": "The 2.x sessions could not be listed for the resume picker, so it shows the 1.x list alone. Error class only.",
|
|
1079
1094
|
"credential.mirrored": "A provider sign-in change was copied into the 2.x database. `outcome` (written, removed, unchanged, skipped) only; never a provider id or value.",
|
|
@@ -1128,12 +1143,13 @@ var RUNTIME_LOG_AREAS = defineLogAreas({
|
|
|
1128
1143
|
description: "This process's event loop. A stall of 10 seconds or more is written at error, so no level hides it.",
|
|
1129
1144
|
events: {
|
|
1130
1145
|
stalled: {
|
|
1131
|
-
description: "A timer fired late, so every request in that window waited. In the backend the line also names what ran: `storageMs` and the `storage*` fields describe the slow SQLite calls in the window (`operation.slow` in `storage`), `commandsInFlight` and `commands` the commands running,
|
|
1146
|
+
description: "A timer fired late, so every request in that window waited. In the backend the line also names what ran: `storageMs` and the `storage*` fields describe the slow SQLite calls in the window (`operation.slow` in `storage`), `commandsInFlight` and `commands` the commands running, `blockingCommand` one whose synchronous part overlapped it, and `jobsInWindow` and `jobs` the recurring jobs that ran around it. `cpuMs` is the CPU time the process used in the window: near `lagMs` its own thread was busy, far below it the thread waited.",
|
|
1132
1147
|
essential: true,
|
|
1133
1148
|
minLevel: "error",
|
|
1134
1149
|
fields: {
|
|
1135
1150
|
lagMs: "number",
|
|
1136
1151
|
intervalMs: "number",
|
|
1152
|
+
cpuMs: "number",
|
|
1137
1153
|
storageMs: "number",
|
|
1138
1154
|
storageDatabase: "label",
|
|
1139
1155
|
storageOp: "label",
|
|
@@ -1141,7 +1157,8 @@ var RUNTIME_LOG_AREAS = defineLogAreas({
|
|
|
1141
1157
|
storageLongestMs: "number",
|
|
1142
1158
|
storageBusy: "boolean",
|
|
1143
1159
|
commandsInFlight: "number",
|
|
1144
|
-
blockingCommandMs: "number"
|
|
1160
|
+
blockingCommandMs: "number",
|
|
1161
|
+
jobsInWindow: "number"
|
|
1145
1162
|
}
|
|
1146
1163
|
}
|
|
1147
1164
|
}
|
|
@@ -1181,6 +1198,8 @@ var TERMINAL_LOG_AREAS = defineLogAreas({
|
|
|
1181
1198
|
"pty.exit-notify-failed": "Notifying a terminal's exit failed.",
|
|
1182
1199
|
"pty.late-exit-listener-failed": "A listener added after a terminal exited threw.",
|
|
1183
1200
|
"setup.pty-reused": "A setup terminal reused its existing PTY.",
|
|
1201
|
+
"setup.pty-retired": "A setup retry ended the terminal the previous run left open, so the new run gets its own.",
|
|
1202
|
+
"setup.pty-retire-failed": "A setup retry could not end the previous run's process tree, so it kept that terminal and started nothing.",
|
|
1184
1203
|
"setup.pty-spawning": "A setup terminal is spawning its PTY. The argument count only, never the arguments.",
|
|
1185
1204
|
"setup.pty-spawned": "A setup terminal's PTY started.",
|
|
1186
1205
|
"setup.pty-exited": "A setup terminal's PTY exited.",
|
|
@@ -1308,6 +1327,7 @@ var TMUX_LOG_AREAS = defineLogAreas({
|
|
|
1308
1327
|
"cleanup.skipped": "Environment tmux cleanup was skipped because tmux could not be reached and nothing required it.",
|
|
1309
1328
|
"cleanup.environments-load-failed": "Environments could not be loaded during tmux cleanup, so it stays incomplete.",
|
|
1310
1329
|
"cleanup.kill-failed": "An environment's tmux sessions could not be killed.",
|
|
1330
|
+
"cleanup.kill-incomplete": "An environment's tmux sessions could not all be shown gone (a session survived, or the socket was unreachable while another tmux process might own it), so cleanup stays incomplete.",
|
|
1311
1331
|
"hooks.uninstall-failed": "Workspace hooks could not be uninstalled.",
|
|
1312
1332
|
"hooks.git-exclude-failed": "The git exclude for Claude's local settings could not be set.",
|
|
1313
1333
|
"naming.prepare-failed": "First-prompt naming could not be prepared; the prompt still goes ahead.",
|
|
@@ -1437,6 +1457,7 @@ var STORAGE_LOG_AREAS = defineLogAreas({
|
|
|
1437
1457
|
"config.restrict-mode-failed": "A config file holding provider secrets could not be set to owner-only; the backend carries on.",
|
|
1438
1458
|
"legacy-json.moved": "JSON store files written after the SQLite migration were archived, not imported.",
|
|
1439
1459
|
"legacy-json.archive-failed": "Imported JSON store files could not be archived.",
|
|
1460
|
+
"native-session-owners.backfill-failed": "Native-session rows could not be given their environment as owner at open; an environment delete then parses those rows instead, and the next open retries.",
|
|
1440
1461
|
"lease.timed-out": "A waiter gave up on a lease; `lease` and `family` name it, `holderAgeMs` is the time since its holder's last heartbeat (null when the holder had just gone), `waitedMs` how long the waiter waited.",
|
|
1441
1462
|
"lease.heartbeat-failed": "A held lease's heartbeat failed, which shortens the lease; the next one retries.",
|
|
1442
1463
|
"scrub.vacuum-failed": "Deleted-content page reclamation failed; the checkpoint is attempted independently.",
|
|
@@ -1486,9 +1507,12 @@ var BUILD_PIPELINE_LOG_AREAS = defineLogAreas({
|
|
|
1486
1507
|
"transcripts.maintenance-failed": "Migrating or sweeping stage transcripts failed; the next start retries.",
|
|
1487
1508
|
"restore.skipped": "A pipeline could not be restored at startup and was skipped.",
|
|
1488
1509
|
"criteria.record-failed": "Acceptance criteria results could not be recorded on the ticket.",
|
|
1510
|
+
"completion-notes.publish-failed": "A finished pipeline's notes tab could not be added to the layout; the run stays complete.",
|
|
1489
1511
|
"workspace.waiting": "A pipeline is waiting for its workspace; written once per reason.",
|
|
1490
1512
|
"rewind.pending": "A pipeline's code rewind has not finished; written once per reason.",
|
|
1491
1513
|
"kanban.status-failed": "A restarted pipeline's Kanban status could not be set; it retries shortly.",
|
|
1514
|
+
"kanban.environment-deleted-read-failed": "The pipelines of an environment being deleted could not be read, so their tickets keep their columns.",
|
|
1515
|
+
"kanban.environment-deleted-update-failed": "The ticket of a pipeline whose environment was deleted could not be moved; the deletion goes on.",
|
|
1492
1516
|
"usage.read-failed": "Reading a stage session's token usage failed.",
|
|
1493
1517
|
"checkpoint.deferred": "A stage transcript checkpoint could not be written yet; the provider's history stands.",
|
|
1494
1518
|
"checkpoint.not-committed": "A stage transcript checkpoint was reverted in the commit that should have kept it.",
|
|
@@ -1527,6 +1551,8 @@ var CHANGE_TRACKING_LOG_AREAS = defineLogAreas({
|
|
|
1527
1551
|
"dispatch.record-failed": "Recording a turn's dispatch outcome failed.",
|
|
1528
1552
|
"turn.finalize-failed": "Finalizing a turn failed.",
|
|
1529
1553
|
"turn.settle-failed": "Settling a late interrupted turn failed.",
|
|
1554
|
+
"turn.end-recovery": "A background retry of a turn end capture that timed out finished: recovered, done (no longer eligible) or exhausted.",
|
|
1555
|
+
"turn.end-recovery-failed": "A background retry of a turn end capture threw; it counts as a failed attempt.",
|
|
1530
1556
|
"evidence.pull-failed": "Pulling change evidence from a bridge failed; a later pull retries.",
|
|
1531
1557
|
"measurement.failed": "Recomputing a tool's measurement failed."
|
|
1532
1558
|
}
|
|
@@ -1537,6 +1563,7 @@ var CHANGE_TRACKING_LOG_AREAS = defineLogAreas({
|
|
|
1537
1563
|
"baseline.update-failed": "An environment's diff baseline could not be updated.",
|
|
1538
1564
|
"scan.watcher-failed": "An environment's diff watcher failed; its scans fall back to polling.",
|
|
1539
1565
|
"scan.failed": "A diff scan failed; the last results stay, marked stale, and the scan is retried.",
|
|
1566
|
+
"scan.target-missing": "A local environment's worktree folder is missing (deleted, moved or on an unmounted drive); no scan runs, the last results stay, marked stale, and the folder is checked again on the failure backoff.",
|
|
1540
1567
|
"scan.freshness-read-failed": "Reading whether an environment's remote is fresh failed.",
|
|
1541
1568
|
"scan.listener-failed": "A change-tracking scan listener threw; the scan itself stands.",
|
|
1542
1569
|
"emit.diff-stats-failed": "A diff stats change could not be emitted to its sink.",
|
|
@@ -1595,6 +1622,7 @@ var COORDINATOR_LOG_AREAS = defineLogAreas({
|
|
|
1595
1622
|
"node-release.no-coordinator": "Work closed on a released node belonged to a coordinator that no longer exists, so nobody was told.",
|
|
1596
1623
|
"node-offline.notice-failed": "The notice that a node has been unreachable for a day could not be sent; the next failed read retries.",
|
|
1597
1624
|
"node-offline.check-failed": "Whether a long-unreachable node's coordinators were told could not be checked; the next read retries.",
|
|
1625
|
+
"node-reconnect.notice-failed": "The message that a node a coordinator tried while it was disconnected is back could not be sent; it is not retried, since the coordinator already holds the refusal.",
|
|
1598
1626
|
"checkout.merge-followed": "After an environment's PR merged, the project checkout was fast-forwarded, or `outcome` says why not.",
|
|
1599
1627
|
"checkout.merge-follow-failed": "Fast-forwarding the project checkout failed, after an environment's PR merged or before mail woke the main coordinator.",
|
|
1600
1628
|
"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`).",
|
|
@@ -1647,7 +1675,8 @@ var REVIEW_LOG_AREAS = defineLogAreas({
|
|
|
1647
1675
|
"monitor.task-store-failed": "A pull request could not be recorded on its Kanban task.",
|
|
1648
1676
|
"monitor.merged-tickets-closed": "The startup sweep moved Kanban tickets whose pull request had merged to done (`count`).",
|
|
1649
1677
|
"monitor.merged-tickets-close-failed": "The startup sweep closing Kanban tickets whose pull request merged failed; the next backend start retries.",
|
|
1650
|
-
"monitor.emit-failed": "A pull request monitor event could not be emitted to its sink."
|
|
1678
|
+
"monitor.emit-failed": "A pull request monitor event could not be emitted to its sink.",
|
|
1679
|
+
"branch-cleanup.kept": "A merge or cleanup kept a pull request's head branch because it is not the branch created for the environment (`reason`)."
|
|
1651
1680
|
}
|
|
1652
1681
|
}
|
|
1653
1682
|
});
|
|
@@ -1679,6 +1708,8 @@ var AGENT_ACCOUNTS_LOG_AREAS = defineLogAreas({
|
|
|
1679
1708
|
"kept-note.failed": "Recording why a limit stop found no account to move to failed; the stop stands.",
|
|
1680
1709
|
"container-sync.failed": "Handing a login or account to a container failed; `step` says which part.",
|
|
1681
1710
|
"last-usage.save-failed": "The last plan usage reading could not be saved; the next save retries.",
|
|
1711
|
+
"shared-usage.save-failed": "The shared usage readings could not be saved; they stay in memory and the next reading saves them.",
|
|
1712
|
+
"shared-usage.record-failed": "A fresh usage reading could not be kept for sharing with other machines; the account's own reading stands.",
|
|
1682
1713
|
"login-cleanup.failed": "A temporary login could not be cleaned up.",
|
|
1683
1714
|
"login-renewal.failed": "Renewing an idle account's sign-in to read its usage failed; it is retried after a backoff.",
|
|
1684
1715
|
"login-renewal.not-extended": "Claude Code ran to renew an idle account's sign-in, but its token is still lapsed.",
|
|
@@ -1696,6 +1727,7 @@ var DOCKER_LOG_AREAS = defineLogAreas({
|
|
|
1696
1727
|
"git-mirror.mount-unavailable": "A new container gets no project Git mirror, so its clone goes to the remote.",
|
|
1697
1728
|
"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.",
|
|
1698
1729
|
"git-mirror.refreshed": "A project's Git mirror was built or updated.",
|
|
1730
|
+
"git-mirror.access-changed": "A project's Git mirror was withdrawn because containers are now given a different credential (another access kind, or a token acting as another or an unreadable account), so no reader keeps what it could not fetch itself.",
|
|
1699
1731
|
"git-mirror.seeded": "A project's Git mirror was built from its host checkout and only what the remote added to it.",
|
|
1700
1732
|
"git-mirror.seed-skipped": "A project's host checkout could not seed its Git mirror, so the build downloads everything.",
|
|
1701
1733
|
"git-mirror.refresh-failed": "A project's Git mirror could not be updated. New clones still work, from the mirror as it was or from the remote.",
|
|
@@ -1709,6 +1741,9 @@ var DOCKER_LOG_AREAS = defineLogAreas({
|
|
|
1709
1741
|
"git-mirror.clone-fallback": "A new environment could not clone from its project's Git mirror and cloned from the remote.",
|
|
1710
1742
|
"project-seed.refused": "A project .env, .env.local or opencode.json was not copied into a new container: a link, not a regular file, outside the project, too large or unreadable.",
|
|
1711
1743
|
"opencode.warm-incomplete": "OpenCode did not finish loading /workspace in a container.",
|
|
1744
|
+
"opencode.listener-replaced": "The process on a container's OpenCode port (`provider`: `opencode` or `opencode2`) is not the server the backend launched and recorded, so its password was withheld and the next start replaces it. `stage` is `request` when the re-check after a refused connection or an unexpected answer found it; that connection then sends nothing more.",
|
|
1745
|
+
"opencode.project-config-too-large": "A checkout's opencode.json or opencode.jsonc was larger than the limit, so a launched OpenCode server does not read it. File name only.",
|
|
1746
|
+
"opencode.project-config-filtered": "Values were left out of a checkout's OpenCode configuration before a launched server reads it: counts of plugin keys, `{env:}` and `{file:}` references and dropped instructions (including separate instructionGlob and instructionUrl counts), and the names of files that were not a JSONC object. Never values.",
|
|
1712
1747
|
"log-driver.unbounded": "The Docker daemon offers neither the local nor the json-file log driver, so new containers keep its default driver, whose log may be uncapped. Written once per backend.",
|
|
1713
1748
|
"lifecycle-event.reconcile-failed": "Reconciling an environment after a container start or stop event failed; the next status read retries.",
|
|
1714
1749
|
"login-keeper.pass-failed": "A Claude login keeper pass failed; the next interval retries.",
|
|
@@ -1743,6 +1778,17 @@ var DOCKER_LOG_AREAS = defineLogAreas({
|
|
|
1743
1778
|
description: "A bridge process was launched in a container, for the first time there or as a relaunch; `provider` names it. A relaunch keeps the run before it in the previous log.",
|
|
1744
1779
|
essential: true,
|
|
1745
1780
|
fields: { provider: "label", containerPort: "number" }
|
|
1781
|
+
},
|
|
1782
|
+
"bridge.listener-refused": {
|
|
1783
|
+
description: "The socket listening on a container bridge's port is not the one the bridge the backend started opened, so its token is not handed out and the next start replaces it. `reason` is a fixed label: `different-socket`, `several-sockets`, `pending` (a start has not recorded its bridge yet, or failed before it did) or `scan-incomplete`.",
|
|
1784
|
+
essential: true,
|
|
1785
|
+
fields: { provider: "label", reason: "label" }
|
|
1786
|
+
},
|
|
1787
|
+
"bridge.listener-adopted": "A running container bridge had no listener record, because a backend from before the record started it, so the socket on its port was recorded as the bridge's; `provider` names it.",
|
|
1788
|
+
"bridge.listener-unrecorded": {
|
|
1789
|
+
description: "A bridge the backend just launched could not be recorded as its port's listener, for the fixed `reason` given (`no-listener`, `several-sockets`, `launch-exited` or `scan-incomplete`); what listens on the port is stopped and the start fails.",
|
|
1790
|
+
essential: true,
|
|
1791
|
+
fields: { provider: "label", reason: "label" }
|
|
1746
1792
|
}
|
|
1747
1793
|
}
|
|
1748
1794
|
},
|
|
@@ -1797,7 +1843,8 @@ var MCP_LOG_AREAS = defineLogAreas({
|
|
|
1797
1843
|
"listener.port-free": "The Control MCP's fixed port is free again, so it is listening.",
|
|
1798
1844
|
"state-listener.failed": "A Control MCP state listener threw; the others still run.",
|
|
1799
1845
|
"delegation.remote-open-failed": "A delegation could not be opened on another node.",
|
|
1800
|
-
"delegation.open-failed": "A coordinator delegation could not be opened."
|
|
1846
|
+
"delegation.open-failed": "A coordinator delegation could not be opened.",
|
|
1847
|
+
"delegation.turn-origin-unreadable": "A coordinator's last turn origin could not be read, so its delegated prompt is marked as arising from agent mail."
|
|
1801
1848
|
}
|
|
1802
1849
|
},
|
|
1803
1850
|
"mcp-management": {
|
|
@@ -1882,6 +1929,7 @@ var NODES_LOG_AREAS = defineLogAreas({
|
|
|
1882
1929
|
"ticket-sync.failed": "A Kanban sync with a node failed; it is retried.",
|
|
1883
1930
|
"ticket-sync.unknown-project": "A node sent ticket changes for a project that no longer exists here.",
|
|
1884
1931
|
"ticket-sync.forget-failed": "A detached command node's ticket copies could not be released.",
|
|
1932
|
+
"usage-sync.failed": "Sharing usage readings with a node failed; the next reading or reconnect retries.",
|
|
1885
1933
|
"fleet-update.requested": "The update policy asked an older leaf to install the command node's version.",
|
|
1886
1934
|
"fleet-update.failed": "The update policy could not read or update a leaf; it retries later.",
|
|
1887
1935
|
"fleet-update.policy-load-failed": "The stored update policy could not be read; it is off."
|
|
@@ -1973,6 +2021,20 @@ var SCHEDULER_LOG_AREAS = defineLogAreas({
|
|
|
1973
2021
|
}
|
|
1974
2022
|
});
|
|
1975
2023
|
|
|
2024
|
+
// ../protocol/src/log-vocabulary/self-improvement.ts
|
|
2025
|
+
var SELF_IMPROVEMENT_LOG_AREAS = defineLogAreas({
|
|
2026
|
+
"self-improvement": {
|
|
2027
|
+
description: "Self-improvement runs: diagnostics and conversation review turned into tickets. Counts and steps only, never conversation text.",
|
|
2028
|
+
events: {
|
|
2029
|
+
"run.started": "A run started; `trigger` is manual, daily or dry-run.",
|
|
2030
|
+
"run.finished": "A run finished; `created`, `verified`, `fixFailed` and `parts` count its tickets, confirmed fixes, failed fixes and conversation parts read.",
|
|
2031
|
+
"run.failed": "A run stopped before it finished; `reason` is a fixed label.",
|
|
2032
|
+
"review.call-failed": "One conversation review call failed; the run carries on and the part is read again next run.",
|
|
2033
|
+
"daily.check-failed": "The daily run check failed; the next check retries."
|
|
2034
|
+
}
|
|
2035
|
+
}
|
|
2036
|
+
});
|
|
2037
|
+
|
|
1976
2038
|
// ../protocol/src/log-vocabulary/web-app.ts
|
|
1977
2039
|
var WEB_APP_LOG_AREAS = defineLogAreas({
|
|
1978
2040
|
"web.app": {
|
|
@@ -2240,6 +2302,7 @@ var WEB_KANBAN_LOG_AREAS = defineLogAreas({
|
|
|
2240
2302
|
"task.move-failed": "A task move failed and its status was rolled back.",
|
|
2241
2303
|
"comment.add-failed": "A comment could not be added to a task.",
|
|
2242
2304
|
"comment.delete-failed": "A comment could not be deleted from a task.",
|
|
2305
|
+
"pr.merge-failed": "Merging a ticket's pull request from its Notes tab failed; the error was shown to the user.",
|
|
2243
2306
|
"image.add-failed": "An image could not be added to a task.",
|
|
2244
2307
|
"image.delete-failed": "An image could not be deleted from a task.",
|
|
2245
2308
|
"notes.load-failed": "Project notes could not be loaded; the editor stays disabled.",
|
|
@@ -2308,6 +2371,10 @@ var WEB_SETTINGS_LOG_AREAS = defineLogAreas({
|
|
|
2308
2371
|
"web.settings": {
|
|
2309
2372
|
description: "The settings screens.",
|
|
2310
2373
|
events: {
|
|
2374
|
+
"self-improvement.status-failed": "Settings → Self-improvement could not read the status.",
|
|
2375
|
+
"self-improvement.projects-failed": "Settings → Self-improvement could not list the projects.",
|
|
2376
|
+
"self-improvement.save-failed": "Settings → Self-improvement could not save a setting.",
|
|
2377
|
+
"self-improvement.run-failed": "Settings → Self-improvement could not start a run.",
|
|
2311
2378
|
"config.save-failed": "Global settings could not be saved.",
|
|
2312
2379
|
"config.load-failed": "The settings page could not load the config.",
|
|
2313
2380
|
"config.reload-failed": "Re-reading the workspace config after a save failed.",
|
|
@@ -2477,6 +2544,7 @@ var LOG_VOCABULARY = {
|
|
|
2477
2544
|
...HOST_LOG_AREAS,
|
|
2478
2545
|
...TRANSCRIPT_ARTIFACTS_LOG_AREAS,
|
|
2479
2546
|
...SCHEDULER_LOG_AREAS,
|
|
2547
|
+
...SELF_IMPROVEMENT_LOG_AREAS,
|
|
2480
2548
|
...WEB_APP_LOG_AREAS,
|
|
2481
2549
|
...WEB_BUILD_PIPELINE_LOG_AREAS,
|
|
2482
2550
|
...WEB_CHAT_LOG_AREAS,
|
|
@@ -2598,6 +2666,14 @@ var SIGNALS = new Set([
|
|
|
2598
2666
|
"SIGXFSZ"
|
|
2599
2667
|
]);
|
|
2600
2668
|
var PROVIDERS = new Set(["claude", "codex", "opencode", "cursor", "grok", "acp", "pi"]);
|
|
2669
|
+
var BRIDGE_LISTENER_REASONS = new Set([
|
|
2670
|
+
"different-socket",
|
|
2671
|
+
"several-sockets",
|
|
2672
|
+
"pending",
|
|
2673
|
+
"scan-incomplete",
|
|
2674
|
+
"no-listener",
|
|
2675
|
+
"launch-exited"
|
|
2676
|
+
]);
|
|
2601
2677
|
var UUID = "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}";
|
|
2602
2678
|
var SOURCE = new RegExp(`^(?:claude|codex|opencode|cursor|grok|acp|pi):${UUID}$`, "i");
|
|
2603
2679
|
var STORAGE_DATABASES = new Set(["main", "ledger", "other"]);
|
|
@@ -3459,6 +3535,56 @@ function turnTokenTotal(usage) {
|
|
|
3459
3535
|
}
|
|
3460
3536
|
// ../../bridges/cursor-bridge/src/credentials.ts
|
|
3461
3537
|
import { Cursor, FileCredentialStore } from "@cursor/sdk";
|
|
3538
|
+
|
|
3539
|
+
// ../protocol/src/node/bounded-wait.ts
|
|
3540
|
+
function boundedWait(work, timeoutMs, options = {}) {
|
|
3541
|
+
return new Promise((resolve, reject) => {
|
|
3542
|
+
let timedOut = false;
|
|
3543
|
+
const timer = setTimeout(() => {
|
|
3544
|
+
timedOut = true;
|
|
3545
|
+
resolve({ settled: false });
|
|
3546
|
+
}, timeoutMs);
|
|
3547
|
+
unrefTimer(timer);
|
|
3548
|
+
Promise.resolve(work).then((value) => {
|
|
3549
|
+
if (!timedOut) {
|
|
3550
|
+
clearTimeout(timer);
|
|
3551
|
+
resolve({ settled: true, value });
|
|
3552
|
+
return;
|
|
3553
|
+
}
|
|
3554
|
+
disposeLate(options.onLate, value);
|
|
3555
|
+
}, (error) => {
|
|
3556
|
+
if (!timedOut) {
|
|
3557
|
+
clearTimeout(timer);
|
|
3558
|
+
reject(error);
|
|
3559
|
+
}
|
|
3560
|
+
});
|
|
3561
|
+
});
|
|
3562
|
+
}
|
|
3563
|
+
async function boundedWaitOrThrow(work, timeoutMs, timeoutError, options = {}) {
|
|
3564
|
+
const result = await boundedWait(work, timeoutMs, options);
|
|
3565
|
+
if (!result.settled)
|
|
3566
|
+
throw timeoutError();
|
|
3567
|
+
return result.value;
|
|
3568
|
+
}
|
|
3569
|
+
function unrefTimer(timer) {
|
|
3570
|
+
const handle = timer;
|
|
3571
|
+
if (typeof handle === "object" && typeof handle.unref === "function")
|
|
3572
|
+
handle.unref();
|
|
3573
|
+
}
|
|
3574
|
+
function disposeLate(onLate, value) {
|
|
3575
|
+
if (!onLate)
|
|
3576
|
+
return;
|
|
3577
|
+
try {
|
|
3578
|
+
const disposal = onLate(value);
|
|
3579
|
+
if (disposal && typeof disposal.then === "function") {
|
|
3580
|
+
Promise.resolve(disposal).catch(() => {
|
|
3581
|
+
return;
|
|
3582
|
+
});
|
|
3583
|
+
}
|
|
3584
|
+
} catch {}
|
|
3585
|
+
}
|
|
3586
|
+
|
|
3587
|
+
// ../../bridges/cursor-bridge/src/credentials.ts
|
|
3462
3588
|
var CURSOR_AUTHENTICATION_REQUIRED_MESSAGE = "Cursor is not signed in. Sign in from Settings › Cursor, or set a Cursor API key.";
|
|
3463
3589
|
var AUTH_CACHE_TTL_MS = 15000;
|
|
3464
3590
|
var authCache;
|
|
@@ -3579,23 +3705,11 @@ async function lookUpAccount(credential) {
|
|
|
3579
3705
|
if (entry.timedOut)
|
|
3580
3706
|
return { settled: false, account: undefined };
|
|
3581
3707
|
const active = entry;
|
|
3582
|
-
const
|
|
3583
|
-
|
|
3584
|
-
|
|
3585
|
-
|
|
3586
|
-
|
|
3587
|
-
new Promise((resolve) => {
|
|
3588
|
-
timer = setTimeout(() => {
|
|
3589
|
-
active.timedOut = true;
|
|
3590
|
-
resolve({ settled: false, account: undefined });
|
|
3591
|
-
}, accountLookupTimeoutMs);
|
|
3592
|
-
timer.unref();
|
|
3593
|
-
})
|
|
3594
|
-
]);
|
|
3595
|
-
} finally {
|
|
3596
|
-
if (timer)
|
|
3597
|
-
clearTimeout(timer);
|
|
3598
|
-
}
|
|
3708
|
+
const outcome = await boundedWait(entry.result, accountLookupTimeoutMs);
|
|
3709
|
+
if (outcome.settled)
|
|
3710
|
+
return { settled: true, account: outcome.value };
|
|
3711
|
+
active.timedOut = true;
|
|
3712
|
+
return { settled: false, account: undefined };
|
|
3599
3713
|
}
|
|
3600
3714
|
function beginLogin(options = {}) {
|
|
3601
3715
|
const controller = new AbortController;
|
|
@@ -3858,20 +3972,8 @@ function boundId(value) {
|
|
|
3858
3972
|
const trimmed = value?.trim() ?? "";
|
|
3859
3973
|
return Buffer.byteLength(trimmed) > MAX_MODEL_ID_BYTES ? "" : trimmed;
|
|
3860
3974
|
}
|
|
3861
|
-
|
|
3862
|
-
|
|
3863
|
-
try {
|
|
3864
|
-
return await Promise.race([
|
|
3865
|
-
work,
|
|
3866
|
-
new Promise((_, reject) => {
|
|
3867
|
-
timer = setTimeout(() => reject(new Error("Cursor catalogue read timed out")), timeoutMs);
|
|
3868
|
-
timer.unref();
|
|
3869
|
-
})
|
|
3870
|
-
]);
|
|
3871
|
-
} finally {
|
|
3872
|
-
if (timer)
|
|
3873
|
-
clearTimeout(timer);
|
|
3874
|
-
}
|
|
3975
|
+
function withTimeout(work, timeoutMs) {
|
|
3976
|
+
return boundedWaitOrThrow(work, timeoutMs, () => new Error("Cursor catalogue read timed out"));
|
|
3875
3977
|
}
|
|
3876
3978
|
// ../../bridges/cursor-bridge/src/mcp.ts
|
|
3877
3979
|
import { promises as fs } from "node:fs";
|
|
@@ -27266,6 +27368,58 @@ var PROTECTED_SEGMENTS = new Set([
|
|
|
27266
27368
|
".mcp.json"
|
|
27267
27369
|
]);
|
|
27268
27370
|
|
|
27371
|
+
// ../protocol/src/agent-mail.ts
|
|
27372
|
+
var AGENT_MAIL_MAX_BODY_BYTES = 32 * 1024;
|
|
27373
|
+
var AGENT_MAIL_MAX_STORE_BYTES = 32 * 1024 * 1024;
|
|
27374
|
+
var AGENT_MAIL_DEFAULT_RETENTION_DAYS = 14;
|
|
27375
|
+
var AGENT_MAIL_MAX_ATTACHMENT_BYTES = 8 * 1024 * 1024;
|
|
27376
|
+
var AGENT_MAIL_MAX_TOTAL_ATTACHMENT_BYTES = 32 * 1024 * 1024;
|
|
27377
|
+
var AGENT_MAIL_DEFAULT_AUTONOMOUS_WAKE_BUDGET = 16;
|
|
27378
|
+
var AGENT_MAIL_DEFAULT_HOURLY_WAKE_LIMIT = 40;
|
|
27379
|
+
var AGENT_MAIL_TOOL_NAMES = Object.freeze([
|
|
27380
|
+
"list_mailboxes",
|
|
27381
|
+
"send_message",
|
|
27382
|
+
"check_inbox",
|
|
27383
|
+
"read_message",
|
|
27384
|
+
"ack_message",
|
|
27385
|
+
"reply_message",
|
|
27386
|
+
"get_message_status"
|
|
27387
|
+
]);
|
|
27388
|
+
var DEFAULT_AGENT_MESSAGING_SETTINGS = Object.freeze({
|
|
27389
|
+
enabled: true,
|
|
27390
|
+
allowCrossProject: false,
|
|
27391
|
+
defaultInjectPolicy: "off",
|
|
27392
|
+
wakePeers: false,
|
|
27393
|
+
autonomousWakeBudget: AGENT_MAIL_DEFAULT_AUTONOMOUS_WAKE_BUDGET,
|
|
27394
|
+
hourlyWakeLimit: AGENT_MAIL_DEFAULT_HOURLY_WAKE_LIMIT,
|
|
27395
|
+
coordinatorStatusWakes: "settled",
|
|
27396
|
+
retentionDays: AGENT_MAIL_DEFAULT_RETENTION_DAYS,
|
|
27397
|
+
paused: false
|
|
27398
|
+
});
|
|
27399
|
+
function agentMailCapabilities(tabType, agent, locked = true) {
|
|
27400
|
+
if (tabType === "agent-native") {
|
|
27401
|
+
if (!locked || !agent)
|
|
27402
|
+
return { canPull: false, canSend: false, canInject: false };
|
|
27403
|
+
if (agent === "claude" || agent === "codex" || agent === "opencode" || agent === "pi" || agent === "cursor" || agent === "grok") {
|
|
27404
|
+
return { canPull: true, canSend: true, canInject: true };
|
|
27405
|
+
}
|
|
27406
|
+
return { canPull: false, canSend: false, canInject: false };
|
|
27407
|
+
}
|
|
27408
|
+
if (tabType === "claude-tmux")
|
|
27409
|
+
return { canPull: true, canSend: true, canInject: true };
|
|
27410
|
+
if (tabType === "pipeline-worker") {
|
|
27411
|
+
return agent ? { canPull: true, canSend: true, canInject: true } : { canPull: false, canSend: false, canInject: false };
|
|
27412
|
+
}
|
|
27413
|
+
if (["claude", "codex", "opencode"].includes(tabType)) {
|
|
27414
|
+
return { canPull: true, canSend: true, canInject: false };
|
|
27415
|
+
}
|
|
27416
|
+
if (["cursor", "grok", "pi"].includes(tabType)) {
|
|
27417
|
+
return { canPull: false, canSend: false, canInject: false };
|
|
27418
|
+
}
|
|
27419
|
+
return { canPull: false, canSend: false, canInject: false };
|
|
27420
|
+
}
|
|
27421
|
+
var NATIVE_AGENT_MAIL_CAPABILITIES = Object.freeze(Object.fromEntries(AGENT_PLATFORMS.map((agent) => [agent, agentMailCapabilities("agent-native", agent)])));
|
|
27422
|
+
|
|
27269
27423
|
// ../protocol/src/review-evidence-frames.ts
|
|
27270
27424
|
var SYSTEM_INSTRUCTIONS_FRAME_OPEN = "<orkestrator-system-instructions>";
|
|
27271
27425
|
var SYSTEM_INSTRUCTIONS_FRAME_CLOSE = "</orkestrator-system-instructions>";
|
|
@@ -27850,6 +28004,11 @@ var BACKGROUND_CAPABLE_SHELL_TOOL_NAMES = new Set([
|
|
|
27850
28004
|
"run_terminal_cmd",
|
|
27851
28005
|
"execute_command"
|
|
27852
28006
|
]);
|
|
28007
|
+
var NATIVE_AGENT_BRANCH_LIST_LIMITS = Object.freeze({
|
|
28008
|
+
branches: 50,
|
|
28009
|
+
promptChars: 280,
|
|
28010
|
+
entryIdChars: 512
|
|
28011
|
+
});
|
|
27853
28012
|
var NATIVE_AGENT_COMMAND_EXECUTION_KINDS = [
|
|
27854
28013
|
"provider-prompt",
|
|
27855
28014
|
"provider-command",
|
|
@@ -28975,58 +29134,6 @@ function transcriptBoundSummary(state) {
|
|
|
28975
29134
|
};
|
|
28976
29135
|
}
|
|
28977
29136
|
|
|
28978
|
-
// ../protocol/src/agent-mail.ts
|
|
28979
|
-
var AGENT_MAIL_MAX_BODY_BYTES = 32 * 1024;
|
|
28980
|
-
var AGENT_MAIL_MAX_STORE_BYTES = 32 * 1024 * 1024;
|
|
28981
|
-
var AGENT_MAIL_DEFAULT_RETENTION_DAYS = 14;
|
|
28982
|
-
var AGENT_MAIL_MAX_ATTACHMENT_BYTES = 8 * 1024 * 1024;
|
|
28983
|
-
var AGENT_MAIL_MAX_TOTAL_ATTACHMENT_BYTES = 32 * 1024 * 1024;
|
|
28984
|
-
var AGENT_MAIL_DEFAULT_AUTONOMOUS_WAKE_BUDGET = 16;
|
|
28985
|
-
var AGENT_MAIL_DEFAULT_HOURLY_WAKE_LIMIT = 40;
|
|
28986
|
-
var AGENT_MAIL_TOOL_NAMES = Object.freeze([
|
|
28987
|
-
"list_mailboxes",
|
|
28988
|
-
"send_message",
|
|
28989
|
-
"check_inbox",
|
|
28990
|
-
"read_message",
|
|
28991
|
-
"ack_message",
|
|
28992
|
-
"reply_message",
|
|
28993
|
-
"get_message_status"
|
|
28994
|
-
]);
|
|
28995
|
-
var DEFAULT_AGENT_MESSAGING_SETTINGS = Object.freeze({
|
|
28996
|
-
enabled: true,
|
|
28997
|
-
allowCrossProject: false,
|
|
28998
|
-
defaultInjectPolicy: "off",
|
|
28999
|
-
wakePeers: false,
|
|
29000
|
-
autonomousWakeBudget: AGENT_MAIL_DEFAULT_AUTONOMOUS_WAKE_BUDGET,
|
|
29001
|
-
hourlyWakeLimit: AGENT_MAIL_DEFAULT_HOURLY_WAKE_LIMIT,
|
|
29002
|
-
coordinatorStatusWakes: "settled",
|
|
29003
|
-
retentionDays: AGENT_MAIL_DEFAULT_RETENTION_DAYS,
|
|
29004
|
-
paused: false
|
|
29005
|
-
});
|
|
29006
|
-
function agentMailCapabilities(tabType, agent, locked = true) {
|
|
29007
|
-
if (tabType === "agent-native") {
|
|
29008
|
-
if (!locked || !agent)
|
|
29009
|
-
return { canPull: false, canSend: false, canInject: false };
|
|
29010
|
-
if (agent === "claude" || agent === "codex" || agent === "opencode" || agent === "pi" || agent === "cursor" || agent === "grok") {
|
|
29011
|
-
return { canPull: true, canSend: true, canInject: true };
|
|
29012
|
-
}
|
|
29013
|
-
return { canPull: false, canSend: false, canInject: false };
|
|
29014
|
-
}
|
|
29015
|
-
if (tabType === "claude-tmux")
|
|
29016
|
-
return { canPull: true, canSend: true, canInject: true };
|
|
29017
|
-
if (tabType === "pipeline-worker") {
|
|
29018
|
-
return agent ? { canPull: true, canSend: true, canInject: true } : { canPull: false, canSend: false, canInject: false };
|
|
29019
|
-
}
|
|
29020
|
-
if (["claude", "codex", "opencode"].includes(tabType)) {
|
|
29021
|
-
return { canPull: true, canSend: true, canInject: false };
|
|
29022
|
-
}
|
|
29023
|
-
if (["cursor", "grok", "pi"].includes(tabType)) {
|
|
29024
|
-
return { canPull: false, canSend: false, canInject: false };
|
|
29025
|
-
}
|
|
29026
|
-
return { canPull: false, canSend: false, canInject: false };
|
|
29027
|
-
}
|
|
29028
|
-
var NATIVE_AGENT_MAIL_CAPABILITIES = Object.freeze(Object.fromEntries(AGENT_PLATFORMS.map((agent) => [agent, agentMailCapabilities("agent-native", agent)])));
|
|
29029
|
-
|
|
29030
29137
|
// ../protocol/src/transcript-artifacts.ts
|
|
29031
29138
|
var ARTIFACT_TOOL_NAMES = Object.freeze([
|
|
29032
29139
|
"create_artifact",
|
|
@@ -29445,33 +29552,12 @@ async function hostServerTools(input) {
|
|
|
29445
29552
|
}
|
|
29446
29553
|
async function connectWithTimeout(transport, url, token) {
|
|
29447
29554
|
const controller = new AbortController;
|
|
29448
|
-
const attempt = transport.connect(url, token, controller.signal);
|
|
29449
|
-
let timedOut = false;
|
|
29450
|
-
let timer;
|
|
29451
|
-
const deadline = new Promise((_resolve, reject) => {
|
|
29452
|
-
timer = setTimeout(() => {
|
|
29453
|
-
timedOut = true;
|
|
29454
|
-
controller.abort();
|
|
29455
|
-
reject(new Error("Orkestrator MCP timed out"));
|
|
29456
|
-
}, connectTimeoutMs);
|
|
29457
|
-
timer.unref();
|
|
29458
|
-
});
|
|
29459
29555
|
try {
|
|
29460
|
-
return await
|
|
29556
|
+
return await boundedWaitOrThrow(transport.connect(url, token, controller.signal), connectTimeoutMs, () => new Error("Orkestrator MCP timed out"), { onLate: (late) => late.close() });
|
|
29461
29557
|
} catch (error) {
|
|
29462
29558
|
if (!controller.signal.aborted)
|
|
29463
29559
|
controller.abort();
|
|
29464
|
-
if (timedOut) {
|
|
29465
|
-
attempt.then((late) => late.close().catch(() => {
|
|
29466
|
-
return;
|
|
29467
|
-
}), () => {
|
|
29468
|
-
return;
|
|
29469
|
-
});
|
|
29470
|
-
}
|
|
29471
29560
|
throw error;
|
|
29472
|
-
} finally {
|
|
29473
|
-
if (timer)
|
|
29474
|
-
clearTimeout(timer);
|
|
29475
29561
|
}
|
|
29476
29562
|
}
|
|
29477
29563
|
var defaultTransport = {
|
|
@@ -31232,8 +31318,8 @@ function cursorAppliedPolicy(state) {
|
|
|
31232
31318
|
// ../../bridges/cursor-bridge/src/agent-session.ts
|
|
31233
31319
|
import { createHash as createHash7, randomBytes as randomBytes6 } from "node:crypto";
|
|
31234
31320
|
import { readFile as readFile2 } from "node:fs/promises";
|
|
31235
|
-
import { homedir as
|
|
31236
|
-
import { join as
|
|
31321
|
+
import { homedir as homedir5 } from "node:os";
|
|
31322
|
+
import { join as join9 } from "node:path";
|
|
31237
31323
|
|
|
31238
31324
|
// ../../bridges/cursor-bridge/src/persistence.ts
|
|
31239
31325
|
import { randomBytes as randomBytes5 } from "node:crypto";
|
|
@@ -31828,7 +31914,7 @@ async function sweepTemporaries(stateFile) {
|
|
|
31828
31914
|
continue;
|
|
31829
31915
|
const middle = name.slice(prefix.length, -".tmp".length);
|
|
31830
31916
|
const match = TEMPORARY_NAME.exec(middle);
|
|
31831
|
-
if (
|
|
31917
|
+
if (!match)
|
|
31832
31918
|
continue;
|
|
31833
31919
|
const path = join3(directory, name);
|
|
31834
31920
|
if (match?.[1] !== String(process.pid)) {
|
|
@@ -32317,20 +32403,8 @@ async function cancelSurvivingRuns(agentId, cancelTimeoutMs) {
|
|
|
32317
32403
|
const stopped = await Promise.all(running.map((run) => withTimeout2(Promise.resolve().then(() => run.cancel()), cancelTimeoutMs).then(() => true, () => false)));
|
|
32318
32404
|
return stopped.every(Boolean) ? "cancelled" : "running";
|
|
32319
32405
|
}
|
|
32320
|
-
|
|
32321
|
-
|
|
32322
|
-
try {
|
|
32323
|
-
return await Promise.race([
|
|
32324
|
-
work,
|
|
32325
|
-
new Promise((_, reject) => {
|
|
32326
|
-
timer = setTimeout(() => reject(new Error("Cursor history read timed out")), timeoutMs);
|
|
32327
|
-
timer.unref();
|
|
32328
|
-
})
|
|
32329
|
-
]);
|
|
32330
|
-
} finally {
|
|
32331
|
-
if (timer)
|
|
32332
|
-
clearTimeout(timer);
|
|
32333
|
-
}
|
|
32406
|
+
function withTimeout2(work, timeoutMs) {
|
|
32407
|
+
return boundedWaitOrThrow(work, timeoutMs, () => new Error("Cursor history read timed out"));
|
|
32334
32408
|
}
|
|
32335
32409
|
|
|
32336
32410
|
// ../../bridges/cursor-bridge/src/session-tombstones.ts
|
|
@@ -32338,8 +32412,8 @@ var log3 = createLogger("bridge.cursor");
|
|
|
32338
32412
|
async function closeRestoredTombstone(id, ackTimeoutMs = CLOSE_ACK_TIMEOUT_MS) {
|
|
32339
32413
|
if (!closingTombstones.has(id) && !tombstoneCloses.has(id))
|
|
32340
32414
|
return "closed";
|
|
32341
|
-
const outcome = await
|
|
32342
|
-
return outcome
|
|
32415
|
+
const outcome = await boundedWait(finishTombstone(id), ackTimeoutMs);
|
|
32416
|
+
return outcome.settled ? outcome.value : "pending";
|
|
32343
32417
|
}
|
|
32344
32418
|
var tombstoneCloses = new Map;
|
|
32345
32419
|
var publishingTombstones = new Map;
|
|
@@ -32422,21 +32496,6 @@ async function finishRestoredTombstones() {
|
|
|
32422
32496
|
}
|
|
32423
32497
|
return result;
|
|
32424
32498
|
}
|
|
32425
|
-
async function withBudget(work, timeoutMs) {
|
|
32426
|
-
let timer;
|
|
32427
|
-
try {
|
|
32428
|
-
return await Promise.race([
|
|
32429
|
-
work,
|
|
32430
|
-
new Promise((resolve) => {
|
|
32431
|
-
timer = setTimeout(() => resolve("timeout"), timeoutMs);
|
|
32432
|
-
timer.unref?.();
|
|
32433
|
-
})
|
|
32434
|
-
]);
|
|
32435
|
-
} finally {
|
|
32436
|
-
if (timer)
|
|
32437
|
-
clearTimeout(timer);
|
|
32438
|
-
}
|
|
32439
|
-
}
|
|
32440
32499
|
|
|
32441
32500
|
// ../protocol/src/node/cursor-plan-usage.ts
|
|
32442
32501
|
import { Buffer as Buffer4 } from "node:buffer";
|
|
@@ -32651,6 +32710,1092 @@ function schedulePlanAccountRefresh(timeoutMs = CATALOG_TIMEOUT_MS) {
|
|
|
32651
32710
|
});
|
|
32652
32711
|
}
|
|
32653
32712
|
|
|
32713
|
+
// ../../bridges/cursor-bridge/src/read-boundary.ts
|
|
32714
|
+
import { homedir as homedir4 } from "node:os";
|
|
32715
|
+
import { isAbsolute as isAbsolute5, resolve as resolve6, sep as sep5 } from "node:path";
|
|
32716
|
+
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
32717
|
+
// ../protocol/src/coordinator.ts
|
|
32718
|
+
var COORDINATOR_PROTECTED_DATA_DIR_ENV = "ORKESTRATOR_COORDINATOR_PROTECTED_DATA_DIR";
|
|
32719
|
+
var COORDINATOR_OTHER_ENVIRONMENTS_SETTING_LABEL = "Let the coordinator use environments it did not create";
|
|
32720
|
+
var COORDINATOR_ENVIRONMENT_ORIGIN_REFUSAL = `Not done: this coordinator did not create that environment, so it may not send it work. Do not retry. Use an environment this coordinator launched, or start a new one. If the user wants this coordinator to work in environments it did not create, tell them to turn on "${COORDINATOR_OTHER_ENVIRONMENTS_SETTING_LABEL}" in this project's settings, under Coordinator.`;
|
|
32721
|
+
var COORDINATOR_CONTROL_TOOL_NAMES = Object.freeze([
|
|
32722
|
+
"mark_topic",
|
|
32723
|
+
"mark_question",
|
|
32724
|
+
"ack_message",
|
|
32725
|
+
"add_ticket_comment",
|
|
32726
|
+
"address_multi_review",
|
|
32727
|
+
"adopt_workflow",
|
|
32728
|
+
"answer_worker_question",
|
|
32729
|
+
"ask_agents",
|
|
32730
|
+
"cancel_build_pipeline",
|
|
32731
|
+
"cancel_graph_run",
|
|
32732
|
+
"cancel_multi_review",
|
|
32733
|
+
"cancel_schedule",
|
|
32734
|
+
"clear_worker_goal",
|
|
32735
|
+
"compare_project_files",
|
|
32736
|
+
"create_pr",
|
|
32737
|
+
"create_schedule",
|
|
32738
|
+
"create_ticket",
|
|
32739
|
+
"create_ticket_label",
|
|
32740
|
+
"custom_fix_multi_review",
|
|
32741
|
+
"edit_worker_tab",
|
|
32742
|
+
"fork_worker",
|
|
32743
|
+
"get_build_pipeline",
|
|
32744
|
+
"get_environment",
|
|
32745
|
+
"get_feature_plan",
|
|
32746
|
+
"get_graph_run",
|
|
32747
|
+
"get_launch_options",
|
|
32748
|
+
"get_message",
|
|
32749
|
+
"get_message_status",
|
|
32750
|
+
"get_multi_review",
|
|
32751
|
+
"get_repository_context",
|
|
32752
|
+
"get_tab_state",
|
|
32753
|
+
"get_tab_transcript",
|
|
32754
|
+
"get_ticket",
|
|
32755
|
+
"get_usage_limits",
|
|
32756
|
+
"get_worker_changes",
|
|
32757
|
+
"get_worker_goal",
|
|
32758
|
+
"launch_environment",
|
|
32759
|
+
"launch_feature_plan",
|
|
32760
|
+
"launch_graph",
|
|
32761
|
+
"launch_job",
|
|
32762
|
+
"launch_multi_review",
|
|
32763
|
+
"launch_terminal",
|
|
32764
|
+
"list_agents",
|
|
32765
|
+
"list_environments",
|
|
32766
|
+
"list_graph_templates",
|
|
32767
|
+
"list_mailboxes",
|
|
32768
|
+
"list_nodes",
|
|
32769
|
+
"list_projects",
|
|
32770
|
+
"list_provider_accounts",
|
|
32771
|
+
"list_schedules",
|
|
32772
|
+
"list_tabs",
|
|
32773
|
+
"list_ticket_labels",
|
|
32774
|
+
"list_tickets",
|
|
32775
|
+
"list_worker_commands",
|
|
32776
|
+
"list_workflows",
|
|
32777
|
+
"open_multi_review",
|
|
32778
|
+
"open_multi_review_fix",
|
|
32779
|
+
"open_worker_browser",
|
|
32780
|
+
"pause_build_pipeline",
|
|
32781
|
+
"pause_schedule",
|
|
32782
|
+
"pause_worker_goal",
|
|
32783
|
+
"propose_agents_md_update",
|
|
32784
|
+
"read_messages",
|
|
32785
|
+
"read_node_environment",
|
|
32786
|
+
"request_env_value_reveal",
|
|
32787
|
+
"request_environment_deletion",
|
|
32788
|
+
"request_project_file_update",
|
|
32789
|
+
"request_project_on_node",
|
|
32790
|
+
"request_root_changes",
|
|
32791
|
+
"resolve_conflicts",
|
|
32792
|
+
"restart_build_pipeline_step",
|
|
32793
|
+
"resume_build_pipeline",
|
|
32794
|
+
"resume_schedule",
|
|
32795
|
+
"run_worker_command",
|
|
32796
|
+
"send_message",
|
|
32797
|
+
"send_prompt_to_tab",
|
|
32798
|
+
"set_ticket_label",
|
|
32799
|
+
"set_worker_goal",
|
|
32800
|
+
"start_build_pipeline",
|
|
32801
|
+
"start_environment",
|
|
32802
|
+
"stop_environment",
|
|
32803
|
+
"stop_worker_turn",
|
|
32804
|
+
"switch_provider_account",
|
|
32805
|
+
"set_account_auto_switch",
|
|
32806
|
+
"transfer_files",
|
|
32807
|
+
"update_schedule",
|
|
32808
|
+
"update_ticket"
|
|
32809
|
+
]);
|
|
32810
|
+
var COORDINATOR_PROJECT_HOME_MESSAGE_WINDOW_MS = 3 * 60 * 60000;
|
|
32811
|
+
|
|
32812
|
+
// ../protocol/src/node/coordinator-read-boundary.ts
|
|
32813
|
+
import { realpathSync as realpathSync2 } from "node:fs";
|
|
32814
|
+
import { homedir as homedir3 } from "node:os";
|
|
32815
|
+
import { dirname as dirname2, isAbsolute as isAbsolute2, join as join4, parse as parse4, resolve as resolve3, sep as sep2 } from "node:path";
|
|
32816
|
+
function canonicalPath(path) {
|
|
32817
|
+
let existing = path;
|
|
32818
|
+
const tail = [];
|
|
32819
|
+
for (;; ) {
|
|
32820
|
+
try {
|
|
32821
|
+
return join4(realpathSync2.native(existing), ...tail.reverse());
|
|
32822
|
+
} catch {
|
|
32823
|
+
const parent = dirname2(existing);
|
|
32824
|
+
if (parent === existing)
|
|
32825
|
+
return path;
|
|
32826
|
+
tail.push(existing.slice(parent.length).replace(/^[/\\]+/, ""));
|
|
32827
|
+
existing = parent;
|
|
32828
|
+
}
|
|
32829
|
+
}
|
|
32830
|
+
}
|
|
32831
|
+
function namedAndCanonicalPaths(paths) {
|
|
32832
|
+
const named = paths.flatMap((path) => path?.trim() && isAbsolute2(path) ? [path] : []);
|
|
32833
|
+
return [...new Set(named.flatMap((path) => [resolve3(path), canonicalPath(path)]))];
|
|
32834
|
+
}
|
|
32835
|
+
function isWithin2(root, path) {
|
|
32836
|
+
if (path === root)
|
|
32837
|
+
return true;
|
|
32838
|
+
const prefix = root === parse4(root).root ? root : `${root}${sep2}`;
|
|
32839
|
+
return path.startsWith(prefix);
|
|
32840
|
+
}
|
|
32841
|
+
function protectedDataDirBoundary(dataDir, allowances) {
|
|
32842
|
+
const trimmed = dataDir?.trim();
|
|
32843
|
+
if (!trimmed || !isAbsolute2(trimmed))
|
|
32844
|
+
return null;
|
|
32845
|
+
const deny = namedAndCanonicalPaths([trimmed]);
|
|
32846
|
+
return {
|
|
32847
|
+
deny,
|
|
32848
|
+
allow: namedAndCanonicalPaths(allowances).filter((path) => !deny.includes(path) && deny.some((root) => isWithin2(root, path)))
|
|
32849
|
+
};
|
|
32850
|
+
}
|
|
32851
|
+
function deniedForm(boundary, path) {
|
|
32852
|
+
return boundary.deny.some((root) => isWithin2(root, path)) && !boundary.allow.some((root) => isWithin2(root, path));
|
|
32853
|
+
}
|
|
32854
|
+
function expandedHome(path) {
|
|
32855
|
+
if (path === "~")
|
|
32856
|
+
return homedir3();
|
|
32857
|
+
return path.startsWith("~/") ? `${homedir3()}${sep2}${path.slice(2)}` : path;
|
|
32858
|
+
}
|
|
32859
|
+
function readBoundaryRefuses(boundary, path, cwd, options = {}) {
|
|
32860
|
+
const expanded = expandedHome(path);
|
|
32861
|
+
const raw = isAbsolute2(expanded) ? expanded : `${cwd}${sep2}${expanded}`;
|
|
32862
|
+
const lexical = resolve3(raw);
|
|
32863
|
+
const real = canonicalPath(raw);
|
|
32864
|
+
if (deniedForm(boundary, lexical) || deniedForm(boundary, real))
|
|
32865
|
+
return true;
|
|
32866
|
+
return options.traversal === true && boundary.deny.some((root) => isWithin2(lexical, root) || isWithin2(real, root));
|
|
32867
|
+
}
|
|
32868
|
+
|
|
32869
|
+
// ../../bridges/cursor-bridge/src/prompt-attachments.ts
|
|
32870
|
+
import { constants as constants2 } from "node:fs";
|
|
32871
|
+
import { lstat, open as open3, realpath } from "node:fs/promises";
|
|
32872
|
+
import { isAbsolute as isAbsolute3, join as join5, relative as relative2, resolve as resolve4, sep as sep3 } from "node:path";
|
|
32873
|
+
|
|
32874
|
+
class PromptAttachmentError extends Error {
|
|
32875
|
+
code;
|
|
32876
|
+
name = "PromptAttachmentError";
|
|
32877
|
+
constructor(code, message) {
|
|
32878
|
+
super(message);
|
|
32879
|
+
this.code = code;
|
|
32880
|
+
}
|
|
32881
|
+
}
|
|
32882
|
+
var MAX_IMAGE_ATTACHMENT_BYTES = 8 * 1024 * 1024;
|
|
32883
|
+
var MAX_PROMPT_ATTACHMENTS = 20;
|
|
32884
|
+
var MAX_TOTAL_IMAGE_ATTACHMENT_BYTES = 32 * 1024 * 1024;
|
|
32885
|
+
var MAX_ATTACHMENT_PATH_BYTES = 4 * 1024;
|
|
32886
|
+
var MAX_ATTACHMENT_FILENAME_BYTES = 1 * 1024;
|
|
32887
|
+
var READ_CHUNK_BYTES = 64 * 1024;
|
|
32888
|
+
function parsePromptAttachments(value) {
|
|
32889
|
+
if (value === undefined || value === null)
|
|
32890
|
+
return [];
|
|
32891
|
+
if (!Array.isArray(value)) {
|
|
32892
|
+
throw new PromptAttachmentError("attachment_invalid", "attachments must be an array");
|
|
32893
|
+
}
|
|
32894
|
+
if (value.length > MAX_PROMPT_ATTACHMENTS) {
|
|
32895
|
+
throw new PromptAttachmentError("attachment_invalid", `A prompt can carry at most ${MAX_PROMPT_ATTACHMENTS} attachments`);
|
|
32896
|
+
}
|
|
32897
|
+
return value.map((candidate) => {
|
|
32898
|
+
if (candidate === null || typeof candidate !== "object" || Array.isArray(candidate)) {
|
|
32899
|
+
throw new PromptAttachmentError("attachment_invalid", "Each attachment must be an object");
|
|
32900
|
+
}
|
|
32901
|
+
const record = candidate;
|
|
32902
|
+
if (record.type !== "image") {
|
|
32903
|
+
throw new PromptAttachmentError("attachment_invalid", "Cursor accepts image attachments only");
|
|
32904
|
+
}
|
|
32905
|
+
const path = typeof record.path === "string" ? record.path.trim() : "";
|
|
32906
|
+
if (!path || Buffer.byteLength(path) > MAX_ATTACHMENT_PATH_BYTES) {
|
|
32907
|
+
throw new PromptAttachmentError("attachment_invalid", "Each attachment needs a workspace path");
|
|
32908
|
+
}
|
|
32909
|
+
if (path.includes("\x00")) {
|
|
32910
|
+
throw new PromptAttachmentError("attachment_invalid", "An attachment path must not contain null bytes");
|
|
32911
|
+
}
|
|
32912
|
+
const filename = typeof record.filename === "string" && record.filename.trim() && Buffer.byteLength(record.filename) <= MAX_ATTACHMENT_FILENAME_BYTES ? record.filename : undefined;
|
|
32913
|
+
return { type: "image", path, ...filename ? { filename } : {} };
|
|
32914
|
+
});
|
|
32915
|
+
}
|
|
32916
|
+
async function readPromptImages(attachments, workspaceRoot) {
|
|
32917
|
+
const images = [];
|
|
32918
|
+
let totalBytes = 0;
|
|
32919
|
+
for (const attachment of attachments) {
|
|
32920
|
+
const { bytes, absolutePath } = await readWorkspaceImage(attachment.path, workspaceRoot);
|
|
32921
|
+
totalBytes += bytes.length;
|
|
32922
|
+
if (totalBytes > MAX_TOTAL_IMAGE_ATTACHMENT_BYTES) {
|
|
32923
|
+
throw new PromptAttachmentError("attachment_too_large", "Image attachments exceed the 32MB total limit");
|
|
32924
|
+
}
|
|
32925
|
+
images.push({
|
|
32926
|
+
data: bytes.toString("base64"),
|
|
32927
|
+
mimeType: imageMimeType(bytes),
|
|
32928
|
+
path: attachment.path,
|
|
32929
|
+
absolutePath,
|
|
32930
|
+
...attachment.filename ? { filename: attachment.filename } : {}
|
|
32931
|
+
});
|
|
32932
|
+
}
|
|
32933
|
+
return images;
|
|
32934
|
+
}
|
|
32935
|
+
function imageMimeType(bytes) {
|
|
32936
|
+
if (bytes.length >= 8 && bytes.subarray(0, 8).equals(Buffer.from([137, 80, 78, 71, 13, 10, 26, 10])))
|
|
32937
|
+
return "image/png";
|
|
32938
|
+
if (bytes.length >= 3 && bytes[0] === 255 && bytes[1] === 216 && bytes[2] === 255) {
|
|
32939
|
+
return "image/jpeg";
|
|
32940
|
+
}
|
|
32941
|
+
if (bytes.length >= 6 && (bytes.subarray(0, 6).toString("latin1") === "GIF87a" || bytes.subarray(0, 6).toString("latin1") === "GIF89a"))
|
|
32942
|
+
return "image/gif";
|
|
32943
|
+
if (bytes.length >= 12 && bytes.subarray(0, 4).toString("latin1") === "RIFF" && bytes.subarray(8, 12).toString("latin1") === "WEBP")
|
|
32944
|
+
return "image/webp";
|
|
32945
|
+
throw new PromptAttachmentError("attachment_unsupported_format", "Image attachments must be PNG, JPEG, GIF, or WebP");
|
|
32946
|
+
}
|
|
32947
|
+
function attachmentErrorForFsFailure(error) {
|
|
32948
|
+
const code = error?.code;
|
|
32949
|
+
if (code === "ELOOP") {
|
|
32950
|
+
return new PromptAttachmentError("attachment_symlink_not_allowed", "Image attachments must be regular workspace files, not symbolic links");
|
|
32951
|
+
}
|
|
32952
|
+
return new PromptAttachmentError("attachment_read_failed", "Image attachment could not be read from the workspace");
|
|
32953
|
+
}
|
|
32954
|
+
var BRIDGE_ATTACHMENT_ROOT_ENV = "ORKESTRATOR_BRIDGE_ATTACHMENT_ROOT";
|
|
32955
|
+
function configuredAttachmentRoot(env = process.env) {
|
|
32956
|
+
const value = env[BRIDGE_ATTACHMENT_ROOT_ENV]?.trim();
|
|
32957
|
+
return value && isAbsolute3(value) ? resolve4(value) : undefined;
|
|
32958
|
+
}
|
|
32959
|
+
function attachmentContainmentRoot(filePath, workspaceRoot, extraRoot = configuredAttachmentRoot()) {
|
|
32960
|
+
if (extraRoot && isAbsolute3(filePath) && isPathWithin(extraRoot, resolve4(filePath))) {
|
|
32961
|
+
return extraRoot;
|
|
32962
|
+
}
|
|
32963
|
+
return resolve4(workspaceRoot);
|
|
32964
|
+
}
|
|
32965
|
+
function isPathWithin(root, candidate) {
|
|
32966
|
+
if (candidate === root)
|
|
32967
|
+
return true;
|
|
32968
|
+
const childPath = relative2(root, candidate);
|
|
32969
|
+
return Boolean(childPath) && childPath !== ".." && !childPath.startsWith(`..${sep3}`) && !isAbsolute3(childPath);
|
|
32970
|
+
}
|
|
32971
|
+
async function assertNoSymlinkComponents(root, targetPath) {
|
|
32972
|
+
let currentPath = root;
|
|
32973
|
+
for (const segment of relative2(root, targetPath).split(sep3).filter(Boolean)) {
|
|
32974
|
+
currentPath = join5(currentPath, segment);
|
|
32975
|
+
const stats = await lstat(currentPath).catch((error) => {
|
|
32976
|
+
throw attachmentErrorForFsFailure(error);
|
|
32977
|
+
});
|
|
32978
|
+
if (stats.isSymbolicLink()) {
|
|
32979
|
+
throw new PromptAttachmentError("attachment_symlink_not_allowed", "Image attachments must be regular workspace files, not symbolic links");
|
|
32980
|
+
}
|
|
32981
|
+
}
|
|
32982
|
+
}
|
|
32983
|
+
async function assertOpenedWorkspaceFile(targetPath, canonicalRoot, openedStats) {
|
|
32984
|
+
const [pathStats, canonicalTarget] = await Promise.all([
|
|
32985
|
+
lstat(targetPath),
|
|
32986
|
+
realpath(targetPath)
|
|
32987
|
+
]).catch((error) => {
|
|
32988
|
+
throw attachmentErrorForFsFailure(error);
|
|
32989
|
+
});
|
|
32990
|
+
if (pathStats.isSymbolicLink()) {
|
|
32991
|
+
throw new PromptAttachmentError("attachment_symlink_not_allowed", "Image attachments must be regular workspace files, not symbolic links");
|
|
32992
|
+
}
|
|
32993
|
+
if (!pathStats.isFile() || !openedStats.isFile() || pathStats.dev !== openedStats.dev || pathStats.ino !== openedStats.ino) {
|
|
32994
|
+
throw new PromptAttachmentError("attachment_not_regular_file", "Image attachment is not a stable regular workspace file");
|
|
32995
|
+
}
|
|
32996
|
+
if (!isPathWithin(canonicalRoot, canonicalTarget)) {
|
|
32997
|
+
throw new PromptAttachmentError("attachment_outside_workspace", "Image attachment must be contained in the current workspace");
|
|
32998
|
+
}
|
|
32999
|
+
}
|
|
33000
|
+
function assertStableRead(initial, final, bytesRead) {
|
|
33001
|
+
if (final.dev !== initial.dev || final.ino !== initial.ino || final.size !== initial.size || final.size !== bytesRead || final.mtimeMs !== initial.mtimeMs || final.ctimeMs !== initial.ctimeMs) {
|
|
33002
|
+
throw new PromptAttachmentError("attachment_changed", "Image attachment changed while it was being read; attach it again");
|
|
33003
|
+
}
|
|
33004
|
+
}
|
|
33005
|
+
async function readWorkspaceImage(filePath, workspaceRoot) {
|
|
33006
|
+
const lexicalRoot = attachmentContainmentRoot(filePath, workspaceRoot);
|
|
33007
|
+
const targetPath = isAbsolute3(filePath) ? resolve4(filePath) : resolve4(lexicalRoot, filePath);
|
|
33008
|
+
if (!isPathWithin(lexicalRoot, targetPath)) {
|
|
33009
|
+
throw new PromptAttachmentError("attachment_outside_workspace", "Image attachment must be contained in the current workspace");
|
|
33010
|
+
}
|
|
33011
|
+
const canonicalRoot = await realpath(lexicalRoot).catch((error) => {
|
|
33012
|
+
throw attachmentErrorForFsFailure(error);
|
|
33013
|
+
});
|
|
33014
|
+
await assertNoSymlinkComponents(lexicalRoot, targetPath);
|
|
33015
|
+
const canonicalTarget = await realpath(targetPath).catch((error) => {
|
|
33016
|
+
throw attachmentErrorForFsFailure(error);
|
|
33017
|
+
});
|
|
33018
|
+
if (!isPathWithin(canonicalRoot, canonicalTarget)) {
|
|
33019
|
+
throw new PromptAttachmentError("attachment_outside_workspace", "Image attachment must be contained in the current workspace");
|
|
33020
|
+
}
|
|
33021
|
+
const noFollow = constants2.O_NOFOLLOW ?? 0;
|
|
33022
|
+
const handle = await open3(targetPath, constants2.O_RDONLY | noFollow).catch((error) => {
|
|
33023
|
+
throw attachmentErrorForFsFailure(error);
|
|
33024
|
+
});
|
|
33025
|
+
try {
|
|
33026
|
+
const initialStats = await handle.stat();
|
|
33027
|
+
await assertOpenedWorkspaceFile(targetPath, canonicalRoot, initialStats);
|
|
33028
|
+
if (initialStats.size > MAX_IMAGE_ATTACHMENT_BYTES) {
|
|
33029
|
+
throw new PromptAttachmentError("attachment_too_large", "Image attachment exceeds the 8MB limit");
|
|
33030
|
+
}
|
|
33031
|
+
const chunks = [];
|
|
33032
|
+
let totalBytes = 0;
|
|
33033
|
+
while (totalBytes <= MAX_IMAGE_ATTACHMENT_BYTES) {
|
|
33034
|
+
const remaining = MAX_IMAGE_ATTACHMENT_BYTES + 1 - totalBytes;
|
|
33035
|
+
const chunk = Buffer.allocUnsafe(Math.min(READ_CHUNK_BYTES, remaining));
|
|
33036
|
+
const { bytesRead } = await handle.read(chunk, 0, chunk.length, null);
|
|
33037
|
+
if (bytesRead === 0)
|
|
33038
|
+
break;
|
|
33039
|
+
chunks.push(chunk.subarray(0, bytesRead));
|
|
33040
|
+
totalBytes += bytesRead;
|
|
33041
|
+
}
|
|
33042
|
+
if (totalBytes > MAX_IMAGE_ATTACHMENT_BYTES) {
|
|
33043
|
+
throw new PromptAttachmentError("attachment_too_large", "Image attachment exceeds the 8MB limit");
|
|
33044
|
+
}
|
|
33045
|
+
if (totalBytes === 0) {
|
|
33046
|
+
throw new PromptAttachmentError("attachment_empty", "Image attachment file is empty");
|
|
33047
|
+
}
|
|
33048
|
+
const finalStats = await handle.stat();
|
|
33049
|
+
await assertOpenedWorkspaceFile(targetPath, canonicalRoot, finalStats);
|
|
33050
|
+
assertStableRead(initialStats, finalStats, totalBytes);
|
|
33051
|
+
return { bytes: Buffer.concat(chunks, totalBytes), absolutePath: targetPath };
|
|
33052
|
+
} catch (error) {
|
|
33053
|
+
if (error instanceof PromptAttachmentError)
|
|
33054
|
+
throw error;
|
|
33055
|
+
throw attachmentErrorForFsFailure(error);
|
|
33056
|
+
} finally {
|
|
33057
|
+
await handle.close();
|
|
33058
|
+
}
|
|
33059
|
+
}
|
|
33060
|
+
|
|
33061
|
+
// ../../bridges/cursor-bridge/src/read-tools.ts
|
|
33062
|
+
import { isUtf8 } from "node:buffer";
|
|
33063
|
+
import { spawn } from "node:child_process";
|
|
33064
|
+
import { existsSync as existsSync2, realpathSync as realpathSync3 } from "node:fs";
|
|
33065
|
+
import { open as open4, stat as stat2 } from "node:fs/promises";
|
|
33066
|
+
import { basename as basename2, dirname as dirname3, extname, isAbsolute as isAbsolute4, join as join6, relative as relative3, resolve as resolve5, sep as sep4 } from "node:path";
|
|
33067
|
+
import { fileURLToPath } from "node:url";
|
|
33068
|
+
var MAX_READ_BYTES = 8 * 1024 * 1024;
|
|
33069
|
+
var MAX_SEARCH_ENTRIES = 2000;
|
|
33070
|
+
var MAX_MATCH_LINE_CHARS = 1000;
|
|
33071
|
+
var MAX_RIPGREP_OUTPUT_BYTES = 16 * 1024 * 1024;
|
|
33072
|
+
var MAX_RIPGREP_STDERR_BYTES = 4096;
|
|
33073
|
+
var SEARCH_TIMEOUT_MS = 25000;
|
|
33074
|
+
var LS_TIMEOUT_MS = 5000;
|
|
33075
|
+
var LS_CHARACTER_BUDGET = 2500;
|
|
33076
|
+
var IMAGE_EXTENSIONS = new Set([".png", ".jpg", ".jpeg", ".gif", ".webp"]);
|
|
33077
|
+
function withClone(value) {
|
|
33078
|
+
Object.defineProperty(value, "clone", {
|
|
33079
|
+
value: () => withClone(structuredClone(value)),
|
|
33080
|
+
enumerable: false
|
|
33081
|
+
});
|
|
33082
|
+
return value;
|
|
33083
|
+
}
|
|
33084
|
+
function errorCode(error) {
|
|
33085
|
+
return error && typeof error === "object" && "code" in error ? String(error.code) : undefined;
|
|
33086
|
+
}
|
|
33087
|
+
function errorMessage2(error) {
|
|
33088
|
+
return error instanceof Error ? error.message : "Unknown error occurred";
|
|
33089
|
+
}
|
|
33090
|
+
function countLines(text) {
|
|
33091
|
+
let lines = 1;
|
|
33092
|
+
for (let index = text.indexOf(`
|
|
33093
|
+
`);index !== -1; index = text.indexOf(`
|
|
33094
|
+
`, index + 1)) {
|
|
33095
|
+
lines += 1;
|
|
33096
|
+
}
|
|
33097
|
+
return lines;
|
|
33098
|
+
}
|
|
33099
|
+
function clampLine(value, total) {
|
|
33100
|
+
if (Number.isNaN(value) || value === 0)
|
|
33101
|
+
return 0;
|
|
33102
|
+
if (value === Number.POSITIVE_INFINITY)
|
|
33103
|
+
return total;
|
|
33104
|
+
if (value === Number.NEGATIVE_INFINITY)
|
|
33105
|
+
return 0;
|
|
33106
|
+
const whole = Math.trunc(value);
|
|
33107
|
+
return whole < 0 ? Math.max(total + whole, 0) : Math.min(whole, total);
|
|
33108
|
+
}
|
|
33109
|
+
function readLineRange(totalLines, empty, args) {
|
|
33110
|
+
if (args.offset === undefined && args.limit === undefined)
|
|
33111
|
+
return { applied: false };
|
|
33112
|
+
if (empty)
|
|
33113
|
+
return { applied: false };
|
|
33114
|
+
const offset = args.offset ?? 1;
|
|
33115
|
+
const limit = args.limit ?? (offset < 0 ? Math.abs(offset) : totalLines);
|
|
33116
|
+
const first = offset < 0 ? Math.max(0, totalLines + offset) : Math.max(0, offset - 1);
|
|
33117
|
+
if (first >= totalLines)
|
|
33118
|
+
return { applied: false };
|
|
33119
|
+
const last = Math.min(totalLines, first + limit);
|
|
33120
|
+
const start = clampLine(first, totalLines);
|
|
33121
|
+
return { applied: true, start, end: Math.max(start, clampLine(last, totalLines)) };
|
|
33122
|
+
}
|
|
33123
|
+
function sliceLines(text, start, end) {
|
|
33124
|
+
if (start >= end)
|
|
33125
|
+
return "";
|
|
33126
|
+
let from = 0;
|
|
33127
|
+
for (let line = 0;line < start; line += 1) {
|
|
33128
|
+
const next = text.indexOf(`
|
|
33129
|
+
`, from);
|
|
33130
|
+
if (next === -1)
|
|
33131
|
+
return "";
|
|
33132
|
+
from = next + 1;
|
|
33133
|
+
}
|
|
33134
|
+
let to = from;
|
|
33135
|
+
for (let line = start;line < end; line += 1) {
|
|
33136
|
+
const next = text.indexOf(`
|
|
33137
|
+
`, to);
|
|
33138
|
+
if (next === -1)
|
|
33139
|
+
return text.slice(from);
|
|
33140
|
+
to = next + 1;
|
|
33141
|
+
}
|
|
33142
|
+
return text.slice(from, to);
|
|
33143
|
+
}
|
|
33144
|
+
function readCharacterLimit(args) {
|
|
33145
|
+
if (args.maxChars === undefined || args.offset !== undefined || args.limit !== undefined) {
|
|
33146
|
+
return MAX_READ_BYTES;
|
|
33147
|
+
}
|
|
33148
|
+
return Math.min(MAX_READ_BYTES, args.maxChars + 2);
|
|
33149
|
+
}
|
|
33150
|
+
function trimSurrogate(text) {
|
|
33151
|
+
const last = text.charCodeAt(text.length - 1);
|
|
33152
|
+
return last >= 55296 && last <= 56319 ? text.slice(0, -1) : text;
|
|
33153
|
+
}
|
|
33154
|
+
var BINARY_SIGNATURES = [
|
|
33155
|
+
Buffer.from("%PDF-", "ascii"),
|
|
33156
|
+
Buffer.from([80, 75, 3, 4]),
|
|
33157
|
+
Buffer.from([127, 69, 76, 70]),
|
|
33158
|
+
Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]),
|
|
33159
|
+
Buffer.from([255, 216, 255]),
|
|
33160
|
+
Buffer.from("GIF87a", "ascii"),
|
|
33161
|
+
Buffer.from("GIF89a", "ascii"),
|
|
33162
|
+
Buffer.from("SQLite format 3\x00", "ascii"),
|
|
33163
|
+
Buffer.from([31, 139])
|
|
33164
|
+
];
|
|
33165
|
+
function looksBinary(head) {
|
|
33166
|
+
if (BINARY_SIGNATURES.some((signature) => head.subarray(0, signature.length).equals(signature))) {
|
|
33167
|
+
return true;
|
|
33168
|
+
}
|
|
33169
|
+
return head.includes(0);
|
|
33170
|
+
}
|
|
33171
|
+
async function readHead(path, bytes) {
|
|
33172
|
+
const handle = await open4(path, "r");
|
|
33173
|
+
try {
|
|
33174
|
+
const buffer = Buffer.alloc(bytes);
|
|
33175
|
+
const { bytesRead } = await handle.read(buffer, 0, bytes, 0);
|
|
33176
|
+
return buffer.subarray(0, bytesRead);
|
|
33177
|
+
} finally {
|
|
33178
|
+
await handle.close();
|
|
33179
|
+
}
|
|
33180
|
+
}
|
|
33181
|
+
function success(path, value) {
|
|
33182
|
+
return { result: { case: "success", value: withClone({ path, ...value }) } };
|
|
33183
|
+
}
|
|
33184
|
+
async function readFileTool(path, args) {
|
|
33185
|
+
try {
|
|
33186
|
+
const stats = await stat2(path);
|
|
33187
|
+
if (stats.isDirectory()) {
|
|
33188
|
+
return {
|
|
33189
|
+
result: {
|
|
33190
|
+
case: "invalidFile",
|
|
33191
|
+
value: { path, reason: "Path is a directory, not a file" }
|
|
33192
|
+
}
|
|
33193
|
+
};
|
|
33194
|
+
}
|
|
33195
|
+
if (!stats.isFile()) {
|
|
33196
|
+
return {
|
|
33197
|
+
result: {
|
|
33198
|
+
case: "invalidFile",
|
|
33199
|
+
value: { path, reason: "Path is neither a file nor a directory" }
|
|
33200
|
+
}
|
|
33201
|
+
};
|
|
33202
|
+
}
|
|
33203
|
+
const fileSize = BigInt(stats.size);
|
|
33204
|
+
const extension = extname(path).toLowerCase();
|
|
33205
|
+
const head = await readHead(path, Math.min(stats.size, 8192));
|
|
33206
|
+
if (IMAGE_EXTENSIONS.has(extension) || extension === ".pdf" || looksBinary(head)) {
|
|
33207
|
+
if (!(IMAGE_EXTENSIONS.has(extension) || extension === ".pdf")) {
|
|
33208
|
+
return {
|
|
33209
|
+
result: {
|
|
33210
|
+
case: "invalidFile",
|
|
33211
|
+
value: { path, reason: "File content is binary data, not text" }
|
|
33212
|
+
}
|
|
33213
|
+
};
|
|
33214
|
+
}
|
|
33215
|
+
if (stats.size > MAX_READ_BYTES) {
|
|
33216
|
+
return {
|
|
33217
|
+
result: {
|
|
33218
|
+
case: "invalidFile",
|
|
33219
|
+
value: { path, reason: `File is larger than ${MAX_READ_BYTES} bytes` }
|
|
33220
|
+
}
|
|
33221
|
+
};
|
|
33222
|
+
}
|
|
33223
|
+
const data = await readHead(path, stats.size);
|
|
33224
|
+
return success(path, {
|
|
33225
|
+
output: { case: "data", value: new Uint8Array(data) },
|
|
33226
|
+
totalLines: 0,
|
|
33227
|
+
fileSize,
|
|
33228
|
+
truncated: false
|
|
33229
|
+
});
|
|
33230
|
+
}
|
|
33231
|
+
const capped = stats.size > MAX_READ_BYTES;
|
|
33232
|
+
const bytes = await readHead(path, Math.min(stats.size, MAX_READ_BYTES));
|
|
33233
|
+
let text = bytes.toString("utf8");
|
|
33234
|
+
if (text.charCodeAt(0) === 65279)
|
|
33235
|
+
text = text.slice(1);
|
|
33236
|
+
const totalLines = countLines(text);
|
|
33237
|
+
const range = readLineRange(totalLines, text === "", args);
|
|
33238
|
+
let content = range.applied ? sliceLines(text, range.start, range.end) : text;
|
|
33239
|
+
let truncated = capped;
|
|
33240
|
+
const limit = readCharacterLimit(args);
|
|
33241
|
+
if (content.length > limit) {
|
|
33242
|
+
content = trimSurrogate(content.substring(0, limit));
|
|
33243
|
+
truncated = true;
|
|
33244
|
+
}
|
|
33245
|
+
return success(path, {
|
|
33246
|
+
output: { case: "content", value: content },
|
|
33247
|
+
totalLines,
|
|
33248
|
+
fileSize,
|
|
33249
|
+
truncated,
|
|
33250
|
+
rangeApplied: range.applied
|
|
33251
|
+
});
|
|
33252
|
+
} catch (error) {
|
|
33253
|
+
const code = errorCode(error);
|
|
33254
|
+
if (code === "ENOENT")
|
|
33255
|
+
return { result: { case: "fileNotFound", value: { path } } };
|
|
33256
|
+
if (code === "EACCES" || code === "EPERM") {
|
|
33257
|
+
return { result: { case: "permissionDenied", value: { path } } };
|
|
33258
|
+
}
|
|
33259
|
+
return { result: { case: "error", value: { path, error: errorMessage2(error) } } };
|
|
33260
|
+
}
|
|
33261
|
+
}
|
|
33262
|
+
function sdkDirectory() {
|
|
33263
|
+
try {
|
|
33264
|
+
return realpathSync3(dirname3(fileURLToPath(import.meta.resolve("@cursor/sdk"))));
|
|
33265
|
+
} catch {
|
|
33266
|
+
return;
|
|
33267
|
+
}
|
|
33268
|
+
}
|
|
33269
|
+
function resolveRipgrep(workspace, env = process.env, from = [sdkDirectory(), dirname3(fileURLToPath(import.meta.url))]) {
|
|
33270
|
+
const binary = process.platform === "win32" ? "rg.exe" : "rg";
|
|
33271
|
+
const configured = env.CURSOR_RIPGREP_PATH?.trim();
|
|
33272
|
+
if (configured && isAbsolute4(configured) && existsSync2(configured))
|
|
33273
|
+
return configured;
|
|
33274
|
+
const workspaceRoot = resolve5(workspace);
|
|
33275
|
+
const insideWorkspace = (path) => {
|
|
33276
|
+
const inside = relative3(workspaceRoot, path);
|
|
33277
|
+
return inside === "" || !inside.startsWith("..") && !isAbsolute4(inside);
|
|
33278
|
+
};
|
|
33279
|
+
const relativeBinary = join6("node_modules", "@cursor", `sdk-${process.platform}-${process.arch}`, "bin", binary);
|
|
33280
|
+
for (const start of from) {
|
|
33281
|
+
if (!start)
|
|
33282
|
+
continue;
|
|
33283
|
+
let directory = resolve5(start);
|
|
33284
|
+
for (;; ) {
|
|
33285
|
+
const candidate = join6(directory, relativeBinary);
|
|
33286
|
+
if (!insideWorkspace(candidate) && existsSync2(candidate))
|
|
33287
|
+
return candidate;
|
|
33288
|
+
const parent = dirname3(directory);
|
|
33289
|
+
if (parent === directory)
|
|
33290
|
+
break;
|
|
33291
|
+
directory = parent;
|
|
33292
|
+
}
|
|
33293
|
+
}
|
|
33294
|
+
return binary;
|
|
33295
|
+
}
|
|
33296
|
+
function runRipgrep(ripgrep, args, cwd, timeoutMs) {
|
|
33297
|
+
return new Promise((resolvePromise, reject) => {
|
|
33298
|
+
const child = spawn(ripgrep, args, { cwd, stdio: ["ignore", "pipe", "pipe"] });
|
|
33299
|
+
const chunks = [];
|
|
33300
|
+
let bytes = 0;
|
|
33301
|
+
let stderr = "";
|
|
33302
|
+
let timedOut = false;
|
|
33303
|
+
let outputCapped = false;
|
|
33304
|
+
const timer = setTimeout(() => {
|
|
33305
|
+
timedOut = true;
|
|
33306
|
+
child.kill("SIGKILL");
|
|
33307
|
+
}, timeoutMs);
|
|
33308
|
+
child.stdout.on("data", (chunk) => {
|
|
33309
|
+
if (outputCapped)
|
|
33310
|
+
return;
|
|
33311
|
+
const room = MAX_RIPGREP_OUTPUT_BYTES - bytes;
|
|
33312
|
+
if (chunk.length >= room) {
|
|
33313
|
+
chunks.push(chunk.subarray(0, room));
|
|
33314
|
+
bytes += room;
|
|
33315
|
+
outputCapped = true;
|
|
33316
|
+
child.kill("SIGKILL");
|
|
33317
|
+
return;
|
|
33318
|
+
}
|
|
33319
|
+
chunks.push(chunk);
|
|
33320
|
+
bytes += chunk.length;
|
|
33321
|
+
});
|
|
33322
|
+
child.stderr.on("data", (chunk) => {
|
|
33323
|
+
if (stderr.length < MAX_RIPGREP_STDERR_BYTES) {
|
|
33324
|
+
stderr = (stderr + chunk.toString("utf8")).slice(0, MAX_RIPGREP_STDERR_BYTES);
|
|
33325
|
+
}
|
|
33326
|
+
});
|
|
33327
|
+
child.once("error", (error) => {
|
|
33328
|
+
clearTimeout(timer);
|
|
33329
|
+
reject(error);
|
|
33330
|
+
});
|
|
33331
|
+
child.once("close", (exitCode) => {
|
|
33332
|
+
clearTimeout(timer);
|
|
33333
|
+
resolvePromise({
|
|
33334
|
+
stdout: Buffer.concat(chunks),
|
|
33335
|
+
stderr,
|
|
33336
|
+
exitCode,
|
|
33337
|
+
timedOut,
|
|
33338
|
+
outputCapped
|
|
33339
|
+
});
|
|
33340
|
+
});
|
|
33341
|
+
});
|
|
33342
|
+
}
|
|
33343
|
+
function ripgrepFailed(run) {
|
|
33344
|
+
return !run.timedOut && !run.outputCapped && run.exitCode === 2 && run.stdout.length === 0;
|
|
33345
|
+
}
|
|
33346
|
+
function ripgrepError(run) {
|
|
33347
|
+
return run.stderr.trim().split(/\r?\n/)[0] || `ripgrep exited with code ${run.exitCode}`;
|
|
33348
|
+
}
|
|
33349
|
+
function outputModeOf(value) {
|
|
33350
|
+
const mode = value ?? "content";
|
|
33351
|
+
return mode === "content" || mode === "files_with_matches" || mode === "count" ? mode : undefined;
|
|
33352
|
+
}
|
|
33353
|
+
function listsFiles(args, mode) {
|
|
33354
|
+
return mode === "files_with_matches" && (args.pattern ?? "") === "" && Boolean(args.glob);
|
|
33355
|
+
}
|
|
33356
|
+
function page(entries, args) {
|
|
33357
|
+
const offset = args.offset !== undefined && args.offset > 0 ? Math.trunc(args.offset) : 0;
|
|
33358
|
+
let kept = entries.slice(offset);
|
|
33359
|
+
let headLimitApplied;
|
|
33360
|
+
if (args.headLimit !== undefined && args.headLimit > 0 && kept.length > args.headLimit) {
|
|
33361
|
+
headLimitApplied = Math.trunc(args.headLimit);
|
|
33362
|
+
kept = kept.slice(0, headLimitApplied);
|
|
33363
|
+
}
|
|
33364
|
+
const clientTruncated = kept.length > MAX_SEARCH_ENTRIES;
|
|
33365
|
+
if (clientTruncated)
|
|
33366
|
+
kept = kept.slice(0, MAX_SEARCH_ENTRIES);
|
|
33367
|
+
return {
|
|
33368
|
+
kept,
|
|
33369
|
+
...headLimitApplied !== undefined ? { headLimitApplied } : {},
|
|
33370
|
+
...offset > 0 ? { offsetApplied: offset } : {},
|
|
33371
|
+
clientTruncated
|
|
33372
|
+
};
|
|
33373
|
+
}
|
|
33374
|
+
function grepArguments(args, mode, target) {
|
|
33375
|
+
const files = listsFiles(args, mode);
|
|
33376
|
+
const rg = [];
|
|
33377
|
+
if (mode === "content") {
|
|
33378
|
+
rg.push("--json");
|
|
33379
|
+
if (args.contextBefore !== undefined)
|
|
33380
|
+
rg.push("--before-context", String(args.contextBefore));
|
|
33381
|
+
if (args.contextAfter !== undefined)
|
|
33382
|
+
rg.push("--after-context", String(args.contextAfter));
|
|
33383
|
+
if (args.context !== undefined && args.contextBefore === undefined && args.contextAfter === undefined) {
|
|
33384
|
+
rg.push("--context", String(args.context));
|
|
33385
|
+
}
|
|
33386
|
+
} else if (mode === "files_with_matches") {
|
|
33387
|
+
rg.push(files ? "--files" : "--files-with-matches", "--null");
|
|
33388
|
+
} else {
|
|
33389
|
+
rg.push("--count", "--with-filename", "--null");
|
|
33390
|
+
}
|
|
33391
|
+
rg.push(args.caseInsensitive === true ? "--ignore-case" : "--case-sensitive");
|
|
33392
|
+
if (args.type)
|
|
33393
|
+
rg.push("--type", args.type);
|
|
33394
|
+
if (args.glob) {
|
|
33395
|
+
rg.push("--iglob", args.glob);
|
|
33396
|
+
if (files)
|
|
33397
|
+
rg.push("--iglob", "!**/.git");
|
|
33398
|
+
}
|
|
33399
|
+
if (args.multiline)
|
|
33400
|
+
rg.push("--multiline", "--multiline-dotall");
|
|
33401
|
+
const sort = args.sort ?? "modified";
|
|
33402
|
+
if (sort !== "none")
|
|
33403
|
+
rg.push(args.sortAscending === true ? "--sort" : "--sortr", sort);
|
|
33404
|
+
rg.push("--no-config", "--color=never", "--hidden", "--follow");
|
|
33405
|
+
if (!files)
|
|
33406
|
+
rg.push("--regexp", args.pattern ?? "");
|
|
33407
|
+
rg.push("--", target);
|
|
33408
|
+
return rg;
|
|
33409
|
+
}
|
|
33410
|
+
function withoutDotSlash(path) {
|
|
33411
|
+
return path.startsWith(`.${sep4}`) ? path.slice(2) : path;
|
|
33412
|
+
}
|
|
33413
|
+
function pathText(bytes) {
|
|
33414
|
+
return isUtf8(bytes) ? bytes.toString("utf8") : undefined;
|
|
33415
|
+
}
|
|
33416
|
+
function splitNull(output) {
|
|
33417
|
+
const paths = [];
|
|
33418
|
+
let start = 0;
|
|
33419
|
+
for (let end = output.indexOf(0);end !== -1; end = output.indexOf(0, start)) {
|
|
33420
|
+
const path = pathText(output.subarray(start, end));
|
|
33421
|
+
if (path)
|
|
33422
|
+
paths.push(path);
|
|
33423
|
+
start = end + 1;
|
|
33424
|
+
}
|
|
33425
|
+
return paths;
|
|
33426
|
+
}
|
|
33427
|
+
function jsonText(value) {
|
|
33428
|
+
if (!value)
|
|
33429
|
+
return "";
|
|
33430
|
+
if (typeof value.text === "string")
|
|
33431
|
+
return value.text;
|
|
33432
|
+
return typeof value.bytes === "string" ? Buffer.from(value.bytes, "base64").toString("utf8") : "";
|
|
33433
|
+
}
|
|
33434
|
+
function contentLines(output) {
|
|
33435
|
+
const lines = [];
|
|
33436
|
+
for (const raw of output.toString("utf8").split(`
|
|
33437
|
+
`)) {
|
|
33438
|
+
if (!raw.trim())
|
|
33439
|
+
continue;
|
|
33440
|
+
let event;
|
|
33441
|
+
try {
|
|
33442
|
+
event = JSON.parse(raw);
|
|
33443
|
+
} catch {
|
|
33444
|
+
continue;
|
|
33445
|
+
}
|
|
33446
|
+
if (event.type !== "match" && event.type !== "context")
|
|
33447
|
+
continue;
|
|
33448
|
+
const data = event.data ?? {};
|
|
33449
|
+
const reportedPath = data.path;
|
|
33450
|
+
const file = reportedPath?.bytes !== undefined ? pathText(Buffer.from(reportedPath.bytes, "base64")) : reportedPath?.text;
|
|
33451
|
+
if (!file)
|
|
33452
|
+
continue;
|
|
33453
|
+
const text = jsonText(data.lines).replace(/\r?\n$/, "");
|
|
33454
|
+
const lineNumber = typeof data.line_number === "number" ? data.line_number : 0;
|
|
33455
|
+
text.split(`
|
|
33456
|
+
`).forEach((line, index) => {
|
|
33457
|
+
const truncated = line.length > MAX_MATCH_LINE_CHARS;
|
|
33458
|
+
lines.push({
|
|
33459
|
+
file: withoutDotSlash(file),
|
|
33460
|
+
lineNumber: lineNumber + index,
|
|
33461
|
+
content: truncated ? line.slice(0, MAX_MATCH_LINE_CHARS) : line,
|
|
33462
|
+
contentTruncated: truncated,
|
|
33463
|
+
isContextLine: event.type === "context"
|
|
33464
|
+
});
|
|
33465
|
+
});
|
|
33466
|
+
}
|
|
33467
|
+
return lines;
|
|
33468
|
+
}
|
|
33469
|
+
async function grepTool(args, options) {
|
|
33470
|
+
const mode = outputModeOf(args.outputMode);
|
|
33471
|
+
if (!mode) {
|
|
33472
|
+
return {
|
|
33473
|
+
result: { case: "error", value: { error: `Unknown output mode: ${args.outputMode}` } }
|
|
33474
|
+
};
|
|
33475
|
+
}
|
|
33476
|
+
const { cwd, refused } = options;
|
|
33477
|
+
try {
|
|
33478
|
+
const targetStats = await stat2(options.target).catch((error) => {
|
|
33479
|
+
if (errorCode(error) === "ENOENT")
|
|
33480
|
+
return;
|
|
33481
|
+
throw error;
|
|
33482
|
+
});
|
|
33483
|
+
if (!targetStats) {
|
|
33484
|
+
return {
|
|
33485
|
+
result: { case: "error", value: { error: `Path does not exist: ${options.target}` } }
|
|
33486
|
+
};
|
|
33487
|
+
}
|
|
33488
|
+
const inside = relative3(cwd, options.target);
|
|
33489
|
+
const target = inside === "" ? "." : !inside.startsWith("..") && !isAbsolute4(inside) ? inside : options.target;
|
|
33490
|
+
const rgArgs = grepArguments(args, mode, target);
|
|
33491
|
+
const cursorIgnore = join6(cwd, ".cursorignore");
|
|
33492
|
+
if (existsSync2(cursorIgnore))
|
|
33493
|
+
rgArgs.unshift("--ignore-file", cursorIgnore);
|
|
33494
|
+
const run = await runRipgrep(options.ripgrep, rgArgs, cwd, SEARCH_TIMEOUT_MS);
|
|
33495
|
+
if (ripgrepFailed(run)) {
|
|
33496
|
+
return { result: { case: "error", value: { error: ripgrepError(run) } } };
|
|
33497
|
+
}
|
|
33498
|
+
const ripgrepTruncated = run.timedOut || run.outputCapped;
|
|
33499
|
+
const admitted = (file) => !refused(resolve5(cwd, file));
|
|
33500
|
+
let union;
|
|
33501
|
+
if (mode === "content") {
|
|
33502
|
+
const lines = contentLines(run.stdout).filter((line) => admitted(line.file));
|
|
33503
|
+
const paged = page(lines, args);
|
|
33504
|
+
const byFile = new Map;
|
|
33505
|
+
for (const { file, ...line } of paged.kept) {
|
|
33506
|
+
const matches = byFile.get(file) ?? [];
|
|
33507
|
+
matches.push(line);
|
|
33508
|
+
byFile.set(file, matches);
|
|
33509
|
+
}
|
|
33510
|
+
union = {
|
|
33511
|
+
case: "content",
|
|
33512
|
+
value: {
|
|
33513
|
+
matches: Array.from(byFile, ([file, matches]) => ({ file, matches })),
|
|
33514
|
+
totalLines: lines.length,
|
|
33515
|
+
totalMatchedLines: lines.filter((line) => !line.isContextLine).length,
|
|
33516
|
+
clientTruncated: paged.clientTruncated,
|
|
33517
|
+
ripgrepTruncated,
|
|
33518
|
+
headLimitApplied: paged.headLimitApplied,
|
|
33519
|
+
offsetApplied: paged.offsetApplied
|
|
33520
|
+
}
|
|
33521
|
+
};
|
|
33522
|
+
} else if (mode === "files_with_matches") {
|
|
33523
|
+
const files = splitNull(run.stdout).map(withoutDotSlash).filter(admitted);
|
|
33524
|
+
const paged = page(files, args);
|
|
33525
|
+
union = {
|
|
33526
|
+
case: "files",
|
|
33527
|
+
value: {
|
|
33528
|
+
files: paged.kept,
|
|
33529
|
+
totalFiles: files.length,
|
|
33530
|
+
clientTruncated: paged.clientTruncated,
|
|
33531
|
+
ripgrepTruncated,
|
|
33532
|
+
headLimitApplied: paged.headLimitApplied,
|
|
33533
|
+
offsetApplied: paged.offsetApplied
|
|
33534
|
+
}
|
|
33535
|
+
};
|
|
33536
|
+
} else {
|
|
33537
|
+
const counts = [];
|
|
33538
|
+
let start = 0;
|
|
33539
|
+
while (start < run.stdout.length) {
|
|
33540
|
+
const separator = run.stdout.indexOf(0, start);
|
|
33541
|
+
if (separator === -1)
|
|
33542
|
+
break;
|
|
33543
|
+
const end = run.stdout.indexOf(10, separator + 1);
|
|
33544
|
+
if (end === -1)
|
|
33545
|
+
break;
|
|
33546
|
+
const path = pathText(run.stdout.subarray(start, separator));
|
|
33547
|
+
const count = Number.parseInt(run.stdout.subarray(separator + 1, end).toString("ascii"), 10);
|
|
33548
|
+
if (path !== undefined) {
|
|
33549
|
+
const file = withoutDotSlash(path);
|
|
33550
|
+
if (Number.isFinite(count) && admitted(file))
|
|
33551
|
+
counts.push({ file, count });
|
|
33552
|
+
}
|
|
33553
|
+
start = end + 1;
|
|
33554
|
+
}
|
|
33555
|
+
const paged = page(counts, args);
|
|
33556
|
+
union = {
|
|
33557
|
+
case: "count",
|
|
33558
|
+
value: {
|
|
33559
|
+
counts: paged.kept,
|
|
33560
|
+
totalFiles: counts.length,
|
|
33561
|
+
totalMatches: counts.reduce((sum, entry) => sum + entry.count, 0),
|
|
33562
|
+
clientTruncated: paged.clientTruncated,
|
|
33563
|
+
ripgrepTruncated,
|
|
33564
|
+
headLimitApplied: paged.headLimitApplied,
|
|
33565
|
+
offsetApplied: paged.offsetApplied
|
|
33566
|
+
}
|
|
33567
|
+
};
|
|
33568
|
+
}
|
|
33569
|
+
return {
|
|
33570
|
+
result: {
|
|
33571
|
+
case: "success",
|
|
33572
|
+
value: {
|
|
33573
|
+
pattern: args.pattern ?? "",
|
|
33574
|
+
path: args.path ?? "",
|
|
33575
|
+
outputMode: mode,
|
|
33576
|
+
workspaceResults: { [cwd]: { result: union } }
|
|
33577
|
+
}
|
|
33578
|
+
}
|
|
33579
|
+
};
|
|
33580
|
+
} catch (error) {
|
|
33581
|
+
return { result: { case: "error", value: { error: errorMessage2(error) } } };
|
|
33582
|
+
}
|
|
33583
|
+
}
|
|
33584
|
+
function treeNode(absPath, processed) {
|
|
33585
|
+
return {
|
|
33586
|
+
absPath,
|
|
33587
|
+
childrenDirs: [],
|
|
33588
|
+
childrenFiles: [],
|
|
33589
|
+
childrenWereProcessed: processed,
|
|
33590
|
+
fullSubtreeExtensionCounts: {}
|
|
33591
|
+
};
|
|
33592
|
+
}
|
|
33593
|
+
|
|
33594
|
+
class TreeBuilder {
|
|
33595
|
+
rootPath;
|
|
33596
|
+
root;
|
|
33597
|
+
nodes = new Map;
|
|
33598
|
+
charactersUsed;
|
|
33599
|
+
budgetExceeded = false;
|
|
33600
|
+
constructor(rootPath) {
|
|
33601
|
+
this.rootPath = rootPath;
|
|
33602
|
+
this.root = treeNode(rootPath, true);
|
|
33603
|
+
this.nodes.set(rootPath, this.root);
|
|
33604
|
+
this.charactersUsed = rootPath.length;
|
|
33605
|
+
}
|
|
33606
|
+
ancestors(directory) {
|
|
33607
|
+
const chain = [];
|
|
33608
|
+
let current = directory;
|
|
33609
|
+
for (;; ) {
|
|
33610
|
+
const node = this.nodes.get(current);
|
|
33611
|
+
if (node)
|
|
33612
|
+
chain.push(node);
|
|
33613
|
+
if (current === this.rootPath)
|
|
33614
|
+
break;
|
|
33615
|
+
const parent = dirname3(current);
|
|
33616
|
+
if (parent === current || !parent.startsWith(this.rootPath))
|
|
33617
|
+
break;
|
|
33618
|
+
current = parent;
|
|
33619
|
+
}
|
|
33620
|
+
return chain;
|
|
33621
|
+
}
|
|
33622
|
+
ensureDirectory(directory) {
|
|
33623
|
+
const existing = this.nodes.get(directory);
|
|
33624
|
+
if (existing)
|
|
33625
|
+
return existing;
|
|
33626
|
+
const inside = relative3(this.rootPath, directory);
|
|
33627
|
+
if (inside === ".." || inside.startsWith(`..${sep4}`) || isAbsolute4(inside))
|
|
33628
|
+
return;
|
|
33629
|
+
const parent = this.ensureDirectory(dirname3(directory));
|
|
33630
|
+
const node = treeNode(directory, !this.budgetExceeded);
|
|
33631
|
+
this.nodes.set(directory, node);
|
|
33632
|
+
parent?.childrenDirs.push(node);
|
|
33633
|
+
return node;
|
|
33634
|
+
}
|
|
33635
|
+
add(file) {
|
|
33636
|
+
const name = basename2(file);
|
|
33637
|
+
const directory = dirname3(file);
|
|
33638
|
+
const node = this.ensureDirectory(directory);
|
|
33639
|
+
if (!node)
|
|
33640
|
+
return;
|
|
33641
|
+
if (!this.budgetExceeded && this.charactersUsed + name.length <= LS_CHARACTER_BUDGET) {
|
|
33642
|
+
node.childrenFiles.push({ name });
|
|
33643
|
+
this.charactersUsed += name.length;
|
|
33644
|
+
return;
|
|
33645
|
+
}
|
|
33646
|
+
const chain = this.ancestors(directory);
|
|
33647
|
+
if (!this.budgetExceeded) {
|
|
33648
|
+
this.budgetExceeded = true;
|
|
33649
|
+
for (const ancestor of chain)
|
|
33650
|
+
ancestor.childrenWereProcessed = false;
|
|
33651
|
+
}
|
|
33652
|
+
const extension = extname(name).replace(/^\./, "") || name;
|
|
33653
|
+
for (const ancestor of chain) {
|
|
33654
|
+
ancestor.fullSubtreeExtensionCounts[extension] = (ancestor.fullSubtreeExtensionCounts[extension] ?? 0) + 1;
|
|
33655
|
+
ancestor.numFiles = (ancestor.numFiles ?? 0) + 1;
|
|
33656
|
+
}
|
|
33657
|
+
}
|
|
33658
|
+
sorted() {
|
|
33659
|
+
const sort = (node) => {
|
|
33660
|
+
node.childrenDirs.sort((a, b) => basename2(a.absPath).localeCompare(basename2(b.absPath)));
|
|
33661
|
+
node.childrenFiles.sort((a, b) => a.name.localeCompare(b.name));
|
|
33662
|
+
node.childrenDirs.forEach(sort);
|
|
33663
|
+
};
|
|
33664
|
+
sort(this.root);
|
|
33665
|
+
return this.root;
|
|
33666
|
+
}
|
|
33667
|
+
}
|
|
33668
|
+
async function lsTool(path, args, options) {
|
|
33669
|
+
try {
|
|
33670
|
+
let stats;
|
|
33671
|
+
try {
|
|
33672
|
+
stats = await stat2(path);
|
|
33673
|
+
} catch (error) {
|
|
33674
|
+
if (errorCode(error) === "ENOENT") {
|
|
33675
|
+
return {
|
|
33676
|
+
result: { case: "error", value: { path, error: `Path does not exist: ${path}` } }
|
|
33677
|
+
};
|
|
33678
|
+
}
|
|
33679
|
+
return { result: { case: "error", value: { path, error: errorMessage2(error) } } };
|
|
33680
|
+
}
|
|
33681
|
+
if (!stats.isDirectory()) {
|
|
33682
|
+
return {
|
|
33683
|
+
result: { case: "error", value: { path, error: `Path is not a directory: ${path}` } }
|
|
33684
|
+
};
|
|
33685
|
+
}
|
|
33686
|
+
const rgArgs = [
|
|
33687
|
+
"--files",
|
|
33688
|
+
"--null",
|
|
33689
|
+
"--hidden",
|
|
33690
|
+
"--no-require-git",
|
|
33691
|
+
"--no-config",
|
|
33692
|
+
"--color=never"
|
|
33693
|
+
];
|
|
33694
|
+
for (const ignore of args.ignore ?? [])
|
|
33695
|
+
rgArgs.push("--iglob", `!${ignore}`);
|
|
33696
|
+
const cursorIgnore = join6(path, ".cursorignore");
|
|
33697
|
+
if (existsSync2(cursorIgnore))
|
|
33698
|
+
rgArgs.push("--ignore-file", cursorIgnore);
|
|
33699
|
+
const run = await runRipgrep(options.ripgrep, rgArgs, path, args.timeoutMs ?? LS_TIMEOUT_MS);
|
|
33700
|
+
if (ripgrepFailed(run)) {
|
|
33701
|
+
return { result: { case: "error", value: { path, error: ripgrepError(run) } } };
|
|
33702
|
+
}
|
|
33703
|
+
const tree = new TreeBuilder(path);
|
|
33704
|
+
for (const line of splitNull(run.stdout)) {
|
|
33705
|
+
if (!line)
|
|
33706
|
+
continue;
|
|
33707
|
+
const file = resolve5(path, line);
|
|
33708
|
+
if (options.refused(file))
|
|
33709
|
+
continue;
|
|
33710
|
+
tree.add(file);
|
|
33711
|
+
}
|
|
33712
|
+
const directoryTreeRoot = tree.sorted();
|
|
33713
|
+
return run.timedOut ? { result: { case: "timeout", value: { directoryTreeRoot } } } : { result: { case: "success", value: { directoryTreeRoot } } };
|
|
33714
|
+
} catch (error) {
|
|
33715
|
+
return { result: { case: "error", value: { path, error: errorMessage2(error) } } };
|
|
33716
|
+
}
|
|
33717
|
+
}
|
|
33718
|
+
|
|
33719
|
+
// ../../bridges/cursor-bridge/src/read-boundary.ts
|
|
33720
|
+
var CURSOR_READ_BOUNDARY_REFUSAL = "Coordinators cannot read Orkestrator's data directory, which holds credentials with wider authority than this conversation. This conversation's own attachments stay readable.";
|
|
33721
|
+
function cursorCoordinatorReadBoundary(cwd, env = process.env) {
|
|
33722
|
+
return protectedDataDirBoundary(env[COORDINATOR_PROTECTED_DATA_DIR_ENV], [
|
|
33723
|
+
cwd,
|
|
33724
|
+
canonicalPath(cwd),
|
|
33725
|
+
configuredAttachmentRoot(env)
|
|
33726
|
+
]);
|
|
33727
|
+
}
|
|
33728
|
+
function cursorToolPath(value, cwd) {
|
|
33729
|
+
let path = value.trim();
|
|
33730
|
+
if (path.startsWith("file://")) {
|
|
33731
|
+
try {
|
|
33732
|
+
path = fileURLToPath2(path);
|
|
33733
|
+
} catch {
|
|
33734
|
+
return;
|
|
33735
|
+
}
|
|
33736
|
+
}
|
|
33737
|
+
if (path === "~")
|
|
33738
|
+
path = homedir4();
|
|
33739
|
+
else if (path.startsWith("~/"))
|
|
33740
|
+
path = `${homedir4()}${sep5}${path.slice(2)}`;
|
|
33741
|
+
return isAbsolute5(path) ? resolve6(path) : resolve6(cwd, path);
|
|
33742
|
+
}
|
|
33743
|
+
function cursorReadBoundaryExecutors(boundary, cwd, options = {}) {
|
|
33744
|
+
const refused = (path) => readBoundaryRefuses(boundary, path, cwd);
|
|
33745
|
+
let ripgrep = options.ripgrep;
|
|
33746
|
+
const rg = () => ripgrep ??= resolveRipgrep(cwd);
|
|
33747
|
+
return {
|
|
33748
|
+
overrideReadExecutor: {
|
|
33749
|
+
async execute(_context, args) {
|
|
33750
|
+
const raw = args?.path ?? "";
|
|
33751
|
+
if (raw.trim() === "") {
|
|
33752
|
+
return {
|
|
33753
|
+
result: {
|
|
33754
|
+
case: "error",
|
|
33755
|
+
value: { path: raw, error: "path is empty or only whitespace" }
|
|
33756
|
+
}
|
|
33757
|
+
};
|
|
33758
|
+
}
|
|
33759
|
+
const path = cursorToolPath(raw, cwd);
|
|
33760
|
+
if (path === undefined || refused(path)) {
|
|
33761
|
+
return {
|
|
33762
|
+
result: {
|
|
33763
|
+
case: "rejected",
|
|
33764
|
+
value: { path: path ?? raw, reason: CURSOR_READ_BOUNDARY_REFUSAL }
|
|
33765
|
+
}
|
|
33766
|
+
};
|
|
33767
|
+
}
|
|
33768
|
+
return readFileTool(path, args);
|
|
33769
|
+
}
|
|
33770
|
+
},
|
|
33771
|
+
overrideGrepExecutor: {
|
|
33772
|
+
async execute(_context, args) {
|
|
33773
|
+
const named = args?.path?.trim() ? args.path : ".";
|
|
33774
|
+
const target = cursorToolPath(named, cwd);
|
|
33775
|
+
if (target === undefined || refused(target)) {
|
|
33776
|
+
return { result: { case: "error", value: { error: CURSOR_READ_BOUNDARY_REFUSAL } } };
|
|
33777
|
+
}
|
|
33778
|
+
return grepTool(args ?? {}, { cwd, target, refused, ripgrep: rg() });
|
|
33779
|
+
}
|
|
33780
|
+
},
|
|
33781
|
+
overrideLsExecutor: {
|
|
33782
|
+
async execute(_context, args) {
|
|
33783
|
+
const named = args?.path?.trim() ? args.path : ".";
|
|
33784
|
+
const path = cursorToolPath(named, cwd);
|
|
33785
|
+
if (path === undefined || refused(path)) {
|
|
33786
|
+
return {
|
|
33787
|
+
result: {
|
|
33788
|
+
case: "rejected",
|
|
33789
|
+
value: { path: path ?? named, reason: CURSOR_READ_BOUNDARY_REFUSAL }
|
|
33790
|
+
}
|
|
33791
|
+
};
|
|
33792
|
+
}
|
|
33793
|
+
return lsTool(path, args ?? {}, { refused, ripgrep: rg() });
|
|
33794
|
+
}
|
|
33795
|
+
}
|
|
33796
|
+
};
|
|
33797
|
+
}
|
|
33798
|
+
|
|
32654
33799
|
// ../../bridges/cursor-bridge/src/sdk-runtime.ts
|
|
32655
33800
|
import {
|
|
32656
33801
|
Cursor as Cursor3,
|
|
@@ -32772,11 +33917,10 @@ function setLiveBridgeDiagnostics(enabled) {
|
|
|
32772
33917
|
for (const scope of Array.from(liveScopes))
|
|
32773
33918
|
scope.syncActive();
|
|
32774
33919
|
}
|
|
32775
|
-
function bridgeDebugEnabled(
|
|
33920
|
+
function bridgeDebugEnabled(_bridge, env = process.env) {
|
|
32776
33921
|
if (liveDiagnostics !== undefined && env === process.env)
|
|
32777
33922
|
return liveDiagnostics;
|
|
32778
|
-
|
|
32779
|
-
return readBridgeDebugFlag(value);
|
|
33923
|
+
return readBridgeDebugFlag(env.ORKESTRATOR_BRIDGE_DEBUG);
|
|
32780
33924
|
}
|
|
32781
33925
|
function safeDiagnosticMetrics(value) {
|
|
32782
33926
|
const result = {};
|
|
@@ -33735,7 +34879,7 @@ async function prewarmCursorWorkspace(options, sandboxBoundary) {
|
|
|
33735
34879
|
}
|
|
33736
34880
|
|
|
33737
34881
|
// ../../bridges/cursor-bridge/src/change-evidence.ts
|
|
33738
|
-
import { basename as
|
|
34882
|
+
import { basename as basename3, dirname as dirname4, isAbsolute as isAbsolute6, join as join8, relative as relative4, resolve as resolve7, sep as sep6 } from "node:path";
|
|
33739
34883
|
|
|
33740
34884
|
// ../protocol/src/field-validation.ts
|
|
33741
34885
|
function isPlainRecord(value) {
|
|
@@ -34141,7 +35285,7 @@ function workspaceObservationReportIssues(value) {
|
|
|
34141
35285
|
import { createHash as createHash6, randomUUID } from "node:crypto";
|
|
34142
35286
|
import { readdirSync as readdirSync2, readFileSync as readFileSync2 } from "node:fs";
|
|
34143
35287
|
import { appendFile, mkdir as mkdir2, rename as rename2, rm, writeFile as writeFile2 } from "node:fs/promises";
|
|
34144
|
-
import { join as
|
|
35288
|
+
import { join as join7 } from "node:path";
|
|
34145
35289
|
var DEFAULT_EVIDENCE_SPOOL_LIMITS = {
|
|
34146
35290
|
maxEntries: 2048,
|
|
34147
35291
|
maxEntryBytes: 256 * 1024,
|
|
@@ -34404,7 +35548,7 @@ class ChangeEvidenceSpool {
|
|
|
34404
35548
|
const lines = this.pendingLines.splice(0).join("");
|
|
34405
35549
|
this.enqueueIo(async () => {
|
|
34406
35550
|
await mkdir2(directory, { recursive: true, mode: 448 });
|
|
34407
|
-
await appendFile(
|
|
35551
|
+
await appendFile(join7(directory, ENTRIES_FILE), lines, { mode: 384 });
|
|
34408
35552
|
});
|
|
34409
35553
|
}
|
|
34410
35554
|
persistBody(id, bytes) {
|
|
@@ -34412,9 +35556,9 @@ class ChangeEvidenceSpool {
|
|
|
34412
35556
|
if (!directory || this.restoring)
|
|
34413
35557
|
return;
|
|
34414
35558
|
this.enqueueIo(async () => {
|
|
34415
|
-
const bodies =
|
|
35559
|
+
const bodies = join7(directory, BODY_DIRECTORY);
|
|
34416
35560
|
await mkdir2(bodies, { recursive: true, mode: 448 });
|
|
34417
|
-
await writeFile2(
|
|
35561
|
+
await writeFile2(join7(bodies, bodyFileName(id)), bytes, { mode: 384, flag: "wx" }).catch((error) => {
|
|
34418
35562
|
if (error.code !== "EEXIST")
|
|
34419
35563
|
throw error;
|
|
34420
35564
|
});
|
|
@@ -34424,7 +35568,7 @@ class ChangeEvidenceSpool {
|
|
|
34424
35568
|
const directory = this.directory;
|
|
34425
35569
|
if (!directory)
|
|
34426
35570
|
return;
|
|
34427
|
-
this.enqueueIo(() => rm(
|
|
35571
|
+
this.enqueueIo(() => rm(join7(directory, BODY_DIRECTORY, bodyFileName(id)), { force: true }));
|
|
34428
35572
|
}
|
|
34429
35573
|
compactPersisted() {
|
|
34430
35574
|
const directory = this.directory;
|
|
@@ -34435,7 +35579,7 @@ class ChangeEvidenceSpool {
|
|
|
34435
35579
|
`);
|
|
34436
35580
|
this.enqueueIo(async () => {
|
|
34437
35581
|
await mkdir2(directory, { recursive: true, mode: 448 });
|
|
34438
|
-
const file =
|
|
35582
|
+
const file = join7(directory, ENTRIES_FILE);
|
|
34439
35583
|
const temp = `${file}.${process.pid}.tmp`;
|
|
34440
35584
|
await writeFile2(temp, body ? `${body}
|
|
34441
35585
|
` : "", { mode: 384 });
|
|
@@ -34447,10 +35591,10 @@ class ChangeEvidenceSpool {
|
|
|
34447
35591
|
await this.io;
|
|
34448
35592
|
}
|
|
34449
35593
|
restore(directory) {
|
|
34450
|
-
const bodyDirectory =
|
|
35594
|
+
const bodyDirectory = join7(directory, BODY_DIRECTORY);
|
|
34451
35595
|
try {
|
|
34452
35596
|
for (const name of readdirSync2(bodyDirectory)) {
|
|
34453
|
-
const bytes = new Uint8Array(readFileSync2(
|
|
35597
|
+
const bytes = new Uint8Array(readFileSync2(join7(bodyDirectory, name)));
|
|
34454
35598
|
const id = evidenceBodyId(bytes);
|
|
34455
35599
|
if (bodyFileName(id) !== name)
|
|
34456
35600
|
continue;
|
|
@@ -34462,7 +35606,7 @@ class ChangeEvidenceSpool {
|
|
|
34462
35606
|
} catch {}
|
|
34463
35607
|
let text = "";
|
|
34464
35608
|
try {
|
|
34465
|
-
text = readFileSync2(
|
|
35609
|
+
text = readFileSync2(join7(directory, ENTRIES_FILE), "utf8");
|
|
34466
35610
|
} catch {
|
|
34467
35611
|
return;
|
|
34468
35612
|
}
|
|
@@ -35147,7 +36291,7 @@ function resolveCaptureExecutor(stateDirectory = stateDirectoryPath()) {
|
|
|
35147
36291
|
return "unknown";
|
|
35148
36292
|
if (stateDirectory === CONTAINER_STATE_DIRECTORY)
|
|
35149
36293
|
return "container-worker";
|
|
35150
|
-
if (
|
|
36294
|
+
if (basename3(dirname4(stateDirectory)) === HOST_STATE_ROOT)
|
|
35151
36295
|
return "host-worker";
|
|
35152
36296
|
return "unknown";
|
|
35153
36297
|
}
|
|
@@ -35179,7 +36323,7 @@ var runtime;
|
|
|
35179
36323
|
function currentRuntime() {
|
|
35180
36324
|
if (!runtime) {
|
|
35181
36325
|
const directory = stateDirectoryPath();
|
|
35182
|
-
const spool = new ChangeEvidenceSpool(directory ? { directory:
|
|
36326
|
+
const spool = new ChangeEvidenceSpool(directory ? { directory: join8(directory, "change-evidence") } : {});
|
|
35183
36327
|
runtime = createRuntime(spool, resolveCaptureExecutor());
|
|
35184
36328
|
}
|
|
35185
36329
|
return runtime;
|
|
@@ -35203,11 +36347,11 @@ function evidencePath(value) {
|
|
|
35203
36347
|
if (!nonBlank(value))
|
|
35204
36348
|
return;
|
|
35205
36349
|
const raw = value.trim();
|
|
35206
|
-
const absolute =
|
|
35207
|
-
const inside =
|
|
35208
|
-
if (!inside || inside.startsWith("..") ||
|
|
36350
|
+
const absolute = isAbsolute6(raw) ? raw : resolve7(workingDirectory, raw);
|
|
36351
|
+
const inside = relative4(workingDirectory, absolute);
|
|
36352
|
+
if (!inside || inside.startsWith("..") || isAbsolute6(inside))
|
|
35209
36353
|
return raw;
|
|
35210
|
-
return inside.split(
|
|
36354
|
+
return inside.split(sep6).join("/");
|
|
35211
36355
|
}
|
|
35212
36356
|
function cursorPatchFormat(text) {
|
|
35213
36357
|
if (!text.startsWith("diff --git ") && !text.startsWith("--- "))
|
|
@@ -35637,8 +36781,8 @@ async function cursorMcpConfigRevision(state) {
|
|
|
35637
36781
|
return { fingerprint: "read-only", sources: { user: "excluded", project: "excluded" } };
|
|
35638
36782
|
}
|
|
35639
36783
|
const [user, project] = await Promise.all([
|
|
35640
|
-
fileDigest(
|
|
35641
|
-
policy.projectResources ? fileDigest(
|
|
36784
|
+
fileDigest(join9(configHomeForTests ?? homedir5(), ".cursor", "mcp.json")),
|
|
36785
|
+
policy.projectResources ? fileDigest(join9(workingDirectory, ".cursor", "mcp.json")) : Promise.resolve("excluded")
|
|
35642
36786
|
]);
|
|
35643
36787
|
return {
|
|
35644
36788
|
fingerprint: createHash7("sha256").update(`user=${user}\x00project=${project}`).digest("base64url"),
|
|
@@ -35683,7 +36827,7 @@ async function attach(state) {
|
|
|
35683
36827
|
const mcpServers = await cursorMcpServers(state.agentMcp, {
|
|
35684
36828
|
readOnly,
|
|
35685
36829
|
projectResources: policy.projectResources,
|
|
35686
|
-
...selectServers ? { userServers: selectServers, configHome: configHomeForTests ??
|
|
36830
|
+
...selectServers ? { userServers: selectServers, configHome: configHomeForTests ?? homedir5() } : {}
|
|
35687
36831
|
});
|
|
35688
36832
|
const allowHttpMcp = !readOnly || policy.sandbox === "container";
|
|
35689
36833
|
const [hosted, research] = readOnly ? await Promise.all([
|
|
@@ -35717,6 +36861,7 @@ async function attach(state) {
|
|
|
35717
36861
|
selectsServers: selectServers !== undefined
|
|
35718
36862
|
});
|
|
35719
36863
|
state.loadsProjectRules = settingSources.includes("project");
|
|
36864
|
+
const readBoundary = readOnly ? cursorCoordinatorReadBoundary(workingDirectory) : null;
|
|
35720
36865
|
const options = {
|
|
35721
36866
|
apiKey,
|
|
35722
36867
|
model: modelSelection(state.composer),
|
|
@@ -35726,7 +36871,8 @@ async function attach(state) {
|
|
|
35726
36871
|
settingSources,
|
|
35727
36872
|
sandboxOptions: { enabled: policy.sandbox === "provider" },
|
|
35728
36873
|
autoReview: policy.sandbox === "provider" && policy.approvals === "auto-approve",
|
|
35729
|
-
...customTools ? { customTools } : {}
|
|
36874
|
+
...customTools ? { customTools } : {},
|
|
36875
|
+
...readBoundary ? { resourceProviderOptions: cursorReadBoundaryExecutors(readBoundary, workingDirectory) } : {}
|
|
35730
36876
|
},
|
|
35731
36877
|
...readOnly ? {
|
|
35732
36878
|
tools: [
|
|
@@ -36608,17 +37754,17 @@ function repositoryInstructionsBlock(path, content, truncated) {
|
|
|
36608
37754
|
}
|
|
36609
37755
|
|
|
36610
37756
|
// ../protocol/src/node/repository-instructions.ts
|
|
36611
|
-
import { open as
|
|
36612
|
-
import { join as
|
|
37757
|
+
import { open as open5, realpath as realpath2 } from "node:fs/promises";
|
|
37758
|
+
import { join as join10, relative as relative5, isAbsolute as isAbsolute7 } from "node:path";
|
|
36613
37759
|
var MAX_REPOSITORY_INSTRUCTIONS_BYTES = 256 * 1024;
|
|
36614
37760
|
async function readRepositoryInstructions(cwd, maxBytes = MAX_REPOSITORY_INSTRUCTIONS_BYTES) {
|
|
36615
|
-
const path =
|
|
37761
|
+
const path = join10(cwd, REPOSITORY_INSTRUCTIONS_FILE);
|
|
36616
37762
|
try {
|
|
36617
|
-
const [root, target] = await Promise.all([
|
|
36618
|
-
const inside =
|
|
36619
|
-
if (!inside || inside.startsWith("..") ||
|
|
37763
|
+
const [root, target] = await Promise.all([realpath2(cwd), realpath2(path)]);
|
|
37764
|
+
const inside = relative5(root, target);
|
|
37765
|
+
if (!inside || inside.startsWith("..") || isAbsolute7(inside))
|
|
36620
37766
|
return;
|
|
36621
|
-
const handle = await
|
|
37767
|
+
const handle = await open5(target, "r");
|
|
36622
37768
|
try {
|
|
36623
37769
|
const buffer = Buffer.alloc(maxBytes + 1);
|
|
36624
37770
|
const { bytesRead } = await handle.read(buffer, 0, maxBytes + 1, 0);
|
|
@@ -36813,7 +37959,7 @@ var STRUCTURED_OUTPUT_FAILURE_CODES = new Set([
|
|
|
36813
37959
|
import { randomUUID as randomUUID4 } from "node:crypto";
|
|
36814
37960
|
|
|
36815
37961
|
// ../../bridges/cursor-bridge/src/command-changes.ts
|
|
36816
|
-
import { resolve as
|
|
37962
|
+
import { resolve as resolve9 } from "node:path";
|
|
36817
37963
|
|
|
36818
37964
|
// ../protocol/src/node/command-change-journal.ts
|
|
36819
37965
|
var MAX_JOURNAL_BYTES = 8 * 1024 * 1024;
|
|
@@ -36842,12 +37988,12 @@ function isFileEditToolName(toolName) {
|
|
|
36842
37988
|
// ../protocol/src/node/workspace-change-probe.ts
|
|
36843
37989
|
import { randomUUID as randomUUID3 } from "node:crypto";
|
|
36844
37990
|
import { rmSync as rmSync2 } from "node:fs";
|
|
36845
|
-
import { copyFile, lstat, mkdtemp, rm as rm2 } from "node:fs/promises";
|
|
37991
|
+
import { copyFile, lstat as lstat2, mkdtemp, rm as rm2 } from "node:fs/promises";
|
|
36846
37992
|
import { tmpdir } from "node:os";
|
|
36847
|
-
import { delimiter, isAbsolute as
|
|
37993
|
+
import { delimiter, isAbsolute as isAbsolute8, join as join11, resolve as resolve8 } from "node:path";
|
|
36848
37994
|
|
|
36849
37995
|
// ../protocol/src/node/command-capture.ts
|
|
36850
|
-
import { spawn } from "node:child_process";
|
|
37996
|
+
import { spawn as spawn2 } from "node:child_process";
|
|
36851
37997
|
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
36852
37998
|
import { constants as fsConstants } from "node:fs";
|
|
36853
37999
|
import * as captureFs from "node:fs";
|
|
@@ -37394,7 +38540,7 @@ function spawnCaptured(command, args, options, stdoutFd, stderrFd) {
|
|
|
37394
38540
|
kill: (signal) => child.kill(signal)
|
|
37395
38541
|
};
|
|
37396
38542
|
}
|
|
37397
|
-
const child =
|
|
38543
|
+
const child = spawn2(command, args, {
|
|
37398
38544
|
cwd: options.cwd,
|
|
37399
38545
|
env,
|
|
37400
38546
|
detached,
|
|
@@ -37955,8 +39101,8 @@ class WorkspaceChangeProbe {
|
|
|
37955
39101
|
return;
|
|
37956
39102
|
return {
|
|
37957
39103
|
root,
|
|
37958
|
-
indexPath:
|
|
37959
|
-
objectsPath:
|
|
39104
|
+
indexPath: isAbsolute8(index) ? index : resolve8(cwd, index),
|
|
39105
|
+
objectsPath: isAbsolute8(objects) ? objects : resolve8(cwd, objects)
|
|
37960
39106
|
};
|
|
37961
39107
|
}).catch(() => {
|
|
37962
39108
|
return;
|
|
@@ -37999,8 +39145,8 @@ class WorkspaceChangeProbe {
|
|
|
37999
39145
|
return;
|
|
38000
39146
|
const { root, indexPath } = repo.location;
|
|
38001
39147
|
const started = this.now();
|
|
38002
|
-
const tempIndex =
|
|
38003
|
-
const objectDirectory = await mkdtemp(
|
|
39148
|
+
const tempIndex = join11(this.tempDir, `orkestrator-probe-${randomUUID3()}.index`);
|
|
39149
|
+
const objectDirectory = await mkdtemp(join11(this.tempDir, "orkestrator-probe-objects-"));
|
|
38004
39150
|
temporaryObjectDirectories.add(objectDirectory);
|
|
38005
39151
|
let retained = false;
|
|
38006
39152
|
try {
|
|
@@ -38017,7 +39163,7 @@ class WorkspaceChangeProbe {
|
|
|
38017
39163
|
const included = [];
|
|
38018
39164
|
const skipped = new Map;
|
|
38019
39165
|
for (const path of untracked) {
|
|
38020
|
-
const stats = await
|
|
39166
|
+
const stats = await lstat2(join11(root, path)).catch(() => {
|
|
38021
39167
|
return;
|
|
38022
39168
|
});
|
|
38023
39169
|
if (!stats)
|
|
@@ -38253,7 +39399,7 @@ function classify(toolCall) {
|
|
|
38253
39399
|
if (toolCall.type === "shell") {
|
|
38254
39400
|
if (args.isBackground === true || args.runInBackground === true)
|
|
38255
39401
|
return;
|
|
38256
|
-
const cwd = nonBlank(args.workingDirectory) ?
|
|
39402
|
+
const cwd = nonBlank(args.workingDirectory) ? resolve9(workingDirectory, args.workingDirectory.trim()) : workingDirectory;
|
|
38257
39403
|
return { measure: true, cwd };
|
|
38258
39404
|
}
|
|
38259
39405
|
if (isFileEditToolName(toolCall.type) || CURSOR_FILE_EDIT_TOOLS.has(toolCall.type)) {
|
|
@@ -38880,211 +40026,8 @@ function errorText(error) {
|
|
|
38880
40026
|
return error.trim();
|
|
38881
40027
|
return "The Cursor turn failed";
|
|
38882
40028
|
}
|
|
38883
|
-
|
|
38884
|
-
|
|
38885
|
-
try {
|
|
38886
|
-
return await Promise.race([
|
|
38887
|
-
work,
|
|
38888
|
-
new Promise((_, reject) => {
|
|
38889
|
-
timer = setTimeout(() => reject(new TurnTimeoutError), timeoutMs);
|
|
38890
|
-
timer.unref();
|
|
38891
|
-
})
|
|
38892
|
-
]);
|
|
38893
|
-
} finally {
|
|
38894
|
-
if (timer)
|
|
38895
|
-
clearTimeout(timer);
|
|
38896
|
-
}
|
|
38897
|
-
}
|
|
38898
|
-
// ../../bridges/cursor-bridge/src/prompt-attachments.ts
|
|
38899
|
-
import { constants as constants2 } from "node:fs";
|
|
38900
|
-
import { lstat as lstat2, open as open4, realpath as realpath2 } from "node:fs/promises";
|
|
38901
|
-
import { isAbsolute as isAbsolute5, join as join9, relative as relative4, resolve as resolve6, sep as sep3 } from "node:path";
|
|
38902
|
-
|
|
38903
|
-
class PromptAttachmentError extends Error {
|
|
38904
|
-
code;
|
|
38905
|
-
name = "PromptAttachmentError";
|
|
38906
|
-
constructor(code, message) {
|
|
38907
|
-
super(message);
|
|
38908
|
-
this.code = code;
|
|
38909
|
-
}
|
|
38910
|
-
}
|
|
38911
|
-
var MAX_IMAGE_ATTACHMENT_BYTES = 8 * 1024 * 1024;
|
|
38912
|
-
var MAX_PROMPT_ATTACHMENTS = 20;
|
|
38913
|
-
var MAX_TOTAL_IMAGE_ATTACHMENT_BYTES = 32 * 1024 * 1024;
|
|
38914
|
-
var MAX_ATTACHMENT_PATH_BYTES = 4 * 1024;
|
|
38915
|
-
var MAX_ATTACHMENT_FILENAME_BYTES = 1 * 1024;
|
|
38916
|
-
var READ_CHUNK_BYTES = 64 * 1024;
|
|
38917
|
-
function parsePromptAttachments(value) {
|
|
38918
|
-
if (value === undefined || value === null)
|
|
38919
|
-
return [];
|
|
38920
|
-
if (!Array.isArray(value)) {
|
|
38921
|
-
throw new PromptAttachmentError("attachment_invalid", "attachments must be an array");
|
|
38922
|
-
}
|
|
38923
|
-
if (value.length > MAX_PROMPT_ATTACHMENTS) {
|
|
38924
|
-
throw new PromptAttachmentError("attachment_invalid", `A prompt can carry at most ${MAX_PROMPT_ATTACHMENTS} attachments`);
|
|
38925
|
-
}
|
|
38926
|
-
return value.map((candidate) => {
|
|
38927
|
-
if (candidate === null || typeof candidate !== "object" || Array.isArray(candidate)) {
|
|
38928
|
-
throw new PromptAttachmentError("attachment_invalid", "Each attachment must be an object");
|
|
38929
|
-
}
|
|
38930
|
-
const record = candidate;
|
|
38931
|
-
if (record.type !== "image") {
|
|
38932
|
-
throw new PromptAttachmentError("attachment_invalid", "Cursor accepts image attachments only");
|
|
38933
|
-
}
|
|
38934
|
-
const path = typeof record.path === "string" ? record.path.trim() : "";
|
|
38935
|
-
if (!path || Buffer.byteLength(path) > MAX_ATTACHMENT_PATH_BYTES) {
|
|
38936
|
-
throw new PromptAttachmentError("attachment_invalid", "Each attachment needs a workspace path");
|
|
38937
|
-
}
|
|
38938
|
-
if (path.includes("\x00")) {
|
|
38939
|
-
throw new PromptAttachmentError("attachment_invalid", "An attachment path must not contain null bytes");
|
|
38940
|
-
}
|
|
38941
|
-
const filename = typeof record.filename === "string" && record.filename.trim() && Buffer.byteLength(record.filename) <= MAX_ATTACHMENT_FILENAME_BYTES ? record.filename : undefined;
|
|
38942
|
-
return { type: "image", path, ...filename ? { filename } : {} };
|
|
38943
|
-
});
|
|
38944
|
-
}
|
|
38945
|
-
async function readPromptImages(attachments, workspaceRoot) {
|
|
38946
|
-
const images = [];
|
|
38947
|
-
let totalBytes = 0;
|
|
38948
|
-
for (const attachment of attachments) {
|
|
38949
|
-
const { bytes, absolutePath } = await readWorkspaceImage(attachment.path, workspaceRoot);
|
|
38950
|
-
totalBytes += bytes.length;
|
|
38951
|
-
if (totalBytes > MAX_TOTAL_IMAGE_ATTACHMENT_BYTES) {
|
|
38952
|
-
throw new PromptAttachmentError("attachment_too_large", "Image attachments exceed the 32MB total limit");
|
|
38953
|
-
}
|
|
38954
|
-
images.push({
|
|
38955
|
-
data: bytes.toString("base64"),
|
|
38956
|
-
mimeType: imageMimeType(bytes),
|
|
38957
|
-
path: attachment.path,
|
|
38958
|
-
absolutePath,
|
|
38959
|
-
...attachment.filename ? { filename: attachment.filename } : {}
|
|
38960
|
-
});
|
|
38961
|
-
}
|
|
38962
|
-
return images;
|
|
38963
|
-
}
|
|
38964
|
-
function imageMimeType(bytes) {
|
|
38965
|
-
if (bytes.length >= 8 && bytes.subarray(0, 8).equals(Buffer.from([137, 80, 78, 71, 13, 10, 26, 10])))
|
|
38966
|
-
return "image/png";
|
|
38967
|
-
if (bytes.length >= 3 && bytes[0] === 255 && bytes[1] === 216 && bytes[2] === 255) {
|
|
38968
|
-
return "image/jpeg";
|
|
38969
|
-
}
|
|
38970
|
-
if (bytes.length >= 6 && (bytes.subarray(0, 6).toString("latin1") === "GIF87a" || bytes.subarray(0, 6).toString("latin1") === "GIF89a"))
|
|
38971
|
-
return "image/gif";
|
|
38972
|
-
if (bytes.length >= 12 && bytes.subarray(0, 4).toString("latin1") === "RIFF" && bytes.subarray(8, 12).toString("latin1") === "WEBP")
|
|
38973
|
-
return "image/webp";
|
|
38974
|
-
throw new PromptAttachmentError("attachment_unsupported_format", "Image attachments must be PNG, JPEG, GIF, or WebP");
|
|
38975
|
-
}
|
|
38976
|
-
function attachmentErrorForFsFailure(error) {
|
|
38977
|
-
const code = error?.code;
|
|
38978
|
-
if (code === "ELOOP") {
|
|
38979
|
-
return new PromptAttachmentError("attachment_symlink_not_allowed", "Image attachments must be regular workspace files, not symbolic links");
|
|
38980
|
-
}
|
|
38981
|
-
return new PromptAttachmentError("attachment_read_failed", "Image attachment could not be read from the workspace");
|
|
38982
|
-
}
|
|
38983
|
-
var BRIDGE_ATTACHMENT_ROOT_ENV = "ORKESTRATOR_BRIDGE_ATTACHMENT_ROOT";
|
|
38984
|
-
function configuredAttachmentRoot(env = process.env) {
|
|
38985
|
-
const value = env[BRIDGE_ATTACHMENT_ROOT_ENV]?.trim();
|
|
38986
|
-
return value && isAbsolute5(value) ? resolve6(value) : undefined;
|
|
38987
|
-
}
|
|
38988
|
-
function attachmentContainmentRoot(filePath, workspaceRoot, extraRoot = configuredAttachmentRoot()) {
|
|
38989
|
-
if (extraRoot && isAbsolute5(filePath) && isPathWithin(extraRoot, resolve6(filePath))) {
|
|
38990
|
-
return extraRoot;
|
|
38991
|
-
}
|
|
38992
|
-
return resolve6(workspaceRoot);
|
|
38993
|
-
}
|
|
38994
|
-
function isPathWithin(root, candidate) {
|
|
38995
|
-
if (candidate === root)
|
|
38996
|
-
return true;
|
|
38997
|
-
const childPath = relative4(root, candidate);
|
|
38998
|
-
return Boolean(childPath) && childPath !== ".." && !childPath.startsWith(`..${sep3}`) && !isAbsolute5(childPath);
|
|
38999
|
-
}
|
|
39000
|
-
async function assertNoSymlinkComponents(root, targetPath) {
|
|
39001
|
-
let currentPath = root;
|
|
39002
|
-
for (const segment of relative4(root, targetPath).split(sep3).filter(Boolean)) {
|
|
39003
|
-
currentPath = join9(currentPath, segment);
|
|
39004
|
-
const stats = await lstat2(currentPath).catch((error) => {
|
|
39005
|
-
throw attachmentErrorForFsFailure(error);
|
|
39006
|
-
});
|
|
39007
|
-
if (stats.isSymbolicLink()) {
|
|
39008
|
-
throw new PromptAttachmentError("attachment_symlink_not_allowed", "Image attachments must be regular workspace files, not symbolic links");
|
|
39009
|
-
}
|
|
39010
|
-
}
|
|
39011
|
-
}
|
|
39012
|
-
async function assertOpenedWorkspaceFile(targetPath, canonicalRoot, openedStats) {
|
|
39013
|
-
const [pathStats, canonicalTarget] = await Promise.all([
|
|
39014
|
-
lstat2(targetPath),
|
|
39015
|
-
realpath2(targetPath)
|
|
39016
|
-
]).catch((error) => {
|
|
39017
|
-
throw attachmentErrorForFsFailure(error);
|
|
39018
|
-
});
|
|
39019
|
-
if (pathStats.isSymbolicLink()) {
|
|
39020
|
-
throw new PromptAttachmentError("attachment_symlink_not_allowed", "Image attachments must be regular workspace files, not symbolic links");
|
|
39021
|
-
}
|
|
39022
|
-
if (!pathStats.isFile() || !openedStats.isFile() || pathStats.dev !== openedStats.dev || pathStats.ino !== openedStats.ino) {
|
|
39023
|
-
throw new PromptAttachmentError("attachment_not_regular_file", "Image attachment is not a stable regular workspace file");
|
|
39024
|
-
}
|
|
39025
|
-
if (!isPathWithin(canonicalRoot, canonicalTarget)) {
|
|
39026
|
-
throw new PromptAttachmentError("attachment_outside_workspace", "Image attachment must be contained in the current workspace");
|
|
39027
|
-
}
|
|
39028
|
-
}
|
|
39029
|
-
function assertStableRead(initial, final, bytesRead) {
|
|
39030
|
-
if (final.dev !== initial.dev || final.ino !== initial.ino || final.size !== initial.size || final.size !== bytesRead || final.mtimeMs !== initial.mtimeMs || final.ctimeMs !== initial.ctimeMs) {
|
|
39031
|
-
throw new PromptAttachmentError("attachment_changed", "Image attachment changed while it was being read; attach it again");
|
|
39032
|
-
}
|
|
39033
|
-
}
|
|
39034
|
-
async function readWorkspaceImage(filePath, workspaceRoot) {
|
|
39035
|
-
const lexicalRoot = attachmentContainmentRoot(filePath, workspaceRoot);
|
|
39036
|
-
const targetPath = isAbsolute5(filePath) ? resolve6(filePath) : resolve6(lexicalRoot, filePath);
|
|
39037
|
-
if (!isPathWithin(lexicalRoot, targetPath)) {
|
|
39038
|
-
throw new PromptAttachmentError("attachment_outside_workspace", "Image attachment must be contained in the current workspace");
|
|
39039
|
-
}
|
|
39040
|
-
const canonicalRoot = await realpath2(lexicalRoot).catch((error) => {
|
|
39041
|
-
throw attachmentErrorForFsFailure(error);
|
|
39042
|
-
});
|
|
39043
|
-
await assertNoSymlinkComponents(lexicalRoot, targetPath);
|
|
39044
|
-
const canonicalTarget = await realpath2(targetPath).catch((error) => {
|
|
39045
|
-
throw attachmentErrorForFsFailure(error);
|
|
39046
|
-
});
|
|
39047
|
-
if (!isPathWithin(canonicalRoot, canonicalTarget)) {
|
|
39048
|
-
throw new PromptAttachmentError("attachment_outside_workspace", "Image attachment must be contained in the current workspace");
|
|
39049
|
-
}
|
|
39050
|
-
const noFollow = constants2.O_NOFOLLOW ?? 0;
|
|
39051
|
-
const handle = await open4(targetPath, constants2.O_RDONLY | noFollow).catch((error) => {
|
|
39052
|
-
throw attachmentErrorForFsFailure(error);
|
|
39053
|
-
});
|
|
39054
|
-
try {
|
|
39055
|
-
const initialStats = await handle.stat();
|
|
39056
|
-
await assertOpenedWorkspaceFile(targetPath, canonicalRoot, initialStats);
|
|
39057
|
-
if (initialStats.size > MAX_IMAGE_ATTACHMENT_BYTES) {
|
|
39058
|
-
throw new PromptAttachmentError("attachment_too_large", "Image attachment exceeds the 8MB limit");
|
|
39059
|
-
}
|
|
39060
|
-
const chunks = [];
|
|
39061
|
-
let totalBytes = 0;
|
|
39062
|
-
while (totalBytes <= MAX_IMAGE_ATTACHMENT_BYTES) {
|
|
39063
|
-
const remaining = MAX_IMAGE_ATTACHMENT_BYTES + 1 - totalBytes;
|
|
39064
|
-
const chunk = Buffer.allocUnsafe(Math.min(READ_CHUNK_BYTES, remaining));
|
|
39065
|
-
const { bytesRead } = await handle.read(chunk, 0, chunk.length, null);
|
|
39066
|
-
if (bytesRead === 0)
|
|
39067
|
-
break;
|
|
39068
|
-
chunks.push(chunk.subarray(0, bytesRead));
|
|
39069
|
-
totalBytes += bytesRead;
|
|
39070
|
-
}
|
|
39071
|
-
if (totalBytes > MAX_IMAGE_ATTACHMENT_BYTES) {
|
|
39072
|
-
throw new PromptAttachmentError("attachment_too_large", "Image attachment exceeds the 8MB limit");
|
|
39073
|
-
}
|
|
39074
|
-
if (totalBytes === 0) {
|
|
39075
|
-
throw new PromptAttachmentError("attachment_empty", "Image attachment file is empty");
|
|
39076
|
-
}
|
|
39077
|
-
const finalStats = await handle.stat();
|
|
39078
|
-
await assertOpenedWorkspaceFile(targetPath, canonicalRoot, finalStats);
|
|
39079
|
-
assertStableRead(initialStats, finalStats, totalBytes);
|
|
39080
|
-
return { bytes: Buffer.concat(chunks, totalBytes), absolutePath: targetPath };
|
|
39081
|
-
} catch (error) {
|
|
39082
|
-
if (error instanceof PromptAttachmentError)
|
|
39083
|
-
throw error;
|
|
39084
|
-
throw attachmentErrorForFsFailure(error);
|
|
39085
|
-
} finally {
|
|
39086
|
-
await handle.close();
|
|
39087
|
-
}
|
|
40029
|
+
function withTimeout3(work, timeoutMs) {
|
|
40030
|
+
return boundedWaitOrThrow(work, timeoutMs, () => new TurnTimeoutError);
|
|
39088
40031
|
}
|
|
39089
40032
|
// ../protocol/src/node/transcript-window.ts
|
|
39090
40033
|
import { Buffer as Buffer5 } from "node:buffer";
|
|
@@ -39460,6 +40403,11 @@ function applyBridgeLogPolicy(value, env = process.env) {
|
|
|
39460
40403
|
return { status: 200, body: { applied: true, seq: policy.seq, diagnostics } };
|
|
39461
40404
|
}
|
|
39462
40405
|
|
|
40406
|
+
// ../protocol/src/terminal-text.ts
|
|
40407
|
+
var MAX_STRING_LENGTH = 8 * 1024;
|
|
40408
|
+
var BUDGET_FLOOR = 4 * 1024;
|
|
40409
|
+
var MAX_MOVE = 4 * 1024;
|
|
40410
|
+
|
|
39463
40411
|
// ../protocol/src/human-prompts.ts
|
|
39464
40412
|
var HUMAN_PROMPT_SCAN_BYTES = 16 * 1024;
|
|
39465
40413
|
var HUMAN_PROMPT_KINDS = new Set([
|
|
@@ -39542,18 +40490,8 @@ async function closeSessionPermanently(state, ackTimeoutMs = CLOSE_ACK_TIMEOUT_M
|
|
|
39542
40490
|
state.closing = undefined;
|
|
39543
40491
|
});
|
|
39544
40492
|
}
|
|
39545
|
-
const
|
|
39546
|
-
|
|
39547
|
-
const timedOut = new Promise((resolve) => {
|
|
39548
|
-
timer = setTimeout(() => resolve("pending"), ackTimeoutMs);
|
|
39549
|
-
timer.unref?.();
|
|
39550
|
-
});
|
|
39551
|
-
try {
|
|
39552
|
-
return await Promise.race([operation.then(() => "closed"), timedOut]);
|
|
39553
|
-
} finally {
|
|
39554
|
-
if (timer)
|
|
39555
|
-
clearTimeout(timer);
|
|
39556
|
-
}
|
|
40493
|
+
const outcome = await boundedWait(state.closing, ackTimeoutMs);
|
|
40494
|
+
return outcome.settled ? "closed" : "pending";
|
|
39557
40495
|
}
|
|
39558
40496
|
async function runClose(state) {
|
|
39559
40497
|
if (!state.closeFenced) {
|
|
@@ -39602,6 +40540,27 @@ function requestStop(state) {
|
|
|
39602
40540
|
}
|
|
39603
40541
|
}
|
|
39604
40542
|
|
|
40543
|
+
// ../protocol/src/contract/ipc-error.ts
|
|
40544
|
+
var REGISTERED_ERROR_CODES = {
|
|
40545
|
+
"unknown-command": { domain: "text", command: "text" },
|
|
40546
|
+
"unsupported-version": { domain: "text", range: "range", command: "text" },
|
|
40547
|
+
"unsupported-field": { domain: "text", field: "text", command: "text" },
|
|
40548
|
+
"kanban-request-id-conflict": { record: "text" },
|
|
40549
|
+
"native-job-receipt-capacity": { limit: "count" },
|
|
40550
|
+
"native-agent-provider-session-missing": {},
|
|
40551
|
+
"container-lifecycle": { reason: "text" },
|
|
40552
|
+
"mcp-management": { reason: "text" },
|
|
40553
|
+
"pane-layout-revision-conflict": {},
|
|
40554
|
+
"design-revision-conflict": {},
|
|
40555
|
+
"prompt-queue-message-conflict": {},
|
|
40556
|
+
"unknown-node": {},
|
|
40557
|
+
"node-admin-refused": {},
|
|
40558
|
+
"node-scope-closed": {},
|
|
40559
|
+
"node-unavailable": {}
|
|
40560
|
+
};
|
|
40561
|
+
var REGISTERED_ERROR_CODE_LIST = Object.keys(REGISTERED_ERROR_CODES);
|
|
40562
|
+
var MAX_COUNT = 2 ** 31 - 1;
|
|
40563
|
+
|
|
39605
40564
|
// ../protocol/src/mcp-management.ts
|
|
39606
40565
|
var MCP_CONFIG_REPORTING_VERSION = 1;
|
|
39607
40566
|
var MCP_MANAGEMENT_LIMITS = {
|
|
@@ -40645,11 +41604,6 @@ async function routeGlobal(request, response, url) {
|
|
|
40645
41604
|
json(response, 200, { models: await listModels() });
|
|
40646
41605
|
return true;
|
|
40647
41606
|
}
|
|
40648
|
-
if (url.pathname === "/global/usage" && request.method === "GET") {
|
|
40649
|
-
const account = await refreshPlanAccountWindows();
|
|
40650
|
-
json(response, 200, { account: account ?? null });
|
|
40651
|
-
return true;
|
|
40652
|
-
}
|
|
40653
41607
|
if (url.pathname === "/global/refresh-catalog" && request.method === "POST") {
|
|
40654
41608
|
refreshModels();
|
|
40655
41609
|
json(response, 200, { ok: true });
|
|
@@ -40785,8 +41739,8 @@ async function routeSession(request, response, url, clientSignal) {
|
|
|
40785
41739
|
return json(response, 200, unsupportedCommandRefresh());
|
|
40786
41740
|
}
|
|
40787
41741
|
const tombstoned = hasRestoredTombstone(match[1]);
|
|
40788
|
-
if (tombstoned &&
|
|
40789
|
-
return await answerCloseOperation(response, closeRestoredTombstone(match[1])
|
|
41742
|
+
if (tombstoned && isCloseRequest(action, request)) {
|
|
41743
|
+
return await answerCloseOperation(response, closeRestoredTombstone(match[1]));
|
|
40790
41744
|
}
|
|
40791
41745
|
if (isCloseRequest(action, request) && !subject) {
|
|
40792
41746
|
return json(response, 200, { closed: true, missing: true });
|
|
@@ -40946,11 +41900,8 @@ async function routeSession(request, response, url, clientSignal) {
|
|
|
40946
41900
|
if (action === "prompt" && request.method === "POST") {
|
|
40947
41901
|
return await handlePrompt(request, response, state, clientSignal);
|
|
40948
41902
|
}
|
|
40949
|
-
if (!action && request.method === "DELETE") {
|
|
40950
|
-
return await answerCloseOperation(response, closeSessionPermanently(state), "delete");
|
|
40951
|
-
}
|
|
40952
41903
|
if (isCloseRequest(action, request) && !subject) {
|
|
40953
|
-
return await answerCloseOperation(response, closeSessionPermanently(state)
|
|
41904
|
+
return await answerCloseOperation(response, closeSessionPermanently(state));
|
|
40954
41905
|
}
|
|
40955
41906
|
return json(response, 405, { error: "Method not allowed" });
|
|
40956
41907
|
}
|
|
@@ -41047,12 +41998,12 @@ function rejectSteer(response, requestId, reason) {
|
|
|
41047
41998
|
function isCloseRequest(action, request) {
|
|
41048
41999
|
return action === "close" && request.method === "POST";
|
|
41049
42000
|
}
|
|
41050
|
-
async function answerCloseOperation(response, operation
|
|
42001
|
+
async function answerCloseOperation(response, operation) {
|
|
41051
42002
|
let outcome;
|
|
41052
42003
|
try {
|
|
41053
42004
|
outcome = await operation;
|
|
41054
42005
|
} catch (error) {
|
|
41055
|
-
if (
|
|
42006
|
+
if (!(error instanceof PersistenceError))
|
|
41056
42007
|
throw error;
|
|
41057
42008
|
return json(response, 503, {
|
|
41058
42009
|
closed: false,
|
|
@@ -41062,9 +42013,9 @@ async function answerCloseOperation(response, operation, route) {
|
|
|
41062
42013
|
code: error.code
|
|
41063
42014
|
});
|
|
41064
42015
|
}
|
|
41065
|
-
return answerClose(response, outcome
|
|
42016
|
+
return answerClose(response, outcome);
|
|
41066
42017
|
}
|
|
41067
|
-
function answerClose(response, outcome
|
|
42018
|
+
function answerClose(response, outcome) {
|
|
41068
42019
|
if (outcome === "pending") {
|
|
41069
42020
|
return json(response, 503, {
|
|
41070
42021
|
closed: false,
|
|
@@ -41072,7 +42023,7 @@ function answerClose(response, outcome, route) {
|
|
|
41072
42023
|
error: "Cursor session close is still in progress"
|
|
41073
42024
|
});
|
|
41074
42025
|
}
|
|
41075
|
-
return json(response, 200,
|
|
42026
|
+
return json(response, 200, { closed: true, retained: true });
|
|
41076
42027
|
}
|
|
41077
42028
|
async function handleConfig(request, response, state) {
|
|
41078
42029
|
const body = await readJson(request);
|