repositories / pi-ext

pi-ext

bugabingas pi extensions

owned by bugabinga

extensions/forget/PLAN.md

Raw

forget plan

Experimental goal: let the model manage stale active context in long mixed-task sessions with one small prefix-cut API.

SDK constraints

Design

Real-provider learnings

Tests

Manual test

cd extensions/forget
bun test
FORGET_REAL=1 bun run test:real
pi -e ./index.ts --model kimi-coding/kimi-for-coding
Markdown source
File outline
# forget plan

Experimental goal:
let the model manage stale active context in long mixed-task sessions with one
small prefix-cut API.

## SDK constraints

- Pi session files are append-only.
  Entries cannot be modified or physically deleted through `SessionManager`.
- Active context can still be changed safely by adding a compaction entry.
  `appendCompaction(summary, firstKeptEntryId, tokensBefore, details, fromHook)`
  makes `buildSessionContext()` emit the summary, then branch messages from
  `firstKeptEntryId` onward.
- Recent tail deletion is already covered by Pi tree navigation/forking.
  It is out of scope for Forget.
- Middle deletion is not supported without replaying or filtering the
  transcript.
  Replay breaks IDs/tool-call adjacency; per-turn filtering is fragile and not a
  persistent session edit.

## Design

- Tool:
  `forget(target?, reason?)`
  - `target="current_user"`:
    keep the latest user request onward; drop older active context.
  - `target="previous_user"`:
    keep the immediately previous user request onward; drop older active
    context.
  - omitted `target` defaults to `current_user`.
- Per-prompt system reminder:
  short turn-local line tells the agent to consider Forget in long mixed-task
  sessions and skip when prior context may still be needed.
- Guardrails:
  - no entry IDs exposed to the model.
  - no inspect/debug/status tool.
  - no ranges or holes.
  - target must resolve to a user message on the active branch.
  - no physical deletion claim; JSONL keeps recoverable history.
  - not a secret-redaction guarantee; newer/current messages and model thinking
    can still contain sensitive strings.

## Real-provider learnings

- Long-session probes showed `previous_user` is useful for preserving immediate
  setup while dropping older task context.
- Kimi and OpenAI used the API best in long mixed-task sessions.
- Z.ai used it aggressively but still gained context cleanup.
- MiniMax often ignored the tool; that is acceptable for weak-tool models.
- `inspect`, raw entry IDs, `status`, and `user:<offset>` added complexity
  without reliable model gains.

## Tests

- Unit:
  target normalization, user-boundary resolution, terse errors, tombstone
  summary.
- Harness:
  extension loads, tool registers, reminder injects, `current_user` and
  `previous_user` create compactions with expected `firstKeptEntryId`, context
  drops old text, invalid targets fail tersely.
- Real MiniMax:
  optional `FORGET_REAL=1`; runs isolated SDK session with only Forget loaded,
  calls the tool directly, verifies compaction is active.

## Manual test

```bash
cd extensions/forget
bun test
FORGET_REAL=1 bun run test:real
pi -e ./index.ts --model kimi-coding/kimi-for-coding
```