@chainpatrol/cli 1.17.2 → 1.19.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/CHANGELOG.md +51 -0
- package/dist/{chunk-XLPLTBKX.js → chunk-RAFCCHOO.js} +85 -73
- package/dist/{chunk-DY5VY6FO.js → chunk-XICYSDVF.js} +30 -23
- package/dist/cli.js +80 -30
- package/dist/{completions-HYTAOGE4.js → completions-VJMT2W5B.js} +1 -1
- package/dist/{list-Z2WGCOB5.js → list-EBX2AYJ5.js} +5 -3
- package/dist/set-expiry-ZOLZPC4N.js +134 -0
- package/dist/{setup-skill-RQG43DFT.js → setup-skill-M2PVQC4Z.js} +2 -2
- package/dist/{takedown-time-6WUEIKXV.js → takedown-time-35OTRJWA.js} +35 -9
- package/dist/{takedown-time-trend-IWVYHADT.js → takedown-time-trend-3PWWE2D3.js} +2 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,56 @@
|
|
|
1
1
|
# @chainpatrol/cli
|
|
2
2
|
|
|
3
|
+
## 1.19.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- f1026ab: Set when organization assets expire. Assets that should only stay for a while, such as a partner's site, can be given an allowlist expiry; once it passes they stay for a 14-day grace period, then are removed from the organization without changing their status.
|
|
8
|
+
|
|
9
|
+
- MCP: new `organization_assets_set_expiry` tool for `POST /organization/assets/expiry`.
|
|
10
|
+
- SDK: `setOrganizationAssetsExpiry()`, and `allowlistExpiresAt` / `allowlistExpiredAt` on organization asset list items.
|
|
11
|
+
- CLI: `chainpatrol orgs assets set-expiry <asset-id...> (--expires <date> | --in <6m|1y|30d> | --clear)`, and `orgs assets list` shows each asset's expiry.
|
|
12
|
+
|
|
13
|
+
Backed by @chainpatrol/external-trpc and @chainpatrol/validation, which are private.
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- 34543e7: Call unconfirmed detection results "suspected threats" in descriptions and help text. The `detection_list` and `webhook_config` MCP tool descriptions, the `detection_evaluation` prompt and the server instructions, the `chainpatrol detections list` help and shell completions, and the SDK's `DetectionListInput` / `DetectionListItem` docs and bundled CLI skill now say "suspected threats" where they meant an unconfirmed result. No command, tool, endpoint, field or type name changes. The matching description changes in @chainpatrol/external-trpc are in a private package and need no version bump.
|
|
18
|
+
- Updated dependencies [7745183]
|
|
19
|
+
- Updated dependencies [8f841bc]
|
|
20
|
+
- Updated dependencies [8c6bc23]
|
|
21
|
+
- Updated dependencies [e2360a1]
|
|
22
|
+
- Updated dependencies [f1026ab]
|
|
23
|
+
- Updated dependencies [84b14a7]
|
|
24
|
+
- Updated dependencies [3c88e8c]
|
|
25
|
+
- Updated dependencies [139bb37]
|
|
26
|
+
- Updated dependencies [ac7b96a]
|
|
27
|
+
- Updated dependencies [34543e7]
|
|
28
|
+
- Updated dependencies [5146d02]
|
|
29
|
+
- @chainpatrol/sdk@1.19.0
|
|
30
|
+
- @chainpatrol/mcp@1.17.0
|
|
31
|
+
|
|
32
|
+
## 1.18.0
|
|
33
|
+
|
|
34
|
+
### Minor Changes
|
|
35
|
+
|
|
36
|
+
- 34e7f89: `/metrics/takedown-time` can now be narrowed to several asset types at once, either
|
|
37
|
+
individually (`assetTypes`) or by the app's asset-type filter groups
|
|
38
|
+
(`assetTypeGroups`, e.g. `DOMAINS`, `SOCIALS`). It also returns `overall`: one
|
|
39
|
+
median pooled across every takedown in scope, which cannot be worked out from the
|
|
40
|
+
per-asset-type medians. The CLI exposes these as `chainpatrol metrics takedown-time
|
|
41
|
+
--asset-type <list> --asset-group <list>` and prints the overall median first.
|
|
42
|
+
Server-side work in @chainpatrol/validation, @chainpatrol/external-trpc and
|
|
43
|
+
@chainpatrol/metrics supports this; those are private packages.
|
|
44
|
+
|
|
45
|
+
### Patch Changes
|
|
46
|
+
|
|
47
|
+
- 3c71e43: Time-to-takedown results carry `excludedAssetTypes`: the asset types the API left out because no asset-type filter was given (crypto addresses by default). `chainpatrol metrics takedown-time` and `takedown-time-trend` now label the unfiltered median "all asset types except ADDRESS" instead of "all asset types", and their help explains the default.
|
|
48
|
+
- Updated dependencies [3c71e43]
|
|
49
|
+
- Updated dependencies [34e7f89]
|
|
50
|
+
- Updated dependencies [3c71e43]
|
|
51
|
+
- @chainpatrol/sdk@1.18.0
|
|
52
|
+
- @chainpatrol/mcp@1.16.0
|
|
53
|
+
|
|
3
54
|
## 1.17.2
|
|
4
55
|
|
|
5
56
|
### Patch Changes
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
import {
|
|
5
5
|
installCompletions,
|
|
6
6
|
uninstallCompletions
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-XICYSDVF.js";
|
|
8
8
|
|
|
9
9
|
// src/commands/setup-skill.ts
|
|
10
10
|
import { mkdirSync as mkdirSync2, writeFileSync as writeFileSync2, existsSync as existsSync2, readFileSync as readFileSync2, rmSync } from "fs";
|
|
@@ -17,10 +17,6 @@ import { parseSkillVersion as parseSkillVersion2 } from "@chainpatrol/sdk/skill"
|
|
|
17
17
|
import { mkdirSync, writeFileSync, readFileSync, existsSync, unlinkSync } from "fs";
|
|
18
18
|
import { homedir } from "os";
|
|
19
19
|
import { join, dirname } from "path";
|
|
20
|
-
var CLAUDE_DIR = join(homedir(), ".claude");
|
|
21
|
-
var HOOK_DIR = join(CLAUDE_DIR, "hooks");
|
|
22
|
-
var HOOK_FILE = join(HOOK_DIR, "chainpatrol-login.sh");
|
|
23
|
-
var SETTINGS_FILE = join(CLAUDE_DIR, "settings.json");
|
|
24
20
|
var HOOK_SCRIPT = `#!/bin/bash
|
|
25
21
|
# chainpatrol auto-login hook \u2014 installed by \`chainpatrol setup\`.
|
|
26
22
|
# On Claude Code session start, if the user has no chainpatrol credentials,
|
|
@@ -46,68 +42,77 @@ cat <<'JSON'
|
|
|
46
42
|
JSON
|
|
47
43
|
exit 0
|
|
48
44
|
`;
|
|
49
|
-
function
|
|
50
|
-
|
|
51
|
-
|
|
45
|
+
function getLoginHookPaths(homeDir = homedir()) {
|
|
46
|
+
const claudeDir = join(homeDir, ".claude");
|
|
47
|
+
return {
|
|
48
|
+
hookFile: join(claudeDir, "hooks", "chainpatrol-login.sh"),
|
|
49
|
+
settingsFile: join(claudeDir, "settings.json")
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
function installLoginHook(homeDir = homedir()) {
|
|
53
|
+
const { hookFile, settingsFile } = getLoginHookPaths(homeDir);
|
|
54
|
+
mkdirSync(dirname(hookFile), { recursive: true });
|
|
55
|
+
const hookWritten = !existsSync(hookFile) || readFileSync(hookFile, "utf-8") !== HOOK_SCRIPT;
|
|
52
56
|
if (hookWritten) {
|
|
53
|
-
writeFileSync(
|
|
57
|
+
writeFileSync(hookFile, HOOK_SCRIPT, { mode: 493 });
|
|
54
58
|
}
|
|
55
|
-
const settingsUpdated = registerHookInSettings();
|
|
59
|
+
const settingsUpdated = registerHookInSettings(settingsFile, hookFile);
|
|
56
60
|
return {
|
|
57
|
-
hookPath:
|
|
61
|
+
hookPath: hookFile,
|
|
58
62
|
hookWritten,
|
|
59
|
-
settingsPath:
|
|
63
|
+
settingsPath: settingsFile,
|
|
60
64
|
settingsUpdated
|
|
61
65
|
};
|
|
62
66
|
}
|
|
63
|
-
function uninstallLoginHook() {
|
|
67
|
+
function uninstallLoginHook(homeDir = homedir()) {
|
|
68
|
+
const { hookFile, settingsFile } = getLoginHookPaths(homeDir);
|
|
64
69
|
let hookRemoved = false;
|
|
65
|
-
if (existsSync(
|
|
66
|
-
unlinkSync(
|
|
70
|
+
if (existsSync(hookFile)) {
|
|
71
|
+
unlinkSync(hookFile);
|
|
67
72
|
hookRemoved = true;
|
|
68
73
|
}
|
|
69
|
-
const settingsUpdated = unregisterHookFromSettings();
|
|
74
|
+
const settingsUpdated = unregisterHookFromSettings(settingsFile, hookFile);
|
|
70
75
|
return { hookRemoved, settingsUpdated };
|
|
71
76
|
}
|
|
72
|
-
function readSettings() {
|
|
73
|
-
if (!existsSync(
|
|
74
|
-
const raw = readFileSync(
|
|
77
|
+
function readSettings(settingsFile) {
|
|
78
|
+
if (!existsSync(settingsFile)) return {};
|
|
79
|
+
const raw = readFileSync(settingsFile, "utf-8");
|
|
75
80
|
if (raw.trim() === "") return {};
|
|
76
81
|
return JSON.parse(raw);
|
|
77
82
|
}
|
|
78
|
-
function writeSettings(settings) {
|
|
79
|
-
mkdirSync(dirname(
|
|
80
|
-
writeFileSync(
|
|
83
|
+
function writeSettings(settingsFile, settings) {
|
|
84
|
+
mkdirSync(dirname(settingsFile), { recursive: true });
|
|
85
|
+
writeFileSync(settingsFile, JSON.stringify(settings, null, 2) + "\n", {
|
|
81
86
|
mode: 420
|
|
82
87
|
});
|
|
83
88
|
}
|
|
84
|
-
function hasHookEntry(settings) {
|
|
89
|
+
function hasHookEntry(settings, hookFile) {
|
|
85
90
|
const matchers = settings.hooks?.SessionStart;
|
|
86
91
|
if (!Array.isArray(matchers)) return false;
|
|
87
92
|
return matchers.some(
|
|
88
|
-
(matcher) => Array.isArray(matcher?.hooks) && matcher.hooks.some((h) => h?.command ===
|
|
93
|
+
(matcher) => Array.isArray(matcher?.hooks) && matcher.hooks.some((h) => h?.command === hookFile)
|
|
89
94
|
);
|
|
90
95
|
}
|
|
91
|
-
function registerHookInSettings() {
|
|
92
|
-
const settings = readSettings();
|
|
93
|
-
if (hasHookEntry(settings)) return false;
|
|
96
|
+
function registerHookInSettings(settingsFile, hookFile) {
|
|
97
|
+
const settings = readSettings(settingsFile);
|
|
98
|
+
if (hasHookEntry(settings, hookFile)) return false;
|
|
94
99
|
const hooks = settings.hooks ??= {};
|
|
95
100
|
const sessionStart = hooks.SessionStart ??= [];
|
|
96
101
|
sessionStart.push({
|
|
97
|
-
hooks: [{ type: "command", command:
|
|
102
|
+
hooks: [{ type: "command", command: hookFile }]
|
|
98
103
|
});
|
|
99
|
-
writeSettings(settings);
|
|
104
|
+
writeSettings(settingsFile, settings);
|
|
100
105
|
return true;
|
|
101
106
|
}
|
|
102
|
-
function unregisterHookFromSettings() {
|
|
103
|
-
if (!existsSync(
|
|
104
|
-
const settings = readSettings();
|
|
107
|
+
function unregisterHookFromSettings(settingsFile, hookFile) {
|
|
108
|
+
if (!existsSync(settingsFile)) return false;
|
|
109
|
+
const settings = readSettings(settingsFile);
|
|
105
110
|
const sessionStart = settings.hooks?.SessionStart;
|
|
106
111
|
if (!Array.isArray(sessionStart)) return false;
|
|
107
112
|
let changed = false;
|
|
108
113
|
const filtered = sessionStart.map((matcher) => {
|
|
109
114
|
if (!Array.isArray(matcher?.hooks)) return matcher;
|
|
110
|
-
const remaining = matcher.hooks.filter((h) => h?.command !==
|
|
115
|
+
const remaining = matcher.hooks.filter((h) => h?.command !== hookFile);
|
|
111
116
|
if (remaining.length === matcher.hooks.length) return matcher;
|
|
112
117
|
changed = true;
|
|
113
118
|
return remaining.length > 0 ? { ...matcher, hooks: remaining } : null;
|
|
@@ -121,30 +126,33 @@ function unregisterHookFromSettings() {
|
|
|
121
126
|
} else {
|
|
122
127
|
settings.hooks.SessionStart = filtered;
|
|
123
128
|
}
|
|
124
|
-
writeSettings(settings);
|
|
129
|
+
writeSettings(settingsFile, settings);
|
|
125
130
|
return true;
|
|
126
131
|
}
|
|
127
132
|
|
|
128
133
|
// src/commands/setup-skill.ts
|
|
129
|
-
|
|
130
|
-
|
|
134
|
+
function getSkillPaths(homeDir) {
|
|
135
|
+
const dir = join2(homeDir, ".claude", "skills", "chainpatrol");
|
|
136
|
+
return { dir, file: join2(dir, "SKILL.md") };
|
|
137
|
+
}
|
|
131
138
|
function getBundledSkillVersion() {
|
|
132
139
|
return getCliVersion();
|
|
133
140
|
}
|
|
134
141
|
function getBundledSkillContent() {
|
|
135
142
|
return buildSkillContent(getCliVersion());
|
|
136
143
|
}
|
|
137
|
-
function readInstalledSkillVersion() {
|
|
138
|
-
|
|
144
|
+
function readInstalledSkillVersion(homeDir = homedir2()) {
|
|
145
|
+
const { file } = getSkillPaths(homeDir);
|
|
146
|
+
if (!existsSync2(file)) return void 0;
|
|
139
147
|
try {
|
|
140
|
-
const raw = readFileSync2(
|
|
148
|
+
const raw = readFileSync2(file, "utf-8");
|
|
141
149
|
return parseSkillVersion(raw);
|
|
142
150
|
} catch {
|
|
143
151
|
return void 0;
|
|
144
152
|
}
|
|
145
153
|
}
|
|
146
|
-
function isSkillInstalled() {
|
|
147
|
-
return existsSync2(
|
|
154
|
+
function isSkillInstalled(homeDir = homedir2()) {
|
|
155
|
+
return existsSync2(getSkillPaths(homeDir).file);
|
|
148
156
|
}
|
|
149
157
|
var LOGO = `
|
|
150
158
|
\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2557
|
|
@@ -158,31 +166,34 @@ var LOGO = `
|
|
|
158
166
|
\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
|
|
159
167
|
`;
|
|
160
168
|
function setupSkill(options) {
|
|
169
|
+
const homeDir = options.homeDir ?? homedir2();
|
|
170
|
+
const log = options.log ?? ((message) => console.log(message));
|
|
171
|
+
const { dir: skillDir, file: skillFile } = getSkillPaths(homeDir);
|
|
161
172
|
const skillContent = buildSkillContent(getCliVersion());
|
|
162
|
-
const skillAlreadyExists = existsSync2(
|
|
163
|
-
const skillUpToDate = skillAlreadyExists && readFileSync2(
|
|
173
|
+
const skillAlreadyExists = existsSync2(skillFile);
|
|
174
|
+
const skillUpToDate = skillAlreadyExists && readFileSync2(skillFile, "utf-8") === skillContent;
|
|
164
175
|
let skillStatus;
|
|
165
176
|
if (!skillAlreadyExists) {
|
|
166
|
-
mkdirSync2(
|
|
167
|
-
writeFileSync2(
|
|
177
|
+
mkdirSync2(skillDir, { recursive: true });
|
|
178
|
+
writeFileSync2(skillFile, skillContent, { mode: 420 });
|
|
168
179
|
skillStatus = "installed";
|
|
169
180
|
} else if (!skillUpToDate) {
|
|
170
|
-
writeFileSync2(
|
|
181
|
+
writeFileSync2(skillFile, skillContent, { mode: 420 });
|
|
171
182
|
skillStatus = "updated";
|
|
172
183
|
} else {
|
|
173
184
|
skillStatus = "up-to-date";
|
|
174
185
|
}
|
|
175
|
-
const completionResult = installCompletions();
|
|
176
|
-
const loginHookResult = options.cloud ? installLoginHook() : null;
|
|
186
|
+
const completionResult = installCompletions(homeDir);
|
|
187
|
+
const loginHookResult = options.cloud ? installLoginHook(homeDir) : null;
|
|
177
188
|
const completionsChanged = completionResult.installed || completionResult.configuredShellRc;
|
|
178
189
|
const loginHookChanged = loginHookResult != null && (loginHookResult.hookWritten || loginHookResult.settingsUpdated);
|
|
179
190
|
const overallStatus = skillStatus !== "up-to-date" ? skillStatus : completionsChanged || loginHookChanged ? "updated" : "up-to-date";
|
|
180
191
|
if (options.json) {
|
|
181
|
-
|
|
192
|
+
log(
|
|
182
193
|
JSON.stringify({
|
|
183
194
|
status: overallStatus,
|
|
184
|
-
path:
|
|
185
|
-
skill: { status: skillStatus, path:
|
|
195
|
+
path: skillFile,
|
|
196
|
+
skill: { status: skillStatus, path: skillFile },
|
|
186
197
|
completions: completionResult,
|
|
187
198
|
loginHook: loginHookResult
|
|
188
199
|
})
|
|
@@ -190,45 +201,46 @@ function setupSkill(options) {
|
|
|
190
201
|
return;
|
|
191
202
|
}
|
|
192
203
|
if (overallStatus === "up-to-date") {
|
|
193
|
-
|
|
204
|
+
log("Claude Code skill, completions, and login hook are already up to date.");
|
|
194
205
|
return;
|
|
195
206
|
}
|
|
196
|
-
|
|
207
|
+
log(LOGO);
|
|
197
208
|
if (skillStatus === "installed") {
|
|
198
|
-
|
|
209
|
+
log(`Installed Claude Code skill at ${skillFile}`);
|
|
199
210
|
} else if (skillStatus === "updated") {
|
|
200
|
-
|
|
211
|
+
log(`Updated Claude Code skill at ${skillFile}`);
|
|
201
212
|
}
|
|
202
|
-
|
|
213
|
+
log("You can now use /chainpatrol in Claude Code from any project.");
|
|
203
214
|
if (loginHookChanged && loginHookResult) {
|
|
204
|
-
|
|
215
|
+
log(`Installed auto-login hook at ${loginHookResult.hookPath}`);
|
|
205
216
|
if (loginHookResult.settingsUpdated) {
|
|
206
|
-
|
|
217
|
+
log(`Registered SessionStart hook in ${loginHookResult.settingsPath}`);
|
|
207
218
|
}
|
|
208
219
|
}
|
|
209
220
|
if (completionResult.installed) {
|
|
210
|
-
|
|
211
|
-
`Installed ${completionResult.shell} completions at ${completionResult.path}`
|
|
212
|
-
);
|
|
221
|
+
log(`Installed ${completionResult.shell} completions at ${completionResult.path}`);
|
|
213
222
|
if (completionResult.configuredShellRc) {
|
|
214
|
-
|
|
223
|
+
log("Added completion config to ~/.zshrc");
|
|
215
224
|
}
|
|
216
|
-
|
|
225
|
+
log('Run "exec zsh" or open a new terminal to enable tab completion.');
|
|
217
226
|
}
|
|
218
227
|
}
|
|
219
228
|
function uninstallSkill(options) {
|
|
220
|
-
const
|
|
229
|
+
const homeDir = options.homeDir ?? homedir2();
|
|
230
|
+
const log = options.log ?? ((message) => console.log(message));
|
|
231
|
+
const { dir: skillDir, file: skillFile } = getSkillPaths(homeDir);
|
|
232
|
+
const skillInstalled = existsSync2(skillFile);
|
|
221
233
|
if (skillInstalled) {
|
|
222
|
-
rmSync(
|
|
234
|
+
rmSync(skillDir, { recursive: true });
|
|
223
235
|
}
|
|
224
|
-
const removedCompletions = uninstallCompletions();
|
|
225
|
-
const loginHookResult = uninstallLoginHook();
|
|
236
|
+
const removedCompletions = uninstallCompletions(homeDir);
|
|
237
|
+
const loginHookResult = uninstallLoginHook(homeDir);
|
|
226
238
|
const removedAnything = skillInstalled || removedCompletions || loginHookResult.hookRemoved || loginHookResult.settingsUpdated;
|
|
227
239
|
if (options.json) {
|
|
228
|
-
|
|
240
|
+
log(
|
|
229
241
|
JSON.stringify({
|
|
230
242
|
status: removedAnything ? "uninstalled" : "not-installed",
|
|
231
|
-
path:
|
|
243
|
+
path: skillFile,
|
|
232
244
|
removedCompletions,
|
|
233
245
|
loginHook: loginHookResult
|
|
234
246
|
})
|
|
@@ -236,17 +248,17 @@ function uninstallSkill(options) {
|
|
|
236
248
|
return;
|
|
237
249
|
}
|
|
238
250
|
if (!removedAnything) {
|
|
239
|
-
|
|
251
|
+
log("Claude Code skill is not installed.");
|
|
240
252
|
return;
|
|
241
253
|
}
|
|
242
254
|
if (skillInstalled) {
|
|
243
|
-
|
|
255
|
+
log("Removed Claude Code skill from " + skillDir);
|
|
244
256
|
}
|
|
245
257
|
if (loginHookResult.hookRemoved || loginHookResult.settingsUpdated) {
|
|
246
|
-
|
|
258
|
+
log("Removed chainpatrol auto-login hook.");
|
|
247
259
|
}
|
|
248
260
|
if (removedCompletions) {
|
|
249
|
-
|
|
261
|
+
log("Removed shell completions.");
|
|
250
262
|
}
|
|
251
263
|
}
|
|
252
264
|
|
|
@@ -19,7 +19,7 @@ _chainpatrol() {
|
|
|
19
19
|
'whoami:Show the current authenticated identity'
|
|
20
20
|
'asset:Check or list assets against ChainPatrol'
|
|
21
21
|
'configs:Manage detection configs'
|
|
22
|
-
'detections:Validate, run
|
|
22
|
+
'detections:Validate, run and update detection configs; list suspected threats'
|
|
23
23
|
'metrics:Query organization metrics'
|
|
24
24
|
'reports:Create, list, search reports from terminal'
|
|
25
25
|
'proposals:Review proposals waiting on your organization'
|
|
@@ -83,7 +83,7 @@ _chainpatrol() {
|
|
|
83
83
|
'validate:Validate detection configs'
|
|
84
84
|
'drift:Show detection drift signals'
|
|
85
85
|
'run:Run detection configs'
|
|
86
|
-
'list:List
|
|
86
|
+
'list:List suspected threats'
|
|
87
87
|
'configs:Manage detection configs'
|
|
88
88
|
)
|
|
89
89
|
_describe 'subcommand' detections_subcommands
|
|
@@ -212,7 +212,7 @@ var BASH_COMPLETION = `_chainpatrol() {
|
|
|
212
212
|
;;
|
|
213
213
|
assets)
|
|
214
214
|
if [[ "\${COMP_WORDS[COMP_CWORD-2]}" == "orgs" ]]; then
|
|
215
|
-
COMPREPLY=( $(compgen -W "list" -- "\${cur}") )
|
|
215
|
+
COMPREPLY=( $(compgen -W "list set-expiry" -- "\${cur}") )
|
|
216
216
|
return 0
|
|
217
217
|
fi
|
|
218
218
|
;;
|
|
@@ -254,13 +254,18 @@ function printCompletions(shell) {
|
|
|
254
254
|
const resolved = shell ?? (process.env.SHELL?.includes("zsh") ? "zsh" : "bash");
|
|
255
255
|
console.log(getCompletionScript(resolved));
|
|
256
256
|
}
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
257
|
+
function getZshPaths(homeDir) {
|
|
258
|
+
const completionsDir = join(homeDir, ".zsh", "completions");
|
|
259
|
+
return {
|
|
260
|
+
completionsDir,
|
|
261
|
+
completionFile: join(completionsDir, "_chainpatrol"),
|
|
262
|
+
zshrc: join(homeDir, ".zshrc")
|
|
263
|
+
};
|
|
264
|
+
}
|
|
260
265
|
var SHELL_MARKER = "# Added by chainpatrol setup";
|
|
261
|
-
function ensureZshrcCompletions() {
|
|
262
|
-
if (!existsSync(
|
|
263
|
-
const content = readFileSync(
|
|
266
|
+
function ensureZshrcCompletions(zshrc) {
|
|
267
|
+
if (!existsSync(zshrc)) return false;
|
|
268
|
+
const content = readFileSync(zshrc, "utf-8");
|
|
264
269
|
if (content.includes(SHELL_MARKER)) return false;
|
|
265
270
|
const snippet = [
|
|
266
271
|
"",
|
|
@@ -269,12 +274,12 @@ function ensureZshrcCompletions() {
|
|
|
269
274
|
"autoload -Uz compinit && compinit",
|
|
270
275
|
""
|
|
271
276
|
].join("\n");
|
|
272
|
-
appendFileSync(
|
|
277
|
+
appendFileSync(zshrc, snippet);
|
|
273
278
|
return true;
|
|
274
279
|
}
|
|
275
|
-
function removeZshrcCompletions() {
|
|
276
|
-
if (!existsSync(
|
|
277
|
-
const content = readFileSync(
|
|
280
|
+
function removeZshrcCompletions(zshrc) {
|
|
281
|
+
if (!existsSync(zshrc)) return false;
|
|
282
|
+
const content = readFileSync(zshrc, "utf-8");
|
|
278
283
|
if (!content.includes(SHELL_MARKER)) return false;
|
|
279
284
|
const lines = content.split("\n");
|
|
280
285
|
const filtered = lines.filter((line, i) => {
|
|
@@ -283,26 +288,28 @@ function removeZshrcCompletions() {
|
|
|
283
288
|
if (line === "autoload -Uz compinit && compinit") return false;
|
|
284
289
|
return true;
|
|
285
290
|
});
|
|
286
|
-
writeFileSync(
|
|
291
|
+
writeFileSync(zshrc, filtered.join("\n"));
|
|
287
292
|
return true;
|
|
288
293
|
}
|
|
289
|
-
function installCompletions() {
|
|
294
|
+
function installCompletions(homeDir = homedir()) {
|
|
290
295
|
const shell = process.env.SHELL ?? "";
|
|
291
296
|
if (!shell.includes("zsh")) {
|
|
292
297
|
return { installed: false, path: "", shell: "bash", configuredShellRc: false };
|
|
293
298
|
}
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
299
|
+
const { completionsDir, completionFile, zshrc } = getZshPaths(homeDir);
|
|
300
|
+
mkdirSync(completionsDir, { recursive: true });
|
|
301
|
+
writeFileSync(completionFile, ZSH_COMPLETION, { mode: 420 });
|
|
302
|
+
const configuredShellRc = ensureZshrcCompletions(zshrc);
|
|
303
|
+
return { installed: true, path: completionFile, shell: "zsh", configuredShellRc };
|
|
298
304
|
}
|
|
299
|
-
function uninstallCompletions() {
|
|
305
|
+
function uninstallCompletions(homeDir = homedir()) {
|
|
306
|
+
const { completionFile, zshrc } = getZshPaths(homeDir);
|
|
300
307
|
let removed = false;
|
|
301
|
-
if (existsSync(
|
|
302
|
-
unlinkSync(
|
|
308
|
+
if (existsSync(completionFile)) {
|
|
309
|
+
unlinkSync(completionFile);
|
|
303
310
|
removed = true;
|
|
304
311
|
}
|
|
305
|
-
removeZshrcCompletions();
|
|
312
|
+
removeZshrcCompletions(zshrc);
|
|
306
313
|
return removed;
|
|
307
314
|
}
|
|
308
315
|
|
package/dist/cli.js
CHANGED
|
@@ -11,12 +11,12 @@ import {
|
|
|
11
11
|
getBundledSkillVersion,
|
|
12
12
|
isSkillInstalled,
|
|
13
13
|
readInstalledSkillVersion
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-RAFCCHOO.js";
|
|
15
15
|
import {
|
|
16
16
|
compareVersions,
|
|
17
17
|
getCliVersion
|
|
18
18
|
} from "./chunk-OKIUEBUK.js";
|
|
19
|
-
import "./chunk-
|
|
19
|
+
import "./chunk-XICYSDVF.js";
|
|
20
20
|
import {
|
|
21
21
|
DateTime
|
|
22
22
|
} from "./chunk-TFCNKBRC.js";
|
|
@@ -175,7 +175,7 @@ var HELP = {
|
|
|
175
175
|
examples: ["chainpatrol configs list --org acme"]
|
|
176
176
|
},
|
|
177
177
|
detections: {
|
|
178
|
-
description: "Validate, run
|
|
178
|
+
description: "Validate, run and update detection configs, and list suspected threats.",
|
|
179
179
|
usage: "chainpatrol detections <healthcheck|validate|drift|run|list|configs>",
|
|
180
180
|
options: ["--org <slug> Organization slug"],
|
|
181
181
|
examples: [
|
|
@@ -188,7 +188,7 @@ var HELP = {
|
|
|
188
188
|
]
|
|
189
189
|
},
|
|
190
190
|
"detections list": {
|
|
191
|
-
description: "List recent
|
|
191
|
+
description: "List recent suspected threats for an organization: unconfirmed results of automated threat detection. Returns human-readable confidence levels (none/low/medium/high) and report status. Filter parity with the app's Suspected Threats page: source, confidence, asset status/type, brand, liveness, watchlist, reported, country, and deleted items.",
|
|
192
192
|
usage: "chainpatrol detections list --org <slug> [filters]",
|
|
193
193
|
options: [
|
|
194
194
|
"--org <slug> Organization slug",
|
|
@@ -204,12 +204,12 @@ var HELP = {
|
|
|
204
204
|
"--watchlist <list> Comma list: ENABLED|DISABLED",
|
|
205
205
|
"--reported <list> Comma list: reported|not_reported",
|
|
206
206
|
"--country-code <list> Comma list of 2-letter ISO country codes (e.g. US,GB)",
|
|
207
|
-
"--only-deleted Return only soft-deleted
|
|
208
|
-
"--exclude-deleted Leave soft-deleted
|
|
207
|
+
"--only-deleted Return only soft-deleted suspected threats. Without this flag the endpoint returns both deleted and non-deleted (existing public-API behavior).",
|
|
208
|
+
"--exclude-deleted Leave soft-deleted suspected threats out, so totals match the app. Cannot be combined with --only-deleted",
|
|
209
209
|
"--block-status <list> Comma list: blocked|pending. Both = every confirmed threat, including pending blocks for orgs without active protection",
|
|
210
|
-
"--min-score <n> Only
|
|
211
|
-
"--max-score <n> Only
|
|
212
|
-
"--include-total Also print how many
|
|
210
|
+
"--min-score <n> Only suspected threats with raw score >= n (0-1). Use instead of --confidence for a fixed cut-off",
|
|
211
|
+
"--max-score <n> Only suspected threats with raw score <= n (0-1)",
|
|
212
|
+
"--include-total Also print how many suspected threats match across all pages",
|
|
213
213
|
"--from <iso> Start date (ISO 8601)",
|
|
214
214
|
"--to <iso> End date (ISO 8601)"
|
|
215
215
|
],
|
|
@@ -361,14 +361,20 @@ var HELP = {
|
|
|
361
361
|
]
|
|
362
362
|
},
|
|
363
363
|
"metrics takedown-time": {
|
|
364
|
-
description: "Median time from takedown start to completion, per asset type. Defaults to the trailing 3 months if no date range is given.",
|
|
365
|
-
usage: "chainpatrol metrics takedown-time --org <slug> [--from ISO --to ISO|--this-week]",
|
|
364
|
+
description: "Median time from takedown start to completion: one overall median pooled across every takedown in scope, plus one per asset type. Narrow to asset types or to the app's asset-type groups (Domains, Socials, \u2026). Defaults to the trailing 3 months if no date range is given. Crypto addresses (ADDRESS) are left out unless you ask for them with --asset-type ADDRESS or --asset-group CRYPTO: an address is reported on many sites at once, and how long its takedown takes depends on how many platforms are covered.",
|
|
365
|
+
usage: "chainpatrol metrics takedown-time --org <slug> [--from ISO --to ISO|--this-week] [--asset-type URL,TWITTER] [--asset-group DOMAINS,SOCIALS]",
|
|
366
366
|
options: [
|
|
367
367
|
"--org <slug> Organization slug",
|
|
368
368
|
"--from <iso> Start date (ISO 8601)",
|
|
369
369
|
"--to <iso> End date (ISO 8601); a date-only value covers the whole day",
|
|
370
370
|
"--this-week Use the current ISO week (overrides default)",
|
|
371
|
-
"--brand <ids> Comma-separated brand IDs"
|
|
371
|
+
"--brand <ids> Comma-separated brand IDs",
|
|
372
|
+
"--asset-type <types> Comma-separated asset types to include",
|
|
373
|
+
"--asset-group <list> Comma-separated asset-type groups to include: DOMAINS, SOCIALS, APP_STORES, ADS, EXTENSIONS, CRYPTO, EMAIL, PACKAGES, OTHER. Unioned with --asset-type"
|
|
374
|
+
],
|
|
375
|
+
examples: [
|
|
376
|
+
"chainpatrol metrics takedown-time --org acme --asset-group DOMAINS",
|
|
377
|
+
"chainpatrol metrics takedown-time --org acme --asset-group SOCIALS --asset-type EMAIL"
|
|
372
378
|
]
|
|
373
379
|
},
|
|
374
380
|
"metrics time-to-detection": {
|
|
@@ -383,7 +389,7 @@ var HELP = {
|
|
|
383
389
|
]
|
|
384
390
|
},
|
|
385
391
|
"metrics takedown-time-trend": {
|
|
386
|
-
description: "Median time from takedown start to completion bucketed by month, over a trailing window, with the month-over-month change.",
|
|
392
|
+
description: "Median time from takedown start to completion bucketed by month, over a trailing window, with the month-over-month change. Crypto addresses (ADDRESS) are left out of the pooled series unless you pass --asset-type ADDRESS.",
|
|
387
393
|
usage: "chainpatrol metrics takedown-time-trend --org <slug> [--months 12] [--asset-type TWITTER,URL]",
|
|
388
394
|
options: [
|
|
389
395
|
"--org <slug> Organization slug",
|
|
@@ -593,18 +599,19 @@ var HELP = {
|
|
|
593
599
|
},
|
|
594
600
|
orgs: {
|
|
595
601
|
description: "List organizations, their assets, and asset groups. Top-level `orgs list` lists organizations accessible to you; `orgs get <slug>` returns details for a single accessible org; the nested subcommands operate on the org tied to your API key.",
|
|
596
|
-
usage: "chainpatrol orgs <list|get <slug>|assets list|watchlist list|asset-groups list>",
|
|
602
|
+
usage: "chainpatrol orgs <list|get <slug>|assets list|assets set-expiry|watchlist list|asset-groups list>",
|
|
597
603
|
examples: [
|
|
598
604
|
"chainpatrol orgs list",
|
|
599
605
|
"chainpatrol orgs get acme",
|
|
600
606
|
"chainpatrol orgs assets list --asset-type URL",
|
|
607
|
+
"chainpatrol orgs assets set-expiry 12345 --in 6m",
|
|
601
608
|
"chainpatrol orgs watchlist list --include-total",
|
|
602
609
|
"chainpatrol orgs asset-groups list"
|
|
603
610
|
]
|
|
604
611
|
},
|
|
605
612
|
"orgs assets": {
|
|
606
|
-
description: "List assets in your organization's allowlist.",
|
|
607
|
-
usage: "chainpatrol orgs assets list
|
|
613
|
+
description: "List assets in your organization's allowlist, or set when they expire.",
|
|
614
|
+
usage: "chainpatrol orgs assets <list|set-expiry>"
|
|
608
615
|
},
|
|
609
616
|
"orgs assets list": {
|
|
610
617
|
description: "List assets belonging to an organization's allowlist. Pass --org <slug> to choose one, or omit it to use the org tied to your API key. Supports filtering by type, group, and search query.",
|
|
@@ -624,6 +631,23 @@ var HELP = {
|
|
|
624
631
|
"chainpatrol orgs assets list --group-id 12 --per-page 250 --output csv"
|
|
625
632
|
]
|
|
626
633
|
},
|
|
634
|
+
"orgs assets set-expiry": {
|
|
635
|
+
description: "Set, renew or clear when assets drop off your organization's allowlist. After the expiry, assets stay for a 14-day grace period, then are removed from your organization; their status does not change. Needs an organization API key with write access, or an organization owner or admin.",
|
|
636
|
+
usage: "chainpatrol orgs assets set-expiry <asset-id...> (--expires <date> | --in <duration> | --clear)",
|
|
637
|
+
options: [
|
|
638
|
+
"--org <slug> Organization slug (omit for org-scoped API keys)",
|
|
639
|
+
"--expires <date> Expiry date (YYYY-MM-DD, end of that UTC day) or ISO date-time",
|
|
640
|
+
"--in <duration> Expire after a duration from today: 30d, 6m, 1y",
|
|
641
|
+
"--clear Remove the expiry so the assets stay indefinitely",
|
|
642
|
+
"--id <n> Asset ID (repeatable; positional IDs also work)",
|
|
643
|
+
"--dry-run Show what would change without changing it"
|
|
644
|
+
],
|
|
645
|
+
examples: [
|
|
646
|
+
"chainpatrol orgs assets set-expiry 12345 12346 --in 6m",
|
|
647
|
+
"chainpatrol orgs assets set-expiry 12345 --expires 2027-04-30",
|
|
648
|
+
"chainpatrol orgs assets set-expiry 12345 --clear --org acme"
|
|
649
|
+
]
|
|
650
|
+
},
|
|
627
651
|
"orgs watchlist": {
|
|
628
652
|
description: "List the assets ChainPatrol is watching for your organization.",
|
|
629
653
|
usage: "chainpatrol orgs watchlist list [filters]"
|
|
@@ -802,7 +826,7 @@ function getTopLevelHelp() {
|
|
|
802
826
|
" mcp Serve the public API to AI agents over MCP (stdio)",
|
|
803
827
|
" asset Check, search, or list assets, or list supported asset types",
|
|
804
828
|
" configs Manage detection configs",
|
|
805
|
-
" detections Validate, run
|
|
829
|
+
" detections Validate, run and update detection configs; list suspected threats",
|
|
806
830
|
" healthchecks List and run organization healthchecks",
|
|
807
831
|
" metrics Query organization metrics and breakdowns",
|
|
808
832
|
" reports Create, list, and search reports from terminal",
|
|
@@ -838,12 +862,12 @@ var NPM_REGISTRY_URL = "https://registry.npmjs.org/@chainpatrol/cli/latest";
|
|
|
838
862
|
var CHECK_FILE_NAME = "version-check.json";
|
|
839
863
|
var CHECK_INTERVAL_MS = 24 * 60 * 60 * 1e3;
|
|
840
864
|
var NPM_REQUEST_TIMEOUT_MS = 1500;
|
|
841
|
-
function checkSkillStatus() {
|
|
865
|
+
function checkSkillStatus(homeDir) {
|
|
842
866
|
const bundled = getBundledSkillVersion();
|
|
843
|
-
if (!isSkillInstalled()) {
|
|
867
|
+
if (!isSkillInstalled(homeDir)) {
|
|
844
868
|
return { state: "missing", bundled };
|
|
845
869
|
}
|
|
846
|
-
const installed = readInstalledSkillVersion();
|
|
870
|
+
const installed = readInstalledSkillVersion(homeDir);
|
|
847
871
|
if (!installed) {
|
|
848
872
|
return { state: "outdated", installed: void 0, bundled };
|
|
849
873
|
}
|
|
@@ -939,7 +963,7 @@ function formatNpmNudge(status) {
|
|
|
939
963
|
return void 0;
|
|
940
964
|
}
|
|
941
965
|
async function runVersionChecks(options) {
|
|
942
|
-
const skill = checkSkillStatus();
|
|
966
|
+
const skill = checkSkillStatus(options?.homeDir);
|
|
943
967
|
const npm = await checkNpmStatus(options);
|
|
944
968
|
const messages = [];
|
|
945
969
|
const skillMsg = formatSkillNudge(skill);
|
|
@@ -1095,6 +1119,7 @@ ${getTopLevelHelp()}
|
|
|
1095
1119
|
pendingApprovalService: { type: "string" },
|
|
1096
1120
|
query: { type: "string" },
|
|
1097
1121
|
assetType: { type: "string" },
|
|
1122
|
+
assetGroup: { type: "string" },
|
|
1098
1123
|
takedownStatus: { type: "string" },
|
|
1099
1124
|
livenessStatus: { type: "string" },
|
|
1100
1125
|
nextPage: { type: "string" },
|
|
@@ -1104,6 +1129,9 @@ ${getTopLevelHelp()}
|
|
|
1104
1129
|
brandSlug: { type: "string" },
|
|
1105
1130
|
type: { type: "string" },
|
|
1106
1131
|
groupId: { type: "number" },
|
|
1132
|
+
expires: { type: "string" },
|
|
1133
|
+
in: { type: "string" },
|
|
1134
|
+
clear: { type: "boolean", default: false },
|
|
1107
1135
|
confidence: { type: "string" },
|
|
1108
1136
|
assetStatus: { type: "string" },
|
|
1109
1137
|
liveness: { type: "string" },
|
|
@@ -1309,7 +1337,7 @@ async function main() {
|
|
|
1309
1337
|
return;
|
|
1310
1338
|
}
|
|
1311
1339
|
if (cliContext.dryRun) {
|
|
1312
|
-
const dryRunSupported = command === "reports" && subcommand === "create" || command === "proposals" && subcommand === "review" || command === "detections" && subcommand === "run" || command === "detections" && subcommand === "configs" && action === "run" || command === "detections" && subcommand === "configs" && action === "update";
|
|
1340
|
+
const dryRunSupported = command === "reports" && subcommand === "create" || command === "orgs" && subcommand === "assets" && action === "set-expiry" || command === "proposals" && subcommand === "review" || command === "detections" && subcommand === "run" || command === "detections" && subcommand === "configs" && action === "run" || command === "detections" && subcommand === "configs" && action === "update";
|
|
1313
1341
|
if (!dryRunSupported) {
|
|
1314
1342
|
throw new CliExitError(
|
|
1315
1343
|
"--dry-run is only supported for mutation commands.",
|
|
@@ -1622,13 +1650,15 @@ async function main() {
|
|
|
1622
1650
|
break;
|
|
1623
1651
|
}
|
|
1624
1652
|
if (subcommand === "takedown-time" || subcommand === "takedownTime") {
|
|
1625
|
-
const { runMetricsTakedownTime } = await import("./takedown-time-
|
|
1653
|
+
const { runMetricsTakedownTime } = await import("./takedown-time-35OTRJWA.js");
|
|
1626
1654
|
await runMetricsTakedownTime({
|
|
1627
1655
|
org,
|
|
1628
1656
|
from: cli.flags.from,
|
|
1629
1657
|
to: cli.flags.to,
|
|
1630
1658
|
thisWeek: cli.flags.thisWeek,
|
|
1631
1659
|
brandIds: parseBrandIds(),
|
|
1660
|
+
assetTypes: parseCsvList(cli.flags.assetType),
|
|
1661
|
+
assetTypeGroups: parseCsvList(cli.flags.assetGroup),
|
|
1632
1662
|
json: jsonMode,
|
|
1633
1663
|
outputFormat: cliContext.outputFormat
|
|
1634
1664
|
});
|
|
@@ -1648,7 +1678,7 @@ async function main() {
|
|
|
1648
1678
|
break;
|
|
1649
1679
|
}
|
|
1650
1680
|
if (subcommand === "takedown-time-trend" || subcommand === "takedownTimeTrend") {
|
|
1651
|
-
const { runMetricsTakedownTimeTrend } = await import("./takedown-time-trend-
|
|
1681
|
+
const { runMetricsTakedownTimeTrend } = await import("./takedown-time-trend-3PWWE2D3.js");
|
|
1652
1682
|
await runMetricsTakedownTimeTrend({
|
|
1653
1683
|
org,
|
|
1654
1684
|
months: cli.flags.months,
|
|
@@ -1899,7 +1929,7 @@ async function main() {
|
|
|
1899
1929
|
}
|
|
1900
1930
|
if (subcommand === "assets") {
|
|
1901
1931
|
if (action === "list") {
|
|
1902
|
-
const { runOrgsAssetsList } = await import("./list-
|
|
1932
|
+
const { runOrgsAssetsList } = await import("./list-EBX2AYJ5.js");
|
|
1903
1933
|
await runOrgsAssetsList({
|
|
1904
1934
|
// Optional: organization-scoped API keys resolve the org from the
|
|
1905
1935
|
// key, so only pass a slug when one is actually available.
|
|
@@ -1914,7 +1944,27 @@ async function main() {
|
|
|
1914
1944
|
});
|
|
1915
1945
|
break;
|
|
1916
1946
|
}
|
|
1917
|
-
|
|
1947
|
+
if (action === "set-expiry") {
|
|
1948
|
+
const { runOrgsAssetsSetExpiry } = await import("./set-expiry-ZOLZPC4N.js");
|
|
1949
|
+
await runOrgsAssetsSetExpiry({
|
|
1950
|
+
slug: await tryResolveOrg(),
|
|
1951
|
+
assetIds: [
|
|
1952
|
+
...cli.input.slice(3),
|
|
1953
|
+
...cli.flags.id ?? [],
|
|
1954
|
+
...cli.flags.assetId !== void 0 ? [String(cli.flags.assetId)] : []
|
|
1955
|
+
],
|
|
1956
|
+
expires: cli.flags.expires,
|
|
1957
|
+
in: cli.flags.in,
|
|
1958
|
+
clear: cli.flags.clear,
|
|
1959
|
+
dryRun: cliContext.dryRun,
|
|
1960
|
+
json: jsonMode,
|
|
1961
|
+
outputFormat: cliContext.outputFormat
|
|
1962
|
+
});
|
|
1963
|
+
break;
|
|
1964
|
+
}
|
|
1965
|
+
throw new Error(
|
|
1966
|
+
"Usage: chainpatrol orgs assets <list [filters]|set-expiry <asset-id...> (--expires <date> | --in <duration> | --clear)>"
|
|
1967
|
+
);
|
|
1918
1968
|
}
|
|
1919
1969
|
if (subcommand === "watchlist") {
|
|
1920
1970
|
if (action === "list") {
|
|
@@ -1948,7 +1998,7 @@ async function main() {
|
|
|
1948
1998
|
}
|
|
1949
1999
|
const hint = subcommand ? suggest(subcommand, ["list", "get", "assets", "watchlist", "asset-groups"]) : null;
|
|
1950
2000
|
throw new Error(
|
|
1951
|
-
subcommand ? `Unknown subcommand: orgs ${subcommand}${hint ? `. Did you mean "orgs ${hint}"?` : ""}` : "Usage: chainpatrol orgs <list|get <slug>|assets list|watchlist list|asset-groups list> [filters]"
|
|
2001
|
+
subcommand ? `Unknown subcommand: orgs ${subcommand}${hint ? `. Did you mean "orgs ${hint}"?` : ""}` : "Usage: chainpatrol orgs <list|get <slug>|assets list|assets set-expiry|watchlist list|asset-groups list> [filters]"
|
|
1952
2002
|
);
|
|
1953
2003
|
}
|
|
1954
2004
|
case "brands": {
|
|
@@ -2050,17 +2100,17 @@ async function main() {
|
|
|
2050
2100
|
case "setup":
|
|
2051
2101
|
case "install":
|
|
2052
2102
|
case "i": {
|
|
2053
|
-
const { setupSkill } = await import("./setup-skill-
|
|
2103
|
+
const { setupSkill } = await import("./setup-skill-M2PVQC4Z.js");
|
|
2054
2104
|
setupSkill({ json: jsonMode, cloud: cli.flags.cloud });
|
|
2055
2105
|
break;
|
|
2056
2106
|
}
|
|
2057
2107
|
case "uninstall": {
|
|
2058
|
-
const { uninstallSkill } = await import("./setup-skill-
|
|
2108
|
+
const { uninstallSkill } = await import("./setup-skill-M2PVQC4Z.js");
|
|
2059
2109
|
uninstallSkill({ json: jsonMode });
|
|
2060
2110
|
break;
|
|
2061
2111
|
}
|
|
2062
2112
|
case "completions": {
|
|
2063
|
-
const { printCompletions } = await import("./completions-
|
|
2113
|
+
const { printCompletions } = await import("./completions-VJMT2W5B.js");
|
|
2064
2114
|
printCompletions(subcommand);
|
|
2065
2115
|
break;
|
|
2066
2116
|
}
|
|
@@ -24,7 +24,9 @@ function toRow(asset) {
|
|
|
24
24
|
group: asset.group?.name ?? "",
|
|
25
25
|
groupId: asset.group?.id ?? "",
|
|
26
26
|
createdAt: asset.createdAt,
|
|
27
|
-
updatedAt: asset.updatedAt
|
|
27
|
+
updatedAt: asset.updatedAt,
|
|
28
|
+
allowlistExpiresAt: asset.allowlistExpiresAt ?? "",
|
|
29
|
+
allowlistExpiredAt: asset.allowlistExpiredAt ?? ""
|
|
28
30
|
};
|
|
29
31
|
}
|
|
30
32
|
async function runOrgsAssetsList(options) {
|
|
@@ -57,7 +59,7 @@ async function runOrgsAssetsList(options) {
|
|
|
57
59
|
`- Next page cursor: ${result.next_page ?? "none"}`,
|
|
58
60
|
"",
|
|
59
61
|
...rows.map(
|
|
60
|
-
(row) => `- #${row.id} [${row.status}] ${row.content} (${row.type}) group=${row.group || "-"} updated=${row.updatedAt}`
|
|
62
|
+
(row) => `- #${row.id} [${row.status}] ${row.content} (${row.type}) group=${row.group || "-"} updated=${row.updatedAt}${row.allowlistExpiresAt ? ` expires=${row.allowlistExpiresAt}` : ""}`
|
|
61
63
|
)
|
|
62
64
|
].join("\n"),
|
|
63
65
|
csv: toCsvRows(rows),
|
|
@@ -69,7 +71,7 @@ async function runOrgsAssetsList(options) {
|
|
|
69
71
|
console.log(`Organization assets \u2014 returned ${result.assets.length}`);
|
|
70
72
|
for (const row of rows) {
|
|
71
73
|
console.log(
|
|
72
|
-
`#${row.id} [${row.status}] ${row.content} (${row.type}) group=${row.group || "-"} name=${row.name || "-"} updated=${row.updatedAt}`
|
|
74
|
+
`#${row.id} [${row.status}] ${row.content} (${row.type}) group=${row.group || "-"} name=${row.name || "-"} updated=${row.updatedAt}${row.allowlistExpiresAt ? ` expires=${row.allowlistExpiresAt}` : ""}`
|
|
73
75
|
);
|
|
74
76
|
}
|
|
75
77
|
if (result.next_page) {
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CliExitError,
|
|
3
|
+
ExitCode
|
|
4
|
+
} from "./chunk-E2LAMILJ.js";
|
|
5
|
+
import {
|
|
6
|
+
printOutput,
|
|
7
|
+
toCsvRows
|
|
8
|
+
} from "./chunk-VFT3TD3E.js";
|
|
9
|
+
import {
|
|
10
|
+
createApiClient
|
|
11
|
+
} from "./chunk-MCW6HE5W.js";
|
|
12
|
+
import "./chunk-4QZ7KD2Y.js";
|
|
13
|
+
import {
|
|
14
|
+
DateTime
|
|
15
|
+
} from "./chunk-TFCNKBRC.js";
|
|
16
|
+
import "./chunk-ORAY4KMA.js";
|
|
17
|
+
import "./chunk-K4RAUZSD.js";
|
|
18
|
+
|
|
19
|
+
// src/commands/orgs/assets/set-expiry.ts
|
|
20
|
+
var USAGE = "Usage: chainpatrol orgs assets set-expiry <asset-id...> (--expires <date> | --in <6m|1y|30d> | --clear)";
|
|
21
|
+
var DURATION = /^(\d+)\s*(d|m|y)$/i;
|
|
22
|
+
var DATE_ONLY = /^\d{4}-\d{2}-\d{2}$/;
|
|
23
|
+
function parseAssetIds(values) {
|
|
24
|
+
const ids = values.flatMap((value) => value.split(",")).map((value) => value.trim()).filter((value) => value !== "");
|
|
25
|
+
if (ids.length === 0) {
|
|
26
|
+
throw new CliExitError(`Pass at least one asset ID.
|
|
27
|
+
${USAGE}`, ExitCode.USAGE);
|
|
28
|
+
}
|
|
29
|
+
return [
|
|
30
|
+
...new Set(
|
|
31
|
+
ids.map((value) => {
|
|
32
|
+
const id = Number(value);
|
|
33
|
+
if (!Number.isInteger(id) || id <= 0) {
|
|
34
|
+
throw new CliExitError(`Invalid asset ID '${value}'.`, ExitCode.USAGE);
|
|
35
|
+
}
|
|
36
|
+
return id;
|
|
37
|
+
})
|
|
38
|
+
)
|
|
39
|
+
];
|
|
40
|
+
}
|
|
41
|
+
function resolveExpiry(options, now) {
|
|
42
|
+
const given = [options.expires, options.in, options.clear || void 0].filter(
|
|
43
|
+
(value) => value !== void 0
|
|
44
|
+
);
|
|
45
|
+
if (given.length !== 1) {
|
|
46
|
+
throw new CliExitError(
|
|
47
|
+
`Pass exactly one of --expires, --in or --clear.
|
|
48
|
+
${USAGE}`,
|
|
49
|
+
ExitCode.USAGE
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
if (options.clear) return null;
|
|
53
|
+
let expiresAt;
|
|
54
|
+
if (options.in !== void 0) {
|
|
55
|
+
const match = options.in.trim().match(DURATION);
|
|
56
|
+
if (!match) {
|
|
57
|
+
throw new CliExitError(
|
|
58
|
+
`Invalid --in '${options.in}'. Use a number of days, months or years, like 30d, 6m or 1y.`,
|
|
59
|
+
ExitCode.USAGE
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
const amount = Number(match[1]);
|
|
63
|
+
const unit = match[2].toLowerCase();
|
|
64
|
+
expiresAt = now.toUTC().plus(
|
|
65
|
+
unit === "d" ? { days: amount } : unit === "m" ? { months: amount } : { years: amount }
|
|
66
|
+
).endOf("day");
|
|
67
|
+
} else {
|
|
68
|
+
const value = (options.expires ?? "").trim();
|
|
69
|
+
const parsed = DATE_ONLY.test(value) ? DateTime.fromISO(value, { zone: "utc" }).endOf("day") : DateTime.fromISO(value, { setZone: true }).toUTC();
|
|
70
|
+
if (!parsed.isValid) {
|
|
71
|
+
throw new CliExitError(
|
|
72
|
+
`Invalid --expires '${options.expires}'. Use a date like 2027-04-30 or an ISO date-time.`,
|
|
73
|
+
ExitCode.USAGE
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
expiresAt = parsed;
|
|
77
|
+
}
|
|
78
|
+
if (expiresAt <= now.toUTC()) {
|
|
79
|
+
throw new CliExitError("The expiry must be in the future.", ExitCode.USAGE);
|
|
80
|
+
}
|
|
81
|
+
return expiresAt.toISO();
|
|
82
|
+
}
|
|
83
|
+
async function runOrgsAssetsSetExpiry(options) {
|
|
84
|
+
const outputFormat = options.outputFormat ?? (options.json ? "json" : "human");
|
|
85
|
+
const assetIds = parseAssetIds(options.assetIds);
|
|
86
|
+
const expiresAt = resolveExpiry(options, options.now ?? DateTime.now().toUTC());
|
|
87
|
+
const input = {
|
|
88
|
+
slug: options.slug,
|
|
89
|
+
assetIds,
|
|
90
|
+
expiresAt
|
|
91
|
+
};
|
|
92
|
+
const describeExpiry = expiresAt ? `expire on ${expiresAt}` : "never expire";
|
|
93
|
+
if (options.dryRun) {
|
|
94
|
+
printOutput({
|
|
95
|
+
outputFormat,
|
|
96
|
+
json: { dryRun: true, mutation: "organization.assets.setExpiry", payload: input },
|
|
97
|
+
markdown: [
|
|
98
|
+
"# Dry Run: Set Asset Expiry",
|
|
99
|
+
"",
|
|
100
|
+
`- Org: ${input.slug ?? "from API key"}`,
|
|
101
|
+
`- Assets: ${assetIds.length}`,
|
|
102
|
+
`- Expires: ${expiresAt ?? "never (clears the expiry)"}`
|
|
103
|
+
].join("\n"),
|
|
104
|
+
csv: toCsvRows(assetIds.map((id) => ({ id, expiresAt: expiresAt ?? "" }))),
|
|
105
|
+
human: () => {
|
|
106
|
+
console.log("Dry run only. No expiry was changed.");
|
|
107
|
+
console.log(`Would make ${assetIds.length} asset(s) ${describeExpiry}.`);
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
const client = options.apiClient ?? createApiClient();
|
|
113
|
+
const result = await client.setOrganizationAssetsExpiry(input);
|
|
114
|
+
printOutput({
|
|
115
|
+
outputFormat,
|
|
116
|
+
json: result,
|
|
117
|
+
markdown: [
|
|
118
|
+
"# Asset Expiry Updated",
|
|
119
|
+
"",
|
|
120
|
+
`- Updated: ${result.updatedCount}`,
|
|
121
|
+
`- Expires: ${result.expiresAt ?? "never"}`
|
|
122
|
+
].join("\n"),
|
|
123
|
+
csv: toCsvRows(assetIds.map((id) => ({ id, expiresAt: result.expiresAt ?? "" }))),
|
|
124
|
+
human: () => {
|
|
125
|
+
console.log(
|
|
126
|
+
result.expiresAt ? `${result.updatedCount} asset(s) will expire on ${result.expiresAt}. They stay on your organization for 14 days after that, then are removed; their status does not change.` : `Cleared the expiry on ${result.updatedCount} asset(s).`
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
export {
|
|
132
|
+
resolveExpiry,
|
|
133
|
+
runOrgsAssetsSetExpiry
|
|
134
|
+
};
|
|
@@ -6,9 +6,9 @@ import {
|
|
|
6
6
|
readInstalledSkillVersion,
|
|
7
7
|
setupSkill,
|
|
8
8
|
uninstallSkill
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-RAFCCHOO.js";
|
|
10
10
|
import "./chunk-OKIUEBUK.js";
|
|
11
|
-
import "./chunk-
|
|
11
|
+
import "./chunk-XICYSDVF.js";
|
|
12
12
|
export {
|
|
13
13
|
getBundledSkillContent,
|
|
14
14
|
getBundledSkillVersion,
|
|
@@ -26,12 +26,26 @@ function formatDuration(hours) {
|
|
|
26
26
|
}
|
|
27
27
|
return `${(hours / 24).toFixed(1)}d`;
|
|
28
28
|
}
|
|
29
|
+
function formatMedian(label, row) {
|
|
30
|
+
return `${label}: ${formatDuration(row.medianTakedownHours)} (${row.count} takedowns)`;
|
|
31
|
+
}
|
|
32
|
+
function describeAssetTypeScope(assetTypes, assetTypeGroups, excludedAssetTypes = []) {
|
|
33
|
+
const parts = [...assetTypeGroups ?? [], ...assetTypes ?? []];
|
|
34
|
+
if (parts.length > 0) {
|
|
35
|
+
return parts.join(", ");
|
|
36
|
+
}
|
|
37
|
+
return excludedAssetTypes.length > 0 ? `all asset types except ${excludedAssetTypes.join(", ")}` : "all asset types";
|
|
38
|
+
}
|
|
29
39
|
async function runMetricsTakedownTime(options) {
|
|
30
40
|
const range = resolveDateRange({
|
|
31
41
|
from: options.from,
|
|
32
42
|
to: options.to,
|
|
33
43
|
thisWeek: options.thisWeek
|
|
34
44
|
});
|
|
45
|
+
const assetTypes = options.assetTypes?.map((assetType) => assetType.toUpperCase());
|
|
46
|
+
const assetTypeGroups = options.assetTypeGroups?.map(
|
|
47
|
+
(group) => group.toUpperCase()
|
|
48
|
+
);
|
|
35
49
|
const client = options.apiClient ?? createApiClient();
|
|
36
50
|
const result = await client.getMetricsTakedownTime({
|
|
37
51
|
slug: options.org,
|
|
@@ -41,8 +55,16 @@ async function runMetricsTakedownTime(options) {
|
|
|
41
55
|
// day off.
|
|
42
56
|
startDate: options.from ?? range.startDate,
|
|
43
57
|
endDate: options.to ?? range.endDate,
|
|
44
|
-
brandIds: options.brandIds
|
|
58
|
+
brandIds: options.brandIds,
|
|
59
|
+
assetTypes,
|
|
60
|
+
assetTypeGroups
|
|
45
61
|
});
|
|
62
|
+
const scope = describeAssetTypeScope(
|
|
63
|
+
assetTypes,
|
|
64
|
+
assetTypeGroups,
|
|
65
|
+
result.excludedAssetTypes
|
|
66
|
+
);
|
|
67
|
+
const overallLabel = `Overall (${scope})`;
|
|
46
68
|
const outputFormat = options.outputFormat ?? (options.json ? "json" : "human");
|
|
47
69
|
printOutput({
|
|
48
70
|
outputFormat,
|
|
@@ -52,12 +74,14 @@ async function runMetricsTakedownTime(options) {
|
|
|
52
74
|
"",
|
|
53
75
|
`- Range: ${range.startDate} \u2192 ${range.endDate}`,
|
|
54
76
|
"",
|
|
55
|
-
...result.
|
|
56
|
-
|
|
57
|
-
)
|
|
77
|
+
...result.overall ? [`- ${formatMedian(overallLabel, result.overall)}`, ""] : [],
|
|
78
|
+
...result.byAssetType.map((row) => `- ${formatMedian(row.assetType, row)}`)
|
|
58
79
|
].join("\n"),
|
|
59
80
|
csv: toCsvRows(
|
|
60
|
-
|
|
81
|
+
[
|
|
82
|
+
...result.overall ? [{ ...result.overall, assetType: "ALL" }] : [],
|
|
83
|
+
...result.byAssetType
|
|
84
|
+
].map((row) => ({
|
|
61
85
|
rangeLabel: range.label,
|
|
62
86
|
startDate: range.startDate,
|
|
63
87
|
endDate: range.endDate,
|
|
@@ -72,17 +96,19 @@ async function runMetricsTakedownTime(options) {
|
|
|
72
96
|
console.log(`Median time to takedown for ${options.org} \u2014 ${range.label}`);
|
|
73
97
|
console.log(`Range: ${range.startDate} \u2192 ${range.endDate}`);
|
|
74
98
|
if (result.byAssetType.length === 0) {
|
|
75
|
-
console.log(
|
|
99
|
+
console.log(`No completed takedowns in this range for ${scope}.`);
|
|
76
100
|
return;
|
|
77
101
|
}
|
|
102
|
+
if (result.overall) {
|
|
103
|
+
console.log(formatMedian(overallLabel, result.overall));
|
|
104
|
+
}
|
|
78
105
|
for (const row of result.byAssetType) {
|
|
79
|
-
console.log(
|
|
80
|
-
`${row.assetType}: ${formatDuration(row.medianTakedownHours)} (${row.count} takedowns)`
|
|
81
|
-
);
|
|
106
|
+
console.log(formatMedian(row.assetType, row));
|
|
82
107
|
}
|
|
83
108
|
}
|
|
84
109
|
});
|
|
85
110
|
}
|
|
86
111
|
export {
|
|
112
|
+
describeAssetTypeScope,
|
|
87
113
|
runMetricsTakedownTime
|
|
88
114
|
};
|
|
@@ -40,7 +40,8 @@ async function runMetricsTakedownTimeTrend(options) {
|
|
|
40
40
|
assetTypes: options.assetTypes,
|
|
41
41
|
brandIds: options.brandIds
|
|
42
42
|
});
|
|
43
|
-
const
|
|
43
|
+
const excluded = result.excludedAssetTypes ?? [];
|
|
44
|
+
const seriesLabel = (assetType) => assetType ?? (excluded.length > 0 ? `All asset types except ${excluded.join(", ")}` : "All asset types");
|
|
44
45
|
const outputFormat = options.outputFormat ?? (options.json ? "json" : "human");
|
|
45
46
|
printOutput({
|
|
46
47
|
outputFormat,
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@chainpatrol/cli",
|
|
3
3
|
"description": "The official ChainPatrol CLI — terminal interface for threat detection",
|
|
4
4
|
"author": "Umar Ahmed <umar@chainpatrol.io>",
|
|
5
|
-
"version": "1.
|
|
5
|
+
"version": "1.19.0",
|
|
6
6
|
"license": "UNLICENSED",
|
|
7
7
|
"homepage": "https://chainpatrol.com/docs/cli",
|
|
8
8
|
"keywords": [
|
|
@@ -33,8 +33,8 @@
|
|
|
33
33
|
"lint": "npx oxlint ."
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@chainpatrol/mcp": "1.
|
|
37
|
-
"@chainpatrol/sdk": "1.
|
|
36
|
+
"@chainpatrol/mcp": "1.17.0",
|
|
37
|
+
"@chainpatrol/sdk": "1.19.0",
|
|
38
38
|
"@modelcontextprotocol/sdk": "^1.30.0",
|
|
39
39
|
"ink": "^7.0.1",
|
|
40
40
|
"meow": "^14.1.0",
|