Skip to content

2026.10.04 - Phase 3: Pi DCP Compact Markers - #73

Merged
lanhhoang merged 7 commits into
masterfrom
20261004-phase-03-pi-dcp-compact-markers
Oct 4, 2026
Merged

lanhhoang merged 7 commits into
masterfrom
20261004-phase-03-pi-dcp-compact-markers

Conversation

@lanhhoang

Copy link
Copy Markdown
Contributor
  • Compact markers replace verbose XML tags — every injectable user/assistant message now ends with a standalone @mN@, or @mN:P@ when a compression priority from 1 to 5 is assigned. On a 2,000-message clean workload this cut estimated metadata overhead from about 20,000 tokens to about 4,000. The injected format derives from a strict formatMessageMarker(ref, priority) that round-trips canonical refs through parseMessageRef and rejects noncanonical inputs or out-of-range priorities (src/utils/message-ids.ts, src/messages/inject.ts, tests/inject.test.ts, tests/message-ids.test.ts).
  • Compact input is accepted and normalized to the canonical ref — parseBoundaryId now tries canonical m0001, then exact compact m1 / @m1@ / @m1:3@ / @m12:3@, then block bN. resolveBoundaryIndex re-runs the parsed index through formatMessageRef before comparing with SessionState.messageIds.byIndex, so a copied @m12:3@ resolves to the same stored message as m0012 rather than merely parsing. parseMessageRef itself stays canonical-only, block parsing rejects unsafe integers, and zero/negative/decimal/partial-padding/wrapped-padded inputs all return undefined (src/utils/message-ids.ts, src/compress/search.ts, tests/message-ids.test.ts, tests/compress-search.test.ts).
  • Line-bounded sanitizer strips whole marker lines only — a new DCP_COMPACT_MARKER_LINE regex removes only complete or truncated markers (@m1@, @m1:3@, @m1, @m1:, @m1:2) on a line boundary, under LF or CRLF, with optional horizontal whitespace. The line boundary itself is preserved so surrounding prose is not concatenated. Inline @m1@, person@m1@example.com, @mention, and marker text inside a sentence are left untouched. Compact cleanup runs before the legacy XML fallbacks, which remain active for stored assistant output (src/messages/strip.ts, tests/strip.test.ts, tests/message-end.test.ts).
  • Snapshot pairs are validated as canonical — parsePairs in src/state/persistence.ts switches from a permissive parseMessageRef(entry[1]) ?? 0 > 0 check to the strict isCanonicalMessageRef predicate. A compact persisted ref is discarded rather than normalized, nextRefIndex stays authoritative, the snapshot version is unchanged, and no stored map is migrated (src/state/persistence.ts, src/utils/message-ids.ts, tests/persistence.test.ts).
  • Model-facing copy teaches the compact protocol — the system prompt documents @mN@, @mN:P@, and <dcp-system-reminder> as environment-injected metadata that must not be output, repeated, or invented; the message-mode tool description explains priority values and accepts the padded form as an alternative; the range tool and message tool descriptions use m1 / @m1@ examples while keeping bN block examples and the pruned/unavailable explanation. The legacy Choose a message ID (m0001)… error messages in normalizeEntries are now Choose a message marker (m1 or @m1@)… (src/prompts/system.ts, src/prompts/compress-message.ts, src/index.ts, src/compress/handler.ts, tests/index.test.ts, tests/integration.test.ts, tests/pipeline.test.ts, tests/compress-cycle.test.ts).
  • Benchmark token gates are release-blocking — tests/benchmark.test.ts now asserts three deterministic budgets so a token regression fails pnpm check: injected-marker overhead on clean-2000-messages must stay at or below 6,000 tokens, and the repeated-tool-pairs-2000 and restored-nested-blocks-100 reduction ratios must stay within five percentage points of the retained 962873 / 1017575 and 1171 / 1291 baselines. Ratios are compared as exact fractions rather than rounded percentages, and elapsed-time reporting remains informational. The retained benchmarks/result.json was refreshed on Node 24.21.0 with the compact marker overhead now showing as -3,992 instead of -20,000 (tests/benchmark.test.ts, benchmarks/result.json, README.md).
  • Version bump and docs refresh — version 0.7.0 → 0.8.0 (package.json); CHANGELOG.md adds a [0.8.0] - 2026-10-04 entry under Added / Changed / Removed covering compact markers, normalized lookup, line-bounded sanitization, snapshot canonical validation, and the dropped <dcp-message-id> XML formatter; README.md replaces the 0.7.0 block with a focused "What's new in 0.8.0" section and adds a "Message markers and IDs" reference table (package.json, CHANGELOG.md, README.md).
  • Plan refresh and local-only ignore — the Phase 3 plan was tightened to match what shipped: the codec invariants, the line-bounded sanitizer rule, the canonical-only snapshot rule, and the high-index / invalid-input tables are all consistent with the implementation (docs/superpowers/plans/2026-10-03-phase-03-pi-dcp-compact-markers.md). .gitignore adds .DS_Store (.gitignore).

Automatic pruning timing, canonical padded references, the version-1 persisted snapshot shape, the generated schema, and Pi lifecycle hooks remain unchanged; no new runtime dependencies, no published Pi or OpenCode reference repositories, and no release workflow were touched. Verified end-to-end with pnpm check (format, warning-free lint, typecheck, tests) and pnpm benchmark (all three workloads complete within the new token gates; retained benchmarks/result.json refreshed on Node 24.21.0).

@lanhhoang
lanhhoang merged commit 9188118 into master Oct 4, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant