orkestrator 2.37.4-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 +45 -12
- package/dist/main.js +1275 -1518
- package/package.json +4 -4
- package/resources/acp-bridge/dist/index.js +23 -51
- package/resources/claude-bridge/dist/index.js +98 -296
- package/resources/codex-bridge/dist/index.js +23 -139
- package/resources/cursor-bridge/dist/index.js +29 -27
- package/resources/cursor-bridge/runtime/install.json +1 -1
- package/resources/pi-bridge/dist/index.js +26 -34
- 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
|
@@ -250,10 +250,13 @@ var BRIDGE_LOG_AREAS = defineLogAreas({
|
|
|
250
250
|
"prompt.accepted": "The route accepted a prompt and answered 202.",
|
|
251
251
|
"prompt.failed": "A prompt turn failed; the session reports the error.",
|
|
252
252
|
"prompt.processing-failed": "A prompt accepted by the route failed while processing.",
|
|
253
|
+
"prompt.processing-usage-limited": "A prompt accepted by the route ended on a usage limit; the turn already logged prompt.usage-limited.",
|
|
253
254
|
"prompt.received": "A prompt reached the bridge; only its length is logged.",
|
|
254
255
|
"prompt.send-failed": "A prompt request failed; the route answered with an error.",
|
|
256
|
+
"prompt.usage-limited": "A prompt turn ended because the account's plan allowance is used up; the session reports the limit.",
|
|
255
257
|
"query.close-failed": "Stopping the Claude query failed while closing a tab; the close stays pending.",
|
|
256
258
|
"query.failed": "A Claude query ended with an error result.",
|
|
259
|
+
"query.usage-limited": "Claude refused a query because the account's plan allowance is used up; the turn reports the limit.",
|
|
257
260
|
"question.answer-failed": "The answer-question route failed.",
|
|
258
261
|
"question.answering": "Answering a parked question.",
|
|
259
262
|
"question.answers-prepared": "The route prepared a question answer for the session.",
|
|
@@ -452,10 +455,10 @@ var DESKTOP_LOG_AREAS = defineLogAreas({
|
|
|
452
455
|
"dev-mode.ignored-packaged": "A packaged app was launched with ELECTRON_DEV=1 and ignored it; it loads its bundled renderer.",
|
|
453
456
|
"instance.already-running": "Another instance holds this data directory; this one will quit.",
|
|
454
457
|
"main-thread.stalled": {
|
|
455
|
-
description: "A timer fired late, so windows, IPC and the stdout reader waited.",
|
|
458
|
+
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.",
|
|
456
459
|
essential: true,
|
|
457
460
|
minLevel: "error",
|
|
458
|
-
fields: { lagMs: "number", intervalMs: "number" }
|
|
461
|
+
fields: { lagMs: "number", intervalMs: "number", cpuMs: "number" }
|
|
459
462
|
},
|
|
460
463
|
"process-memory": "Development only: working set per Electron process type, sampled on an interval.",
|
|
461
464
|
"process-memory.failed": "Development only: one process memory sample could not be read.",
|
|
@@ -954,12 +957,13 @@ var RUNTIME_LOG_AREAS = defineLogAreas({
|
|
|
954
957
|
description: "This process's event loop. A stall of 10 seconds or more is written at error, so no level hides it.",
|
|
955
958
|
events: {
|
|
956
959
|
stalled: {
|
|
957
|
-
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,
|
|
960
|
+
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.",
|
|
958
961
|
essential: true,
|
|
959
962
|
minLevel: "error",
|
|
960
963
|
fields: {
|
|
961
964
|
lagMs: "number",
|
|
962
965
|
intervalMs: "number",
|
|
966
|
+
cpuMs: "number",
|
|
963
967
|
storageMs: "number",
|
|
964
968
|
storageDatabase: "label",
|
|
965
969
|
storageOp: "label",
|
|
@@ -967,7 +971,8 @@ var RUNTIME_LOG_AREAS = defineLogAreas({
|
|
|
967
971
|
storageLongestMs: "number",
|
|
968
972
|
storageBusy: "boolean",
|
|
969
973
|
commandsInFlight: "number",
|
|
970
|
-
blockingCommandMs: "number"
|
|
974
|
+
blockingCommandMs: "number",
|
|
975
|
+
jobsInWindow: "number"
|
|
971
976
|
}
|
|
972
977
|
}
|
|
973
978
|
}
|
|
@@ -1007,6 +1012,8 @@ var TERMINAL_LOG_AREAS = defineLogAreas({
|
|
|
1007
1012
|
"pty.exit-notify-failed": "Notifying a terminal's exit failed.",
|
|
1008
1013
|
"pty.late-exit-listener-failed": "A listener added after a terminal exited threw.",
|
|
1009
1014
|
"setup.pty-reused": "A setup terminal reused its existing PTY.",
|
|
1015
|
+
"setup.pty-retired": "A setup retry ended the terminal the previous run left open, so the new run gets its own.",
|
|
1016
|
+
"setup.pty-retire-failed": "A setup retry could not end the previous run's process tree, so it kept that terminal and started nothing.",
|
|
1010
1017
|
"setup.pty-spawning": "A setup terminal is spawning its PTY. The argument count only, never the arguments.",
|
|
1011
1018
|
"setup.pty-spawned": "A setup terminal's PTY started.",
|
|
1012
1019
|
"setup.pty-exited": "A setup terminal's PTY exited.",
|
|
@@ -1318,6 +1325,8 @@ var BUILD_PIPELINE_LOG_AREAS = defineLogAreas({
|
|
|
1318
1325
|
"workspace.waiting": "A pipeline is waiting for its workspace; written once per reason.",
|
|
1319
1326
|
"rewind.pending": "A pipeline's code rewind has not finished; written once per reason.",
|
|
1320
1327
|
"kanban.status-failed": "A restarted pipeline's Kanban status could not be set; it retries shortly.",
|
|
1328
|
+
"kanban.environment-deleted-read-failed": "The pipelines of an environment being deleted could not be read, so their tickets keep their columns.",
|
|
1329
|
+
"kanban.environment-deleted-update-failed": "The ticket of a pipeline whose environment was deleted could not be moved; the deletion goes on.",
|
|
1321
1330
|
"usage.read-failed": "Reading a stage session's token usage failed.",
|
|
1322
1331
|
"checkpoint.deferred": "A stage transcript checkpoint could not be written yet; the provider's history stands.",
|
|
1323
1332
|
"checkpoint.not-committed": "A stage transcript checkpoint was reverted in the commit that should have kept it.",
|
|
@@ -1368,6 +1377,7 @@ var CHANGE_TRACKING_LOG_AREAS = defineLogAreas({
|
|
|
1368
1377
|
"baseline.update-failed": "An environment's diff baseline could not be updated.",
|
|
1369
1378
|
"scan.watcher-failed": "An environment's diff watcher failed; its scans fall back to polling.",
|
|
1370
1379
|
"scan.failed": "A diff scan failed; the last results stay, marked stale, and the scan is retried.",
|
|
1380
|
+
"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.",
|
|
1371
1381
|
"scan.freshness-read-failed": "Reading whether an environment's remote is fresh failed.",
|
|
1372
1382
|
"scan.listener-failed": "A change-tracking scan listener threw; the scan itself stands.",
|
|
1373
1383
|
"emit.diff-stats-failed": "A diff stats change could not be emitted to its sink.",
|
|
@@ -1545,9 +1555,9 @@ var DOCKER_LOG_AREAS = defineLogAreas({
|
|
|
1545
1555
|
"git-mirror.clone-fallback": "A new environment could not clone from its project's Git mirror and cloned from the remote.",
|
|
1546
1556
|
"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.",
|
|
1547
1557
|
"opencode.warm-incomplete": "OpenCode did not finish loading /workspace in a container.",
|
|
1548
|
-
"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
|
|
1558
|
+
"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.",
|
|
1549
1559
|
"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.",
|
|
1550
|
-
"opencode.project-config-filtered": "Values were left out of a checkout's OpenCode configuration before a launched server reads it
|
|
1560
|
+
"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.",
|
|
1551
1561
|
"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.",
|
|
1552
1562
|
"lifecycle-event.reconcile-failed": "Reconciling an environment after a container start or stop event failed; the next status read retries.",
|
|
1553
1563
|
"login-keeper.pass-failed": "A Claude login keeper pass failed; the next interval retries.",
|
|
@@ -1584,7 +1594,7 @@ var DOCKER_LOG_AREAS = defineLogAreas({
|
|
|
1584
1594
|
fields: { provider: "label", containerPort: "number" }
|
|
1585
1595
|
},
|
|
1586
1596
|
"bridge.listener-refused": {
|
|
1587
|
-
description: "The socket listening on a container bridge's port is not the one the bridge the backend started opened
|
|
1597
|
+
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`.",
|
|
1588
1598
|
essential: true,
|
|
1589
1599
|
fields: { provider: "label", reason: "label" }
|
|
1590
1600
|
},
|
|
@@ -2106,6 +2116,7 @@ var WEB_KANBAN_LOG_AREAS = defineLogAreas({
|
|
|
2106
2116
|
"task.move-failed": "A task move failed and its status was rolled back.",
|
|
2107
2117
|
"comment.add-failed": "A comment could not be added to a task.",
|
|
2108
2118
|
"comment.delete-failed": "A comment could not be deleted from a task.",
|
|
2119
|
+
"pr.merge-failed": "Merging a ticket's pull request from its Notes tab failed; the error was shown to the user.",
|
|
2109
2120
|
"image.add-failed": "An image could not be added to a task.",
|
|
2110
2121
|
"image.delete-failed": "An image could not be deleted from a task.",
|
|
2111
2122
|
"notes.load-failed": "Project notes could not be loaded; the editor stays disabled.",
|
|
@@ -3402,11 +3413,10 @@ function setLiveBridgeDiagnostics(enabled) {
|
|
|
3402
3413
|
for (const scope of Array.from(liveScopes))
|
|
3403
3414
|
scope.syncActive();
|
|
3404
3415
|
}
|
|
3405
|
-
function bridgeDebugEnabled(
|
|
3416
|
+
function bridgeDebugEnabled(_bridge, env = process.env) {
|
|
3406
3417
|
if (liveDiagnostics !== undefined && env === process.env)
|
|
3407
3418
|
return liveDiagnostics;
|
|
3408
|
-
|
|
3409
|
-
return readBridgeDebugFlag(value);
|
|
3419
|
+
return readBridgeDebugFlag(env.ORKESTRATOR_BRIDGE_DEBUG);
|
|
3410
3420
|
}
|
|
3411
3421
|
function safeDiagnosticMetrics(value) {
|
|
3412
3422
|
const result = {};
|
|
@@ -6871,26 +6881,6 @@ function claudePlanWindowFromKind(kind, modelName) {
|
|
|
6871
6881
|
}
|
|
6872
6882
|
return;
|
|
6873
6883
|
}
|
|
6874
|
-
var LEGACY_CLAUDE_WINDOW_LABELS = {
|
|
6875
|
-
"five hour": "five_hour",
|
|
6876
|
-
session: "five_hour",
|
|
6877
|
-
weekly: "seven_day",
|
|
6878
|
-
"weekly all": "seven_day",
|
|
6879
|
-
"weekly (oauth apps)": "seven_day_oauth_apps"
|
|
6880
|
-
};
|
|
6881
|
-
function claudePlanWindowFromLabel(label) {
|
|
6882
|
-
const normalized = label.trim().toLowerCase();
|
|
6883
|
-
const legacyId = LEGACY_CLAUDE_WINDOW_LABELS[normalized];
|
|
6884
|
-
for (const [id, meta] of Object.entries(CLAUDE_PLAN_WINDOW_LABELS)) {
|
|
6885
|
-
if (id === legacyId || meta.label.toLowerCase() === normalized)
|
|
6886
|
-
return { id, ...meta };
|
|
6887
|
-
}
|
|
6888
|
-
const model = label.trim().match(/^weekly \((.+)\)$/i)?.[1] ?? label.trim().match(/^weekly (.+) limit$/i)?.[1];
|
|
6889
|
-
if (!model)
|
|
6890
|
-
return;
|
|
6891
|
-
const known = Object.entries(CLAUDE_PLAN_WINDOW_LABELS).find(([id]) => id === `seven_day_${model.trim().toLowerCase()}`);
|
|
6892
|
-
return known ? { id: known[0], ...known[1] } : claudeModelWeeklyWindow(model);
|
|
6893
|
-
}
|
|
6894
6884
|
|
|
6895
6885
|
// ../../bridges/claude-bridge/src/services/event-message-id.ts
|
|
6896
6886
|
function eventMessageId(event) {
|
|
@@ -7708,21 +7698,6 @@ async function updateSessionPreferences(sdkSessionId, update) {
|
|
|
7708
7698
|
}).catch(() => {});
|
|
7709
7699
|
return write;
|
|
7710
7700
|
}
|
|
7711
|
-
async function deleteSessionPreferences(sdkSessionId) {
|
|
7712
|
-
const writeKey = normalizedSessionId(sdkSessionId);
|
|
7713
|
-
const path = preferencesPath(sdkSessionId);
|
|
7714
|
-
if (!writeKey || !path)
|
|
7715
|
-
return;
|
|
7716
|
-
const previous = pendingWrites.get(writeKey) ?? Promise.resolve();
|
|
7717
|
-
const deletion = previous.catch(() => {}).then(() => withPreferenceFileLock(path, () => rm(path, { force: true })));
|
|
7718
|
-
pendingWrites.set(writeKey, deletion);
|
|
7719
|
-
deletion.finally(() => {
|
|
7720
|
-
if (pendingWrites.get(writeKey) === deletion) {
|
|
7721
|
-
pendingWrites.delete(writeKey);
|
|
7722
|
-
}
|
|
7723
|
-
}).catch(() => {});
|
|
7724
|
-
return deletion;
|
|
7725
|
-
}
|
|
7726
7701
|
|
|
7727
7702
|
// ../../bridges/claude-bridge/src/services/session-manager-core.ts
|
|
7728
7703
|
import { execFile } from "node:child_process";
|
|
@@ -7743,7 +7718,6 @@ var pendingPromptDispatchClaims = new Map;
|
|
|
7743
7718
|
var IDLE_TRANSCRIPT_EVICTION_MS = 30 * 60 * 1000;
|
|
7744
7719
|
var IDLE_TRANSCRIPT_SWEEP_INTERVAL_MS = 5 * 60 * 1000;
|
|
7745
7720
|
var STRUCTURED_USAGE_REQUEST_TIMEOUT_MS = 1000;
|
|
7746
|
-
var PLAN_USAGE_PROBE_TIMEOUT_MS = 1e4;
|
|
7747
7721
|
|
|
7748
7722
|
class StructuredUsageRequestTimeoutError extends Error {
|
|
7749
7723
|
constructor(timeoutMs = STRUCTURED_USAGE_REQUEST_TIMEOUT_MS) {
|
|
@@ -8502,8 +8476,6 @@ async function persistedSessionExistsOnDisk(sdkSessionId) {
|
|
|
8502
8476
|
return true;
|
|
8503
8477
|
try {
|
|
8504
8478
|
const sdk = await claudeSdk();
|
|
8505
|
-
if (typeof sdk.getSessionInfo !== "function")
|
|
8506
|
-
return true;
|
|
8507
8479
|
const info = await sdk.getSessionInfo(sdkSessionId, {
|
|
8508
8480
|
dir: currentWorkingDirectory()
|
|
8509
8481
|
});
|
|
@@ -8537,8 +8509,6 @@ async function persistSessionTitle(session, title) {
|
|
|
8537
8509
|
if (!session.sdkSessionId)
|
|
8538
8510
|
return;
|
|
8539
8511
|
const sdk = await claudeSdk();
|
|
8540
|
-
if (typeof sdk.renameSession !== "function")
|
|
8541
|
-
return;
|
|
8542
8512
|
await sdk.renameSession(session.sdkSessionId, title, {
|
|
8543
8513
|
dir: currentWorkingDirectory()
|
|
8544
8514
|
});
|
|
@@ -16075,11 +16045,6 @@ function commandChangeJournal(sdkSessionId) {
|
|
|
16075
16045
|
}
|
|
16076
16046
|
return journal;
|
|
16077
16047
|
}
|
|
16078
|
-
async function deleteCommandChangeJournal(sdkSessionId) {
|
|
16079
|
-
const journal = commandChangeJournal(sdkSessionId);
|
|
16080
|
-
journals.delete(sdkSessionId);
|
|
16081
|
-
await journal?.remove();
|
|
16082
|
-
}
|
|
16083
16048
|
function isMeasuredCommand(toolName, toolInput) {
|
|
16084
16049
|
if (toolName !== "Bash")
|
|
16085
16050
|
return false;
|
|
@@ -16259,9 +16224,6 @@ function labelSubagentModel(row, parent, records) {
|
|
|
16259
16224
|
}
|
|
16260
16225
|
}
|
|
16261
16226
|
async function rehydrateSubagentParts(sdk, sdkSessionId, dir, messages) {
|
|
16262
|
-
if (typeof sdk.listSubagents !== "function" || typeof sdk.getSubagentMessages !== "function") {
|
|
16263
|
-
return;
|
|
16264
|
-
}
|
|
16265
16227
|
const agentIds = (await sdk.listSubagents(sdkSessionId, { dir }).catch(() => [])).slice(0, MAX_REHYDRATED_SUBAGENTS);
|
|
16266
16228
|
if (agentIds.length === 0)
|
|
16267
16229
|
return;
|
|
@@ -16324,19 +16286,7 @@ function applyLocalTranscriptOverlay(session) {
|
|
|
16324
16286
|
markTranscriptChanged(session);
|
|
16325
16287
|
}
|
|
16326
16288
|
var sessionDeletionTick = 0;
|
|
16327
|
-
var DELETE_TOMBSTONE_LIMIT = 128;
|
|
16328
16289
|
var deletedSdkSessionTicks = new Map;
|
|
16329
|
-
function recordDeletedSdkSession(sdkSessionId) {
|
|
16330
|
-
sessionDeletionTick += 1;
|
|
16331
|
-
deletedSdkSessionTicks.delete(sdkSessionId);
|
|
16332
|
-
deletedSdkSessionTicks.set(sdkSessionId, sessionDeletionTick);
|
|
16333
|
-
while (deletedSdkSessionTicks.size > DELETE_TOMBSTONE_LIMIT) {
|
|
16334
|
-
const oldest = deletedSdkSessionTicks.keys().next();
|
|
16335
|
-
if (oldest.done)
|
|
16336
|
-
break;
|
|
16337
|
-
deletedSdkSessionTicks.delete(oldest.value);
|
|
16338
|
-
}
|
|
16339
|
-
}
|
|
16340
16290
|
function deletedSinceTick(sdkSessionId, readTick) {
|
|
16341
16291
|
const deletedAt = deletedSdkSessionTicks.get(sdkSessionId);
|
|
16342
16292
|
return deletedAt !== undefined && deletedAt > readTick;
|
|
@@ -16350,8 +16300,6 @@ function isDefaultSessionTitle(title, bridgeId, sdkId) {
|
|
|
16350
16300
|
}
|
|
16351
16301
|
async function reconcilePersistedSessions() {
|
|
16352
16302
|
const sdk = await claudeSdk();
|
|
16353
|
-
if (typeof sdk.listSessions !== "function")
|
|
16354
|
-
return;
|
|
16355
16303
|
const cwd = currentWorkingDirectory();
|
|
16356
16304
|
const listStartedAtTick = sessionDeletionTick;
|
|
16357
16305
|
const infos = await sdk.listSessions({
|
|
@@ -16415,8 +16363,6 @@ async function materializePersistedSessionState(sessionId, sdkId) {
|
|
|
16415
16363
|
const racedDuringImport = sessions.get(sessionId);
|
|
16416
16364
|
if (racedDuringImport)
|
|
16417
16365
|
return racedDuringImport;
|
|
16418
|
-
if (typeof sdk.getSessionInfo !== "function")
|
|
16419
|
-
return;
|
|
16420
16366
|
const [info, preferences] = await Promise.all([
|
|
16421
16367
|
sdk.getSessionInfo(sdkId, {
|
|
16422
16368
|
dir: currentWorkingDirectory()
|
|
@@ -16479,8 +16425,6 @@ async function readPersistedSessionMessages(session) {
|
|
|
16479
16425
|
if (!session.sdkSessionId)
|
|
16480
16426
|
return;
|
|
16481
16427
|
const sdk = await claudeSdk();
|
|
16482
|
-
if (typeof sdk.getSessionMessages !== "function")
|
|
16483
|
-
return;
|
|
16484
16428
|
const [persisted, commandChanges, preferences] = await Promise.all([
|
|
16485
16429
|
sdk.getSessionMessages(session.sdkSessionId, {
|
|
16486
16430
|
dir: currentWorkingDirectory(),
|
|
@@ -16630,60 +16574,6 @@ function startIdleTranscriptSweep(intervalMs = IDLE_TRANSCRIPT_SWEEP_INTERVAL_MS
|
|
|
16630
16574
|
return timer;
|
|
16631
16575
|
}
|
|
16632
16576
|
startIdleTranscriptSweep();
|
|
16633
|
-
async function deleteSessionDurably(sessionId) {
|
|
16634
|
-
const session = sessions.get(sessionId) ?? await ensurePersistedSession(sessionId);
|
|
16635
|
-
if (!session) {
|
|
16636
|
-
const sdkSessionId = sdkSessionIdFromBridgeId(sessionId);
|
|
16637
|
-
if (sdkSessionId) {
|
|
16638
|
-
await deleteSessionPreferences(sdkSessionId);
|
|
16639
|
-
await deleteCommandChangeJournal(sdkSessionId);
|
|
16640
|
-
}
|
|
16641
|
-
return false;
|
|
16642
|
-
}
|
|
16643
|
-
if (session.deleting) {
|
|
16644
|
-
throw sessionOperationError("conflict", "Session deletion is already in progress");
|
|
16645
|
-
}
|
|
16646
|
-
session.deleting = true;
|
|
16647
|
-
session.status = "running";
|
|
16648
|
-
claimedPromptDispatches.delete(sessionId);
|
|
16649
|
-
session.abortController?.abort();
|
|
16650
|
-
session.abortController = undefined;
|
|
16651
|
-
cleanupPendingInteractions(sessionId);
|
|
16652
|
-
await releaseQueryControls(session);
|
|
16653
|
-
await waitForPendingPromptDispatchClaim(sessionId);
|
|
16654
|
-
let rolloutDeleted = false;
|
|
16655
|
-
try {
|
|
16656
|
-
const preferenceSessionId = session.sdkSessionId ?? sdkSessionIdFromBridgeId(session.id);
|
|
16657
|
-
if (session.sdkSessionId) {
|
|
16658
|
-
const sdk = await claudeSdk();
|
|
16659
|
-
if (typeof sdk.deleteSession === "function") {
|
|
16660
|
-
await sdk.deleteSession(session.sdkSessionId, {
|
|
16661
|
-
dir: currentWorkingDirectory()
|
|
16662
|
-
});
|
|
16663
|
-
}
|
|
16664
|
-
rolloutDeleted = true;
|
|
16665
|
-
recordDeletedSdkSession(session.sdkSessionId);
|
|
16666
|
-
}
|
|
16667
|
-
forgetPromptDispatchesForSession(sessionId);
|
|
16668
|
-
if (preferenceSessionId) {
|
|
16669
|
-
await deleteSessionPreferences(preferenceSessionId);
|
|
16670
|
-
await deleteCommandChangeJournal(preferenceSessionId);
|
|
16671
|
-
}
|
|
16672
|
-
sessions.delete(sessionId);
|
|
16673
|
-
return true;
|
|
16674
|
-
} catch (error) {
|
|
16675
|
-
if (rolloutDeleted && session.sdkSessionId) {
|
|
16676
|
-
recordDeletedSdkSession(session.sdkSessionId);
|
|
16677
|
-
sessions.delete(sessionId);
|
|
16678
|
-
throw error;
|
|
16679
|
-
}
|
|
16680
|
-
session.deleting = false;
|
|
16681
|
-
session.status = "idle";
|
|
16682
|
-
session.turnStartedAt = undefined;
|
|
16683
|
-
session.completionBlockedByBackgroundTasks = false;
|
|
16684
|
-
throw error;
|
|
16685
|
-
}
|
|
16686
|
-
}
|
|
16687
16577
|
async function renameSessionDurably(sessionId, title) {
|
|
16688
16578
|
const session = await ensurePersistedSession(sessionId);
|
|
16689
16579
|
if (!session)
|
|
@@ -16707,9 +16597,6 @@ async function forkPersistedSession(sessionId, options = {}) {
|
|
|
16707
16597
|
throw sessionOperationError("conflict", "Cannot fork a running session");
|
|
16708
16598
|
}
|
|
16709
16599
|
const sdk = await claudeSdk();
|
|
16710
|
-
if (typeof sdk.forkSession !== "function") {
|
|
16711
|
-
throw sessionOperationError("conflict", "Installed Claude Agent SDK does not support session forking");
|
|
16712
|
-
}
|
|
16713
16600
|
const boundaryId = options.upToMessageId ? await resolvePersistedMessageId(source, options.upToMessageId) : undefined;
|
|
16714
16601
|
if (options.upToMessageId && !boundaryId) {
|
|
16715
16602
|
throw sessionOperationError("invalid", "The selected Claude message is not a persisted fork boundary");
|
|
@@ -16744,8 +16631,6 @@ async function resolvePersistedMessageId(session, normalizedMessageId, allowedTy
|
|
|
16744
16631
|
if (local && !allowedTypes.has(local.role))
|
|
16745
16632
|
return;
|
|
16746
16633
|
const sdk = await claudeSdk();
|
|
16747
|
-
if (typeof sdk.getSessionMessages !== "function")
|
|
16748
|
-
return candidate;
|
|
16749
16634
|
const persisted = await sdk.getSessionMessages(session.sdkSessionId, {
|
|
16750
16635
|
dir: currentWorkingDirectory(),
|
|
16751
16636
|
includeSystemMessages: false
|
|
@@ -17685,6 +17570,29 @@ class PromptStream {
|
|
|
17685
17570
|
}
|
|
17686
17571
|
}
|
|
17687
17572
|
|
|
17573
|
+
// ../protocol/src/agent-usage-limits.ts
|
|
17574
|
+
var USAGE_LIMIT_PATTERNS = [
|
|
17575
|
+
/usage[\s_-]?limit/i,
|
|
17576
|
+
/hit your (?:usage |session |weekly )?limit/i,
|
|
17577
|
+
/\b(?:5|five)[\s-]?hour limit\b/i,
|
|
17578
|
+
/\bweekly limit\b/i,
|
|
17579
|
+
/\b(?:usage|quota|credits?|allowance) (?:is |has been )?(?:exhausted|exceeded|used up)\b/i,
|
|
17580
|
+
/\bquota exceeded\b|\binsufficient_quota\b|\bout of (?:credits|usage)\b/i,
|
|
17581
|
+
/\bUSAGE_EXHAUSTED\b|\bPAYMENT_REQUIRED\b/,
|
|
17582
|
+
/\b(?:usage|plan|session|daily|weekly|monthly|go) limit reached\b/i
|
|
17583
|
+
];
|
|
17584
|
+
function classifyUsageLimitError(text) {
|
|
17585
|
+
if (typeof text !== "string" || !text.trim())
|
|
17586
|
+
return null;
|
|
17587
|
+
const bounded = text.slice(0, 2000);
|
|
17588
|
+
if (!USAGE_LIMIT_PATTERNS.some((pattern) => pattern.test(bounded)))
|
|
17589
|
+
return null;
|
|
17590
|
+
const reset = bounded.match(/\b(?:resets?|try again)(?:\s+(?:at|in|after))?\s+([^.\n·]{1,60})/i);
|
|
17591
|
+
const hint = reset?.[1]?.trim();
|
|
17592
|
+
return hint ? { resetHint: hint } : {};
|
|
17593
|
+
}
|
|
17594
|
+
var USAGE_LIMIT_ERROR_CODE = "usage-limit";
|
|
17595
|
+
|
|
17688
17596
|
// ../protocol/src/structured-output-text.ts
|
|
17689
17597
|
var STRUCTURED_OUTPUT_RECOVERY_CHARS = 1024 * 1024;
|
|
17690
17598
|
var THINKING_TAGS = "thinking|thought|reasoning|think";
|
|
@@ -17995,6 +17903,27 @@ function diagnosticErrorClass(error) {
|
|
|
17995
17903
|
return "Error";
|
|
17996
17904
|
}
|
|
17997
17905
|
}
|
|
17906
|
+
function isUsageLimitError(error) {
|
|
17907
|
+
try {
|
|
17908
|
+
const text = error instanceof Error ? error.message : error;
|
|
17909
|
+
return classifyUsageLimitError(text) !== null;
|
|
17910
|
+
} catch {
|
|
17911
|
+
return false;
|
|
17912
|
+
}
|
|
17913
|
+
}
|
|
17914
|
+
var USAGE_LIMITED_ERROR_PROPERTY = "usageLimited";
|
|
17915
|
+
function markUsageLimitError(error) {
|
|
17916
|
+
if (typeof error !== "object" && typeof error !== "function" || error === null)
|
|
17917
|
+
return;
|
|
17918
|
+
try {
|
|
17919
|
+
Object.defineProperty(error, USAGE_LIMITED_ERROR_PROPERTY, {
|
|
17920
|
+
value: true,
|
|
17921
|
+
configurable: true,
|
|
17922
|
+
enumerable: false,
|
|
17923
|
+
writable: false
|
|
17924
|
+
});
|
|
17925
|
+
} catch {}
|
|
17926
|
+
}
|
|
17998
17927
|
function ownsActiveTurn(turn) {
|
|
17999
17928
|
const { session, sessionId } = turn;
|
|
18000
17929
|
return !turn.abortController.signal.aborted && sessions.get(sessionId) === session && session.abortController === turn.abortController;
|
|
@@ -18665,13 +18594,6 @@ async function getMcpServerInfo(cwd) {
|
|
|
18665
18594
|
function sourceDigest(digest) {
|
|
18666
18595
|
return digest === null ? "absent" : `sha256:${digest}`;
|
|
18667
18596
|
}
|
|
18668
|
-
function normalizeScope(scope) {
|
|
18669
|
-
if (scope === true)
|
|
18670
|
-
return "all";
|
|
18671
|
-
if (scope === false)
|
|
18672
|
-
return "user";
|
|
18673
|
-
return scope;
|
|
18674
|
-
}
|
|
18675
18597
|
function mcpSourceScopeForPolicy(policy) {
|
|
18676
18598
|
if (isCoordinatorReadOnlyPolicy(policy)) {
|
|
18677
18599
|
return (nativeAgentUserMcpGrant(policy)?.length ?? 0) > 0 ? "user" : "none";
|
|
@@ -18743,7 +18665,7 @@ function revisionFingerprint(sources) {
|
|
|
18743
18665
|
return createHash9("sha256").update(`user=${sources.user}\x00project=${sources.project}`).digest("base64url");
|
|
18744
18666
|
}
|
|
18745
18667
|
async function getMcpRuntimeConfig(cwd, env = process.env, connection, sources = "all", allowConfigured) {
|
|
18746
|
-
const scoped = await loadScopedMcpServers(cwd,
|
|
18668
|
+
const scoped = await loadScopedMcpServers(cwd, sources);
|
|
18747
18669
|
const { revision } = scoped;
|
|
18748
18670
|
const configs = allowConfigured ? Object.fromEntries(Object.entries(scoped.configs).filter(([name]) => allowConfigured(name))) : scoped.configs;
|
|
18749
18671
|
const servers = toSdkServers(configs);
|
|
@@ -18768,7 +18690,7 @@ async function getMcpRuntimeConfig(cwd, env = process.env, connection, sources =
|
|
|
18768
18690
|
delete servers[ORKESTRATOR_ARTIFACT_MCP_SERVER_NAME];
|
|
18769
18691
|
layers.delete(ORKESTRATOR_ARTIFACT_MCP_SERVER_NAME);
|
|
18770
18692
|
}
|
|
18771
|
-
const research =
|
|
18693
|
+
const research = sources === "none" ? coordinatorResearchMcpServersFromEnv(env) : [];
|
|
18772
18694
|
for (const server of research)
|
|
18773
18695
|
servers[server.name] = { type: "http", url: server.url };
|
|
18774
18696
|
return {
|
|
@@ -19862,44 +19784,6 @@ async function performSessionMcpAction(sessionId, serverId, action) {
|
|
|
19862
19784
|
});
|
|
19863
19785
|
}
|
|
19864
19786
|
}
|
|
19865
|
-
function claudeWindowId(label) {
|
|
19866
|
-
const known = claudePlanWindowFromLabel(label);
|
|
19867
|
-
if (known)
|
|
19868
|
-
return known.id;
|
|
19869
|
-
const slug = label.trim().toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
|
|
19870
|
-
return slug || "window";
|
|
19871
|
-
}
|
|
19872
|
-
async function planUsageFrom(control) {
|
|
19873
|
-
const getStructuredUsage = control.usage_EXPERIMENTAL_MAY_CHANGE_DO_NOT_RELY_ON_THIS_API_YET;
|
|
19874
|
-
if (!getStructuredUsage) {
|
|
19875
|
-
throw new Error("Claude's plan usage API is unavailable in this CLI version");
|
|
19876
|
-
}
|
|
19877
|
-
const structuredUsage = await getStructuredUsageWithTimeout(getStructuredUsage, control, PLAN_USAGE_PROBE_TIMEOUT_MS);
|
|
19878
|
-
return rateLimitsFromStructuredUsage(structuredUsage);
|
|
19879
|
-
}
|
|
19880
|
-
async function readClaudePlanUsage() {
|
|
19881
|
-
let rateLimits = await readFromLiveClaude((control) => control.usage_EXPERIMENTAL_MAY_CHANGE_DO_NOT_RELY_ON_THIS_API_YET ? planUsageFrom(control) : undefined, PLAN_USAGE_PROBE_TIMEOUT_MS);
|
|
19882
|
-
let probe;
|
|
19883
|
-
try {
|
|
19884
|
-
if (rateLimits === undefined) {
|
|
19885
|
-
probe = createProbe();
|
|
19886
|
-
rateLimits = await planUsageFrom(probe);
|
|
19887
|
-
}
|
|
19888
|
-
if (rateLimits === undefined) {
|
|
19889
|
-
throw new Error("Claude did not report plan usage");
|
|
19890
|
-
}
|
|
19891
|
-
return rateLimits.map((window) => ({
|
|
19892
|
-
window: claudeWindowId(window.label),
|
|
19893
|
-
label: window.label,
|
|
19894
|
-
...window.usedPercent !== undefined ? { usedPercent: window.usedPercent } : {},
|
|
19895
|
-
...window.resetsAt !== undefined ? { resetsAt: window.resetsAt } : {}
|
|
19896
|
-
}));
|
|
19897
|
-
} finally {
|
|
19898
|
-
await Promise.resolve(probe?.close()).catch(() => {
|
|
19899
|
-
return;
|
|
19900
|
-
});
|
|
19901
|
-
}
|
|
19902
|
-
}
|
|
19903
19787
|
async function steerClaudeSession(sessionId, text, requestId, expectedRunId) {
|
|
19904
19788
|
const capacityRefusal = {
|
|
19905
19789
|
outcome: "rejected",
|
|
@@ -22750,29 +22634,6 @@ var LEAF_MESSAGE_HANDLERS = {
|
|
|
22750
22634
|
conversation_reset: handleConversationReset
|
|
22751
22635
|
};
|
|
22752
22636
|
|
|
22753
|
-
// ../protocol/src/agent-usage-limits.ts
|
|
22754
|
-
var USAGE_LIMIT_PATTERNS = [
|
|
22755
|
-
/usage[\s_-]?limit/i,
|
|
22756
|
-
/hit your (?:usage |session |weekly )?limit/i,
|
|
22757
|
-
/\b(?:5|five)[\s-]?hour limit\b/i,
|
|
22758
|
-
/\bweekly limit\b/i,
|
|
22759
|
-
/\b(?:usage|quota|credits?|allowance) (?:is |has been )?(?:exhausted|exceeded|used up)\b/i,
|
|
22760
|
-
/\bquota exceeded\b|\binsufficient_quota\b|\bout of (?:credits|usage)\b/i,
|
|
22761
|
-
/\bUSAGE_EXHAUSTED\b|\bPAYMENT_REQUIRED\b/,
|
|
22762
|
-
/\b(?:usage|plan|session|daily|weekly|monthly|go) limit reached\b/i
|
|
22763
|
-
];
|
|
22764
|
-
function classifyUsageLimitError(text) {
|
|
22765
|
-
if (typeof text !== "string" || !text.trim())
|
|
22766
|
-
return null;
|
|
22767
|
-
const bounded = text.slice(0, 2000);
|
|
22768
|
-
if (!USAGE_LIMIT_PATTERNS.some((pattern) => pattern.test(bounded)))
|
|
22769
|
-
return null;
|
|
22770
|
-
const reset = bounded.match(/\b(?:resets?|try again)(?:\s+(?:at|in|after))?\s+([^.\n·]{1,60})/i);
|
|
22771
|
-
const hint = reset?.[1]?.trim();
|
|
22772
|
-
return hint ? { resetHint: hint } : {};
|
|
22773
|
-
}
|
|
22774
|
-
var USAGE_LIMIT_ERROR_CODE = "usage-limit";
|
|
22775
|
-
|
|
22776
22637
|
// ../../bridges/claude-bridge/src/services/session-manager-prompt-handlers/result.ts
|
|
22777
22638
|
var log14 = createLogger("bridge.claude");
|
|
22778
22639
|
function claudeStartupFailureMessage(reason) {
|
|
@@ -22979,9 +22840,13 @@ async function handleResultMessage(turn, message) {
|
|
|
22979
22840
|
debugLog("[session-manager] Query stopped by the user", { sessionId });
|
|
22980
22841
|
finishTurnInputIfSettled(turn);
|
|
22981
22842
|
} else {
|
|
22982
|
-
log14.error("query.failed", { subtype: resultMsg.subtype, sessionId, isError: resultIsError });
|
|
22983
22843
|
const startupFailure = resultMsg.startup_failure_reason ? withStartupFailureDetail(claudeStartupFailureMessage(resultMsg.startup_failure_reason), resultMsg.errors) : undefined;
|
|
22984
22844
|
const usageLimit = resultMsg.subtype === "success" && classifyUsageLimitError(resultMsg.result) ? resultMsg.result.trim().slice(0, MAX_USAGE_LIMIT_ERROR_CHARS) : undefined;
|
|
22845
|
+
if (!startupFailure && (usageLimit || turn.rateLimitRejected)) {
|
|
22846
|
+
log14.warn("query.usage-limited", { subtype: resultMsg.subtype, sessionId });
|
|
22847
|
+
} else {
|
|
22848
|
+
log14.error("query.failed", { subtype: resultMsg.subtype, sessionId, isError: resultIsError });
|
|
22849
|
+
}
|
|
22985
22850
|
const resultError = startupFailure || resultMsg.errors?.filter(Boolean).join(`
|
|
22986
22851
|
`) || usageLimit || (resultMsg.subtype === "success" ? "Claude ended the turn on an API error." : `Claude query failed: ${resultMsg.subtype}`);
|
|
22987
22852
|
if (startupFailure) {
|
|
@@ -24229,9 +24094,15 @@ function settleFailedTurn(turn, error) {
|
|
|
24229
24094
|
recordInterruptedStructuredOutputIfCurrent(turn);
|
|
24230
24095
|
return;
|
|
24231
24096
|
}
|
|
24232
|
-
|
|
24097
|
+
const killedBy = killedClaudeProcessSignal(error);
|
|
24098
|
+
const usageLimited = !killedBy && (turn.rateLimitRejected || isUsageLimitError(error));
|
|
24099
|
+
if (usageLimited) {
|
|
24100
|
+
log18.warn("prompt.usage-limited", { errorClass: diagnosticErrorClass(error) });
|
|
24101
|
+
markUsageLimitError(error);
|
|
24102
|
+
} else {
|
|
24103
|
+
log18.error("prompt.failed", { errorClass: diagnosticErrorClass(error) });
|
|
24104
|
+
}
|
|
24233
24105
|
if (session.abortController === abortController) {
|
|
24234
|
-
const killedBy = killedClaudeProcessSignal(error);
|
|
24235
24106
|
const failure = killedBy ? claudeProcessKilledMessage(killedBy) : error instanceof Error ? error.message : String(error);
|
|
24236
24107
|
if (options?.outputSchema && structuredRequestId && !session.structuredOutput) {
|
|
24237
24108
|
recordStructuredOutput(session, structuredOutputFailure("claude", "provider_error", failure, {
|
|
@@ -25615,6 +25486,22 @@ function sessionErrorStatus(error) {
|
|
|
25615
25486
|
return 503;
|
|
25616
25487
|
return 500;
|
|
25617
25488
|
}
|
|
25489
|
+
function isUsageLimitedRejection(error) {
|
|
25490
|
+
try {
|
|
25491
|
+
if (error?.usageLimited === true)
|
|
25492
|
+
return true;
|
|
25493
|
+
return classifyUsageLimitError(error instanceof Error ? error.message : error) !== null;
|
|
25494
|
+
} catch {
|
|
25495
|
+
return false;
|
|
25496
|
+
}
|
|
25497
|
+
}
|
|
25498
|
+
function logPromptProcessingFailure(error) {
|
|
25499
|
+
if (isUsageLimitedRejection(error)) {
|
|
25500
|
+
log23.debug("prompt.processing-usage-limited");
|
|
25501
|
+
return;
|
|
25502
|
+
}
|
|
25503
|
+
log23.error("prompt.processing-failed", { error: formatLogError(error) });
|
|
25504
|
+
}
|
|
25618
25505
|
var STALE_PROMPT_STATUS = 409;
|
|
25619
25506
|
function stalePrompt(message) {
|
|
25620
25507
|
return { error: message, status: "stale" };
|
|
@@ -25764,35 +25651,6 @@ session.get("/:id/usage", async (c) => {
|
|
|
25764
25651
|
return c.json({ error: "Context usage is temporarily unavailable" }, 503);
|
|
25765
25652
|
}
|
|
25766
25653
|
});
|
|
25767
|
-
session.put("/:id/preferences", async (c) => {
|
|
25768
|
-
const id = c.req.param("id");
|
|
25769
|
-
try {
|
|
25770
|
-
let body;
|
|
25771
|
-
try {
|
|
25772
|
-
body = await c.req.json();
|
|
25773
|
-
} catch {
|
|
25774
|
-
return c.json({ error: "Request body must be valid JSON" }, 400);
|
|
25775
|
-
}
|
|
25776
|
-
if (body === null || typeof body !== "object" || Array.isArray(body) || Object.getPrototypeOf(body) !== Object.prototype) {
|
|
25777
|
-
return c.json({ error: "Request body must be a JSON object" }, 400);
|
|
25778
|
-
}
|
|
25779
|
-
const record = body;
|
|
25780
|
-
const unexpectedField = Object.keys(record).find((key) => key !== "planMode");
|
|
25781
|
-
if (unexpectedField) {
|
|
25782
|
-
return c.json({ error: `Unexpected session preference field: ${unexpectedField}` }, 400);
|
|
25783
|
-
}
|
|
25784
|
-
if (!Object.hasOwn(record, "planMode")) {
|
|
25785
|
-
return c.json({ error: "planMode is required" }, 400);
|
|
25786
|
-
}
|
|
25787
|
-
if (Object.hasOwn(record, "planMode") && typeof record.planMode !== "boolean") {
|
|
25788
|
-
return c.json({ error: "planMode must be a boolean" }, 400);
|
|
25789
|
-
}
|
|
25790
|
-
const updated = await setSessionPreferences(id, typeof record.planMode === "boolean" ? { planMode: record.planMode } : {});
|
|
25791
|
-
return c.json({ planMode: updated.planMode ?? false });
|
|
25792
|
-
} catch (error) {
|
|
25793
|
-
return c.json({ error: errorMessage(error, "Failed to update session preferences") }, sessionErrorStatus(error));
|
|
25794
|
-
}
|
|
25795
|
-
});
|
|
25796
25654
|
function claudeApprovalMode(value) {
|
|
25797
25655
|
return value === "default" || value === "acceptEdits" || value === "auto" || value === "bypassPermissions" ? value : undefined;
|
|
25798
25656
|
}
|
|
@@ -25913,17 +25771,6 @@ session.get("/:id/structured-output", (c) => {
|
|
|
25913
25771
|
requestId: sessionData.structuredOutputRequestId
|
|
25914
25772
|
});
|
|
25915
25773
|
});
|
|
25916
|
-
session.get("/:id/tasks", async (c) => {
|
|
25917
|
-
const id = c.req.param("id");
|
|
25918
|
-
const sessionData = getSession(id) ?? await ensurePersistedSession(id);
|
|
25919
|
-
if (!sessionData) {
|
|
25920
|
-
return c.json({ error: "Session not found" }, 404);
|
|
25921
|
-
}
|
|
25922
|
-
if (sessionData.persistedMessagesLoaded === false) {
|
|
25923
|
-
await hydratePersistedSessionMessages(id);
|
|
25924
|
-
}
|
|
25925
|
-
return c.json(sessionData.taskRegistry?.snapshot() ?? { items: [], complete: true });
|
|
25926
|
-
});
|
|
25927
25774
|
session.get("/:id/messages", async (c) => {
|
|
25928
25775
|
const id = c.req.param("id");
|
|
25929
25776
|
const resolved = await resolveSession(id, "Failed to load session messages");
|
|
@@ -26096,7 +25943,7 @@ session.post("/:id/prompt", async (c) => {
|
|
|
26096
25943
|
rejectStarted?.(sessionOperationError("conflict", "Prompt stopped before launch"));
|
|
26097
25944
|
}, (error) => {
|
|
26098
25945
|
rejectStarted?.(error);
|
|
26099
|
-
|
|
25946
|
+
logPromptProcessingFailure(error);
|
|
26100
25947
|
});
|
|
26101
25948
|
return { started, completion };
|
|
26102
25949
|
});
|
|
@@ -26151,7 +25998,7 @@ session.post("/:id/prompt", async (c) => {
|
|
|
26151
25998
|
...workflowResultTurn ? { workflowResultTurn } : {},
|
|
26152
25999
|
...providerPrompt !== undefined ? { providerPrompt } : {}
|
|
26153
26000
|
}).catch((error) => {
|
|
26154
|
-
|
|
26001
|
+
logPromptProcessingFailure(error);
|
|
26155
26002
|
});
|
|
26156
26003
|
log23.debug("prompt.accepted", { sessionId: id });
|
|
26157
26004
|
return c.json({
|
|
@@ -26195,34 +26042,7 @@ session.post("/:id/hard-abort", (c) => {
|
|
|
26195
26042
|
return c.json({ error: "Session not found" }, 404);
|
|
26196
26043
|
return c.json({ status: abortSession(id) ? "aborted" : "not_running" });
|
|
26197
26044
|
});
|
|
26198
|
-
session.delete("/:id", async (c) => {
|
|
26199
|
-
const id = c.req.param("id");
|
|
26200
|
-
try {
|
|
26201
|
-
const deleted = await deleteSessionDurably(id);
|
|
26202
|
-
if (deleted) {
|
|
26203
|
-
return c.json({ status: "deleted" });
|
|
26204
|
-
}
|
|
26205
|
-
return c.json({ error: "Session not found" }, 404);
|
|
26206
|
-
} catch (error) {
|
|
26207
|
-
log23.error("session.delete-failed", { error: formatLogError(error) });
|
|
26208
|
-
return c.json({ error: errorMessage(error, "Failed to delete session") }, sessionErrorStatus(error));
|
|
26209
|
-
}
|
|
26210
|
-
});
|
|
26211
26045
|
registerSessionCloseRoute(session);
|
|
26212
|
-
session.post("/:id/rename", async (c) => {
|
|
26213
|
-
const id = c.req.param("id");
|
|
26214
|
-
const body = await c.req.json().catch(() => ({}));
|
|
26215
|
-
const title = typeof body.title === "string" ? body.title.trim() : "";
|
|
26216
|
-
if (!title)
|
|
26217
|
-
return c.json({ error: "Title is required" }, 400);
|
|
26218
|
-
try {
|
|
26219
|
-
const renamed = await renameSessionDurably(id, title);
|
|
26220
|
-
return renamed ? c.json({ status: "renamed", title }) : c.json({ error: "Session not found" }, 404);
|
|
26221
|
-
} catch (error) {
|
|
26222
|
-
log23.error("session.rename-failed", { error: formatLogError(error) });
|
|
26223
|
-
return c.json({ error: errorMessage(error, "Failed to rename session") }, sessionErrorStatus(error));
|
|
26224
|
-
}
|
|
26225
|
-
});
|
|
26226
26046
|
session.post("/:id/title", async (c) => {
|
|
26227
26047
|
const title = String((await c.req.json().catch(() => ({}))).title ?? "").trim();
|
|
26228
26048
|
if (!title)
|
|
@@ -29247,7 +29067,6 @@ app.onError((error, c) => {
|
|
|
29247
29067
|
return c.json({ error: "Internal Server Error" }, 500);
|
|
29248
29068
|
});
|
|
29249
29069
|
var BRIDGE_TOKEN_ENV = "CLAUDE_BRIDGE_TOKEN";
|
|
29250
|
-
var BRIDGE_ALLOWED_ORIGINS_ENV = "CLAUDE_BRIDGE_ALLOWED_ORIGINS";
|
|
29251
29070
|
var bridgeCredential = loadBridgeCredential(BRIDGE_TOKEN_ENV);
|
|
29252
29071
|
process.env.ORKESTRATOR_NATIVE_AGENT_BRIDGE = "claude";
|
|
29253
29072
|
var bridgeAuthEnabledOverrideForTesting = null;
|
|
@@ -29269,11 +29088,6 @@ function bearerToken(header) {
|
|
|
29269
29088
|
function isTrustedBridgeOrigin(origin) {
|
|
29270
29089
|
if (!origin)
|
|
29271
29090
|
return true;
|
|
29272
|
-
if (origin === "null" || origin === "file://")
|
|
29273
|
-
return true;
|
|
29274
|
-
const configured = (process.env[BRIDGE_ALLOWED_ORIGINS_ENV] ?? "").split(",").map((entry) => entry.trim().replace(/\/$/, "")).filter(Boolean);
|
|
29275
|
-
if (configured.includes(origin.replace(/\/$/, "")))
|
|
29276
|
-
return true;
|
|
29277
29091
|
try {
|
|
29278
29092
|
const parsed = new URL(origin);
|
|
29279
29093
|
return (parsed.protocol === "http:" || parsed.protocol === "https:") && (parsed.hostname === "127.0.0.1" || parsed.hostname === "localhost" || parsed.hostname === "::1" || parsed.hostname === "[::1]");
|
|
@@ -29289,21 +29103,10 @@ app.use("*", async (c, next) => {
|
|
|
29289
29103
|
if (!isTrustedBridgeOrigin(origin)) {
|
|
29290
29104
|
return c.json({ error: "Origin is not allowed" }, 403);
|
|
29291
29105
|
}
|
|
29292
|
-
if (origin) {
|
|
29293
|
-
c.header("Access-Control-Allow-Origin", origin);
|
|
29294
|
-
c.header("Vary", "Origin");
|
|
29295
|
-
}
|
|
29296
|
-
if (c.req.method === "OPTIONS") {
|
|
29297
|
-
c.header("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
|
|
29298
|
-
c.header("Access-Control-Allow-Headers", "Content-Type, Authorization, X-Orkestrator-Claude-Token");
|
|
29299
|
-
c.header("Access-Control-Allow-Private-Network", "true");
|
|
29300
|
-
return c.body(null, 204);
|
|
29301
|
-
}
|
|
29302
29106
|
if (isBridgeAuthEnabled() && !isPublicHealthRequest(c.req.method, c.req.path)) {
|
|
29303
29107
|
const dedicatedHeaderToken = c.req.raw.headers.get("x-orkestrator-claude-token")?.trim();
|
|
29304
29108
|
const headerToken = bearerToken(c.req.raw.headers.get("authorization") ?? undefined);
|
|
29305
|
-
|
|
29306
|
-
if (!tokenMatches(dedicatedHeaderToken) && !tokenMatches(headerToken) && !tokenMatches(eventToken)) {
|
|
29109
|
+
if (!tokenMatches(dedicatedHeaderToken) && !tokenMatches(headerToken)) {
|
|
29307
29110
|
return c.json({ error: "Unauthorized" }, 401);
|
|
29308
29111
|
}
|
|
29309
29112
|
const admission = await admitFetchBridgeRequest(bridgeCredential.authority, c.req.raw);
|
|
@@ -29329,7 +29132,6 @@ app.use("/session/:id/transcript", compress({ encoding: "gzip" }));
|
|
|
29329
29132
|
compressTranscriptReads(app);
|
|
29330
29133
|
app.get("/global/auth-check", (c) => c.json({ status: "ok" }));
|
|
29331
29134
|
app.get("/global/auth", async (c) => c.json(await readClaudeAuthStatus()));
|
|
29332
|
-
app.get("/global/usage", async (c) => c.json({ account: await readClaudePlanUsage() }));
|
|
29333
29135
|
app.post("/global/auth/login", (c) => c.json({ error: "Claude signs in from the sign-in card in its tab or from Settings → Claude." }, 405));
|
|
29334
29136
|
app.post("/global/auth/logout", (c) => c.json({ error: "Claude sign-out is available from a terminal tab." }, 405));
|
|
29335
29137
|
app.post("/global/refresh-catalog", async (c) => {
|