Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/session/compaction-handoff.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,34 @@ describe("iterative folding", () => {
expect(withoutFile.artifact.goal).not.toContain(`${token} ${token}`);
});

test("two without-file re-folds of a start-at-0 token ending with ellipsis keep one Output token", () => {
const token = `FILES_DONE=${"src/session/compaction-handoff.ts/".repeat(8)}end...`;
expect(token.length).toBeGreaterThan(160);
expect(token.endsWith("...")).toBe(true);
const goal = `${token} trailing prose after the standing token`;
const first = buildHandoffFold([userTurn(goal)], "narrative");
expect(first.artifact.goal).toBe(goal);
expect(first.spineText).toContain(`Output: ${token}`);

const withoutFile = buildHandoffFold(
[spineTurn(first.spineText), userTurn("Continue.")],
"narrative",
);
const again = buildHandoffFold(
[spineTurn(withoutFile.spineText), userTurn("Continue.")],
"narrative",
);

for (const fold of [withoutFile, again]) {
expect(
fold.spineText.split("\n").find((line) => line.startsWith("Output: ")),
).toBe(`Output: ${token}`);
expect(fold.artifact.goal).toBe(token);
expect(fold.artifact.goal).not.toContain(`${token} ${token}`);
expect(fold.artifact.goal).not.toContain(`${token}... ${token}`);
}
});

test("without-file re-fold of a start-at-0 comma-joined FILES_DONE keeps one token", () => {
const token = `FILES_DONE=${Array.from({ length: 20 }, (_, i) => `src/session/file${i}.ts`).join(",")}`;
expect(token.length).toBeGreaterThan(160);
Expand Down
8 changes: 3 additions & 5 deletions src/session/compaction-handoff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,9 @@ function mergeStandingOutputToken(
// cutSpineGoal glues "..." onto a start-at-0 token longer than the cap.
// outputFormatTokenRe (\S+) eats that sentinel, so Goal's harvested token
// is token+"..." and never equals the Output token. Strip the glued
// sentinel and keep the standing token once.
if (
goal.endsWith(SPINE_CUT_SENTINEL) &&
!token.endsWith(SPINE_CUT_SENTINEL)
) {
// sentinel and keep the standing token once, including when the standing
// token already ends with "...".
if (goal.endsWith(SPINE_CUT_SENTINEL)) {
const prefix = goal.slice(0, -SPINE_CUT_SENTINEL.length);
if (
hasStandingOutputToken(prefix, token) ||
Expand Down
Loading