@chainpatrol/sdk 0.8.0 → 0.9.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.
@@ -0,0 +1,1689 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ var fs = require('fs');
5
+ var path = require('path');
6
+ var os = require('os');
7
+ var url = require('url');
8
+
9
+ // src/skill/content.ts
10
+ function buildSkillContent(version) {
11
+ return `---
12
+ name: chainpatrol
13
+ version: ${version}
14
+ description: |
15
+ ChainPatrol CLI assistant. Helps use the chainpatrol CLI tool: login via device
16
+ code flow, check auth status, list detection configs, list reports (including
17
+ customer-reported ones), run CLI commands, and run an organization
18
+ healthcheck across the detection / reviewing / blocklisting / takedown
19
+ pipeline.
20
+ Use when: "chainpatrol cli", "login to chainpatrol", "check detection configs",
21
+ "am I logged in", "list configs", "use the cli", "list reports",
22
+ "customer reports", "reports reported by customer", "find detection gaps",
23
+ "org healthcheck", "organization health check", "audit my org",
24
+ "what's wrong with org", "review org setup", "list orgs", "list organizations",
25
+ "get org", "get organization", "show org details", "org by slug",
26
+ "fetch org details", "org info",
27
+ "orgs with takedowns off", "automation off across orgs",
28
+ "which customers have X enabled", "service toggles by org",
29
+ "obligatory admin approval", "obligatory organization admin approval",
30
+ "obligatory approval", "admin approval enabled", "admin approval orgs",
31
+ "requires customer review", "requires admin approval",
32
+ "orgs that require admin approval", "orgs requiring approval",
33
+ "which orgs require approval for twitter", "approval scope",
34
+ "admin approval asset types", "approval per asset type",
35
+ "pending approval", "pending approvals", "pending service approval",
36
+ "orgs with pending approval", "pending wallet blocking approval",
37
+ "pending takedown approval", "awaiting approval", "waiting for approval",
38
+ "is protection active approval", "wallet blocking approval",
39
+ "who needs to approve wallet blocking", "service change request",
40
+ "track orgs with pending approval", "orgs awaiting sign-off",
41
+ "is this URL blocked", "is this domain blocked", "is this address blocked",
42
+ "check this asset", "asset check", "lookup asset status",
43
+ "what is ARCHIVE_ORG", "what does PAGE mean", "list asset types",
44
+ "supported asset types", "asset type mapping", "asset type enum",
45
+ "what asset types are there", "human readable asset type",
46
+ "how many takedowns", "takedowns in the last", "threats taken down",
47
+ "across all clients", "across all customers", "across all orgs",
48
+ "across all brands", "company-wide", "total takedowns", "total threats",
49
+ "total reports", "average takedowns", "average threats", "average per day",
50
+ "average per customer", "average per org", "rollup across customers",
51
+ "sum across orgs", "sum across customers",
52
+ "trends in org", "search for trends", "trend search", "look for trends",
53
+ "any trends", "trending threats", "spike in asset type",
54
+ "spike in threat volume", "coordinated attack", "spike check",
55
+ "anything unusual", "anything new for", "what's new for",
56
+ "employee being targeted", "spike on a sub-brand", "spike on a brand",
57
+ "sub-brand spike",
58
+ "list brands", "brands for org", "list sub-brands", "employee brands",
59
+ "individual brands", "brand list", "all brands in org".
60
+ allowed-tools:
61
+ - Bash
62
+ - Read
63
+ - Grep
64
+ - Glob
65
+ ---
66
+
67
+ # ChainPatrol CLI Skill
68
+
69
+ You are a ChainPatrol CLI assistant. Help the user interact with the ChainPatrol
70
+ platform using the CLI tool.
71
+
72
+ ## Running the CLI
73
+
74
+ IMPORTANT: Claude Code's sandbox shell often has a minimal PATH
75
+ (\`/usr/bin:/bin:/usr/sbin:/sbin\`) that may not include the directory where
76
+ \`chainpatrol\` is installed, so bare \`chainpatrol\` calls may fail with
77
+ "command not found". Always invoke the CLI by its full path.
78
+
79
+ The install location depends on the environment:
80
+
81
+ - **Local installs** typically land at \`/usr/local/bin/chainpatrol\` (when
82
+ installed globally via \`npm install -g @chainpatrol/cli\`).
83
+ - **Cloud / sandboxed environments** (e.g. Claude Code on the web, Cursor
84
+ Cloud) often install Node into \`/opt\` and the binary ends up under a
85
+ Node-version-specific path like \`/opt/node22/bin/chainpatrol\`. Variants
86
+ such as \`/opt/node20/bin/chainpatrol\` or \`/opt/node21/bin/chainpatrol\`
87
+ are also possible depending on which Node version is active.
88
+
89
+ To find the binary, try (in order):
90
+
91
+ \`\`\`bash
92
+ command -v chainpatrol \\
93
+ || ls /usr/local/bin/chainpatrol /opt/node*/bin/chainpatrol 2>/dev/null \\
94
+ | head -n 1
95
+ \`\`\`
96
+
97
+ Then use that full path for every subsequent command, e.g.:
98
+
99
+ \`\`\`bash
100
+ /opt/node22/bin/chainpatrol <command> [options]
101
+ # or
102
+ /usr/local/bin/chainpatrol <command> [options]
103
+ \`\`\`
104
+
105
+ All examples below use the short name \`chainpatrol\` for readability, but you
106
+ MUST substitute the full resolved path in your Bash commands.
107
+
108
+ ## Available Commands
109
+
110
+ ### \`login\` \u2014 Authenticate with ChainPatrol
111
+
112
+ Uses the OAuth Device Code flow (RFC 8628):
113
+ 1. CLI requests a device code from the server
114
+ 2. User is shown a code and a URL to visit
115
+ 3. User authorizes in the browser
116
+ 4. CLI polls for the token
117
+
118
+ \`\`\`bash
119
+ chainpatrol login
120
+ \`\`\`
121
+
122
+ JSON mode (for automation):
123
+ \`\`\`bash
124
+ chainpatrol --json login
125
+ \`\`\`
126
+
127
+ #### Running \`login\` from an agent (headless / non-TTY)
128
+
129
+ The login flow blocks for up to 30 minutes while polling for the user to
130
+ authorize in their browser. If you (the agent) run it as a foreground
131
+ command and wait for it to exit before reading output, you will appear
132
+ stuck \u2014 the verification URL will never be shown because the process is
133
+ still polling.
134
+
135
+ **Always run \`login\` in the background and stream its output**, then
136
+ surface the verification URL to the user as soon as it appears:
137
+
138
+ \`\`\`bash
139
+ # 1. Kick off login in the background (do NOT wait for it to exit)
140
+ chainpatrol --json login > /tmp/cp-login.out 2>&1 &
141
+
142
+ # 2. Wait briefly for the first line, which contains the URL
143
+ for _ in 1 2 3 4 5 6 7 8 9 10; do
144
+ test -s /tmp/cp-login.out && break
145
+ sleep 1
146
+ done
147
+ cat /tmp/cp-login.out
148
+ \`\`\`
149
+
150
+ The first line emitted is JSON describing the device code, e.g.:
151
+
152
+ \`\`\`json
153
+ {"action":"open_url","user_code":"ABCD-1234","verification_uri":"https://app.chainpatrol.io/auth/verify-device","verification_uri_complete":"https://app.chainpatrol.io/auth/verify-device?user_code=ABCD-1234","expires_in":1800,"headless":true}
154
+ \`\`\`
155
+
156
+ Show the user the \`verification_uri_complete\` link (or
157
+ \`verification_uri\` + \`user_code\` as a fallback) and explain that the
158
+ CLI will pick up the token automatically once they authorize. Then keep
159
+ the background process running and tail it for the final
160
+ \`{"status":"success",...}\` or \`{"error":...}\` line.
161
+
162
+ CLI v0.3.3+ also auto-detects non-TTY stdout and prints the URL as plain
163
+ text immediately when you run \`chainpatrol login\` without \`--json\`,
164
+ so the same background+tail pattern works without \`--json\`. Prefer
165
+ \`--json\` so the output is structured and machine-parseable.
166
+
167
+ ### \`logout\` \u2014 Clear stored credentials
168
+
169
+ \`\`\`bash
170
+ chainpatrol logout
171
+ \`\`\`
172
+
173
+ ### \`asset check\` \u2014 Check one or many assets against the blocklist
174
+
175
+ Look up a URL, domain, or crypto address and return its aggregated status
176
+ (\`BLOCKED\`, \`ALLOWED\`, or \`UNKNOWN\`) plus a per-source breakdown
177
+ (ChainPatrol + external feeds like eth-phishing-detect, phishfort, seal,
178
+ polkadot-phishing). Works whether you're authenticated via device-code
179
+ login or via a \`CHAINPATROL_API_KEY\` env var.
180
+
181
+ Single asset:
182
+
183
+ \`\`\`bash
184
+ chainpatrol asset check https://phish.example
185
+ chainpatrol asset check 0xabc123...
186
+ \`\`\`
187
+
188
+ #### Bulk checks (preferred for >1 asset)
189
+
190
+ Pass multiple assets in a single invocation \u2014 the CLI runs them in
191
+ parallel (concurrency 10) and returns one row per asset. **Do this
192
+ instead of looping the CLI in a shell \`for\` loop**: one process, one
193
+ auth handshake, parallel HTTP. Use either positional args or repeated
194
+ \`--asset\`:
195
+
196
+ \`\`\`bash
197
+ # positional form
198
+ chainpatrol asset check a.example b.example c.example
199
+
200
+ # repeated --asset (handy when content has spaces or special chars)
201
+ chainpatrol asset check --asset a.example --asset b.example
202
+
203
+ # from a file of one-asset-per-line (use xargs to splat into one call)
204
+ xargs -a domains.txt chainpatrol asset check
205
+ \`\`\`
206
+
207
+ JSON mode is the agent-friendly default \u2014 single-asset JSON keeps the
208
+ flat \`{ content, status, source, reason?, sources[], watchStatus? }\`
209
+ shape; multi-asset JSON returns \`{ results: [...], summary: { checked,
210
+ blocked, allowed, unknown, errored } }\`:
211
+
212
+ \`\`\`bash
213
+ chainpatrol --json asset check https://phish.example
214
+ chainpatrol --json asset check a.example b.example c.example
215
+ \`\`\`
216
+
217
+ Markdown / CSV are also available for sharing in docs / chat:
218
+
219
+ \`\`\`bash
220
+ chainpatrol asset check phish.example --output markdown
221
+ chainpatrol asset check a.example b.example --output csv
222
+ \`\`\`
223
+
224
+ If any individual lookup fails, the CLI still prints results for the
225
+ successful ones, then exits non-zero so failures aren't silently
226
+ swallowed.
227
+
228
+ ### \`asset types\` \u2014 List every supported asset type and what it means
229
+
230
+ When a user asks "what is \`ARCHIVE_ORG\`?", "what does \`PAGE\` mean?",
231
+ or "what asset types does ChainPatrol support?" \u2014 don't guess. Run:
232
+
233
+ \`\`\`bash
234
+ chainpatrol asset types
235
+ chainpatrol --json asset types
236
+ \`\`\`
237
+
238
+ The mapping is bundled with the CLI (no API or auth required), so this
239
+ is safe to run anywhere. Each row is \`{ type, label, description }\`:
240
+ \`type\` is the canonical enum value used by every \`--asset-type\` flag
241
+ (\`asset list\`, \`threats list\`, \`takedowns list\`, \`detections list\`,
242
+ \`reports list\`, \`orgs assets list\`); \`label\` is the human-friendly
243
+ display name (\`ARCHIVE_ORG\` \u2192 \`Archive.org\`, \`PAGE\` \u2192 \`Page\`,
244
+ \`FIVE_HUNDRED_PX\` \u2192 \`500px\`); \`description\` is a one-line note for
245
+ unobvious entries.
246
+
247
+ Use this whenever you need to translate between enum and display name,
248
+ validate that a type the user mentioned is real, or enumerate options
249
+ before constructing a filter.
250
+
251
+ ### \`configs list\` \u2014 List detection configurations
252
+
253
+ Requires authentication and an organization slug.
254
+
255
+ \`\`\`bash
256
+ chainpatrol configs list --org <slug>
257
+ \`\`\`
258
+
259
+ JSON mode:
260
+ \`\`\`bash
261
+ chainpatrol --json configs list --org <slug>
262
+ \`\`\`
263
+
264
+ The \`--org\` flag is saved for future commands. Once set, you can omit it:
265
+ \`\`\`bash
266
+ chainpatrol configs list
267
+ \`\`\`
268
+
269
+ ### \`reports list\` \u2014 List recent reports for an organization
270
+
271
+ Returns the most recent reports submitted for an organization. Each report
272
+ includes a \`reportedByCustomer\` boolean indicating whether the report was
273
+ submitted by a customer of ChainPatrol (e.g. via API key, Slack/Telegram bot,
274
+ or another external integration) rather than by ChainPatrol's automated
275
+ detections or staff reviewers.
276
+
277
+ \`\`\`bash
278
+ chainpatrol reports list --org <slug>
279
+ \`\`\`
280
+
281
+ Common flags:
282
+ - \`--limit <n>\` page size (1-20)
283
+ - \`--cursor <id>\` pagination cursor (use \`nextCursor\` from a previous response)
284
+ - \`--status <s>\` filter by report status (e.g. \`TODO\`, \`IN_PROGRESS\`, \`DONE\`)
285
+ - \`--search <q>\` search query across title/description/asset content
286
+ - \`--reported-by-customer\` only show reports submitted by a customer
287
+ - \`--no-reported-by-customer\` only show reports NOT submitted by a customer
288
+ (i.e. found by ChainPatrol's automation or staff)
289
+
290
+ JSON mode is recommended when you want to analyze the data programmatically:
291
+ \`\`\`bash
292
+ chainpatrol --json reports list --org <slug> --reported-by-customer
293
+ \`\`\`
294
+
295
+ The response includes \`totalCount\`: the number of reports matching the same
296
+ filters as the query, independent of \`--limit\`/\`--cursor\`. Use it to:
297
+ - Report a denominator when sampling (e.g. "sampled 200 of ~4,235").
298
+ - Decide up front whether to page through everything or narrow filters first \u2014
299
+ if \`totalCount\` is huge, add more filters instead of paginating blindly.
300
+ - Drive a progress indicator while paginating with \`nextCursor\`.
301
+
302
+ \`totalCount\` honors every list filter (\`--status\`, \`--reported-by-customer\` /
303
+ \`--no-reported-by-customer\`, \`--exclude-automation\`, \`--review-status\` /
304
+ \`--only-rejected\`, \`--asset-type\`, brand, \`--country-code\`, \`--from\`/\`--to\`,
305
+ \`--updated-from\`/\`--updated-to\`, \`--search\`, \`--reporter-query\`), so changing
306
+ filters changes the count. \`reports\` (the returned page) is capped by
307
+ \`--limit\` (max 20); \`totalCount\` is not.
308
+
309
+ #### Use case: finding gaps in ChainPatrol detection
310
+
311
+ Customer-reported reports (\`reportedByCustomer=true\`) are a valuable signal
312
+ for finding gaps in ChainPatrol's automated detections and staff triage: each
313
+ one is a threat the customer found before ChainPatrol's own systems did. When
314
+ the user asks something like:
315
+
316
+ - "show me the threats our customers are reporting"
317
+ - "what is X's customer reporting?"
318
+ - "where are we missing detections for org Y?"
319
+ - "summarize recent reports submitted by customers"
320
+
321
+ \u2026use \`chainpatrol --json reports list --org <slug> --reported-by-customer\`
322
+ to fetch them, then highlight patterns (asset types, domains, common
323
+ keywords, recurring brands) so the user can:
324
+ 1. Spot detection coverage gaps to fix in the org's detection configs.
325
+ 2. Improve staff triage runbooks for recurring scams.
326
+ 3. Work directly with the customer to close the loop and prevent future
327
+ misses.
328
+
329
+ You can also compare with the non-customer set using
330
+ \`--no-reported-by-customer\` to gauge detection coverage on the same time
331
+ window.
332
+
333
+ ### \`detections healthcheck\` \u2014 Validate enabled detection configs produce recent results
334
+
335
+ Server-side check. The CLI calls the ChainPatrol API; the server fetches each
336
+ enabled detection config for the org, counts results produced in the lookback
337
+ window, and FAILs configs that fall under \`--min-results\` (or whose run
338
+ errored when \`--run\` is set).
339
+
340
+ \`\`\`bash
341
+ chainpatrol --json detections healthcheck --org <slug>
342
+ \`\`\`
343
+
344
+ Flags:
345
+ - \`--source <key>\` only validate one source (e.g. \`twitter_search\`)
346
+ - \`--min-results <n>\` minimum results required in the window to pass
347
+ - \`--lookback-hours <n>\` size of the lookback window
348
+ - \`--run\` ask the server to run each config first, then validate the fresh output
349
+ - \`--include-disabled\` also validate disabled configs
350
+
351
+ What this command covers:
352
+ - Configs that have gone silent (recentResultCount below threshold)
353
+ - Configs that error when run (runOk=false) when \`--run\` is set
354
+
355
+ What it does NOT cover:
356
+ - Reviewing backlog / SLA breaches \u2192 use \`queues snapshot\`
357
+ - Takedown ToDo / In Progress / Cancelled volumes \u2192 use \`queues snapshot\`
358
+ - Spikes or drops in detection volume over time \u2192 use \`metrics breakdown\`
359
+ - Customer-reported gaps \u2192 use \`reports list --reported-by-customer\`
360
+ - Google Safe Browsing submission errors (not yet exposed in CLI)
361
+
362
+ Use it as the first signal in the Detection part of an org healthcheck, then
363
+ fall back to the manual checks in the HealthCheck Guide below for everything
364
+ else.
365
+
366
+ > Prefer the newer \`healthchecks\` namespace below. \`detections healthcheck\`
367
+ > is the original single-purpose command; the \`healthchecks\` namespace is
368
+ > the canonical place to discover and run every check we expose.
369
+
370
+ ### \`healthchecks list | run\` \u2014 Run uniform org healthchecks via the public API
371
+
372
+ The \`healthchecks\` namespace is the canonical way to run the named checks
373
+ from the Organization HealthCheck Guide below. Each implemented endpoint
374
+ returns the same uniform shape \u2014 \`{ id, ok, severity, observed, threshold,
375
+ findings, suggestedAction }\` \u2014 so the CLI / agent can render every check the
376
+ same way regardless of category.
377
+
378
+ \`\`\`bash
379
+ # Discover every check the platform exposes today, including planned checks
380
+ # that are not yet implemented on the backend.
381
+ chainpatrol --json healthchecks list
382
+
383
+ # Run a single named check.
384
+ chainpatrol --json healthchecks run reviewing.backlog --org <slug>
385
+
386
+ # Run every implemented check in parallel and aggregate the results.
387
+ chainpatrol --json healthchecks run --all --org <slug>
388
+ \`\`\`
389
+
390
+ Each implemented check has a stable id of the form \`category.name\`. Implemented
391
+ ids today: \`detections.silent-configs\`, \`reviewing.backlog\`,
392
+ \`reviewing.old-proposals\`, \`reviewing.watchlist-backlog\`,
393
+ \`reviewing.watchlist-old\`, \`takedowns.todo-volume\`,
394
+ \`takedowns.in-progress-volume\`, \`takedowns.stale-in-progress\`,
395
+ \`takedowns.cancelled-count\`, \`takedowns.automation-off\`,
396
+ \`assets.dead-asset-spike\`.
397
+
398
+ ### Pending proposals: "Needs Review" vs "Watchlisted"
399
+
400
+ PENDING proposals split into two operationally distinct buckets, and we
401
+ grade them with separate checks:
402
+
403
+ - **Needs Review** \u2014 pending proposals the reviewing UI shows by default
404
+ (\`excludeWatchlisted=true\`): assets that are NOT on a watchlist, OR
405
+ reports submitted by a customer (those stay visible even when the asset
406
+ is watchlisted). This is the actionable queue reviewers work from, so
407
+ pile-ups and old items here are high-priority signals (\`fail\` severity
408
+ is reachable).
409
+ - **Watchlisted** \u2014 pending proposals on watchlisted assets (excluding
410
+ customer-reported reports). The reviewing UI hides these by default
411
+ because watchlisting is the act of intentionally deferring an asset.
412
+ Pile-ups and aged items here are worth surfacing as cleanup work, but
413
+ severity is **capped at warn** so they never block on the same SLA as
414
+ Needs Review. When reporting findings, treat these as lower-priority.
415
+
416
+ Each healthcheck result includes an \`appUrl\` field (string or null) that
417
+ deep-links to the relevant filtered admin page in the web app \u2014 e.g. the
418
+ takedowns page filtered to IN_PROGRESS for \`takedowns.stale-in-progress\`,
419
+ or the review page filtered to oldest pending for \`reviewing.old-proposals\`.
420
+ **When reporting a non-OK healthcheck to the user, always surface the
421
+ \`appUrl\` so they can jump straight to the right view.** Some checks
422
+ (\`detections.silent-configs\`, \`assets.dead-asset-spike\`) emit \`null\`
423
+ because no filterable list page exists for that signal yet.
424
+
425
+ Implemented checks today:
426
+
427
+ - **detections.silent-configs** \u2014 equivalent to \`detections healthcheck\`,
428
+ exposed under the uniform shape.
429
+ - **reviewing.backlog** \u2014 counts Needs Review pending proposals and grades
430
+ severity against per-org thresholds (default warn=50, fail=100).
431
+ - **reviewing.old-proposals** \u2014 counts Needs Review proposals older than
432
+ the warn / fail age thresholds (default 7 / 14 days) and lists the
433
+ oldest offenders.
434
+ - **reviewing.watchlist-backlog** \u2014 counts watchlisted pending proposals
435
+ (default warn=200). Severity capped at warn.
436
+ - **reviewing.watchlist-old** \u2014 counts watchlisted pending proposals older
437
+ than the warn-age threshold (default 30 days) and lists the oldest.
438
+ Severity capped at warn.
439
+ - **takedowns.todo-volume** \u2014 counts takedowns in TODO (default warn=50,
440
+ fail=100). Pile-ups here usually mean an automation gap on a new threat
441
+ surface, or manual-filing capacity issues.
442
+ - **takedowns.in-progress-volume** \u2014 counts takedowns currently IN_PROGRESS
443
+ regardless of age (default warn=30, fail=75). Complements
444
+ \`stale-in-progress\` \u2014 a high count signals vendor-side or
445
+ submission-format problems even before items go stale.
446
+ - **takedowns.stale-in-progress** \u2014 counts takedowns sitting in IN_PROGRESS
447
+ past the staleness threshold (default 7 days) and lists the oldest.
448
+ - **takedowns.cancelled-count** \u2014 counts CANCELLED transitions from the
449
+ TakedownEvent log over a rolling window (default 7d, warn=3, fail=10).
450
+ Cancellations should be rare; a spike usually means a proposal-funnel
451
+ quality problem or misuse of the CANCELLED status.
452
+ - **takedowns.automation-off** \u2014 flags orgs with takedown service enabled
453
+ but \`isAutomatedTakedownsActive\` off for too long (default warn=30d,
454
+ fail=60d). Skipped for orgs with takedown service entirely disabled.
455
+ - **assets.dead-asset-spike** \u2014 compares DEAD-detection events in the
456
+ current window against the prior baseline rate; warns on a multiplier
457
+ exceeding the threshold (default 24h vs 7d, \xD72 warn / \xD74 fail) once the
458
+ current count clears the \`minSpikeCount\` floor. Catches liveness-checker
459
+ regressions after platform changes.
460
+
461
+ The following checks are listed by \`healthchecks list\` (\`implemented: false\`)
462
+ but **not yet implemented on the backend** \u2014 when the agent surfaces them in
463
+ a healthcheck report, mark them explicitly as "manual check, no API yet":
464
+
465
+ - **detections.coverage-gaps** \u2014 blocked assets vs. enabled-source correlation.
466
+ Still requires manual reasoning with \`configs list\` + \`reports list\`.
467
+ - **detections.spike** / **detections.drop** \u2014 require server-side baseline
468
+ modeling. Use \`metrics breakdown --by day\` as an interim signal.
469
+ - **reviewing.auto-approval-spike** \u2014 needs distinguishing automation vs.
470
+ human approvers in the review history. Use \`metrics breakdown\` as a proxy.
471
+ - **blocklisting.gsb-cancelled-rate** \u2014 Google Safe Browsing submission state
472
+ is not yet exposed in the public API.
473
+ - **assets.dead-but-alive** / **assets.alive-but-marked-dead** \u2014 require live
474
+ HTTP probes against asset URLs, which is not a synchronous-healthcheck
475
+ shape. Until a dedicated probe command exists, sample a handful manually
476
+ from \`assets list --status DEAD\` (or ALIVE) and verify in a browser. Notify
477
+ ChainPatrol engineering if the liveness checker looks miscalibrated.
478
+
479
+ When the user asks to "run a healthcheck on org X", the canonical command is:
480
+
481
+ \`\`\`bash
482
+ chainpatrol --json healthchecks run --all --org X
483
+ \`\`\`
484
+
485
+ This iterates the implemented entries in \`healthchecks list\`, runs them in
486
+ parallel, and aggregates the uniform results. Combine with the manual checks
487
+ in the HealthCheck Guide below for everything still marked
488
+ \`implemented: false\`.
489
+
490
+ ### \`queues snapshot\` \u2014 Operations review/takedown queue snapshot
491
+
492
+ Server-side aggregation of the operations review queue (pending proposals,
493
+ SLA breaches, age buckets) and the takedown queue (open, in-progress, stale).
494
+
495
+ \`\`\`bash
496
+ chainpatrol --json queues snapshot --org <slug>
497
+ \`\`\`
498
+
499
+ Useful for the **Reviewing** and **Takedowns** sections of the HealthCheck
500
+ Guide. Key signals in the response:
501
+ - \`reviewQueue.totalPendingProposals\` and \`reviewQueue.distinctReports\` \u2014
502
+ backlog size
503
+ - \`reviewQueue.slaBuckets.breached\` \u2014 SLA breaches (treat any breach as a
504
+ finding)
505
+ - \`reviewQueue.ageBuckets.gte168h\` \u2014 proposals older than 7 days (anything
506
+ >14 days from the manual guide should always be in here)
507
+ - \`takedownQueue.totalOpen\` and \`takedownQueue.staleInProgress\` \u2014 open
508
+ and stuck takedowns
509
+
510
+ Use \`--all\` to snapshot every org you have access to instead of a single slug.
511
+
512
+ ### \`orgs list\` \u2014 List organizations with subscription status, service toggles, and admin-approval scope
513
+
514
+ Returns every organization the caller can see, with each org's
515
+ subscription status (\`PROSPECT\`, \`TRIAL\`, \`ACTIVE\`, \`INTEGRATION\`),
516
+ which services are active, and the per-org "Obligatory Organization
517
+ Admin Approval" toggle (with its asset-type scope). Use it to answer
518
+ questions like "which customers have takedowns enabled but automation
519
+ off?", "which prospects don't have detection turned on yet?", or "which
520
+ orgs require admin approval before adding Twitter assets to the
521
+ blocklist?" \u2014 filters compose with AND and are applied server-side, so
522
+ one call returns the final list.
523
+
524
+ \`\`\`bash
525
+ chainpatrol --json orgs list \\
526
+ --subscription-status ACTIVE \\
527
+ --service-active takedowns \\
528
+ --service-manual takedowns
529
+ \`\`\`
530
+
531
+ #### Per-service response shape \u2014 \`automated\` is takedowns-only
532
+
533
+ Every service exposes an \`active\` boolean. **Only \`takedowns\`
534
+ additionally exposes \`automated\`** \u2014 that is the one service where the
535
+ manual-vs-automated distinction changes real platform behavior (whether
536
+ ChainPatrol files the takedown on its own, or queues it for a human to
537
+ file). \`reporting\`, \`reviewing\`, and \`protection\` have backing
538
+ \`isAutomated*Active\` columns in the database, but those flags have no
539
+ operational effect today, so the API deliberately omits them from both
540
+ the response and the \`services\` filter \u2014 surfacing them would invite
541
+ misleading filters like "reporting.automated=true" that don't mean
542
+ anything. \`detection\` and \`darkWebMonitoring\` have always been
543
+ single-flag services.
544
+
545
+ #### Obligatory Organization Admin Approval
546
+
547
+ Each org also has a separate "Obligatory Organization Admin Approval"
548
+ toggle (\`Organization.requiresCustomerReview\` in the schema, surfaced
549
+ on the Services settings page in the app) that gates customer-side
550
+ review of proposals ChainPatrol staff have already approved before
551
+ they're added to the blocklist. It is NOT one of the operational
552
+ services above \u2014 it is an org-policy toggle with its own per-asset-type
553
+ scope.
554
+
555
+ Each org's response includes:
556
+
557
+ \`\`\`json
558
+ {
559
+ "obligatoryAdminApproval": {
560
+ "active": true,
561
+ "assetTypes": ["TWITTER", "URL"]
562
+ }
563
+ }
564
+ \`\`\`
565
+
566
+ - \`active=true\` + empty \`assetTypes\` means approval applies to
567
+ **all** asset types \u2014 the org has not narrowed the scope.
568
+ - \`active=true\` + a non-empty \`assetTypes\` list means approval is
569
+ required only for those asset types.
570
+ - \`active=false\` means no approval is required; \`assetTypes\` is
571
+ always empty in that case.
572
+
573
+ So per-org JSON looks like:
574
+
575
+ \`\`\`json
576
+ {
577
+ "services": {
578
+ "reporting": { "active": true },
579
+ "reviewing": { "active": true },
580
+ "protection": { "active": false },
581
+ "takedowns": { "active": true, "automated": false },
582
+ "detection": { "active": true },
583
+ "darkWebMonitoring": { "active": false }
584
+ },
585
+ "obligatoryAdminApproval": { "active": true, "assetTypes": ["TWITTER"] },
586
+ "pendingServiceApprovals": [
587
+ {
588
+ "service": "protection",
589
+ "automated": false,
590
+ "serviceType": "isProtectionActive",
591
+ "serviceName": "Wallet Blocking",
592
+ "requestedAt": "2026-05-30T18:04:11.000Z"
593
+ }
594
+ ]
595
+ }
596
+ \`\`\`
597
+
598
+ #### Pending service approvals (Wallet Blocking / Takedowns)
599
+
600
+ Turning on **Wallet Blocking** (\`protection\`, the "is protection active"
601
+ toggle) or **Takedowns** is approval-gated: when a lower-level org member
602
+ tries to enable one, ChainPatrol records a pending request that a higher-up
603
+ at the org \u2014 an org OWNER, or ChainPatrol staff acting as owner \u2014 must
604
+ approve before the service actually turns on. \`pendingServiceApprovals\`
605
+ lists those open, awaiting-sign-off requests per org.
606
+
607
+ This is the answer to "which organizations have a pending approval for
608
+ Wallet blocking or Takedown services?" \u2014 it is NOT the same as "which orgs
609
+ have Wallet Blocking turned off". An org can have \`protection.active=false\`
610
+ with **no** pending approval (nobody has asked) OR **with** a pending
611
+ approval (someone asked and it's waiting on an owner). Only
612
+ \`pendingServiceApprovals\` distinguishes the two.
613
+
614
+ Each entry:
615
+
616
+ - \`service\` \u2014 \`protection\` (Wallet Blocking) or \`takedowns\`, matching the
617
+ \`services\` keys.
618
+ - \`automated\` \u2014 \`true\` when the request is for the automated variant
619
+ (e.g. "Automated Wallet Blocking").
620
+ - \`serviceType\` \u2014 raw enum, e.g. \`isProtectionActive\`.
621
+ - \`serviceName\` \u2014 human label, e.g. \`Wallet Blocking\`.
622
+ - \`requestedAt\` \u2014 when the enable request was submitted (ISO 8601, UTC).
623
+
624
+ An **empty array means nothing is awaiting approval** \u2014 read \`services\` for
625
+ the current on/off state, never infer it from this field.
626
+
627
+ When a user asks about "automated reporting / reviewing / protection",
628
+ explain that the flag exists in the DB but has no operational effect and
629
+ isn't exposed by the public API \u2014 only \`takedowns.automated\` carries a
630
+ real meaning.
631
+
632
+ Filter flags (all optional, all comma-separated lists where noted):
633
+
634
+ - \`--query <text>\` partial name match (substring, case-insensitive)
635
+ - \`--subscription-status <list>\` one or more of \`PROSPECT\`, \`TRIAL\`,
636
+ \`ACTIVE\`, \`INTEGRATION\`. \`INACTIVE\` is intentionally not reachable
637
+ through this filter \u2014 \`orgs list\` only ever returns live customers.
638
+ - \`--service-active <list>\` services that must be active
639
+ - \`--service-inactive <list>\` services that must be inactive
640
+ - \`--service-automated <list>\` services whose automation must be ON.
641
+ **Only \`takedowns\` is accepted** \u2014 the other services don't have a
642
+ meaningful automation toggle. Passing any other service name errors out.
643
+ - \`--service-manual <list>\` services whose automation must be OFF.
644
+ Same restriction \u2014 only \`takedowns\`.
645
+ - \`--obligatory-approval-active\` \u2014 only orgs with admin approval on
646
+ - \`--obligatory-approval-inactive\` \u2014 only orgs with admin approval off
647
+ - \`--obligatory-approval-asset-type <list>\` \u2014 only orgs whose admin
648
+ approval scope covers EVERY listed asset type. The match treats an
649
+ org's empty per-asset-type list as "applies to all asset types", so a
650
+ fully-broad org matches every value passed here. Passing this flag
651
+ implies the feature is on, so it can't be combined with
652
+ \`--obligatory-approval-inactive\`. Use the canonical asset-type enum
653
+ names (\`TWITTER\`, \`URL\`, \`PAGE\`, \u2026); run \`chainpatrol asset types\`
654
+ to see them all.
655
+ - \`--pending-approval-active\` \u2014 only orgs with at least one open
656
+ service-enable approval awaiting a higher-up's sign-off.
657
+ - \`--pending-approval-inactive\` \u2014 only orgs with no pending approvals.
658
+ - \`--pending-approval-service <list>\` \u2014 only orgs with a pending approval
659
+ for one of the listed services. Accepts \`protection\` (Wallet Blocking)
660
+ and/or \`takedowns\` \u2014 those are the only approval-gated services.
661
+ Matches both the manual and automated variant. Passing this flag implies
662
+ a pending approval exists, so it can't be combined with
663
+ \`--pending-approval-inactive\`.
664
+
665
+ Service names: \`reporting\`, \`reviewing\`, \`protection\`, \`takedowns\`,
666
+ \`detection\`, \`darkWebMonitoring\`.
667
+
668
+ Customers see only orgs they're a member of. Staff/superuser sessions see
669
+ every matching org. The response is the same in both cases; visibility is
670
+ enforced server-side.
671
+
672
+ #### Use case: finding which orgs require admin approval for an asset type
673
+
674
+ When a user asks "which orgs require admin approval before blocking
675
+ Twitter assets?", reach straight for the filter \u2014 no client-side
676
+ post-processing needed:
677
+
678
+ \`\`\`bash
679
+ chainpatrol --json orgs list --obligatory-approval-asset-type TWITTER
680
+ \`\`\`
681
+
682
+ To audit just the broad opt-ins ("which orgs require approval for
683
+ everything?"), filter on the toggle and inspect \`assetTypes\` in the
684
+ output \u2014 an empty array means "all":
685
+
686
+ \`\`\`bash
687
+ chainpatrol --json orgs list --obligatory-approval-active \\
688
+ | jq '.organizations[] | select(.obligatoryAdminApproval.assetTypes | length == 0) | .slug'
689
+ \`\`\`
690
+
691
+ #### Use case: tracking orgs with a pending Wallet Blocking / Takedown approval
692
+
693
+ When a user asks "which organizations have a pending approval for Wallet
694
+ blocking or Takedown services?", do NOT reach for \`--service-inactive
695
+ protection\` \u2014 that lists orgs with the service turned OFF, which is a
696
+ different question. Use the pending-approval filter, which surfaces
697
+ staff-initiated enable requests still waiting on a higher-up:
698
+
699
+ \`\`\`bash
700
+ # Every org with a pending Wallet Blocking OR Takedown approval:
701
+ chainpatrol --json orgs list --pending-approval-service protection,takedowns
702
+
703
+ # Just Wallet Blocking:
704
+ chainpatrol --json orgs list --pending-approval-service protection
705
+
706
+ # Any pending approval at all, then read each org's pendingServiceApprovals:
707
+ chainpatrol --json orgs list --pending-approval-active \\
708
+ | jq '.organizations[] | {slug, pending: [.pendingServiceApprovals[].serviceName]}'
709
+ \`\`\`
710
+
711
+ ### \`orgs get\` \u2014 Get a single organization by slug
712
+
713
+ Look up one organization the caller has access to. Returns the same per-org
714
+ shape as a single row from \`orgs list\` \u2014 \`active\` for every service,
715
+ plus \`automated\` on \`takedowns\` only (see the note above on why other
716
+ services don't expose an automation flag), plus \`obligatoryAdminApproval\`
717
+ (\`active\` + \`assetTypes\`) and \`pendingServiceApprovals\` (open Wallet
718
+ Blocking / Takedown enable requests awaiting a higher-up's sign-off).
719
+ Anything you could read from \`orgs list\` you can also read here without
720
+ paging or filtering. Use it when the user names a specific customer ("show
721
+ me acme's setup", "is takedowns automation on for morpho?", "does this org
722
+ require admin approval for Twitter?", "is morpho waiting on a Wallet
723
+ Blocking approval?") and you don't need the rest of the catalogue.
724
+
725
+ \`\`\`bash
726
+ chainpatrol orgs get <slug>
727
+ chainpatrol --json orgs get <slug>
728
+ \`\`\`
729
+
730
+ Permission rules match \`orgs list\`:
731
+
732
+ - Org-scoped API keys: must match the slug \u2014 querying another org returns
733
+ 403.
734
+ - User sessions / user-scoped API keys: need an active OrganizationMembership
735
+ on the slug. Staff/superusers can read any org.
736
+ - Soft-deleted orgs are not returned (404). A 404 also fires for orgs the
737
+ caller would not be authorized to see \u2014 the endpoint deliberately does
738
+ not distinguish "doesn't exist" from "you can't see this" beyond the
739
+ generic 403/404 envelope.
740
+
741
+ Prefer \`orgs get\` over \`orgs list\` + client-side filter whenever the
742
+ caller already knows the slug; it's one round-trip and side-steps the
743
+ list filters entirely.
744
+
745
+ #### Use case: finding service configuration gaps across the customer base
746
+
747
+ When the user asks something like "which customers are paying us but don't
748
+ have takedowns automated yet?" or "any orgs running detection without
749
+ takedowns?", reach for \`orgs list\` \u2014 it's the only command that exposes
750
+ service flags across multiple orgs in one call. Run it in \`--json\` mode
751
+ and summarize patterns by service or by subscription tier.
752
+
753
+ ### \`brands list\` \u2014 List the brands (sub-brands) belonging to an org
754
+
755
+ Returns every brand for the org the caller is authenticated as, both
756
+ parent / product brands (\`type: "ORGANIZATION"\`) and individual /
757
+ employee brands (\`type: "INDIVIDUAL"\`). Soft-deleted brands are excluded.
758
+ The endpoint is org-scoped and inferred from auth \u2014 there's no \`--org\`
759
+ flag \u2014 so org-scoped API keys, user API keys, and user sessions all work
760
+ without extra arguments.
761
+
762
+ \`\`\`bash
763
+ chainpatrol brands list # all brands
764
+ chainpatrol brands list --type INDIVIDUAL # employee / person brands only
765
+ chainpatrol brands list --type ORGANIZATION # product / parent brands only
766
+ chainpatrol --json brands list # machine-readable
767
+ \`\`\`
768
+
769
+ Each entry has \`{ id, slug, name, type, description, brandGroupId, createdAt }\`.
770
+ Use this when you need to:
771
+
772
+ - Distinguish employee vs. product brands ahead of time \u2014 e.g. while
773
+ running a trend search and you want to highlight which spiking
774
+ sub-brands are employees so the user gets a direct heads-up to the
775
+ person involved.
776
+ - Resolve a brand name the user mentions to its \`slug\` for use with
777
+ \`metrics organization --brand-slug <slug>\` or as a \`brandId\` for
778
+ \`takedowns list --brand <id>\`.
779
+ - Audit a customer's setup \u2014 "how many employee brands does this org
780
+ protect?" or "are there brands the org set up but never wired into a
781
+ detection config?"
782
+
783
+ ### \`metrics summary | found | breakdown | organization\` \u2014 Org metrics for spike/drop analysis
784
+
785
+ #### Decision rule \u2014 read this before picking a metrics subcommand
786
+
787
+ When the user asks for a number that **spans more than one customer/org/brand**
788
+ \u2014 phrases like "across all clients", "across all customers", "across all orgs",
789
+ "across all brands", "company-wide", "total takedowns", "total threats",
790
+ "average takedowns per day across customers", "rollup across customers",
791
+ "how many takedowns in the last 7 days?" (no org named) \u2014 the answer is
792
+ **\`chainpatrol metrics organization --all-my-orgs\`** (or \`--slugs\`
793
+ if you want a specific subset). \`summary\`, \`found\`, and \`breakdown\`
794
+ are single-org commands and have **no** \`--slugs\`/\`--all-my-orgs\`
795
+ form; only \`organization\` does. The multi-org form rolls totals +
796
+ per-day / per-org-per-day averages + a per-org breakdown server-side
797
+ in **one** HTTP call.
798
+
799
+ **Anti-patterns to avoid:**
800
+
801
+ - \u274C "There's no cross-org aggregation in the CLI." There is \u2014
802
+ \`metrics organization --all-my-orgs\` (or \`--slugs\`). Don't bail
803
+ out citing the docs without trying these flags.
804
+ - \u274C Looping \`metrics summary --org X\` once per customer to sum
805
+ client-side. The multi-org form is one round-trip; the loop is what
806
+ made the endpoint 503-prone in the first place.
807
+ - \u274C Calling \`orgs list\` to build a slug list when you just want
808
+ "everything." Use \`--all-my-orgs\` and skip the enumeration entirely \u2014
809
+ the server resolves the same set via shared logic. Save \`orgs list\`
810
+ + \`--slugs\` for cases where the user asked for a specific subset.
811
+ - \u274C Routing the user to Metabase / the data warehouse for a question
812
+ the CLI can answer. Reach for Metabase only when the metric isn't
813
+ in the \`--include\` list (\`reports\`, \`newThreats\`,
814
+ \`threatsWatchlisted\`, \`takedownsFiled\`, \`takedownsCompleted\`,
815
+ \`domainThreats\`, \`twitterThreats\`, \`telegramThreats\`,
816
+ \`otherThreats\`, \`blockedByType\`, \`blockedByDay\`).
817
+ - \u274C "Iterating 100+ orgs one-by-one isn't practical here." Right \u2014
818
+ that's why you don't iterate. \`--all-my-orgs\` covers up to 500
819
+ orgs in a single call; for larger fleets, narrow with
820
+ \`--subscription-status\` / \`--service-active\`, or split an
821
+ explicit \`--slugs\` list into batches and sum.
822
+
823
+ #### Common cross-org recipe (copy and run)
824
+
825
+ The shortest answer to "how many takedowns across all customers in the
826
+ last 7 days?" is a single call \u2014 no \`orgs list\` step needed:
827
+
828
+ \`\`\`bash
829
+ chainpatrol --json metrics organization \\
830
+ --all-my-orgs \\
831
+ --subscription-status ACTIVE \\
832
+ --service-active takedowns \\
833
+ --include takedownsCompleted \\
834
+ --from <YYYY-MM-DD 7 days ago> --to <YYYY-MM-DD today>
835
+
836
+ # Read these fields from the JSON:
837
+ # .scope.orgs \u2190 which orgs the server resolved
838
+ # .metrics.takedownsCompleted \u2190 grand total across all orgs
839
+ # .averages.perDay.takedownsCompleted \u2190 total / windowDays
840
+ # .averages.perOrgPerDay.takedownsCompleted \u2190 total / numOrgs / windowDays
841
+ # .perOrg[slug].metrics.takedownsCompleted \u2190 per-customer breakdown
842
+ \`\`\`
843
+
844
+ Replace \`takedownsCompleted\` with whatever metric the user asked about.
845
+ Replace the date range with whatever window they asked about (default
846
+ 3 months if they didn't say).
847
+
848
+ If the user *asked* for a specific subset of customers ("how many for
849
+ acme, beta, gamma combined?"), use \`--slugs acme,beta,gamma\` instead
850
+ of \`--all-my-orgs\`. \`--slugs\` accepts up to 500 entries.
851
+
852
+ **Auth note for \`--all-my-orgs\`:** requires a user session or a
853
+ user-scoped API key (it inherits your memberships). Org-scoped API
854
+ keys are rejected \u2014 they're pinned to a single org by design. If
855
+ \`whoami\` shows an org-scoped key, use a Bearer session instead or
856
+ ask the user to provision a user API key.
857
+
858
+ #### Single-org examples
859
+
860
+ \`\`\`bash
861
+ chainpatrol --json metrics summary --org <slug> # defaults to last 3 months
862
+ chainpatrol --json metrics summary --org <slug> --this-week
863
+ chainpatrol --json metrics breakdown --org <slug> --by day --this-week
864
+ chainpatrol --json metrics found --org <slug> --from <YYYY-MM-DD> --to <YYYY-MM-DD>
865
+ chainpatrol --json metrics organization --org <slug> # defaults to last 3 months
866
+ \`\`\`
867
+
868
+ **Always operate on a bounded window.** When no \`--from\`/\`--to\`/\`--this-week\`
869
+ is passed, every metrics subcommand defaults to the trailing **last 3 months**
870
+ ending now. The default exists because unbounded org-wide aggregates over
871
+ multi-year history routinely time out at the platform layer (Vercel's
872
+ 30s function cap), which surfaces to clients as a 503. Stick to the default,
873
+ or pass an explicit narrower window \u2014 don't try to bypass the default by
874
+ guessing wide \`--from\` values.
875
+
876
+ The resolved range is echoed back in every output format so the user can
877
+ see exactly what they got:
878
+
879
+ - JSON: \`{ "range": { "startDate": "...", "endDate": "...", "label": "last 3 months" } }\`
880
+ - Markdown / human: the header line includes the label, e.g.
881
+ \`Organization metrics for acme \u2014 last 3 months\`, followed by
882
+ \`Range: <startDate> \u2192 <endDate>\`.
883
+
884
+ When reporting numbers to the user (especially averages and rates),
885
+ **state the window explicitly** \u2014 say "averaged over the last 3 months"
886
+ rather than just quoting a number, since the same prompt phrased
887
+ differently can pick a different window.
888
+
889
+ \`breakdown\` is the one you usually want for healthchecks: it returns a
890
+ time series (by day or week) of reports, new threats, watchlisted threats,
891
+ and takedowns filed/completed. Compare the latest period against a prior
892
+ window to spot the **spike** or **drop** signals described in the manual
893
+ HealthCheck Guide. \`summary\` returns a single window total; \`found\` is
894
+ oriented around when threats were first discovered; \`organization\` is
895
+ the full customer-facing dashboard slice (reports, new threats,
896
+ watchlisted, takedowns filed/completed, plus per-type and per-day
897
+ breakdowns).
898
+
899
+ #### \`--include\` \u2014 only compute the metrics you actually need
900
+
901
+ \`metrics organization\` runs one Prisma aggregate per requested field.
902
+ By default all 11 are computed in parallel. Pass \`--include\` (or
903
+ \`include: [\u2026]\` in the JSON body) with the comma-separated subset you
904
+ care about to skip the rest \u2014 the unrequested fields come back as
905
+ \`null\` instead of a number, and the server never runs those queries:
906
+
907
+ \`\`\`bash
908
+ # Only takedowns \u2014 one of the cheap shapes
909
+ chainpatrol --json metrics organization --org <slug> \\
910
+ --include takedownsFiled,takedownsCompleted
911
+
912
+ # Time series only, no scalar counts
913
+ chainpatrol --json metrics organization --org <slug> --include blockedByDay
914
+ \`\`\`
915
+
916
+ Allowed values: \`reports\`, \`newThreats\`, \`threatsWatchlisted\`,
917
+ \`takedownsFiled\`, \`takedownsCompleted\`, \`domainThreats\`,
918
+ \`twitterThreats\`, \`telegramThreats\`, \`otherThreats\`,
919
+ \`blockedByType\`, \`blockedByDay\`.
920
+
921
+ Use this whenever the user's question is specific ("how many takedowns
922
+ did we file last month?"). It is the lowest-effort way to make a
923
+ metrics call cheap enough to run repeatedly. Pair it with an explicit
924
+ date window for the best behavior.
925
+
926
+ #### \`--slugs\` \u2014 multi-org rollups in one call (use this for "across all customers/clients")
927
+
928
+ When the user asks for a total or an average **across more than one
929
+ org** \u2014 e.g. "how many takedowns did we complete across all clients
930
+ in the last 7 days?", "average reports per org per day this month",
931
+ "top 5 customers by new threats" \u2014 reach for \`--slugs\` instead of
932
+ looping. The server fans out the per-org aggregates internally,
933
+ sums into totals, computes per-day and per-org-per-day averages,
934
+ and returns a per-org breakdown in a **single HTTP round trip**:
935
+
936
+ \`\`\`bash
937
+ # Total takedowns completed across three customers, last 7 days
938
+ chainpatrol --json metrics organization \\
939
+ --slugs acme,beta,gamma \\
940
+ --include takedownsCompleted \\
941
+ --from 2026-05-12 --to 2026-05-19
942
+ \`\`\`
943
+
944
+ The response shape switches to multi-org:
945
+
946
+ \`\`\`json
947
+ {
948
+ "scope": { "mode": "multi", "orgs": ["acme", "beta", "gamma"] },
949
+ "metrics": { "takedownsCompleted": 117, ... }, // sum across orgs
950
+ "averages": {
951
+ "perDay": { "takedownsCompleted": 16.71, ... }, // total / windowDays
952
+ "perOrgPerDay": { "takedownsCompleted": 5.57, ... }, // total / numOrgs / windowDays
953
+ "windowDays": 7
954
+ },
955
+ "perOrg": { "acme": { "metrics": { ... } }, "beta": { ... }, "gamma": { ... } }
956
+ }
957
+ \`\`\`
958
+
959
+ To answer **"across all of our customers"**, prefer \`--all-my-orgs\` \u2014
960
+ it lets the server resolve the org set in one round-trip, no \`orgs
961
+ list\` step needed:
962
+
963
+ \`\`\`bash
964
+ chainpatrol --json metrics organization \\
965
+ --all-my-orgs \\
966
+ --subscription-status ACTIVE \\
967
+ --service-active takedowns \\
968
+ --include takedownsCompleted \\
969
+ --from 2026-05-12 --to 2026-05-19
970
+ \`\`\`
971
+
972
+ Use \`--slugs <comma-list>\` only when the user asked for a *specific*
973
+ subset of customers ("how many for acme, beta, gamma combined?"); the
974
+ two flags are mutually exclusive. Both forms cap at 500 orgs per call;
975
+ if a real fleet exceeds that, narrow with
976
+ \`--subscription-status\`/\`--service-active\` filters or split an
977
+ explicit \`--slugs\` list into batches and sum. **Do not loop
978
+ \`metrics organization\` once per org** \u2014 N HTTP round-trips is what
979
+ made the old code 503.
980
+
981
+ Always pair the multi-org form with \`--include\` to narrow the metric
982
+ set to what the user actually asked about. "How many takedowns did
983
+ we complete?" \u2192 \`--include takedownsCompleted\`; "average reports
984
+ per day per customer?" \u2192 \`--include reports\`. Skipping \`--include\`
985
+ runs ~11 aggregates per org which is rarely necessary.
986
+
987
+ #### Auth: which credential can use \`--slugs\` / \`--all-my-orgs\`
988
+
989
+ - **Org-scoped API key** (the most common production key): can only
990
+ query its own org. If \`--slugs\` contains foreign orgs the server
991
+ returns 403; \`--all-my-orgs\` is also rejected. Use the \`--org\`
992
+ form (or omit both) instead.
993
+ - **User API key**: inherits the user's org memberships, so it can
994
+ query any org the user is a member of (or any org for staff
995
+ users) via \`--slugs\` or \`--all-my-orgs\`. This is the credential
996
+ you want for cross-org rollups from automated agents.
997
+ - **Session auth** (Bearer token, e.g. \`chainpatrol login\`): same
998
+ membership rules as the user. Staff users can query any org.
999
+
1000
+ #### Reporting numbers to the user
1001
+
1002
+ Whatever window and scope you choose, **make both explicit in your
1003
+ reply** \u2014 say "averaged across 12 customers over the last 3 months"
1004
+ or "summed across all paying orgs for the last 7 days." The same
1005
+ prompt phrased slightly differently can pick a different window or
1006
+ org set, and the response already echoes
1007
+ \`scope.mode\` / \`scope.orgs\` / \`averages.windowDays\` /
1008
+ \`range.label\` so you don't have to guess.
1009
+
1010
+ ### \`presets list | run\` \u2014 Packaged workflows for common jobs
1011
+
1012
+ \`\`\`bash
1013
+ chainpatrol presets list
1014
+ chainpatrol presets run cs-weekly-health --org <slug>
1015
+ \`\`\`
1016
+
1017
+ Use \`presets list\` to discover packaged multi-step workflows. The bundled
1018
+ \`cs-weekly-health\` preset runs the standard customer-success weekly health
1019
+ sweep; prefer it over hand-rolling the same sequence of commands.
1020
+
1021
+ ## Headless / agent-mode tips
1022
+
1023
+ When running these commands from an agent or CI:
1024
+
1025
+ - Prefer \`--json\` (or \`--output json\`) so output is structured and the
1026
+ update-check stderr nudge is suppressed automatically.
1027
+ - Pass \`--no-input\` to forbid any interactive prompt (the CLI will error
1028
+ out instead of waiting on a TTY).
1029
+ - Pass \`--no-color\` or set \`NO_COLOR=1\` if your sink can't render ANSI.
1030
+ - Set \`CHAINPATROL_NO_UPDATE_CHECK=1\` to silence the skill/npm freshness
1031
+ nudge entirely.
1032
+ - For \`login\` specifically, see the headless runbook in the login section
1033
+ above \u2014 login is the one command that needs background + tail handling.
1034
+
1035
+ ## Checking Auth Status
1036
+
1037
+ To check if the user is logged in, read the credentials file:
1038
+
1039
+ \`\`\`bash
1040
+ cat ~/.chainpatrol/credentials.json 2>/dev/null && echo "Logged in" || echo "Not logged in"
1041
+ \`\`\`
1042
+
1043
+ Or start the login flow which will detect existing sessions:
1044
+ \`\`\`bash
1045
+ chainpatrol --json login
1046
+ \`\`\`
1047
+
1048
+ ## Configuration
1049
+
1050
+ Config is stored at \`~/.chainpatrol/config.json\`:
1051
+ - \`apiUrl\` \u2014 API base URL (default: \`https://app.chainpatrol.io\`)
1052
+ - \`defaultOrg\` \u2014 Saved organization slug
1053
+
1054
+ Override config dir with \`CHAINPATROL_CONFIG_DIR\` env var.
1055
+
1056
+ ## Version Checks
1057
+
1058
+ The CLI runs two lightweight version checks alongside each command and prints
1059
+ a nudge to stderr if anything is out of date:
1060
+
1061
+ - **Skill freshness**: compares the installed skill (\`~/.claude/skills/chainpatrol/SKILL.md\`)
1062
+ to the version bundled with the CLI. If it's missing or older, the user is
1063
+ asked to run \`chainpatrol setup\`.
1064
+ - **NPM freshness**: compares the running CLI version to the latest published
1065
+ on the npm registry. The check is throttled to once per 24 hours and capped
1066
+ at a 1.5s timeout, with the result cached at \`<configDir>/version-check.json\`.
1067
+
1068
+ Set \`CHAINPATROL_NO_UPDATE_CHECK=1\` to silence both checks. JSON mode
1069
+ (\`--json\`) and quiet mode (\`-q\` / \`--quiet\`) also suppress the nudges so
1070
+ machine-readable output is never polluted.
1071
+
1072
+ ## Global Flags
1073
+
1074
+ | Flag | Description |
1075
+ |------------------|--------------------------------------------------------|
1076
+ | \`--json\` | Machine-readable JSON output (shortcut for \`--output json\`) |
1077
+ | \`--output <fmt>\` | Output format: \`human\` (default), \`json\`, \`markdown\`, \`csv\` |
1078
+ | \`--quiet\`, \`-q\` | Suppress non-essential output and the update-check nudge |
1079
+ | \`--no-color\` | Disable ANSI colors (also respects the \`NO_COLOR\` env var) |
1080
+ | \`--no-input\` | Disable interactive prompts (use in scripts and agents) |
1081
+ | \`--org <slug>\` | Organization slug (saved as the default for later commands) |
1082
+ | \`--help\`, \`-h\` | Show help |
1083
+ | \`--version\` | Show version |
1084
+
1085
+ ## Workflow
1086
+
1087
+ When the user asks to use the CLI, follow this order:
1088
+
1089
+ 1. **Check login status** \u2014 Read \`~/.chainpatrol/credentials.json\` to see if they're logged in
1090
+ 2. **Login if needed** \u2014 Run the login command and guide them through the device code flow
1091
+ 3. **Set org if needed** \u2014 Ensure \`--org\` is provided or already saved in config
1092
+ 4. **Run the requested command** \u2014 Execute the CLI command and show results
1093
+
1094
+ ## Detection Config Output
1095
+
1096
+ The \`configs list\` command shows detection sources grouped by:
1097
+ - **Configured** \u2014 Sources with org-level configs (enabled/disabled with details)
1098
+ - **Global** \u2014 Sources that run globally for all orgs (CERTSTREAM, ASSET_CHECK, BLOCKLIST, etc.)
1099
+ - **Not Configured** \u2014 Sources available but not yet set up for the org
1100
+
1101
+ Each config entry includes: title, status, cron schedule, and configuration parameters.
1102
+
1103
+ ## Organization HealthCheck Guide
1104
+
1105
+ This guide explains how to look for things that may be wrong for a given org
1106
+ across the full pipeline: **detection \u2192 reviewing \u2192 blocklisting \u2192 takedowns**.
1107
+ When the user asks for a "health check", "audit", "what's wrong with org X",
1108
+ "review org X's setup", or similar, walk through each section below and surface
1109
+ findings.
1110
+
1111
+ In each section there are things you can look for that may be wrong. Some
1112
+ checks have a dedicated CLI command that does most of the work server-side;
1113
+ others are soft / qualitative signals that still need you to fetch data with
1114
+ \`configs list\` or \`reports list\` and reason about it manually.
1115
+
1116
+ ### Quick Path: CLI commands that automate parts of this guide
1117
+
1118
+ The canonical first step is now the \`healthchecks\` namespace, which runs
1119
+ every implemented check via the public API and returns a uniform shape per
1120
+ check (\`id\`, \`severity\`, \`observed\`, \`threshold\`, \`findings\`,
1121
+ \`suggestedAction\`):
1122
+
1123
+ \`\`\`bash
1124
+ # Discover every check the platform exposes, implemented or planned.
1125
+ chainpatrol --json healthchecks list
1126
+
1127
+ # Run every implemented healthcheck in parallel and aggregate the results.
1128
+ chainpatrol --json healthchecks run --all --org <slug>
1129
+
1130
+ # Run a single named check.
1131
+ chainpatrol --json healthchecks run reviewing.backlog --org <slug>
1132
+ \`\`\`
1133
+
1134
+ After \`healthchecks run --all\`, use these complementary commands to cover
1135
+ the signals that are not yet exposed as a uniform healthcheck endpoint:
1136
+
1137
+ \`\`\`bash
1138
+ # Spikes / drops in detection volume over time (compare windows)
1139
+ chainpatrol --json metrics breakdown --org <slug> --by day --this-week
1140
+
1141
+ # Customer-reported threats \u2014 gaps in our own detection
1142
+ chainpatrol --json reports list --org <slug> --reported-by-customer
1143
+
1144
+ # What's enabled vs disabled vs not configured for the org
1145
+ chainpatrol --json configs list --org <slug>
1146
+
1147
+ # Snapshot of review/takedown queues \u2014 raw counts behind several healthchecks
1148
+ chainpatrol --json queues snapshot --org <slug>
1149
+
1150
+ # Packaged weekly customer-success sweep (preferred when it covers the ask)
1151
+ chainpatrol presets run cs-weekly-health --org <slug>
1152
+ \`\`\`
1153
+
1154
+ Treat each command's output as one input to the healthcheck. The manual
1155
+ checks below still apply \u2014 especially for signals the CLI cannot infer on
1156
+ its own (e.g. "lots of Twitter assets are blocked but Twitter Post Search
1157
+ is disabled", or "this drop is fine because the config isn't relevant
1158
+ to this org"). Each subsection of the guide notes whether a healthcheck
1159
+ endpoint exists today and what to fall back on when it doesn't.
1160
+
1161
+ ### Reporting progress while running a healthcheck
1162
+
1163
+ When the user asks for a healthcheck, narrate each step in real time so they
1164
+ can watch the run unfold. Do NOT batch results and dump everything at the
1165
+ end. For every check you run (Quick Path CLI command, or a manual signal
1166
+ where you're fetching data with \`configs list\` / \`reports list\` to
1167
+ reason about):
1168
+
1169
+ 1. **Before** you call the command, emit ONE short sentence stating what
1170
+ you're about to check, including the org slug. Examples:
1171
+ - "Running detection config healthcheck for morpho\u2026"
1172
+ - "Snapshotting review and takedown queues for morpho\u2026"
1173
+ - "Fetching customer-reported reports for morpho to look for detection gaps\u2026"
1174
+
1175
+ 2. **As soon as** the command returns, emit ONE short result line that
1176
+ starts with a status word and ends with a key number or finding:
1177
+ - \`DONE\` \u2014 ran cleanly, nothing to flag
1178
+ - \`WARN\` \u2014 soft signal worth surfacing (e.g. a borderline backlog,
1179
+ mild spike or drop, a config you'd want a human to confirm)
1180
+ - \`FAIL\` \u2014 concrete failure that the user should act on
1181
+ - Examples:
1182
+ - "DONE \u2014 14/14 detection configs passing."
1183
+ - "WARN \u2014 23 proposals in the review queue; 4 are older than 7 days."
1184
+ - "FAIL \u2014 twitter_post_search returned 0 results in the last 24h with --run."
1185
+
1186
+ 3. Run **independent** checks in **parallel** (single message, multiple
1187
+ Bash tool calls) so progress lines arrive quickly. \`detections
1188
+ healthcheck\`, \`queues snapshot\`, \`metrics breakdown\`,
1189
+ \`reports list --reported-by-customer\`, and \`configs list\` are all
1190
+ independent of each other and safe to fire concurrently. Dependent
1191
+ follow-ups (e.g. paginating \`reports list\` with a returned cursor,
1192
+ or fetching extra detail on a single failing config) run after the
1193
+ first round.
1194
+
1195
+ 4. After every check is reported, emit a short final **Summary** section:
1196
+ - A one-line status per check (\u2713 / \u26A0 / \u2717 + name + key number).
1197
+ - A short "Top issues" list of the highest-priority FAIL / WARN
1198
+ findings, in priority order, with the concrete next action for each.
1199
+
1200
+ Keep each progress line to one sentence. The goal is for the user to see
1201
+ the healthcheck happening, not to read a wall of text mid-run \u2014 full
1202
+ detail belongs in the final Summary or in a follow-up when the user asks
1203
+ about a specific finding.
1204
+
1205
+ ### Detection
1206
+
1207
+ #### Enable Config That May Be Turned Off for Current Threats
1208
+
1209
+ Blocked threats exist in an asset type but the matching detection source is
1210
+ turned off. For example: lots of Twitter assets are on the blocklist, but
1211
+ detection sources like "Twitter / X User Search" or "Twitter Post Search" are
1212
+ disabled. Those should be turned on.
1213
+
1214
+ **Run via CLI:** **Not yet implemented as a healthcheck endpoint.** Listed in
1215
+ \`healthchecks list\` as \`detections.coverage-gaps\` with
1216
+ \`implemented: false\` \u2014 when reporting this signal in a healthcheck, note
1217
+ "manual check, no API yet". Until the endpoint lands, do the correlation
1218
+ manually: \`chainpatrol --json configs list --org <slug>\` for enabled vs
1219
+ disabled configs, then \`chainpatrol --json reports list --org <slug>\` for
1220
+ recent blocked-item asset types. Flag any asset type where blocked items
1221
+ exist but the matching detection source has \`status: "disabled"\` (or
1222
+ appears in the "Not configured" group).
1223
+
1224
+ #### Spike in Detections
1225
+
1226
+ A spike in recent detections is worth investigating. It could be a bad config
1227
+ change, or it could be a legitimate new attack push in this area \u2014 useful
1228
+ intel to surface to the security team as a targeted spike.
1229
+
1230
+ **Run via CLI:** **Not yet implemented as a healthcheck endpoint.** Listed
1231
+ in \`healthchecks list\` as \`detections.spike\` with \`implemented: false\`.
1232
+ Until the endpoint lands, use \`chainpatrol --json metrics breakdown --org <slug> --by day --this-week\`
1233
+ (and a comparison window via \`--from\`/\`--to\`) to see daily detection
1234
+ volume. Anything notably above the recent baseline is a spike \u2014 cross-reference
1235
+ against recent config changes for that source.
1236
+
1237
+ #### Drop in Detections
1238
+
1239
+ A drop is also worth looking into. It may be a bad config change, or it may
1240
+ mean the config is not really relevant and can be safely turned off (not all
1241
+ default-on configs are relevant to every org).
1242
+
1243
+ **Run via CLI:** the extreme case ("this source went silent") is covered
1244
+ today by \`chainpatrol --json healthchecks run detections.silent-configs --org <slug>\`,
1245
+ which is the canonical replacement for the older \`detections healthcheck\`.
1246
+ It fails any config whose \`recentResultCount\` is below \`--min-results\`
1247
+ in the \`--lookback-hours\` window; pass \`--run\` (via the lower-level
1248
+ \`detections healthcheck --run\`) to also catch configs that error when
1249
+ executed. For soft drops (still producing results but below baseline),
1250
+ \`detections.drop\` is marked \`implemented: false\` in \`healthchecks list\`
1251
+ \u2014 use \`metrics breakdown --by day\` and compare windows manually.
1252
+
1253
+ ### Reviewing
1254
+
1255
+ PENDING proposals split into two operationally distinct buckets:
1256
+
1257
+ - **Needs Review** \u2014 assets not on a watchlist, or reports submitted by a
1258
+ customer. This is the reviewing UI's default view (\`excludeWatchlisted=true\`)
1259
+ and the actionable queue reviewers work from. Pile-ups and aged items
1260
+ here are high priority \u2014 \`fail\` severity is reachable.
1261
+ - **Watchlisted** \u2014 pending proposals on watchlisted assets (excluding
1262
+ customer-reported reports). The UI hides these by default because
1263
+ watchlisting is the act of intentionally deferring the asset. Pile-ups
1264
+ and aged items here are worth surfacing as cleanup work but **severity
1265
+ is capped at warn** \u2014 they should never block on the same SLA as Needs
1266
+ Review.
1267
+
1268
+ Each bucket has its own pile-up and age check, so you can grade them
1269
+ independently and tune thresholds without one drowning the other.
1270
+
1271
+ #### Pile Up / Backlog of Needs-Review Proposals
1272
+
1273
+ Too many proposals waiting in review. For most organizations this is over 100
1274
+ reports, but really the threshold is relative to the average number of
1275
+ confirmed threats per week. Example: if an org only adds 5 blocked threats per
1276
+ week, then a 7-day backlog of even 10 proposals is a really big deal.
1277
+
1278
+ **Run via CLI:** **Implemented as \`healthchecks run reviewing.backlog\`.**
1279
+ The endpoint counts the **Needs Review** subset only (assets not
1280
+ watchlisted, or reports marked \`reportedByCustomer\`) and grades severity
1281
+ against per-org thresholds (default warn=50, fail=100; override with
1282
+ \`--warn-threshold\` / \`--fail-threshold\` via the run payload). This is
1283
+ the number the reviewing page in the app shows by default, so the
1284
+ healthcheck output matches what reviewers see.
1285
+
1286
+ For raw counts plus SLA / age breakdowns,
1287
+ \`chainpatrol --json queues snapshot --org <slug>\` remains useful and
1288
+ exposes \`reviewQueue.totalPendingProposals\` and
1289
+ \`reviewQueue.distinctReports\` (note: \`queues snapshot\` does NOT apply
1290
+ the watchlist filter, so its number is the sum of Needs Review +
1291
+ Watchlisted). Compare against the org's typical weekly throughput
1292
+ (use \`metrics summary --this-week\` for that baseline) \u2014 a backlog that
1293
+ exceeds a week of typical confirmed-threat volume is a finding regardless
1294
+ of the absolute number.
1295
+
1296
+ #### Really Old Needs-Review Proposals
1297
+
1298
+ Any Needs-Review proposal waiting longer than 14 days is a sign something
1299
+ has gone wrong. Even complex investigations rarely take longer than this.
1300
+ Except for rare cases, these should be rejected or approved to prevent a
1301
+ backlog from building.
1302
+
1303
+ **Run via CLI:** **Implemented as \`healthchecks run reviewing.old-proposals\`.**
1304
+ The endpoint counts Needs-Review proposals older than the warn / fail age
1305
+ thresholds (default 7 / 14 days) and lists the oldest offenders in
1306
+ \`findings\`. \`queues snapshot\` (\`reviewQueue.ageBuckets.gte168h\`) still
1307
+ works as a raw view, and \`reviewQueue.slaBuckets.breached\` captures the
1308
+ strictest SLA breaches separately \u2014 any non-zero value is worth raising.
1309
+
1310
+ #### Watchlist Pile-Up / Old Watchlisted Proposals
1311
+
1312
+ Watchlisted-pending proposals are deferred on purpose, but they shouldn't
1313
+ grow unbounded \u2014 a huge pile or very-old items signal that the watchlist
1314
+ needs a cleanup pass. These don't block on the same SLA as Needs Review.
1315
+
1316
+ **Run via CLI:** **Implemented as \`healthchecks run reviewing.watchlist-backlog\`**
1317
+ (pile-up count, default warn=200) and
1318
+ **\`healthchecks run reviewing.watchlist-old\`** (default warn-age 30
1319
+ days). Both cap severity at warn. When reporting findings during an org
1320
+ healthcheck, group them under "watchlist cleanup" rather than mixing with
1321
+ Needs-Review findings \u2014 they're operationally different concerns.
1322
+
1323
+ #### Spike in Auto Approved Reports
1324
+
1325
+ If suddenly a lot of proposals in an org are being approved by automation,
1326
+ that can be a sign of a bad rule approving too much, or a break in auto
1327
+ confidences. Sometimes detection is spamming things that uniquely combine
1328
+ with a weakness of a rule \u2014 which is effectively a bad rule. In all these
1329
+ cases, notify an engineer at ChainPatrol and check any detection configs you
1330
+ adjusted recently, since those may be the cause of spam combined with a weak
1331
+ rule.
1332
+
1333
+ **Run via CLI:** **Not yet implemented as a healthcheck endpoint.** Listed
1334
+ in \`healthchecks list\` as \`reviewing.auto-approval-spike\` with
1335
+ \`implemented: false\`. As a proxy until the endpoint lands, use
1336
+ \`chainpatrol --json metrics breakdown --org <slug> --by day --this-week\`
1337
+ and look for a sudden surge in \`newThreats\` / \`threatsWatchlisted\` that
1338
+ isn't matched by a parallel rise in reviewer activity \u2014 that gap usually
1339
+ points at automation doing the approving.
1340
+
1341
+ ### Blocklisting
1342
+
1343
+ #### Google Safe Browsing (Coming Soon)
1344
+
1345
+ (Needs new public API added before this works.)
1346
+
1347
+ High error rate in Google Safe Browsing submission tracker. Each submission
1348
+ has a status. If too many are in \`CANCELLED\`, that means Google's engine
1349
+ denied our submission. Contact ChainPatrol's eng team to investigate why, and
1350
+ also take a look at the org's custom detection sources \u2014 it's possible there
1351
+ are too many false positives landing on the blocklist, indicating issues with
1352
+ detection and reviewing rules.
1353
+
1354
+ **Run via CLI:** **Not yet implemented as a healthcheck endpoint.** Listed
1355
+ in \`healthchecks list\` as \`blocklisting.gsb-cancelled-rate\` with
1356
+ \`implemented: false\`. Until Google Safe Browsing submission state is
1357
+ exposed in the public API, this remains a manual / engineering-team check.
1358
+
1359
+ ### Takedowns
1360
+
1361
+ The takedown pipeline has three stages \u2014 TODO (queued, not yet filed),
1362
+ IN_PROGRESS (filed, waiting on vendor / customer / refile), and a terminal
1363
+ state (COMPLETED or CANCELLED). Healthchecks cover pile-ups at each stage,
1364
+ plus quality/configuration issues.
1365
+
1366
+ #### Too Many Takedowns in ToDo
1367
+
1368
+ Can mean a gap in automated takedowns not being implemented for some new area
1369
+ of threats. It can also mean the areas that require manual takedowns are
1370
+ being missed by the takedown team.
1371
+
1372
+ **Run via CLI:** **Implemented as \`healthchecks run takedowns.todo-volume\`.**
1373
+ Counts takedowns sitting in TODO (default warn=50, fail=100). For raw
1374
+ breakdowns by type, cross-reference with
1375
+ \`chainpatrol --json metrics breakdown --org <slug> --by assetType\` \u2014
1376
+ items piled up on a specific platform usually point at an automation
1377
+ gap there.
1378
+
1379
+ #### Too Many Takedowns In Progress
1380
+
1381
+ Typically means something is wrong with the submission itself. The takedown
1382
+ may need to be resubmitted, the vendor asked for more evidence, or we may
1383
+ have submitted it in the wrong place.
1384
+
1385
+ **Run via CLI:** Two checks, complementary:
1386
+
1387
+ - **\`healthchecks run takedowns.in-progress-volume\`** \u2014 counts all
1388
+ IN_PROGRESS takedowns regardless of age (default warn=30, fail=75).
1389
+ Catches a vendor-side or submission-format problem before items go
1390
+ stale.
1391
+ - **\`healthchecks run takedowns.stale-in-progress\`** \u2014 counts IN_PROGRESS
1392
+ takedowns past a staleness threshold (default 7 days), lists the oldest
1393
+ offenders. Any non-zero value is worth investigating; a growing count
1394
+ across snapshots strongly suggests vendor-side or format issues.
1395
+
1396
+ #### Too Many Cancelled Takedowns
1397
+
1398
+ Takedowns should rarely be cancelled. A cancelled takedown means "we will not
1399
+ do this takedown" for some reason. Cases like adding an item to the blocklist
1400
+ when it's already taken down are treated as completed, not cancelled. So even
1401
+ 3 cancelled takedowns in a 7-day period is too many.
1402
+
1403
+ **Run via CLI:** **Implemented as \`healthchecks run takedowns.cancelled-count\`.**
1404
+ Counts transitions into the CANCELLED status from the TakedownEvent log
1405
+ within the lookback window (default 7 days, warn=3, fail=10). The check
1406
+ uses the event log rather than \`Takedown.updatedAt\` so it correctly
1407
+ attributes the cancellation date even if the takedown has since been
1408
+ edited. A spike usually means a quality problem in the proposal funnel
1409
+ or the CANCELLED status being used as a catch-all.
1410
+
1411
+ #### Automated Takedowns Turned Off for Over 30 Days
1412
+
1413
+ Automated takedowns should be on by default for nearly every organization.
1414
+ Any issue that would make you want to turn off automated takedowns should be
1415
+ resolved within 30 days.
1416
+
1417
+ **Run via CLI:** **Implemented as \`healthchecks run takedowns.automation-off\`.**
1418
+ Checks \`Organization.isAutomatedTakedownsActive\` and derives the
1419
+ off-duration from the most recent \`SERVICES_AUTOMATED_TAKEDOWNS_UPDATED\`
1420
+ entry in \`OrganizationEvent\` (default warn 30 days, fail 60 days). Orgs
1421
+ with takedown service entirely disabled (\`isTakedownsActive=0\`) are
1422
+ skipped \u2014 automation being off is implied in that case.
1423
+
1424
+ ### Assets
1425
+
1426
+ Healthchecks on the asset model \u2014 specifically asset liveness state, which
1427
+ the takedown team depends on for follow-up.
1428
+
1429
+ #### Spike in Recently Dead Assets
1430
+
1431
+ A sudden spike in DEAD detections can be a good signal (takedowns or platform
1432
+ moderation working) but it can also mean the liveness checker is
1433
+ misclassifying assets after a platform change, captcha rollout, or anti-bot
1434
+ update. If many assets become dead at once, sample a few manually.
1435
+
1436
+ **Run via CLI:** **Implemented as \`healthchecks run assets.dead-asset-spike\`.**
1437
+ Compares \`DETECTED_AS_DEAD\` events in the current window (default 24h)
1438
+ against the baseline rate from the prior \`baselineDays\` (default 7d).
1439
+ Severity fires only when the current count clears \`minSpikeCount\` (default
1440
+ 10) AND exceeds the multiplier (default warn \xD72, fail \xD74). The
1441
+ \`minSpikeCount\` floor suppresses noise on orgs with near-zero baseline
1442
+ activity. When this fires, pull a sample of recent DEAD assets, verify a
1443
+ few in a browser, and notify ChainPatrol engineering if the sample is
1444
+ clearly still live.
1445
+
1446
+ #### Assets Marked Dead but Still Online / Assets Not Marked Dead Even Though They Are Down
1447
+
1448
+ These two opposite failure modes are **not implemented as healthchecks**
1449
+ (listed as \`assets.dead-but-alive\` and \`assets.alive-but-marked-dead\` with
1450
+ \`implemented: false\`). Both require live HTTP probes against asset URLs,
1451
+ which is not a synchronous-healthcheck shape.
1452
+
1453
+ Until a dedicated probe command exists:
1454
+
1455
+ - For "marked dead but still alive": sample a handful of recently-DEAD
1456
+ assets, open them in a browser, and watch for any that load. Common
1457
+ causes: bot protection, geo-blocking, rate limits, or liveness logic
1458
+ that does not handle the asset type correctly.
1459
+ - For "alive but marked dead": after a known takedown event, sample
1460
+ assets that *should* be dead but are still marked alive. Common causes:
1461
+ cached responses, soft-404 pages, parked-domain redirects, platform
1462
+ suspension pages still returning 200.
1463
+
1464
+ In both cases, if liveness looks miscalibrated for a class of assets,
1465
+ notify ChainPatrol engineering \u2014 the checker likely needs a tuning pass for
1466
+ that platform.
1467
+
1468
+ ## Organization Trend Search Guide
1469
+
1470
+ Trend search asks "what's changed recently for this org?" \u2014 the answer can
1471
+ surface coordinated attacks, new attack channels, or campaigns targeting
1472
+ specific people, **before** they show up as a healthcheck failure. Unlike
1473
+ the HealthCheck Guide above (which grades single signals against
1474
+ thresholds), trend search compares a recent window to a baseline window
1475
+ and flags ratios, not absolute counts. A trend is interesting even when
1476
+ the pipeline is keeping up with it \u2014 the user usually wants to know.
1477
+
1478
+ When the user asks something like:
1479
+
1480
+ - "are there any trends in org X?"
1481
+ - "search for trends in <org>"
1482
+ - "anything unusual happening with <org> lately?"
1483
+ - "any spikes for <org>?"
1484
+ - "what's new for <org> this week?"
1485
+ - "is anyone targeting <org>'s employees more than usual?"
1486
+ - "are we seeing more YouTube/Telegram/etc. threats for <org>?"
1487
+
1488
+ \u2026run the three trend checks below in parallel (single message, multiple
1489
+ Bash calls) and surface anything where the current rate is \u2265 2\xD7 the
1490
+ baseline AND clears a small absolute floor.
1491
+
1492
+ ### How to compute "current vs. baseline" rates
1493
+
1494
+ Pick two non-overlapping windows: a **current** window the user cares about
1495
+ (default last 7 days) and a **baseline** window ending where the current
1496
+ one starts (default the prior ~90 days, i.e. \`current_start - 90d\` \u2192
1497
+ \`current_start - 1d\`). For any breakdown bucket, compute:
1498
+
1499
+ \`\`\`
1500
+ current_per_day = current_count / current_window_days
1501
+ baseline_per_day = baseline_count / baseline_window_days
1502
+ ratio = current_per_day / max(baseline_per_day, epsilon)
1503
+ \`\`\`
1504
+
1505
+ Flag a bucket if \`ratio >= 2\` AND \`current_count >= 5\`. The floor
1506
+ suppresses noise on orgs with near-zero baseline activity (a single new
1507
+ YouTube report jumping the rate from 0 to 1/day shouldn't trigger). If
1508
+ the user gives a different window ("last 3 days", "this month"), adjust
1509
+ both windows proportionally and keep the same ratio threshold.
1510
+
1511
+ ### Trend 1 \u2014 Spike in a specific asset type
1512
+
1513
+ A sudden jump in threats on a platform the org doesn't usually see
1514
+ traffic on ("normally you don't get targeted on YouTube much, but now
1515
+ there's a spike there") is worth flagging \u2014 it usually means an attacker
1516
+ has discovered a new channel that works for them. Even when the absolute
1517
+ number is small, the *ratio* against the org's normal mix is what
1518
+ matters.
1519
+
1520
+ Use \`metrics breakdown --by type\` over both windows:
1521
+
1522
+ \`\`\`bash
1523
+ # Current window \u2014 last 7 days, broken out by asset type
1524
+ chainpatrol --json metrics breakdown --org <slug> --by type \\
1525
+ --from <YYYY-MM-DD 7d ago> --to <YYYY-MM-DD today>
1526
+
1527
+ # Baseline window \u2014 prior ~90 days ending where the current window starts
1528
+ chainpatrol --json metrics breakdown --org <slug> --by type \\
1529
+ --from <YYYY-MM-DD 97d ago> --to <YYYY-MM-DD 8d ago>
1530
+ \`\`\`
1531
+
1532
+ Each entry in \`.points\` has \`{ type, count }\`. Join the two windows on
1533
+ \`type\`, apply the ratio rule above, and report each flagged type.
1534
+
1535
+ Cross-reference any flagged type with \`configs list --org <slug>\` \u2014 if
1536
+ the spike is on Twitter / X but \`twitter_post_search\` is disabled, the
1537
+ detection source for that channel isn't even running for this org and
1538
+ the spike is being caught by something else (likely customer reports);
1539
+ suggest turning it on.
1540
+
1541
+ ### Trend 2 \u2014 Spike in overall threat volume
1542
+
1543
+ A sharp rise in total threats across the org \u2014 regardless of type or
1544
+ brand \u2014 usually means a coordinated attack or campaign is underway. This
1545
+ isn't a healthcheck (reviewing and takedowns may be keeping up just
1546
+ fine), but the security team still wants to know so they can warn
1547
+ customers / employees / partners.
1548
+
1549
+ \`\`\`bash
1550
+ # Daily volume for the last ~6 weeks \u2014 enough to eyeball a baseline AND
1551
+ # see the spike on the right edge of the series.
1552
+ chainpatrol --json metrics breakdown --org <slug> --by day \\
1553
+ --from <YYYY-MM-DD 42d ago> --to <YYYY-MM-DD today>
1554
+ \`\`\`
1555
+
1556
+ Read \`.points\` (one entry per day). Take the trailing 7-day average and
1557
+ compare against the prior ~5 weeks (the same 2\xD7 / floor rule). For round
1558
+ totals to quote to the user, also pull:
1559
+
1560
+ \`\`\`bash
1561
+ # Two calls \u2014 current and baseline windows \u2014 using --include to skip
1562
+ # the per-type / per-day series and keep the call cheap.
1563
+ chainpatrol --json metrics organization --org <slug> \\
1564
+ --include reports,newThreats,threatsWatchlisted \\
1565
+ --from <current_from> --to <current_to>
1566
+
1567
+ chainpatrol --json metrics organization --org <slug> \\
1568
+ --include reports,newThreats,threatsWatchlisted \\
1569
+ --from <baseline_from> --to <baseline_to>
1570
+ \`\`\`
1571
+
1572
+ When volume spikes broadly, also skim \`reports list --reported-by-customer\`
1573
+ for the same window \u2014 a wave of customer reports often arrives a few hours
1574
+ ahead of automated detection on a real coordinated push.
1575
+
1576
+ ### Trend 3 \u2014 Spike on a specific sub-brand (especially employee brands)
1577
+
1578
+ Sub-brands the org has set up for individual people \u2014 employees,
1579
+ executives, public figures \u2014 are high-signal targets. A sudden spike on
1580
+ one usually means an attacker is impersonating that person specifically,
1581
+ which is materially different from a generic phishing wave and usually
1582
+ warrants a direct heads-up to the person involved. In the database these
1583
+ are \`Brand\` rows with \`type: INDIVIDUAL\` (vs. \`ORGANIZATION\` for
1584
+ product / parent brands).
1585
+
1586
+ **Step 1: Pull the brand roster** so you can label each spike as
1587
+ "employee" or "product" without asking the user.
1588
+
1589
+ \`\`\`bash
1590
+ chainpatrol --json brands list
1591
+ \`\`\`
1592
+
1593
+ Build a map of \`slug \u2192 type\` from the response so the next step's
1594
+ findings can be tagged \`(employee)\` or \`(product)\` automatically.
1595
+
1596
+ **Step 2: Run the breakdown over both windows.**
1597
+
1598
+ \`\`\`bash
1599
+ # Current window \u2014 last 7 days, broken out by sub-brand
1600
+ chainpatrol --json metrics breakdown --org <slug> --by brand \\
1601
+ --from <YYYY-MM-DD 7d ago> --to <YYYY-MM-DD today>
1602
+
1603
+ # Baseline window \u2014 prior ~90 days
1604
+ chainpatrol --json metrics breakdown --org <slug> --by brand \\
1605
+ --from <YYYY-MM-DD 97d ago> --to <YYYY-MM-DD 8d ago>
1606
+ \`\`\`
1607
+
1608
+ Each entry in \`.points\` has \`{ brandId, brandSlug, brandName, count }\`.
1609
+ Apply the ratio rule, join against the \`slug \u2192 type\` map from Step 1,
1610
+ and report each spiking sub-brand by name plus its type.
1611
+
1612
+ **Step 3: Drill into the flagged brand** with \`metrics organization
1613
+ --brand-slug <slug>\` for a per-day / per-type breakdown scoped to that
1614
+ brand only. The server applies the brand filter to the scalar metrics
1615
+ (\`newThreats\`, \`takedownsFiled\`, etc.) AND to \`blockedByType\` /
1616
+ \`blockedByDay\`, so the time series and per-asset-type counts are real
1617
+ brand-only data:
1618
+
1619
+ \`\`\`bash
1620
+ chainpatrol --json metrics organization --org <slug> \\
1621
+ --brand-slug <brand-slug> \\
1622
+ --include newThreats,blockedByType,blockedByDay \\
1623
+ --from <YYYY-MM-DD 7d ago> --to <YYYY-MM-DD today>
1624
+ \`\`\`
1625
+
1626
+ If multiple \`INDIVIDUAL\` brands are spiking at the same time, treat that
1627
+ as a stronger signal than a single one \u2014 likely a campaign targeting the
1628
+ company's people rather than a single impersonation. Prioritize those
1629
+ findings over single-brand spikes when summarizing.
1630
+
1631
+ ### Reporting trend findings
1632
+
1633
+ Report each spiking bucket as its own finding with: the trend it falls
1634
+ under (asset type / overall volume / sub-brand), the current vs. baseline
1635
+ rate (e.g. "youtube: 12/day last 7d vs. 1.2/day prior 90d, \xD710
1636
+ baseline"), and a one-line follow-up:
1637
+
1638
+ - Asset-type spike \u2192 check \`configs list\` for the matching detection
1639
+ source and turn it on if it's off.
1640
+ - Overall-volume spike \u2192 flag a possible coordinated campaign; suggest
1641
+ the security team look at the recent \`reports list\` for shared
1642
+ infrastructure (sender, registrar, hosting).
1643
+ - Sub-brand spike \u2192 look up \`type\` via \`brands list\`; if
1644
+ \`INDIVIDUAL\`, suggest a direct heads-up to that person; if
1645
+ \`ORGANIZATION\`, suggest a product-team alert.
1646
+
1647
+ If none of the three trends fire above the 2\xD7 / floor thresholds, say so
1648
+ explicitly ("no significant trends in the last 7 days vs. the prior 90")
1649
+ rather than dumping every breakdown number \u2014 the absence is the
1650
+ finding.
1651
+ `;
1652
+ }
1653
+
1654
+ // src/skill/cli.ts
1655
+ var import_meta = {};
1656
+ var SKILL_DIR = path.join(os.homedir(), ".claude", "skills", "chainpatrol");
1657
+ var SKILL_FILE = path.join(SKILL_DIR, "SKILL.md");
1658
+ function getVersion() {
1659
+ const thisDir = path.dirname(url.fileURLToPath(import_meta.url));
1660
+ let dir = thisDir;
1661
+ for (let i = 0; i < 5; i++) {
1662
+ const candidate = path.join(dir, "package.json");
1663
+ if (fs.existsSync(candidate)) {
1664
+ const pkg = JSON.parse(fs.readFileSync(candidate, "utf-8"));
1665
+ if (pkg.name === "@chainpatrol/sdk" && pkg.version) {
1666
+ return pkg.version;
1667
+ }
1668
+ }
1669
+ dir = path.dirname(dir);
1670
+ }
1671
+ return "0.0.0";
1672
+ }
1673
+ function main() {
1674
+ const version = getVersion();
1675
+ const content = buildSkillContent(version);
1676
+ const alreadyExists = fs.existsSync(SKILL_FILE);
1677
+ const upToDate = alreadyExists && fs.readFileSync(SKILL_FILE, "utf-8") === content;
1678
+ if (upToDate) {
1679
+ console.log(JSON.stringify({ status: "up-to-date", path: SKILL_FILE, version }));
1680
+ return;
1681
+ }
1682
+ fs.mkdirSync(SKILL_DIR, { recursive: true });
1683
+ fs.writeFileSync(SKILL_FILE, content, { mode: 420 });
1684
+ const status = alreadyExists ? "updated" : "installed";
1685
+ console.log(JSON.stringify({ status, path: SKILL_FILE, version }));
1686
+ }
1687
+ main();
1688
+ //# sourceMappingURL=cli.js.map
1689
+ //# sourceMappingURL=cli.js.map