pi-workfeed 0.0.0-stage → 0.1.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/CHANGELOG.md +54 -0
- package/LICENSE +21 -0
- package/README.md +437 -2
- package/docs/README.md +12 -0
- package/docs/schema.md +454 -0
- package/docs/verification.md +141 -0
- package/docs/versioning.md +91 -0
- package/extensions/journal/digest.ts +318 -0
- package/extensions/journal/index.ts +664 -0
- package/extensions/journal/replay.ts +359 -0
- package/extensions/todo/index.ts +324 -0
- package/package.json +54 -4
- package/schemas/workfeed-event-v1.schema.json +176 -0
- package/skills/workfeed-analysis/SKILL.md +142 -0
package/docs/schema.md
ADDED
|
@@ -0,0 +1,454 @@
|
|
|
1
|
+
# Workfeed wire format v1 — protocol specification
|
|
2
|
+
|
|
3
|
+
**Status:** normative for `schemaVersion = 1`. The wire version is its own axis and does not
|
|
4
|
+
follow the package version (§10), so this document applies to every release that ships
|
|
5
|
+
`v: 1` — see `docs/versioning.md`.
|
|
6
|
+
**Machine-readable form:** [`../schemas/workfeed-event-v1.schema.json`](../schemas/workfeed-event-v1.schema.json).
|
|
7
|
+
|
|
8
|
+
This is a protocol, not a feature tour. If you write a consumer (an analyzer, an importer,
|
|
9
|
+
another agent), the tables below are what you may rely on; anything not stated here is
|
|
10
|
+
implementation detail and may change without a version bump. Terms **MUST / SHOULD / MAY**
|
|
11
|
+
are used in their RFC 2119 sense.
|
|
12
|
+
|
|
13
|
+
A producer that violates an invariant in §5 is buggy, and the correct consumer behaviour is
|
|
14
|
+
to detect it (see §11), not to silently average it away.
|
|
15
|
+
|
|
16
|
+
## Freeze (applies to every release that ships `v: 1`)
|
|
17
|
+
|
|
18
|
+
`schemaVersion = 1` is **frozen**: no new fields and no new event types are added before the
|
|
19
|
+
first release. The frozen contract is stored as a snapshot
|
|
20
|
+
(`test/fixtures/schema-freeze-v1.json`) and `test/schema-freeze.test.mjs` rebuilds that
|
|
21
|
+
summary from the machine schema and compares it field by field, so an accidental addition
|
|
22
|
+
fails the suite instead of slipping into a consumer's parser.
|
|
23
|
+
|
|
24
|
+
Changing it is allowed, but it is a version decision, not a patch: bump the wire version per
|
|
25
|
+
`docs/versioning.md`, ship the new version beside v1, and update the snapshot in the same
|
|
26
|
+
commit. Fields may still be documented better, and the *digest* — a derived view — may grow
|
|
27
|
+
new lines without touching this document.
|
|
28
|
+
|
|
29
|
+
## 1. Transport and file layout
|
|
30
|
+
|
|
31
|
+
```text
|
|
32
|
+
${PI_WORKFEED_DIR:-~/.pi/agent/logs}/<YYYY-MM-DD>/
|
|
33
|
+
├── workfeed-<sid>.jsonl # truth: append-only event stream
|
|
34
|
+
└── workfeed-<sid>.digest.md # derived: a projection of the .jsonl, delete-safe
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
- One session owns **exactly one** `.jsonl` file. `<YYYY-MM-DD>` is the day the session
|
|
38
|
+
first logged; a session resumed after midnight keeps appending to its original file
|
|
39
|
+
instead of starting a second one, so a consumer looking for a session SHOULD search all
|
|
40
|
+
date directories for `workfeed-<sid>.jsonl` rather than assume today's directory.
|
|
41
|
+
- Files are created with mode `0600` inside a `0700` directory (POSIX; Windows applies them
|
|
42
|
+
only partially). Treat the directory as sensitive regardless — see §7.
|
|
43
|
+
- `workfeed-<sid>.digest.md` is **derived data**. Deleting it MUST be safe (see §9).
|
|
44
|
+
|
|
45
|
+
## 2. Line grammar
|
|
46
|
+
|
|
47
|
+
- Encoding UTF-8, no BOM. One JSON object per line, terminated by `\n`. No pretty-printing,
|
|
48
|
+
no comments, no multi-line objects.
|
|
49
|
+
- **Append-only.** Existing bytes are never rewritten, reordered or truncated by the producer.
|
|
50
|
+
Ordering is by `ts` (non-decreasing); equal `ts` values are permitted and their relative
|
|
51
|
+
order is meaningful (a `tool` `start` precedes its `end`).
|
|
52
|
+
- A **torn final line** is the expected artifact of a killed process. A parser MUST ignore
|
|
53
|
+
a final line that does not parse, and MUST NOT treat it as corruption of earlier lines.
|
|
54
|
+
- **Corruption before the tail is not "recovered"; it is damage.** A parser MUST report
|
|
55
|
+
unparsable lines by number, MUST NOT present its aggregates as complete, and MUST NOT
|
|
56
|
+
silently continue as if the file were whole. The producer's own reader reports
|
|
57
|
+
`corrupt`, `badEnvelope` and `unknown` as three distinct classes (`parseLogDetailed`
|
|
58
|
+
in `extensions/journal/replay.ts`); a consumer SHOULD do the same rather than collapsing
|
|
59
|
+
everything into "skipped".
|
|
60
|
+
- An **envelope violation** (unexpected `v`, missing or mistyped `ts`/`sid`/`task`/`t`) is
|
|
61
|
+
a producer bug: reject the line, report it with a reason.
|
|
62
|
+
- An **unknown `t`** is normal forward compatibility: keep the line, label it, and do not
|
|
63
|
+
let it contribute to any aggregate you do not understand.
|
|
64
|
+
- A parser MUST skip lines whose `v` is not `1` **or** unknown, rather than guessing their
|
|
65
|
+
meaning.
|
|
66
|
+
- Unknown keys MUST be tolerated (forward compatibility). Absent keys MUST be treated as
|
|
67
|
+
"not recorded", never as a default value.
|
|
68
|
+
|
|
69
|
+
## 3. Envelope (every line)
|
|
70
|
+
|
|
71
|
+
| Field | Type | Req | Constraints |
|
|
72
|
+
|---|---|---|---|
|
|
73
|
+
| `v` | integer | yes | exactly `1` for this document |
|
|
74
|
+
| `ts` | integer | yes | epoch milliseconds, non-decreasing within a file |
|
|
75
|
+
| `sid` | string | yes | non-empty session id, constant within a file |
|
|
76
|
+
| `task` | integer | yes | ≥ `0`; `0` only before the first user prompt; **non-decreasing**, incremented once per user prompt |
|
|
77
|
+
| `item` | integer | no | ≥ `1`; id of the work item that was `in_progress`; absent when none |
|
|
78
|
+
| `t` | string | yes | one of the event types in §4 |
|
|
79
|
+
|
|
80
|
+
`task` and `item` are the **join keys**. Their guarantees:
|
|
81
|
+
|
|
82
|
+
- `task` is assigned per session and **survives process restarts**: a producer MUST continue
|
|
83
|
+
from the highest `task` already present in its file (§5, I1). Two lines with the same
|
|
84
|
+
`sid` and `task` and different prompts is a protocol violation.
|
|
85
|
+
- `item` ids are **unique within a session**: never reused after `clear` (§5, I2). Two items
|
|
86
|
+
with the same id in one session is a violation.
|
|
87
|
+
- **The source of `item` is replaceable.** The wire format says "the work item that was
|
|
88
|
+
in_progress", not "the id of `workfeed_todo`": by default the todo extension supplies it,
|
|
89
|
+
but a planner, an external issue list, or another extension may supply the same ids as
|
|
90
|
+
long as they are unique per session and stable while the item exists. Consumers MUST treat
|
|
91
|
+
`item` as an opaque id and MUST NOT assume the producing tool. `todo` snapshots are then
|
|
92
|
+
just that source's state, which is why the digest treats them as evidence rather than as
|
|
93
|
+
the definition of work.
|
|
94
|
+
- A `tool` `end` line **repeats the attribution captured at `start`**, not the state at
|
|
95
|
+
finish (§5, I3). A consumer MUST use each line's own `item`; pairing `start`/`end` by
|
|
96
|
+
timestamp to infer attribution is wrong by design.
|
|
97
|
+
- Item identity is **positional, not semantic**: the producer matches items by their `text`.
|
|
98
|
+
Reword an item and it becomes a new id with fresh timing. Do not assume two equal texts
|
|
99
|
+
across sessions are the same work.
|
|
100
|
+
|
|
101
|
+
### Scope of the join keys: session-local, not business ids
|
|
102
|
+
|
|
103
|
+
`task` and `item` are counters inside one `sid`. They are sufficient to join everything
|
|
104
|
+
inside one session and **insufficient** to compare sessions:
|
|
105
|
+
|
|
106
|
+
| Key | Scope | Stable across | Not stable across |
|
|
107
|
+
|---|---|---|---|
|
|
108
|
+
| `sid` | one session | restarts of the same session (same file) | `/new`, fork, compaction into a new session |
|
|
109
|
+
| `task` | one `sid` | process restarts (producer resumes the counter) | sessions — `task 3` in two sessions are unrelated |
|
|
110
|
+
| `item` | one `sid` | `clear` (ids are never reused) | sessions, and reworded items within a session |
|
|
111
|
+
|
|
112
|
+
Therefore a cross-session key MUST be built as `(sid, task)` or `(sid, task, item)`; a
|
|
113
|
+
consumer MUST NOT compare `task`/`item` values across files and infer that the same work
|
|
114
|
+
happened. Aggregating across sessions is allowed only over *dimensions* (tool names,
|
|
115
|
+
durations, failure rates), never over these ids directly.
|
|
116
|
+
|
|
117
|
+
v1 deliberately ships **no** globally unique task or item id: a stable id would have to be
|
|
118
|
+
assigned by the model (or a planner) rather than derived from a position, and inventing one
|
|
119
|
+
inside the producer would silently change the meaning of `task`. If a future version adds
|
|
120
|
+
`tid` / `iid`, those fields are additive and the positional keys above keep their meaning.
|
|
121
|
+
|
|
122
|
+
## 4. Event catalog
|
|
123
|
+
|
|
124
|
+
Field tables list **extra** fields only; the envelope of §3 is implied. "Req" = required
|
|
125
|
+
(MUST be present); "opt" = MAY be absent. `—` in `phase` means the event has no phase.
|
|
126
|
+
|
|
127
|
+
### `session`
|
|
128
|
+
|
|
129
|
+
Emitted on `session_start` (startup, resume, `/new`, fork).
|
|
130
|
+
|
|
131
|
+
| Field | Type | Req | Notes |
|
|
132
|
+
|---|---|---|---|
|
|
133
|
+
| `reason` | string | opt | producer-supplied reason (`startup`, `resume`, …) |
|
|
134
|
+
| `cwd` | string | opt | working directory; last path segment only when content is off (§7) |
|
|
135
|
+
| `sessionFile` | string | opt | pi session file; basename only when content is off |
|
|
136
|
+
| `model` | string | opt | model id at that moment |
|
|
137
|
+
| `provider` | string | opt | provider id |
|
|
138
|
+
| `pid` | integer | opt | process that wrote the line — distinguishes the runs of one file |
|
|
139
|
+
|
|
140
|
+
A file MAY contain several `session` lines (one per process). Consumers MUST NOT treat a
|
|
141
|
+
second `session` line as a new session: `sid` is the session identity.
|
|
142
|
+
|
|
143
|
+
### `prompt`
|
|
144
|
+
|
|
145
|
+
| Field | Type | Req | Notes |
|
|
146
|
+
|---|---|---|---|
|
|
147
|
+
| `chars` | integer | yes | length of the prompt, always recorded |
|
|
148
|
+
| `text` | string | opt | ≤3000 chars, scrubbed; omitted when content is off |
|
|
149
|
+
| `model` | string | opt | model that will serve this task |
|
|
150
|
+
| `thinking` | string | opt | thinking level |
|
|
151
|
+
|
|
152
|
+
Written only for **user** prompts. A tool-injected or compaction turn produces no `prompt`
|
|
153
|
+
line and no `settle` line.
|
|
154
|
+
|
|
155
|
+
### `agent_start`
|
|
156
|
+
|
|
157
|
+
No extra fields. Marks the agent loop beginning after a `prompt`.
|
|
158
|
+
|
|
159
|
+
### `turn`
|
|
160
|
+
|
|
161
|
+
| `phase` | Field | Type | Req | Notes |
|
|
162
|
+
|---|---|---|---|---|
|
|
163
|
+
| `start` | `turn` | integer | yes | 1-based index within the task |
|
|
164
|
+
| `start` | `model` | string | opt | model serving this turn |
|
|
165
|
+
| `end` | `turn` | integer | yes | same index as its `start` |
|
|
166
|
+
| `end` | `durMs` | integer | opt | `turn_start`→`turn_end` wall clock |
|
|
167
|
+
| `end` | `outcome` | string | opt | producer-supplied outcome token |
|
|
168
|
+
| `end` | `stopReason` | string | opt | provider stop reason |
|
|
169
|
+
| `end` | `usage` | object | opt | raw provider usage, passed through (`input`, `output`, `cacheRead`, `cacheWrite`, `totalTokens`…) |
|
|
170
|
+
| `end` | `tools` | integer | opt | tool calls executed in this turn |
|
|
171
|
+
|
|
172
|
+
`usage` is the provider's own object and MUST be treated as producer-specific; use
|
|
173
|
+
`settle.tokens` for normalized numbers (§8).
|
|
174
|
+
|
|
175
|
+
### `tool`
|
|
176
|
+
|
|
177
|
+
| `phase` | Field | Type | Req | Notes |
|
|
178
|
+
|---|---|---|---|---|
|
|
179
|
+
| `start` | `id` | string | yes | call id; correlates with the `end` line |
|
|
180
|
+
| `start` | `name` | string | yes | tool name |
|
|
181
|
+
| `start` | `parent` | string | opt | parent call id for nested calls |
|
|
182
|
+
| `start` | `args` | object | opt | policy-shaped (§7); may be `{keys,stringBytes}` in `shape` mode |
|
|
183
|
+
| `end` | `id` | string | yes | same id as its `start` |
|
|
184
|
+
| `end` | `name` | string | yes | tool name |
|
|
185
|
+
| `end` | `durMs` | integer | opt | monotonic `execute()` duration — trust this one (§8) |
|
|
186
|
+
| `end` | `wallMs` | integer | opt | `start`→`end` wall clock, includes scheduling |
|
|
187
|
+
| `end` | `isError` | boolean | yes | whether the call failed |
|
|
188
|
+
| `end` | `exitCode` | integer | opt | process exit code when the tool reports one |
|
|
189
|
+
| `end` | `truncated` | boolean | opt | producer-side truncation of the output |
|
|
190
|
+
| `end` | `outBytes` | integer | opt | true output size in bytes, before excerpting |
|
|
191
|
+
| `end` | `out` | string | opt | excerpt (≤`PI_WORKFEED_EXCERPT`), scrubbed; omitted when content is off |
|
|
192
|
+
|
|
193
|
+
Invariant I4: within a file, each `id` has **at most one** `start` and **at most one** `end`,
|
|
194
|
+
and an `end` NEVER precedes its `start`. An `id` with a `start` and no `end` is legal — the
|
|
195
|
+
process died (§12).
|
|
196
|
+
|
|
197
|
+
### `todo`
|
|
198
|
+
|
|
199
|
+
Full snapshot of the list, written **only when the list changes** (identical snapshots are
|
|
200
|
+
deduplicated by the producer, and by the journal as a defence in depth).
|
|
201
|
+
|
|
202
|
+
| Field | Type | Req | Notes |
|
|
203
|
+
|---|---|---|---|
|
|
204
|
+
| `rev` | integer | opt | monotonic snapshot counter within the session |
|
|
205
|
+
| `items` | array | yes | ordered list, `[]` = emptied |
|
|
206
|
+
|
|
207
|
+
Each entry:
|
|
208
|
+
|
|
209
|
+
| Field | Type | Req | Notes |
|
|
210
|
+
|---|---|---|---|
|
|
211
|
+
| `id` | integer | yes | ≥1, unique within the session |
|
|
212
|
+
| `status` | string | yes | `pending` \| `in_progress` \| `completed` |
|
|
213
|
+
| `elapsedMs` | integer | yes | accumulated completed in-progress time |
|
|
214
|
+
| `text` | string | opt | ≤120 chars, scrubbed; omitted when content is off |
|
|
215
|
+
| `textChars` | integer | opt | length of `text`, present **instead of** `text` when content is off |
|
|
216
|
+
|
|
217
|
+
**Snapshots replace, ids accumulate.** Each `todo` line is the full current list, so the
|
|
218
|
+
*last* line is the current state — but ids are unique per session (§3, I2), which means a
|
|
219
|
+
consumer SHOULD accumulate items by id instead of keeping only the last snapshot. Taking
|
|
220
|
+
only the last one loses the timing of items that no longer exist but that `tool` lines still
|
|
221
|
+
reference: after a `clear`, the item table would read "none" while slowest-calls still
|
|
222
|
+
cites `item 1`. The digest therefore merges snapshots and marks vanished items as dropped,
|
|
223
|
+
keeping their `elapsedMs` (§8, I8: absence is not zero).
|
|
224
|
+
|
|
225
|
+
`rev` MUST be non-decreasing. A consumer reading the last `todo` line gets the current list;
|
|
226
|
+
a consumer reconstructing item timing SHOULD process snapshots in order and treat
|
|
227
|
+
`elapsedMs` as authoritative (it is the producer's accumulated number, not a reconstruction).
|
|
228
|
+
|
|
229
|
+
### `user_bash`
|
|
230
|
+
|
|
231
|
+
A command run by the user outside the agent loop.
|
|
232
|
+
|
|
233
|
+
| Field | Type | Req | Notes |
|
|
234
|
+
|---|---|---|---|
|
|
235
|
+
| `chars` | integer | yes | always recorded |
|
|
236
|
+
| `command` | string | opt | ≤4000 chars, scrubbed; omitted when content is off |
|
|
237
|
+
|
|
238
|
+
### `provider`
|
|
239
|
+
|
|
240
|
+
Only written for HTTP status ≥ 400.
|
|
241
|
+
|
|
242
|
+
| Field | Type | Req | Notes |
|
|
243
|
+
|---|---|---|---|
|
|
244
|
+
| `status` | integer | yes | HTTP status |
|
|
245
|
+
| `requestId` | string | opt | provider request id, when exposed |
|
|
246
|
+
|
|
247
|
+
### `compact` / `compact_failed`
|
|
248
|
+
|
|
249
|
+
Both are written from pi's `session_compact` / `session_compact_failed` events, so the
|
|
250
|
+
fields below are exactly what pi reports. There is no "tokens after" count: pi records the
|
|
251
|
+
context size *before* compaction and rebuilds the context afterwards, and it does not hand
|
|
252
|
+
the post-compaction size back to extensions. Do not expect a symmetric pair.
|
|
253
|
+
|
|
254
|
+
| `t` | Field | Type | Req | Notes |
|
|
255
|
+
|---|---|---|---|---|
|
|
256
|
+
| `compact` | `reason` | string | opt | what triggered it: `manual`, `threshold` or `overflow` |
|
|
257
|
+
| `compact` | `before` | integer | opt | tokens in context before compaction (`CompactionEntry.tokensBefore`) |
|
|
258
|
+
| `compact` | `willRetry` | boolean | opt | the aborted turn is retried after this compaction (overflow recovery) |
|
|
259
|
+
| `compact_failed` | `reason` | string | opt | what triggered it |
|
|
260
|
+
| `compact_failed` | `error` | string | opt | pi's `errorMessage`; absent when it was aborted rather than broken |
|
|
261
|
+
| `compact_failed` | `aborted` | boolean | opt | cancelled or aborted — a no-op, not a failure |
|
|
262
|
+
| `compact_failed` | `willRetry` | boolean | opt | the aborted turn would have been retried |
|
|
263
|
+
|
|
264
|
+
A compaction that fails changes no task or tool row, so the digest reports it in
|
|
265
|
+
`## data quality` instead of leaving a clean-looking summary. The digest separates three
|
|
266
|
+
outcomes: `completed`, `failed`, and `skipped`. A `skipped` entry is an empty answer, not a
|
|
267
|
+
breakage — either the turn was aborted, or pi replied "Nothing to compact (session too small)"
|
|
268
|
+
because a manual `/compact` ran before the context reached the keep-recent threshold. That is
|
|
269
|
+
the normal answer to a premature `/compact`, it is not counted as a failure, and its reason
|
|
270
|
+
is kept so the reader can tell why nothing happened.
|
|
271
|
+
|
|
272
|
+
### `settle`
|
|
273
|
+
|
|
274
|
+
Closes one task. Written **only** when a user prompt opened a task (no prompt ⇒ no settle;
|
|
275
|
+
this is what keeps "duration 0 with the previous task's counters" from existing).
|
|
276
|
+
|
|
277
|
+
| Field | Type | Req | Notes |
|
|
278
|
+
|---|---|---|---|
|
|
279
|
+
| `taskMs` | integer | yes | `prompt`→`agent_settled` wall clock |
|
|
280
|
+
| `aborted` | boolean | yes | whether the turn was aborted |
|
|
281
|
+
| `turns` | integer | yes | turns in this task |
|
|
282
|
+
| `tools` | integer | yes | tool calls in this task |
|
|
283
|
+
| `tokens` | object | yes | normalized buckets, next table |
|
|
284
|
+
|
|
285
|
+
`tokens`:
|
|
286
|
+
|
|
287
|
+
| Field | Type | Req | Notes |
|
|
288
|
+
|---|---|---|---|
|
|
289
|
+
| `input` | integer | yes | prompt tokens |
|
|
290
|
+
| `output` | integer | yes | completion tokens |
|
|
291
|
+
| `cacheRead` | integer | yes | cache-hit tokens (0 when unreported) |
|
|
292
|
+
| `cacheWrite` | integer | yes | cache-write tokens (0 when unreported) |
|
|
293
|
+
| `total` | integer | yes | reported total **when positive**, otherwise `input+output+cacheRead+cacheWrite`; self-hosted endpoints that omit or send `0` are normalized here |
|
|
294
|
+
|
|
295
|
+
### `shutdown`
|
|
296
|
+
|
|
297
|
+
| Field | Type | Req | Notes |
|
|
298
|
+
|---|---|---|---|
|
|
299
|
+
| `reason` | string | opt | why the process ended |
|
|
300
|
+
| `turns` | integer | opt | counters of **that process** |
|
|
301
|
+
| `tools` | integer | opt | counters of that process |
|
|
302
|
+
| `tasks` | integer | opt | settled tasks seen by that process |
|
|
303
|
+
| `lastTaskMs` | integer | opt | last task duration seen by that process |
|
|
304
|
+
|
|
305
|
+
These are process-local counters and MUST NOT be used as session aggregates (§9).
|
|
306
|
+
|
|
307
|
+
## 5. Invariants
|
|
308
|
+
|
|
309
|
+
1. **I1 — task continues.** `task` is non-decreasing per file and continues from the
|
|
310
|
+
maximum already present. A resumed process MUST replay the existing log before assigning
|
|
311
|
+
the next task index.
|
|
312
|
+
2. **I2 — item ids unique per session.** Never reused, including after `clear`.
|
|
313
|
+
3. **I3 — attribution frozen.** `tool` `end` carries the `task`/`item` of its `start`.
|
|
314
|
+
4. **I4 — one start, one end per call id**, in that order; a `start` may have no `end`.
|
|
315
|
+
5. **I5 — todo only on change**, `rev` non-decreasing.
|
|
316
|
+
6. **I6 — single writer.** One process appends to a file at a time.
|
|
317
|
+
7. **I7 — digest is a pure projection.** `parse → aggregate → buildDigest`, no process
|
|
318
|
+
memory, no retention cap, deterministic bytes.
|
|
319
|
+
8. **I8 — absence is not zero.** A missing field means "not recorded"; `0` means measured
|
|
320
|
+
zero. Consumers MUST NOT conflate them.
|
|
321
|
+
|
|
322
|
+
## 6. Nullability and absence
|
|
323
|
+
|
|
324
|
+
- Optional fields are **omitted** when unrecorded; the producer does not emit `null`.
|
|
325
|
+
- Numbers are integers in milliseconds, tokens or bytes; they are never floats, never
|
|
326
|
+
strings. A consumer MUST tolerate an unexpected `null` defensively (and treat it as
|
|
327
|
+
"not recorded"), but a producer MUST NOT send one.
|
|
328
|
+
- Booleans are JSON booleans (`true` / `false`), not `0` / `1`.
|
|
329
|
+
- `item` absent means "no item was in progress". `item: 0` is not a valid value.
|
|
330
|
+
|
|
331
|
+
## 7. Privacy channels
|
|
332
|
+
|
|
333
|
+
Collection is a policy with an owner per channel. A metadata-only log contains no free text.
|
|
334
|
+
|
|
335
|
+
| Channel | Default | `PI_WORKFEED_CONTENT=0` | Owner |
|
|
336
|
+
|---|---|---|---|
|
|
337
|
+
| `t`, `ts`, `sid`, `task`, `item` | kept | kept | fixed |
|
|
338
|
+
| tool `name`, `durMs`, `wallMs`, `isError`, `exitCode`, `outBytes` | kept | kept | fixed |
|
|
339
|
+
| `usage` / `tokens` / `turn` counters | kept | kept | fixed |
|
|
340
|
+
| `todo` `id`, `status`, `elapsedMs`, `rev` | kept | kept | fixed |
|
|
341
|
+
| `tool` `args` for built-in tools (`command`, `pattern`, `path`) | kept, clipped 2000, scrubbed | omitted (`args` = shape) | `PI_WORKFEED_ARGS` |
|
|
342
|
+
| `tool` `args` for unknown tools (MCP, other extensions) | JSON, clipped 1200, **every string scrubbed** | omitted (`args` = shape) | `PI_WORKFEED_ARGS` |
|
|
343
|
+
| `prompt` `text` | kept ≤3000, scrubbed | omitted (`chars` only) | `PI_WORKFEED_CONTENT` |
|
|
344
|
+
| `tool` `out` | kept ≤`PI_WORKFEED_EXCERPT`, scrubbed | omitted (`outBytes` only) | `PI_WORKFEED_CONTENT` / `PI_WORKFEED_EXCERPT` |
|
|
345
|
+
| `write` / `edit` body | never — byte counts only | never | fixed |
|
|
346
|
+
| `cwd`, `sessionFile`, `args.path` | full | last path segment, `<…>/name` | `PI_WORKFEED_CONTENT` |
|
|
347
|
+
| `todo` `items[].text` | kept ≤120, scrubbed | omitted (`textChars` only) | `PI_WORKFEED_CONTENT` |
|
|
348
|
+
| `user_bash` `command` | kept ≤4000, scrubbed | omitted (`chars` only) | `PI_WORKFEED_CONTENT` |
|
|
349
|
+
|
|
350
|
+
`PI_WORKFEED_ARGS` ∈ {`full`, `redacted`, `shape`, `off`}; default `shape` when
|
|
351
|
+
`PI_WORKFEED_CONTENT=0`, else `redacted`. `shape` records `{keys, stringBytes}` — which
|
|
352
|
+
arguments existed and how large, never values. `off` omits `args` entirely.
|
|
353
|
+
|
|
354
|
+
Argument values are scrubbed in **every** mode, including `full` and the fallback branch for
|
|
355
|
+
unrecognized tools. Recognized shapes: `--token …`, `Authorization:` / `Bearer`,
|
|
356
|
+
`API_KEY=` / `PASSWORD=` / `DATABASE_URL=` style assignments, `sk-…` / `ghp_…` / `AKIA…`,
|
|
357
|
+
JWTs, inline PEM private keys, `curl -u u:p`, `scheme://user:password@host`.
|
|
358
|
+
|
|
359
|
+
**Best effort, not a guarantee.** A secret shaped like an ordinary word survives. Do not
|
|
360
|
+
treat a log as credential-free because it went through the scrubber.
|
|
361
|
+
|
|
362
|
+
Files `0600`, directories `0700` (POSIX; Windows honour them partially). Even metadata tells
|
|
363
|
+
which tools ran on which files for how long.
|
|
364
|
+
|
|
365
|
+
## 8. Measurement definitions
|
|
366
|
+
|
|
367
|
+
Definitions are normative: a consumer computing a different number MUST name it differently.
|
|
368
|
+
|
|
369
|
+
| Measurement | Definition | Source |
|
|
370
|
+
|---|---|---|
|
|
371
|
+
| **Task duration** | wall clock, user prompt → `agent_settled`; includes model latency, tool time and queueing | `settle.taskMs` |
|
|
372
|
+
| **Turn duration** | `turn_start` → `turn_end`: one model request plus its tool execution | `turn.end.durMs` |
|
|
373
|
+
| **Tool duration** | monotonic `execute()` duration reported by pi; the number to trust for "this command was slow" | `tool.end.durMs` |
|
|
374
|
+
| **Tool wall time** | `start`→`end` including scheduling and streaming; an upper bound only | `tool.end.wallMs` |
|
|
375
|
+
| **Item duration** | accumulated `in_progress` time; counts model and tool time alike; cannot separate agent work from a human leaving the terminal | `todo.items[].elapsedMs` |
|
|
376
|
+
| **Tokens** | normalized bucket from `usage`; `total` falls back to the sum of parts when the provider omits it or sends `0` | `settle.tokens` |
|
|
377
|
+
| **Digest wall clock** | sum of `settle.taskMs`, so concurrent/serialised tasks are not double-counted as one span | digest `## tasks` header |
|
|
378
|
+
| **Cost** | **not recorded.** A self-hosted OpenAI-compatible endpoint reports `cost: 0`, and a wrong number is worse than no number. Price tokens yourself. | — |
|
|
379
|
+
|
|
380
|
+
## 9. Digest contract
|
|
381
|
+
|
|
382
|
+
The digest is a projection of the log: `parse → aggregate → buildDigest`
|
|
383
|
+
(`extensions/journal/replay.ts`, no pi API, no I/O beyond the read).
|
|
384
|
+
|
|
385
|
+
- **No dependence on the collector.** Every line on disk is rendered, not just the part the
|
|
386
|
+
current process witnessed.
|
|
387
|
+
- **No retention cap on the counters, caps on the rendered lists.** 250 tasks and 2 100 calls
|
|
388
|
+
are counted exactly; what the digest *shows* is capped — `## tools` lists the eight names
|
|
389
|
+
with the highest total, `slowest calls` the top five by `durMs`, `last failures` the last
|
|
390
|
+
five failing calls. A row missing from a list means "outside the cap", never "absent from
|
|
391
|
+
the log"; a consumer that needs completeness MUST read the JSONL.
|
|
392
|
+
- **Deterministic.** Header timestamp is the last event's `ts`, so the same file yields
|
|
393
|
+
byte-identical bytes; digests can be diffed or checksummed.
|
|
394
|
+
- **Deletable.** `rebuildDigest(path)` restores it offline, with no pi process involved.
|
|
395
|
+
- **States its own coverage.** `## data quality` reports finished calls, `start` lines with
|
|
396
|
+
no matching `end`, item-attribution ratio, tasks with a non-zero token total, and a
|
|
397
|
+
**log integrity** line: lines read, lines dropped (unparsable / envelope violations with
|
|
398
|
+
the line number), a torn tail when there was one, and unknown event types. A low
|
|
399
|
+
attribution ratio or a damaged file is a fact about the data, not something to hide.
|
|
400
|
+
- **Section sources.** `settle` → task table; `tool` `phase:"end"` → tool rollup and
|
|
401
|
+
slowest/last-failure lists; the last `todo` → item table; `session` / `prompt` → model,
|
|
402
|
+
provider, cwd. Counters inside `shutdown` lines are **not** digest sources.
|
|
403
|
+
- The digest is Markdown for a model to read, not a data format. Consumers wanting numbers
|
|
404
|
+
MUST read the JSONL; the digest may be stale by one task.
|
|
405
|
+
|
|
406
|
+
## 10. Versioning and compatibility
|
|
407
|
+
|
|
408
|
+
- `v` is the **wire** version. It changes only for a breaking change: removing or renaming a
|
|
409
|
+
field, changing a field's type or meaning, changing an invariant's guarantee.
|
|
410
|
+
- **Additive** fields do not bump `v`: consumers tolerate unknown keys.
|
|
411
|
+
- A producer MUST NOT reuse a field name for a different meaning within `v = 1`.
|
|
412
|
+
- Consumers MUST reject unknown `v` values (§2) rather than best-effort parse them.
|
|
413
|
+
- The wire version is only **one of three independent axes**. It does not follow the npm
|
|
414
|
+
package version, and neither follows a git tag: see `docs/versioning.md` for how the three
|
|
415
|
+
relate, when each moves, and the release checklist that keeps them from drifting apart.
|
|
416
|
+
|
|
417
|
+
## 11. Consumer checklist
|
|
418
|
+
|
|
419
|
+
If you build a parser or an analyzer, verify these in this order — each one is a real
|
|
420
|
+
failure mode, not a hypothetical:
|
|
421
|
+
|
|
422
|
+
1. Skip the torn last line; do not abort the file.
|
|
423
|
+
2. **Report any other unparsable line by number**, and say your aggregates cover only the
|
|
424
|
+
readable part. Distinguish unparsable, envelope-violating and unknown-type lines —
|
|
425
|
+
three different failures, three different responses.
|
|
426
|
+
3. Reject lines with unknown `v`; label unknown `t`; ignore unknown keys.
|
|
427
|
+
4. Use each line's own `task`/`item`; never reconstruct attribution from timestamps.
|
|
428
|
+
5. Treat a missing field as "not recorded"; do not substitute `0`.
|
|
429
|
+
6. Count `start` lines without `end` and report them; do not average them into tool time.
|
|
430
|
+
7. Use `durMs` for tool latency; `wallMs` only as an upper bound.
|
|
431
|
+
8. Confirm `task` is non-decreasing; a duplicate `task` after a `prompt` means the producer
|
|
432
|
+
lost its counter — report it.
|
|
433
|
+
9. Confirm `item` ids are unique; a reused id means two lists were conflated — report it.
|
|
434
|
+
10. Use `settle.tokens.total` as-is (already normalized); do not re-derive a "better" total.
|
|
435
|
+
11. Never use `shutdown` counters as session totals.
|
|
436
|
+
12. Never compare `task`/`item` values across sessions; see the scope table in §3.
|
|
437
|
+
|
|
438
|
+
## 12. Known gaps
|
|
439
|
+
|
|
440
|
+
- **No `end` line ⇒ not in the tool table.** A crashed or killed call has a `start` and
|
|
441
|
+
nothing else. The digest reports the count in `## data quality`; a consumer doing its own
|
|
442
|
+
analysis must count `phase:"start"` versus `phase:"end"`.
|
|
443
|
+
- **Filename vs directory.** A session that spans midnight lives in the day it *started*;
|
|
444
|
+
tools that only glob today's directory will miss it.
|
|
445
|
+
- **No schema-level validation in the producer.** Fields are written by hand in TypeScript;
|
|
446
|
+
`schemas/workfeed-event-v1.schema.json` is normative for consumers, and the test suite
|
|
447
|
+
validates shipped fixtures against it, but a producer-side regression is caught by tests
|
|
448
|
+
only.
|
|
449
|
+
- **`usage` is passthrough.** Its keys are provider-specific; only `settle.tokens` is normalized.
|
|
450
|
+
- **No cross-session identity.** `task`/`item` are counters, not business ids (§3). Cross-session
|
|
451
|
+
analysis is limited to dimensions until a future version adds explicit ids.
|
|
452
|
+
- **Integrity is reported, not repaired.** A damaged line is named in the digest and
|
|
453
|
+
`hasDamage(integrity)` returns true for a caller (`replayLog`); nothing rewrites the log.
|
|
454
|
+
Repairing truth is out of scope on purpose.
|
|
@@ -0,0 +1,141 @@
|
|
|
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
|
+
## Clean install from the published artifact
|
|
57
|
+
|
|
58
|
+
Installing from the checkout proves nothing about the artifact: the checkout has `test/`, the
|
|
59
|
+
git history and a symlink the package does not. The check below therefore installs the tarball
|
|
60
|
+
itself into a throwaway home.
|
|
61
|
+
|
|
62
|
+
1. `npm pack` → `pi-workfeed-<version>.tgz` (the file that would be published).
|
|
63
|
+
2. Extract it — the tree contains only `CHANGELOG.md`, `LICENSE`, `README.md`, `docs/`,
|
|
64
|
+
`extensions/`, `package.json`, `schemas/`, `skills/`.
|
|
65
|
+
3. `pi install <extracted dir>` with `USERPROFILE`/`HOME` pointing at an empty directory, so
|
|
66
|
+
the real `~/.pi/agent` is not involved. `pi list` then shows the package.
|
|
67
|
+
4. Start a session there and read the log directory of that throwaway home.
|
|
68
|
+
|
|
69
|
+
Observed at 0.4.6: the package installed, and the journal extension **ran** — a
|
|
70
|
+
`workfeed-*.jsonl` appeared under `<throwaway home>/.pi/agent/logs/2026-11-10/` with
|
|
71
|
+
|
|
72
|
+
```
|
|
73
|
+
{"v":1,"ts":…,"sid":"…","task":0,"t":"session","reason":"startup","cwd":"…\\wf-cleanprobe\\home", …}
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
which is the extension's own session handler writing into a home that contains nothing else.
|
|
77
|
+
`skills/workfeed-analysis/SKILL.md` is present in the extracted tree with valid front matter
|
|
78
|
+
(`name: workfeed-analysis`, a description). The `SKILL.md` rules pi documents — front matter,
|
|
79
|
+
a non-empty description, name matching the directory — are asserted by
|
|
80
|
+
`test/package.test.mjs`, so a skill pi would silently skip fails CI instead.
|
|
81
|
+
|
|
82
|
+
Not observable headlessly: that pi lists the skill in the model's system prompt. pi has no
|
|
83
|
+
command that prints the prompt, and forcing it through a model call would prove the model's
|
|
84
|
+
sentence, not pi's loader. The static checks above are what can be verified without inventing
|
|
85
|
+
evidence; if you want the end-to-end confirmation, run `pi` and check that
|
|
86
|
+
`/skill:workfeed-analysis` is offered.
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
## The two defects a real run found
|
|
90
|
+
|
|
91
|
+
1. **`compact_failed` lost its reason.** The handler read `event.error`; pi calls it
|
|
92
|
+
`errorMessage`. Every real failure logged a row with no explanation at all.
|
|
93
|
+
2. **`compact` lost its counts.** The handler read `messagesBefore` / `messagesAfter`; pi
|
|
94
|
+
reports a `CompactionEntry` whose `tokensBefore` is the only count it exposes, and the
|
|
95
|
+
digest had no line for compaction either way.
|
|
96
|
+
|
|
97
|
+
Both are now fixed and covered by `test/compaction.test.mjs`, which uses pi's documented
|
|
98
|
+
field names rather than a shape invented for the test.
|
|
99
|
+
|
|
100
|
+
## Coverage, stated honestly
|
|
101
|
+
|
|
102
|
+
`item attribution` in the digest is a measurement, not a promise. A model that issues its
|
|
103
|
+
`workfeed_todo` call in the same turn as other tool calls makes those calls *start* before
|
|
104
|
+
the new snapshot arrives, so they carry no `item` — a real run showed `2/4` and `4/7`.
|
|
105
|
+
If you want every call of a task attributed, write the list first and alone.
|
|
106
|
+
The digest states the real ratio instead of rounding it.
|
|
107
|
+
|
|
108
|
+
## Platforms
|
|
109
|
+
|
|
110
|
+
| Platform | Status |
|
|
111
|
+
|---|---|
|
|
112
|
+
| Windows 11 · pi 1.5.0 · Node 22 | verified with the flow above |
|
|
113
|
+
| 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 |
|
|
114
|
+
| 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 |
|
|
115
|
+
|
|
116
|
+
Linux and macOS run the same Node code path; the only platform-specific parts are the file
|
|
117
|
+
mode bits (best effort on Windows) and the host's shell. A problem on either should be
|
|
118
|
+
reported rather than assumed to be a local mistake.
|
|
119
|
+
|
|
120
|
+
## Known rough edges
|
|
121
|
+
|
|
122
|
+
- **A premature `/compact` is an empty answer, not a failure.** On a session below pi's
|
|
123
|
+
keep-recent threshold, `/compact` replies "Nothing to compact (session too small)". The
|
|
124
|
+
digest reports that as `skipped`, with pi's reason attached, so the first digest a new
|
|
125
|
+
user reads does not say "1 failed" about an operation that had nothing to do.
|
|
126
|
+
- **A non-built-in model** needs an entry in `~/.pi/agent/models.json`; without pricing
|
|
127
|
+
there, the host reports zero cost and workfeed passes through what the host reports. That
|
|
128
|
+
is host configuration, not a workfeed setting.
|
|
129
|
+
- **Project-level `.pi/settings.json` versus `--approve`** is a host trust question. One
|
|
130
|
+
Linux run changed both at once and could not attribute the difference — change one
|
|
131
|
+
variable at a time if a project-level setting looks ignored.
|
|
132
|
+
|
|
133
|
+
## Reproducing
|
|
134
|
+
|
|
135
|
+
```bash
|
|
136
|
+
pi install /path/to/pi-workfeed # or npm:pi-workfeed once published
|
|
137
|
+
pi --mode rpc --session-dir /tmp/s --provider <you> --model <yours> --approve
|
|
138
|
+
# send {"type":"prompt","message":"…"} and {"type":"compact"} on stdin,
|
|
139
|
+
# read {"type":"agent_settled"} to know when a task is done
|
|
140
|
+
node --experimental-strip-types test/run.mjs
|
|
141
|
+
```
|