Skip to content

Commit 3b794ec

Browse files
authored
Merge pull request #6 from agenticoding/refactor/notebook
feat(notebook): rename ledger to notebook with subject-oriented grounding and add topic-awareness layerRefactor/notebook
2 parents 7b016b2 + b74f7ca commit 3b794ec

17 files changed

Lines changed: 1098 additions & 471 deletions

README.md

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# pi-agenticoding
22

33
[![pi.dev package](https://img.shields.io/badge/pi.dev-package-purple)](https://pi.dev/packages/pi-agenticoding)
4-
[![npm version](https://img.shields.io/badge/npm-0.2.0-blue)](https://www.npmjs.com/package/pi-agenticoding)
4+
[![npm version](https://img.shields.io/badge/npm-0.3.0-blue)](https://www.npmjs.com/package/pi-agenticoding)
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

@@ -40,7 +40,7 @@ Then disable pi's built-in compaction so handoff stays in control:
4040
}
4141
```
4242

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

4545
---
4646

@@ -49,10 +49,10 @@ That's it. Your agent now has `spawn`, `ledger_add`, `ledger_get`, `ledger_list`
4949
| Feature | What it looks like |
5050
|---------|-------------------|
5151
| **Context usage %** | `ctx 65%` in status bar — green < 30%, yellow < 50%, orange < 70%, red ≥ 70% |
52-
| **Ledger count** | 📒 `3` when entries exist, hidden when empty |
52+
| **Notebook count** | 📒 `3` when pages exist, dim `📒 0` when empty |
5353
| **`/handoff` command** | Instant pivot — agent drafts brief, compacts context, resumes |
54-
| **`/ledger` command** | Overlay showing all entries with previews |
55-
| **Auto-rehydration** | Ledger entries survive session restarts |
54+
| **`/notebook` command** | Overlay showing all notebook pages with previews |
55+
| **Auto-rehydration** | Notebook pages survive session restarts |
5656
| **Spawn transparency** | Watch child agents work in real time in the TUI |
5757
| **Token cost visibility** | Each spawn reports input/output tokens, cache hits, and cost |
5858
| **No polling** | Writes serialized via a process-local lock — no race conditions |
@@ -86,17 +86,17 @@ You: "Add OAuth to the backend"
8686
spawn("audit current auth code")
8787
8888
89-
ledger_add("oauth-decisions", "Flow: PKCE. Scope: read+write.")
89+
notebook_write("oauth-decisions", "Flow: PKCE. Scope: read+write.")
9090
9191
├── spawn("implement token endpoint")
9292
└── spawn("write tests")
9393
9494
9595
handoff("Wire OAuth routes into the middleware stack.
96-
Ledger 'oauth-decisions' holds the constraints.")
96+
Notebook page 'oauth-decisions' holds the constraints.")
9797
```
9898

99-
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.**
99+
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.**
100100

101101
---
102102

@@ -106,15 +106,15 @@ The agent decided to spawn research children, save reusable findings to the ledg
106106

107107
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).
108108

109-
### Ledger — Continuity Across Cuts
109+
### Notebook — Continuity Across Cuts
110110

111-
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.**
111+
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.
112112

113113
### Handoff — Deliberate Compaction
114114

115-
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.
115+
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.
116116

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

119119
---
120120

@@ -139,7 +139,7 @@ A single summary blob mixes durable knowledge with transient situational context
139139
| Operation | Primitive | What It Prevents |
140140
|-----------|-----------|-----------------|
141141
| **Isolate** | Spawn | Context pollution from noisy subtasks |
142-
| **Persist** | Ledger | Knowledge loss across resets and pivots |
142+
| **Persist** | Notebook | Knowledge loss across resets and pivots |
143143
| **Compact** | Handoff | Degradation from overstuffed context |
144144

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

158158
---
159159

@@ -166,18 +166,18 @@ The extension hooks into pi's lifecycle:
166166

167167
| Hook | What it does |
168168
|------|-------------|
169-
| `before_agent_start` | Injects context management primer + live ledger listing into system prompt |
169+
| `before_agent_start` | Injects context management primer + live notebook index into system prompt |
170170
| `context` | Injects advisory watchdog reminders when context > 30% |
171-
| `session_start` | Rehydrates ledger from persisted entries; resets on `/new` |
172-
| `turn_end` | Updates TUI indicators (context %, ledger count) |
171+
| `session_start` | Rehydrates notebook pages from persisted entries; resets on `/new` |
172+
| `turn_end` | Updates TUI indicators (context %, notebook count) |
173173
| `agent_end` | Records last context usage percent |
174174
| `session_before_compact` | Consumes pending handoff task and sets it as compaction summary |
175175

176176
All state lives in a single `AgenticodingState` instance:
177177

178178
```typescript
179179
interface AgenticodingState {
180-
ledger: Map<string, string>
180+
notebookPages: Map<string, string>
181181
epoch: number
182182
lastContextPercent: number | null
183183
pendingHandoff: { task, source } | null
@@ -190,6 +190,12 @@ interface AgenticodingState {
190190

191191
</details>
192192

193+
<details>
194+
<summary><strong>Deep dive → ARCHITECTURE.md</strong></summary>
195+
196+
See [ARCHITECTURE.md](ARCHITECTURE.md) for full module breakdown, tool schemas, lifecycle wiring, spawn child-session lifecycle, and notebook rehydration algorithm.
197+
198+
</details>
193199
---
194200

195201
## Contributing

0 commit comments

Comments
 (0)