Fix Pi compaction slash commands (#1338)

* fix: handle Pi compact slash command

* fix: handle Pi compaction slash commands

* fix: harden Pi compaction commands

* fix: handle missing Pi autocompaction state

---------

Co-authored-by: X <X@16x.org>
Co-authored-by: Mohamed Boudra <boudra.moha@gmail.com>
This commit is contained in:
chyendongnhanh338
2026-06-06 22:41:08 +08:00
committed by GitHub
co-authored by X Mohamed Boudra
parent 6aa73baaab
commit 59d48d235a
9 changed files with 731 additions and 15 deletions
+36
View File
@@ -99,6 +99,21 @@ function todoTimeline(items: { text: string; completed: boolean }[]): AgentStrea
};
}
function compactionTimeline(
status: "loading" | "completed",
trigger?: "auto" | "manual",
): AgentStreamEventPayload {
return {
type: "timeline",
provider: "pi",
item: {
type: "compaction",
status,
...(trigger ? { trigger } : {}),
},
};
}
function findToolByCallId(state: StreamItem[], callId: string): AgentToolCallItem | undefined {
return state.find(
(item): item is AgentToolCallItem =>
@@ -693,6 +708,27 @@ describe("stream reducer canonical tool calls", () => {
assert.strictEqual(todos.items[1]?.completed, true);
});
it("preserves compaction trigger when completed update replaces loading marker", () => {
const state = hydrateStreamState([
{
event: compactionTimeline("loading", "auto"),
timestamp: new Date("2025-01-01T10:50:00Z"),
},
{
event: compactionTimeline("completed"),
timestamp: new Date("2025-01-01T10:50:01Z"),
},
]);
const compactions = state.filter(
(item): item is Extract<StreamItem, { kind: "compaction" }> => item.kind === "compaction",
);
assert.strictEqual(compactions.length, 1);
assert.strictEqual(compactions[0].status, "completed");
assert.strictEqual(compactions[0].trigger, "auto");
});
it("renders Claude TodoWrite as todo_list and suppresses tool call badge", () => {
const state = hydrateStreamState([
{
+2 -2
View File
@@ -726,8 +726,8 @@ function reduceTimelineCompaction(
const updated: CompactionItem = {
...existing,
status: "completed",
trigger: item.trigger,
preTokens: item.preTokens,
trigger: item.trigger ?? existing.trigger,
preTokens: item.preTokens ?? existing.preTokens,
};
return [...state.slice(0, loadingIdx), updated, ...state.slice(loadingIdx + 1)];
}