forked niri forked from okami.mom/niri

feat(compaction): companion compaction pipeline + strategy dispatch #54

targeting main from deleted fork:compaction-companion
Merged opened by and assigned to callie.on-her.computer
targeting main from deleted fork:compaction-companion

Configurable compaction strategy tuned for a persistent companion agent (relational history, not disposable coding scaffolding).

config (context.*) #

  • compaction_strategy: companion | context-full | snapcompact | remote | off (default companion)
  • deep_archive (default true) — layer-3 toggle
  • journal_before_compaction (default true) — layer-1 toggle
  • remote_compaction { endpoint, model, streaming_endpoint } — OpenAI provider-native seam for a future gpt-5.6 / terra swap

companion pipeline (3 layers, at the trigger) #

  1. journal-first — the same-model summary that replaces the middle history is also appended to the durable indexed journal, so the ephemeral in-context summary need not carry the whole emotional load
  2. same-model directed summary — configuredSummaryProvider(preferActiveModel) forces the head that generated the conversation (only way to salvage lessons from a provider that hides its CoT); accepts a one-time cache bust at the cliff instead of letting preserve_prompt_cache silently disable all compaction
  3. deep archive — pluggable DeepArchiveBackend: OpenAiRemoteArchive (config endpoint), TextAppendixArchive (Anthropic/default collapsed raw block), SnapcompactFramesArchive (stub until oh-my-pi's native renderer is vendored — follow-up)

loop.ts gets a single applyCompaction() dispatcher; snapcompact degrades to context-full until frames exist; companion defers proactive tool-result nibbling to the one decisive cliff-defense burn to protect cache.

Designed to defend the 200k price cliff (paired nix change sets compact_trigger_tokens=200000, strategy=companion).

verification #

  • typecheck clean
  • 77/77 niri-runtime tests pass (7 new: deep-archive backends + strategy enum)
Commits 0