Skip to content

feat: honest session receipt — attribution, stop-hook receipt, hygiene, forecast + goal.md decomposition - #55

Merged
PDgit12 merged 1 commit into
mainfrom
feat/receipt
Jul 6, 2026
Merged

feat: honest session receipt — attribution, stop-hook receipt, hygiene, forecast + goal.md decomposition#55
PDgit12 merged 1 commit into
mainfrom
feat/receipt

Conversation

@PDgit12

@PDgit12 PDgit12 commented Jul 6, 2026

Copy link
Copy Markdown
Owner

What (Build 2 — THE RECEIPT, docs/LOOP-ENGINEERING.md Tier-1.2)

Savings were computed then thrown away — one invisible meter number. Now every optimization event is attributed and the session ends with an honest receipt.

  • G1 attribution: all 3 doors (MCP tools, hooks, proxy) write {source, rawTokens, storedTokens, saved} into the ONE activity ledger (extended backward-compatibly; CAP 1000 behind a size gate; session-aware trim protection).
  • G2 stop receipt: Stop hook emits a one-screen receipt (systemMessage) via the Build-1 adapters on claude/codex/vscode; cursor/gemini stay silent by design (their stop channels are behavioral contracts) and get it via knitbrain_context_meter, which now returns the receipt mid-session.
  • G3 hygiene: repeat-reads of unchanged files + oversized-read redirects tracked per session (bounded-CAS writes, newer-mtime-wins merge) and named in the receipt.
  • G6 cap forecast: plan-billing only, ≥10min sessions, labeled estimate.
  • G7 trust stats: lifetime saved + exact recalls from existing stores.
  • goal.md fix: onboarding decomposes per-domain checkboxes from goal clauses; no meaningful split → ONE checkbox + coverage note (kills the 9× duplication).
  • Honest math enforced structurally: redirects record saved:0 (knitbrain_read counts once), no-savings sessions produce a no-claims receipt, headline numbers come from meter deltas that never rotate.
  • KNITBRAIN_PROJECT_DIR override so helper processes (proxy) land state in the right project.

Verification

rm -rf dist && npm run verify EXIT=0 (560 tests). Live smoke on the built binary: seeded 3-door fixture session → claude Stop printed the receipt with exact sums, cursor stop printed nothing, honest-zero and rotation-disclaimer paths verified (smoke caught + fixed a trimmed-flag false positive unit tests missed).

Not in this PR

No version bump, no publish — gated on explicit OK. After merge: bump 0.18.0 (package.json + src/version.ts), publish, then Build 1 regression + Build 2 fresh live tests, separately and combined.

…eipt, hygiene, forecast, trust stats + goal.md decomposition

- src/engine/activity.ts: ActivityEvent gains optional source/file/rawTokens/
  storedTokens/kind (legacy lines parse); CAP 1000 behind a 300KB size gate;
  since(ts) with rotation-honest trimmed flag (only claims at CAP scale);
  session-aware trim via protectSince (ceiling 5000)
- src/engine/receipt.ts (new): pure buildReceipt (consumed/avoided, top-5
  sinks, hygiene offenders, integrity, plan-only labeled forecast, lifetime
  trust stats, honest-zero no-claims path) + session marker & hygiene helpers
  with bounded-CAS writes (newer-mtime-wins merge so a reset survives a race)
- src/engine/onboard.ts: goalCheckboxes decomposes per-domain from goal
  clauses; no meaningful split -> ONE checkbox + coverage note (kills the
  9x-duplicate goal.md)
- hooks: sessionstart writes the session mark; pretooluse tracks repeat-reads
  + redirects (saved:0 by contract — knitbrain_read counts once); posttooluse
  records source:hook ledger events; stop emits the receipt as systemMessage
  through the adapters (claude/codex/vscode; cursor/gemini stay silent —
  their stop channels are behavioral contracts, not display surfaces)
- mcp: capture/pendingLedger attribute optimize+read savings; context_meter
  returns the receipt mid-session; load_session marks hook-less hosts
- proxy: records source:proxy ledger events; paths honor KNITBRAIN_PROJECT_DIR
  so helper processes land in the right project

560 tests, rm -rf dist && npm run verify EXIT=0
Copilot AI review requested due to automatic review settings July 6, 2026 13:06

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@PDgit12
PDgit12 merged commit 380d968 into main Jul 6, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants