@letta-ai/letta-code 0.34.50 → 0.34.51
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/mcp-client.js +2 -2
- package/dist/mcp-client.js.map +1 -1
- package/dist/mcp-oauth.js +2 -2
- package/dist/mcp-oauth.js.map +1 -1
- package/dist/types/agent/subagents/remote-turn-wait.d.ts.map +1 -1
- package/dist/types/headless-listener-launch.d.ts +2 -0
- package/dist/types/headless-listener-launch.d.ts.map +1 -1
- package/dist/types/tools/impl/bash.d.ts.map +1 -1
- package/dist/types/tools/impl/claude-stream-session.d.ts +1 -0
- package/dist/types/tools/impl/claude-stream-session.d.ts.map +1 -1
- package/dist/types/tools/impl/codex-app-server.d.ts +1 -0
- package/dist/types/tools/impl/codex-app-server.d.ts.map +1 -1
- package/dist/types/tools/impl/exec-command.d.ts.map +1 -1
- package/dist/types/tools/impl/monitor.d.ts.map +1 -1
- package/dist/types/tools/impl/process_manager.d.ts +6 -0
- package/dist/types/tools/impl/process_manager.d.ts.map +1 -1
- package/dist/types/tools/impl/remote-external-coding-agent.d.ts.map +1 -1
- package/dist/types/tools/impl/stop-conversation-background.d.ts +4 -0
- package/dist/types/tools/impl/stop-conversation-background.d.ts.map +1 -0
- package/dist/types/tools/impl/subagent-stop-bridge.d.ts +7 -0
- package/dist/types/tools/impl/subagent-stop-bridge.d.ts.map +1 -0
- package/dist/types/tools/impl/task-abort-hook.d.ts.map +1 -1
- package/dist/types/tools/impl/task-stop.d.ts.map +1 -1
- package/dist/types/tools/impl/wake.d.ts +6 -0
- package/dist/types/tools/impl/wake.d.ts.map +1 -1
- package/dist/types/types/subagent-protocol.d.ts +6 -1
- package/dist/types/types/subagent-protocol.d.ts.map +1 -1
- package/dist/types/utils/confirm-process-exit.d.ts +3 -0
- package/dist/types/utils/confirm-process-exit.d.ts.map +1 -0
- package/letta.js +454 -84
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
package/letta.js
CHANGED
|
@@ -6077,7 +6077,7 @@ var package_default;
|
|
|
6077
6077
|
var init_package = __esm(() => {
|
|
6078
6078
|
package_default = {
|
|
6079
6079
|
name: "@letta-ai/letta-code",
|
|
6080
|
-
version: "0.34.
|
|
6080
|
+
version: "0.34.51",
|
|
6081
6081
|
lettaStartupLogProtocol: 1,
|
|
6082
6082
|
lettaConfigDirProtocol: 1,
|
|
6083
6083
|
description: "Letta Code is a CLI tool for interacting with stateful Letta agents from the terminal.",
|
|
@@ -212165,7 +212165,7 @@ var init_mcp_client = __esm(() => {
|
|
|
212165
212165
|
init_streamableHttp();
|
|
212166
212166
|
DEFAULT_CLIENT_INFO = {
|
|
212167
212167
|
name: "letta-code",
|
|
212168
|
-
version: "0.34.
|
|
212168
|
+
version: "0.34.51"
|
|
212169
212169
|
};
|
|
212170
212170
|
});
|
|
212171
212171
|
|
|
@@ -222297,6 +222297,8 @@ async function bash(args) {
|
|
|
222297
222297
|
});
|
|
222298
222298
|
bgProcess = {
|
|
222299
222299
|
process: runningProcess.process,
|
|
222300
|
+
completion: runningProcess.completion,
|
|
222301
|
+
terminate: runningProcess.terminate,
|
|
222300
222302
|
command,
|
|
222301
222303
|
stdout: [],
|
|
222302
222304
|
stderr: [],
|
|
@@ -239890,6 +239892,8 @@ async function startExecSession(args) {
|
|
|
239890
239892
|
}
|
|
239891
239893
|
backgroundProcesses.set(id2, {
|
|
239892
239894
|
process: runningProcess.process,
|
|
239895
|
+
completion: runningProcess.completion,
|
|
239896
|
+
terminate: runningProcess.terminate,
|
|
239893
239897
|
command: args.cmd,
|
|
239894
239898
|
status: session3.status,
|
|
239895
239899
|
exitCode: session3.exitCode,
|
|
@@ -242551,6 +242555,14 @@ async function wake(args, deps = {}) {
|
|
|
242551
242555
|
});
|
|
242552
242556
|
}
|
|
242553
242557
|
}
|
|
242558
|
+
async function cancelConversationWakes(scope, deps = {}) {
|
|
242559
|
+
const current = await listCurrentWakes(scope, { action: "list" }, deps);
|
|
242560
|
+
if (current.warnings.length)
|
|
242561
|
+
throw new Error(current.warnings.join("; "));
|
|
242562
|
+
for (const record6 of current.wakes) {
|
|
242563
|
+
await cancelWake({ action: "cancel", id: record6.id }, scope, deps);
|
|
242564
|
+
}
|
|
242565
|
+
}
|
|
242554
242566
|
var import_cron_parser2, MAX_ACTIVE_WAKES = 20, MIN_RECURRING_INTERVAL_MS, MAX_NAME_LENGTH = 80, MAX_PROMPT_LENGTH = 4000;
|
|
242555
242567
|
var init_wake = __esm(() => {
|
|
242556
242568
|
init_request();
|
|
@@ -243437,6 +243449,7 @@ function startCommandMonitor(args) {
|
|
|
243437
243449
|
}
|
|
243438
243450
|
});
|
|
243439
243451
|
processState = {
|
|
243452
|
+
completion: runningProcess.completion,
|
|
243440
243453
|
process: {
|
|
243441
243454
|
kill(signal) {
|
|
243442
243455
|
events.cancel();
|
|
@@ -245321,6 +245334,22 @@ function createAppServerClient(options) {
|
|
|
245321
245334
|
var DEFAULT_REQUEST_TIMEOUT_MS = 30000, WEBSOCKET_OPEN_STATE = 1;
|
|
245322
245335
|
var init_app_server_client = () => {};
|
|
245323
245336
|
|
|
245337
|
+
// src/tools/impl/subagent-stop-bridge.ts
|
|
245338
|
+
function registerLocalSubagentStop(connectionId, stop) {
|
|
245339
|
+
owners.set(connectionId, stop);
|
|
245340
|
+
return () => {
|
|
245341
|
+
if (owners.get(connectionId) === stop)
|
|
245342
|
+
owners.delete(connectionId);
|
|
245343
|
+
};
|
|
245344
|
+
}
|
|
245345
|
+
function stopLocalSubagent(connectionId, command) {
|
|
245346
|
+
return owners.get(connectionId)?.(command);
|
|
245347
|
+
}
|
|
245348
|
+
var owners;
|
|
245349
|
+
var init_subagent_stop_bridge = __esm(() => {
|
|
245350
|
+
owners = new Map;
|
|
245351
|
+
});
|
|
245352
|
+
|
|
245324
245353
|
// src/headless-environment-response.ts
|
|
245325
245354
|
function buildEnvironmentResponseMetadata(params) {
|
|
245326
245355
|
return {
|
|
@@ -245492,6 +245521,50 @@ async function cancelAcceptedListenerInput(receipt) {
|
|
|
245492
245521
|
client.close();
|
|
245493
245522
|
}
|
|
245494
245523
|
}
|
|
245524
|
+
async function stopAcceptedListenerConversation(receipt) {
|
|
245525
|
+
if (!receipt.connection_id)
|
|
245526
|
+
throw new Error("The owning listener is unknown");
|
|
245527
|
+
const scope = {
|
|
245528
|
+
agent_id: receipt.agent_id,
|
|
245529
|
+
conversation_id: receipt.conversation_id,
|
|
245530
|
+
acting_user_id: receipt.acting_user_id ?? undefined
|
|
245531
|
+
};
|
|
245532
|
+
try {
|
|
245533
|
+
await dequeueConversationMessage({
|
|
245534
|
+
agentId: getEnqueueAgentId(receipt),
|
|
245535
|
+
conversationId: receipt.conversation_id,
|
|
245536
|
+
clientMessageId: receipt.client_message_id,
|
|
245537
|
+
actingUserId: receipt.acting_user_id
|
|
245538
|
+
}, AbortSignal.timeout(1e4));
|
|
245539
|
+
} catch (error5) {
|
|
245540
|
+
if (!(error5 instanceof ApiRequestError && error5.status === 404))
|
|
245541
|
+
throw error5;
|
|
245542
|
+
}
|
|
245543
|
+
const command = {
|
|
245544
|
+
type: "subagent_stop",
|
|
245545
|
+
request_id: randomUUID37(),
|
|
245546
|
+
runtime: { ...scope, agent_id: getEnqueueAgentId(receipt) },
|
|
245547
|
+
agent_id: getEnqueueAgentId(receipt),
|
|
245548
|
+
conversation: scope,
|
|
245549
|
+
client_message_id: receipt.client_message_id
|
|
245550
|
+
};
|
|
245551
|
+
const requireStopped = (response) => {
|
|
245552
|
+
if (!response.success || !response.stopped || !response.cleanup_confirmed)
|
|
245553
|
+
throw new Error(response.error ?? "The listener did not confirm the stop");
|
|
245554
|
+
};
|
|
245555
|
+
const local = stopLocalSubagent(receipt.connection_id, command);
|
|
245556
|
+
if (local) {
|
|
245557
|
+
requireStopped(await local);
|
|
245558
|
+
return;
|
|
245559
|
+
}
|
|
245560
|
+
const client = await createListenerClient(receipt.connection_id, scope);
|
|
245561
|
+
try {
|
|
245562
|
+
await client.connect();
|
|
245563
|
+
requireStopped(await client.stopSubagent(command));
|
|
245564
|
+
} finally {
|
|
245565
|
+
client.close();
|
|
245566
|
+
}
|
|
245567
|
+
}
|
|
245495
245568
|
async function launchListenerConversation(params, deps = {}) {
|
|
245496
245569
|
const agentId = params.scope.agent_id ?? params.parentAgentId;
|
|
245497
245570
|
if (!agentId)
|
|
@@ -245681,6 +245754,7 @@ var init_headless_listener_launch = __esm(() => {
|
|
|
245681
245754
|
init_app_server_client();
|
|
245682
245755
|
init_conversation_enqueue();
|
|
245683
245756
|
init_request();
|
|
245757
|
+
init_subagent_stop_bridge();
|
|
245684
245758
|
init_headless_environment_response();
|
|
245685
245759
|
});
|
|
245686
245760
|
|
|
@@ -246236,6 +246310,15 @@ function recordRemoteRunProgress(messages, state2, subagentId) {
|
|
|
246236
246310
|
}
|
|
246237
246311
|
}
|
|
246238
246312
|
async function collectRemoteTurnResult(receipt, state2, subagentId, signal = new AbortController().signal, deps = {}) {
|
|
246313
|
+
const task = [...backgroundTasks.values()].find((task2) => task2.subagentId === subagentId);
|
|
246314
|
+
let stopConfirmed = false;
|
|
246315
|
+
if (task) {
|
|
246316
|
+
task.remote = true;
|
|
246317
|
+
task.stop = async () => {
|
|
246318
|
+
await stopAcceptedListenerConversation(receipt);
|
|
246319
|
+
stopConfirmed = true;
|
|
246320
|
+
};
|
|
246321
|
+
}
|
|
246239
246322
|
const startedAt = Date.now();
|
|
246240
246323
|
updateSubagent(subagentId, {
|
|
246241
246324
|
agentId: receipt.agent_id ?? undefined,
|
|
@@ -246282,7 +246365,7 @@ async function collectRemoteTurnResult(receipt, state2, subagentId, signal = new
|
|
|
246282
246365
|
} catch (error5) {
|
|
246283
246366
|
let detail = getErrorMessage2(error5);
|
|
246284
246367
|
if (signal.aborted) {
|
|
246285
|
-
const cancelled = await cancelAcceptedListenerInput(receipt).catch(() => false);
|
|
246368
|
+
const cancelled = stopConfirmed || await cancelAcceptedListenerInput(receipt).catch(() => false);
|
|
246286
246369
|
detail = cancelled ? INTERRUPTED_BY_USER : `${INTERRUPTED_BY_USER} (could not confirm cancellation of remote Super Run ${receipt.super_run_id})`;
|
|
246287
246370
|
}
|
|
246288
246371
|
return {
|
|
@@ -246303,6 +246386,7 @@ var init_remote_turn_wait = __esm(() => {
|
|
|
246303
246386
|
init_constants2();
|
|
246304
246387
|
init_headless_listener_launch();
|
|
246305
246388
|
init_headless_super_run_wait();
|
|
246389
|
+
init_process_manager();
|
|
246306
246390
|
init_task_transcript();
|
|
246307
246391
|
init_message_queue_bridge();
|
|
246308
246392
|
init_task_notifications();
|
|
@@ -246846,6 +246930,21 @@ var init_subagent_process = __esm(() => {
|
|
|
246846
246930
|
init_package_manager_spawn();
|
|
246847
246931
|
});
|
|
246848
246932
|
|
|
246933
|
+
// src/utils/confirm-process-exit.ts
|
|
246934
|
+
async function confirmProcessExit(exit, name) {
|
|
246935
|
+
let timer;
|
|
246936
|
+
try {
|
|
246937
|
+
await Promise.race([
|
|
246938
|
+
exit,
|
|
246939
|
+
new Promise((_4, reject2) => {
|
|
246940
|
+
timer = setTimeout(() => reject2(new Error(`${name} process exit was not confirmed`)), 1e4);
|
|
246941
|
+
})
|
|
246942
|
+
]);
|
|
246943
|
+
} finally {
|
|
246944
|
+
clearTimeout(timer);
|
|
246945
|
+
}
|
|
246946
|
+
}
|
|
246947
|
+
|
|
246849
246948
|
// src/utils/native-cli-env.ts
|
|
246850
246949
|
import { homedir as homedir19 } from "node:os";
|
|
246851
246950
|
import { join as join64 } from "node:path";
|
|
@@ -247410,25 +247509,6 @@ import { createInterface as createInterface8 } from "node:readline";
|
|
|
247410
247509
|
function errorMessage2(error5) {
|
|
247411
247510
|
return error5 instanceof Error ? error5.message : String(error5);
|
|
247412
247511
|
}
|
|
247413
|
-
function userInput(prompt, uuid5) {
|
|
247414
|
-
return `${JSON.stringify({
|
|
247415
|
-
type: "user",
|
|
247416
|
-
uuid: uuid5,
|
|
247417
|
-
message: {
|
|
247418
|
-
role: "user",
|
|
247419
|
-
content: [{ type: "text", text: prompt }]
|
|
247420
|
-
}
|
|
247421
|
-
})}
|
|
247422
|
-
`;
|
|
247423
|
-
}
|
|
247424
|
-
function interruptInput(requestId) {
|
|
247425
|
-
return `${JSON.stringify({
|
|
247426
|
-
type: "control_request",
|
|
247427
|
-
request_id: requestId,
|
|
247428
|
-
request: { subtype: "interrupt" }
|
|
247429
|
-
})}
|
|
247430
|
-
`;
|
|
247431
|
-
}
|
|
247432
247512
|
function buildClaudeStreamArgs(options) {
|
|
247433
247513
|
const args = [
|
|
247434
247514
|
"--print",
|
|
@@ -247564,7 +247644,8 @@ function writeInput(session3, prompt) {
|
|
|
247564
247644
|
const uuid5 = randomUUID39();
|
|
247565
247645
|
session3.latestInputUuid = uuid5;
|
|
247566
247646
|
session3.latestInputStarted = false;
|
|
247567
|
-
return writeRaw(session3.transport.process.stdin,
|
|
247647
|
+
return writeRaw(session3.transport.process.stdin, `${JSON.stringify({ type: "user", uuid: uuid5, message: { role: "user", content: [{ type: "text", text: prompt }] } })}
|
|
247648
|
+
`);
|
|
247568
247649
|
}
|
|
247569
247650
|
function acknowledgeInput(session3, uuid5) {
|
|
247570
247651
|
if (typeof uuid5 !== "string" || !session3.latestInputUuid)
|
|
@@ -247979,7 +248060,8 @@ async function steerSession(session3, prompt, signal) {
|
|
|
247979
248060
|
}, CONTROL_RESPONSE_TIMEOUT_MS);
|
|
247980
248061
|
timeout.unref?.();
|
|
247981
248062
|
try {
|
|
247982
|
-
await writeRaw(session3.transport.process.stdin,
|
|
248063
|
+
await writeRaw(session3.transport.process.stdin, `${JSON.stringify({ type: "control_request", request_id: requestId, request: { subtype: "interrupt" } })}
|
|
248064
|
+
`);
|
|
247983
248065
|
await response;
|
|
247984
248066
|
interruptAcknowledged = true;
|
|
247985
248067
|
signal?.throwIfAborted();
|
|
@@ -248057,6 +248139,14 @@ async function sendClaudeMessage(options, deps = {}) {
|
|
|
248057
248139
|
return { mode: "steered", sessionId: options.sessionId };
|
|
248058
248140
|
return trackedReceipt(delivered.session);
|
|
248059
248141
|
}
|
|
248142
|
+
async function stopClaudeSession(sessionId) {
|
|
248143
|
+
const session3 = sessions.get(sessionId);
|
|
248144
|
+
if (!session3)
|
|
248145
|
+
return false;
|
|
248146
|
+
session3.abortController.abort(new Error("Stopped by parent"));
|
|
248147
|
+
await confirmProcessExit(session3.exit, "Claude Code");
|
|
248148
|
+
return true;
|
|
248149
|
+
}
|
|
248060
248150
|
var sessions, CONTROL_RESPONSE_TIMEOUT_MS = 30000, TURN_START_TIMEOUT_MS = 60000, BACKGROUND_TASK_WAIT_CAP_MS, SETTLED_EXIT_GRACE_MS = 1e4;
|
|
248061
248151
|
var init_claude_stream_session = __esm(() => {
|
|
248062
248152
|
init_subagent_process();
|
|
@@ -248234,21 +248324,20 @@ function textInput(text2) {
|
|
|
248234
248324
|
return [{ type: "text", text: text2 }];
|
|
248235
248325
|
}
|
|
248236
248326
|
function spawnTransport(options) {
|
|
248237
|
-
const
|
|
248238
|
-
const child =
|
|
248239
|
-
|
|
248240
|
-
|
|
248241
|
-
stdio: ["pipe", "pipe", "pipe"],
|
|
248242
|
-
windowsHide: true
|
|
248327
|
+
const controller = new AbortController;
|
|
248328
|
+
const { process: child, completion } = spawnManagedWorkloadProcess("codex", [...options.configArgs ?? [], "app-server", "--stdio"], {
|
|
248329
|
+
...options,
|
|
248330
|
+
signal: controller.signal
|
|
248243
248331
|
});
|
|
248244
248332
|
return {
|
|
248245
248333
|
stdin: child.stdin,
|
|
248246
248334
|
stdout: child.stdout,
|
|
248247
248335
|
stderr: child.stderr,
|
|
248248
|
-
kill: () =>
|
|
248249
|
-
exited:
|
|
248250
|
-
|
|
248251
|
-
|
|
248336
|
+
kill: () => controller.abort(),
|
|
248337
|
+
exited: completion.then((exit) => ({
|
|
248338
|
+
code: exit.exitCode,
|
|
248339
|
+
signal: exit.exitSignal
|
|
248340
|
+
}))
|
|
248252
248341
|
};
|
|
248253
248342
|
}
|
|
248254
248343
|
|
|
@@ -248302,7 +248391,7 @@ class CodexAppServerClient {
|
|
|
248302
248391
|
await this.request("initialize", {
|
|
248303
248392
|
clientInfo: {
|
|
248304
248393
|
name: "letta-code",
|
|
248305
|
-
version: "0.34.
|
|
248394
|
+
version: "0.34.51"
|
|
248306
248395
|
},
|
|
248307
248396
|
capabilities: null
|
|
248308
248397
|
});
|
|
@@ -248329,6 +248418,13 @@ class CodexAppServerClient {
|
|
|
248329
248418
|
`);
|
|
248330
248419
|
}
|
|
248331
248420
|
}
|
|
248421
|
+
async stop() {
|
|
248422
|
+
if (!this.transport.exited)
|
|
248423
|
+
throw new Error("Codex process exit cannot be confirmed");
|
|
248424
|
+
this.transport.kill?.();
|
|
248425
|
+
await confirmProcessExit(this.transport.exited, "Codex");
|
|
248426
|
+
await this.close();
|
|
248427
|
+
}
|
|
248332
248428
|
dispose() {
|
|
248333
248429
|
this.transport.kill?.();
|
|
248334
248430
|
this.close();
|
|
@@ -248814,11 +248910,19 @@ async function runCodexTurn(options, deps = {}) {
|
|
|
248814
248910
|
};
|
|
248815
248911
|
}
|
|
248816
248912
|
}
|
|
248913
|
+
async function stopCodexSession(threadId) {
|
|
248914
|
+
const session3 = sessions2.get(threadId);
|
|
248915
|
+
if (!session3)
|
|
248916
|
+
return false;
|
|
248917
|
+
await session3.client.stop();
|
|
248918
|
+
if (sessions2.get(threadId) === session3)
|
|
248919
|
+
sessions2.delete(threadId);
|
|
248920
|
+
return true;
|
|
248921
|
+
}
|
|
248817
248922
|
var sessions2, sessionCreations, DEFAULT_IDLE_TIMEOUT_MS, CODEX_NOT_SIGNED_IN_ERROR = "Codex is not signed in. Run `codex login` on this computer.";
|
|
248818
248923
|
var init_codex_app_server = __esm(() => {
|
|
248819
248924
|
init_subagent_process();
|
|
248820
248925
|
init_native_cli_env();
|
|
248821
|
-
init_package_manager_spawn();
|
|
248822
248926
|
init_codex_app_server_payloads();
|
|
248823
248927
|
init_external_llm_trace_launch();
|
|
248824
248928
|
init_external_llm_trace_session();
|
|
@@ -250545,17 +250649,17 @@ function captureNativeSession(source, sessionId, scope, env6 = process.env, requ
|
|
|
250545
250649
|
return sealing.then(() => startDrain(state2, source, sessionId));
|
|
250546
250650
|
}
|
|
250547
250651
|
function getNativeSessionOwner(source, sessionId) {
|
|
250548
|
-
return
|
|
250652
|
+
return owners2.get(key3(source, sessionId));
|
|
250549
250653
|
}
|
|
250550
250654
|
function rememberNativeSession(source, sessionId, scope, cloudUrl = getServerUrl()) {
|
|
250551
250655
|
scavengeStaleSpoolDirectories();
|
|
250552
250656
|
const id2 = key3(source, sessionId);
|
|
250553
|
-
if (!
|
|
250554
|
-
|
|
250555
|
-
if (
|
|
250556
|
-
const oldest =
|
|
250657
|
+
if (!owners2.has(id2)) {
|
|
250658
|
+
owners2.set(id2, { ...scope });
|
|
250659
|
+
if (owners2.size > MAX_NATIVE_SESSION_OWNERS) {
|
|
250660
|
+
const oldest = owners2.keys().next().value;
|
|
250557
250661
|
if (oldest !== undefined)
|
|
250558
|
-
|
|
250662
|
+
owners2.delete(oldest);
|
|
250559
250663
|
}
|
|
250560
250664
|
}
|
|
250561
250665
|
if (!states2.has(id2) && UUID2.test(sessionId) && isCloudServerUrl(cloudUrl))
|
|
@@ -250575,7 +250679,7 @@ function reportNativeSessionCaptureFailure(source, sessionId, error5) {
|
|
|
250575
250679
|
const reason = error5 instanceof ApiRequestError ? `HTTP ${error5.status}` : error5 instanceof Error ? error5.name : "unknown error";
|
|
250576
250680
|
debugWarn("native-session", `${source} ${sessionId}: upload failed (${reason})`);
|
|
250577
250681
|
}
|
|
250578
|
-
var NativeChunkAcknowledgmentError, NativeSessionSourceGrowthError, states2, admissions, spoolDirectories, captureProcessInstanceId, activeInstanceRegistryKey, activeCaptureInstances, spoolDirectoryName, staleSpoolsScavenged = false, sealHookForTests, prefixVerificationHookForTests, drainHookForTests, NATIVE_SESSION_CAPTURE_CHUNK_BYTES, INITIAL_DRAIN_RETRY_MS = 250, MAX_DRAIN_RETRY_MS = 30000, SEAL_RETRY_DELAYS_MS, UUID2, MAX_NATIVE_SESSION_OWNERS = 1024,
|
|
250682
|
+
var NativeChunkAcknowledgmentError, NativeSessionSourceGrowthError, states2, admissions, spoolDirectories, captureProcessInstanceId, activeInstanceRegistryKey, activeCaptureInstances, spoolDirectoryName, staleSpoolsScavenged = false, sealHookForTests, prefixVerificationHookForTests, drainHookForTests, NATIVE_SESSION_CAPTURE_CHUNK_BYTES, INITIAL_DRAIN_RETRY_MS = 250, MAX_DRAIN_RETRY_MS = 30000, SEAL_RETRY_DELAYS_MS, UUID2, MAX_NATIVE_SESSION_OWNERS = 1024, owners2;
|
|
250579
250683
|
var init_native_session_capture = __esm(() => {
|
|
250580
250684
|
init_request();
|
|
250581
250685
|
init_server_url();
|
|
@@ -250613,7 +250717,7 @@ var init_native_session_capture = __esm(() => {
|
|
|
250613
250717
|
cleanupSpoolDirectorySync(directory);
|
|
250614
250718
|
}
|
|
250615
250719
|
});
|
|
250616
|
-
|
|
250720
|
+
owners2 = new Map;
|
|
250617
250721
|
});
|
|
250618
250722
|
|
|
250619
250723
|
// src/tools/impl/opencode-server.ts
|
|
@@ -252704,7 +252808,7 @@ async function fetchParentConversationMessages(params) {
|
|
|
252704
252808
|
}
|
|
252705
252809
|
return messages;
|
|
252706
252810
|
}
|
|
252707
|
-
function
|
|
252811
|
+
function contentText3(content) {
|
|
252708
252812
|
if (typeof content === "string")
|
|
252709
252813
|
return content;
|
|
252710
252814
|
if (!Array.isArray(content))
|
|
@@ -252730,7 +252834,7 @@ function renderToolCall(call2) {
|
|
|
252730
252834
|
}
|
|
252731
252835
|
function renderToolResult(result3) {
|
|
252732
252836
|
const raw2 = result3.tool_return ?? result3.func_response;
|
|
252733
|
-
const text2 = typeof raw2 === "string" ? raw2 :
|
|
252837
|
+
const text2 = typeof raw2 === "string" ? raw2 : contentText3(raw2) || (raw2 == null ? "" : JSON.stringify(raw2));
|
|
252734
252838
|
return {
|
|
252735
252839
|
type: "tool_result",
|
|
252736
252840
|
call_id: result3.tool_call_id ?? undefined,
|
|
@@ -252766,11 +252870,11 @@ function userEvents(text2, speaker) {
|
|
|
252766
252870
|
function renderMessage(message2) {
|
|
252767
252871
|
switch (message2.message_type) {
|
|
252768
252872
|
case "user_message": {
|
|
252769
|
-
const text2 =
|
|
252873
|
+
const text2 = contentText3(message2.content).replace(SYSTEM_REMINDER_PATTERN, "").trim();
|
|
252770
252874
|
return userEvents(text2, message2.name ?? undefined);
|
|
252771
252875
|
}
|
|
252772
252876
|
case "assistant_message": {
|
|
252773
|
-
const text2 =
|
|
252877
|
+
const text2 = contentText3(message2.content).trim();
|
|
252774
252878
|
return text2 ? [
|
|
252775
252879
|
{
|
|
252776
252880
|
type: "message",
|
|
@@ -253862,6 +253966,8 @@ async function stopRemoteExternalCodingAgent(params, deps = {}) {
|
|
|
253862
253966
|
});
|
|
253863
253967
|
if (!response.success)
|
|
253864
253968
|
throw new Error(response.error ?? "Stop failed");
|
|
253969
|
+
if (!response.cleanup_confirmed)
|
|
253970
|
+
throw new Error("The remote listener did not confirm process cleanup; update that listener and retry");
|
|
253865
253971
|
return { stopped: response.stopped };
|
|
253866
253972
|
} finally {
|
|
253867
253973
|
client.close();
|
|
@@ -254068,12 +254174,44 @@ var init_kill_bash = __esm(() => {
|
|
|
254068
254174
|
init_process_manager();
|
|
254069
254175
|
});
|
|
254070
254176
|
|
|
254177
|
+
// src/tools/impl/stop-conversation-background.ts
|
|
254178
|
+
async function stopConversationBackground(scope) {
|
|
254179
|
+
const owned = [...backgroundProcesses].filter(([, process21]) => process21.runtimeScope?.conversationId === scope.conversationId && (scope.conversationId !== "default" || process21.runtimeScope.agentId === scope.agentId));
|
|
254180
|
+
for (const [, process21] of owned)
|
|
254181
|
+
process21.completionNotificationSuppressed = true;
|
|
254182
|
+
const failures = [];
|
|
254183
|
+
for (const [id2, process21] of owned) {
|
|
254184
|
+
await cancelMonitorBackup(id2);
|
|
254185
|
+
if (process21.status !== "running")
|
|
254186
|
+
continue;
|
|
254187
|
+
try {
|
|
254188
|
+
if (process21.terminate)
|
|
254189
|
+
process21.terminate();
|
|
254190
|
+
else if (!killBackgroundProcess(id2))
|
|
254191
|
+
throw new Error("Stop failed");
|
|
254192
|
+
if (process21.completion)
|
|
254193
|
+
await confirmProcessExit(process21.completion, id2);
|
|
254194
|
+
else if (!process21.kind)
|
|
254195
|
+
throw new Error("Process exit cannot be confirmed");
|
|
254196
|
+
} catch {
|
|
254197
|
+
failures.push(id2);
|
|
254198
|
+
}
|
|
254199
|
+
}
|
|
254200
|
+
if (failures.length)
|
|
254201
|
+
throw new Error(`Could not stop background tasks: ${failures.join(", ")}`);
|
|
254202
|
+
}
|
|
254203
|
+
var init_stop_conversation_background = __esm(() => {
|
|
254204
|
+
init_kill_bash();
|
|
254205
|
+
init_monitor_backup();
|
|
254206
|
+
init_process_manager();
|
|
254207
|
+
});
|
|
254208
|
+
|
|
254071
254209
|
// src/tools/impl/task-stop.ts
|
|
254072
254210
|
var exports_task_stop = {};
|
|
254073
254211
|
__export(exports_task_stop, {
|
|
254074
254212
|
task_stop: () => task_stop
|
|
254075
254213
|
});
|
|
254076
|
-
async function cancelRemoteRun(subagentId) {
|
|
254214
|
+
async function cancelRemoteRun(subagentId, allowIdle = false) {
|
|
254077
254215
|
const child = getSubagents().find((agent) => agent.id === subagentId);
|
|
254078
254216
|
const target2 = child?.conversationId === "default" ? child.agentId : child?.conversationId;
|
|
254079
254217
|
try {
|
|
@@ -254081,11 +254219,13 @@ async function cancelRemoteRun(subagentId) {
|
|
|
254081
254219
|
throw new Error("its conversation is not known yet");
|
|
254082
254220
|
const results = await getBackend().cancelConversation(target2);
|
|
254083
254221
|
const outcomes = Object.values(results);
|
|
254084
|
-
if (outcomes.length === 0 || outcomes.some((status) => status !== "cancelled")) {
|
|
254222
|
+
if (!allowIdle && outcomes.length === 0 || outcomes.some((status) => status !== "cancelled")) {
|
|
254085
254223
|
throw new Error("Cloud did not cancel every run");
|
|
254086
254224
|
}
|
|
254087
|
-
return { killed: true, output: "Cancelled the remote run" };
|
|
254225
|
+
return allowIdle ? { killed: true } : { killed: true, output: "Cancelled the remote run" };
|
|
254088
254226
|
} catch (error5) {
|
|
254227
|
+
if (allowIdle && error5 instanceof ApiRequestError && error5.status === 409)
|
|
254228
|
+
return { killed: true };
|
|
254089
254229
|
return {
|
|
254090
254230
|
killed: false,
|
|
254091
254231
|
output: `Couldn't cancel the remote run: ${getErrorMessage2(error5)}`
|
|
@@ -254105,17 +254245,45 @@ async function withTimeout3(promise2, timeoutMs) {
|
|
|
254105
254245
|
clearTimeout(timer);
|
|
254106
254246
|
}
|
|
254107
254247
|
}
|
|
254248
|
+
async function finishPendingWakeCancellation(task) {
|
|
254249
|
+
for (let attempt2 = 0;attempt2 < 2; attempt2++) {
|
|
254250
|
+
try {
|
|
254251
|
+
await task.cancelPendingWakes?.();
|
|
254252
|
+
task.cancelPendingWakes = undefined;
|
|
254253
|
+
return { killed: true };
|
|
254254
|
+
} catch (error5) {
|
|
254255
|
+
if (attempt2 === 1)
|
|
254256
|
+
return {
|
|
254257
|
+
killed: false,
|
|
254258
|
+
output: `The process stopped, but its wakes could not be cancelled: ${getErrorMessage2(error5)}. Retry TaskStop to cancel the wakes.`
|
|
254259
|
+
};
|
|
254260
|
+
}
|
|
254261
|
+
}
|
|
254262
|
+
return { killed: false };
|
|
254263
|
+
}
|
|
254108
254264
|
async function task_stop(args, deps = {}) {
|
|
254109
254265
|
validateRequiredParams(args, ["task_id"], "TaskStop");
|
|
254110
254266
|
const { task_id } = args;
|
|
254111
254267
|
const task = backgroundTasks.get(task_id);
|
|
254112
254268
|
if (task) {
|
|
254269
|
+
if (task.cancelPendingWakes)
|
|
254270
|
+
return finishPendingWakeCancellation(task);
|
|
254113
254271
|
if (task.status === "running" && task.abortController) {
|
|
254272
|
+
const initialStop = task.stop;
|
|
254114
254273
|
const child = getSubagents().find((agent) => agent.id === task.subagentId);
|
|
254115
254274
|
const external3 = parseExternalCodingAgentId(child?.agentId ?? undefined);
|
|
254116
254275
|
let remote;
|
|
254117
254276
|
let remoteExternalStopped = false;
|
|
254118
|
-
if (
|
|
254277
|
+
if (task.stop) {
|
|
254278
|
+
try {
|
|
254279
|
+
const result3 = await withTimeout3(task.stop(), deps.remoteStopTimeoutMs ?? REMOTE_STOP_TIMEOUT_MS);
|
|
254280
|
+
if (result3 === TIMED_OUT)
|
|
254281
|
+
throw new Error("The owning listener did not answer; the subagent may still be running");
|
|
254282
|
+
remote = { killed: true };
|
|
254283
|
+
} catch (error5) {
|
|
254284
|
+
remote = { killed: false, output: getErrorMessage2(error5) };
|
|
254285
|
+
}
|
|
254286
|
+
} else if (external3?.computer) {
|
|
254119
254287
|
try {
|
|
254120
254288
|
if (!task.runtimeScope)
|
|
254121
254289
|
throw new Error("its parent conversation is not known");
|
|
@@ -254143,22 +254311,73 @@ async function task_stop(args, deps = {}) {
|
|
|
254143
254311
|
output: `Couldn't stop the remote external subagent: ${getErrorMessage2(error5)}`
|
|
254144
254312
|
};
|
|
254145
254313
|
}
|
|
254146
|
-
} else if (task.remote) {
|
|
254147
|
-
remote = await cancelRemoteRun(task.subagentId);
|
|
254314
|
+
} else if (task.remote || !external3 && child?.conversationId) {
|
|
254315
|
+
remote = await cancelRemoteRun(task.subagentId, !task.remote);
|
|
254148
254316
|
}
|
|
254149
254317
|
if (remote && !remote.killed)
|
|
254150
254318
|
return remote;
|
|
254319
|
+
try {
|
|
254320
|
+
if (external3 && !external3.computer) {
|
|
254321
|
+
if (external3.type === "claude-code")
|
|
254322
|
+
await stopClaudeSession(external3.sessionId);
|
|
254323
|
+
if (external3.type === "codex")
|
|
254324
|
+
await stopCodexSession(external3.sessionId);
|
|
254325
|
+
}
|
|
254326
|
+
} catch (error5) {
|
|
254327
|
+
return { killed: false, output: getErrorMessage2(error5) };
|
|
254328
|
+
}
|
|
254151
254329
|
task.abortController.abort(remoteExternalStopped ? REMOTE_EXTERNAL_WORKER_STOPPED : undefined);
|
|
254152
254330
|
task.error = "Aborted by user";
|
|
254153
|
-
|
|
254154
|
-
|
|
254331
|
+
try {
|
|
254332
|
+
if (!task.completion && (task.remote || external3 || initialStop))
|
|
254333
|
+
throw new Error("Subagent process exit cannot be confirmed");
|
|
254334
|
+
const completionTimeoutMs = deps.completionTimeoutMs ?? (external3?.computer ? COMPLETION_TIMEOUT_MS : 1e4);
|
|
254335
|
+
const settled = task.completion ? await withTimeout3(task.completion, completionTimeoutMs) : undefined;
|
|
254336
|
+
if (settled === TIMED_OUT) {
|
|
254337
|
+
if (!remoteExternalStopped)
|
|
254338
|
+
throw new Error("Subagent process exit was not confirmed");
|
|
254339
|
+
task.status = "failed";
|
|
254340
|
+
scheduleBackgroundTaskCleanup(task_id);
|
|
254341
|
+
return {
|
|
254342
|
+
killed: true,
|
|
254343
|
+
output: `${remote?.output ?? "Stopped the task"}, but stopped waiting for its result after ${completionTimeoutMs / 1000}s`
|
|
254344
|
+
};
|
|
254345
|
+
}
|
|
254346
|
+
} catch (error5) {
|
|
254347
|
+
return { killed: false, output: getErrorMessage2(error5) };
|
|
254348
|
+
}
|
|
254349
|
+
if (task.stop && task.stop !== initialStop) {
|
|
254350
|
+
try {
|
|
254351
|
+
const result3 = await withTimeout3(task.stop(), deps.remoteStopTimeoutMs ?? REMOTE_STOP_TIMEOUT_MS);
|
|
254352
|
+
if (result3 === TIMED_OUT)
|
|
254353
|
+
throw new Error("The owning listener did not confirm cancellation");
|
|
254354
|
+
} catch (error5) {
|
|
254355
|
+
return { killed: false, output: getErrorMessage2(error5) };
|
|
254356
|
+
}
|
|
254357
|
+
}
|
|
254358
|
+
if (!external3 && !initialStop && child?.conversationId) {
|
|
254359
|
+
const agentId = child.agentId ?? child.parentAgentId;
|
|
254360
|
+
if (agentId) {
|
|
254361
|
+
const scope = { agentId, conversationId: child.conversationId };
|
|
254362
|
+
try {
|
|
254363
|
+
await stopConversationBackground(scope);
|
|
254364
|
+
} catch (error5) {
|
|
254365
|
+
return { killed: false, output: getErrorMessage2(error5) };
|
|
254366
|
+
}
|
|
254367
|
+
task.status = "failed";
|
|
254368
|
+
scheduleBackgroundTaskCleanup(task_id);
|
|
254369
|
+
task.cancelPendingWakes = () => runWithRuntimeContext({
|
|
254370
|
+
...scope,
|
|
254371
|
+
actingUserId: task.actingUserId ?? undefined,
|
|
254372
|
+
suppressActingUserFallback: task.actingUserId === null
|
|
254373
|
+
}, () => cancelConversationWakes(scope));
|
|
254374
|
+
const cleaned = await finishPendingWakeCancellation(task);
|
|
254375
|
+
if (!cleaned.killed)
|
|
254376
|
+
return cleaned;
|
|
254377
|
+
}
|
|
254378
|
+
}
|
|
254155
254379
|
task.status = "failed";
|
|
254156
254380
|
scheduleBackgroundTaskCleanup(task_id);
|
|
254157
|
-
if (settled === TIMED_OUT)
|
|
254158
|
-
return {
|
|
254159
|
-
killed: true,
|
|
254160
|
-
output: `${remote?.output ?? "Stopped the task"}, but stopped waiting for its result after ${completionTimeoutMs / 1000}s`
|
|
254161
|
-
};
|
|
254162
254381
|
return remote ?? { killed: true };
|
|
254163
254382
|
}
|
|
254164
254383
|
return { killed: false };
|
|
@@ -254182,26 +254401,32 @@ var REMOTE_STOP_TIMEOUT_MS = 30000, COMPLETION_TIMEOUT_MS = 5000, TIMED_OUT;
|
|
|
254182
254401
|
var init_task_stop = __esm(() => {
|
|
254183
254402
|
init_subagent_state();
|
|
254184
254403
|
init_backend2();
|
|
254404
|
+
init_request();
|
|
254405
|
+
init_runtime_context();
|
|
254406
|
+
init_claude_stream_session();
|
|
254407
|
+
init_codex_app_server();
|
|
254185
254408
|
init_external_coding_agent();
|
|
254186
254409
|
init_kill_bash();
|
|
254187
254410
|
init_process_manager();
|
|
254188
254411
|
init_remote_external_coding_agent();
|
|
254412
|
+
init_stop_conversation_background();
|
|
254413
|
+
init_wake();
|
|
254189
254414
|
TIMED_OUT = Symbol("timed out");
|
|
254190
254415
|
});
|
|
254191
254416
|
|
|
254192
254417
|
// src/tools/impl/task-abort-hook.ts
|
|
254193
254418
|
function buildBackgroundTaskAbortHook(taskId, abortController) {
|
|
254194
254419
|
const bgTask = backgroundTasks.get(taskId);
|
|
254195
|
-
const
|
|
254196
|
-
const failSafeAbort = () => !
|
|
254420
|
+
const isRemote = () => Boolean(bgTask?.remote || bgTask?.stop);
|
|
254421
|
+
const failSafeAbort = () => !isRemote() && abortController.abort();
|
|
254197
254422
|
const hook = () => {
|
|
254198
254423
|
Promise.resolve().then(() => (init_task_stop(), exports_task_stop)).then((m4) => m4.task_stop({ task_id: taskId })).then((result3) => {
|
|
254199
254424
|
if (!result3.killed)
|
|
254200
254425
|
failSafeAbort();
|
|
254201
|
-
settleInterruptedCancel(bgTask,
|
|
254426
|
+
settleInterruptedCancel(bgTask, isRemote(), result3.killed, hook);
|
|
254202
254427
|
}).catch(() => {
|
|
254203
254428
|
failSafeAbort();
|
|
254204
|
-
settleInterruptedCancel(bgTask,
|
|
254429
|
+
settleInterruptedCancel(bgTask, isRemote(), false, hook);
|
|
254205
254430
|
});
|
|
254206
254431
|
};
|
|
254207
254432
|
return hook;
|
|
@@ -453596,12 +453821,12 @@ function rowToolCalls(row, index, diagnostics2) {
|
|
|
453596
453821
|
}
|
|
453597
453822
|
return calls;
|
|
453598
453823
|
}
|
|
453599
|
-
function
|
|
453824
|
+
function contentText4(content) {
|
|
453600
453825
|
if (typeof content === "string") {
|
|
453601
453826
|
if (content.startsWith(CONTENT_JSON_PREFIX)) {
|
|
453602
453827
|
const encoded = content.slice(CONTENT_JSON_PREFIX.length);
|
|
453603
453828
|
try {
|
|
453604
|
-
return
|
|
453829
|
+
return contentText4(JSON.parse(encoded));
|
|
453605
453830
|
} catch {
|
|
453606
453831
|
return encoded;
|
|
453607
453832
|
}
|
|
@@ -453687,7 +453912,7 @@ var init_hermes = __esm(() => {
|
|
|
453687
453912
|
});
|
|
453688
453913
|
};
|
|
453689
453914
|
if (row.role === "user") {
|
|
453690
|
-
const content =
|
|
453915
|
+
const content = contentText4(row.content);
|
|
453691
453916
|
if (content) {
|
|
453692
453917
|
emit({
|
|
453693
453918
|
type: "message",
|
|
@@ -453707,7 +453932,7 @@ var init_hermes = __esm(() => {
|
|
|
453707
453932
|
...timestamp ? { timestamp } : {}
|
|
453708
453933
|
});
|
|
453709
453934
|
}
|
|
453710
|
-
const content =
|
|
453935
|
+
const content = contentText4(row.content);
|
|
453711
453936
|
if (content) {
|
|
453712
453937
|
emit({
|
|
453713
453938
|
type: "message",
|
|
@@ -453730,7 +453955,7 @@ var init_hermes = __esm(() => {
|
|
|
453730
453955
|
if (row.role === "tool") {
|
|
453731
453956
|
emit({
|
|
453732
453957
|
type: "tool_result",
|
|
453733
|
-
content:
|
|
453958
|
+
content: contentText4(row.content),
|
|
453734
453959
|
...typeof row.tool_call_id === "string" && row.tool_call_id ? { callId: row.tool_call_id } : {},
|
|
453735
453960
|
...timestamp ? { timestamp } : {}
|
|
453736
453961
|
});
|
|
@@ -461355,7 +461580,9 @@ async function handleAbortMessageInput(listener, params, deps = {}) {
|
|
|
461355
461580
|
scheduleQueuePump,
|
|
461356
461581
|
cancelConversation: async (agentId, conversationId) => {
|
|
461357
461582
|
const cancelId = conversationId === "default" || !conversationId ? agentId : conversationId;
|
|
461358
|
-
await getBackend().cancelConversation(cancelId);
|
|
461583
|
+
const results = await getBackend().cancelConversation(cancelId);
|
|
461584
|
+
if (!Object.values(results).length || Object.values(results).some((value) => value !== "cancelled"))
|
|
461585
|
+
throw new Error("Backend did not confirm cancellation of every run");
|
|
461359
461586
|
},
|
|
461360
461587
|
cancelRun: async (agentId, runId) => {
|
|
461361
461588
|
const result3 = await getBackend().cancelRun(agentId, runId);
|
|
@@ -461459,16 +461686,32 @@ async function handleAbortMessageInput(listener, params, deps = {}) {
|
|
|
461459
461686
|
const cancelAgentId = scopedRuntime.agentId;
|
|
461460
461687
|
const cancelRunId = interruptedRunId ?? params.command.run_id ?? null;
|
|
461461
461688
|
const backendCancellation = cancelAgentId && cancelRunId ? resolvedDeps.cancelRun(cancelAgentId, cancelRunId).catch(() => resolvedDeps.cancelConversation(cancelAgentId, cancelConversationId)) : cancelAgentId ? resolvedDeps.cancelConversation(cancelAgentId, cancelConversationId) : resolvedDeps.cancelConversationRun(cancelConversationId, cancelRunId);
|
|
461462
|
-
|
|
461689
|
+
const pumpQueue = () => resolvedDeps.scheduleQueuePump(scopedRuntime, params.socket, params.opts, params.processQueuedTurn);
|
|
461690
|
+
const settlementPromise = backendCancellation.finally(() => {
|
|
461463
461691
|
if (!cancellation.lease) {
|
|
461464
461692
|
return;
|
|
461465
461693
|
}
|
|
461466
461694
|
const settlement = scopedRuntime.turnLifecycle.settleCancellation(cancellation.lease);
|
|
461467
|
-
if (settlement.released)
|
|
461468
|
-
|
|
461469
|
-
}
|
|
461695
|
+
if (settlement.released && !params.confirmBackendCancellation)
|
|
461696
|
+
pumpQueue();
|
|
461470
461697
|
});
|
|
461471
|
-
|
|
461698
|
+
try {
|
|
461699
|
+
if (params.confirmBackendCancellation) {
|
|
461700
|
+
await settlementPromise;
|
|
461701
|
+
const deadline = Date.now() + 1e4;
|
|
461702
|
+
while (cancellation.lease && scopedRuntime.turnLifecycle.isCurrent(cancellation.lease)) {
|
|
461703
|
+
if (Date.now() >= deadline)
|
|
461704
|
+
throw new Error("The listener turn did not stop");
|
|
461705
|
+
await new Promise((resolve39) => setTimeout(resolve39, 20));
|
|
461706
|
+
}
|
|
461707
|
+
} else {
|
|
461708
|
+
settlementPromise.catch(() => {
|
|
461709
|
+
return;
|
|
461710
|
+
});
|
|
461711
|
+
}
|
|
461712
|
+
} finally {
|
|
461713
|
+
pumpQueue();
|
|
461714
|
+
}
|
|
461472
461715
|
return true;
|
|
461473
461716
|
}
|
|
461474
461717
|
async function handleCwdChange(msg, socket, runtime) {
|
|
@@ -462087,7 +462330,14 @@ function isSubagentMessageCommand(value) {
|
|
|
462087
462330
|
return typeof value.message === "string" && value.message.trim().length > 0 && (value.tool_call_id === undefined || typeof value.tool_call_id === "string" && value.tool_call_id.trim().length > 0);
|
|
462088
462331
|
}
|
|
462089
462332
|
function isSubagentStopCommand(value) {
|
|
462090
|
-
|
|
462333
|
+
if (!hasValidControlBase(value) || value.type !== "subagent_stop")
|
|
462334
|
+
return false;
|
|
462335
|
+
if (value.client_message_id !== undefined && (typeof value.client_message_id !== "string" || !value.client_message_id.trim()))
|
|
462336
|
+
return false;
|
|
462337
|
+
if (value.conversation === undefined)
|
|
462338
|
+
return true;
|
|
462339
|
+
const scope = value.conversation;
|
|
462340
|
+
return Boolean(scope && typeof scope === "object" && typeof scope.conversation_id === "string" && (scope.agent_id === null || typeof scope.agent_id === "string"));
|
|
462091
462341
|
}
|
|
462092
462342
|
function isReadSubagentEventsCommand(value) {
|
|
462093
462343
|
if (!value || typeof value !== "object")
|
|
@@ -469116,6 +469366,60 @@ var init_skills_agents = __esm(() => {
|
|
|
469116
469366
|
init_protocol_inbound();
|
|
469117
469367
|
});
|
|
469118
469368
|
|
|
469369
|
+
// src/websocket/listener/commands/stop-conversation.ts
|
|
469370
|
+
async function stopListenerConversation(command, abort, deps = {}) {
|
|
469371
|
+
const base2 = {
|
|
469372
|
+
type: "subagent_stop_response",
|
|
469373
|
+
request_id: command.request_id,
|
|
469374
|
+
runtime: command.runtime,
|
|
469375
|
+
agent_id: command.agent_id,
|
|
469376
|
+
success: false,
|
|
469377
|
+
stopped: false
|
|
469378
|
+
};
|
|
469379
|
+
const scope = command.conversation;
|
|
469380
|
+
if (!scope || scope.conversation_id !== command.runtime.conversation_id || scope.agent_id && scope.agent_id !== command.runtime.agent_id)
|
|
469381
|
+
return {
|
|
469382
|
+
...base2,
|
|
469383
|
+
error: "Stop conversation does not match the control scope"
|
|
469384
|
+
};
|
|
469385
|
+
const backgroundScope = {
|
|
469386
|
+
agentId: scope.agent_id ?? command.runtime.agent_id,
|
|
469387
|
+
conversationId: scope.conversation_id
|
|
469388
|
+
};
|
|
469389
|
+
try {
|
|
469390
|
+
const results = await Promise.allSettled([
|
|
469391
|
+
stopConversationBackground(backgroundScope),
|
|
469392
|
+
abort(scope)
|
|
469393
|
+
]);
|
|
469394
|
+
for (const result3 of results)
|
|
469395
|
+
if (result3.status === "rejected")
|
|
469396
|
+
throw result3.reason;
|
|
469397
|
+
const aborted2 = results[1]?.status === "fulfilled" && results[1].value;
|
|
469398
|
+
if (!aborted2) {
|
|
469399
|
+
try {
|
|
469400
|
+
const results2 = await getBackend().cancelConversation(scope.conversation_id);
|
|
469401
|
+
if (Object.values(results2).some((value) => value !== "cancelled"))
|
|
469402
|
+
throw new Error("Backend did not confirm cancellation of every run");
|
|
469403
|
+
} catch (error5) {
|
|
469404
|
+
if (!(error5 instanceof ApiRequestError && error5.status === 409))
|
|
469405
|
+
throw error5;
|
|
469406
|
+
}
|
|
469407
|
+
}
|
|
469408
|
+
await stopConversationBackground(backgroundScope);
|
|
469409
|
+
await runWithRuntimeContext({ ...backgroundScope, actingUserId: command.runtime.acting_user_id }, () => (deps.cancelWakes ?? cancelConversationWakes)(backgroundScope));
|
|
469410
|
+
return { ...base2, success: true, stopped: true, cleanup_confirmed: true };
|
|
469411
|
+
} catch (error5) {
|
|
469412
|
+
return { ...base2, error: getErrorMessage2(error5) };
|
|
469413
|
+
}
|
|
469414
|
+
}
|
|
469415
|
+
var init_stop_conversation = __esm(() => {
|
|
469416
|
+
init_backend2();
|
|
469417
|
+
init_request();
|
|
469418
|
+
init_runtime_context();
|
|
469419
|
+
init_stop_conversation_background();
|
|
469420
|
+
init_wake();
|
|
469421
|
+
});
|
|
469422
|
+
|
|
469119
469423
|
// src/websocket/listener/input-ack.ts
|
|
469120
469424
|
function acknowledgeInputFrame(send, socket, frame, accepted, error5, disposition, deliveryHandling, mayRecreateOwner, extras) {
|
|
469121
469425
|
let duplicateOwnerLive;
|
|
@@ -470196,18 +470500,46 @@ async function handleSubagentStopCommand(command, parent) {
|
|
|
470196
470500
|
if (parent.agentId !== command.runtime.agent_id || parent.conversationId !== command.runtime.conversation_id)
|
|
470197
470501
|
return { ...base2, error: "Parent runtime does not match the stop request" };
|
|
470198
470502
|
const owned = findOwnedTask(parent, command.agent_id);
|
|
470503
|
+
let nativeStopped = false;
|
|
470504
|
+
if (!owned && ownsNativeSession(parent, command.agent_id)) {
|
|
470505
|
+
const target2 = parseExternalCodingAgentId(command.agent_id);
|
|
470506
|
+
try {
|
|
470507
|
+
if (target2 && !target2.computer) {
|
|
470508
|
+
if (target2.type === "claude-code")
|
|
470509
|
+
nativeStopped = await stopClaudeSession(target2.sessionId);
|
|
470510
|
+
if (target2.type === "codex")
|
|
470511
|
+
nativeStopped = await stopCodexSession(target2.sessionId);
|
|
470512
|
+
}
|
|
470513
|
+
} catch (error5) {
|
|
470514
|
+
return {
|
|
470515
|
+
...base2,
|
|
470516
|
+
error: error5 instanceof Error ? error5.message : String(error5)
|
|
470517
|
+
};
|
|
470518
|
+
}
|
|
470519
|
+
}
|
|
470199
470520
|
if (!owned) {
|
|
470200
470521
|
if (ownsNativeSession(parent, command.agent_id))
|
|
470201
|
-
return {
|
|
470522
|
+
return {
|
|
470523
|
+
...base2,
|
|
470524
|
+
success: true,
|
|
470525
|
+
stopped: nativeStopped,
|
|
470526
|
+
cleanup_confirmed: true
|
|
470527
|
+
};
|
|
470202
470528
|
return { ...base2, error: "Subagent does not belong to this conversation" };
|
|
470203
470529
|
}
|
|
470204
|
-
const [, task2] = owned;
|
|
470530
|
+
const [taskId, task2] = owned;
|
|
470205
470531
|
if (task2.status !== "running")
|
|
470206
|
-
return { ...base2, success: true };
|
|
470532
|
+
return { ...base2, success: true, stopped: true, cleanup_confirmed: true };
|
|
470207
470533
|
if (!task2.abortController)
|
|
470208
470534
|
return { ...base2, error: "Subagent could not be stopped" };
|
|
470209
|
-
|
|
470210
|
-
return {
|
|
470535
|
+
const result3 = await task_stop({ task_id: taskId });
|
|
470536
|
+
return {
|
|
470537
|
+
...base2,
|
|
470538
|
+
success: result3.killed,
|
|
470539
|
+
stopped: result3.killed,
|
|
470540
|
+
cleanup_confirmed: result3.killed,
|
|
470541
|
+
error: result3.output
|
|
470542
|
+
};
|
|
470211
470543
|
}
|
|
470212
470544
|
var DEDUPE_TTL_MS = 30000, responses;
|
|
470213
470545
|
var init_subagent_control = __esm(() => {
|
|
@@ -470220,6 +470552,7 @@ var init_subagent_control = __esm(() => {
|
|
|
470220
470552
|
init_external_coding_agent_task();
|
|
470221
470553
|
init_native_session_capture();
|
|
470222
470554
|
init_process_manager();
|
|
470555
|
+
init_task_stop();
|
|
470223
470556
|
init_cwd();
|
|
470224
470557
|
responses = new Map;
|
|
470225
470558
|
});
|
|
@@ -470337,6 +470670,13 @@ async function handleTaskControlCommand(command, context3) {
|
|
|
470337
470670
|
safeSocketSend
|
|
470338
470671
|
} = context3;
|
|
470339
470672
|
const execute = async () => {
|
|
470673
|
+
if (command.type === "subagent_stop" && command.conversation) {
|
|
470674
|
+
const response2 = await stopListenerConversation(command, context3.abortConversation ?? (async () => {
|
|
470675
|
+
throw new Error("Listener cancellation is unavailable");
|
|
470676
|
+
}));
|
|
470677
|
+
safeSocketSend(socket, response2, response2.type, command.type);
|
|
470678
|
+
return;
|
|
470679
|
+
}
|
|
470340
470680
|
if (command.type === "monitor_stop") {
|
|
470341
470681
|
const response2 = await handleMonitorStopCommand(command, runtime);
|
|
470342
470682
|
safeSocketSend(socket, response2, response2.type, command.type);
|
|
@@ -470359,6 +470699,7 @@ async function handleTaskControlCommand(command, context3) {
|
|
|
470359
470699
|
}
|
|
470360
470700
|
var init_task_control = __esm(() => {
|
|
470361
470701
|
init_monitors();
|
|
470702
|
+
init_stop_conversation();
|
|
470362
470703
|
init_subagent_control();
|
|
470363
470704
|
init_subagent_events2();
|
|
470364
470705
|
init_subagents3();
|
|
@@ -470388,6 +470729,32 @@ function createListenerMessageHandler(params) {
|
|
|
470388
470729
|
} = params;
|
|
470389
470730
|
const connectionId = explicitConnectionId ?? opts.connectionId;
|
|
470390
470731
|
const lineageId = explicitLineageId ?? runtime.connections.get(connectionId)?.startupOwner.lineageId ?? connectionId ?? runtime.sessionId;
|
|
470732
|
+
const abortStoppedConversation = async (scope, command) => {
|
|
470733
|
+
const child = getOrCreateScopedRuntime2(runtime, scope.agent_id, scope.conversation_id);
|
|
470734
|
+
child.queueRuntime.pause();
|
|
470735
|
+
for (const item of [...child.queueRuntime.items]) {
|
|
470736
|
+
if (item.source === "task_notification" || item.source === "cron" || command.client_message_id !== undefined && item.clientMessageId === command.client_message_id)
|
|
470737
|
+
child.queueRuntime.removeItem(item.id);
|
|
470738
|
+
}
|
|
470739
|
+
return handleAbortMessageInput2(runtime, {
|
|
470740
|
+
command: {
|
|
470741
|
+
type: "abort_message",
|
|
470742
|
+
request_id: command.request_id,
|
|
470743
|
+
runtime: scope
|
|
470744
|
+
},
|
|
470745
|
+
socket,
|
|
470746
|
+
connectionId,
|
|
470747
|
+
opts,
|
|
470748
|
+
processQueuedTurn,
|
|
470749
|
+
confirmBackendCancellation: true
|
|
470750
|
+
});
|
|
470751
|
+
};
|
|
470752
|
+
const removeLocalStop = registerLocalSubagentStop(connectionId, (command) => {
|
|
470753
|
+
if (runtime !== getActiveRuntime() || runtime.intentionallyClosed)
|
|
470754
|
+
return;
|
|
470755
|
+
return stopListenerConversation(command, (scope) => abortStoppedConversation(scope, command));
|
|
470756
|
+
});
|
|
470757
|
+
socket.once?.("close", removeLocalStop);
|
|
470391
470758
|
return async (data) => {
|
|
470392
470759
|
if (!await waitForListenerConnectionStartup(runtime, connectionId, socket))
|
|
470393
470760
|
return;
|
|
@@ -470441,7 +470808,8 @@ function createListenerMessageHandler(params) {
|
|
|
470441
470808
|
connectionId,
|
|
470442
470809
|
getOrCreateScopedRuntime: getOrCreateScopedRuntime2,
|
|
470443
470810
|
runDetachedListenerTask: runDetachedListenerTask2,
|
|
470444
|
-
safeSocketSend
|
|
470811
|
+
safeSocketSend,
|
|
470812
|
+
abortConversation: parsed.type === "subagent_stop" ? (scope) => abortStoppedConversation(scope, parsed) : undefined
|
|
470445
470813
|
});
|
|
470446
470814
|
return;
|
|
470447
470815
|
}
|
|
@@ -470826,6 +471194,7 @@ function createListenerMessageHandler(params) {
|
|
|
470826
471194
|
var init_message_router = __esm(() => {
|
|
470827
471195
|
init_system_prompt_warning();
|
|
470828
471196
|
init_settings_manager();
|
|
471197
|
+
init_subagent_stop_bridge();
|
|
470829
471198
|
init_debug();
|
|
470830
471199
|
init_startup_log_boundary();
|
|
470831
471200
|
init_terminal_handler();
|
|
@@ -470846,6 +471215,7 @@ var init_message_router = __esm(() => {
|
|
|
470846
471215
|
init_secrets2();
|
|
470847
471216
|
init_settings3();
|
|
470848
471217
|
init_skills_agents();
|
|
471218
|
+
init_stop_conversation();
|
|
470849
471219
|
init_connection();
|
|
470850
471220
|
init_cwd();
|
|
470851
471221
|
init_external_tools();
|
|
@@ -543682,4 +544052,4 @@ function registerBunOAuthFlows() {
|
|
|
543682
544052
|
registerBunOAuthFlows();
|
|
543683
544053
|
await init_src5().then(() => exports_src2);
|
|
543684
544054
|
|
|
543685
|
-
//# debugId=
|
|
544055
|
+
//# debugId=CDC0C27D3A902ABD64756E2164756E21
|