From 2e6d36a85544c7b71a79414d7cd2cb7b26ec165e Mon Sep 17 00:00:00 2001 From: GRayHook Date: Wed, 17 Jun 2026 11:46:38 +0700 Subject: [PATCH] =?UTF-8?q?Phase=206:=20add=20PI=5FAUTO=5FCOMPACT=5FFOLLOW?= =?UTF-8?q?=5FUP=5FPREFIXES=20=E2=80=94=20document=20pi-auto-compact=20phr?= =?UTF-8?q?ases.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Constants match SPEC §16.9 for tests and docs; runtime v1 does not match follow-up text. Co-authored-by: Cursor --- src/auto-compact.ts | 8 ++++++ test/auto-compact.test.ts | 55 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 test/auto-compact.test.ts diff --git a/src/auto-compact.ts b/src/auto-compact.ts index a4ae915..a80df6b 100644 --- a/src/auto-compact.ts +++ b/src/auto-compact.ts @@ -25,3 +25,11 @@ export function resolveDeliveryMode( ): ReinjectDeliveryMode { return effectiveIntegration(settings, runtime.autoCompactDetected, sessionIntegrationOverride); } + +/** pi-auto-compact follow-up message prefixes (SPEC §16.9); documentation/tests only, not runtime v1. */ +export const PI_AUTO_COMPACT_FOLLOW_UP_PREFIXES = [ + "Auto-compact ran before this turn.", + "Auto-compact ran mid-turn.", + "Emergency auto-compact ran.", + "Auto-compact ran on session resume.", +] as const; diff --git a/test/auto-compact.test.ts b/test/auto-compact.test.ts new file mode 100644 index 0000000..a106621 --- /dev/null +++ b/test/auto-compact.test.ts @@ -0,0 +1,55 @@ +import { describe, expect, it } from "vitest"; +import { + detectAndCachePiAutoCompact, + detectPiAutoCompact, + PI_AUTO_COMPACT_FOLLOW_UP_PREFIXES, + resolveDeliveryMode, +} from "../src/auto-compact"; +import { createDefaultSettings } from "../src/settings"; +import { createRuntimeFlags } from "../src/state"; + +describe("detectPiAutoCompact", () => { + it("returns true when auto-compact command is registered", () => { + const pi = { + getCommands: () => [{ name: "auto-compact" }], + }; + expect(detectPiAutoCompact(pi as never)).toBe(true); + }); + + it("returns false when auto-compact command is absent", () => { + const pi = { + getCommands: () => [{ name: "skill-reinject" }], + }; + expect(detectPiAutoCompact(pi as never)).toBe(false); + }); +}); + +describe("detectAndCachePiAutoCompact", () => { + it("writes detect result into runtime flags", () => { + const runtime = createRuntimeFlags(); + const pi = { + getCommands: () => [{ name: "auto-compact" }], + }; + expect(detectAndCachePiAutoCompact(pi as never, runtime)).toBe(true); + expect(runtime.autoCompactDetected).toBe(true); + }); +}); + +describe("resolveDeliveryMode", () => { + it("defers when pi-auto-compact is cached as detected", () => { + const runtime = createRuntimeFlags(); + runtime.autoCompactDetected = true; + expect(resolveDeliveryMode(createDefaultSettings(), runtime)).toBe("defer"); + }); +}); + +describe("PI_AUTO_COMPACT_FOLLOW_UP_PREFIXES", () => { + it("documents pi-auto-compact follow-up phrases from SPEC §16.9", () => { + expect([...PI_AUTO_COMPACT_FOLLOW_UP_PREFIXES]).toEqual([ + "Auto-compact ran before this turn.", + "Auto-compact ran mid-turn.", + "Emergency auto-compact ran.", + "Auto-compact ran on session resume.", + ]); + }); +});