@gswangg/pi-duncan 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,92 @@
1
+ # duncan
2
+
3
+ Session memory for [pi](https://github.com/badlogic/pi-mono). Query dormant sessions, hand off context across session boundaries.
4
+
5
+ ## What it does
6
+
7
+ When pi sessions end or hit their context window limit, the conversation is gone from the LLM's perspective. Duncan lets you query those dormant sessions — the full conversation history is still on disk, and duncan loads it into a fresh LLM call to answer questions about what happened.
8
+
9
+ **`duncan` tool** — the LLM calls this to query past sessions. Supports targeting by lineage (ancestors, descendants, parent) or by project (all sessions in the same working directory). Handles compaction windows so pre-compaction context is still reachable.
10
+
11
+ **`/skill:duncan`** — natural language interface. Just ask a question and the LLM figures out which sessions to search and how to route the query.
12
+
13
+ **`/dfork`** — hands off the current session to a new one with a structured summary. Use when you're approaching the context limit. The new session starts with a compressed checkpoint of everything that happened. Duncan warns at 80% context usage.
14
+
15
+ **`/lineage`** — shows the session tree and lets you switch between sessions. Displays generation, compaction window count, and a preview of each session's first message.
16
+
17
+ ## Install
18
+
19
+ ```bash
20
+ pi install git:github.com/gswangg/pi-duncan
21
+ ```
22
+
23
+ ## Configuration
24
+
25
+ **Query log** — duncan logs all queries to `duncan.jsonl` in the extension's own directory (next to `duncan.ts`). Override with:
26
+
27
+ ```bash
28
+ export DUNCAN_LOG=/path/to/duncan.jsonl
29
+ ```
30
+
31
+ ## Usage
32
+
33
+ ### Querying past sessions
34
+
35
+ The LLM uses the `duncan` tool automatically when it needs information from a previous session. You can also ask directly via the skill:
36
+
37
+ ```
38
+ /skill:duncan what did we decide about the database schema?
39
+ ```
40
+
41
+ ### Handing off context
42
+
43
+ When your context window is getting full (duncan warns at 80%):
44
+
45
+ ```
46
+ /dfork
47
+ ```
48
+
49
+ This generates a structured summary of the current session and starts a new one with that summary as the opening message. The new session is linked to the old one via pi's parent session mechanism.
50
+
51
+ ### Navigating sessions
52
+
53
+ ```
54
+ /lineage # show tree of related sessions
55
+ /lineage all # include unrelated sessions too
56
+ ```
57
+
58
+ ## How it works
59
+
60
+ ### Compaction windows
61
+
62
+ Pi's compaction feature summarizes old messages to free up context space, but the original messages are still in the session file. Duncan splits each session into independently queryable "windows" — one per compaction boundary — so information that was compacted away is still reachable.
63
+
64
+ ### Query routing
65
+
66
+ The `sessions` parameter controls which sessions are searched:
67
+
68
+ | Mode | Behavior |
69
+ |------|----------|
70
+ | `ancestors` | Walk up the parent chain (default, start here) |
71
+ | `parent` | Immediate parent only |
72
+ | `descendants` | Children, breadth-first |
73
+ | `project` | All sessions in the same working directory, newest first |
74
+ | `global` | All sessions across all working directories, newest first |
75
+ | `<filename>` | A specific session file |
76
+
77
+ Each session/window is queried independently. Duncan uses structured output (tool call) to get a `hasContext` boolean from each query — only answers that actually found relevant context are returned.
78
+
79
+ ### Pagination
80
+
81
+ Multi-session modes (`ancestors`, `descendants`, `project`, `global`) default to 50 windows per query. If there are more, the response includes pagination info. The LLM (or you via the skill) can request the next batch:
82
+
83
+ ```
84
+ /skill:duncan same question, but search the next batch (offset 50)
85
+ ```
86
+
87
+ ## Development
88
+
89
+ ```bash
90
+ npm install
91
+ tsx tests/compaction-windows.test.mjs
92
+ ```