@chainpatrol/cli 1.18.0 → 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 CHANGED
@@ -1,5 +1,34 @@
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
+
3
32
  ## 1.18.0
4
33
 
5
34
  ### Minor Changes
@@ -4,7 +4,7 @@ import {
4
4
  import {
5
5
  installCompletions,
6
6
  uninstallCompletions
7
- } from "./chunk-DY5VY6FO.js";
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 installLoginHook() {
50
- mkdirSync(HOOK_DIR, { recursive: true });
51
- const hookWritten = !existsSync(HOOK_FILE) || readFileSync(HOOK_FILE, "utf-8") !== HOOK_SCRIPT;
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(HOOK_FILE, HOOK_SCRIPT, { mode: 493 });
57
+ writeFileSync(hookFile, HOOK_SCRIPT, { mode: 493 });
54
58
  }
55
- const settingsUpdated = registerHookInSettings();
59
+ const settingsUpdated = registerHookInSettings(settingsFile, hookFile);
56
60
  return {
57
- hookPath: HOOK_FILE,
61
+ hookPath: hookFile,
58
62
  hookWritten,
59
- settingsPath: SETTINGS_FILE,
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(HOOK_FILE)) {
66
- unlinkSync(HOOK_FILE);
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(SETTINGS_FILE)) return {};
74
- const raw = readFileSync(SETTINGS_FILE, "utf-8");
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(SETTINGS_FILE), { recursive: true });
80
- writeFileSync(SETTINGS_FILE, JSON.stringify(settings, null, 2) + "\n", {
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 === HOOK_FILE)
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: HOOK_FILE }]
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(SETTINGS_FILE)) return false;
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 !== HOOK_FILE);
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
- var SKILL_DIR = join2(homedir2(), ".claude", "skills", "chainpatrol");
130
- var SKILL_FILE = join2(SKILL_DIR, "SKILL.md");
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
- if (!existsSync2(SKILL_FILE)) return void 0;
144
+ function readInstalledSkillVersion(homeDir = homedir2()) {
145
+ const { file } = getSkillPaths(homeDir);
146
+ if (!existsSync2(file)) return void 0;
139
147
  try {
140
- const raw = readFileSync2(SKILL_FILE, "utf-8");
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(SKILL_FILE);
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(SKILL_FILE);
163
- const skillUpToDate = skillAlreadyExists && readFileSync2(SKILL_FILE, "utf-8") === skillContent;
173
+ const skillAlreadyExists = existsSync2(skillFile);
174
+ const skillUpToDate = skillAlreadyExists && readFileSync2(skillFile, "utf-8") === skillContent;
164
175
  let skillStatus;
165
176
  if (!skillAlreadyExists) {
166
- mkdirSync2(SKILL_DIR, { recursive: true });
167
- writeFileSync2(SKILL_FILE, skillContent, { mode: 420 });
177
+ mkdirSync2(skillDir, { recursive: true });
178
+ writeFileSync2(skillFile, skillContent, { mode: 420 });
168
179
  skillStatus = "installed";
169
180
  } else if (!skillUpToDate) {
170
- writeFileSync2(SKILL_FILE, skillContent, { mode: 420 });
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
- console.log(
192
+ log(
182
193
  JSON.stringify({
183
194
  status: overallStatus,
184
- path: SKILL_FILE,
185
- skill: { status: skillStatus, path: SKILL_FILE },
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
- console.log("Claude Code skill, completions, and login hook are already up to date.");
204
+ log("Claude Code skill, completions, and login hook are already up to date.");
194
205
  return;
195
206
  }
196
- console.log(LOGO);
207
+ log(LOGO);
197
208
  if (skillStatus === "installed") {
198
- console.log(`Installed Claude Code skill at ${SKILL_FILE}`);
209
+ log(`Installed Claude Code skill at ${skillFile}`);
199
210
  } else if (skillStatus === "updated") {
200
- console.log(`Updated Claude Code skill at ${SKILL_FILE}`);
211
+ log(`Updated Claude Code skill at ${skillFile}`);
201
212
  }
202
- console.log("You can now use /chainpatrol in Claude Code from any project.");
213
+ log("You can now use /chainpatrol in Claude Code from any project.");
203
214
  if (loginHookChanged && loginHookResult) {
204
- console.log(`Installed auto-login hook at ${loginHookResult.hookPath}`);
215
+ log(`Installed auto-login hook at ${loginHookResult.hookPath}`);
205
216
  if (loginHookResult.settingsUpdated) {
206
- console.log(`Registered SessionStart hook in ${loginHookResult.settingsPath}`);
217
+ log(`Registered SessionStart hook in ${loginHookResult.settingsPath}`);
207
218
  }
208
219
  }
209
220
  if (completionResult.installed) {
210
- console.log(
211
- `Installed ${completionResult.shell} completions at ${completionResult.path}`
212
- );
221
+ log(`Installed ${completionResult.shell} completions at ${completionResult.path}`);
213
222
  if (completionResult.configuredShellRc) {
214
- console.log("Added completion config to ~/.zshrc");
223
+ log("Added completion config to ~/.zshrc");
215
224
  }
216
- console.log('Run "exec zsh" or open a new terminal to enable tab completion.');
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 skillInstalled = existsSync2(SKILL_FILE);
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(SKILL_DIR, { recursive: true });
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
- console.log(
240
+ log(
229
241
  JSON.stringify({
230
242
  status: removedAnything ? "uninstalled" : "not-installed",
231
- path: SKILL_FILE,
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
- console.log("Claude Code skill is not installed.");
251
+ log("Claude Code skill is not installed.");
240
252
  return;
241
253
  }
242
254
  if (skillInstalled) {
243
- console.log("Removed Claude Code skill from " + SKILL_DIR);
255
+ log("Removed Claude Code skill from " + skillDir);
244
256
  }
245
257
  if (loginHookResult.hookRemoved || loginHookResult.settingsUpdated) {
246
- console.log("Removed chainpatrol auto-login hook.");
258
+ log("Removed chainpatrol auto-login hook.");
247
259
  }
248
260
  if (removedCompletions) {
249
- console.log("Removed shell completions.");
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, list, update detection configs and results'
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 threat detection results'
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
- var ZSH_COMPLETIONS_DIR = join(homedir(), ".zsh", "completions");
258
- var ZSH_COMPLETION_FILE = join(ZSH_COMPLETIONS_DIR, "_chainpatrol");
259
- var ZSHRC = join(homedir(), ".zshrc");
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(ZSHRC)) return false;
263
- const content = readFileSync(ZSHRC, "utf-8");
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(ZSHRC, snippet);
277
+ appendFileSync(zshrc, snippet);
273
278
  return true;
274
279
  }
275
- function removeZshrcCompletions() {
276
- if (!existsSync(ZSHRC)) return false;
277
- const content = readFileSync(ZSHRC, "utf-8");
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(ZSHRC, filtered.join("\n"));
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
- mkdirSync(ZSH_COMPLETIONS_DIR, { recursive: true });
295
- writeFileSync(ZSH_COMPLETION_FILE, ZSH_COMPLETION, { mode: 420 });
296
- const configuredShellRc = ensureZshrcCompletions();
297
- return { installed: true, path: ZSH_COMPLETION_FILE, shell: "zsh", configuredShellRc };
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(ZSH_COMPLETION_FILE)) {
302
- unlinkSync(ZSH_COMPLETION_FILE);
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-XLPLTBKX.js";
14
+ } from "./chunk-RAFCCHOO.js";
15
15
  import {
16
16
  compareVersions,
17
17
  getCliVersion
18
18
  } from "./chunk-OKIUEBUK.js";
19
- import "./chunk-DY5VY6FO.js";
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, list, and update detection configs and results.",
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 threat detection results for an organization. Returns human-readable confidence levels (none/low/medium/high) and report status. Filter parity with the app's detections view: source, confidence, asset status/type, brand, liveness, watchlist, reported, country, and deleted items.",
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 detections. Without this flag the endpoint returns both deleted and non-deleted (existing public-API behavior).",
208
- "--exclude-deleted Leave soft-deleted detections out, so totals match the app. Cannot be combined with --only-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 detections with raw score >= n (0-1). Use instead of --confidence for a fixed cut-off",
211
- "--max-score <n> Only detections with raw score <= n (0-1)",
212
- "--include-total Also print how many detections match across all pages",
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
  ],
@@ -599,18 +599,19 @@ var HELP = {
599
599
  },
600
600
  orgs: {
601
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.",
602
- 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>",
603
603
  examples: [
604
604
  "chainpatrol orgs list",
605
605
  "chainpatrol orgs get acme",
606
606
  "chainpatrol orgs assets list --asset-type URL",
607
+ "chainpatrol orgs assets set-expiry 12345 --in 6m",
607
608
  "chainpatrol orgs watchlist list --include-total",
608
609
  "chainpatrol orgs asset-groups list"
609
610
  ]
610
611
  },
611
612
  "orgs assets": {
612
- description: "List assets in your organization's allowlist.",
613
- usage: "chainpatrol orgs assets list [filters]"
613
+ description: "List assets in your organization's allowlist, or set when they expire.",
614
+ usage: "chainpatrol orgs assets <list|set-expiry>"
614
615
  },
615
616
  "orgs assets list": {
616
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.",
@@ -630,6 +631,23 @@ var HELP = {
630
631
  "chainpatrol orgs assets list --group-id 12 --per-page 250 --output csv"
631
632
  ]
632
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
+ },
633
651
  "orgs watchlist": {
634
652
  description: "List the assets ChainPatrol is watching for your organization.",
635
653
  usage: "chainpatrol orgs watchlist list [filters]"
@@ -808,7 +826,7 @@ function getTopLevelHelp() {
808
826
  " mcp Serve the public API to AI agents over MCP (stdio)",
809
827
  " asset Check, search, or list assets, or list supported asset types",
810
828
  " configs Manage detection configs",
811
- " detections Validate, run, list, update detection configs and results",
829
+ " detections Validate, run and update detection configs; list suspected threats",
812
830
  " healthchecks List and run organization healthchecks",
813
831
  " metrics Query organization metrics and breakdowns",
814
832
  " reports Create, list, and search reports from terminal",
@@ -844,12 +862,12 @@ var NPM_REGISTRY_URL = "https://registry.npmjs.org/@chainpatrol/cli/latest";
844
862
  var CHECK_FILE_NAME = "version-check.json";
845
863
  var CHECK_INTERVAL_MS = 24 * 60 * 60 * 1e3;
846
864
  var NPM_REQUEST_TIMEOUT_MS = 1500;
847
- function checkSkillStatus() {
865
+ function checkSkillStatus(homeDir) {
848
866
  const bundled = getBundledSkillVersion();
849
- if (!isSkillInstalled()) {
867
+ if (!isSkillInstalled(homeDir)) {
850
868
  return { state: "missing", bundled };
851
869
  }
852
- const installed = readInstalledSkillVersion();
870
+ const installed = readInstalledSkillVersion(homeDir);
853
871
  if (!installed) {
854
872
  return { state: "outdated", installed: void 0, bundled };
855
873
  }
@@ -945,7 +963,7 @@ function formatNpmNudge(status) {
945
963
  return void 0;
946
964
  }
947
965
  async function runVersionChecks(options) {
948
- const skill = checkSkillStatus();
966
+ const skill = checkSkillStatus(options?.homeDir);
949
967
  const npm = await checkNpmStatus(options);
950
968
  const messages = [];
951
969
  const skillMsg = formatSkillNudge(skill);
@@ -1111,6 +1129,9 @@ ${getTopLevelHelp()}
1111
1129
  brandSlug: { type: "string" },
1112
1130
  type: { type: "string" },
1113
1131
  groupId: { type: "number" },
1132
+ expires: { type: "string" },
1133
+ in: { type: "string" },
1134
+ clear: { type: "boolean", default: false },
1114
1135
  confidence: { type: "string" },
1115
1136
  assetStatus: { type: "string" },
1116
1137
  liveness: { type: "string" },
@@ -1316,7 +1337,7 @@ async function main() {
1316
1337
  return;
1317
1338
  }
1318
1339
  if (cliContext.dryRun) {
1319
- 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";
1320
1341
  if (!dryRunSupported) {
1321
1342
  throw new CliExitError(
1322
1343
  "--dry-run is only supported for mutation commands.",
@@ -1908,7 +1929,7 @@ async function main() {
1908
1929
  }
1909
1930
  if (subcommand === "assets") {
1910
1931
  if (action === "list") {
1911
- const { runOrgsAssetsList } = await import("./list-Z2WGCOB5.js");
1932
+ const { runOrgsAssetsList } = await import("./list-EBX2AYJ5.js");
1912
1933
  await runOrgsAssetsList({
1913
1934
  // Optional: organization-scoped API keys resolve the org from the
1914
1935
  // key, so only pass a slug when one is actually available.
@@ -1923,7 +1944,27 @@ async function main() {
1923
1944
  });
1924
1945
  break;
1925
1946
  }
1926
- throw new Error("Usage: chainpatrol orgs assets list [filters]");
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
+ );
1927
1968
  }
1928
1969
  if (subcommand === "watchlist") {
1929
1970
  if (action === "list") {
@@ -1957,7 +1998,7 @@ async function main() {
1957
1998
  }
1958
1999
  const hint = subcommand ? suggest(subcommand, ["list", "get", "assets", "watchlist", "asset-groups"]) : null;
1959
2000
  throw new Error(
1960
- 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]"
1961
2002
  );
1962
2003
  }
1963
2004
  case "brands": {
@@ -2059,17 +2100,17 @@ async function main() {
2059
2100
  case "setup":
2060
2101
  case "install":
2061
2102
  case "i": {
2062
- const { setupSkill } = await import("./setup-skill-RQG43DFT.js");
2103
+ const { setupSkill } = await import("./setup-skill-M2PVQC4Z.js");
2063
2104
  setupSkill({ json: jsonMode, cloud: cli.flags.cloud });
2064
2105
  break;
2065
2106
  }
2066
2107
  case "uninstall": {
2067
- const { uninstallSkill } = await import("./setup-skill-RQG43DFT.js");
2108
+ const { uninstallSkill } = await import("./setup-skill-M2PVQC4Z.js");
2068
2109
  uninstallSkill({ json: jsonMode });
2069
2110
  break;
2070
2111
  }
2071
2112
  case "completions": {
2072
- const { printCompletions } = await import("./completions-HYTAOGE4.js");
2113
+ const { printCompletions } = await import("./completions-VJMT2W5B.js");
2073
2114
  printCompletions(subcommand);
2074
2115
  break;
2075
2116
  }
@@ -3,7 +3,7 @@ import {
3
3
  installCompletions,
4
4
  printCompletions,
5
5
  uninstallCompletions
6
- } from "./chunk-DY5VY6FO.js";
6
+ } from "./chunk-XICYSDVF.js";
7
7
  export {
8
8
  getCompletionScript,
9
9
  installCompletions,
@@ -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-XLPLTBKX.js";
9
+ } from "./chunk-RAFCCHOO.js";
10
10
  import "./chunk-OKIUEBUK.js";
11
- import "./chunk-DY5VY6FO.js";
11
+ import "./chunk-XICYSDVF.js";
12
12
  export {
13
13
  getBundledSkillContent,
14
14
  getBundledSkillVersion,
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.18.0",
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.16.0",
37
- "@chainpatrol/sdk": "1.18.0",
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",