brainblast 0.4.0 → 0.4.2

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/README.md CHANGED
@@ -11,10 +11,70 @@ parses your code statically and runs offline.
11
11
  npx brainblast . # scan the repo, write .agent-research/report.json
12
12
  npx brainblast . --ci # exit 1 if a confirmed FAIL remains
13
13
  npx brainblast . --ci --strict # also fail on CANT_TELL (can't statically prove)
14
+ npx brainblast . --since origin/main # diff-aware: only audit what changed
15
+ npx brainblast fix . # dry run: list mechanical fixes
16
+ npx brainblast fix . --apply # write fixes, re-audit RED -> GREEN
14
17
  ```
15
18
 
16
19
  Exit codes: **0** clean · **1** a confirmed FAIL · CANT_TELL is a warning by
17
- default (a red build always means a real, confirmed problem).
20
+ default (a red build always means a real, confirmed problem). `2` means
21
+ `--since <ref>` could not run `git diff` (bad ref, or not a git work tree).
22
+
23
+ ### Diff-aware scanning (`--since <ref>`)
24
+
25
+ `--since <ref>` audits only what's changed relative to `<ref>` (any git
26
+ revision: a branch, `HEAD~1`, a commit SHA): TS/Rust functions whose line
27
+ range overlaps `git diff <ref>`, and config/env files that changed at all.
28
+ This makes brainblast fast enough to run on every commit or PR instead of a
29
+ full-repo scan:
30
+
31
+ ```sh
32
+ npx brainblast . --since origin/main # CI: only the PR's diff
33
+ npx brainblast . --since HEAD # pre-commit/save hook: working tree changes
34
+ ```
35
+
36
+ Living-memory precedents (see below) are still looked up and shown in
37
+ `--since` mode, but the memory snapshot itself is only written on full
38
+ (non-`--since`) runs — a partial diff-scan never overwrites the full picture.
39
+
40
+ ### Watch mode (`brainblast watch`)
41
+
42
+ ```sh
43
+ npx brainblast watch .
44
+ ```
45
+
46
+ Runs as a daemon: every time a file is saved, brainblast re-scans only the
47
+ working-tree changes (uncommitted edits vs `HEAD`, plus untracked files —
48
+ the "what did I just save?" view) and emits one **NDJSON event per line** on
49
+ stdout:
50
+
51
+ ```json
52
+ {"type":"watch_started","targetDir":"."}
53
+ {"type":"finding","ruleId":"stripe-webhook-raw-body-verification","severity":"critical","result":"fail","file":"src/webhook.ts","line":3,"detail":"...","fix":{...}}
54
+ {"type":"scan_complete","filesChanged":1,"findings":1,"durationMs":62}
55
+ ```
56
+
57
+ Event types: `watch_started`, `finding` (one per FAIL/CANT_TELL), `scan_complete`
58
+ (per debounced save, even if nothing changed), and `scan_error` (e.g. not a
59
+ git work tree). This is the integration point for an agent daemon — tail
60
+ stdout for structured findings instead of polling `.agent-research/report.json`.
61
+ Exit with Ctrl-C / SIGTERM.
62
+
63
+ ### Auto-fix (`brainblast fix`)
64
+
65
+ ```sh
66
+ npx brainblast fix . # dry run: list available mechanical fixes
67
+ npx brainblast fix . --apply # write each fix.diff to disk, then re-audit
68
+ npx brainblast fix . --apply --branch # also commit to brainblast/auto-fix-<ts>
69
+ ```
70
+
71
+ Every confirmed FAIL that ships a mechanical `fix.diff` (e.g. Stripe raw-body,
72
+ Privy `audience`/`issuer`) can be applied directly. `--apply` writes each diff,
73
+ then re-runs the audit to confirm the finding now passes (RED -> GREEN) — any
74
+ fix that doesn't take is reported, not silently dropped. Findings with only a
75
+ `suggestion` (structural fixes brainblast won't auto-synthesize) are listed as
76
+ guidance, not applied. `--branch` additionally creates a new branch and commits
77
+ the applied changes.
18
78
 
19
79
  ## What it catches
20
80
 
@@ -34,6 +94,13 @@ default (a red build always means a real, confirmed problem).
34
94
  | `metaplex-metadata-immutable` | `createV1` / `createNft` omits `isMutable: false` | Metadata defaults to mutable; any update authority can change the token's name, image, or attributes after launch |
35
95
  | `anchor-init-if-needed-guarded` | Anchor instruction uses `init_if_needed` without a re-initialization guard | Any user can reinitialize another user's account, overwriting its state |
36
96
 
97
+ ### Config / env
98
+
99
+ | Rule | What's wrong | Consequence |
100
+ |------|--------------|-------------|
101
+ | `env-secrets-committed` | A `.env*` file (not `.env.example`/`.sample`/`.template`) is tracked by git and contains a secret-shaped key (`SECRET`, `*_PRIVATE_KEY`, `*_API_KEY`, `*_TOKEN`, `*_PASSWORD`, etc.) with a real-looking (non-placeholder) value | Anyone with read access to the repo — including forks of a public repo — can read the live credential |
102
+ | `env-secret-leaked-to-sink` | A secret-shaped `process.env.X` value (directly, via a local variable, or one hop through a same-file helper) is passed to `console.log`/`res.json`/`res.send`/etc. | Credentials end up in logs, error trackers, or API responses — readable by anyone with log/response access |
103
+
37
104
  Each finding lands in `.agent-research/report.json` (stable `schemaVersion: "1.0"`)
38
105
  with a `checks[]` array a CI gate can read. Each confirmed FAIL ships a
39
106
  generated behavioral test (RED on vulnerable, GREEN on fixed).
@@ -116,7 +183,7 @@ All types are exported: `Rule`, `CheckResult`, `CostReport`, `AccountFlow`,
116
183
 
117
184
  ```sh
118
185
  npm install
119
- npm test # unit suite (135 tests)
186
+ npm test # unit suite (173 tests)
120
187
  npm run prove # end-to-end: generated tests RED on vulnerable, GREEN on fixed
121
188
  npm run build # produce dist/ (the published artifact)
122
189
  ```