Skip to content

Commit 6f1def4

Browse files
committed
refactor(agents): dedupe cli assistant deltas
1 parent 3f6ed50 commit 6f1def4

1 file changed

Lines changed: 25 additions & 44 deletions

File tree

src/agents/cli-runner/execute.ts

Lines changed: 25 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import {
3333
extractCliErrorMessage,
3434
parseCliOutput,
3535
type CliOutput,
36+
type CliStreamingDelta,
3637
} from "../cli-output.js";
3738
import { classifyFailoverReason } from "../embedded-agent-helpers.js";
3839
import {
@@ -992,6 +993,28 @@ export async function executePreparedCliRun(
992993
},
993994
});
994995
};
996+
const emitCliAssistantDelta = ({ text, delta }: CliStreamingDelta) => {
997+
if (text || delta) {
998+
observedCliActivity = true;
999+
}
1000+
if (!emitLiveEvents) {
1001+
return;
1002+
}
1003+
emitAgentEvent({
1004+
runId: params.runId,
1005+
stream: "assistant",
1006+
data: {
1007+
text: applyPluginTextReplacements(
1008+
text,
1009+
context.backendResolved.textTransforms?.output,
1010+
),
1011+
delta: applyPluginTextReplacements(
1012+
delta,
1013+
context.backendResolved.textTransforms?.output,
1014+
),
1015+
},
1016+
});
1017+
};
9951018
if (shouldUseClaudeLiveSession(context)) {
9961019
if (!hasJsonlOutput) {
9971020
throw new Error("Claude live session requires JSONL streaming parser");
@@ -1018,28 +1041,7 @@ export async function executePreparedCliRun(
10181041
useResume,
10191042
noOutputTimeoutMs,
10201043
getProcessSupervisor: executeDeps.getProcessSupervisor,
1021-
onAssistantDelta: ({ text, delta }) => {
1022-
if (text || delta) {
1023-
observedCliActivity = true;
1024-
}
1025-
if (!emitLiveEvents) {
1026-
return;
1027-
}
1028-
emitAgentEvent({
1029-
runId: params.runId,
1030-
stream: "assistant",
1031-
data: {
1032-
text: applyPluginTextReplacements(
1033-
text,
1034-
context.backendResolved.textTransforms?.output,
1035-
),
1036-
delta: applyPluginTextReplacements(
1037-
delta,
1038-
context.backendResolved.textTransforms?.output,
1039-
),
1040-
},
1041-
});
1042-
},
1044+
onAssistantDelta: emitCliAssistantDelta,
10431045
onToolUseStart: emitCliToolUseStart,
10441046
onToolResult: emitCliToolResult,
10451047
onCommentaryText:
@@ -1072,28 +1074,7 @@ export async function executePreparedCliRun(
10721074
? createCliJsonlStreamingParser({
10731075
backend,
10741076
providerId: context.backendResolved.id,
1075-
onAssistantDelta: ({ text, delta }) => {
1076-
if (text || delta) {
1077-
observedCliActivity = true;
1078-
}
1079-
if (!emitLiveEvents) {
1080-
return;
1081-
}
1082-
emitAgentEvent({
1083-
runId: params.runId,
1084-
stream: "assistant",
1085-
data: {
1086-
text: applyPluginTextReplacements(
1087-
text,
1088-
context.backendResolved.textTransforms?.output,
1089-
),
1090-
delta: applyPluginTextReplacements(
1091-
delta,
1092-
context.backendResolved.textTransforms?.output,
1093-
),
1094-
},
1095-
});
1096-
},
1077+
onAssistantDelta: emitCliAssistantDelta,
10971078
onToolUseStart: emitCliToolUseStart,
10981079
onToolResult: emitCliToolResult,
10991080
onCommentaryText:

0 commit comments

Comments
 (0)