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/package.json CHANGED
@@ -1,6 +1,56 @@
1
1
  {
2
2
  "name": "pi-workfeed",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.1",
4
+ "description": "Structured event journal for Pi agent workflows, with task timing, replay, and evidence-based analysis",
5
+ "keywords": [
6
+ "pi-package",
7
+ "pi",
8
+ "agent",
9
+ "coding-agent",
10
+ "jsonl",
11
+ "workflow",
12
+ "telemetry",
13
+ "observability"
14
+ ],
15
+ "license": "MIT",
16
+ "author": "Wren-Xin",
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+https://github.com/Wren-Xin/pi-workfeed.git"
20
+ },
21
+ "homepage": "https://github.com/Wren-Xin/pi-workfeed",
22
+ "bugs": {
23
+ "url": "https://github.com/Wren-Xin/pi-workfeed/issues"
24
+ },
25
+ "type": "module",
26
+ "files": [
27
+ "extensions",
28
+ "skills",
29
+ "docs",
30
+ "schemas",
31
+ "README.md",
32
+ "CHANGELOG.md",
33
+ "LICENSE"
34
+ ],
35
+ "scripts": {
36
+ "test": "node --experimental-strip-types test/run.mjs"
37
+ },
38
+ "peerDependencies": {
39
+ "@earendil-works/pi-ai": "*",
40
+ "@earendil-works/pi-coding-agent": "*",
41
+ "@earendil-works/pi-tui": "*",
42
+ "typebox": "*"
43
+ },
44
+ "engines": {
45
+ "node": ">=22.19.0"
46
+ },
47
+ "pi": {
48
+ "extensions": [
49
+ "./extensions/todo/index.ts",
50
+ "./extensions/journal/index.ts"
51
+ ],
52
+ "skills": [
53
+ "./skills"
54
+ ]
55
+ }
56
+ }
@@ -0,0 +1,176 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "$id": "https://github.com/Wren-Xin/pi-workfeed/schemas/workfeed-event-v1.schema.json",
4
+ "title": "pi-workfeed event line (schemaVersion 1)",
5
+ "description": "One JSON object per line of workfeed-<sid>.jsonl. Normative companion of docs/schema.md. Consumers must tolerate unknown properties and treat absent properties as 'not recorded'. Field names and required flags here are checked against the prose tables in docs/schema.md by test/schema-docs.test.mjs.",
6
+ "type": "object",
7
+ "required": ["v", "ts", "sid", "task", "t"],
8
+ "properties": {
9
+ "v": { "const": 1, "description": "wire schema version" },
10
+ "ts": { "type": "integer", "minimum": 0, "description": "epoch milliseconds; non-decreasing within a file" },
11
+ "sid": { "type": "string", "minLength": 1, "description": "session id, constant within a file" },
12
+ "task": { "type": "integer", "minimum": 0, "description": "1-based user-instruction index; 0 before the first prompt; non-decreasing" },
13
+ "item": { "type": "integer", "minimum": 1, "description": "work item id that was in_progress (source-neutral: todo list, planner or external list); absent when none" },
14
+ "t": { "type": "string", "description": "event type" }
15
+ },
16
+ "additionalProperties": true,
17
+ "oneOf": [
18
+ {
19
+ "properties": {
20
+ "t": { "const": "session" },
21
+ "reason": { "type": "string" },
22
+ "cwd": { "type": "string" },
23
+ "sessionFile": { "type": "string" },
24
+ "model": { "type": "string" },
25
+ "provider": { "type": "string" },
26
+ "pid": { "type": "integer", "minimum": 1 }
27
+ },
28
+ "required": ["t"]
29
+ },
30
+ {
31
+ "properties": {
32
+ "t": { "const": "prompt" },
33
+ "chars": { "type": "integer", "minimum": 0 },
34
+ "text": { "type": "string", "maxLength": 3000 },
35
+ "model": { "type": "string" },
36
+ "thinking": { "type": "string" }
37
+ },
38
+ "required": ["t", "chars"]
39
+ },
40
+ { "properties": { "t": { "const": "agent_start" } }, "required": ["t"] },
41
+ {
42
+ "properties": {
43
+ "t": { "const": "turn" },
44
+ "phase": { "enum": ["start", "end"] },
45
+ "turn": { "type": "integer", "minimum": 0, "description": "0-based turn index within the task; pi numbers the first turn 0" },
46
+ "durMs": { "type": "integer", "minimum": 0 },
47
+ "outcome": { "type": "string" },
48
+ "stopReason": { "type": "string" },
49
+ "tools": { "type": "integer", "minimum": 0 },
50
+ "usage": { "type": "object" },
51
+ "model": { "type": "string" }
52
+ },
53
+ "required": ["t", "phase", "turn"],
54
+ "allOf": [
55
+ {
56
+ "if": { "properties": { "phase": { "const": "end" } }, "required": ["phase"] },
57
+ "then": { "required": ["turn"] }
58
+ }
59
+ ]
60
+ },
61
+ {
62
+ "properties": {
63
+ "t": { "const": "tool" },
64
+ "phase": { "enum": ["start", "end"] },
65
+ "id": { "type": "string" },
66
+ "name": { "type": "string" },
67
+ "parent": { "type": "string" },
68
+ "args": { "type": "object" },
69
+ "durMs": { "type": "integer", "minimum": 0 },
70
+ "wallMs": { "type": "integer", "minimum": 0 },
71
+ "isError": { "type": "boolean" },
72
+ "exitCode": { "type": "integer" },
73
+ "truncated": { "type": "boolean" },
74
+ "outBytes": { "type": "integer", "minimum": 0 },
75
+ "out": { "type": "string" }
76
+ },
77
+ "required": ["t", "phase", "id", "name"],
78
+ "allOf": [
79
+ {
80
+ "if": { "properties": { "phase": { "const": "end" } }, "required": ["phase"] },
81
+ "then": { "required": ["isError"] }
82
+ }
83
+ ]
84
+ },
85
+ {
86
+ "properties": {
87
+ "t": { "const": "todo" },
88
+ "rev": { "type": "integer", "minimum": 1 },
89
+ "items": {
90
+ "type": "array",
91
+ "items": {
92
+ "type": "object",
93
+ "required": ["id", "status", "elapsedMs"],
94
+ "properties": {
95
+ "id": { "type": "integer", "minimum": 1 },
96
+ "status": { "enum": ["pending", "in_progress", "completed"] },
97
+ "elapsedMs": { "type": "integer", "minimum": 0 },
98
+ "text": { "type": "string", "maxLength": 120 },
99
+ "textChars": { "type": "integer", "minimum": 0 }
100
+ },
101
+ "additionalProperties": true
102
+ }
103
+ }
104
+ },
105
+ "required": ["t", "items"]
106
+ },
107
+ {
108
+ "properties": {
109
+ "t": { "const": "user_bash" },
110
+ "chars": { "type": "integer", "minimum": 0 },
111
+ "command": { "type": "string", "maxLength": 4000 }
112
+ },
113
+ "required": ["t", "chars"]
114
+ },
115
+ {
116
+ "properties": {
117
+ "t": { "const": "provider" },
118
+ "status": { "type": "integer", "minimum": 400, "maximum": 599 },
119
+ "requestId": { "type": "string" }
120
+ },
121
+ "required": ["t", "status"]
122
+ },
123
+ {
124
+ "properties": {
125
+ "t": { "const": "compact" },
126
+ "reason": { "type": "string" },
127
+ "before": { "type": "integer", "minimum": 0 },
128
+ "willRetry": { "type": "boolean" }
129
+ },
130
+ "required": ["t"]
131
+ },
132
+ {
133
+ "properties": {
134
+ "t": { "const": "compact_failed" },
135
+ "reason": { "type": "string" },
136
+ "error": { "type": "string" },
137
+ "aborted": { "type": "boolean" },
138
+ "willRetry": { "type": "boolean" }
139
+ },
140
+ "required": ["t"]
141
+ },
142
+ {
143
+ "properties": {
144
+ "t": { "const": "settle" },
145
+ "taskMs": { "type": "integer", "minimum": 0 },
146
+ "aborted": { "type": "boolean" },
147
+ "turns": { "type": "integer", "minimum": 0 },
148
+ "tools": { "type": "integer", "minimum": 0 },
149
+ "tokens": {
150
+ "type": "object",
151
+ "required": ["input", "output", "cacheRead", "cacheWrite", "total"],
152
+ "properties": {
153
+ "input": { "type": "integer", "minimum": 0 },
154
+ "output": { "type": "integer", "minimum": 0 },
155
+ "cacheRead": { "type": "integer", "minimum": 0 },
156
+ "cacheWrite": { "type": "integer", "minimum": 0 },
157
+ "total": { "type": "integer", "minimum": 0 }
158
+ },
159
+ "additionalProperties": true
160
+ }
161
+ },
162
+ "required": ["t", "taskMs", "aborted", "turns", "tools", "tokens"]
163
+ },
164
+ {
165
+ "properties": {
166
+ "t": { "const": "shutdown" },
167
+ "reason": { "type": "string" },
168
+ "turns": { "type": "integer", "minimum": 0 },
169
+ "tools": { "type": "integer", "minimum": 0 },
170
+ "tasks": { "type": "integer", "minimum": 0 },
171
+ "lastTaskMs": { "type": "integer", "minimum": 0 }
172
+ },
173
+ "required": ["t"]
174
+ }
175
+ ]
176
+ }
@@ -0,0 +1,142 @@
1
+ ---
2
+ name: workfeed-analysis
3
+ description: Read pi-workfeed output and explain where a session's time, tokens and failures went. Use when the user asks why a run was slow, where the time went, which tool calls failed or repeated, how long todo items took, or asks for workflow tuning advice based on session logs.
4
+ ---
5
+
6
+ # workfeed-analysis
7
+
8
+ `pi-workfeed` records a session as two files. Read them in this order and never the other
9
+ way round.
10
+
11
+ ## Where the files are
12
+
13
+ ```text
14
+ ${PI_WORKFEED_DIR:-~/.pi/agent/logs}/<YYYY-MM-DD>/
15
+ ├── workfeed-<sid>.digest.md start here
16
+ └── workfeed-<sid>.jsonl drill down here, filtered
17
+ ```
18
+
19
+ `/workfeed` prints both paths for the current session. The digest is derived data: it may
20
+ be stale by one task, and it may be regenerated at any time from the JSONL — `/workfeed-digest`
21
+ rebuilds it in place, and `rebuildDigest(path)` (in `../../extensions/journal/replay.ts`,
22
+ relative to this skill's own directory) rebuilds it offline, after a restart, or for a session
23
+ no process is watching. When a number matters, confirm it in the JSONL.
24
+
25
+ Paths in this skill are relative to the skill directory, not to the session's working
26
+ directory: the package root is two levels up. Read `../../docs/schema.md` before interpreting
27
+ fields, and resolve any other package path the same way — do not look for these files under
28
+ the user's project.
29
+
30
+ ## Read `## data quality` first — it decides how strong your claims may be
31
+
32
+ The digest opens with a `## data quality` section. It is not boilerplate: it states what the
33
+ recording *failed to capture*, and every conclusion downstream inherits those limits. Read
34
+ it before the tables, then carry its numbers into your wording.
35
+
36
+ | Line | How it constrains what you may say |
37
+ |---|---|
38
+ | `item attribution: N/M calls carry an item (P%)` | This is the share of tool time you can attribute to work items. Above ~80%, per-item claims are safe. Below ~50%, say "the log attributes only P% of calls to items, so per-item shares are indicative, not exact" — and do not rank items against each other as if the numbers were complete. |
39
+ | `task coverage: K/N prompts have a settle` | Prompts without a settle were killed, crashed, or are still running. Their duration and tokens are **unknown, not zero**. Never sum tasks to a session total when `K < N`; say the total covers only the settled ones. |
40
+ | `tool calls: N finished, U started without an end line` | `U` calls were cut off. Their time is missing from every tool total. When a tool looks cheap but has cut-off calls, say the evidence is partial. |
41
+ | `token totals: K/N tasks report a non-zero total` | Some endpoints report no totals. When `K < N`, report input/output separately and do not present a summed total as complete. |
42
+ | `log integrity: N lines, D dropped, X of unknown type` | The digest was built on a log with damage. See below. |
43
+
44
+ If a section you need is shaped by a missing line (e.g. no `task coverage` line because the
45
+ log predates it), say what you cannot separate instead of implying a clean number.
46
+
47
+ ### When the log is damaged
48
+
49
+ `log integrity` is present on every digest. If it reports `D > 0` dropped lines, or lists
50
+ `corrupt lines` / `rejected line N: reason`, then:
51
+
52
+ 1. **Report the damage before the analysis**, in one sentence: how many lines were dropped,
53
+ where (line numbers), and what that means for ordering near them.
54
+ 2. Then analyse, and mark the affected claims: "tool totals exclude the dropped lines, so the
55
+ figures are a lower bound".
56
+ 3. Never present an ordering-based conclusion (first failure, last call, retry sequence)
57
+ around a dropped line without saying it is approximate.
58
+
59
+ Unknown event types (`X of unknown type`) are forward-compatibility, not damage: they are
60
+ kept and marked, they do not enter the aggregates, and you may ignore them unless a
61
+ conclusion depends on them.
62
+
63
+ If the digest's integrity line reports dropped lines, or you rebuilt from a log where
64
+ `hasDamage(integrity)` is true, the first line of your answer is the damage statement — not
65
+ the headline number. A tidy conclusion over a damaged log is worse than a hedged one.
66
+
67
+ ### Denominator discipline
68
+
69
+ Every percentage in the digest names its own denominator (`2/3`, `67%`). Quote both. Do not
70
+ recompute a percentage from a different population — a "70% of time in bash" computed from a
71
+ partial `item attribution` share is a new number with a new, unstated denominator.
72
+
73
+ ## Procedure
74
+
75
+ 1. **Read `## data quality`, then the digest.** Quality decides the strength of every claim
76
+ (see above). The digest already holds the task table, tool rollup, slowest calls, last
77
+ failures and per-item todo timing with shares. Most questions are answered here.
78
+ Items marked `dropped` were removed from the list by `clear`; their timing is still
79
+ evidence of work that happened, so include them when accounting for time.
80
+ 2. **Form a hypothesis with a number attached.** "bash accounts for 70% of tool time",
81
+ "item #3 took 40% of the run", "the last three failures share exit code 2".
82
+ 3. **Drill down only to test it.** Filter the JSONL, never page through it:
83
+
84
+ ```bash
85
+ grep '"t":"tool"' workfeed-*.jsonl | grep '"phase":"end"' | grep '"isError":true'
86
+ grep '"t":"tool"' workfeed-*.jsonl | grep '"name":"bash"' | grep '"durMs"'
87
+ grep '"t":"todo"' workfeed-*.jsonl | tail -3
88
+ ```
89
+
90
+ To attribute work, filter by `task` (user instruction) or `item` (work item id — opaque,
91
+ usually a todo id, but any provider may supply it).
92
+ 4. **Report evidence, then advice.** Every claim names its source: `digest`, or the event
93
+ type and count you filtered. Do not average, extrapolate or round-trip numbers the log
94
+ does not contain. Where a quality line capped the evidence, name that cap in the same
95
+ sentence as the claim.
96
+
97
+ ## Measurement definitions (do not improvise)
98
+
99
+ | Number | Source | Means |
100
+ |---|---|---|
101
+ | task time | `settle.taskMs` | prompt → `agent_settled` wall clock |
102
+ | turn time | `turn.end.durMs` | one model request + its tool execution |
103
+ | tool time | `tool.end.durMs` | monotonic `execute()` duration — **the only trustworthy "this was slow" number** |
104
+ | tool wall time | `tool.end.wallMs` | call → end, includes scheduling; upper bound only |
105
+ | item time | `todo.items[].elapsedMs` | accumulated `in_progress` time; mixes agent and human time |
106
+ | tokens | `turn.end.usage` | provider-reported usage |
107
+ | cost | — | **not recorded**; self-hosted endpoints report 0. Price tokens yourself or say "cost unknown" |
108
+
109
+ If the session has no `settle` event yet (still running), say so instead of reporting a
110
+ partial task as complete. If `task coverage` shows prompts without a settle, that is the
111
+ same rule applied to individual tasks: their absence from the task table means *unknown*,
112
+ never *zero*, and their tool calls still appear in the rollup — which is why the totals can
113
+ exceed the sum of listed tasks. Explain that gap rather than smoothing it away.
114
+
115
+ ## Patterns worth naming
116
+
117
+ Look for these before recommending anything generic:
118
+
119
+ - **One tool dominates** — check whether it is one slow command or many fast ones
120
+ (rollup `calls` vs `avg`). Both look identical in total time.
121
+ - **Retry storms** — same `name` + same `exitCode` + same `item`, clustered in time. The fix
122
+ is usually the command, not the model.
123
+ - **Long tool, no artifact** — `durMs` large, but no later `write`/`edit` in the same `item`,
124
+ and the next `read` touches the same path. Often a wasted exploration pass.
125
+ - **Item stall** — an item whose `elapsedMs` share is high but whose status never became
126
+ `completed` before the next `write` demoted it.
127
+ - **Turn inflation** — high `turns` with low `tools` per turn: the model is thinking in
128
+ circles, or a `prompt` was too vague.
129
+ - **Compaction pressure** — many `compact` events in one task means the task is carrying
130
+ more context than the window; suggest splitting it.
131
+
132
+ ## Output shape
133
+
134
+ 1. One or two sentences of answer, with the headline number.
135
+ 2. Evidence bullets: `digest` table or filtered event counts, each carrying the quality
136
+ caveat that applies (attribution share, unsettled tasks, dropped lines).
137
+ 3. Advice as 2–3 concrete, falsifiable changes ("fold the three `read` calls on
138
+ `src/pipeline.py` into one"), not principles.
139
+ 4. State what the log does **not** tell you (cost, human idle time, model-side latency).
140
+
141
+ Never publish a conclusion that needs data absent from the log without labelling it as a
142
+ guess.