@letta-ai/letta-code 0.34.70 → 0.34.71
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/app-server-client.cjs.map +2 -2
- package/dist/app-server-client.js.map +2 -2
- 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/subagent-state.d.ts +4 -1
- package/dist/types/agent/subagent-state.d.ts.map +1 -1
- package/dist/types/agent/subagents/background-link.d.ts +1 -1
- package/dist/types/agent/subagents/background-link.d.ts.map +1 -1
- package/dist/types/agent/subagents/child-send-tracking.d.ts +5 -0
- package/dist/types/agent/subagents/child-send-tracking.d.ts.map +1 -1
- package/dist/types/agent/subagents/ephemeral-subagent.d.ts +1 -0
- package/dist/types/agent/subagents/ephemeral-subagent.d.ts.map +1 -1
- package/dist/types/agent/subagents/index.d.ts.map +1 -1
- package/dist/types/agent/subagents/manager.d.ts.map +1 -1
- package/dist/types/agent/subagents/subagent-launcher.d.ts +1 -0
- package/dist/types/agent/subagents/subagent-launcher.d.ts.map +1 -1
- package/dist/types/backend/api/environments.d.ts +9 -2
- package/dist/types/backend/api/environments.d.ts.map +1 -1
- package/dist/types/backend/api/ephemeral-conversations.d.ts +1 -0
- package/dist/types/backend/api/ephemeral-conversations.d.ts.map +1 -1
- package/dist/types/backend/api/subagents.d.ts +48 -0
- package/dist/types/backend/api/subagents.d.ts.map +1 -0
- package/dist/types/backend/dev/pi-stream-adapter.d.ts +4 -10
- package/dist/types/backend/dev/pi-stream-adapter.d.ts.map +1 -1
- package/dist/types/backend/local/local-backend.d.ts +2 -0
- package/dist/types/backend/local/local-backend.d.ts.map +1 -1
- package/dist/types/backend/local/local-executor-factory.d.ts +2 -7
- package/dist/types/backend/local/local-executor-factory.d.ts.map +1 -1
- package/dist/types/permissions/checker.d.ts.map +1 -1
- package/dist/types/telemetry/error-reporting.d.ts +1 -0
- package/dist/types/telemetry/error-reporting.d.ts.map +1 -1
- package/dist/types/tools/impl/antigravity-session.d.ts +29 -0
- package/dist/types/tools/impl/antigravity-session.d.ts.map +1 -0
- package/dist/types/tools/impl/codex-app-server.d.ts.map +1 -1
- package/dist/types/tools/impl/external-coding-agent-task.d.ts.map +1 -1
- package/dist/types/tools/impl/external-coding-agent.d.ts +1 -1
- package/dist/types/tools/impl/external-coding-agent.d.ts.map +1 -1
- package/dist/types/tools/impl/external-llm-trace-launch.d.ts +1 -4
- package/dist/types/tools/impl/external-llm-trace-launch.d.ts.map +1 -1
- package/dist/types/tools/impl/external-llm-trace-payload.d.ts +1 -1
- package/dist/types/tools/impl/external-llm-trace-payload.d.ts.map +1 -1
- package/dist/types/tools/impl/external-llm-trace-proxy.d.ts +1 -0
- package/dist/types/tools/impl/external-llm-trace-proxy.d.ts.map +1 -1
- package/dist/types/tools/impl/external-llm-trace-session.d.ts.map +1 -1
- package/dist/types/tools/impl/list-agents.d.ts +35 -0
- package/dist/types/tools/impl/list-agents.d.ts.map +1 -0
- package/dist/types/tools/impl/native-session-owner.d.ts +3 -1
- package/dist/types/tools/impl/native-session-owner.d.ts.map +1 -1
- package/dist/types/tools/impl/remote-external-coding-agent.d.ts.map +1 -1
- package/dist/types/tools/impl/remote-external-worker-computer.d.ts.map +1 -1
- package/dist/types/tools/impl/send-agent-message.d.ts.map +1 -1
- package/dist/types/tools/impl/subagent-persistence.d.ts +10 -0
- package/dist/types/tools/impl/subagent-persistence.d.ts.map +1 -0
- package/dist/types/tools/impl/task-agent-selection.d.ts +1 -1
- package/dist/types/tools/impl/task-agent-selection.d.ts.map +1 -1
- package/dist/types/tools/impl/task-stop.d.ts.map +1 -1
- package/dist/types/tools/impl/task.d.ts +2 -1
- package/dist/types/tools/impl/task.d.ts.map +1 -1
- package/dist/types/tools/tool-definitions.d.ts +87 -0
- package/dist/types/tools/tool-definitions.d.ts.map +1 -1
- package/dist/types/tools/toolset-catalog.d.ts +1 -1
- package/dist/types/tools/toolset-catalog.d.ts.map +1 -1
- package/dist/types/types/app-server-info.d.ts +1 -0
- package/dist/types/types/app-server-info.d.ts.map +1 -1
- package/dist/types/types/external-tool-protocol.d.ts +1 -0
- package/dist/types/types/external-tool-protocol.d.ts.map +1 -1
- package/dist/types/utils/subagent-launch-marker.d.ts +1 -0
- package/dist/types/utils/subagent-launch-marker.d.ts.map +1 -1
- package/letta.js +1044 -298
- package/npm-shrinkwrap.json +123 -123
- package/package.json +2 -2
- package/skills/image-generation/SKILL.md +24 -11
package/letta.js
CHANGED
|
@@ -3472,14 +3472,14 @@ function trackEndTurnNoAssistant(params) {
|
|
|
3472
3472
|
});
|
|
3473
3473
|
}
|
|
3474
3474
|
function extractHttpStatus(message) {
|
|
3475
|
-
const match = /(?:^|:\s
|
|
3475
|
+
const match = /(?:^|:\s*|API error \()(?:HTTP\s+)?([45]\d{2})\b/.exec(message);
|
|
3476
3476
|
return match ? Number(match[1]) : undefined;
|
|
3477
3477
|
}
|
|
3478
3478
|
function reportExternalWorkerLaunchFailure(options) {
|
|
3479
3479
|
try {
|
|
3480
3480
|
const safe = (value, pattern) => value && pattern.test(value) ? value : undefined;
|
|
3481
3481
|
const safeId = (id) => safe(id, /^[a-zA-Z0-9_-]{1,128}$/);
|
|
3482
|
-
const httpStatus = extractHttpStatus(formatTelemetryErrorMessage(options.error));
|
|
3482
|
+
const httpStatus = options.httpStatus === undefined ? extractHttpStatus(formatTelemetryErrorMessage(options.error)) : options.httpStatus ?? undefined;
|
|
3483
3483
|
telemetry.trackError("external_worker_launch_failed", "External worker launch failed", JSON.stringify({
|
|
3484
3484
|
stage: options.stage,
|
|
3485
3485
|
harness: safe(options.harness, /^[a-z-]{1,32}$/),
|
|
@@ -4629,6 +4629,7 @@ var init_toolset_catalog = __esm(() => {
|
|
|
4629
4629
|
"SetWorkingDirectory",
|
|
4630
4630
|
"Task",
|
|
4631
4631
|
"SendAgentMessage",
|
|
4632
|
+
"ListAgents",
|
|
4632
4633
|
"Monitor",
|
|
4633
4634
|
"WatchPR",
|
|
4634
4635
|
"Wake",
|
|
@@ -4675,6 +4676,7 @@ var init_toolset_catalog = __esm(() => {
|
|
|
4675
4676
|
"Workflow",
|
|
4676
4677
|
"Task",
|
|
4677
4678
|
"SendAgentMessage",
|
|
4679
|
+
"ListAgents",
|
|
4678
4680
|
"TaskCreate",
|
|
4679
4681
|
"TaskGet",
|
|
4680
4682
|
"TaskList",
|
|
@@ -4693,6 +4695,7 @@ var init_toolset_catalog = __esm(() => {
|
|
|
4693
4695
|
"SetWorkingDirectory",
|
|
4694
4696
|
"Task",
|
|
4695
4697
|
"SendAgentMessage",
|
|
4698
|
+
"ListAgents",
|
|
4696
4699
|
"Monitor",
|
|
4697
4700
|
"WatchPR",
|
|
4698
4701
|
"Wake",
|
|
@@ -6139,7 +6142,7 @@ var package_default;
|
|
|
6139
6142
|
var init_package = __esm(() => {
|
|
6140
6143
|
package_default = {
|
|
6141
6144
|
name: "@letta-ai/letta-code",
|
|
6142
|
-
version: "0.34.
|
|
6145
|
+
version: "0.34.71",
|
|
6143
6146
|
lettaStartupLogProtocol: 1,
|
|
6144
6147
|
lettaConfigDirProtocol: 1,
|
|
6145
6148
|
description: "Letta Code is a CLI tool for interacting with stateful Letta agents from the terminal.",
|
|
@@ -6426,7 +6429,7 @@ var init_package = __esm(() => {
|
|
|
6426
6429
|
},
|
|
6427
6430
|
lettaLifecycleProtocol: 1,
|
|
6428
6431
|
lettaRuntimeGraphProtocol: 1,
|
|
6429
|
-
lettaRuntimeGraphSha512: "sha512-
|
|
6432
|
+
lettaRuntimeGraphSha512: "sha512-j5GwILxjJXaimzogBnQyZHVILv0v0BgYhSIPUyy2KYUTn9frhkCbOrBlCJtFk/QGChUYISTEpCHX/IbyGPQZzA==",
|
|
6430
6433
|
patchedDependencies: {
|
|
6431
6434
|
"@earendil-works/pi-ai@1.5.2": "patches/@earendil-works%2Fpi-ai@1.5.2.patch"
|
|
6432
6435
|
}
|
|
@@ -6463,7 +6466,7 @@ function maybeMapKnownApiError(status, responseText) {
|
|
|
6463
6466
|
try {
|
|
6464
6467
|
const errorData = JSON.parse(responseText);
|
|
6465
6468
|
if (typeof errorData.error === "string" && errorData.error.includes("only available for pro or enterprise")) {
|
|
6466
|
-
return new Error("PLAN_UPGRADE_REQUIRED");
|
|
6469
|
+
return Object.assign(new Error("PLAN_UPGRADE_REQUIRED"), { status });
|
|
6467
6470
|
}
|
|
6468
6471
|
} catch {}
|
|
6469
6472
|
return null;
|
|
@@ -94370,7 +94373,7 @@ function consumeSubagentLaunch(env4) {
|
|
|
94370
94373
|
delete env4[SUBAGENT_LAUNCH_ENV];
|
|
94371
94374
|
return isLaunch;
|
|
94372
94375
|
}
|
|
94373
|
-
var SUBAGENT_LAUNCH_ENV = "LETTA_SUBAGENT_LAUNCH", SUBAGENT_LAUNCH_PROFILE_ENV = "LETTA_SUBAGENT_LAUNCH_PROFILE", SUBAGENT_NAME_ENV = "LETTA_SUBAGENT_NAME", LISTENER_CONNECTION_ENV = "LETTA_RUNTIME_LISTENER_CONNECTION_ID";
|
|
94376
|
+
var SUBAGENT_LAUNCH_ENV = "LETTA_SUBAGENT_LAUNCH", SUBAGENT_LAUNCH_PROFILE_ENV = "LETTA_SUBAGENT_LAUNCH_PROFILE", SUBAGENT_SUMMARY_ENV = "LETTA_SUBAGENT_SUMMARY", SUBAGENT_NAME_ENV = "LETTA_SUBAGENT_NAME", LISTENER_CONNECTION_ENV = "LETTA_RUNTIME_LISTENER_CONNECTION_ID";
|
|
94374
94377
|
|
|
94375
94378
|
// src/constants.ts
|
|
94376
94379
|
var DEFAULT_TITLE_SUMMARIZATION_MODEL = "openai/gpt-6-luna", DEFAULT_AGENT_NAME = "Letta Code", INTERRUPTED_BY_USER = "Interrupted by user", TURN_DID_NOT_COMPLETE = "Turn did not complete", SYSTEM_REMINDER_TAG = "system-reminder", SYSTEM_REMINDER_OPEN, SYSTEM_REMINDER_CLOSE, SYSTEM_ALERT_TAG = "system-alert", SYSTEM_ALERT_OPEN, SYSTEM_ALERT_CLOSE, COMPACTION_SUMMARY_HEADER = "(Earlier messages in this conversation have been compacted to free up context, summarized below)", TOKEN_DISPLAY_THRESHOLD = 100, ELAPSED_DISPLAY_THRESHOLD_MS;
|
|
@@ -94743,7 +94746,9 @@ function resolveEphemeralSubagentLink(env4 = process.env) {
|
|
|
94743
94746
|
const parentAgentId = env4.LETTA_PARENT_AGENT_ID?.trim();
|
|
94744
94747
|
if (!parentAgentId)
|
|
94745
94748
|
return null;
|
|
94749
|
+
const summary = env4[SUBAGENT_SUMMARY_ENV]?.trim();
|
|
94746
94750
|
return {
|
|
94751
|
+
...summary ? { summary } : {},
|
|
94747
94752
|
parent_agent_id: parentAgentId,
|
|
94748
94753
|
is_subagent: true,
|
|
94749
94754
|
name: resolveCreatedAgentName(undefined, true, env4[SUBAGENT_NAME_ENV]?.trim() || undefined)
|
|
@@ -98724,6 +98729,7 @@ var init_subagents2 = __esm(() => {
|
|
|
98724
98729
|
MEMFS_V2_BUILTIN_SOURCES = [init_v2_default, reflection_v2_default];
|
|
98725
98730
|
GLOBAL_AGENTS_DIR = getGlobalAgentsDir();
|
|
98726
98731
|
RESERVED_EXTERNAL_SUBAGENT_NAMES = new Set([
|
|
98732
|
+
"antigravity",
|
|
98727
98733
|
"letta",
|
|
98728
98734
|
"claude-code",
|
|
98729
98735
|
"codex",
|
|
@@ -109348,6 +109354,13 @@ var exports_pi_stream_adapter = {};
|
|
|
109348
109354
|
__export(exports_pi_stream_adapter, {
|
|
109349
109355
|
PiStreamAdapter: () => PiStreamAdapter
|
|
109350
109356
|
});
|
|
109357
|
+
function inputAfterCompaction(input, compaction) {
|
|
109358
|
+
return {
|
|
109359
|
+
...input,
|
|
109360
|
+
uiMessages: compaction.uiMessages,
|
|
109361
|
+
systemPrompt: compaction.systemPrompt ?? input.systemPrompt
|
|
109362
|
+
};
|
|
109363
|
+
}
|
|
109351
109364
|
async function sleepWithAbort(delayMs, abortSignal) {
|
|
109352
109365
|
if (delayMs <= 0)
|
|
109353
109366
|
return;
|
|
@@ -109556,12 +109569,7 @@ class PiStreamAdapter {
|
|
|
109556
109569
|
if (!shouldCompactForContextPressure({ contextTokens, contextWindow })) {
|
|
109557
109570
|
return null;
|
|
109558
109571
|
}
|
|
109559
|
-
return this.onContextPressure(input, {
|
|
109560
|
-
contextTokens,
|
|
109561
|
-
contextWindow,
|
|
109562
|
-
phase: "preflight",
|
|
109563
|
-
source: "estimate"
|
|
109564
|
-
});
|
|
109572
|
+
return this.onContextPressure(input, { contextTokens, contextWindow });
|
|
109565
109573
|
}
|
|
109566
109574
|
async* streamOnce(input) {
|
|
109567
109575
|
const tools = toPiTools(input.clientTools);
|
|
@@ -109659,7 +109667,6 @@ class PiStreamAdapter {
|
|
|
109659
109667
|
const result = this.runStream(resolved.model, context3, options);
|
|
109660
109668
|
let streamError;
|
|
109661
109669
|
let finalMessage;
|
|
109662
|
-
let finalLocalMessage;
|
|
109663
109670
|
for await (const part of result) {
|
|
109664
109671
|
if (part.type === "error") {
|
|
109665
109672
|
const error3 = new PiProviderError(part.error);
|
|
@@ -109673,8 +109680,7 @@ class PiStreamAdapter {
|
|
|
109673
109680
|
}
|
|
109674
109681
|
if (part.type === "done") {
|
|
109675
109682
|
finalMessage = part.message;
|
|
109676
|
-
|
|
109677
|
-
yield providerLocalMessage(finalLocalMessage);
|
|
109683
|
+
yield providerLocalMessage(toLocalAssistantMessage(part.message, input));
|
|
109678
109684
|
}
|
|
109679
109685
|
yield providerStreamPart(part, resolved.model);
|
|
109680
109686
|
}
|
|
@@ -109694,26 +109700,6 @@ class PiStreamAdapter {
|
|
|
109694
109700
|
if (finalMessage.stopReason === "error" || finalMessage.stopReason === "aborted") {
|
|
109695
109701
|
throw new PiProviderError(finalMessage);
|
|
109696
109702
|
}
|
|
109697
|
-
if (this.onContextPressure) {
|
|
109698
|
-
const usageContextTokens = contextTokensFromUsage(finalMessage.usage);
|
|
109699
|
-
const contextTokens = usageContextTokens ?? estimateProviderContextTokens({
|
|
109700
|
-
...input,
|
|
109701
|
-
uiMessages: [
|
|
109702
|
-
...input.uiMessages,
|
|
109703
|
-
finalLocalMessage ?? toLocalAssistantMessage(finalMessage, input)
|
|
109704
|
-
]
|
|
109705
|
-
});
|
|
109706
|
-
const contextWindow = resolved.model.contextWindow;
|
|
109707
|
-
const compaction = shouldCompactForContextPressure({ contextTokens, contextWindow }) && contextTokens !== undefined ? await this.onContextPressure(input, {
|
|
109708
|
-
contextTokens,
|
|
109709
|
-
contextWindow,
|
|
109710
|
-
phase: "post_turn",
|
|
109711
|
-
source: usageContextTokens === undefined ? "estimate" : "usage"
|
|
109712
|
-
}) : null;
|
|
109713
|
-
if (compaction) {
|
|
109714
|
-
yield* this.emitCompactionChunks(compaction, "context_window_limit");
|
|
109715
|
-
}
|
|
109716
|
-
}
|
|
109717
109703
|
} catch (error3) {
|
|
109718
109704
|
if (!llmEnded) {
|
|
109719
109705
|
const endError = llmEndErrorFromError(error3);
|
|
@@ -109738,7 +109724,7 @@ class PiStreamAdapter {
|
|
|
109738
109724
|
preflightCompactionChecked = true;
|
|
109739
109725
|
const compaction = await this.compactBeforeProviderCall(activeInput);
|
|
109740
109726
|
if (compaction) {
|
|
109741
|
-
activeInput =
|
|
109727
|
+
activeInput = inputAfterCompaction(activeInput, compaction);
|
|
109742
109728
|
yield* this.emitCompactionChunks(compaction, "context_window_limit");
|
|
109743
109729
|
continue;
|
|
109744
109730
|
}
|
|
@@ -109763,7 +109749,7 @@ class PiStreamAdapter {
|
|
|
109763
109749
|
if (!compaction)
|
|
109764
109750
|
throw error3;
|
|
109765
109751
|
contextOverflowCompactions += 1;
|
|
109766
|
-
activeInput =
|
|
109752
|
+
activeInput = inputAfterCompaction(activeInput, compaction);
|
|
109767
109753
|
yield* this.emitCompactionChunks(compaction, "context_window_overflow");
|
|
109768
109754
|
continue;
|
|
109769
109755
|
}
|
|
@@ -109784,7 +109770,7 @@ class PiStreamAdapter {
|
|
|
109784
109770
|
}
|
|
109785
109771
|
if (compaction) {
|
|
109786
109772
|
contextOverflowCompactions += 1;
|
|
109787
|
-
activeInput =
|
|
109773
|
+
activeInput = inputAfterCompaction(activeInput, compaction);
|
|
109788
109774
|
yield* this.emitCompactionChunks(compaction, "context_window_overflow");
|
|
109789
109775
|
continue;
|
|
109790
109776
|
}
|
|
@@ -110439,11 +110425,7 @@ var init_local_backend = __esm(() => {
|
|
|
110439
110425
|
}
|
|
110440
110426
|
async compactAfterContextOverflow(input, _error) {
|
|
110441
110427
|
const result = await this.compactLocalConversation(input.conversationId, input.agentId, "context_window_overflow", undefined, input);
|
|
110442
|
-
return
|
|
110443
|
-
uiMessages: this.store.listLocalMessages(input.conversationId, input.agentId),
|
|
110444
|
-
summary: result.summary,
|
|
110445
|
-
stats: result.stats
|
|
110446
|
-
};
|
|
110428
|
+
return this.turnCompaction(input, result);
|
|
110447
110429
|
}
|
|
110448
110430
|
async compactForContextPressure(input, pressure) {
|
|
110449
110431
|
const messageTokens = estimateLocalMessageTokens2(this.store.listLocalMessages(input.conversationId, input.agentId));
|
|
@@ -110451,10 +110433,16 @@ var init_local_backend = __esm(() => {
|
|
|
110451
110433
|
const result = await runLocalPressureCompaction(() => this.compactLocalConversation(input.conversationId, input.agentId, "context_window_limit", undefined, input, (contextCompactionThreshold(pressure.contextWindow) ?? 0) - fixedTokens));
|
|
110452
110434
|
if (!result)
|
|
110453
110435
|
return null;
|
|
110436
|
+
return this.turnCompaction(input, result);
|
|
110437
|
+
}
|
|
110438
|
+
turnCompaction(input, result) {
|
|
110454
110439
|
return {
|
|
110455
110440
|
uiMessages: this.store.listLocalMessages(input.conversationId, input.agentId),
|
|
110456
110441
|
summary: result.summary,
|
|
110457
|
-
stats: result.stats
|
|
110442
|
+
stats: result.stats,
|
|
110443
|
+
...result.systemPrompt !== undefined ? {
|
|
110444
|
+
systemPrompt: appendAvailableSkillsBlock(result.systemPrompt, input.clientSkills)
|
|
110445
|
+
} : {}
|
|
110458
110446
|
};
|
|
110459
110447
|
}
|
|
110460
110448
|
effectiveContextWindow(conversationId, agentId) {
|
|
@@ -110491,8 +110479,16 @@ var init_local_backend = __esm(() => {
|
|
|
110491
110479
|
async compactLocalConversation(conversationId, agentId, trigger, body, turn, maxMessageTokens) {
|
|
110492
110480
|
await this.emitCompactStart(conversationId, agentId, trigger);
|
|
110493
110481
|
const result = await this.compactLocalConversationInner(conversationId, agentId, trigger, body, turn, maxMessageTokens);
|
|
110482
|
+
const systemPrompt = await this.recompileMemoryAfterCompaction(conversationId, agentId);
|
|
110494
110483
|
await this.emitCompactEnd(conversationId, agentId, trigger, result.stats);
|
|
110495
|
-
return result;
|
|
110484
|
+
return systemPrompt === undefined ? result : { ...result, systemPrompt };
|
|
110485
|
+
}
|
|
110486
|
+
async recompileMemoryAfterCompaction(conversationId, agentId) {
|
|
110487
|
+
if (this.store.isAgentFreeConversation(conversationId) || !this.isMemfsEnabledForAgent(agentId)) {
|
|
110488
|
+
return;
|
|
110489
|
+
}
|
|
110490
|
+
const compiled = await this.compileAndMaybePersistSystemPrompt(conversationId, agentId, { dryRun: false });
|
|
110491
|
+
return compiled.content;
|
|
110496
110492
|
}
|
|
110497
110493
|
async compactLocalConversationInner(conversationId, agentId, trigger, body, turn, maxMessageTokens) {
|
|
110498
110494
|
const agent = this.effectiveAgentForConversation(conversationId, agentId);
|
|
@@ -110503,27 +110499,20 @@ var init_local_backend = __esm(() => {
|
|
|
110503
110499
|
const self2 = isLocalSelfCompactionMode(settings.mode) ? await this.selfCompactionContext(conversationId, agentId, turn) : undefined;
|
|
110504
110500
|
if (isLocalSlidingWindowMode(settings.mode)) {
|
|
110505
110501
|
try {
|
|
110506
|
-
const
|
|
110507
|
-
if (
|
|
110508
|
-
|
|
110509
|
-
dryRun: false
|
|
110510
|
-
});
|
|
110511
|
-
return result2;
|
|
110502
|
+
const result = await this.compactLocalConversationPass(conversationId, agentId, agent, trigger, settings, self2);
|
|
110503
|
+
if (result.stats.context_window === undefined || result.stats.context_tokens_after === undefined || result.stats.context_tokens_after < result.stats.context_window) {
|
|
110504
|
+
return result;
|
|
110512
110505
|
}
|
|
110513
110506
|
} catch (error3) {
|
|
110514
110507
|
if (!isLocalSlidingWindowCompactionPlanningError(error3))
|
|
110515
110508
|
throw error3;
|
|
110516
110509
|
}
|
|
110517
110510
|
}
|
|
110518
|
-
|
|
110511
|
+
return this.compactLocalConversationPass(conversationId, agentId, agent, trigger, {
|
|
110519
110512
|
...settings,
|
|
110520
110513
|
mode: self2 ? "self_compact_all" : "all",
|
|
110521
110514
|
prompt: settings.prompt
|
|
110522
110515
|
}, self2);
|
|
110523
|
-
await this.compileAndMaybePersistSystemPrompt(conversationId, agentId, {
|
|
110524
|
-
dryRun: false
|
|
110525
|
-
});
|
|
110526
|
-
return result;
|
|
110527
110516
|
}
|
|
110528
110517
|
async compactLocalConversationPass(conversationId, agentId, agent, trigger, settings, self2) {
|
|
110529
110518
|
const slidingWindow = isLocalSlidingWindowMode(settings.mode);
|
|
@@ -203477,7 +203466,7 @@ var init_mcp_client = __esm(() => {
|
|
|
203477
203466
|
init_streamableHttp();
|
|
203478
203467
|
DEFAULT_CLIENT_INFO = {
|
|
203479
203468
|
name: "letta-code",
|
|
203480
|
-
version: "0.34.
|
|
203469
|
+
version: "0.34.71"
|
|
203481
203470
|
};
|
|
203482
203471
|
});
|
|
203483
203472
|
|
|
@@ -207825,6 +207814,11 @@ A powerful search tool built on ripgrep
|
|
|
207825
207814
|
`;
|
|
207826
207815
|
var init_Grep = () => {};
|
|
207827
207816
|
|
|
207817
|
+
// src/tools/descriptions/ListAgents.md
|
|
207818
|
+
var ListAgents_default = `List unarchived subagents launched by the current conversation, most recently updated first. Each entry includes timestamps, status, and the address for SendAgentMessage. Returns up to 20 entries by default. Filter by running, completed, failed, or stopped. When has_more is true, pass next_cursor as cursor to get the next page with the same status filter.
|
|
207819
|
+
`;
|
|
207820
|
+
var init_ListAgents = () => {};
|
|
207821
|
+
|
|
207828
207822
|
// src/tools/descriptions/LS.md
|
|
207829
207823
|
var LS_default = `# LS
|
|
207830
207824
|
|
|
@@ -215839,6 +215833,37 @@ function excerptProgressText(value, max2) {
|
|
|
215839
215833
|
const line = value.replace(/\s+/g, " ").trim();
|
|
215840
215834
|
return line.length > max2 ? `${line.slice(0, max2)}…` : line;
|
|
215841
215835
|
}
|
|
215836
|
+
function observeSubagentState(id, observer) {
|
|
215837
|
+
const state2 = store2.agents.get(id);
|
|
215838
|
+
if (state2)
|
|
215839
|
+
stateObservers.set(state2, observer);
|
|
215840
|
+
}
|
|
215841
|
+
function captureSubagentStop(id) {
|
|
215842
|
+
const state2 = store2.agents.get(id);
|
|
215843
|
+
const observer = state2 && stateObservers.get(state2);
|
|
215844
|
+
return () => {
|
|
215845
|
+
if (!state2 || !observer)
|
|
215846
|
+
return;
|
|
215847
|
+
const current = store2.agents.get(id) ?? state2;
|
|
215848
|
+
observer({
|
|
215849
|
+
...current,
|
|
215850
|
+
stopOutcome: { attempt: current.stopAttempts ?? 0, kind: "stopped" }
|
|
215851
|
+
});
|
|
215852
|
+
};
|
|
215853
|
+
}
|
|
215854
|
+
function observeStateChange(previous, next, resultIdentity) {
|
|
215855
|
+
const observer = stateObservers.get(previous);
|
|
215856
|
+
if (!observer)
|
|
215857
|
+
return;
|
|
215858
|
+
stateObservers.set(next, observer);
|
|
215859
|
+
if (resultIdentity || previous.status !== next.status || previous.agentId !== next.agentId || previous.conversationId !== next.conversationId || previous.cancelPending !== next.cancelPending || previous.stopOutcome?.kind !== next.stopOutcome?.kind) {
|
|
215860
|
+
observer(resultIdentity ? {
|
|
215861
|
+
...next,
|
|
215862
|
+
agentId: next.agentId || resultIdentity.agentId,
|
|
215863
|
+
conversationId: resultIdentity.conversationId || next.conversationId
|
|
215864
|
+
} : next);
|
|
215865
|
+
}
|
|
215866
|
+
}
|
|
215842
215867
|
function updateSnapshot() {
|
|
215843
215868
|
const agents = Array.from(store2.agents.values());
|
|
215844
215869
|
const now2 = Date.now();
|
|
@@ -215949,8 +215974,14 @@ function updateSubagent(id, updates) {
|
|
|
215949
215974
|
const isNoop = keys2.every((k3) => agent[k3] === updates[k3]) && nextMax === agent.maxToolCallsSeen;
|
|
215950
215975
|
if (isNoop)
|
|
215951
215976
|
return;
|
|
215952
|
-
const updatedAgent = {
|
|
215977
|
+
const updatedAgent = {
|
|
215978
|
+
...agent,
|
|
215979
|
+
...updates,
|
|
215980
|
+
maxToolCallsSeen: nextMax,
|
|
215981
|
+
updatedAt: Date.now()
|
|
215982
|
+
};
|
|
215953
215983
|
store2.agents.set(id, updatedAgent);
|
|
215984
|
+
observeStateChange(agent, updatedAgent);
|
|
215954
215985
|
if (updatedAgent.status === "completed" || updatedAgent.status === "error") {
|
|
215955
215986
|
scheduleCompletedSubagentCleanup(id);
|
|
215956
215987
|
} else {
|
|
@@ -215973,6 +216004,7 @@ function addToolCall(subagentId, toolCallId, toolName2, toolArgs) {
|
|
|
215973
216004
|
maxToolCallsSeen: Math.max(agent.maxToolCallsSeen, agent.toolCalls.length + 1)
|
|
215974
216005
|
};
|
|
215975
216006
|
store2.agents.set(subagentId, updatedAgent);
|
|
216007
|
+
observeStateChange(agent, updatedAgent);
|
|
215976
216008
|
notifyListeners();
|
|
215977
216009
|
}
|
|
215978
216010
|
function addProgressText(subagentId, text2, now2 = () => new Date) {
|
|
@@ -215984,23 +216016,26 @@ function addProgressText(subagentId, text2, now2 = () => new Date) {
|
|
|
215984
216016
|
if (!excerpt || previous?.text === excerpt)
|
|
215985
216017
|
return;
|
|
215986
216018
|
const count = (agent.progressTextCount ?? 0) + 1;
|
|
215987
|
-
|
|
216019
|
+
const updatedAgent = {
|
|
215988
216020
|
...agent,
|
|
215989
216021
|
progressTexts: [
|
|
215990
216022
|
...agent.progressTexts ?? [],
|
|
215991
216023
|
{ id: `text-${count}`, at: now2().toISOString(), text: excerpt }
|
|
215992
216024
|
].slice(-MAX_PROGRESS_TEXTS),
|
|
215993
216025
|
progressTextCount: count
|
|
215994
|
-
}
|
|
216026
|
+
};
|
|
216027
|
+
store2.agents.set(subagentId, updatedAgent);
|
|
216028
|
+
observeStateChange(agent, updatedAgent);
|
|
215995
216029
|
notifyListeners();
|
|
215996
216030
|
}
|
|
215997
|
-
function completeSubagent(id, result2) {
|
|
216031
|
+
function completeSubagent(id, result2, resultIdentity) {
|
|
215998
216032
|
const agent = store2.agents.get(id);
|
|
215999
216033
|
if (!agent)
|
|
216000
216034
|
return;
|
|
216001
216035
|
const updatedAgent = {
|
|
216002
216036
|
...agent,
|
|
216003
216037
|
status: result2.success ? "completed" : "error",
|
|
216038
|
+
updatedAt: Date.now(),
|
|
216004
216039
|
error: result2.error,
|
|
216005
216040
|
stopFailed: undefined,
|
|
216006
216041
|
...result2.result !== undefined ? { result: result2.result } : {},
|
|
@@ -216010,6 +216045,7 @@ function completeSubagent(id, result2) {
|
|
|
216010
216045
|
maxToolCallsSeen: Math.max(agent.maxToolCallsSeen, agent.toolCalls.length)
|
|
216011
216046
|
};
|
|
216012
216047
|
store2.agents.set(id, updatedAgent);
|
|
216048
|
+
observeStateChange(agent, updatedAgent, resultIdentity);
|
|
216013
216049
|
scheduleCompletedSubagentCleanup(id);
|
|
216014
216050
|
notifyListeners();
|
|
216015
216051
|
}
|
|
@@ -216115,12 +216151,14 @@ function interruptActiveSubagents(errorMessage3, scope) {
|
|
|
216115
216151
|
const updatedAgent = {
|
|
216116
216152
|
...agent,
|
|
216117
216153
|
status: "error",
|
|
216154
|
+
updatedAt: Date.now(),
|
|
216118
216155
|
error: errorMessage3,
|
|
216119
216156
|
durationMs: Date.now() - agent.startTime,
|
|
216120
216157
|
...hook ? { cancelPending: true, stopAttempts: (agent.stopAttempts ?? 0) + 1 } : {},
|
|
216121
216158
|
stopFailed: undefined
|
|
216122
216159
|
};
|
|
216123
216160
|
store2.agents.set(id, updatedAgent);
|
|
216161
|
+
observeStateChange(agent, updatedAgent);
|
|
216124
216162
|
scheduleCompletedSubagentCleanup(id);
|
|
216125
216163
|
anyInterrupted = true;
|
|
216126
216164
|
}
|
|
@@ -216150,6 +216188,7 @@ function interruptStopFailedSubagents(errorMessage3, scope) {
|
|
|
216150
216188
|
stopFailed: undefined
|
|
216151
216189
|
};
|
|
216152
216190
|
store2.agents.set(id, updatedAgent);
|
|
216191
|
+
observeStateChange(agent, updatedAgent);
|
|
216153
216192
|
scheduleCompletedSubagentCleanup(id);
|
|
216154
216193
|
interrupted.push(id);
|
|
216155
216194
|
}
|
|
@@ -216193,7 +216232,7 @@ function emitStreamEvent(subagentId, event) {
|
|
|
216193
216232
|
listener(subagentId, event);
|
|
216194
216233
|
}
|
|
216195
216234
|
}
|
|
216196
|
-
var PROGRESS_TEXT_CHARS = 300, MAX_PROGRESS_TEXTS = 20, store2, cachedSnapshot, cachedLifecycleItems, DEFAULT_COMPLETED_SUBAGENT_RETENTION_MS = 30000, completedSubagentRetentionMs, DEFAULT_PUBLISHED_RESULT_RETENTION_MS, publishedResultRetentionMs, completedSubagentCleanupTimers, subagentCounter = 0, subagentAbortHooks, streamEventListeners;
|
|
216235
|
+
var PROGRESS_TEXT_CHARS = 300, MAX_PROGRESS_TEXTS = 20, store2, stateObservers, cachedSnapshot, cachedLifecycleItems, DEFAULT_COMPLETED_SUBAGENT_RETENTION_MS = 30000, completedSubagentRetentionMs, DEFAULT_PUBLISHED_RESULT_RETENTION_MS, publishedResultRetentionMs, completedSubagentCleanupTimers, subagentCounter = 0, subagentAbortHooks, streamEventListeners;
|
|
216197
216236
|
var init_subagent_state = __esm(() => {
|
|
216198
216237
|
init_subagent_events();
|
|
216199
216238
|
store2 = {
|
|
@@ -216201,6 +216240,7 @@ var init_subagent_state = __esm(() => {
|
|
|
216201
216240
|
expanded: false,
|
|
216202
216241
|
listeners: new Set
|
|
216203
216242
|
};
|
|
216243
|
+
stateObservers = new WeakMap;
|
|
216204
216244
|
cachedSnapshot = {
|
|
216205
216245
|
agents: [],
|
|
216206
216246
|
expanded: false
|
|
@@ -221357,6 +221397,7 @@ function getDefaultDecision(toolName2, toolArgs, modTools = getAvailableModTools
|
|
|
221357
221397
|
"TaskGet",
|
|
221358
221398
|
"TaskList",
|
|
221359
221399
|
"TaskUpdate",
|
|
221400
|
+
"ListAgents",
|
|
221360
221401
|
"read_artifact_file",
|
|
221361
221402
|
"write_artifact_file",
|
|
221362
221403
|
"Wake",
|
|
@@ -232527,6 +232568,257 @@ var init_grep = __esm(() => {
|
|
|
232527
232568
|
execFileAsync10 = promisify14(execFile14);
|
|
232528
232569
|
});
|
|
232529
232570
|
|
|
232571
|
+
// src/backend/api/subagents.ts
|
|
232572
|
+
function usesCloudSubagents() {
|
|
232573
|
+
return resolveBackendMode() === "api" && isCloudServerUrl();
|
|
232574
|
+
}
|
|
232575
|
+
function listCloudSubagentsPage(conversationId, actingUserId, options) {
|
|
232576
|
+
return apiRequest("GET", "/v1/subagents", undefined, {
|
|
232577
|
+
actingUserId,
|
|
232578
|
+
signal: AbortSignal.timeout(15000),
|
|
232579
|
+
query: {
|
|
232580
|
+
parent_conversation_id: conversationId,
|
|
232581
|
+
archived: options.archived ?? false,
|
|
232582
|
+
after: options.after,
|
|
232583
|
+
limit: options.limit,
|
|
232584
|
+
status: options.status
|
|
232585
|
+
}
|
|
232586
|
+
});
|
|
232587
|
+
}
|
|
232588
|
+
async function listCloudSubagents(conversationId, actingUserId, archived = false) {
|
|
232589
|
+
const records = [];
|
|
232590
|
+
let after2;
|
|
232591
|
+
while (true) {
|
|
232592
|
+
const page = await listCloudSubagentsPage(conversationId, actingUserId, {
|
|
232593
|
+
archived,
|
|
232594
|
+
after: after2,
|
|
232595
|
+
limit: 200
|
|
232596
|
+
});
|
|
232597
|
+
records.push(...page);
|
|
232598
|
+
if (page.length < 200)
|
|
232599
|
+
return records;
|
|
232600
|
+
after2 = page.at(-1)?.subagent_id;
|
|
232601
|
+
}
|
|
232602
|
+
}
|
|
232603
|
+
function queueSubagentUpdates(record4, update2) {
|
|
232604
|
+
let pending2 = record4.catch(() => {
|
|
232605
|
+
debugLog("subagents", "Could not resolve the persisted subagent");
|
|
232606
|
+
return;
|
|
232607
|
+
});
|
|
232608
|
+
return (change) => {
|
|
232609
|
+
pending2 = pending2.then(async (id) => {
|
|
232610
|
+
if (id) {
|
|
232611
|
+
try {
|
|
232612
|
+
await update2(id, change);
|
|
232613
|
+
} catch {
|
|
232614
|
+
debugLog("subagents", "Could not update the persisted subagent");
|
|
232615
|
+
}
|
|
232616
|
+
}
|
|
232617
|
+
return id;
|
|
232618
|
+
});
|
|
232619
|
+
};
|
|
232620
|
+
}
|
|
232621
|
+
function createSubagentWriter(input, actingUserId) {
|
|
232622
|
+
const record4 = apiRequest("POST", "/v1/subagents", { ...input }, {
|
|
232623
|
+
actingUserId,
|
|
232624
|
+
signal: AbortSignal.timeout(15000)
|
|
232625
|
+
}).then((row) => row.subagent_id);
|
|
232626
|
+
return subagentWriter(record4, actingUserId);
|
|
232627
|
+
}
|
|
232628
|
+
function subagentWriter(record4, actingUserId) {
|
|
232629
|
+
return queueSubagentUpdates(record4, (id, change) => apiRequest("PATCH", `/v1/subagents/${encodeURIComponent(id)}`, { ...change }, {
|
|
232630
|
+
actingUserId,
|
|
232631
|
+
signal: AbortSignal.timeout(15000)
|
|
232632
|
+
}));
|
|
232633
|
+
}
|
|
232634
|
+
function resumeSubagentWriter(conversationId, target, actingUserId) {
|
|
232635
|
+
if (!usesCloudSubagents() || conversationId === "default" || !target.conversation_id && !target.worker_session_id)
|
|
232636
|
+
return;
|
|
232637
|
+
const matches3 = (record5) => target.worker_session_id ? record5.worker_session_id === target.worker_session_id : record5.conversation_id === target.conversation_id;
|
|
232638
|
+
const record4 = (async () => {
|
|
232639
|
+
for (const archived of [false, true]) {
|
|
232640
|
+
const records = await listCloudSubagents(conversationId, actingUserId, archived);
|
|
232641
|
+
const match3 = records.filter(matches3).sort((a2, b3) => b3.updated_at.localeCompare(a2.updated_at))[0];
|
|
232642
|
+
if (match3)
|
|
232643
|
+
return match3.subagent_id;
|
|
232644
|
+
}
|
|
232645
|
+
return;
|
|
232646
|
+
})();
|
|
232647
|
+
const update2 = subagentWriter(record4, actingUserId);
|
|
232648
|
+
update2({ status: "running", archived: false });
|
|
232649
|
+
return { update: update2, found: record4.then(Boolean, () => false) };
|
|
232650
|
+
}
|
|
232651
|
+
var init_subagents3 = __esm(() => {
|
|
232652
|
+
init_backend_mode();
|
|
232653
|
+
init_debug();
|
|
232654
|
+
init_request();
|
|
232655
|
+
init_server_url();
|
|
232656
|
+
});
|
|
232657
|
+
|
|
232658
|
+
// src/tools/schemas/ListAgents.json
|
|
232659
|
+
var ListAgents_default2;
|
|
232660
|
+
var init_ListAgents2 = __esm(() => {
|
|
232661
|
+
ListAgents_default2 = {
|
|
232662
|
+
type: "object",
|
|
232663
|
+
properties: {
|
|
232664
|
+
limit: {
|
|
232665
|
+
type: "integer",
|
|
232666
|
+
minimum: 1,
|
|
232667
|
+
maximum: 100,
|
|
232668
|
+
default: 20,
|
|
232669
|
+
description: "Maximum number of subagents to return."
|
|
232670
|
+
},
|
|
232671
|
+
cursor: {
|
|
232672
|
+
type: "string",
|
|
232673
|
+
minLength: 1,
|
|
232674
|
+
description: "The next_cursor from the previous page. Keep the same status filter."
|
|
232675
|
+
},
|
|
232676
|
+
status: {
|
|
232677
|
+
type: "string",
|
|
232678
|
+
enum: ["running", "completed", "failed", "stopped"],
|
|
232679
|
+
description: "Only return subagents with this status."
|
|
232680
|
+
}
|
|
232681
|
+
},
|
|
232682
|
+
additionalProperties: false
|
|
232683
|
+
};
|
|
232684
|
+
});
|
|
232685
|
+
|
|
232686
|
+
// src/tools/impl/subagent-persistence.ts
|
|
232687
|
+
function createLaunchSubagentObserver(scope, args, description, prompt, harness, forkContext, computer, cloud) {
|
|
232688
|
+
if (!scope || scope.conversationId === "default" || !usesCloudSubagents())
|
|
232689
|
+
return;
|
|
232690
|
+
const actingUserId = getRuntimeActingUserAttribution();
|
|
232691
|
+
const input = {
|
|
232692
|
+
parent_agent_id: scope.agentId,
|
|
232693
|
+
parent_conversation_id: scope.conversationId,
|
|
232694
|
+
description,
|
|
232695
|
+
prompt,
|
|
232696
|
+
harness,
|
|
232697
|
+
subagent_type: args.subagent_type ?? null,
|
|
232698
|
+
fork_context: forkContext,
|
|
232699
|
+
model_config: args.model ? { model: args.model } : null,
|
|
232700
|
+
agent_id: args.agent_id ?? null,
|
|
232701
|
+
conversation_id: args.conversation_id === "default" ? null : args.conversation_id ?? null,
|
|
232702
|
+
computer: computer ?? null,
|
|
232703
|
+
repositories: cloud?.githubRepositories?.map(({ owner, repo, commit }) => `${owner}/${repo}${commit ? `@${commit}` : ""}`) ?? null,
|
|
232704
|
+
sandbox_size: cloud?.sandboxSize ?? null,
|
|
232705
|
+
mcp_config: args.mcp ?? null,
|
|
232706
|
+
worker_session_id: null,
|
|
232707
|
+
status: "running"
|
|
232708
|
+
};
|
|
232709
|
+
return () => {
|
|
232710
|
+
const write = createSubagentWriter(input, actingUserId);
|
|
232711
|
+
let previous;
|
|
232712
|
+
let stopped = false;
|
|
232713
|
+
let resolvedLinks = {};
|
|
232714
|
+
return (state2) => {
|
|
232715
|
+
const links2 = harness === "letta" ? {
|
|
232716
|
+
...state2.agentId ? { agent_id: state2.agentId } : {},
|
|
232717
|
+
...state2.conversationId && state2.conversationId !== "default" ? { conversation_id: state2.conversationId } : {}
|
|
232718
|
+
} : state2.agentId ? { worker_session_id: state2.agentId } : {};
|
|
232719
|
+
const status = stopped ? "stopped" : persistedSubagentStatus(state2);
|
|
232720
|
+
stopped = status === "stopped";
|
|
232721
|
+
resolvedLinks = { ...resolvedLinks, ...links2 };
|
|
232722
|
+
const change = { ...resolvedLinks, status };
|
|
232723
|
+
const serialized = JSON.stringify(change);
|
|
232724
|
+
if (serialized === previous)
|
|
232725
|
+
return;
|
|
232726
|
+
previous = serialized;
|
|
232727
|
+
write(change);
|
|
232728
|
+
};
|
|
232729
|
+
};
|
|
232730
|
+
}
|
|
232731
|
+
function persistedSubagentStatus(state2) {
|
|
232732
|
+
if (state2.stopOutcome?.kind === "stopped")
|
|
232733
|
+
return "stopped";
|
|
232734
|
+
if (state2.status === "error" && !state2.cancelPending)
|
|
232735
|
+
return "failed";
|
|
232736
|
+
if (state2.status === "completed")
|
|
232737
|
+
return "completed";
|
|
232738
|
+
return "running";
|
|
232739
|
+
}
|
|
232740
|
+
var init_subagent_persistence = __esm(() => {
|
|
232741
|
+
init_subagents3();
|
|
232742
|
+
init_runtime_context();
|
|
232743
|
+
});
|
|
232744
|
+
|
|
232745
|
+
// src/tools/impl/list-agents.ts
|
|
232746
|
+
function formatPage(rows, limit4) {
|
|
232747
|
+
const agents = rows.slice(0, limit4);
|
|
232748
|
+
const has_more = rows.length > limit4;
|
|
232749
|
+
return {
|
|
232750
|
+
agents,
|
|
232751
|
+
has_more,
|
|
232752
|
+
next_cursor: has_more ? agents.at(-1)?.subagent_id ?? null : null
|
|
232753
|
+
};
|
|
232754
|
+
}
|
|
232755
|
+
async function list_agents({
|
|
232756
|
+
limit: limit4 = 20,
|
|
232757
|
+
cursor,
|
|
232758
|
+
status
|
|
232759
|
+
} = {}) {
|
|
232760
|
+
if (!Number.isInteger(limit4) || limit4 < 1 || limit4 > 100) {
|
|
232761
|
+
throw new Error("ListAgents limit must be an integer between 1 and 100.");
|
|
232762
|
+
}
|
|
232763
|
+
if (status !== undefined && !ListAgents_default2.properties.status.enum.includes(status)) {
|
|
232764
|
+
throw new Error("ListAgents status must be running, completed, failed, or stopped.");
|
|
232765
|
+
}
|
|
232766
|
+
const scope = resolveNotificationScope();
|
|
232767
|
+
if (!scope)
|
|
232768
|
+
throw new Error("ListAgents requires a calling conversation.");
|
|
232769
|
+
if (usesCloudSubagents()) {
|
|
232770
|
+
if (scope.conversationId === "default")
|
|
232771
|
+
return formatPage([], limit4);
|
|
232772
|
+
const rows2 = await listCloudSubagentsPage(scope.conversationId, getRuntimeActingUserAttribution(), { after: cursor, limit: limit4 + 1, status });
|
|
232773
|
+
return formatPage(rows2.map(({
|
|
232774
|
+
subagent_id,
|
|
232775
|
+
description,
|
|
232776
|
+
harness,
|
|
232777
|
+
subagent_type,
|
|
232778
|
+
status: status2,
|
|
232779
|
+
agent_id,
|
|
232780
|
+
conversation_id,
|
|
232781
|
+
worker_session_id,
|
|
232782
|
+
created_at,
|
|
232783
|
+
updated_at
|
|
232784
|
+
}) => ({
|
|
232785
|
+
subagent_id,
|
|
232786
|
+
description,
|
|
232787
|
+
harness,
|
|
232788
|
+
subagent_type,
|
|
232789
|
+
status: status2,
|
|
232790
|
+
agent_id: worker_session_id ?? agent_id,
|
|
232791
|
+
conversation_id,
|
|
232792
|
+
worker_session_id,
|
|
232793
|
+
created_at,
|
|
232794
|
+
updated_at
|
|
232795
|
+
})), limit4);
|
|
232796
|
+
}
|
|
232797
|
+
const rows = getSubagents().filter((agent) => agent.parentAgentId === scope.agentId && agent.parentConversationId === scope.conversationId).map((agent) => ({
|
|
232798
|
+
subagent_id: agent.id,
|
|
232799
|
+
description: agent.description,
|
|
232800
|
+
subagent_type: agent.type,
|
|
232801
|
+
status: persistedSubagentStatus(agent),
|
|
232802
|
+
agent_id: agent.agentId ?? null,
|
|
232803
|
+
conversation_id: agent.conversationId ?? null,
|
|
232804
|
+
created_at: new Date(agent.startTime).toISOString(),
|
|
232805
|
+
updated_at: new Date(agent.updatedAt ?? agent.startTime).toISOString()
|
|
232806
|
+
})).sort((a2, b3) => b3.updated_at.localeCompare(a2.updated_at) || b3.subagent_id.localeCompare(a2.subagent_id));
|
|
232807
|
+
const cursorIndex = cursor ? rows.findIndex((row) => row.subagent_id === cursor) : -1;
|
|
232808
|
+
if (cursor && cursorIndex === -1)
|
|
232809
|
+
return formatPage([], limit4);
|
|
232810
|
+
const page = rows.slice(cursorIndex + 1).filter((row) => !status || row.status === status);
|
|
232811
|
+
return formatPage(page, limit4);
|
|
232812
|
+
}
|
|
232813
|
+
var init_list_agents = __esm(() => {
|
|
232814
|
+
init_subagent_state();
|
|
232815
|
+
init_subagents3();
|
|
232816
|
+
init_runtime_context();
|
|
232817
|
+
init_ListAgents2();
|
|
232818
|
+
init_task_notifications();
|
|
232819
|
+
init_subagent_persistence();
|
|
232820
|
+
});
|
|
232821
|
+
|
|
232530
232822
|
// node_modules/picomatch/lib/constants.js
|
|
232531
232823
|
var require_constants2 = __commonJS((exports, module) => {
|
|
232532
232824
|
var path28 = __require("path");
|
|
@@ -234079,6 +234371,7 @@ __export(exports_environments3, {
|
|
|
234079
234371
|
environmentMatchesSelector: () => environmentMatchesSelector,
|
|
234080
234372
|
describeEnvironment: () => describeEnvironment,
|
|
234081
234373
|
createAgentSandbox: () => createAgentSandbox,
|
|
234374
|
+
WorkerSandboxExpiredError: () => WorkerSandboxExpiredError,
|
|
234082
234375
|
SUBAGENT_CLOUD_OPTIONS_ENV: () => SUBAGENT_CLOUD_OPTIONS_ENV,
|
|
234083
234376
|
ComputerResolutionError: () => ComputerResolutionError
|
|
234084
234377
|
});
|
|
@@ -234098,17 +234391,39 @@ async function sendEnvironmentMessage(connectionId, body3) {
|
|
|
234098
234391
|
async function getEnvironmentConnection(deviceId) {
|
|
234099
234392
|
return apiRequest("GET", `/v1/environments/${encodeURIComponent(deviceId)}`);
|
|
234100
234393
|
}
|
|
234394
|
+
function isSandboxExpiredResponse(error4) {
|
|
234395
|
+
if (!(error4 instanceof ApiRequestError))
|
|
234396
|
+
return false;
|
|
234397
|
+
if (error4.status === 410)
|
|
234398
|
+
return true;
|
|
234399
|
+
try {
|
|
234400
|
+
return JSON.parse(error4.responseText)?.code === "SANDBOX_EXPIRED";
|
|
234401
|
+
} catch {
|
|
234402
|
+
return false;
|
|
234403
|
+
}
|
|
234404
|
+
}
|
|
234101
234405
|
async function createAgentSandbox(agentId, options = {}, request3 = apiRequest) {
|
|
234102
234406
|
const conversationId = options.conversationId === "default" ? undefined : options.conversationId;
|
|
234103
|
-
|
|
234104
|
-
|
|
234105
|
-
|
|
234106
|
-
|
|
234107
|
-
|
|
234108
|
-
|
|
234109
|
-
|
|
234110
|
-
|
|
234111
|
-
|
|
234407
|
+
let sandbox;
|
|
234408
|
+
try {
|
|
234409
|
+
sandbox = await request3("POST", `/v1/agents/${encodeURIComponent(agentId)}/sandboxes`, {
|
|
234410
|
+
...conversationId && { conversationId },
|
|
234411
|
+
...options.resumeOnly && { resumeOnly: true },
|
|
234412
|
+
...options.githubRepositories !== undefined && {
|
|
234413
|
+
githubRepositories: options.githubRepositories
|
|
234414
|
+
},
|
|
234415
|
+
...options.sandboxSize !== undefined && {
|
|
234416
|
+
sandboxSize: options.sandboxSize
|
|
234417
|
+
}
|
|
234418
|
+
});
|
|
234419
|
+
} catch (error4) {
|
|
234420
|
+
if (options.resumeOnly && isSandboxExpiredResponse(error4))
|
|
234421
|
+
throw new WorkerSandboxExpiredError;
|
|
234422
|
+
throw error4;
|
|
234423
|
+
}
|
|
234424
|
+
if (options.resumeOnly && sandbox.resumed === false)
|
|
234425
|
+
throw new WorkerSandboxExpiredError;
|
|
234426
|
+
return sandbox;
|
|
234112
234427
|
}
|
|
234113
234428
|
function isEnvironmentOnline(environment) {
|
|
234114
234429
|
return typeof environment.connectionId === "string" && environment.connectionId.length > 0 && typeof environment.lastHeartbeat === "number" && Date.now() - environment.lastHeartbeat < 120000;
|
|
@@ -234165,8 +234480,17 @@ async function resolveEnvironmentConnectionId(selector, list = listEnvironments)
|
|
|
234165
234480
|
async function resolveAgentSandboxConnectionId(agentId, options = {}) {
|
|
234166
234481
|
const timeoutMs = options.timeoutMs ?? 3 * 60000;
|
|
234167
234482
|
const pollIntervalMs = options.pollIntervalMs ?? 2000;
|
|
234168
|
-
|
|
234169
|
-
|
|
234483
|
+
let deviceId;
|
|
234484
|
+
let connectionName;
|
|
234485
|
+
try {
|
|
234486
|
+
const sandbox = await createAgentSandbox(agentId, options);
|
|
234487
|
+
deviceId = sandbox.deviceId || `sandbox-${agentId}`;
|
|
234488
|
+
connectionName = sandbox.connectionName;
|
|
234489
|
+
} catch (error4) {
|
|
234490
|
+
if (error4 instanceof WorkerSandboxExpiredError)
|
|
234491
|
+
throw error4;
|
|
234492
|
+
throw new ComputerResolutionError("cloud_sandbox_create_failed", error4 instanceof Error ? error4.message : String(error4), error4);
|
|
234493
|
+
}
|
|
234170
234494
|
const deadline = Date.now() + timeoutMs;
|
|
234171
234495
|
let lastEnvironment = null;
|
|
234172
234496
|
let lastError = null;
|
|
@@ -234183,9 +234507,9 @@ async function resolveAgentSandboxConnectionId(agentId, options = {}) {
|
|
|
234183
234507
|
await new Promise((resolve33) => setTimeout(resolve33, pollIntervalMs));
|
|
234184
234508
|
}
|
|
234185
234509
|
if (lastEnvironment) {
|
|
234186
|
-
throw new
|
|
234510
|
+
throw new ComputerResolutionError("cloud_sandbox_online_timeout", `Timed out waiting for cloud sandbox ${connectionName} to come online. Last status: ${describeEnvironment(lastEnvironment)}`, lastError);
|
|
234187
234511
|
}
|
|
234188
|
-
throw new
|
|
234512
|
+
throw new ComputerResolutionError("cloud_sandbox_register_timeout", `Timed out waiting for cloud sandbox ${connectionName} to register${lastError instanceof Error ? `: ${lastError.message}` : ""}`, lastError);
|
|
234189
234513
|
}
|
|
234190
234514
|
function getTeleportStatus(agentId, conversationId, teleportId, request3 = apiRequest) {
|
|
234191
234515
|
return request3("GET", `/v1/environments/runtimes/${encodeURIComponent(agentId)}/${encodeURIComponent(conversationId)}/teleports/${encodeURIComponent(teleportId)}`, undefined, { signal: AbortSignal.timeout(5000) });
|
|
@@ -234196,15 +234520,27 @@ async function teleportToEnvironment(agentId, conversationId, targetConnectionId
|
|
|
234196
234520
|
idempotencyKey: randomUUID37()
|
|
234197
234521
|
});
|
|
234198
234522
|
}
|
|
234199
|
-
var SUBAGENT_CLOUD_OPTIONS_ENV = "LETTA_SUBAGENT_CLOUD_OPTIONS", ComputerResolutionError;
|
|
234523
|
+
var SUBAGENT_CLOUD_OPTIONS_ENV = "LETTA_SUBAGENT_CLOUD_OPTIONS", WorkerSandboxExpiredError, ComputerResolutionError;
|
|
234200
234524
|
var init_environments3 = __esm(() => {
|
|
234201
234525
|
init_request();
|
|
234526
|
+
WorkerSandboxExpiredError = class WorkerSandboxExpiredError extends Error {
|
|
234527
|
+
constructor() {
|
|
234528
|
+
super("The worker's cloud sandbox expired and was deleted. Launch a new worker with Agent.");
|
|
234529
|
+
}
|
|
234530
|
+
};
|
|
234202
234531
|
ComputerResolutionError = class ComputerResolutionError extends Error {
|
|
234203
234532
|
code;
|
|
234204
|
-
|
|
234205
|
-
|
|
234533
|
+
httpStatus;
|
|
234534
|
+
constructor(code, message, cause) {
|
|
234535
|
+
super(message, { cause });
|
|
234206
234536
|
this.code = code;
|
|
234207
234537
|
this.name = "ComputerResolutionError";
|
|
234538
|
+
if (cause && typeof cause === "object" && "status" in cause) {
|
|
234539
|
+
const status = cause.status;
|
|
234540
|
+
if (typeof status === "number" && Number.isInteger(status) && status >= 400 && status <= 599) {
|
|
234541
|
+
this.httpStatus = status;
|
|
234542
|
+
}
|
|
234543
|
+
}
|
|
234208
234544
|
}
|
|
234209
234545
|
};
|
|
234210
234546
|
});
|
|
@@ -239102,6 +239438,20 @@ function waitForChildRun(receipt, signal, onIdle) {
|
|
|
239102
239438
|
onIdle
|
|
239103
239439
|
});
|
|
239104
239440
|
}
|
|
239441
|
+
function trackPersistedChildSend(receipt, writer) {
|
|
239442
|
+
writer.found.then(async (found) => {
|
|
239443
|
+
if (!found)
|
|
239444
|
+
return;
|
|
239445
|
+
try {
|
|
239446
|
+
await waitForChildRun(receipt, new AbortController().signal, () => {
|
|
239447
|
+
return;
|
|
239448
|
+
});
|
|
239449
|
+
writer.update({ status: "completed" });
|
|
239450
|
+
} catch {
|
|
239451
|
+
writer.update({ status: "failed" });
|
|
239452
|
+
}
|
|
239453
|
+
});
|
|
239454
|
+
}
|
|
239105
239455
|
function trackChildSend(input) {
|
|
239106
239456
|
const { receipt, child, parentScope } = input;
|
|
239107
239457
|
const subagentId = generateSubagentId();
|
|
@@ -239115,10 +239465,16 @@ function trackChildSend(input) {
|
|
|
239115
239465
|
})
|
|
239116
239466
|
});
|
|
239117
239467
|
const onIdle = createRemoteIdleNotifier(subagentId, parentScope);
|
|
239118
|
-
(input.waitForRun ?? ((receipt2, signal) => waitForChildRun(receipt2, signal, onIdle)))(receipt, input.signal ?? new AbortController().signal).then(() =>
|
|
239119
|
-
|
|
239120
|
-
|
|
239121
|
-
})
|
|
239468
|
+
(input.waitForRun ?? ((receipt2, signal) => waitForChildRun(receipt2, signal, onIdle)))(receipt, input.signal ?? new AbortController().signal).then(() => {
|
|
239469
|
+
input.persistRun?.({ status: "completed" });
|
|
239470
|
+
completeSubagent(subagentId, { success: true });
|
|
239471
|
+
}, (error4) => {
|
|
239472
|
+
input.persistRun?.({ status: "failed" });
|
|
239473
|
+
completeSubagent(subagentId, {
|
|
239474
|
+
success: false,
|
|
239475
|
+
error: getErrorMessage2(error4)
|
|
239476
|
+
});
|
|
239477
|
+
});
|
|
239122
239478
|
return subagentId;
|
|
239123
239479
|
}
|
|
239124
239480
|
var init_child_send_tracking = __esm(() => {
|
|
@@ -239330,6 +239686,7 @@ function composeSubagentChildEnv(options) {
|
|
|
239330
239686
|
},
|
|
239331
239687
|
LETTA_PARENT_AGENT_ID: parentAgentId,
|
|
239332
239688
|
LETTA_PARENT_CONVERSATION_ID: options.parentConversationId,
|
|
239689
|
+
[SUBAGENT_SUMMARY_ENV]: options.subagentSummary,
|
|
239333
239690
|
[SUBAGENT_DEPTH_ENV]: String(readSubagentDepth(parentProcessEnv) + 1),
|
|
239334
239691
|
...transcriptPath && { TRANSCRIPT_PATH: transcriptPath }
|
|
239335
239692
|
};
|
|
@@ -239606,6 +239963,250 @@ var init_subagent_process = __esm(() => {
|
|
|
239606
239963
|
init_package_manager_spawn();
|
|
239607
239964
|
});
|
|
239608
239965
|
|
|
239966
|
+
// src/tools/impl/native-session-owner.ts
|
|
239967
|
+
import { createHash as createHash11 } from "node:crypto";
|
|
239968
|
+
import { mkdirSync as mkdirSync38, readFileSync as readFileSync41, rmSync as rmSync16, writeFileSync as writeFileSync33 } from "node:fs";
|
|
239969
|
+
import { join as join68 } from "node:path";
|
|
239970
|
+
function ownerPath(source, sessionId) {
|
|
239971
|
+
const id = createHash11("sha256").update(`${source}:${sessionId}`).digest("hex");
|
|
239972
|
+
return join68(resolveGlobalConfigDir(), "native-session-owners", `${id}.json`);
|
|
239973
|
+
}
|
|
239974
|
+
function readNativeSessionOwner(source, sessionId) {
|
|
239975
|
+
try {
|
|
239976
|
+
const owner = JSON.parse(readFileSync41(ownerPath(source, sessionId), "utf8"));
|
|
239977
|
+
if (typeof owner.agentId === "string" && typeof owner.conversationId === "string" && (owner.cloudSkillRepositories === undefined || isCloudRepositoryNames(owner.cloudSkillRepositories)))
|
|
239978
|
+
return owner;
|
|
239979
|
+
throw new Error("Invalid native session owner record");
|
|
239980
|
+
} catch (error4) {
|
|
239981
|
+
if (error4.code !== "ENOENT")
|
|
239982
|
+
throw error4;
|
|
239983
|
+
}
|
|
239984
|
+
return;
|
|
239985
|
+
}
|
|
239986
|
+
function persistNativeSessionOwner(source, sessionId, scope) {
|
|
239987
|
+
const path30 = ownerPath(source, sessionId);
|
|
239988
|
+
mkdirSync38(join68(path30, ".."), { recursive: true, mode: 448 });
|
|
239989
|
+
try {
|
|
239990
|
+
writeFileSync33(path30, JSON.stringify(scope), { flag: "wx", mode: 384 });
|
|
239991
|
+
} catch (error4) {
|
|
239992
|
+
if (error4.code !== "EEXIST")
|
|
239993
|
+
throw error4;
|
|
239994
|
+
}
|
|
239995
|
+
}
|
|
239996
|
+
var init_native_session_owner = __esm(() => {
|
|
239997
|
+
init_cloud_repository_roots();
|
|
239998
|
+
init_settings_path();
|
|
239999
|
+
});
|
|
240000
|
+
|
|
240001
|
+
// src/tools/impl/antigravity-session.ts
|
|
240002
|
+
import { createInterface as createInterface8 } from "node:readline";
|
|
240003
|
+
async function runAntigravityTurn(options, env6, secrets2) {
|
|
240004
|
+
const start = Date.now();
|
|
240005
|
+
if (env6.GEMINI_API_KEY)
|
|
240006
|
+
secrets2 = { ...secrets2, GEMINI_API_KEY: env6.GEMINI_API_KEY };
|
|
240007
|
+
let sessionId = options.resumeSessionId;
|
|
240008
|
+
const state2 = { queue: [], closing: false };
|
|
240009
|
+
const controller = new AbortController;
|
|
240010
|
+
const signal = options.signal ? AbortSignal.any([controller.signal, options.signal]) : controller.signal;
|
|
240011
|
+
const base2 = {
|
|
240012
|
+
model: options.model,
|
|
240013
|
+
report: "",
|
|
240014
|
+
agentId: options.parentAgentId
|
|
240015
|
+
};
|
|
240016
|
+
try {
|
|
240017
|
+
signal.throwIfAborted();
|
|
240018
|
+
const args = [
|
|
240019
|
+
"--mode",
|
|
240020
|
+
"accept-edits",
|
|
240021
|
+
"--input-format",
|
|
240022
|
+
"stream-json",
|
|
240023
|
+
"--output-format",
|
|
240024
|
+
"stream-json",
|
|
240025
|
+
"--disable-slash-commands"
|
|
240026
|
+
];
|
|
240027
|
+
if (env6.GEMINI_API_KEY)
|
|
240028
|
+
args.push("--settings", '{"modelProvider":"gemini"}');
|
|
240029
|
+
if (sessionId) {
|
|
240030
|
+
const owner = readNativeSessionOwner("antigravity", sessionId);
|
|
240031
|
+
if (!sessionPattern.test(sessionId) || owner?.agentId !== options.parentAgentId)
|
|
240032
|
+
throw new Error("Antigravity session does not belong to this agent");
|
|
240033
|
+
if (sessions.has(sessionId))
|
|
240034
|
+
throw new Error("Antigravity session is already running");
|
|
240035
|
+
sessions.set(sessionId, state2);
|
|
240036
|
+
args.push("--conversation", sessionId);
|
|
240037
|
+
options = {
|
|
240038
|
+
...options,
|
|
240039
|
+
cwd: owner.cwd ?? options.cwd,
|
|
240040
|
+
model: options.model ?? owner.model
|
|
240041
|
+
};
|
|
240042
|
+
}
|
|
240043
|
+
if (options.model)
|
|
240044
|
+
args.push("--model", options.model);
|
|
240045
|
+
const running = spawnManagedWorkloadProcess("agy", args, {
|
|
240046
|
+
cwd: options.cwd,
|
|
240047
|
+
env: env6,
|
|
240048
|
+
signal
|
|
240049
|
+
});
|
|
240050
|
+
const child = running.process;
|
|
240051
|
+
let diagnostic = "";
|
|
240052
|
+
let spawnError;
|
|
240053
|
+
child.once("error", (error5) => {
|
|
240054
|
+
spawnError = error5;
|
|
240055
|
+
});
|
|
240056
|
+
child.stderr.on("data", (chunk2) => {
|
|
240057
|
+
diagnostic = (diagnostic + chunk2).slice(-2048);
|
|
240058
|
+
});
|
|
240059
|
+
child.stdin.on("error", () => {});
|
|
240060
|
+
const lines = createInterface8({ input: child.stdout });
|
|
240061
|
+
const send = (content) => child.stdin.write(`${JSON.stringify({ event: "user", message: { content } })}
|
|
240062
|
+
`);
|
|
240063
|
+
send([options.mcpReminder, options.prompt].filter(Boolean).join(`
|
|
240064
|
+
|
|
240065
|
+
`));
|
|
240066
|
+
let report;
|
|
240067
|
+
let error4;
|
|
240068
|
+
let initialized = false;
|
|
240069
|
+
const text2 = createSecretStreamScrubber(secrets2);
|
|
240070
|
+
const tools = new Set;
|
|
240071
|
+
try {
|
|
240072
|
+
for await (const line of lines) {
|
|
240073
|
+
if (!line.trim())
|
|
240074
|
+
continue;
|
|
240075
|
+
const event = JSON.parse(line);
|
|
240076
|
+
if (!isRecord2(event))
|
|
240077
|
+
throw new Error("Invalid Antigravity event");
|
|
240078
|
+
if (event.event === "init") {
|
|
240079
|
+
const id = event.conversation_id;
|
|
240080
|
+
if (initialized || typeof id !== "string" || !sessionPattern.test(id) || sessionId && id !== sessionId || !sessionId && sessions.has(id))
|
|
240081
|
+
throw new Error("Invalid Antigravity conversation ID");
|
|
240082
|
+
sessionId = id;
|
|
240083
|
+
if (!options.resumeSessionId)
|
|
240084
|
+
persistNativeSessionOwner("antigravity", id, {
|
|
240085
|
+
agentId: options.parentAgentId,
|
|
240086
|
+
conversationId: options.parentConversationId ?? "default",
|
|
240087
|
+
cwd: options.cwd,
|
|
240088
|
+
model: options.model
|
|
240089
|
+
});
|
|
240090
|
+
if (readNativeSessionOwner("antigravity", id)?.agentId !== options.parentAgentId)
|
|
240091
|
+
throw new Error("Antigravity session owner mismatch");
|
|
240092
|
+
sessions.set(id, state2);
|
|
240093
|
+
initialized = true;
|
|
240094
|
+
options.onStarted?.(`antigravity_${id}`);
|
|
240095
|
+
} else if (event.event === "step_update" && isRecord2(event.step_update)) {
|
|
240096
|
+
const step = event.step_update;
|
|
240097
|
+
if (!initialized || step.conversation_id !== sessionId)
|
|
240098
|
+
throw new Error("Unexpected Antigravity step conversation");
|
|
240099
|
+
if (step.step_type === "agent_response" && typeof step.text_delta === "string") {
|
|
240100
|
+
const delta = text2.push(step.text_delta);
|
|
240101
|
+
if (delta)
|
|
240102
|
+
emitProgress(options.onText, delta);
|
|
240103
|
+
}
|
|
240104
|
+
if (step.step_type === "tool" && typeof step.step_index === "number" && typeof step.tool_name === "string") {
|
|
240105
|
+
const info = isRecord2(step.tool_info) ? step.tool_info : {};
|
|
240106
|
+
const id = `step-${step.step_index}`;
|
|
240107
|
+
if (!tools.has(step.step_index)) {
|
|
240108
|
+
tools.add(step.step_index);
|
|
240109
|
+
emitProgress(options.onToolCall, {
|
|
240110
|
+
id,
|
|
240111
|
+
name: step.tool_name,
|
|
240112
|
+
args: formatExternalToolCallArgs(info.parameters)
|
|
240113
|
+
});
|
|
240114
|
+
}
|
|
240115
|
+
if (step.state === "DONE")
|
|
240116
|
+
emitProgress(options.onToolResult, {
|
|
240117
|
+
id,
|
|
240118
|
+
name: step.tool_name,
|
|
240119
|
+
isError: !!info.error,
|
|
240120
|
+
output: toolOutputText(info.error ?? info.output)
|
|
240121
|
+
});
|
|
240122
|
+
}
|
|
240123
|
+
} else if (event.event === "result" && isRecord2(event.result)) {
|
|
240124
|
+
const result3 = event.result;
|
|
240125
|
+
const tail2 = text2.flush();
|
|
240126
|
+
if (tail2)
|
|
240127
|
+
emitProgress(options.onText, tail2);
|
|
240128
|
+
if (result3.status !== "SUCCESS")
|
|
240129
|
+
error4 = typeof result3.error === "string" ? result3.error : "Antigravity turn failed";
|
|
240130
|
+
else if (!initialized || result3.conversation_id !== sessionId || typeof result3.response !== "string" || state2.closing)
|
|
240131
|
+
throw new Error("Invalid Antigravity result");
|
|
240132
|
+
const next = !error4 && state2.queue.shift();
|
|
240133
|
+
if (next) {
|
|
240134
|
+
tools.clear();
|
|
240135
|
+
send(next);
|
|
240136
|
+
} else {
|
|
240137
|
+
state2.closing = true;
|
|
240138
|
+
report = typeof result3.response === "string" ? result3.response : undefined;
|
|
240139
|
+
child.stdin.end();
|
|
240140
|
+
}
|
|
240141
|
+
}
|
|
240142
|
+
}
|
|
240143
|
+
const { exitCode } = await running.completion;
|
|
240144
|
+
signal.throwIfAborted();
|
|
240145
|
+
if (spawnError?.code === "ENOENT")
|
|
240146
|
+
throw new Error("Required executable 'agy' was not found on PATH");
|
|
240147
|
+
if (!initialized && /authentication required|authentication failed/i.test(`${diagnostic}
|
|
240148
|
+
${error4}`))
|
|
240149
|
+
throw new Error("Antigravity is not signed in: run agy to authenticate");
|
|
240150
|
+
if (spawnError || error4 || exitCode !== 0 || report === undefined || !sessionId)
|
|
240151
|
+
throw spawnError ?? new Error(error4 || diagnostic.trim() || "Antigravity exited without a result");
|
|
240152
|
+
return {
|
|
240153
|
+
...base2,
|
|
240154
|
+
agentId: `antigravity_${sessionId}`,
|
|
240155
|
+
runtimeSessionId: sessionId,
|
|
240156
|
+
report: scrubSecretsFromString(report, secrets2),
|
|
240157
|
+
success: true,
|
|
240158
|
+
durationMs: Date.now() - start
|
|
240159
|
+
};
|
|
240160
|
+
} finally {
|
|
240161
|
+
lines.close();
|
|
240162
|
+
if (child.exitCode === null && child.signalCode === null)
|
|
240163
|
+
controller.abort();
|
|
240164
|
+
await running.completion;
|
|
240165
|
+
}
|
|
240166
|
+
} catch (error4) {
|
|
240167
|
+
return {
|
|
240168
|
+
...base2,
|
|
240169
|
+
success: false,
|
|
240170
|
+
error: scrubSecretsFromString(error4 instanceof Error ? error4.message : String(error4), secrets2),
|
|
240171
|
+
durationMs: Date.now() - start
|
|
240172
|
+
};
|
|
240173
|
+
} finally {
|
|
240174
|
+
if (sessionId && sessions.get(sessionId) === state2)
|
|
240175
|
+
sessions.delete(sessionId);
|
|
240176
|
+
}
|
|
240177
|
+
}
|
|
240178
|
+
function sendAntigravityMessage(options, env6, secrets2) {
|
|
240179
|
+
const id = options.resumeSessionId;
|
|
240180
|
+
if (readNativeSessionOwner("antigravity", id)?.agentId !== options.parentAgentId)
|
|
240181
|
+
throw new Error("Antigravity session does not belong to this agent");
|
|
240182
|
+
const active = sessions.get(id);
|
|
240183
|
+
if (active) {
|
|
240184
|
+
if (active.closing)
|
|
240185
|
+
throw new Error("Antigravity session is finishing; retry after completion");
|
|
240186
|
+
active.queue.push(options.prompt);
|
|
240187
|
+
return { mode: "steered", queued: true };
|
|
240188
|
+
}
|
|
240189
|
+
const controller = new AbortController;
|
|
240190
|
+
const signal = options.signal ? AbortSignal.any([controller.signal, options.signal]) : controller.signal;
|
|
240191
|
+
const completion = runAntigravityTurn({ ...options, signal }, env6, secrets2);
|
|
240192
|
+
return {
|
|
240193
|
+
mode: "resumed",
|
|
240194
|
+
completion,
|
|
240195
|
+
interrupt: async () => {
|
|
240196
|
+
controller.abort();
|
|
240197
|
+
await completion;
|
|
240198
|
+
}
|
|
240199
|
+
};
|
|
240200
|
+
}
|
|
240201
|
+
var sessions, sessionPattern;
|
|
240202
|
+
var init_antigravity_session = __esm(() => {
|
|
240203
|
+
init_subagent_process();
|
|
240204
|
+
init_secret_substitution();
|
|
240205
|
+
init_native_session_owner();
|
|
240206
|
+
sessions = new Map;
|
|
240207
|
+
sessionPattern = /^[a-f\d]{8}(?:-[a-f\d]{4}){3}-[a-f\d]{12}$/i;
|
|
240208
|
+
});
|
|
240209
|
+
|
|
239609
240210
|
// src/utils/confirm-process-exit.ts
|
|
239610
240211
|
async function confirmProcessExit(exit, name) {
|
|
239611
240212
|
let timer;
|
|
@@ -239623,11 +240224,11 @@ async function confirmProcessExit(exit, name) {
|
|
|
239623
240224
|
|
|
239624
240225
|
// src/utils/native-cli-env.ts
|
|
239625
240226
|
import { homedir as homedir19 } from "node:os";
|
|
239626
|
-
import { join as
|
|
240227
|
+
import { join as join69 } from "node:path";
|
|
239627
240228
|
function withNativeCliPath(env6, platform7 = process.platform) {
|
|
239628
240229
|
if (platform7 === "win32")
|
|
239629
240230
|
return { ...env6 };
|
|
239630
|
-
const nativeBin =
|
|
240231
|
+
const nativeBin = join69(env6.HOME || homedir19(), ".local", "bin");
|
|
239631
240232
|
const paths = (env6.PATH ?? "/usr/bin:/bin").split(":");
|
|
239632
240233
|
if (!paths.includes(nativeBin))
|
|
239633
240234
|
paths.push(nativeBin);
|
|
@@ -239638,7 +240239,7 @@ var init_native_cli_env = () => {};
|
|
|
239638
240239
|
// src/tools/impl/claude-repository-skills.ts
|
|
239639
240240
|
import { mkdir as mkdir11, mkdtemp as mkdtemp4, rm as rm8, stat as stat10, symlink as symlink3 } from "node:fs/promises";
|
|
239640
240241
|
import { tmpdir as tmpdir13 } from "node:os";
|
|
239641
|
-
import { basename as basename22, join as
|
|
240242
|
+
import { basename as basename22, join as join70 } from "node:path";
|
|
239642
240243
|
async function stageClaudeRepositorySkills(repositoryRoots) {
|
|
239643
240244
|
const directories = [];
|
|
239644
240245
|
let stagingRoot;
|
|
@@ -239649,7 +240250,7 @@ async function stageClaudeRepositorySkills(repositoryRoots) {
|
|
|
239649
240250
|
try {
|
|
239650
240251
|
for (const repo of repositoryRoots) {
|
|
239651
240252
|
for (const source of [".claude", ".agents"]) {
|
|
239652
|
-
const skills =
|
|
240253
|
+
const skills = join70(repo, source, "skills");
|
|
239653
240254
|
const info = await stat10(skills).catch((error4) => {
|
|
239654
240255
|
if (error4.code === "ENOENT" || error4.code === "ENOTDIR")
|
|
239655
240256
|
return;
|
|
@@ -239657,11 +240258,11 @@ async function stageClaudeRepositorySkills(repositoryRoots) {
|
|
|
239657
240258
|
});
|
|
239658
240259
|
if (!info?.isDirectory())
|
|
239659
240260
|
continue;
|
|
239660
|
-
stagingRoot ??= await mkdtemp4(
|
|
239661
|
-
const directory =
|
|
239662
|
-
const claudeDir =
|
|
240261
|
+
stagingRoot ??= await mkdtemp4(join70(tmpdir13(), "letta-claude-skills-"));
|
|
240262
|
+
const directory = join70(stagingRoot, source, basename22(repo));
|
|
240263
|
+
const claudeDir = join70(directory, ".claude");
|
|
239663
240264
|
await mkdir11(claudeDir, { recursive: true });
|
|
239664
|
-
await symlink3(skills,
|
|
240265
|
+
await symlink3(skills, join70(claudeDir, "skills"), "dir");
|
|
239665
240266
|
directories.push(directory);
|
|
239666
240267
|
}
|
|
239667
240268
|
}
|
|
@@ -239800,11 +240401,17 @@ function traceJsonFits(bytes, encodedBytes) {
|
|
|
239800
240401
|
function tracePayloadFits(json2) {
|
|
239801
240402
|
return traceJsonFits(Buffer.byteLength(json2), Buffer.byteLength(JSON.stringify(json2)));
|
|
239802
240403
|
}
|
|
239803
|
-
function
|
|
240404
|
+
function isInlineImage(value) {
|
|
240405
|
+
if (value.type === "image")
|
|
240406
|
+
return value.source?.type === "base64" && typeof value.source.data === "string";
|
|
240407
|
+
const url2 = typeof value.image_url === "string" ? value.image_url : value.image_url?.url;
|
|
240408
|
+
return (value.type === "input_image" || value.type === "image_url") && typeof url2 === "string" && /^data:image\/[^;,]+;base64,/i.test(url2);
|
|
240409
|
+
}
|
|
240410
|
+
function compactTracePayload(json2, mode = "full") {
|
|
239804
240411
|
const payload = JSON.parse(json2);
|
|
239805
240412
|
if (!payload || typeof payload !== "object")
|
|
239806
240413
|
return TRUNCATED_TRACE_JSON;
|
|
239807
|
-
if (!Array.isArray(payload)) {
|
|
240414
|
+
if (mode === "full" && !Array.isArray(payload)) {
|
|
239808
240415
|
const object4 = payload;
|
|
239809
240416
|
delete object4.system;
|
|
239810
240417
|
delete object4.tools;
|
|
@@ -239816,36 +240423,47 @@ function compactTracePayload(json2) {
|
|
|
239816
240423
|
let encodedBytes = Buffer.byteLength(JSON.stringify(initial2));
|
|
239817
240424
|
if (traceJsonFits(bytes, encodedBytes))
|
|
239818
240425
|
return initial2;
|
|
239819
|
-
|
|
239820
|
-
|
|
239821
|
-
|
|
239822
|
-
|
|
239823
|
-
|
|
239824
|
-
|
|
239825
|
-
|
|
239826
|
-
|
|
239827
|
-
|
|
239828
|
-
|
|
239829
|
-
|
|
239830
|
-
|
|
239831
|
-
|
|
239832
|
-
|
|
239833
|
-
|
|
239834
|
-
|
|
239835
|
-
|
|
239836
|
-
|
|
240426
|
+
function shrink(imagesOnly) {
|
|
240427
|
+
const candidates = [];
|
|
240428
|
+
function collect(container) {
|
|
240429
|
+
for (const [key2, value] of Object.entries(container)) {
|
|
240430
|
+
const isObject5 = value !== null && typeof value === "object";
|
|
240431
|
+
if (imagesOnly && (!isObject5 || !isInlineImage(value))) {
|
|
240432
|
+
if (isObject5)
|
|
240433
|
+
collect(value);
|
|
240434
|
+
continue;
|
|
240435
|
+
}
|
|
240436
|
+
if (!imagesOnly && (Array.isArray(value) || key2 === "response" && isObject5)) {
|
|
240437
|
+
collect(value);
|
|
240438
|
+
continue;
|
|
240439
|
+
}
|
|
240440
|
+
const serialized = JSON.stringify(value);
|
|
240441
|
+
const bytes2 = Buffer.byteLength(serialized) - Buffer.byteLength(TRUNCATED_TRACE_JSON);
|
|
240442
|
+
const encodedBytes2 = Buffer.byteLength(JSON.stringify(serialized)) - Buffer.byteLength(JSON.stringify(TRUNCATED_TRACE_JSON));
|
|
240443
|
+
if (bytes2 > 0 && encodedBytes2 > 0) {
|
|
240444
|
+
candidates.push({
|
|
240445
|
+
bytes: bytes2,
|
|
240446
|
+
encodedBytes: encodedBytes2,
|
|
240447
|
+
replace: () => {
|
|
240448
|
+
container[key2] = truncated;
|
|
240449
|
+
}
|
|
240450
|
+
});
|
|
240451
|
+
}
|
|
239837
240452
|
}
|
|
239838
240453
|
}
|
|
240454
|
+
collect(payload);
|
|
240455
|
+
candidates.sort((a2, b3) => b3.bytes - a2.bytes);
|
|
240456
|
+
for (const candidate of candidates) {
|
|
240457
|
+
if (traceJsonFits(bytes, encodedBytes))
|
|
240458
|
+
break;
|
|
240459
|
+
candidate.replace();
|
|
240460
|
+
bytes -= candidate.bytes;
|
|
240461
|
+
encodedBytes -= candidate.encodedBytes;
|
|
240462
|
+
}
|
|
239839
240463
|
}
|
|
239840
|
-
|
|
239841
|
-
|
|
239842
|
-
|
|
239843
|
-
if (traceJsonFits(bytes, encodedBytes))
|
|
239844
|
-
break;
|
|
239845
|
-
candidate.replace();
|
|
239846
|
-
bytes -= candidate.bytes;
|
|
239847
|
-
encodedBytes -= candidate.encodedBytes;
|
|
239848
|
-
}
|
|
240464
|
+
shrink(true);
|
|
240465
|
+
if (mode === "full" && !traceJsonFits(bytes, encodedBytes))
|
|
240466
|
+
shrink(false);
|
|
239849
240467
|
return traceJsonFits(bytes, encodedBytes) ? marked() : TRUNCATED_TRACE_JSON;
|
|
239850
240468
|
}
|
|
239851
240469
|
var MAX_TRACE_PAYLOAD_BYTES, SENSITIVE, MAX_TRACE_BUFFER_BYTES, MAX_ENCODED_PAYLOAD_BYTES, truncated, TRUNCATED_TRACE_JSON;
|
|
@@ -239865,12 +240483,24 @@ import { createServer as createServer6, request as httpRequest3 } from "node:htt
|
|
|
239865
240483
|
import { request as httpsRequest2 } from "node:https";
|
|
239866
240484
|
import { isDeepStrictEqual } from "node:util";
|
|
239867
240485
|
import { brotliDecompressSync, gunzipSync, inflateSync } from "node:zlib";
|
|
240486
|
+
function withoutCacheBreakpoints(item) {
|
|
240487
|
+
if (!item || typeof item !== "object" || Array.isArray(item))
|
|
240488
|
+
return item;
|
|
240489
|
+
const block = { ...item };
|
|
240490
|
+
const cacheControl = block.cache_control;
|
|
240491
|
+
if (cacheControl && typeof cacheControl === "object" && "type" in cacheControl && cacheControl.type === "ephemeral")
|
|
240492
|
+
delete block.cache_control;
|
|
240493
|
+
if (Array.isArray(block.content))
|
|
240494
|
+
block.content = block.content.map(withoutCacheBreakpoints);
|
|
240495
|
+
return block;
|
|
240496
|
+
}
|
|
239868
240497
|
async function startTraceProxy(options) {
|
|
239869
240498
|
const upstream = new URL(options.upstream);
|
|
239870
240499
|
if (!["http:", "https:"].includes(upstream.protocol) || upstream.username || upstream.password)
|
|
239871
240500
|
throw new Error("Unsupported trace upstream");
|
|
239872
240501
|
const prefix = `/${randomUUID39()}`;
|
|
239873
240502
|
const historyKey = options.harness === "claude_code" ? "messages" : "input";
|
|
240503
|
+
const comparable = (item) => options.harness === "claude_code" ? withoutCacheBreakpoints(item) : item;
|
|
239874
240504
|
let previous;
|
|
239875
240505
|
let activeCaptures = 0;
|
|
239876
240506
|
const pending2 = new Set;
|
|
@@ -239948,21 +240578,26 @@ async function startTraceProxy(options) {
|
|
|
239948
240578
|
requestJson = fallbackJson;
|
|
239949
240579
|
if (previous?.sessionId === scope.worker_session_id && Array.isArray(items)) {
|
|
239950
240580
|
const prefixItems = previous.items.length;
|
|
239951
|
-
if (prefixItems > 0 && items.length > prefixItems && previous.items.every((item, index) => isDeepStrictEqual(item, items[index]))) {
|
|
239952
|
-
const
|
|
240581
|
+
if (prefixItems > 0 && items.length > prefixItems && previous.items.every((item, index) => isDeepStrictEqual(item, comparable(items[index])))) {
|
|
240582
|
+
const rawDelta = JSON.stringify({
|
|
239953
240583
|
...request3,
|
|
239954
240584
|
[historyKey]: items.slice(prefixItems),
|
|
239955
240585
|
base_trace_id: previous.id,
|
|
239956
240586
|
prefix_items: prefixItems
|
|
239957
240587
|
});
|
|
239958
|
-
|
|
240588
|
+
const deltaJson = tracePayloadFits(rawDelta) ? rawDelta : compactTracePayload(rawDelta, "images");
|
|
240589
|
+
if (deltaJson !== TRUNCATED_TRACE_JSON) {
|
|
239959
240590
|
requestJson = deltaJson;
|
|
239960
240591
|
delta = { baseId: previous.id, fallbackJson };
|
|
239961
240592
|
}
|
|
239962
240593
|
}
|
|
239963
240594
|
}
|
|
239964
240595
|
}
|
|
239965
|
-
previous = Array.isArray(items) && (!requestTruncated || delta) ? {
|
|
240596
|
+
previous = Array.isArray(items) && (!requestTruncated || delta) ? {
|
|
240597
|
+
id,
|
|
240598
|
+
sessionId: scope.worker_session_id,
|
|
240599
|
+
items: items.map(comparable)
|
|
240600
|
+
} : undefined;
|
|
239966
240601
|
const response = assembled.response;
|
|
239967
240602
|
const usage = response.usage ?? {};
|
|
239968
240603
|
const token2 = (value) => typeof value === "number" && Number.isFinite(value) && value >= 0 ? Math.min(Math.trunc(value), 4294967295) : null;
|
|
@@ -239975,6 +240610,7 @@ async function startTraceProxy(options) {
|
|
|
239975
240610
|
const error4 = transportError || status >= 400 || Boolean(response.error) || response.status === "failed";
|
|
239976
240611
|
options.emit({
|
|
239977
240612
|
...scope,
|
|
240613
|
+
task_description: scope.task_description === undefined ? undefined : JSON.parse(sanitizeTraceJson(JSON.stringify(scope.task_description), credentials)),
|
|
239978
240614
|
id,
|
|
239979
240615
|
harness: options.harness,
|
|
239980
240616
|
model: JSON.parse(sanitizeTraceJson(JSON.stringify(String(response.model ?? request3?.model ?? "")), credentials)).slice(0, 255),
|
|
@@ -240026,6 +240662,7 @@ async function startTraceProxy(options) {
|
|
|
240026
240662
|
reply.on("end", () => finish());
|
|
240027
240663
|
reply.on("error", () => {
|
|
240028
240664
|
finish(true);
|
|
240665
|
+
res.socket?.destroy();
|
|
240029
240666
|
res.destroy();
|
|
240030
240667
|
});
|
|
240031
240668
|
reply.pipe(res);
|
|
@@ -240057,6 +240694,15 @@ async function startTraceProxy(options) {
|
|
|
240057
240694
|
});
|
|
240058
240695
|
req.pipe(target);
|
|
240059
240696
|
});
|
|
240697
|
+
if (options.harness === "codex") {
|
|
240698
|
+
server2.on("upgrade", (_request, socket) => {
|
|
240699
|
+
socket.end(`HTTP/1.1 404 Not Found\r
|
|
240700
|
+
Connection: close\r
|
|
240701
|
+
Content-Length: 0\r
|
|
240702
|
+
\r
|
|
240703
|
+
`);
|
|
240704
|
+
});
|
|
240705
|
+
}
|
|
240060
240706
|
await new Promise((resolve34, reject2) => {
|
|
240061
240707
|
server2.once("error", reject2);
|
|
240062
240708
|
server2.listen(0, "127.0.0.1", resolve34);
|
|
@@ -240083,8 +240729,10 @@ var init_external_llm_trace_proxy = __esm(() => {
|
|
|
240083
240729
|
// src/tools/impl/external-llm-trace-session.ts
|
|
240084
240730
|
function updateExternalTraceTask(sessionId, context3) {
|
|
240085
240731
|
const scope = sessionScopes.get(sessionId);
|
|
240086
|
-
if (scope && context3 && scope.parent_agent_id === context3.parent_agent_id && scope.parent_conversation_id === context3.parent_conversation_id)
|
|
240732
|
+
if (scope && context3 && scope.parent_agent_id === context3.parent_agent_id && scope.parent_conversation_id === context3.parent_conversation_id) {
|
|
240087
240733
|
scope.task_id = context3.task_id;
|
|
240734
|
+
scope.task_description = context3.task_description;
|
|
240735
|
+
}
|
|
240088
240736
|
}
|
|
240089
240737
|
function describeUploadError(error4, secrets2) {
|
|
240090
240738
|
if (!(error4 instanceof Error))
|
|
@@ -240280,12 +240928,21 @@ async function traceClaudeLaunch(context3, env6, sessionId) {
|
|
|
240280
240928
|
function record4(value) {
|
|
240281
240929
|
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
240282
240930
|
}
|
|
240283
|
-
async function traceCodexLaunch(context3, env6, client, createTrace2 = createTraceSession) {
|
|
240931
|
+
async function traceCodexLaunch(context3, env6, client, resumeThreadId, createTrace2 = createTraceSession) {
|
|
240284
240932
|
if (!context3 || env6.LETTA_CODE_TELEM === "0" || env6.LETTA_CODE_TELEM === "false" || env6.DO_NOT_TRACK === "1")
|
|
240285
240933
|
return;
|
|
240286
240934
|
try {
|
|
240287
240935
|
const configuration = record4((await client.request("config/read", { includeLayers: false })).config);
|
|
240288
|
-
const
|
|
240936
|
+
const resumed = resumeThreadId ? await client.request("thread/read", {
|
|
240937
|
+
threadId: resumeThreadId,
|
|
240938
|
+
includeTurns: false
|
|
240939
|
+
}).catch(() => {
|
|
240940
|
+
return;
|
|
240941
|
+
}) : undefined;
|
|
240942
|
+
const persistedProvider = record4(resumed?.thread).modelProvider;
|
|
240943
|
+
const configuredProvider = configuration.model_provider;
|
|
240944
|
+
const sourceProvider = typeof persistedProvider === "string" && persistedProvider ? persistedProvider : configuredProvider;
|
|
240945
|
+
const providerId2 = typeof sourceProvider === "string" && sourceProvider !== "letta_trace" ? sourceProvider : "openai";
|
|
240289
240946
|
const provider2 = record4(record4(configuration.model_providers)[providerId2]);
|
|
240290
240947
|
const account = record4((await client.request("account/read", { refreshToken: false })).account);
|
|
240291
240948
|
const configuredUrl = provider2.base_url ?? (providerId2 === "openai" ? configuration.openai_base_url ?? env6.OPENAI_BASE_URL : undefined);
|
|
@@ -240302,6 +240959,8 @@ async function traceCodexLaunch(context3, env6, client, createTrace2 = createTra
|
|
|
240302
240959
|
[`model_providers.${selected}.supports_websockets`]: false
|
|
240303
240960
|
};
|
|
240304
240961
|
if (providerId2 === "openai") {
|
|
240962
|
+
if (resumeThreadId)
|
|
240963
|
+
overrides.openai_base_url = trace.url;
|
|
240305
240964
|
overrides[`model_providers.${selected}.name`] = "OpenAI trace";
|
|
240306
240965
|
overrides[`model_providers.${selected}.requires_openai_auth`] = true;
|
|
240307
240966
|
overrides[`model_providers.${selected}.wire_api`] = "responses";
|
|
@@ -240311,8 +240970,7 @@ async function traceCodexLaunch(context3, env6, client, createTrace2 = createTra
|
|
|
240311
240970
|
args: Object.entries(overrides).flatMap(([key2, value]) => [
|
|
240312
240971
|
"-c",
|
|
240313
240972
|
`${key2}=${JSON.stringify(value)}`
|
|
240314
|
-
])
|
|
240315
|
-
params: { modelProvider: selected }
|
|
240973
|
+
])
|
|
240316
240974
|
};
|
|
240317
240975
|
} catch {
|
|
240318
240976
|
return;
|
|
@@ -240324,7 +240982,7 @@ var init_external_llm_trace_launch = __esm(() => {
|
|
|
240324
240982
|
|
|
240325
240983
|
// src/tools/impl/claude-stream-session.ts
|
|
240326
240984
|
import { randomUUID as randomUUID40 } from "node:crypto";
|
|
240327
|
-
import { createInterface as
|
|
240985
|
+
import { createInterface as createInterface9 } from "node:readline";
|
|
240328
240986
|
function errorMessage3(error4) {
|
|
240329
240987
|
return error4 instanceof Error ? error4.message : String(error4);
|
|
240330
240988
|
}
|
|
@@ -240730,12 +241388,12 @@ async function launchSession(options, deps) {
|
|
|
240730
241388
|
onReasoning: options.onReasoning,
|
|
240731
241389
|
toolNames: new Map
|
|
240732
241390
|
};
|
|
240733
|
-
|
|
241391
|
+
sessions2.set(sessionId, session3);
|
|
240734
241392
|
transport3.process.stderr.setEncoding("utf8");
|
|
240735
241393
|
transport3.process.stderr.on("data", (chunk2) => {
|
|
240736
241394
|
session3.stderr += chunk2;
|
|
240737
241395
|
});
|
|
240738
|
-
const stdout =
|
|
241396
|
+
const stdout = createInterface9({ input: transport3.process.stdout });
|
|
240739
241397
|
stdout.on("line", (line) => {
|
|
240740
241398
|
if (!line.trim())
|
|
240741
241399
|
return;
|
|
@@ -240784,8 +241442,8 @@ async function launchSession(options, deps) {
|
|
|
240784
241442
|
}).finally(() => {
|
|
240785
241443
|
session3.exited = true;
|
|
240786
241444
|
removeUpstreamAbort();
|
|
240787
|
-
if (
|
|
240788
|
-
|
|
241445
|
+
if (sessions2.get(sessionId) === session3)
|
|
241446
|
+
sessions2.delete(sessionId);
|
|
240789
241447
|
resolveExit();
|
|
240790
241448
|
});
|
|
240791
241449
|
try {
|
|
@@ -240839,7 +241497,7 @@ async function startSession(options, deps) {
|
|
|
240839
241497
|
const key2 = options.resumeSessionId ?? options.sessionId;
|
|
240840
241498
|
if (key2) {
|
|
240841
241499
|
for (;; ) {
|
|
240842
|
-
const existing =
|
|
241500
|
+
const existing = sessions2.get(key2);
|
|
240843
241501
|
if (!existing)
|
|
240844
241502
|
break;
|
|
240845
241503
|
if (!existing.settled)
|
|
@@ -240871,14 +241529,14 @@ async function steerSession(session3, prompt, signal) {
|
|
|
240871
241529
|
signal?.throwIfAborted();
|
|
240872
241530
|
await waitForTurnStart(session3, signal);
|
|
240873
241531
|
if (session3.idleOnBackgroundTasks) {
|
|
240874
|
-
if (session3.settled ||
|
|
241532
|
+
if (session3.settled || sessions2.get(session3.sessionId) !== session3) {
|
|
240875
241533
|
throw new Error("Claude Code session is no longer active");
|
|
240876
241534
|
}
|
|
240877
241535
|
session3.idleOnBackgroundTasks = false;
|
|
240878
241536
|
await writeInput(session3, prompt);
|
|
240879
241537
|
return "steered";
|
|
240880
241538
|
}
|
|
240881
|
-
if (session3.settled ||
|
|
241539
|
+
if (session3.settled || sessions2.get(session3.sessionId) !== session3) {
|
|
240882
241540
|
throw new Error("Claude Code session is no longer active");
|
|
240883
241541
|
}
|
|
240884
241542
|
const requestId = randomUUID40();
|
|
@@ -240911,7 +241569,7 @@ async function steerSession(session3, prompt, signal) {
|
|
|
240911
241569
|
session3.suppressedResult = undefined;
|
|
240912
241570
|
return "steered";
|
|
240913
241571
|
} catch (error4) {
|
|
240914
|
-
if (ackTimedOut && !signal?.aborted && !session3.settled &&
|
|
241572
|
+
if (ackTimedOut && !signal?.aborted && !session3.settled && sessions2.get(session3.sessionId) === session3 && await queueSteerPrompt(session3, prompt))
|
|
240915
241573
|
return "queued";
|
|
240916
241574
|
session3.pendingSteers = Math.max(0, session3.pendingSteers - 1);
|
|
240917
241575
|
if (interruptAcknowledged) {
|
|
@@ -240923,7 +241581,7 @@ async function steerSession(session3, prompt, signal) {
|
|
|
240923
241581
|
const suppressed = session3.suppressedResult;
|
|
240924
241582
|
session3.suppressedResult = undefined;
|
|
240925
241583
|
finishResult(session3, suppressed);
|
|
240926
|
-
} else if (session3.resultCount === resultCount && !session3.settled &&
|
|
241584
|
+
} else if (session3.resultCount === resultCount && !session3.settled && sessions2.get(session3.sessionId) === session3) {
|
|
240927
241585
|
markTurnStarted(session3);
|
|
240928
241586
|
}
|
|
240929
241587
|
throw error4;
|
|
@@ -240953,7 +241611,7 @@ async function deliverClaudeMessage(options, deps, launch) {
|
|
|
240953
241611
|
await pending3;
|
|
240954
241612
|
continue;
|
|
240955
241613
|
}
|
|
240956
|
-
const existing =
|
|
241614
|
+
const existing = sessions2.get(options.sessionId);
|
|
240957
241615
|
if (!existing)
|
|
240958
241616
|
break;
|
|
240959
241617
|
if (existing.settled) {
|
|
@@ -240968,7 +241626,7 @@ async function deliverClaudeMessage(options, deps, launch) {
|
|
|
240968
241626
|
session: existing
|
|
240969
241627
|
};
|
|
240970
241628
|
} catch (error4) {
|
|
240971
|
-
if (
|
|
241629
|
+
if (sessions2.get(options.sessionId) === existing && !existing.settled)
|
|
240972
241630
|
throw error4;
|
|
240973
241631
|
}
|
|
240974
241632
|
}
|
|
@@ -241010,14 +241668,14 @@ async function sendClaudeMessage(options, deps = {}) {
|
|
|
241010
241668
|
return trackedReceipt(delivered.session);
|
|
241011
241669
|
}
|
|
241012
241670
|
async function stopClaudeSession(sessionId) {
|
|
241013
|
-
const session3 =
|
|
241671
|
+
const session3 = sessions2.get(sessionId);
|
|
241014
241672
|
if (!session3)
|
|
241015
241673
|
return false;
|
|
241016
241674
|
session3.abortController.abort(new Error("Stopped by parent"));
|
|
241017
241675
|
await confirmProcessExit(session3.exit, "Claude Code");
|
|
241018
241676
|
return true;
|
|
241019
241677
|
}
|
|
241020
|
-
var
|
|
241678
|
+
var sessions2, pendingResumes, BACKGROUND_TASK_WAIT_CAP_MS, SETTLED_EXIT_GRACE_MS = 1e4;
|
|
241021
241679
|
var init_claude_stream_session = __esm(() => {
|
|
241022
241680
|
init_subagent_process();
|
|
241023
241681
|
init_cloud_repository_roots();
|
|
@@ -241025,7 +241683,7 @@ var init_claude_stream_session = __esm(() => {
|
|
|
241025
241683
|
init_claude_repository_skills();
|
|
241026
241684
|
init_claude_steer_timeouts();
|
|
241027
241685
|
init_external_llm_trace_launch();
|
|
241028
|
-
|
|
241686
|
+
sessions2 = new Map;
|
|
241029
241687
|
pendingResumes = new Map;
|
|
241030
241688
|
BACKGROUND_TASK_WAIT_CAP_MS = 35 * 60000;
|
|
241031
241689
|
});
|
|
@@ -241199,8 +241857,8 @@ var init_codex_steer_receipt = __esm(() => {
|
|
|
241199
241857
|
});
|
|
241200
241858
|
|
|
241201
241859
|
// src/tools/impl/codex-app-server.ts
|
|
241202
|
-
import { join as
|
|
241203
|
-
import { createInterface as
|
|
241860
|
+
import { join as join71 } from "node:path";
|
|
241861
|
+
import { createInterface as createInterface10 } from "node:readline";
|
|
241204
241862
|
import { setTimeout as sleep12 } from "node:timers/promises";
|
|
241205
241863
|
async function listCodexModels(cwd2, env6) {
|
|
241206
241864
|
const controller = new AbortController;
|
|
@@ -241284,7 +241942,7 @@ class CodexAppServerClient {
|
|
|
241284
241942
|
this.transport = transport3;
|
|
241285
241943
|
this.onNotification = onNotification;
|
|
241286
241944
|
this.onClose = onClose;
|
|
241287
|
-
const stdout =
|
|
241945
|
+
const stdout = createInterface10({ input: transport3.stdout });
|
|
241288
241946
|
stdout.once("error", () => void this.close());
|
|
241289
241947
|
stdout.on("line", (line) => {
|
|
241290
241948
|
if (!line.trim())
|
|
@@ -241322,7 +241980,7 @@ class CodexAppServerClient {
|
|
|
241322
241980
|
await this.request("initialize", {
|
|
241323
241981
|
clientInfo: {
|
|
241324
241982
|
name: "letta-code",
|
|
241325
|
-
version: "0.34.
|
|
241983
|
+
version: "0.34.71"
|
|
241326
241984
|
},
|
|
241327
241985
|
capabilities: null
|
|
241328
241986
|
});
|
|
@@ -241382,8 +242040,8 @@ class CodexAppServerClient {
|
|
|
241382
242040
|
}
|
|
241383
242041
|
function failSession(session3, error4) {
|
|
241384
242042
|
clearIdleSessionCleanup(session3);
|
|
241385
|
-
if (
|
|
241386
|
-
|
|
242043
|
+
if (sessions3.get(session3.threadId) === session3)
|
|
242044
|
+
sessions3.delete(session3.threadId);
|
|
241387
242045
|
const waiter = session3.activeWaiter;
|
|
241388
242046
|
session3.activeTurnId = undefined;
|
|
241389
242047
|
session3.activeWaiter = undefined;
|
|
@@ -241526,8 +242184,8 @@ function clearIdleSessionCleanup(session3) {
|
|
|
241526
242184
|
}
|
|
241527
242185
|
function disposeSession(session3) {
|
|
241528
242186
|
clearIdleSessionCleanup(session3);
|
|
241529
|
-
if (
|
|
241530
|
-
|
|
242187
|
+
if (sessions3.get(session3.threadId) === session3)
|
|
242188
|
+
sessions3.delete(session3.threadId);
|
|
241531
242189
|
session3.client.dispose();
|
|
241532
242190
|
}
|
|
241533
242191
|
function scheduleIdleSessionCleanup(session3) {
|
|
@@ -241583,7 +242241,7 @@ async function createSession(options, deps) {
|
|
|
241583
242241
|
try {
|
|
241584
242242
|
await client.initialize();
|
|
241585
242243
|
await assertCodexSignedIn(client);
|
|
241586
|
-
trace = deps.createTransport ? undefined : await traceCodexLaunch(options.traceContext, env6, client);
|
|
242244
|
+
trace = deps.createTransport ? undefined : await traceCodexLaunch(options.traceContext, env6, client, options.resumeThreadId);
|
|
241587
242245
|
if (trace) {
|
|
241588
242246
|
client.dispose();
|
|
241589
242247
|
transport3 = spawnTransport({
|
|
@@ -241600,12 +242258,13 @@ async function createSession(options, deps) {
|
|
|
241600
242258
|
});
|
|
241601
242259
|
if (options.cloudSkillRepositories?.length) {
|
|
241602
242260
|
await client.request("skills/extraRoots/set", {
|
|
241603
|
-
extraRoots: cloudRepositoryRoots(options.cloudSkillRepositories).map((root2) =>
|
|
242261
|
+
extraRoots: cloudRepositoryRoots(options.cloudSkillRepositories).map((root2) => join71(root2, PROJECT_SKILLS_DIR))
|
|
241604
242262
|
});
|
|
241605
242263
|
}
|
|
241606
242264
|
const method2 = options.resumeThreadId ? "thread/resume" : "thread/start";
|
|
241607
242265
|
const params = options.resumeThreadId ? {
|
|
241608
242266
|
threadId: options.resumeThreadId,
|
|
242267
|
+
model: options.model,
|
|
241609
242268
|
...options.mcpReminder ? { developerInstructions: options.mcpReminder } : {}
|
|
241610
242269
|
} : {
|
|
241611
242270
|
cwd: options.cwd,
|
|
@@ -241614,7 +242273,7 @@ async function createSession(options, deps) {
|
|
|
241614
242273
|
sandbox: "danger-full-access",
|
|
241615
242274
|
developerInstructions: options.mcpReminder
|
|
241616
242275
|
};
|
|
241617
|
-
response = await client.request(method2,
|
|
242276
|
+
response = await client.request(method2, params);
|
|
241618
242277
|
} catch (error4) {
|
|
241619
242278
|
trace?.close();
|
|
241620
242279
|
client.dispose();
|
|
@@ -241636,13 +242295,13 @@ async function createSession(options, deps) {
|
|
|
241636
242295
|
client,
|
|
241637
242296
|
cwd: readString3(thread, "cwd") ?? options.cwd,
|
|
241638
242297
|
parentAgentId: options.parentAgentId,
|
|
241639
|
-
model: options.model,
|
|
242298
|
+
model: readString3(response, "model") ?? options.model,
|
|
241640
242299
|
startLock: Promise.resolve(),
|
|
241641
242300
|
pendingNotifications,
|
|
241642
242301
|
idleTimeoutMs: deps.idleTimeoutMs ?? DEFAULT_IDLE_TIMEOUT_MS,
|
|
241643
242302
|
sleep: deps.sleep ?? sleep12
|
|
241644
242303
|
};
|
|
241645
|
-
|
|
242304
|
+
sessions3.set(threadId, session3);
|
|
241646
242305
|
return session3;
|
|
241647
242306
|
}
|
|
241648
242307
|
async function startTurnAttempt(session3, prompt, startedAt, listeners6) {
|
|
@@ -241654,7 +242313,6 @@ async function startTurnAttempt(session3, prompt, startedAt, listeners6) {
|
|
|
241654
242313
|
threadId: session3.threadId,
|
|
241655
242314
|
input: textInput(prompt),
|
|
241656
242315
|
cwd: session3.cwd,
|
|
241657
|
-
model: session3.model,
|
|
241658
242316
|
approvalPolicy: "never",
|
|
241659
242317
|
sandboxPolicy: { type: "dangerFullAccess" }
|
|
241660
242318
|
});
|
|
@@ -241763,7 +242421,7 @@ async function startCodexTurn(options, deps = {}) {
|
|
|
241763
242421
|
}
|
|
241764
242422
|
}
|
|
241765
242423
|
async function resumeSession(threadId, options, deps) {
|
|
241766
|
-
const loaded =
|
|
242424
|
+
const loaded = sessions3.get(threadId);
|
|
241767
242425
|
if (loaded) {
|
|
241768
242426
|
clearIdleSessionCleanup(loaded);
|
|
241769
242427
|
return loaded;
|
|
@@ -241823,7 +242481,7 @@ async function sendCodexMessage(options, deps = {}) {
|
|
|
241823
242481
|
};
|
|
241824
242482
|
}));
|
|
241825
242483
|
} catch (error4) {
|
|
241826
|
-
if (!session3.activeTurnId &&
|
|
242484
|
+
if (!session3.activeTurnId && sessions3.get(session3.threadId) === session3) {
|
|
241827
242485
|
scheduleIdleSessionCleanup(session3);
|
|
241828
242486
|
}
|
|
241829
242487
|
throw error4;
|
|
@@ -241844,15 +242502,15 @@ async function runCodexTurn(options, deps = {}) {
|
|
|
241844
242502
|
}
|
|
241845
242503
|
}
|
|
241846
242504
|
async function stopCodexSession(threadId) {
|
|
241847
|
-
const session3 =
|
|
242505
|
+
const session3 = sessions3.get(threadId);
|
|
241848
242506
|
if (!session3)
|
|
241849
242507
|
return false;
|
|
241850
242508
|
await session3.client.stop();
|
|
241851
|
-
if (
|
|
241852
|
-
|
|
242509
|
+
if (sessions3.get(threadId) === session3)
|
|
242510
|
+
sessions3.delete(threadId);
|
|
241853
242511
|
return true;
|
|
241854
242512
|
}
|
|
241855
|
-
var
|
|
242513
|
+
var sessions3, sessionCreations, DEFAULT_IDLE_TIMEOUT_MS, CODEX_NOT_SIGNED_IN_ERROR = "Codex is not signed in. Run `codex login` on this computer.";
|
|
241856
242514
|
var init_codex_app_server = __esm(() => {
|
|
241857
242515
|
init_skills5();
|
|
241858
242516
|
init_subagent_process();
|
|
@@ -241862,7 +242520,7 @@ var init_codex_app_server = __esm(() => {
|
|
|
241862
242520
|
init_codex_steer_receipt();
|
|
241863
242521
|
init_external_llm_trace_launch();
|
|
241864
242522
|
init_external_llm_trace_session();
|
|
241865
|
-
|
|
242523
|
+
sessions3 = new Map;
|
|
241866
242524
|
sessionCreations = new Map;
|
|
241867
242525
|
DEFAULT_IDLE_TIMEOUT_MS = 5 * 60000;
|
|
241868
242526
|
});
|
|
@@ -241870,8 +242528,8 @@ var init_codex_app_server = __esm(() => {
|
|
|
241870
242528
|
// src/tools/impl/cursor-session.ts
|
|
241871
242529
|
import { randomUUID as randomUUID41 } from "node:crypto";
|
|
241872
242530
|
import { existsSync as existsSync47 } from "node:fs";
|
|
241873
|
-
import { join as
|
|
241874
|
-
import { createInterface as
|
|
242531
|
+
import { join as join72 } from "node:path";
|
|
242532
|
+
import { createInterface as createInterface11 } from "node:readline";
|
|
241875
242533
|
import { fileURLToPath as fileURLToPath7 } from "node:url";
|
|
241876
242534
|
function key2(options, id) {
|
|
241877
242535
|
if (!UUID.test(id) || !/^[\w-]+$/.test(options.parentAgentId))
|
|
@@ -241904,7 +242562,7 @@ async function runCursorTurn(options, env6 = process.env, secrets2 = {}) {
|
|
|
241904
242562
|
try {
|
|
241905
242563
|
options.signal?.throwIfAborted();
|
|
241906
242564
|
sessionKey = key2(options, id);
|
|
241907
|
-
if (
|
|
242565
|
+
if (sessions4.has(sessionKey))
|
|
241908
242566
|
throw new Error("Cursor session already has an active turn");
|
|
241909
242567
|
if (!env6.CURSOR_API_KEY)
|
|
241910
242568
|
throw new Error("Cursor is not signed in: add CURSOR_API_KEY to the agent's secrets or the selected computer's environment.");
|
|
@@ -241937,7 +242595,7 @@ async function runCursorTurn(options, env6 = process.env, secrets2 = {}) {
|
|
|
241937
242595
|
let stderr = "";
|
|
241938
242596
|
let requestId = 0;
|
|
241939
242597
|
const pending2 = new Map;
|
|
241940
|
-
const output =
|
|
242598
|
+
const output = createInterface11({ input: running.process.stdout });
|
|
241941
242599
|
running.process.stderr.on("data", (chunk2) => {
|
|
241942
242600
|
stderr = (stderr + chunk2).slice(-8192);
|
|
241943
242601
|
});
|
|
@@ -242021,12 +242679,12 @@ async function runCursorTurn(options, env6 = process.env, secrets2 = {}) {
|
|
|
242021
242679
|
await completion;
|
|
242022
242680
|
}
|
|
242023
242681
|
};
|
|
242024
|
-
|
|
242682
|
+
sessions4.set(sessionKey, active);
|
|
242025
242683
|
const command = {
|
|
242026
242684
|
type: "start",
|
|
242027
242685
|
sessionId: id,
|
|
242028
242686
|
resume: !!options.resumeSessionId,
|
|
242029
|
-
stateDir:
|
|
242687
|
+
stateDir: join72(resolveGlobalConfigDir(), "cursor-sessions", sessionKey),
|
|
242030
242688
|
cwd: options.cwd,
|
|
242031
242689
|
model: options.model,
|
|
242032
242690
|
reminder: options.mcpReminder,
|
|
@@ -242045,8 +242703,8 @@ async function runCursorTurn(options, env6 = process.env, secrets2 = {}) {
|
|
|
242045
242703
|
durationMs: Date.now() - startedAt
|
|
242046
242704
|
};
|
|
242047
242705
|
} finally {
|
|
242048
|
-
if (sessionKey && active &&
|
|
242049
|
-
|
|
242706
|
+
if (sessionKey && active && sessions4.get(sessionKey) === active)
|
|
242707
|
+
sessions4.delete(sessionKey);
|
|
242050
242708
|
}
|
|
242051
242709
|
}
|
|
242052
242710
|
async function sendCursorMessage(options, env6 = process.env, secrets2 = {}) {
|
|
@@ -242056,7 +242714,7 @@ async function sendCursorMessage(options, env6 = process.env, secrets2 = {}) {
|
|
|
242056
242714
|
return;
|
|
242057
242715
|
}).then(async () => {
|
|
242058
242716
|
options.signal?.throwIfAborted();
|
|
242059
|
-
const active =
|
|
242717
|
+
const active = sessions4.get(sessionKey);
|
|
242060
242718
|
const tail2 = queued.get(sessionKey);
|
|
242061
242719
|
if ((!tail2 || tail2.started) && active && await active.steer(options.prompt))
|
|
242062
242720
|
return { mode: "steered" };
|
|
@@ -242115,7 +242773,7 @@ async function listCursorModels(cwd2, env6, timeoutMs = 30000) {
|
|
|
242115
242773
|
const running = spawnManagedWorkloadProcess(process.execPath, [resolveCursorWorkerPath()], { cwd: cwd2, env: env6, signal: controller.signal });
|
|
242116
242774
|
let event;
|
|
242117
242775
|
let stderr = "";
|
|
242118
|
-
const output =
|
|
242776
|
+
const output = createInterface11({ input: running.process.stdout });
|
|
242119
242777
|
output.on("line", (line) => {
|
|
242120
242778
|
if (line.startsWith("letta-cursor:"))
|
|
242121
242779
|
event = JSON.parse(line.slice("letta-cursor:".length));
|
|
@@ -242142,14 +242800,14 @@ async function listCursorModels(cwd2, env6, timeoutMs = 30000) {
|
|
|
242142
242800
|
}
|
|
242143
242801
|
throw new Error(controller.signal.aborted ? "Cursor model discovery timed out" : event?.type === "error" ? event.error : `Cursor exited without a model catalog: ${stderr}`);
|
|
242144
242802
|
}
|
|
242145
|
-
var
|
|
242803
|
+
var sessions4, queued, followupControllers, locks, UUID;
|
|
242146
242804
|
var init_cursor_session = __esm(() => {
|
|
242147
242805
|
init_subagent_depth();
|
|
242148
242806
|
init_subagent_process();
|
|
242149
242807
|
init_runtime_context();
|
|
242150
242808
|
init_secret_substitution();
|
|
242151
242809
|
init_settings_path();
|
|
242152
|
-
|
|
242810
|
+
sessions4 = new Map;
|
|
242153
242811
|
queued = new Map;
|
|
242154
242812
|
followupControllers = new Set;
|
|
242155
242813
|
locks = new Map;
|
|
@@ -243125,41 +243783,6 @@ var init_engine = __esm(() => {
|
|
|
243125
243783
|
assertSharedReminderCoverage();
|
|
243126
243784
|
});
|
|
243127
243785
|
|
|
243128
|
-
// src/tools/impl/native-session-owner.ts
|
|
243129
|
-
import { createHash as createHash11 } from "node:crypto";
|
|
243130
|
-
import { mkdirSync as mkdirSync38, readFileSync as readFileSync41, rmSync as rmSync16, writeFileSync as writeFileSync33 } from "node:fs";
|
|
243131
|
-
import { join as join72 } from "node:path";
|
|
243132
|
-
function ownerPath(source, sessionId) {
|
|
243133
|
-
const id = createHash11("sha256").update(`${source}:${sessionId}`).digest("hex");
|
|
243134
|
-
return join72(resolveGlobalConfigDir(), "native-session-owners", `${id}.json`);
|
|
243135
|
-
}
|
|
243136
|
-
function readNativeSessionOwner(source, sessionId) {
|
|
243137
|
-
try {
|
|
243138
|
-
const owner = JSON.parse(readFileSync41(ownerPath(source, sessionId), "utf8"));
|
|
243139
|
-
if (typeof owner.agentId === "string" && typeof owner.conversationId === "string" && (owner.cloudSkillRepositories === undefined || isCloudRepositoryNames(owner.cloudSkillRepositories)))
|
|
243140
|
-
return owner;
|
|
243141
|
-
throw new Error("Invalid native session owner record");
|
|
243142
|
-
} catch (error4) {
|
|
243143
|
-
if (error4.code !== "ENOENT")
|
|
243144
|
-
throw error4;
|
|
243145
|
-
}
|
|
243146
|
-
return;
|
|
243147
|
-
}
|
|
243148
|
-
function persistNativeSessionOwner(source, sessionId, scope) {
|
|
243149
|
-
const path30 = ownerPath(source, sessionId);
|
|
243150
|
-
mkdirSync38(join72(path30, ".."), { recursive: true, mode: 448 });
|
|
243151
|
-
try {
|
|
243152
|
-
writeFileSync33(path30, JSON.stringify(scope), { flag: "wx", mode: 384 });
|
|
243153
|
-
} catch (error4) {
|
|
243154
|
-
if (error4.code !== "EEXIST")
|
|
243155
|
-
throw error4;
|
|
243156
|
-
}
|
|
243157
|
-
}
|
|
243158
|
-
var init_native_session_owner = __esm(() => {
|
|
243159
|
-
init_cloud_repository_roots();
|
|
243160
|
-
init_settings_path();
|
|
243161
|
-
});
|
|
243162
|
-
|
|
243163
243786
|
// src/tools/impl/native-session-capture.ts
|
|
243164
243787
|
import { createHash as createHash12, randomUUID as randomUUID42 } from "node:crypto";
|
|
243165
243788
|
import { readdirSync as readdirSync18, rmSync as rmSync17 } from "node:fs";
|
|
@@ -243949,8 +244572,8 @@ function dispose(session3, error4) {
|
|
|
243949
244572
|
if (session3.stopping)
|
|
243950
244573
|
return session3.stopping;
|
|
243951
244574
|
clearTimeout(session3.idleTimer);
|
|
243952
|
-
if (
|
|
243953
|
-
|
|
244575
|
+
if (sessions5.get(session3.id) === session3)
|
|
244576
|
+
sessions5.delete(session3.id);
|
|
243954
244577
|
session3.stopping = session3.server.close().then(() => {
|
|
243955
244578
|
if (session3.active)
|
|
243956
244579
|
finish(session3, session3.active, {
|
|
@@ -244033,7 +244656,7 @@ async function createSession2(options, env6) {
|
|
|
244033
244656
|
lock: Promise.resolve()
|
|
244034
244657
|
};
|
|
244035
244658
|
const stream11 = await server2.events((event) => onEvent(session3, event));
|
|
244036
|
-
|
|
244659
|
+
sessions5.set(session3.id, session3);
|
|
244037
244660
|
stream11.completion.catch((error4) => dispose(session3, message(error4)));
|
|
244038
244661
|
return session3;
|
|
244039
244662
|
} catch (error4) {
|
|
@@ -244047,7 +244670,7 @@ async function getSession(options, env6) {
|
|
|
244047
244670
|
const id = options.resumeSessionId;
|
|
244048
244671
|
if (!id)
|
|
244049
244672
|
return createSession2(options, env6);
|
|
244050
|
-
const loaded =
|
|
244673
|
+
const loaded = sessions5.get(id);
|
|
244051
244674
|
if (loaded)
|
|
244052
244675
|
return loaded;
|
|
244053
244676
|
const pending2 = creations.get(id);
|
|
@@ -244166,11 +244789,11 @@ async function sendOpenCodeMessage(options, env6 = process.env) {
|
|
|
244166
244789
|
};
|
|
244167
244790
|
});
|
|
244168
244791
|
}
|
|
244169
|
-
var
|
|
244792
|
+
var sessions5, creations;
|
|
244170
244793
|
var init_opencode_session = __esm(() => {
|
|
244171
244794
|
init_subagent_depth();
|
|
244172
244795
|
init_opencode_server();
|
|
244173
|
-
|
|
244796
|
+
sessions5 = new Map;
|
|
244174
244797
|
creations = new Map;
|
|
244175
244798
|
});
|
|
244176
244799
|
|
|
@@ -244345,7 +244968,7 @@ async function defaultRunPreflight(executable, args, env6, signal) {
|
|
|
244345
244968
|
function classifyExternalCodingAgentStartupError(error4) {
|
|
244346
244969
|
if (error4.startsWith(MISSING_EXECUTABLE_PREFIX) || error4.startsWith(CODEX_NOT_READY_PREFIX))
|
|
244347
244970
|
return "not_installed";
|
|
244348
|
-
if (error4.startsWith(CLAUDE_NOT_SIGNED_IN_PREFIX) || error4.startsWith(CODEX_NOT_SIGNED_IN_ERROR) || error4.startsWith("Cursor is not signed in:"))
|
|
244971
|
+
if (error4.startsWith(CLAUDE_NOT_SIGNED_IN_PREFIX) || error4.startsWith(CODEX_NOT_SIGNED_IN_ERROR) || error4.startsWith("Cursor is not signed in:") || error4.startsWith("Antigravity is not signed in:"))
|
|
244349
244972
|
return "not_signed_in";
|
|
244350
244973
|
return;
|
|
244351
244974
|
}
|
|
@@ -244473,12 +245096,16 @@ function scrubWorkerListeners(listeners6, secretEnv) {
|
|
|
244473
245096
|
async function runExternalCodingAgent(options, deps = {}) {
|
|
244474
245097
|
const startedAt = Date.now();
|
|
244475
245098
|
const { env: env6, secretEnv, mcpReminder } = await buildExternalWorkerLaunchEnv(options, deps);
|
|
245099
|
+
if (options.type === "antigravity" && env6.GEMINI_API_KEY)
|
|
245100
|
+
secretEnv.GEMINI_API_KEY = env6.GEMINI_API_KEY;
|
|
244476
245101
|
options = {
|
|
244477
245102
|
...options,
|
|
244478
245103
|
...scrubWorkerListeners(options, secretEnv),
|
|
244479
245104
|
mcpReminder
|
|
244480
245105
|
};
|
|
244481
245106
|
const cwd2 = options.cwd ?? getCurrentWorkingDirectory();
|
|
245107
|
+
if (options.type === "antigravity")
|
|
245108
|
+
return runAntigravityTurn({ ...options, cwd: cwd2 }, env6, secretEnv);
|
|
244482
245109
|
const captureActingUserId = options.actingUserId !== undefined ? options.actingUserId : getRuntimeActingUserAttribution();
|
|
244483
245110
|
const scope = options.parentConversationId ? {
|
|
244484
245111
|
agentId: options.parentAgentId,
|
|
@@ -244553,7 +245180,8 @@ async function runExternalCodingAgent(options, deps = {}) {
|
|
|
244553
245180
|
secretValues: Object.values(secretEnv),
|
|
244554
245181
|
parent_agent_id: scope.agentId,
|
|
244555
245182
|
parent_conversation_id: scope.conversationId,
|
|
244556
|
-
task_id: options.taskId ?? randomUUID44()
|
|
245183
|
+
task_id: options.taskId ?? randomUUID44(),
|
|
245184
|
+
task_description: options.description
|
|
244557
245185
|
} : undefined,
|
|
244558
245186
|
prompt: options.prompt,
|
|
244559
245187
|
parentAgentId: options.parentAgentId,
|
|
@@ -244607,7 +245235,8 @@ async function runExternalCodingAgent(options, deps = {}) {
|
|
|
244607
245235
|
secretValues: Object.values(secretEnv),
|
|
244608
245236
|
parent_agent_id: scope.agentId,
|
|
244609
245237
|
parent_conversation_id: scope.conversationId,
|
|
244610
|
-
task_id: options.taskId ?? randomUUID44()
|
|
245238
|
+
task_id: options.taskId ?? randomUUID44(),
|
|
245239
|
+
task_description: options.description
|
|
244611
245240
|
} : undefined,
|
|
244612
245241
|
prompt: options.prompt,
|
|
244613
245242
|
parentAgentId: options.parentAgentId,
|
|
@@ -244668,18 +245297,21 @@ var init_external_coding_agent = __esm(() => {
|
|
|
244668
245297
|
init_secret_substitution();
|
|
244669
245298
|
init_debug();
|
|
244670
245299
|
init_native_cli_env();
|
|
245300
|
+
init_antigravity_session();
|
|
244671
245301
|
init_claude_stream_session();
|
|
244672
245302
|
init_codex_app_server();
|
|
244673
245303
|
init_cursor_session();
|
|
244674
245304
|
init_native_session_capture();
|
|
244675
245305
|
init_opencode_session();
|
|
244676
245306
|
EXTERNAL_CODING_AGENT_TYPES = [
|
|
245307
|
+
"antigravity",
|
|
244677
245308
|
"claude-code",
|
|
244678
245309
|
"codex",
|
|
244679
245310
|
"opencode",
|
|
244680
245311
|
"cursor"
|
|
244681
245312
|
];
|
|
244682
245313
|
EXTERNAL_AGENT_ID_PREFIXES = {
|
|
245314
|
+
antigravity: "antigravity_",
|
|
244683
245315
|
"claude-code": "claude_",
|
|
244684
245316
|
codex: "codex_",
|
|
244685
245317
|
opencode: "opencode_",
|
|
@@ -244695,15 +245327,8 @@ function deadlineFor(timeoutMs) {
|
|
|
244695
245327
|
function deadlineReached(deadline) {
|
|
244696
245328
|
return deadline !== null && Date.now() >= deadline;
|
|
244697
245329
|
}
|
|
244698
|
-
|
|
244699
|
-
|
|
244700
|
-
while (!signal?.aborted) {
|
|
244701
|
-
const agent = getSnapshot2().agents.find((entry) => entry.id === subagentId);
|
|
244702
|
-
if (!agent || agent.agentURL || agent.conversationId || agent.status === "error" || agent.status === "completed" || deadlineReached(deadline)) {
|
|
244703
|
-
return;
|
|
244704
|
-
}
|
|
244705
|
-
await sleep9(BACKGROUND_STARTUP_POLL_MS);
|
|
244706
|
-
}
|
|
245330
|
+
function waitForBackgroundSubagentLink(subagentId, timeoutMs = null, signal) {
|
|
245331
|
+
return waitForBackgroundSubagentConversationId(subagentId, timeoutMs, signal);
|
|
244707
245332
|
}
|
|
244708
245333
|
async function waitForBackgroundSubagentAgentId(subagentId, timeoutMs = null, signal) {
|
|
244709
245334
|
const deadline = deadlineFor(timeoutMs);
|
|
@@ -245564,6 +246189,7 @@ async function executeSubagent(type, config2, model2, userPrompt, subagentId, is
|
|
|
245564
246189
|
actingUserId: actingUserIdOverride,
|
|
245565
246190
|
transcriptPath,
|
|
245566
246191
|
subagentId,
|
|
246192
|
+
subagentSummary: existingAgentId || existingConversationId ? undefined : getSubagents().find((agent) => agent.id === subagentId)?.description,
|
|
245567
246193
|
subagentName: existingAgentId || existingConversationId ? undefined : allocateSubagentName(parentAgentName)
|
|
245568
246194
|
});
|
|
245569
246195
|
delete childEnv[SUBAGENT_CLOUD_OPTIONS_ENV];
|
|
@@ -245882,7 +246508,7 @@ async function fetchParentConversationMessages(params) {
|
|
|
245882
246508
|
}
|
|
245883
246509
|
return messages.reverse();
|
|
245884
246510
|
}
|
|
245885
|
-
function
|
|
246511
|
+
function contentText2(content) {
|
|
245886
246512
|
if (typeof content === "string")
|
|
245887
246513
|
return content;
|
|
245888
246514
|
if (!Array.isArray(content))
|
|
@@ -245908,7 +246534,7 @@ function renderToolCall(call) {
|
|
|
245908
246534
|
}
|
|
245909
246535
|
function renderToolResult(result3) {
|
|
245910
246536
|
const raw2 = result3.tool_return ?? result3.func_response;
|
|
245911
|
-
const text2 = typeof raw2 === "string" ? raw2 :
|
|
246537
|
+
const text2 = typeof raw2 === "string" ? raw2 : contentText2(raw2) || (raw2 == null ? "" : JSON.stringify(raw2));
|
|
245912
246538
|
return {
|
|
245913
246539
|
type: "tool_result",
|
|
245914
246540
|
call_id: result3.tool_call_id ?? undefined,
|
|
@@ -245944,11 +246570,11 @@ function userEvents(text2, speaker) {
|
|
|
245944
246570
|
function renderMessage(message2) {
|
|
245945
246571
|
switch (message2.message_type) {
|
|
245946
246572
|
case "user_message": {
|
|
245947
|
-
const text2 =
|
|
246573
|
+
const text2 = contentText2(message2.content).replace(SYSTEM_REMINDER_PATTERN, "").trim();
|
|
245948
246574
|
return userEvents(text2, message2.name ?? undefined);
|
|
245949
246575
|
}
|
|
245950
246576
|
case "assistant_message": {
|
|
245951
|
-
const text2 =
|
|
246577
|
+
const text2 = contentText2(message2.content).trim();
|
|
245952
246578
|
return text2 ? [
|
|
245953
246579
|
{
|
|
245954
246580
|
type: "message",
|
|
@@ -246664,23 +247290,29 @@ var init_remote_connect_retry = __esm(() => {
|
|
|
246664
247290
|
async function resolveExternalWorkerComputer(computer, scope, cloudOptions) {
|
|
246665
247291
|
if (!isCloudEnvironmentSelector(computer))
|
|
246666
247292
|
return resolveEnvironmentConnectionId(computer);
|
|
246667
|
-
const client = await getClient();
|
|
246668
247293
|
const parentConversationId = scope.conversationId && scope.conversationId !== "default" ? scope.conversationId : undefined;
|
|
246669
247294
|
const createParams = {
|
|
246670
247295
|
agent_id: scope.agentId,
|
|
246671
247296
|
hidden: true,
|
|
246672
247297
|
...parentConversationId ? { parent_conversation_id: parentConversationId } : {}
|
|
246673
247298
|
};
|
|
246674
|
-
|
|
246675
|
-
|
|
246676
|
-
|
|
246677
|
-
|
|
246678
|
-
|
|
246679
|
-
|
|
246680
|
-
|
|
247299
|
+
let conversationId;
|
|
247300
|
+
try {
|
|
247301
|
+
const client = await getClient();
|
|
247302
|
+
const conversation = await client.conversations.create(createParams).catch((error4) => {
|
|
247303
|
+
if (!parentConversationId || !error4 || typeof error4 !== "object" || !("status" in error4) || error4.status !== 403) {
|
|
247304
|
+
throw error4;
|
|
247305
|
+
}
|
|
247306
|
+
const fallbackParams = { agent_id: scope.agentId, hidden: true };
|
|
247307
|
+
return client.conversations.create(fallbackParams);
|
|
247308
|
+
});
|
|
247309
|
+
conversationId = conversation.id;
|
|
247310
|
+
} catch (error4) {
|
|
247311
|
+
throw new ComputerResolutionError("cloud_conversation_create_failed", error4 instanceof Error ? error4.message : String(error4), error4);
|
|
247312
|
+
}
|
|
246681
247313
|
return resolveAgentSandboxConnectionId(scope.agentId, {
|
|
246682
247314
|
...cloudOptions,
|
|
246683
|
-
conversationId
|
|
247315
|
+
conversationId
|
|
246684
247316
|
});
|
|
246685
247317
|
}
|
|
246686
247318
|
var init_remote_external_worker_computer = __esm(() => {
|
|
@@ -246813,32 +247445,35 @@ async function defaultConnect(connectionId, scope) {
|
|
|
246813
247445
|
throw error4;
|
|
246814
247446
|
}
|
|
246815
247447
|
}
|
|
246816
|
-
async function resolveQualifiedComputer(deviceId, scope) {
|
|
247448
|
+
async function resolveQualifiedComputer(deviceId, scope, resumeOnly = false) {
|
|
247449
|
+
const prefix = `sandbox-${scope.agentId}-`;
|
|
247450
|
+
const suffix = deviceId.startsWith(prefix) ? deviceId.slice(prefix.length).match(/^(conv-[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})-linux-vm$/i) : null;
|
|
246817
247451
|
let environment;
|
|
246818
247452
|
try {
|
|
246819
247453
|
environment = await getEnvironmentConnection(deviceId);
|
|
246820
|
-
} catch {
|
|
246821
|
-
|
|
246822
|
-
|
|
246823
|
-
|
|
246824
|
-
|
|
246825
|
-
|
|
246826
|
-
|
|
246827
|
-
|
|
246828
|
-
|
|
246829
|
-
|
|
246830
|
-
|
|
246831
|
-
|
|
246832
|
-
|
|
246833
|
-
|
|
246834
|
-
throw new Error(`Computer "${deviceId}" is offline`);
|
|
247454
|
+
} catch (error4) {
|
|
247455
|
+
if (!(resumeOnly && suffix && error4 instanceof ApiRequestError && error4.status === 404))
|
|
247456
|
+
return resolveEnvironmentConnectionId(deviceId);
|
|
247457
|
+
}
|
|
247458
|
+
if (environment && isEnvironmentOnline(environment) && environment.connectionId)
|
|
247459
|
+
return { connectionId: environment.connectionId, environment };
|
|
247460
|
+
if (suffix && (!environment || environment.deviceId === deviceId)) {
|
|
247461
|
+
const resolved = await resolveAgentSandboxConnectionId(scope.agentId, {
|
|
247462
|
+
conversationId: suffix[1],
|
|
247463
|
+
resumeOnly
|
|
247464
|
+
});
|
|
247465
|
+
if (resolved.environment.deviceId !== deviceId)
|
|
247466
|
+
throw new Error("Cloud sandbox device changed while waking worker");
|
|
247467
|
+
return resolved;
|
|
246835
247468
|
}
|
|
246836
|
-
|
|
247469
|
+
throw new Error(`Computer "${deviceId}" is offline`);
|
|
246837
247470
|
}
|
|
246838
247471
|
function errorMessage5(error4) {
|
|
246839
247472
|
return error4 instanceof Error ? error4.message : String(error4);
|
|
246840
247473
|
}
|
|
246841
247474
|
function classifyRemoteExternalWorkerControlError(error4) {
|
|
247475
|
+
if (error4 instanceof WorkerSandboxExpiredError)
|
|
247476
|
+
return "sandbox_expired";
|
|
246842
247477
|
if (error4 instanceof ComputerResolutionError) {
|
|
246843
247478
|
return error4.code === "computer_offline" || error4.code === "computer_not_found" ? error4.code : "other";
|
|
246844
247479
|
}
|
|
@@ -247042,13 +247677,14 @@ class RemoteSubagentFollower {
|
|
|
247042
247677
|
}
|
|
247043
247678
|
async function launchRemoteExternalCodingAgent(params, deps) {
|
|
247044
247679
|
const { type, computer, parentScope } = params;
|
|
247045
|
-
const fail2 = (stage, error4, errorCode) => {
|
|
247680
|
+
const fail2 = (stage, error4, errorCode, httpStatus) => {
|
|
247046
247681
|
reportExternalWorkerLaunchFailure({
|
|
247047
247682
|
stage,
|
|
247048
247683
|
harness: type,
|
|
247049
247684
|
computer: stage === "resolve_computer" ? undefined : computer,
|
|
247050
247685
|
error: error4,
|
|
247051
247686
|
errorCode,
|
|
247687
|
+
httpStatus,
|
|
247052
247688
|
agentId: parentScope.agentId,
|
|
247053
247689
|
conversationId: parentScope.conversationId,
|
|
247054
247690
|
toolCallId: params.toolCallId
|
|
@@ -247077,7 +247713,8 @@ async function launchRemoteExternalCodingAgent(params, deps) {
|
|
|
247077
247713
|
if (outdated)
|
|
247078
247714
|
return fail2("outdated_computer", outdated);
|
|
247079
247715
|
} catch (error4) {
|
|
247080
|
-
|
|
247716
|
+
const resolutionError = error4 instanceof ComputerResolutionError ? error4 : undefined;
|
|
247717
|
+
return fail2("resolve_computer", errorMessage5(error4), resolutionError?.code, resolutionError ? resolutionError.httpStatus ?? null : undefined);
|
|
247081
247718
|
}
|
|
247082
247719
|
params.signal?.throwIfAborted();
|
|
247083
247720
|
const connect = () => (deps.connect ?? defaultConnect)(connectionId, parentScope);
|
|
@@ -247211,17 +247848,17 @@ async function launchRemoteExternalCodingAgent(params, deps) {
|
|
|
247211
247848
|
conversation_id: null
|
|
247212
247849
|
};
|
|
247213
247850
|
}
|
|
247214
|
-
async function connectQualifiedTarget(agentId, parentScope, deps) {
|
|
247851
|
+
async function connectQualifiedTarget(agentId, parentScope, deps, resumeOnly = false) {
|
|
247215
247852
|
const target = parseExternalCodingAgentId(agentId);
|
|
247216
247853
|
if (!target?.computer || target.type === "opencode")
|
|
247217
247854
|
throw new Error(`Invalid remote external coding agent ID: ${agentId}`);
|
|
247218
|
-
const resolved = await (deps.resolveComputer ?? resolveQualifiedComputer)(target.computer, parentScope);
|
|
247855
|
+
const resolved = await (deps.resolveComputer ?? resolveQualifiedComputer)(target.computer, parentScope, resumeOnly);
|
|
247219
247856
|
if (resolved.environment.metadata?.subagent_message !== true)
|
|
247220
247857
|
throw new Error(formatOutdatedSteeringError(target.computer));
|
|
247221
247858
|
return {
|
|
247222
247859
|
target,
|
|
247223
247860
|
lettaCodeVersion: resolved.environment.metadata?.lettaCodeVersion,
|
|
247224
|
-
client: await (deps.connect ?? defaultConnect)(resolved.connectionId, parentScope)
|
|
247861
|
+
client: await connectRemoteWorkerWithRetry(() => (deps.connect ?? defaultConnect)(resolved.connectionId, parentScope))
|
|
247225
247862
|
};
|
|
247226
247863
|
}
|
|
247227
247864
|
async function stopRemoteExternalCodingAgent(params, deps = {}) {
|
|
@@ -247250,6 +247887,8 @@ async function sendRemoteExternalCodingAgentMessage(params, deps = {}) {
|
|
|
247250
247887
|
try {
|
|
247251
247888
|
return await deliverRemoteExternalCodingAgentMessage(params, deps);
|
|
247252
247889
|
} catch (error4) {
|
|
247890
|
+
if (error4 instanceof WorkerSandboxExpiredError)
|
|
247891
|
+
throw error4;
|
|
247253
247892
|
const target = parseExternalCodingAgentId(params.agentId);
|
|
247254
247893
|
reportExternalWorkerLaunchFailure({
|
|
247255
247894
|
stage: error4 instanceof OutdatedRemoteWorkerError ? "outdated_computer" : "follow_up",
|
|
@@ -247266,10 +247905,10 @@ async function sendRemoteExternalCodingAgentMessage(params, deps = {}) {
|
|
|
247266
247905
|
}
|
|
247267
247906
|
async function deliverRemoteExternalCodingAgentMessage(params, deps) {
|
|
247268
247907
|
const requestId = `subagent-message-${randomUUID47()}`;
|
|
247269
|
-
const { target, client, lettaCodeVersion } = await connectQualifiedTarget(params.agentId, params.parentScope, deps);
|
|
247908
|
+
const { target, client, lettaCodeVersion } = await connectQualifiedTarget(params.agentId, params.parentScope, deps, true);
|
|
247270
247909
|
const toolCallId = params.toolCallId ?? `remote-followup-${randomUUID47()}`;
|
|
247271
247910
|
const connect = async () => {
|
|
247272
|
-
const resolved = await (deps.resolveComputer ?? resolveQualifiedComputer)(target.computer, params.parentScope);
|
|
247911
|
+
const resolved = await (deps.resolveComputer ?? resolveQualifiedComputer)(target.computer, params.parentScope, true);
|
|
247273
247912
|
return (deps.connect ?? defaultConnect)(resolved.connectionId, params.parentScope);
|
|
247274
247913
|
};
|
|
247275
247914
|
const follower = new RemoteSubagentFollower(params.parentScope, toolCallId, connect, 2000);
|
|
@@ -247378,6 +248017,7 @@ var init_remote_external_coding_agent = __esm(() => {
|
|
|
247378
248017
|
init_remote_subagent_events();
|
|
247379
248018
|
REMOTE_EXTERNAL_WORKER_STOPPED = Symbol("remote external worker stopped");
|
|
247380
248019
|
DISPLAY_NAMES = {
|
|
248020
|
+
antigravity: "Antigravity",
|
|
247381
248021
|
"claude-code": "Claude Code",
|
|
247382
248022
|
codex: "Codex",
|
|
247383
248023
|
opencode: "OpenCode",
|
|
@@ -247575,6 +248215,7 @@ async function task_stop(args, deps = {}) {
|
|
|
247575
248215
|
return finishPendingWakeCancellation(task);
|
|
247576
248216
|
if (task.status === "running" && task.abortController) {
|
|
247577
248217
|
const initialStop = task.stop;
|
|
248218
|
+
const markStopped = captureSubagentStop(task.subagentId);
|
|
247578
248219
|
const child = getSubagents().find((agent) => agent.id === task.subagentId);
|
|
247579
248220
|
const external3 = parseExternalCodingAgentId(child?.agentId ?? undefined);
|
|
247580
248221
|
let remote;
|
|
@@ -247642,6 +248283,7 @@ async function task_stop(args, deps = {}) {
|
|
|
247642
248283
|
if (!remoteExternalStopped)
|
|
247643
248284
|
throw new Error("Subagent process exit was not confirmed");
|
|
247644
248285
|
task.status = "failed";
|
|
248286
|
+
markStopped();
|
|
247645
248287
|
scheduleBackgroundTaskCleanup(task_id);
|
|
247646
248288
|
return {
|
|
247647
248289
|
killed: true,
|
|
@@ -247671,6 +248313,7 @@ async function task_stop(args, deps = {}) {
|
|
|
247671
248313
|
}
|
|
247672
248314
|
task.status = "failed";
|
|
247673
248315
|
scheduleBackgroundTaskCleanup(task_id);
|
|
248316
|
+
markStopped();
|
|
247674
248317
|
task.cancelPendingWakes = () => runWithRuntimeContext({
|
|
247675
248318
|
...scope,
|
|
247676
248319
|
actingUserId: task.actingUserId ?? undefined,
|
|
@@ -247683,6 +248326,7 @@ async function task_stop(args, deps = {}) {
|
|
|
247683
248326
|
}
|
|
247684
248327
|
task.status = "failed";
|
|
247685
248328
|
scheduleBackgroundTaskCleanup(task_id);
|
|
248329
|
+
markStopped();
|
|
247686
248330
|
return remote ?? { killed: true };
|
|
247687
248331
|
}
|
|
247688
248332
|
return { killed: false };
|
|
@@ -247881,7 +248525,14 @@ var init_Task2 = __esm(() => {
|
|
|
247881
248525
|
},
|
|
247882
248526
|
harness: {
|
|
247883
248527
|
type: "string",
|
|
247884
|
-
enum: [
|
|
248528
|
+
enum: [
|
|
248529
|
+
"letta",
|
|
248530
|
+
"claude-code",
|
|
248531
|
+
"codex",
|
|
248532
|
+
"cursor",
|
|
248533
|
+
"opencode",
|
|
248534
|
+
"antigravity"
|
|
248535
|
+
],
|
|
247885
248536
|
description: "The harness that executes the task. Defaults to letta (a Letta subagent). Set to override the harness that runs the subagent worker (requires the harness to be installed on the computer)."
|
|
247886
248537
|
},
|
|
247887
248538
|
subagent_type: {
|
|
@@ -248118,6 +248769,8 @@ function spawnBackgroundSubagentTask(args) {
|
|
|
248118
248769
|
openTaskProgressLog(subagentId, outputFile, resolvedParentScope?.agentId);
|
|
248119
248770
|
if (publishResult)
|
|
248120
248771
|
serveTaskEvents(subagentId);
|
|
248772
|
+
if (args.observePersistedState)
|
|
248773
|
+
observeSubagentState(subagentId, args.observePersistedState());
|
|
248121
248774
|
const parentAgentIdForSpawn = resolvedParentScope?.agentId;
|
|
248122
248775
|
const workerMemoryDir = subagentType === "memory" && resolvedParentScope ? memoryScope?.primaryRoot ?? getScopedMemoryFilesystemRoot(resolvedParentScope.agentId) : undefined;
|
|
248123
248776
|
const effectiveMemoryScope = memoryScope ?? (workerMemoryDir ? { primaryRoot: workerMemoryDir, writableRoots: [workerMemoryDir] } : undefined);
|
|
@@ -248158,7 +248811,10 @@ function spawnBackgroundSubagentTask(args) {
|
|
|
248158
248811
|
...publishResult && result3.success ? {
|
|
248159
248812
|
result: truncateByChars(result3.report || "", LIMITS.TASK_OUTPUT_CHARS, "Task", { workingDirectory: getCurrentWorkingDirectory() }).content
|
|
248160
248813
|
} : {}
|
|
248161
|
-
}
|
|
248814
|
+
}, args.observePersistedState ? {
|
|
248815
|
+
agentId: result3.agentId || existingAgentId,
|
|
248816
|
+
conversationId: result3.conversationId || existingConversationId
|
|
248817
|
+
} : undefined);
|
|
248162
248818
|
try {
|
|
248163
248819
|
await onComplete?.({
|
|
248164
248820
|
success: result3.success,
|
|
@@ -248352,9 +249008,10 @@ async function launchSubagent(args, cloudSkillRepositories) {
|
|
|
248352
249008
|
if (resolvedComputer.error) {
|
|
248353
249009
|
return { success: false, error: resolvedComputer.error };
|
|
248354
249010
|
}
|
|
248355
|
-
const cloud = parseTaskCloudOptions(
|
|
249011
|
+
const cloud = parseTaskCloudOptions(resolvedComputer.computer, args.cloud);
|
|
248356
249012
|
if ("error" in cloud)
|
|
248357
249013
|
return { success: false, error: cloud.error };
|
|
249014
|
+
const observePersistedState = args.notifyCaller ? undefined : createLaunchSubagentObserver(resolvedParentScope, args, description, inputPrompt, externalCodingAgentType ?? "letta", Boolean(config2.fork), resolvedComputer.computer, cloud.options);
|
|
248358
249015
|
let effectiveAgentId = args.agent_id;
|
|
248359
249016
|
let effectiveConversationId = args.conversation_id;
|
|
248360
249017
|
const callerNotification = args.notifyCaller ? {
|
|
@@ -248387,7 +249044,9 @@ async function launchSubagent(args, cloudSkillRepositories) {
|
|
|
248387
249044
|
agentId: parentAgentId
|
|
248388
249045
|
},
|
|
248389
249046
|
signal
|
|
248390
|
-
}, {
|
|
249047
|
+
}, {
|
|
249048
|
+
spawn: (task) => spawnBackgroundSubagentTask({ ...task, observePersistedState })
|
|
249049
|
+
});
|
|
248391
249050
|
}
|
|
248392
249051
|
const worker = await prepareExternalWorkerPrompt({
|
|
248393
249052
|
prompt: inputPrompt,
|
|
@@ -248410,6 +249069,7 @@ async function launchSubagent(args, cloudSkillRepositories) {
|
|
|
248410
249069
|
const { taskId: taskId2, outputFile: outputFile2, subagentId: subagentId2 } = spawnBackgroundSubagentTask({
|
|
248411
249070
|
subagentType: configName,
|
|
248412
249071
|
config: config2,
|
|
249072
|
+
observePersistedState,
|
|
248413
249073
|
prompt: worker.prompt,
|
|
248414
249074
|
description,
|
|
248415
249075
|
model: model2,
|
|
@@ -248512,6 +249172,7 @@ async function launchSubagent(args, cloudSkillRepositories) {
|
|
|
248512
249172
|
description,
|
|
248513
249173
|
model: model2,
|
|
248514
249174
|
toolCallId,
|
|
249175
|
+
observePersistedState,
|
|
248515
249176
|
existingAgentId: effectiveAgentId,
|
|
248516
249177
|
existingConversationId: effectiveConversationId,
|
|
248517
249178
|
maxTurns: args.max_turns,
|
|
@@ -248524,10 +249185,11 @@ async function launchSubagent(args, cloudSkillRepositories) {
|
|
|
248524
249185
|
});
|
|
248525
249186
|
const abortStartup = () => backgroundTasks.get(taskId)?.abortController?.abort(signal?.reason);
|
|
248526
249187
|
signal?.addEventListener("abort", abortStartup, { once: true });
|
|
249188
|
+
let linkedConversationId;
|
|
248527
249189
|
try {
|
|
248528
249190
|
if (signal?.aborted)
|
|
248529
249191
|
abortStartup();
|
|
248530
|
-
await waitForBackgroundSubagentLink(subagentId, null, signal);
|
|
249192
|
+
linkedConversationId = await waitForBackgroundSubagentLink(subagentId, null, signal);
|
|
248531
249193
|
signal?.throwIfAborted();
|
|
248532
249194
|
} finally {
|
|
248533
249195
|
signal?.removeEventListener("abort", abortStartup);
|
|
@@ -248539,7 +249201,7 @@ async function launchSubagent(args, cloudSkillRepositories) {
|
|
|
248539
249201
|
error: backgroundTasks.get(taskId)?.error ?? "Subagent launch failed"
|
|
248540
249202
|
};
|
|
248541
249203
|
}
|
|
248542
|
-
const conversationId = linkedAgent?.conversationId ?? effectiveConversationId ?? null;
|
|
249204
|
+
const conversationId = linkedConversationId ?? linkedAgent?.conversationId ?? effectiveConversationId ?? null;
|
|
248543
249205
|
if (!isDeployingExisting)
|
|
248544
249206
|
recordTaskSummary(conversationId, description);
|
|
248545
249207
|
return {
|
|
@@ -248596,6 +249258,7 @@ var init_task = __esm(() => {
|
|
|
248596
249258
|
init_process_manager();
|
|
248597
249259
|
init_remote_external_coding_agent();
|
|
248598
249260
|
init_subagent_computer();
|
|
249261
|
+
init_subagent_persistence();
|
|
248599
249262
|
init_task_abort_hook();
|
|
248600
249263
|
init_task_agent_selection();
|
|
248601
249264
|
init_task_cloud_options();
|
|
@@ -248608,6 +249271,15 @@ var init_task = __esm(() => {
|
|
|
248608
249271
|
// src/tools/impl/external-coding-agent-task.ts
|
|
248609
249272
|
function trackExternalFollowupCompletion(args) {
|
|
248610
249273
|
return spawnBackgroundSubagentTask({
|
|
249274
|
+
observePersistedState: args.publishResult ? undefined : () => {
|
|
249275
|
+
const writer = resumeSubagentWriter(args.parentScope.conversationId, { worker_session_id: args.agentId }, args.parentScope.actingUserId === undefined ? getRuntimeActingUserAttribution() : args.parentScope.actingUserId);
|
|
249276
|
+
let stopped = false;
|
|
249277
|
+
return (state2) => {
|
|
249278
|
+
const status = stopped ? "stopped" : persistedSubagentStatus(state2);
|
|
249279
|
+
stopped = status === "stopped";
|
|
249280
|
+
writer?.update({ status, worker_session_id: args.agentId });
|
|
249281
|
+
};
|
|
249282
|
+
},
|
|
248611
249283
|
taskId: args.taskId,
|
|
248612
249284
|
subagentType: args.type,
|
|
248613
249285
|
config: createExternalCodingAgentConfig(args.type),
|
|
@@ -248662,10 +249334,12 @@ function trackExternalFollowupCompletion(args) {
|
|
|
248662
249334
|
});
|
|
248663
249335
|
}
|
|
248664
249336
|
var init_external_coding_agent_task = __esm(() => {
|
|
249337
|
+
init_subagents3();
|
|
248665
249338
|
init_runtime_context();
|
|
248666
249339
|
init_external_coding_agent();
|
|
248667
249340
|
init_native_session_capture();
|
|
248668
249341
|
init_process_manager();
|
|
249342
|
+
init_subagent_persistence();
|
|
248669
249343
|
init_task();
|
|
248670
249344
|
init_task_transcript();
|
|
248671
249345
|
});
|
|
@@ -248754,6 +249428,8 @@ async function send_agent_message(args, deps = {}) {
|
|
|
248754
249428
|
}
|
|
248755
249429
|
args.signal?.throwIfAborted();
|
|
248756
249430
|
const parentScope = sender;
|
|
249431
|
+
const steerActingUserId = getRuntimeActingUserAttribution();
|
|
249432
|
+
const recordSteer = () => resumeSubagentWriter(parentScope.conversationId, { worker_session_id: args.agent_id }, steerActingUserId);
|
|
248757
249433
|
if (externalTarget.computer) {
|
|
248758
249434
|
const receipt3 = await (deps.sendRemoteExternalMessage ?? sendRemoteExternalCodingAgentMessage)({
|
|
248759
249435
|
agentId: args.agent_id,
|
|
@@ -248765,6 +249441,8 @@ async function send_agent_message(args, deps = {}) {
|
|
|
248765
249441
|
}, {
|
|
248766
249442
|
track: deps.trackExternalFollowup ?? trackExternalFollowupCompletion
|
|
248767
249443
|
});
|
|
249444
|
+
if (receipt3.delivery !== "resumed")
|
|
249445
|
+
recordSteer();
|
|
248768
249446
|
return {
|
|
248769
249447
|
content: JSON.stringify({
|
|
248770
249448
|
status: "accepted",
|
|
@@ -248777,7 +249455,7 @@ async function send_agent_message(args, deps = {}) {
|
|
|
248777
249455
|
status: "success"
|
|
248778
249456
|
};
|
|
248779
249457
|
}
|
|
248780
|
-
if (externalTarget.type === "opencode" || externalTarget.type === "cursor") {
|
|
249458
|
+
if (externalTarget.type === "antigravity" || externalTarget.type === "opencode" || externalTarget.type === "cursor") {
|
|
248781
249459
|
const messageOptions = {
|
|
248782
249460
|
sessionId: externalTarget.sessionId,
|
|
248783
249461
|
prompt: args.message,
|
|
@@ -248786,13 +249464,22 @@ async function send_agent_message(args, deps = {}) {
|
|
|
248786
249464
|
signal: args.signal
|
|
248787
249465
|
};
|
|
248788
249466
|
const secrets2 = externalTarget.type === "cursor" ? await resolveExternalCodingAgentSecretEnv(parentScope.agentId) : {};
|
|
248789
|
-
const
|
|
249467
|
+
const worker2 = externalTarget.type === "antigravity" ? await buildExternalWorkerResumeEnv({
|
|
249468
|
+
parentAgentId: parentScope.agentId,
|
|
249469
|
+
actingUserId: getRuntimeActingUserAttribution()
|
|
249470
|
+
}, deps.workerEnv) : undefined;
|
|
249471
|
+
const receipt3 = worker2 ? sendAntigravityMessage({
|
|
249472
|
+
...messageOptions,
|
|
249473
|
+
resumeSessionId: externalTarget.sessionId,
|
|
249474
|
+
mcpReminder: worker2.mcpReminder
|
|
249475
|
+
}, worker2.env, worker2.secretEnv) : externalTarget.type === "cursor" ? await sendCursorMessage(messageOptions, { ...process.env, ...secrets2 }, secrets2) : await sendOpenCodeMessage(messageOptions);
|
|
248790
249476
|
if (receipt3.mode === "steered") {
|
|
249477
|
+
recordSteer();
|
|
248791
249478
|
return {
|
|
248792
249479
|
content: JSON.stringify({
|
|
248793
249480
|
status: "accepted",
|
|
248794
249481
|
agent_id: args.agent_id,
|
|
248795
|
-
delivery: externalTarget.type === "cursor" ? "run/steer" : "session/abort+prompt"
|
|
249482
|
+
delivery: externalTarget.type === "antigravity" ? "queued" : externalTarget.type === "cursor" ? "run/steer" : "session/abort+prompt"
|
|
248796
249483
|
}),
|
|
248797
249484
|
status: "success"
|
|
248798
249485
|
};
|
|
@@ -248861,6 +249548,7 @@ async function send_agent_message(args, deps = {}) {
|
|
|
248861
249548
|
throw error4;
|
|
248862
249549
|
}
|
|
248863
249550
|
if (receipt3.mode === "steered") {
|
|
249551
|
+
recordSteer();
|
|
248864
249552
|
return {
|
|
248865
249553
|
content: JSON.stringify({
|
|
248866
249554
|
status: "accepted",
|
|
@@ -248932,6 +249620,7 @@ async function send_agent_message(args, deps = {}) {
|
|
|
248932
249620
|
throw error4;
|
|
248933
249621
|
}
|
|
248934
249622
|
if (receipt2.mode === "steered") {
|
|
249623
|
+
recordSteer();
|
|
248935
249624
|
return {
|
|
248936
249625
|
content: JSON.stringify({
|
|
248937
249626
|
status: "accepted",
|
|
@@ -249025,16 +249714,20 @@ async function send_agent_message(args, deps = {}) {
|
|
|
249025
249714
|
actingUserId
|
|
249026
249715
|
}, signal);
|
|
249027
249716
|
const child = receipt.agent_id ? await resolveChildSubagent(backend3, receipt.agent_id, sender.agentId) : null;
|
|
249717
|
+
const persistRun = resumeSubagentWriter(sender.conversationId, { conversation_id: receipt.conversation_id }, actingUserId);
|
|
249028
249718
|
if (child) {
|
|
249029
249719
|
(deps.trackChildSend ?? trackChildSend)({
|
|
249030
249720
|
receipt,
|
|
249031
249721
|
child,
|
|
249722
|
+
...persistRun && { persistRun: persistRun.update },
|
|
249032
249723
|
prompt: args.message,
|
|
249033
249724
|
parentScope: {
|
|
249034
249725
|
agentId: sender.agentId,
|
|
249035
249726
|
conversationId: sender.conversationId
|
|
249036
249727
|
}
|
|
249037
249728
|
});
|
|
249729
|
+
} else if (persistRun) {
|
|
249730
|
+
trackPersistedChildSend(receipt, persistRun);
|
|
249038
249731
|
}
|
|
249039
249732
|
return {
|
|
249040
249733
|
content: JSON.stringify({
|
|
@@ -249074,9 +249767,11 @@ var init_send_agent_message = __esm(() => {
|
|
|
249074
249767
|
init_agent_message();
|
|
249075
249768
|
init_conversation_enqueue();
|
|
249076
249769
|
init_request();
|
|
249770
|
+
init_subagents3();
|
|
249077
249771
|
init_runtime_context();
|
|
249078
249772
|
init_runtime_execution_settings();
|
|
249079
249773
|
init_debug();
|
|
249774
|
+
init_antigravity_session();
|
|
249080
249775
|
init_claude_stream_session();
|
|
249081
249776
|
init_codex_app_server();
|
|
249082
249777
|
init_cursor_session();
|
|
@@ -253475,6 +254170,27 @@ function buildBashDescriptionForPlatform(platform9 = process.platform) {
|
|
|
253475
254170
|
|
|
253476
254171
|
${WINDOWS_BASH_EXECUTION_GUIDANCE}` : baseDescription;
|
|
253477
254172
|
}
|
|
254173
|
+
function buildTaskSchema(env6 = process.env) {
|
|
254174
|
+
const { computer } = resolveSubagentComputer({
|
|
254175
|
+
requested: undefined,
|
|
254176
|
+
subagentType: "general-purpose",
|
|
254177
|
+
config: { fork: false, launchProfile: "default" },
|
|
254178
|
+
env: env6
|
|
254179
|
+
});
|
|
254180
|
+
if (!computer)
|
|
254181
|
+
return Task_default2;
|
|
254182
|
+
const destination = computer.toLowerCase() === "cloud" ? "a fresh Cloud sandbox, where this machine's files are unavailable" : `the connected computer ${JSON.stringify(computer)}; unless that is this machine, this machine's files are unavailable there`;
|
|
254183
|
+
return {
|
|
254184
|
+
...Task_default2,
|
|
254185
|
+
properties: {
|
|
254186
|
+
...Task_default2.properties,
|
|
254187
|
+
computer: {
|
|
254188
|
+
...Task_default2.properties.computer,
|
|
254189
|
+
description: `Omitting computer sends subagents to ${destination}. memory and recall subagents always stay on this machine. Pass "local" to stay on this machine, "cloud" for a fresh Cloud sandbox, or a connected computer ID or name. Prefer a stable device ID or computer name; ephemeral connection IDs are also supported to pin a specific listener. Fails fast if the device is offline or does not support routing.`
|
|
254190
|
+
}
|
|
254191
|
+
}
|
|
254192
|
+
};
|
|
254193
|
+
}
|
|
253478
254194
|
function execCommandDescription() {
|
|
253479
254195
|
const baseDescription = applyCommitTrailer(ExecCommand_default.trim());
|
|
253480
254196
|
return process.platform === "win32" ? `${baseDescription}
|
|
@@ -253497,6 +254213,7 @@ var init_tool_definitions = __esm(() => {
|
|
|
253497
254213
|
init_ExitWorktree();
|
|
253498
254214
|
init_Glob();
|
|
253499
254215
|
init_Grep();
|
|
254216
|
+
init_ListAgents();
|
|
253500
254217
|
init_LS();
|
|
253501
254218
|
init_Memory();
|
|
253502
254219
|
init_Monitor();
|
|
@@ -253531,6 +254248,7 @@ var init_tool_definitions = __esm(() => {
|
|
|
253531
254248
|
init_exit_worktree();
|
|
253532
254249
|
init_glob();
|
|
253533
254250
|
init_grep();
|
|
254251
|
+
init_list_agents();
|
|
253534
254252
|
init_ls();
|
|
253535
254253
|
init_memory4();
|
|
253536
254254
|
init_monitor();
|
|
@@ -253540,6 +254258,7 @@ var init_tool_definitions = __esm(() => {
|
|
|
253540
254258
|
init_send_agent_message();
|
|
253541
254259
|
init_set_working_directory();
|
|
253542
254260
|
init_skill();
|
|
254261
|
+
init_subagent_computer();
|
|
253543
254262
|
init_task();
|
|
253544
254263
|
init_task_create();
|
|
253545
254264
|
init_task_get();
|
|
@@ -253561,6 +254280,7 @@ var init_tool_definitions = __esm(() => {
|
|
|
253561
254280
|
init_ExitWorktree2();
|
|
253562
254281
|
init_Glob2();
|
|
253563
254282
|
init_Grep2();
|
|
254283
|
+
init_ListAgents2();
|
|
253564
254284
|
init_LS2();
|
|
253565
254285
|
init_Memory2();
|
|
253566
254286
|
init_Monitor2();
|
|
@@ -253670,6 +254390,11 @@ ${WINDOWS_UNIFIED_EXEC_GUIDANCE}`;
|
|
|
253670
254390
|
description: ReadLSP_default.trim(),
|
|
253671
254391
|
impl: read_lsp
|
|
253672
254392
|
}),
|
|
254393
|
+
ListAgents: defineTool({
|
|
254394
|
+
schema: ListAgents_default2,
|
|
254395
|
+
description: ListAgents_default.trim(),
|
|
254396
|
+
impl: list_agents
|
|
254397
|
+
}),
|
|
253673
254398
|
SendAgentMessage: defineTool({
|
|
253674
254399
|
schema: SendAgentMessage_default2,
|
|
253675
254400
|
description: SendAgentMessage_default.trim(),
|
|
@@ -253691,7 +254416,7 @@ ${WINDOWS_UNIFIED_EXEC_GUIDANCE}`;
|
|
|
253691
254416
|
impl: skill
|
|
253692
254417
|
}),
|
|
253693
254418
|
Task: defineTool({
|
|
253694
|
-
schema:
|
|
254419
|
+
schema: buildTaskSchema(),
|
|
253695
254420
|
description: Task_default.trim(),
|
|
253696
254421
|
impl: task
|
|
253697
254422
|
}),
|
|
@@ -264321,7 +265046,8 @@ function toExternalToolDefinition(listener, tool, connectionId, runtimeScope) {
|
|
|
264321
265046
|
}
|
|
264322
265047
|
};
|
|
264323
265048
|
return enableListenerExternalToolBackground(toolDefinition, {
|
|
264324
|
-
createNotificationGuard: () => captureExternalToolNotificationGuard(listener, runtimeScope)
|
|
265049
|
+
createNotificationGuard: () => captureExternalToolNotificationGuard(listener, runtimeScope),
|
|
265050
|
+
...tool.foreground_yield_ms !== undefined ? { yieldMs: clampForegroundYieldMs(tool.foreground_yield_ms) } : {}
|
|
264325
265051
|
});
|
|
264326
265052
|
}
|
|
264327
265053
|
function installExternalToolBridge(runtime, options) {
|
|
@@ -264607,6 +265333,7 @@ function rejectPendingExternalToolCalls(runtime, reason) {
|
|
|
264607
265333
|
var EXTERNAL_TOOL_CALL_TIMEOUT_MS, registeredToolsByRuntime, lastSubmittingConnectionByRuntime, nextRegistrationSequence = 0, connectionIdByRegistrationKey;
|
|
264608
265334
|
var init_external_tools = __esm(() => {
|
|
264609
265335
|
init_external_tool_background_eligibility();
|
|
265336
|
+
init_foreground_yield();
|
|
264610
265337
|
init_manager2();
|
|
264611
265338
|
init_debug();
|
|
264612
265339
|
init_connection();
|
|
@@ -447705,12 +448432,12 @@ function rowToolCalls(row, index, diagnostics2) {
|
|
|
447705
448432
|
}
|
|
447706
448433
|
return calls;
|
|
447707
448434
|
}
|
|
447708
|
-
function
|
|
448435
|
+
function contentText3(content) {
|
|
447709
448436
|
if (typeof content === "string") {
|
|
447710
448437
|
if (content.startsWith(CONTENT_JSON_PREFIX)) {
|
|
447711
448438
|
const encoded = content.slice(CONTENT_JSON_PREFIX.length);
|
|
447712
448439
|
try {
|
|
447713
|
-
return
|
|
448440
|
+
return contentText3(JSON.parse(encoded));
|
|
447714
448441
|
} catch {
|
|
447715
448442
|
return encoded;
|
|
447716
448443
|
}
|
|
@@ -447796,7 +448523,7 @@ var init_hermes = __esm(() => {
|
|
|
447796
448523
|
});
|
|
447797
448524
|
};
|
|
447798
448525
|
if (row.role === "user") {
|
|
447799
|
-
const content =
|
|
448526
|
+
const content = contentText3(row.content);
|
|
447800
448527
|
if (content) {
|
|
447801
448528
|
emit({
|
|
447802
448529
|
type: "message",
|
|
@@ -447816,7 +448543,7 @@ var init_hermes = __esm(() => {
|
|
|
447816
448543
|
...timestamp ? { timestamp } : {}
|
|
447817
448544
|
});
|
|
447818
448545
|
}
|
|
447819
|
-
const content =
|
|
448546
|
+
const content = contentText3(row.content);
|
|
447820
448547
|
if (content) {
|
|
447821
448548
|
emit({
|
|
447822
448549
|
type: "message",
|
|
@@ -447839,7 +448566,7 @@ var init_hermes = __esm(() => {
|
|
|
447839
448566
|
if (row.role === "tool") {
|
|
447840
448567
|
emit({
|
|
447841
448568
|
type: "tool_result",
|
|
447842
|
-
content:
|
|
448569
|
+
content: contentText3(row.content),
|
|
447843
448570
|
...typeof row.tool_call_id === "string" && row.tool_call_id ? { callId: row.tool_call_id } : {},
|
|
447844
448571
|
...timestamp ? { timestamp } : {}
|
|
447845
448572
|
});
|
|
@@ -456064,7 +456791,7 @@ function isRuntimeScope2(value) {
|
|
|
456064
456791
|
function isExternalToolDefinitionPayload(value) {
|
|
456065
456792
|
if (!isRecord18(value))
|
|
456066
456793
|
return false;
|
|
456067
|
-
return typeof value.name === "string" && (value.label === undefined || typeof value.label === "string") && typeof value.description === "string" && isRecord18(value.parameters) && (value.auto_background === undefined || typeof value.auto_background === "boolean") && (value.timeout_ms === undefined || typeof value.timeout_ms === "number" && Number.isSafeInteger(value.timeout_ms) && value.timeout_ms >= 1000 && value.timeout_ms <= 300000);
|
|
456794
|
+
return typeof value.name === "string" && (value.label === undefined || typeof value.label === "string") && typeof value.description === "string" && isRecord18(value.parameters) && (value.auto_background === undefined || typeof value.auto_background === "boolean") && (value.foreground_yield_ms === undefined || typeof value.foreground_yield_ms === "number" && Number.isFinite(value.foreground_yield_ms) && value.foreground_yield_ms > 0) && (value.timeout_ms === undefined || typeof value.timeout_ms === "number" && Number.isSafeInteger(value.timeout_ms) && value.timeout_ms >= 1000 && value.timeout_ms <= 300000);
|
|
456068
456795
|
}
|
|
456069
456796
|
function isStringList(value) {
|
|
456070
456797
|
return Array.isArray(value) && value.every((entry) => typeof entry === "string");
|
|
@@ -456276,6 +457003,7 @@ var init_subagent_protocol_inbound = __esm(() => {
|
|
|
456276
457003
|
"mcp"
|
|
456277
457004
|
]);
|
|
456278
457005
|
LEGACY_EXTERNAL_SUBAGENT_TYPES = new Set([
|
|
457006
|
+
"antigravity",
|
|
456279
457007
|
"claude-code",
|
|
456280
457008
|
"codex",
|
|
456281
457009
|
"cursor",
|
|
@@ -459690,6 +460418,7 @@ function buildAppServerInfoResponse(command, options) {
|
|
|
459690
460418
|
runtime_external_tools_update: true,
|
|
459691
460419
|
runtime_tool_policy: true,
|
|
459692
460420
|
runtime_tool_policy_foreground_yield: true,
|
|
460421
|
+
external_tool_foreground_yield: true,
|
|
459693
460422
|
structured_outputs: options.backend === "api",
|
|
459694
460423
|
write_file_base64: true,
|
|
459695
460424
|
split_channels: false
|
|
@@ -462815,6 +463544,7 @@ async function applyRuntimeStartState(parsed, context3, scope, scopedRuntime) {
|
|
|
462815
463544
|
if (!mode) {
|
|
462816
463545
|
throw new Error(`Unsupported permission mode: ${parsed.mode}`);
|
|
462817
463546
|
}
|
|
463547
|
+
const hadPermissionMode = context3.runtime.permissionModeByConversation.has(getPermissionModeScopeKey(scope.agent_id, scope.conversation_id));
|
|
462818
463548
|
const state2 = getOrCreateConversationPermissionModeStateRef(context3.runtime, scope.agent_id, scope.conversation_id);
|
|
462819
463549
|
if (!(parsed.mode_is_default && state2.explicit)) {
|
|
462820
463550
|
const previousMode = state2.mode;
|
|
@@ -462822,7 +463552,7 @@ async function applyRuntimeStartState(parsed, context3, scope, scopedRuntime) {
|
|
|
462822
463552
|
if (!parsed.mode_is_default)
|
|
462823
463553
|
state2.explicit = true;
|
|
462824
463554
|
persistPermissionModeMapForRuntime(context3.runtime);
|
|
462825
|
-
if (previousMode !== mode) {
|
|
463555
|
+
if (hadPermissionMode && previousMode !== mode) {
|
|
462826
463556
|
telemetry.trackPermissionModeChanged({
|
|
462827
463557
|
agent_id: scope.agent_id,
|
|
462828
463558
|
conversation_id: scope.conversation_id,
|
|
@@ -464275,6 +465005,8 @@ function nativeSessionOwner(agentId) {
|
|
|
464275
465005
|
const target = parseExternalCodingAgentId(agentId);
|
|
464276
465006
|
if (!target || target.computer)
|
|
464277
465007
|
return;
|
|
465008
|
+
if (target.type === "antigravity")
|
|
465009
|
+
return readNativeSessionOwner(target.type, target.sessionId);
|
|
464278
465010
|
if (target.type !== "claude-code" && target.type !== "codex")
|
|
464279
465011
|
return;
|
|
464280
465012
|
return getNativeSessionOwner(target.type === "claude-code" ? "claude_code" : "codex", target.sessionId);
|
|
@@ -464344,6 +465076,14 @@ async function handleSubagentMessageCommand(command, parent, deps = {}) {
|
|
|
464344
465076
|
parentAgentId: command.runtime.agent_id,
|
|
464345
465077
|
actingUserId: command.runtime.acting_user_id
|
|
464346
465078
|
}, deps.workerEnv);
|
|
465079
|
+
if (target.type === "antigravity" && worker)
|
|
465080
|
+
return sendAntigravityMessage({
|
|
465081
|
+
resumeSessionId: sessionId,
|
|
465082
|
+
prompt: command.message,
|
|
465083
|
+
parentAgentId: command.runtime.agent_id,
|
|
465084
|
+
cwd: getCurrentWorkingDirectory(),
|
|
465085
|
+
mcpReminder: worker.mcpReminder
|
|
465086
|
+
}, worker.env, worker.secretEnv);
|
|
464347
465087
|
return target.type === "cursor" ? sendCursorMessage({
|
|
464348
465088
|
sessionId,
|
|
464349
465089
|
prompt: command.message,
|
|
@@ -464505,6 +465245,7 @@ var DEDUPE_TTL_MS = 30000, responses;
|
|
|
464505
465245
|
var init_subagent_control = __esm(() => {
|
|
464506
465246
|
init_subagent_state();
|
|
464507
465247
|
init_runtime_context();
|
|
465248
|
+
init_antigravity_session();
|
|
464508
465249
|
init_claude_steer_timeouts();
|
|
464509
465250
|
init_claude_stream_session();
|
|
464510
465251
|
init_codex_app_server();
|
|
@@ -464512,6 +465253,7 @@ var init_subagent_control = __esm(() => {
|
|
|
464512
465253
|
init_external_coding_agent();
|
|
464513
465254
|
init_external_coding_agent_task();
|
|
464514
465255
|
init_native_session_capture();
|
|
465256
|
+
init_native_session_owner();
|
|
464515
465257
|
init_process_manager();
|
|
464516
465258
|
init_task_stop();
|
|
464517
465259
|
init_cwd();
|
|
@@ -464610,7 +465352,7 @@ async function handleLaunchSubagentCommand(command, parent, connectionId, launch
|
|
|
464610
465352
|
signal.removeEventListener("abort", onAbort);
|
|
464611
465353
|
}
|
|
464612
465354
|
}
|
|
464613
|
-
var
|
|
465355
|
+
var init_subagents4 = __esm(() => {
|
|
464614
465356
|
init_runtime_context();
|
|
464615
465357
|
init_task();
|
|
464616
465358
|
init_cwd();
|
|
@@ -464670,7 +465412,7 @@ var init_task_control = __esm(() => {
|
|
|
464670
465412
|
init_stop_conversation();
|
|
464671
465413
|
init_subagent_control();
|
|
464672
465414
|
init_subagent_events2();
|
|
464673
|
-
|
|
465415
|
+
init_subagents4();
|
|
464674
465416
|
});
|
|
464675
465417
|
|
|
464676
465418
|
// src/websocket/listener/message-router.ts
|
|
@@ -472361,7 +473103,7 @@ var exports_external_worker_models = {};
|
|
|
472361
473103
|
__export(exports_external_worker_models, {
|
|
472362
473104
|
listExternalWorkerModels: () => listExternalWorkerModels
|
|
472363
473105
|
});
|
|
472364
|
-
import { createInterface as
|
|
473106
|
+
import { createInterface as createInterface12 } from "node:readline";
|
|
472365
473107
|
async function listClaudeModels(cwd2, env6) {
|
|
472366
473108
|
const controller = new AbortController;
|
|
472367
473109
|
const running = spawnManagedWorkloadProcess("claude", [
|
|
@@ -472379,7 +473121,7 @@ async function listClaudeModels(cwd2, env6) {
|
|
|
472379
473121
|
'{"disableAllHooks":true}'
|
|
472380
473122
|
], { cwd: cwd2, env: env6, signal: controller.signal });
|
|
472381
473123
|
const timer = setTimeout(() => controller.abort(), 30000);
|
|
472382
|
-
const lines =
|
|
473124
|
+
const lines = createInterface12({ input: running.process.stdout });
|
|
472383
473125
|
let stderr = "";
|
|
472384
473126
|
running.process.once("error", (error4) => {
|
|
472385
473127
|
stderr = error4.message;
|
|
@@ -478495,10 +479237,10 @@ async function openReadOnlyDatabase(path49) {
|
|
|
478495
479237
|
async function exportHermesSession(storePath, sessionId) {
|
|
478496
479238
|
const database = await openReadOnlyDatabase(storePath);
|
|
478497
479239
|
try {
|
|
478498
|
-
const
|
|
479240
|
+
const sessions6 = database.all("SELECT * FROM sessions WHERE id = ?", sessionId);
|
|
478499
479241
|
const messages = database.all("SELECT * FROM messages WHERE session_id = ? ORDER BY id", sessionId);
|
|
478500
479242
|
return JSON.stringify({
|
|
478501
|
-
session:
|
|
479243
|
+
session: sessions6[0] ?? { id: sessionId },
|
|
478502
479244
|
messages
|
|
478503
479245
|
});
|
|
478504
479246
|
} finally {
|
|
@@ -478742,8 +479484,8 @@ async function readManifest(dir) {
|
|
|
478742
479484
|
}
|
|
478743
479485
|
return JSON.parse(raw2);
|
|
478744
479486
|
}
|
|
478745
|
-
function filterSessions(
|
|
478746
|
-
return
|
|
479487
|
+
function filterSessions(sessions6, filter3) {
|
|
479488
|
+
return sessions6.filter((session3) => (!filter3.source || session3.source === filter3.source) && (!filter3.project || (session3.project ?? "").startsWith(filter3.project)));
|
|
478747
479489
|
}
|
|
478748
479490
|
async function resolveSessionFile(dir, target) {
|
|
478749
479491
|
if (target.endsWith(".json")) {
|
|
@@ -478918,19 +479660,19 @@ async function runDetect(asJson) {
|
|
|
478918
479660
|
}
|
|
478919
479661
|
async function runList4(flags) {
|
|
478920
479662
|
const manifest2 = await readManifest(flags.dir);
|
|
478921
|
-
const
|
|
479663
|
+
const sessions6 = filterSessions(manifest2.sessions, flags);
|
|
478922
479664
|
if (flags.asJson) {
|
|
478923
|
-
console.log(JSON.stringify({ sessions:
|
|
479665
|
+
console.log(JSON.stringify({ sessions: sessions6 }, null, 2));
|
|
478924
479666
|
return 0;
|
|
478925
479667
|
}
|
|
478926
|
-
for (const session3 of
|
|
479668
|
+
for (const session3 of sessions6) {
|
|
478927
479669
|
console.log(`${(session3.startedAt ?? "unknown").slice(0, 19)} ${session3.source} msgs:${session3.userMessages} ${session3.file}`);
|
|
478928
479670
|
if (session3.firstUserPrompt) {
|
|
478929
479671
|
console.log(` ${session3.firstUserPrompt.replace(/\s+/g, " ").slice(0, 90)}`);
|
|
478930
479672
|
}
|
|
478931
479673
|
}
|
|
478932
479674
|
console.log(`
|
|
478933
|
-
Total: ${
|
|
479675
|
+
Total: ${sessions6.length} session(s); errors: ${manifest2.errors.length}; sources: ${Object.keys(manifest2.sources).join(", ")}`);
|
|
478934
479676
|
return 0;
|
|
478935
479677
|
}
|
|
478936
479678
|
async function runView(flags, target, options) {
|
|
@@ -484323,13 +485065,16 @@ async function createSubagentConversation(cloudBackend, parentConversationId, ag
|
|
|
484323
485065
|
if (!cloudBackend || !parentConversationId || parentConversationId === "default") {
|
|
484324
485066
|
return "default";
|
|
484325
485067
|
}
|
|
485068
|
+
const summary = process.env[SUBAGENT_SUMMARY_ENV]?.trim();
|
|
484326
485069
|
const body3 = {
|
|
484327
485070
|
agent_id: agentId,
|
|
484328
485071
|
parent_conversation_id: parentConversationId,
|
|
484329
|
-
is_subagent: true
|
|
485072
|
+
is_subagent: true,
|
|
485073
|
+
...summary ? { summary } : {}
|
|
484330
485074
|
};
|
|
484331
485075
|
return (await create4(body3)).id;
|
|
484332
485076
|
}
|
|
485077
|
+
var init_subagent_conversation = () => {};
|
|
484333
485078
|
|
|
484334
485079
|
// src/stream-json-writer.ts
|
|
484335
485080
|
function stampWireMessage(msg) {
|
|
@@ -488605,6 +489350,7 @@ var LLM_API_ERROR_MAX_RETRIES2 = 3, EMPTY_RESPONSE_MAX_RETRIES2 = 2, HEADLESS_ST
|
|
|
488605
489350
|
var init_headless = __esm(() => {
|
|
488606
489351
|
init_error();
|
|
488607
489352
|
init_preloaded_skills();
|
|
489353
|
+
init_subagent_conversation();
|
|
488608
489354
|
init_subagent_launcher();
|
|
488609
489355
|
init_paths();
|
|
488610
489356
|
init_constants2();
|
|
@@ -538523,4 +539269,4 @@ function registerBunOAuthFlows() {
|
|
|
538523
539269
|
registerBunOAuthFlows();
|
|
538524
539270
|
await init_src5().then(() => exports_src2);
|
|
538525
539271
|
|
|
538526
|
-
//# debugId=
|
|
539272
|
+
//# debugId=51AADFFB825ABBC564756E2164756E21
|