unbound-cli 1.24.0 → 1.25.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -14,7 +14,7 @@ npm install -g unbound-cli
14
14
  # Login via browser
15
15
  unbound login
16
16
 
17
- # Or login with your CLI key from Configure → API Access (for CI/CD or headless environments)
17
+ # Or login with your CLI key from Settings → API Tokens (for CI/CD or headless environments)
18
18
  unbound login --api-key <your-cli-key>
19
19
 
20
20
  # Check your status, role, and connected tools
@@ -378,7 +378,7 @@ unbound config show
378
378
 
379
379
  Bare hostnames are accepted (`backend.acme.com` becomes `https://backend.acme.com`). Each URL also accepts a per-process override via env var.
380
380
 
381
- **API keys.** The CLI key (Configure → API Access) can read your organization's data, so `unbound login` keeps it in the OS keychain: macOS Keychain, Windows Credential Manager, or the Linux Secret Service (`secret-tool`). Without a keychain, set `UNBOUND_TOKEN` instead; the CLI reads it only when the keychain has no key. The send-only device key that tools and hooks use is stored as `api_key` in `~/.unbound/config.json`. `unbound setup` fetches it from your login, and `--api-key` takes a device key. Run `unbound login` again after upgrading.
381
+ **API keys.** The CLI key (Settings → API Tokens) can read your organization's data, so `unbound login` keeps it in the OS keychain: macOS Keychain, Windows Credential Manager, or the Linux Secret Service (`secret-tool`). Without a keychain, set `UNBOUND_TOKEN` instead; the CLI reads it only when the keychain has no key. The send-only device key that tools and hooks use is stored as `api_key` in `~/.unbound/config.json`. `unbound setup` fetches it from your login, and `--api-key` takes a device key. Run `unbound login` again after upgrading.
382
382
 
383
383
  **Backend URL priority** (highest to lowest):
384
384
  1. `UNBOUND_API_URL` environment variable
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "unbound-cli",
3
- "version": "1.24.0",
3
+ "version": "1.25.1",
4
4
  "description": "CLI tool for Unbound - AI Gateway management",
5
5
  "main": "src/index.js",
6
6
  "bin": {
package/src/auth.js CHANGED
@@ -12,7 +12,7 @@ const output = require('./output');
12
12
  const api = require('./api');
13
13
  const { getDeviceSerial, probeDeviceSerialLive } = require('./device-serial');
14
14
 
15
- const NOT_A_CLI_KEY = "This key can't be used with the CLI. Copy it from Configure \u2192 API Access, or run `unbound login`.";
15
+ const NOT_A_CLI_KEY = "This key can't be used with the CLI. Create one in Settings \u2192 API Tokens, or run `unbound login`.";
16
16
 
17
17
  // 401/403 means the key is not a CLI key; anything else (offline, 5xx) is an outage, not an answer.
18
18
  function isRejected(err) {
@@ -22,7 +22,7 @@ function isRejected(err) {
22
22
  function warnIfNotStored(stored) {
23
23
  if (stored === false) {
24
24
  output.warn('No OS keychain is available, so this login lasts for this run only. '
25
- + 'Set UNBOUND_TOKEN to your CLI key (Configure \u2192 API Access) to stay logged in.');
25
+ + 'Set UNBOUND_TOKEN to your CLI key (Settings \u2192 API Tokens) to stay logged in.');
26
26
  }
27
27
  }
28
28
 
@@ -28,7 +28,7 @@ Authentication methods:
28
28
 
29
29
  API key login (--api-key):
30
30
  Non-interactive login for CI/CD or automation. Takes the CLI key from
31
- Configure → API Access and keeps it in the OS keychain (or set
31
+ Settings → API Tokens and keeps it in the OS keychain (or set
32
32
  UNBOUND_TOKEN where there is none). Device and MDM keys are refused.
33
33
 
34
34
  Tenant deployments (URL flags persist to ~/.unbound/config.json):
@@ -131,6 +131,12 @@ function formatToolTypes(types) {
131
131
  return types.join(', ');
132
132
  }
133
133
 
134
+ /** --tools value as the body's scope_tool_types: "all" clears the targets; ids are checked by the server. */
135
+ function parseToolIds(value) {
136
+ if (String(value).trim().toLowerCase() === 'all') return [];
137
+ return parseCommaSeparated(value).map((t) => t.toUpperCase());
138
+ }
139
+
134
140
  function displayPolicy(policy) {
135
141
  if (!policy) {
136
142
  output.warn('No policy data to display.');
@@ -194,6 +200,7 @@ function displayToolPolicy(policy) {
194
200
  ['Status', policy.status || '-'],
195
201
  ['Custom Message', policy.custom_message || '-'],
196
202
  ['Scope Groups', formatScope(policy.scope_user_groups)],
203
+ ['AI Tools', formatToolTypes(policy.scope_tool_types)],
197
204
  ];
198
205
  if (policy.policy_type === 'TERMINAL_COMMAND') {
199
206
  rows.push(['Command Family', policy.command_family || '-']);
@@ -1410,6 +1417,7 @@ Subcommands:
1410
1417
  { key: 'action', header: 'Action' },
1411
1418
  { key: 'enabled', header: 'Enabled', format: (v) => (v ? 'yes' : 'no') },
1412
1419
  { key: 'scope_user_groups', header: 'Scope', format: (v) => formatScope(v) },
1420
+ { key: 'scope_tool_types', header: 'AI Tools', format: (v) => formatToolTypes(v) },
1413
1421
  ]);
1414
1422
 
1415
1423
  if (!opts.all && meta.total_pages && meta.total_pages > 1) {
@@ -1475,6 +1483,7 @@ Subcommands:
1475
1483
  .option('--description <text>', 'Human-readable description')
1476
1484
  .option('--custom-message <text>', 'Message shown to the user when the policy fires. Required when --action is BLOCK or WARN.')
1477
1485
  .option('--group <names|ids>', 'Comma-separated user group names or IDs to scope this policy to')
1486
+ .option('--tools <ids>', 'Comma-separated AI tool ids this policy applies to (e.g. CURSOR,CODEX); default all tools')
1478
1487
  .option('--disabled', 'Create the policy in disabled state')
1479
1488
  .option('--config <json>', 'Advanced: raw config JSON (skips --field builder)')
1480
1489
  .option('--yes', 'Skip the confirmation prompt for --prompt flows (preview is still printed)')
@@ -1563,6 +1572,7 @@ Learn more: ${DOCS_TOOL}
1563
1572
  return;
1564
1573
  }
1565
1574
  const body = result.body;
1575
+ if (opts.tools !== undefined) body.scope_tool_types = parseToolIds(opts.tools);
1566
1576
  let data;
1567
1577
  try {
1568
1578
  data = await api.post('/api/v1/command-policies/', { body });
@@ -1636,6 +1646,7 @@ Learn more: ${DOCS_TOOL}
1636
1646
  const formData = await loadFormData();
1637
1647
  body.scope_user_group_ids = resolveByName(formData.user_groups || [], opts.group, { kind: 'user group' });
1638
1648
  }
1649
+ if (opts.tools !== undefined) body.scope_tool_types = parseToolIds(opts.tools);
1639
1650
 
1640
1651
  const data = await api.post('/api/v1/command-policies/', { body });
1641
1652
  if (opts.json) {
@@ -1663,6 +1674,7 @@ Learn more: ${DOCS_TOOL}
1663
1674
  .option('--description <text>', 'Human-readable description. Override AI suggestion when used with --prompt.')
1664
1675
  .option('--custom-message <text>', 'Message shown to the user when the policy fires. Required when --action is BLOCK or WARN. Override AI suggestion when used with --prompt.')
1665
1676
  .option('--group <names|ids>', 'Comma-separated user group names or IDs to scope this policy to')
1677
+ .option('--tools <ids>', 'Comma-separated AI tool ids this policy applies to (e.g. CURSOR,CODEX); default all tools')
1666
1678
  .option('--disabled', 'Create the policy in disabled state')
1667
1679
  .option('--config <json>', 'Advanced: raw config JSON')
1668
1680
  .option('--yes', 'Skip the confirmation prompt for --prompt flows (preview is still printed)')
@@ -1741,6 +1753,7 @@ Learn more: ${DOCS_TOOL}
1741
1753
  return;
1742
1754
  }
1743
1755
  const body = result.body;
1756
+ if (opts.tools !== undefined) body.scope_tool_types = parseToolIds(opts.tools);
1744
1757
  let data;
1745
1758
  try {
1746
1759
  data = await api.post('/api/v1/command-policies/', { body });
@@ -1811,6 +1824,7 @@ Learn more: ${DOCS_TOOL}
1811
1824
  const formData = await loadFormData();
1812
1825
  body.scope_user_group_ids = resolveByName(formData.user_groups || [], opts.group, { kind: 'user group' });
1813
1826
  }
1827
+ if (opts.tools !== undefined) body.scope_tool_types = parseToolIds(opts.tools);
1814
1828
 
1815
1829
  const data = await api.post('/api/v1/command-policies/', { body });
1816
1830
  if (opts.json) {
@@ -1833,6 +1847,7 @@ Learn more: ${DOCS_TOOL}
1833
1847
  .option('--action <action>', `New action: ${TOOL_ACTIONS.join(' | ')}`)
1834
1848
  .option('--custom-message <text>', 'New custom message')
1835
1849
  .option('--group <names|ids>', 'Replace scope')
1850
+ .option('--tools <ids>', 'Replace the AI tools this policy applies to (comma-separated ids, or "all")')
1836
1851
  .option('--enabled', 'Enable the policy')
1837
1852
  .option('--disabled', 'Disable the policy')
1838
1853
  .option('--command-family <family>', '(TERMINAL only) new command family')
@@ -1884,6 +1899,7 @@ Learn more: ${DOCS_TOOL}
1884
1899
  const formData = await loadFormData();
1885
1900
  body.scope_user_group_ids = resolveByName(formData.user_groups || [], opts.group, { kind: 'user group' });
1886
1901
  }
1902
+ if (opts.tools !== undefined) body.scope_tool_types = parseToolIds(opts.tools);
1887
1903
 
1888
1904
  if ((body.action === 'BLOCK' || body.action === 'WARN') && !body.custom_message && opts.customMessage === undefined) {
1889
1905
  output.warn('Action changed to BLOCK/WARN without --custom-message. The existing custom_message will remain; pass --custom-message to replace it.');
@@ -40,8 +40,12 @@ function toolRowToPolicy(row) {
40
40
  p.mcp = mcp;
41
41
  if (row.config && Object.keys(row.config).length) p.config = row.config;
42
42
  }
43
+ const scope = {};
43
44
  const groups = groupNames(row);
44
- if (groups.length) p.scope = { userGroups: groups };
45
+ if (groups.length) scope.userGroups = groups;
46
+ // An empty list is exported too: a tool pack that omits toolTypes leaves the live targets alone.
47
+ if (Array.isArray(row.scope_tool_types)) scope.toolTypes = [...row.scope_tool_types];
48
+ if (Object.keys(scope).length) p.scope = scope;
45
49
  return p;
46
50
  }
47
51
 
@@ -181,6 +181,9 @@ function expandActionType(ref, server, actionType) {
181
181
  return [...tools].sort();
182
182
  }
183
183
 
184
+ // The server stores these legacy ids under their current names, so plans compare the current name.
185
+ const LEGACY_TOOL_IDS = { UNBOUND_CLAUDE_CODE: 'CLAUDE_CODE', UNBOUND_CODEX: 'CODEX' };
186
+
184
187
  function toolDesired(policy, ref, where) {
185
188
  const scopeIds = resolveIds(ref.userGroups, policy.scope && policy.scope.userGroups, 'user group', { where });
186
189
  const body = {
@@ -202,6 +205,11 @@ function toolDesired(policy, ref, where) {
202
205
  enabled: body.enabled,
203
206
  scope_user_group_ids: scopeIds,
204
207
  };
208
+ // Tool targets are managed only when the pack lists them, so packs without the field plan no change.
209
+ if (policy.scope && policy.scope.toolTypes !== undefined) {
210
+ body.scope_tool_types = [...new Set(policy.scope.toolTypes.map((t) => LEGACY_TOOL_IDS[t] || t))].sort();
211
+ proj.scope_tool_types = body.scope_tool_types;
212
+ }
205
213
  let mcp = null;
206
214
  if (policy.type === 'TERMINAL_COMMAND') {
207
215
  body.command_family = policy.commandFamily;
@@ -319,6 +327,7 @@ function liveProjection(row, table) {
319
327
  description: row.description || '',
320
328
  enabled: row.enabled !== undefined ? !!row.enabled : row.status === 'ACTIVE',
321
329
  scope_user_group_ids: scopeIds,
330
+ scope_tool_types: [...new Set(row.scope_tool_types || [])].sort(),
322
331
  };
323
332
  if (row.policy_type === 'TERMINAL_COMMAND') {
324
333
  proj.command_family = row.command_family;
@@ -358,6 +367,7 @@ const PROJ_TO_BODY = {
358
367
  description: (d) => ({ description: d.body.description }),
359
368
  enabled: (d) => ({ enabled: d.body.enabled }),
360
369
  scope_user_group_ids: (d) => ({ scope_user_group_ids: d.body.scope_user_group_ids }),
370
+ scope_tool_types: (d) => ({ scope_tool_types: d.body.scope_tool_types }),
361
371
  command_family: (d) => ({ command_family: d.body.command_family, config: d.body.config }),
362
372
  config: (d) => (d.body.policy_type === 'TERMINAL_COMMAND'
363
373
  ? { command_family: d.body.command_family, config: d.body.config }
@@ -404,6 +414,12 @@ function findBySlug(rows, slug) {
404
414
  * live: { tool: [rows], generic: [rows] } — only rows under this pack's prefix
405
415
  * options.prune: delete managed rows absent from the pack
406
416
  */
417
+ // A pack without toolTypes leaves targets unmanaged, so a replacement keeps the live row's.
418
+ function replaceBody(d, row) {
419
+ if (d.proj.scope_tool_types !== undefined || !Array.isArray(row.scope_tool_types) || !row.scope_tool_types.length) return d.body;
420
+ return { ...d.body, scope_tool_types: [...row.scope_tool_types] };
421
+ }
422
+
407
423
  function buildPlan(desired, live, { prune = false } = {}) {
408
424
  const ops = [];
409
425
  const matchedTool = new Set();
@@ -465,7 +481,7 @@ function buildPlan(desired, live, { prune = false } = {}) {
465
481
  const liveProj = liveProjection(row, d.table);
466
482
  if (d.table === 'tool' && (row.policy_type !== d.body.policy_type || (d.proj.mcp_server && liveProj.mcp_server !== d.proj.mcp_server))) {
467
483
  const what = row.policy_type !== d.body.policy_type ? `type ${row.policy_type} -> ${d.body.policy_type}` : `MCP server ${liveProj.mcp_server} -> ${d.proj.mcp_server}`;
468
- ops.push({ ...base, op: 'replace', row, body: d.body, changes: [{ field: 'identity', from: row.policy_type, to: d.body.policy_type }], reason: what });
484
+ ops.push({ ...base, op: 'replace', row, body: replaceBody(d, row), changes: [{ field: 'identity', from: row.policy_type, to: d.body.policy_type }], reason: what });
469
485
  continue;
470
486
  }
471
487
 
@@ -485,7 +501,7 @@ function buildPlan(desired, live, { prune = false } = {}) {
485
501
  Object.assign(body, patch);
486
502
  }
487
503
  if (unpatchable) {
488
- ops.push({ ...base, op: 'replace', row, body: d.body, changes, reason: `${unpatchable} cannot be patched in place` });
504
+ ops.push({ ...base, op: 'replace', row, body: replaceBody(d, row), changes, reason: `${unpatchable} cannot be patched in place` });
489
505
  } else {
490
506
  ops.push({ ...base, op: 'update', row, body, changes });
491
507
  }
@@ -89,16 +89,15 @@ function rejectUnknownKeys(obj, allowed, where, file) {
89
89
  }
90
90
  }
91
91
 
92
- function validateScope(scope, where, file, { allowToolTypes }) {
92
+ function validateScope(scope, where, file) {
93
93
  if (scope === undefined) return undefined;
94
94
  if (!isPlainObject(scope)) throw new PackError(`${where}.scope must be an object`, { file });
95
95
  rejectUnknownKeys(scope, SCOPE_KEYS, `${where}.scope`, file);
96
96
  if (scope.userGroups !== undefined && !isStringArray(scope.userGroups)) {
97
97
  throw new PackError(`${where}.scope.userGroups must be a list of user group names`, { file });
98
98
  }
99
- if (scope.toolTypes !== undefined) {
100
- if (!allowToolTypes) throw new PackError(`${where}.scope.toolTypes applies to security, model and cost policies only`, { file });
101
- if (!isStringArray(scope.toolTypes)) throw new PackError(`${where}.scope.toolTypes must be a list of tool type names`, { file });
99
+ if (scope.toolTypes !== undefined && !isStringArray(scope.toolTypes)) {
100
+ throw new PackError(`${where}.scope.toolTypes must be a list of tool type names`, { file });
102
101
  }
103
102
  return scope;
104
103
  }
@@ -129,7 +128,7 @@ function validateDefaults(defaults, file) {
129
128
  rejectUnknownKeys(defaults, DEFAULTS_KEYS, 'defaults', file);
130
129
  if (defaults.enabled !== undefined && typeof defaults.enabled !== 'boolean') throw new PackError('defaults.enabled must be true or false', { file });
131
130
  if (defaults.labels !== undefined && !isStringArray(defaults.labels)) throw new PackError('defaults.labels must be a list of label names', { file });
132
- validateScope(defaults.scope, 'defaults', file, { allowToolTypes: true });
131
+ validateScope(defaults.scope, 'defaults', file);
133
132
  return defaults;
134
133
  }
135
134
 
@@ -296,7 +295,7 @@ function validatePack(doc, file) {
296
295
  const label = `${where} (${raw.id})`;
297
296
  if (raw.kind === 'tool') validateToolPolicy(raw, label, file);
298
297
  else validateGenericPolicy(raw, label, file);
299
- validateScope(raw.scope, label, file, { allowToolTypes: raw.kind !== 'tool' });
298
+ validateScope(raw.scope, label, file);
300
299
 
301
300
  const merged = mergeDefaults(raw, defaults);
302
301
  return {
@@ -286,7 +286,7 @@ function routeBackendError(err) {
286
286
  const code = err.statusCode;
287
287
  if (code === 401 || code === 403) {
288
288
  return {
289
- message: 'Authentication failed / not authorized. Tool policies require admin. Run `unbound whoami` to check role.',
289
+ message: 'Authentication failed / not authorized. Tool policies require admin. Run `unbound status` to check role.',
290
290
  exitCode: 3,
291
291
  };
292
292
  }
@@ -46,6 +46,7 @@ test('login --api-key rejects a device or MDM key and stores nothing', async ()
46
46
  const { auth, state } = freshAuth();
47
47
  await assert.rejects(() => auth.loginWithApiKey('device-key'));
48
48
  assert.match(state.failed, /can't be used with the CLI/);
49
+ assert.match(state.failed, /Settings \u2192 API Tokens/);
49
50
  assert.equal(state.keychain, null);
50
51
  assert.equal(state.config, null);
51
52
  });
@@ -361,3 +361,38 @@ test('T11: create-terminal --prompt without CLAUDECODE still routes to the assis
361
361
  }
362
362
  });
363
363
  });
364
+
365
+ test('create-terminal --tools sends the AI tool ids, and "all" sends an empty list', async () => {
366
+ for (const [value, expected] of [['cursor,codex', ['CURSOR', 'CODEX']], ['all', []]]) {
367
+ const h = buildHarness();
368
+ await withEnv({}, async () => {
369
+ try {
370
+ await runArgv([
371
+ 'policy', 'tool', 'create-terminal', '--no-ai', '--name', 'X', '--command-family', 'git',
372
+ '--field', 'command=git push*', '--action', 'AUDIT', '--tools', value,
373
+ ]);
374
+ const create = h.calls.posts.find((c) => c.path === '/api/v1/command-policies/');
375
+ assert.deepEqual(create.body.scope_tool_types, expected);
376
+ } finally {
377
+ h.restoreLog();
378
+ }
379
+ });
380
+ }
381
+ });
382
+
383
+ test('create-terminal without --tools leaves the targets out', async () => {
384
+ const h = buildHarness();
385
+ await withEnv({}, async () => {
386
+ try {
387
+ await runArgv([
388
+ 'policy', 'tool', 'create-terminal', '--no-ai', '--name', 'X', '--command-family', 'git',
389
+ '--field', 'command=git push*', '--action', 'AUDIT',
390
+ ]);
391
+ const create = h.calls.posts.find((c) => c.path === '/api/v1/command-policies/');
392
+ assert.equal('scope_tool_types' in create.body, false);
393
+ } finally {
394
+ h.restoreLog();
395
+ }
396
+ });
397
+ });
398
+
@@ -99,3 +99,24 @@ test('round trip validates a checked-in terminal command family', () => {
99
99
  const validated = schema.validatePack(schema.parsePackText(exp.stringifyPack(doc), 'base.yaml'), 'base.yaml');
100
100
  assert.deepEqual(validated.policies[0].config, { operation: 'push' });
101
101
  });
102
+
103
+ test('an all-tools tool policy exports an empty toolTypes, so applying it clears targets', () => {
104
+ const live = { ...LIVE, tool: LIVE.tool.map((r) => (r.code_slug === 'gh-writes' ? { ...r, scope_tool_types: [] } : r)) };
105
+ const doc = exp.liveToPack('base', live, REF);
106
+ assert.deepEqual(doc.policies.find((p) => p.id === 'gh-writes').scope, { toolTypes: [] });
107
+ const pack = schema.validatePack(schema.parsePackText(exp.stringifyPack(doc), 'base.yaml'), 'base.yaml');
108
+ const targeted = { ...live, tool: live.tool.map((r) => (r.code_slug === 'gh-writes' ? { ...r, scope_tool_types: ['CURSOR'] } : r)) };
109
+ const op = plan.buildPlan(plan.toDesired(pack, REF), targeted).find((o) => o.id === 'gh-writes');
110
+ assert.equal(op.op, 'update');
111
+ assert.deepEqual(op.body, { scope_tool_types: [] });
112
+ });
113
+
114
+ test('a tool policy aimed at AI tools exports its targets and plans unchanged', () => {
115
+ const live = { ...LIVE, tool: LIVE.tool.map((r) => (r.code_slug === 'gh-writes' ? { ...r, scope_tool_types: ['CURSOR'] } : r)) };
116
+ const doc = exp.liveToPack('base', live, REF);
117
+ assert.deepEqual(doc.policies.find((p) => p.id === 'gh-writes').scope, { toolTypes: ['CURSOR'] });
118
+ const pack = schema.validatePack(schema.parsePackText(exp.stringifyPack(doc), 'base.yaml'), 'base.yaml');
119
+ const ops = plan.buildPlan(plan.toDesired(pack, REF), live, { prune: true });
120
+ assert.deepEqual(ops.map((o) => o.op), ops.map(() => 'unchanged'));
121
+ });
122
+
@@ -121,6 +121,22 @@ test('buildPlan: MCP server change and type change are replace', () => {
121
121
  assert.equal(plan.buildPlan(type, { tool: [LIVE_MCP], generic: [] })[0].op, 'replace');
122
122
  });
123
123
 
124
+ test('buildPlan: a replace keeps live tool targets the pack does not manage, and uses the pack list when it does', () => {
125
+ const live = { tool: [{ ...LIVE_MCP, scope_tool_types: ['CURSOR'] }], generic: [] };
126
+ const unmanaged = plan.toDesired(pack([{ ...MCP, mcp: { server: 'slack', tool: 'post_message' } }]), REF);
127
+ assert.deepEqual(plan.buildPlan(unmanaged, live)[0].body.scope_tool_types, ['CURSOR']);
128
+ const managed = plan.toDesired(pack([{ ...MCP, mcp: { server: 'slack', tool: 'post_message' }, scope: { toolTypes: [] } }]), REF);
129
+ assert.deepEqual(plan.buildPlan(managed, live)[0].body.scope_tool_types, []);
130
+ });
131
+
132
+ test('buildPlan: an unpatchable-field replace keeps live tool targets the pack does not manage', () => {
133
+ const live = { tool: [{ ...LIVE_MCP, mcp_tools: ['push_files'], mcp_canonical_group: null, scope_tool_types: ['CURSOR'] }], generic: [] };
134
+ const [op] = plan.buildPlan(plan.toDesired(pack([MCP]), REF), live);
135
+ assert.equal(op.op, 'replace');
136
+ assert.match(op.reason, /cannot be patched in place/);
137
+ assert.deepEqual(op.body.scope_tool_types, ['CURSOR']);
138
+ });
139
+
124
140
  test('an action-type selector the catalogue cannot resolve is an error, never "unchanged"', () => {
125
141
  const unknownServer = { ...MCP, mcp: { server: 'nope', actionType: 'write' } };
126
142
  assert.throws(() => plan.toDesired(pack([unknownServer]), REF), /not in this org's MCP catalogue/);
@@ -216,3 +232,18 @@ test('a name already used elsewhere in the org is a conflict at plan time, not a
216
232
  const renamedOps = plan.buildPlan(renamed, { tool: [], generic: [{ ...LIVE_SECURITY, name: 'PII guard' }], names }, { prune: true });
217
233
  assert.deepEqual(renamedOps.map((o) => o.op), ['conflict'], 'a refused rename is a conflict and never also an orphan or delete');
218
234
  });
235
+
236
+ test('tool policy targets: a pack without toolTypes plans no change, a changed list patches only it', () => {
237
+ const live = { tool: [{ ...LIVE_TERMINAL, scope_tool_types: ['CURSOR'] }], generic: [] };
238
+ const unmanaged = plan.buildPlan(plan.toDesired(pack([TERMINAL]), REF), live);
239
+ assert.equal(unmanaged[0].op, 'unchanged', 'targets set elsewhere are left alone');
240
+
241
+ const same = { ...TERMINAL, scope: { ...TERMINAL.scope, toolTypes: ['CURSOR'] } };
242
+ assert.equal(plan.buildPlan(plan.toDesired(pack([same]), REF), live)[0].op, 'unchanged');
243
+
244
+ const changed = { ...TERMINAL, scope: { ...TERMINAL.scope, toolTypes: ['UNBOUND_CODEX', 'CURSOR'] } };
245
+ const ops = plan.buildPlan(plan.toDesired(pack([changed]), REF), live);
246
+ assert.equal(ops[0].op, 'update');
247
+ assert.deepEqual(ops[0].body, { scope_tool_types: ['CODEX', 'CURSOR'] }, 'legacy ids compare as their current name');
248
+ });
249
+
@@ -93,8 +93,8 @@ test('validatePack: kind-specific keys are enforced', () => {
93
93
  assert.throws(() => load(BASE.replace(' kind: cost', ' kind: cost\n action: BLOCK')), /unknown key "action"/);
94
94
  // generic-only key on a tool policy
95
95
  assert.throws(() => load(BASE.replace(' kind: tool\n type: TERMINAL_COMMAND', ' kind: tool\n priority: 1\n type: TERMINAL_COMMAND')), /unknown key "priority"/);
96
- // toolTypes scope only on generic
97
- assert.throws(() => load(BASE.replace(' userGroups: [Contractors]', ' toolTypes: [cursor]')), /scope.toolTypes applies to/);
96
+ // toolTypes scope must be a list on any policy kind
97
+ assert.throws(() => load(BASE.replace(' userGroups: [Contractors]', ' toolTypes: cursor')), /scope.toolTypes must be a list/);
98
98
  // guardrails only on security
99
99
  assert.throws(() => load(BASE.replace(' kind: cost', ' kind: cost\n guardrails: []')), /unknown key "guardrails"/);
100
100
  });
@@ -395,7 +395,7 @@ test('routing: 401 → exit 3 + admin-required wording', async () => {
395
395
  await runCreateMcp(['--prompt', 'audit linear writes', '--yes']);
396
396
  assert.equal(process.exitCode, 3);
397
397
  assert.ok(
398
- h.captured.error.some((m) => m === 'Authentication failed / not authorized. Tool policies require admin. Run `unbound whoami` to check role.'),
398
+ h.captured.error.some((m) => m === 'Authentication failed / not authorized. Tool policies require admin. Run `unbound status` to check role.'),
399
399
  `got: ${JSON.stringify(h.captured.error)}`
400
400
  );
401
401
  } finally {
@@ -795,7 +795,7 @@ test('routing: 401 → exit 3 + admin-required wording', async () => {
795
795
  await runCreate(['--prompt', 'block rm -rf', '--yes']);
796
796
  assert.equal(process.exitCode, 3);
797
797
  assert.ok(
798
- h.captured.error.some((m) => m === 'Authentication failed / not authorized. Tool policies require admin. Run `unbound whoami` to check role.'),
798
+ h.captured.error.some((m) => m === 'Authentication failed / not authorized. Tool policies require admin. Run `unbound status` to check role.'),
799
799
  `got: ${JSON.stringify(h.captured.error)}`
800
800
  );
801
801
  } finally {