@buildautomaton/cli 0.1.75 → 0.1.77
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/cli.js +196 -166
- package/dist/cli.js.map +4 -4
- package/dist/index.js +196 -166
- package/dist/index.js.map +4 -4
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -30606,7 +30606,7 @@ function installBridgeProcessResilience() {
|
|
|
30606
30606
|
}
|
|
30607
30607
|
|
|
30608
30608
|
// src/cli-version.ts
|
|
30609
|
-
var CLI_VERSION = "0.1.
|
|
30609
|
+
var CLI_VERSION = "0.1.77".length > 0 ? "0.1.77" : "0.0.0-dev";
|
|
30610
30610
|
|
|
30611
30611
|
// src/connection/heartbeat/constants.ts
|
|
30612
30612
|
var BRIDGE_APP_HEARTBEAT_INTERVAL_MS = 1e4;
|
|
@@ -33224,9 +33224,12 @@ function cancelPendingCursorPermissionRequests(pendingRequests2, respond) {
|
|
|
33224
33224
|
// src/agents/acp/clients/cursor/create-cursor-acp-handle.ts
|
|
33225
33225
|
function createCursorAcpHandle(options) {
|
|
33226
33226
|
let teardownStarted = false;
|
|
33227
|
+
let cancelFallback = null;
|
|
33227
33228
|
async function disconnectGracefully() {
|
|
33228
33229
|
if (teardownStarted) return;
|
|
33229
33230
|
teardownStarted = true;
|
|
33231
|
+
if (cancelFallback) clearTimeout(cancelFallback);
|
|
33232
|
+
cancelFallback = null;
|
|
33230
33233
|
cancelPendingCursorPermissionRequests(options.pendingRequests, options.wire.respond);
|
|
33231
33234
|
try {
|
|
33232
33235
|
await options.transport.cancelSession(options.sessionId);
|
|
@@ -33252,7 +33255,17 @@ function createCursorAcpHandle(options) {
|
|
|
33252
33255
|
},
|
|
33253
33256
|
async cancel() {
|
|
33254
33257
|
cancelPendingCursorPermissionRequests(options.pendingRequests, options.wire.respond);
|
|
33255
|
-
|
|
33258
|
+
try {
|
|
33259
|
+
await options.transport.cancelSession(options.sessionId);
|
|
33260
|
+
} catch {
|
|
33261
|
+
}
|
|
33262
|
+
if (cancelFallback) return;
|
|
33263
|
+
cancelFallback = setTimeout(() => {
|
|
33264
|
+
if (options.child.exitCode == null && options.child.signalCode == null) {
|
|
33265
|
+
void disconnectGracefully();
|
|
33266
|
+
}
|
|
33267
|
+
}, 5e3);
|
|
33268
|
+
cancelFallback.unref?.();
|
|
33256
33269
|
},
|
|
33257
33270
|
resolveRequest(requestId, result) {
|
|
33258
33271
|
if (options.pendingRequests.has(requestId)) {
|
|
@@ -35008,6 +35021,66 @@ function augmentPromptResultAuthFields(agentType, errorText) {
|
|
|
35008
35021
|
return { agentAuthRequired: true, agentType };
|
|
35009
35022
|
}
|
|
35010
35023
|
|
|
35024
|
+
// src/agents/planning/submit-planning-todos-for-turn.ts
|
|
35025
|
+
async function submitPlanningTodosForTurn(params) {
|
|
35026
|
+
const token = params.getCloudAccessToken();
|
|
35027
|
+
if (!token.trim()) return { ok: false, error: "Missing cloud access token" };
|
|
35028
|
+
const base = params.cloudApiBaseUrl.replace(/\/$/, "");
|
|
35029
|
+
const url2 = `${base}/internal/sessions/todos/submit`;
|
|
35030
|
+
const res = await fetch(url2, {
|
|
35031
|
+
method: "POST",
|
|
35032
|
+
headers: {
|
|
35033
|
+
Authorization: `Bearer ${token}`,
|
|
35034
|
+
"Content-Type": "application/json"
|
|
35035
|
+
},
|
|
35036
|
+
body: JSON.stringify({
|
|
35037
|
+
sessionId: params.sessionId,
|
|
35038
|
+
turnId: params.turnId,
|
|
35039
|
+
items: params.items
|
|
35040
|
+
})
|
|
35041
|
+
});
|
|
35042
|
+
if (!res.ok) {
|
|
35043
|
+
const body = await res.json().catch(() => null);
|
|
35044
|
+
return { ok: false, error: body?.error ?? `Planning todo submit failed (${res.status})` };
|
|
35045
|
+
}
|
|
35046
|
+
return { ok: true };
|
|
35047
|
+
}
|
|
35048
|
+
|
|
35049
|
+
// src/agents/planning/maybe-submit-planning-todos-after-agent-success.ts
|
|
35050
|
+
async function maybeSubmitPlanningTodosAfterAgentSuccess(params) {
|
|
35051
|
+
const { sessionId, runId, resultSuccess, output, cloudApiBaseUrl, getCloudAccessToken, log: log2 } = params;
|
|
35052
|
+
const buffered = runId ? getPlanningSessionTurnOutput(runId) : "";
|
|
35053
|
+
const outputFromResult = typeof output === "string" ? output : "";
|
|
35054
|
+
const outputStr = buffered.trim() !== "" ? buffered : outputFromResult;
|
|
35055
|
+
if (!sessionId || !runId || !resultSuccess || outputStr.trim() === "") {
|
|
35056
|
+
return { submitted: false, suppressOutput: false };
|
|
35057
|
+
}
|
|
35058
|
+
if (!cloudApiBaseUrl || !getCloudAccessToken) {
|
|
35059
|
+
return { submitted: false, suppressOutput: false };
|
|
35060
|
+
}
|
|
35061
|
+
const items = parsePlanningTodoAgentJson(outputStr);
|
|
35062
|
+
if (items.length === 0) {
|
|
35063
|
+
return { submitted: false, suppressOutput: false };
|
|
35064
|
+
}
|
|
35065
|
+
const result = await submitPlanningTodosForTurn({
|
|
35066
|
+
sessionId,
|
|
35067
|
+
turnId: runId,
|
|
35068
|
+
items,
|
|
35069
|
+
cloudApiBaseUrl,
|
|
35070
|
+
getCloudAccessToken
|
|
35071
|
+
});
|
|
35072
|
+
if (!result.ok) {
|
|
35073
|
+
log2(`[Agent] Planning todo submit failed: ${result.error}`);
|
|
35074
|
+
return { submitted: false, suppressOutput: false };
|
|
35075
|
+
}
|
|
35076
|
+
if (runId) consumePlanningSessionTurnOutput(runId);
|
|
35077
|
+
log2(`[Agent] Planning session: stored ${items.length} todo(s) via internal API`);
|
|
35078
|
+
return { submitted: true, suppressOutput: true };
|
|
35079
|
+
}
|
|
35080
|
+
|
|
35081
|
+
// src/agents/acp/prompts/report-post-turn-enrichment.ts
|
|
35082
|
+
init_yield_to_event_loop();
|
|
35083
|
+
|
|
35011
35084
|
// src/git/git-runtime.ts
|
|
35012
35085
|
init_cli_process_interrupt();
|
|
35013
35086
|
var activeGitChildProcesses = /* @__PURE__ */ new Set();
|
|
@@ -35344,6 +35417,7 @@ async function loadPreTurnSnapshot(options) {
|
|
|
35344
35417
|
}
|
|
35345
35418
|
return data;
|
|
35346
35419
|
} catch (e) {
|
|
35420
|
+
if (e.code === "ENOENT") return null;
|
|
35347
35421
|
log2(
|
|
35348
35422
|
`[turn-diff] No pre-turn snapshot for run ${runId.slice(0, 8)}\u2026: ${e instanceof Error ? e.message : String(e)}`
|
|
35349
35423
|
);
|
|
@@ -35369,61 +35443,30 @@ async function collectTurnGitDiffFromPreTurnSnapshot(options) {
|
|
|
35369
35443
|
});
|
|
35370
35444
|
}
|
|
35371
35445
|
|
|
35372
|
-
// src/agents/
|
|
35373
|
-
|
|
35374
|
-
|
|
35375
|
-
|
|
35376
|
-
|
|
35377
|
-
|
|
35378
|
-
|
|
35379
|
-
|
|
35380
|
-
|
|
35381
|
-
|
|
35382
|
-
|
|
35383
|
-
|
|
35384
|
-
|
|
35385
|
-
|
|
35386
|
-
|
|
35387
|
-
|
|
35388
|
-
|
|
35389
|
-
|
|
35390
|
-
|
|
35391
|
-
|
|
35392
|
-
|
|
35393
|
-
}
|
|
35394
|
-
|
|
35395
|
-
}
|
|
35396
|
-
|
|
35397
|
-
// src/agents/planning/maybe-submit-planning-todos-after-agent-success.ts
|
|
35398
|
-
async function maybeSubmitPlanningTodosAfterAgentSuccess(params) {
|
|
35399
|
-
const { sessionId, runId, resultSuccess, output, cloudApiBaseUrl, getCloudAccessToken, log: log2 } = params;
|
|
35400
|
-
const buffered = runId ? getPlanningSessionTurnOutput(runId) : "";
|
|
35401
|
-
const outputFromResult = typeof output === "string" ? output : "";
|
|
35402
|
-
const outputStr = buffered.trim() !== "" ? buffered : outputFromResult;
|
|
35403
|
-
if (!sessionId || !runId || !resultSuccess || outputStr.trim() === "") {
|
|
35404
|
-
return { submitted: false, suppressOutput: false };
|
|
35405
|
-
}
|
|
35406
|
-
if (!cloudApiBaseUrl || !getCloudAccessToken) {
|
|
35407
|
-
return { submitted: false, suppressOutput: false };
|
|
35408
|
-
}
|
|
35409
|
-
const items = parsePlanningTodoAgentJson(outputStr);
|
|
35410
|
-
if (items.length === 0) {
|
|
35411
|
-
return { submitted: false, suppressOutput: false };
|
|
35412
|
-
}
|
|
35413
|
-
const result = await submitPlanningTodosForTurn({
|
|
35414
|
-
sessionId,
|
|
35415
|
-
turnId: runId,
|
|
35416
|
-
items,
|
|
35417
|
-
cloudApiBaseUrl,
|
|
35418
|
-
getCloudAccessToken
|
|
35446
|
+
// src/agents/acp/prompts/report-post-turn-enrichment.ts
|
|
35447
|
+
function reportPostTurnEnrichment(options) {
|
|
35448
|
+
void (async () => {
|
|
35449
|
+
const {
|
|
35450
|
+
sessionId,
|
|
35451
|
+
runId,
|
|
35452
|
+
agentCwd,
|
|
35453
|
+
result,
|
|
35454
|
+
sendSessionUpdate,
|
|
35455
|
+
log: log2
|
|
35456
|
+
} = options;
|
|
35457
|
+
await yieldToEventLoop();
|
|
35458
|
+
if (sessionId && runId && sendSessionUpdate && agentCwd && result.success) {
|
|
35459
|
+
await collectTurnGitDiffFromPreTurnSnapshot({
|
|
35460
|
+
sessionId,
|
|
35461
|
+
runId,
|
|
35462
|
+
agentCwd,
|
|
35463
|
+
sendSessionUpdate,
|
|
35464
|
+
log: log2
|
|
35465
|
+
});
|
|
35466
|
+
}
|
|
35467
|
+
})().catch((error40) => {
|
|
35468
|
+
options.log(`[Agent] Post-turn enrichment failed: ${error40 instanceof Error ? error40.message : String(error40)}`);
|
|
35419
35469
|
});
|
|
35420
|
-
if (!result.ok) {
|
|
35421
|
-
log2(`[Agent] Planning todo submit failed: ${result.error}`);
|
|
35422
|
-
return { submitted: false, suppressOutput: false };
|
|
35423
|
-
}
|
|
35424
|
-
if (runId) consumePlanningSessionTurnOutput(runId);
|
|
35425
|
-
log2(`[Agent] Planning session: stored ${items.length} todo(s) via internal API`);
|
|
35426
|
-
return { submitted: true, suppressOutput: true };
|
|
35427
35470
|
}
|
|
35428
35471
|
|
|
35429
35472
|
// src/agents/acp/prompts/finalize-and-send-prompt-result.ts
|
|
@@ -35443,16 +35486,7 @@ async function finalizeAndSendPromptResult(params) {
|
|
|
35443
35486
|
sendSessionUpdate,
|
|
35444
35487
|
log: log2
|
|
35445
35488
|
} = params;
|
|
35446
|
-
|
|
35447
|
-
await collectTurnGitDiffFromPreTurnSnapshot({
|
|
35448
|
-
sessionId,
|
|
35449
|
-
runId,
|
|
35450
|
-
agentCwd,
|
|
35451
|
-
sendSessionUpdate,
|
|
35452
|
-
log: log2
|
|
35453
|
-
});
|
|
35454
|
-
}
|
|
35455
|
-
const planningTodosSubmit = await maybeSubmitPlanningTodosAfterAgentSuccess({
|
|
35489
|
+
const planningTodosSubmit = isPlanningSession ? await maybeSubmitPlanningTodosAfterAgentSuccess({
|
|
35456
35490
|
sessionId,
|
|
35457
35491
|
runId,
|
|
35458
35492
|
resultSuccess: result.success === true,
|
|
@@ -35460,11 +35494,11 @@ async function finalizeAndSendPromptResult(params) {
|
|
|
35460
35494
|
cloudApiBaseUrl,
|
|
35461
35495
|
getCloudAccessToken,
|
|
35462
35496
|
log: log2
|
|
35463
|
-
});
|
|
35497
|
+
}) : { suppressOutput: false };
|
|
35498
|
+
const planningFallbackOutput = !planningTodosSubmit.suppressOutput && isPlanningSession && runId ? consumePlanningSessionTurnOutput(runId) : "";
|
|
35464
35499
|
const errStr = typeof result.error === "string" ? result.error : void 0;
|
|
35465
35500
|
const resultStop = typeof result.stopReason === "string" ? result.stopReason.trim() : "";
|
|
35466
35501
|
const cancelledByAgent = resultStop.toLowerCase() === "cancelled" || errStr != null && isUserEndedSessionTurnErrorText(errStr);
|
|
35467
|
-
const planningFallbackOutput = !planningTodosSubmit.suppressOutput && isPlanningSession && runId ? consumePlanningSessionTurnOutput(runId) : "";
|
|
35468
35502
|
sendResult({
|
|
35469
35503
|
type: "prompt_result",
|
|
35470
35504
|
id: promptId,
|
|
@@ -35485,6 +35519,14 @@ async function finalizeAndSendPromptResult(params) {
|
|
|
35485
35519
|
);
|
|
35486
35520
|
}
|
|
35487
35521
|
}
|
|
35522
|
+
void reportPostTurnEnrichment({
|
|
35523
|
+
sessionId,
|
|
35524
|
+
runId,
|
|
35525
|
+
agentCwd,
|
|
35526
|
+
result,
|
|
35527
|
+
sendSessionUpdate,
|
|
35528
|
+
log: log2
|
|
35529
|
+
});
|
|
35488
35530
|
}
|
|
35489
35531
|
|
|
35490
35532
|
// src/agents/acp/build-forked-session-agent-prompt.ts
|
|
@@ -36033,7 +36075,6 @@ async function sendPromptToAgent(options) {
|
|
|
36033
36075
|
followUpCatalogPromptId,
|
|
36034
36076
|
cloudApiBaseUrl,
|
|
36035
36077
|
getCloudAccessToken,
|
|
36036
|
-
e2ee,
|
|
36037
36078
|
sendResult,
|
|
36038
36079
|
sendSessionUpdate,
|
|
36039
36080
|
log: log2
|
|
@@ -36056,16 +36097,6 @@ async function sendPromptToAgent(options) {
|
|
|
36056
36097
|
}
|
|
36057
36098
|
}
|
|
36058
36099
|
|
|
36059
|
-
// src/agents/acp/manager/get-acp-agent-state.ts
|
|
36060
|
-
function getAcpSessionAgentState(ctx, acpSessionAgentKey) {
|
|
36061
|
-
let state = ctx.acpAgents.get(acpSessionAgentKey);
|
|
36062
|
-
if (!state) {
|
|
36063
|
-
state = createEmptyAcpClientState();
|
|
36064
|
-
ctx.acpAgents.set(acpSessionAgentKey, state);
|
|
36065
|
-
}
|
|
36066
|
-
return state;
|
|
36067
|
-
}
|
|
36068
|
-
|
|
36069
36100
|
// src/agents/acp/manager/handle-pending-prompt-cancel.ts
|
|
36070
36101
|
async function handlePendingPromptCancel(params) {
|
|
36071
36102
|
const { ctx, activeRunId, promptId, sessionId, handle, sendResult } = params;
|
|
@@ -36089,94 +36120,104 @@ async function handlePendingPromptCancel(params) {
|
|
|
36089
36120
|
return true;
|
|
36090
36121
|
}
|
|
36091
36122
|
|
|
36092
|
-
// src/agents/acp/manager/
|
|
36093
|
-
async function
|
|
36094
|
-
const {
|
|
36095
|
-
|
|
36096
|
-
|
|
36097
|
-
sessionId,
|
|
36098
|
-
mode,
|
|
36099
|
-
agentConfig,
|
|
36100
|
-
sessionParentPath,
|
|
36101
|
-
sendResult,
|
|
36102
|
-
sendSessionUpdate,
|
|
36103
|
-
followUpCatalogPromptId,
|
|
36104
|
-
cloudApiBaseUrl,
|
|
36105
|
-
getCloudAccessToken,
|
|
36106
|
-
e2ee,
|
|
36107
|
-
attachments,
|
|
36108
|
-
isNewSession
|
|
36109
|
-
} = opts;
|
|
36110
|
-
const { activeRunId, activeAcpAgentKey, activeAcpSessionAgentKey, preferredForPrompt } = runCtx;
|
|
36111
|
-
const acpAgentState = getAcpSessionAgentState(ctx, activeAcpSessionAgentKey);
|
|
36112
|
-
const handle = await ensureAcpClient({
|
|
36113
|
-
state: acpAgentState,
|
|
36114
|
-
acpAgentKey: activeAcpAgentKey,
|
|
36115
|
-
preferredAgentType: preferredForPrompt,
|
|
36116
|
-
mode,
|
|
36117
|
-
agentConfig: agentConfig ?? null,
|
|
36118
|
-
sessionParentPath,
|
|
36119
|
-
resolveRouting: () => ctx.promptRouting.resolveRouting(activeAcpSessionAgentKey),
|
|
36120
|
-
cloudSessionId: sessionId,
|
|
36121
|
-
bridgeAccessPort: ctx.getBridgeAccessPort(),
|
|
36122
|
-
sendSessionUpdate,
|
|
36123
|
-
sendRequest: sendSessionUpdate,
|
|
36124
|
-
log: ctx.log,
|
|
36125
|
-
reportAgentCapabilities: ctx.reportAgentCapabilities
|
|
36126
|
-
});
|
|
36127
|
-
if (!handle) {
|
|
36128
|
-
const errMsg = acpAgentState.lastAcpStartError || "No agent configured. Register local agents on this bridge in the app.";
|
|
36129
|
-
const evaluated = Boolean(preferredForPrompt && errMsg.trim());
|
|
36130
|
-
const suggestsAuth = evaluated ? localAgentErrorSuggestsAuth(preferredForPrompt, errMsg) : false;
|
|
36131
|
-
const auth = suggestsAuth && preferredForPrompt ? { agentAuthRequired: true, agentType: preferredForPrompt } : {};
|
|
36132
|
-
sendResult({
|
|
36123
|
+
// src/agents/acp/manager/dispatch-acp-prompt.ts
|
|
36124
|
+
async function dispatchAcpPrompt(ctx, runCtx, opts, handle) {
|
|
36125
|
+
const { activeRunId, activeAcpSessionAgentKey, preferredForPrompt } = runCtx;
|
|
36126
|
+
if (!ctx.promptRouting.isRegisteredRun(activeRunId)) {
|
|
36127
|
+
opts.sendResult({
|
|
36133
36128
|
type: "prompt_result",
|
|
36134
|
-
id: promptId,
|
|
36135
|
-
...sessionId ? { sessionId } : {},
|
|
36129
|
+
id: opts.promptId,
|
|
36130
|
+
...opts.sessionId ? { sessionId: opts.sessionId } : {},
|
|
36136
36131
|
runId: activeRunId,
|
|
36137
36132
|
success: false,
|
|
36138
|
-
error:
|
|
36139
|
-
...auth
|
|
36133
|
+
error: "Prompt dispatch was superseded before the agent started."
|
|
36140
36134
|
});
|
|
36141
36135
|
return;
|
|
36142
36136
|
}
|
|
36143
|
-
if (!ctx.promptRouting.isRegisteredRun(activeRunId)) {
|
|
36144
|
-
return;
|
|
36145
|
-
}
|
|
36146
36137
|
const cancelled = await handlePendingPromptCancel({
|
|
36147
36138
|
ctx,
|
|
36148
36139
|
activeRunId,
|
|
36149
|
-
promptId,
|
|
36150
|
-
sessionId,
|
|
36140
|
+
promptId: opts.promptId,
|
|
36141
|
+
sessionId: opts.sessionId,
|
|
36151
36142
|
handle,
|
|
36152
|
-
sendResult
|
|
36143
|
+
sendResult: opts.sendResult
|
|
36153
36144
|
});
|
|
36154
36145
|
if (cancelled) return;
|
|
36155
36146
|
ctx.promptRouting.setStreamingRunId(activeAcpSessionAgentKey, activeRunId);
|
|
36156
36147
|
try {
|
|
36157
36148
|
await sendPromptToAgent({
|
|
36158
36149
|
handle,
|
|
36159
|
-
promptText,
|
|
36160
|
-
promptId,
|
|
36161
|
-
sessionId,
|
|
36150
|
+
promptText: opts.promptText,
|
|
36151
|
+
promptId: opts.promptId,
|
|
36152
|
+
sessionId: opts.sessionId,
|
|
36162
36153
|
runId: activeRunId,
|
|
36163
36154
|
agentType: preferredForPrompt,
|
|
36164
|
-
agentCwd: resolveSessionParentPathForAgentProcess(sessionParentPath),
|
|
36165
|
-
sendResult,
|
|
36166
|
-
sendSessionUpdate,
|
|
36155
|
+
agentCwd: resolveSessionParentPathForAgentProcess(opts.sessionParentPath),
|
|
36156
|
+
sendResult: opts.sendResult,
|
|
36157
|
+
sendSessionUpdate: opts.sendSessionUpdate,
|
|
36167
36158
|
log: ctx.log,
|
|
36168
|
-
followUpCatalogPromptId,
|
|
36169
|
-
cloudApiBaseUrl,
|
|
36170
|
-
getCloudAccessToken,
|
|
36171
|
-
e2ee,
|
|
36172
|
-
attachments,
|
|
36173
|
-
isNewSession
|
|
36159
|
+
followUpCatalogPromptId: opts.followUpCatalogPromptId,
|
|
36160
|
+
cloudApiBaseUrl: opts.cloudApiBaseUrl,
|
|
36161
|
+
getCloudAccessToken: opts.getCloudAccessToken,
|
|
36162
|
+
e2ee: opts.e2ee,
|
|
36163
|
+
attachments: opts.attachments,
|
|
36164
|
+
isNewSession: opts.isNewSession
|
|
36174
36165
|
});
|
|
36175
36166
|
} finally {
|
|
36176
36167
|
ctx.promptRouting.clearStreamingRunId(activeAcpSessionAgentKey, activeRunId);
|
|
36177
36168
|
}
|
|
36178
36169
|
}
|
|
36179
36170
|
|
|
36171
|
+
// src/agents/acp/manager/get-acp-agent-state.ts
|
|
36172
|
+
function getAcpSessionAgentState(ctx, acpSessionAgentKey) {
|
|
36173
|
+
let state = ctx.acpAgents.get(acpSessionAgentKey);
|
|
36174
|
+
if (!state) {
|
|
36175
|
+
state = createEmptyAcpClientState();
|
|
36176
|
+
ctx.acpAgents.set(acpSessionAgentKey, state);
|
|
36177
|
+
}
|
|
36178
|
+
return state;
|
|
36179
|
+
}
|
|
36180
|
+
|
|
36181
|
+
// src/agents/acp/manager/ensure-acp-prompt-client.ts
|
|
36182
|
+
async function ensureAcpPromptClient(ctx, runCtx, opts) {
|
|
36183
|
+
const state = getAcpSessionAgentState(ctx, runCtx.activeAcpSessionAgentKey);
|
|
36184
|
+
const handle = await ensureAcpClient({
|
|
36185
|
+
state,
|
|
36186
|
+
acpAgentKey: runCtx.activeAcpAgentKey,
|
|
36187
|
+
preferredAgentType: runCtx.preferredForPrompt,
|
|
36188
|
+
mode: opts.mode,
|
|
36189
|
+
agentConfig: opts.agentConfig ?? null,
|
|
36190
|
+
sessionParentPath: opts.sessionParentPath,
|
|
36191
|
+
resolveRouting: () => ctx.promptRouting.resolveRouting(runCtx.activeAcpSessionAgentKey),
|
|
36192
|
+
cloudSessionId: opts.sessionId,
|
|
36193
|
+
bridgeAccessPort: ctx.getBridgeAccessPort(),
|
|
36194
|
+
sendSessionUpdate: opts.sendSessionUpdate,
|
|
36195
|
+
sendRequest: opts.sendSessionUpdate,
|
|
36196
|
+
log: ctx.log,
|
|
36197
|
+
reportAgentCapabilities: ctx.reportAgentCapabilities
|
|
36198
|
+
});
|
|
36199
|
+
if (handle) return handle;
|
|
36200
|
+
const error40 = state.lastAcpStartError || "No agent configured. Register local agents on this bridge in the app.";
|
|
36201
|
+
const agentType = runCtx.preferredForPrompt;
|
|
36202
|
+
const requiresAuth = Boolean(agentType && localAgentErrorSuggestsAuth(agentType, error40));
|
|
36203
|
+
opts.sendResult({
|
|
36204
|
+
type: "prompt_result",
|
|
36205
|
+
id: opts.promptId,
|
|
36206
|
+
...opts.sessionId ? { sessionId: opts.sessionId } : {},
|
|
36207
|
+
runId: runCtx.activeRunId,
|
|
36208
|
+
success: false,
|
|
36209
|
+
error: error40,
|
|
36210
|
+
...requiresAuth && agentType ? { agentAuthRequired: true, agentType } : {}
|
|
36211
|
+
});
|
|
36212
|
+
return null;
|
|
36213
|
+
}
|
|
36214
|
+
|
|
36215
|
+
// src/agents/acp/manager/run-acp-prompt.ts
|
|
36216
|
+
async function runAcpPrompt(ctx, runCtx, opts) {
|
|
36217
|
+
const handle = await ensureAcpPromptClient(ctx, runCtx, opts);
|
|
36218
|
+
if (handle) await dispatchAcpPrompt(ctx, runCtx, opts, handle);
|
|
36219
|
+
}
|
|
36220
|
+
|
|
36180
36221
|
// src/agents/acp/manager/handle-prompt.ts
|
|
36181
36222
|
function handlePrompt(ctx, opts) {
|
|
36182
36223
|
const { promptId, sessionId, runId, mode, agentType, agentConfig, sendResult } = opts;
|
|
@@ -48869,15 +48910,18 @@ function dispatchLocalPrompt(next, deps) {
|
|
|
48869
48910
|
|
|
48870
48911
|
// src/prompt-turn-queue/runner/run-id-queue-key-map.ts
|
|
48871
48912
|
var runIdToQueueKey = /* @__PURE__ */ new Map();
|
|
48913
|
+
var locallyDispatchedRunIds = /* @__PURE__ */ new Set();
|
|
48872
48914
|
function getRunIdQueueKey(runId) {
|
|
48873
48915
|
return runIdToQueueKey.get(runId);
|
|
48874
48916
|
}
|
|
48875
48917
|
function setRunIdQueueKey(runId, queueKey) {
|
|
48876
48918
|
runIdToQueueKey.set(runId, queueKey);
|
|
48919
|
+
locallyDispatchedRunIds.add(runId);
|
|
48877
48920
|
}
|
|
48878
48921
|
function deleteRunIdQueueKey(runId) {
|
|
48879
48922
|
const queueKey = runIdToQueueKey.get(runId);
|
|
48880
48923
|
runIdToQueueKey.delete(runId);
|
|
48924
|
+
locallyDispatchedRunIds.delete(runId);
|
|
48881
48925
|
return queueKey;
|
|
48882
48926
|
}
|
|
48883
48927
|
function syncRunningTurnQueueKeys(turns, queueKey) {
|
|
@@ -48932,7 +48976,7 @@ async function handlePromptQueueCancellations(entries, deps) {
|
|
|
48932
48976
|
for (const [queueKey] of entries) {
|
|
48933
48977
|
const file2 = await readPersistedQueue(queueKey);
|
|
48934
48978
|
const turn = file2?.turns.find((row) => row.bridgeServerState === "cancel_requested" && row.lastCliState === "running");
|
|
48935
|
-
if (!turn) {
|
|
48979
|
+
if (!turn || getRunIdQueueKey(turn.turnId) !== queueKey) {
|
|
48936
48980
|
await yieldToEventLoop();
|
|
48937
48981
|
continue;
|
|
48938
48982
|
}
|
|
@@ -48941,19 +48985,8 @@ async function handlePromptQueueCancellations(entries, deps) {
|
|
|
48941
48985
|
await yieldToEventLoop();
|
|
48942
48986
|
continue;
|
|
48943
48987
|
}
|
|
48944
|
-
deps.log(`[Queue]
|
|
48988
|
+
deps.log(`[Queue] No local ACP run remains for ${turn.turnId.slice(0, 8)}\u2026; reconciling cancelled turn.`);
|
|
48945
48989
|
await finalizePromptTurnOnBridge(deps.getWs, turn.turnId, false, { terminalCliState: "cancelled" });
|
|
48946
|
-
const ws = deps.getWs();
|
|
48947
|
-
if (ws && turn.sessionId) {
|
|
48948
|
-
sendWsMessage(ws, {
|
|
48949
|
-
type: "prompt_result",
|
|
48950
|
-
sessionId: turn.sessionId,
|
|
48951
|
-
runId: turn.turnId,
|
|
48952
|
-
success: false,
|
|
48953
|
-
error: "Stopped by user",
|
|
48954
|
-
stopReason: "cancelled"
|
|
48955
|
-
});
|
|
48956
|
-
}
|
|
48957
48990
|
await yieldToEventLoop();
|
|
48958
48991
|
}
|
|
48959
48992
|
}
|
|
@@ -49343,17 +49376,14 @@ function handleBridgePrompt(msg, deps) {
|
|
|
49343
49376
|
log2(
|
|
49344
49377
|
`[Bridge service] Prompt ignored: empty or missing prompt text (session ${typeof msg.sessionId === "string" ? msg.sessionId.slice(0, 8) : "\u2014"}\u2026, run ${typeof msg.runId === "string" ? msg.runId.slice(0, 8) : "\u2014"}\u2026).`
|
|
49345
49378
|
);
|
|
49346
|
-
senders.
|
|
49347
|
-
|
|
49348
|
-
|
|
49349
|
-
|
|
49350
|
-
|
|
49351
|
-
|
|
49352
|
-
|
|
49353
|
-
|
|
49354
|
-
},
|
|
49355
|
-
["error"]
|
|
49356
|
-
);
|
|
49379
|
+
senders.sendResult({
|
|
49380
|
+
type: "prompt_result",
|
|
49381
|
+
...promptId ? { id: promptId } : {},
|
|
49382
|
+
...sessionId ? { sessionId } : {},
|
|
49383
|
+
...runId ? { runId } : {},
|
|
49384
|
+
success: false,
|
|
49385
|
+
error: "Empty or missing prompt text from the bridge; this turn was not sent to the agent."
|
|
49386
|
+
});
|
|
49357
49387
|
return;
|
|
49358
49388
|
}
|
|
49359
49389
|
const isNewSession = msg.isNewSession === true;
|