blackbrake 0.1.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 +202 -0
- package/NOTICE +4 -0
- package/README.md +123 -0
- package/SECURITY.md +22 -0
- package/THIRD_PARTY_NOTICES +36 -0
- package/bin/blackbrake.mjs +163 -0
- package/package.json +47 -0
- package/src/cost/analyzer.mjs +114 -0
- package/src/cost/prices.mjs +26 -0
- package/src/load/inventory.mjs +184 -0
- package/src/run.mjs +13 -0
- package/src/secrets/audit.mjs +86 -0
- package/src/secrets/context.mjs +59 -0
- package/src/secrets/engine.mjs +121 -0
- package/src/transcripts.mjs +87 -0
- package/vendor/gitleaks.rules.json +4922 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/NOTICE
ADDED
package/README.md
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
# blackbrake
|
|
2
|
+
|
|
3
|
+
**See what your AI coding agent has exposed. Locally, read-only, in one command.**
|
|
4
|
+
|
|
5
|
+
```
|
|
6
|
+
npx blackbrake audit
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
## What it does NOT do
|
|
10
|
+
|
|
11
|
+
Read this first. It is the reason you can run it.
|
|
12
|
+
|
|
13
|
+
- **No network.** blackbrake opens no connections: no telemetry, no update checks, no API calls.
|
|
14
|
+
A test in this repository fails if any network module is ever imported.
|
|
15
|
+
- **No writes.** It only reads files. It does not modify, redact or delete your transcripts.
|
|
16
|
+
- **No secret values in the output.** Findings are shown as a rule name, a masked shape
|
|
17
|
+
(`lin_…(48)`) and a short hash. Never the value, not even in `--json`.
|
|
18
|
+
- **No dependencies.** Zero runtime packages. What you install is the code in this repository.
|
|
19
|
+
- **No AI.** Detection is deterministic: regular expressions, entropy and context rules.
|
|
20
|
+
|
|
21
|
+
## What it does (v0)
|
|
22
|
+
|
|
23
|
+
One screen, three sections, from files Claude Code already keeps on your machine
|
|
24
|
+
(`~/.claude/projects/**/*.jsonl`, `~/.claude/`, `~/.claude.json`):
|
|
25
|
+
|
|
26
|
+
1. **Exposure** — secrets that ended up in your transcripts.
|
|
27
|
+
2. **What you load** — skills, agents, commands, plugins and MCP servers: how much of it is paid
|
|
28
|
+
for on every turn, how much you ever use, and static patterns worth a look (nothing is executed).
|
|
29
|
+
3. **Spend** — where your agent spend concentrates: your costliest 10% of episodes, your typical
|
|
30
|
+
and 90th-percentile episode, the fixed context you pay on every turn. Descriptive only: no
|
|
31
|
+
"you could save X%" claims.
|
|
32
|
+
|
|
33
|
+
### Exposure
|
|
34
|
+
|
|
35
|
+
It reports **secrets that ended up in your transcripts**:
|
|
36
|
+
|
|
37
|
+
- which secrets look real, and which look like test fixtures, documented examples or local-dev values;
|
|
38
|
+
- how many copies of each one exist, and where (your messages, agent commands, tool output,
|
|
39
|
+
subagents, file snapshots);
|
|
40
|
+
- how each one got in first: pasted by you, read from a file, printed by a command.
|
|
41
|
+
|
|
42
|
+
Everything in a transcript has already been sent to the model provider and sits in plain text on
|
|
43
|
+
your disk. A key pasted once can end up copied dozens of times.
|
|
44
|
+
|
|
45
|
+
```
|
|
46
|
+
EXPOSURE — secrets found in your agent transcripts
|
|
47
|
+
1 secret looks real · 18 findings look like examples, tests or local-dev values
|
|
48
|
+
|
|
49
|
+
Looks real — consider rotating these:
|
|
50
|
+
linear-api-key lin_…(48) 5 copies in 1 session
|
|
51
|
+
first pasted by you on 2026-09-18 · copies by: you 1 · agent 1 · other 3
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Why the classification matters
|
|
55
|
+
|
|
56
|
+
A scanner that ignores context confidently tells you to rotate keys that never existed. On the
|
|
57
|
+
author's own transcripts, a first version flagged 12 "real" secrets; after checking where each one
|
|
58
|
+
appeared, none were real (a deliberately fake token used to test a scanner, an AWS example key in a
|
|
59
|
+
test, `localhost` verification links). blackbrake only lists a secret under "consider rotating" when
|
|
60
|
+
most of its occurrences look real, and never when it was written into a test or fixture file.
|
|
61
|
+
It is still a heuristic: check where a finding appears before rotating anything. `--all` shows the
|
|
62
|
+
findings it considered not real, so you can disagree.
|
|
63
|
+
|
|
64
|
+
### What you load
|
|
65
|
+
|
|
66
|
+
```
|
|
67
|
+
WHAT YOU LOAD — skills, agents, plugins and MCP servers
|
|
68
|
+
337 skills · 68 agents · 94 commands · 4 plugins enabled · 2 MCP servers
|
|
69
|
+
353 items installed twice under the same name (counted once)
|
|
70
|
+
Descriptions loaded into every turn: ~28.9k tokens (skills ~25.1k, agents ~3.9k; estimated)
|
|
71
|
+
Skills used at least once: 17 of 337 (5%)
|
|
72
|
+
Settings: the dangerous-mode confirmation prompt is turned off
|
|
73
|
+
Patterns worth a look: 1 in executable code · 3 in documentation
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Patterns are signals, not verdicts: security skills legitimately describe `curl | sh` in their
|
|
77
|
+
docs. Matches in executable files and hooks are listed first.
|
|
78
|
+
|
|
79
|
+
### Spend
|
|
80
|
+
|
|
81
|
+
```
|
|
82
|
+
SPEND — where your agent spend concentrates
|
|
83
|
+
$960 across 136 episodes (API list prices; on a subscription this is a unit of effort, not a bill)
|
|
84
|
+
Your costliest 10% of episodes account for 68% of it · typical episode $1.33 · 90th percentile $21.44
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
An *episode* is one prompt you wrote plus all the agent work until your next one. Messages the
|
|
88
|
+
harness injects into the conversation (subagent reports, skill bodies) do not count as prompts;
|
|
89
|
+
counting them splits expensive episodes into pieces and hides the concentration.
|
|
90
|
+
|
|
91
|
+
## Usage
|
|
92
|
+
|
|
93
|
+
```
|
|
94
|
+
blackbrake audit [--path <dir>] [--home <dir>] [--json] [--all]
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
| Option | Meaning |
|
|
98
|
+
|---|---|
|
|
99
|
+
| `--path <dir>` | Transcript folder. Default: `~/.claude/projects` |
|
|
100
|
+
| `--home <dir>` | Folder holding `.claude/` and `.claude.json`. Default: your home |
|
|
101
|
+
| `--json` | Machine-readable output. Secret values are never included |
|
|
102
|
+
| `--all` | Show every finding, including those classified as not real or found in documentation |
|
|
103
|
+
|
|
104
|
+
Requires Node.js 20 or later.
|
|
105
|
+
|
|
106
|
+
## Roadmap
|
|
107
|
+
|
|
108
|
+
A real-time `guard` that starts in observe-only mode (cost and damage brakes with session
|
|
109
|
+
context, built on [cc-safety-net](https://github.com/kenryu42/cc-safety-net) rather than
|
|
110
|
+
replacing it). Other agents (Codex, Cursor) after that.
|
|
111
|
+
|
|
112
|
+
## Credits
|
|
113
|
+
|
|
114
|
+
Secret detection rules come from [gitleaks](https://github.com/gitleaks/gitleaks) (MIT), converted
|
|
115
|
+
to run on JavaScript's regex engine. See [THIRD_PARTY_NOTICES](THIRD_PARTY_NOTICES).
|
|
116
|
+
|
|
117
|
+
## Security
|
|
118
|
+
|
|
119
|
+
Found a vulnerability? Please report it privately to **security@blackbrake.dev**. See [SECURITY.md](SECURITY.md).
|
|
120
|
+
|
|
121
|
+
## License
|
|
122
|
+
|
|
123
|
+
[Apache-2.0](LICENSE)
|
package/SECURITY.md
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# Security policy
|
|
2
|
+
|
|
3
|
+
## Reporting a vulnerability
|
|
4
|
+
|
|
5
|
+
Please report security issues **privately** by email to **security@blackbrake.dev**.
|
|
6
|
+
Do not open a public issue for vulnerabilities.
|
|
7
|
+
|
|
8
|
+
Include what you found, how to reproduce it, and the version (`blackbrake --version`).
|
|
9
|
+
You will get an acknowledgement within 3 working days.
|
|
10
|
+
|
|
11
|
+
## Scope
|
|
12
|
+
|
|
13
|
+
Especially relevant for this project:
|
|
14
|
+
|
|
15
|
+
- any way blackbrake could send data over the network;
|
|
16
|
+
- any way it could write to, modify or delete files;
|
|
17
|
+
- any way a secret value could appear in its output, logs or error messages;
|
|
18
|
+
- rule-handling issues that make it miss a class of secrets (false negatives).
|
|
19
|
+
|
|
20
|
+
## Supported versions
|
|
21
|
+
|
|
22
|
+
Only the latest published version receives fixes while the project is pre-1.0.
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
Third-party notices for blackbrake
|
|
2
|
+
==================================
|
|
3
|
+
|
|
4
|
+
blackbrake includes material from the projects listed below. Each is used under its own license,
|
|
5
|
+
reproduced here.
|
|
6
|
+
|
|
7
|
+
----------------------------------------------------------------------------------------------------
|
|
8
|
+
gitleaks — default detection rules (config/gitleaks.toml)
|
|
9
|
+
https://github.com/gitleaks/gitleaks
|
|
10
|
+
Upstream commit: b58d3f102cf3a2c84cb7f923d05c25c9b1aed84b
|
|
11
|
+
Used in: vendor/src/gitleaks.toml (verbatim), vendor/gitleaks.rules.json (converted to JavaScript
|
|
12
|
+
regular expressions by scripts/build-rules.mjs; case-insensitive groups widened to whole-pattern
|
|
13
|
+
flags, named groups and POSIX classes rewritten).
|
|
14
|
+
----------------------------------------------------------------------------------------------------
|
|
15
|
+
|
|
16
|
+
MIT License
|
|
17
|
+
|
|
18
|
+
Copyright (c) 2019 Zachary Rice
|
|
19
|
+
|
|
20
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
21
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
22
|
+
in the Software without restriction, including without limitation the rights
|
|
23
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
24
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
25
|
+
furnished to do so, subject to the following conditions:
|
|
26
|
+
|
|
27
|
+
The above copyright notice and this permission notice shall be included in all
|
|
28
|
+
copies or substantial portions of the Software.
|
|
29
|
+
|
|
30
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
31
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
32
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
33
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
34
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
35
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
36
|
+
SOFTWARE.
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// blackbrake — local, read-only audit of AI coding agent transcripts and setup.
|
|
3
|
+
// No network access, no writes, no dependencies. See README "What it does NOT do".
|
|
4
|
+
import fs from 'node:fs';
|
|
5
|
+
import os from 'node:os';
|
|
6
|
+
import path from 'node:path';
|
|
7
|
+
import { fileURLToPath } from 'node:url';
|
|
8
|
+
import { createCostAnalyzer } from '../src/cost/analyzer.mjs';
|
|
9
|
+
import { PRICES_DATE } from '../src/cost/prices.mjs';
|
|
10
|
+
import { inventory } from '../src/load/inventory.mjs';
|
|
11
|
+
import { runAnalyzers } from '../src/run.mjs';
|
|
12
|
+
import { createSecretsAnalyzer } from '../src/secrets/audit.mjs';
|
|
13
|
+
import { CLASSES } from '../src/secrets/context.mjs';
|
|
14
|
+
import { loadRules } from '../src/secrets/engine.mjs';
|
|
15
|
+
import { defaultRoot, listTranscripts } from '../src/transcripts.mjs';
|
|
16
|
+
|
|
17
|
+
const pkg = JSON.parse(fs.readFileSync(path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../package.json'), 'utf8'));
|
|
18
|
+
|
|
19
|
+
const HELP = `blackbrake ${pkg.version} — see what your AI coding agent has exposed, loads and spends. Locally.
|
|
20
|
+
|
|
21
|
+
Usage:
|
|
22
|
+
blackbrake audit [--path <dir>] [--home <dir>] [--json] [--all]
|
|
23
|
+
|
|
24
|
+
Options:
|
|
25
|
+
--path <dir> Transcript folder (default: ~/.claude/projects)
|
|
26
|
+
--home <dir> Home folder holding .claude/ and .claude.json (default: your home)
|
|
27
|
+
--json Machine-readable output (secret values are never included)
|
|
28
|
+
--all Show every finding, including ones classified as examples/tests or local-dev
|
|
29
|
+
-h, --help Show this help
|
|
30
|
+
-v, --version Show version
|
|
31
|
+
|
|
32
|
+
blackbrake reads files only. It opens no network connections and writes nothing to disk.`;
|
|
33
|
+
|
|
34
|
+
function parseArgs(argv) {
|
|
35
|
+
const opts = { command: null, path: null, home: null, json: false, all: false };
|
|
36
|
+
for (let i = 0; i < argv.length; i++) {
|
|
37
|
+
const a = argv[i];
|
|
38
|
+
if (a === '-h' || a === '--help') opts.help = true;
|
|
39
|
+
else if (a === '-v' || a === '--version') opts.version = true;
|
|
40
|
+
else if (a === '--json') opts.json = true;
|
|
41
|
+
else if (a === '--all') opts.all = true;
|
|
42
|
+
else if (a === '--path') opts.path = argv[++i];
|
|
43
|
+
else if (a === '--home') opts.home = argv[++i];
|
|
44
|
+
else if (!opts.command) opts.command = a;
|
|
45
|
+
else throw new Error(`Unknown argument: ${a}`);
|
|
46
|
+
}
|
|
47
|
+
return opts;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const plural = (n, one, many = `${one}s`) => `${n.toLocaleString('en-US')} ${n === 1 ? one : many}`;
|
|
51
|
+
const fmtBytes = (b) => (b > 1e6 ? `${(b / 1e6).toFixed(0)} MB` : `${Math.max(1, Math.round(b / 1e3))} KB`);
|
|
52
|
+
const usd = (n) => `$${n >= 100 ? n.toFixed(0) : n.toFixed(2)}`;
|
|
53
|
+
const pct = (x) => `${Math.round(x * 100)}%`;
|
|
54
|
+
const k = (n) => (n >= 1000 ? `${(n / 1000).toFixed(1)}k` : String(n));
|
|
55
|
+
|
|
56
|
+
function describeWhere(where) {
|
|
57
|
+
const groups = { you: 0, agent: 0, tools: 0, snapshots: 0, other: 0 };
|
|
58
|
+
for (const [key, n] of Object.entries(where)) {
|
|
59
|
+
if (key === 'user') groups.you += n;
|
|
60
|
+
else if (key.startsWith('tool-output')) groups.tools += n;
|
|
61
|
+
else if (key.startsWith('tool-input') || key === 'assistant') groups.agent += n;
|
|
62
|
+
else if (key === 'snapshot') groups.snapshots += n;
|
|
63
|
+
else groups.other += n;
|
|
64
|
+
}
|
|
65
|
+
return Object.entries(groups).filter(([, n]) => n).map(([g, n]) => `${g} ${n}`).join(' · ');
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function exposureSection(findings, showAll) {
|
|
69
|
+
const real = findings.filter((f) => f.classification === CLASSES.real);
|
|
70
|
+
const other = findings.filter((f) => f.classification !== CLASSES.real);
|
|
71
|
+
const out = ['EXPOSURE — secrets found in your agent transcripts'];
|
|
72
|
+
if (!findings.length) return [...out, ' No secrets detected.'];
|
|
73
|
+
out.push(` ${plural(real.length, 'secret')} look real · ${plural(other.length, 'finding')} look like examples, tests or local-dev values`);
|
|
74
|
+
if (real.length) {
|
|
75
|
+
out.push('', ' Looks real — consider rotating these:');
|
|
76
|
+
for (const f of real) {
|
|
77
|
+
out.push(` ${f.ruleId.padEnd(24)} ${f.shape.padEnd(12)} ${plural(f.copies, 'copy', 'copies')} in ${plural(f.sessions, 'session')}${f.subagentCopies ? ` (${f.subagentCopies} in subagents)` : ''}`);
|
|
78
|
+
out.push(` ${''.padEnd(24)} first ${f.origin}${f.firstSeen ? ` on ${f.firstSeen.slice(0, 10)}` : ''} · copies by: ${describeWhere(f.where)}`);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
if (showAll && other.length) {
|
|
82
|
+
out.push('', ' Probably not real:');
|
|
83
|
+
for (const f of other) out.push(` ${f.ruleId.padEnd(24)} ${f.shape.padEnd(12)} ${f.classification.padEnd(16)} ${plural(f.copies, 'copy', 'copies')}`);
|
|
84
|
+
} else if (other.length) {
|
|
85
|
+
out.push(` (${plural(other.length, 'finding')} classified as not real are hidden; --all shows them)`);
|
|
86
|
+
}
|
|
87
|
+
out.push(' Classification is a heuristic. Check where a finding appears before rotating anything.');
|
|
88
|
+
return out;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function loadSection(inv, showAll) {
|
|
92
|
+
const c = inv.counts;
|
|
93
|
+
const out = ['WHAT YOU LOAD — skills, agents, plugins and MCP servers'];
|
|
94
|
+
out.push(` ${plural(c.skills, 'skill')} · ${plural(c.agents, 'agent')} · ${plural(c.commands, 'command')} · ${plural(c.pluginsEnabled, 'plugin')} enabled · ${plural(inv.mcp.length, 'MCP server')}`);
|
|
95
|
+
if (c.duplicates) out.push(` ${plural(c.duplicates, 'item')} installed twice under the same name (counted once)`);
|
|
96
|
+
const perTurn = inv.perTurnTokens.skills + inv.perTurnTokens.agents;
|
|
97
|
+
if (perTurn) out.push(` Descriptions loaded into every turn: ~${k(perTurn)} tokens (skills ~${k(inv.perTurnTokens.skills)}, agents ~${k(inv.perTurnTokens.agents)}; estimated)`);
|
|
98
|
+
if (inv.usedSkills !== null && c.skills) out.push(` Skills used at least once: ${inv.usedSkills} of ${c.skills} (${pct(inv.usedSkills / c.skills)})`);
|
|
99
|
+
const posture = [];
|
|
100
|
+
if (inv.posture.dangerousModePromptSkipped) posture.push('the dangerous-mode confirmation prompt is turned off');
|
|
101
|
+
if (inv.posture.defaultModeBypass) posture.push('permissions are bypassed by default');
|
|
102
|
+
if (posture.length) out.push(` Settings: ${posture.join('; ')}`);
|
|
103
|
+
const inCode = inv.risks.filter((r) => r.inCode);
|
|
104
|
+
const inDocs = inv.risks.filter((r) => !r.inCode);
|
|
105
|
+
if (!inv.risks.length) out.push(' No risky patterns found in installed add-ons.');
|
|
106
|
+
else {
|
|
107
|
+
out.push(` Patterns worth a look: ${plural(inCode.length, 'in executable code', 'in executable code')} · ${plural(inDocs.length, 'in documentation', 'in documentation')}`);
|
|
108
|
+
const list = showAll ? inv.risks : inCode.slice(0, 10);
|
|
109
|
+
for (const r of list) out.push(` ${r.label.padEnd(48)} ${r.owner} (${r.inCode ? 'code' : 'docs'})`);
|
|
110
|
+
if (!showAll && inCode.length > 10) out.push(` … ${inCode.length - 10} more in code; --all lists everything`);
|
|
111
|
+
if (!showAll && inDocs.length) out.push(' Matches in documentation are often examples inside security skills; --all lists them.');
|
|
112
|
+
}
|
|
113
|
+
return out;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function spendSection(cost) {
|
|
117
|
+
const out = ['SPEND — where your agent spend concentrates'];
|
|
118
|
+
if (!cost.episodes) return [...out, ' No usage data found.'];
|
|
119
|
+
out.push(` ${usd(cost.total)} across ${plural(cost.episodes, 'episode')} (API list prices of ${PRICES_DATE}; on a subscription this is a unit of effort, not a bill)`);
|
|
120
|
+
out.push(` Your costliest 10% of episodes (${cost.topN}) account for ${pct(cost.topShare)} of it · typical episode ${usd(cost.p50)} · 90th percentile ${usd(cost.p90)}`);
|
|
121
|
+
if (cost.worst.length) {
|
|
122
|
+
out.push(' Costliest episodes:');
|
|
123
|
+
for (const e of cost.worst) {
|
|
124
|
+
const dur = e.hours !== null && e.hours >= 1 ? ` · ${e.hours.toFixed(0)} h` : '';
|
|
125
|
+
out.push(` ${usd(e.cost).padStart(8)} ${e.date ?? ' '} ${plural(e.turns, 'turn')} · ${plural(e.tools, 'tool call')}${e.subagents ? ` · ${plural(e.subagents, 'subagent')}` : ''}${dur}`);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
if (cost.floor.sessions) out.push(` Fixed context per turn (median): ~${k(cost.floor.medianTokens)} tokens, ${pct(cost.floor.share)} of main-thread spend`);
|
|
129
|
+
if (cost.unknownModels.length) out.push(` Unknown models priced as mid-tier: ${cost.unknownModels.join(', ')}`);
|
|
130
|
+
return out;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
async function main() {
|
|
134
|
+
let opts;
|
|
135
|
+
try { opts = parseArgs(process.argv.slice(2)); } catch (e) { console.error(e.message); console.error(HELP); process.exit(2); }
|
|
136
|
+
if (opts.version) { console.log(pkg.version); return; }
|
|
137
|
+
if (opts.help || !opts.command) { console.log(HELP); return; }
|
|
138
|
+
if (opts.command !== 'audit') { console.error(`Unknown command: ${opts.command}\n\n${HELP}`); process.exit(2); }
|
|
139
|
+
|
|
140
|
+
const home = path.resolve(opts.home ?? os.homedir());
|
|
141
|
+
const root = path.resolve(opts.path ?? (opts.home ? path.join(home, '.claude', 'projects') : defaultRoot()));
|
|
142
|
+
if (!fs.existsSync(root)) { console.error(`No transcripts folder at ${root}. Use --path to point to one.`); process.exit(1); }
|
|
143
|
+
|
|
144
|
+
const t0 = Date.now();
|
|
145
|
+
const files = listTranscripts(root);
|
|
146
|
+
const bytes = files.reduce((n, f) => n + fs.statSync(f).size, 0);
|
|
147
|
+
const rules = loadRules();
|
|
148
|
+
const [secrets, cost] = await runAnalyzers({ root, files, analyzers: [createSecretsAnalyzer(rules), createCostAnalyzer()] });
|
|
149
|
+
const inv = inventory({ home });
|
|
150
|
+
const ms = Date.now() - t0;
|
|
151
|
+
|
|
152
|
+
if (opts.json) {
|
|
153
|
+
console.log(JSON.stringify({ version: pkg.version, root, files: files.length, bytes, ms, rules: rules.meta, pricesDate: PRICES_DATE, secrets, load: inv, spend: cost }, null, 2));
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
const out = [`blackbrake audit · ${root}`, '', ...exposureSection(secrets, opts.all), '', ...loadSection(inv, opts.all), '', ...spendSection(cost)];
|
|
157
|
+
out.push('', '─'.repeat(78));
|
|
158
|
+
out.push(`Read ${plural(files.length, 'file')} (${fmtBytes(bytes)}) in ${(ms / 1000).toFixed(1)} s · 0 network connections · 0 files written`);
|
|
159
|
+
out.push(`blackbrake ${pkg.version} · ${rules.meta.count} detection rules from gitleaks (MIT) · secret values are never printed`);
|
|
160
|
+
console.log(out.join('\n'));
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
main().catch((e) => { console.error(e.stack ?? e.message); process.exit(1); });
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "blackbrake",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Local, read-only audit of AI coding agent transcripts: exposed secrets, risky add-ons and where your spend concentrates. No network, no writes, no dependencies.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"blackbrake": "bin/blackbrake.mjs"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"bin/",
|
|
11
|
+
"src/",
|
|
12
|
+
"vendor/gitleaks.rules.json",
|
|
13
|
+
"LICENSE",
|
|
14
|
+
"NOTICE",
|
|
15
|
+
"THIRD_PARTY_NOTICES",
|
|
16
|
+
"SECURITY.md",
|
|
17
|
+
"README.md"
|
|
18
|
+
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"test": "node --test",
|
|
21
|
+
"build:rules": "node scripts/build-rules.mjs"
|
|
22
|
+
},
|
|
23
|
+
"engines": {
|
|
24
|
+
"node": ">=20"
|
|
25
|
+
},
|
|
26
|
+
"publishConfig": {
|
|
27
|
+
"access": "public",
|
|
28
|
+
"provenance": true
|
|
29
|
+
},
|
|
30
|
+
"keywords": [
|
|
31
|
+
"ai-agents",
|
|
32
|
+
"claude-code",
|
|
33
|
+
"secrets",
|
|
34
|
+
"security",
|
|
35
|
+
"audit",
|
|
36
|
+
"local-first"
|
|
37
|
+
],
|
|
38
|
+
"license": "Apache-2.0",
|
|
39
|
+
"homepage": "https://blackbrake.dev",
|
|
40
|
+
"repository": {
|
|
41
|
+
"type": "git",
|
|
42
|
+
"url": "git+https://github.com/blackbrake-dev/blackbrake.git"
|
|
43
|
+
},
|
|
44
|
+
"bugs": {
|
|
45
|
+
"url": "https://github.com/blackbrake-dev/blackbrake/issues"
|
|
46
|
+
}
|
|
47
|
+
}
|