Skip to content

Commit 852a181

Browse files
committed
Merge remote-tracking branch 'origin/main' into story-03-handoff-resume-control
# Conflicts: # README.md # agenticoding.test.ts # handoff/tool.ts
2 parents a9a3959 + 3b794ec commit 852a181

17 files changed

Lines changed: 1097 additions & 470 deletions

README.md

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
[![MIT License](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE)
66
![Status](https://img.shields.io/badge/status-active-brightgreen)
77

8-
**A Pi extension that gives the LLM tools to manage its own context.** `spawn`, `ledger`, and `handoff` let the agent actively isolate work, persist reusable knowledge, and restart clean — without platform compaction or manual copy-paste.
8+
**A Pi extension that gives the LLM tools to manage its own context.** `spawn`, `notebook`, and `handoff` let the agent actively isolate work, persist reusable knowledge, and restart clean — without platform compaction or manual copy-paste.
99

1010
---
1111

@@ -42,7 +42,7 @@ Then disable pi's built-in compaction so handoff stays in control:
4242

4343
Optional handoff resume preferences can be changed later with `/agenticoding-settings`.
4444

45-
That's it. Your agent now has `spawn`, `ledger_add`, `ledger_get`, `ledger_list`, `handoff`, and `/agenticoding-settings`. The status bar shows context usage and ledger count.
45+
That's it. Your agent now has `spawn`, `notebook_write`, `notebook_read`, `notebook_index`, `handoff`, and `/agenticoding-settings`. The status bar shows context usage and notebook count.
4646

4747
---
4848

@@ -51,11 +51,11 @@ That's it. Your agent now has `spawn`, `ledger_add`, `ledger_get`, `ledger_list`
5151
| Feature | What it looks like |
5252
|---------|-------------------|
5353
| **Context usage %** | `ctx 65%` in status bar — green < 30%, yellow < 50%, orange < 70%, red ≥ 70% |
54-
| **Ledger count** | 📒 `3` when entries exist, hidden when empty |
54+
| **Notebook count** | 📒 `3` when pages exist, dim `📒 0` when empty |
5555
| **`/handoff` command** | Instant pivot — agent drafts brief, compacts context, waits for next input (configurable auto-resume) |
5656
| **`/agenticoding-settings` command** | TUI panel for global handoff resume behavior, with project override warnings |
57-
| **`/ledger` command** | Overlay showing all entries with previews |
58-
| **Auto-rehydration** | Ledger entries survive session restarts |
57+
| **`/notebook` command** | Overlay showing all notebook pages with previews |
58+
| **Auto-rehydration** | Notebook pages survive session restarts |
5959
| **Spawn transparency** | Watch child agents work in real time in the TUI |
6060
| **Token cost visibility** | Each spawn reports input/output tokens, cache hits, and cost |
6161
| **No polling** | Writes serialized via a process-local lock — no race conditions |
@@ -89,17 +89,17 @@ You: "Add OAuth to the backend"
8989
spawn("audit current auth code")
9090
9191
92-
ledger_add("oauth-decisions", "Flow: PKCE. Scope: read+write.")
92+
notebook_write("oauth-decisions", "Flow: PKCE. Scope: read+write.")
9393
9494
├── spawn("implement token endpoint")
9595
└── spawn("write tests")
9696
9797
9898
handoff("Wire OAuth routes into the middleware stack.
99-
Ledger 'oauth-decisions' holds the constraints.")
99+
Notebook page 'oauth-decisions' holds the constraints.")
100100
```
101101

102-
The agent decided to spawn research children, save reusable findings to the ledger, delegate implementation subtasks, and handoff when context got noisy. **You said one sentence.**
102+
The agent decided to spawn research children, save reusable findings to the notebook, delegate implementation subtasks, and handoff when context got noisy. **You said one sentence.**
103103

104104
---
105105

@@ -109,13 +109,13 @@ The agent decided to spawn research children, save reusable findings to the ledg
109109

110110
Delegate messy work to an isolated child agent with clean context. The child inherits the parent's model and tools, works independently, and returns only the condensed result. Siblings run in parallel; the parent stays focused on orchestration. Children cannot spawn grandchildren (explosive branch prevention).
111111

112-
### Ledger — Continuity Across Cuts
112+
### Notebook — Continuity Across Cuts
113113

114-
A sparse continuity cache the agent curates while working. After discovering something reusable — a fact, constraint, decision, or expensive finding — it saves a named entry. Later contexts fetch entries on demand instead of re-deriving the work. **The ledger persists across handoffs and existing-session restarts; starting a new session with `/new` resets it.**
114+
A sparse pocket notebook the agent curates while working. After discovering something reusable — a fact, constraint, decision, or expensive finding — it writes a named page. Later contexts read pages on demand instead of re-deriving the work. The notebook persists across handoffs, context resets, and session restarts. Starting a new session with `/new` resets all notebook pages.
115115

116116
### Handoff — Deliberate Compaction
117117

118-
When context degrades or the job changes, the agent saves reusable state to the ledger, writes a focused brief preserving what's still missing, and restarts clean. The new context starts with the brief front-and-center, all ledger entries accessible, and zero noise.
118+
When context degrades or the job changes, the agent saves reusable state to the notebook, writes a focused brief preserving what's still missing, and restarts clean. The new context starts with the brief front-and-center, all notebook pages accessible, and zero noise.
119119

120120
By default, handoff waits after compaction for your next input. To auto-resume, set `handoff.resumeBehavior` to `"proceed"`; valid values are `"wait"` and `"proceed"`.
121121

@@ -127,7 +127,7 @@ By default, handoff waits after compaction for your next input. To auto-resume,
127127

128128
Run `/agenticoding-settings` to change this from the TUI. It saves global-only to `~/.pi/agent/settings.json`; project `.pi/settings.json` values still override global settings, and the panel warns when an override is active.
129129

130-
**Rule of thumb:** The ledger holds reusable learned knowledge. Handoff carries the remaining situational context.
130+
**Rule of thumb:** The notebook holds reusable learned knowledge. Handoff carries the remaining situational context.
131131

132132
---
133133

@@ -152,7 +152,7 @@ A single summary blob mixes durable knowledge with transient situational context
152152
| Operation | Primitive | What It Prevents |
153153
|-----------|-----------|-----------------|
154154
| **Isolate** | Spawn | Context pollution from noisy subtasks |
155-
| **Persist** | Ledger | Knowledge loss across resets and pivots |
155+
| **Persist** | Notebook | Knowledge loss across resets and pivots |
156156
| **Compact** | Handoff | Degradation from overstuffed context |
157157

158158
---
@@ -163,10 +163,10 @@ A single summary blob mixes durable knowledge with transient situational context
163163
|---|---|---|---|---|
164164
| **Compaction** | Runtime decides | User decides | Manual wipe + copy-paste | **Agent decides** |
165165
| **Subagents** | Pre-defined or manual trigger | None | None | **Agent spawns dynamically** |
166-
| **Persistent memory** | Background-generated (if at all) | None | None — gone on reset | **Ledger — agent-curated reusable continuity** |
166+
| **Persistent memory** | Background-generated (if at all) | None | None — gone on reset | **Notebook — agent-curated reusable continuity** |
167167
| **Context awareness** | Token count only | Token count only | None | **Primacy-zone heuristic (~30%)** |
168-
| **Cross-session continuity** | Rare (opt-in, background) | Manual copy-paste | Manual copy-paste | **Ledger persists across restarts** |
169-
| **Structured handoff** | No | No | No | **Yes — resets context while carrying forward non-ledger state explicitly** |
168+
| **Cross-session continuity** | Rare (opt-in, background) | Manual copy-paste | Manual copy-paste | **Notebook persists across restarts** |
169+
| **Structured handoff** | No | No | No | **Yes — resets context while carrying forward non-notebook state explicitly** |
170170

171171
---
172172

@@ -179,18 +179,18 @@ The extension hooks into pi's lifecycle:
179179

180180
| Hook | What it does |
181181
|------|-------------|
182-
| `before_agent_start` | Injects context management primer + live ledger listing into system prompt |
182+
| `before_agent_start` | Injects context management primer + live notebook index into system prompt |
183183
| `context` | Injects advisory watchdog reminders when context > 30% |
184-
| `session_start` | Rehydrates ledger from persisted entries; resets on `/new` |
185-
| `turn_end` | Updates TUI indicators (context %, ledger count) |
184+
| `session_start` | Rehydrates notebook pages from persisted entries; resets on `/new` |
185+
| `turn_end` | Updates TUI indicators (context %, notebook count) |
186186
| `agent_end` | Records last context usage percent |
187187
| `session_before_compact` | Consumes pending handoff task and sets it as compaction summary |
188188

189189
All state lives in a single `AgenticodingState` instance:
190190

191191
```typescript
192192
interface AgenticodingState {
193-
ledger: Map<string, string>
193+
notebookPages: Map<string, string>
194194
epoch: number
195195
lastContextPercent: number | null
196196
pendingHandoff: { task, source } | null
@@ -203,6 +203,12 @@ interface AgenticodingState {
203203

204204
</details>
205205

206+
<details>
207+
<summary><strong>Deep dive → ARCHITECTURE.md</strong></summary>
208+
209+
See [ARCHITECTURE.md](ARCHITECTURE.md) for full module breakdown, tool schemas, lifecycle wiring, spawn child-session lifecycle, and notebook rehydration algorithm.
210+
211+
</details>
206212
---
207213

208214
## Contributing

0 commit comments

Comments
 (0)