@ftrdotdev/pi-tracker 0.6.0 → 0.7.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
@@ -6,9 +6,10 @@ pi-tracker is an extension for Pi. It manages todolists in your session.
6
6
 
7
7
  - Create and delete todolists.
8
8
  - Add, update, and remove items in a todolist.
9
+ - Give an item a short title, a longer description, and optional declarations.
9
10
  - Mark an item as complete or incomplete.
10
- - Change the task text of an item.
11
11
  - Declare dependencies between items, so work happens in order.
12
+ - Declare the references and products an item needs, so the next step survives compaction.
12
13
  - Persist todolists with the session.
13
14
  - Show the active todolist in a widget above the editor.
14
15
  - Start Pi's compaction when a completed item's detail is no longer needed.
@@ -27,38 +28,40 @@ The snapshot does not enter the LLM context.
27
28
  Ask Pi to manage your todolists. Pi calls the `tracker` tool. The tool
28
29
  supports these actions:
29
30
 
30
- | Action | Purpose | Parameters |
31
- | ------------- | ----------------------------------------- | ----------------------------------------------------------- |
32
- | `list` | Show all lists and items | None |
33
- | `create_list` | Create a list (becomes active by default) | `name`, `initial_items?`, `activate?` |
34
- | `delete_list` | Delete a list | `list_id` |
35
- | `set_active` | Set or clear the active list | `list_id` (optional) |
36
- | `add_item` | Add one or more items | `list_id`, `text` (string, item object, or array) |
37
- | `update_item` | Update one or more items | `item_id` + `text?`/`done?`/`deps?`, or `list_id` + `items` |
38
- | `remove_item` | Remove an item | `item_id` |
31
+ | Action | Purpose | Parameters |
32
+ | -------------- | ----------------------------------------- | ------------------------------------------ |
33
+ | `list` | Show all lists and items | None |
34
+ | `create_list` | Create a list (becomes active by default) | `name`, `initial_items?`, `activate?` |
35
+ | `delete_list` | Delete a list | `list_id` |
36
+ | `set_active` | Set or clear the active list | `list_id` (optional) |
37
+ | `add_items` | Add one or more items | `list_id`, `items` (array of item objects) |
38
+ | `update_items` | Update one or more items | `item_id` + fields, or `list_id` + `items` |
39
+ | `remove_item` | Remove an item | `item_id` |
39
40
 
40
41
  `create_list` accepts `initial_items` to create the list with its first
41
- items in one call, so the list and its items are created atomically. Each
42
- item is either a text string or an object `{text, deps?}`. `add_item`
43
- accepts the same shapes, plus an array of them, to add several items in one
44
- call.
42
+ items in one call, so the list and its items are created atomically. Every
43
+ item is an object `{title, description?, refs?, produces?, deps?}`, and
44
+ `add_items` takes the same objects in its `items` array, so an item is
45
+ always declared the same way. A title is one short action line, at most 200
46
+ characters; put the longer detail in `description`.
45
47
 
46
48
  Item ids are `listName:id`, as the `list` action shows them (e.g. `Work:2`).
47
49
  An id is permanent: it is stored on the item, it is unique within its list,
48
50
  and it is never reused. Removing an item leaves a gap in the numbering
49
51
  instead of shifting the items after it, so a reference you already hold stays
50
- valid. `update_item` accepts the scalar form (`item_id` with optional
51
- `text`/`done`/`deps`) or a per-list batched form: `list_id` plus an `items`
52
- array (`[{item_id, text?, done?, deps?}, ...]`), mirroring `add_item`'s
53
- `list_id + text[]` shape, so one batch stays within a single list. Creating a
54
- list makes it the active list (the widget switches to it); pass
55
- `activate: false` to keep the current active list.
52
+ valid. `update_items` accepts the scalar form (`item_id` with optional
53
+ `title`/`description`/`refs`/`produces`/`done`/`deps`) or a per-list batched
54
+ form: `list_id` plus an `items`
55
+ array (`[{item_id, title?, description?, refs?, produces?, done?, deps?}, ...]`),
56
+ mirroring `add_items`' `list_id + items` shape, so one batch stays within a
57
+ single list. Creating a list makes it the active list (the widget switches to
58
+ it); pass `activate: false` to keep the current active list.
56
59
 
57
60
  The tool validates every call and returns an error that names exactly what to
58
61
  fix: each action accepts only its own parameters, required fields are
59
- enforced, and the two `update_item` forms never mix. Read the error and retry
62
+ enforced, and the two `update_items` forms never mix. Read the error and retry
60
63
  with corrected parameters. Not-found errors also list the available ids.
61
- `update_item` also appends a reminder when one call marks two or more items
64
+ `update_items` also appends a reminder when one call marks two or more items
62
65
  done and leaves no open items behind (the terminal batch): the working
63
66
  rhythm is to mark each item done in the same turn it completes, never batch
64
67
  the marking at the end.
@@ -70,10 +73,29 @@ Example prompt:
70
73
  Call `set_active` without `list_id` to deselect. The widget hides when no
71
74
  list is active.
72
75
 
76
+ ### Titles, descriptions, and declarations
77
+
78
+ Every item has a required `title`: one short action line, at most 200
79
+ characters. An item may also carry a `description` with the longer detail. The
80
+ widget shows the title, with the description dimmed on the line below; the
81
+ `/tracker` items pane shows the full description.
82
+
83
+ An item may declare two optional lists:
84
+
85
+ - `refs`: what the item must read after the completed work. Each entry is
86
+ `{kind: "path", path, symbol?, span?}` or `{kind: "decision", topic}`.
87
+ - `produces`: every document the item will write. Each entry is `{path}`.
88
+
89
+ Declarations tell the tracker what the next step needs. At the settle boundary
90
+ the tracker resolves a declared path against disk. If the detail is readable
91
+ there, the rule table can compact the completed work and keep the next step
92
+ moving without a classifier call. After a session restore there is no tool
93
+ footprint, so references resolve as unresolved and only products check disk.
94
+
73
95
  ### Dependencies and readiness
74
96
 
75
97
  An item can wait for other items. Pass `deps` on the item object when you
76
- create it, or through `update_item`, as a list of `listName:id` references to
98
+ create it, or through `update_items`, as a list of `listName:id` references to
77
99
  items in the same list. `deps` replaces the whole dependency set, so pass `[]`
78
100
  to clear it. The result names the set before and after whenever the two
79
101
  differ, so a dependency the call dropped does not disappear silently.
@@ -105,7 +127,7 @@ keeps the output it had before dependencies existed. A dependency reference
105
127
  that does not resolve counts as a blocker, so a hand-edited snapshot cannot
106
128
  silently unblock work.
107
129
 
108
- An `update_item` batch applies its patches in order, so it behaves like the
130
+ An `update_items` batch applies its patches in order, so it behaves like the
109
131
  same calls in sequence: one call can complete a chain, and a completion that
110
132
  comes before its blocker in the array is refused.
111
133
 
@@ -119,8 +141,8 @@ action, the widget, and the `/tracker` items pane all use that order.
119
141
  The intended rhythm: break multi-step work into items up front (one item per
120
142
  deliverable), work through them one at a time, and mark each done as it
121
143
  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.
144
+ reads it with `list` before starting and after finishing, and updates an item's
145
+ title or description with `update_items` when scope changes.
124
146
 
125
147
  Failed calls are recoverable: the tool's errors say what to fix, and
126
148
  not-found errors name the available ids. The agent corrects the call and
@@ -144,7 +166,7 @@ pane for editing.
144
166
  | `d` | Delete a list |
145
167
  | `a` | Add an item |
146
168
  | `x` | Toggle an item complete or incomplete |
147
- | `e` | Edit the item text |
169
+ | `e` | Edit the item title |
148
170
  | `r` | Remove an item |
149
171
  | `esc` | Close the view |
150
172
 
@@ -180,41 +202,55 @@ output and the `/tracker` items pane, which have room for it.
180
202
 
181
203
  ### Smart compaction
182
204
 
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.
205
+ When you complete an item in the active list, pi-tracker decides whether the
206
+ **ready items** need the completed work. A measured rule row runs first. When
207
+ an accepted row fires, it decides the whole ready frontier on its own. Every
208
+ other row reports its name and hands the frontier to the classifier, which
209
+ judges up to `maxCandidates` entries, dependents first. Each candidate gets one
210
+ two-label choice question: `needs-context` or `stands-alone`. The answer carries
211
+ a probability and a `confidence`. When no ready item needs the detail,
212
+ pi-tracker starts Pi's compaction at the settle boundary and then resumes the
213
+ session with a pointer to the next ready item.
190
214
 
191
215
  The feature reads five keys from `tui.json`, under `smartCompaction`:
192
216
 
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.
217
+ | Key | Type | Default | Meaning |
218
+ | ---------------------------------- | ---------------- | ------- | -------------------------------------------------------------------------------------------------------------------- |
219
+ | `enabled` | boolean | `true` | Turn smart compaction on or off. |
220
+ | `classifier` | string or null | `null` | A `provider/modelId` classifier. `null` uses the preference order: Clef Flash, then TypeSafe Jev, then OpenCode Jev. |
221
+ | `needsContextProbabilityThreshold` | number in (0, 1) | `0.5` | The `needs-context` probability at or above which the context is kept. |
222
+ | `minAnswerConfidence` | number in (0, 1) | `0.5` | The answer's self-reported confidence below which the context is kept. |
223
+ | `maxCandidates` | integer 1..20 | `8` | How many ready items one classification judges. |
224
+
225
+ `needsContextProbabilityThreshold` is the probability knob: raise it to compact
226
+ more often, lower it to keep context more often. It cuts on the probability the
227
+ classifier assigns to `needs-context`, not on its confidence. `minAnswerConfidence`
228
+ is a separate guard on the answer's self-reported confidence: when the model is
229
+ less confident than the floor, pi-tracker keeps the context. This guard only
230
+ adds keeping, so it can never cause a premature compaction. Both keys still
231
+ accept their pre-rename names (`keepContextThreshold`, `keepContextMinConfidence`)
232
+ as aliases; the current key wins when both are present. `maxCandidates` bounds the
233
+ classifier input; when more items are ready than the cap, the first
234
+ `maxCandidates` are judged, dependents first.
207
235
 
208
236
  A value outside the range in the table falls back to the default. The feature
209
237
  fails open. A disabled feature, no credential-available classifier, a classifier
210
238
  error or timeout, an aborted run, or a list with no ready item keeps the full
211
239
  context. The classifier input is the item list only. The transcript never leaves
212
- the session.
240
+ the session. An unaccepted rule row abstains, so it never compacts on its own.
241
+
242
+ The rule table lives in `src/compaction/rules.ts`. Only rows in
243
+ `ACCEPTED_RULES` compact on their own. A row enters that set only when the eval
244
+ gate accepts it on labeled decisions: at least 10 labeled firings, at least 95%
245
+ agreement, above the pass base rate, in at least two passes. Every decision on
246
+ an item with declarations records the fired row and the resolved states as a
247
+ `tracker/reliance-decision` session entry, which the eval reads back.
248
+ `bun run eval:rules` prints the tables and the gate.
213
249
 
214
250
  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.
251
+ (toggle), `Compaction classifier` (picker), `Needs-context probability`, `Answer
252
+ confidence floor`, and `Max candidates` (`+` and `-` adjust the numeric rows).
253
+ The Compaction tab appears only while the tracker extension is loaded.
218
254
 
219
255
  ## Persistence
220
256
 
@@ -224,7 +260,9 @@ and written in order, and each result reports the state its own call produced
224
260
  instead of a value another surface cached.
225
261
 
226
262
  A snapshot saved before item ids existed loads with each item id equal to its
227
- position, so references in that format still resolve.
263
+ position, so references in that format still resolve. A snapshot written before
264
+ the title/description split loads with the first line as the title and the rest
265
+ as the description.
228
266
 
229
267
  ## Installation
230
268
 
@@ -258,12 +296,15 @@ Registration lives in `package.json` under the `pi` field:
258
296
 
259
297
  ## Development
260
298
 
261
- | Command | Purpose |
262
- | ------------------- | -------------------------------------------- |
263
- | `bun test` | Run the test suite (vitest + @effect/vitest) |
264
- | `bun test:watch` | Run the test suite in watch mode |
265
- | `bunx tsc --noEmit` | Type check |
266
- | `bun lint` | Lint with oxlint |
299
+ | Command | Purpose |
300
+ | ---------------------- | -------------------------------------------- |
301
+ | `bun run test` | Run the test suite (vitest + @effect/vitest) |
302
+ | `bun run test:watch` | Run the test suite in watch mode |
303
+ | `bun run typecheck` | Type check with `tsc --noEmit` |
304
+ | `bun run lint` | Lint with oxlint |
305
+ | `bun run eval:harvest` | Harvest the eval corpus from local sessions |
306
+ | `bun run eval:rules` | Print the rule tables and the promotion gate |
307
+ | `bun run eval:promote` | Align `ACCEPTED_RULES` with the measured set |
267
308
 
268
309
  ## Project structure
269
310
 
@@ -273,7 +314,15 @@ Registration lives in `package.json` under the `pi` field:
273
314
  | `src/core/deps.ts` | Dependency references, cycle detection, readiness, derived order |
274
315
  | `src/core/store.ts` | `TrackerStore` service with `Effect.Ref` state |
275
316
  | `src/core/persistence.ts` | `TrackerPersistence` service (save and restore snapshots) |
276
- | `src/compaction/*.ts` | Smart compaction: classifier, settle, digest, pointer, settings |
317
+ | `src/compaction/observations.ts` | Resolves declared references and products against disk |
318
+ | `src/compaction/rules.ts` | The rule table, `ACCEPTED_RULES`, and the gate constants |
319
+ | `src/compaction/footprint.ts` | Records what each batch wrote, read, and ran |
320
+ | `src/compaction/settle.ts` | The settle decision: rules first, then the classifier |
321
+ | `src/compaction/digest.ts` | The bounded classifier input |
322
+ | `src/compaction/decision-record.ts` | The `tracker/reliance-decision` session entry |
323
+ | `src/compaction/classifier.ts` | The classifier gateway |
324
+ | `src/compaction/pointer.ts` | The resume pointer and its custom entry |
325
+ | `src/compaction/settings.ts` | The `tui.json` reader |
277
326
  | `src/presentation/ui.ts` | Widget pane and interactive `/tracker` component |
278
327
  | `src/presentation/tool-metadata.ts` | Tool parameters, result details, and display labels |
279
328
  | `src/index.ts` | Pi bridge: tool, command, session hooks, widget refresh |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ftrdotdev/pi-tracker",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "description": "Session-persistent todolist extension for Pi",
5
5
  "keywords": [
6
6
  "effect",
@@ -37,6 +37,11 @@
37
37
  "scripts": {
38
38
  "test": "vitest run",
39
39
  "test:watch": "vitest",
40
+ "eval:harvest": "bun evals/harvest.ts",
41
+ "eval:review": "bun evals/review.ts",
42
+ "eval:label": "bun evals/label.ts",
43
+ "eval:rules": "bun evals/rules.ts",
44
+ "eval:promote": "bun evals/promote.ts",
40
45
  "lint": "oxlint && oxlint --type-aware -A all -D typescript/unbound-method",
41
46
  "lint:fix": "oxlint --fix",
42
47
  "fmt": "oxfmt",
@@ -45,11 +50,11 @@
45
50
  "dependencies": {
46
51
  "@effect/platform-node": "4.0.0",
47
52
  "@effect/platform-node-shared": "4.0.0",
48
- "@ftrdotdev/pi-tui": "^0.6.0",
53
+ "@ftrdotdev/pi-tui": "^0.7.0",
49
54
  "effect": "4.0.0"
50
55
  },
51
56
  "devDependencies": {
52
- "@earendil-works/pi-tui": "1.0.2",
57
+ "@earendil-works/pi-tui": "1.1.0",
53
58
  "@effect/tsgo": "0.47.2",
54
59
  "@effect/vitest": "4.0.0",
55
60
  "@types/bun": "latest",
@@ -6,11 +6,14 @@ import { TodoItem, TodoList } from "../core/domain.ts";
6
6
  interface ItemSpec {
7
7
  readonly id: number;
8
8
  readonly done: boolean;
9
- readonly text?: string;
9
+ readonly title?: string;
10
10
  readonly deps?: readonly string[];
11
11
  }
12
12
 
13
- const completion = (items: readonly ItemSpec[], completedItemIds: readonly number[]): PendingCompletion => {
13
+ const completion = (
14
+ items: readonly ItemSpec[],
15
+ completedItemIds: readonly number[],
16
+ ): PendingCompletion => {
14
17
  const list = new TodoList({
15
18
  id: 1,
16
19
  name: "Work",
@@ -18,7 +21,7 @@ const completion = (items: readonly ItemSpec[], completedItemIds: readonly numbe
18
21
  (item) =>
19
22
  new TodoItem({
20
23
  id: item.id,
21
- text: item.text ?? `item ${item.id}`,
24
+ title: item.title ?? `item ${item.id}`,
22
25
  done: item.done,
23
26
  deps: [...(item.deps ?? [])],
24
27
  }),
@@ -131,9 +134,9 @@ it("selectCandidates carries the completed batch as prior work", () => {
131
134
  const candidate = first(
132
135
  completion(
133
136
  [
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
+ { id: 1, done: true, title: "first" },
138
+ { id: 3, done: true, title: "third" },
139
+ { id: 4, done: false, title: "fourth", deps: ["Work:3"] },
137
140
  ],
138
141
  [1, 3],
139
142
  ),
@@ -1,4 +1,5 @@
1
1
  import { dependentsOf, formatItemRef, readiness } from "../core/deps.ts";
2
+ import type { DeclaredProduct, DeclaredReference } from "../core/domain.ts";
2
3
  import type { PendingCompletion } from "./completion.ts";
3
4
 
4
5
  /** Why the candidate was chosen; the classifier question is keyed by this. */
@@ -8,6 +9,8 @@ export type CandidateClass = "dependent-successor" | "ready-queue";
8
9
  export interface CompletedItem {
9
10
  readonly ref: string;
10
11
  readonly text: string;
12
+ /** The item's description, when it carries one. Part of the batch text. */
13
+ readonly description?: string;
11
14
  }
12
15
 
13
16
  /** The single next unfinished item, with the batch as referenced prior work. */
@@ -15,9 +18,16 @@ export interface CompactionCandidate {
15
18
  readonly class: CandidateClass;
16
19
  readonly listName: string;
17
20
  readonly id: number;
21
+ /** The item's title. */
18
22
  readonly text: string;
23
+ /** The item's description, when it carries one. */
24
+ readonly description?: string;
19
25
  /** Every item completed since the last decision. Never the subject. */
20
26
  readonly completed: readonly CompletedItem[];
27
+ /** The item's declared references, when it carries any. */
28
+ readonly refs?: readonly DeclaredReference[];
29
+ /** The item's declared products, when it carries any. */
30
+ readonly produces?: readonly DeclaredProduct[];
21
31
  }
22
32
 
23
33
  /**
@@ -40,7 +50,16 @@ export const selectCandidates = (
40
50
  const completedIds = new Set(completion.completedItemIds);
41
51
  const completed: CompletedItem[] = completion.completedItemIds.flatMap((id) => {
42
52
  const item = list.items.find((candidate) => candidate.id === id);
43
- return item === undefined ? [] : [{ ref: formatItemRef(list.name, id), text: item.text }];
53
+ if (item === undefined) return [];
54
+ return [
55
+ {
56
+ ref: formatItemRef(list.name, id),
57
+ text: item.title,
58
+ ...(item.description === undefined || item.description.length === 0
59
+ ? {}
60
+ : { description: item.description }),
61
+ },
62
+ ];
44
63
  });
45
64
 
46
65
  // The completed items were selected because the candidate depends on one of
@@ -55,7 +74,18 @@ export const selectCandidates = (
55
74
 
56
75
  const make = (index: number, cls: CandidateClass): CompactionCandidate => {
57
76
  const item = list.items[index]!;
58
- return { class: cls, listName: list.name, id: item.id, text: item.text, completed };
77
+ return {
78
+ class: cls,
79
+ listName: list.name,
80
+ id: item.id,
81
+ text: item.title,
82
+ ...(item.description === undefined || item.description.length === 0
83
+ ? {}
84
+ : { description: item.description }),
85
+ completed,
86
+ ...(item.refs.length === 0 ? {} : { refs: item.refs }),
87
+ ...(item.produces.length === 0 ? {} : { produces: item.produces }),
88
+ };
59
89
  };
60
90
 
61
91
  const ordered: CompactionCandidate[] = [];
@@ -11,8 +11,8 @@ import type {
11
11
  } from "@earendil-works/pi-ai";
12
12
  import {
13
13
  CLASSIFY_TIMEOUT_MILLIS,
14
- DEFAULT_KEEP_CONTEXT_MIN_CONFIDENCE,
15
- DEFAULT_KEEP_CONTEXT_THRESHOLD,
14
+ DEFAULT_MIN_ANSWER_CONFIDENCE,
15
+ DEFAULT_NEEDS_CONTEXT_PROBABILITY_THRESHOLD,
16
16
  NEEDS_CONTEXT_LABEL,
17
17
  NEEDS_NONE_LABEL,
18
18
  ClassifierGateway,
@@ -74,17 +74,17 @@ const choiceResult = (needsMass: number, confidence = 1, key = QUESTION_KEY): Cl
74
74
  const verdict = (
75
75
  result: ClassifierResult,
76
76
  questionKeys: readonly string[],
77
- keepContextThreshold = DEFAULT_KEEP_CONTEXT_THRESHOLD,
78
- keepContextMinConfidence = DEFAULT_KEEP_CONTEXT_MIN_CONFIDENCE,
79
- ) => classifyVerdict(result, questionKeys, keepContextThreshold, keepContextMinConfidence);
77
+ needsContextProbabilityThreshold = DEFAULT_NEEDS_CONTEXT_PROBABILITY_THRESHOLD,
78
+ minAnswerConfidence = DEFAULT_MIN_ANSWER_CONFIDENCE,
79
+ ) => classifyVerdict(result, questionKeys, needsContextProbabilityThreshold, minAnswerConfidence);
80
80
 
81
81
  const input = (
82
82
  registry: ClassifierRegistry,
83
83
  overrides: {
84
84
  enabled?: boolean;
85
85
  chosen?: Option.Option<ClassifierIdentity>;
86
- keepContextThreshold?: number;
87
- keepContextMinConfidence?: number;
86
+ needsContextProbabilityThreshold?: number;
87
+ minAnswerConfidence?: number;
88
88
  digest?: JsonObject;
89
89
  questions?: readonly CompactionQuestion[];
90
90
  signal?: AbortSignal;
@@ -93,17 +93,16 @@ const input = (
93
93
  registry,
94
94
  enabled: overrides.enabled ?? true,
95
95
  chosen: overrides.chosen ?? Option.none(),
96
- keepContextThreshold: overrides.keepContextThreshold ?? DEFAULT_KEEP_CONTEXT_THRESHOLD,
97
- keepContextMinConfidence:
98
- overrides.keepContextMinConfidence ?? DEFAULT_KEEP_CONTEXT_MIN_CONFIDENCE,
96
+ needsContextProbabilityThreshold:
97
+ overrides.needsContextProbabilityThreshold ?? DEFAULT_NEEDS_CONTEXT_PROBABILITY_THRESHOLD,
98
+ minAnswerConfidence: overrides.minAnswerConfidence ?? DEFAULT_MIN_ANSWER_CONFIDENCE,
99
99
  digest: overrides.digest ?? DIGEST,
100
100
  questions: overrides.questions ?? [question],
101
101
  signal: overrides.signal,
102
102
  });
103
103
 
104
- const withGateway = <A, E>(
105
- program: Effect.Effect<A, E, ClassifierGateway>,
106
- ): Effect.Effect<A, E> => program.pipe(Effect.provide(ClassifierGateway.layer));
104
+ const withGateway = <A, E>(program: Effect.Effect<A, E, ClassifierGateway>): Effect.Effect<A, E> =>
105
+ program.pipe(Effect.provide(ClassifierGateway.layer));
107
106
 
108
107
  // ---------------------------------------------------------------------------
109
108
  // resolveClassifier
@@ -179,9 +178,12 @@ it("resolveClassifier returns none when no classifier is credential-available",
179
178
  // ---------------------------------------------------------------------------
180
179
 
181
180
  it("classifyVerdict keeps context at the threshold", () => {
182
- assert.deepStrictEqual(verdict(choiceResult(DEFAULT_KEEP_CONTEXT_THRESHOLD), [QUESTION_KEY]), {
183
- kind: "keep",
184
- });
181
+ assert.deepStrictEqual(
182
+ verdict(choiceResult(DEFAULT_NEEDS_CONTEXT_PROBABILITY_THRESHOLD), [QUESTION_KEY]),
183
+ {
184
+ kind: "keep",
185
+ },
186
+ );
185
187
  });
186
188
 
187
189
  it("classifyVerdict compacts below the threshold", () => {
@@ -210,7 +212,7 @@ it("classifyVerdict keeps context when an answer is below the confidence floor",
210
212
 
211
213
  it("classifyVerdict compacts when the answer reaches the confidence floor", () => {
212
214
  assert.deepStrictEqual(
213
- verdict(choiceResult(0.1, DEFAULT_KEEP_CONTEXT_MIN_CONFIDENCE), [QUESTION_KEY]),
215
+ verdict(choiceResult(0.1, DEFAULT_MIN_ANSWER_CONFIDENCE), [QUESTION_KEY]),
214
216
  { kind: "compact" },
215
217
  );
216
218
  });
@@ -334,51 +336,56 @@ it.effect("gateway returns disabled when the classifier call exceeds the deadlin
334
336
  ),
335
337
  );
336
338
 
337
- it.effect("gateway returns a compact verdict for an available classifier and a low probability", () =>
338
- withGateway(
339
- Effect.gen(function* () {
340
- const gateway = yield* ClassifierGateway;
341
- const registry: ClassifierRegistry = {
342
- getAvailableOfType: async () => [clefFlash, jev],
343
- classify: async () => choiceResult(0.1, 0.9),
344
- };
345
- const result = yield* gateway.verdict(input(registry));
346
- assert.deepStrictEqual(result, { kind: "compact" });
347
- }),
348
- ),
339
+ it.effect(
340
+ "gateway returns a compact verdict for an available classifier and a low probability",
341
+ () =>
342
+ withGateway(
343
+ Effect.gen(function* () {
344
+ const gateway = yield* ClassifierGateway;
345
+ const registry: ClassifierRegistry = {
346
+ getAvailableOfType: async () => [clefFlash, jev],
347
+ classify: async () => choiceResult(0.1, 0.9),
348
+ };
349
+ const result = yield* gateway.verdict(input(registry));
350
+ assert.deepStrictEqual(result, { kind: "compact" });
351
+ }),
352
+ ),
349
353
  );
350
354
 
351
- it.effect("gateway forwards the run signal to the classifier call and returns disabled on abort", () => {
352
- // Constructed outside the Effect program so the run signal is a plain value.
353
- const controller = new AbortController();
354
- return withGateway(
355
- Effect.gen(function* () {
356
- const gateway = yield* ClassifierGateway;
357
- const captured: { signal?: AbortSignal } = {};
358
- const registry: ClassifierRegistry = {
359
- getAvailableOfType: async () => [jev],
360
- classify: (_model, _context, options) => {
361
- captured.signal = options?.signal;
362
- return new Promise((_resolve, reject) => {
363
- options?.signal?.addEventListener("abort", () => reject(new Error("run abort")));
364
- });
365
- },
366
- };
367
- const fiber = yield* Effect.forkChild(
368
- gateway.verdict(input(registry, { signal: controller.signal })),
369
- );
370
- let attempts = 0;
371
- while (captured.signal === undefined && attempts < 1000) {
372
- yield* Effect.yieldNow;
373
- attempts += 1;
374
- }
375
- controller.abort();
376
- const result = yield* Fiber.join(fiber);
377
- assert.deepStrictEqual(result, { kind: "disabled" });
378
- assert.strictEqual(captured.signal?.aborted, true);
379
- }),
380
- );
381
- });
355
+ it.effect(
356
+ "gateway forwards the run signal to the classifier call and returns disabled on abort",
357
+ () => {
358
+ // Constructed outside the Effect program so the run signal is a plain value.
359
+ const controller = new AbortController();
360
+ return withGateway(
361
+ Effect.gen(function* () {
362
+ const gateway = yield* ClassifierGateway;
363
+ const captured: { signal?: AbortSignal } = {};
364
+ const registry: ClassifierRegistry = {
365
+ getAvailableOfType: async () => [jev],
366
+ classify: (_model, _context, options) => {
367
+ captured.signal = options?.signal;
368
+ return new Promise((_resolve, reject) => {
369
+ options?.signal?.addEventListener("abort", () => reject(new Error("run abort")));
370
+ });
371
+ },
372
+ };
373
+ const fiber = yield* Effect.forkChild(
374
+ gateway.verdict(input(registry, { signal: controller.signal })),
375
+ );
376
+ let attempts = 0;
377
+ while (captured.signal === undefined && attempts < 1000) {
378
+ yield* Effect.yieldNow;
379
+ attempts += 1;
380
+ }
381
+ controller.abort();
382
+ const result = yield* Fiber.join(fiber);
383
+ assert.deepStrictEqual(result, { kind: "disabled" });
384
+ assert.strictEqual(captured.signal?.aborted, true);
385
+ }),
386
+ );
387
+ },
388
+ );
382
389
 
383
390
  it.effect("gateway sends exactly one choice question with the digest as the classifier state", () =>
384
391
  withGateway(