@letta-ai/letta-code 0.34.58 → 0.34.59
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/mcp-client.js +2 -2
- package/dist/mcp-client.js.map +1 -1
- package/dist/mcp-oauth.js +2 -2
- package/dist/mcp-oauth.js.map +1 -1
- package/dist/types/agent/memory-filesystem.d.ts +2 -0
- package/dist/types/agent/memory-filesystem.d.ts.map +1 -1
- package/dist/types/agent/memory-runtime.d.ts.map +1 -1
- package/dist/types/backend/api/monitors.d.ts +17 -0
- package/dist/types/backend/api/monitors.d.ts.map +1 -0
- package/dist/types/tools/impl/github-pull-request-diff.d.ts +2 -1
- package/dist/types/tools/impl/github-pull-request-diff.d.ts.map +1 -1
- package/dist/types/tools/impl/github-pull-request-types.d.ts +14 -0
- package/dist/types/tools/impl/github-pull-request-types.d.ts.map +1 -1
- package/dist/types/tools/impl/github-workflow-run.d.ts +23 -0
- package/dist/types/tools/impl/github-workflow-run.d.ts.map +1 -0
- package/dist/types/tools/impl/kill-bash.d.ts.map +1 -1
- package/dist/types/tools/impl/memory.d.ts.map +1 -1
- package/dist/types/tools/impl/monitor-script.d.ts +1 -0
- package/dist/types/tools/impl/monitor-script.d.ts.map +1 -1
- package/dist/types/tools/impl/monitor-state.d.ts +16 -0
- package/dist/types/tools/impl/monitor-state.d.ts.map +1 -0
- package/dist/types/tools/impl/monitor.d.ts +1 -0
- package/dist/types/tools/impl/monitor.d.ts.map +1 -1
- package/dist/types/tools/impl/process_manager.d.ts +2 -0
- package/dist/types/tools/impl/process_manager.d.ts.map +1 -1
- package/dist/types/tools/impl/remote-external-coding-agent.d.ts.map +1 -1
- package/dist/types/tools/impl/task-stop.d.ts.map +1 -1
- package/dist/types/tools/impl/watch-pr.d.ts +2 -0
- package/dist/types/tools/impl/watch-pr.d.ts.map +1 -1
- package/dist/types/tools/toolset.d.ts +2 -0
- package/dist/types/tools/toolset.d.ts.map +1 -1
- package/dist/types/utils/memory-access.d.ts +4 -0
- package/dist/types/utils/memory-access.d.ts.map +1 -0
- package/letta.js +815 -327
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
package/letta.js
CHANGED
|
@@ -6135,7 +6135,7 @@ var package_default;
|
|
|
6135
6135
|
var init_package = __esm(() => {
|
|
6136
6136
|
package_default = {
|
|
6137
6137
|
name: "@letta-ai/letta-code",
|
|
6138
|
-
version: "0.34.
|
|
6138
|
+
version: "0.34.59",
|
|
6139
6139
|
lettaStartupLogProtocol: 1,
|
|
6140
6140
|
lettaConfigDirProtocol: 1,
|
|
6141
6141
|
description: "Letta Code is a CLI tool for interacting with stateful Letta agents from the terminal.",
|
|
@@ -100022,7 +100022,9 @@ async function applyMemfsFlags(agentId, memfsFlag, options) {
|
|
|
100022
100022
|
if (!isGitRepo2(agentId)) {
|
|
100023
100023
|
await cloneMemoryRepo2(agentId);
|
|
100024
100024
|
} else if (options?.pullOnExistingRepo) {
|
|
100025
|
-
const result = await pullMemory2(agentId
|
|
100025
|
+
const result = await pullMemory2(agentId, {
|
|
100026
|
+
throwOnFailure: options?.throwOnPullFailure
|
|
100027
|
+
});
|
|
100026
100028
|
pullSummary = result.summary;
|
|
100027
100029
|
} else {
|
|
100028
100030
|
installMemoryGitHooks(getScopedMemoryFilesystemRoot(agentId));
|
|
@@ -203260,7 +203262,7 @@ var init_mcp_client = __esm(() => {
|
|
|
203260
203262
|
init_streamableHttp();
|
|
203261
203263
|
DEFAULT_CLIENT_INFO = {
|
|
203262
203264
|
name: "letta-code",
|
|
203263
|
-
version: "0.34.
|
|
203265
|
+
version: "0.34.59"
|
|
203264
203266
|
};
|
|
203265
203267
|
});
|
|
203266
203268
|
|
|
@@ -207647,6 +207649,8 @@ Use WatchPR instead of writing a Monitor or shell polling loop when you need ong
|
|
|
207647
207649
|
The initial result includes current blockers and changes since the previous watch ended for the same agent, conversation, and PR, when a locally saved snapshot is at most seven days old. The first snapshot is never merge-ready: readiness requires a second consecutive read on the same head, so \`awaiting a second same-head readiness read\` is expected at startup. Later changes arrive as task notifications in this conversation. It uses the locally authenticated \`gh\` CLI and keeps watching after checks become green because reviews, comments, conflicts, and new pushes can still arrive. Green checks are not the same as a mergeable PR, so report the PR as ready, green, or mergeable only once the watcher reports it merge-ready.
|
|
207648
207650
|
|
|
207649
207651
|
Pass a URL ending at the PR number, such as \`https://github.com/owner/repo/pull/123\`. Remove \`/files\`, \`/commits\`, \`/checks\`, and other suffixes. The watcher is read-only and errors if the PR is already merged or closed.
|
|
207652
|
+
|
|
207653
|
+
Use \`notify_on\` to limit PR notifications (for example \`["merged", "closed", "conflict"]\` or \`["checks_done"]\`); watcher errors still report. For several PRs, start one watch per URL. Workflow run URLs (\`https://github.com/owner/repo/actions/runs/123\`) report status changes and completion with conclusion and failed jobs/steps, including runs without a PR. Reruns remain a separate action.
|
|
207650
207654
|
`;
|
|
207651
207655
|
var init_WatchPR = () => {};
|
|
207652
207656
|
|
|
@@ -217105,9 +217109,25 @@ var init_tool_name_mapping = __esm(() => {
|
|
|
217105
217109
|
};
|
|
217106
217110
|
});
|
|
217107
217111
|
|
|
217112
|
+
// src/utils/memory-access.ts
|
|
217113
|
+
function isMemoryUnavailable(agentId) {
|
|
217114
|
+
return unavailableAgents.has(agentId);
|
|
217115
|
+
}
|
|
217116
|
+
function markMemoryUnavailable(agentId) {
|
|
217117
|
+
unavailableAgents.add(agentId);
|
|
217118
|
+
}
|
|
217119
|
+
function isMemoryAccessRefusal(error4) {
|
|
217120
|
+
const message = error4 instanceof Error ? error4.message : String(error4);
|
|
217121
|
+
return /(?:returned error:|HTTP(?: status)?)[ :]*(?:401|403)\b|authentication failed|permission denied \(publickey\)/i.test(message);
|
|
217122
|
+
}
|
|
217123
|
+
var unavailableAgents;
|
|
217124
|
+
var init_memory_access = __esm(() => {
|
|
217125
|
+
unavailableAgents = new Set;
|
|
217126
|
+
});
|
|
217127
|
+
|
|
217108
217128
|
// src/agent/memory-runtime.ts
|
|
217109
217129
|
function isActiveMemfsEnabled(agentId) {
|
|
217110
|
-
return getBackend().capabilities.localMemfs || settingsManager.isMemfsEnabled(agentId);
|
|
217130
|
+
return !isMemoryUnavailable(agentId) && (getBackend().capabilities.localMemfs || settingsManager.isMemfsEnabled(agentId));
|
|
217111
217131
|
}
|
|
217112
217132
|
function getActiveMemoryDirectory(agentId) {
|
|
217113
217133
|
return isActiveMemfsEnabled(agentId) ? getScopedMemoryFilesystemRoot(agentId) : undefined;
|
|
@@ -217118,6 +217138,7 @@ function isLocalMemfsActive() {
|
|
|
217118
217138
|
var init_memory_runtime = __esm(() => {
|
|
217119
217139
|
init_backend2();
|
|
217120
217140
|
init_settings_manager();
|
|
217141
|
+
init_memory_access();
|
|
217121
217142
|
init_memory_filesystem2();
|
|
217122
217143
|
});
|
|
217123
217144
|
|
|
@@ -217347,6 +217368,10 @@ ${clampContent(content, fullPath, LIMITS.READ_OUTPUT_CHARS - open4.length - clos
|
|
|
217347
217368
|
${close}`;
|
|
217348
217369
|
}
|
|
217349
217370
|
async function memory(args) {
|
|
217371
|
+
const agentId = getCurrentAgentId();
|
|
217372
|
+
if (agentId && isMemoryUnavailable(agentId)) {
|
|
217373
|
+
return { content: "Memory is not available on this machine." };
|
|
217374
|
+
}
|
|
217350
217375
|
validateRequiredParams(args, ["path"], "Memory");
|
|
217351
217376
|
const memoryDir = resolveMemoryToolDirectory();
|
|
217352
217377
|
if (!memoryDir) {
|
|
@@ -217401,6 +217426,7 @@ var init_memory4 = __esm(() => {
|
|
|
217401
217426
|
init_context();
|
|
217402
217427
|
init_memory_format();
|
|
217403
217428
|
init_memory_runtime();
|
|
217429
|
+
init_memory_access();
|
|
217404
217430
|
init_truncation();
|
|
217405
217431
|
MAX_FILE_BYTES = 10 * 1024 * 1024;
|
|
217406
217432
|
});
|
|
@@ -234317,7 +234343,7 @@ async function startScriptMonitor(args, hooks) {
|
|
|
234317
234343
|
await releaseToolContext(toolContextId);
|
|
234318
234344
|
throw error4;
|
|
234319
234345
|
});
|
|
234320
|
-
const taskId = getNextMonitorId();
|
|
234346
|
+
const taskId = args.taskId ?? getNextMonitorId();
|
|
234321
234347
|
const outputFile = createBackgroundOutputFile(taskId);
|
|
234322
234348
|
const output = hooks.createOutput(outputFile);
|
|
234323
234349
|
const scope = resolveNotificationScope(args.parentScope);
|
|
@@ -234476,6 +234502,103 @@ var init_monitor_script = __esm(() => {
|
|
|
234476
234502
|
init_process_manager();
|
|
234477
234503
|
});
|
|
234478
234504
|
|
|
234505
|
+
// src/backend/api/monitors.ts
|
|
234506
|
+
function createMonitorState(input, actingUserId) {
|
|
234507
|
+
return apiRequest("POST", "/v1/monitors", input, {
|
|
234508
|
+
actingUserId,
|
|
234509
|
+
signal: AbortSignal.timeout(15000)
|
|
234510
|
+
});
|
|
234511
|
+
}
|
|
234512
|
+
function updateMonitorState(id, input, actingUserId) {
|
|
234513
|
+
return apiRequest("PATCH", `/v1/monitors/${encodeURIComponent(id)}`, input, {
|
|
234514
|
+
actingUserId,
|
|
234515
|
+
signal: AbortSignal.timeout(15000)
|
|
234516
|
+
});
|
|
234517
|
+
}
|
|
234518
|
+
var init_monitors = __esm(() => {
|
|
234519
|
+
init_request();
|
|
234520
|
+
});
|
|
234521
|
+
|
|
234522
|
+
// src/tools/impl/monitor-state.ts
|
|
234523
|
+
async function withMonitorState(input, start) {
|
|
234524
|
+
if (resolveBackendMode() === "local")
|
|
234525
|
+
return start(getNextMonitorId());
|
|
234526
|
+
const runtime = getRuntimeContext();
|
|
234527
|
+
const scope = !input.parentScope && runtime?.agentId === null && runtime.conversationId ? { agentId: null, conversationId: runtime.conversationId } : resolveNotificationScope(input.parentScope);
|
|
234528
|
+
if (!scope)
|
|
234529
|
+
throw new Error("A conversation is required to start a cloud monitor");
|
|
234530
|
+
const actingUserId = getRuntimeActingUserAttribution();
|
|
234531
|
+
const secrets2 = {
|
|
234532
|
+
...captureSecretRedactions(scope.agentId ?? undefined),
|
|
234533
|
+
...input.secretEnv
|
|
234534
|
+
};
|
|
234535
|
+
const record4 = await createMonitorState({
|
|
234536
|
+
agent_id: scope.agentId || null,
|
|
234537
|
+
conversation_id: scope.conversationId,
|
|
234538
|
+
description: scrubSecretsFromString(input.description, secrets2),
|
|
234539
|
+
command: scrubSecretsFromString(input.command, secrets2),
|
|
234540
|
+
kind: input.kind,
|
|
234541
|
+
persistent: input.persistent,
|
|
234542
|
+
status: "running",
|
|
234543
|
+
device_id: getRuntimeContext()?.environmentDeviceId ?? null,
|
|
234544
|
+
started_at: new Date().toISOString(),
|
|
234545
|
+
output_file: null,
|
|
234546
|
+
exit_code: null
|
|
234547
|
+
}, actingUserId);
|
|
234548
|
+
const id = record4.monitor_id;
|
|
234549
|
+
try {
|
|
234550
|
+
input.signal?.throwIfAborted();
|
|
234551
|
+
const result3 = await start(id);
|
|
234552
|
+
const process21 = backgroundProcesses.get(id);
|
|
234553
|
+
if (!process21)
|
|
234554
|
+
throw new Error("Monitor did not register its process");
|
|
234555
|
+
let pending2 = Promise.resolve();
|
|
234556
|
+
process21.persistState = () => {
|
|
234557
|
+
const state2 = {
|
|
234558
|
+
status: process21.status,
|
|
234559
|
+
exit_code: process21.exitCode,
|
|
234560
|
+
output_file: process21.outputFile ?? null
|
|
234561
|
+
};
|
|
234562
|
+
pending2 = pending2.catch(() => {}).then(async () => {
|
|
234563
|
+
await updateMonitorState(id, state2, actingUserId);
|
|
234564
|
+
});
|
|
234565
|
+
return pending2;
|
|
234566
|
+
};
|
|
234567
|
+
await process21.persistState();
|
|
234568
|
+
return result3;
|
|
234569
|
+
} catch (error4) {
|
|
234570
|
+
const process21 = backgroundProcesses.get(id);
|
|
234571
|
+
if (process21) {
|
|
234572
|
+
process21.completionNotificationSuppressed = true;
|
|
234573
|
+
process21.status = "failed";
|
|
234574
|
+
process21.process.kill("SIGTERM");
|
|
234575
|
+
notifyBackgroundProcessStateChanged(process21.runtimeScope);
|
|
234576
|
+
scheduleBackgroundProcessCleanup(id);
|
|
234577
|
+
}
|
|
234578
|
+
await updateMonitorState(id, {
|
|
234579
|
+
status: "failed",
|
|
234580
|
+
exit_code: null,
|
|
234581
|
+
output_file: process21?.outputFile ?? null
|
|
234582
|
+
}, actingUserId).catch((persistenceError) => {
|
|
234583
|
+
console.error("Failed to persist monitor state:", persistenceError);
|
|
234584
|
+
});
|
|
234585
|
+
throw error4;
|
|
234586
|
+
}
|
|
234587
|
+
}
|
|
234588
|
+
async function persistMonitorState(process21) {
|
|
234589
|
+
await process21.persistState?.().catch((error4) => {
|
|
234590
|
+
console.error("Failed to persist monitor state:", error4);
|
|
234591
|
+
});
|
|
234592
|
+
}
|
|
234593
|
+
var init_monitor_state = __esm(() => {
|
|
234594
|
+
init_monitors();
|
|
234595
|
+
init_backend_mode();
|
|
234596
|
+
init_runtime_context();
|
|
234597
|
+
init_secret_substitution();
|
|
234598
|
+
init_task_notifications();
|
|
234599
|
+
init_process_manager();
|
|
234600
|
+
});
|
|
234601
|
+
|
|
234479
234602
|
// src/tools/impl/monitor-timeout.ts
|
|
234480
234603
|
function getMonitorMaxTimeoutMs() {
|
|
234481
234604
|
const seconds = process.env.LETTA_MONITOR_MAX_TIMEOUT_SECONDS;
|
|
@@ -234917,6 +235040,7 @@ function queueCommandCompletion(params) {
|
|
|
234917
235040
|
function markMonitorFinished(taskId, processState, status, exitCode) {
|
|
234918
235041
|
processState.status = status;
|
|
234919
235042
|
processState.exitCode = exitCode;
|
|
235043
|
+
persistMonitorState(processState);
|
|
234920
235044
|
cancelMonitorBackup(taskId);
|
|
234921
235045
|
scrubCompletedBackgroundOutput(processState);
|
|
234922
235046
|
notifyBackgroundProcessStateChanged(processState.runtimeScope);
|
|
@@ -234938,7 +235062,7 @@ function startCommandMonitor(args) {
|
|
|
234938
235062
|
}
|
|
234939
235063
|
noteExpectedWorktreeForLauncher(launcher, cwd2);
|
|
234940
235064
|
const sandboxed = applyShellSandbox(launcher, cwd2, env6);
|
|
234941
|
-
const taskId =
|
|
235065
|
+
const taskId = args.taskId;
|
|
234942
235066
|
const outputFile = createBackgroundOutputFile(taskId);
|
|
234943
235067
|
const output = new MonitorOutputWriter(outputFile);
|
|
234944
235068
|
const scope = resolveNotificationScope(args.parentScope);
|
|
@@ -235107,7 +235231,7 @@ function startCommandMonitor(args) {
|
|
|
235107
235231
|
function startWebSocketMonitor(args) {
|
|
235108
235232
|
assertBackgroundProcessCapacity();
|
|
235109
235233
|
const source = args.ws;
|
|
235110
|
-
const taskId =
|
|
235234
|
+
const taskId = args.taskId;
|
|
235111
235235
|
const outputFile = createBackgroundOutputFile(taskId);
|
|
235112
235236
|
const output = new MonitorOutputWriter(outputFile);
|
|
235113
235237
|
const scope = resolveNotificationScope(args.parentScope);
|
|
@@ -235279,6 +235403,7 @@ async function startScriptSource(args) {
|
|
|
235279
235403
|
const { taskId, outputFile } = await startScriptMonitor({
|
|
235280
235404
|
description: args.description,
|
|
235281
235405
|
script: args.script,
|
|
235406
|
+
taskId: args.taskId,
|
|
235282
235407
|
args: args.args,
|
|
235283
235408
|
timeout_ms: args.timeout_ms,
|
|
235284
235409
|
persistent: args.persistent,
|
|
@@ -235327,7 +235452,14 @@ async function monitor(args) {
|
|
|
235327
235452
|
}
|
|
235328
235453
|
const normalized = normalizeMonitorArgs(args);
|
|
235329
235454
|
installMonitorProcessExitCleanup();
|
|
235330
|
-
const result3 =
|
|
235455
|
+
const result3 = await withMonitorState({
|
|
235456
|
+
...normalized,
|
|
235457
|
+
kind: normalized.script !== undefined ? "script" : normalized.command !== undefined ? "command" : "websocket",
|
|
235458
|
+
command: normalized.command ?? normalized.script ?? (normalized.ws ? webSocketDisplayUrl(normalized.ws.url) : "")
|
|
235459
|
+
}, (taskId) => {
|
|
235460
|
+
const sourceArgs = { ...normalized, taskId };
|
|
235461
|
+
return normalized.script !== undefined ? startScriptSource(sourceArgs) : normalized.command !== undefined ? startCommandMonitor(sourceArgs) : startWebSocketMonitor(sourceArgs);
|
|
235462
|
+
});
|
|
235331
235463
|
if (normalized.backup_after_seconds === undefined)
|
|
235332
235464
|
return result3;
|
|
235333
235465
|
const note = await armMonitorBackup({
|
|
@@ -235357,6 +235489,10 @@ function stopMonitorsForProcessExit() {
|
|
|
235357
235489
|
} catch {}
|
|
235358
235490
|
}
|
|
235359
235491
|
}
|
|
235492
|
+
async function shutdownMonitors() {
|
|
235493
|
+
stopMonitorsForProcessExit();
|
|
235494
|
+
await Promise.all([...backgroundProcesses.values()].filter((process21) => process21.kind === "monitor").map(persistMonitorState));
|
|
235495
|
+
}
|
|
235360
235496
|
function installMonitorProcessExitCleanup() {
|
|
235361
235497
|
if (monitorProcessExitCleanupInstalled)
|
|
235362
235498
|
return;
|
|
@@ -235376,6 +235512,7 @@ var init_monitor = __esm(() => {
|
|
|
235376
235512
|
init_monitor_backup();
|
|
235377
235513
|
init_monitor_event_stream();
|
|
235378
235514
|
init_monitor_script();
|
|
235515
|
+
init_monitor_state();
|
|
235379
235516
|
init_monitor_timeout();
|
|
235380
235517
|
init_monitor_url_cloud();
|
|
235381
235518
|
init_process_manager();
|
|
@@ -239988,7 +240125,7 @@ class CodexAppServerClient {
|
|
|
239988
240125
|
await this.request("initialize", {
|
|
239989
240126
|
clientInfo: {
|
|
239990
240127
|
name: "letta-code",
|
|
239991
|
-
version: "0.34.
|
|
240128
|
+
version: "0.34.59"
|
|
239992
240129
|
},
|
|
239993
240130
|
capabilities: null
|
|
239994
240131
|
});
|
|
@@ -241523,7 +241660,7 @@ ${SYSTEM_REMINDER_CLOSE}`;
|
|
|
241523
241660
|
return `${SYSTEM_REMINDER_OPEN}
|
|
241524
241661
|
MCP servers with available tools: ${rendered}
|
|
241525
241662
|
Do not automatically store results of principal-restricted operations in shared memory.
|
|
241526
|
-
Find tools (with schemas) with \`letta mcp search "<what you want to do>"\`, list one server's tools with \`letta mcp tools <server>\` (\`--full\` includes schemas, \`letta mcp schema <tool-name>\` fetches one), and invoke one with \`letta mcp call <tool-name> --args '{"key":"value"}'\`.
|
|
241663
|
+
Find tools (with schemas) with \`letta mcp search "<what you want to do>"\`, list one server's tools with \`letta mcp tools <server>\` (\`--full\` includes schemas, \`letta mcp schema <tool-name>\` fetches one), and invoke one with \`letta mcp call <tool-name> --args '{"key":"value"}'\`. For large or quote-heavy arguments, use \`--args-file <path>\` (\`-\` for stdin) instead of \`--args\`. Exit code 2 means the tool returned an error result: read its \`content\`, fix the arguments, and retry (exit 1 is a CLI/usage error).
|
|
241527
241664
|
${SYSTEM_REMINDER_CLOSE}`;
|
|
241528
241665
|
}
|
|
241529
241666
|
async function listMcpServersForAgent(agentId, _state, deps = {}) {
|
|
@@ -245328,8 +245465,19 @@ async function defaultResolveComputer(computer, scope) {
|
|
|
245328
245465
|
if (!isCloudEnvironmentSelector(computer))
|
|
245329
245466
|
return resolveEnvironmentConnectionId(computer);
|
|
245330
245467
|
const client = await getClient();
|
|
245331
|
-
const
|
|
245332
|
-
const
|
|
245468
|
+
const parentConversationId = scope.conversationId && scope.conversationId !== "default" ? scope.conversationId : undefined;
|
|
245469
|
+
const createParams = {
|
|
245470
|
+
agent_id: scope.agentId,
|
|
245471
|
+
hidden: true,
|
|
245472
|
+
...parentConversationId ? { parent_conversation_id: parentConversationId } : {}
|
|
245473
|
+
};
|
|
245474
|
+
const conversation = await client.conversations.create(createParams).catch((error4) => {
|
|
245475
|
+
if (!parentConversationId || !error4 || typeof error4 !== "object" || !("status" in error4) || error4.status !== 403) {
|
|
245476
|
+
throw error4;
|
|
245477
|
+
}
|
|
245478
|
+
const fallbackParams = { agent_id: scope.agentId, hidden: true };
|
|
245479
|
+
return client.conversations.create(fallbackParams);
|
|
245480
|
+
});
|
|
245333
245481
|
return resolveAgentSandboxConnectionId(scope.agentId, {
|
|
245334
245482
|
conversationId: conversation.id
|
|
245335
245483
|
});
|
|
@@ -245563,21 +245711,27 @@ async function launchRemoteExternalCodingAgent(params, deps) {
|
|
|
245563
245711
|
});
|
|
245564
245712
|
return { success: false, error: error4 };
|
|
245565
245713
|
};
|
|
245566
|
-
let connectionId;
|
|
245567
|
-
let deviceId;
|
|
245568
|
-
let supportsSteering;
|
|
245569
|
-
let sendsForkContext;
|
|
245570
|
-
|
|
245571
|
-
|
|
245714
|
+
let connectionId = "";
|
|
245715
|
+
let deviceId = "";
|
|
245716
|
+
let supportsSteering = false;
|
|
245717
|
+
let sendsForkContext = false;
|
|
245718
|
+
const resolveComputer = deps.resolveComputer ?? defaultResolveComputer;
|
|
245719
|
+
function configureComputer(resolved) {
|
|
245572
245720
|
if (resolved.environment.metadata?.launch_subagent_notify_caller !== true)
|
|
245573
|
-
return
|
|
245721
|
+
return formatOutdatedComputerError(type, computer);
|
|
245574
245722
|
sendsForkContext = resolved.environment.metadata?.external_fork_context === true;
|
|
245575
245723
|
if (params.forkContext && !sendsForkContext)
|
|
245576
|
-
return
|
|
245724
|
+
return `Update Letta Code on ${computer} to fork external workers with destination-local history files.`;
|
|
245577
245725
|
sendsForkContext ||= (compareSemver(resolved.environment.metadata?.lettaCodeVersion ?? "", "0.34.40") ?? -1) >= 0;
|
|
245578
245726
|
connectionId = resolved.connectionId;
|
|
245579
245727
|
deviceId = resolved.environment.deviceId;
|
|
245580
245728
|
supportsSteering = resolved.environment.metadata?.subagent_message === true;
|
|
245729
|
+
return;
|
|
245730
|
+
}
|
|
245731
|
+
try {
|
|
245732
|
+
const outdated = configureComputer(await resolveComputer(computer, parentScope));
|
|
245733
|
+
if (outdated)
|
|
245734
|
+
return fail2("outdated_computer", outdated);
|
|
245581
245735
|
} catch (error4) {
|
|
245582
245736
|
return fail2("resolve_computer", errorMessage5(error4));
|
|
245583
245737
|
}
|
|
@@ -245590,27 +245744,53 @@ async function launchRemoteExternalCodingAgent(params, deps) {
|
|
|
245590
245744
|
} catch (error4) {
|
|
245591
245745
|
return fail2("connect", `Can't reach ${computer}: ${errorMessage5(error4)}`);
|
|
245592
245746
|
}
|
|
245593
|
-
const
|
|
245594
|
-
|
|
245747
|
+
const createFollower = () => {
|
|
245748
|
+
const next = new RemoteSubagentFollower(parentScope, toolCallId, connect, deps.reconnectDelayMs ?? 2000);
|
|
245749
|
+
next.attach(client);
|
|
245750
|
+
return next;
|
|
245751
|
+
};
|
|
245752
|
+
let follower = createFollower();
|
|
245753
|
+
const launch = () => client.launchSubagent({
|
|
245754
|
+
request_id: `launch-subagent-${randomUUID46()}`,
|
|
245755
|
+
runtime: {
|
|
245756
|
+
agent_id: parentScope.agentId,
|
|
245757
|
+
conversation_id: parentScope.conversationId,
|
|
245758
|
+
...parentScope.actingUserId ? { acting_user_id: parentScope.actingUserId } : {}
|
|
245759
|
+
},
|
|
245760
|
+
args: {
|
|
245761
|
+
...sendsForkContext ? { harness: type, fork_context: params.forkContext === true } : { subagent_type: type },
|
|
245762
|
+
prompt: params.prompt,
|
|
245763
|
+
description: params.description,
|
|
245764
|
+
...params.model ? { model: params.model } : {},
|
|
245765
|
+
...params.mcp ? { mcp: params.mcp } : {}
|
|
245766
|
+
},
|
|
245767
|
+
tool_call_id: toolCallId,
|
|
245768
|
+
notify: "caller"
|
|
245769
|
+
});
|
|
245595
245770
|
let launched;
|
|
245596
245771
|
try {
|
|
245597
|
-
|
|
245598
|
-
|
|
245599
|
-
|
|
245600
|
-
|
|
245601
|
-
|
|
245602
|
-
|
|
245603
|
-
|
|
245604
|
-
|
|
245605
|
-
|
|
245606
|
-
|
|
245607
|
-
|
|
245608
|
-
|
|
245609
|
-
|
|
245610
|
-
|
|
245611
|
-
|
|
245612
|
-
|
|
245613
|
-
|
|
245772
|
+
try {
|
|
245773
|
+
launched = await launch();
|
|
245774
|
+
} catch (error4) {
|
|
245775
|
+
follower.close();
|
|
245776
|
+
let resolved;
|
|
245777
|
+
try {
|
|
245778
|
+
resolved = await resolveComputer(isCloudEnvironmentSelector(computer) ? deviceId : computer, parentScope);
|
|
245779
|
+
} catch (resolveError) {
|
|
245780
|
+
if (/\boffline\b/i.test(errorMessage5(resolveError)))
|
|
245781
|
+
throw new Error(`${computer} disconnected during the launch: ${errorMessage5(resolveError)}`);
|
|
245782
|
+
throw resolveError;
|
|
245783
|
+
}
|
|
245784
|
+
if (resolved.connectionId === connectionId)
|
|
245785
|
+
throw error4;
|
|
245786
|
+
const outdated = configureComputer(resolved);
|
|
245787
|
+
if (outdated)
|
|
245788
|
+
throw new Error(outdated);
|
|
245789
|
+
params.signal?.throwIfAborted();
|
|
245790
|
+
client = await connect();
|
|
245791
|
+
follower = createFollower();
|
|
245792
|
+
launched = await launch();
|
|
245793
|
+
}
|
|
245614
245794
|
} catch (error4) {
|
|
245615
245795
|
follower.close();
|
|
245616
245796
|
return fail2("launch_request", `Couldn't launch ${type} on ${computer}: ${errorMessage5(error4)}`);
|
|
@@ -245693,6 +245873,7 @@ async function connectQualifiedTarget(agentId, parentScope, deps) {
|
|
|
245693
245873
|
throw new Error(formatOutdatedSteeringError(target.computer));
|
|
245694
245874
|
return {
|
|
245695
245875
|
target,
|
|
245876
|
+
lettaCodeVersion: resolved.environment.metadata?.lettaCodeVersion,
|
|
245696
245877
|
client: await (deps.connect ?? defaultConnect)(resolved.connectionId, parentScope)
|
|
245697
245878
|
};
|
|
245698
245879
|
}
|
|
@@ -245724,7 +245905,7 @@ async function sendRemoteExternalCodingAgentMessage(params, deps = {}) {
|
|
|
245724
245905
|
} catch (error4) {
|
|
245725
245906
|
const target = parseExternalCodingAgentId(params.agentId);
|
|
245726
245907
|
reportExternalWorkerLaunchFailure({
|
|
245727
|
-
stage: "follow_up",
|
|
245908
|
+
stage: error4 instanceof OutdatedRemoteWorkerError ? "outdated_computer" : "follow_up",
|
|
245728
245909
|
harness: target?.type ?? "unknown",
|
|
245729
245910
|
computer: target?.computer,
|
|
245730
245911
|
error: error4,
|
|
@@ -245737,7 +245918,7 @@ async function sendRemoteExternalCodingAgentMessage(params, deps = {}) {
|
|
|
245737
245918
|
}
|
|
245738
245919
|
async function deliverRemoteExternalCodingAgentMessage(params, deps) {
|
|
245739
245920
|
const requestId = `subagent-message-${randomUUID46()}`;
|
|
245740
|
-
const { target, client } = await connectQualifiedTarget(params.agentId, params.parentScope, deps);
|
|
245921
|
+
const { target, client, lettaCodeVersion } = await connectQualifiedTarget(params.agentId, params.parentScope, deps);
|
|
245741
245922
|
const toolCallId = params.toolCallId ?? `remote-followup-${randomUUID46()}`;
|
|
245742
245923
|
const connect = async () => {
|
|
245743
245924
|
const resolved = await (deps.resolveComputer ?? resolveQualifiedComputer)(target.computer, params.parentScope);
|
|
@@ -245765,6 +245946,9 @@ async function deliverRemoteExternalCodingAgentMessage(params, deps) {
|
|
|
245765
245946
|
}
|
|
245766
245947
|
if (!response.success) {
|
|
245767
245948
|
follower.close();
|
|
245949
|
+
if (response.error === "Subagent does not belong to this conversation" && (compareSemver(lettaCodeVersion ?? "", "0.34.54") ?? -1) < 0) {
|
|
245950
|
+
throw new OutdatedRemoteWorkerError(`${target.computer} is running Letta Code ${lettaCodeVersion ?? "(unknown version)"}, which doesn't keep track of finished or restarted workers, so it can't resume this one. Update Letta Code on ${target.computer}, or launch a new worker.`);
|
|
245951
|
+
}
|
|
245768
245952
|
throw new Error(response.error);
|
|
245769
245953
|
}
|
|
245770
245954
|
if (response.delivery === "steered") {
|
|
@@ -245829,7 +246013,7 @@ async function deliverRemoteExternalCodingAgentMessage(params, deps) {
|
|
|
245829
246013
|
outputFile: tracked.outputFile
|
|
245830
246014
|
};
|
|
245831
246015
|
}
|
|
245832
|
-
var REMOTE_EXTERNAL_WORKER_STOPPED, DISPLAY_NAMES, RemoteWorkerLostError, MAX_RECONNECT_DELAY_MS = 30000;
|
|
246016
|
+
var REMOTE_EXTERNAL_WORKER_STOPPED, DISPLAY_NAMES, RemoteWorkerLostError, OutdatedRemoteWorkerError, MAX_RECONNECT_DELAY_MS = 30000;
|
|
245833
246017
|
var init_remote_external_coding_agent = __esm(() => {
|
|
245834
246018
|
init_subagent_state();
|
|
245835
246019
|
init_app_server_client();
|
|
@@ -245850,6 +246034,8 @@ var init_remote_external_coding_agent = __esm(() => {
|
|
|
245850
246034
|
};
|
|
245851
246035
|
RemoteWorkerLostError = class RemoteWorkerLostError extends Error {
|
|
245852
246036
|
};
|
|
246037
|
+
OutdatedRemoteWorkerError = class OutdatedRemoteWorkerError extends Error {
|
|
246038
|
+
};
|
|
245853
246039
|
});
|
|
245854
246040
|
|
|
245855
246041
|
// src/tools/impl/subagent-computer.ts
|
|
@@ -245916,6 +246102,7 @@ function killBackgroundProcess(shell_id) {
|
|
|
245916
246102
|
proc.status = "failed";
|
|
245917
246103
|
}
|
|
245918
246104
|
proc.process.kill("SIGTERM");
|
|
246105
|
+
persistMonitorState(proc);
|
|
245919
246106
|
if (proc.kind === "monitor")
|
|
245920
246107
|
cancelMonitorBackup(shell_id);
|
|
245921
246108
|
clearBackgroundProcessCleanup(shell_id);
|
|
@@ -245934,6 +246121,7 @@ function killBackgroundProcess(shell_id) {
|
|
|
245934
246121
|
}
|
|
245935
246122
|
var init_kill_bash = __esm(() => {
|
|
245936
246123
|
init_monitor_backup();
|
|
246124
|
+
init_monitor_state();
|
|
245937
246125
|
init_process_manager();
|
|
245938
246126
|
});
|
|
245939
246127
|
|
|
@@ -246158,6 +246346,15 @@ async function task_stop(args, deps = {}) {
|
|
|
246158
246346
|
return (deps.stopCloudMonitor ?? stopCloudUrlMonitor)(task_id);
|
|
246159
246347
|
}
|
|
246160
246348
|
const killed = killBackgroundProcess(task_id);
|
|
246349
|
+
try {
|
|
246350
|
+
if (killed)
|
|
246351
|
+
await process21?.persistState?.();
|
|
246352
|
+
} catch {
|
|
246353
|
+
return {
|
|
246354
|
+
killed,
|
|
246355
|
+
output: "Monitor stopped, but its server state could not be saved"
|
|
246356
|
+
};
|
|
246357
|
+
}
|
|
246161
246358
|
return {
|
|
246162
246359
|
killed,
|
|
246163
246360
|
...killed && process21?.kind === "tool" ? { output: "Stopped" } : {}
|
|
@@ -248867,40 +249064,44 @@ function matchesCurrentFailure(attempt2, currentFailures) {
|
|
|
248867
249064
|
function sameKnownValue(previous, current) {
|
|
248868
249065
|
return current === "UNKNOWN" || previous === current;
|
|
248869
249066
|
}
|
|
248870
|
-
function diffGitHubPullRequestSnapshots(previous, current) {
|
|
249067
|
+
function diffGitHubPullRequestSnapshots(previous, current, notifyOn) {
|
|
248871
249068
|
const events = [];
|
|
249069
|
+
const add2 = (kind, ...lines) => {
|
|
249070
|
+
if (!notifyOn || notifyOn.includes(kind))
|
|
249071
|
+
events.push(...lines);
|
|
249072
|
+
};
|
|
248872
249073
|
const headChanged = previous.headSha !== current.headSha;
|
|
248873
249074
|
if (headChanged) {
|
|
248874
|
-
|
|
249075
|
+
add2("push", `PR head changed from ${shortGitHubPullRequestSha(previous.headSha)} to ${shortGitHubPullRequestSha(current.headSha)}. ${githubPullRequestCheckSummary(current)}; ${githubPullRequestBlockerSummary(current)}.`);
|
|
248875
249076
|
const currentFailures = current.checks.filter((check) => check.phase === "failure");
|
|
248876
249077
|
for (const attempt2 of current.checkAttempts) {
|
|
248877
249078
|
if (attempt2.phase === "failure" && !matchesCurrentFailure(attempt2, currentFailures)) {
|
|
248878
|
-
|
|
249079
|
+
add2("checks", `Check attempt failed on new head before the next poll: ${attempt2.name} (${attempt2.result}).${checkUrl(attempt2)}`);
|
|
248879
249080
|
}
|
|
248880
249081
|
}
|
|
248881
249082
|
}
|
|
248882
249083
|
if (previous.state !== current.state) {
|
|
248883
|
-
|
|
249084
|
+
add2(current.state === "MERGED" ? "merged" : "closed", current.state === "MERGED" ? `PR merged at ${shortGitHubPullRequestSha(current.headSha)}: ${current.ref.url}` : current.state === "CLOSED" ? `PR closed without merge at ${shortGitHubPullRequestSha(current.headSha)}: ${current.ref.url}` : `PR reopened at ${shortGitHubPullRequestSha(current.headSha)}: ${current.ref.url}`);
|
|
248884
249085
|
}
|
|
248885
249086
|
if (previous.isDraft !== current.isDraft) {
|
|
248886
|
-
|
|
249087
|
+
add2("state", current.isDraft ? "PR moved back to draft." : "PR marked ready for review.");
|
|
248887
249088
|
}
|
|
248888
249089
|
const previousComments = new Map(previous.comments.map((comment2) => [comment2.id, comment2]));
|
|
248889
249090
|
for (const comment2 of current.comments) {
|
|
248890
249091
|
const old = previousComments.get(comment2.id);
|
|
248891
249092
|
if (!old) {
|
|
248892
|
-
|
|
249093
|
+
add2("comment", commentEvent("New PR comment", comment2));
|
|
248893
249094
|
} else if (old.updatedAt !== comment2.updatedAt) {
|
|
248894
|
-
|
|
249095
|
+
add2("comment", commentEvent("PR comment edited", comment2));
|
|
248895
249096
|
}
|
|
248896
249097
|
}
|
|
248897
249098
|
const previousReviews = new Map(previous.reviews.map((review) => [review.id, review]));
|
|
248898
249099
|
for (const review of current.reviews) {
|
|
248899
249100
|
const old = previousReviews.get(review.id);
|
|
248900
249101
|
if (!old) {
|
|
248901
|
-
|
|
249102
|
+
add2("review", commentEvent(`New ${review.state.toLowerCase()} review`, review));
|
|
248902
249103
|
} else if (old.state !== review.state || old.updatedAt !== review.updatedAt) {
|
|
248903
|
-
|
|
249104
|
+
add2("review", commentEvent(`Review changed to ${review.state.toLowerCase()}`, review));
|
|
248904
249105
|
}
|
|
248905
249106
|
}
|
|
248906
249107
|
const previousThreads = new Map(previous.reviewThreads.map((thread) => [thread.id, thread]));
|
|
@@ -248908,19 +249109,19 @@ function diffGitHubPullRequestSnapshots(previous, current) {
|
|
|
248908
249109
|
const old = previousThreads.get(thread.id);
|
|
248909
249110
|
if (old && old.isResolved !== thread.isResolved) {
|
|
248910
249111
|
const url2 = thread.comments.at(-1)?.url ?? current.ref.url;
|
|
248911
|
-
|
|
249112
|
+
add2("review", thread.isResolved ? `Review thread resolved: ${url2}` : `Review thread reopened: ${url2}`);
|
|
248912
249113
|
}
|
|
248913
249114
|
const oldComments = new Map(old?.comments.map((comment2) => [comment2.id, comment2]) ?? []);
|
|
248914
249115
|
for (const comment2 of thread.comments) {
|
|
248915
249116
|
const oldComment = oldComments.get(comment2.id);
|
|
248916
249117
|
if (!oldComment) {
|
|
248917
|
-
|
|
249118
|
+
add2("comment", inlineCommentEvent(comment2));
|
|
248918
249119
|
} else {
|
|
248919
249120
|
if (oldComment.updatedAt !== comment2.updatedAt) {
|
|
248920
|
-
|
|
249121
|
+
add2("comment", inlineCommentEvent(comment2, "Inline review comment edited"));
|
|
248921
249122
|
}
|
|
248922
249123
|
if (oldComment.outdated !== comment2.outdated) {
|
|
248923
|
-
|
|
249124
|
+
add2("comment", comment2.outdated ? `Review comment became outdated: ${comment2.url}` : `Review comment is current again: ${comment2.url}`);
|
|
248924
249125
|
}
|
|
248925
249126
|
}
|
|
248926
249127
|
}
|
|
@@ -248933,39 +249134,42 @@ function diffGitHubPullRequestSnapshots(previous, current) {
|
|
|
248933
249134
|
for (const check of current.checks) {
|
|
248934
249135
|
const old = previousChecks.get(check.key);
|
|
248935
249136
|
if (check.phase === "pending" && old && old.phase !== "pending") {
|
|
248936
|
-
|
|
249137
|
+
add2("checks", `Check rerun started: ${check.name}.${checkUrl(check)}`);
|
|
248937
249138
|
}
|
|
248938
249139
|
if ((!old || old.phase !== "failure") && check.phase === "failure") {
|
|
248939
|
-
|
|
249140
|
+
add2("checks", `Check failed: ${check.name} (${check.result}).${checkUrl(check)}`);
|
|
248940
249141
|
} else if (old?.phase === "failure" && (check.phase === "success" || check.phase === "neutral")) {
|
|
248941
|
-
|
|
249142
|
+
add2("checks", `Check recovered: ${check.name} (${check.result}).${checkUrl(check)}`);
|
|
248942
249143
|
}
|
|
248943
249144
|
}
|
|
248944
249145
|
if (previousPending > 0 && currentPending === 0) {
|
|
248945
|
-
|
|
249146
|
+
add2("checks_done", `Current-head checks finished: ${githubPullRequestCheckSummary(current)}.`);
|
|
248946
249147
|
}
|
|
248947
249148
|
const previousAttempts = new Set(previous.checkAttempts.map((attempt2) => attempt2.key));
|
|
248948
249149
|
for (const attempt2 of current.checkAttempts) {
|
|
248949
249150
|
if (attempt2.phase === "failure" && !previousAttempts.has(attempt2.key) && !matchesCurrentFailure(attempt2, currentFailures)) {
|
|
248950
|
-
|
|
249151
|
+
add2("checks", `Check attempt failed before the next poll: ${attempt2.name} (${attempt2.result}).${checkUrl(attempt2)}`);
|
|
248951
249152
|
}
|
|
248952
249153
|
}
|
|
248953
249154
|
}
|
|
248954
249155
|
if (!sameKnownValue(previous.mergeable, current.mergeable)) {
|
|
248955
|
-
|
|
249156
|
+
add2("conflict", current.mergeable === "CONFLICTING" ? "PR now has merge conflicts." : `PR mergeability changed to ${current.mergeable}.`);
|
|
248956
249157
|
}
|
|
248957
249158
|
if (!sameKnownValue(previous.mergeStateStatus, current.mergeStateStatus)) {
|
|
248958
|
-
|
|
249159
|
+
add2("state", `GitHub merge state changed from ${previous.mergeStateStatus} to ${current.mergeStateStatus}.`);
|
|
248959
249160
|
}
|
|
248960
249161
|
if (previous.reviewDecision !== current.reviewDecision) {
|
|
248961
|
-
|
|
249162
|
+
add2("review", `Review decision changed from ${previous.reviewDecision} to ${current.reviewDecision}.`);
|
|
248962
249163
|
}
|
|
248963
249164
|
const wasReady = isGitHubPullRequestReady(previous);
|
|
248964
249165
|
const isReady = isGitHubPullRequestReady(current);
|
|
248965
249166
|
if (!wasReady && isReady) {
|
|
248966
|
-
|
|
249167
|
+
add2("state", `PR is merge-ready on head ${shortGitHubPullRequestSha(current.headSha)} after a fresh read: ${current.ref.url}`);
|
|
248967
249168
|
} else if (wasReady && !isReady) {
|
|
248968
|
-
|
|
249169
|
+
add2("state", `PR is no longer merge-ready on head ${shortGitHubPullRequestSha(current.headSha)}: ${githubPullRequestBlockerSummary(current)}; ${githubPullRequestCheckSummary(current)}.`);
|
|
249170
|
+
}
|
|
249171
|
+
if (headChanged && notifyOn?.includes("checks_done") && pendingGitHubPullRequestChecks(current).length === 0) {
|
|
249172
|
+
add2("checks_done", `Current-head checks finished: ${githubPullRequestCheckSummary(current)}.`);
|
|
248969
249173
|
}
|
|
248970
249174
|
return {
|
|
248971
249175
|
events,
|
|
@@ -248975,6 +249179,130 @@ function diffGitHubPullRequestSnapshots(previous, current) {
|
|
|
248975
249179
|
var MAX_SUMMARY_BODY_CHARS = 240;
|
|
248976
249180
|
var init_github_pull_request_diff = () => {};
|
|
248977
249181
|
|
|
249182
|
+
// src/tools/impl/github-workflow-run.ts
|
|
249183
|
+
import { execFile as execFile17 } from "node:child_process";
|
|
249184
|
+
import { promisify as promisify17 } from "node:util";
|
|
249185
|
+
function parseGitHubWorkflowRunUrl(value) {
|
|
249186
|
+
const url2 = new URL(value);
|
|
249187
|
+
const match3 = url2.pathname.match(/^\/([^/]+)\/([^/]+)\/actions\/runs\/([1-9]\d*)\/?$/);
|
|
249188
|
+
if (url2.protocol !== "https:" || url2.hostname !== "github.com" || url2.username || url2.password || !match3) {
|
|
249189
|
+
throw new Error("WatchPR url must look like https://github.com/owner/repo/actions/runs/123");
|
|
249190
|
+
}
|
|
249191
|
+
const [, owner, repo, id] = match3;
|
|
249192
|
+
if (!owner || !repo || !id || !Number.isSafeInteger(Number(id)))
|
|
249193
|
+
throw new Error("Invalid workflow run URL");
|
|
249194
|
+
return {
|
|
249195
|
+
owner,
|
|
249196
|
+
repo,
|
|
249197
|
+
number: Number(id),
|
|
249198
|
+
url: `https://github.com/${owner}/${repo}/actions/runs/${id}`
|
|
249199
|
+
};
|
|
249200
|
+
}
|
|
249201
|
+
function workflowRunSnapshot(ref, run) {
|
|
249202
|
+
if (!run.status || !run.headSha || !Array.isArray(run.jobs))
|
|
249203
|
+
throw new Error("Invalid workflow run snapshot");
|
|
249204
|
+
return {
|
|
249205
|
+
ref,
|
|
249206
|
+
headSha: run.headSha,
|
|
249207
|
+
state: run.status === "completed" ? "CLOSED" : "OPEN",
|
|
249208
|
+
isDraft: false,
|
|
249209
|
+
mergeable: "UNKNOWN",
|
|
249210
|
+
mergeStateStatus: "UNKNOWN",
|
|
249211
|
+
reviewDecision: "NONE",
|
|
249212
|
+
readinessConfirmed: false,
|
|
249213
|
+
checks: [],
|
|
249214
|
+
checkAttempts: [],
|
|
249215
|
+
comments: [],
|
|
249216
|
+
reviews: [],
|
|
249217
|
+
reviewThreads: [],
|
|
249218
|
+
workflowRun: run
|
|
249219
|
+
};
|
|
249220
|
+
}
|
|
249221
|
+
function describeWorkflowRun(snapshot2) {
|
|
249222
|
+
const run = snapshot2.workflowRun;
|
|
249223
|
+
if (!run)
|
|
249224
|
+
throw new Error("Missing workflow run");
|
|
249225
|
+
const failures = run.jobs.filter((job) => job.conclusion === "failure").map((job) => {
|
|
249226
|
+
const steps = (job.steps ?? []).filter((step) => step.conclusion === "failure").map((step) => step.name);
|
|
249227
|
+
return `${job.name}${steps.length ? ` (${steps.join(", ")})` : ""}`;
|
|
249228
|
+
});
|
|
249229
|
+
return `Workflow run ${snapshot2.ref.url}: ${run.status}${run.conclusion ? ` (${run.conclusion})` : ""}.${failures.length ? ` Failed jobs/steps: ${failures.join("; ")}.` : ""}`;
|
|
249230
|
+
}
|
|
249231
|
+
async function requestRun(ref, signal) {
|
|
249232
|
+
const client = await getClient();
|
|
249233
|
+
try {
|
|
249234
|
+
const response = await client.post("/v1/integrations/github/pull-request-snapshots", {
|
|
249235
|
+
body: {
|
|
249236
|
+
pull_requests: [],
|
|
249237
|
+
workflow_runs: [
|
|
249238
|
+
{ owner: ref.owner, repo: ref.repo, number: ref.number }
|
|
249239
|
+
]
|
|
249240
|
+
},
|
|
249241
|
+
signal,
|
|
249242
|
+
maxRetries: 0,
|
|
249243
|
+
timeout: 30000
|
|
249244
|
+
});
|
|
249245
|
+
return response.workflow_runs?.find((item) => item.owner.toLowerCase() === ref.owner.toLowerCase() && item.repo.toLowerCase() === ref.repo.toLowerCase() && item.number === ref.number);
|
|
249246
|
+
} catch (error4) {
|
|
249247
|
+
if (error4 instanceof APIError && [400, 404, 422, 501].includes(error4.status ?? 0))
|
|
249248
|
+
return;
|
|
249249
|
+
throw error4;
|
|
249250
|
+
}
|
|
249251
|
+
}
|
|
249252
|
+
function createGitHubWorkflowRunFetcher(deps = {}) {
|
|
249253
|
+
let unsupported = false;
|
|
249254
|
+
let hasSnapshot = false;
|
|
249255
|
+
const runGh = deps.runGh ?? (async (args, options) => (await promisify17(execFile17)("gh", args, {
|
|
249256
|
+
...options,
|
|
249257
|
+
timeout: 30000,
|
|
249258
|
+
maxBuffer: 5 * 1024 * 1024,
|
|
249259
|
+
encoding: "utf8",
|
|
249260
|
+
windowsHide: true
|
|
249261
|
+
})).stdout);
|
|
249262
|
+
return async (ref, options) => {
|
|
249263
|
+
if (!unsupported && (deps.isCloud ?? (() => resolveBackendMode() === "api" && isCloudServerUrl()))()) {
|
|
249264
|
+
try {
|
|
249265
|
+
const entry = await (deps.request ?? requestRun)(ref, options.signal);
|
|
249266
|
+
if (entry) {
|
|
249267
|
+
if (entry.inaccessible)
|
|
249268
|
+
throw new Error(`Cloud could not access ${ref.url}`);
|
|
249269
|
+
if (entry.stale || entry.retry_at)
|
|
249270
|
+
throw new GitHubPullRequestSnapshotPending;
|
|
249271
|
+
if (!entry.snapshot)
|
|
249272
|
+
throw new Error("Cloud returned no workflow run snapshot");
|
|
249273
|
+
const snapshot3 = workflowRunSnapshot(ref, entry.snapshot);
|
|
249274
|
+
hasSnapshot = true;
|
|
249275
|
+
return snapshot3;
|
|
249276
|
+
}
|
|
249277
|
+
unsupported = true;
|
|
249278
|
+
} catch (error4) {
|
|
249279
|
+
options.signal?.throwIfAborted();
|
|
249280
|
+
if (hasSnapshot || !(error4 instanceof APIConnectionError || error4 instanceof GitHubPullRequestSnapshotPending))
|
|
249281
|
+
throw error4;
|
|
249282
|
+
}
|
|
249283
|
+
}
|
|
249284
|
+
const run = JSON.parse(await runGh([
|
|
249285
|
+
"run",
|
|
249286
|
+
"view",
|
|
249287
|
+
String(ref.number),
|
|
249288
|
+
"-R",
|
|
249289
|
+
`${ref.owner}/${ref.repo}`,
|
|
249290
|
+
"--json",
|
|
249291
|
+
"status,conclusion,headSha,jobs"
|
|
249292
|
+
], options));
|
|
249293
|
+
const snapshot2 = workflowRunSnapshot(ref, run);
|
|
249294
|
+
hasSnapshot = true;
|
|
249295
|
+
return snapshot2;
|
|
249296
|
+
};
|
|
249297
|
+
}
|
|
249298
|
+
var init_github_workflow_run = __esm(() => {
|
|
249299
|
+
init_letta_client();
|
|
249300
|
+
init_client4();
|
|
249301
|
+
init_server_url();
|
|
249302
|
+
init_backend_mode();
|
|
249303
|
+
init_github_pull_request_cloud();
|
|
249304
|
+
});
|
|
249305
|
+
|
|
248978
249306
|
// src/tools/impl/watch-pr.ts
|
|
248979
249307
|
import { createHash as createHash12, randomUUID as randomUUID48 } from "node:crypto";
|
|
248980
249308
|
import {
|
|
@@ -249039,7 +249367,7 @@ function saveSnapshot(path32, snapshot2) {
|
|
|
249039
249367
|
} catch {}
|
|
249040
249368
|
}
|
|
249041
249369
|
}
|
|
249042
|
-
function resumedChanges(path32, initial2) {
|
|
249370
|
+
function resumedChanges(path32, initial2, notifyOn) {
|
|
249043
249371
|
if (!path32)
|
|
249044
249372
|
return "";
|
|
249045
249373
|
try {
|
|
@@ -249047,7 +249375,7 @@ function resumedChanges(path32, initial2) {
|
|
|
249047
249375
|
const age = Date.now() - saved.savedAt;
|
|
249048
249376
|
if (!Number.isFinite(age) || age < 0 || age > 7 * 24 * 3600000)
|
|
249049
249377
|
return "";
|
|
249050
|
-
const changes = diffGitHubPullRequestSnapshots(saved.snapshot, initial2).events;
|
|
249378
|
+
const changes = diffGitHubPullRequestSnapshots(saved.snapshot, initial2, notifyOn).events;
|
|
249051
249379
|
if (!changes.length)
|
|
249052
249380
|
return "";
|
|
249053
249381
|
let text2 = changes.map((line) => line.length > MONITOR_EVENT_LINE_CHARS ? `${line.slice(0, MONITOR_EVENT_LINE_CHARS)}...(truncated)` : line).join(`
|
|
@@ -249068,9 +249396,11 @@ async function watch_pr(args, deps = {}) {
|
|
|
249068
249396
|
if (typeof args.url !== "string") {
|
|
249069
249397
|
throw new Error("WatchPR url is required");
|
|
249070
249398
|
}
|
|
249071
|
-
const
|
|
249399
|
+
const isRun = args.url.includes("/actions/runs/");
|
|
249400
|
+
const ref = isRun ? parseGitHubWorkflowRunUrl(args.url) : parseGitHubPullRequestUrl(args.url);
|
|
249401
|
+
const describe2 = isRun ? describeWorkflowRun : describeGitHubPullRequestSnapshot;
|
|
249072
249402
|
const cwd2 = getCurrentWorkingDirectory();
|
|
249073
|
-
const fetchSnapshot = deps.fetchSnapshot ?? createGitHubPullRequestSnapshotFetcher();
|
|
249403
|
+
const fetchSnapshot = deps.fetchSnapshot ?? (isRun ? createGitHubWorkflowRunFetcher() : createGitHubPullRequestSnapshotFetcher());
|
|
249074
249404
|
const runtimeContext = getRuntimeContext();
|
|
249075
249405
|
const parentScope = args.parentScope ?? (runtimeContext?.agentId ? {
|
|
249076
249406
|
agentId: runtimeContext.agentId,
|
|
@@ -249079,7 +249409,7 @@ async function watch_pr(args, deps = {}) {
|
|
|
249079
249409
|
const scope = resolveNotificationScope(parentScope);
|
|
249080
249410
|
let snapshotPath;
|
|
249081
249411
|
try {
|
|
249082
|
-
snapshotPath = scope ? join74(resolveGlobalConfigDir(), "cache", "watch-pr", `${createHash12("sha256").update(JSON.stringify([
|
|
249412
|
+
snapshotPath = scope && !isRun ? join74(resolveGlobalConfigDir(), "cache", "watch-pr", `${createHash12("sha256").update(JSON.stringify([
|
|
249083
249413
|
scope.agentId,
|
|
249084
249414
|
scope.conversationId,
|
|
249085
249415
|
ref.owner.toLowerCase(),
|
|
@@ -249089,220 +249419,248 @@ async function watch_pr(args, deps = {}) {
|
|
|
249089
249419
|
} catch {}
|
|
249090
249420
|
const initial2 = await fetchSnapshot(ref, { cwd: cwd2, signal: args.signal });
|
|
249091
249421
|
args.signal?.throwIfAborted();
|
|
249092
|
-
const changesSincePreviousWatch = resumedChanges(snapshotPath, initial2);
|
|
249422
|
+
const changesSincePreviousWatch = resumedChanges(snapshotPath, initial2, args.notify_on);
|
|
249423
|
+
if (isRun && initial2.state !== "OPEN") {
|
|
249424
|
+
return {
|
|
249425
|
+
content: [{ type: "text", text: describe2(initial2) }],
|
|
249426
|
+
taskId: "",
|
|
249427
|
+
url: ref.url,
|
|
249428
|
+
headSha: initial2.headSha,
|
|
249429
|
+
persistent: false
|
|
249430
|
+
};
|
|
249431
|
+
}
|
|
249093
249432
|
if (initial2.state !== "OPEN") {
|
|
249094
249433
|
saveSnapshot(snapshotPath, initial2);
|
|
249095
249434
|
throw new Error(`WatchPR did not start because ${ref.url} is already ${initial2.state.toLowerCase()}.`);
|
|
249096
249435
|
}
|
|
249097
249436
|
assertBackgroundProcessCapacity();
|
|
249098
249437
|
installMonitorProcessExitCleanup();
|
|
249099
|
-
const
|
|
249100
|
-
const outputFile = createBackgroundOutputFile(taskId);
|
|
249101
|
-
const output = deps.createOutputWriter?.(outputFile) ?? new MonitorOutputWriter(outputFile);
|
|
249102
|
-
if (!output.append(`[initial snapshot]
|
|
249103
|
-
${describeGitHubPullRequestSnapshot(initial2)}${changesSincePreviousWatch}
|
|
249104
|
-
`)) {
|
|
249105
|
-
rmSync19(outputFile, { force: true });
|
|
249106
|
-
throw new Error(`WatchPR could not write its output file: ${outputFile}`);
|
|
249107
|
-
}
|
|
249108
|
-
saveSnapshot(snapshotPath, initial2);
|
|
249109
|
-
const actingUserId = getRuntimeActingUserAttribution();
|
|
249110
|
-
const description = `PR ${ref.owner}/${ref.repo}#${ref.number} checks, reviews, and mergeability`;
|
|
249111
|
-
const controller = new AbortController;
|
|
249112
|
-
const secrets2 = {};
|
|
249113
|
-
let processState;
|
|
249438
|
+
const description = isRun ? `Workflow run ${ref.owner}/${ref.repo}#${ref.number}` : `PR ${ref.owner}/${ref.repo}#${ref.number} checks, reviews, and mergeability`;
|
|
249114
249439
|
const persistent = !isManagedCloudRuntime();
|
|
249115
|
-
|
|
249116
|
-
|
|
249117
|
-
|
|
249118
|
-
|
|
249119
|
-
|
|
249120
|
-
|
|
249121
|
-
|
|
249122
|
-
|
|
249123
|
-
|
|
249124
|
-
|
|
249125
|
-
|
|
249126
|
-
|
|
249127
|
-
|
|
249128
|
-
|
|
249129
|
-
|
|
249130
|
-
|
|
249131
|
-
|
|
249440
|
+
return withMonitorState({
|
|
249441
|
+
description,
|
|
249442
|
+
persistent,
|
|
249443
|
+
command: ref.url,
|
|
249444
|
+
kind: "github_pull_request",
|
|
249445
|
+
parentScope,
|
|
249446
|
+
signal: args.signal
|
|
249447
|
+
}, (taskId) => {
|
|
249448
|
+
const outputFile = createBackgroundOutputFile(taskId);
|
|
249449
|
+
const output = deps.createOutputWriter?.(outputFile) ?? new MonitorOutputWriter(outputFile);
|
|
249450
|
+
if (!output.append(`[initial snapshot]
|
|
249451
|
+
${describe2(initial2)}${changesSincePreviousWatch}
|
|
249452
|
+
`)) {
|
|
249453
|
+
rmSync19(outputFile, { force: true });
|
|
249454
|
+
throw new Error(`WatchPR could not write its output file: ${outputFile}`);
|
|
249455
|
+
}
|
|
249456
|
+
saveSnapshot(snapshotPath, initial2);
|
|
249457
|
+
const actingUserId = getRuntimeActingUserAttribution();
|
|
249458
|
+
const controller = new AbortController;
|
|
249459
|
+
const secrets2 = {};
|
|
249460
|
+
let processState;
|
|
249461
|
+
const maxTimeoutMs = getMonitorMaxTimeoutMs();
|
|
249462
|
+
let timeout;
|
|
249463
|
+
const events = createMonitorEventStream({
|
|
249464
|
+
emit(event) {
|
|
249465
|
+
queueMonitorEvent({
|
|
249466
|
+
taskId,
|
|
249467
|
+
event,
|
|
249468
|
+
scope,
|
|
249469
|
+
actingUserId,
|
|
249470
|
+
secrets: secrets2
|
|
249471
|
+
});
|
|
249472
|
+
},
|
|
249473
|
+
stopSource() {
|
|
249474
|
+
if (!processState || processState.status !== "running")
|
|
249475
|
+
return;
|
|
249476
|
+
processState.completionNotificationSuppressed = true;
|
|
249477
|
+
output.append(`
|
|
249132
249478
|
[stopped: output rate too high]
|
|
249133
249479
|
`);
|
|
249134
|
-
|
|
249135
|
-
controller.abort();
|
|
249136
|
-
}
|
|
249137
|
-
});
|
|
249138
|
-
const emit = (lines) => {
|
|
249139
|
-
if (lines.length === 0 || processState.status !== "running")
|
|
249140
|
-
return;
|
|
249141
|
-
const text2 = scrubSecretsFromString(`${lines.join(`
|
|
249142
|
-
`)}
|
|
249143
|
-
`, {});
|
|
249144
|
-
if (!output.append(text2)) {
|
|
249145
|
-
processState.completionNotificationSuppressed = true;
|
|
249146
|
-
markMonitorFinished(taskId, processState, "failed", null);
|
|
249147
|
-
controller.abort();
|
|
249148
|
-
return;
|
|
249149
|
-
}
|
|
249150
|
-
events.onData(text2);
|
|
249151
|
-
};
|
|
249152
|
-
processState = {
|
|
249153
|
-
process: {
|
|
249154
|
-
kill() {
|
|
249155
|
-
clearTimeout(timeout);
|
|
249156
|
-
events.cancel();
|
|
249480
|
+
markMonitorFinished(taskId, processState, "failed", null);
|
|
249157
249481
|
controller.abort();
|
|
249158
249482
|
}
|
|
249159
|
-
}
|
|
249160
|
-
|
|
249161
|
-
|
|
249162
|
-
exitCode: null,
|
|
249163
|
-
startTime: new Date,
|
|
249164
|
-
outputFile,
|
|
249165
|
-
runtimeScope: scope,
|
|
249166
|
-
actingUserId,
|
|
249167
|
-
kind: "monitor",
|
|
249168
|
-
description,
|
|
249169
|
-
monitorSource: "github_pull_request",
|
|
249170
|
-
persistent,
|
|
249171
|
-
secrets: secrets2
|
|
249172
|
-
};
|
|
249173
|
-
backgroundProcesses.set(taskId, processState);
|
|
249174
|
-
notifyBackgroundProcessStateChanged(scope);
|
|
249175
|
-
if (!persistent) {
|
|
249176
|
-
timeout = setTimeout(() => {
|
|
249177
|
-
if (processState.status !== "running")
|
|
249483
|
+
});
|
|
249484
|
+
const emit = (lines) => {
|
|
249485
|
+
if (lines.length === 0 || processState.status !== "running")
|
|
249178
249486
|
return;
|
|
249179
|
-
|
|
249180
|
-
|
|
249487
|
+
const text2 = scrubSecretsFromString(`${lines.join(`
|
|
249488
|
+
`)}
|
|
249489
|
+
`, {});
|
|
249490
|
+
if (!output.append(text2)) {
|
|
249491
|
+
processState.completionNotificationSuppressed = true;
|
|
249492
|
+
markMonitorFinished(taskId, processState, "failed", null);
|
|
249493
|
+
controller.abort();
|
|
249181
249494
|
return;
|
|
249182
|
-
|
|
249183
|
-
|
|
249184
|
-
|
|
249185
|
-
|
|
249186
|
-
|
|
249187
|
-
|
|
249188
|
-
|
|
249189
|
-
|
|
249190
|
-
|
|
249191
|
-
|
|
249192
|
-
|
|
249193
|
-
|
|
249194
|
-
|
|
249195
|
-
|
|
249196
|
-
|
|
249197
|
-
|
|
249198
|
-
|
|
249199
|
-
|
|
249200
|
-
|
|
249201
|
-
|
|
249202
|
-
|
|
249203
|
-
|
|
249204
|
-
|
|
249205
|
-
|
|
249495
|
+
}
|
|
249496
|
+
events.onData(text2);
|
|
249497
|
+
};
|
|
249498
|
+
processState = {
|
|
249499
|
+
process: {
|
|
249500
|
+
kill() {
|
|
249501
|
+
clearTimeout(timeout);
|
|
249502
|
+
events.cancel();
|
|
249503
|
+
controller.abort();
|
|
249504
|
+
}
|
|
249505
|
+
},
|
|
249506
|
+
command: ref.url,
|
|
249507
|
+
status: "running",
|
|
249508
|
+
exitCode: null,
|
|
249509
|
+
startTime: new Date,
|
|
249510
|
+
outputFile,
|
|
249511
|
+
runtimeScope: scope,
|
|
249512
|
+
actingUserId,
|
|
249513
|
+
kind: "monitor",
|
|
249514
|
+
description,
|
|
249515
|
+
monitorSource: "github_pull_request",
|
|
249516
|
+
persistent,
|
|
249517
|
+
secrets: secrets2
|
|
249518
|
+
};
|
|
249519
|
+
backgroundProcesses.set(taskId, processState);
|
|
249520
|
+
notifyBackgroundProcessStateChanged(scope);
|
|
249521
|
+
if (!persistent) {
|
|
249522
|
+
timeout = setTimeout(() => {
|
|
249206
249523
|
if (processState.status !== "running")
|
|
249207
249524
|
return;
|
|
249208
|
-
|
|
249209
|
-
cwd: cwd2,
|
|
249210
|
-
signal: controller.signal
|
|
249211
|
-
});
|
|
249525
|
+
events.finish();
|
|
249212
249526
|
if (processState.status !== "running")
|
|
249213
249527
|
return;
|
|
249214
|
-
|
|
249215
|
-
|
|
249216
|
-
|
|
249217
|
-
|
|
249218
|
-
}
|
|
249219
|
-
|
|
249220
|
-
|
|
249221
|
-
|
|
249222
|
-
|
|
249223
|
-
|
|
249224
|
-
|
|
249225
|
-
|
|
249226
|
-
|
|
249227
|
-
|
|
249228
|
-
|
|
249229
|
-
|
|
249230
|
-
|
|
249231
|
-
|
|
249232
|
-
|
|
249233
|
-
|
|
249234
|
-
|
|
249235
|
-
|
|
249236
|
-
|
|
249237
|
-
|
|
249238
|
-
|
|
249528
|
+
const event = getMonitorTimeoutEvent(maxTimeoutMs, "WatchPR");
|
|
249529
|
+
output.append(`
|
|
249530
|
+
${event}
|
|
249531
|
+
`);
|
|
249532
|
+
queueMonitorEvent({ taskId, event, scope, actingUserId, secrets: secrets2 });
|
|
249533
|
+
processState.completionNotificationSuppressed = true;
|
|
249534
|
+
markMonitorFinished(taskId, processState, "failed", null);
|
|
249535
|
+
processState.process.kill();
|
|
249536
|
+
}, maxTimeoutMs);
|
|
249537
|
+
unrefTimer(timeout);
|
|
249538
|
+
}
|
|
249539
|
+
const wait = deps.wait ?? defaultWait;
|
|
249540
|
+
const now2 = deps.now ?? Date.now;
|
|
249541
|
+
(async () => {
|
|
249542
|
+
let previous = initial2;
|
|
249543
|
+
let lastFreshSnapshotAt = now2();
|
|
249544
|
+
let freshnessNoticeSent = false;
|
|
249545
|
+
let nextPollMs = WATCH_POLL_MS;
|
|
249546
|
+
let failedPolls = 0;
|
|
249547
|
+
let failureStartedAt;
|
|
249548
|
+
let lastNotifiedError;
|
|
249549
|
+
while (processState.status === "running") {
|
|
249550
|
+
try {
|
|
249551
|
+
await wait(controller.signal, nextPollMs);
|
|
249552
|
+
if (processState.status !== "running")
|
|
249553
|
+
return;
|
|
249554
|
+
const current = await fetchSnapshot(ref, {
|
|
249555
|
+
cwd: cwd2,
|
|
249556
|
+
signal: controller.signal
|
|
249557
|
+
});
|
|
249558
|
+
if (processState.status !== "running")
|
|
249559
|
+
return;
|
|
249560
|
+
lastFreshSnapshotAt = now2();
|
|
249561
|
+
if (freshnessNoticeSent) {
|
|
249562
|
+
emit(["WatchPR is receiving PR updates again."]);
|
|
249563
|
+
freshnessNoticeSent = false;
|
|
249239
249564
|
}
|
|
249240
|
-
return;
|
|
249241
|
-
}
|
|
249242
|
-
} catch (error4) {
|
|
249243
|
-
if (controller.signal.aborted || processState.status !== "running") {
|
|
249244
|
-
return;
|
|
249245
|
-
}
|
|
249246
|
-
if (!freshnessNoticeSent && now2() - lastFreshSnapshotAt >= WATCH_FRESH_SNAPSHOT_NOTIFY_AFTER_MS) {
|
|
249247
|
-
emit([
|
|
249248
|
-
"WatchPR hasn't received fresh PR data for 30 minutes; still watching."
|
|
249249
|
-
]);
|
|
249250
|
-
freshnessNoticeSent = true;
|
|
249251
|
-
}
|
|
249252
|
-
if (error4 instanceof GitHubPullRequestSnapshotPending) {
|
|
249253
249565
|
nextPollMs = WATCH_POLL_MS;
|
|
249254
|
-
if (
|
|
249566
|
+
if (lastNotifiedError !== undefined) {
|
|
249567
|
+
emit([
|
|
249568
|
+
`WatchPR recovered after ${failedPolls} failed poll${failedPolls === 1 ? "" : "s"}.`
|
|
249569
|
+
]);
|
|
249570
|
+
}
|
|
249571
|
+
failedPolls = 0;
|
|
249572
|
+
failureStartedAt = undefined;
|
|
249573
|
+
lastNotifiedError = undefined;
|
|
249574
|
+
const sameHead = current.headSha === previous.headSha;
|
|
249575
|
+
const stableCurrent = { ...current, readinessConfirmed: false };
|
|
249576
|
+
stableCurrent.readinessConfirmed = Boolean(sameHead && hasGitHubPullRequestReadyConditions(previous) && hasGitHubPullRequestReadyConditions(stableCurrent));
|
|
249577
|
+
saveSnapshot(snapshotPath, stableCurrent);
|
|
249578
|
+
const diff2 = isRun ? {
|
|
249579
|
+
events: previous.workflowRun?.status !== current.workflowRun?.status || previous.workflowRun?.conclusion !== current.workflowRun?.conclusion ? [describe2(current)] : [],
|
|
249580
|
+
terminal: current.state !== "OPEN"
|
|
249581
|
+
} : diffGitHubPullRequestSnapshots(previous, stableCurrent, args.notify_on);
|
|
249582
|
+
emit(diff2.events);
|
|
249583
|
+
previous = stableCurrent;
|
|
249584
|
+
if (diff2.terminal) {
|
|
249585
|
+
events.finish();
|
|
249586
|
+
if (processState.status === "running") {
|
|
249587
|
+
markMonitorFinished(taskId, processState, "completed", 0);
|
|
249588
|
+
}
|
|
249589
|
+
return;
|
|
249590
|
+
}
|
|
249591
|
+
} catch (error4) {
|
|
249592
|
+
if (controller.signal.aborted || processState.status !== "running") {
|
|
249593
|
+
return;
|
|
249594
|
+
}
|
|
249595
|
+
if (!freshnessNoticeSent && now2() - lastFreshSnapshotAt >= WATCH_FRESH_SNAPSHOT_NOTIFY_AFTER_MS) {
|
|
249596
|
+
emit([
|
|
249597
|
+
"WatchPR hasn't received fresh PR data for 30 minutes; still watching."
|
|
249598
|
+
]);
|
|
249599
|
+
freshnessNoticeSent = true;
|
|
249600
|
+
}
|
|
249601
|
+
if (error4 instanceof GitHubPullRequestSnapshotPending) {
|
|
249602
|
+
nextPollMs = WATCH_POLL_MS;
|
|
249603
|
+
if (!output.append(`[poll pending] Waiting for fresh PR data
|
|
249604
|
+
`)) {
|
|
249605
|
+
processState.completionNotificationSuppressed = true;
|
|
249606
|
+
markMonitorFinished(taskId, processState, "failed", null);
|
|
249607
|
+
controller.abort();
|
|
249608
|
+
return;
|
|
249609
|
+
}
|
|
249610
|
+
continue;
|
|
249611
|
+
}
|
|
249612
|
+
failedPolls += 1;
|
|
249613
|
+
nextPollMs = pollDelayMs(failedPolls);
|
|
249614
|
+
failureStartedAt ??= now2();
|
|
249615
|
+
const message2 = errorText(error4);
|
|
249616
|
+
if (!output.append(`[poll error ${failedPolls}] ${message2}
|
|
249255
249617
|
`)) {
|
|
249256
249618
|
processState.completionNotificationSuppressed = true;
|
|
249257
249619
|
markMonitorFinished(taskId, processState, "failed", null);
|
|
249258
249620
|
controller.abort();
|
|
249259
249621
|
return;
|
|
249260
249622
|
}
|
|
249261
|
-
|
|
249262
|
-
|
|
249263
|
-
|
|
249264
|
-
|
|
249265
|
-
|
|
249266
|
-
|
|
249267
|
-
if (!output.append(`[poll error ${failedPolls}] ${message2}
|
|
249268
|
-
`)) {
|
|
249269
|
-
processState.completionNotificationSuppressed = true;
|
|
249270
|
-
markMonitorFinished(taskId, processState, "failed", null);
|
|
249271
|
-
controller.abort();
|
|
249272
|
-
return;
|
|
249273
|
-
}
|
|
249274
|
-
if (now2() - failureStartedAt >= WATCH_REFRESH_ERROR_NOTIFY_AFTER_MS && message2 !== lastNotifiedError) {
|
|
249275
|
-
emit([`WatchPR could not refresh ${ref.url}: ${message2}. Retrying.`]);
|
|
249276
|
-
lastNotifiedError = message2;
|
|
249623
|
+
if (now2() - failureStartedAt >= WATCH_REFRESH_ERROR_NOTIFY_AFTER_MS && message2 !== lastNotifiedError) {
|
|
249624
|
+
emit([
|
|
249625
|
+
`WatchPR could not refresh ${ref.url}: ${message2}. Retrying.`
|
|
249626
|
+
]);
|
|
249627
|
+
lastNotifiedError = message2;
|
|
249628
|
+
}
|
|
249277
249629
|
}
|
|
249278
249630
|
}
|
|
249279
|
-
}
|
|
249280
|
-
|
|
249281
|
-
|
|
249282
|
-
|
|
249283
|
-
|
|
249284
|
-
|
|
249285
|
-
|
|
249286
|
-
|
|
249287
|
-
|
|
249288
|
-
|
|
249289
|
-
|
|
249290
|
-
|
|
249291
|
-
|
|
249292
|
-
|
|
249293
|
-
|
|
249631
|
+
})().catch((error4) => {
|
|
249632
|
+
if (processState.status !== "running")
|
|
249633
|
+
return;
|
|
249634
|
+
emit([
|
|
249635
|
+
`WatchPR stopped after an unexpected error: ${errorText(error4)}`
|
|
249636
|
+
]);
|
|
249637
|
+
events.finish();
|
|
249638
|
+
if (processState.status === "running") {
|
|
249639
|
+
markMonitorFinished(taskId, processState, "failed", null);
|
|
249640
|
+
}
|
|
249641
|
+
}).finally(() => clearTimeout(timeout));
|
|
249642
|
+
return {
|
|
249643
|
+
content: [
|
|
249644
|
+
{
|
|
249645
|
+
type: "text",
|
|
249646
|
+
text: isRun ? `WatchPR started (task ${taskId}). It reports workflow run status changes and completion with conclusion and failed jobs/steps.
|
|
249647
|
+
|
|
249648
|
+
${describe2(initial2)}
|
|
249649
|
+
|
|
249650
|
+
Output file: ${outputFile}` : `WatchPR started (task ${taskId}). ${args.notify_on ? `It will report ${args.notify_on.join(", ")} and watcher errors.` : "It will keep watching after CI finishes and report new failures, reviews, comments, conflicts, head changes, merge-state changes, and watcher errors."} It stops when the PR merges/closes, on TaskStop, or when this session ends.${persistent ? "" : ` A hard ${maxTimeoutMs / 3600000}-hour limit applies in this Cloud sandbox; call WatchPR again to re-arm it, or use Wake or cron for much longer waits.`}
|
|
249294
249651
|
|
|
249295
249652
|
Current state:
|
|
249296
|
-
${
|
|
249653
|
+
${describe2(initial2)}${changesSincePreviousWatch}
|
|
249297
249654
|
|
|
249298
249655
|
Output file: ${outputFile}`
|
|
249299
|
-
|
|
249300
|
-
|
|
249301
|
-
|
|
249302
|
-
|
|
249303
|
-
|
|
249304
|
-
|
|
249305
|
-
|
|
249656
|
+
}
|
|
249657
|
+
],
|
|
249658
|
+
taskId,
|
|
249659
|
+
url: ref.url,
|
|
249660
|
+
headSha: initial2.headSha,
|
|
249661
|
+
persistent
|
|
249662
|
+
};
|
|
249663
|
+
});
|
|
249306
249664
|
}
|
|
249307
249665
|
var WATCH_POLL_MS = 30000, WATCH_MAX_POLL_MS, WATCH_REFRESH_ERROR_NOTIFY_AFTER_MS, WATCH_FRESH_SNAPSHOT_NOTIFY_AFTER_MS;
|
|
249308
249666
|
var init_watch_pr = __esm(() => {
|
|
@@ -249313,8 +249671,10 @@ var init_watch_pr = __esm(() => {
|
|
|
249313
249671
|
init_github_pull_request_cloud();
|
|
249314
249672
|
init_github_pull_request_diff();
|
|
249315
249673
|
init_github_pull_request_watch();
|
|
249674
|
+
init_github_workflow_run();
|
|
249316
249675
|
init_monitor();
|
|
249317
249676
|
init_monitor_event_stream();
|
|
249677
|
+
init_monitor_state();
|
|
249318
249678
|
init_monitor_timeout();
|
|
249319
249679
|
init_process_manager();
|
|
249320
249680
|
WATCH_MAX_POLL_MS = 5 * 60000;
|
|
@@ -251361,7 +251721,26 @@ var init_WatchPR2 = __esm(() => {
|
|
|
251361
251721
|
properties: {
|
|
251362
251722
|
url: {
|
|
251363
251723
|
type: "string",
|
|
251364
|
-
description: "Open github.com pull request URL ending at the PR number, for example https://github.com/owner/repo/pull/123. Remove sub-page suffixes such as /files or /commits."
|
|
251724
|
+
description: "Open github.com pull request URL ending at the PR number, for example https://github.com/owner/repo/pull/123. Remove sub-page suffixes such as /files or /commits. Also accepts https://github.com/owner/repo/actions/runs/123."
|
|
251725
|
+
},
|
|
251726
|
+
notify_on: {
|
|
251727
|
+
type: "array",
|
|
251728
|
+
minItems: 1,
|
|
251729
|
+
items: {
|
|
251730
|
+
type: "string",
|
|
251731
|
+
enum: [
|
|
251732
|
+
"merged",
|
|
251733
|
+
"closed",
|
|
251734
|
+
"conflict",
|
|
251735
|
+
"checks_done",
|
|
251736
|
+
"review",
|
|
251737
|
+
"comment",
|
|
251738
|
+
"push",
|
|
251739
|
+
"state",
|
|
251740
|
+
"checks"
|
|
251741
|
+
]
|
|
251742
|
+
},
|
|
251743
|
+
description: "PR events to report; omitted reports all. checks_done reports when no checks remain pending, including pass/fail. Workflow runs always report status and completion."
|
|
251365
251744
|
}
|
|
251366
251745
|
},
|
|
251367
251746
|
required: ["url"],
|
|
@@ -267553,9 +267932,10 @@ async function prepareToolExecutionContextForScope(params) {
|
|
|
267553
267932
|
} = params;
|
|
267554
267933
|
const clientToolset = mergeClientToolsetFields(requestClientToolset, getStoredClientPreferences(agentId, conversationId).toolset);
|
|
267555
267934
|
const backend3 = getBackend();
|
|
267556
|
-
const
|
|
267935
|
+
const readScopeState = params.readScopeState ?? ((read2) => read2());
|
|
267936
|
+
const agent = agentId ? cachedAgent ?? await readScopeState(() => backend3.retrieveAgent(agentId)) : null;
|
|
267557
267937
|
const agentTarget = modelTargetFromCarrier(agent);
|
|
267558
|
-
const conversationTarget = conversationId && conversationId !== "default" ? modelTargetFromCarrier(await backend3.retrieveConversation(conversationId)) : { model: null, providerType: null, openAICompatibleProxy: false };
|
|
267938
|
+
const conversationTarget = conversationId && conversationId !== "default" ? modelTargetFromCarrier(await readScopeState(() => backend3.retrieveConversation(conversationId))) : { model: null, providerType: null, openAICompatibleProxy: false };
|
|
267559
267939
|
const explicitModel = normalizeModelHandle(overrideModel);
|
|
267560
267940
|
const cachedModel = normalizeModelHandle(cachedEffectiveModel);
|
|
267561
267941
|
const effectiveModel = explicitModel ?? cachedModel ?? conversationTarget.model ?? agentTarget.model;
|
|
@@ -439148,6 +439528,7 @@ async function syncMemfsForAgent(agentId) {
|
|
|
439148
439528
|
debugWarn("memfs-sync", `Agent ${agentId} is missing the memfs tag on Letta Cloud — repairing (auto-enabling memfs).`);
|
|
439149
439529
|
await applyMemfsFlags2(agentId, true, {
|
|
439150
439530
|
pullOnExistingRepo: true,
|
|
439531
|
+
throwOnPullFailure: true,
|
|
439151
439532
|
agentTags: agent.tags ?? []
|
|
439152
439533
|
});
|
|
439153
439534
|
debugLog("memfs-sync", `Memfs repair complete for agent ${agentId}`);
|
|
@@ -439156,19 +439537,26 @@ async function syncMemfsForAgent(agentId) {
|
|
|
439156
439537
|
debugLog("memfs-sync", `Syncing memfs for agent ${agentId}`);
|
|
439157
439538
|
await applyMemfsFlags2(agentId, undefined, {
|
|
439158
439539
|
pullOnExistingRepo: true,
|
|
439540
|
+
throwOnPullFailure: true,
|
|
439159
439541
|
agentTags: agent.tags,
|
|
439160
439542
|
skipPromptUpdate: true
|
|
439161
439543
|
});
|
|
439162
439544
|
debugLog("memfs-sync", `Memfs sync complete for agent ${agentId}`);
|
|
439163
439545
|
}
|
|
439164
439546
|
async function ensureMemfsSyncedForAgent(listener, agentId) {
|
|
439547
|
+
if (isMemoryUnavailable(agentId))
|
|
439548
|
+
return false;
|
|
439165
439549
|
const existing = listener.memfsSyncedAgents.get(agentId);
|
|
439166
439550
|
if (existing) {
|
|
439167
439551
|
return existing;
|
|
439168
439552
|
}
|
|
439169
439553
|
const promise2 = syncMemfsForAgent(agentId).then(() => true, (err) => {
|
|
439170
439554
|
debugWarn("memfs-sync", `Failed to sync memfs for agent ${agentId}: ${err instanceof Error ? err.message : String(err)}`);
|
|
439171
|
-
|
|
439555
|
+
if (isMemoryAccessRefusal(err)) {
|
|
439556
|
+
markMemoryUnavailable(agentId);
|
|
439557
|
+
} else {
|
|
439558
|
+
listener.memfsSyncedAgents.delete(agentId);
|
|
439559
|
+
}
|
|
439172
439560
|
return false;
|
|
439173
439561
|
});
|
|
439174
439562
|
listener.memfsSyncedAgents.set(agentId, promise2);
|
|
@@ -439176,6 +439564,7 @@ async function ensureMemfsSyncedForAgent(listener, agentId) {
|
|
|
439176
439564
|
}
|
|
439177
439565
|
var init_memfs_sync = __esm(() => {
|
|
439178
439566
|
init_debug();
|
|
439567
|
+
init_memory_access();
|
|
439179
439568
|
});
|
|
439180
439569
|
|
|
439181
439570
|
// src/websocket/listener/mod-adapter.ts
|
|
@@ -440964,6 +441353,46 @@ var init_recovery = __esm(() => {
|
|
|
440964
441353
|
init_recovery_debug();
|
|
440965
441354
|
});
|
|
440966
441355
|
|
|
441356
|
+
// src/websocket/listener/recovery-read.ts
|
|
441357
|
+
async function retryApprovalRecoveryRead(read2, assertCurrent, signal) {
|
|
441358
|
+
for (let attempt2 = 0;; attempt2++) {
|
|
441359
|
+
assertCurrent();
|
|
441360
|
+
try {
|
|
441361
|
+
const result3 = await read2();
|
|
441362
|
+
assertCurrent();
|
|
441363
|
+
return result3;
|
|
441364
|
+
} catch (error4) {
|
|
441365
|
+
assertCurrent();
|
|
441366
|
+
const detail = extractConflictDetail(error4);
|
|
441367
|
+
if (attempt2 >= LLM_API_ERROR_MAX_RETRIES || !shouldRetryPreStreamTransientError({
|
|
441368
|
+
status: error4 instanceof APIError ? error4.status : undefined,
|
|
441369
|
+
detail
|
|
441370
|
+
}))
|
|
441371
|
+
throw error4;
|
|
441372
|
+
await new Promise((resolve37) => {
|
|
441373
|
+
const done = () => {
|
|
441374
|
+
clearTimeout(timer);
|
|
441375
|
+
signal.removeEventListener("abort", done);
|
|
441376
|
+
resolve37();
|
|
441377
|
+
};
|
|
441378
|
+
const timer = setTimeout(done, getRetryDelayMs2({
|
|
441379
|
+
category: "transient_provider",
|
|
441380
|
+
attempt: attempt2 + 1,
|
|
441381
|
+
detail
|
|
441382
|
+
}));
|
|
441383
|
+
signal.addEventListener("abort", done, { once: true });
|
|
441384
|
+
if (signal.aborted)
|
|
441385
|
+
done();
|
|
441386
|
+
});
|
|
441387
|
+
}
|
|
441388
|
+
}
|
|
441389
|
+
}
|
|
441390
|
+
var init_recovery_read = __esm(() => {
|
|
441391
|
+
init_error();
|
|
441392
|
+
init_turn_recovery_policy();
|
|
441393
|
+
init_constants3();
|
|
441394
|
+
});
|
|
441395
|
+
|
|
440967
441396
|
// src/websocket/listener/skill-injection.ts
|
|
440968
441397
|
function injectQueuedSkillContent(messages, context3) {
|
|
440969
441398
|
const skillContents = consumeQueuedSkillContent();
|
|
@@ -441129,7 +441558,7 @@ async function tryResumeBusyConversationStream(params) {
|
|
|
441129
441558
|
async function resolveStaleApprovals(runtime, socket, turnLease, deps = {}) {
|
|
441130
441559
|
if (!runtime.agentId && runtime.conversationId === "default")
|
|
441131
441560
|
return null;
|
|
441132
|
-
const getResumeDataImpl = deps.getResumeData ?? getResumeDataFromBackend;
|
|
441561
|
+
const getResumeDataImpl = (...args) => retryApprovalRecoveryRead(() => (deps.getResumeData ?? getResumeDataFromBackend)(...args), assertCurrentTurnLease, turnLease.signal);
|
|
441133
441562
|
const prepareToolExecutionContext = deps.prepareToolExecutionContext ?? prepareToolExecutionContextForScope;
|
|
441134
441563
|
const sendApprovalContinuation = deps.sendApprovalContinuation ?? sendApprovalContinuationWithRetry;
|
|
441135
441564
|
const drainRecoveryStream = deps.drainRecoveryStream ?? drainRecoveryStreamWithEmission;
|
|
@@ -441142,10 +441571,10 @@ async function resolveStaleApprovals(runtime, socket, turnLease, deps = {}) {
|
|
|
441142
441571
|
const backend3 = getBackend();
|
|
441143
441572
|
let agent;
|
|
441144
441573
|
try {
|
|
441145
|
-
agent = await retrieveResumeState(runtime.agentId, runtime.conversationId, {
|
|
441574
|
+
agent = await retryApprovalRecoveryRead(() => retrieveResumeState(runtime.agentId, runtime.conversationId, {
|
|
441146
441575
|
retrieveAgent: deps.retrieveAgent ?? backend3.retrieveAgent.bind(backend3),
|
|
441147
441576
|
retrieveConversation: deps.retrieveConversation ?? backend3.retrieveConversation.bind(backend3)
|
|
441148
|
-
});
|
|
441577
|
+
}), assertCurrentTurnLease, turnLease.signal);
|
|
441149
441578
|
} catch (err) {
|
|
441150
441579
|
assertCurrentTurnLease();
|
|
441151
441580
|
if (isBackendNotFoundError2(err)) {
|
|
@@ -441621,6 +442050,7 @@ var init_send = __esm(() => {
|
|
|
441621
442050
|
init_protocol_outbound();
|
|
441622
442051
|
init_recorded_tool_results();
|
|
441623
442052
|
init_recovery();
|
|
442053
|
+
init_recovery_read();
|
|
441624
442054
|
init_skill_injection();
|
|
441625
442055
|
init_turn_input_state();
|
|
441626
442056
|
init_turn_status();
|
|
@@ -444959,7 +445389,7 @@ async function runListenerTurnCleanup(params) {
|
|
|
444959
445389
|
await runPostTurnMemorySync({
|
|
444960
445390
|
conversationId,
|
|
444961
445391
|
agentId,
|
|
444962
|
-
isEnabled: (id) => settingsManager.isMemfsEnabled(id),
|
|
445392
|
+
isEnabled: (id) => !isMemoryUnavailable(id) && settingsManager.isMemfsEnabled(id),
|
|
444963
445393
|
debugLabel: "Post-turn listener memory sync",
|
|
444964
445394
|
onMemoryPushed: () => {
|
|
444965
445395
|
const transport3 = runtime.listener.transport ?? runtime.listener.socket;
|
|
@@ -444977,6 +445407,7 @@ async function runListenerTurnCleanup(params) {
|
|
|
444977
445407
|
var init_turn_cleanup = __esm(() => {
|
|
444978
445408
|
init_memory_git_sync();
|
|
444979
445409
|
init_settings_manager();
|
|
445410
|
+
init_memory_access();
|
|
444980
445411
|
init_channel_runtime_tools();
|
|
444981
445412
|
init_connection();
|
|
444982
445413
|
init_permission_mode();
|
|
@@ -449088,11 +449519,11 @@ import { randomUUID as randomUUID54 } from "node:crypto";
|
|
|
449088
449519
|
import { existsSync as existsSync62 } from "node:fs";
|
|
449089
449520
|
import { mkdir as mkdir13 } from "node:fs/promises";
|
|
449090
449521
|
import { dirname as dirname37, isAbsolute as isAbsolute26, join as join97, resolve as resolve37 } from "node:path";
|
|
449091
|
-
import { promisify as
|
|
449522
|
+
import { promisify as promisify18 } from "node:util";
|
|
449092
449523
|
async function runGit4(cwd2, args) {
|
|
449093
449524
|
try {
|
|
449094
449525
|
const allArgs = [...GIT_DISABLE_COMMIT_SIGNING_ARGS, ...args];
|
|
449095
|
-
const { stdout, stderr } = await
|
|
449526
|
+
const { stdout, stderr } = await execFile18("git", allArgs, {
|
|
449096
449527
|
cwd: cwd2,
|
|
449097
449528
|
env: {
|
|
449098
449529
|
...process.env,
|
|
@@ -449461,7 +449892,7 @@ async function finalizeReflectionMemoryWorktreeUnlocked(worktree, options) {
|
|
|
449461
449892
|
async function finalizeReflectionMemoryWorktree(worktree, options) {
|
|
449462
449893
|
return withMemoryOperation(worktree.parentMemoryDir, () => finalizeReflectionMemoryWorktreeUnlocked(worktree, options));
|
|
449463
449894
|
}
|
|
449464
|
-
var
|
|
449895
|
+
var execFile18, GIT_TIMEOUT_MS = 30000, HARNESS_GIT_ENV;
|
|
449465
449896
|
var init_memory_worktree = __esm(() => {
|
|
449466
449897
|
init_memory_auth();
|
|
449467
449898
|
init_memory_git();
|
|
@@ -449469,7 +449900,7 @@ var init_memory_worktree = __esm(() => {
|
|
|
449469
449900
|
init_memory_operation();
|
|
449470
449901
|
init_memfs_git_proxy();
|
|
449471
449902
|
init_debug();
|
|
449472
|
-
|
|
449903
|
+
execFile18 = promisify18(execFileCb3);
|
|
449473
449904
|
HARNESS_GIT_ENV = {
|
|
449474
449905
|
GIT_AUTHOR_NAME: "Letta Code",
|
|
449475
449906
|
GIT_AUTHOR_EMAIL: "noreply@letta.com",
|
|
@@ -451255,6 +451686,10 @@ async function prepareListenerTurn(params) {
|
|
|
451255
451686
|
excludeInteractiveTools: msg.excludeInteractiveTools
|
|
451256
451687
|
}, toolOwner.toolPolicy);
|
|
451257
451688
|
const preparedToolContext = await prepareToolExecutionContextForScope({
|
|
451689
|
+
readScopeState: (read2) => retryApprovalRecoveryRead(read2, () => {
|
|
451690
|
+
if (isInterrupted())
|
|
451691
|
+
throw new Error("Cancelled by user");
|
|
451692
|
+
}, turnLease.signal),
|
|
451258
451693
|
connectionId: executionConnectionId,
|
|
451259
451694
|
environmentDeviceId,
|
|
451260
451695
|
agentId,
|
|
@@ -451355,6 +451790,7 @@ var init_turn_setup = __esm(() => {
|
|
|
451355
451790
|
init_image_policy();
|
|
451356
451791
|
init_interrupts();
|
|
451357
451792
|
init_mod_adapter2();
|
|
451793
|
+
init_recovery_read();
|
|
451358
451794
|
init_runtime6();
|
|
451359
451795
|
init_turn_events();
|
|
451360
451796
|
init_turn_input_state();
|
|
@@ -452602,7 +453038,7 @@ var init_inbound_dispatch = __esm(() => {
|
|
|
452602
453038
|
});
|
|
452603
453039
|
|
|
452604
453040
|
// src/utils/machine-metadata.ts
|
|
452605
|
-
import { execFile as
|
|
453041
|
+
import { execFile as execFile19 } from "node:child_process";
|
|
452606
453042
|
import { readFile as readFile25 } from "node:fs/promises";
|
|
452607
453043
|
import { cpus, totalmem } from "node:os";
|
|
452608
453044
|
function getMachineMetadata() {
|
|
@@ -452620,7 +453056,7 @@ function localSources() {
|
|
|
452620
453056
|
memoryBytes: Math.min(totalmem(), limit4 || Number.POSITIVE_INFINITY),
|
|
452621
453057
|
read: (path41, signal) => readFile25(path41, { encoding: "utf8", signal }),
|
|
452622
453058
|
run: (command, args, signal) => new Promise((resolve38, reject2) => {
|
|
452623
|
-
|
|
453059
|
+
execFile19(command, args, {
|
|
452624
453060
|
encoding: "utf8",
|
|
452625
453061
|
signal,
|
|
452626
453062
|
killSignal: "SIGKILL",
|
|
@@ -453281,7 +453717,6 @@ async function completeInitialConnectionStartup(listener, connection, transport3
|
|
|
453281
453717
|
async function replaySubscribedConnectionState(listener, transport3, runtime, scope, options = {}) {
|
|
453282
453718
|
const connection = findListenerConnectionByTransport(listener, transport3);
|
|
453283
453719
|
const isCurrent = () => !connection || listener.connections.get(connection.id) === connection && (connection.writer === transport3 || connection.streamWriter === transport3) && !connection.cancellation.signal.aborted;
|
|
453284
|
-
await (options.refreshGitContext ?? refreshDeviceGitContext)(listener, scope);
|
|
453285
453720
|
if (!isCurrent())
|
|
453286
453721
|
return;
|
|
453287
453722
|
if (connection) {
|
|
@@ -453293,12 +453728,28 @@ async function replaySubscribedConnectionState(listener, transport3, runtime, sc
|
|
|
453293
453728
|
if (!isCurrent())
|
|
453294
453729
|
return;
|
|
453295
453730
|
}
|
|
453731
|
+
const gitContextBefore = JSON.stringify(buildDeviceStatus(listener, scope).git_context);
|
|
453296
453732
|
emitStateSync(transport3, listener, scope, {
|
|
453297
453733
|
forceDeviceStatus: options.forceDeviceStatus,
|
|
453298
453734
|
...connection ? { routing: toListenerConnection(connection.id) } : {}
|
|
453299
453735
|
});
|
|
453736
|
+
(async () => {
|
|
453737
|
+
await (options.refreshGitContext ?? refreshDeviceGitContext)(listener, scope);
|
|
453738
|
+
if (!isCurrent())
|
|
453739
|
+
return;
|
|
453740
|
+
if (JSON.stringify(buildDeviceStatus(listener, scope).git_context) === gitContextBefore)
|
|
453741
|
+
return;
|
|
453742
|
+
emitDeviceStatusUpdate(transport3, listener, scope, connection ? toListenerConnection(connection.id) : undefined);
|
|
453743
|
+
})().catch((error4) => {
|
|
453744
|
+
trackBoundaryError({
|
|
453745
|
+
errorType: "listener_git_context_refresh_failed",
|
|
453746
|
+
error: error4,
|
|
453747
|
+
context: "listener_state_replay"
|
|
453748
|
+
});
|
|
453749
|
+
});
|
|
453300
453750
|
}
|
|
453301
453751
|
var init_connection_state_sync = __esm(() => {
|
|
453752
|
+
init_error_reporting();
|
|
453302
453753
|
init_approval();
|
|
453303
453754
|
init_connection();
|
|
453304
453755
|
init_protocol_outbound();
|
|
@@ -453664,7 +454115,7 @@ var init_control_inputs = __esm(() => {
|
|
|
453664
454115
|
});
|
|
453665
454116
|
|
|
453666
454117
|
// src/websocket/listener/grep-in-files.ts
|
|
453667
|
-
import { execFile as
|
|
454118
|
+
import { execFile as execFile20 } from "node:child_process";
|
|
453668
454119
|
import { createRequire as createRequire8 } from "node:module";
|
|
453669
454120
|
import * as path42 from "node:path";
|
|
453670
454121
|
import { fileURLToPath as fileURLToPath10 } from "node:url";
|
|
@@ -453720,7 +454171,7 @@ async function runGrepInFiles(args) {
|
|
|
453720
454171
|
}
|
|
453721
454172
|
function runRipgrep2(rgArgs) {
|
|
453722
454173
|
return new Promise((resolve38, reject2) => {
|
|
453723
|
-
const child =
|
|
454174
|
+
const child = execFile20(rgPath, rgArgs, {
|
|
453724
454175
|
maxBuffer: 50 * 1024 * 1024,
|
|
453725
454176
|
windowsHide: true
|
|
453726
454177
|
}, (error4, stdout, _stderr) => {
|
|
@@ -458867,8 +459318,8 @@ var init_cron3 = __esm(() => {
|
|
|
458867
459318
|
});
|
|
458868
459319
|
|
|
458869
459320
|
// src/websocket/listener/commands/git-branches.ts
|
|
458870
|
-
import { execFile as
|
|
458871
|
-
import { promisify as
|
|
459321
|
+
import { execFile as execFile21 } from "node:child_process";
|
|
459322
|
+
import { promisify as promisify19 } from "node:util";
|
|
458872
459323
|
function handleGitBranchCommand(parsed, context3) {
|
|
458873
459324
|
const { socket, runtime, safeSocketSend, runDetachedListenerTask: runDetachedListenerTask2 } = context3;
|
|
458874
459325
|
if (isSearchBranchesCommand(parsed)) {
|
|
@@ -458876,7 +459327,7 @@ function handleGitBranchCommand(parsed, context3) {
|
|
|
458876
459327
|
try {
|
|
458877
459328
|
const cwd2 = parsed.cwd ?? getBootWorkingDirectory(runtime);
|
|
458878
459329
|
const maxResults = parsed.max_results ?? 20;
|
|
458879
|
-
const execFileAsync12 =
|
|
459330
|
+
const execFileAsync12 = promisify19(execFile21);
|
|
458880
459331
|
const { stdout } = await execFileAsync12("git", ["branch", "-a", "--format=%(refname:short)\t%(HEAD)"], {
|
|
458881
459332
|
cwd: cwd2,
|
|
458882
459333
|
encoding: "utf-8",
|
|
@@ -458916,7 +459367,7 @@ function handleGitBranchCommand(parsed, context3) {
|
|
|
458916
459367
|
runDetachedListenerTask2("checkout_branch", async () => {
|
|
458917
459368
|
try {
|
|
458918
459369
|
const cwd2 = parsed.cwd ?? getBootWorkingDirectory(runtime);
|
|
458919
|
-
const execFileAsync12 =
|
|
459370
|
+
const execFileAsync12 = promisify19(execFile21);
|
|
458920
459371
|
const args = parsed.create ? ["checkout", "-b", parsed.branch] : ["checkout", parsed.branch];
|
|
458921
459372
|
await execFileAsync12("git", args, {
|
|
458922
459373
|
cwd: cwd2,
|
|
@@ -459225,8 +459676,8 @@ function handleMemoryProtocolCommand(parsed, context3) {
|
|
|
459225
459676
|
runDetachedListenerTask2("memory_history", async () => {
|
|
459226
459677
|
const { getScopedMemoryFilesystemRoot: getScopedMemoryFilesystemRoot2 } = await Promise.resolve().then(() => (init_memory_filesystem2(), exports_memory_filesystem));
|
|
459227
459678
|
const { execFile: execFileCb4 } = await import("node:child_process");
|
|
459228
|
-
const { promisify:
|
|
459229
|
-
const execFileAsync12 =
|
|
459679
|
+
const { promisify: promisify20 } = await import("node:util");
|
|
459680
|
+
const execFileAsync12 = promisify20(execFileCb4);
|
|
459230
459681
|
const memoryRoot = getScopedMemoryFilesystemRoot2(parsed.agent_id);
|
|
459231
459682
|
const limit4 = parsed.limit ?? 50;
|
|
459232
459683
|
const gitArgs = ["log", `--max-count=${limit4}`, "--format=%H|%s|%aI|%an"];
|
|
@@ -459261,8 +459712,8 @@ function handleMemoryProtocolCommand(parsed, context3) {
|
|
|
459261
459712
|
runDetachedListenerTask2("memory_file_at_ref", async () => {
|
|
459262
459713
|
const { getScopedMemoryFilesystemRoot: getScopedMemoryFilesystemRoot2 } = await Promise.resolve().then(() => (init_memory_filesystem2(), exports_memory_filesystem));
|
|
459263
459714
|
const { execFile: execFileCb4 } = await import("node:child_process");
|
|
459264
|
-
const { promisify:
|
|
459265
|
-
const execFileAsync12 =
|
|
459715
|
+
const { promisify: promisify20 } = await import("node:util");
|
|
459716
|
+
const execFileAsync12 = promisify20(execFileCb4);
|
|
459266
459717
|
const memoryRoot = getScopedMemoryFilesystemRoot2(parsed.agent_id);
|
|
459267
459718
|
try {
|
|
459268
459719
|
const { stdout } = await execFileAsync12("git", ["show", `${parsed.ref}:${parsed.file_path}`], { cwd: memoryRoot, timeout: 1e4 });
|
|
@@ -459292,8 +459743,8 @@ function handleMemoryProtocolCommand(parsed, context3) {
|
|
|
459292
459743
|
runDetachedListenerTask2("memory_commit_diff", async () => {
|
|
459293
459744
|
const { getScopedMemoryFilesystemRoot: getScopedMemoryFilesystemRoot2 } = await Promise.resolve().then(() => (init_memory_filesystem2(), exports_memory_filesystem));
|
|
459294
459745
|
const { execFile: execFileCb4 } = await import("node:child_process");
|
|
459295
|
-
const { promisify:
|
|
459296
|
-
const execFileAsync12 =
|
|
459746
|
+
const { promisify: promisify20 } = await import("node:util");
|
|
459747
|
+
const execFileAsync12 = promisify20(execFileCb4);
|
|
459297
459748
|
const memoryRoot = getScopedMemoryFilesystemRoot2(parsed.agent_id);
|
|
459298
459749
|
try {
|
|
459299
459750
|
const { stdout } = await execFileAsync12("git", ["show", parsed.sha, "--format=", "--no-color"], { cwd: memoryRoot, timeout: 1e4 });
|
|
@@ -459618,12 +460069,14 @@ var init_memory5 = __esm(() => {
|
|
|
459618
460069
|
function createMemfsSyncedTaskRunner(parsed, runtime, runDetachedListenerTask2) {
|
|
459619
460070
|
const command = parsed;
|
|
459620
460071
|
const agentId = command.agent_id;
|
|
459621
|
-
if (typeof agentId !== "string" || command.type === "enable_memfs") {
|
|
460072
|
+
if (typeof agentId !== "string" || command.type === "enable_memfs" && !isMemoryUnavailable(agentId)) {
|
|
459622
460073
|
return runDetachedListenerTask2;
|
|
459623
460074
|
}
|
|
459624
460075
|
return (commandName, task2) => {
|
|
459625
460076
|
runDetachedListenerTask2(commandName, async () => {
|
|
459626
|
-
await ensureMemfsSyncedForAgent(runtime, agentId)
|
|
460077
|
+
if (!await ensureMemfsSyncedForAgent(runtime, agentId)) {
|
|
460078
|
+
throw new Error("Memory is not available on this machine.");
|
|
460079
|
+
}
|
|
459627
460080
|
await task2();
|
|
459628
460081
|
});
|
|
459629
460082
|
};
|
|
@@ -459636,6 +460089,7 @@ function handleMemfsSyncedMemoryProtocolCommand(parsed, context3) {
|
|
|
459636
460089
|
});
|
|
459637
460090
|
}
|
|
459638
460091
|
var init_memory_command_sync = __esm(() => {
|
|
460092
|
+
init_memory_access();
|
|
459639
460093
|
init_memfs_sync();
|
|
459640
460094
|
init_memory5();
|
|
459641
460095
|
});
|
|
@@ -460812,10 +461266,20 @@ async function handleRuntimeStartCommand(parsed, context3) {
|
|
|
460812
461266
|
let startResponseSent = false;
|
|
460813
461267
|
try {
|
|
460814
461268
|
validateRuntimeStartShape(parsed);
|
|
460815
|
-
agent = await resolveRuntimeStartAgent(parsed, created);
|
|
460816
461269
|
const backend3 = getBackend();
|
|
460817
461270
|
const createEphemeral = context3.createEphemeralConversation ?? backend3.createEphemeralConversation?.bind(backend3) ?? createEphemeralConversation;
|
|
460818
|
-
|
|
461271
|
+
const retrieveConversation = context3.retrieveConversation ?? ((id) => backend3.retrieveConversation(id));
|
|
461272
|
+
let retrievedConversation;
|
|
461273
|
+
if (hasString(parsed.conversation_id) && parsed.conversation_id !== "default") {
|
|
461274
|
+
[agent, retrievedConversation] = await Promise.all([
|
|
461275
|
+
resolveRuntimeStartAgent(parsed, created),
|
|
461276
|
+
retrieveConversation(parsed.conversation_id)
|
|
461277
|
+
]);
|
|
461278
|
+
} else {
|
|
461279
|
+
agent = await resolveRuntimeStartAgent(parsed, created);
|
|
461280
|
+
}
|
|
461281
|
+
const cachedConversation = retrievedConversation;
|
|
461282
|
+
conversation = await resolveRuntimeStartConversation(parsed, agent, created, createEphemeral, cachedConversation ? async () => cachedConversation : retrieveConversation);
|
|
460819
461283
|
conversation = await applyRuntimeStartConversationSourceTags(parsed, conversation);
|
|
460820
461284
|
runtimeScope = buildRuntimeScope(agent, conversation);
|
|
460821
461285
|
const { connectionId } = context3;
|
|
@@ -462146,6 +462610,12 @@ async function stopMonitor(command) {
|
|
|
462146
462610
|
return { ...response, success: true };
|
|
462147
462611
|
if (!killBackgroundProcess(command.process_id))
|
|
462148
462612
|
return { ...response, error: "Monitor could not be stopped" };
|
|
462613
|
+
let persistenceError;
|
|
462614
|
+
try {
|
|
462615
|
+
await process21.persistState?.();
|
|
462616
|
+
} catch {
|
|
462617
|
+
persistenceError = "Monitor stopped, but its server state could not be saved";
|
|
462618
|
+
}
|
|
462149
462619
|
addToMessageQueue({
|
|
462150
462620
|
kind: "task_notification",
|
|
462151
462621
|
agentId: command.runtime.agent_id,
|
|
@@ -462156,7 +462626,12 @@ async function stopMonitor(command) {
|
|
|
462156
462626
|
event: "The user cancelled this Monitor. Do not restart it unless the user asks."
|
|
462157
462627
|
})
|
|
462158
462628
|
});
|
|
462159
|
-
return {
|
|
462629
|
+
return {
|
|
462630
|
+
...response,
|
|
462631
|
+
success: !persistenceError,
|
|
462632
|
+
stopped: true,
|
|
462633
|
+
...persistenceError ? { error: persistenceError } : {}
|
|
462634
|
+
};
|
|
462160
462635
|
}
|
|
462161
462636
|
var init_stop_monitor = __esm(() => {
|
|
462162
462637
|
init_message_queue_bridge();
|
|
@@ -462180,7 +462655,7 @@ async function handleMonitorStopCommand(command, runtime) {
|
|
|
462180
462655
|
}
|
|
462181
462656
|
return stopMonitor(command);
|
|
462182
462657
|
}
|
|
462183
|
-
var
|
|
462658
|
+
var init_monitors2 = __esm(() => {
|
|
462184
462659
|
init_stop_monitor();
|
|
462185
462660
|
init_runtime6();
|
|
462186
462661
|
});
|
|
@@ -462200,19 +462675,25 @@ function finishUntrackedNativeCapture2(completion, reservation, source, sessionI
|
|
|
462200
462675
|
completion.then(() => reservation.capture(), () => reservation.capture()).catch((error4) => reportNativeSessionCaptureFailure(source, sessionId, error4));
|
|
462201
462676
|
}
|
|
462202
462677
|
function findOwnedTask(runtime, agentId) {
|
|
462203
|
-
const subagent = getSubagents().find((entry) => entry.agentId === agentId && entry.parentAgentId === runtime.agentId
|
|
462678
|
+
const subagent = getSubagents().find((entry) => entry.agentId === agentId && entry.parentAgentId === runtime.agentId);
|
|
462204
462679
|
if (!subagent)
|
|
462205
462680
|
return;
|
|
462206
462681
|
return [...backgroundTasks.entries()].find(([, task2]) => task2.subagentId === subagent.id);
|
|
462207
462682
|
}
|
|
462208
|
-
function
|
|
462683
|
+
function nativeSessionOwner(agentId) {
|
|
462209
462684
|
const target = parseExternalCodingAgentId(agentId);
|
|
462210
462685
|
if (!target || target.computer)
|
|
462211
|
-
return
|
|
462686
|
+
return;
|
|
462212
462687
|
if (target.type !== "claude-code" && target.type !== "codex")
|
|
462213
|
-
return
|
|
462214
|
-
|
|
462215
|
-
|
|
462688
|
+
return;
|
|
462689
|
+
return getNativeSessionOwner(target.type === "claude-code" ? "claude_code" : "codex", target.sessionId);
|
|
462690
|
+
}
|
|
462691
|
+
function ownsNativeSession(runtime, agentId) {
|
|
462692
|
+
return nativeSessionOwner(agentId)?.agentId === runtime.agentId;
|
|
462693
|
+
}
|
|
462694
|
+
function subagentAccessError(agentId) {
|
|
462695
|
+
const known = getSubagents().some((entry) => entry.agentId === agentId) || nativeSessionOwner(agentId);
|
|
462696
|
+
return known ? "Subagent does not belong to this conversation" : `Subagent ${agentId} was not found on this computer`;
|
|
462216
462697
|
}
|
|
462217
462698
|
function runtimeContext(parent, command) {
|
|
462218
462699
|
return {
|
|
@@ -462246,7 +462727,7 @@ async function handleSubagentMessageCommand(command, parent, deps = {}) {
|
|
|
462246
462727
|
if (parent.agentId !== command.runtime.agent_id || parent.conversationId !== command.runtime.conversation_id)
|
|
462247
462728
|
throw new Error("Parent runtime does not match the message request");
|
|
462248
462729
|
if (!findOwnedTask(parent, command.agent_id) && !ownsNativeSession(parent, command.agent_id))
|
|
462249
|
-
throw new Error(
|
|
462730
|
+
throw new Error(subagentAccessError(command.agent_id));
|
|
462250
462731
|
const target = parseExternalCodingAgentId(command.agent_id);
|
|
462251
462732
|
if (!target || target.computer || !isExternalCodingAgentType(target.type))
|
|
462252
462733
|
throw new Error("Invalid external coding agent ID");
|
|
@@ -462399,7 +462880,7 @@ async function handleSubagentStopCommand(command, parent) {
|
|
|
462399
462880
|
stopped: nativeStopped,
|
|
462400
462881
|
cleanup_confirmed: true
|
|
462401
462882
|
};
|
|
462402
|
-
return { ...base2, error:
|
|
462883
|
+
return { ...base2, error: subagentAccessError(command.agent_id) };
|
|
462403
462884
|
}
|
|
462404
462885
|
const [taskId, task2] = owned;
|
|
462405
462886
|
if (task2.status !== "running")
|
|
@@ -462440,7 +462921,7 @@ function handleReadSubagentEventsCommand(command) {
|
|
|
462440
462921
|
subagent_id: command.subagent_id
|
|
462441
462922
|
};
|
|
462442
462923
|
const subagent = getSubagents().find((entry) => entry.id === command.subagent_id);
|
|
462443
|
-
if (!subagent || subagent.parentAgentId !== command.runtime.agent_id
|
|
462924
|
+
if (!subagent || subagent.parentAgentId !== command.runtime.agent_id)
|
|
462444
462925
|
return {
|
|
462445
462926
|
...base2,
|
|
462446
462927
|
success: false,
|
|
@@ -462572,7 +463053,7 @@ async function handleTaskControlCommand(command, context3) {
|
|
|
462572
463053
|
}
|
|
462573
463054
|
}
|
|
462574
463055
|
var init_task_control = __esm(() => {
|
|
462575
|
-
|
|
463056
|
+
init_monitors2();
|
|
462576
463057
|
init_stop_conversation();
|
|
462577
463058
|
init_subagent_control();
|
|
462578
463059
|
init_subagent_events2();
|
|
@@ -467986,6 +468467,7 @@ async function runListenSubcommand(argv, appServer) {
|
|
|
467986
468467
|
}
|
|
467987
468468
|
} catch {}
|
|
467988
468469
|
await cancelBackgroundMemoryTasks();
|
|
468470
|
+
await shutdownMonitors();
|
|
467989
468471
|
await flushRemoteSettingsWrites();
|
|
467990
468472
|
await releaseManualListenerLock();
|
|
467991
468473
|
await flushListenerTelemetryEnd(`listener_${signal.toLowerCase()}`);
|
|
@@ -467999,6 +468481,7 @@ async function runListenSubcommand(argv, appServer) {
|
|
|
467999
468481
|
await closeChannelGateway();
|
|
468000
468482
|
} catch {}
|
|
468001
468483
|
await cancelBackgroundMemoryTasks();
|
|
468484
|
+
await shutdownMonitors();
|
|
468002
468485
|
await flushRemoteSettingsWrites();
|
|
468003
468486
|
await releaseManualListenerLock();
|
|
468004
468487
|
await flushListenerTelemetryEnd(exitReason);
|
|
@@ -468502,6 +468985,7 @@ var init_listen = __esm(async () => {
|
|
|
468502
468985
|
init_settings_manager();
|
|
468503
468986
|
init_telemetry();
|
|
468504
468987
|
init_memory_task_lifecycle();
|
|
468988
|
+
init_monitor();
|
|
468505
468989
|
init_service_protocol();
|
|
468506
468990
|
init_debug();
|
|
468507
468991
|
init_startup_log_boundary();
|
|
@@ -469213,10 +469697,10 @@ async function runMemorySubcommand(argv, deps = {}) {
|
|
|
469213
469697
|
return 1;
|
|
469214
469698
|
}
|
|
469215
469699
|
const { execFile: execFileCb4 } = await import("node:child_process");
|
|
469216
|
-
const { promisify:
|
|
469217
|
-
const
|
|
469700
|
+
const { promisify: promisify20 } = await import("node:util");
|
|
469701
|
+
const execFile22 = promisify20(execFileCb4);
|
|
469218
469702
|
const dir = getScopedMemoryFilesystemRoot(agentId);
|
|
469219
|
-
const { stdout } = await
|
|
469703
|
+
const { stdout } = await execFile22("git", ["diff"], { cwd: dir });
|
|
469220
469704
|
if (stdout.trim()) {
|
|
469221
469705
|
console.log(stdout);
|
|
469222
469706
|
return 2;
|
|
@@ -475379,15 +475863,15 @@ function resolveSkillSourceSpecifier(input) {
|
|
|
475379
475863
|
}
|
|
475380
475864
|
return null;
|
|
475381
475865
|
}
|
|
475382
|
-
async function
|
|
475866
|
+
async function execFile22(command, args, options = {}) {
|
|
475383
475867
|
const { execFile: execFileCb4 } = await import("node:child_process");
|
|
475384
|
-
const { promisify:
|
|
475385
|
-
return
|
|
475868
|
+
const { promisify: promisify20 } = await import("node:util");
|
|
475869
|
+
return promisify20(execFileCb4)(command, args, options);
|
|
475386
475870
|
}
|
|
475387
475871
|
async function resolveBranchAndSubdir(location) {
|
|
475388
475872
|
if (!location.subdir)
|
|
475389
475873
|
return location;
|
|
475390
|
-
const { stdout } = await
|
|
475874
|
+
const { stdout } = await execFile22("git", ["ls-remote", "--heads", location.repoUrl], {
|
|
475391
475875
|
timeout: 60000
|
|
475392
475876
|
});
|
|
475393
475877
|
const branches = stdout.split(`
|
|
@@ -475414,7 +475898,7 @@ async function cloneSkillSource(location) {
|
|
|
475414
475898
|
args.push("--branch", resolvedLocation.branch);
|
|
475415
475899
|
}
|
|
475416
475900
|
args.push(resolvedLocation.repoUrl, tmpDir);
|
|
475417
|
-
await
|
|
475901
|
+
await execFile22("git", args, { timeout: 120000 });
|
|
475418
475902
|
const sourceDir = resolvedLocation.subdir ? join107(tmpDir, resolvedLocation.subdir) : tmpDir;
|
|
475419
475903
|
return { tmpDir, sourceDir };
|
|
475420
475904
|
}
|
|
@@ -475527,7 +476011,7 @@ async function downloadClawHubSkillSource(location) {
|
|
|
475527
476011
|
throw new Error(`ClawHub download failed for ${location.slug}@${version3}: ${response.status}`);
|
|
475528
476012
|
}
|
|
475529
476013
|
writeFileSync47(zipPath, Buffer.from(await response.arrayBuffer()));
|
|
475530
|
-
const { stdout } = await
|
|
476014
|
+
const { stdout } = await execFile22("unzip", ["-Z1", zipPath], {
|
|
475531
476015
|
timeout: 30000
|
|
475532
476016
|
});
|
|
475533
476017
|
const members = stdout.split(`
|
|
@@ -475536,7 +476020,7 @@ async function downloadClawHubSkillSource(location) {
|
|
|
475536
476020
|
throw new Error(`ClawHub download was empty for ${location.slug}@${version3}`);
|
|
475537
476021
|
}
|
|
475538
476022
|
members.forEach(assertSafeZipMember);
|
|
475539
|
-
await
|
|
476023
|
+
await execFile22("unzip", ["-q", zipPath, "-d", sourceDir], {
|
|
475540
476024
|
timeout: 30000
|
|
475541
476025
|
});
|
|
475542
476026
|
return { tmpDir, sourceDir };
|
|
@@ -483487,6 +483971,7 @@ async function sendScopedApprovalMessages(params) {
|
|
|
483487
483971
|
});
|
|
483488
483972
|
}
|
|
483489
483973
|
async function flushAndExit(code) {
|
|
483974
|
+
await shutdownMonitors();
|
|
483490
483975
|
const flushWritable = (stream11) => new Promise((resolve41) => {
|
|
483491
483976
|
if (stream11.destroyed || stream11.writableEnded)
|
|
483492
483977
|
return resolve41();
|
|
@@ -486358,6 +486843,7 @@ var init_headless = __esm(() => {
|
|
|
486358
486843
|
init_runtime_execution_settings();
|
|
486359
486844
|
init_settings_manager();
|
|
486360
486845
|
init_memory_task_lifecycle();
|
|
486846
|
+
init_monitor();
|
|
486361
486847
|
init_manager2();
|
|
486362
486848
|
init_toolset();
|
|
486363
486849
|
init_debug();
|
|
@@ -487657,7 +488143,7 @@ import { existsSync as existsSync75 } from "node:fs";
|
|
|
487657
488143
|
import { appendFile as appendFile3, chmod, mkdir as mkdir18, writeFile as writeFile21 } from "node:fs/promises";
|
|
487658
488144
|
import { homedir as homedir34 } from "node:os";
|
|
487659
488145
|
import { join as join113 } from "node:path";
|
|
487660
|
-
import { promisify as
|
|
488146
|
+
import { promisify as promisify20 } from "node:util";
|
|
487661
488147
|
function getReflectionArenaHfCacheRoot(env6 = process.env, fallbackHome = homedir34()) {
|
|
487662
488148
|
return join113(resolveGlobalConfigDir(env6, fallbackHome), "reflection-arena", "hf-upload");
|
|
487663
488149
|
}
|
|
@@ -487683,7 +488169,7 @@ function formatTokenStatus(token2) {
|
|
|
487683
488169
|
}
|
|
487684
488170
|
async function runGit6(cwd2, args, env6) {
|
|
487685
488171
|
try {
|
|
487686
|
-
await
|
|
488172
|
+
await execFile23("git", args, {
|
|
487687
488173
|
cwd: cwd2,
|
|
487688
488174
|
env: env6,
|
|
487689
488175
|
encoding: "utf-8",
|
|
@@ -487768,12 +488254,12 @@ async function maybeUploadReflectionArenaChoiceToHf(row) {
|
|
|
487768
488254
|
};
|
|
487769
488255
|
}
|
|
487770
488256
|
}
|
|
487771
|
-
var
|
|
488257
|
+
var execFile23, HF_REPO_ID = "letta-ai/reflection-arena", HF_REPO_URL, GIT_TIMEOUT_MS2 = 60000, HF_CACHE_ROOT, HF_REPO_DIR, HF_DATASET_PATH = "data/choices.jsonl";
|
|
487772
488258
|
var init_reflection_arena_hf_upload = __esm(() => {
|
|
487773
488259
|
init_secrets_store();
|
|
487774
488260
|
init_settings_path();
|
|
487775
488261
|
init_version();
|
|
487776
|
-
|
|
488262
|
+
execFile23 = promisify20(execFileCb4);
|
|
487777
488263
|
HF_REPO_URL = `https://huggingface.co/datasets/${HF_REPO_ID}`;
|
|
487778
488264
|
HF_CACHE_ROOT = getReflectionArenaHfCacheRoot();
|
|
487779
488265
|
HF_REPO_DIR = join113(HF_CACHE_ROOT, "repo");
|
|
@@ -487784,7 +488270,7 @@ import { execFile as execFileCb5 } from "node:child_process";
|
|
|
487784
488270
|
import { randomInt as randomInt2, randomUUID as randomUUID67 } from "node:crypto";
|
|
487785
488271
|
import { appendFile as appendFile4, mkdir as mkdir19, readFile as readFile34, writeFile as writeFile22 } from "node:fs/promises";
|
|
487786
488272
|
import { join as join114 } from "node:path";
|
|
487787
|
-
import { promisify as
|
|
488273
|
+
import { promisify as promisify21 } from "node:util";
|
|
487788
488274
|
function sampleReflectionArenaComparisonModel(excludedModels = []) {
|
|
487789
488275
|
const excluded = new Set(excludedModels);
|
|
487790
488276
|
const candidates = REFLECTION_ARENA_COMPARISON_MODEL_POOL.filter((entry) => !excluded.has(entry.model));
|
|
@@ -487801,7 +488287,7 @@ function sampleReflectionArenaComparisonModel(excludedModels = []) {
|
|
|
487801
488287
|
}
|
|
487802
488288
|
async function getGitOutput(cwd2, args) {
|
|
487803
488289
|
try {
|
|
487804
|
-
const { stdout } = await
|
|
488290
|
+
const { stdout } = await execFile24("git", args, {
|
|
487805
488291
|
cwd: cwd2,
|
|
487806
488292
|
encoding: "utf-8",
|
|
487807
488293
|
timeout: 30000,
|
|
@@ -488357,7 +488843,7 @@ async function finalizeReflectionArenaChoice(options) {
|
|
|
488357
488843
|
run: completedRun
|
|
488358
488844
|
};
|
|
488359
488845
|
}
|
|
488360
|
-
var
|
|
488846
|
+
var execFile24, REFLECTION_ARENA_TELEMETRY_TRANSCRIPT_MAX_CHARS = 1e6, REFLECTION_ARENA_MODEL_A_DEFAULT = "letta/auto-memory", REFLECTION_ARENA_COMPARISON_FALLBACK_MODEL = "lc-anthropic/claude-sonnet-5", REFLECTION_ARENA_COMPARISON_MODEL_POOL, ANSI_BOLD = "\x1B[1m", ANSI_CYAN = "\x1B[36m", ANSI_MAGENTA = "\x1B[35m", ANSI_RESET_BOLD = "\x1B[22m", ANSI_RESET_FOREGROUND = "\x1B[39m", REFLECTION_ARENA_CANDIDATE_COUNT = 2, REFLECTION_ARENA_CHOICE_QUESTION = "Which reflection should be merged?", REFLECTION_ARENA_NOTES_QUESTION = "Optional feedback for this choice?", updateLocks;
|
|
488361
488847
|
var init_reflection_arena = __esm(() => {
|
|
488362
488848
|
init_memory_worktree();
|
|
488363
488849
|
init_app_urls();
|
|
@@ -488368,7 +488854,7 @@ var init_reflection_arena = __esm(() => {
|
|
|
488368
488854
|
init_telemetry();
|
|
488369
488855
|
init_debug();
|
|
488370
488856
|
init_settings_path();
|
|
488371
|
-
|
|
488857
|
+
execFile24 = promisify21(execFileCb5);
|
|
488372
488858
|
REFLECTION_ARENA_COMPARISON_MODEL_POOL = [
|
|
488373
488859
|
{ model: "lc-anthropic/claude-sonnet-5", weight: 1 },
|
|
488374
488860
|
{ model: "lc-anthropic/claude-opus-4-8", weight: 3 },
|
|
@@ -504769,7 +505255,7 @@ __export(exports_generate_memory_viewer, {
|
|
|
504769
505255
|
import { execFile as execFileCb6 } from "node:child_process";
|
|
504770
505256
|
import { chmodSync as chmodSync11, existsSync as existsSync78, mkdirSync as mkdirSync60, writeFileSync as writeFileSync52 } from "node:fs";
|
|
504771
505257
|
import { join as join118 } from "node:path";
|
|
504772
|
-
import { promisify as
|
|
505258
|
+
import { promisify as promisify22 } from "node:util";
|
|
504773
505259
|
function messagesFromOverview(overview) {
|
|
504774
505260
|
return overview.messages?.map((message2) => ({
|
|
504775
505261
|
id: message2.id,
|
|
@@ -504796,7 +505282,7 @@ function contextFromOverview(overview, model2, contextWindow) {
|
|
|
504796
505282
|
}
|
|
504797
505283
|
async function runGitSafe(cwd2, args) {
|
|
504798
505284
|
try {
|
|
504799
|
-
const { stdout } = await
|
|
505285
|
+
const { stdout } = await execFile25("git", args, {
|
|
504800
505286
|
cwd: cwd2,
|
|
504801
505287
|
maxBuffer: 10 * 1024 * 1024,
|
|
504802
505288
|
timeout: 60000
|
|
@@ -505108,7 +505594,7 @@ async function generateAndOpenMemoryViewer(agentId, options) {
|
|
|
505108
505594
|
}
|
|
505109
505595
|
return { filePath, opened: !skipOpen };
|
|
505110
505596
|
}
|
|
505111
|
-
var
|
|
505597
|
+
var execFile25, VIEWERS_DIR, MAX_COMMITS = 500, RECENT_DIFF_COUNT = 50, PER_DIFF_CAP = 1e5, TOTAL_PAYLOAD_CAP = 5000000, RECORD_SEP = "\x1E", REFLECTION_PATTERN;
|
|
505112
505598
|
var init_generate_memory_viewer = __esm(() => {
|
|
505113
505599
|
init_memory_filesystem2();
|
|
505114
505600
|
init_memory_format();
|
|
@@ -505121,7 +505607,7 @@ var init_generate_memory_viewer = __esm(() => {
|
|
|
505121
505607
|
init_context_usage();
|
|
505122
505608
|
init_local_memory_context();
|
|
505123
505609
|
init_memory_viewer_template();
|
|
505124
|
-
|
|
505610
|
+
execFile25 = promisify22(execFileCb6);
|
|
505125
505611
|
VIEWERS_DIR = join118(resolveGlobalConfigDir(), "viewers");
|
|
505126
505612
|
REFLECTION_PATTERN = /\(reflection\)|🔮|reflection:/i;
|
|
505127
505613
|
});
|
|
@@ -515793,10 +516279,10 @@ __export(exports_generate_diff_viewer, {
|
|
|
515793
516279
|
import { execFile as execFileCb7 } from "node:child_process";
|
|
515794
516280
|
import { chmodSync as chmodSync12, existsSync as existsSync80, mkdirSync as mkdirSync61, writeFileSync as writeFileSync53 } from "node:fs";
|
|
515795
516281
|
import { isAbsolute as isAbsolute28, join as join122, resolve as resolve42 } from "node:path";
|
|
515796
|
-
import { promisify as
|
|
516282
|
+
import { promisify as promisify23 } from "node:util";
|
|
515797
516283
|
async function runGit8(cwd2, args) {
|
|
515798
516284
|
try {
|
|
515799
|
-
const { stdout } = await
|
|
516285
|
+
const { stdout } = await execFile26("git", args, {
|
|
515800
516286
|
cwd: cwd2,
|
|
515801
516287
|
maxBuffer: GIT_MAX_BUFFER,
|
|
515802
516288
|
timeout: GIT_TIMEOUT_MS3
|
|
@@ -516035,7 +516521,7 @@ async function generateAndOpenDiffViewer(targetPath) {
|
|
|
516035
516521
|
}
|
|
516036
516522
|
return { filePath, opened: !skipOpen, fileCount: rendered.files.length };
|
|
516037
516523
|
}
|
|
516038
|
-
var
|
|
516524
|
+
var execFile26, VIEWERS_DIR2, GIT_TIMEOUT_MS3 = 60000, GIT_MAX_BUFFER, MAX_RENDERED_FILES = 100, DIFF_UNSAFE_CSS = `
|
|
516039
516525
|
:host {
|
|
516040
516526
|
--diffs-addition-color-override: #15803d;
|
|
516041
516527
|
--diffs-deletion-color-override: #b91c1c;
|
|
@@ -516090,7 +516576,7 @@ var execFile25, VIEWERS_DIR2, GIT_TIMEOUT_MS3 = 60000, GIT_MAX_BUFFER, MAX_RENDE
|
|
|
516090
516576
|
var init_generate_diff_viewer = __esm(() => {
|
|
516091
516577
|
init_settings_path();
|
|
516092
516578
|
init_diff_viewer_template();
|
|
516093
|
-
|
|
516579
|
+
execFile26 = promisify23(execFileCb7);
|
|
516094
516580
|
VIEWERS_DIR2 = join122(resolveGlobalConfigDir(), "viewers");
|
|
516095
516581
|
GIT_MAX_BUFFER = 50 * 1024 * 1024;
|
|
516096
516582
|
});
|
|
@@ -517286,11 +517772,13 @@ function saveLastSessionBeforeExit(conversationId) {
|
|
|
517286
517772
|
async function prepareSessionExit(conversationId) {
|
|
517287
517773
|
saveLastSessionBeforeExit(conversationId);
|
|
517288
517774
|
await cancelBackgroundMemoryTasks();
|
|
517775
|
+
await shutdownMonitors();
|
|
517289
517776
|
}
|
|
517290
517777
|
var init_session3 = __esm(() => {
|
|
517291
517778
|
init_context();
|
|
517292
517779
|
init_settings_manager();
|
|
517293
517780
|
init_memory_task_lifecycle();
|
|
517781
|
+
init_monitor();
|
|
517294
517782
|
});
|
|
517295
517783
|
|
|
517296
517784
|
// src/cli/app/use-agent-mcp-servers.ts
|
|
@@ -526127,10 +526615,10 @@ __export(exports_worktree_diff_list, {
|
|
|
526127
526615
|
});
|
|
526128
526616
|
import { execFile as execFileCb8 } from "node:child_process";
|
|
526129
526617
|
import { basename as basename34 } from "node:path";
|
|
526130
|
-
import { promisify as
|
|
526618
|
+
import { promisify as promisify24 } from "node:util";
|
|
526131
526619
|
async function runGit9(cwd2, args) {
|
|
526132
526620
|
try {
|
|
526133
|
-
const { stdout } = await
|
|
526621
|
+
const { stdout } = await execFile27("git", args, {
|
|
526134
526622
|
cwd: cwd2,
|
|
526135
526623
|
maxBuffer: GIT_MAX_BUFFER2,
|
|
526136
526624
|
timeout: GIT_TIMEOUT_MS4
|
|
@@ -526259,9 +526747,9 @@ async function listWorktreeDiffOptions(cwd2 = process.cwd()) {
|
|
|
526259
526747
|
const worktrees = parseWorktreeList(output, currentPath);
|
|
526260
526748
|
return Promise.all(worktrees.map((worktree) => summarizeWorktree(worktree)));
|
|
526261
526749
|
}
|
|
526262
|
-
var
|
|
526750
|
+
var execFile27, GIT_TIMEOUT_MS4 = 60000, GIT_MAX_BUFFER2;
|
|
526263
526751
|
var init_worktree_diff_list = __esm(() => {
|
|
526264
|
-
|
|
526752
|
+
execFile27 = promisify24(execFileCb8);
|
|
526265
526753
|
GIT_MAX_BUFFER2 = 10 * 1024 * 1024;
|
|
526266
526754
|
});
|
|
526267
526755
|
|
|
@@ -536215,4 +536703,4 @@ function registerBunOAuthFlows() {
|
|
|
536215
536703
|
registerBunOAuthFlows();
|
|
536216
536704
|
await init_src5().then(() => exports_src2);
|
|
536217
536705
|
|
|
536218
|
-
//# debugId=
|
|
536706
|
+
//# debugId=F2C2B5566F98148D64756E2164756E21
|