@ftrdotdev/pi-tracker 0.5.1 → 0.6.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 CHANGED
@@ -11,6 +11,7 @@ pi-tracker is an extension for Pi. It manages todolists in your session.
11
11
  - Declare dependencies between items, so work happens in order.
12
12
  - Persist todolists with the session.
13
13
  - Show the active todolist in a widget above the editor.
14
+ - Start Pi's compaction when a completed item's detail is no longer needed.
14
15
 
15
16
  ## How it works
16
17
 
@@ -28,7 +29,7 @@ supports these actions:
28
29
 
29
30
  | Action | Purpose | Parameters |
30
31
  | ------------- | ----------------------------------------- | ----------------------------------------------------------- |
31
- | `list` | Show all lists and items | — |
32
+ | `list` | Show all lists and items | None |
32
33
  | `create_list` | Create a list (becomes active by default) | `name`, `initial_items?`, `activate?` |
33
34
  | `delete_list` | Delete a list | `list_id` |
34
35
  | `set_active` | Set or clear the active list | `list_id` (optional) |
@@ -56,7 +57,7 @@ list makes it the active list (the widget switches to it); pass
56
57
  The tool validates every call and returns an error that names exactly what to
57
58
  fix: each action accepts only its own parameters, required fields are
58
59
  enforced, and the two `update_item` forms never mix. Read the error and retry
59
- with corrected parameters — not-found errors also list the available ids.
60
+ with corrected parameters. Not-found errors also list the available ids.
60
61
  `update_item` also appends a reminder when one call marks two or more items
61
62
  done and leaves no open items behind (the terminal batch): the working
62
63
  rhythm is to mark each item done in the same turn it completes, never batch
@@ -117,9 +118,9 @@ action, the widget, and the `/tracker` items pane all use that order.
117
118
 
118
119
  The intended rhythm: break multi-step work into items up front (one item per
119
120
  deliverable), work through them one at a time, and mark each done as it
120
- completes. The list — shown in the widget — always shows current progress; the
121
- agent should read it with `list` before starting and after finishing, and
122
- update item text with `update_item` when scope changes.
121
+ completes. The list in the widget always shows current progress. The agent
122
+ reads it with `list` before starting and after finishing, and updates item text
123
+ with `update_item` when scope changes.
123
124
 
124
125
  Failed calls are recoverable: the tool's errors say what to fix, and
125
126
  not-found errors name the available ids. The agent corrects the call and
@@ -177,6 +178,44 @@ whole report of an item's state, so a done item whose dependency was reopened
177
178
  keeps the `✓` there; the `(waiting on ...)` annotation appears in the `list`
178
179
  output and the `/tracker` items pane, which have room for it.
179
180
 
181
+ ### Smart compaction
182
+
183
+ When you complete an item in the active list, pi-tracker asks a small
184
+ classifier whether the **ready items** need the completed work. It judges the
185
+ whole ready frontier in one call, up to `maxCandidates` entries, dependents
186
+ first. Each candidate gets one two-label choice question: `needs-context` or
187
+ `stands-alone`. The answer carries a probability and a `confidence`. When no
188
+ ready item needs the detail, pi-tracker starts Pi's compaction at the settle
189
+ boundary and then resumes the session with a pointer to the next ready item.
190
+
191
+ The feature reads five keys from `tui.json`, under `smartCompaction`:
192
+
193
+ | Key | Type | Default | Meaning |
194
+ | -------------------------- | ---------------- | ------- | ---------------------------------------------------------------------------------------- |
195
+ | `enabled` | boolean | `true` | Turn smart compaction on or off. |
196
+ | `classifier` | string or null | `null` | A `provider/modelId` classifier. `null` uses the preference order: Clef Flash, then TypeSafe Jev, then OpenCode Jev. |
197
+ | `keepContextThreshold` | number in (0, 1) | `0.5` | The probability of `needs-context` at or above which the context is kept. |
198
+ | `keepContextMinConfidence` | number in (0, 1) | `0.5` | The answer confidence below which the context is kept. |
199
+ | `maxCandidates` | integer 1..20 | `8` | How many ready items one classification judges. |
200
+
201
+ `keepContextThreshold` is the probability knob: raise it to compact less often,
202
+ lower it to compact more often. `keepContextMinConfidence` is the second guard:
203
+ when the model's answer is less confident than the floor, pi-tracker keeps the
204
+ context. The gate only adds keeping, so it can never cause a premature
205
+ compaction. `maxCandidates` bounds the classifier input; when more items are
206
+ ready than the cap, the first `maxCandidates` are judged, dependents first.
207
+
208
+ A value outside the range in the table falls back to the default. The feature
209
+ fails open. A disabled feature, no credential-available classifier, a classifier
210
+ error or timeout, an aborted run, or a list with no ready item keeps the full
211
+ context. The classifier input is the item list only. The transcript never leaves
212
+ the session.
213
+
214
+ The `/tui` command edits all five on a **Compaction** tab: `Smart compaction`
215
+ (toggle), `Compaction classifier` (picker), `Keep-context confidence`, `Min
216
+ confidence`, and `Max candidates` (`+` and `-` adjust the numeric rows). The
217
+ Compaction tab appears only while the tracker extension is loaded.
218
+
180
219
  ## Persistence
181
220
 
182
221
  The state lives in the session file. Pi writes a snapshot after every change.
@@ -213,7 +252,7 @@ Registration lives in `package.json` under the `pi` field:
213
252
 
214
253
  ```json
215
254
  "pi": {
216
- "extensions": ["./src/index.ts"]
255
+ "extensions": ["./index.ts"]
217
256
  }
218
257
  ```
219
258
 
@@ -228,12 +267,14 @@ Registration lives in `package.json` under the `pi` field:
228
267
 
229
268
  ## Project structure
230
269
 
231
- | File | Purpose |
232
- | -------------------- | ---------------------------------------------------------------- |
233
- | `src/domain.ts` | Schema domain model (`TodoItem`, `TodoList`, `TrackerState`) |
234
- | `src/deps.ts` | Dependency references, cycle detection, readiness, derived order |
235
- | `src/store.ts` | `TrackerStore` service with `Effect.Ref` state |
236
- | `src/persistence.ts` | `TrackerPersistence` service (save and restore snapshots) |
237
- | `src/ui.ts` | Widget pane and interactive `/tracker` component |
238
- | `src/index.ts` | Pi bridge: tool, command, session hooks, widget refresh |
239
- | `src/*.test.ts` | Test suites |
270
+ | File | Purpose |
271
+ | ----------------------------------- | ---------------------------------------------------------------- |
272
+ | `src/core/domain.ts` | Schema domain model (`TodoItem`, `TodoList`, `TrackerState`) |
273
+ | `src/core/deps.ts` | Dependency references, cycle detection, readiness, derived order |
274
+ | `src/core/store.ts` | `TrackerStore` service with `Effect.Ref` state |
275
+ | `src/core/persistence.ts` | `TrackerPersistence` service (save and restore snapshots) |
276
+ | `src/compaction/*.ts` | Smart compaction: classifier, settle, digest, pointer, settings |
277
+ | `src/presentation/ui.ts` | Widget pane and interactive `/tracker` component |
278
+ | `src/presentation/tool-metadata.ts` | Tool parameters, result details, and display labels |
279
+ | `src/index.ts` | Pi bridge: tool, command, session hooks, widget refresh |
280
+ | `src/**/*.test.ts` | Test suites, colocated with each module |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ftrdotdev/pi-tracker",
3
- "version": "0.5.1",
3
+ "version": "0.6.0",
4
4
  "description": "Session-persistent todolist extension for Pi",
5
5
  "keywords": [
6
6
  "effect",
@@ -35,7 +35,6 @@
35
35
  "access": "public"
36
36
  },
37
37
  "scripts": {
38
- "prepare": "bun effect-tsgo patch --typescript --oxlint",
39
38
  "test": "vitest run",
40
39
  "test:watch": "vitest",
41
40
  "lint": "oxlint && oxlint --type-aware -A all -D typescript/unbound-method",
@@ -44,14 +43,15 @@
44
43
  "typecheck": "tsc --noEmit"
45
44
  },
46
45
  "dependencies": {
47
- "@effect/platform-node": "4.0.0-rc.116",
48
- "@effect/platform-node-shared": "4.0.0-rc.116",
49
- "@ftrdotdev/pi-tui": "^0.5.1",
50
- "effect": "4.0.0-rc.116"
46
+ "@effect/platform-node": "4.0.0",
47
+ "@effect/platform-node-shared": "4.0.0",
48
+ "@ftrdotdev/pi-tui": "^0.6.0",
49
+ "effect": "4.0.0"
51
50
  },
52
51
  "devDependencies": {
53
- "@effect/tsgo": "0.45.0",
54
- "@effect/vitest": "4.0.0-rc.116",
52
+ "@earendil-works/pi-tui": "1.0.2",
53
+ "@effect/tsgo": "0.47.2",
54
+ "@effect/vitest": "4.0.0",
55
55
  "@types/bun": "latest",
56
56
  "oxfmt": "^0.63.0",
57
57
  "oxlint": "1.82.0",
@@ -0,0 +1,188 @@
1
+ import { assert, it } from "@effect/vitest";
2
+ import { selectCandidates, type CompactionCandidate } from "./candidate.ts";
3
+ import type { PendingCompletion } from "./completion.ts";
4
+ import { TodoItem, TodoList } from "../core/domain.ts";
5
+
6
+ interface ItemSpec {
7
+ readonly id: number;
8
+ readonly done: boolean;
9
+ readonly text?: string;
10
+ readonly deps?: readonly string[];
11
+ }
12
+
13
+ const completion = (items: readonly ItemSpec[], completedItemIds: readonly number[]): PendingCompletion => {
14
+ const list = new TodoList({
15
+ id: 1,
16
+ name: "Work",
17
+ items: items.map(
18
+ (item) =>
19
+ new TodoItem({
20
+ id: item.id,
21
+ text: item.text ?? `item ${item.id}`,
22
+ done: item.done,
23
+ deps: [...(item.deps ?? [])],
24
+ }),
25
+ ),
26
+ nextItemId: items.reduce((max, item) => Math.max(max, item.id), 0) + 1,
27
+ });
28
+ return { list, completedItemIds };
29
+ };
30
+
31
+ /** The primary candidate: the first entry, which the pointer names. */
32
+ const first = (pending: PendingCompletion, limit = 8): CompactionCandidate => {
33
+ const candidates = selectCandidates(pending, limit);
34
+ assert.isAtLeast(candidates.length, 1);
35
+ return candidates[0]!;
36
+ };
37
+
38
+ it("selectCandidates prefers the first ready dependent successor", () => {
39
+ const candidate = first(
40
+ completion(
41
+ [
42
+ { id: 1, done: true },
43
+ { id: 2, done: false, deps: ["Work:1"] },
44
+ { id: 3, done: false },
45
+ ],
46
+ [1],
47
+ ),
48
+ );
49
+ assert.strictEqual(candidate.id, 2);
50
+ assert.strictEqual(candidate.class, "dependent-successor");
51
+ });
52
+
53
+ it("selectCandidates skips a dependent successor that is still blocked", () => {
54
+ const candidate = first(
55
+ completion(
56
+ [
57
+ { id: 1, done: true },
58
+ { id: 2, done: false, deps: ["Work:1", "Work:4"] },
59
+ { id: 3, done: false },
60
+ { id: 4, done: false },
61
+ ],
62
+ [1],
63
+ ),
64
+ );
65
+ assert.strictEqual(candidate.id, 3);
66
+ assert.strictEqual(candidate.class, "ready-queue");
67
+ });
68
+
69
+ it("selectCandidates considers every item in the completed batch", () => {
70
+ const candidate = first(
71
+ completion(
72
+ [
73
+ { id: 1, done: true },
74
+ { id: 2, done: false },
75
+ { id: 3, done: true },
76
+ { id: 4, done: false, deps: ["Work:3"] },
77
+ ],
78
+ [1, 3],
79
+ ),
80
+ );
81
+ assert.strictEqual(candidate.id, 4);
82
+ assert.strictEqual(candidate.class, "dependent-successor");
83
+ });
84
+
85
+ it("selectCandidates falls back to the first remaining ready item in list order", () => {
86
+ const candidate = first(
87
+ completion(
88
+ [
89
+ { id: 1, done: true },
90
+ { id: 3, done: false },
91
+ { id: 4, done: false },
92
+ ],
93
+ [1],
94
+ ),
95
+ );
96
+ assert.strictEqual(candidate.id, 3);
97
+ assert.strictEqual(candidate.class, "ready-queue");
98
+ });
99
+
100
+ it("selectCandidates excludes every completed item from the fallback", () => {
101
+ const candidate = first(
102
+ completion(
103
+ [
104
+ { id: 1, done: false },
105
+ { id: 2, done: false },
106
+ { id: 3, done: false },
107
+ ],
108
+ [1, 2],
109
+ ),
110
+ );
111
+ assert.strictEqual(candidate.id, 3);
112
+ assert.notStrictEqual(candidate.id, 1);
113
+ assert.notStrictEqual(candidate.id, 2);
114
+ });
115
+
116
+ it("selectCandidates returns an empty array when nothing is ready", () => {
117
+ const candidates = selectCandidates(
118
+ completion(
119
+ [
120
+ { id: 1, done: true },
121
+ { id: 2, done: false, deps: ["Work:9"] },
122
+ ],
123
+ [1],
124
+ ),
125
+ 8,
126
+ );
127
+ assert.deepStrictEqual(candidates, []);
128
+ });
129
+
130
+ it("selectCandidates carries the completed batch as prior work", () => {
131
+ const candidate = first(
132
+ completion(
133
+ [
134
+ { id: 1, done: true, text: "first" },
135
+ { id: 3, done: true, text: "third" },
136
+ { id: 4, done: false, text: "fourth", deps: ["Work:3"] },
137
+ ],
138
+ [1, 3],
139
+ ),
140
+ );
141
+ assert.deepStrictEqual(candidate.completed, [
142
+ { ref: "Work:1", text: "first" },
143
+ { ref: "Work:3", text: "third" },
144
+ ]);
145
+ assert.strictEqual(candidate.id, 4);
146
+ });
147
+
148
+ it("selectCandidates orders dependent successors before the ready queue", () => {
149
+ const candidates = selectCandidates(
150
+ completion(
151
+ [
152
+ { id: 1, done: true },
153
+ { id: 2, done: false, deps: ["Work:1"] },
154
+ { id: 3, done: false },
155
+ { id: 4, done: false, deps: ["Work:1"] },
156
+ ],
157
+ [1],
158
+ ),
159
+ 8,
160
+ );
161
+ assert.deepStrictEqual(
162
+ candidates.map((candidate) => candidate.id),
163
+ [2, 4, 3],
164
+ );
165
+ assert.deepStrictEqual(
166
+ candidates.map((candidate) => candidate.class),
167
+ ["dependent-successor", "dependent-successor", "ready-queue"],
168
+ );
169
+ });
170
+
171
+ it("selectCandidates caps the judged set at the limit, dependents first", () => {
172
+ const candidates = selectCandidates(
173
+ completion(
174
+ [
175
+ { id: 1, done: true },
176
+ { id: 2, done: false },
177
+ { id: 3, done: false, deps: ["Work:1"] },
178
+ { id: 4, done: false },
179
+ ],
180
+ [1],
181
+ ),
182
+ 2,
183
+ );
184
+ assert.deepStrictEqual(
185
+ candidates.map((candidate) => candidate.id),
186
+ [3, 2],
187
+ );
188
+ });
@@ -0,0 +1,75 @@
1
+ import { dependentsOf, formatItemRef, readiness } from "../core/deps.ts";
2
+ import type { PendingCompletion } from "./completion.ts";
3
+
4
+ /** Why the candidate was chosen; the classifier question is keyed by this. */
5
+ export type CandidateClass = "dependent-successor" | "ready-queue";
6
+
7
+ /** One item from the completed batch, as referenced prior work. */
8
+ export interface CompletedItem {
9
+ readonly ref: string;
10
+ readonly text: string;
11
+ }
12
+
13
+ /** The single next unfinished item, with the batch as referenced prior work. */
14
+ export interface CompactionCandidate {
15
+ readonly class: CandidateClass;
16
+ readonly listName: string;
17
+ readonly id: number;
18
+ readonly text: string;
19
+ /** Every item completed since the last decision. Never the subject. */
20
+ readonly completed: readonly CompletedItem[];
21
+ }
22
+
23
+ /**
24
+ * The single next unfinished item: the first open ready item in list order that
25
+ * depends on any item in the completed batch, else the first remaining ready
26
+ * item in list order, excluding every completed item. Reuses the readiness and
27
+ * dependent-set derivations (`deps.ts`); adds no graph behavior.
28
+ *
29
+ * The candidates to judge, in decision order: the ready dependent successors
30
+ * first (in list order), then the remaining ready items (in list order),
31
+ * excluding every completed item, capped at `limit`. The first entry is the
32
+ * pointer target, so it matches the old single candidate; the array is empty
33
+ * when nothing is ready.
34
+ */
35
+ export const selectCandidates = (
36
+ completion: PendingCompletion,
37
+ limit: number,
38
+ ): readonly CompactionCandidate[] => {
39
+ const { list } = completion;
40
+ const completedIds = new Set(completion.completedItemIds);
41
+ const completed: CompletedItem[] = completion.completedItemIds.flatMap((id) => {
42
+ const item = list.items.find((candidate) => candidate.id === id);
43
+ return item === undefined ? [] : [{ ref: formatItemRef(list.name, id), text: item.text }];
44
+ });
45
+
46
+ // The completed items were selected because the candidate depends on one of
47
+ // them; a blocked dependent is skipped and the ready queue takes over.
48
+ const completedIndexes = list.items
49
+ .map((item, index) => (completedIds.has(item.id) ? index : -1))
50
+ .filter((index) => index >= 0);
51
+ const dependentIndexes = new Set(
52
+ completedIndexes.flatMap((index) => [...dependentsOf(list, index)]),
53
+ );
54
+ const view = readiness(list);
55
+
56
+ const make = (index: number, cls: CandidateClass): CompactionCandidate => {
57
+ const item = list.items[index]!;
58
+ return { class: cls, listName: list.name, id: item.id, text: item.text, completed };
59
+ };
60
+
61
+ const ordered: CompactionCandidate[] = [];
62
+ const take = (index: number, cls: CandidateClass): void => {
63
+ if (ordered.length < limit) ordered.push(make(index, cls));
64
+ };
65
+ for (let index = 0; index < list.items.length && ordered.length < limit; index += 1) {
66
+ if (view[index]!.ready && dependentIndexes.has(index)) take(index, "dependent-successor");
67
+ }
68
+ for (let index = 0; index < list.items.length && ordered.length < limit; index += 1) {
69
+ const item = list.items[index]!;
70
+ if (view[index]!.ready && !completedIds.has(item.id) && !dependentIndexes.has(index)) {
71
+ take(index, "ready-queue");
72
+ }
73
+ }
74
+ return ordered;
75
+ };