@roodriigoooo/pi-docket 0.4.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.
Files changed (43) hide show
  1. package/CHANGELOG.md +132 -0
  2. package/LICENSE +21 -0
  3. package/README.md +241 -0
  4. package/assets/docket_logo.jpeg +0 -0
  5. package/docs/adr/0001-bundle-first-checkpoints.md +21 -0
  6. package/docs/adr/0002-rename-to-docket.md +44 -0
  7. package/docs/architecture.md +101 -0
  8. package/docs/bundle-guidelines.md +39 -0
  9. package/docs/configuration.md +191 -0
  10. package/docs/releases/0.4.0.md +93 -0
  11. package/extensions/artifact-catalog.ts +467 -0
  12. package/extensions/background-work.ts +510 -0
  13. package/extensions/checkpoint-commands.ts +147 -0
  14. package/extensions/checkpoint-lifecycle.ts +195 -0
  15. package/extensions/checkpoint-selector.ts +162 -0
  16. package/extensions/checkpoint-store.ts +230 -0
  17. package/extensions/checkpoint-summarizer.ts +141 -0
  18. package/extensions/docket-command-grammar.ts +319 -0
  19. package/extensions/docket-command-router.ts +626 -0
  20. package/extensions/docket-config.ts +88 -0
  21. package/extensions/docket-extension-surface.ts +43 -0
  22. package/extensions/docket-navigator.ts +585 -0
  23. package/extensions/docket.README.md +46 -0
  24. package/extensions/docket.ts +2965 -0
  25. package/extensions/event-log.ts +121 -0
  26. package/extensions/git-context.ts +44 -0
  27. package/extensions/loaded-artifact-context.ts +228 -0
  28. package/extensions/search-index.ts +140 -0
  29. package/extensions/types.ts +40 -0
  30. package/extensions/worker-activity.ts +402 -0
  31. package/extensions/worker-changes.ts +180 -0
  32. package/extensions/worker-commands.ts +251 -0
  33. package/extensions/worker-dock-cache.ts +147 -0
  34. package/extensions/worker-events.ts +87 -0
  35. package/extensions/worker-eviction.ts +55 -0
  36. package/extensions/worker-guardrails.md +125 -0
  37. package/extensions/worker-kinds/patcher.md +23 -0
  38. package/extensions/worker-kinds/scout.md +17 -0
  39. package/extensions/worker-kinds.ts +280 -0
  40. package/extensions/worker-result.ts +193 -0
  41. package/extensions/worker-store.ts +621 -0
  42. package/extensions/worker-summary-embed.ts +98 -0
  43. package/package.json +53 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,132 @@
1
+ # Changelog
2
+
3
+ ## 0.4.0
4
+
5
+ - **rename to pi-docket**: product, package, repo title, command, storage paths, worker tools, tmux session, and extension surface now use Docket. Package is `@roodriigoooo/pi-docket`; GitHub repo title should be `pi-docket`; command is `/docket`; extension surface is `globalThis.__docket`; worker tmux session is `docket-workers`.
6
+ - **no compatibility command aliases**: old `/trail` commands are intentionally not retained. Removed public grammar for `/docket checkpoint`, `/docket continue`, `/docket resume`, short aliases (`ckpt`, `r`, `s`, `v`), worker-result aliases (`w<N>`, `result`, `use`), and `inject` alias. The command surface now favors explicit verbs.
7
+ - **evidence bundles replace checkpoint-first UX**: use `/docket save` to save selected evidence as a durable zero-token bundle and label the current Pi tree leaf; use `/docket load` to mount bundle or worker artifacts. Pi's native `/tree`, `/fork`, `/clone`, `/compact`, `/new`, and `/resume` remain responsible for session movement and context topology.
8
+ - **worker protocol renamed**: workers now call `docket_todos`, `docket_wait`, `docket_done`, `docket_fail`, and `docket_spawn_child`. Worker-side `/docket wait|done|fail` remains only a fallback for prompt entry mistakes.
9
+ - **release notes**: see [docs/releases/0.4.0.md](docs/releases/0.4.0.md) for rationale, migration notes, and repository rename checklist.
10
+
11
+ ## 0.3.2
12
+
13
+ - **bundle-first checkpoints**: a checkpoint is now a frozen artifact bundle (`<id>.artifacts.json`) plus a small deterministic orientation header — git state, files touched, errors, and your note — not a model summary. `continue` and `load` both *mount* the bundle at zero model-context tokens; `continue` injects only the header, and artifacts are chipped on demand. The model summarizer becomes an opt-in `--summarize` layer (`--model` / `--max-output` imply it), off the default path. The four mode flags (`--handoff` / `--compact` / `--debug` / `--review`) and `--raw` are dropped in favour of one default selection that the interactive selector prunes. Checkpoints written by older versions still read and continue (`CheckpointMode` kept for back-compat reads). Rationale in [ADR-0001](docs/adr/0001-bundle-first-checkpoints.md); a new `CONTEXT.md` glossary fixes the "checkpoint = bundle, not summary" ambiguity.
14
+ - **verdict card**: a focused per-worker decision surface. Open it with `ctrl+shift+d` (jumps to the highest-attention decision), `/docket v` / `/docket verdict [w<N>]`, or `enter` on a worker row. It reads only status fields and the deterministic change set — the worker's intent line, its question, or the diffstat (`+/-` with a proportional bar) — never the transcript or artifacts, so it costs zero model-context tokens. `d` opens the full diff in an overlay without injecting it.
15
+ - **worker-proposed decisions**: `docket_wait({ risk?, options?, recommend? })` lets a blocked worker propose discrete branches. The card renders them as the menu (sent back to the worker verbatim), pre-selects the recommended option, and surfaces `risk` as a warning — ADR-0001's human-authored-note lesson applied to the question side.
16
+ - **verdict queue**: opening the card without a target now walks every pending decision in attention order instead of resolving only the top one — the footer counts what's left and `esc` stops the walk. It re-ranks after each resolution so new arrivals and dismissals stay current. Verbs name the outcome: **promote** / **discard** when a change set exists, **acknowledge** / **dismiss** when it doesn't, plus **reject & stop** and **chat**; a cancelled sub-action returns to the verb menu instead of closing the card.
17
+ - **live dock dot**: the frozen `[o ]` worker chip becomes a breathing dot that animates only while a worker is active; static mascot frames are stripped from one-shot spawn messages.
18
+ - **cross-project worker views**: `/docket workers --all` and `/docket list --all` surface workers from other projects, and the dock breadcrumb summarizes their attention state (`N waiting · N failed · N ready`) instead of a bare count.
19
+ - new tests cover verdict verbs/queue, the change-set card, structured `docket_wait`, bundle-first checkpoint selection + orientation header, and cross-project worker ranking.
20
+
21
+ ## 0.3.1
22
+
23
+ - **auto-embed ready summary**: when a worker reaches `ready`, docket appends a short summary (outcome + one-line headline + up to five recommended bullets) to the parent pi session via `pi.sendMessage({ triggerTurn: false })`. The parent assistant sees it on its next turn without manual `/docket inject`, and any worker spawned afterwards inherits it through session seeding — so sibling findings cross-pollinate without a dedicated channel. Full artifacts still live on disk; `/docket load w<N>` remains the path for the long-form detail. Gated by `worker.autoEmbedSummary` (default true) for users who prefer the pure-ledger behavior. New pure formatter `formatReadyEmbedMessage` in `extensions/worker-summary-embed.ts` is fully testable without pi.
24
+ - **kind visibility in the UI**: the worker kind now shows in three surfaces that previously only labelled the worker by index. Dock row renders `● w1·scout …` next to the label; the spawn announce chip becomes `w3·patcher[o ] · starting`; the spawn-detail and the `/docket w<N>` mini-report both gain an explicit `kind:` line. The implicit `default` kind is suppressed everywhere to keep the common case clean. Model badge keeps its existing brackets so kind and model are visually distinct.
25
+
26
+ ## 0.3.0
27
+
28
+ Included:
29
+ - **worker kinds**: frontmatter MD presets that tune one worker's posture without changing the protocol contract. Bundled `scout` (fast read-only recon) and `patcher` (edits in worktree, can dispatch scout) under `extensions/worker-kinds/`; user overrides in `~/.pi/agent/docket/worker-kinds/*.md` and `<project>/.pi/docket/worker-kinds/*.md`. Fields: `name`, `description`, `model`, `thinking`, `read_only`, `default_worktree`, `parent_seed`, `max_artifacts`, `max_duration_sec`, `can_spawn`, `layout`, `guardrails_append`, plus a markdown body that is *appended* to the universal guardrails (never replaces them).
30
+ - **`/docket spawn --as <kind>`**: pick a kind per spawn. `/docket kinds` lists registered kinds.
31
+ - **fleet + depth caps**: `worker.maxActive` (default 8) rejects spawns past the cap with a clear error rather than queuing. `worker.maxSpawnDepth` (default 2) bounds how deep child spawns can recurse.
32
+ - **cascade delete**: `/docket delete w<N>` now purges children dispatched via `docket_spawn_child` along with the parent.
33
+ - **`docket_spawn_child` tool**: only registered for workers whose kind has a `can_spawn` allowlist and only when current depth is below the cap. Child status carries `parentWorkerId`/`depth`; child outcome surfaces in the parent worker's inbox, not directly to the human user.
34
+ - **stable tmux window id**: `tmuxWindowId` (`@N`) captured at spawn time. kill, send-keys, and pipe-pane target the id first with name fallback, so renamed/recycled windows no longer misroute parent input.
35
+ - **per-kind tmux layout**: `layout: split-events` opens a right pane showing `tail -F events.ndjson` so the user can watch tool activity live without context switching.
36
+ - **optional tmux status-line dock**: `worker.tmuxStatusLine: true` writes a compact `docket ?N ✗N ✓N ●N` summary to the shared session's `status-right` so the dock survives even when you're attached to a pane.
37
+ - **optional terminal capture**: `worker.captureTerminal: true` enables `tmux pipe-pane` to `pane.log` inside each worker dir for post-hoc debug.
38
+ - **`/docket respawn <w<N>|all>`**: relaunch workers whose tmux window died (orphan reconciliation no longer means losing the session dir).
39
+ - **`globalThis.__docket` extension surface**: `registerWorkerKind`, `listWorkerKinds`, `onWorkerEvent`. Other pi extensions can contribute kinds at runtime and subscribe to worker events without coupling to docket internals.
40
+ - **worker event subscription**: `WorkerSnapshotCache.snapshot()` now returns `newEventsByWorker` (events read this tick) alongside the existing sticky `eventsByWorker` ring. The parent dock pipes new events through the extension surface on every refresh.
41
+ - new tests cover worker-kinds parsing + registry, extension surface, grammar (`--as`, `kinds`, `respawn`), cascade purge, and `countActive`.
42
+ - **docs cleanup**: README slimmed (587 → ~400 lines) and points at new `docs/configuration.md` for the full config reference, worker-kind frontmatter table, and worked kind examples. `docs/architecture.md` rewritten as a module map + worker lifecycle + storage + extension surface. `docs/stress-test.md` moved out of `scripts/` and inlined the sampler so it has no external dependency. `docs/design-decisions-tmux-and-events.md` removed; same content now lives in much shorter form in `docs/architecture.md`. `scripts/` removed from the package and gitignored. npm-pack leak of personal stress-test results closed by moving the file to a hidden, gitignored path.
43
+ - **README banner**: npm version badge.
44
+
45
+ ## 0.2.2
46
+
47
+ Included:
48
+ - shared `docket-workers` tmux session: one server hosts every worker window instead of N servers
49
+ - worker NDJSON event stream at `workers/<id>/events.ndjson` for state, todo, and tool-call events
50
+ - dock sub-line under thinking workers showing the latest non-protocol tool call (file path, command, etc.)
51
+ - `WorkerSnapshotCache` keeps a sticky recent-event buffer so sub-lines survive across refresh ticks
52
+ - `fs.watch`-driven dock refresh in place of the 500 ms polling timer, with mtime-cached status + artifacts reads
53
+ - heartbeat dedup: workers skip `writeArtifacts` when their artifact list signature is unchanged
54
+ - session JSONL seeding (`SessionManager.forkFrom`) so spawned workers resume from the parent's prefix and hit the provider's prompt cache. Opt out with `/docket spawn --fresh`
55
+ - `/docket attach [w<N>]` first-class command that copies the tmux attach incantation, optionally pinned to one worker
56
+ - idle eviction: ended workers auto-hide from the dock after `worker.dockIdleHideMinutes` (default 30) and auto-prune after `worker.pruneAfterHours` (default 24)
57
+ - worker guardrails note that the tmux session is shared; workers must not invoke `tmux` directly
58
+ - README simplified, outdated demo gifs removed
59
+ - stress-test runbook + sampler under `scripts/`
60
+ - architecture doc resynced (storage layout, shared topology, event stream, eviction)
61
+
62
+ ## 0.2.1
63
+
64
+ Included:
65
+ - README rewrite with a more direct, personal tone
66
+ - note that current GIFs are outdated and need refreshing
67
+
68
+ ## 0.2.0
69
+
70
+ Included:
71
+ - compact worker dock above the prompt for live worker state without context injection
72
+ - worker protocol tools (`docket_wait`, `docket_done`, `docket_fail`) plus bash fallback interception for accidental `/docket wait|done|fail` calls
73
+ - `/docket tell w<N> [text]` for explicit worker input/follow-up, with modal input when text is omitted
74
+ - simplified Navigator modes: Review, Answers, All
75
+ - hard rename from Memory to Answers and Catalog to All
76
+ - numeric mode keys (`1` Review, `2` Answers, `3` All) and `t` for telling workers
77
+ - `/docket workers` positioned as a debug/power view with clearer labels
78
+ - docs and tests for updated worker/mode UX
79
+
80
+ ## 0.1.4
81
+
82
+ Included:
83
+ - soft-consume for `--once` checkpoints: marked consumed at session end (not on inject), files retained for `consumedRetentionDays` (default 7) so accidental cancels are recoverable
84
+ - `/docket load [id|last|w<N>] [--include-consumed]` — lazy carryover of checkpoint or worker artifacts into the navigator with **zero** model-context cost; injected only when user creates a chip with `/docket ref` or `/docket inject-full`
85
+ - unified `/docket load` picker for checkpoints and workers, with preview for checkpoints before loading
86
+ - `/docket unload <id|w<N>|all>` — drop loaded checkpoint/worker artifacts from the session and cancel pending checkpoint consume contracts
87
+ - tmux-backed `/docket spawn <task>` workers, plus `/docket list --workers`, `/docket load w<N>`, and `/docket delete w<N>`
88
+ - worker artifact snapshots so parent sessions can inspect and reference worker findings via loaded slots
89
+ - JSONL-backed checkpoint event log with legacy index backfill
90
+ - navigator `s` key cycles source filter (current / all / `c1` / `w1` / ...); default view is `current`
91
+ - carryover artifacts namespaced as `<slot>.<displayId>` (e.g. `c1.f12` or `w2.c3`), refs unchanged
92
+ - `/docket list [--include-consumed]` shows soft-consumed checkpoints
93
+ - `/docket delete` permanently purges checkpoints (bypasses soft-consume) and kills workers when targeting `w<N>`
94
+ - internal deepening: Loaded Artifact Context, Checkpoint Commands, and Worker Commands concentrate reference/carryover and command-flow logic behind tested Modules
95
+
96
+ ## 0.1.3
97
+
98
+ Included:
99
+ - ranked artifact search index backing `/docket search`, with ripgrep-backed candidate scoring and in-memory fallback
100
+ - npm trusted publishing pipeline for releases
101
+ - README demo videos / gif walkthroughs
102
+
103
+ ## 0.1.2
104
+
105
+ Included:
106
+ - cleaner checkpoint reference lists with single file guidance note
107
+ - hidden checkpoint context loading for `/docket continue` to avoid editor prompt bloat
108
+ - loaded checkpoint chip above the editor
109
+ - `/docket delete [id|last]` command
110
+ - checkpoint selector delete action with confirmation
111
+
112
+ ## 0.1.1
113
+
114
+ Included:
115
+ - centered Docket command-center overlay with stronger island borders
116
+ - denser artifact rows with filter chips, relative time, and preview toggle
117
+ - interactive `/docket resume` / `/docket continue` checkpoint selector
118
+ - checkpoint preview and edit-before-continue flow
119
+ - checkpoint summaries with file, error, command, and token estimates
120
+
121
+ ## 0.1.0
122
+
123
+ Initial package scaffold.
124
+
125
+ Included:
126
+ - `/docket` artifact navigator
127
+ - artifact search via ripgrep-backed temp docs
128
+ - compact artifact references
129
+ - full artifact injection
130
+ - summarized/raw checkpoints
131
+ - one-off `--once` checkpoints
132
+ - checkpoint sidecar artifacts
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Docket contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,241 @@
1
+ <p align="center">
2
+ <img src="./assets/docket_logo.jpeg" alt="Docket logo" width="220" />
3
+ </p>
4
+
5
+ <p align="center">
6
+ <a href="https://www.npmjs.com/package/@roodriigoooo/pi-docket"><img src="https://img.shields.io/npm/v/@roodriigoooo/pi-docket?color=cb3837&label=npm&logo=npm" alt="npm version" /></a>
7
+ </p>
8
+
9
+ # pi-docket
10
+
11
+ Docket is a decision queue for work done inside pi.
12
+
13
+ It pulls the few moments that need human judgment out of long agent work: worker findings, proposed patches, failed commands, saved evidence bundles, and questions. It is not a transcript browser, not a memory system, and not a task manager. Docket keeps evidence available and asks: **what needs a decision now?**
14
+
15
+ > Formerly `trail`. The rename is intentional: the product is no longer framed as a history trail or session-resume system. Docket is a docket of cases needing judgment, with evidence bundles attached.
16
+
17
+ ## Core philosophy
18
+
19
+ - **Pi owns sessions.** Use pi's `/tree`, `/fork`, `/clone`, `/compact`, `/new`, and `/resume` for conversation topology and context-window management.
20
+ - **Docket owns decisions.** It ranks artifacts into review items, shows cards, and keeps evidence out of model context until you attach it.
21
+ - **tmux owns parallel visibility.** Workers are visible pi processes in one shared tmux session. You can attach and inspect them directly.
22
+ - **Workers are explicit.** Docket may eventually suggest a worker only when context-heavy work is obvious and maps to a known worker kind. It must never silently spawn.
23
+
24
+ ## Install
25
+
26
+ ```bash
27
+ pi install git:github.com/roodriigoooo/pi-docket
28
+ ```
29
+
30
+ Open Docket:
31
+
32
+ ```bash
33
+ /docket
34
+ ```
35
+
36
+ Spawn a worker explicitly:
37
+
38
+ ```bash
39
+ /docket spawn --as scout map callers of getUser()
40
+ ```
41
+
42
+ Save evidence as a zero-token bundle:
43
+
44
+ ```bash
45
+ /docket save auth investigation findings
46
+ ```
47
+
48
+ Load a bundle or worker artifacts:
49
+
50
+ ```bash
51
+ /docket load last
52
+ /docket load w1
53
+ ```
54
+
55
+ ## Rename from Trail
56
+
57
+ This release is a breaking rename.
58
+
59
+ - Package: `@roodriigoooo/pi-docket`
60
+ - GitHub repo title: `pi-docket`
61
+ - Slash command: `/docket`
62
+ - Old `/trail` commands are not kept as aliases.
63
+ - Worker protocol tools are now `docket_wait`, `docket_done`, `docket_fail`, `docket_todos`, and `docket_spawn_child`.
64
+ - Storage/config paths now use `docket`:
65
+ - `~/.pi/agent/docket/`
66
+ - `~/.pi/agent/docket.json`
67
+ - `<project>/.pi/docket.json`
68
+ - `<project>/.pi/docket/worker-kinds/*.md`
69
+
70
+ If you need old data, copy it manually before deleting the old package:
71
+
72
+ ```bash
73
+ cp -R ~/.pi/agent/trail ~/.pi/agent/docket
74
+ cp ~/.pi/agent/trail.json ~/.pi/agent/docket.json 2>/dev/null || true
75
+ cp -R .pi/trail .pi/docket 2>/dev/null || true
76
+ cp .pi/trail.json .pi/docket.json 2>/dev/null || true
77
+ ```
78
+
79
+ ## Basic loop
80
+
81
+ ```text
82
+ work / spawn capture decide act
83
+ current pi -> artifacts -> /docket cards -> Enter review
84
+ /docket spawn status.json evidence c reply/save
85
+ bundles/workers a attach ref
86
+ ```
87
+
88
+ 1. **Work or spawn** — keep working in the parent session, or explicitly start a background worker with `/docket spawn`.
89
+ 2. **Capture** — Docket records failed commands, file changes, worker results, saved bundles, and questions.
90
+ 3. **Decide** — `/docket` opens only items that likely need attention.
91
+ 4. **Act** — review, reply, promote, dismiss, attach evidence, save/load bundles, or attach to tmux.
92
+
93
+ ## Commands
94
+
95
+ Primary commands:
96
+
97
+ | Command | Purpose |
98
+ |---|---|
99
+ | `/docket` | Open decision docket. |
100
+ | `/docket spawn [--fresh] [--as <kind>] <task>` | Start explicit background worker. |
101
+ | `/docket tell w<N> [text]` | Reply to worker. |
102
+ | `/docket attach [w<N>]` | Copy tmux attach command for shared worker session. |
103
+ | `/docket save [flags] [note]` | Save selected evidence as bundle and label current pi tree leaf. |
104
+ | `/docket load [id\|last\|w<N>]` | Mount bundle or worker artifacts at zero model-context cost. |
105
+
106
+ Advanced commands:
107
+
108
+ | Command | Purpose |
109
+ |---|---|
110
+ | `/docket workers [--all]` | Worker dashboard. |
111
+ | `/docket verdict [w<N>]` | Resolve highest-attention worker decision. |
112
+ | `/docket kinds` | List worker kinds. |
113
+ | `/docket respawn <w<N>\|all>` | Relaunch worker whose tmux window died. |
114
+ | `/docket answers [query]` | Browse assistant/worker answers. |
115
+ | `/docket log` | Audit timeline grouped by episode. |
116
+ | `/docket search <query>` | Ranked artifact search. |
117
+ | `/docket list [--include-consumed] [--workers\|--all]` | List saved bundles or workers. |
118
+ | `/docket unload <id\|w<N>\|all>` | Drop mounted bundle/worker artifacts. |
119
+ | `/docket delete [id\|last\|w<N>]` | Delete bundle or worker. Worker delete cascades to children. |
120
+ | `/docket ref <artifact-id>` | Attach compact artifact reference to next prompt. |
121
+ | `/docket inject-full <artifact-id>` | Attach full artifact text to next prompt. |
122
+ | `/docket copy <artifact-id>` | Copy artifact text. |
123
+ | `/docket clear` | Drop pending chips/widgets. |
124
+
125
+ No short aliases are intentionally provided. Fewer commands, clearer intent.
126
+
127
+ ## Evidence bundles
128
+
129
+ A Docket bundle is a frozen artifact sidecar plus a small orientation markdown file. It is not a model-written summary by default.
130
+
131
+ `/docket save`:
132
+
133
+ - selects relevant artifacts,
134
+ - lets you prune/edit the bundle header,
135
+ - writes `<id>.md` + `<id>.artifacts.json`,
136
+ - labels the current pi session tree leaf as `docket:<id>`.
137
+
138
+ `/docket load` mounts bundle artifacts into the current session's Docket navigator at zero model-context cost. Nothing enters the model prompt until you explicitly attach a compact ref or full artifact.
139
+
140
+ This deliberately complements pi:
141
+
142
+ - use `/tree` to move conversation state,
143
+ - use `/fork` or `/clone` to split sessions,
144
+ - use `/compact` for lossy summary,
145
+ - use `/docket save` for durable evidence,
146
+ - use `/docket load` when that evidence becomes relevant.
147
+
148
+ ## Workers
149
+
150
+ `/docket spawn <task>` starts a background pi worker as one window in a shared tmux session named `docket-workers`.
151
+
152
+ Workers have:
153
+
154
+ - hidden workspace, often a detached git worktree,
155
+ - task file,
156
+ - `status.json`,
157
+ - `artifacts.json`,
158
+ - append-only `events.ndjson`,
159
+ - protocol tools for parent communication.
160
+
161
+ Worker artifacts never enter model context automatically except for the short ready summary, if enabled. Full evidence stays on disk until loaded or attached.
162
+
163
+ ### Worker kinds
164
+
165
+ Bundled kinds:
166
+
167
+ - `default` — general worker, edits allowed when task asks.
168
+ - `scout` — fast read-only recon.
169
+ - `patcher` — edits in worker worktree and proposes a change set.
170
+
171
+ Examples:
172
+
173
+ ```bash
174
+ /docket spawn --as scout find route handlers that touch auth cookies
175
+ /docket spawn --as patcher rename AccountService in src only
176
+ ```
177
+
178
+ Custom kinds live in:
179
+
180
+ - `~/.pi/agent/docket/worker-kinds/*.md`
181
+ - `<project>/.pi/docket/worker-kinds/*.md`
182
+
183
+ See [docs/configuration.md](./docs/configuration.md#worker-kinds).
184
+
185
+ ### Worker protocol
186
+
187
+ Workers use tools, not shell commands:
188
+
189
+ | Tool | Purpose |
190
+ |---|---|
191
+ | `docket_todos` | Publish small progress board. |
192
+ | `docket_wait` | Ask parent for input and pause. |
193
+ | `docket_done` | Mark useful output ready for review. |
194
+ | `docket_fail` | Mark cannot continue with no useful partial output. |
195
+ | `docket_spawn_child` | Dispatch allowed child worker kind. |
196
+
197
+ Worker-side `/docket wait`, `/docket done`, and `/docket fail` are fallback prompt commands only.
198
+
199
+ ## tmux
200
+
201
+ All workers live in one shared tmux session:
202
+
203
+ ```bash
204
+ tmux attach -t docket-workers
205
+ ```
206
+
207
+ `/docket attach` copies the attach command. `/docket attach w2` selects that worker's window.
208
+
209
+ This is intentional: tmux gives direct observability and real parallelism, while Docket controls artifact capture and parent/worker coordination.
210
+
211
+ ## Development
212
+
213
+ Run from repo:
214
+
215
+ ```bash
216
+ pi --no-extensions -e ./extensions/docket.ts
217
+ ```
218
+
219
+ Smoke test:
220
+
221
+ ```bash
222
+ npm run smoke:help
223
+ ```
224
+
225
+ Type check:
226
+
227
+ ```bash
228
+ npm run check
229
+ ```
230
+
231
+ Tests:
232
+
233
+ ```bash
234
+ npm test
235
+ ```
236
+
237
+ Dry-run package:
238
+
239
+ ```bash
240
+ npm run pack:dry
241
+ ```
Binary file
@@ -0,0 +1,21 @@
1
+ # Bundle-first checkpoints
2
+
3
+ Superseded in public UX by [ADR-0002](./0002-rename-to-docket.md): users now see **evidence bundles** via `/docket save` and `/docket load`; Pi owns session continuation. Internal storage still uses checkpoint type names for compatibility.
4
+
5
+ A checkpoint is a frozen **artifact bundle** (`<id>.artifacts.json`) plus a small deterministic **orientation header** — not a model-written summary. The old `continue` path opened a fresh session, **mounted** the bundle at zero model-context tokens, and injected only the header (git, files touched, errors, the human-authored note); artifacts were chipped on demand. The model summarizer became an opt-in `--summarize` layer, off the default path. The four modes (`handoff/compact/debug/review`) were dropped in favour of one default selection (errors + files + recent decisions) that the interactive selector prunes.
6
+
7
+ ## Status
8
+
9
+ accepted
10
+
11
+ ## Considered options
12
+
13
+ - **Summary-first (previous default):** the summarizer ran on every checkpoint and `continue` injected its prose. Rejected: it contradicts Docket's stated thesis ("it keeps the useful artifacts around" rather than "compressing everything into a summary"), pays a model call per checkpoint, bloats the fresh session's context, and lets the model *invent* decisions/next-steps — the one thing its own system prompt warned against.
14
+ - **Keep four modes:** rejected once the summarizer left the hot path — the modes reduced to thin kind-orderings that the interactive selector already supersedes.
15
+
16
+ ## Consequences
17
+
18
+ - The **note** is now load-bearing: decisions and next steps are human-authored, not model-guessed. Checkpoint quality tracks what the human writes.
19
+ - `continue` no longer puts artifact *contents* in context on turn 1 — only the orientation header. Resuming work needs a chip or a question first. This is deliberate and matches the zero-token philosophy that `load` already embodied.
20
+ - `continue` now composes `load` (both mount); they stop being separate restore paths.
21
+ - The summarizer module, provider/model config, and the `CheckpointMode` branch stay in-tree but become optional/back-compat surface, not the spine.
@@ -0,0 +1,44 @@
1
+ # Rename Trail to Docket
2
+
3
+ Trail is renamed to **Docket** and the repository/package title becomes **pi-docket**.
4
+
5
+ ## Status
6
+
7
+ accepted
8
+
9
+ ## Context
10
+
11
+ The old name, Trail, suggested a history path, transcript browser, or session-resume tool. That conflicted with the product direction.
12
+
13
+ Pi already provides first-class session topology and context-management tools: `/tree`, `/fork`, `/clone`, `/compact`, `/new`, and `/resume`. Docket should respect those instead of competing with them.
14
+
15
+ The extension's stronger identity is a decision queue: artifacts become review items, workers produce evidence, verdict cards resolve cases, and evidence bundles can be mounted at zero model-context cost.
16
+
17
+ ## Decision
18
+
19
+ Rename the product surface to Docket:
20
+
21
+ - package: `@roodriigoooo/pi-docket`
22
+ - repo title: `pi-docket`
23
+ - command: `/docket`
24
+ - extension entrypoint: `extensions/docket.ts`
25
+ - extension surface: `globalThis.__docket`
26
+ - worker tmux session: `docket-workers`
27
+ - worker protocol tools: `docket_todos`, `docket_wait`, `docket_done`, `docket_fail`, `docket_spawn_child`
28
+ - config/storage paths: `~/.pi/agent/docket*` and `.pi/docket*`
29
+
30
+ Do not keep `/trail` compatibility aliases. Command bloat works against the new clarity.
31
+
32
+ Replace checkpoint-first user language with **evidence bundle** language:
33
+
34
+ - `/docket save` creates a durable evidence bundle and labels the current Pi tree leaf.
35
+ - `/docket load` mounts bundle or worker artifacts at zero model-context cost.
36
+ - Pi owns continuation and branch/session movement.
37
+
38
+ ## Consequences
39
+
40
+ - This is a breaking release.
41
+ - Users must move from `/trail` to `/docket`.
42
+ - Old Trail storage is not automatically read from the new Docket paths. Migration is a copy operation documented in README and release notes.
43
+ - Internal TypeScript module names may still use `checkpoint` where storage compatibility makes a full rename low-value.
44
+ - Future spawn suggestions, if added, must be rare and explicit: only when context-heavy work is obvious, maps to a known worker kind, and separate context protects the parent session.
@@ -0,0 +1,101 @@
1
+ # Docket Architecture
2
+
3
+ Docket is a pi extension. The unit of work is an **artifact**: a structured object derived from session activity (command, file edit, prompt, response, error, worker status, or saved evidence bundle). A small attention queue ranks unresolved artifacts as **review items**; the **verdict** card is where one worker decision is resolved — reading only status fields and the deterministic change set, never the transcript. **Workers** are background pi processes; **evidence bundles** are durable artifact packages. Pi owns session movement; Docket owns evidence and decisions. Rename rationale lives in [ADR-0002](./adr/0002-rename-to-docket.md).
4
+
5
+ If you're contributing, read this end-to-end. If you're using Docket, the README and [configuration.md](./configuration.md) are what you want.
6
+
7
+ ## Module map
8
+
9
+ Each module owns its data, its interface, and its tests. Adapters at the seam talk to pi, tmux, the filesystem, or the clipboard.
10
+
11
+ | Module | File | Owns |
12
+ |---|---|---|
13
+ | Artifact Catalog | `extensions/artifact-catalog.ts` | Extraction, identity, lookup, references, full text, inspect, bundle payloads. |
14
+ | Search Index | `extensions/search-index.ts` | Ripgrep adapter over artifact docs, in-memory fallback, attention-weighted ranking. |
15
+ | Bundle Lifecycle | `extensions/checkpoint-lifecycle.ts` | Bundle-first: select candidates → user prune → orientation header (opt-in `--summarize`) → review → persist. Internal type names still use checkpoint for storage compatibility. See [ADR-0001](./adr/0001-bundle-first-checkpoints.md). |
16
+ | Bundle Store | `extensions/checkpoint-store.ts` | Markdown + sidecar JSON on disk; event-backed lifecycle; soft-consume. |
17
+ | Bundle Commands | `extensions/checkpoint-commands.ts` | `list` / `delete` support for saved bundles. |
18
+ | Bundle Selector | `extensions/checkpoint-selector.ts` | Interactive accept/exclude before optional summarization. |
19
+ | Loaded Artifact Context | `extensions/loaded-artifact-context.ts` | Mounted source slots, reference/full chip expansion, consume-on-use queue. |
20
+ | Background Work | `extensions/background-work.ts` | Worker state transitions, protocol semantics, synthetic status artifacts, heartbeat dedup. |
21
+ | Worker Commands | `extensions/worker-commands.ts` | `spawn` / `tell` / `delete` / `load` / `unload` / completion. |
22
+ | Worker Store | `extensions/worker-store.ts` | Shared tmux session topology, `send-keys -l` stdin, session seeding. |
23
+ | Worker Events | `extensions/worker-events.ts` | NDJSON append + tail + rotation. |
24
+ | Worker Snapshot Cache | `extensions/worker-dock-cache.ts` | mtime-cached status/artifacts read, `fs.watch`, sticky recent-event ring. |
25
+ | Worker Eviction | `extensions/worker-eviction.ts` | Dock idle-hide window, prune-after-hours sweep. |
26
+ | Worker Kinds | `extensions/worker-kinds.ts` | Frontmatter parser, registry, guardrails appendix composer. |
27
+ | Extension Surface | `extensions/docket.ts` (via `globalThis.__docket`) | `registerWorkerKind`, `listWorkerKinds`, `onWorkerEvent`. |
28
+ | Navigator | `extensions/docket-navigator.ts` | View model, ranking, selection state, mode/source transitions. |
29
+ | Command Router | `extensions/docket-command-router.ts` | Routes parsed intents to the modules above. |
30
+
31
+ ## Worker lifecycle
32
+
33
+ 1. `Worker Commands.spawn(task, { as, fresh, worktree })` resolves the kind, checks `maxActive`, calls `Worker Store.spawn`.
34
+ 2. `Worker Store` opens a window in the shared tmux session `docket-workers`. If `parent_seed: full`, it forks the parent's JSONL via `SessionManager.forkFrom` and launches with `--continue`.
35
+ 3. The worker pi writes to `task.md`, ticks `status.json` every 15 s (heartbeat), updates `artifacts.json` only when its signature changes, and appends every state transition / todo update / tool call to `events.ndjson`.
36
+ 4. Parent watches the workers root with `fs.watch` (recursive on macOS, polled fallback elsewhere). `WorkerSnapshotCache` reads new event bytes since its held offset, deduplicates by mtime, and keeps a 16-event sticky ring per worker.
37
+ 5. `Background Work` projects the snapshot into a synthetic status artifact. Navigator ranks it alongside file edits and errors. The dock renders one row per worker plus an event sub-line when thinking.
38
+ 6. Worker calls `docket_done` / `docket_fail` → state goes terminal → row enters `ready` / `failed` until evicted (`worker.dockIdleHideMinutes`) or pruned (`worker.pruneAfterHours`).
39
+
40
+ ## Worker protocol
41
+
42
+ One contract for every kind. The MD body of a kind extends the universal guardrails; it does not replace them.
43
+
44
+ | Tool | When | Effect |
45
+ |---|---|---|
46
+ | `docket_todos` | Multi-step work. | Replaces the visible todo board. |
47
+ | `docket_wait` | Ambiguity, blocked auth, irreversible action. | Worker → `needs_input`, parent gets an inbox row. |
48
+ | `docket_done` | Finished with useful output. | Requires `outcome`, `summary`, `evidence`. Vague work is rejected back to `docket_wait`. |
49
+ | `docket_fail` | Cannot continue, no useful partial output. | Worker → `failed`. |
50
+ | `docket_spawn_child` | Kind has `can_spawn`. | Opens a sibling window; child returns to parent worker, not the human. |
51
+
52
+ `/docket wait` etc. via bash are intercepted inside worker sessions for fallback.
53
+
54
+ ## Storage layout
55
+
56
+ Per-worker state under `~/.pi/agent/docket/workers/<id>/`:
57
+
58
+ | File | Owner | Purpose |
59
+ |---|---|---|
60
+ | `task.md` | parent on spawn | Assignment, read once by the worker. |
61
+ | `status.json` | worker heartbeat + protocol | Current state, mtime-cached by the dock. |
62
+ | `artifacts.json` | worker heartbeat | Snapshot, signature-deduped between heartbeats. |
63
+ | `events.ndjson` | worker live | Append-only event stream; rotated at 5 MB, one generation retained. |
64
+ | `session/` | parent (seeded) | Forked pi JSONL prefix, enables `--continue` + cache reuse. |
65
+ | `workspace/` | parent (seeded) | Detached git worktree isolated from the parent's working copy. |
66
+
67
+ Bundle state under `~/.pi/agent/docket/`:
68
+
69
+ | File | Owner | Purpose |
70
+ |---|---|---|
71
+ | `checkpoints/<id>.md` | Bundle Lifecycle | Orientation markdown. |
72
+ | `checkpoints/<id>.artifacts.json` | Bundle Lifecycle | Sidecar refs, mounted by `/docket load`. |
73
+ | `events.ndjson` | Bundle Store | Append-only lifecycle (save/consume/purge/sweep). |
74
+ | `index.json` | Bundle Store (snapshot) | Compatibility snapshot, rebuilt from `events.ndjson`. |
75
+
76
+ `index.json` is not authoritative — the event log is. It exists so external readers don't break.
77
+
78
+ ## Extension surface
79
+
80
+ Other pi extensions read `globalThis.__docket` (installed once on activation):
81
+
82
+ ```ts
83
+ declare global {
84
+ var __docket: {
85
+ registerWorkerKind(kind: WorkerKind): () => void;
86
+ listWorkerKinds(): WorkerKind[];
87
+ onWorkerEvent(handler: (event: WorkerEvent) => void): () => void;
88
+ };
89
+ }
90
+ ```
91
+
92
+ `onWorkerEvent` fires once per event tail per dock tick. Subscriber errors are caught and dropped — a misbehaving extension cannot crash Docket.
93
+
94
+ ## Key design choices
95
+
96
+ - **One tmux session, N windows.** Pays for one tmux server regardless of fleet size. `send-keys -l` gives a safe parent→worker stdin without inventing a FIFO/socket protocol.
97
+ - **NDJSON event stream over `fs.watch`.** Disk-backed, survives parent restarts, no daemon. Drives the dock without polling. `pipe-pane` captures terminal noise, not structured events — opt-in via `worker.captureTerminal` when debugging.
98
+ - **Heartbeat dedup.** Worker hashes its artifact list each heartbeat; `writeArtifacts` is skipped when unchanged. Quiet workers cost ~0 disk I/O.
99
+ - **mtime-cached reads in the parent.** `WorkerSnapshotCache` skips parse when neither status nor artifacts has changed.
100
+ - **Session seeding for prompt cache.** `/docket spawn` (without `--fresh`) forks the parent JSONL into the worker session dir; worker resumes with `--continue` so the shared prefix is provider-cache eligible.
101
+ - **Kinds extend, never replace.** Every worker runs the universal guardrails; the kind MD is appended. Adding a kind needs zero TypeScript.
@@ -0,0 +1,39 @@
1
+ # Evidence bundle guidelines
2
+
3
+ Docket bundles preserve useful evidence for future decisions. They are not transcript archives and they do not replace Pi's session commands.
4
+
5
+ Use Pi for session movement:
6
+
7
+ - `/tree`
8
+ - `/fork`
9
+ - `/clone`
10
+ - `/compact`
11
+ - `/new`
12
+ - `/resume`
13
+
14
+ Use Docket bundles for evidence:
15
+
16
+ - `/docket save` — save selected artifacts and label current Pi tree leaf.
17
+ - `/docket load` — mount artifacts at zero model-context cost.
18
+ - `/docket ref` / `/docket inject-full` — attach specific artifacts only when needed.
19
+
20
+ ## Principles
21
+
22
+ - Preserve decision-critical evidence only: goal, current state, decisions, failed attempts, dead ends, next steps, and references.
23
+ - Prefer artifact references over pasted content. Quote exact output only when it changes the next action.
24
+ - Separate facts from hypotheses. Do not present guesses, unknowns, or stale plans as decisions.
25
+ - Make failure history explicit enough to avoid repeated mistakes, but remove redundant logs and low-signal output.
26
+ - Keep next steps concrete and ordered.
27
+ - Optimize for context-window health. Smaller bundles are better when they preserve the same continuation power.
28
+
29
+ ## Bundle-first shape
30
+
31
+ An evidence bundle is an artifact sidecar plus a deterministic orientation header — not a summary (see [ADR-0001](./adr/0001-bundle-first-checkpoints.md)). The header carries git state, files touched, errors, and the human note. Artifact contents never auto-enter model context.
32
+
33
+ The **note** is load-bearing: decisions and next steps are human-authored, never model-guessed. `--summarize` adds optional model prose on top.
34
+
35
+ ## Artifact selection
36
+
37
+ Selection pre-picks a decision-oriented set (errors first, then files, commands, recent decisions). Interactive review removes noisy or irrelevant artifacts before persist.
38
+
39
+ Excluded artifacts should stay excluded from the orientation header references and the sidecar JSON.