@letta-ai/letta-code 0.34.58 → 0.34.60
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 +1232 -709
- package/npm-shrinkwrap.json +5 -5
- package/package.json +2 -2
- package/skills/working-across-computers/references/connect-a-computer-for-remote-access.md +2 -25
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.60",
|
|
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.",
|
|
@@ -6422,7 +6422,7 @@ var init_package = __esm(() => {
|
|
|
6422
6422
|
},
|
|
6423
6423
|
lettaLifecycleProtocol: 1,
|
|
6424
6424
|
lettaRuntimeGraphProtocol: 1,
|
|
6425
|
-
lettaRuntimeGraphSha512: "sha512-
|
|
6425
|
+
lettaRuntimeGraphSha512: "sha512-WIuDCHjU7HpMkupg3IJU9kpdNZeagbwQQttyZaFDwGbI5Joz+NYvDSWoXrYPaA1w2Oxy6HVIBBPtv/lzIoENmg==",
|
|
6426
6426
|
patchedDependencies: {
|
|
6427
6427
|
"@earendil-works/pi-ai@1.5.2": "patches/@earendil-works%2Fpi-ai@1.5.2.patch"
|
|
6428
6428
|
}
|
|
@@ -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.60"
|
|
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.60"
|
|
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;
|
|
@@ -439124,6 +439504,38 @@ var init_mod_adapter = __esm(() => {
|
|
|
439124
439504
|
});
|
|
439125
439505
|
|
|
439126
439506
|
// src/websocket/listener/memfs-sync.ts
|
|
439507
|
+
import { execFileSync as execFileSync11 } from "node:child_process";
|
|
439508
|
+
import { lstat as lstat2, realpath as realpath6, rm as rm11 } from "node:fs/promises";
|
|
439509
|
+
import { isAbsolute as isAbsolute26, join as join83, relative as relative7, resolve as resolve37, sep as sep8 } from "node:path";
|
|
439510
|
+
async function removeRefusedCheckout(agentId, error4) {
|
|
439511
|
+
const message2 = error4 instanceof Error ? error4.message : String(error4);
|
|
439512
|
+
if (isLocalBackendEnvEnabled() || !/(?:returned error:|HTTP(?: status)?)[ :]*403\b/i.test(message2))
|
|
439513
|
+
return;
|
|
439514
|
+
try {
|
|
439515
|
+
const { getScopedMemoryFilesystemRoot: getScopedMemoryFilesystemRoot2 } = await Promise.resolve().then(() => (init_memory_filesystem2(), exports_memory_filesystem));
|
|
439516
|
+
const { isMemfsRemoteUrlForAgent: isMemfsRemoteUrlForAgent2 } = await Promise.resolve().then(() => (init_memory_git(), exports_memory_git));
|
|
439517
|
+
const configDir = await realpath6(resolveGlobalConfigDir());
|
|
439518
|
+
if (!agentId || agentId === "." || agentId === ".." || /[/\\]/.test(agentId))
|
|
439519
|
+
return;
|
|
439520
|
+
const expected = join83(configDir, "agents", agentId, "memory");
|
|
439521
|
+
const checkout = resolve37(getScopedMemoryFilesystemRoot2(agentId));
|
|
439522
|
+
if (await realpath6(checkout) !== expected || !(await lstat2(checkout)).isDirectory())
|
|
439523
|
+
return;
|
|
439524
|
+
const cwdRelative = relative7(expected, await realpath6(process.cwd()));
|
|
439525
|
+
if (!cwdRelative || !cwdRelative.startsWith(`..${sep8}`) && cwdRelative !== ".." && !isAbsolute26(cwdRelative))
|
|
439526
|
+
return;
|
|
439527
|
+
if (!(await lstat2(join83(checkout, ".git"))).isDirectory())
|
|
439528
|
+
return;
|
|
439529
|
+
const origin = execFileSync11("git", ["-C", checkout, "remote", "get-url", "origin"], {
|
|
439530
|
+
encoding: "utf8",
|
|
439531
|
+
timeout: 5000,
|
|
439532
|
+
stdio: ["ignore", "pipe", "ignore"]
|
|
439533
|
+
}).trim();
|
|
439534
|
+
if (!isMemfsRemoteUrlForAgent2(origin, agentId))
|
|
439535
|
+
return;
|
|
439536
|
+
await rm11(checkout, { recursive: true, force: true });
|
|
439537
|
+
} catch {}
|
|
439538
|
+
}
|
|
439127
439539
|
async function syncMemfsForAgent(agentId) {
|
|
439128
439540
|
const { settingsManager: settingsManager2 } = await Promise.resolve().then(() => (init_settings_manager(), exports_settings_manager));
|
|
439129
439541
|
if (settingsManager2.isMemfsExplicitlyDisabled(agentId)) {
|
|
@@ -439148,6 +439560,7 @@ async function syncMemfsForAgent(agentId) {
|
|
|
439148
439560
|
debugWarn("memfs-sync", `Agent ${agentId} is missing the memfs tag on Letta Cloud — repairing (auto-enabling memfs).`);
|
|
439149
439561
|
await applyMemfsFlags2(agentId, true, {
|
|
439150
439562
|
pullOnExistingRepo: true,
|
|
439563
|
+
throwOnPullFailure: true,
|
|
439151
439564
|
agentTags: agent.tags ?? []
|
|
439152
439565
|
});
|
|
439153
439566
|
debugLog("memfs-sync", `Memfs repair complete for agent ${agentId}`);
|
|
@@ -439156,31 +439569,42 @@ async function syncMemfsForAgent(agentId) {
|
|
|
439156
439569
|
debugLog("memfs-sync", `Syncing memfs for agent ${agentId}`);
|
|
439157
439570
|
await applyMemfsFlags2(agentId, undefined, {
|
|
439158
439571
|
pullOnExistingRepo: true,
|
|
439572
|
+
throwOnPullFailure: true,
|
|
439159
439573
|
agentTags: agent.tags,
|
|
439160
439574
|
skipPromptUpdate: true
|
|
439161
439575
|
});
|
|
439162
439576
|
debugLog("memfs-sync", `Memfs sync complete for agent ${agentId}`);
|
|
439163
439577
|
}
|
|
439164
439578
|
async function ensureMemfsSyncedForAgent(listener, agentId) {
|
|
439579
|
+
if (isMemoryUnavailable(agentId))
|
|
439580
|
+
return false;
|
|
439165
439581
|
const existing = listener.memfsSyncedAgents.get(agentId);
|
|
439166
439582
|
if (existing) {
|
|
439167
439583
|
return existing;
|
|
439168
439584
|
}
|
|
439169
|
-
const promise2 = syncMemfsForAgent(agentId).then(() => true, (err) => {
|
|
439585
|
+
const promise2 = syncMemfsForAgent(agentId).then(() => true, async (err) => {
|
|
439170
439586
|
debugWarn("memfs-sync", `Failed to sync memfs for agent ${agentId}: ${err instanceof Error ? err.message : String(err)}`);
|
|
439171
|
-
|
|
439587
|
+
if (isMemoryAccessRefusal(err)) {
|
|
439588
|
+
await removeRefusedCheckout(agentId, err);
|
|
439589
|
+
markMemoryUnavailable(agentId);
|
|
439590
|
+
} else {
|
|
439591
|
+
listener.memfsSyncedAgents.delete(agentId);
|
|
439592
|
+
}
|
|
439172
439593
|
return false;
|
|
439173
439594
|
});
|
|
439174
439595
|
listener.memfsSyncedAgents.set(agentId, promise2);
|
|
439175
439596
|
return promise2;
|
|
439176
439597
|
}
|
|
439177
439598
|
var init_memfs_sync = __esm(() => {
|
|
439599
|
+
init_paths();
|
|
439178
439600
|
init_debug();
|
|
439601
|
+
init_memory_access();
|
|
439602
|
+
init_settings_path();
|
|
439179
439603
|
});
|
|
439180
439604
|
|
|
439181
439605
|
// src/websocket/listener/mod-adapter.ts
|
|
439182
439606
|
import { createHash as createHash18 } from "node:crypto";
|
|
439183
|
-
import { join as
|
|
439607
|
+
import { join as join84 } from "node:path";
|
|
439184
439608
|
async function getUnavailableListenerClient() {
|
|
439185
439609
|
throw new Error("letta.client is not available in listener mods");
|
|
439186
439610
|
}
|
|
@@ -439256,14 +439680,14 @@ function ensureListenerModAdapter(runtime) {
|
|
|
439256
439680
|
}
|
|
439257
439681
|
function resolveListenerAgentModsDirectory(agentId) {
|
|
439258
439682
|
try {
|
|
439259
|
-
return settingsManager.isMemfsEnabled(agentId) ?
|
|
439683
|
+
return settingsManager.isMemfsEnabled(agentId) ? join84(getScopedMemoryFilesystemRoot(agentId), "mods") : null;
|
|
439260
439684
|
} catch {
|
|
439261
439685
|
return null;
|
|
439262
439686
|
}
|
|
439263
439687
|
}
|
|
439264
439688
|
function resolveListenerAgentModCacheDirectory(agentId) {
|
|
439265
439689
|
const cacheKey = createHash18("sha256").update(agentId).digest("hex");
|
|
439266
|
-
return
|
|
439690
|
+
return join84(getModCacheDirectory(), "listener-agents", cacheKey);
|
|
439267
439691
|
}
|
|
439268
439692
|
async function ensureListenerAgentModAdapter(runtime, agentId) {
|
|
439269
439693
|
runtime.agentModAdapters ??= new Map;
|
|
@@ -440085,7 +440509,7 @@ async function mergeSettledRecoveryResultRetriably(store3, params, retryDelayMs
|
|
|
440085
440509
|
if (!(error4 instanceof Error) || error4.message !== "Timed out acquiring durable filesystem lock") {
|
|
440086
440510
|
throw error4;
|
|
440087
440511
|
}
|
|
440088
|
-
await new Promise((
|
|
440512
|
+
await new Promise((resolve38) => setTimeout(resolve38, retryDelayMs));
|
|
440089
440513
|
}
|
|
440090
440514
|
}
|
|
440091
440515
|
}
|
|
@@ -440964,6 +441388,46 @@ var init_recovery = __esm(() => {
|
|
|
440964
441388
|
init_recovery_debug();
|
|
440965
441389
|
});
|
|
440966
441390
|
|
|
441391
|
+
// src/websocket/listener/recovery-read.ts
|
|
441392
|
+
async function retryApprovalRecoveryRead(read2, assertCurrent, signal) {
|
|
441393
|
+
for (let attempt2 = 0;; attempt2++) {
|
|
441394
|
+
assertCurrent();
|
|
441395
|
+
try {
|
|
441396
|
+
const result3 = await read2();
|
|
441397
|
+
assertCurrent();
|
|
441398
|
+
return result3;
|
|
441399
|
+
} catch (error4) {
|
|
441400
|
+
assertCurrent();
|
|
441401
|
+
const detail = extractConflictDetail(error4);
|
|
441402
|
+
if (attempt2 >= LLM_API_ERROR_MAX_RETRIES || !shouldRetryPreStreamTransientError({
|
|
441403
|
+
status: error4 instanceof APIError ? error4.status : undefined,
|
|
441404
|
+
detail
|
|
441405
|
+
}))
|
|
441406
|
+
throw error4;
|
|
441407
|
+
await new Promise((resolve38) => {
|
|
441408
|
+
const done = () => {
|
|
441409
|
+
clearTimeout(timer);
|
|
441410
|
+
signal.removeEventListener("abort", done);
|
|
441411
|
+
resolve38();
|
|
441412
|
+
};
|
|
441413
|
+
const timer = setTimeout(done, getRetryDelayMs2({
|
|
441414
|
+
category: "transient_provider",
|
|
441415
|
+
attempt: attempt2 + 1,
|
|
441416
|
+
detail
|
|
441417
|
+
}));
|
|
441418
|
+
signal.addEventListener("abort", done, { once: true });
|
|
441419
|
+
if (signal.aborted)
|
|
441420
|
+
done();
|
|
441421
|
+
});
|
|
441422
|
+
}
|
|
441423
|
+
}
|
|
441424
|
+
}
|
|
441425
|
+
var init_recovery_read = __esm(() => {
|
|
441426
|
+
init_error();
|
|
441427
|
+
init_turn_recovery_policy();
|
|
441428
|
+
init_constants3();
|
|
441429
|
+
});
|
|
441430
|
+
|
|
440967
441431
|
// src/websocket/listener/skill-injection.ts
|
|
440968
441432
|
function injectQueuedSkillContent(messages, context3) {
|
|
440969
441433
|
const skillContents = consumeQueuedSkillContent();
|
|
@@ -441017,7 +441481,7 @@ async function sleepWithAbort3(delayMs, abortSignal) {
|
|
|
441017
441481
|
if (delayMs <= 0) {
|
|
441018
441482
|
return;
|
|
441019
441483
|
}
|
|
441020
|
-
await new Promise((
|
|
441484
|
+
await new Promise((resolve38, reject2) => {
|
|
441021
441485
|
let timeout = null;
|
|
441022
441486
|
function cleanup() {
|
|
441023
441487
|
if (timeout) {
|
|
@@ -441037,7 +441501,7 @@ async function sleepWithAbort3(delayMs, abortSignal) {
|
|
|
441037
441501
|
abortSignal?.addEventListener("abort", onAbort, { once: true });
|
|
441038
441502
|
timeout = setTimeout(() => {
|
|
441039
441503
|
cleanup();
|
|
441040
|
-
|
|
441504
|
+
resolve38();
|
|
441041
441505
|
}, delayMs);
|
|
441042
441506
|
});
|
|
441043
441507
|
}
|
|
@@ -441129,7 +441593,7 @@ async function tryResumeBusyConversationStream(params) {
|
|
|
441129
441593
|
async function resolveStaleApprovals(runtime, socket, turnLease, deps = {}) {
|
|
441130
441594
|
if (!runtime.agentId && runtime.conversationId === "default")
|
|
441131
441595
|
return null;
|
|
441132
|
-
const getResumeDataImpl = deps.getResumeData ?? getResumeDataFromBackend;
|
|
441596
|
+
const getResumeDataImpl = (...args) => retryApprovalRecoveryRead(() => (deps.getResumeData ?? getResumeDataFromBackend)(...args), assertCurrentTurnLease, turnLease.signal);
|
|
441133
441597
|
const prepareToolExecutionContext = deps.prepareToolExecutionContext ?? prepareToolExecutionContextForScope;
|
|
441134
441598
|
const sendApprovalContinuation = deps.sendApprovalContinuation ?? sendApprovalContinuationWithRetry;
|
|
441135
441599
|
const drainRecoveryStream = deps.drainRecoveryStream ?? drainRecoveryStreamWithEmission;
|
|
@@ -441142,10 +441606,10 @@ async function resolveStaleApprovals(runtime, socket, turnLease, deps = {}) {
|
|
|
441142
441606
|
const backend3 = getBackend();
|
|
441143
441607
|
let agent;
|
|
441144
441608
|
try {
|
|
441145
|
-
agent = await retrieveResumeState(runtime.agentId, runtime.conversationId, {
|
|
441609
|
+
agent = await retryApprovalRecoveryRead(() => retrieveResumeState(runtime.agentId, runtime.conversationId, {
|
|
441146
441610
|
retrieveAgent: deps.retrieveAgent ?? backend3.retrieveAgent.bind(backend3),
|
|
441147
441611
|
retrieveConversation: deps.retrieveConversation ?? backend3.retrieveConversation.bind(backend3)
|
|
441148
|
-
});
|
|
441612
|
+
}), assertCurrentTurnLease, turnLease.signal);
|
|
441149
441613
|
} catch (err) {
|
|
441150
441614
|
assertCurrentTurnLease();
|
|
441151
441615
|
if (isBackendNotFoundError2(err)) {
|
|
@@ -441386,7 +441850,7 @@ async function sendMessageStreamWithRetry(conversationId, messages, opts, socket
|
|
|
441386
441850
|
conversationId
|
|
441387
441851
|
});
|
|
441388
441852
|
}
|
|
441389
|
-
await new Promise((
|
|
441853
|
+
await new Promise((resolve38) => setTimeout(resolve38, delayMs));
|
|
441390
441854
|
if (abortSignal?.aborted) {
|
|
441391
441855
|
throw new Error("Cancelled by user");
|
|
441392
441856
|
}
|
|
@@ -441534,7 +441998,7 @@ async function sendApprovalContinuationWithRetry(conversationId, messages, opts,
|
|
|
441534
441998
|
conversationId
|
|
441535
441999
|
});
|
|
441536
442000
|
}
|
|
441537
|
-
await new Promise((
|
|
442001
|
+
await new Promise((resolve38) => setTimeout(resolve38, delayMs));
|
|
441538
442002
|
if (abortSignal?.aborted) {
|
|
441539
442003
|
throw new Error("Cancelled by user");
|
|
441540
442004
|
}
|
|
@@ -441621,6 +442085,7 @@ var init_send = __esm(() => {
|
|
|
441621
442085
|
init_protocol_outbound();
|
|
441622
442086
|
init_recorded_tool_results();
|
|
441623
442087
|
init_recovery();
|
|
442088
|
+
init_recovery_read();
|
|
441624
442089
|
init_skill_injection();
|
|
441625
442090
|
init_turn_input_state();
|
|
441626
442091
|
init_turn_status();
|
|
@@ -442545,7 +443010,7 @@ var init_diff2 = __esm(() => {
|
|
|
442545
443010
|
});
|
|
442546
443011
|
|
|
442547
443012
|
// src/cli/helpers/shell-semantic-display.ts
|
|
442548
|
-
import { relative as
|
|
443013
|
+
import { relative as relative8 } from "node:path";
|
|
442549
443014
|
function quoteSummaryValue(value) {
|
|
442550
443015
|
return JSON.stringify(value);
|
|
442551
443016
|
}
|
|
@@ -442612,7 +443077,7 @@ function formatDisplayPath2(filePath) {
|
|
|
442612
443077
|
return ".";
|
|
442613
443078
|
}
|
|
442614
443079
|
const cwd2 = process.cwd();
|
|
442615
|
-
const relativePath =
|
|
443080
|
+
const relativePath = relative8(cwd2, filePath);
|
|
442616
443081
|
if (relativePath === "") {
|
|
442617
443082
|
return ".";
|
|
442618
443083
|
}
|
|
@@ -443237,13 +443702,13 @@ __export(exports_format_args_display, {
|
|
|
443237
443702
|
parsePatchInput: () => parsePatchInput,
|
|
443238
443703
|
formatArgsDisplay: () => formatArgsDisplay
|
|
443239
443704
|
});
|
|
443240
|
-
import { relative as
|
|
443705
|
+
import { relative as relative9 } from "node:path";
|
|
443241
443706
|
function formatItemCount(count) {
|
|
443242
443707
|
return `${String(count)} item${count === 1 ? "" : "s"}`;
|
|
443243
443708
|
}
|
|
443244
443709
|
function formatDisplayPath3(filePath) {
|
|
443245
443710
|
const cwd2 = process.cwd();
|
|
443246
|
-
const relativePath =
|
|
443711
|
+
const relativePath = relative9(cwd2, filePath);
|
|
443247
443712
|
if (relativePath.startsWith("..")) {
|
|
443248
443713
|
return filePath;
|
|
443249
443714
|
}
|
|
@@ -443939,7 +444404,7 @@ async function waitForApprovalTransportOpen(isDeliveryReady, shouldInterrupt) {
|
|
|
443939
444404
|
if (isDeliveryReady())
|
|
443940
444405
|
return "open";
|
|
443941
444406
|
while (!shouldInterrupt()) {
|
|
443942
|
-
await new Promise((
|
|
444407
|
+
await new Promise((resolve38) => setTimeout(resolve38, APPROVAL_TRANSPORT_REOPEN_POLL_MS));
|
|
443943
444408
|
if (isDeliveryReady())
|
|
443944
444409
|
return "open";
|
|
443945
444410
|
}
|
|
@@ -444550,7 +445015,7 @@ var init_turn_approval = __esm(() => {
|
|
|
444550
445015
|
|
|
444551
445016
|
// src/agent/attached-repository-git-sync.ts
|
|
444552
445017
|
import { existsSync as existsSync59 } from "node:fs";
|
|
444553
|
-
import { join as
|
|
445018
|
+
import { join as join85 } from "node:path";
|
|
444554
445019
|
async function getPendingCommitCount(path41) {
|
|
444555
445020
|
const divergence = await getMemoryAheadBehind(path41);
|
|
444556
445021
|
if (divergence) {
|
|
@@ -444580,7 +445045,7 @@ async function syncPendingAttachedRepositoryCommitsUnlocked(params) {
|
|
|
444580
445045
|
path: path41,
|
|
444581
445046
|
permissions: params.repository.permissions ?? "unknown"
|
|
444582
445047
|
};
|
|
444583
|
-
if (!existsSync59(
|
|
445048
|
+
if (!existsSync59(join85(path41, ".git"))) {
|
|
444584
445049
|
return {
|
|
444585
445050
|
...resultBase,
|
|
444586
445051
|
status: "skipped",
|
|
@@ -444751,7 +445216,7 @@ var init_attached_repository_git_sync = __esm(() => {
|
|
|
444751
445216
|
|
|
444752
445217
|
// src/reminders/memory-git-sync.ts
|
|
444753
445218
|
import { existsSync as existsSync60 } from "node:fs";
|
|
444754
|
-
import { join as
|
|
445219
|
+
import { join as join86 } from "node:path";
|
|
444755
445220
|
function formatMemoryRepairInProgressReminder(result3) {
|
|
444756
445221
|
return `${SYSTEM_REMINDER_OPEN}
|
|
444757
445222
|
MEMORY REPAIR RUNNING: A background worker is repairing the memory repository.
|
|
@@ -444861,7 +445326,7 @@ async function runPostTurnMemorySync(params, dependencies = {}) {
|
|
|
444861
445326
|
if (memorySyncEnabled) {
|
|
444862
445327
|
try {
|
|
444863
445328
|
const memoryDir = getScopedMemoryFilesystemRoot(params.agentId);
|
|
444864
|
-
const release = existsSync60(
|
|
445329
|
+
const release = existsSync60(join86(memoryDir, ".git")) ? await (dependencies.claimOperation ?? claimMemoryOperation)(memoryDir) : undefined;
|
|
444865
445330
|
if (release !== null) {
|
|
444866
445331
|
try {
|
|
444867
445332
|
const result3 = await syncMemory(params.agentId);
|
|
@@ -444959,7 +445424,7 @@ async function runListenerTurnCleanup(params) {
|
|
|
444959
445424
|
await runPostTurnMemorySync({
|
|
444960
445425
|
conversationId,
|
|
444961
445426
|
agentId,
|
|
444962
|
-
isEnabled: (id) => settingsManager.isMemfsEnabled(id),
|
|
445427
|
+
isEnabled: (id) => !isMemoryUnavailable(id) && settingsManager.isMemfsEnabled(id),
|
|
444963
445428
|
debugLabel: "Post-turn listener memory sync",
|
|
444964
445429
|
onMemoryPushed: () => {
|
|
444965
445430
|
const transport3 = runtime.listener.transport ?? runtime.listener.socket;
|
|
@@ -444977,6 +445442,7 @@ async function runListenerTurnCleanup(params) {
|
|
|
444977
445442
|
var init_turn_cleanup = __esm(() => {
|
|
444978
445443
|
init_memory_git_sync();
|
|
444979
445444
|
init_settings_manager();
|
|
445445
|
+
init_memory_access();
|
|
444980
445446
|
init_channel_runtime_tools();
|
|
444981
445447
|
init_connection();
|
|
444982
445448
|
init_permission_mode();
|
|
@@ -447095,7 +447561,7 @@ var init_core5 = __esm(() => {
|
|
|
447095
447561
|
import { spawn as spawn12 } from "node:child_process";
|
|
447096
447562
|
import { accessSync as accessSync2, constants as constants6 } from "node:fs";
|
|
447097
447563
|
import { homedir as homedir23 } from "node:os";
|
|
447098
|
-
import { join as
|
|
447564
|
+
import { join as join87 } from "node:path";
|
|
447099
447565
|
import { fileURLToPath as fileURLToPath9 } from "node:url";
|
|
447100
447566
|
async function normalizeCheckpoint(input) {
|
|
447101
447567
|
const { decoded, bounds, filters } = await decodeCheckpoint(input);
|
|
@@ -447119,10 +447585,10 @@ async function decodeCheckpoint(input) {
|
|
|
447119
447585
|
}
|
|
447120
447586
|
async function loadDeepAgentsCheckpoint(checkpoint) {
|
|
447121
447587
|
validateLocation(checkpoint);
|
|
447122
|
-
const path41 = checkpoint.path ??
|
|
447588
|
+
const path41 = checkpoint.path ?? join87(homedir23(), ".deepagents", "sessions.db");
|
|
447123
447589
|
const python = checkpoint.pythonExecutable ?? process.env.PYTHON ?? "python3";
|
|
447124
447590
|
const helper = resolveHelperPath();
|
|
447125
|
-
return await new Promise((
|
|
447591
|
+
return await new Promise((resolve38, reject2) => {
|
|
447126
447592
|
const child = spawn12(python, [helper], {
|
|
447127
447593
|
stdio: ["pipe", "pipe", "pipe"],
|
|
447128
447594
|
windowsHide: true
|
|
@@ -447179,7 +447645,7 @@ async function loadDeepAgentsCheckpoint(checkpoint) {
|
|
|
447179
447645
|
reject2(new NormalizationError("invalid_checkpoint_state", "Deep Agents checkpoint helper returned an invalid message envelope."));
|
|
447180
447646
|
return;
|
|
447181
447647
|
}
|
|
447182
|
-
|
|
447648
|
+
resolve38({ ...response.data, threadId: checkpoint.threadId });
|
|
447183
447649
|
});
|
|
447184
447650
|
child.stdin.on("error", () => {});
|
|
447185
447651
|
child.stdin.end(JSON.stringify({
|
|
@@ -447339,7 +447805,7 @@ var init_deepagents = __esm(() => {
|
|
|
447339
447805
|
|
|
447340
447806
|
// node_modules/@letta-ai/trajectory/dist/adapters/listing-shared.js
|
|
447341
447807
|
import { readdirSync as readdirSync24, statSync as statSync24 } from "node:fs";
|
|
447342
|
-
import { join as
|
|
447808
|
+
import { join as join88 } from "node:path";
|
|
447343
447809
|
function sortListings(items) {
|
|
447344
447810
|
return items.sort((left, right) => {
|
|
447345
447811
|
const l3 = left.updatedAt ?? "";
|
|
@@ -447384,7 +447850,7 @@ function collectFiles(root2, extension, depth) {
|
|
|
447384
447850
|
return [];
|
|
447385
447851
|
const collected = [];
|
|
447386
447852
|
for (const entry of safeReadDir(root2)) {
|
|
447387
|
-
const full =
|
|
447853
|
+
const full = join88(root2, entry.name);
|
|
447388
447854
|
if (entry.isFile && entry.name.endsWith(extension)) {
|
|
447389
447855
|
collected.push(full);
|
|
447390
447856
|
} else if (entry.isDirectory) {
|
|
@@ -447469,18 +447935,18 @@ var init_listing_shared = __esm(() => {
|
|
|
447469
447935
|
|
|
447470
447936
|
// node_modules/@letta-ai/trajectory/dist/adapters/claude-code/list.js
|
|
447471
447937
|
import { homedir as homedir24 } from "node:os";
|
|
447472
|
-
import { basename as basename25, join as
|
|
447938
|
+
import { basename as basename25, join as join89 } from "node:path";
|
|
447473
447939
|
async function listClaudeCodeTrajectories(root2) {
|
|
447474
|
-
const base2 = root2 ??
|
|
447940
|
+
const base2 = root2 ?? join89(homedir24(), ".claude", "projects");
|
|
447475
447941
|
const items = [];
|
|
447476
447942
|
for (const project of safeReadDir(base2)) {
|
|
447477
447943
|
if (!project.isDirectory)
|
|
447478
447944
|
continue;
|
|
447479
|
-
const projectPath =
|
|
447945
|
+
const projectPath = join89(base2, project.name);
|
|
447480
447946
|
for (const entry of safeReadDir(projectPath)) {
|
|
447481
447947
|
if (!entry.isFile || !entry.name.endsWith(".jsonl"))
|
|
447482
447948
|
continue;
|
|
447483
|
-
const path41 =
|
|
447949
|
+
const path41 = join89(projectPath, entry.name);
|
|
447484
447950
|
const listing = listingFromFile(basename25(entry.name, ".jsonl"), path41);
|
|
447485
447951
|
if (listing)
|
|
447486
447952
|
items.push(listing);
|
|
@@ -447494,9 +447960,9 @@ var init_list = __esm(() => {
|
|
|
447494
447960
|
|
|
447495
447961
|
// node_modules/@letta-ai/trajectory/dist/adapters/codex/list.js
|
|
447496
447962
|
import { homedir as homedir25 } from "node:os";
|
|
447497
|
-
import { basename as basename26, join as
|
|
447963
|
+
import { basename as basename26, join as join90 } from "node:path";
|
|
447498
447964
|
async function listCodexTrajectories(root2) {
|
|
447499
|
-
const base2 = root2 ??
|
|
447965
|
+
const base2 = root2 ?? join90(homedir25(), ".codex", "sessions");
|
|
447500
447966
|
const items = [];
|
|
447501
447967
|
for (const path41 of collectFiles(base2, ".jsonl", 4)) {
|
|
447502
447968
|
const listing = listingFromFile(basename26(path41, ".jsonl"), path41);
|
|
@@ -447511,7 +447977,7 @@ var init_list2 = __esm(() => {
|
|
|
447511
447977
|
|
|
447512
447978
|
// node_modules/@letta-ai/trajectory/dist/adapters/deepagents/list.js
|
|
447513
447979
|
import { homedir as homedir26 } from "node:os";
|
|
447514
|
-
import { join as
|
|
447980
|
+
import { join as join91 } from "node:path";
|
|
447515
447981
|
async function listDeepAgentsTrajectories(root2) {
|
|
447516
447982
|
const path41 = resolveStorePath(root2);
|
|
447517
447983
|
if (!safeStat(path41))
|
|
@@ -447532,8 +447998,8 @@ async function listDeepAgentsTrajectories(root2) {
|
|
|
447532
447998
|
}
|
|
447533
447999
|
function resolveStorePath(root2) {
|
|
447534
448000
|
if (root2 === undefined)
|
|
447535
|
-
return
|
|
447536
|
-
return root2.endsWith(".db") ? root2 :
|
|
448001
|
+
return join91(homedir26(), ".deepagents", "sessions.db");
|
|
448002
|
+
return root2.endsWith(".db") ? root2 : join91(root2, "sessions.db");
|
|
447537
448003
|
}
|
|
447538
448004
|
var init_list3 = __esm(() => {
|
|
447539
448005
|
init_listing_shared();
|
|
@@ -447541,7 +448007,7 @@ var init_list3 = __esm(() => {
|
|
|
447541
448007
|
|
|
447542
448008
|
// node_modules/@letta-ai/trajectory/dist/adapters/hermes/list.js
|
|
447543
448009
|
import { homedir as homedir27 } from "node:os";
|
|
447544
|
-
import { join as
|
|
448010
|
+
import { join as join92 } from "node:path";
|
|
447545
448011
|
async function listHermesTrajectories(root2) {
|
|
447546
448012
|
const path41 = resolveStorePath2(root2);
|
|
447547
448013
|
if (!safeStat(path41))
|
|
@@ -447568,8 +448034,8 @@ async function listHermesTrajectories(root2) {
|
|
|
447568
448034
|
}
|
|
447569
448035
|
function resolveStorePath2(root2) {
|
|
447570
448036
|
if (root2 === undefined)
|
|
447571
|
-
return
|
|
447572
|
-
return root2.endsWith(".db") ? root2 :
|
|
448037
|
+
return join92(homedir27(), ".hermes", "state.db");
|
|
448038
|
+
return root2.endsWith(".db") ? root2 : join92(root2, "state.db");
|
|
447573
448039
|
}
|
|
447574
448040
|
function numeric2(value) {
|
|
447575
448041
|
return typeof value === "number" && Number.isFinite(value) && value > 0 ? value : undefined;
|
|
@@ -447580,18 +448046,18 @@ var init_list4 = __esm(() => {
|
|
|
447580
448046
|
|
|
447581
448047
|
// node_modules/@letta-ai/trajectory/dist/adapters/letta-code/list.js
|
|
447582
448048
|
import { homedir as homedir28 } from "node:os";
|
|
447583
|
-
import { join as
|
|
448049
|
+
import { join as join93 } from "node:path";
|
|
447584
448050
|
async function listLettaCodeTrajectories(root2) {
|
|
447585
|
-
const base2 = root2 ??
|
|
448051
|
+
const base2 = root2 ?? join93(homedir28(), ".letta", "transcripts");
|
|
447586
448052
|
const items = [];
|
|
447587
448053
|
for (const agent of safeReadDir(base2)) {
|
|
447588
448054
|
if (!agent.isDirectory)
|
|
447589
448055
|
continue;
|
|
447590
|
-
const agentPath2 =
|
|
448056
|
+
const agentPath2 = join93(base2, agent.name);
|
|
447591
448057
|
for (const conversation of safeReadDir(agentPath2)) {
|
|
447592
448058
|
if (!conversation.isDirectory)
|
|
447593
448059
|
continue;
|
|
447594
|
-
const path41 =
|
|
448060
|
+
const path41 = join93(agentPath2, conversation.name, "transcript.jsonl");
|
|
447595
448061
|
const listing = listingFromFile(`${agent.name}/${conversation.name}`, path41);
|
|
447596
448062
|
if (listing && (listing.sizeBytes ?? 0) > 0)
|
|
447597
448063
|
items.push(listing);
|
|
@@ -447606,19 +448072,19 @@ var init_list5 = __esm(() => {
|
|
|
447606
448072
|
// node_modules/@letta-ai/trajectory/dist/adapters/openclaw/list.js
|
|
447607
448073
|
import { existsSync as existsSync61 } from "node:fs";
|
|
447608
448074
|
import { homedir as homedir29 } from "node:os";
|
|
447609
|
-
import { basename as basename27, join as
|
|
448075
|
+
import { basename as basename27, join as join94 } from "node:path";
|
|
447610
448076
|
async function listOpenClawTrajectories(root2) {
|
|
447611
448077
|
const base2 = root2 ?? defaultStateDir();
|
|
447612
448078
|
const items = [];
|
|
447613
|
-
const agentsPath =
|
|
448079
|
+
const agentsPath = join94(base2, "agents");
|
|
447614
448080
|
for (const agent of safeReadDir(agentsPath)) {
|
|
447615
448081
|
if (!agent.isDirectory)
|
|
447616
448082
|
continue;
|
|
447617
|
-
const sessionsPath =
|
|
448083
|
+
const sessionsPath = join94(agentsPath, agent.name, "sessions");
|
|
447618
448084
|
for (const entry of safeReadDir(sessionsPath)) {
|
|
447619
448085
|
if (!entry.isFile || !entry.name.endsWith(".jsonl"))
|
|
447620
448086
|
continue;
|
|
447621
|
-
const path41 =
|
|
448087
|
+
const path41 = join94(sessionsPath, entry.name);
|
|
447622
448088
|
const listing = listingFromFile(basename27(entry.name, ".jsonl"), path41);
|
|
447623
448089
|
if (listing)
|
|
447624
448090
|
items.push(listing);
|
|
@@ -447630,10 +448096,10 @@ function defaultStateDir() {
|
|
|
447630
448096
|
const override = process.env.OPENCLAW_STATE_DIR?.trim() || process.env.CLAWDBOT_STATE_DIR?.trim();
|
|
447631
448097
|
if (override)
|
|
447632
448098
|
return override;
|
|
447633
|
-
const current =
|
|
448099
|
+
const current = join94(homedir29(), ".openclaw");
|
|
447634
448100
|
if (existsSync61(current))
|
|
447635
448101
|
return current;
|
|
447636
|
-
return
|
|
448102
|
+
return join94(homedir29(), ".clawdbot");
|
|
447637
448103
|
}
|
|
447638
448104
|
var init_list6 = __esm(() => {
|
|
447639
448105
|
init_listing_shared();
|
|
@@ -447641,14 +448107,14 @@ var init_list6 = __esm(() => {
|
|
|
447641
448107
|
|
|
447642
448108
|
// node_modules/@letta-ai/trajectory/dist/adapters/openhands/list.js
|
|
447643
448109
|
import { homedir as homedir30 } from "node:os";
|
|
447644
|
-
import { join as
|
|
448110
|
+
import { join as join95 } from "node:path";
|
|
447645
448111
|
async function listOpenHandsTrajectories(root2) {
|
|
447646
|
-
const base2 = root2 ??
|
|
448112
|
+
const base2 = root2 ?? join95(homedir30(), ".openhands", "sessions");
|
|
447647
448113
|
const items = [];
|
|
447648
448114
|
for (const entry of safeReadDir(base2)) {
|
|
447649
448115
|
if (!entry.isDirectory)
|
|
447650
448116
|
continue;
|
|
447651
|
-
const path41 =
|
|
448117
|
+
const path41 = join95(base2, entry.name);
|
|
447652
448118
|
const facts = safeStat(path41);
|
|
447653
448119
|
items.push({
|
|
447654
448120
|
id: entry.name,
|
|
@@ -447822,7 +448288,7 @@ __export(exports_memory_scanner, {
|
|
|
447822
448288
|
getFileNodes: () => getFileNodes
|
|
447823
448289
|
});
|
|
447824
448290
|
import { readdirSync as readdirSync25, readFileSync as readFileSync50, statSync as statSync25 } from "node:fs";
|
|
447825
|
-
import { join as
|
|
448291
|
+
import { join as join96, relative as relative10 } from "node:path";
|
|
447826
448292
|
function scanMemoryFilesystem(memoryRoot) {
|
|
447827
448293
|
const nodes = [];
|
|
447828
448294
|
const scanDir = (dir, depth, parentIsLast) => {
|
|
@@ -447834,8 +448300,8 @@ function scanMemoryFilesystem(memoryRoot) {
|
|
|
447834
448300
|
}
|
|
447835
448301
|
const filtered = entries2.filter((name) => !name.startsWith("."));
|
|
447836
448302
|
const sorted = filtered.sort((a2, b3) => {
|
|
447837
|
-
const aPath =
|
|
447838
|
-
const bPath =
|
|
448303
|
+
const aPath = join96(dir, a2);
|
|
448304
|
+
const bPath = join96(dir, b3);
|
|
447839
448305
|
let aIsDir = false;
|
|
447840
448306
|
let bIsDir = false;
|
|
447841
448307
|
try {
|
|
@@ -447855,14 +448321,14 @@ function scanMemoryFilesystem(memoryRoot) {
|
|
|
447855
448321
|
return a2.localeCompare(b3);
|
|
447856
448322
|
});
|
|
447857
448323
|
sorted.forEach((name, index) => {
|
|
447858
|
-
const fullPath =
|
|
448324
|
+
const fullPath = join96(dir, name);
|
|
447859
448325
|
let isDir = false;
|
|
447860
448326
|
try {
|
|
447861
448327
|
isDir = statSync25(fullPath).isDirectory();
|
|
447862
448328
|
} catch {
|
|
447863
448329
|
return;
|
|
447864
448330
|
}
|
|
447865
|
-
const relativePath =
|
|
448331
|
+
const relativePath = relative10(memoryRoot, fullPath).replace(/\\/g, "/");
|
|
447866
448332
|
const isLast = index === sorted.length - 1;
|
|
447867
448333
|
nodes.push({
|
|
447868
448334
|
name: isDir ? `${name}/` : name,
|
|
@@ -447973,7 +448439,7 @@ import {
|
|
|
447973
448439
|
stat as stat12,
|
|
447974
448440
|
writeFile as writeFile15
|
|
447975
448441
|
} from "node:fs/promises";
|
|
447976
|
-
import { join as
|
|
448442
|
+
import { join as join97 } from "node:path";
|
|
447977
448443
|
function buildReflectionSelectorPrompt(options) {
|
|
447978
448444
|
const lines = [
|
|
447979
448445
|
'You are selecting conversation transcripts for memory reflection. The transcript candidates path is available as the `$TRANSCRIPT_PATH` env var — read it via Bash (e.g. `wc -c "$TRANSCRIPT_PATH"`). Note: `$TRANSCRIPT_PATH` only expands in shell commands; Edit file_path is literal and does NOT expand env vars.',
|
|
@@ -448007,7 +448473,7 @@ async function collectParentMemoryFiles(memoryDir) {
|
|
|
448007
448473
|
return a2.name.localeCompare(b3.name);
|
|
448008
448474
|
});
|
|
448009
448475
|
for (const entry of sortedEntries) {
|
|
448010
|
-
const entryPath =
|
|
448476
|
+
const entryPath = join97(currentDir, entry.name);
|
|
448011
448477
|
const relativePath = relativeDir ? `${relativeDir}/${entry.name}` : entry.name;
|
|
448012
448478
|
if (entry.isDirectory()) {
|
|
448013
448479
|
await walk3(entryPath, relativePath);
|
|
@@ -448423,17 +448889,17 @@ async function writeState(paths, state2) {
|
|
|
448423
448889
|
}
|
|
448424
448890
|
function buildPayloadPath(rootDir, kind) {
|
|
448425
448891
|
const nonce = Math.random().toString(36).slice(2, 8);
|
|
448426
|
-
return
|
|
448892
|
+
return join97(rootDir, `payload-${kind}-${nonce}.json`);
|
|
448427
448893
|
}
|
|
448428
448894
|
function getAgentTranscriptRoot(agentId) {
|
|
448429
|
-
return
|
|
448895
|
+
return join97(getTranscriptRoot(), sanitizePathSegment2(agentId));
|
|
448430
448896
|
}
|
|
448431
448897
|
function getReflectionTranscriptPaths(agentId, conversationId) {
|
|
448432
|
-
const rootDir =
|
|
448898
|
+
const rootDir = join97(getTranscriptRoot(), sanitizePathSegment2(agentId), sanitizePathSegment2(conversationId));
|
|
448433
448899
|
return {
|
|
448434
448900
|
rootDir,
|
|
448435
|
-
transcriptPath:
|
|
448436
|
-
statePath:
|
|
448901
|
+
transcriptPath: join97(rootDir, "transcript.jsonl"),
|
|
448902
|
+
statePath: join97(rootDir, "state.json")
|
|
448437
448903
|
};
|
|
448438
448904
|
}
|
|
448439
448905
|
async function appendTranscriptDeltaJsonl(agentId, conversationId, lines) {
|
|
@@ -448523,7 +448989,7 @@ async function getTranscriptLastUpdatedAt(paths) {
|
|
|
448523
448989
|
}
|
|
448524
448990
|
}
|
|
448525
448991
|
async function ensureAgentPayloadRoot(agentId) {
|
|
448526
|
-
const root2 =
|
|
448992
|
+
const root2 = join97(getAgentTranscriptRoot(agentId), "multi-reflection-payloads");
|
|
448527
448993
|
await mkdir12(root2, { recursive: true });
|
|
448528
448994
|
return root2;
|
|
448529
448995
|
}
|
|
@@ -449087,12 +449553,12 @@ import { execFile as execFileCb3 } from "node:child_process";
|
|
|
449087
449553
|
import { randomUUID as randomUUID54 } from "node:crypto";
|
|
449088
449554
|
import { existsSync as existsSync62 } from "node:fs";
|
|
449089
449555
|
import { mkdir as mkdir13 } from "node:fs/promises";
|
|
449090
|
-
import { dirname as dirname37, isAbsolute as
|
|
449091
|
-
import { promisify as
|
|
449556
|
+
import { dirname as dirname37, isAbsolute as isAbsolute27, join as join98, resolve as resolve38 } from "node:path";
|
|
449557
|
+
import { promisify as promisify18 } from "node:util";
|
|
449092
449558
|
async function runGit4(cwd2, args) {
|
|
449093
449559
|
try {
|
|
449094
449560
|
const allArgs = [...GIT_DISABLE_COMMIT_SIGNING_ARGS, ...args];
|
|
449095
|
-
const { stdout, stderr } = await
|
|
449561
|
+
const { stdout, stderr } = await execFile18("git", allArgs, {
|
|
449096
449562
|
cwd: cwd2,
|
|
449097
449563
|
env: {
|
|
449098
449564
|
...process.env,
|
|
@@ -449124,7 +449590,7 @@ function normalizeGitPath(path41, cwd2) {
|
|
|
449124
449590
|
const trimmed = path41.trim();
|
|
449125
449591
|
if (!trimmed)
|
|
449126
449592
|
return trimmed;
|
|
449127
|
-
return
|
|
449593
|
+
return isAbsolute27(trimmed) ? trimmed : resolve38(cwd2, trimmed);
|
|
449128
449594
|
}
|
|
449129
449595
|
function buildReflectionWorktreeId(now2 = new Date) {
|
|
449130
449596
|
const timestamp = now2.toISOString().replace(/[^0-9]/g, "").slice(0, 14);
|
|
@@ -449145,11 +449611,11 @@ async function buildReflectionMergeMessage(parentMemoryDir, branchName) {
|
|
|
449145
449611
|
return `merge(reflection): ${summary}`;
|
|
449146
449612
|
}
|
|
449147
449613
|
async function createReflectionMemoryWorktree(options) {
|
|
449148
|
-
const parentMemoryDir =
|
|
449614
|
+
const parentMemoryDir = resolve38(options.parentMemoryDir);
|
|
449149
449615
|
const id = buildReflectionWorktreeId(options.now);
|
|
449150
|
-
const worktreeBaseDir =
|
|
449616
|
+
const worktreeBaseDir = join98(dirname37(parentMemoryDir), "memory-worktrees");
|
|
449151
449617
|
const label = options.label ?? "reflection";
|
|
449152
|
-
const worktreeDir =
|
|
449618
|
+
const worktreeDir = join98(worktreeBaseDir, `${label}-${id}`);
|
|
449153
449619
|
const branchName = `letta/${label}/${id}`;
|
|
449154
449620
|
await mkdir13(worktreeBaseDir, { recursive: true });
|
|
449155
449621
|
const { stdout: baseHeadOut } = await runGit4(parentMemoryDir, [
|
|
@@ -449214,7 +449680,7 @@ async function getStatusPorcelain(cwd2) {
|
|
|
449214
449680
|
return stdout.trim();
|
|
449215
449681
|
}
|
|
449216
449682
|
async function reflectionMemoryParentHasChanges(parentMemoryDir) {
|
|
449217
|
-
return (await getStatusPorcelain(
|
|
449683
|
+
return (await getStatusPorcelain(resolve38(parentMemoryDir))).length > 0;
|
|
449218
449684
|
}
|
|
449219
449685
|
async function getCommitCount(worktree) {
|
|
449220
449686
|
const { stdout } = await runGit4(worktree.worktreeDir, [
|
|
@@ -449461,7 +449927,7 @@ async function finalizeReflectionMemoryWorktreeUnlocked(worktree, options) {
|
|
|
449461
449927
|
async function finalizeReflectionMemoryWorktree(worktree, options) {
|
|
449462
449928
|
return withMemoryOperation(worktree.parentMemoryDir, () => finalizeReflectionMemoryWorktreeUnlocked(worktree, options));
|
|
449463
449929
|
}
|
|
449464
|
-
var
|
|
449930
|
+
var execFile18, GIT_TIMEOUT_MS = 30000, HARNESS_GIT_ENV;
|
|
449465
449931
|
var init_memory_worktree = __esm(() => {
|
|
449466
449932
|
init_memory_auth();
|
|
449467
449933
|
init_memory_git();
|
|
@@ -449469,7 +449935,7 @@ var init_memory_worktree = __esm(() => {
|
|
|
449469
449935
|
init_memory_operation();
|
|
449470
449936
|
init_memfs_git_proxy();
|
|
449471
449937
|
init_debug();
|
|
449472
|
-
|
|
449938
|
+
execFile18 = promisify18(execFileCb3);
|
|
449473
449939
|
HARNESS_GIT_ENV = {
|
|
449474
449940
|
GIT_AUTHOR_NAME: "Letta Code",
|
|
449475
449941
|
GIT_AUTHOR_EMAIL: "noreply@letta.com",
|
|
@@ -450050,7 +450516,7 @@ async function runExplicitReflectionIntegration(params) {
|
|
|
450050
450516
|
spawnBackgroundSubagentTask: spawnBackgroundSubagentTask2,
|
|
450051
450517
|
waitForBackgroundSubagentConversationId: waitForBackgroundSubagentConversationId2
|
|
450052
450518
|
} = await Promise.resolve().then(() => (init_task(), exports_task));
|
|
450053
|
-
return await new Promise((
|
|
450519
|
+
return await new Promise((resolve39) => {
|
|
450054
450520
|
try {
|
|
450055
450521
|
const { subagentId } = spawnBackgroundSubagentTask2({
|
|
450056
450522
|
subagentType: "general-purpose",
|
|
@@ -450069,7 +450535,7 @@ async function runExplicitReflectionIntegration(params) {
|
|
|
450069
450535
|
},
|
|
450070
450536
|
silentCompletion: true,
|
|
450071
450537
|
onComplete: (result3) => {
|
|
450072
|
-
|
|
450538
|
+
resolve39({
|
|
450073
450539
|
success: result3.success,
|
|
450074
450540
|
error: result3.success ? undefined : result3.error ?? "Reflection integration did not complete",
|
|
450075
450541
|
conversationId: result3.conversationId
|
|
@@ -450086,7 +450552,7 @@ async function runExplicitReflectionIntegration(params) {
|
|
|
450086
450552
|
debugWarn("memory", `Failed to title reflection integration conversation: ${error4 instanceof Error ? error4.message : String(error4)}`);
|
|
450087
450553
|
});
|
|
450088
450554
|
} catch (error4) {
|
|
450089
|
-
|
|
450555
|
+
resolve39({
|
|
450090
450556
|
success: false,
|
|
450091
450557
|
error: error4 instanceof Error ? error4.message : String(error4)
|
|
450092
450558
|
});
|
|
@@ -450849,7 +451315,7 @@ async function prepareProviderRetryInput(params) {
|
|
|
450849
451315
|
agentId: params.agentId,
|
|
450850
451316
|
conversationId: params.conversationId
|
|
450851
451317
|
});
|
|
450852
|
-
await new Promise((
|
|
451318
|
+
await new Promise((resolve39) => setTimeout(resolve39, delayMs));
|
|
450853
451319
|
if (params.turnLease.signal.aborted) {
|
|
450854
451320
|
throw new Error("Cancelled by user");
|
|
450855
451321
|
}
|
|
@@ -451255,6 +451721,10 @@ async function prepareListenerTurn(params) {
|
|
|
451255
451721
|
excludeInteractiveTools: msg.excludeInteractiveTools
|
|
451256
451722
|
}, toolOwner.toolPolicy);
|
|
451257
451723
|
const preparedToolContext = await prepareToolExecutionContextForScope({
|
|
451724
|
+
readScopeState: (read2) => retryApprovalRecoveryRead(read2, () => {
|
|
451725
|
+
if (isInterrupted())
|
|
451726
|
+
throw new Error("Cancelled by user");
|
|
451727
|
+
}, turnLease.signal),
|
|
451258
451728
|
connectionId: executionConnectionId,
|
|
451259
451729
|
environmentDeviceId,
|
|
451260
451730
|
agentId,
|
|
@@ -451355,6 +451825,7 @@ var init_turn_setup = __esm(() => {
|
|
|
451355
451825
|
init_image_policy();
|
|
451356
451826
|
init_interrupts();
|
|
451357
451827
|
init_mod_adapter2();
|
|
451828
|
+
init_recovery_read();
|
|
451358
451829
|
init_runtime6();
|
|
451359
451830
|
init_turn_events();
|
|
451360
451831
|
init_turn_input_state();
|
|
@@ -451808,7 +452279,7 @@ async function handleIncomingMessageInner(msg, socket, runtime, onStatusChange,
|
|
|
451808
452279
|
agentId,
|
|
451809
452280
|
conversationId
|
|
451810
452281
|
});
|
|
451811
|
-
await new Promise((
|
|
452282
|
+
await new Promise((resolve39) => setTimeout(resolve39, delayMs));
|
|
451812
452283
|
if (turnAbortSignal.aborted) {
|
|
451813
452284
|
throw new Error("Cancelled by user");
|
|
451814
452285
|
}
|
|
@@ -452602,7 +453073,7 @@ var init_inbound_dispatch = __esm(() => {
|
|
|
452602
453073
|
});
|
|
452603
453074
|
|
|
452604
453075
|
// src/utils/machine-metadata.ts
|
|
452605
|
-
import { execFile as
|
|
453076
|
+
import { execFile as execFile19 } from "node:child_process";
|
|
452606
453077
|
import { readFile as readFile25 } from "node:fs/promises";
|
|
452607
453078
|
import { cpus, totalmem } from "node:os";
|
|
452608
453079
|
function getMachineMetadata() {
|
|
@@ -452619,14 +453090,14 @@ function localSources() {
|
|
|
452619
453090
|
cpu: cpus()[0]?.model,
|
|
452620
453091
|
memoryBytes: Math.min(totalmem(), limit4 || Number.POSITIVE_INFINITY),
|
|
452621
453092
|
read: (path41, signal) => readFile25(path41, { encoding: "utf8", signal }),
|
|
452622
|
-
run: (command, args, signal) => new Promise((
|
|
452623
|
-
|
|
453093
|
+
run: (command, args, signal) => new Promise((resolve39, reject2) => {
|
|
453094
|
+
execFile19(command, args, {
|
|
452624
453095
|
encoding: "utf8",
|
|
452625
453096
|
signal,
|
|
452626
453097
|
killSignal: "SIGKILL",
|
|
452627
453098
|
windowsHide: true,
|
|
452628
453099
|
maxBuffer: 512 * 1024
|
|
452629
|
-
}, (error4, stdout) => error4 ? reject2(error4) :
|
|
453100
|
+
}, (error4, stdout) => error4 ? reject2(error4) : resolve39(stdout));
|
|
452630
453101
|
})
|
|
452631
453102
|
};
|
|
452632
453103
|
}
|
|
@@ -452743,10 +453214,10 @@ async function collectMachineMetadata(sources = localSources(), timeoutMs = COLL
|
|
|
452743
453214
|
try {
|
|
452744
453215
|
await Promise.race([
|
|
452745
453216
|
probe2().catch(() => {}),
|
|
452746
|
-
new Promise((
|
|
453217
|
+
new Promise((resolve39) => {
|
|
452747
453218
|
timer = setTimeout(() => {
|
|
452748
453219
|
controller.abort();
|
|
452749
|
-
|
|
453220
|
+
resolve39();
|
|
452750
453221
|
}, timeoutMs);
|
|
452751
453222
|
})
|
|
452752
453223
|
]);
|
|
@@ -452880,7 +453351,7 @@ async function registerWithCloud(opts, fetchImpl = fetch) {
|
|
|
452880
453351
|
async function registerWithCloudRetry(opts, callbacks) {
|
|
452881
453352
|
const startTime = Date.now();
|
|
452882
453353
|
const maxDurationMs = callbacks?.maxDurationMs ?? REGISTER_MAX_DURATION_MS;
|
|
452883
|
-
const sleep12 = callbacks?.sleep ?? ((delayMs) => new Promise((
|
|
453354
|
+
const sleep12 = callbacks?.sleep ?? ((delayMs) => new Promise((resolve39) => setTimeout(resolve39, delayMs)));
|
|
452884
453355
|
let attempt2 = 0;
|
|
452885
453356
|
for (;; ) {
|
|
452886
453357
|
try {
|
|
@@ -453281,7 +453752,6 @@ async function completeInitialConnectionStartup(listener, connection, transport3
|
|
|
453281
453752
|
async function replaySubscribedConnectionState(listener, transport3, runtime, scope, options = {}) {
|
|
453282
453753
|
const connection = findListenerConnectionByTransport(listener, transport3);
|
|
453283
453754
|
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
453755
|
if (!isCurrent())
|
|
453286
453756
|
return;
|
|
453287
453757
|
if (connection) {
|
|
@@ -453293,12 +453763,28 @@ async function replaySubscribedConnectionState(listener, transport3, runtime, sc
|
|
|
453293
453763
|
if (!isCurrent())
|
|
453294
453764
|
return;
|
|
453295
453765
|
}
|
|
453766
|
+
const gitContextBefore = JSON.stringify(buildDeviceStatus(listener, scope).git_context);
|
|
453296
453767
|
emitStateSync(transport3, listener, scope, {
|
|
453297
453768
|
forceDeviceStatus: options.forceDeviceStatus,
|
|
453298
453769
|
...connection ? { routing: toListenerConnection(connection.id) } : {}
|
|
453299
453770
|
});
|
|
453771
|
+
(async () => {
|
|
453772
|
+
await (options.refreshGitContext ?? refreshDeviceGitContext)(listener, scope);
|
|
453773
|
+
if (!isCurrent())
|
|
453774
|
+
return;
|
|
453775
|
+
if (JSON.stringify(buildDeviceStatus(listener, scope).git_context) === gitContextBefore)
|
|
453776
|
+
return;
|
|
453777
|
+
emitDeviceStatusUpdate(transport3, listener, scope, connection ? toListenerConnection(connection.id) : undefined);
|
|
453778
|
+
})().catch((error4) => {
|
|
453779
|
+
trackBoundaryError({
|
|
453780
|
+
errorType: "listener_git_context_refresh_failed",
|
|
453781
|
+
error: error4,
|
|
453782
|
+
context: "listener_state_replay"
|
|
453783
|
+
});
|
|
453784
|
+
});
|
|
453300
453785
|
}
|
|
453301
453786
|
var init_connection_state_sync = __esm(() => {
|
|
453787
|
+
init_error_reporting();
|
|
453302
453788
|
init_approval();
|
|
453303
453789
|
init_connection();
|
|
453304
453790
|
init_protocol_outbound();
|
|
@@ -453307,7 +453793,7 @@ var init_connection_state_sync = __esm(() => {
|
|
|
453307
453793
|
});
|
|
453308
453794
|
|
|
453309
453795
|
// src/websocket/listener/control-inputs.ts
|
|
453310
|
-
import { realpath as
|
|
453796
|
+
import { realpath as realpath7, stat as stat13 } from "node:fs/promises";
|
|
453311
453797
|
import path41 from "node:path";
|
|
453312
453798
|
function trackListenerError(errorType, error4, context3) {
|
|
453313
453799
|
trackBoundaryError({
|
|
@@ -453576,7 +454062,7 @@ async function handleAbortMessageInput(listener, params, deps = {}) {
|
|
|
453576
454062
|
while (cancellation.lease && scopedRuntime.turnLifecycle.isCurrent(cancellation.lease)) {
|
|
453577
454063
|
if (Date.now() >= deadline)
|
|
453578
454064
|
throw new Error("The listener turn did not stop");
|
|
453579
|
-
await new Promise((
|
|
454065
|
+
await new Promise((resolve39) => setTimeout(resolve39, 20));
|
|
453580
454066
|
}
|
|
453581
454067
|
} else {
|
|
453582
454068
|
settlementPromise.catch(() => {
|
|
@@ -453598,7 +454084,7 @@ async function handleCwdChange(msg, socket, runtime) {
|
|
|
453598
454084
|
throw new Error("Working directory cannot be empty");
|
|
453599
454085
|
}
|
|
453600
454086
|
const resolvedPath = path41.isAbsolute(requestedPath) ? requestedPath : path41.resolve(currentWorkingDirectory, requestedPath);
|
|
453601
|
-
const normalizedPath = await
|
|
454087
|
+
const normalizedPath = await realpath7(resolvedPath);
|
|
453602
454088
|
const stats = await stat13(normalizedPath);
|
|
453603
454089
|
if (!stats.isDirectory()) {
|
|
453604
454090
|
throw new Error(`Not a directory: ${normalizedPath}`);
|
|
@@ -453664,7 +454150,7 @@ var init_control_inputs = __esm(() => {
|
|
|
453664
454150
|
});
|
|
453665
454151
|
|
|
453666
454152
|
// src/websocket/listener/grep-in-files.ts
|
|
453667
|
-
import { execFile as
|
|
454153
|
+
import { execFile as execFile20 } from "node:child_process";
|
|
453668
454154
|
import { createRequire as createRequire8 } from "node:module";
|
|
453669
454155
|
import * as path42 from "node:path";
|
|
453670
454156
|
import { fileURLToPath as fileURLToPath10 } from "node:url";
|
|
@@ -453719,8 +454205,8 @@ async function runGrepInFiles(args) {
|
|
|
453719
454205
|
});
|
|
453720
454206
|
}
|
|
453721
454207
|
function runRipgrep2(rgArgs) {
|
|
453722
|
-
return new Promise((
|
|
453723
|
-
const child =
|
|
454208
|
+
return new Promise((resolve39, reject2) => {
|
|
454209
|
+
const child = execFile20(rgPath, rgArgs, {
|
|
453724
454210
|
maxBuffer: 50 * 1024 * 1024,
|
|
453725
454211
|
windowsHide: true
|
|
453726
454212
|
}, (error4, stdout, _stderr) => {
|
|
@@ -453728,7 +454214,7 @@ function runRipgrep2(rgArgs) {
|
|
|
453728
454214
|
reject2(error4);
|
|
453729
454215
|
return;
|
|
453730
454216
|
}
|
|
453731
|
-
|
|
454217
|
+
resolve39(stdout);
|
|
453732
454218
|
});
|
|
453733
454219
|
const timer = setTimeout(() => {
|
|
453734
454220
|
child.kill("SIGTERM");
|
|
@@ -455094,8 +455580,8 @@ function normalizeAbsPath(value) {
|
|
|
455094
455580
|
return path44.resolve(value);
|
|
455095
455581
|
}
|
|
455096
455582
|
function isWithinOrEqual(parent, child) {
|
|
455097
|
-
const
|
|
455098
|
-
return
|
|
455583
|
+
const relative12 = path44.relative(parent, child);
|
|
455584
|
+
return relative12 === "" || !relative12.startsWith("..") && !path44.isAbsolute(relative12);
|
|
455099
455585
|
}
|
|
455100
455586
|
function getHomeDirectory() {
|
|
455101
455587
|
return normalizeAbsPath(process.env.HOME || homedir32());
|
|
@@ -455108,10 +455594,10 @@ function getProtectedHomeSegment(absPath) {
|
|
|
455108
455594
|
const target = normalizeAbsPath(absPath);
|
|
455109
455595
|
if (!isWithinOrEqual(home, target))
|
|
455110
455596
|
return null;
|
|
455111
|
-
const
|
|
455112
|
-
if (!
|
|
455597
|
+
const relative12 = path44.relative(home, target);
|
|
455598
|
+
if (!relative12)
|
|
455113
455599
|
return null;
|
|
455114
|
-
const [firstSegment] =
|
|
455600
|
+
const [firstSegment] = relative12.split(path44.sep);
|
|
455115
455601
|
const normalized = firstSegment?.toLowerCase();
|
|
455116
455602
|
return normalized && PROTECTED_HOME_NAMES.has(normalized) ? normalized : null;
|
|
455117
455603
|
}
|
|
@@ -456229,9 +456715,9 @@ __export(exports_custom, {
|
|
|
456229
456715
|
});
|
|
456230
456716
|
import { existsSync as existsSync63 } from "node:fs";
|
|
456231
456717
|
import { readdir as readdir11, readFile as readFile27 } from "node:fs/promises";
|
|
456232
|
-
import { basename as basename29, dirname as dirname38, join as
|
|
456718
|
+
import { basename as basename29, dirname as dirname38, join as join99 } from "node:path";
|
|
456233
456719
|
function getGlobalCommandsDir() {
|
|
456234
|
-
return
|
|
456720
|
+
return join99(resolveGlobalConfigDir(), "commands");
|
|
456235
456721
|
}
|
|
456236
456722
|
async function getCustomCommands() {
|
|
456237
456723
|
if (cachedCommands !== null) {
|
|
@@ -456243,7 +456729,7 @@ async function getCustomCommands() {
|
|
|
456243
456729
|
function refreshCustomCommands() {
|
|
456244
456730
|
cachedCommands = null;
|
|
456245
456731
|
}
|
|
456246
|
-
async function discoverCustomCommands(projectPath =
|
|
456732
|
+
async function discoverCustomCommands(projectPath = join99(process.cwd(), COMMANDS_DIR)) {
|
|
456247
456733
|
const commandsById = new Map;
|
|
456248
456734
|
const userCommands = await discoverFromDirectory(getGlobalCommandsDir(), "user");
|
|
456249
456735
|
for (const cmd of userCommands) {
|
|
@@ -456275,7 +456761,7 @@ async function findCommandFiles(currentPath, rootPath, commands, source) {
|
|
|
456275
456761
|
try {
|
|
456276
456762
|
const entries2 = await readdir11(currentPath, { withFileTypes: true });
|
|
456277
456763
|
for (const entry of entries2) {
|
|
456278
|
-
const fullPath =
|
|
456764
|
+
const fullPath = join99(currentPath, entry.name);
|
|
456279
456765
|
if (entry.isDirectory()) {
|
|
456280
456766
|
await findCommandFiles(fullPath, rootPath, commands, source);
|
|
456281
456767
|
} else if (entry.isFile() && entry.name.endsWith(".md")) {
|
|
@@ -457671,7 +458157,7 @@ var init_app_server_info = __esm(() => {
|
|
|
457671
458157
|
});
|
|
457672
458158
|
|
|
457673
458159
|
// src/websocket/listener/commands/boot-working-directory.ts
|
|
457674
|
-
import { realpath as
|
|
458160
|
+
import { realpath as realpath8, stat as stat14 } from "node:fs/promises";
|
|
457675
458161
|
import path45 from "node:path";
|
|
457676
458162
|
async function resolveDirectory(requestedPath, currentBootWorkingDirectory) {
|
|
457677
458163
|
const trimmedPath = requestedPath.trim();
|
|
@@ -457679,7 +458165,7 @@ async function resolveDirectory(requestedPath, currentBootWorkingDirectory) {
|
|
|
457679
458165
|
throw new Error("Working directory cannot be empty");
|
|
457680
458166
|
}
|
|
457681
458167
|
const resolvedPath = path45.isAbsolute(trimmedPath) ? trimmedPath : path45.resolve(currentBootWorkingDirectory, trimmedPath);
|
|
457682
|
-
const normalizedPath = await
|
|
458168
|
+
const normalizedPath = await realpath8(resolvedPath);
|
|
457683
458169
|
const stats = await stat14(normalizedPath);
|
|
457684
458170
|
if (!stats.isDirectory()) {
|
|
457685
458171
|
throw new Error(`Not a directory: ${normalizedPath}`);
|
|
@@ -458867,8 +459353,8 @@ var init_cron3 = __esm(() => {
|
|
|
458867
459353
|
});
|
|
458868
459354
|
|
|
458869
459355
|
// src/websocket/listener/commands/git-branches.ts
|
|
458870
|
-
import { execFile as
|
|
458871
|
-
import { promisify as
|
|
459356
|
+
import { execFile as execFile21 } from "node:child_process";
|
|
459357
|
+
import { promisify as promisify19 } from "node:util";
|
|
458872
459358
|
function handleGitBranchCommand(parsed, context3) {
|
|
458873
459359
|
const { socket, runtime, safeSocketSend, runDetachedListenerTask: runDetachedListenerTask2 } = context3;
|
|
458874
459360
|
if (isSearchBranchesCommand(parsed)) {
|
|
@@ -458876,7 +459362,7 @@ function handleGitBranchCommand(parsed, context3) {
|
|
|
458876
459362
|
try {
|
|
458877
459363
|
const cwd2 = parsed.cwd ?? getBootWorkingDirectory(runtime);
|
|
458878
459364
|
const maxResults = parsed.max_results ?? 20;
|
|
458879
|
-
const execFileAsync12 =
|
|
459365
|
+
const execFileAsync12 = promisify19(execFile21);
|
|
458880
459366
|
const { stdout } = await execFileAsync12("git", ["branch", "-a", "--format=%(refname:short)\t%(HEAD)"], {
|
|
458881
459367
|
cwd: cwd2,
|
|
458882
459368
|
encoding: "utf-8",
|
|
@@ -458916,7 +459402,7 @@ function handleGitBranchCommand(parsed, context3) {
|
|
|
458916
459402
|
runDetachedListenerTask2("checkout_branch", async () => {
|
|
458917
459403
|
try {
|
|
458918
459404
|
const cwd2 = parsed.cwd ?? getBootWorkingDirectory(runtime);
|
|
458919
|
-
const execFileAsync12 =
|
|
459405
|
+
const execFileAsync12 = promisify19(execFile21);
|
|
458920
459406
|
const args = parsed.create ? ["checkout", "-b", parsed.branch] : ["checkout", parsed.branch];
|
|
458921
459407
|
await execFileAsync12("git", args, {
|
|
458922
459408
|
cwd: cwd2,
|
|
@@ -458986,8 +459472,8 @@ async function awaitMemoryPushBounded(commandName, agentId, memoryRoot) {
|
|
|
458986
459472
|
}
|
|
458987
459473
|
};
|
|
458988
459474
|
let timer;
|
|
458989
|
-
const capPromise = new Promise((
|
|
458990
|
-
timer = setTimeout(() =>
|
|
459475
|
+
const capPromise = new Promise((resolve39) => {
|
|
459476
|
+
timer = setTimeout(() => resolve39("timed_out"), MEMORY_PUSH_AWAIT_CAP_MS);
|
|
458991
459477
|
});
|
|
458992
459478
|
try {
|
|
458993
459479
|
const result3 = await Promise.race([syncPromise, capPromise]);
|
|
@@ -459019,9 +459505,9 @@ async function handleListMemoryCommand(parsed, socket, safeSocketSend, overrides
|
|
|
459019
459505
|
const { scanMemoryFilesystem: scanMemoryFilesystem2, getFileNodes: getFileNodes2, readFileContent: readFileContent2 } = await Promise.resolve().then(() => (init_memory_scanner(), exports_memory_scanner));
|
|
459020
459506
|
const { parseFrontmatter: parseFrontmatter2 } = await Promise.resolve().then(() => exports_frontmatter);
|
|
459021
459507
|
const { existsSync: existsSync64, statSync: statSync26 } = await import("node:fs");
|
|
459022
|
-
const { join:
|
|
459508
|
+
const { join: join100, posix: posix4 } = await import("node:path");
|
|
459023
459509
|
const memoryRoot = getMemoryFilesystemRoot2(parsed.agent_id);
|
|
459024
|
-
let memfsInitialized = existsSync64(
|
|
459510
|
+
let memfsInitialized = existsSync64(join100(memoryRoot, ".git"));
|
|
459025
459511
|
const memfsEnabled = memfsInitialized ? true : await isMemfsEnabledOnServer2(parsed.agent_id);
|
|
459026
459512
|
if (!memfsEnabled) {
|
|
459027
459513
|
safeSocketSend(socket, {
|
|
@@ -459039,7 +459525,7 @@ async function handleListMemoryCommand(parsed, socket, safeSocketSend, overrides
|
|
|
459039
459525
|
await ensureLocalMemfsCheckout2(parsed.agent_id, {
|
|
459040
459526
|
pullOnExistingRepo: true
|
|
459041
459527
|
});
|
|
459042
|
-
memfsInitialized = existsSync64(
|
|
459528
|
+
memfsInitialized = existsSync64(join100(memoryRoot, ".git"));
|
|
459043
459529
|
if (!memfsInitialized) {
|
|
459044
459530
|
throw new Error("MemFS is enabled, but the local memory checkout could not be initialized.");
|
|
459045
459531
|
}
|
|
@@ -459225,8 +459711,8 @@ function handleMemoryProtocolCommand(parsed, context3) {
|
|
|
459225
459711
|
runDetachedListenerTask2("memory_history", async () => {
|
|
459226
459712
|
const { getScopedMemoryFilesystemRoot: getScopedMemoryFilesystemRoot2 } = await Promise.resolve().then(() => (init_memory_filesystem2(), exports_memory_filesystem));
|
|
459227
459713
|
const { execFile: execFileCb4 } = await import("node:child_process");
|
|
459228
|
-
const { promisify:
|
|
459229
|
-
const execFileAsync12 =
|
|
459714
|
+
const { promisify: promisify20 } = await import("node:util");
|
|
459715
|
+
const execFileAsync12 = promisify20(execFileCb4);
|
|
459230
459716
|
const memoryRoot = getScopedMemoryFilesystemRoot2(parsed.agent_id);
|
|
459231
459717
|
const limit4 = parsed.limit ?? 50;
|
|
459232
459718
|
const gitArgs = ["log", `--max-count=${limit4}`, "--format=%H|%s|%aI|%an"];
|
|
@@ -459261,8 +459747,8 @@ function handleMemoryProtocolCommand(parsed, context3) {
|
|
|
459261
459747
|
runDetachedListenerTask2("memory_file_at_ref", async () => {
|
|
459262
459748
|
const { getScopedMemoryFilesystemRoot: getScopedMemoryFilesystemRoot2 } = await Promise.resolve().then(() => (init_memory_filesystem2(), exports_memory_filesystem));
|
|
459263
459749
|
const { execFile: execFileCb4 } = await import("node:child_process");
|
|
459264
|
-
const { promisify:
|
|
459265
|
-
const execFileAsync12 =
|
|
459750
|
+
const { promisify: promisify20 } = await import("node:util");
|
|
459751
|
+
const execFileAsync12 = promisify20(execFileCb4);
|
|
459266
459752
|
const memoryRoot = getScopedMemoryFilesystemRoot2(parsed.agent_id);
|
|
459267
459753
|
try {
|
|
459268
459754
|
const { stdout } = await execFileAsync12("git", ["show", `${parsed.ref}:${parsed.file_path}`], { cwd: memoryRoot, timeout: 1e4 });
|
|
@@ -459292,8 +459778,8 @@ function handleMemoryProtocolCommand(parsed, context3) {
|
|
|
459292
459778
|
runDetachedListenerTask2("memory_commit_diff", async () => {
|
|
459293
459779
|
const { getScopedMemoryFilesystemRoot: getScopedMemoryFilesystemRoot2 } = await Promise.resolve().then(() => (init_memory_filesystem2(), exports_memory_filesystem));
|
|
459294
459780
|
const { execFile: execFileCb4 } = await import("node:child_process");
|
|
459295
|
-
const { promisify:
|
|
459296
|
-
const execFileAsync12 =
|
|
459781
|
+
const { promisify: promisify20 } = await import("node:util");
|
|
459782
|
+
const execFileAsync12 = promisify20(execFileCb4);
|
|
459297
459783
|
const memoryRoot = getScopedMemoryFilesystemRoot2(parsed.agent_id);
|
|
459298
459784
|
try {
|
|
459299
459785
|
const { stdout } = await execFileAsync12("git", ["show", parsed.sha, "--format=", "--no-color"], { cwd: memoryRoot, timeout: 1e4 });
|
|
@@ -459340,33 +459826,33 @@ function handleMemoryProtocolCommand(parsed, context3) {
|
|
|
459340
459826
|
} = await Promise.resolve().then(() => (init_memory_filesystem2(), exports_memory_filesystem));
|
|
459341
459827
|
const { readFile: readFile28 } = await import("node:fs/promises");
|
|
459342
459828
|
const { existsSync: existsSync64 } = await import("node:fs");
|
|
459343
|
-
const { isAbsolute:
|
|
459344
|
-
if (
|
|
459829
|
+
const { isAbsolute: isAbsolute28, join: join100, normalize: normalize5, relative: relative12, sep: sep9 } = await import("node:path");
|
|
459830
|
+
if (isAbsolute28(parsed.path) || parsed.path.length === 0) {
|
|
459345
459831
|
sendFailure("path must be a non-empty relative path");
|
|
459346
459832
|
return;
|
|
459347
459833
|
}
|
|
459348
459834
|
const memoryRoot = getScopedMemoryFilesystemRoot2(parsed.agent_id);
|
|
459349
|
-
const absolutePath = normalize5(
|
|
459350
|
-
const rel =
|
|
459351
|
-
if (rel.startsWith("..") || rel === "" ||
|
|
459835
|
+
const absolutePath = normalize5(join100(memoryRoot, parsed.path));
|
|
459836
|
+
const rel = relative12(memoryRoot, absolutePath);
|
|
459837
|
+
if (rel.startsWith("..") || rel === "" || isAbsolute28(rel) || rel.split(sep9).includes("..")) {
|
|
459352
459838
|
sendFailure("path must resolve inside the memory root");
|
|
459353
459839
|
return;
|
|
459354
459840
|
}
|
|
459355
|
-
if (!existsSync64(
|
|
459841
|
+
if (!existsSync64(join100(memoryRoot, ".git"))) {
|
|
459356
459842
|
const enabled = await isMemfsEnabledOnServer2(parsed.agent_id);
|
|
459357
459843
|
if (!enabled) {
|
|
459358
459844
|
sendFailure("memfs is not enabled for this agent");
|
|
459359
459845
|
return;
|
|
459360
459846
|
}
|
|
459361
459847
|
await ensureLocalMemfsCheckout2(parsed.agent_id);
|
|
459362
|
-
if (!existsSync64(
|
|
459848
|
+
if (!existsSync64(join100(memoryRoot, ".git"))) {
|
|
459363
459849
|
sendFailure("failed to initialize local memory checkout");
|
|
459364
459850
|
return;
|
|
459365
459851
|
}
|
|
459366
459852
|
}
|
|
459367
459853
|
const buffer = await readFile28(absolutePath);
|
|
459368
459854
|
const content = encoding === "base64" ? buffer.toString("base64") : buffer.toString("utf-8");
|
|
459369
|
-
const pathspec = rel.split(
|
|
459855
|
+
const pathspec = rel.split(sep9).join("/");
|
|
459370
459856
|
safeSocketSend(socket, {
|
|
459371
459857
|
type: "read_memory_file_response",
|
|
459372
459858
|
request_id: parsed.request_id,
|
|
@@ -459406,26 +459892,26 @@ function handleMemoryProtocolCommand(parsed, context3) {
|
|
|
459406
459892
|
const { commitMemoryWrite: commitMemoryWrite2 } = await Promise.resolve().then(() => (init_memory_git(), exports_memory_git));
|
|
459407
459893
|
const { writeFile: writeFile17, mkdir: mkdir15 } = await import("node:fs/promises");
|
|
459408
459894
|
const { existsSync: existsSync64 } = await import("node:fs");
|
|
459409
|
-
const { dirname: dirname39, isAbsolute:
|
|
459410
|
-
if (
|
|
459895
|
+
const { dirname: dirname39, isAbsolute: isAbsolute28, join: join100, normalize: normalize5, relative: relative12, sep: sep9 } = await import("node:path");
|
|
459896
|
+
if (isAbsolute28(parsed.path) || parsed.path.length === 0) {
|
|
459411
459897
|
sendFailure("write_memory_file: path must be a non-empty relative path");
|
|
459412
459898
|
return;
|
|
459413
459899
|
}
|
|
459414
459900
|
const memoryRoot = getScopedMemoryFilesystemRoot2(parsed.agent_id);
|
|
459415
|
-
const absolutePath = normalize5(
|
|
459416
|
-
const rel =
|
|
459417
|
-
if (rel.startsWith("..") || rel === "" ||
|
|
459901
|
+
const absolutePath = normalize5(join100(memoryRoot, parsed.path));
|
|
459902
|
+
const rel = relative12(memoryRoot, absolutePath);
|
|
459903
|
+
if (rel.startsWith("..") || rel === "" || isAbsolute28(rel) || rel.split(sep9).includes("..")) {
|
|
459418
459904
|
sendFailure("write_memory_file: path must resolve inside the memory root");
|
|
459419
459905
|
return;
|
|
459420
459906
|
}
|
|
459421
|
-
if (!existsSync64(
|
|
459907
|
+
if (!existsSync64(join100(memoryRoot, ".git"))) {
|
|
459422
459908
|
const enabled = await isMemfsEnabledOnServer2(parsed.agent_id);
|
|
459423
459909
|
if (!enabled) {
|
|
459424
459910
|
sendFailure("write_memory_file: memfs is not enabled for this agent");
|
|
459425
459911
|
return;
|
|
459426
459912
|
}
|
|
459427
459913
|
await ensureLocalMemfsCheckout2(parsed.agent_id);
|
|
459428
|
-
if (!existsSync64(
|
|
459914
|
+
if (!existsSync64(join100(memoryRoot, ".git"))) {
|
|
459429
459915
|
sendFailure("write_memory_file: failed to initialize local memory checkout");
|
|
459430
459916
|
return;
|
|
459431
459917
|
}
|
|
@@ -459443,7 +459929,7 @@ function handleMemoryProtocolCommand(parsed, context3) {
|
|
|
459443
459929
|
agentName = agent.name.trim();
|
|
459444
459930
|
}
|
|
459445
459931
|
} catch {}
|
|
459446
|
-
const pathspec = rel.split(
|
|
459932
|
+
const pathspec = rel.split(sep9).join("/");
|
|
459447
459933
|
const reason = parsed.commit_message?.trim() || `Update memory file ${pathspec}`;
|
|
459448
459934
|
const commitResult = await commitMemoryWrite2({
|
|
459449
459935
|
memoryDir: memoryRoot,
|
|
@@ -459504,31 +459990,31 @@ function handleMemoryProtocolCommand(parsed, context3) {
|
|
|
459504
459990
|
const { commitMemoryWrite: commitMemoryWrite2 } = await Promise.resolve().then(() => (init_memory_git(), exports_memory_git));
|
|
459505
459991
|
const { unlink: unlink3 } = await import("node:fs/promises");
|
|
459506
459992
|
const { existsSync: existsSync64 } = await import("node:fs");
|
|
459507
|
-
const { isAbsolute:
|
|
459508
|
-
if (
|
|
459993
|
+
const { isAbsolute: isAbsolute28, join: join100, normalize: normalize5, relative: relative12, sep: sep9 } = await import("node:path");
|
|
459994
|
+
if (isAbsolute28(parsed.path) || parsed.path.length === 0) {
|
|
459509
459995
|
sendFailure("delete_memory_file: path must be a non-empty relative path");
|
|
459510
459996
|
return;
|
|
459511
459997
|
}
|
|
459512
459998
|
const memoryRoot = getScopedMemoryFilesystemRoot2(parsed.agent_id);
|
|
459513
|
-
const absolutePath = normalize5(
|
|
459514
|
-
const rel =
|
|
459515
|
-
if (rel.startsWith("..") || rel === "" ||
|
|
459999
|
+
const absolutePath = normalize5(join100(memoryRoot, parsed.path));
|
|
460000
|
+
const rel = relative12(memoryRoot, absolutePath);
|
|
460001
|
+
if (rel.startsWith("..") || rel === "" || isAbsolute28(rel) || rel.split(sep9).includes("..")) {
|
|
459516
460002
|
sendFailure("delete_memory_file: path must resolve inside the memory root");
|
|
459517
460003
|
return;
|
|
459518
460004
|
}
|
|
459519
|
-
if (!existsSync64(
|
|
460005
|
+
if (!existsSync64(join100(memoryRoot, ".git"))) {
|
|
459520
460006
|
const enabled = await isMemfsEnabledOnServer2(parsed.agent_id);
|
|
459521
460007
|
if (!enabled) {
|
|
459522
460008
|
sendFailure("delete_memory_file: memfs is not enabled for this agent");
|
|
459523
460009
|
return;
|
|
459524
460010
|
}
|
|
459525
460011
|
await ensureLocalMemfsCheckout2(parsed.agent_id);
|
|
459526
|
-
if (!existsSync64(
|
|
460012
|
+
if (!existsSync64(join100(memoryRoot, ".git"))) {
|
|
459527
460013
|
sendFailure("delete_memory_file: failed to initialize local memory checkout");
|
|
459528
460014
|
return;
|
|
459529
460015
|
}
|
|
459530
460016
|
}
|
|
459531
|
-
const pathspec = rel.split(
|
|
460017
|
+
const pathspec = rel.split(sep9).join("/");
|
|
459532
460018
|
const removeIfPresent = async () => {
|
|
459533
460019
|
if (!existsSync64(absolutePath))
|
|
459534
460020
|
return false;
|
|
@@ -459618,12 +460104,14 @@ var init_memory5 = __esm(() => {
|
|
|
459618
460104
|
function createMemfsSyncedTaskRunner(parsed, runtime, runDetachedListenerTask2) {
|
|
459619
460105
|
const command = parsed;
|
|
459620
460106
|
const agentId = command.agent_id;
|
|
459621
|
-
if (typeof agentId !== "string" || command.type === "enable_memfs") {
|
|
460107
|
+
if (typeof agentId !== "string" || command.type === "enable_memfs" && !isMemoryUnavailable(agentId)) {
|
|
459622
460108
|
return runDetachedListenerTask2;
|
|
459623
460109
|
}
|
|
459624
460110
|
return (commandName, task2) => {
|
|
459625
460111
|
runDetachedListenerTask2(commandName, async () => {
|
|
459626
|
-
await ensureMemfsSyncedForAgent(runtime, agentId)
|
|
460112
|
+
if (!await ensureMemfsSyncedForAgent(runtime, agentId)) {
|
|
460113
|
+
throw new Error("Memory is not available on this machine.");
|
|
460114
|
+
}
|
|
459627
460115
|
await task2();
|
|
459628
460116
|
});
|
|
459629
460117
|
};
|
|
@@ -459636,6 +460124,7 @@ function handleMemfsSyncedMemoryProtocolCommand(parsed, context3) {
|
|
|
459636
460124
|
});
|
|
459637
460125
|
}
|
|
459638
460126
|
var init_memory_command_sync = __esm(() => {
|
|
460127
|
+
init_memory_access();
|
|
459639
460128
|
init_memfs_sync();
|
|
459640
460129
|
init_memory5();
|
|
459641
460130
|
});
|
|
@@ -459654,10 +460143,10 @@ __export(exports_remote_model_catalog, {
|
|
|
459654
460143
|
__testResetRemoteModelCatalog: () => __testResetRemoteModelCatalog
|
|
459655
460144
|
});
|
|
459656
460145
|
import { existsSync as existsSync64, mkdirSync as mkdirSync50, readFileSync as readFileSync51, writeFileSync as writeFileSync43 } from "node:fs";
|
|
459657
|
-
import { dirname as dirname39, join as
|
|
460146
|
+
import { dirname as dirname39, join as join100 } from "node:path";
|
|
459658
460147
|
function catalogCachePath() {
|
|
459659
|
-
const dir = process.env.LETTA_MODEL_CATALOG_CACHE_DIR ||
|
|
459660
|
-
return
|
|
460148
|
+
const dir = process.env.LETTA_MODEL_CATALOG_CACHE_DIR || join100(resolveGlobalConfigDir(), "cache");
|
|
460149
|
+
return join100(dir, "model-catalog.json");
|
|
459661
460150
|
}
|
|
459662
460151
|
function normalizeCatalogSource(source) {
|
|
459663
460152
|
try {
|
|
@@ -460812,10 +461301,20 @@ async function handleRuntimeStartCommand(parsed, context3) {
|
|
|
460812
461301
|
let startResponseSent = false;
|
|
460813
461302
|
try {
|
|
460814
461303
|
validateRuntimeStartShape(parsed);
|
|
460815
|
-
agent = await resolveRuntimeStartAgent(parsed, created);
|
|
460816
461304
|
const backend3 = getBackend();
|
|
460817
461305
|
const createEphemeral = context3.createEphemeralConversation ?? backend3.createEphemeralConversation?.bind(backend3) ?? createEphemeralConversation;
|
|
460818
|
-
|
|
461306
|
+
const retrieveConversation = context3.retrieveConversation ?? ((id) => backend3.retrieveConversation(id));
|
|
461307
|
+
let retrievedConversation;
|
|
461308
|
+
if (hasString(parsed.conversation_id) && parsed.conversation_id !== "default") {
|
|
461309
|
+
[agent, retrievedConversation] = await Promise.all([
|
|
461310
|
+
resolveRuntimeStartAgent(parsed, created),
|
|
461311
|
+
retrieveConversation(parsed.conversation_id)
|
|
461312
|
+
]);
|
|
461313
|
+
} else {
|
|
461314
|
+
agent = await resolveRuntimeStartAgent(parsed, created);
|
|
461315
|
+
}
|
|
461316
|
+
const cachedConversation = retrievedConversation;
|
|
461317
|
+
conversation = await resolveRuntimeStartConversation(parsed, agent, created, createEphemeral, cachedConversation ? async () => cachedConversation : retrieveConversation);
|
|
460819
461318
|
conversation = await applyRuntimeStartConversationSourceTags(parsed, conversation);
|
|
460820
461319
|
runtimeScope = buildRuntimeScope(agent, conversation);
|
|
460821
461320
|
const { connectionId } = context3;
|
|
@@ -461066,7 +461565,7 @@ async function handleSkillCommand(parsed, socket, safeSocketSend) {
|
|
|
461066
461565
|
symlinkSync: symlinkSync2,
|
|
461067
461566
|
unlinkSync: unlinkSync18
|
|
461068
461567
|
} = await import("node:fs");
|
|
461069
|
-
const { basename: basename30, join:
|
|
461568
|
+
const { basename: basename30, join: join101 } = await import("node:path");
|
|
461070
461569
|
const globalSkillsDir = getGlobalSkillsDir();
|
|
461071
461570
|
if (parsed.type === "skill_enable") {
|
|
461072
461571
|
try {
|
|
@@ -461079,7 +461578,7 @@ async function handleSkillCommand(parsed, socket, safeSocketSend) {
|
|
|
461079
461578
|
}, "listener_skill_send_failed", "listener_skill_command");
|
|
461080
461579
|
return true;
|
|
461081
461580
|
}
|
|
461082
|
-
const skillMdPath =
|
|
461581
|
+
const skillMdPath = join101(parsed.skill_path, "SKILL.md");
|
|
461083
461582
|
if (!existsSync65(skillMdPath)) {
|
|
461084
461583
|
safeSocketSend(socket, {
|
|
461085
461584
|
type: "skill_enable_response",
|
|
@@ -461090,7 +461589,7 @@ async function handleSkillCommand(parsed, socket, safeSocketSend) {
|
|
|
461090
461589
|
return true;
|
|
461091
461590
|
}
|
|
461092
461591
|
const linkName = basename30(parsed.skill_path);
|
|
461093
|
-
const linkPath =
|
|
461592
|
+
const linkPath = join101(globalSkillsDir, linkName);
|
|
461094
461593
|
mkdirSync51(globalSkillsDir, { recursive: true });
|
|
461095
461594
|
if (existsSync65(linkPath)) {
|
|
461096
461595
|
const stat15 = lstatSync4(linkPath);
|
|
@@ -461133,7 +461632,7 @@ async function handleSkillCommand(parsed, socket, safeSocketSend) {
|
|
|
461133
461632
|
}
|
|
461134
461633
|
if (parsed.type === "skill_disable") {
|
|
461135
461634
|
try {
|
|
461136
|
-
const linkPath =
|
|
461635
|
+
const linkPath = join101(globalSkillsDir, parsed.name);
|
|
461137
461636
|
if (!existsSync65(linkPath)) {
|
|
461138
461637
|
safeSocketSend(socket, {
|
|
461139
461638
|
type: "skill_disable_response",
|
|
@@ -461905,7 +462404,7 @@ async function waitForPairedSocketAcceptance(socket, identity3) {
|
|
|
461905
462404
|
return { status: "closed" };
|
|
461906
462405
|
}
|
|
461907
462406
|
const timeoutMs = getStreamOpenTimeoutMs();
|
|
461908
|
-
return await new Promise((
|
|
462407
|
+
return await new Promise((resolve39) => {
|
|
461909
462408
|
let settled = false;
|
|
461910
462409
|
const timeout = setTimeout(() => settle3({ status: "timed_out", timeoutMs }), timeoutMs);
|
|
461911
462410
|
timeout.unref?.();
|
|
@@ -461920,7 +462419,7 @@ async function waitForPairedSocketAcceptance(socket, identity3) {
|
|
|
461920
462419
|
return;
|
|
461921
462420
|
settled = true;
|
|
461922
462421
|
cleanup();
|
|
461923
|
-
|
|
462422
|
+
resolve39(result3);
|
|
461924
462423
|
}
|
|
461925
462424
|
function handleFailure() {
|
|
461926
462425
|
settle3({ status: "closed" });
|
|
@@ -461948,7 +462447,7 @@ async function waitForStreamSocketOpen(streamSocket) {
|
|
|
461948
462447
|
return { status: "closed" };
|
|
461949
462448
|
}
|
|
461950
462449
|
const timeoutMs = getStreamOpenTimeoutMs();
|
|
461951
|
-
return await new Promise((
|
|
462450
|
+
return await new Promise((resolve39) => {
|
|
461952
462451
|
let timeout = null;
|
|
461953
462452
|
let settled = false;
|
|
461954
462453
|
function cleanup() {
|
|
@@ -461966,7 +462465,7 @@ async function waitForStreamSocketOpen(streamSocket) {
|
|
|
461966
462465
|
}
|
|
461967
462466
|
settled = true;
|
|
461968
462467
|
cleanup();
|
|
461969
|
-
|
|
462468
|
+
resolve39(result3);
|
|
461970
462469
|
}
|
|
461971
462470
|
function handleOpen() {
|
|
461972
462471
|
settle3({ status: "open", transport: streamSocket });
|
|
@@ -462146,6 +462645,12 @@ async function stopMonitor(command) {
|
|
|
462146
462645
|
return { ...response, success: true };
|
|
462147
462646
|
if (!killBackgroundProcess(command.process_id))
|
|
462148
462647
|
return { ...response, error: "Monitor could not be stopped" };
|
|
462648
|
+
let persistenceError;
|
|
462649
|
+
try {
|
|
462650
|
+
await process21.persistState?.();
|
|
462651
|
+
} catch {
|
|
462652
|
+
persistenceError = "Monitor stopped, but its server state could not be saved";
|
|
462653
|
+
}
|
|
462149
462654
|
addToMessageQueue({
|
|
462150
462655
|
kind: "task_notification",
|
|
462151
462656
|
agentId: command.runtime.agent_id,
|
|
@@ -462156,7 +462661,12 @@ async function stopMonitor(command) {
|
|
|
462156
462661
|
event: "The user cancelled this Monitor. Do not restart it unless the user asks."
|
|
462157
462662
|
})
|
|
462158
462663
|
});
|
|
462159
|
-
return {
|
|
462664
|
+
return {
|
|
462665
|
+
...response,
|
|
462666
|
+
success: !persistenceError,
|
|
462667
|
+
stopped: true,
|
|
462668
|
+
...persistenceError ? { error: persistenceError } : {}
|
|
462669
|
+
};
|
|
462160
462670
|
}
|
|
462161
462671
|
var init_stop_monitor = __esm(() => {
|
|
462162
462672
|
init_message_queue_bridge();
|
|
@@ -462180,7 +462690,7 @@ async function handleMonitorStopCommand(command, runtime) {
|
|
|
462180
462690
|
}
|
|
462181
462691
|
return stopMonitor(command);
|
|
462182
462692
|
}
|
|
462183
|
-
var
|
|
462693
|
+
var init_monitors2 = __esm(() => {
|
|
462184
462694
|
init_stop_monitor();
|
|
462185
462695
|
init_runtime6();
|
|
462186
462696
|
});
|
|
@@ -462200,19 +462710,25 @@ function finishUntrackedNativeCapture2(completion, reservation, source, sessionI
|
|
|
462200
462710
|
completion.then(() => reservation.capture(), () => reservation.capture()).catch((error4) => reportNativeSessionCaptureFailure(source, sessionId, error4));
|
|
462201
462711
|
}
|
|
462202
462712
|
function findOwnedTask(runtime, agentId) {
|
|
462203
|
-
const subagent = getSubagents().find((entry) => entry.agentId === agentId && entry.parentAgentId === runtime.agentId
|
|
462713
|
+
const subagent = getSubagents().find((entry) => entry.agentId === agentId && entry.parentAgentId === runtime.agentId);
|
|
462204
462714
|
if (!subagent)
|
|
462205
462715
|
return;
|
|
462206
462716
|
return [...backgroundTasks.entries()].find(([, task2]) => task2.subagentId === subagent.id);
|
|
462207
462717
|
}
|
|
462208
|
-
function
|
|
462718
|
+
function nativeSessionOwner(agentId) {
|
|
462209
462719
|
const target = parseExternalCodingAgentId(agentId);
|
|
462210
462720
|
if (!target || target.computer)
|
|
462211
|
-
return
|
|
462721
|
+
return;
|
|
462212
462722
|
if (target.type !== "claude-code" && target.type !== "codex")
|
|
462213
|
-
return
|
|
462214
|
-
|
|
462215
|
-
|
|
462723
|
+
return;
|
|
462724
|
+
return getNativeSessionOwner(target.type === "claude-code" ? "claude_code" : "codex", target.sessionId);
|
|
462725
|
+
}
|
|
462726
|
+
function ownsNativeSession(runtime, agentId) {
|
|
462727
|
+
return nativeSessionOwner(agentId)?.agentId === runtime.agentId;
|
|
462728
|
+
}
|
|
462729
|
+
function subagentAccessError(agentId) {
|
|
462730
|
+
const known = getSubagents().some((entry) => entry.agentId === agentId) || nativeSessionOwner(agentId);
|
|
462731
|
+
return known ? "Subagent does not belong to this conversation" : `Subagent ${agentId} was not found on this computer`;
|
|
462216
462732
|
}
|
|
462217
462733
|
function runtimeContext(parent, command) {
|
|
462218
462734
|
return {
|
|
@@ -462246,7 +462762,7 @@ async function handleSubagentMessageCommand(command, parent, deps = {}) {
|
|
|
462246
462762
|
if (parent.agentId !== command.runtime.agent_id || parent.conversationId !== command.runtime.conversation_id)
|
|
462247
462763
|
throw new Error("Parent runtime does not match the message request");
|
|
462248
462764
|
if (!findOwnedTask(parent, command.agent_id) && !ownsNativeSession(parent, command.agent_id))
|
|
462249
|
-
throw new Error(
|
|
462765
|
+
throw new Error(subagentAccessError(command.agent_id));
|
|
462250
462766
|
const target = parseExternalCodingAgentId(command.agent_id);
|
|
462251
462767
|
if (!target || target.computer || !isExternalCodingAgentType(target.type))
|
|
462252
462768
|
throw new Error("Invalid external coding agent ID");
|
|
@@ -462399,7 +462915,7 @@ async function handleSubagentStopCommand(command, parent) {
|
|
|
462399
462915
|
stopped: nativeStopped,
|
|
462400
462916
|
cleanup_confirmed: true
|
|
462401
462917
|
};
|
|
462402
|
-
return { ...base2, error:
|
|
462918
|
+
return { ...base2, error: subagentAccessError(command.agent_id) };
|
|
462403
462919
|
}
|
|
462404
462920
|
const [taskId, task2] = owned;
|
|
462405
462921
|
if (task2.status !== "running")
|
|
@@ -462440,7 +462956,7 @@ function handleReadSubagentEventsCommand(command) {
|
|
|
462440
462956
|
subagent_id: command.subagent_id
|
|
462441
462957
|
};
|
|
462442
462958
|
const subagent = getSubagents().find((entry) => entry.id === command.subagent_id);
|
|
462443
|
-
if (!subagent || subagent.parentAgentId !== command.runtime.agent_id
|
|
462959
|
+
if (!subagent || subagent.parentAgentId !== command.runtime.agent_id)
|
|
462444
462960
|
return {
|
|
462445
462961
|
...base2,
|
|
462446
462962
|
success: false,
|
|
@@ -462572,7 +463088,7 @@ async function handleTaskControlCommand(command, context3) {
|
|
|
462572
463088
|
}
|
|
462573
463089
|
}
|
|
462574
463090
|
var init_task_control = __esm(() => {
|
|
462575
|
-
|
|
463091
|
+
init_monitors2();
|
|
462576
463092
|
init_stop_conversation();
|
|
462577
463093
|
init_subagent_control();
|
|
462578
463094
|
init_subagent_events2();
|
|
@@ -463106,7 +463622,7 @@ var init_message_router = __esm(() => {
|
|
|
463106
463622
|
});
|
|
463107
463623
|
|
|
463108
463624
|
// src/websocket/listener/process-services.ts
|
|
463109
|
-
import { join as
|
|
463625
|
+
import { join as join101 } from "node:path";
|
|
463110
463626
|
function installProcessEventRouting(params) {
|
|
463111
463627
|
const { runtime, processTransport, opts, processQueuedTurn } = params;
|
|
463112
463628
|
runtime._unsubscribeSubagentState?.();
|
|
@@ -463196,7 +463712,7 @@ function installProcessEventRouting(params) {
|
|
|
463196
463712
|
scheduleQueuePump(targetRuntime, processTransport, opts, processQueuedTurn);
|
|
463197
463713
|
});
|
|
463198
463714
|
runtime._stopDiskSpaceWatch?.();
|
|
463199
|
-
runtime._stopDiskSpaceWatch = watchSandboxDiskSpace(getCurrentWorkingDirectory, (text3) => deliverSandboxDiskAlert(runtime, text3), { reserveDirectory:
|
|
463715
|
+
runtime._stopDiskSpaceWatch = watchSandboxDiskSpace(getCurrentWorkingDirectory, (text3) => deliverSandboxDiskAlert(runtime, text3), { reserveDirectory: join101(resolveGlobalConfigDir(), "state") });
|
|
463200
463716
|
}
|
|
463201
463717
|
function deliverSandboxDiskAlert(runtime, text3) {
|
|
463202
463718
|
const target = getMostRecentlyActiveConversation(runtime);
|
|
@@ -464270,11 +464786,11 @@ async function replaySyncStateForRuntime(listenerRuntime, socket, scope, opts) {
|
|
|
464270
464786
|
if (syncScopedRuntime.recoveredApprovalState && (syncScopedRuntime.recoveredApprovalState.autoDecisions?.length ?? 0) > 0) {
|
|
464271
464787
|
let signalLeaseReady;
|
|
464272
464788
|
let releaseLeaseBarrier;
|
|
464273
|
-
const leaseReady = new Promise((
|
|
464274
|
-
signalLeaseReady =
|
|
464789
|
+
const leaseReady = new Promise((resolve39) => {
|
|
464790
|
+
signalLeaseReady = resolve39;
|
|
464275
464791
|
});
|
|
464276
|
-
const leaseBarrier = new Promise((
|
|
464277
|
-
releaseLeaseBarrier =
|
|
464792
|
+
const leaseBarrier = new Promise((resolve39) => {
|
|
464793
|
+
releaseLeaseBarrier = resolve39;
|
|
464278
464794
|
});
|
|
464279
464795
|
const recovery = startRecoveredApprovalContinuation(syncScopedRuntime, getOrCreateProcessTransport(listenerRuntime), opts?.processIncomingMessage ?? handleIncomingMessage, {
|
|
464280
464796
|
onStatusChange: opts?.onStatusChange,
|
|
@@ -464678,8 +465194,8 @@ async function connectWithRetry(runtime, opts, attempt2 = 0, startTime = Date.no
|
|
|
464678
465194
|
}
|
|
464679
465195
|
const delay7 = Math.min(INITIAL_RETRY_DELAY_MS2 * 2 ** (attempt2 - 1), MAX_RETRY_DELAY_MS);
|
|
464680
465196
|
opts.onRetrying?.(attempt2, MAX_RETRY_ATTEMPTS, delay7, opts.connectionId);
|
|
464681
|
-
await new Promise((
|
|
464682
|
-
runtime.reconnectTimeout = setTimeout(
|
|
465197
|
+
await new Promise((resolve39) => {
|
|
465198
|
+
runtime.reconnectTimeout = setTimeout(resolve39, delay7);
|
|
464683
465199
|
});
|
|
464684
465200
|
runtime.reconnectTimeout = null;
|
|
464685
465201
|
if (runtime !== getActiveRuntime() || runtime.intentionallyClosed) {
|
|
@@ -465040,7 +465556,7 @@ async function runTurnViaListenerRuntime(params) {
|
|
|
465040
465556
|
}
|
|
465041
465557
|
};
|
|
465042
465558
|
const processQueuedTurn = createConnectionTurnProcessor(listener);
|
|
465043
|
-
return await new Promise((
|
|
465559
|
+
return await new Promise((resolve39) => {
|
|
465044
465560
|
let text3 = "";
|
|
465045
465561
|
let reasoning = "";
|
|
465046
465562
|
let usage = {
|
|
@@ -465067,7 +465583,7 @@ async function runTurnViaListenerRuntime(params) {
|
|
|
465067
465583
|
observers.delete(observer);
|
|
465068
465584
|
unregisterTurnObserver();
|
|
465069
465585
|
toolTracker?.dispose();
|
|
465070
|
-
|
|
465586
|
+
resolve39({ text: text3, reasoning, usage, error: error4 });
|
|
465071
465587
|
};
|
|
465072
465588
|
const observer = (message2) => {
|
|
465073
465589
|
if (message2.type === "runtime_stopped") {
|
|
@@ -466207,14 +466723,14 @@ async function startAppServer(options = {}) {
|
|
|
466207
466723
|
clearInterval(heartbeatInterval);
|
|
466208
466724
|
});
|
|
466209
466725
|
try {
|
|
466210
|
-
await new Promise((
|
|
466726
|
+
await new Promise((resolve39, reject2) => {
|
|
466211
466727
|
const onError = (error4) => {
|
|
466212
466728
|
server2.off("listening", onListening);
|
|
466213
466729
|
reject2(error4);
|
|
466214
466730
|
};
|
|
466215
466731
|
const onListening = () => {
|
|
466216
466732
|
server2.off("error", onError);
|
|
466217
|
-
|
|
466733
|
+
resolve39();
|
|
466218
466734
|
};
|
|
466219
466735
|
server2.once("error", onError);
|
|
466220
466736
|
server2.once("listening", onListening);
|
|
@@ -466235,7 +466751,7 @@ async function startAppServer(options = {}) {
|
|
|
466235
466751
|
setActiveRuntime(runtime);
|
|
466236
466752
|
} else if (getActiveRuntime() !== runtime) {
|
|
466237
466753
|
clearInterval(heartbeatInterval);
|
|
466238
|
-
await new Promise((
|
|
466754
|
+
await new Promise((resolve39) => server2.close(() => resolve39()));
|
|
466239
466755
|
throw new Error("Shared app-server runtime must be the active listener runtime");
|
|
466240
466756
|
}
|
|
466241
466757
|
if (ownsRuntime) {
|
|
@@ -466263,16 +466779,16 @@ async function startAppServer(options = {}) {
|
|
|
466263
466779
|
stopRuntime(runtime, true);
|
|
466264
466780
|
setActiveRuntime(null);
|
|
466265
466781
|
}
|
|
466266
|
-
await new Promise((
|
|
466782
|
+
await new Promise((resolve39, reject2) => {
|
|
466267
466783
|
wss.close();
|
|
466268
|
-
const timeout = setTimeout(
|
|
466784
|
+
const timeout = setTimeout(resolve39, 1000);
|
|
466269
466785
|
server2.close((serverError) => {
|
|
466270
466786
|
clearTimeout(timeout);
|
|
466271
466787
|
if (serverError) {
|
|
466272
466788
|
reject2(serverError);
|
|
466273
466789
|
return;
|
|
466274
466790
|
}
|
|
466275
|
-
|
|
466791
|
+
resolve39();
|
|
466276
466792
|
});
|
|
466277
466793
|
});
|
|
466278
466794
|
}
|
|
@@ -466320,7 +466836,7 @@ Examples:
|
|
|
466320
466836
|
letta server --listen ws://127.0.0.1:4500 --openai-api`);
|
|
466321
466837
|
}
|
|
466322
466838
|
async function waitForShutdown(close) {
|
|
466323
|
-
return await new Promise((
|
|
466839
|
+
return await new Promise((resolve39) => {
|
|
466324
466840
|
let shuttingDown = false;
|
|
466325
466841
|
const shutdown = (signal) => {
|
|
466326
466842
|
if (shuttingDown)
|
|
@@ -466329,10 +466845,10 @@ async function waitForShutdown(close) {
|
|
|
466329
466845
|
close().then(() => {
|
|
466330
466846
|
console.log(`
|
|
466331
466847
|
Stopped App Server (${signal}).`);
|
|
466332
|
-
|
|
466848
|
+
resolve39(0);
|
|
466333
466849
|
}).catch((error4) => {
|
|
466334
466850
|
console.error(error4 instanceof Error ? `Error: ${error4.message}` : String(error4));
|
|
466335
|
-
|
|
466851
|
+
resolve39(1);
|
|
466336
466852
|
});
|
|
466337
466853
|
};
|
|
466338
466854
|
process.once("SIGINT", shutdown);
|
|
@@ -466718,7 +467234,7 @@ import {
|
|
|
466718
467234
|
readdirSync as readdirSync26,
|
|
466719
467235
|
unlinkSync as unlinkSync18
|
|
466720
467236
|
} from "node:fs";
|
|
466721
|
-
import { join as
|
|
467237
|
+
import { join as join102 } from "node:path";
|
|
466722
467238
|
function formatTimestamp2() {
|
|
466723
467239
|
const now2 = new Date;
|
|
466724
467240
|
const h3 = String(now2.getHours()).padStart(2, "0");
|
|
@@ -466739,7 +467255,7 @@ function pruneOldLogs(dir, maxFiles) {
|
|
|
466739
467255
|
const toDelete = files.slice(0, files.length - maxFiles + 1);
|
|
466740
467256
|
for (const file of toDelete) {
|
|
466741
467257
|
try {
|
|
466742
|
-
unlinkSync18(
|
|
467258
|
+
unlinkSync18(join102(dir, file));
|
|
466743
467259
|
} catch {}
|
|
466744
467260
|
}
|
|
466745
467261
|
}
|
|
@@ -466778,7 +467294,7 @@ class RemoteSessionLog {
|
|
|
466778
467294
|
freshPath() {
|
|
466779
467295
|
const stamp = formatFileTimestamp(new Date);
|
|
466780
467296
|
const suffix = this.rotation > 0 ? `.${this.rotation}` : "";
|
|
466781
|
-
return
|
|
467297
|
+
return join102(this.dir, `${stamp}${suffix}.log`);
|
|
466782
467298
|
}
|
|
466783
467299
|
rotate() {
|
|
466784
467300
|
const previous = this.path;
|
|
@@ -466819,13 +467335,13 @@ var REMOTE_LOG_DIR, MAX_LOG_FILES = 10, MAX_LOG_BYTES2;
|
|
|
466819
467335
|
var init_listen_log = __esm(() => {
|
|
466820
467336
|
init_settings_path();
|
|
466821
467337
|
init_ws_event_redaction();
|
|
466822
|
-
REMOTE_LOG_DIR =
|
|
467338
|
+
REMOTE_LOG_DIR = join102(resolveGlobalConfigDir(), "logs", "remote");
|
|
466823
467339
|
MAX_LOG_BYTES2 = 10 * 1024 * 1024;
|
|
466824
467340
|
});
|
|
466825
467341
|
|
|
466826
467342
|
// src/websocket/listener/manual-instance-lock.ts
|
|
466827
467343
|
import { createHash as createHash21, randomUUID as randomUUID60 } from "node:crypto";
|
|
466828
|
-
import { link as link4, mkdir as mkdir15, readFile as readFile28, rm as
|
|
467344
|
+
import { link as link4, mkdir as mkdir15, readFile as readFile28, rm as rm12, unlink as unlink3, writeFile as writeFile17 } from "node:fs/promises";
|
|
466829
467345
|
import { uptime as uptime2 } from "node:os";
|
|
466830
467346
|
import path46 from "node:path";
|
|
466831
467347
|
function hasErrorCode3(error4, code) {
|
|
@@ -466899,7 +467415,7 @@ async function publishInitializedFile(targetPath, contents) {
|
|
|
466899
467415
|
} catch (error4) {
|
|
466900
467416
|
publicationError = error4;
|
|
466901
467417
|
}
|
|
466902
|
-
await
|
|
467418
|
+
await rm12(candidatePath, { force: true }).catch(() => {});
|
|
466903
467419
|
return publicationError;
|
|
466904
467420
|
}
|
|
466905
467421
|
function getRecoveryClaimPath2(lockPath, staleContents, depth) {
|
|
@@ -466908,7 +467424,7 @@ function getRecoveryClaimPath2(lockPath, staleContents, depth) {
|
|
|
466908
467424
|
}
|
|
466909
467425
|
async function cleanupRecoveryClaims2(lockPath, staleContents, deepestClaim) {
|
|
466910
467426
|
for (let depth = deepestClaim;depth >= 0; depth--) {
|
|
466911
|
-
await
|
|
467427
|
+
await rm12(getRecoveryClaimPath2(lockPath, staleContents, depth), {
|
|
466912
467428
|
force: true
|
|
466913
467429
|
}).catch(() => {});
|
|
466914
467430
|
}
|
|
@@ -467569,8 +468085,8 @@ async function startChannelGatewaySupervisor(options) {
|
|
|
467569
468085
|
let resolveInitialReady = null;
|
|
467570
468086
|
let rejectInitialReady = null;
|
|
467571
468087
|
const pendingCommands = new Map;
|
|
467572
|
-
const initialReady = new Promise((
|
|
467573
|
-
resolveInitialReady =
|
|
468088
|
+
const initialReady = new Promise((resolve39, reject2) => {
|
|
468089
|
+
resolveInitialReady = resolve39;
|
|
467574
468090
|
rejectInitialReady = reject2;
|
|
467575
468091
|
});
|
|
467576
468092
|
function clearStableTimer() {
|
|
@@ -467796,7 +468312,7 @@ async function startChannelGatewaySupervisor(options) {
|
|
|
467796
468312
|
clearTimeout(startupTimeout);
|
|
467797
468313
|
}
|
|
467798
468314
|
return {
|
|
467799
|
-
request: (command) => new Promise((
|
|
468315
|
+
request: (command) => new Promise((resolve39, reject2) => {
|
|
467800
468316
|
const activeChild = readyChild;
|
|
467801
468317
|
if (!activeChild?.stdin?.writable) {
|
|
467802
468318
|
reject2(new Error("ChannelGateway process is not available"));
|
|
@@ -467807,7 +468323,7 @@ async function startChannelGatewaySupervisor(options) {
|
|
|
467807
468323
|
pendingCommands.delete(requestId);
|
|
467808
468324
|
reject2(new Error(`ChannelGateway command timed out: ${command.kind}`));
|
|
467809
468325
|
}, COMMAND_TIMEOUT_MS);
|
|
467810
|
-
pendingCommands.set(requestId, { resolve:
|
|
468326
|
+
pendingCommands.set(requestId, { resolve: resolve39, reject: reject2, timeout });
|
|
467811
468327
|
activeChild.stdin.write(`${JSON.stringify({ type: "command", requestId, command })}
|
|
467812
468328
|
`, (error4) => {
|
|
467813
468329
|
if (!error4)
|
|
@@ -467832,14 +468348,14 @@ async function startChannelGatewaySupervisor(options) {
|
|
|
467832
468348
|
rejectPendingCommands(closeError);
|
|
467833
468349
|
if (!activeChild || activeChild.exitCode !== null)
|
|
467834
468350
|
return;
|
|
467835
|
-
await new Promise((
|
|
468351
|
+
await new Promise((resolve39) => {
|
|
467836
468352
|
const timeout = setTimeout(() => {
|
|
467837
468353
|
activeChild.kill("SIGKILL");
|
|
467838
|
-
|
|
468354
|
+
resolve39();
|
|
467839
468355
|
}, SHUTDOWN_TIMEOUT_MS);
|
|
467840
468356
|
activeChild.once("exit", () => {
|
|
467841
468357
|
clearTimeout(timeout);
|
|
467842
|
-
|
|
468358
|
+
resolve39();
|
|
467843
468359
|
});
|
|
467844
468360
|
activeChild.kill("SIGTERM");
|
|
467845
468361
|
});
|
|
@@ -467986,6 +468502,7 @@ async function runListenSubcommand(argv, appServer) {
|
|
|
467986
468502
|
}
|
|
467987
468503
|
} catch {}
|
|
467988
468504
|
await cancelBackgroundMemoryTasks();
|
|
468505
|
+
await shutdownMonitors();
|
|
467989
468506
|
await flushRemoteSettingsWrites();
|
|
467990
468507
|
await releaseManualListenerLock();
|
|
467991
468508
|
await flushListenerTelemetryEnd(`listener_${signal.toLowerCase()}`);
|
|
@@ -467999,6 +468516,7 @@ async function runListenSubcommand(argv, appServer) {
|
|
|
467999
468516
|
await closeChannelGateway();
|
|
468000
468517
|
} catch {}
|
|
468001
468518
|
await cancelBackgroundMemoryTasks();
|
|
468519
|
+
await shutdownMonitors();
|
|
468002
468520
|
await flushRemoteSettingsWrites();
|
|
468003
468521
|
await releaseManualListenerLock();
|
|
468004
468522
|
await flushListenerTelemetryEnd(exitReason);
|
|
@@ -468502,6 +469020,7 @@ var init_listen = __esm(async () => {
|
|
|
468502
469020
|
init_settings_manager();
|
|
468503
469021
|
init_telemetry();
|
|
468504
469022
|
init_memory_task_lifecycle();
|
|
469023
|
+
init_monitor();
|
|
468505
469024
|
init_service_protocol();
|
|
468506
469025
|
init_debug();
|
|
468507
469026
|
init_startup_log_boundary();
|
|
@@ -468542,7 +469061,7 @@ import {
|
|
|
468542
469061
|
readFileSync as readFileSync52,
|
|
468543
469062
|
writeFileSync as writeFileSync44
|
|
468544
469063
|
} from "node:fs";
|
|
468545
|
-
import { join as
|
|
469064
|
+
import { join as join103 } from "node:path";
|
|
468546
469065
|
function readJsonl(path47) {
|
|
468547
469066
|
if (!existsSync66(path47))
|
|
468548
469067
|
return [];
|
|
@@ -468825,7 +469344,7 @@ function convertMessages4(messages, mode, nextId2) {
|
|
|
468825
469344
|
}
|
|
468826
469345
|
function migrateLocalBackendTranscripts(input) {
|
|
468827
469346
|
const storageDir = input.storageDir;
|
|
468828
|
-
const conversationsDir =
|
|
469347
|
+
const conversationsDir = join103(storageDir, "conversations");
|
|
468829
469348
|
const result3 = {
|
|
468830
469349
|
storageDir,
|
|
468831
469350
|
converted: [],
|
|
@@ -468835,9 +469354,9 @@ function migrateLocalBackendTranscripts(input) {
|
|
|
468835
469354
|
if (!existsSync66(conversationsDir))
|
|
468836
469355
|
return result3;
|
|
468837
469356
|
for (const name of readdirSync27(conversationsDir)) {
|
|
468838
|
-
const conversationDir =
|
|
468839
|
-
const messagesPath =
|
|
468840
|
-
const manifestPath =
|
|
469357
|
+
const conversationDir = join103(conversationsDir, name);
|
|
469358
|
+
const messagesPath = join103(conversationDir, "messages.jsonl");
|
|
469359
|
+
const manifestPath = join103(conversationDir, "manifest.json");
|
|
468841
469360
|
const hasManifest = existsSync66(manifestPath);
|
|
468842
469361
|
const existingManifest = hasManifest ? (() => {
|
|
468843
469362
|
try {
|
|
@@ -468880,7 +469399,7 @@ function migrateLocalBackendTranscripts(input) {
|
|
|
468880
469399
|
const backupPath = `${messagesPath}.pre-pi-backup-${timestampSuffix()}`;
|
|
468881
469400
|
if (!input.dryRun) {
|
|
468882
469401
|
copyFileSync3(messagesPath, backupPath);
|
|
468883
|
-
const conversationPath =
|
|
469402
|
+
const conversationPath = join103(conversationDir, "conversation.json");
|
|
468884
469403
|
let conversation;
|
|
468885
469404
|
if (existsSync66(conversationPath)) {
|
|
468886
469405
|
try {
|
|
@@ -469078,7 +469597,7 @@ var init_memory_tokens = __esm(() => {
|
|
|
469078
469597
|
// src/cli/subcommands/memory.ts
|
|
469079
469598
|
import { cpSync, existsSync as existsSync67, mkdirSync as mkdirSync53, rmSync as rmSync24, statSync as statSync26 } from "node:fs";
|
|
469080
469599
|
import { readdir as readdir12 } from "node:fs/promises";
|
|
469081
|
-
import { dirname as dirname40, join as
|
|
469600
|
+
import { dirname as dirname40, join as join104 } from "node:path";
|
|
469082
469601
|
import { parseArgs as parseArgs12 } from "node:util";
|
|
469083
469602
|
function printUsage8() {
|
|
469084
469603
|
console.log(`
|
|
@@ -469148,7 +469667,7 @@ async function listBackups(agentId) {
|
|
|
469148
469667
|
continue;
|
|
469149
469668
|
if (!entry.name.startsWith("memory-backup-"))
|
|
469150
469669
|
continue;
|
|
469151
|
-
const path47 =
|
|
469670
|
+
const path47 = join104(agentRoot, entry.name);
|
|
469152
469671
|
let createdAt = null;
|
|
469153
469672
|
try {
|
|
469154
469673
|
const stat15 = statSync26(path47);
|
|
@@ -469165,7 +469684,7 @@ function resolveBackupPath(agentId, from) {
|
|
|
469165
469684
|
if (from.startsWith("/") || /^[A-Za-z]:[/\\]/.test(from)) {
|
|
469166
469685
|
return from;
|
|
469167
469686
|
}
|
|
469168
|
-
return
|
|
469687
|
+
return join104(getAgentRoot(agentId), from);
|
|
469169
469688
|
}
|
|
469170
469689
|
async function runMemorySubcommand(argv, deps = {}) {
|
|
469171
469690
|
let parsed;
|
|
@@ -469213,10 +469732,10 @@ async function runMemorySubcommand(argv, deps = {}) {
|
|
|
469213
469732
|
return 1;
|
|
469214
469733
|
}
|
|
469215
469734
|
const { execFile: execFileCb4 } = await import("node:child_process");
|
|
469216
|
-
const { promisify:
|
|
469217
|
-
const
|
|
469735
|
+
const { promisify: promisify20 } = await import("node:util");
|
|
469736
|
+
const execFile22 = promisify20(execFileCb4);
|
|
469218
469737
|
const dir = getScopedMemoryFilesystemRoot(agentId);
|
|
469219
|
-
const { stdout } = await
|
|
469738
|
+
const { stdout } = await execFile22("git", ["diff"], { cwd: dir });
|
|
469220
469739
|
if (stdout.trim()) {
|
|
469221
469740
|
console.log(stdout);
|
|
469222
469741
|
return 2;
|
|
@@ -469249,7 +469768,7 @@ async function runMemorySubcommand(argv, deps = {}) {
|
|
|
469249
469768
|
}
|
|
469250
469769
|
const agentRoot = getAgentRoot(agentId);
|
|
469251
469770
|
const backupName = `memory-backup-${formatBackupTimestamp()}`;
|
|
469252
|
-
const backupPath =
|
|
469771
|
+
const backupPath = join104(agentRoot, backupName);
|
|
469253
469772
|
if (existsSync67(backupPath)) {
|
|
469254
469773
|
console.error(`Backup already exists at ${backupPath}`);
|
|
469255
469774
|
return 1;
|
|
@@ -469350,7 +469869,7 @@ var init_memory6 = __esm(() => {
|
|
|
469350
469869
|
|
|
469351
469870
|
// src/backend/local/transcript-search.ts
|
|
469352
469871
|
import { existsSync as existsSync68, readdirSync as readdirSync28, readFileSync as readFileSync53, statSync as statSync27 } from "node:fs";
|
|
469353
|
-
import { join as
|
|
469872
|
+
import { join as join105 } from "node:path";
|
|
469354
469873
|
function readJsonFile3(path47) {
|
|
469355
469874
|
if (!existsSync68(path47))
|
|
469356
469875
|
return;
|
|
@@ -469595,7 +470114,7 @@ function collectConversationMessages(input) {
|
|
|
469595
470114
|
return [];
|
|
469596
470115
|
if (input.conversationId && conversation.id !== input.conversationId)
|
|
469597
470116
|
return [];
|
|
469598
|
-
const manifest2 = readJsonFile3(
|
|
470117
|
+
const manifest2 = readJsonFile3(join105(conversationDir, "manifest.json"));
|
|
469599
470118
|
let format3 = transcriptFormatFromManifest(manifest2);
|
|
469600
470119
|
const records2 = [];
|
|
469601
470120
|
const echoToolCallIds = [];
|
|
@@ -469655,7 +470174,7 @@ function collectConversationMessages(input) {
|
|
|
469655
470174
|
}
|
|
469656
470175
|
addRow(row, rowIndex);
|
|
469657
470176
|
};
|
|
469658
|
-
const messagesPath =
|
|
470177
|
+
const messagesPath = join105(conversationDir, "messages.jsonl");
|
|
469659
470178
|
let rowError;
|
|
469660
470179
|
try {
|
|
469661
470180
|
forEachJsonlRow(messagesPath, (row) => {
|
|
@@ -469684,11 +470203,11 @@ function collectConversationMessages(input) {
|
|
|
469684
470203
|
return records2;
|
|
469685
470204
|
}
|
|
469686
470205
|
function conversationDirectories(storageDir) {
|
|
469687
|
-
const conversationsDir =
|
|
470206
|
+
const conversationsDir = join105(storageDir, "conversations");
|
|
469688
470207
|
if (!existsSync68(conversationsDir))
|
|
469689
470208
|
return [];
|
|
469690
470209
|
try {
|
|
469691
|
-
return readdirSync28(conversationsDir).map((entry) =>
|
|
470210
|
+
return readdirSync28(conversationsDir).map((entry) => join105(conversationsDir, entry)).filter((entryPath) => statSync27(entryPath).isDirectory());
|
|
469692
470211
|
} catch {
|
|
469693
470212
|
return [];
|
|
469694
470213
|
}
|
|
@@ -469715,7 +470234,7 @@ function searchLocalTranscriptMessages(storageDir, body3, options = {}) {
|
|
|
469715
470234
|
const endDate = typeof body3.end_date === "string" ? body3.end_date : undefined;
|
|
469716
470235
|
const includeHidden = body3.include_hidden === true;
|
|
469717
470236
|
const records2 = conversationDirectories(storageDir).flatMap((conversationDir) => {
|
|
469718
|
-
const conversation = conversationSearchRecord(readJsonFile3(
|
|
470237
|
+
const conversation = conversationSearchRecord(readJsonFile3(join105(conversationDir, "conversation.json")));
|
|
469719
470238
|
if (!conversation)
|
|
469720
470239
|
return [];
|
|
469721
470240
|
if (conversation.hidden && !includeHidden)
|
|
@@ -469819,7 +470338,7 @@ var init_message_status = __esm(() => {
|
|
|
469819
470338
|
|
|
469820
470339
|
// src/cli/subcommands/messages.ts
|
|
469821
470340
|
import { writeFile as writeFile18 } from "node:fs/promises";
|
|
469822
|
-
import { resolve as
|
|
470341
|
+
import { resolve as resolve39 } from "node:path";
|
|
469823
470342
|
import { parseArgs as parseArgs13 } from "node:util";
|
|
469824
470343
|
function printUsage9() {
|
|
469825
470344
|
console.log(`
|
|
@@ -470149,7 +470668,7 @@ async function runMessagesSubcommand(argv, deps = {}) {
|
|
|
470149
470668
|
const pageLimit = Math.max(1, parseLimit3(parsed.values.limit, 100));
|
|
470150
470669
|
const maxPages = Math.max(1, parseLimit3(parsed.values["max-pages"], 200));
|
|
470151
470670
|
const outputPathRaw = parsed.values.out || parsed.values.output;
|
|
470152
|
-
const outputPath = outputPathRaw ?
|
|
470671
|
+
const outputPath = outputPathRaw ? resolve39(process.cwd(), outputPathRaw) : undefined;
|
|
470153
470672
|
const { messages, truncated } = await fetchConversationMessages(conversationId, agentId || undefined, pageLimit, maxPages);
|
|
470154
470673
|
const transcript2 = messages.flatMap((msg) => formatEntry(msg)).join(`
|
|
470155
470674
|
|
|
@@ -470387,9 +470906,9 @@ function filterStructuredOutputRows(rows) {
|
|
|
470387
470906
|
return { supported, unknownCount };
|
|
470388
470907
|
}
|
|
470389
470908
|
async function printJson3(value) {
|
|
470390
|
-
await new Promise((
|
|
470909
|
+
await new Promise((resolve40, reject2) => {
|
|
470391
470910
|
process.stdout.write(`${JSON.stringify(value, null, 2)}
|
|
470392
|
-
`, (error4) => error4 ? reject2(error4) :
|
|
470911
|
+
`, (error4) => error4 ? reject2(error4) : resolve40());
|
|
470393
470912
|
});
|
|
470394
470913
|
}
|
|
470395
470914
|
async function runModelSubcommand(argv) {
|
|
@@ -470766,8 +471285,8 @@ function isRecord21(value) {
|
|
|
470766
471285
|
function isPathInsideOrEqual2(childPath, parentPath) {
|
|
470767
471286
|
const child = path47.resolve(childPath);
|
|
470768
471287
|
const parent = path47.resolve(parentPath);
|
|
470769
|
-
const
|
|
470770
|
-
return
|
|
471288
|
+
const relative12 = path47.relative(parent, child);
|
|
471289
|
+
return relative12 === "" || !!relative12 && !relative12.startsWith("..") && !path47.isAbsolute(relative12);
|
|
470771
471290
|
}
|
|
470772
471291
|
function readPackageJson(packageJsonPath) {
|
|
470773
471292
|
let parsed;
|
|
@@ -471108,7 +471627,7 @@ function writeNpmInstallManifest(tempRoot) {
|
|
|
471108
471627
|
`);
|
|
471109
471628
|
}
|
|
471110
471629
|
function runProcess2(params) {
|
|
471111
|
-
return new Promise((
|
|
471630
|
+
return new Promise((resolve40, reject2) => {
|
|
471112
471631
|
const child = params.spawnImpl(params.command, params.args, {
|
|
471113
471632
|
cwd: params.cwd,
|
|
471114
471633
|
stdio: ["ignore", "pipe", "pipe"]
|
|
@@ -471124,7 +471643,7 @@ function runProcess2(params) {
|
|
|
471124
471643
|
child.on("error", reject2);
|
|
471125
471644
|
child.on("exit", (code) => {
|
|
471126
471645
|
if (code === 0) {
|
|
471127
|
-
|
|
471646
|
+
resolve40({ stderr: stderr.join(""), stdout: stdout.join("") });
|
|
471128
471647
|
return;
|
|
471129
471648
|
}
|
|
471130
471649
|
const details = stderr.join("").trim() || stdout.join("").trim();
|
|
@@ -471744,7 +472263,7 @@ var init_package_scaffolder = __esm(() => {
|
|
|
471744
472263
|
});
|
|
471745
472264
|
|
|
471746
472265
|
// src/cli/subcommands/mods.ts
|
|
471747
|
-
import { dirname as dirname41, join as
|
|
472266
|
+
import { dirname as dirname41, join as join106 } from "node:path";
|
|
471748
472267
|
import { parseArgs as parseArgs15 } from "node:util";
|
|
471749
472268
|
function printUsage11() {
|
|
471750
472269
|
console.log(`
|
|
@@ -471783,7 +472302,7 @@ function getExplicitAgentId(values4) {
|
|
|
471783
472302
|
return typeof explicitAgent === "string" && explicitAgent.trim() ? explicitAgent.trim() : null;
|
|
471784
472303
|
}
|
|
471785
472304
|
function getAgentModsDirectory(agentId) {
|
|
471786
|
-
return
|
|
472305
|
+
return join106(getScopedMemoryFilesystemRoot(agentId), "mods");
|
|
471787
472306
|
}
|
|
471788
472307
|
function directFilesForSource(source) {
|
|
471789
472308
|
return source.files.filter((file) => dirname41(file) === source.root);
|
|
@@ -472270,7 +472789,7 @@ var init_sandbox_files = __esm(() => {
|
|
|
472270
472789
|
|
|
472271
472790
|
// src/cli/subcommands/sandbox.ts
|
|
472272
472791
|
import { readFile as readFile29, stat as stat15, writeFile as writeFile19 } from "node:fs/promises";
|
|
472273
|
-
import { basename as basename30, resolve as
|
|
472792
|
+
import { basename as basename30, resolve as resolve40 } from "node:path";
|
|
472274
472793
|
import { parseArgs as parseArgs17 } from "node:util";
|
|
472275
472794
|
function printUsage13() {
|
|
472276
472795
|
console.log(`
|
|
@@ -472493,7 +473012,7 @@ async function runSandboxSubcommand(argv, deps = {}) {
|
|
|
472493
473012
|
if (path49 === undefined)
|
|
472494
473013
|
throw new Error("Missing file path");
|
|
472495
473014
|
if (action === "upload") {
|
|
472496
|
-
const localPath3 =
|
|
473015
|
+
const localPath3 = resolve40(path49);
|
|
472497
473016
|
const fileStat = await (deps.statLocalPath ?? stat15)(localPath3);
|
|
472498
473017
|
if (!fileStat.isFile())
|
|
472499
473018
|
throw new Error(`${localPath3} is not a file`);
|
|
@@ -472505,7 +473024,7 @@ async function runSandboxSubcommand(argv, deps = {}) {
|
|
|
472505
473024
|
}
|
|
472506
473025
|
const sandbox = await ensureSandbox();
|
|
472507
473026
|
const data = await (deps.downloadFile ?? downloadFileFromSandbox)(sandbox.sandboxId, path49);
|
|
472508
|
-
const localPath2 =
|
|
473027
|
+
const localPath2 = resolve40(parsed.values.to ?? basename30(path49));
|
|
472509
473028
|
await (deps.writeLocalFile ?? writeFile19)(localPath2, data);
|
|
472510
473029
|
console.log(JSON.stringify({
|
|
472511
473030
|
path: localPath2,
|
|
@@ -473274,7 +473793,7 @@ __export(exports_setup, {
|
|
|
473274
473793
|
runSetup: () => runSetup
|
|
473275
473794
|
});
|
|
473276
473795
|
async function runSetup(options = {}) {
|
|
473277
|
-
return new Promise((
|
|
473796
|
+
return new Promise((resolve41) => {
|
|
473278
473797
|
let settled = false;
|
|
473279
473798
|
let instance2;
|
|
473280
473799
|
const settle3 = (result3) => {
|
|
@@ -473283,7 +473802,7 @@ async function runSetup(options = {}) {
|
|
|
473283
473802
|
}
|
|
473284
473803
|
settled = true;
|
|
473285
473804
|
instance2.unmount();
|
|
473286
|
-
|
|
473805
|
+
resolve41(result3);
|
|
473287
473806
|
};
|
|
473288
473807
|
instance2 = render_default(import_react35.default.createElement(SetupUI, {
|
|
473289
473808
|
initialMode: options.initialMode,
|
|
@@ -473338,7 +473857,7 @@ var init_setup7 = __esm(async () => {
|
|
|
473338
473857
|
|
|
473339
473858
|
// src/cli/subcommands/shared-memory.ts
|
|
473340
473859
|
import { existsSync as existsSync71 } from "node:fs";
|
|
473341
|
-
import { join as
|
|
473860
|
+
import { join as join107 } from "node:path";
|
|
473342
473861
|
import { parseArgs as parseArgs19 } from "node:util";
|
|
473343
473862
|
function printUsage16() {
|
|
473344
473863
|
console.log(`
|
|
@@ -473545,7 +474064,7 @@ async function runSharedMemorySubcommand(argv, deps = {}) {
|
|
|
473545
474064
|
invalidateClientSkills(agentId);
|
|
473546
474065
|
const recompileError = await recompileAndReportFailure(recompileAgent, agentId);
|
|
473547
474066
|
const mountDir = getRepositoryMountDir(agentId, repository.name);
|
|
473548
|
-
const mounted = existsSync71(
|
|
474067
|
+
const mounted = existsSync71(join107(mountDir, ".git"));
|
|
473549
474068
|
console.log(JSON.stringify({
|
|
473550
474069
|
attached: true,
|
|
473551
474070
|
repository: { id: repository.id, name: repository.name },
|
|
@@ -475137,7 +475656,7 @@ import {
|
|
|
475137
475656
|
} from "node:fs";
|
|
475138
475657
|
import { mkdir as mkdir16, readdir as readdir13 } from "node:fs/promises";
|
|
475139
475658
|
import { tmpdir as tmpdir15 } from "node:os";
|
|
475140
|
-
import { basename as basename31, dirname as dirname42, join as
|
|
475659
|
+
import { basename as basename31, dirname as dirname42, join as join108, normalize as normalize5, resolve as resolve41, sep as sep9 } from "node:path";
|
|
475141
475660
|
import { parseArgs as parseArgs20, TextDecoder as TextDecoder2, TextEncoder as TextEncoder2 } from "node:util";
|
|
475142
475661
|
function printUsage17() {
|
|
475143
475662
|
console.log(`
|
|
@@ -475379,15 +475898,15 @@ function resolveSkillSourceSpecifier(input) {
|
|
|
475379
475898
|
}
|
|
475380
475899
|
return null;
|
|
475381
475900
|
}
|
|
475382
|
-
async function
|
|
475901
|
+
async function execFile22(command, args, options = {}) {
|
|
475383
475902
|
const { execFile: execFileCb4 } = await import("node:child_process");
|
|
475384
|
-
const { promisify:
|
|
475385
|
-
return
|
|
475903
|
+
const { promisify: promisify20 } = await import("node:util");
|
|
475904
|
+
return promisify20(execFileCb4)(command, args, options);
|
|
475386
475905
|
}
|
|
475387
475906
|
async function resolveBranchAndSubdir(location) {
|
|
475388
475907
|
if (!location.subdir)
|
|
475389
475908
|
return location;
|
|
475390
|
-
const { stdout } = await
|
|
475909
|
+
const { stdout } = await execFile22("git", ["ls-remote", "--heads", location.repoUrl], {
|
|
475391
475910
|
timeout: 60000
|
|
475392
475911
|
});
|
|
475393
475912
|
const branches = stdout.split(`
|
|
@@ -475408,14 +475927,14 @@ async function resolveBranchAndSubdir(location) {
|
|
|
475408
475927
|
}
|
|
475409
475928
|
async function cloneSkillSource(location) {
|
|
475410
475929
|
const resolvedLocation = await resolveBranchAndSubdir(location);
|
|
475411
|
-
const tmpDir = mkdtempSync6(
|
|
475930
|
+
const tmpDir = mkdtempSync6(join108(tmpdir15(), "letta-skill-install-"));
|
|
475412
475931
|
const args = ["clone", "--depth", "1"];
|
|
475413
475932
|
if (resolvedLocation.branch) {
|
|
475414
475933
|
args.push("--branch", resolvedLocation.branch);
|
|
475415
475934
|
}
|
|
475416
475935
|
args.push(resolvedLocation.repoUrl, tmpDir);
|
|
475417
|
-
await
|
|
475418
|
-
const sourceDir = resolvedLocation.subdir ?
|
|
475936
|
+
await execFile22("git", args, { timeout: 120000 });
|
|
475937
|
+
const sourceDir = resolvedLocation.subdir ? join108(tmpDir, resolvedLocation.subdir) : tmpDir;
|
|
475419
475938
|
return { tmpDir, sourceDir };
|
|
475420
475939
|
}
|
|
475421
475940
|
function assertDirectSkillFileSize(receivedBytes, maxBytes) {
|
|
@@ -475470,11 +475989,11 @@ async function downloadDirectSkillFileSource(location, options = {}) {
|
|
|
475470
475989
|
throw new Error(`Direct skill file download failed for ${location.url}: ${response.status}`);
|
|
475471
475990
|
}
|
|
475472
475991
|
const skillText = await readResponseTextWithLimit(response, MAX_DIRECT_SKILL_FILE_BYTES);
|
|
475473
|
-
const tmpDir = mkdtempSync6(
|
|
475992
|
+
const tmpDir = mkdtempSync6(join108(tmpdir15(), "letta-direct-skill-"));
|
|
475474
475993
|
try {
|
|
475475
|
-
const sourceDir =
|
|
475994
|
+
const sourceDir = join108(tmpDir, "skill");
|
|
475476
475995
|
await mkdir16(sourceDir, { recursive: true });
|
|
475477
|
-
writeFileSync47(
|
|
475996
|
+
writeFileSync47(join108(sourceDir, "SKILL.md"), skillText, "utf8");
|
|
475478
475997
|
return { tmpDir, sourceDir };
|
|
475479
475998
|
} catch (error4) {
|
|
475480
475999
|
rmSync27(tmpDir, { recursive: true, force: true });
|
|
@@ -475515,9 +476034,9 @@ function assertSafeZipMember(name) {
|
|
|
475515
476034
|
}
|
|
475516
476035
|
async function downloadClawHubSkillSource(location) {
|
|
475517
476036
|
const version3 = await resolveClawHubVersion(location);
|
|
475518
|
-
const tmpDir = mkdtempSync6(
|
|
475519
|
-
const zipPath =
|
|
475520
|
-
const sourceDir =
|
|
476037
|
+
const tmpDir = mkdtempSync6(join108(tmpdir15(), "letta-clawhub-skill-"));
|
|
476038
|
+
const zipPath = join108(tmpDir, "skill.zip");
|
|
476039
|
+
const sourceDir = join108(tmpDir, "skill");
|
|
475521
476040
|
await mkdir16(sourceDir, { recursive: true });
|
|
475522
476041
|
const url2 = new URL(`${CLAWHUB_API_BASE_URL}/download`);
|
|
475523
476042
|
url2.searchParams.set("slug", location.slug);
|
|
@@ -475527,7 +476046,7 @@ async function downloadClawHubSkillSource(location) {
|
|
|
475527
476046
|
throw new Error(`ClawHub download failed for ${location.slug}@${version3}: ${response.status}`);
|
|
475528
476047
|
}
|
|
475529
476048
|
writeFileSync47(zipPath, Buffer.from(await response.arrayBuffer()));
|
|
475530
|
-
const { stdout } = await
|
|
476049
|
+
const { stdout } = await execFile22("unzip", ["-Z1", zipPath], {
|
|
475531
476050
|
timeout: 30000
|
|
475532
476051
|
});
|
|
475533
476052
|
const members = stdout.split(`
|
|
@@ -475536,15 +476055,15 @@ async function downloadClawHubSkillSource(location) {
|
|
|
475536
476055
|
throw new Error(`ClawHub download was empty for ${location.slug}@${version3}`);
|
|
475537
476056
|
}
|
|
475538
476057
|
members.forEach(assertSafeZipMember);
|
|
475539
|
-
await
|
|
476058
|
+
await execFile22("unzip", ["-q", zipPath, "-d", sourceDir], {
|
|
475540
476059
|
timeout: 30000
|
|
475541
476060
|
});
|
|
475542
476061
|
return { tmpDir, sourceDir };
|
|
475543
476062
|
}
|
|
475544
476063
|
function assertInside(parent, child) {
|
|
475545
|
-
const parentPath =
|
|
475546
|
-
const childPath =
|
|
475547
|
-
if (childPath !== parentPath && !childPath.startsWith(`${parentPath}${
|
|
476064
|
+
const parentPath = resolve41(parent);
|
|
476065
|
+
const childPath = resolve41(child);
|
|
476066
|
+
if (childPath !== parentPath && !childPath.startsWith(`${parentPath}${sep9}`)) {
|
|
475548
476067
|
throw new Error(`Resolved path is outside target directory: ${child}`);
|
|
475549
476068
|
}
|
|
475550
476069
|
}
|
|
@@ -475556,16 +476075,16 @@ function sanitizeSkillName(name) {
|
|
|
475556
476075
|
return trimmed;
|
|
475557
476076
|
}
|
|
475558
476077
|
function getSkillName(sourceDir) {
|
|
475559
|
-
const skillMd = readFileSync55(
|
|
476078
|
+
const skillMd = readFileSync55(join108(sourceDir, "SKILL.md"), "utf8");
|
|
475560
476079
|
const { frontmatter } = parseFrontmatter(skillMd);
|
|
475561
476080
|
const frontmatterName = frontmatter.name;
|
|
475562
476081
|
const name = typeof frontmatterName === "string" && frontmatterName.trim() ? frontmatterName : basename31(sourceDir);
|
|
475563
476082
|
return sanitizeSkillName(name);
|
|
475564
476083
|
}
|
|
475565
476084
|
async function installSkillDirectory(params) {
|
|
475566
|
-
const sourceDir =
|
|
475567
|
-
const memoryDir =
|
|
475568
|
-
const skillMdPath =
|
|
476085
|
+
const sourceDir = resolve41(params.sourceDir);
|
|
476086
|
+
const memoryDir = resolve41(params.memoryDir);
|
|
476087
|
+
const skillMdPath = join108(sourceDir, "SKILL.md");
|
|
475569
476088
|
if (!existsSync72(skillMdPath)) {
|
|
475570
476089
|
throw new Error("No SKILL.md found in the skill directory.");
|
|
475571
476090
|
}
|
|
@@ -475573,8 +476092,8 @@ async function installSkillDirectory(params) {
|
|
|
475573
476092
|
throw new Error(`Skill source is not a directory: ${sourceDir}`);
|
|
475574
476093
|
}
|
|
475575
476094
|
const name = getSkillName(sourceDir);
|
|
475576
|
-
const skillsDir =
|
|
475577
|
-
const targetPath =
|
|
476095
|
+
const skillsDir = join108(memoryDir, "skills");
|
|
476096
|
+
const targetPath = join108(skillsDir, name);
|
|
475578
476097
|
assertInside(skillsDir, targetPath);
|
|
475579
476098
|
if (existsSync72(targetPath)) {
|
|
475580
476099
|
if (!params.force) {
|
|
@@ -475590,8 +476109,8 @@ async function installSkillDirectory(params) {
|
|
|
475590
476109
|
return { name, path: normalize5(targetPath) };
|
|
475591
476110
|
}
|
|
475592
476111
|
async function listSkillDirectories(params) {
|
|
475593
|
-
const memoryDir =
|
|
475594
|
-
const skillsDir =
|
|
476112
|
+
const memoryDir = resolve41(params.memoryDir);
|
|
476113
|
+
const skillsDir = join108(memoryDir, "skills");
|
|
475595
476114
|
if (!existsSync72(skillsDir))
|
|
475596
476115
|
return [];
|
|
475597
476116
|
const entries2 = await readdir13(skillsDir, { withFileTypes: true });
|
|
@@ -475599,8 +476118,8 @@ async function listSkillDirectories(params) {
|
|
|
475599
476118
|
for (const entry of entries2) {
|
|
475600
476119
|
if (!entry.isDirectory())
|
|
475601
476120
|
continue;
|
|
475602
|
-
const skillDir =
|
|
475603
|
-
const skillMdPath =
|
|
476121
|
+
const skillDir = join108(skillsDir, entry.name);
|
|
476122
|
+
const skillMdPath = join108(skillDir, "SKILL.md");
|
|
475604
476123
|
if (!existsSync72(skillMdPath))
|
|
475605
476124
|
continue;
|
|
475606
476125
|
let name = entry.name;
|
|
@@ -475620,10 +476139,10 @@ async function listSkillDirectories(params) {
|
|
|
475620
476139
|
return skills.sort((a2, b3) => a2.name.localeCompare(b3.name));
|
|
475621
476140
|
}
|
|
475622
476141
|
async function deleteSkillDirectory(params) {
|
|
475623
|
-
const memoryDir =
|
|
475624
|
-
const skillsDir =
|
|
476142
|
+
const memoryDir = resolve41(params.memoryDir);
|
|
476143
|
+
const skillsDir = join108(memoryDir, "skills");
|
|
475625
476144
|
const name = sanitizeSkillName(params.name);
|
|
475626
|
-
const targetPath =
|
|
476145
|
+
const targetPath = join108(skillsDir, name);
|
|
475627
476146
|
assertInside(skillsDir, targetPath);
|
|
475628
476147
|
if (!existsSync72(targetPath)) {
|
|
475629
476148
|
throw new Error(`Skill "${name}" is not installed at ${targetPath}.`);
|
|
@@ -475672,7 +476191,7 @@ async function installSkill(specifier, agentId, force) {
|
|
|
475672
476191
|
downloaded = await downloadClawHubSkillSource(source.location);
|
|
475673
476192
|
}
|
|
475674
476193
|
tmpDir = downloaded.tmpDir;
|
|
475675
|
-
const sourceDir =
|
|
476194
|
+
const sourceDir = resolve41(downloaded.sourceDir);
|
|
475676
476195
|
assertInside(tmpDir, sourceDir);
|
|
475677
476196
|
if (!existsSync72(sourceDir)) {
|
|
475678
476197
|
const missingPath = source.type === "git" ? source.location.subdir ?? "." : source.type === "direct-file" ? source.location.url : source.location.slug;
|
|
@@ -475855,7 +476374,7 @@ async function runInstall(argv, options = {}) {
|
|
|
475855
476374
|
return 1;
|
|
475856
476375
|
}
|
|
475857
476376
|
}
|
|
475858
|
-
const maybeLocalPath =
|
|
476377
|
+
const maybeLocalPath = resolve41(specifier);
|
|
475859
476378
|
if (isLocalLettaModPackageDirectory(maybeLocalPath)) {
|
|
475860
476379
|
if (hasInstallAgentScope(parsed.values)) {
|
|
475861
476380
|
console.error("Agent-scoped mod package install is not supported yet.");
|
|
@@ -476170,20 +476689,20 @@ async function runTeleportSubcommand(argv, deps = {}) {
|
|
|
476170
476689
|
throw new Error(channelError);
|
|
476171
476690
|
let targetConnectionId;
|
|
476172
476691
|
if (action === "cloud") {
|
|
476173
|
-
const
|
|
476174
|
-
const result4 = await
|
|
476692
|
+
const resolve42 = deps.resolveAgentSandboxConnectionId ?? resolveAgentSandboxConnectionId;
|
|
476693
|
+
const result4 = await resolve42(session3.agentId, {
|
|
476175
476694
|
conversationId: session3.conversationId
|
|
476176
476695
|
});
|
|
476177
476696
|
targetConnectionId = result4.connectionId;
|
|
476178
476697
|
} else if (action === "local") {
|
|
476179
|
-
const
|
|
476180
|
-
const result4 = await
|
|
476698
|
+
const resolve42 = deps.resolveDesktopEnvironmentConnectionId ?? resolveDesktopEnvironmentConnectionId;
|
|
476699
|
+
const result4 = await resolve42();
|
|
476181
476700
|
targetConnectionId = result4.connectionId;
|
|
476182
476701
|
} else if (action === "back") {
|
|
476183
476702
|
throw new Error("Teleport back is not supported. Use `letta teleport local` or choose an explicit computer.");
|
|
476184
476703
|
} else {
|
|
476185
|
-
const
|
|
476186
|
-
const resolved = await
|
|
476704
|
+
const resolve42 = deps.resolveEnvironmentConnectionId ?? resolveEnvironmentConnectionId;
|
|
476705
|
+
const resolved = await resolve42(action);
|
|
476187
476706
|
assertTeleportableRemoteEnvironment(resolved.environment);
|
|
476188
476707
|
targetConnectionId = resolved.connectionId;
|
|
476189
476708
|
}
|
|
@@ -476209,7 +476728,7 @@ var init_teleport2 = __esm(() => {
|
|
|
476209
476728
|
|
|
476210
476729
|
// src/cli/subcommands/trajectories/readers.ts
|
|
476211
476730
|
import { readdir as readdir14, readFile as readFile30, stat as stat16 } from "node:fs/promises";
|
|
476212
|
-
import { join as
|
|
476731
|
+
import { join as join109 } from "node:path";
|
|
476213
476732
|
async function loadSessionTranscript(item) {
|
|
476214
476733
|
const stats = await stat16(item.path);
|
|
476215
476734
|
if (stats.isDirectory()) {
|
|
@@ -476221,13 +476740,13 @@ async function loadSessionTranscript(item) {
|
|
|
476221
476740
|
return readFile30(item.path, "utf-8");
|
|
476222
476741
|
}
|
|
476223
476742
|
async function assembleEventDirectory(sessionDir) {
|
|
476224
|
-
const eventsSubdir =
|
|
476743
|
+
const eventsSubdir = join109(sessionDir, "events");
|
|
476225
476744
|
const eventsDir = (await stat16(eventsSubdir).catch(() => null))?.isDirectory() ? eventsSubdir : sessionDir;
|
|
476226
476745
|
const names = (await readdir14(eventsDir, { withFileTypes: true })).filter((entry) => entry.isFile() && entry.name.endsWith(".json")).map((entry) => entry.name).sort((a2, b3) => Number.parseInt(a2, 10) - Number.parseInt(b3, 10) || a2.localeCompare(b3));
|
|
476227
476746
|
if (names.length === 0) {
|
|
476228
476747
|
throw new Error(`No event files found in ${eventsDir}`);
|
|
476229
476748
|
}
|
|
476230
|
-
const events = await Promise.all(names.map(async (name) => JSON.parse(await readFile30(
|
|
476749
|
+
const events = await Promise.all(names.map(async (name) => JSON.parse(await readFile30(join109(eventsDir, name), "utf-8"))));
|
|
476231
476750
|
return JSON.stringify(events);
|
|
476232
476751
|
}
|
|
476233
476752
|
async function openReadOnlyDatabase(path49) {
|
|
@@ -476301,11 +476820,11 @@ import {
|
|
|
476301
476820
|
mkdir as mkdir17,
|
|
476302
476821
|
readdir as readdir15,
|
|
476303
476822
|
readFile as readFile31,
|
|
476304
|
-
rm as
|
|
476823
|
+
rm as rm13,
|
|
476305
476824
|
stat as stat17,
|
|
476306
476825
|
writeFile as writeFile20
|
|
476307
476826
|
} from "node:fs/promises";
|
|
476308
|
-
import { basename as basename32, join as
|
|
476827
|
+
import { basename as basename32, join as join110 } from "node:path";
|
|
476309
476828
|
function fileTimestamp(startedAt) {
|
|
476310
476829
|
if (!startedAt)
|
|
476311
476830
|
return "unknown-date";
|
|
@@ -476375,7 +476894,7 @@ async function prepareOutDir(outDir) {
|
|
|
476375
476894
|
throw new Error(`--out ${outDir} is not empty and has no ${MANIFEST_NAME}; refusing to overwrite a directory this tool did not create`);
|
|
476376
476895
|
}
|
|
476377
476896
|
for (const entry of entries2) {
|
|
476378
|
-
await
|
|
476897
|
+
await rm13(join110(outDir, entry), { recursive: true, force: true });
|
|
476379
476898
|
}
|
|
476380
476899
|
} catch (error4) {
|
|
476381
476900
|
if (error4.code !== "ENOENT")
|
|
@@ -476418,14 +476937,14 @@ async function runTrajectoryExport(options) {
|
|
|
476418
476937
|
}
|
|
476419
476938
|
const sessionId = sessionHash(source, id);
|
|
476420
476939
|
const base2 = `${fileTimestamp(stats.startedAt)}_${sessionId}`;
|
|
476421
|
-
let file =
|
|
476940
|
+
let file = join110(source, `${base2}.json`);
|
|
476422
476941
|
for (let suffix = 2;usedFiles.has(file); suffix += 1) {
|
|
476423
|
-
file =
|
|
476942
|
+
file = join110(source, `${base2}-${suffix}.json`);
|
|
476424
476943
|
}
|
|
476425
476944
|
usedFiles.add(file);
|
|
476426
476945
|
const body3 = JSON.stringify(records2);
|
|
476427
|
-
await mkdir17(
|
|
476428
|
-
await writeFile20(
|
|
476946
|
+
await mkdir17(join110(options.outDir, source), { recursive: true });
|
|
476947
|
+
await writeFile20(join110(options.outDir, file), body3, "utf-8");
|
|
476429
476948
|
counts.exported += 1;
|
|
476430
476949
|
manifest2.sessions.push({
|
|
476431
476950
|
source,
|
|
@@ -476479,7 +476998,7 @@ async function runTrajectoryExport(options) {
|
|
|
476479
476998
|
await exportCheckpoint(checkpoint, `${basename32(checkpoint.path)}-${checkpoint.threadId}`);
|
|
476480
476999
|
}
|
|
476481
477000
|
manifest2.sessions.sort((a2, b3) => (a2.startedAt ?? "").localeCompare(b3.startedAt ?? ""));
|
|
476482
|
-
await writeFile20(
|
|
477001
|
+
await writeFile20(join110(options.outDir, MANIFEST_NAME), JSON.stringify(manifest2, null, 2), "utf-8");
|
|
476483
477002
|
return manifest2;
|
|
476484
477003
|
}
|
|
476485
477004
|
var MANIFEST_NAME = "manifest.json", FIRST_PROMPT_MAX_CHARS = 200, LIST_PAGE_LIMIT = 1000;
|
|
@@ -476491,13 +477010,13 @@ var init_export = __esm(() => {
|
|
|
476491
477010
|
|
|
476492
477011
|
// src/cli/subcommands/trajectories/review.ts
|
|
476493
477012
|
import { readFile as readFile32 } from "node:fs/promises";
|
|
476494
|
-
import { isAbsolute as
|
|
477013
|
+
import { isAbsolute as isAbsolute28, join as join111 } from "node:path";
|
|
476495
477014
|
async function readManifest(dir) {
|
|
476496
477015
|
let raw2;
|
|
476497
477016
|
try {
|
|
476498
|
-
raw2 = await readFile32(
|
|
477017
|
+
raw2 = await readFile32(join111(dir, "manifest.json"), "utf-8");
|
|
476499
477018
|
} catch {
|
|
476500
|
-
throw new Error(`No manifest at ${
|
|
477019
|
+
throw new Error(`No manifest at ${join111(dir, "manifest.json")}. Run: letta trajectories export --out ${dir}`);
|
|
476501
477020
|
}
|
|
476502
477021
|
return JSON.parse(raw2);
|
|
476503
477022
|
}
|
|
@@ -476506,7 +477025,7 @@ function filterSessions(sessions5, filter3) {
|
|
|
476506
477025
|
}
|
|
476507
477026
|
async function resolveSessionFile(dir, target) {
|
|
476508
477027
|
if (target.endsWith(".json")) {
|
|
476509
|
-
const direct =
|
|
477028
|
+
const direct = isAbsolute28(target) ? target : join111(dir, target);
|
|
476510
477029
|
try {
|
|
476511
477030
|
await readFile32(direct, "utf-8");
|
|
476512
477031
|
return direct;
|
|
@@ -476517,7 +477036,7 @@ async function resolveSessionFile(dir, target) {
|
|
|
476517
477036
|
if (!entry) {
|
|
476518
477037
|
throw new Error(`No session "${target}" in ${dir} (pass a file path, a manifest-relative file, or a sessionId)`);
|
|
476519
477038
|
}
|
|
476520
|
-
return
|
|
477039
|
+
return join111(dir, entry.file);
|
|
476521
477040
|
}
|
|
476522
477041
|
function stamp(timestamp) {
|
|
476523
477042
|
return (timestamp ?? "").slice(0, 19);
|
|
@@ -476560,7 +477079,7 @@ async function searchSessions(dir, keyword, options = {}) {
|
|
|
476560
477079
|
for (const session3 of filterSessions(manifest2.sessions, options)) {
|
|
476561
477080
|
let records2;
|
|
476562
477081
|
try {
|
|
476563
|
-
records2 = JSON.parse(await readFile32(
|
|
477082
|
+
records2 = JSON.parse(await readFile32(join111(dir, session3.file), "utf-8"));
|
|
476564
477083
|
} catch {
|
|
476565
477084
|
continue;
|
|
476566
477085
|
}
|
|
@@ -476896,8 +477415,8 @@ Current plan: ${balance.billing_tier}
|
|
|
476896
477415
|
* Quota Window End: ${quota.quotaWindowEnd}
|
|
476897
477416
|
* Daily Quota Window End: ${quota.dailyQuotaWindowEnd ?? "Unavailable"}
|
|
476898
477417
|
`;
|
|
476899
|
-
await new Promise((
|
|
476900
|
-
process.stdout.write(usage, (error4) => error4 ? reject2(error4) :
|
|
477418
|
+
await new Promise((resolve42, reject2) => {
|
|
477419
|
+
process.stdout.write(usage, (error4) => error4 ? reject2(error4) : resolve42());
|
|
476901
477420
|
});
|
|
476902
477421
|
return 0;
|
|
476903
477422
|
} catch (error4) {
|
|
@@ -481014,12 +481533,12 @@ function createRoutedRuntimeRegistrationRefresher(options) {
|
|
|
481014
481533
|
});
|
|
481015
481534
|
return run;
|
|
481016
481535
|
};
|
|
481017
|
-
const waitForRetry = () => new Promise((
|
|
481018
|
-
resolveRetry =
|
|
481536
|
+
const waitForRetry = () => new Promise((resolve42) => {
|
|
481537
|
+
resolveRetry = resolve42;
|
|
481019
481538
|
retryTimer = setTimeout(() => {
|
|
481020
481539
|
retryTimer = null;
|
|
481021
481540
|
resolveRetry = null;
|
|
481022
|
-
|
|
481541
|
+
resolve42();
|
|
481023
481542
|
}, retryDelayMs);
|
|
481024
481543
|
retryTimer.unref?.();
|
|
481025
481544
|
});
|
|
@@ -481655,7 +482174,7 @@ async function runChannelGatewaySubcommand(argv) {
|
|
|
481655
482174
|
await ensureChannelRuntimeInstalled2(channelName);
|
|
481656
482175
|
}
|
|
481657
482176
|
}
|
|
481658
|
-
return await new Promise((
|
|
482177
|
+
return await new Promise((resolve42) => {
|
|
481659
482178
|
let closing2 = false;
|
|
481660
482179
|
let closeGateway = null;
|
|
481661
482180
|
const finish2 = (code) => {
|
|
@@ -481663,10 +482182,10 @@ async function runChannelGatewaySubcommand(argv) {
|
|
|
481663
482182
|
return;
|
|
481664
482183
|
closing2 = true;
|
|
481665
482184
|
if (!closeGateway) {
|
|
481666
|
-
|
|
482185
|
+
resolve42(code);
|
|
481667
482186
|
return;
|
|
481668
482187
|
}
|
|
481669
|
-
closeGateway().finally(() =>
|
|
482188
|
+
closeGateway().finally(() => resolve42(code));
|
|
481670
482189
|
};
|
|
481671
482190
|
startLocalChannelGateway({
|
|
481672
482191
|
appServerUrl,
|
|
@@ -481714,7 +482233,7 @@ async function runChannelGatewaySubcommand(argv) {
|
|
|
481714
482233
|
gateway.close();
|
|
481715
482234
|
}).catch((error4) => {
|
|
481716
482235
|
console.error(error4 instanceof Error ? error4.message : String(error4));
|
|
481717
|
-
|
|
482236
|
+
resolve42(1);
|
|
481718
482237
|
});
|
|
481719
482238
|
});
|
|
481720
482239
|
}
|
|
@@ -481961,10 +482480,10 @@ async function detectAndEnableKittyProtocol() {
|
|
|
481961
482480
|
detectionComplete = true;
|
|
481962
482481
|
return;
|
|
481963
482482
|
}
|
|
481964
|
-
return new Promise((
|
|
482483
|
+
return new Promise((resolve42) => {
|
|
481965
482484
|
if (!process.stdin.isTTY || !process.stdout.isTTY) {
|
|
481966
482485
|
detectionComplete = true;
|
|
481967
|
-
|
|
482486
|
+
resolve42();
|
|
481968
482487
|
return;
|
|
481969
482488
|
}
|
|
481970
482489
|
const originalRawMode = process.stdin.isRaw;
|
|
@@ -481997,7 +482516,7 @@ async function detectAndEnableKittyProtocol() {
|
|
|
481997
482516
|
console.error("[kitty] protocol query unsupported; enabled anyway (best-effort)");
|
|
481998
482517
|
}
|
|
481999
482518
|
detectionComplete = true;
|
|
482000
|
-
|
|
482519
|
+
resolve42();
|
|
482001
482520
|
};
|
|
482002
482521
|
const handleData = (data) => {
|
|
482003
482522
|
if (timeoutId === undefined) {
|
|
@@ -482516,8 +483035,8 @@ async function waitForEnqueuedReply(params) {
|
|
|
482516
483035
|
let timer;
|
|
482517
483036
|
const event = await Promise.race([
|
|
482518
483037
|
next,
|
|
482519
|
-
new Promise((
|
|
482520
|
-
timer = setTimeout(() =>
|
|
483038
|
+
new Promise((resolve42) => {
|
|
483039
|
+
timer = setTimeout(() => resolve42(null), params.pollMs ?? 1000);
|
|
482521
483040
|
})
|
|
482522
483041
|
]).finally(() => clearTimeout(timer));
|
|
482523
483042
|
if (event) {
|
|
@@ -482894,7 +483413,7 @@ function resolveHeadlessMemfsPolicy(options) {
|
|
|
482894
483413
|
var init_headless_memfs_policy = () => {};
|
|
482895
483414
|
|
|
482896
483415
|
// src/headless-mod-adapter.ts
|
|
482897
|
-
import { join as
|
|
483416
|
+
import { join as join112 } from "node:path";
|
|
482898
483417
|
function isHeadlessMemfsEnabled(agentId) {
|
|
482899
483418
|
try {
|
|
482900
483419
|
return settingsManager.isMemfsEnabled(agentId);
|
|
@@ -482965,7 +483484,7 @@ function createHeadlessModContext(options) {
|
|
|
482965
483484
|
};
|
|
482966
483485
|
}
|
|
482967
483486
|
function createHeadlessModAdapter(options) {
|
|
482968
|
-
const agentModsDirectory = isHeadlessMemfsEnabled(options.agent.id) ?
|
|
483487
|
+
const agentModsDirectory = isHeadlessMemfsEnabled(options.agent.id) ? join112(getScopedMemoryFilesystemRoot(options.agent.id), "mods") : undefined;
|
|
482969
483488
|
return createModAdapter({
|
|
482970
483489
|
...agentModsDirectory ? { agentModsDirectory } : {},
|
|
482971
483490
|
...options.cacheDirectory ? { cacheDirectory: options.cacheDirectory } : {},
|
|
@@ -483087,9 +483606,9 @@ function writeWireMessage(msg) {
|
|
|
483087
483606
|
async function writeWireMessageAsync(msg) {
|
|
483088
483607
|
const line = `${JSON.stringify(stampWireMessage(msg))}
|
|
483089
483608
|
`;
|
|
483090
|
-
return await new Promise((
|
|
483609
|
+
return await new Promise((resolve42, reject2) => {
|
|
483091
483610
|
if (process.stdout.destroyed || process.stdout.writableEnded) {
|
|
483092
|
-
|
|
483611
|
+
resolve42(false);
|
|
483093
483612
|
return;
|
|
483094
483613
|
}
|
|
483095
483614
|
process.stdout.write(line, (error4) => {
|
|
@@ -483097,7 +483616,7 @@ async function writeWireMessageAsync(msg) {
|
|
|
483097
483616
|
reject2(error4);
|
|
483098
483617
|
return;
|
|
483099
483618
|
}
|
|
483100
|
-
|
|
483619
|
+
resolve42(true);
|
|
483101
483620
|
});
|
|
483102
483621
|
});
|
|
483103
483622
|
}
|
|
@@ -483487,10 +484006,11 @@ async function sendScopedApprovalMessages(params) {
|
|
|
483487
484006
|
});
|
|
483488
484007
|
}
|
|
483489
484008
|
async function flushAndExit(code) {
|
|
483490
|
-
|
|
484009
|
+
await shutdownMonitors();
|
|
484010
|
+
const flushWritable = (stream11) => new Promise((resolve42) => {
|
|
483491
484011
|
if (stream11.destroyed || stream11.writableEnded)
|
|
483492
|
-
return
|
|
483493
|
-
stream11.write("", () =>
|
|
484012
|
+
return resolve42();
|
|
484013
|
+
stream11.write("", () => resolve42());
|
|
483494
484014
|
});
|
|
483495
484015
|
await closeClientMcpServers();
|
|
483496
484016
|
await Promise.allSettled([
|
|
@@ -483500,12 +484020,12 @@ async function flushAndExit(code) {
|
|
|
483500
484020
|
process.exit(code);
|
|
483501
484021
|
}
|
|
483502
484022
|
async function writeFinalHeadlessStdout(text3) {
|
|
483503
|
-
await new Promise((
|
|
484023
|
+
await new Promise((resolve42) => {
|
|
483504
484024
|
if (process.stdout.destroyed || process.stdout.writableEnded) {
|
|
483505
|
-
|
|
484025
|
+
resolve42();
|
|
483506
484026
|
return;
|
|
483507
484027
|
}
|
|
483508
|
-
process.stdout.write(text3, () =>
|
|
484028
|
+
process.stdout.write(text3, () => resolve42());
|
|
483509
484029
|
});
|
|
483510
484030
|
}
|
|
483511
484031
|
async function handleHeadlessCommand(parsedArgs, model2, skillsDirectoryOverride, skillSourcesOverride, systemInfoReminderEnabledOverride, startupOptions = {}) {
|
|
@@ -484620,7 +485140,7 @@ Current session AGENT_ID=${process.env.AGENT_ID}; --backend local switches to a
|
|
|
484620
485140
|
} else {
|
|
484621
485141
|
console.error(`Conversation is busy, waiting ${Math.round(retryDelayMs / 1000)}s and retrying...`);
|
|
484622
485142
|
}
|
|
484623
|
-
await new Promise((
|
|
485143
|
+
await new Promise((resolve42) => setTimeout(resolve42, retryDelayMs));
|
|
484624
485144
|
continue;
|
|
484625
485145
|
}
|
|
484626
485146
|
}
|
|
@@ -484649,7 +485169,7 @@ Current session AGENT_ID=${process.env.AGENT_ID}; --backend local switches to a
|
|
|
484649
485169
|
const delaySeconds = Math.round(delayMs / 1000);
|
|
484650
485170
|
console.error(`Transient API error before streaming (attempt ${attempt2} of ${LLM_API_ERROR_MAX_RETRIES2}), retrying in ${delaySeconds}s...`);
|
|
484651
485171
|
}
|
|
484652
|
-
await new Promise((
|
|
485172
|
+
await new Promise((resolve42) => setTimeout(resolve42, delayMs));
|
|
484653
485173
|
conversationBusyRetries = 0;
|
|
484654
485174
|
continue;
|
|
484655
485175
|
}
|
|
@@ -484899,7 +485419,7 @@ Current session AGENT_ID=${process.env.AGENT_ID}; --backend local switches to a
|
|
|
484899
485419
|
const delaySeconds = Math.round(delayMs / 1000);
|
|
484900
485420
|
console.error(`LLM API error encountered (attempt ${attempt2} of ${LLM_API_ERROR_MAX_RETRIES2}), retrying in ${delaySeconds}s...`);
|
|
484901
485421
|
}
|
|
484902
|
-
await new Promise((
|
|
485422
|
+
await new Promise((resolve42) => setTimeout(resolve42, delayMs));
|
|
484903
485423
|
currentInput = refreshInputOtidsForNewRequest(currentInput);
|
|
484904
485424
|
continue;
|
|
484905
485425
|
}
|
|
@@ -484991,7 +485511,7 @@ Current session AGENT_ID=${process.env.AGENT_ID}; --backend local switches to a
|
|
|
484991
485511
|
} else {
|
|
484992
485512
|
console.error(`Empty LLM response, retrying (attempt ${attempt2} of ${EMPTY_RESPONSE_MAX_RETRIES2})...`);
|
|
484993
485513
|
}
|
|
484994
|
-
await new Promise((
|
|
485514
|
+
await new Promise((resolve42) => setTimeout(resolve42, delayMs));
|
|
484995
485515
|
currentInput = refreshInputOtidsForNewRequest(currentInput);
|
|
484996
485516
|
continue;
|
|
484997
485517
|
}
|
|
@@ -485019,7 +485539,7 @@ Current session AGENT_ID=${process.env.AGENT_ID}; --backend local switches to a
|
|
|
485019
485539
|
const delaySeconds = Math.round(delayMs / 1000);
|
|
485020
485540
|
console.error(`LLM API error encountered (attempt ${attempt2} of ${LLM_API_ERROR_MAX_RETRIES2}), retrying in ${delaySeconds}s...`);
|
|
485021
485541
|
}
|
|
485022
|
-
await new Promise((
|
|
485542
|
+
await new Promise((resolve42) => setTimeout(resolve42, delayMs));
|
|
485023
485543
|
currentInput = refreshInputOtidsForNewRequest(currentInput);
|
|
485024
485544
|
continue;
|
|
485025
485545
|
}
|
|
@@ -485049,7 +485569,7 @@ Current session AGENT_ID=${process.env.AGENT_ID}; --backend local switches to a
|
|
|
485049
485569
|
const delaySeconds = Math.round(delayMs / 1000);
|
|
485050
485570
|
console.error(`LLM API error encountered (attempt ${attempt2} of ${LLM_API_ERROR_MAX_RETRIES2}), retrying in ${delaySeconds}s...`);
|
|
485051
485571
|
}
|
|
485052
|
-
await new Promise((
|
|
485572
|
+
await new Promise((resolve42) => setTimeout(resolve42, delayMs));
|
|
485053
485573
|
currentInput = refreshInputOtidsForNewRequest(currentInput);
|
|
485054
485574
|
continue;
|
|
485055
485575
|
}
|
|
@@ -485449,9 +485969,9 @@ async function runBidirectionalMode(agent, conversationId, effectiveModel, _outp
|
|
|
485449
485969
|
const syntheticUserLine = serializeQueuedMessageAsUserLine(queuedMessage);
|
|
485450
485970
|
maybeNotifyBlocked(syntheticUserLine);
|
|
485451
485971
|
if (lineResolver) {
|
|
485452
|
-
const
|
|
485972
|
+
const resolve42 = lineResolver;
|
|
485453
485973
|
lineResolver = null;
|
|
485454
|
-
|
|
485974
|
+
resolve42(syntheticUserLine);
|
|
485455
485975
|
return;
|
|
485456
485976
|
}
|
|
485457
485977
|
lineQueue.push(syntheticUserLine);
|
|
@@ -485471,9 +485991,9 @@ async function runBidirectionalMode(agent, conversationId, effectiveModel, _outp
|
|
|
485471
485991
|
if (action === "abort-active") {
|
|
485472
485992
|
currentAbortController.abort();
|
|
485473
485993
|
if (lineResolver) {
|
|
485474
|
-
const
|
|
485994
|
+
const resolve42 = lineResolver;
|
|
485475
485995
|
lineResolver = null;
|
|
485476
|
-
|
|
485996
|
+
resolve42(null);
|
|
485477
485997
|
}
|
|
485478
485998
|
} else if (action === "latch") {
|
|
485479
485999
|
pendingInterrupt = true;
|
|
@@ -485493,9 +486013,9 @@ async function runBidirectionalMode(agent, conversationId, effectiveModel, _outp
|
|
|
485493
486013
|
if (lineResolver) {
|
|
485494
486014
|
if (parsedLine?.type === "user")
|
|
485495
486015
|
turnStarting = true;
|
|
485496
|
-
const
|
|
486016
|
+
const resolve42 = lineResolver;
|
|
485497
486017
|
lineResolver = null;
|
|
485498
|
-
|
|
486018
|
+
resolve42(line);
|
|
485499
486019
|
} else {
|
|
485500
486020
|
lineQueue.push(line);
|
|
485501
486021
|
}
|
|
@@ -485504,17 +486024,17 @@ async function runBidirectionalMode(agent, conversationId, effectiveModel, _outp
|
|
|
485504
486024
|
setMessageQueueAdder(null);
|
|
485505
486025
|
msgQueueRuntime.clear("shutdown");
|
|
485506
486026
|
if (lineResolver) {
|
|
485507
|
-
const
|
|
486027
|
+
const resolve42 = lineResolver;
|
|
485508
486028
|
lineResolver = null;
|
|
485509
|
-
|
|
486029
|
+
resolve42(null);
|
|
485510
486030
|
}
|
|
485511
486031
|
});
|
|
485512
486032
|
async function getNextLine() {
|
|
485513
486033
|
if (lineQueue.length > 0) {
|
|
485514
486034
|
return lineQueue.shift() ?? null;
|
|
485515
486035
|
}
|
|
485516
|
-
return new Promise((
|
|
485517
|
-
lineResolver =
|
|
486036
|
+
return new Promise((resolve42) => {
|
|
486037
|
+
lineResolver = resolve42;
|
|
485518
486038
|
});
|
|
485519
486039
|
}
|
|
485520
486040
|
const EXTERNAL_TOOL_WAIT_ABORTED = Symbol("externalToolWaitAborted");
|
|
@@ -485525,17 +486045,17 @@ async function runBidirectionalMode(agent, conversationId, effectiveModel, _outp
|
|
|
485525
486045
|
return lineQueue.shift() ?? null;
|
|
485526
486046
|
if (!signal)
|
|
485527
486047
|
return getNextLine();
|
|
485528
|
-
return new Promise((
|
|
486048
|
+
return new Promise((resolve42) => {
|
|
485529
486049
|
const cleanup = () => signal.removeEventListener("abort", onAbort);
|
|
485530
486050
|
const onAbort = () => {
|
|
485531
486051
|
cleanup();
|
|
485532
486052
|
if (lineResolver === settle3)
|
|
485533
486053
|
lineResolver = null;
|
|
485534
|
-
|
|
486054
|
+
resolve42(EXTERNAL_TOOL_WAIT_ABORTED);
|
|
485535
486055
|
};
|
|
485536
486056
|
const settle3 = (line) => {
|
|
485537
486057
|
cleanup();
|
|
485538
|
-
|
|
486058
|
+
resolve42(line);
|
|
485539
486059
|
};
|
|
485540
486060
|
signal.addEventListener("abort", onAbort);
|
|
485541
486061
|
lineResolver = settle3;
|
|
@@ -486063,7 +486583,7 @@ async function runBidirectionalMode(agent, conversationId, effectiveModel, _outp
|
|
|
486063
486583
|
uuid: `retry-bidir-${randomUUID66()}`
|
|
486064
486584
|
};
|
|
486065
486585
|
writeWireMessage(retryMsg);
|
|
486066
|
-
await new Promise((
|
|
486586
|
+
await new Promise((resolve42) => setTimeout(resolve42, delayMs));
|
|
486067
486587
|
continue;
|
|
486068
486588
|
}
|
|
486069
486589
|
throw preStreamError;
|
|
@@ -486358,6 +486878,7 @@ var init_headless = __esm(() => {
|
|
|
486358
486878
|
init_runtime_execution_settings();
|
|
486359
486879
|
init_settings_manager();
|
|
486360
486880
|
init_memory_task_lifecycle();
|
|
486881
|
+
init_monitor();
|
|
486361
486882
|
init_manager2();
|
|
486362
486883
|
init_toolset();
|
|
486363
486884
|
init_debug();
|
|
@@ -486812,7 +487333,7 @@ var BYTES_PER_TOKEN = 4;
|
|
|
486812
487333
|
|
|
486813
487334
|
// src/cli/helpers/window-title-config.ts
|
|
486814
487335
|
import { homedir as homedir33 } from "node:os";
|
|
486815
|
-
import { basename as basename33, resolve as
|
|
487336
|
+
import { basename as basename33, resolve as resolve42 } from "node:path";
|
|
486816
487337
|
function isWindowTitleField(value) {
|
|
486817
487338
|
return WINDOW_TITLE_FIELDS.includes(value);
|
|
486818
487339
|
}
|
|
@@ -486970,7 +487491,7 @@ function terminalTitleProjectName(data) {
|
|
|
486970
487491
|
const directory = titleDirectory(data);
|
|
486971
487492
|
if (!directory)
|
|
486972
487493
|
return null;
|
|
486973
|
-
const resolved =
|
|
487494
|
+
const resolved = resolve42(directory);
|
|
486974
487495
|
const name = basename33(resolved) || formatDirectoryDisplay(resolved) || resolved;
|
|
486975
487496
|
return truncateTerminalTitlePart(name, 24);
|
|
486976
487497
|
}
|
|
@@ -486980,7 +487501,7 @@ function titleDirectory(data) {
|
|
|
486980
487501
|
function formatDirectoryDisplay(directory) {
|
|
486981
487502
|
if (!directory)
|
|
486982
487503
|
return null;
|
|
486983
|
-
const resolved =
|
|
487504
|
+
const resolved = resolve42(directory);
|
|
486984
487505
|
const home = homedir33();
|
|
486985
487506
|
if (resolved === home)
|
|
486986
487507
|
return "~";
|
|
@@ -487656,10 +488177,10 @@ import { execFile as execFileCb4 } from "node:child_process";
|
|
|
487656
488177
|
import { existsSync as existsSync75 } from "node:fs";
|
|
487657
488178
|
import { appendFile as appendFile3, chmod, mkdir as mkdir18, writeFile as writeFile21 } from "node:fs/promises";
|
|
487658
488179
|
import { homedir as homedir34 } from "node:os";
|
|
487659
|
-
import { join as
|
|
487660
|
-
import { promisify as
|
|
488180
|
+
import { join as join114 } from "node:path";
|
|
488181
|
+
import { promisify as promisify20 } from "node:util";
|
|
487661
488182
|
function getReflectionArenaHfCacheRoot(env6 = process.env, fallbackHome = homedir34()) {
|
|
487662
|
-
return
|
|
488183
|
+
return join114(resolveGlobalConfigDir(env6, fallbackHome), "reflection-arena", "hf-upload");
|
|
487663
488184
|
}
|
|
487664
488185
|
function buildGitEnv(token2, askpassPath) {
|
|
487665
488186
|
return {
|
|
@@ -487683,7 +488204,7 @@ function formatTokenStatus(token2) {
|
|
|
487683
488204
|
}
|
|
487684
488205
|
async function runGit6(cwd2, args, env6) {
|
|
487685
488206
|
try {
|
|
487686
|
-
await
|
|
488207
|
+
await execFile23("git", args, {
|
|
487687
488208
|
cwd: cwd2,
|
|
487688
488209
|
env: env6,
|
|
487689
488210
|
encoding: "utf-8",
|
|
@@ -487695,7 +488216,7 @@ async function runGit6(cwd2, args, env6) {
|
|
|
487695
488216
|
}
|
|
487696
488217
|
}
|
|
487697
488218
|
async function writeGitAskpass(repoRoot) {
|
|
487698
|
-
const askpassPath =
|
|
488219
|
+
const askpassPath = join114(repoRoot, "hf-askpass.sh");
|
|
487699
488220
|
await writeFile21(askpassPath, [
|
|
487700
488221
|
"#!/bin/sh",
|
|
487701
488222
|
'case "$1" in',
|
|
@@ -487710,7 +488231,7 @@ async function writeGitAskpass(repoRoot) {
|
|
|
487710
488231
|
}
|
|
487711
488232
|
async function prepareHfRepo(env6) {
|
|
487712
488233
|
await mkdir18(HF_CACHE_ROOT, { recursive: true });
|
|
487713
|
-
if (!existsSync75(
|
|
488234
|
+
if (!existsSync75(join114(HF_REPO_DIR, ".git"))) {
|
|
487714
488235
|
await runGit6(HF_CACHE_ROOT, ["clone", "--depth", "1", HF_REPO_URL, HF_REPO_DIR], env6);
|
|
487715
488236
|
return HF_REPO_DIR;
|
|
487716
488237
|
}
|
|
@@ -487745,8 +488266,8 @@ async function maybeUploadReflectionArenaChoiceToHf(row) {
|
|
|
487745
488266
|
const env6 = buildGitEnv(token2, askpassPath);
|
|
487746
488267
|
try {
|
|
487747
488268
|
const repoDir = await prepareHfRepo(env6);
|
|
487748
|
-
await mkdir18(
|
|
487749
|
-
await appendFile3(
|
|
488269
|
+
await mkdir18(join114(repoDir, "data"), { recursive: true });
|
|
488270
|
+
await appendFile3(join114(repoDir, HF_DATASET_PATH), `${JSON.stringify(row)}
|
|
487750
488271
|
`, {
|
|
487751
488272
|
encoding: "utf-8"
|
|
487752
488273
|
});
|
|
@@ -487768,23 +488289,23 @@ async function maybeUploadReflectionArenaChoiceToHf(row) {
|
|
|
487768
488289
|
};
|
|
487769
488290
|
}
|
|
487770
488291
|
}
|
|
487771
|
-
var
|
|
488292
|
+
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
488293
|
var init_reflection_arena_hf_upload = __esm(() => {
|
|
487773
488294
|
init_secrets_store();
|
|
487774
488295
|
init_settings_path();
|
|
487775
488296
|
init_version();
|
|
487776
|
-
|
|
488297
|
+
execFile23 = promisify20(execFileCb4);
|
|
487777
488298
|
HF_REPO_URL = `https://huggingface.co/datasets/${HF_REPO_ID}`;
|
|
487778
488299
|
HF_CACHE_ROOT = getReflectionArenaHfCacheRoot();
|
|
487779
|
-
HF_REPO_DIR =
|
|
488300
|
+
HF_REPO_DIR = join114(HF_CACHE_ROOT, "repo");
|
|
487780
488301
|
});
|
|
487781
488302
|
|
|
487782
488303
|
// src/cli/helpers/reflection-arena.ts
|
|
487783
488304
|
import { execFile as execFileCb5 } from "node:child_process";
|
|
487784
488305
|
import { randomInt as randomInt2, randomUUID as randomUUID67 } from "node:crypto";
|
|
487785
488306
|
import { appendFile as appendFile4, mkdir as mkdir19, readFile as readFile34, writeFile as writeFile22 } from "node:fs/promises";
|
|
487786
|
-
import { join as
|
|
487787
|
-
import { promisify as
|
|
488307
|
+
import { join as join115 } from "node:path";
|
|
488308
|
+
import { promisify as promisify21 } from "node:util";
|
|
487788
488309
|
function sampleReflectionArenaComparisonModel(excludedModels = []) {
|
|
487789
488310
|
const excluded = new Set(excludedModels);
|
|
487790
488311
|
const candidates = REFLECTION_ARENA_COMPARISON_MODEL_POOL.filter((entry) => !excluded.has(entry.model));
|
|
@@ -487801,7 +488322,7 @@ function sampleReflectionArenaComparisonModel(excludedModels = []) {
|
|
|
487801
488322
|
}
|
|
487802
488323
|
async function getGitOutput(cwd2, args) {
|
|
487803
488324
|
try {
|
|
487804
|
-
const { stdout } = await
|
|
488325
|
+
const { stdout } = await execFile24("git", args, {
|
|
487805
488326
|
cwd: cwd2,
|
|
487806
488327
|
encoding: "utf-8",
|
|
487807
488328
|
timeout: 30000,
|
|
@@ -487832,16 +488353,16 @@ function candidateIsConfirmedNoOp(candidate) {
|
|
|
487832
488353
|
return candidate.result?.success === true && candidate.result.memoryNoChanges === true && candidate.result.memoryHead === candidate.worktree.baseHead;
|
|
487833
488354
|
}
|
|
487834
488355
|
function getReflectionArenaRoot() {
|
|
487835
|
-
return
|
|
488356
|
+
return join115(resolveGlobalConfigDir(), "reflection-arena");
|
|
487836
488357
|
}
|
|
487837
488358
|
function getReflectionArenaRunsDir() {
|
|
487838
|
-
return
|
|
488359
|
+
return join115(getReflectionArenaRoot(), "runs");
|
|
487839
488360
|
}
|
|
487840
488361
|
function getReflectionArenaChoiceLogPath() {
|
|
487841
|
-
return
|
|
488362
|
+
return join115(getReflectionArenaRoot(), "choices.jsonl");
|
|
487842
488363
|
}
|
|
487843
488364
|
function getReflectionArenaRunPath(runId) {
|
|
487844
|
-
return
|
|
488365
|
+
return join115(getReflectionArenaRunsDir(), `${runId}.json`);
|
|
487845
488366
|
}
|
|
487846
488367
|
async function saveReflectionArenaRun(run) {
|
|
487847
488368
|
await mkdir19(getReflectionArenaRunsDir(), { recursive: true });
|
|
@@ -488357,7 +488878,7 @@ async function finalizeReflectionArenaChoice(options) {
|
|
|
488357
488878
|
run: completedRun
|
|
488358
488879
|
};
|
|
488359
488880
|
}
|
|
488360
|
-
var
|
|
488881
|
+
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
488882
|
var init_reflection_arena = __esm(() => {
|
|
488362
488883
|
init_memory_worktree();
|
|
488363
488884
|
init_app_urls();
|
|
@@ -488368,7 +488889,7 @@ var init_reflection_arena = __esm(() => {
|
|
|
488368
488889
|
init_telemetry();
|
|
488369
488890
|
init_debug();
|
|
488370
488891
|
init_settings_path();
|
|
488371
|
-
|
|
488892
|
+
execFile24 = promisify21(execFileCb5);
|
|
488372
488893
|
REFLECTION_ARENA_COMPARISON_MODEL_POOL = [
|
|
488373
488894
|
{ model: "lc-anthropic/claude-sonnet-5", weight: 1 },
|
|
488374
488895
|
{ model: "lc-anthropic/claude-opus-4-8", weight: 3 },
|
|
@@ -488901,8 +489422,8 @@ async function pushToMemoryRepositoryWithTimeout(agentId) {
|
|
|
488901
489422
|
try {
|
|
488902
489423
|
return await Promise.race([
|
|
488903
489424
|
pushToMemoryRepository(agentId),
|
|
488904
|
-
new Promise((
|
|
488905
|
-
timeout = setTimeout(() =>
|
|
489425
|
+
new Promise((resolve43) => {
|
|
489426
|
+
timeout = setTimeout(() => resolve43("timeout"), INITIAL_PUSH_TIMEOUT_MS);
|
|
488906
489427
|
})
|
|
488907
489428
|
]);
|
|
488908
489429
|
} finally {
|
|
@@ -489382,7 +489903,7 @@ import {
|
|
|
489382
489903
|
writeFileSync as writeFileSync50
|
|
489383
489904
|
} from "node:fs";
|
|
489384
489905
|
import { homedir as homedir35, platform as platform10 } from "node:os";
|
|
489385
|
-
import { dirname as dirname43, join as
|
|
489906
|
+
import { dirname as dirname43, join as join116 } from "node:path";
|
|
489386
489907
|
function detectTerminalType() {
|
|
489387
489908
|
if (process.env.CURSOR_TRACE_ID || process.env.CURSOR_CHANNEL) {
|
|
489388
489909
|
return "cursor";
|
|
@@ -489414,16 +489935,16 @@ function getKeybindingsPath(terminal) {
|
|
|
489414
489935
|
}[terminal];
|
|
489415
489936
|
const os7 = platform10();
|
|
489416
489937
|
if (os7 === "darwin") {
|
|
489417
|
-
return
|
|
489938
|
+
return join116(homedir35(), "Library", "Application Support", appName, "User", "keybindings.json");
|
|
489418
489939
|
}
|
|
489419
489940
|
if (os7 === "win32") {
|
|
489420
489941
|
const appData = process.env.APPDATA;
|
|
489421
489942
|
if (!appData)
|
|
489422
489943
|
return null;
|
|
489423
|
-
return
|
|
489944
|
+
return join116(appData, appName, "User", "keybindings.json");
|
|
489424
489945
|
}
|
|
489425
489946
|
if (os7 === "linux") {
|
|
489426
|
-
return
|
|
489947
|
+
return join116(homedir35(), ".config", appName, "User", "keybindings.json");
|
|
489427
489948
|
}
|
|
489428
489949
|
return null;
|
|
489429
489950
|
}
|
|
@@ -489576,14 +490097,14 @@ function getWezTermConfigPath() {
|
|
|
489576
490097
|
}
|
|
489577
490098
|
const xdgConfig = process.env.XDG_CONFIG_HOME;
|
|
489578
490099
|
if (xdgConfig) {
|
|
489579
|
-
const xdgPath =
|
|
490100
|
+
const xdgPath = join116(xdgConfig, "wezterm", "wezterm.lua");
|
|
489580
490101
|
if (existsSync76(xdgPath))
|
|
489581
490102
|
return xdgPath;
|
|
489582
490103
|
}
|
|
489583
|
-
const configPath =
|
|
490104
|
+
const configPath = join116(homedir35(), ".config", "wezterm", "wezterm.lua");
|
|
489584
490105
|
if (existsSync76(configPath))
|
|
489585
490106
|
return configPath;
|
|
489586
|
-
return
|
|
490107
|
+
return join116(homedir35(), ".wezterm.lua");
|
|
489587
490108
|
}
|
|
489588
490109
|
function stripLuaCommentsFromLine(line, blockCommentEnd) {
|
|
489589
490110
|
let code = "";
|
|
@@ -489761,7 +490282,7 @@ __export(exports_settings, {
|
|
|
489761
490282
|
loadProjectSettings: () => loadProjectSettings,
|
|
489762
490283
|
getSetting: () => getSetting
|
|
489763
490284
|
});
|
|
489764
|
-
import { join as
|
|
490285
|
+
import { join as join117 } from "node:path";
|
|
489765
490286
|
function getSettingsPath() {
|
|
489766
490287
|
return resolveGlobalSettingsPath();
|
|
489767
490288
|
}
|
|
@@ -489803,7 +490324,7 @@ async function getSetting(key4) {
|
|
|
489803
490324
|
return settings[key4];
|
|
489804
490325
|
}
|
|
489805
490326
|
function getProjectSettingsPath() {
|
|
489806
|
-
return
|
|
490327
|
+
return join117(process.cwd(), ".letta", "settings.local.json");
|
|
489807
490328
|
}
|
|
489808
490329
|
async function loadProjectSettings() {
|
|
489809
490330
|
if (shouldIsolateHomeProjectConfig(process.cwd()))
|
|
@@ -489825,7 +490346,7 @@ async function saveProjectSettings(settings) {
|
|
|
489825
490346
|
if (shouldIsolateHomeProjectConfig(process.cwd()))
|
|
489826
490347
|
return;
|
|
489827
490348
|
const settingsPath = getProjectSettingsPath();
|
|
489828
|
-
const dirPath =
|
|
490349
|
+
const dirPath = join117(process.cwd(), ".letta");
|
|
489829
490350
|
try {
|
|
489830
490351
|
if (!exists(dirPath)) {
|
|
489831
490352
|
await mkdir(dirPath, { recursive: true });
|
|
@@ -490890,10 +491411,10 @@ var init_InlineBashApproval = __esm(async () => {
|
|
|
490890
491411
|
});
|
|
490891
491412
|
|
|
490892
491413
|
// src/cli/components/DiffRenderer.tsx
|
|
490893
|
-
import { relative as
|
|
491414
|
+
import { relative as relative12 } from "node:path";
|
|
490894
491415
|
function formatDisplayPath4(filePath) {
|
|
490895
491416
|
const cwd2 = process.cwd();
|
|
490896
|
-
const relativePath =
|
|
491417
|
+
const relativePath = relative12(cwd2, filePath);
|
|
490897
491418
|
if (relativePath.startsWith("..")) {
|
|
490898
491419
|
return filePath;
|
|
490899
491420
|
}
|
|
@@ -491252,10 +491773,10 @@ var init_DiffRenderer = __esm(async () => {
|
|
|
491252
491773
|
});
|
|
491253
491774
|
|
|
491254
491775
|
// src/cli/components/AdvancedDiffRenderer.tsx
|
|
491255
|
-
import { relative as
|
|
491776
|
+
import { relative as relative13 } from "node:path";
|
|
491256
491777
|
function formatRelativePath(filePath) {
|
|
491257
491778
|
const cwd2 = process.cwd();
|
|
491258
|
-
const relativePath =
|
|
491779
|
+
const relativePath = relative13(cwd2, filePath);
|
|
491259
491780
|
return relativePath.startsWith("..") ? relativePath : `./${relativePath}`;
|
|
491260
491781
|
}
|
|
491261
491782
|
function padLeft(n, width) {
|
|
@@ -491518,7 +492039,7 @@ function AdvancedDiffRenderer(props) {
|
|
|
491518
492039
|
}
|
|
491519
492040
|
const { hunks } = result3;
|
|
491520
492041
|
const filePath = props.filePath;
|
|
491521
|
-
const
|
|
492042
|
+
const relative14 = formatRelativePath(filePath);
|
|
491522
492043
|
const lang = languageFromPath(filePath);
|
|
491523
492044
|
const shouldHighlight = lang && !exceedsAdvancedDiffHighlightLimits(hunks);
|
|
491524
492045
|
const hunkSyntaxLines = [];
|
|
@@ -491541,7 +492062,7 @@ function AdvancedDiffRenderer(props) {
|
|
|
491541
492062
|
const rows = buildAdvancedDiffRows(hunks, hunkSyntaxLines);
|
|
491542
492063
|
const maxDisplayNo = rows.reduce((m4, r5) => Math.max(m4, r5.displayNo), 1);
|
|
491543
492064
|
const gutterWidth = String(maxDisplayNo).length;
|
|
491544
|
-
const header = props.kind === "write" ? `Wrote changes to ${
|
|
492065
|
+
const header = props.kind === "write" ? `Wrote changes to ${relative14}` : `Updated ${relative14}`;
|
|
491545
492066
|
if (rows.length === 0) {
|
|
491546
492067
|
const noChangesGutter = 4;
|
|
491547
492068
|
return /* @__PURE__ */ jsx_dev_runtime24.jsxDEV(Box_default, {
|
|
@@ -491592,7 +492113,7 @@ function AdvancedDiffRenderer(props) {
|
|
|
491592
492113
|
"No changes to ",
|
|
491593
492114
|
/* @__PURE__ */ jsx_dev_runtime24.jsxDEV(Text2, {
|
|
491594
492115
|
bold: true,
|
|
491595
|
-
children:
|
|
492116
|
+
children: relative14
|
|
491596
492117
|
}, undefined, false, undefined, this),
|
|
491597
492118
|
" (file content identical)"
|
|
491598
492119
|
]
|
|
@@ -491698,9 +492219,9 @@ function getHeaderText(fileEdit) {
|
|
|
491698
492219
|
} else if (operations2.length === 1) {
|
|
491699
492220
|
const op = operations2[0];
|
|
491700
492221
|
if (op) {
|
|
491701
|
-
const { relative:
|
|
492222
|
+
const { relative: relative15 } = __require("node:path");
|
|
491702
492223
|
const cwd3 = process.cwd();
|
|
491703
|
-
const relPath2 =
|
|
492224
|
+
const relPath2 = relative15(cwd3, op.path);
|
|
491704
492225
|
const displayPath2 = relPath2.startsWith("..") ? op.path : relPath2;
|
|
491705
492226
|
if (op.kind === "add") {
|
|
491706
492227
|
return `Write to ${displayPath2}?`;
|
|
@@ -491714,9 +492235,9 @@ function getHeaderText(fileEdit) {
|
|
|
491714
492235
|
}
|
|
491715
492236
|
return "Apply patch?";
|
|
491716
492237
|
}
|
|
491717
|
-
const { relative:
|
|
492238
|
+
const { relative: relative14 } = __require("node:path");
|
|
491718
492239
|
const cwd2 = process.cwd();
|
|
491719
|
-
const relPath =
|
|
492240
|
+
const relPath = relative14(cwd2, fileEdit.filePath);
|
|
491720
492241
|
const displayPath = relPath.startsWith("..") ? fileEdit.filePath : relPath;
|
|
491721
492242
|
if (t2 === "write") {
|
|
491722
492243
|
const { existsSync: existsSync77 } = __require("node:fs");
|
|
@@ -491889,9 +492410,9 @@ var init_InlineFileEditApproval = __esm(async () => {
|
|
|
491889
492410
|
children: fileEdit.patchInput ? /* @__PURE__ */ jsx_dev_runtime25.jsxDEV(Box_default, {
|
|
491890
492411
|
flexDirection: "column",
|
|
491891
492412
|
children: parsePatchOperations(fileEdit.patchInput).map((op, idx) => {
|
|
491892
|
-
const { relative:
|
|
492413
|
+
const { relative: relative14 } = __require("node:path");
|
|
491893
492414
|
const cwd2 = process.cwd();
|
|
491894
|
-
const relPath =
|
|
492415
|
+
const relPath = relative14(cwd2, op.path);
|
|
491895
492416
|
const displayPath = relPath.startsWith("..") ? op.path : relPath;
|
|
491896
492417
|
const diffKey = fileEdit.toolCallId ? `${fileEdit.toolCallId}:${op.path}` : undefined;
|
|
491897
492418
|
const opDiff = diffKey && allDiffs ? allDiffs.get(diffKey) : undefined;
|
|
@@ -500635,7 +501156,7 @@ var init_InputRich = __esm(async () => {
|
|
|
500635
501156
|
});
|
|
500636
501157
|
|
|
500637
501158
|
// src/cli/commands/install-github-app.ts
|
|
500638
|
-
import { execFileSync as
|
|
501159
|
+
import { execFileSync as execFileSync12 } from "node:child_process";
|
|
500639
501160
|
import {
|
|
500640
501161
|
existsSync as existsSync77,
|
|
500641
501162
|
mkdirSync as mkdirSync59,
|
|
@@ -500645,10 +501166,10 @@ import {
|
|
|
500645
501166
|
writeFileSync as writeFileSync51
|
|
500646
501167
|
} from "node:fs";
|
|
500647
501168
|
import { tmpdir as tmpdir16 } from "node:os";
|
|
500648
|
-
import { dirname as dirname44, join as
|
|
501169
|
+
import { dirname as dirname44, join as join118 } from "node:path";
|
|
500649
501170
|
function runCommand(command, args, cwd2, input) {
|
|
500650
501171
|
try {
|
|
500651
|
-
return
|
|
501172
|
+
return execFileSync12(command, args, {
|
|
500652
501173
|
cwd: cwd2,
|
|
500653
501174
|
encoding: "utf8",
|
|
500654
501175
|
stdio: [input ? "pipe" : "ignore", "pipe", "pipe"],
|
|
@@ -500866,8 +501387,8 @@ async function createLettaAgent(apiKey, name) {
|
|
|
500866
501387
|
return createMinimalAgent(apiKey, name);
|
|
500867
501388
|
}
|
|
500868
501389
|
function cloneRepoToTemp(repo) {
|
|
500869
|
-
const tempDir = mkdtempSync7(
|
|
500870
|
-
const repoDir =
|
|
501390
|
+
const tempDir = mkdtempSync7(join118(tmpdir16(), "letta-install-github-app-"));
|
|
501391
|
+
const repoDir = join118(tempDir, "repo");
|
|
500871
501392
|
runCommand("gh", ["repo", "clone", repo, repoDir, "--", "--depth=1"]);
|
|
500872
501393
|
return { tempDir, repoDir };
|
|
500873
501394
|
}
|
|
@@ -500878,7 +501399,7 @@ function runGit7(args, cwd2) {
|
|
|
500878
501399
|
return runCommand("git", args, cwd2);
|
|
500879
501400
|
}
|
|
500880
501401
|
function writeWorkflow(repoDir, workflowPath, content) {
|
|
500881
|
-
const absolutePath =
|
|
501402
|
+
const absolutePath = join118(repoDir, workflowPath);
|
|
500882
501403
|
if (!existsSync77(dirname44(absolutePath))) {
|
|
500883
501404
|
mkdirSync59(dirname44(absolutePath), { recursive: true });
|
|
500884
501405
|
}
|
|
@@ -504768,8 +505289,8 @@ __export(exports_generate_memory_viewer, {
|
|
|
504768
505289
|
});
|
|
504769
505290
|
import { execFile as execFileCb6 } from "node:child_process";
|
|
504770
505291
|
import { chmodSync as chmodSync11, existsSync as existsSync78, mkdirSync as mkdirSync60, writeFileSync as writeFileSync52 } from "node:fs";
|
|
504771
|
-
import { join as
|
|
504772
|
-
import { promisify as
|
|
505292
|
+
import { join as join119 } from "node:path";
|
|
505293
|
+
import { promisify as promisify22 } from "node:util";
|
|
504773
505294
|
function messagesFromOverview(overview) {
|
|
504774
505295
|
return overview.messages?.map((message2) => ({
|
|
504775
505296
|
id: message2.id,
|
|
@@ -504796,7 +505317,7 @@ function contextFromOverview(overview, model2, contextWindow) {
|
|
|
504796
505317
|
}
|
|
504797
505318
|
async function runGitSafe(cwd2, args) {
|
|
504798
505319
|
try {
|
|
504799
|
-
const { stdout } = await
|
|
505320
|
+
const { stdout } = await execFile25("git", args, {
|
|
504800
505321
|
cwd: cwd2,
|
|
504801
505322
|
maxBuffer: 10 * 1024 * 1024,
|
|
504802
505323
|
timeout: 60000
|
|
@@ -505078,7 +505599,7 @@ ${m4.body}` : m4.subject;
|
|
|
505078
505599
|
async function generateAndOpenMemoryViewer(agentId, options) {
|
|
505079
505600
|
const memoryRoot = getScopedMemoryFilesystemRoot(agentId);
|
|
505080
505601
|
const repoDir = memoryRoot;
|
|
505081
|
-
if (!existsSync78(
|
|
505602
|
+
if (!existsSync78(join119(repoDir, ".git"))) {
|
|
505082
505603
|
throw new Error("Memory viewer requires memfs. Run /memfs enable first.");
|
|
505083
505604
|
}
|
|
505084
505605
|
const data = await collectMemoryData(agentId, repoDir, memoryRoot, options?.conversationId);
|
|
@@ -505094,7 +505615,7 @@ async function generateAndOpenMemoryViewer(agentId, options) {
|
|
|
505094
505615
|
try {
|
|
505095
505616
|
chmodSync11(VIEWERS_DIR, 448);
|
|
505096
505617
|
} catch {}
|
|
505097
|
-
const filePath =
|
|
505618
|
+
const filePath = join119(VIEWERS_DIR, `memory-${encodeURIComponent(agentId)}.html`);
|
|
505098
505619
|
writeFileSync52(filePath, html5);
|
|
505099
505620
|
chmodSync11(filePath, 384);
|
|
505100
505621
|
const skipOpen = Boolean(process.env.TMUX) || Boolean(process.env.SSH_CONNECTION) || Boolean(process.env.SSH_TTY);
|
|
@@ -505108,7 +505629,7 @@ async function generateAndOpenMemoryViewer(agentId, options) {
|
|
|
505108
505629
|
}
|
|
505109
505630
|
return { filePath, opened: !skipOpen };
|
|
505110
505631
|
}
|
|
505111
|
-
var
|
|
505632
|
+
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
505633
|
var init_generate_memory_viewer = __esm(() => {
|
|
505113
505634
|
init_memory_filesystem2();
|
|
505114
505635
|
init_memory_format();
|
|
@@ -505121,14 +505642,14 @@ var init_generate_memory_viewer = __esm(() => {
|
|
|
505121
505642
|
init_context_usage();
|
|
505122
505643
|
init_local_memory_context();
|
|
505123
505644
|
init_memory_viewer_template();
|
|
505124
|
-
|
|
505125
|
-
VIEWERS_DIR =
|
|
505645
|
+
execFile25 = promisify22(execFileCb6);
|
|
505646
|
+
VIEWERS_DIR = join119(resolveGlobalConfigDir(), "viewers");
|
|
505126
505647
|
REFLECTION_PATTERN = /\(reflection\)|🔮|reflection:/i;
|
|
505127
505648
|
});
|
|
505128
505649
|
|
|
505129
505650
|
// src/cli/components/MemfsTreeViewer.tsx
|
|
505130
505651
|
import { existsSync as existsSync79 } from "node:fs";
|
|
505131
|
-
import { join as
|
|
505652
|
+
import { join as join120 } from "node:path";
|
|
505132
505653
|
function renderTreePrefix(node) {
|
|
505133
505654
|
let prefix = "";
|
|
505134
505655
|
for (let i4 = 0;i4 < node.depth; i4++) {
|
|
@@ -505157,7 +505678,7 @@ function MemfsTreeViewer({
|
|
|
505157
505678
|
const statusTimerRef = import_react88.useRef(null);
|
|
505158
505679
|
const memoryRoot = getScopedMemoryFilesystemRoot(agentId);
|
|
505159
505680
|
const memoryExists = existsSync79(memoryRoot);
|
|
505160
|
-
const hasGitRepo = import_react88.useMemo(() => existsSync79(
|
|
505681
|
+
const hasGitRepo = import_react88.useMemo(() => existsSync79(join120(memoryRoot, ".git")), [memoryRoot]);
|
|
505161
505682
|
function showStatus(msg, durationMs) {
|
|
505162
505683
|
if (statusTimerRef.current)
|
|
505163
505684
|
clearTimeout(statusTimerRef.current);
|
|
@@ -507889,10 +508410,10 @@ var init_use_chatgpt_rate_limit_state = __esm(() => {
|
|
|
507889
508410
|
// src/utils/aws-credentials.ts
|
|
507890
508411
|
import { readFile as readFile35 } from "node:fs/promises";
|
|
507891
508412
|
import { homedir as homedir36 } from "node:os";
|
|
507892
|
-
import { join as
|
|
508413
|
+
import { join as join121 } from "node:path";
|
|
507893
508414
|
async function parseAwsCredentials() {
|
|
507894
|
-
const credentialsPath =
|
|
507895
|
-
const configPath =
|
|
508415
|
+
const credentialsPath = join121(homedir36(), ".aws", "credentials");
|
|
508416
|
+
const configPath = join121(homedir36(), ".aws", "config");
|
|
507896
508417
|
const profiles = new Map;
|
|
507897
508418
|
try {
|
|
507898
508419
|
const content = await readFile35(credentialsPath, "utf-8");
|
|
@@ -509655,7 +510176,7 @@ var init_ReasoningMessageRich = __esm(async () => {
|
|
|
509655
510176
|
});
|
|
509656
510177
|
|
|
509657
510178
|
// src/cli/components/skills-dialog-paths.ts
|
|
509658
|
-
import { join as
|
|
510179
|
+
import { join as join122 } from "node:path";
|
|
509659
510180
|
function displayDirectory(path50) {
|
|
509660
510181
|
return `${path50.replace(/\\/g, "/").replace(/\/$/, "")}/`;
|
|
509661
510182
|
}
|
|
@@ -509665,7 +510186,7 @@ function getSkillsTabDescription(tab2, agentId, env6 = process.env) {
|
|
|
509665
510186
|
return ".agents/skills/";
|
|
509666
510187
|
case "agent": {
|
|
509667
510188
|
const memoryDir = resolveScopedMemoryDir({ agentId, env: env6 });
|
|
509668
|
-
return memoryDir ? displayDirectory(
|
|
510189
|
+
return memoryDir ? displayDirectory(join122(memoryDir, "skills")) : "$MEMORY_DIR/skills/";
|
|
509669
510190
|
}
|
|
509670
510191
|
case "global":
|
|
509671
510192
|
return displayDirectory(getGlobalSkillsDir(env6));
|
|
@@ -509693,8 +510214,8 @@ function SkillsDialog({ onClose, agentId }) {
|
|
|
509693
510214
|
try {
|
|
509694
510215
|
const { discoverSkills: discoverSkills2, SKILLS_DIR: SKILLS_DIR2 } = await Promise.resolve().then(() => (init_skills5(), exports_skills2));
|
|
509695
510216
|
const { getSkillsDirectory: getSkillsDirectory2, getSkillSources: getSkillSources2 } = await Promise.resolve().then(() => (init_context(), exports_context));
|
|
509696
|
-
const { join:
|
|
509697
|
-
const skillsDir = getSkillsDirectory2() ||
|
|
510217
|
+
const { join: join123 } = await import("node:path");
|
|
510218
|
+
const skillsDir = getSkillsDirectory2() || join123(process.cwd(), SKILLS_DIR2);
|
|
509698
510219
|
const result3 = await discoverSkills2(skillsDir, agentId, {
|
|
509699
510220
|
sources: getSkillSources2()
|
|
509700
510221
|
});
|
|
@@ -514000,9 +514521,9 @@ function getFileEditHeader(toolName2, toolArgs) {
|
|
|
514000
514521
|
} else if (operations2.length === 1) {
|
|
514001
514522
|
const op = operations2[0];
|
|
514002
514523
|
if (op) {
|
|
514003
|
-
const { relative:
|
|
514524
|
+
const { relative: relative15 } = __require("node:path");
|
|
514004
514525
|
const cwd3 = process.cwd();
|
|
514005
|
-
const relPath2 =
|
|
514526
|
+
const relPath2 = relative15(cwd3, op.path);
|
|
514006
514527
|
const displayPath2 = relPath2.startsWith("..") ? op.path : relPath2;
|
|
514007
514528
|
if (op.kind === "add")
|
|
514008
514529
|
return `Write to ${displayPath2}?`;
|
|
@@ -514016,9 +514537,9 @@ function getFileEditHeader(toolName2, toolArgs) {
|
|
|
514016
514537
|
return "Apply patch?";
|
|
514017
514538
|
}
|
|
514018
514539
|
const filePath = args.file_path || "";
|
|
514019
|
-
const { relative:
|
|
514540
|
+
const { relative: relative14 } = __require("node:path");
|
|
514020
514541
|
const cwd2 = process.cwd();
|
|
514021
|
-
const relPath =
|
|
514542
|
+
const relPath = relative14(cwd2, filePath);
|
|
514022
514543
|
const displayPath = relPath.startsWith("..") ? filePath : relPath;
|
|
514023
514544
|
if (t2 === "write") {
|
|
514024
514545
|
const { existsSync: existsSync80 } = __require("node:fs");
|
|
@@ -514103,9 +514624,9 @@ var init_ApprovalPreview = __esm(async () => {
|
|
|
514103
514624
|
/* @__PURE__ */ jsx_dev_runtime96.jsxDEV(Box_default, {
|
|
514104
514625
|
flexDirection: "column",
|
|
514105
514626
|
children: operations2.map((op, idx) => {
|
|
514106
|
-
const { relative:
|
|
514627
|
+
const { relative: relative14 } = __require("node:path");
|
|
514107
514628
|
const cwd2 = process.cwd();
|
|
514108
|
-
const relPath =
|
|
514629
|
+
const relPath = relative14(cwd2, op.path);
|
|
514109
514630
|
const displayPath = relPath.startsWith("..") ? op.path : relPath;
|
|
514110
514631
|
const diffKey = toolCallId ? `${toolCallId}:${op.path}` : undefined;
|
|
514111
514632
|
const opDiff = diffKey && allDiffs ? allDiffs.get(diffKey) : undefined;
|
|
@@ -515792,11 +516313,11 @@ __export(exports_generate_diff_viewer, {
|
|
|
515792
516313
|
});
|
|
515793
516314
|
import { execFile as execFileCb7 } from "node:child_process";
|
|
515794
516315
|
import { chmodSync as chmodSync12, existsSync as existsSync80, mkdirSync as mkdirSync61, writeFileSync as writeFileSync53 } from "node:fs";
|
|
515795
|
-
import { isAbsolute as
|
|
515796
|
-
import { promisify as
|
|
516316
|
+
import { isAbsolute as isAbsolute29, join as join123, resolve as resolve43 } from "node:path";
|
|
516317
|
+
import { promisify as promisify23 } from "node:util";
|
|
515797
516318
|
async function runGit8(cwd2, args) {
|
|
515798
516319
|
try {
|
|
515799
|
-
const { stdout } = await
|
|
516320
|
+
const { stdout } = await execFile26("git", args, {
|
|
515800
516321
|
cwd: cwd2,
|
|
515801
516322
|
maxBuffer: GIT_MAX_BUFFER,
|
|
515802
516323
|
timeout: GIT_TIMEOUT_MS3
|
|
@@ -515994,7 +516515,7 @@ function escapeHtml3(value) {
|
|
|
515994
516515
|
function resolveTargetPath(targetPath) {
|
|
515995
516516
|
if (!targetPath?.trim())
|
|
515996
516517
|
return process.cwd();
|
|
515997
|
-
return
|
|
516518
|
+
return isAbsolute29(targetPath) ? targetPath : resolve43(process.cwd(), targetPath);
|
|
515998
516519
|
}
|
|
515999
516520
|
function shouldSkipOpen() {
|
|
516000
516521
|
return Boolean(process.env.TMUX) || Boolean(process.env.SSH_CONNECTION) || Boolean(process.env.SSH_TTY);
|
|
@@ -516021,7 +516542,7 @@ async function generateAndOpenDiffViewer(targetPath) {
|
|
|
516021
516542
|
try {
|
|
516022
516543
|
chmodSync12(VIEWERS_DIR2, 448);
|
|
516023
516544
|
} catch {}
|
|
516024
|
-
const filePath =
|
|
516545
|
+
const filePath = join123(VIEWERS_DIR2, `diff-${encodeURIComponent(worktreePath)}.html`);
|
|
516025
516546
|
writeFileSync53(filePath, html5);
|
|
516026
516547
|
chmodSync12(filePath, 384);
|
|
516027
516548
|
const skipOpen = shouldSkipOpen();
|
|
@@ -516035,7 +516556,7 @@ async function generateAndOpenDiffViewer(targetPath) {
|
|
|
516035
516556
|
}
|
|
516036
516557
|
return { filePath, opened: !skipOpen, fileCount: rendered.files.length };
|
|
516037
516558
|
}
|
|
516038
|
-
var
|
|
516559
|
+
var execFile26, VIEWERS_DIR2, GIT_TIMEOUT_MS3 = 60000, GIT_MAX_BUFFER, MAX_RENDERED_FILES = 100, DIFF_UNSAFE_CSS = `
|
|
516039
516560
|
:host {
|
|
516040
516561
|
--diffs-addition-color-override: #15803d;
|
|
516041
516562
|
--diffs-deletion-color-override: #b91c1c;
|
|
@@ -516090,8 +516611,8 @@ var execFile25, VIEWERS_DIR2, GIT_TIMEOUT_MS3 = 60000, GIT_MAX_BUFFER, MAX_RENDE
|
|
|
516090
516611
|
var init_generate_diff_viewer = __esm(() => {
|
|
516091
516612
|
init_settings_path();
|
|
516092
516613
|
init_diff_viewer_template();
|
|
516093
|
-
|
|
516094
|
-
VIEWERS_DIR2 =
|
|
516614
|
+
execFile26 = promisify23(execFileCb7);
|
|
516615
|
+
VIEWERS_DIR2 = join123(resolveGlobalConfigDir(), "viewers");
|
|
516095
516616
|
GIT_MAX_BUFFER = 50 * 1024 * 1024;
|
|
516096
516617
|
});
|
|
516097
516618
|
|
|
@@ -517286,11 +517807,13 @@ function saveLastSessionBeforeExit(conversationId) {
|
|
|
517286
517807
|
async function prepareSessionExit(conversationId) {
|
|
517287
517808
|
saveLastSessionBeforeExit(conversationId);
|
|
517288
517809
|
await cancelBackgroundMemoryTasks();
|
|
517810
|
+
await shutdownMonitors();
|
|
517289
517811
|
}
|
|
517290
517812
|
var init_session3 = __esm(() => {
|
|
517291
517813
|
init_context();
|
|
517292
517814
|
init_settings_manager();
|
|
517293
517815
|
init_memory_task_lifecycle();
|
|
517816
|
+
init_monitor();
|
|
517294
517817
|
});
|
|
517295
517818
|
|
|
517296
517819
|
// src/cli/app/use-agent-mcp-servers.ts
|
|
@@ -518052,7 +518575,7 @@ __export(exports_shell_aliases, {
|
|
|
518052
518575
|
});
|
|
518053
518576
|
import { existsSync as existsSync81, readFileSync as readFileSync59 } from "node:fs";
|
|
518054
518577
|
import { homedir as homedir37 } from "node:os";
|
|
518055
|
-
import { join as
|
|
518578
|
+
import { join as join124 } from "node:path";
|
|
518056
518579
|
function parseAliasesFromFile(filePath) {
|
|
518057
518580
|
const aliases = new Map;
|
|
518058
518581
|
if (!existsSync81(filePath)) {
|
|
@@ -518124,7 +518647,7 @@ function loadAliases(forceReload = false) {
|
|
|
518124
518647
|
const home = homedir37();
|
|
518125
518648
|
const allAliases = new Map;
|
|
518126
518649
|
for (const file of ALIAS_FILES) {
|
|
518127
|
-
const filePath =
|
|
518650
|
+
const filePath = join124(home, file);
|
|
518128
518651
|
const fileAliases = parseAliasesFromFile(filePath);
|
|
518129
518652
|
for (const [name, value] of fileAliases) {
|
|
518130
518653
|
allAliases.set(name, value);
|
|
@@ -519285,7 +519808,7 @@ var init_system_reminders2 = __esm(() => {
|
|
|
519285
519808
|
// src/cli/app/use-conversation-loop.ts
|
|
519286
519809
|
import { randomUUID as randomUUID71 } from "node:crypto";
|
|
519287
519810
|
function sleep12(ms) {
|
|
519288
|
-
return new Promise((
|
|
519811
|
+
return new Promise((resolve44) => setTimeout(resolve44, ms));
|
|
519289
519812
|
}
|
|
519290
519813
|
function makeExecutionPhaseHook(setExecutionPhase) {
|
|
519291
519814
|
return ({ chunk: chunk2 }) => {
|
|
@@ -519739,7 +520262,7 @@ function useConversationLoop(ctx) {
|
|
|
519739
520262
|
cancelled = true;
|
|
519740
520263
|
break;
|
|
519741
520264
|
}
|
|
519742
|
-
await new Promise((
|
|
520265
|
+
await new Promise((resolve44) => setTimeout(resolve44, 100));
|
|
519743
520266
|
}
|
|
519744
520267
|
if (!blockingRunId) {
|
|
519745
520268
|
buffersRef.current.byId.delete(statusId);
|
|
@@ -519786,7 +520309,7 @@ function useConversationLoop(ctx) {
|
|
|
519786
520309
|
cancelled = true;
|
|
519787
520310
|
break;
|
|
519788
520311
|
}
|
|
519789
|
-
await new Promise((
|
|
520312
|
+
await new Promise((resolve44) => setTimeout(resolve44, 100));
|
|
519790
520313
|
}
|
|
519791
520314
|
if (retryStatusId) {
|
|
519792
520315
|
buffersRef.current.byId.delete(retryStatusId);
|
|
@@ -520542,7 +521065,7 @@ ${feedback}
|
|
|
520542
521065
|
});
|
|
520543
521066
|
buffersRef.current.order.push(statusId);
|
|
520544
521067
|
refreshDerived();
|
|
520545
|
-
await new Promise((
|
|
521068
|
+
await new Promise((resolve44) => setTimeout(resolve44, delayMs));
|
|
520546
521069
|
buffersRef.current.byId.delete(statusId);
|
|
520547
521070
|
buffersRef.current.order = buffersRef.current.order.filter((id) => id !== statusId);
|
|
520548
521071
|
refreshDerived();
|
|
@@ -520582,7 +521105,7 @@ ${feedback}
|
|
|
520582
521105
|
cancelled = true;
|
|
520583
521106
|
break;
|
|
520584
521107
|
}
|
|
520585
|
-
await new Promise((
|
|
521108
|
+
await new Promise((resolve44) => setTimeout(resolve44, 100));
|
|
520586
521109
|
}
|
|
520587
521110
|
if (retryStatusId) {
|
|
520588
521111
|
buffersRef.current.byId.delete(retryStatusId);
|
|
@@ -523308,7 +523831,7 @@ async function writeHistoryArtifacts(params) {
|
|
|
523308
523831
|
}
|
|
523309
523832
|
async function defaultCommandRunner(command, args, options) {
|
|
523310
523833
|
const startedAt = Date.now();
|
|
523311
|
-
return new Promise((
|
|
523834
|
+
return new Promise((resolve44) => {
|
|
523312
523835
|
const child = spawn16(command, args, {
|
|
523313
523836
|
cwd: options.cwd,
|
|
523314
523837
|
env: options.env,
|
|
@@ -523335,7 +523858,7 @@ async function defaultCommandRunner(command, args, options) {
|
|
|
523335
523858
|
});
|
|
523336
523859
|
child.on("close", (exitCode) => {
|
|
523337
523860
|
clearTimeout(timeout);
|
|
523338
|
-
|
|
523861
|
+
resolve44({
|
|
523339
523862
|
args,
|
|
523340
523863
|
command,
|
|
523341
523864
|
cwd: options.cwd,
|
|
@@ -526127,10 +526650,10 @@ __export(exports_worktree_diff_list, {
|
|
|
526127
526650
|
});
|
|
526128
526651
|
import { execFile as execFileCb8 } from "node:child_process";
|
|
526129
526652
|
import { basename as basename34 } from "node:path";
|
|
526130
|
-
import { promisify as
|
|
526653
|
+
import { promisify as promisify24 } from "node:util";
|
|
526131
526654
|
async function runGit9(cwd2, args) {
|
|
526132
526655
|
try {
|
|
526133
|
-
const { stdout } = await
|
|
526656
|
+
const { stdout } = await execFile27("git", args, {
|
|
526134
526657
|
cwd: cwd2,
|
|
526135
526658
|
maxBuffer: GIT_MAX_BUFFER2,
|
|
526136
526659
|
timeout: GIT_TIMEOUT_MS4
|
|
@@ -526259,9 +526782,9 @@ async function listWorktreeDiffOptions(cwd2 = process.cwd()) {
|
|
|
526259
526782
|
const worktrees = parseWorktreeList(output, currentPath);
|
|
526260
526783
|
return Promise.all(worktrees.map((worktree) => summarizeWorktree(worktree)));
|
|
526261
526784
|
}
|
|
526262
|
-
var
|
|
526785
|
+
var execFile27, GIT_TIMEOUT_MS4 = 60000, GIT_MAX_BUFFER2;
|
|
526263
526786
|
var init_worktree_diff_list = __esm(() => {
|
|
526264
|
-
|
|
526787
|
+
execFile27 = promisify24(execFileCb8);
|
|
526265
526788
|
GIT_MAX_BUFFER2 = 10 * 1024 * 1024;
|
|
526266
526789
|
});
|
|
526267
526790
|
|
|
@@ -526360,7 +526883,7 @@ var init_conversation_switch_alert = __esm(() => {
|
|
|
526360
526883
|
import { randomUUID as randomUUID73 } from "node:crypto";
|
|
526361
526884
|
import { existsSync as existsSync82, readFileSync as readFileSync60, renameSync as renameSync14 } from "node:fs";
|
|
526362
526885
|
import { tmpdir as tmpdir17 } from "node:os";
|
|
526363
|
-
import { join as
|
|
526886
|
+
import { join as join125 } from "node:path";
|
|
526364
526887
|
async function findCustomCommandByName(commandName) {
|
|
526365
526888
|
const { findCustomCommand: findCustomCommand2 } = await Promise.resolve().then(() => (init_custom(), exports_custom));
|
|
526366
526889
|
return findCustomCommand2(commandName);
|
|
@@ -526968,8 +527491,8 @@ ${SYSTEM_REMINDER_CLOSE}`),
|
|
|
526968
527491
|
try {
|
|
526969
527492
|
const memoryRoot = getScopedMemoryFilesystemRoot(agentId);
|
|
526970
527493
|
const personaCandidates = [
|
|
526971
|
-
|
|
526972
|
-
|
|
527494
|
+
join125(memoryRoot, "system", "persona.md"),
|
|
527495
|
+
join125(memoryRoot, "memory", "system", "persona.md")
|
|
526973
527496
|
];
|
|
526974
527497
|
const personaPath = personaCandidates.find((candidate) => existsSync82(candidate));
|
|
526975
527498
|
if (personaPath) {
|
|
@@ -527817,7 +528340,7 @@ Path: ${memoryDir}`, true);
|
|
|
527817
528340
|
updateMemorySyncCommand(cmdId, "No local memory filesystem found to reset.", true, msg);
|
|
527818
528341
|
return { submitted: true };
|
|
527819
528342
|
}
|
|
527820
|
-
const backupDir =
|
|
528343
|
+
const backupDir = join125(tmpdir17(), `letta-memfs-reset-${agentId}-${Date.now()}`);
|
|
527821
528344
|
renameSync14(memoryDir, backupDir);
|
|
527822
528345
|
if (getBackend().capabilities.localMemfs) {
|
|
527823
528346
|
const { initializeLocalMemoryRepo: initializeLocalMemoryRepo2 } = await Promise.resolve().then(() => (init_memory_git(), exports_memory_git));
|
|
@@ -528726,7 +529249,7 @@ var init_use_submit_handler = __esm(async () => {
|
|
|
528726
529249
|
});
|
|
528727
529250
|
|
|
528728
529251
|
// src/cli/app/AppCoordinator.tsx
|
|
528729
|
-
import { join as
|
|
529252
|
+
import { join as join126 } from "node:path";
|
|
528730
529253
|
function buildStartupCommandHints(options) {
|
|
528731
529254
|
const {
|
|
528732
529255
|
isResumingConversation,
|
|
@@ -530007,7 +530530,7 @@ function App2({
|
|
|
530007
530530
|
agentId: a2.agentId ?? null
|
|
530008
530531
|
}))
|
|
530009
530532
|
});
|
|
530010
|
-
const agentModsDirectory = modContext.memfs.enabled && modContext.memfs.memoryDir ?
|
|
530533
|
+
const agentModsDirectory = modContext.memfs.enabled && modContext.memfs.memoryDir ? join126(modContext.memfs.memoryDir, "mods") : null;
|
|
530011
530534
|
const modAdapter = useLocalModAdapter(modContext, {
|
|
530012
530535
|
agentModsDirectory,
|
|
530013
530536
|
disabled: modsDisabled,
|
|
@@ -532348,12 +532871,12 @@ EXAMPLES
|
|
|
532348
532871
|
console.log(usage);
|
|
532349
532872
|
}
|
|
532350
532873
|
async function printInfo() {
|
|
532351
|
-
const { join:
|
|
532874
|
+
const { join: join127 } = await import("node:path");
|
|
532352
532875
|
const { getVersion: getVersion2 } = await Promise.resolve().then(() => (init_version(), exports_version));
|
|
532353
532876
|
const { SKILLS_DIR: SKILLS_DIR2 } = await Promise.resolve().then(() => (init_skills5(), exports_skills2));
|
|
532354
532877
|
const { exists: exists2 } = await Promise.resolve().then(() => (init_fs(), exports_fs));
|
|
532355
532878
|
const cwd2 = process.cwd();
|
|
532356
|
-
const skillsDir =
|
|
532879
|
+
const skillsDir = join127(cwd2, SKILLS_DIR2);
|
|
532357
532880
|
const skillsExist = exists2(skillsDir);
|
|
532358
532881
|
await settingsManager.loadLocalProjectSettings(cwd2);
|
|
532359
532882
|
const pinned = settingsManager.getPinnedAgents();
|
|
@@ -536215,4 +536738,4 @@ function registerBunOAuthFlows() {
|
|
|
536215
536738
|
registerBunOAuthFlows();
|
|
536216
536739
|
await init_src5().then(() => exports_src2);
|
|
536217
536740
|
|
|
536218
|
-
//# debugId=
|
|
536741
|
+
//# debugId=0AC80729B5970D2464756E2164756E21
|