GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Keep one ACP answer when a running tool reports progress · felippeoka/f5@243ac08

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • apps/server
    • scripts
      • acp-mock-agent.ts
    • src/provider/acp
      • AcpJsonRpcConnection.test.ts
      • AcpSessionRuntime.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎apps/server/scripts/acp-mock-agent.ts‎

Copy file name to clipboardExpand all lines: apps/server/scripts/acp-mock-agent.ts
+43Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ const exitLogPath = process.env.T3_ACP_EXIT_LOG_PATH;
1515
const emitToolCalls = process.env.T3_ACP_EMIT_TOOL_CALLS === "1";
1616
const emitInterleavedAssistantToolCalls =
1717
process.env.T3_ACP_EMIT_INTERLEAVED_ASSISTANT_TOOL_CALLS === "1";
18+
const emitBackgroundToolDuringAnswer =
19+
process.env.T3_ACP_EMIT_BACKGROUND_TOOL_DURING_ANSWER === "1";
1820
const emitGenericToolPlaceholders = process.env.T3_ACP_EMIT_GENERIC_TOOL_PLACEHOLDERS === "1";
1921
const emitAskQuestion = process.env.T3_ACP_EMIT_ASK_QUESTION === "1";
2022
const failSetConfigOption = process.env.T3_ACP_FAIL_SET_CONFIG_OPTION === "1";
@@ -440,6 +442,47 @@ const program = Effect.gen(function* () {
440442
process.exit(1);
441443
}
442444

445+
if (emitBackgroundToolDuringAnswer) {
446+
// A command backgrounded earlier reports progress and then finishes
447+
// while the next answer is still streaming.
448+
const toolCallId = "background-1";
449+
const say = (text: string) =>
450+
agent.client.sessionUpdate({
451+
sessionId: requestedSessionId,
452+
update: { sessionUpdate: "agent_message_chunk", content: { type: "text", text } },
453+
});
454+
const progress = (status: "in_progress" | "completed", stdout: string) =>
455+
agent.client.sessionUpdate({
456+
sessionId: requestedSessionId,
457+
update: {
458+
sessionUpdate: "tool_call_update",
459+
toolCallId,
460+
status,
461+
rawOutput: { stdout },
462+
},
463+
});
464+
yield* agent.client.sessionUpdate({
465+
sessionId: requestedSessionId,
466+
update: {
467+
sessionUpdate: "tool_call",
468+
toolCallId,
469+
title: "Terminal",
470+
kind: "execute",
471+
status: "in_progress",
472+
rawInput: { command: "sleep 3 && echo done" },
473+
},
474+
});
475+
yield* say("| a | b |\n|---|---|\n| 1 ");
476+
yield* progress("in_progress", ".");
477+
yield* say("| x |\n");
478+
yield* progress("completed", "done");
479+
yield* say("| 2 | y |\n");
480+
// Agents can repeat a terminal update after the call finished.
481+
yield* progress("completed", "done");
482+
yield* say("| 3 | z |");
483+
return { stopReason: "end_turn" };
484+
}
485+
443486
if (emitInterleavedAssistantToolCalls) {
444487
const toolCallId = "tool-call-1";
445488

Collapse file

‎apps/server/src/provider/acp/AcpJsonRpcConnection.test.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/provider/acp/AcpJsonRpcConnection.test.ts
+44Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,50 @@ describe("AcpSessionRuntime", () => {
441441
),
442442
);
443443

444+
it.effect("keeps one answer when an earlier tool reports progress mid-stream", () =>
445+
Effect.gen(function* () {
446+
const runtime = yield* AcpSessionRuntime;
447+
yield* runtime.start();
448+
yield* runtime.prompt({ prompt: [{ type: "text", text: "hi" }] });
449+
450+
const notes = Array.from(yield* Stream.runCollect(Stream.take(runtime.getEvents(), 9)));
451+
// Neither the progress tick, the completion, nor a repeated completion
452+
// splits the markdown table across assistant items.
453+
expect(notes.map((note) => note._tag)).toEqual([
454+
"ToolCallUpdated",
455+
"AssistantItemStarted",
456+
"ContentDelta",
457+
"ToolCallUpdated",
458+
"ContentDelta",
459+
"ToolCallUpdated",
460+
"ContentDelta",
461+
"ToolCallUpdated",
462+
"ContentDelta",
463+
]);
464+
const itemIds = new Set(
465+
notes.flatMap((note) =>
466+
note._tag === "ContentDelta" || note._tag === "AssistantItemStarted" ? [note.itemId] : [],
467+
),
468+
);
469+
expect(itemIds.size).toBe(1);
470+
}).pipe(
471+
Effect.provide(
472+
AcpSessionRuntime.layer({
473+
spawn: {
474+
command: bunExe,
475+
args: [mockAgentPath],
476+
env: { T3_ACP_EMIT_BACKGROUND_TOOL_DURING_ANSWER: "1" },
477+
},
478+
cwd: process.cwd(),
479+
clientInfo: { name: "t3-test", version: "0.0.0" },
480+
authMethodId: "test",
481+
}),
482+
),
483+
Effect.scoped,
484+
Effect.provide(NodeServices.layer),
485+
),
486+
);
487+
444488
it.effect("segments assistant text around ACP tool calls", () =>
445489
Effect.gen(function* () {
446490
const runtime = yield* AcpSessionRuntime;
Collapse file

‎apps/server/src/provider/acp/AcpSessionRuntime.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/provider/acp/AcpSessionRuntime.ts
+22-4Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,9 @@ const makeAcpSessionRuntime = (
303303
const modeStateRef = yield* Ref.make<AcpSessionModeState | undefined>(undefined);
304304
const toolCallsRef = yield* Ref.make(new Map<string, AcpToolCallState>());
305305
const toolEmissions = new Map<string, { length: number | undefined; skipped: number }>();
306+
// Recently shown tool calls. A late update to a finished call is not a new
307+
// boundary in the answer, although its progress state is gone.
308+
const shownToolCallIds = new Set<string>();
306309
const assistantSegmentRef = yield* Ref.make<AcpAssistantSegmentState>({ nextSegmentIndex: 0 });
307310
const configOptionsRef = yield* Ref.make(sessionConfigOptionsFromSetup(undefined));
308311
const startStateRef = yield* Ref.make<AcpStartState>({ _tag: "NotStarted" });
@@ -457,6 +460,7 @@ const makeAcpSessionRuntime = (
457460
modeStateRef,
458461
toolCallsRef,
459462
toolEmissions,
463+
shownToolCallIds,
460464
assistantSegmentRef,
461465
params: normalized,
462466
...(hardeningEnabled
@@ -888,6 +892,7 @@ const makeAcpSessionRuntime = (
888892
modeStateRef,
889893
toolCallsRef,
890894
toolEmissions,
895+
shownToolCallIds,
891896
assistantSegmentRef,
892897
params: commands,
893898
});
@@ -1092,11 +1097,14 @@ function configOptionCurrentValueMatches(
10921097
return currentValue.trim() === String(value).trim();
10931098
}
10941099

1100+
const MAX_SHOWN_TOOL_CALL_IDS = 256;
1101+
10951102
const handleSessionUpdate = ({
10961103
queue,
10971104
modeStateRef,
10981105
toolCallsRef,
10991106
toolEmissions,
1107+
shownToolCallIds,
11001108
assistantSegmentRef,
11011109
params,
11021110
onActivity,
@@ -1105,6 +1113,7 @@ const handleSessionUpdate = ({
11051113
readonly modeStateRef: Ref.Ref<AcpSessionModeState | undefined>;
11061114
readonly toolCallsRef: Ref.Ref<Map<string, AcpToolCallState>>;
11071115
readonly toolEmissions: Map<string, { length: number | undefined; skipped: number }>;
1116+
readonly shownToolCallIds: Set<string>;
11081117
readonly assistantSegmentRef: Ref.Ref<AcpAssistantSegmentState>;
11091118
readonly params: EffectAcpSchema.SessionNotification;
11101119
readonly onActivity?: Effect.Effect<void>;
@@ -1119,10 +1128,19 @@ const handleSessionUpdate = ({
11191128
}
11201129
for (const event of parsed.events) {
11211130
if (event._tag === "ToolCallUpdated") {
1122-
yield* closeActiveAssistantSegment({
1123-
queue,
1124-
assistantSegmentRef,
1125-
});
1131+
// A new tool call is a boundary in the prose. Progress on a call that
1132+
// is already shown, such as a background command finishing, is not.
1133+
const toolCallId = event.toolCall.toolCallId;
1134+
if (!shownToolCallIds.has(toolCallId)) {
1135+
shownToolCallIds.add(toolCallId);
1136+
// Only recent calls get late updates; keep a long session bounded.
1137+
if (shownToolCallIds.size > MAX_SHOWN_TOOL_CALL_IDS) {
1138+
shownToolCallIds.delete(shownToolCallIds.values().next().value!);
1139+
}
1140+
// A call still running is already on screen, even if it aged out.
1141+
const running = (yield* Ref.get(toolCallsRef)).has(toolCallId);
1142+
if (!running) yield* closeActiveAssistantSegment({ queue, assistantSegmentRef });
1143+
}
11261144
const { previous, merged } = yield* Ref.modify(toolCallsRef, (current) => {
11271145
const previous = current.get(event.toolCall.toolCallId);
11281146
const nextToolCall = mergeToolCallState(previous, event.toolCall);

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.