compaction: the surface — settings row, two ruled dividers, summary dialog, send gate (round 14 slice 3)

- settings: compaction.thresholdTokens row on the Agent tab (owner pick)
  in a Context group — CommitInput mirroring the graph budget row, hint
  resolved through the SAME core resolver the trigger reads; PUT rejects
  below the 32k floor with the anti-churn rationale; own section
  (compaction) in SETTINGS_SECTIONS + the settings-signal union
- view fold: one marker → two dividers — the minimal MOMENT divider at
  the marker (retrying-message register, no rule lines) and the longer
  CUT divider emitted immediately before the first kept message
  (phase-divider geometry, chip carries '· Nk tok'); both carry the full
  summary payload; full history stays visible to the user
- components/compaction-divider.tsx: the dividers + summary dialog
  (pure exported body for SSR pins, the delete-dialog pattern; Esc +
  Close dismiss, backdrop does not)
- chat.tsx: compaction-changed SSE flips the running state — composer
  canSend, onSend/doSend/doSteerOrSend, and both docks' submit + hint
  ('compacting session…') gate on it (the server's registry mutex is the
  structural gate; this is the affordance); dialog mounts beside the
  abort dialog
- pins: settings-body (4), view fold (2), divider SSR (4)
This commit is contained in:
amosblomqvist
2026-10-05 22:51:08 +03:00
parent dd159cc8fb
commit ffc4df1938
14 changed files with 465 additions and 19 deletions
+41
View File
@@ -16,6 +16,7 @@ import {
type LhMarkerMessage,
} from "../src/core/index.ts";
import type { AssistantMessage, ToolResultMessage } from "@earendil-works/pi-ai";
import { projectView } from "../src/core/view.ts";
/**
* COMPACTION (owner round 14, 2026-10-05) — the pure core: the cut walk,
@@ -242,3 +243,43 @@ describe("serializeForSummary + buildCompactionPrompt", () => {
assert.ok(text.includes("Alpha → Beta"));
});
});
// ---------------------------------------------------------------------------
// THE VIEW FOLD (owner round 14): two dividers from one marker —
// the minimal moment divider where the user is, the longer cut divider
// at the kept boundary. Both carry the full summary payload.
// ---------------------------------------------------------------------------
describe("projectView compaction dividers", () => {
const record = (): LhMessage[] => [
{ id: "old1", role: "user", content: "earliest", timestamp: 1 },
{ id: "kept", role: "user", content: "recent", timestamp: 2 },
newCompactionMarker("SUMMARY TEXT", {
firstKeptMessageId: "kept",
tokensBefore: 12345,
at: new Date(0).toISOString(),
}) as unknown as LhMessage,
];
it("emits the cut divider BEFORE the first kept message", () => {
const view = projectView(record());
const idx = view.findIndex((m) => m.parts.some((p) => p.type === "data-compaction-cut"));
const keptIdx = view.findIndex((m) => m.parts.some((p) => p.type === "text" && p.text === "recent"));
assert.ok(idx !== -1, "the cut divider exists");
assert.ok(keptIdx !== -1);
assert.equal(idx, keptIdx - 1, "immediately before the kept message");
const part = view[idx]!.parts.find((p) => p.type === "data-compaction-cut")!;
assert.equal((part.data as { content: string }).content.includes("SUMMARY TEXT"), true);
});
it("emits the moment divider at the marker (the transcript tail)", () => {
const view = projectView(record());
const moment = view.find((m) => m.parts.some((p) => p.type === "data-compaction"));
assert.ok(moment, "the moment divider exists");
const part = moment!.parts.find((p) => p.type === "data-compaction")!;
assert.equal((part.data as { details: { tokensBefore: number } }).details.tokensBefore, 12345);
// and it renders AFTER the kept message (the compaction moment is
// the tail — where the user is when it happens)
const keptIdx = view.findIndex((m) => m.parts.some((p) => p.type === "text" && p.text === "recent"));
assert.ok(view.indexOf(moment!) > keptIdx);
});
});
+72
View File
@@ -0,0 +1,72 @@
/**
* THE COMPACTION DIVIDERS — SSR render pins (owner round 14). Two ruled
* surfaces from one marker: the MOMENT divider (minimal centered small
* text, the retrying-message register — no rule lines) where the user
* is when compaction lands, and the CUT divider (the longer one —
* phase-divider geometry, dotted rules + a chip carrying the summarized
* token count) at the kept boundary. Both open the same summary dialog
* (the marker's full model-facing content, verbatim, scrollable).
*
* The dialog portals to document.body at z-50; SSR renders null when
* closed — the pins hold the open state through a jsdom-free server
* render (createPortal is a no-op passthrough on the server).
*/
import React from "react";
(globalThis as Record<string, unknown>).React = React;
import assert from "node:assert/strict";
import { renderToStaticMarkup } from "react-dom/server";
import { describe, it } from "node:test";
import {
CompactionCutDivider,
CompactionMomentDivider,
CompactionSummaryBody,
CompactionSummaryDialog,
type CompactionDividerData,
} from "../components/compaction-divider.tsx";
const data: CompactionDividerData = {
content: "[SESSION HISTORY COMPACTED]\n\nTHE LEARNER'S UNDERSTANDING: …",
details: {
firstKeptMessageId: "kept_1",
tokensBefore: 152000,
at: "2026-10-05T00:00:00.000Z",
},
};
describe("CompactionMomentDivider", () => {
it("renders the minimal centered note — no rule lines, retrying-message register", () => {
const html = renderToStaticMarkup(<CompactionMomentDivider data={data} onOpen={() => {}} />);
assert.ok(html.includes('data-testid="compaction-divider"'));
assert.ok(html.includes("Context compacted"));
// NO horizontal rule (the owner ruling: minimal, unlike the cut)
assert.ok(!html.includes("border-t-2"));
});
});
describe("CompactionCutDivider", () => {
it("renders the longer seam — dotted rules + chip with the token count", () => {
const html = renderToStaticMarkup(<CompactionCutDivider data={data} onOpen={() => {}} />);
assert.ok(html.includes('data-testid="compaction-cut-divider"'));
assert.ok(html.includes("border-t-2 border-dotted"));
assert.ok(html.includes("History compacted"));
// 152000 → 152k tok
assert.ok(html.includes("152k tok"));
});
});
describe("CompactionSummaryDialog", () => {
it("renders the marker content verbatim, scrollable (the pure body — portals need document)", () => {
const html = renderToStaticMarkup(
<CompactionSummaryBody summary={data} onClose={() => {}} />,
);
assert.ok(html.includes('data-testid="compaction-summary-dialog"'));
assert.ok(html.includes("[SESSION HISTORY COMPACTED]"));
assert.ok(html.includes("overflow-y-auto"));
assert.ok(html.includes('data-testid="compaction-summary-close"'));
});
it("renders nothing when closed", () => {
assert.equal(renderToStaticMarkup(<CompactionSummaryDialog summary={null} onClose={() => {}} />), "");
});
});
+35 -2
View File
@@ -14,6 +14,7 @@ import {
parseModelsSettingsBody,
parseAppearanceSettingsBody,
parseGeneralSettingsBody,
parseCompactionSettingsBody,
parseGraphSettingsBody,
SETTINGS_SECTIONS,
} from "../src/server/settings-body.ts";
@@ -194,9 +195,41 @@ describe("parseGraphSettingsBody", () => {
});
});
describe("parseCompactionSettingsBody (owner round 14)", () => {
it("parses a threshold; absent = the empty section (factory default at resolution)", () => {
const r = parseCompactionSettingsBody({ thresholdTokens: 120000 });
assert.ok(r.ok);
assert.deepEqual(r.settings, { thresholdTokens: 120000 });
const none = parseCompactionSettingsBody({});
assert.ok(none.ok);
assert.deepEqual(none.settings, {});
});
it("floors to integers", () => {
const r = parseCompactionSettingsBody({ thresholdTokens: 120000.9 });
assert.ok(r.ok);
assert.equal(r.settings.thresholdTokens, 120000);
});
it("rejects below the 32k floor with the anti-churn rationale", () => {
const r = parseCompactionSettingsBody({ thresholdTokens: 20_000 });
assert.ok(!r.ok);
assert.match(r.error ?? "", /at least 32000/);
assert.match(r.error ?? "", /churn/);
});
it("rejects non-numbers", () => {
const r = parseCompactionSettingsBody({ thresholdTokens: "big" });
assert.ok(!r.ok);
assert.match(r.error ?? "", /must be a number/);
});
});
describe("SETTINGS_SECTIONS (the route's section map)", () => {
it("maps exactly the six record sections", () => {
assert.deepEqual(Object.keys(SETTINGS_SECTIONS), ["general", "chat", "agent", "appearance", "graph", "models"]);
it("maps exactly the seven record sections", () => {
// compaction joined (owner round 14): its own section PUT — the
// threshold is engine behavior, not an agent-section key.
assert.deepEqual(
Object.keys(SETTINGS_SECTIONS),
["general", "chat", "agent", "appearance", "graph", "compaction", "models"],
);
});
});