@nredd/pi-session-kit 0.0.0-stage → 0.3.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/LICENSE +18 -0
- package/README.md +167 -2
- package/dist/pi-stats-export.mjs +657 -0
- package/docs/stats-snapshots.md +122 -0
- package/package.json +45 -4
- package/src/child.ts +79 -0
- package/src/config.ts +64 -0
- package/src/diff/component.ts +214 -0
- package/src/diff/git.ts +289 -0
- package/src/diff/index.ts +65 -0
- package/src/diff/parse.ts +180 -0
- package/src/diff/view.ts +98 -0
- package/src/goal/index.ts +343 -0
- package/src/goal/state.ts +270 -0
- package/src/goal/subagents.ts +77 -0
- package/src/index.ts +31 -0
- package/src/loop/index.ts +151 -0
- package/src/loop/state.ts +107 -0
- package/src/monitor/README.md +12 -0
- package/src/monitor/coalescer.ts +75 -0
- package/src/monitor/index.ts +213 -0
- package/src/monitor/manager.ts +322 -0
- package/src/monitor/matcher.ts +113 -0
- package/src/monitor/messages.ts +93 -0
- package/src/monitor/output.ts +41 -0
- package/src/monitor/pidfiles.ts +410 -0
- package/src/monitor/process.ts +124 -0
- package/src/monitor/ring.ts +52 -0
- package/src/monitor/splitter.ts +57 -0
- package/src/monitor/types.ts +35 -0
- package/src/monitor/validate.ts +59 -0
- package/src/monitor/widget.ts +75 -0
- package/src/output.ts +25 -0
- package/src/rules/index.ts +94 -0
- package/src/rules/logic.ts +96 -0
- package/src/shared.ts +177 -0
- package/src/stats/aggregate.ts +287 -0
- package/src/stats/chart.ts +247 -0
- package/src/stats/cli.ts +50 -0
- package/src/stats/component.ts +496 -0
- package/src/stats/days.ts +46 -0
- package/src/stats/format.ts +49 -0
- package/src/stats/heatmap.ts +98 -0
- package/src/stats/index.ts +81 -0
- package/src/stats/library.ts +4 -0
- package/src/stats/load.ts +512 -0
- package/src/stats/palette.ts +22 -0
- package/src/stats/snapshot.ts +497 -0
- package/src/titles/aliases.ts +20 -0
- package/src/titles/index.ts +82 -0
- package/src/titles/logic.ts +160 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Redd
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
|
6
|
+
associated documentation files (the "Software"), to deal in the Software without restriction,
|
|
7
|
+
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
|
8
|
+
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
furnished to do so, subject to the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial
|
|
12
|
+
portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
|
15
|
+
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
16
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES
|
|
17
|
+
OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
18
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,168 @@
|
|
|
1
|
-
#
|
|
1
|
+
# pi-session-kit
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Publishable to npm as `@nredd/pi-session-kit` (`publishConfig.access: public`), version `0.3.0`; each publication is recorded in `releases/`.
|
|
4
|
+
Use the [monorepo development commands](https://github.com/nredd/pi-harness/blob/main/README.md). The Git install and standalone harness
|
|
5
|
+
references below describe the legacy deployment, not installation or candidate verification of
|
|
6
|
+
this package.
|
|
7
|
+
|
|
8
|
+
## Standalone use
|
|
9
|
+
|
|
10
|
+
The packed tarball is self-contained: Pi host modules (`@earendil-works/pi-*`, `typebox`) are `*` peers supplied by Pi, there are no runtime dependencies and no sibling plugin is required. Verified by installing the tarball alone and running it in exact stock Pi 1.3.0 (see the repository's `docs/package-contracts.md`). Optional fork integrations (subagents, Plan mode) are absent in that setup; the exercised behavior does not need them.
|
|
11
|
+
|
|
12
|
+
Session-scoped pi extensions for tmux users. No daemon, supervisor, core patch or cross-pane
|
|
13
|
+
registry. Each runtime owns its goal, loops and monitors; persisted goal state follows the active
|
|
14
|
+
session branch. Closing pi stops its work.
|
|
15
|
+
|
|
16
|
+
## Install and config
|
|
17
|
+
|
|
18
|
+
```sh
|
|
19
|
+
pi install git:github.com/nredd/pi-session-kit@v0.3.0
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Optional `~/.pi/agent/pi-session-kit.json` (respects `PI_CODING_AGENT_DIR`):
|
|
23
|
+
|
|
24
|
+
```json
|
|
25
|
+
{
|
|
26
|
+
"titles": { "enabled": true, "model": "anthropic/claude-haiku-5-5" },
|
|
27
|
+
"rules": { "enabled": true },
|
|
28
|
+
"goal": { "enabled": true },
|
|
29
|
+
"loop": { "enabled": true },
|
|
30
|
+
"monitor": { "enabled": true },
|
|
31
|
+
"diff": { "enabled": true },
|
|
32
|
+
"stats": { "enabled": true }
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Every module defaults on. Malformed config reports a diagnostic and uses defaults. No daemon or
|
|
37
|
+
persistent cron is installed. Deferred-tool configurations need `goal_update` in `neverDefer`
|
|
38
|
+
(without forcing it active), and `monitor_read` in `alwaysActive` and `neverDefer` for Plan mode.
|
|
39
|
+
|
|
40
|
+
## Goal and loop
|
|
41
|
+
|
|
42
|
+
- `/goal <objective> [--turns N] [--tokens N]`: keep working toward an explicit objective. Default
|
|
43
|
+
budget: 30 parent turns. Token accounting uses reported usage. `status`, `pause`, `resume` and
|
|
44
|
+
`clear` manage it; the footer chip shows turn and token consumption.
|
|
45
|
+
- `goal_update({status: "complete" | "blocked", evidence})`: complete requires nonempty evidence.
|
|
46
|
+
This is a self-report, not an independent verifier; it does not replace tests or todo evidence.
|
|
47
|
+
- The settle nudge respects existing continuations, background-agent delivery and Plan permissions.
|
|
48
|
+
Abort, settled provider error, budgets and a Plan-mode excursion pause/stop it. Resume restores a
|
|
49
|
+
goal paused. Quota recovery is left to the router; a parked dispatch or direct refusal pauses
|
|
50
|
+
goals and loops, cancels goal wake timers, and requires explicit resume. Goal resume is refused
|
|
51
|
+
while a quota-parked dispatch remains. A settled provider failure also pauses rather than spinning.
|
|
52
|
+
- `/loop <interval> <prompt> [--max N]`: repeat a prompt in the current conversation, unlike
|
|
53
|
+
`Agent({schedule: ...})`, which launches fresh children. Minimum interval 30s; maximum 50 runs.
|
|
54
|
+
`list` and `stop [id|all]` manage loops. Busy ticks are skipped, never queued. Plan mode and an
|
|
55
|
+
active goal suspend ticks; settled errors pause loops. Loops are not persisted across restarts.
|
|
56
|
+
|
|
57
|
+
## Monitor
|
|
58
|
+
|
|
59
|
+
- `monitor_start({argv, name, match?, wake?, timeout_s?})`: run an argv command with stdin closed,
|
|
60
|
+
no implicit shell. Five active monitors maximum, one-hour default timeout. Explicitly passing a
|
|
61
|
+
shell remains arbitrary command execution; this is not a sandbox.
|
|
62
|
+
- `monitor_read({id, since?})`: numbered output since a cursor. Ring buffers retain 2000 lines.
|
|
63
|
+
- `monitor_stop({id})`, `/monitor list`, `/monitor stop <id|all>`: stop and inspect owned monitors.
|
|
64
|
+
- Output batches every two seconds with bounded pending storage and dropped-line reporting. Passive
|
|
65
|
+
batches do not start turns; regex matches, exit and `wake: true` can wake the agent.
|
|
66
|
+
- Children run in process groups: SIGTERM, then SIGKILL. Exit cleanup and pidfiles cover orderly quit
|
|
67
|
+
and later recovery after SIGKILL. Files live at
|
|
68
|
+
`$TMPDIR/pi-monitors-<uid>/<sessionId>.<ownerPid>/<monitorId>.json`. Startup checks dead-owner
|
|
69
|
+
records, including a resumed session, and validates process identity before signalling. It never
|
|
70
|
+
sweeps a live owner's monitors. Two panes resuming the same session have separate directories.
|
|
71
|
+
- Plan mode admits only `monitor_read`; start and stop are mutating tools. Ordinary tool hooks apply
|
|
72
|
+
to the tool call, but a custom argv tool does not automatically inherit Bash-specific policies.
|
|
73
|
+
|
|
74
|
+
## Diff
|
|
75
|
+
|
|
76
|
+
`/diff [ref]` opens a read-only file/patch overlay. Default: staged and working changes against HEAD,
|
|
77
|
+
with untracked files listed. `j/k` or arrows scroll, `n/p` select files, `g/G` and PageUp/PageDown
|
|
78
|
+
navigate, `q` or Escape closes. Output is capped. Invalid refs and non-repositories produce clear
|
|
79
|
+
errors. Print mode emits a stat (pi currently redirects extension stdout to stderr); JSON emits a
|
|
80
|
+
non-triggering display message. The overlay is TUI-only and works in Plan mode.
|
|
81
|
+
|
|
82
|
+
## Stats
|
|
83
|
+
|
|
84
|
+
`/stats` is Claude Code's `/stats` pane over fresh local sessions plus imported machine snapshots,
|
|
85
|
+
split by provider and model. It NEVER performs network I/O. Machine coverage and the last successful
|
|
86
|
+
remote import are shown; unsynced machines show `local-only` / `never synced`. Invalid or missing
|
|
87
|
+
snapshots retain last-good data and show `incomplete coverage`. Overview: an activity heatmap (one column per week), headline numbers (favorite model, total tokens,
|
|
88
|
+
sessions, longest session, active days, streaks, cache tokens, notional cost) and the token chart.
|
|
89
|
+
Models: the chart, then every model grouped under its provider with in/out/cache/cost, two-up from
|
|
90
|
+
80 columns. Tab switches tabs, `r` cycles All / 7d / 30d / 5h / 24h (default All), `m`/`M` cycle the filter
|
|
91
|
+
(All, each provider, each `provider/model`), `j/k` or arrows scroll, `q` or Escape closes.
|
|
92
|
+
|
|
93
|
+
- The chart is an asciichart-style line plot (`╭╮╰╯`), one line per provider under All, else the top
|
|
94
|
+
three models. Where lines overlap they merge into junctions (`┴┬├┤┼`) so every line stays
|
|
95
|
+
connected; the larger series keeps the colour. Line colours start at the theme's `accent` hue,
|
|
96
|
+
saturated, with hues spread evenly over the lines drawn (two providers get opposite hues), so
|
|
97
|
+
muted themes still separate them. The heatmap and the chart span 75% of the pane, with the same right edge; the heatmap shows as
|
|
98
|
+
many weeks as fit, never less than a year when the pane allows. Days sum into 1/2/3/7/14/30-day buckets (longer
|
|
99
|
+
when needed) so the range fits the width; short ranges are interpolated, not stepped. Y ticks land
|
|
100
|
+
on round values with little headroom. Height follows the pane in whole tick steps (5 to 40 rows):
|
|
101
|
+
Overview grows the chart into the rows it has left, Models gives it about half.
|
|
102
|
+
- Rolling 5h/24h use the original call timestamps in zero-filled one-hour UTC buckets, with
|
|
103
|
+
partial edges labeled. Labels use viewer-local time and UTC offsets, including repeated DST
|
|
104
|
+
hours. The same rolling filter feeds chart/model/overview totals; future calls are ignored in
|
|
105
|
+
every range. Long ranges retain the daily chart and activity heatmap.
|
|
106
|
+
- Tokens = input + output + cache read + cache write. Anthropic reports almost every prompt token
|
|
107
|
+
as a cache read or write while Codex reports it as input, so anything less undercounts agentic
|
|
108
|
+
use by orders of magnitude. Cost is pi's recorded list price: notional on a subscription.
|
|
109
|
+
- Counted: assistant messages, under the provider/model that answered. Not counted: tool-result
|
|
110
|
+
usage (pi-subagents' parent-side report; its child sessions already hold those calls), compaction
|
|
111
|
+
usage, `router/*` rows, `faux` and zero-usage rows. A `/fork` or cross-machine copy counts once.
|
|
112
|
+
Preserved assistant entry IDs distinguish equal-value events. Legacy records use the old tuple
|
|
113
|
+
identity and are discarded when an identified counterpart exists. Raw names drive dedup;
|
|
114
|
+
only display text is sanitized.
|
|
115
|
+
- Subagent children (parent link plus a `<type>#<8 hex>` name, or the matching persisted child
|
|
116
|
+
marker, including renamed children) count toward tokens but not
|
|
117
|
+
Sessions. A filter narrows Sessions to the sessions that used the filtered models.
|
|
118
|
+
- Source: `*.jsonl` under `$PI_CODING_AGENT_SESSION_DIR` or `<agentDir>/sessions`. Cache:
|
|
119
|
+
`<agentDir>/pi-session-kit/stats-cache.json`, re-parsing only files whose size or mtime changed;
|
|
120
|
+
deleted sessions keep counting; machine views also retain history from previously configured
|
|
121
|
+
session roots. Version 1 caches migrate without dropping deleted-file records; available files
|
|
122
|
+
are reparsed for preserved IDs. A corrupt record is dropped and rebuilt. Lines that are not JSON
|
|
123
|
+
objects show as `! N unreadable lines`.
|
|
124
|
+
- Print mode prints a per-model table and coverage; JSON emits a display message. Works in Plan mode.
|
|
125
|
+
- After `make install` at the monorepo root, `npm run build:stats-export --workspace @nredd/pi-session-kit`
|
|
126
|
+
reproduces `dist/pi-stats-export.mjs` inside this package. Copy this standalone Node 22+ artifact
|
|
127
|
+
to another machine: neither Pi nor the loaded session-kit extension is needed at runtime.
|
|
128
|
+
`node ARTIFACT export --agent-dir DIR --output OUT` writes ONLY `OUT/machines/<UUID>/`.
|
|
129
|
+
`node ARTIFACT import --agent-dir DIR --input REPO` validates all machines and atomically
|
|
130
|
+
publishes the local global cache. Both emit one JSON object on success; partial imports emit
|
|
131
|
+
JSON and diagnostics with a nonzero exit. No Git/network operations are part of the CLI.
|
|
132
|
+
Schema, identity, atomicity and harness API details: [here](docs/stats-snapshots.md).
|
|
133
|
+
|
|
134
|
+
## Titles and rules
|
|
135
|
+
|
|
136
|
+
- Titles: one attempt after the first eligible TUI run of an unnamed persisted session. Default
|
|
137
|
+
candidates are Haiku 5.5, validated enterprise alias candidates (including the legacy Haiku 4.5
|
|
138
|
+
logical key), then GPT 6 Luna. `titles.model` overrides the preferred candidate. No silent retry
|
|
139
|
+
after provider failure; explicit names and session switches win races. Children, headless runs,
|
|
140
|
+
no-session runs and active planning are skipped. Output is capped at six words/60 characters;
|
|
141
|
+
shorter names are accepted.
|
|
142
|
+
- Rules: Markdown files in `.pi/rules/` and the agent directory's `rules/`, with YAML frontmatter
|
|
143
|
+
`paths: ["src/**/*.ts"]`. No `paths`, no injection. Successful read/edit/write results receive
|
|
144
|
+
matching rules once per context lifetime. Compaction resets deduplication. Eight rules per turn,
|
|
145
|
+
4096 UTF-8 bytes per appended block. The system prompt is not rewritten. Rules injected after an
|
|
146
|
+
edit inform subsequent work, not the edit already performed.
|
|
147
|
+
|
|
148
|
+
## Subagents and verification
|
|
149
|
+
|
|
150
|
+
`pi-subagents` exposes no public child-context marker. The kit recognises its generated
|
|
151
|
+
`<type>#<8 hex>` session names; this is a compatibility heuristic, not a security boundary.
|
|
152
|
+
Commands/continuations are guarded. At `session_start`, parent-only goal/monitor tools are
|
|
153
|
+
re-registered with Pi's `hidden` exposure: child scoping and deferred promotion cannot reactivate
|
|
154
|
+
their schemas or nested-call capabilities. Tool-call and execute guards also deny child calls,
|
|
155
|
+
even after a child renames itself and reloads. Initial child binding persists a
|
|
156
|
+
`session-kit:child` entry with its session id; reload reads the active branch, not a generic
|
|
157
|
+
parent-session link (fresh Plan sessions also have parents). Replacement sessions do not inherit
|
|
158
|
+
cached identity or another session's marker. Goal/monitor factories register the shared identity
|
|
159
|
+
hook before their rebuild hooks, without querying an unbound runtime during factory loading.
|
|
160
|
+
No private subagent marker is imported. Existing tool permissions are not widened.
|
|
161
|
+
|
|
162
|
+
A prior settle handler's continuation (including a todo reminder) suppresses the goal nudge;
|
|
163
|
+
the kit does not append a second reminder or request another continuation.
|
|
164
|
+
|
|
165
|
+
`npm run check`: Biome, TypeScript and Vitest. `pi-harness-e2e` adds faux-provider integration tests,
|
|
166
|
+
real tmux width matrices (60 through 320 columns), Plan-mode tests, background-agent/todo interaction
|
|
167
|
+
and two-pane lifecycle/isolation scenarios. Run its full `make verify` before tags or pins. Real
|
|
168
|
+
monitor/display testing remains manual; see that repo's `docs/footer-cache-ultrawide.md`.
|