bb-cc-lite 0.1.11 → 0.1.13

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.
Files changed (56) hide show
  1. package/README.md +171 -71
  2. package/assets/statusline-coach-guard-demo.gif +0 -0
  3. package/dist/audit.d.ts +47 -0
  4. package/dist/audit.js +427 -0
  5. package/dist/audit.js.map +1 -0
  6. package/dist/baseline-builder.d.ts +5 -0
  7. package/dist/baseline-builder.js +68 -31
  8. package/dist/baseline-builder.js.map +1 -1
  9. package/dist/baseline.d.ts +7 -2
  10. package/dist/baseline.js +53 -3
  11. package/dist/baseline.js.map +1 -1
  12. package/dist/cache-efficiency.d.ts +3 -0
  13. package/dist/cache-efficiency.js +38 -0
  14. package/dist/cache-efficiency.js.map +1 -0
  15. package/dist/cli.js +42 -0
  16. package/dist/cli.js.map +1 -1
  17. package/dist/doctor.js +10 -0
  18. package/dist/doctor.js.map +1 -1
  19. package/dist/event-store-persistence.js +21 -0
  20. package/dist/event-store-persistence.js.map +1 -1
  21. package/dist/event-store-queries.d.ts +3 -1
  22. package/dist/event-store-queries.js +48 -1
  23. package/dist/event-store-queries.js.map +1 -1
  24. package/dist/feedback-outcomes.js +6 -0
  25. package/dist/feedback-outcomes.js.map +1 -1
  26. package/dist/feedback-policy.d.ts +3 -1
  27. package/dist/feedback-policy.js +99 -0
  28. package/dist/feedback-policy.js.map +1 -1
  29. package/dist/file-identity.d.ts +8 -0
  30. package/dist/file-identity.js +43 -0
  31. package/dist/file-identity.js.map +1 -0
  32. package/dist/historical-replay.d.ts +12 -0
  33. package/dist/historical-replay.js +139 -43
  34. package/dist/historical-replay.js.map +1 -1
  35. package/dist/hook-control.js +7 -2
  36. package/dist/hook-control.js.map +1 -1
  37. package/dist/hook-payload.js +13 -4
  38. package/dist/hook-payload.js.map +1 -1
  39. package/dist/hook-summary.d.ts +2 -0
  40. package/dist/hook-summary.js +22 -1
  41. package/dist/hook-summary.js.map +1 -1
  42. package/dist/recovery-stats.d.ts +27 -1
  43. package/dist/recovery-stats.js +128 -5
  44. package/dist/recovery-stats.js.map +1 -1
  45. package/dist/settings.js +2 -1
  46. package/dist/settings.js.map +1 -1
  47. package/dist/signals.js +192 -19
  48. package/dist/signals.js.map +1 -1
  49. package/dist/status-input.js +15 -15
  50. package/dist/transcript.d.ts +1 -0
  51. package/dist/transcript.js +112 -1
  52. package/dist/transcript.js.map +1 -1
  53. package/dist/types.d.ts +57 -0
  54. package/dist/why.js +2 -0
  55. package/dist/why.js.map +1 -1
  56. package/package.json +1 -1
package/README.md CHANGED
@@ -2,48 +2,100 @@
2
2
 
3
3
  [![CI](https://github.com/softcane/bb-cc-lite/actions/workflows/ci.yml/badge.svg)](https://github.com/softcane/bb-cc-lite/actions/workflows/ci.yml)
4
4
 
5
- Claude Code can look busy while it is doing the wrong thing: retrying the same broken test, editing without checking, filling context, or spending money on a stuck loop.
5
+ Behavioral health monitoring for Claude Code sessions.
6
6
 
7
- `bb-cc-lite` is a small local Claude Code session supervisor. It adds a status line that answers one question:
7
+ Claude Code can look busy while doing the wrong thing. It can retry the same failed test, edit without verification, burn tokens, fill the context window, thrash across files, and keep going long after a human should stop it.
8
+
9
+ The small local status line answers one question:
8
10
 
9
11
  > Should I let this Claude Code session keep going?
10
12
 
11
- By default, it also gives Claude a short nudge when the pattern is clear. If the same test keeps failing without a fix, Claude can be told to inspect the first failure before retrying again. If Claude follows that feedback and recovers, `why` can show the loop. If you turn on guard mode, bb can deny the obvious repeated retry before it runs.
13
+ Token spend tells you what it cost. `bb-cc-lite` tries to show whether the session behavior still looks healthy: continue, verify, or stop before more turns are burned.
14
+
15
+ It is local. It is not a cloud dashboard, telemetry service, proxy, gateway, or message router.
16
+
17
+ ```text
18
+ bb: Healthy | ctx 42% | $0.18 | continue normally
19
+ bb: Healthy | validation resolved | continue normally
20
+ bb: Careful | edits have not been checked yet | run the smallest relevant check
21
+ bb: Careful | same test failed twice without a fix | inspect first failure
22
+ bb: Careful | 9 non-read tool calls, no check or recovery seen | pause and ask what changed
23
+ bb: Stop | why: same failure retried 3x without a fix | do: stop and inspect first failure
24
+ ```
12
25
 
13
26
  ![bb-cc-lite statusline examples](./assets/statusline-demo.gif)
14
27
 
15
- ## Requirements
28
+ _The demo shows the difference between healthy progress, unchecked edits, repeated validation failures, and Stop-level retry loops._
16
29
 
17
- - Node.js 20 or newer
18
- - Claude Code with status line support
30
+ ## Why This Exists
19
31
 
20
- ## Install
32
+ Activity is not progress.
21
33
 
22
- ```bash
23
- npx --yes bb-cc-lite install --scope local
24
- ```
34
+ The hard part is not seeing that Claude Code is active. The hard part is knowing whether its activity is still useful. Busy output, tool calls, and token spend can hide negative progress.
25
35
 
26
- Restart Claude Code in the project. The status line appears at the bottom.
36
+ Humans usually notice too late: after the same check has failed three times, after a broad edit streak was never verified, or after the context window is already under pressure.
27
37
 
28
- Default install uses coach mode. It keeps the status line for you and sends Claude short safe feedback when a risky loop is visible. Coach feedback can say things like: a validation check has failed repeatedly, inspect the failure pattern, make one targeted fix, then run one focused check.
38
+ `bb-cc-lite` watches local derived signals from the Claude Code status input, transcript tail, and optional hooks. It classifies the current session as `Healthy`, `Careful`, or `Stop`.
29
39
 
30
- Coach feedback does not include prompts, command text, tool output, file contents, raw paths, raw session ids, or raw MCP names.
40
+ ## What It Catches
31
41
 
32
- Install preserves an existing Claude Code `statusLine` unless you pass `--replace`.
42
+ - Retry loops where the same validation check or tool fails repeatedly without a fix.
43
+ - Repeated test, lint, typecheck, or build failures.
44
+ - Long edit streaks without a test, lint, typecheck, or build check.
45
+ - Busy sessions with many tool calls but no observed check or recovery.
46
+ - Repeated full-file reads of the same unchanged file.
47
+ - Large tool results that suddenly add thousands of input tokens.
48
+ - Cache reuse dropping after it was working well.
49
+ - Context pressure before the session gets too full to reason clearly.
50
+ - Compaction boundaries where Claude should restate the goal before continuing.
51
+ - Cost and time budget warnings that make a stuck session easier to spot.
52
+ - Local baseline patterns, when there is enough aggregate local history.
33
53
 
34
- To uninstall:
54
+ ## Healthy / Careful / Stop
35
55
 
36
- ```bash
37
- npx --yes bb-cc-lite uninstall --scope local
56
+ `Healthy` means the session still looks safe to continue.
57
+
58
+ `Careful` means slow down. Ask for verification, inspect the pattern, or make the next step smaller.
59
+
60
+ `Stop` does not mean the project failed. It means the session pattern is no longer worth blindly continuing. Take over, redirect Claude, or inspect the first failure before spending more turns.
61
+
62
+ ## How It Helps Claude
63
+
64
+ `bb-cc-lite` can run in three install modes.
65
+
66
+ `observe-only` keeps the status line and local derived event data, but does not send feedback to Claude.
67
+
68
+ `coach` is the default. It keeps the status line and can send short, safe Claude-facing notes when a risky pattern is visible, such as repeated validation failure, unchecked edits, high budget with no progress signal, or unresolved validation risk at finish.
69
+
70
+ `guard` includes coach feedback. It may deny a high-confidence repeated Bash validation retry, such as rerunning the same test/lint/typecheck/build category after repeated failures without an edit or passing check. It does not broadly block normal reads, edits, or arbitrary commands.
71
+
72
+ `bb-cc-lite` also records safe feedback outcomes. For example, if bb asks Claude to validate after an edit and Claude runs a passing test, `bb-cc-lite why` can show that the feedback was resolved.
73
+
74
+ When available, `why` includes the recent bb loop:
75
+
76
+ ```text
77
+ Recent bb loop:
78
+ 1. Coach feedback: edits needed validation.
79
+ 2. Claude ran tests.
80
+ 3. Tests passed.
81
+ 4. Outcome: resolved.
38
82
  ```
39
83
 
40
- Prefer a global install?
84
+ ## Install
85
+
86
+ Requirements:
87
+
88
+ - Node.js 20 or newer
89
+ - Claude Code with status line support
41
90
 
42
91
  ```bash
43
- npm install -g bb-cc-lite
44
- bb-cc-lite install --scope local
92
+ npx --yes bb-cc-lite install --scope local
45
93
  ```
46
94
 
95
+ Restart Claude Code in the project. The status line appears at the bottom.
96
+
97
+ Default install uses coach mode and builds a small local baseline when possible. It preserves an existing Claude Code `statusLine` unless you pass `--replace`.
98
+
47
99
  To replace an existing status line:
48
100
 
49
101
  ```bash
@@ -56,81 +108,69 @@ To observe only, without sending feedback to Claude:
56
108
  npx --yes bb-cc-lite install --scope local --observe-only
57
109
  ```
58
110
 
59
- To enable stricter guard behavior:
111
+ To enable stricter repeated-validation retry denial:
60
112
 
61
113
  ```bash
62
114
  npx --yes bb-cc-lite install --scope local --guard
63
115
  ```
64
116
 
65
- Guard mode includes coach feedback. It may deny a high-confidence repeated validation retry with a safe reason. It does not broadly block normal reads or edits.
66
-
67
117
  To disable baseline learning and lesson memory:
68
118
 
69
119
  ```bash
70
120
  npx --yes bb-cc-lite install --scope local --no-learn
71
121
  ```
72
122
 
73
- ## What It Catches
74
-
75
- - Retry loops where the same command or test fails repeatedly without a fix.
76
- - Long stretches of editing without a test, lint, typecheck, or build check.
77
- - Busy sessions with many tool calls but no observed check or recovery.
78
- - Context pressure before the session gets too full to reason clearly.
79
- - Cost and time budget signals that make a stuck session easier to spot.
80
- - Project baseline patterns, when there is enough local aggregate history.
123
+ To uninstall:
81
124
 
82
- ## How It Helps Claude
125
+ ```bash
126
+ npx --yes bb-cc-lite uninstall --scope local
127
+ ```
83
128
 
84
- In observe-only mode, bb records the pattern and updates the status line, but Claude does not receive feedback.
129
+ Prefer a global install?
85
130
 
86
- In coach mode, bb can send Claude a short note during the session. Claude can then inspect the failure, make a targeted fix, run a focused check, or summarize why retrying is not useful.
131
+ ```bash
132
+ npm install -g bb-cc-lite
133
+ bb-cc-lite install --scope local
134
+ ```
87
135
 
88
- In guard mode, bb can deny a high-confidence repeated validation retry. The retry does not run, and Claude sees a safe reason.
136
+ Supported install scopes are `local`, `project`, and `user`. Use `local` for the current repo unless you have a specific reason to edit project or user Claude settings.
89
137
 
90
- bb also records safe feedback outcomes. For example, if bb asks Claude to validate after an edit and Claude runs a passing test, `bb-cc-lite why` can show that the feedback was resolved.
138
+ ## Try Before Installing
91
139
 
92
- ## What It Shows
140
+ Run a retrospective audit against recent local Claude Code history:
93
141
 
94
- ```text
95
- bb: Healthy | ctx 42% | $0.18 | cache warm | continue normally
96
- bb: Healthy | validation resolved | continue normally
97
- bb: Healthy | read-only exploration | continue normally
98
- bb: Careful | edits have not been checked yet | ask Claude to run the smallest relevant check
99
- bb: Careful | 9 non-read tool calls, no check or recovery seen | pause and ask Claude what changed
100
- bb: Careful | session ran 1h plus 9 non-read tool calls, no check or recovery seen | pause and ask Claude what changed before continuing
101
- bb: Careful | same test failed twice without a fix | inspect first failure
102
- bb: Careful | tests failed twice; usually passes after one targeted fix | inspect first failure
103
- bb: Careful | estimated cost $2.25 | ask Claude to summarize progress before continuing
104
- bb: Stop | why: same failure retried 3x without a fix | do: stop and inspect first failure
105
- bb: Stop | why: same test retried after feedback | do: inspect first failure
106
- bb: Stop | why: test loop rarely recovered after 3 failures | do: stop retrying and inspect first failure
107
- bb: Stop | why: high cost plus repeated failures | do: stop and inspect first failure
142
+ ```bash
143
+ npx --yes bb-cc-lite audit --project .
144
+ npx --yes bb-cc-lite audit --all-projects --recent 200
108
145
  ```
109
146
 
110
- `Healthy` means keep going. `Careful` means slow down and verify. `Stop` means take over before Claude burns more turns.
111
-
112
- When available, `why` includes the recent bb loop:
113
-
114
- ```text
115
- Recent bb loop:
116
- 1. Coach feedback: edits needed validation.
117
- 2. Claude ran tests.
118
- 3. Tests passed.
119
- 4. Outcome: resolved.
120
- ```
147
+ `audit` scans recent local Claude Code JSONL history and reports where `bb-cc-lite` would have warned. It highlights repeated retries and risky session patterns; it only shows duplicate retry cost/time when the transcript contains usable measured metadata. It does not install a status line or hooks. Use `--all-projects` only when you want to inspect newest transcripts across local Claude projects.
121
148
 
122
149
  ## Useful Commands
123
150
 
124
151
  ```bash
152
+ bb-cc-lite audit --project .
153
+ bb-cc-lite audit --all-projects --recent 200
125
154
  bb-cc-lite why
126
155
  bb-cc-lite doctor
156
+ bb-cc-lite doctor --baseline
127
157
  bb-cc-lite unlearn
128
158
  bb-cc-lite uninstall --scope local
129
159
  ```
130
160
 
131
- `why` explains the latest statusline decision and recent feedback outcomes when available. Interactive `why` output is lightly colored; set `NO_COLOR=1` or `BB_CC_LITE_COLOR=0` for plain text. `doctor --baseline` shows safe aggregate baseline facts. `unlearn` clears learned personal baselines, project baselines, and lesson memory. `uninstall` restores the previous Claude Code status line when a backup exists.
161
+ `audit` scans recent history without installing.
162
+
163
+ `why` explains the latest stored status line decision and recent feedback outcomes when available. It reads the local derived event store; it does not reopen transcripts to expose raw content. Interactive `why` output is lightly colored; set `NO_COLOR=1` or `BB_CC_LITE_COLOR=0` for plain text.
132
164
 
133
- Budget guard thresholds can be changed with environment variables:
165
+ `doctor` checks Node, Claude settings, optional hooks, transcript access, pricing cache, and related diagnostics.
166
+
167
+ `doctor --baseline` shows safe aggregate baseline facts.
168
+
169
+ `unlearn` clears learned personal baselines, project baselines, and lesson memory.
170
+
171
+ `uninstall` removes bb-owned status line and hooks. When a valid backup exists, it restores the previous Claude Code status line.
172
+
173
+ Budget thresholds can be changed with environment variables:
134
174
 
135
175
  ```bash
136
176
  BB_CC_LITE_BUDGET_COST_USD=1.25
@@ -138,9 +178,28 @@ BB_CC_LITE_BUDGET_COST_DELTA_USD=0.25
138
178
  BB_CC_LITE_BUDGET_DURATION_MINUTES=30
139
179
  ```
140
180
 
141
- ## Project-Specific Checks
181
+ ## Validation Signals
182
+
183
+ `bb-cc-lite` observes checks Claude Code runs. It does not run tests, lint, typecheck, or build commands by itself.
184
+
185
+ It recognizes common Bash validation commands and groups them into safe categories:
142
186
 
143
- bb already recognizes common checks such as `npm test`, `pytest`, `cargo test`, `go test`, `npm run lint`, and `npm run build`.
187
+ - tests
188
+ - lint
189
+ - typecheck
190
+ - build
191
+
192
+ Those categories are used for retry-loop detection, recovery baselines, coach feedback, and guard-mode retry denial.
193
+
194
+ ## Session Signals
195
+
196
+ Some warnings are not about tests. They are about the session shape.
197
+
198
+ `bb-cc-lite` can notice when Claude rereads the same unchanged file, when one tool result makes the next turn much larger, when prompt-cache reuse drops, or when a compaction boundary needs a quick goal check.
199
+
200
+ These signals are intentionally simple. They do not inspect raw prompts, tool output, or file contents. They use derived metadata from the status input and transcript tail.
201
+
202
+ ## Project-Specific Checks
144
203
 
145
204
  If your project uses custom validation commands, you can add an optional `.bb-cc-lite.json`:
146
205
 
@@ -156,14 +215,55 @@ If your project uses custom validation commands, you can add an optional `.bb-cc
156
215
 
157
216
  This file is not generated automatically. It is only needed when you want to teach bb what your project's test, lint, typecheck, or build commands look like. bb uses it for classification, but does not copy those raw commands into its event history.
158
217
 
218
+ ## When This Is Useful
219
+
220
+ - Claude keeps retrying the same failing test.
221
+ - Claude edits many files without running checks.
222
+ - Claude rereads the same file as if it forgot the current context.
223
+ - One tool response suddenly bloats the next turn.
224
+ - Cache reuse drops and the session starts getting more expensive per turn.
225
+ - Context is getting high and reasoning quality may drop.
226
+ - Cost or time is climbing but validation is not improving.
227
+ - A session has many tool calls but no clear recovery signal.
228
+ - You want a quick signal before deciding to continue or intervene.
229
+ - You want local feedback without adding a dashboard or service.
230
+
159
231
  ## Privacy
160
232
 
161
- Everything stays local. `bb-cc-lite` does not upload transcripts, prompts, tool output, shell output, file contents, API keys, raw commands, raw paths, raw Claude session ids, or raw MCP server or tool names.
233
+ `bb-cc-lite` is local-first. There is no cloud backend, SaaS dashboard, transcript upload, proxy, gateway, or message router.
234
+
235
+ The health event store and baselines use derived metadata only: state, reason code, counts, rates, percentiles, confidence labels, feedback outcomes such as `resolved` or `ignored`, safe categories such as `tests`, token/cost/context fields, timestamps, weak pattern labels, hashed file identities, hashed session keys, and hashed project keys.
236
+
237
+ The health data is designed not to store prompts, assistant text, tool output, shell output, command arguments, file contents, transcript paths, workspace paths, API keys, raw Claude session ids, or raw MCP names.
238
+
239
+ For repeated-read warnings, bb may show a short basename-style hint such as `auth.ts`. It does not store or print the full local path.
240
+
241
+ Local files live under `~/.claude/bb-cc-lite` by default, unless `BB_CC_LITE_HOME` or other override environment variables are set. This includes:
242
+
243
+ - `events.json` for derived local decisions and hook events.
244
+ - `baseline.json` for the personal aggregate baseline.
245
+ - `project-baselines/<hashed-project>.json` for aggregate project baselines.
246
+ - `project-lessons/<hashed-project>.json` for decaying project lesson memory.
247
+ - `litellm-pricing.json` for cached public pricing data when refreshed.
248
+ - `backups/` for Claude settings backups used by uninstall.
162
249
 
163
- It stores derived data only: counts, rates, percentiles, confidence labels, reason codes, feedback outcomes such as `resolved` or `ignored`, safe categories such as `tests`, cost/time/context numbers, weak pattern labels, hashed session keys, and hashed project keys.
250
+ Install backups are local settings snapshots so uninstall can restore prior Claude settings. They may contain whatever status line, hook commands, or paths existed in those Claude settings. They are not uploaded by `bb-cc-lite`.
164
251
 
165
- Project baselines are stored under the bb app home, not inside the repo. They use only a hashed project key and safe summary data from that project. Sparse or corrupt project data falls back to the personal baseline or fixed rules.
252
+ LiteLLM is used only as public pricing data for cost estimates. `bb-cc-lite` does not run a LiteLLM proxy or route messages.
166
253
 
167
- Lesson memory is also stored under the bb app home by hashed project key. A lesson card contains only safe fields such as a reason code, safe category, confidence, counts, timestamps, and templated wording. Lesson cards decay and can be removed with `bb-cc-lite unlearn`.
254
+ ## More Examples
168
255
 
169
- LiteLLM is used only as public pricing data for cost estimates. `bb-cc-lite` does not run a proxy, gateway, dashboard, or message router.
256
+ ```text
257
+ bb: Healthy | read-only exploration | continue normally
258
+ bb: Careful | estimated cost $2.25 | ask Claude to summarize progress before continuing
259
+ bb: Careful | session ran 1h plus 9 non-read tool calls, no check or recovery seen | pause and ask what changed before continuing
260
+ bb: Careful | ctx 83% | ask Claude for a 6-bullet handoff before more work
261
+ bb: Careful | compaction event seen | ask Claude to restate current goal and next 3 steps
262
+ bb: Careful | same file reread twice (auth.ts) | ask Claude to use existing context before rereading
263
+ bb: Careful | single tool result added ~12,400 tokens | compact or narrow the next step
264
+ bb: Careful | cache reuse dropped from 68% to 29% | keep the next prompt narrow
265
+ bb: Careful | tests failed twice; usually passes after one targeted fix | inspect first failure
266
+ bb: Stop | why: same file reread 3x (auth.ts) | do: stop and ask why the same file is needed again
267
+ bb: Stop | why: same test retried after feedback | do: inspect first failure
268
+ bb: Stop | why: test loop rarely recovered after 3 failures | do: stop retrying and inspect first failure
269
+ ```
@@ -0,0 +1,47 @@
1
+ import type { DecisionConfidence, DecisionState } from "./types.js";
2
+ export interface AuditOptions {
3
+ projectDir?: string;
4
+ homeDir?: string;
5
+ transcriptPath?: string;
6
+ allProjects?: boolean;
7
+ recent?: number;
8
+ maxBytesPerTranscript?: number;
9
+ }
10
+ export interface AuditReport {
11
+ scope: "project" | "all-projects" | "transcript";
12
+ recentLimit: number;
13
+ sessionsScanned: number;
14
+ transcriptsFound: number;
15
+ unreadableTranscripts: number;
16
+ sessionsWithFindings: number;
17
+ findings: AuditFinding[];
18
+ repeatedRetriesSpotted: number;
19
+ estimatedSavings: AuditSavingsEstimate;
20
+ reportConfidence: DecisionConfidence;
21
+ reportConfidenceReason: string;
22
+ }
23
+ export interface AuditFinding {
24
+ session: number;
25
+ state: DecisionState;
26
+ confidence: DecisionConfidence;
27
+ reasonCode: string;
28
+ evidence: string;
29
+ action: string;
30
+ repeatedRetries?: number;
31
+ estimatedDurationMs?: number;
32
+ estimatedCostUsd?: number;
33
+ savingsEstimateSource?: "measured" | "fallback";
34
+ }
35
+ export interface AuditSavingsEstimate {
36
+ durationMinutes: number;
37
+ costUsd: number;
38
+ repeatedToolRunsAvoided: number;
39
+ confidence: DecisionConfidence;
40
+ basis: string;
41
+ measured: boolean;
42
+ }
43
+ export interface FormatAuditReportOptions {
44
+ color?: boolean;
45
+ }
46
+ export declare function runAudit(options?: AuditOptions): Promise<AuditReport>;
47
+ export declare function formatAuditReport(report: AuditReport, options?: FormatAuditReportOptions): string;