pi-workfeed 0.0.0-stage → 0.1.1
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/CHANGELOG.md +70 -0
- package/LICENSE +21 -0
- package/README.md +317 -2
- package/docs/README.md +15 -0
- package/docs/decisions//346/234/211/346/225/210/345/206/263/347/255/226/344/270/273/350/241/250.md +17 -0
- package/docs/schema.md +454 -0
- package/docs/verification.md +212 -0
- package/docs/versioning.md +91 -0
- package/extensions/journal/digest.ts +318 -0
- package/extensions/journal/index.ts +674 -0
- package/extensions/journal/replay.ts +359 -0
- package/extensions/todo/index.ts +332 -0
- package/package.json +54 -4
- package/schemas/workfeed-event-v1.schema.json +176 -0
- package/skills/workfeed-analysis/SKILL.md +142 -0
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
# Verification
|
|
2
|
+
|
|
3
|
+
What has actually been run against a real pi session, how, and what is still unverified.
|
|
4
|
+
|
|
5
|
+
## Why this page exists
|
|
6
|
+
|
|
7
|
+
The test suites run against stubs. A stub proves the code agrees with *our description of
|
|
8
|
+
pi's interface*; it cannot prove that description is right. Both defects recorded below
|
|
9
|
+
were introduced by a stub — a payload shape this project wrote itself — and only a real
|
|
10
|
+
session exposed them. So a green CI run is not evidence that workfeed works on a real
|
|
11
|
+
host, and this page is where the real evidence lives instead.
|
|
12
|
+
|
|
13
|
+
## How the real run was done
|
|
14
|
+
|
|
15
|
+
- pi 1.5.0 driven in RPC mode (`pi --mode rpc`): the same extension loading path and the
|
|
16
|
+
same tool execution as the TUI, with commands sent over the documented JSONL protocol
|
|
17
|
+
- the extensions installed from this repository as a package (not copied into a test dir)
|
|
18
|
+
- the host's own tools — `bash`, `read`, `edit` — plus `workfeed_todo`
|
|
19
|
+
- a real session file on disk, a real compaction, a real fork, and a real restart of the
|
|
20
|
+
same session file in a second process
|
|
21
|
+
- one hosted chat-completions provider; the model is incidental. What must be real is the
|
|
22
|
+
host, the tools and the events, not which model answered
|
|
23
|
+
|
|
24
|
+
## What was checked
|
|
25
|
+
|
|
26
|
+
| # | Step | Observed |
|
|
27
|
+
|---|---|---|
|
|
28
|
+
| 1 | Start a session with the package installed | `session` line with sid, model, provider, cwd; digest written |
|
|
29
|
+
| 2 | Write three todo items, one `in_progress` | one `todo` snapshot per change, ids 1–3, `rev` increments |
|
|
30
|
+
| 3 | `bash`, `read`, `edit` | `start`/`end` pair per call, `durMs`, `exitCode`, `isError: false` |
|
|
31
|
+
| 4 | A command that exits 3 | `isError: true`, listed under last failures, tool rollup counts it as failed |
|
|
32
|
+
| 5 | Update items: first `completed`, second `in_progress` | ids kept (matched by text), later turns attribute to the new item |
|
|
33
|
+
| 6 | `clear` | empty snapshot; every item stays in the digest marked `dropped`, item timing kept |
|
|
34
|
+
| 7 | `/compact` on a session that is too small | `compact_failed` carrying pi's own message ("Nothing to compact"), reported in data quality |
|
|
35
|
+
| 8 | `/compact` on a large session | `compact` with `before` = 24604 tokens; the todo list survives — a tool call after compaction still carries the item that was in progress |
|
|
36
|
+
| 9 | `fork` | new sid and a new log file; item ids continue (4), task numbering restarts at 1 for the new session |
|
|
37
|
+
| 10 | Restart the same session file | task numbering continues (task 2, not a second task 1); one log, both processes' lines |
|
|
38
|
+
| 11 | Rebuild the digest offline from the JSONL | same bytes the producer wrote; a log killed mid-tool rebuilds to `1 started without an end line` plus `1/1 prompts have a settle — killed or still open` |
|
|
39
|
+
|
|
40
|
+
Both branches of compaction (7 and 8) needed a real pi: one because the failure text only
|
|
41
|
+
exists there, one because a summary is produced by an actual model call.
|
|
42
|
+
|
|
43
|
+
## Smoke matrix, re-run on a release candidate
|
|
44
|
+
|
|
45
|
+
The steps above were run once, fixing defects as they appeared. Before a release they are run
|
|
46
|
+
again as a smoke matrix, on the code that is about to be tagged, because a later patch can
|
|
47
|
+
regress a path that the suite covers only with stubs.
|
|
48
|
+
|
|
49
|
+
| Scenario | What must be true | Result @ 0.4.6 |
|
|
50
|
+
|---|---|---|
|
|
51
|
+
| restart the same session file in a second process | one log file, task numbers continue (`task 3`, not a second `task 1`), `3/3 prompts have a settle` | pass — 43 lines, tasks 1–3 in one file |
|
|
52
|
+
| `clear` the list | empty snapshot, every item kept with its timing (`3 dropped from the list (timing kept)`, `1/3 completed · accumulated in-progress time 2s`) | pass |
|
|
53
|
+
| `/compact` | either a real compaction with `before`, or the empty answer reported as `skipped` — never as a failure | pass — small session: `0 completed, 0 failed, 1 skipped — skipped: …Nothing to compact…`; large session: `1 completed, 0 failed`, `before: 24604` |
|
|
54
|
+
| abnormal exit (kill mid-tool) | `1 started without an end line`, `0/1 prompts have a settle — … unknown, not zero`; offline rebuild needs no pi | pass — 5 events, rebuilt digest says exactly that |
|
|
55
|
+
|
|
56
|
+
## pi 1.6.1 re-check (2026-11-27)
|
|
57
|
+
|
|
58
|
+
pi 1.6.1 replaced 1.5.0 on the Windows host this release was originally verified on. A
|
|
59
|
+
version bump can break a package like this without any change here — the extension API and
|
|
60
|
+
the event names the handlers subscribe to are the host's, not ours — so the upgrade was
|
|
61
|
+
followed by the checks below.
|
|
62
|
+
|
|
63
|
+
- `pi --version` → `1.6.1`; `pi list` still resolves the checkout as a package.
|
|
64
|
+
- every event the two extensions subscribe to is declared in 1.6.1's
|
|
65
|
+
`dist/core/extensions/types.d.ts` — `session_start`, `session_shutdown`,
|
|
66
|
+
`before_agent_start`, `agent_start`, `turn_start`, `turn_end`, `tool_call`,
|
|
67
|
+
`tool_execution_end`, `user_bash`, `after_provider_response`, `session_compact`,
|
|
68
|
+
`session_compact_failed`, `agent_settled`, and `session_tree` for the todo list — and so
|
|
69
|
+
are the context members used: `cwd`, `hasUI`, `model`, `thinkingLevel`,
|
|
70
|
+
`sessionManager.getSessionId/getSessionFile/getBranch`, `ui.notify/setStatus`,
|
|
71
|
+
`pi.events`, `pi.appendEntry`.
|
|
72
|
+
- the compat view 1.6.1 hands extensions for `@earendil-works/pi-ai` still exports
|
|
73
|
+
`StringEnum` (now built with TypeBox's `TUnsafe` instead of a bare JSON schema), and
|
|
74
|
+
`pi-tui`'s `Text` and `typebox` are still among the virtual modules.
|
|
75
|
+
- a headless session (`pi -p --no-session --mode json`) still produced the journal's own
|
|
76
|
+
picture: 16 events, `1/1 prompts have a settle`, `16 lines, 0 dropped, 0 of unknown
|
|
77
|
+
type`, digest written, and `workfeed_todo` present in the system prompt's tool list.
|
|
78
|
+
The provider was unreachable in that run (`ECONNREFUSED`, the local model was not
|
|
79
|
+
running), which is why no tool calls and no tokens appear — the point was extension
|
|
80
|
+
loading and the event path, not a model answer.
|
|
81
|
+
|
|
82
|
+
What this does **not** cover: tool calls, todo attribution, `/compact`, fork and restart on
|
|
83
|
+
1.6.1. Those paths are recorded above on 1.5.x only; a session with a real model and real
|
|
84
|
+
tools is still what closes them.
|
|
85
|
+
|
|
86
|
+
Two behaviours observed on 1.6.1. The first is left as it is (it comes from the host); the second was a schema/prose mismatch that is now reconciled on the schema side:
|
|
87
|
+
|
|
88
|
+
- pi's automatic retry re-emits `agent_start` / `turn_start` / `turn_end` per attempt, so
|
|
89
|
+
one prompt that failed three times is recorded as four turns and the digest row reads
|
|
90
|
+
`| 1 | 14s | 4 | 0 |`. The settle line stays single and task coverage stays `1/1`.
|
|
91
|
+
- `turn` numbers are 0-based (`0` for the first turn). Pre-upgrade logs from 2026-11-10,
|
|
92
|
+
11-13 and 11-19 already carried `turn: 0`, so this was a standing mismatch between the
|
|
93
|
+
prose/schema (`minimum: 1`) and pi's counter, not something 1.6.1 introduced. **Reconciled
|
|
94
|
+
2026-12-03 on the schema side**: the schema now declares `turn` as `minimum: 0` with a
|
|
95
|
+
0-based description, `docs/schema.md` says 0-based, and `test/fixtures/all-events.jsonl`
|
|
96
|
+
records the first turn as `turn: 0` — a value the old `minimum: 1` would have rejected, so
|
|
97
|
+
it now guards the relaxation. pi's behaviour is unchanged and correct; only the contract was wrong.
|
|
98
|
+
|
|
99
|
+
## pi 1.7.0 re-check (2026-12-03)
|
|
100
|
+
|
|
101
|
+
pi 1.7.0 replaced 1.6.1 on the same Windows host (Node 24.22.1). 1.7.0's only breaking change
|
|
102
|
+
is the removal of install telemetry (`enableInstallTelemetry`, `PI_TELEMETRY`,
|
|
103
|
+
`/api/report-install`) — a surface this package does not touch. What pi-workfeed depends on was
|
|
104
|
+
re-checked:
|
|
105
|
+
|
|
106
|
+
- `pi --version` → `1.7.0`; `pi list` still resolves the checkout as a package, and
|
|
107
|
+
`workfeed_todo` still appears in the system prompt's tool list.
|
|
108
|
+
- all 14 subscribed event names are still declared in 1.7.0's `dist/core/extensions/types.d.ts`
|
|
109
|
+
(no rename). `sessionManager.getSessionId` / `getBranch` are absent from that file in **both**
|
|
110
|
+
1.6.1 and 1.7.0 — they live in `agent-session.js` and are reached at runtime, so this is not a
|
|
111
|
+
1.7.0 change.
|
|
112
|
+
- the compat exports pi-workfeed imports are unchanged: `StringEnum` (pi-ai compat view, built
|
|
113
|
+
with TypeBox `TUnsafe`), `pi-tui`'s `Text`, and `typebox` (still 1.3.27).
|
|
114
|
+
- a headless session (`pi -p --no-session --mode json`) loaded both extensions and wrote the
|
|
115
|
+
journal: `session`, `prompt`, `agent_start`, `turn`, `settle`, `shutdown` all recorded, `pi`
|
|
116
|
+
exit 0, no extension error. The provider was unreachable (`ECONNREFUSED`, local model not
|
|
117
|
+
running), so pi auto-retried 3× — which live-reproduced the retry-inflates-turns note above
|
|
118
|
+
(`settle turns=4`, `4× agent_start`, `8× turn`, settle still single, coverage still `1/1`).
|
|
119
|
+
The recorded `turn` values were all `0`, confirming the 0-based fix in `1ecffd3`.
|
|
120
|
+
|
|
121
|
+
What this does **not** cover: tool calls, todo attribution, `/compact`, fork and restart on
|
|
122
|
+
1.7.0 — the same scope limit as the 1.6.1 re-check; a session with a real model and real tools
|
|
123
|
+
is still what closes them.
|
|
124
|
+
|
|
125
|
+
## Clean install from the published artifact
|
|
126
|
+
|
|
127
|
+
Installing from the checkout proves nothing about the artifact: the checkout has `test/`, the
|
|
128
|
+
git history and a symlink the package does not. The check below therefore installs the tarball
|
|
129
|
+
itself into a throwaway home.
|
|
130
|
+
|
|
131
|
+
1. `npm pack` → `pi-workfeed-<version>.tgz` (the file that would be published).
|
|
132
|
+
2. Extract it — the tree contains only `CHANGELOG.md`, `LICENSE`, `README.md`, `docs/`,
|
|
133
|
+
`extensions/`, `package.json`, `schemas/`, `skills/`.
|
|
134
|
+
3. `pi install <extracted dir>` with `USERPROFILE`/`HOME` pointing at an empty directory, so
|
|
135
|
+
the real `~/.pi/agent` is not involved. `pi list` then shows the package.
|
|
136
|
+
4. Start a session there and read the log directory of that throwaway home.
|
|
137
|
+
|
|
138
|
+
Observed at 0.4.6: the package installed, and the journal extension **ran** — a
|
|
139
|
+
`workfeed-*.jsonl` appeared under `<throwaway home>/.pi/agent/logs/2026-11-10/` with
|
|
140
|
+
|
|
141
|
+
```
|
|
142
|
+
{"v":1,"ts":…,"sid":"…","task":0,"t":"session","reason":"startup","cwd":"…\\wf-cleanprobe\\home", …}
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
which is the extension's own session handler writing into a home that contains nothing else.
|
|
146
|
+
`skills/workfeed-analysis/SKILL.md` is present in the extracted tree with valid front matter
|
|
147
|
+
(`name: workfeed-analysis`, a description). The `SKILL.md` rules pi documents — front matter,
|
|
148
|
+
a non-empty description, name matching the directory — are asserted by
|
|
149
|
+
`test/package.test.mjs`, so a skill pi would silently skip fails CI instead.
|
|
150
|
+
|
|
151
|
+
Not observable headlessly: that pi lists the skill in the model's system prompt. pi has no
|
|
152
|
+
command that prints the prompt, and forcing it through a model call would prove the model's
|
|
153
|
+
sentence, not pi's loader. The static checks above are what can be verified without inventing
|
|
154
|
+
evidence; if you want the end-to-end confirmation, run `pi` and check that
|
|
155
|
+
`/skill:workfeed-analysis` is offered.
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
## The two defects a real run found
|
|
159
|
+
|
|
160
|
+
1. **`compact_failed` lost its reason.** The handler read `event.error`; pi calls it
|
|
161
|
+
`errorMessage`. Every real failure logged a row with no explanation at all.
|
|
162
|
+
2. **`compact` lost its counts.** The handler read `messagesBefore` / `messagesAfter`; pi
|
|
163
|
+
reports a `CompactionEntry` whose `tokensBefore` is the only count it exposes, and the
|
|
164
|
+
digest had no line for compaction either way.
|
|
165
|
+
|
|
166
|
+
Both are now fixed and covered by `test/compaction.test.mjs`, which uses pi's documented
|
|
167
|
+
field names rather than a shape invented for the test.
|
|
168
|
+
|
|
169
|
+
## Coverage, stated honestly
|
|
170
|
+
|
|
171
|
+
`item attribution` in the digest is a measurement, not a promise. A model that issues its
|
|
172
|
+
`workfeed_todo` call in the same turn as other tool calls makes those calls *start* before
|
|
173
|
+
the new snapshot arrives, so they carry no `item` — a real run showed `2/4` and `4/7`.
|
|
174
|
+
If you want every call of a task attributed, write the list first and alone.
|
|
175
|
+
The digest states the real ratio instead of rounding it.
|
|
176
|
+
|
|
177
|
+
## Platforms
|
|
178
|
+
|
|
179
|
+
| Platform | Status |
|
|
180
|
+
|---|---|
|
|
181
|
+
| Windows 11 · pi 1.5.0 · Node 22 | verified with the flow above |
|
|
182
|
+
| Linux (Ubuntu 24.04 x64) · pi 1.5.1 · Node 24 | **verified** by a second-environment rerun of the same flow (the maintainer's own run on another machine, not a third party): all suites pass, the nine-step scenario completed including a real compaction, and 11 JSONL↔digest cross-checks matched (80 events, 4 tasks, 15 finished calls, `10/15` item attribution, `1 completed, 0 failed`). Linux-specific expectations held: log and digest `0600`, log dir `0700`, POSIX paths, Chinese text intact, date directory in local time |
|
|
183
|
+
| Windows 11 · pi 1.6.1 · Node 24 | **partially re-verified** — session lifecycle only, per the re-check above: extensions load, events arrive, log and digest are written, `workfeed_todo` is registered; tool calls, todo attribution, compaction, fork and restart were not re-run on this version |
|
|
184
|
+
| Windows 11 · pi 1.7.0 · Node 24 | **partially re-verified** — session lifecycle + event path only, per the 1.7.0 re-check above: extensions load, events arrive, journal written, `pi` exit 0, the retry-inflates-turns behaviour reproduced live and the 0-based `turn` fix confirmed in a real log; tool calls, todo attribution, compaction, fork and restart were not re-run on this version |
|
|
185
|
+
| macOS | **not verified.** This project is limited by resources — no Apple hardware is available, so the extension has never been exercised on macOS. If you run it there and hit a problem, please open an issue with your pi version, your Node version, and the `## data quality` block of the affected digest |
|
|
186
|
+
|
|
187
|
+
Linux and macOS run the same Node code path; the only platform-specific parts are the file
|
|
188
|
+
mode bits (best effort on Windows) and the host's shell. A problem on either should be
|
|
189
|
+
reported rather than assumed to be a local mistake.
|
|
190
|
+
|
|
191
|
+
## Known rough edges
|
|
192
|
+
|
|
193
|
+
- **A premature `/compact` is an empty answer, not a failure.** On a session below pi's
|
|
194
|
+
keep-recent threshold, `/compact` replies "Nothing to compact (session too small)". The
|
|
195
|
+
digest reports that as `skipped`, with pi's reason attached, so the first digest a new
|
|
196
|
+
user reads does not say "1 failed" about an operation that had nothing to do.
|
|
197
|
+
- **A non-built-in model** needs an entry in `~/.pi/agent/models.json`; without pricing
|
|
198
|
+
there, the host reports zero cost and workfeed passes through what the host reports. That
|
|
199
|
+
is host configuration, not a workfeed setting.
|
|
200
|
+
- **Project-level `.pi/settings.json` versus `--approve`** is a host trust question. One
|
|
201
|
+
Linux run changed both at once and could not attribute the difference — change one
|
|
202
|
+
variable at a time if a project-level setting looks ignored.
|
|
203
|
+
|
|
204
|
+
## Reproducing
|
|
205
|
+
|
|
206
|
+
```bash
|
|
207
|
+
pi install /path/to/pi-workfeed # or npm:pi-workfeed once published
|
|
208
|
+
pi --mode rpc --session-dir /tmp/s --provider <you> --model <yours> --approve
|
|
209
|
+
# send {"type":"prompt","message":"…"} and {"type":"compact"} on stdin,
|
|
210
|
+
# read {"type":"agent_settled"} to know when a task is done
|
|
211
|
+
node --experimental-strip-types test/run.mjs
|
|
212
|
+
```
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# Versioning: three independent axes
|
|
2
|
+
|
|
3
|
+
`pi-workfeed` has three version numbers. They measure different things, they change for
|
|
4
|
+
different reasons, and **none of them is derived from another**. Confusing them is how a
|
|
5
|
+
release ends up claiming a protocol it does not implement.
|
|
6
|
+
|
|
7
|
+
| Axis | Where it lives | Changes when | Does **not** change when |
|
|
8
|
+
|---|---|---|---|
|
|
9
|
+
| **Wire (schema) version** | `v` field on every event; `SCHEMA_VERSION` in `extensions/journal/index.ts`; `const` in `schemas/workfeed-event-v1.schema.json`; the heading of `docs/schema.md` | the format breaks: a field is removed, renamed, retyped, given a new meaning, or an invariant guarantee changes | fields are added, docs improve, an analyzer gets smarter |
|
|
10
|
+
| **Package version** | `package.json` `version`; the README roadmap's `(this)` line; the top entry of `CHANGELOG.md` | anything installable changes: code, behaviour, dependencies, shipped docs | a git tag is cut, a release is uploaded |
|
|
11
|
+
| **Source version** | annotated git tag `v<package version>` on the commit that carries that `package.json` | a release is *cut*, i.e. someone decided this commit is the one to hand out | `package.json` alone changes on an ordinary commit |
|
|
12
|
+
|
|
13
|
+
Consequences worth stating out loud:
|
|
14
|
+
|
|
15
|
+
- **A patch release may still be wire `1`.** Most releases are package-only.
|
|
16
|
+
- **Wire `2` forces at least a minor bump**, and a breaking one (consumers must handle it),
|
|
17
|
+
but it does not have to be a major: the package is not a rewrite, just a new stream
|
|
18
|
+
format. `docs/schema.md` §10 defines what counts as breaking.
|
|
19
|
+
- **A tag can lag `package.json`.** `main` may run ahead of the last tag with docs-only or
|
|
20
|
+
test-only commits: those are real commits, not releases. A tag is never moved backwards,
|
|
21
|
+
and never placed on a commit whose `package.json` disagrees with the tag name.
|
|
22
|
+
|
|
23
|
+
## Bump rules for the package version
|
|
24
|
+
|
|
25
|
+
| Bump | Use for | Examples from this repo |
|
|
26
|
+
|---|---|---|
|
|
27
|
+
| patch (`0.3.x`) | docs, tests, internal refactors, policy — nothing a consumer installing the package gets differently | a protocol doc rewrite, a consistency test |
|
|
28
|
+
| minor (`0.x.0`) | new capability or visible behaviour change | integrity reporting, join keys holding across restarts, removing the CLI (an install surface that changed shape) |
|
|
29
|
+
| major | breaking tool contract or install-time behaviour | renaming `workfeed_todo`, changing what `files` ships |
|
|
30
|
+
|
|
31
|
+
Wire version bumps follow the schema rules and are counted separately; when both change,
|
|
32
|
+
the package version moves at least to the next minor.
|
|
33
|
+
|
|
34
|
+
## Cutting a release
|
|
35
|
+
|
|
36
|
+
A tag is cut only when all of these are true on the commit being tagged:
|
|
37
|
+
|
|
38
|
+
1. `npm test` — every suite passes (`ALL SUITES PASS`).
|
|
39
|
+
2. `npm pack --dry-run` — the file list is exactly what you expect: `CHANGELOG.md`, `LICENSE`,
|
|
40
|
+
`README.md`, `docs/`, `extensions/`, `package.json`, `schemas/`, `skills/` — nothing else.
|
|
41
|
+
No `test/`, no `.git`, and no `bin` field: the CLI was removed on purpose, so there is no
|
|
42
|
+
executable in the package and nothing to look for on `PATH`. `test/package.test.mjs` asserts
|
|
43
|
+
this shape, that `pi.extensions` / `pi.skills` point at entries that exist, and that **every
|
|
44
|
+
relative link in the README resolves to a file inside the declared ship set** — the README
|
|
45
|
+
travels in the tarball, so a link that only works in a checkout sends a reader nowhere.
|
|
46
|
+
`HISTORY.md` is at the repository root, outside `files`, and is linked by absolute URL for
|
|
47
|
+
that reason.
|
|
48
|
+
Peer dependencies (`@earendil-works/pi-ai`, `@earendil-works/pi-coding-agent`,
|
|
49
|
+
`@earendil-works/pi-tui`, `typebox`) are declared with `*` and stay that way: the running
|
|
50
|
+
pi host supplies all four, so any range would describe a copy that never loads. They are
|
|
51
|
+
checked for existence and for import use, not for version compatibility — a pi release that
|
|
52
|
+
renames a field is caught by a real run, not by npm.
|
|
53
|
+
3. `package.json` version == top `CHANGELOG.md` entry == README roadmap `(this)` line;
|
|
54
|
+
`test/version.test.mjs` checks exactly this and fails otherwise.
|
|
55
|
+
4. Wire version unchanged, or its bump documented in `docs/schema.md` §10 and reflected in
|
|
56
|
+
`SCHEMA_VERSION`, the JSON schema `const`, and the protocol heading. `schemaVersion = 1`
|
|
57
|
+
is frozen for the first release: `test/schema-freeze.test.mjs` compares the machine schema
|
|
58
|
+
with `test/fixtures/schema-freeze-v1.json` and fails on any added or removed field,
|
|
59
|
+
required flag or event type. Adding to the wire is therefore a wire-version decision —
|
|
60
|
+
bump the version and update the snapshot in the same commit; a plain patch cannot.
|
|
61
|
+
5. `git tag -a v<package version> -m "..."`, then push the tag to **both** remotes
|
|
62
|
+
(`git push origin v<package version>` and `git push gitee v<package version>`) so the
|
|
63
|
+
mirror cannot drift. The tag name is the version in `package.json`, never a literal you
|
|
64
|
+
typed from memory — that is how a tag lands on the wrong commit.
|
|
65
|
+
6. npm publication (when credentials exist) happens **after** the tag and **from the tagged
|
|
66
|
+
commit**, so `npm pack` of the published version produces the same tree the tag points at.
|
|
67
|
+
If a doc fix lands after the tag and before the first publish, re-point the tag to the fixed
|
|
68
|
+
commit (delete the old tag locally and on both remotes, cut it again) rather than publishing
|
|
69
|
+
a tree the tag does not describe — then run the clean-install probe on that artifact, and
|
|
70
|
+
verify from the registry (`npm view pi-workfeed versions`, `dist-tags.latest`) once it is out.
|
|
71
|
+
|
|
72
|
+
## What enforces this
|
|
73
|
+
|
|
74
|
+
`test/version.test.mjs` reads the four declarations and compares them:
|
|
75
|
+
|
|
76
|
+
- `package.json` version
|
|
77
|
+
- first `## [x.y.z]` heading in `CHANGELOG.md`
|
|
78
|
+
- the roadmap's `vX.Y.Z (this)` line in `README.md`
|
|
79
|
+
- `SCHEMA_VERSION` in the producer vs `properties.v.const` in the JSON schema
|
|
80
|
+
|
|
81
|
+
It also looks at git, three times. If `HEAD` is tagged, the tag must be `v<package version>`.
|
|
82
|
+
Every tag must name the version inside **its own commit** (`dev/0.4.6` must contain `0.4.6`).
|
|
83
|
+
And no release tag may claim a version above `package.json` — development milestones therefore
|
|
84
|
+
live under `dev/` (`dev/0.3.1`, `dev/0.4.0` … `dev/0.4.6`), because a `v0.4.6` tag beside an
|
|
85
|
+
npm `0.1.0` reads as "the latest version is 0.4.6" and contradicts the package a reader just
|
|
86
|
+
installed. The two rules together are what makes a number-line reset safe *and* visible: the
|
|
87
|
+
per-commit rule keeps an old tag honest about its own tree, and the ceiling rule keeps the
|
|
88
|
+
release line the only `v*` line.
|
|
89
|
+
|
|
90
|
+
Nothing here is a substitute for the checklist: the test catches text drifting apart, not a
|
|
91
|
+
release that skipped its own evidence.
|
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Digest builder — a pure function, no pi API, no I/O.
|
|
3
|
+
*
|
|
4
|
+
* The digest is derived data: it holds aggregate facts only, never advice.
|
|
5
|
+
* It is rebuilt from `workfeed-<sid>.jsonl`; deleting every digest file must be
|
|
6
|
+
* harmless, because that log is the truth.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
export interface TokenBuckets {
|
|
10
|
+
input: number;
|
|
11
|
+
output: number;
|
|
12
|
+
cacheRead: number;
|
|
13
|
+
cacheWrite: number;
|
|
14
|
+
total: number;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface TaskStats {
|
|
18
|
+
/** 1-based user-instruction index, same value as the `task` field in events */
|
|
19
|
+
index: number;
|
|
20
|
+
/** wall clock from prompt to agent_settled, ms */
|
|
21
|
+
ms: number;
|
|
22
|
+
turns: number;
|
|
23
|
+
tools: number;
|
|
24
|
+
tokens: TokenBuckets;
|
|
25
|
+
aborted: boolean;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface ToolRecord {
|
|
29
|
+
name: string;
|
|
30
|
+
task: number;
|
|
31
|
+
item?: number;
|
|
32
|
+
ts: number;
|
|
33
|
+
/** monotonic duration reported by pi, ms (may be absent for blocked calls) */
|
|
34
|
+
durMs?: number;
|
|
35
|
+
/** wall clock from tool_call to tool_execution_end, ms */
|
|
36
|
+
wallMs?: number;
|
|
37
|
+
isError: boolean;
|
|
38
|
+
exitCode?: number;
|
|
39
|
+
outBytes?: number;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface TodoItem {
|
|
43
|
+
id: number;
|
|
44
|
+
text: string;
|
|
45
|
+
status: string;
|
|
46
|
+
elapsedMs: number;
|
|
47
|
+
/** true when a later snapshot dropped the item (e.g. `clear`): kept, never zeroed */
|
|
48
|
+
dropped?: boolean;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* What a replay could not use, and why. Skipping a bad line is acceptable;
|
|
53
|
+
* skipping it silently is not — the digest has to state how much of the file it
|
|
54
|
+
* could read, or a clean-looking digest hides a hole in the middle of history.
|
|
55
|
+
*/
|
|
56
|
+
export interface LogIntegrity {
|
|
57
|
+
/** non-empty lines seen */
|
|
58
|
+
lines: number;
|
|
59
|
+
/** 1-based line number of an unparsable *final* line (a killed append), else null */
|
|
60
|
+
tornTail: number | null;
|
|
61
|
+
/** 1-based line numbers that failed to parse in the middle of the file */
|
|
62
|
+
corrupt: number[];
|
|
63
|
+
/** lines that parsed but violate the envelope (wrong `v`, missing/typed-wrong key) */
|
|
64
|
+
badEnvelope: Array<{ line: number; reason: string }>;
|
|
65
|
+
/** event types this version does not know: tolerated, but reported */
|
|
66
|
+
unknown: Array<{ line: number; t: string }>;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export interface DigestInput {
|
|
70
|
+
sid: string;
|
|
71
|
+
date: string;
|
|
72
|
+
generatedAt: number;
|
|
73
|
+
model?: string;
|
|
74
|
+
provider?: string;
|
|
75
|
+
cwd: string;
|
|
76
|
+
events: number;
|
|
77
|
+
tasks: TaskStats[];
|
|
78
|
+
tools: ToolRecord[];
|
|
79
|
+
todos: TodoItem[];
|
|
80
|
+
/** how much of the raw stream the tables above actually cover */
|
|
81
|
+
quality?: {
|
|
82
|
+
/** calls that emitted a start line */
|
|
83
|
+
started: number;
|
|
84
|
+
/** calls that emitted both start and end */
|
|
85
|
+
calls: number;
|
|
86
|
+
/** start lines with no matching end line: crash, kill or abort */
|
|
87
|
+
unfinished: number;
|
|
88
|
+
/** finished calls carrying an `item` attribution */
|
|
89
|
+
attributed: number;
|
|
90
|
+
/** settled tasks whose token total is non-zero */
|
|
91
|
+
tasksWithTokens: number;
|
|
92
|
+
/** user prompts seen (one per task) */
|
|
93
|
+
prompts?: number;
|
|
94
|
+
/** prompts with no settle: killed, crashed, or still running */
|
|
95
|
+
unsettled?: number;
|
|
96
|
+
/** compaction runs seen; absent when none happened (no fabricated zero) */
|
|
97
|
+
compaction?: {
|
|
98
|
+
runs: number;
|
|
99
|
+
failed: number;
|
|
100
|
+
/** aborted, or "nothing to compact": an empty answer, not a failure */
|
|
101
|
+
skipped: number;
|
|
102
|
+
lastError?: string;
|
|
103
|
+
lastSkip?: string;
|
|
104
|
+
};
|
|
105
|
+
/** what the parser had to drop, and why */
|
|
106
|
+
integrity?: LogIntegrity;
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const pct = (part: number, whole: number): string =>
|
|
111
|
+
whole > 0 ? `${Math.round((part / whole) * 100)}%` : "-";
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Duration formatting for a human reading the digest.
|
|
115
|
+
*
|
|
116
|
+
* A floor-to-seconds formatter turns a whole column into `0s`, which is worse than
|
|
117
|
+
* useless: "which tool was slow" is the question this digest exists to answer, and
|
|
118
|
+
* every sub-second call then looks identical. So: milliseconds below one second, one
|
|
119
|
+
* decimal below ten seconds, whole seconds above it.
|
|
120
|
+
*/
|
|
121
|
+
export const fmtDur = (ms: number | undefined): string => {
|
|
122
|
+
if (!ms || ms < 0) return "0s";
|
|
123
|
+
if (ms < 1000) return `${Math.round(ms)}ms`;
|
|
124
|
+
const secs = ms / 1000;
|
|
125
|
+
if (secs < 10) {
|
|
126
|
+
const one = secs.toFixed(1);
|
|
127
|
+
return `${one.endsWith(".0") ? one.slice(0, -2) : one}s`;
|
|
128
|
+
}
|
|
129
|
+
const s = Math.round(secs);
|
|
130
|
+
if (s < 60) return `${s}s`;
|
|
131
|
+
const m = Math.floor(s / 60);
|
|
132
|
+
if (m < 60) return `${m}m${String(s % 60).padStart(2, "0")}s`;
|
|
133
|
+
const h = Math.floor(m / 60);
|
|
134
|
+
return `${h}h${String(m % 60).padStart(2, "0")}m`;
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
const clip = (text: string, n: number): string => (text.length <= n ? text : text.slice(0, n - 1) + "…");
|
|
138
|
+
|
|
139
|
+
const fmtTokens = (t: TokenBuckets): string => {
|
|
140
|
+
if (!t || t.total === 0) return "0";
|
|
141
|
+
const k = (n: number) => (n >= 1000 ? `${(n / 1000).toFixed(1)}k` : String(n));
|
|
142
|
+
return `${k(t.input + t.cacheRead + t.cacheWrite)} in / ${k(t.output)} out / ${k(t.total)} total`;
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
/** Slowest tool calls, in duration order (monotonic duration wins over wall clock). */
|
|
146
|
+
export function slowestTools(tools: ToolRecord[], n = 5): ToolRecord[] {
|
|
147
|
+
return tools
|
|
148
|
+
.filter((t) => t.durMs !== undefined)
|
|
149
|
+
.slice()
|
|
150
|
+
.sort((a, b) => (b.durMs ?? 0) - (a.durMs ?? 0))
|
|
151
|
+
.slice(0, n);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/** Tool calls grouped by name, ordered by total time spent. */
|
|
155
|
+
export function toolRollup(tools: ToolRecord[], n = 8): Array<{ name: string; count: number; total: number; max: number; failed: number }> {
|
|
156
|
+
const map = new Map<string, { name: string; count: number; total: number; max: number; failed: number }>();
|
|
157
|
+
for (const t of tools) {
|
|
158
|
+
const e = map.get(t.name) ?? { name: t.name, count: 0, total: 0, max: 0, failed: 0 };
|
|
159
|
+
e.count += 1;
|
|
160
|
+
e.total += t.durMs ?? 0;
|
|
161
|
+
e.max = Math.max(e.max, t.durMs ?? 0);
|
|
162
|
+
e.failed += t.isError ? 1 : 0;
|
|
163
|
+
map.set(t.name, e);
|
|
164
|
+
}
|
|
165
|
+
return [...map.values()].sort((a, b) => b.total - a.total).slice(0, n);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export function buildDigest(input: DigestInput): string {
|
|
169
|
+
const { tasks, tools, todos } = input;
|
|
170
|
+
const lines: string[] = [];
|
|
171
|
+
|
|
172
|
+
lines.push("# workfeed digest");
|
|
173
|
+
lines.push("");
|
|
174
|
+
lines.push(`> derived from workfeed-${input.sid}.jsonl at ${new Date(input.generatedAt).toISOString()} — regenerate, do not hand-edit.`);
|
|
175
|
+
lines.push("");
|
|
176
|
+
lines.push(`- session: ${input.sid}`);
|
|
177
|
+
lines.push(`- date: ${input.date}`);
|
|
178
|
+
lines.push(`- model: ${input.model ?? "?"}${input.provider ? ` (${input.provider})` : ""}`);
|
|
179
|
+
lines.push(`- cwd: ${input.cwd}`);
|
|
180
|
+
lines.push(`- events: ${input.events}`);
|
|
181
|
+
lines.push("");
|
|
182
|
+
|
|
183
|
+
// ---- data quality: what the tables below cannot tell you ----
|
|
184
|
+
if (input.quality) {
|
|
185
|
+
const q = input.quality;
|
|
186
|
+
const pctAttr = q.calls > 0 ? `${Math.round((q.attributed / q.calls) * 100)}%` : "-";
|
|
187
|
+
lines.push("## data quality");
|
|
188
|
+
lines.push("");
|
|
189
|
+
lines.push(`- tool calls: ${q.calls} finished${q.unfinished > 0 ? `, ${q.unfinished} started without an end line (crash, kill or abort)` : ""}`);
|
|
190
|
+
lines.push(`- item attribution: ${q.attributed}/${q.calls} calls carry an item (${pctAttr})`);
|
|
191
|
+
lines.push(`- token totals: ${q.tasksWithTokens}/${tasks.length} tasks report a non-zero total`);
|
|
192
|
+
if (q.prompts !== undefined) {
|
|
193
|
+
const open = q.unsettled ?? 0;
|
|
194
|
+
lines.push(
|
|
195
|
+
`- task coverage: ${tasks.length}/${q.prompts} prompts have a settle${open > 0 ? ` — ${open} ${open === 1 ? "was" : "were"} killed or ${open === 1 ? "is" : "are"} still open, so ${open === 1 ? "its" : "their"} duration and tokens are unknown, not zero` : ""}`,
|
|
196
|
+
);
|
|
197
|
+
}
|
|
198
|
+
// A failed or aborted compaction is invisible in the tables: no task or tool row
|
|
199
|
+
// changes shape, the context just never shrank. Report it instead of letting a
|
|
200
|
+
// clean-looking digest imply the compaction happened.
|
|
201
|
+
if (q.compaction) {
|
|
202
|
+
const c = q.compaction;
|
|
203
|
+
const skipped = c.skipped > 0 ? `${c.skipped} skipped` : undefined;
|
|
204
|
+
// Failures speak first; if there are none, the skipped reason is still worth
|
|
205
|
+
// saying, because "nothing to compact" on a small session is the normal answer.
|
|
206
|
+
const why = c.lastError
|
|
207
|
+
? ` — last: ${clip(c.lastError, 120)}`
|
|
208
|
+
: c.lastSkip
|
|
209
|
+
? ` — skipped: ${clip(c.lastSkip, 120)}`
|
|
210
|
+
: "";
|
|
211
|
+
const parts = [`${c.runs} completed`, `${c.failed} failed`];
|
|
212
|
+
if (skipped) parts.push(skipped);
|
|
213
|
+
lines.push(`- compaction: ${parts.join(", ")}${why}`);
|
|
214
|
+
}
|
|
215
|
+
const integ = q.integrity;
|
|
216
|
+
if (integ) {
|
|
217
|
+
const dropped = integ.corrupt.length + integ.badEnvelope.length;
|
|
218
|
+
lines.push(
|
|
219
|
+
`- log integrity: ${integ.lines} lines, ${dropped} dropped${dropped > 0 ? ` (${integ.corrupt.length} unparsable, ${integ.badEnvelope.length} violating the envelope)` : ""}, ${integ.unknown.length} of unknown type`,
|
|
220
|
+
);
|
|
221
|
+
if (integ.tornTail !== null) {
|
|
222
|
+
lines.push(`- torn tail: line ${integ.tornTail} was an interrupted append; everything before it was used`);
|
|
223
|
+
}
|
|
224
|
+
if (integ.corrupt.length > 0) {
|
|
225
|
+
lines.push(`- corrupt lines: ${integ.corrupt.join(", ")} — facts around them survive, but any ordering near them is lost`);
|
|
226
|
+
}
|
|
227
|
+
for (const bad of integ.badEnvelope.slice(0, 3)) {
|
|
228
|
+
lines.push(`- rejected line ${bad.line}: ${bad.reason}`);
|
|
229
|
+
}
|
|
230
|
+
if (integ.badEnvelope.length > 3) {
|
|
231
|
+
lines.push(`- rejected lines: ${integ.badEnvelope.length} total, first 3 shown`);
|
|
232
|
+
}
|
|
233
|
+
if (integ.unknown.length > 0) {
|
|
234
|
+
lines.push(`- unknown event types: ${[...new Set(integ.unknown.map((u) => u.t))].join(", ")} (ignored; the format is forward compatible)`);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
lines.push("");
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
// ---- tasks ----
|
|
241
|
+
const totalMs = tasks.reduce((a, t) => a + t.ms, 0);
|
|
242
|
+
lines.push(`## tasks (${tasks.length}, wall clock ${fmtDur(totalMs)})`);
|
|
243
|
+
lines.push("");
|
|
244
|
+
if (tasks.length === 0) {
|
|
245
|
+
lines.push("_none yet_");
|
|
246
|
+
} else {
|
|
247
|
+
lines.push("| # | time | turns | tools | tokens | status |");
|
|
248
|
+
lines.push("|---|---|---|---|---|---|");
|
|
249
|
+
for (const t of tasks) {
|
|
250
|
+
lines.push(
|
|
251
|
+
`| ${t.index} | ${fmtDur(t.ms)} | ${t.turns} | ${t.tools} | ${fmtTokens(t.tokens)} | ${t.aborted ? "aborted" : "ok"} |`,
|
|
252
|
+
);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
lines.push("");
|
|
256
|
+
|
|
257
|
+
// ---- tools ----
|
|
258
|
+
const done = tools.filter((t) => t.durMs !== undefined || t.isError);
|
|
259
|
+
const fails = done.filter((t) => t.isError).length;
|
|
260
|
+
lines.push(`## tools (${tools.length} ${tools.length === 1 ? "call" : "calls"}, ${fails} failed)`);
|
|
261
|
+
lines.push("");
|
|
262
|
+
const rollup = toolRollup(tools);
|
|
263
|
+
if (rollup.length === 0) {
|
|
264
|
+
lines.push("_none yet_");
|
|
265
|
+
} else {
|
|
266
|
+
lines.push("| tool | calls | total | avg | max | failed |");
|
|
267
|
+
lines.push("|---|---|---|---|---|---|");
|
|
268
|
+
for (const r of rollup) {
|
|
269
|
+
const avg = r.count > 0 ? r.total / r.count : 0;
|
|
270
|
+
lines.push(`| ${r.name} | ${r.count} | ${fmtDur(r.total)} | ${fmtDur(avg)} | ${fmtDur(r.max)} | ${r.failed} |`);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
lines.push("");
|
|
274
|
+
|
|
275
|
+
const slow = slowestTools(tools, 5);
|
|
276
|
+
if (slow.length > 0) {
|
|
277
|
+
lines.push("slowest calls");
|
|
278
|
+
lines.push("");
|
|
279
|
+
for (const t of slow) {
|
|
280
|
+
lines.push(`- ${fmtDur(t.durMs)} · ${t.name} · task ${t.task}${t.item ? ` · item ${t.item}` : ""}${t.isError ? " · FAILED" : ""}`);
|
|
281
|
+
}
|
|
282
|
+
lines.push("");
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
const failed = tools.filter((t) => t.isError).slice(-5);
|
|
286
|
+
if (failed.length > 0) {
|
|
287
|
+
lines.push("last failures");
|
|
288
|
+
lines.push("");
|
|
289
|
+
for (const t of failed) {
|
|
290
|
+
lines.push(`- ${t.name} · task ${t.task}${t.exitCode !== undefined ? ` · exit ${t.exitCode}` : ""} · ${new Date(t.ts).toISOString().slice(11, 19)}`);
|
|
291
|
+
}
|
|
292
|
+
lines.push("");
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
// ---- todo ----
|
|
296
|
+
lines.push(`## todo items (${todos.length})`);
|
|
297
|
+
lines.push("");
|
|
298
|
+
if (todos.length === 0) {
|
|
299
|
+
lines.push("_none_");
|
|
300
|
+
} else {
|
|
301
|
+
const doneCount = todos.filter((t) => t.status === "completed").length;
|
|
302
|
+
const droppedCount = todos.filter((t) => t.dropped).length;
|
|
303
|
+
const elapsedTotal = todos.reduce((a, t) => a + t.elapsedMs, 0);
|
|
304
|
+
lines.push(
|
|
305
|
+
`${doneCount}/${todos.length} completed · accumulated in-progress time ${fmtDur(elapsedTotal)}${droppedCount > 0 ? ` · ${droppedCount} dropped from the list (timing kept)` : ""}`,
|
|
306
|
+
);
|
|
307
|
+
lines.push("");
|
|
308
|
+
lines.push("| id | status | elapsed | share | text |");
|
|
309
|
+
lines.push("|---|---|---|---|---|");
|
|
310
|
+
for (const t of todos) {
|
|
311
|
+
const status = t.dropped ? `${t.status} · dropped` : t.status;
|
|
312
|
+
lines.push(`| ${t.id} | ${status} | ${fmtDur(t.elapsedMs)} | ${pct(t.elapsedMs, elapsedTotal)} | ${clip(t.text.replace(/\|/g, "\\|"), 60)} |`);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
lines.push("");
|
|
316
|
+
|
|
317
|
+
return lines.join("\n");
|
|
318
|
+
}
|