@phnx-labs/agents-cli 1.23.10 → 1.23.12

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.
@@ -6,10 +6,10 @@ import * as TOML from 'smol-toml';
6
6
  import { getPermissionsDir, getUserPermissionsDir, ensureAgentsDir } from './state.js';
7
7
  import { safeJoin } from './paths.js';
8
8
  import { agentConfigDirName } from './agents.js';
9
- import { supports } from './capabilities.js';
9
+ import { explainSkip, supports } from './capabilities.js';
10
10
  import { updateGeminiSettings } from './gemini-settings.js';
11
- import { ANTIGRAVITY_ACTION_BY_TOOL, CANONICAL_TO_OPENCLAW_TOOL, CODEX_RULES_FILENAME, stripJsonComments, GROK_TOOL_BY_CANONICAL, PERMISSION_TARGETS, readCanonicalPermissions, } from './permissions-registry.js';
12
- export { CODEX_RULES_FILENAME };
11
+ import { ANTIGRAVITY_ACTION_BY_TOOL, CANONICAL_TO_OPENCLAW_TOOL, CODEX_ASK_RULES_FILENAME, CODEX_RULES_FILENAME, stripJsonComments, GROK_TOOL_BY_CANONICAL, PERMISSION_TARGETS, readCanonicalPermissions, } from './permissions-registry.js';
12
+ export { CODEX_ASK_RULES_FILENAME, CODEX_RULES_FILENAME };
13
13
  const HOME = os.homedir();
14
14
  export const COMPUTER_APP_GATED_VERBS = [
15
15
  'screenshot',
@@ -68,35 +68,51 @@ export function containsBroadGrants(rules) {
68
68
  return null;
69
69
  return { broad, reason: Array.from(reasons).join('; ') };
70
70
  }
71
- export function convertDenyToCodexRules(deny) {
71
+ function codexPrefixRule(perm, decision) {
72
+ const parsed = parseCanonicalPattern(perm);
73
+ if (!parsed || parsed.tool !== 'bash')
74
+ return null;
75
+ const command = parsed.pattern.replace(/:?\*$/, '').trim();
76
+ if (!command)
77
+ return null;
78
+ const parts = command.split(/\s+/);
79
+ const patternStr = parts.map(p => JSON.stringify(p)).join(', ');
80
+ return `prefix_rule(\n pattern = [${patternStr}],\n decision = "${decision}",\n)`;
81
+ }
82
+ function formatCodexPrefixRules(perms, decision, source) {
72
83
  const rules = [];
73
- for (const perm of deny) {
74
- const parsed = parseCanonicalPattern(perm);
75
- if (!parsed || parsed.tool !== 'bash')
76
- continue;
77
- const command = parsed.pattern.replace(/:?\*$/, '').trim();
78
- if (!command)
79
- continue;
80
- const parts = command.split(/\s+/);
81
- const patternStr = parts.map(p => JSON.stringify(p)).join(', ');
82
- rules.push(`prefix_rule(\n pattern = [${patternStr}],\n decision = "forbidden",\n)`);
84
+ for (const perm of perms) {
85
+ const rule = codexPrefixRule(perm, decision);
86
+ if (rule)
87
+ rules.push(rule);
83
88
  }
84
89
  if (rules.length === 0)
85
90
  return null;
86
- return `# Auto-generated by agents-cli from deny permission groups.\n# Do not edit manually — re-run "agents use" to regenerate.\n\n${rules.join('\n\n')}\n`;
91
+ return `# Auto-generated by agents-cli from ${source}.\n# Do not edit manually — re-run "agents use" to regenerate.\n\n${rules.join('\n\n')}\n`;
87
92
  }
88
- function syncCodexDenyRules(configDir, deny) {
89
- const rulesPath = path.join(configDir, 'rules', CODEX_RULES_FILENAME);
90
- const rulesContent = deny && deny.length > 0 ? convertDenyToCodexRules(deny) : null;
91
- if (rulesContent) {
93
+ export function convertDenyToCodexRules(deny) {
94
+ return formatCodexPrefixRules(deny, 'forbidden', 'deny permission groups');
95
+ }
96
+ export function convertAskToCodexRules(ask) {
97
+ return formatCodexPrefixRules(ask, 'prompt', 'ask permission groups');
98
+ }
99
+ function syncCodexPrefixFile(configDir, filename, content) {
100
+ const rulesPath = path.join(configDir, 'rules', filename);
101
+ if (content) {
92
102
  fs.mkdirSync(path.dirname(rulesPath), { recursive: true });
93
- fs.writeFileSync(rulesPath, rulesContent, 'utf-8');
103
+ fs.writeFileSync(rulesPath, content, 'utf-8');
94
104
  return;
95
105
  }
96
106
  if (fs.existsSync(rulesPath)) {
97
107
  fs.unlinkSync(rulesPath);
98
108
  }
99
109
  }
110
+ function syncCodexDenyRules(configDir, deny) {
111
+ syncCodexPrefixFile(configDir, CODEX_RULES_FILENAME, deny && deny.length > 0 ? convertDenyToCodexRules(deny) : null);
112
+ }
113
+ function syncCodexAskRules(configDir, ask) {
114
+ syncCodexPrefixFile(configDir, CODEX_ASK_RULES_FILENAME, ask && ask.length > 0 ? convertAskToCodexRules(ask) : null);
115
+ }
100
116
  function ensurePermissionsDir() {
101
117
  const groupsDir = path.join(getUserPermissionsDir(), 'groups');
102
118
  if (!fs.existsSync(groupsDir)) {
@@ -113,11 +129,15 @@ export function parsePermissionSet(filePath) {
113
129
  if (!parsed || typeof parsed !== 'object') {
114
130
  return null;
115
131
  }
132
+ const ask = Array.isArray(parsed.ask)
133
+ ? parsed.ask.filter((rule) => typeof rule === 'string')
134
+ : [];
116
135
  return {
117
136
  name: parsed.name || path.basename(filePath, path.extname(filePath)),
118
137
  description: parsed.description,
119
138
  allow: Array.isArray(parsed.allow) ? parsed.allow : [],
120
139
  deny: Array.isArray(parsed.deny) ? parsed.deny : [],
140
+ ...(ask.length ? { ask } : {}),
121
141
  additionalDirectories: Array.isArray(parsed.additionalDirectories) ? parsed.additionalDirectories : undefined,
122
142
  };
123
143
  }
@@ -225,9 +245,14 @@ export function getActivePermissionPresetName() {
225
245
  const v = process.env[PERMISSION_PRESET_ENV_VAR];
226
246
  return v && v.trim() ? v.trim() : null;
227
247
  }
248
+ const OPTIONAL_MISSING_PERMISSION_GROUPS = new Set(['00-local']);
249
+ function permissionPresetLabel() {
250
+ return getActivePermissionPresetName() ?? '(none)';
251
+ }
228
252
  export function buildPermissionsFromGroups(groupNames) {
229
253
  const allAllow = [];
230
254
  const allDeny = [];
255
+ const allAsk = [];
231
256
  for (const groupName of groupNames) {
232
257
  let filePath = null;
233
258
  for (const baseDir of [getUserPermissionsDir(), getPermissionsDir()]) {
@@ -242,38 +267,47 @@ export function buildPermissionsFromGroups(groupNames) {
242
267
  if (filePath)
243
268
  break;
244
269
  }
245
- if (!filePath)
246
- continue;
270
+ if (!filePath) {
271
+ if (OPTIONAL_MISSING_PERMISSION_GROUPS.has(groupName))
272
+ continue;
273
+ throw new Error(`permission preset "${permissionPresetLabel()}" includes "${groupName}", but no permissions/groups/${groupName}.yaml file exists`);
274
+ }
275
+ let content;
247
276
  try {
248
- const content = fs.readFileSync(filePath, 'utf-8');
249
- const lines = content.split(/\r?\n/);
250
- let section = null;
251
- for (const line of lines) {
252
- const sectionMatch = line.match(/^\s*(allow|deny)\s*:\s*(?:#.*)?$/);
253
- if (sectionMatch) {
254
- section = sectionMatch[1];
255
- continue;
277
+ content = fs.readFileSync(filePath, 'utf-8');
278
+ }
279
+ catch (err) {
280
+ throw new Error(`permission preset "${permissionPresetLabel()}" includes "${groupName}", but permissions/groups/${groupName}.yaml could not be read: ${err.message}`);
281
+ }
282
+ const lines = content.split(/\r?\n/);
283
+ let section = null;
284
+ for (const line of lines) {
285
+ const sectionMatch = line.match(/^\s*(allow|deny|ask)\s*:\s*(?:#.*)?$/);
286
+ if (sectionMatch) {
287
+ section = sectionMatch[1];
288
+ continue;
289
+ }
290
+ const match = line.match(/^\s*-\s*"(.+)"$/);
291
+ if (match) {
292
+ const rule = match[1];
293
+ if (section === 'ask') {
294
+ allAsk.push(rule);
295
+ }
296
+ else if (section === 'deny' || groupName === '99-deny' || groupName.includes('-deny')) {
297
+ allDeny.push(rule);
256
298
  }
257
- const match = line.match(/^\s*-\s*"(.+)"$/);
258
- if (match) {
259
- const rule = match[1];
260
- if (section === 'deny' || groupName === '99-deny' || groupName.includes('-deny')) {
261
- allDeny.push(rule);
262
- }
263
- else {
264
- allAllow.push(rule);
265
- }
299
+ else {
300
+ allAllow.push(rule);
266
301
  }
267
302
  }
268
303
  }
269
- catch {
270
- }
271
304
  }
272
305
  return {
273
306
  name: 'built',
274
307
  description: `Built from groups: ${groupNames.join(', ')}`,
275
308
  allow: allAllow,
276
309
  deny: allDeny.length > 0 ? allDeny : undefined,
310
+ ...(allAsk.length > 0 ? { ask: allAsk } : {}),
277
311
  };
278
312
  }
279
313
  export function listInstalledPermissions() {
@@ -363,6 +397,9 @@ export function convertToClaudeFormat(set) {
363
397
  allow: [...new Set(set.allow.map(canonicalToClaudeRule))],
364
398
  deny: set.deny ? [...new Set(set.deny.map(canonicalToClaudeRule))] : [],
365
399
  };
400
+ if (set.ask?.length) {
401
+ permissions.ask = [...new Set(set.ask.map(canonicalToClaudeRule))];
402
+ }
366
403
  if (set.additionalDirectories?.length) {
367
404
  permissions.additionalDirectories = [...set.additionalDirectories];
368
405
  }
@@ -485,6 +522,33 @@ export function convertToCopilotFormat(set, location) {
485
522
  },
486
523
  };
487
524
  }
525
+ function droidAskRule(permission) {
526
+ const parsed = parseCanonicalPattern(permission);
527
+ if (parsed?.tool !== 'bash')
528
+ return null;
529
+ const command = parsed.pattern.replace(/:?\*$/, '').trim();
530
+ if (!command)
531
+ return null;
532
+ const tokens = command.split(/\s+/);
533
+ return {
534
+ id: `agents-cli/${tokens.join('-')}`,
535
+ decision: 'ask',
536
+ match: { prefix: tokens },
537
+ tests: { match: [tokens.join(' ')], noMatch: ['true'] },
538
+ };
539
+ }
540
+ function droidAskRules(ask) {
541
+ const out = [];
542
+ const seen = new Set();
543
+ for (const permission of ask ?? []) {
544
+ const rule = droidAskRule(permission);
545
+ if (!rule || seen.has(rule.id))
546
+ continue;
547
+ seen.add(rule.id);
548
+ out.push(rule);
549
+ }
550
+ return out;
551
+ }
488
552
  export function convertToDroidFormat(set) {
489
553
  const commands = (permissions) => {
490
554
  const result = new Set();
@@ -499,9 +563,11 @@ export function convertToDroidFormat(set) {
499
563
  }
500
564
  return Array.from(result);
501
565
  };
566
+ const askRules = droidAskRules(set.ask);
502
567
  return {
503
568
  commandAllowlist: commands(set.allow),
504
569
  commandDenylist: commands(set.deny ?? []),
570
+ ...(askRules.length ? { askRules } : {}),
505
571
  };
506
572
  }
507
573
  export function convertToOpenClawFormat(set) {
@@ -554,10 +620,12 @@ export function convertToHermesFormat(set) {
554
620
  export function convertToAntigravityFormat(set) {
555
621
  const allow = serializeAntigravityEntries(set.allow);
556
622
  const deny = set.deny ? serializeAntigravityEntries(set.deny) : [];
623
+ const ask = set.ask?.length ? serializeAntigravityEntries(set.ask) : [];
557
624
  return {
558
625
  permissions: {
559
626
  allow,
560
627
  ...(deny.length ? { deny } : {}),
628
+ ...(ask.length ? { ask } : {}),
561
629
  },
562
630
  };
563
631
  }
@@ -591,6 +659,13 @@ export function convertToGrokFormat(set) {
591
659
  if (rule)
592
660
  rules.push(rule);
593
661
  }
662
+ if (set.ask) {
663
+ for (const perm of set.ask) {
664
+ const rule = canonicalToGrokRule(perm, 'ask');
665
+ if (rule)
666
+ rules.push(rule);
667
+ }
668
+ }
594
669
  if (set.deny) {
595
670
  for (const perm of set.deny) {
596
671
  const rule = canonicalToGrokRule(perm, 'deny');
@@ -655,6 +730,11 @@ export function convertToKimiFormat(set) {
655
730
  for (const perm of set.allow) {
656
731
  rules.push(...canonicalToKimiRules(perm, 'allow'));
657
732
  }
733
+ if (set.ask) {
734
+ for (const perm of set.ask) {
735
+ rules.push(...canonicalToKimiRules(perm, 'ask'));
736
+ }
737
+ }
658
738
  if (set.deny) {
659
739
  for (const perm of set.deny) {
660
740
  rules.push(...canonicalToKimiRules(perm, 'deny'));
@@ -674,6 +754,18 @@ export function convertToOpenCodeFormat(set) {
674
754
  bashPermissions[parsed.pattern] = 'allow';
675
755
  }
676
756
  }
757
+ if (set.ask) {
758
+ for (const perm of set.ask) {
759
+ if (BLANKET_BASH_FORMS.has(perm)) {
760
+ bashPermissions['*'] = 'ask';
761
+ continue;
762
+ }
763
+ const parsed = parseCanonicalPattern(perm);
764
+ if (parsed && parsed.tool === 'bash') {
765
+ bashPermissions[parsed.pattern] = 'ask';
766
+ }
767
+ }
768
+ }
677
769
  if (set.deny) {
678
770
  for (const perm of set.deny) {
679
771
  const parsed = parseCanonicalPattern(perm);
@@ -753,10 +845,12 @@ function readClaudePermissions(scope = 'user', cwd, options) {
753
845
  const content = fs.readFileSync(configPath, 'utf-8');
754
846
  const config = JSON.parse(content);
755
847
  if (config.permissions) {
848
+ const ask = Array.isArray(config.permissions.ask) ? config.permissions.ask : [];
756
849
  return {
757
850
  permissions: {
758
851
  allow: config.permissions.allow || [],
759
852
  deny: config.permissions.deny || [],
853
+ ...(ask.length ? { ask } : {}),
760
854
  },
761
855
  };
762
856
  }
@@ -849,10 +943,14 @@ export function applyClaudePermissions(set, scope = 'user', cwd, merge = true) {
849
943
  const existing = config.permissions;
850
944
  const mergedAllow = new Set([...(existing.allow || []).map(canonicalToClaudeRule), ...newPermissions.permissions.allow]);
851
945
  const mergedDeny = new Set([...(existing.deny || []).map(canonicalToClaudeRule), ...newPermissions.permissions.deny]);
852
- config.permissions = {
946
+ const mergedAsk = new Set([...(existing.ask || []).map(canonicalToClaudeRule), ...(newPermissions.permissions.ask || []).map(canonicalToClaudeRule)]);
947
+ const perms = {
853
948
  allow: [...mergedAllow],
854
949
  deny: [...mergedDeny],
855
950
  };
951
+ if (mergedAsk.size > 0)
952
+ perms.ask = [...mergedAsk];
953
+ config.permissions = perms;
856
954
  }
857
955
  else {
858
956
  config.permissions = newPermissions.permissions;
@@ -944,6 +1042,7 @@ function applyCodexPermissions(set, scope = 'user', cwd, merge = true) {
944
1042
  }
945
1043
  fs.writeFileSync(configPath, TOML.stringify(config), 'utf-8');
946
1044
  syncCodexDenyRules(configDir, set.deny);
1045
+ syncCodexAskRules(configDir, set.ask);
947
1046
  return { success: true };
948
1047
  }
949
1048
  catch (err) {
@@ -962,7 +1061,28 @@ function applyPermissionsToAgent(agentId, set, scope = 'user', cwd, merge = true
962
1061
  return { success: false, error: `Agent '${agentId}' does not support permissions` };
963
1062
  }
964
1063
  }
1064
+ function askSkipMessage(agentId, set) {
1065
+ if (!set.ask?.length)
1066
+ return undefined;
1067
+ const gate = supports(agentId, 'ask');
1068
+ if (gate.ok)
1069
+ return undefined;
1070
+ const target = PERMISSION_TARGETS[agentId];
1071
+ const detail = target && typeof target.ask === 'object'
1072
+ ? target.ask.reason
1073
+ : explainSkip(agentId, 'ask', gate);
1074
+ return `${agentId}: ask rules skipped: ${detail}`;
1075
+ }
1076
+ function withAskSkip(agentId, set, result) {
1077
+ if (!result.success)
1078
+ return result;
1079
+ const line = askSkipMessage(agentId, set);
1080
+ return line ? { ...result, skipped: [line] } : result;
1081
+ }
965
1082
  export function applyPermissionsToVersion(agentId, set, versionHome, merge = true, cwd) {
1083
+ return withAskSkip(agentId, set, applyPermissionsToVersionBody(agentId, set, versionHome, merge, cwd));
1084
+ }
1085
+ function applyPermissionsToVersionBody(agentId, set, versionHome, merge = true, cwd) {
966
1086
  if (!supports(agentId, 'allowlist').ok) {
967
1087
  return { success: false, error: `Agent '${agentId}' does not support permissions` };
968
1088
  }
@@ -980,11 +1100,14 @@ export function applyPermissionsToVersion(agentId, set, versionHome, merge = tru
980
1100
  const existing = config.permissions;
981
1101
  const mergedAllow = new Set([...(existing.allow || []).map(canonicalToClaudeRule), ...newPermissions.permissions.allow]);
982
1102
  const mergedDeny = new Set([...(existing.deny || []).map(canonicalToClaudeRule), ...newPermissions.permissions.deny]);
1103
+ const mergedAsk = new Set([...(existing.ask || []).map(canonicalToClaudeRule), ...(newPermissions.permissions.ask || []).map(canonicalToClaudeRule)]);
983
1104
  const mergedDirs = new Set([...(existing.additionalDirectories || []), ...(newPermissions.permissions.additionalDirectories || [])]);
984
1105
  const perms = {
985
1106
  allow: [...mergedAllow],
986
1107
  deny: [...mergedDeny],
987
1108
  };
1109
+ if (mergedAsk.size > 0)
1110
+ perms.ask = [...mergedAsk];
988
1111
  if (mergedDirs.size > 0) {
989
1112
  perms.additionalDirectories = [...mergedDirs];
990
1113
  }
@@ -1043,6 +1166,7 @@ export function applyPermissionsToVersion(agentId, set, versionHome, merge = tru
1043
1166
  }
1044
1167
  fs.writeFileSync(configPath, TOML.stringify(config), 'utf-8');
1045
1168
  syncCodexDenyRules(configDir, set.deny);
1169
+ syncCodexAskRules(configDir, set.ask);
1046
1170
  return { success: true };
1047
1171
  }
1048
1172
  if (agentId === 'antigravity') {
@@ -1052,6 +1176,9 @@ export function applyPermissionsToVersion(agentId, set, versionHome, merge = tru
1052
1176
  const perms = (typeof settings.permissions === 'object' && settings.permissions !== null && !Array.isArray(settings.permissions))
1053
1177
  ? settings.permissions
1054
1178
  : {};
1179
+ const existingAsk = Array.isArray(perms.ask) ? perms.ask : [];
1180
+ const incomingAsk = antigravityPerms.permissions.ask ?? [];
1181
+ const nextAsk = merge ? Array.from(new Set([...existingAsk, ...incomingAsk])) : incomingAsk;
1055
1182
  if (merge) {
1056
1183
  const existingAllow = Array.isArray(perms.allow) ? perms.allow : [];
1057
1184
  const existingDeny = Array.isArray(perms.deny) ? perms.deny : [];
@@ -1069,6 +1196,10 @@ export function applyPermissionsToVersion(agentId, set, versionHome, merge = tru
1069
1196
  else
1070
1197
  delete perms.deny;
1071
1198
  }
1199
+ if (nextAsk.length)
1200
+ perms.ask = nextAsk;
1201
+ else
1202
+ delete perms.ask;
1072
1203
  settings.permissions = perms;
1073
1204
  });
1074
1205
  return { success: true };
@@ -1178,6 +1309,19 @@ export function applyPermissionsToVersion(agentId, set, versionHome, merge = tru
1178
1309
  config.commandAllowlist = converted.commandAllowlist;
1179
1310
  config.commandDenylist = converted.commandDenylist;
1180
1311
  }
1312
+ const incomingAsk = converted.askRules ?? [];
1313
+ const existingBlock = config.permissionRules;
1314
+ const existingRules = existingBlock && typeof existingBlock === 'object' && !Array.isArray(existingBlock)
1315
+ && Array.isArray(existingBlock.rules)
1316
+ ? existingBlock.rules
1317
+ : [];
1318
+ const nextRules = merge
1319
+ ? [...existingRules.filter((rule) => !(typeof rule?.id === 'string' && rule.id.startsWith('agents-cli/'))), ...incomingAsk]
1320
+ : incomingAsk;
1321
+ if (nextRules.length > 0)
1322
+ config.permissionRules = { version: 1, rules: nextRules };
1323
+ else
1324
+ delete config.permissionRules;
1181
1325
  fs.mkdirSync(path.dirname(configPath), { recursive: true });
1182
1326
  fs.writeFileSync(configPath, JSON.stringify(config, null, 2), 'utf-8');
1183
1327
  return { success: true };
@@ -1305,6 +1449,8 @@ export function claudeToCanonical(perms) {
1305
1449
  allow: perms.permissions.allow,
1306
1450
  deny: perms.permissions.deny.length > 0 ? perms.permissions.deny : undefined,
1307
1451
  };
1452
+ if (perms.permissions.ask?.length)
1453
+ result.ask = perms.permissions.ask;
1308
1454
  if (perms.permissions.additionalDirectories?.length) {
1309
1455
  result.additionalDirectories = perms.permissions.additionalDirectories;
1310
1456
  }
@@ -1313,6 +1459,7 @@ export function claudeToCanonical(perms) {
1313
1459
  export function openCodeToCanonical(perms) {
1314
1460
  const allow = [];
1315
1461
  const deny = [];
1462
+ const ask = [];
1316
1463
  for (const [pattern, action] of Object.entries(perms.permission.bash)) {
1317
1464
  if (action === 'allow') {
1318
1465
  allow.push(`Bash(${pattern})`);
@@ -1320,11 +1467,15 @@ export function openCodeToCanonical(perms) {
1320
1467
  else if (action === 'deny') {
1321
1468
  deny.push(`Bash(${pattern})`);
1322
1469
  }
1470
+ else if (action === 'ask') {
1471
+ ask.push(`Bash(${pattern})`);
1472
+ }
1323
1473
  }
1324
1474
  return {
1325
1475
  name: 'exported',
1326
1476
  allow,
1327
1477
  deny: deny.length > 0 ? deny : undefined,
1478
+ ...(ask.length ? { ask } : {}),
1328
1479
  };
1329
1480
  }
1330
1481
  export function codexToCanonical(perms) {
@@ -1411,19 +1562,25 @@ export function getDefaultPermissionSet() {
1411
1562
  export function computePermissionsDiff(existing, incoming) {
1412
1563
  const existingAllowSet = new Set(existing.allow);
1413
1564
  const existingDenySet = new Set(existing.deny || []);
1565
+ const existingAskSet = new Set(existing.ask || []);
1414
1566
  const allowAdded = incoming.allow.filter((r) => !existingAllowSet.has(r));
1415
1567
  const allowExisting = incoming.allow.filter((r) => existingAllowSet.has(r));
1416
1568
  const incomingDeny = incoming.deny || [];
1417
1569
  const denyAdded = incomingDeny.filter((r) => !existingDenySet.has(r));
1418
1570
  const denyExisting = incomingDeny.filter((r) => existingDenySet.has(r));
1571
+ const incomingAsk = incoming.ask || [];
1572
+ const askAdded = incomingAsk.filter((r) => !existingAskSet.has(r));
1573
+ const askExisting = incomingAsk.filter((r) => existingAskSet.has(r));
1419
1574
  return {
1420
1575
  allow: { added: allowAdded, existing: allowExisting },
1421
1576
  deny: { added: denyAdded, existing: denyExisting },
1577
+ ask: { added: askAdded, existing: askExisting },
1422
1578
  };
1423
1579
  }
1424
1580
  export function mergePermissionSets(existing, incoming) {
1425
1581
  const allowSet = new Set([...existing.allow, ...incoming.allow]);
1426
1582
  const denySet = new Set([...(existing.deny || []), ...(incoming.deny || [])]);
1583
+ const askSet = new Set([...(existing.ask || []), ...(incoming.ask || [])]);
1427
1584
  const dirsSet = new Set([...(existing.additionalDirectories || []), ...(incoming.additionalDirectories || [])]);
1428
1585
  const result = {
1429
1586
  name: existing.name,
@@ -1431,6 +1588,8 @@ export function mergePermissionSets(existing, incoming) {
1431
1588
  allow: Array.from(allowSet).sort(),
1432
1589
  deny: Array.from(denySet).sort(),
1433
1590
  };
1591
+ if (askSet.size > 0)
1592
+ result.ask = Array.from(askSet).sort();
1434
1593
  if (dirsSet.size > 0) {
1435
1594
  result.additionalDirectories = Array.from(dirsSet).sort();
1436
1595
  }
@@ -1470,16 +1629,30 @@ function homeNativePermissionRules(agent, versionHome) {
1470
1629
  case 'cursor': {
1471
1630
  const c = readJsonFileSafe(configPath);
1472
1631
  const perms = (c?.permissions ?? {});
1473
- return { allow: toStringSet(perms.allow), deny: toStringSet(perms.deny) };
1632
+ return {
1633
+ allow: toStringSet(perms.allow),
1634
+ deny: toStringSet(perms.deny),
1635
+ ask: agent === 'claude' ? toStringSet(perms.ask) : new Set(),
1636
+ };
1474
1637
  }
1475
1638
  case 'droid': {
1476
1639
  const c = readJsonFileSafe(configPath);
1477
- return { allow: toStringSet(c?.commandAllowlist), deny: toStringSet(c?.commandDenylist) };
1640
+ const block = c?.permissionRules;
1641
+ const rules = block && typeof block === 'object' && !Array.isArray(block)
1642
+ && Array.isArray(block.rules)
1643
+ ? block.rules
1644
+ : [];
1645
+ const ask = new Set();
1646
+ for (const rule of rules) {
1647
+ if (rule?.decision === 'ask' && typeof rule.id === 'string')
1648
+ ask.add(rule.id);
1649
+ }
1650
+ return { allow: toStringSet(c?.commandAllowlist), deny: toStringSet(c?.commandDenylist), ask };
1478
1651
  }
1479
1652
  case 'openclaw': {
1480
1653
  const c = readJsonFileSafe(configPath);
1481
1654
  const tools = (c?.tools ?? {});
1482
- return { allow: toStringSet(tools.alsoAllow), deny: toStringSet(tools.deny) };
1655
+ return { allow: toStringSet(tools.alsoAllow), deny: toStringSet(tools.deny), ask: new Set() };
1483
1656
  }
1484
1657
  case 'opencode': {
1485
1658
  let c = null;
@@ -1492,13 +1665,16 @@ function homeNativePermissionRules(agent, versionHome) {
1492
1665
  const bash = (c?.permission?.bash ?? {});
1493
1666
  const allow = new Set();
1494
1667
  const deny = new Set();
1668
+ const ask = new Set();
1495
1669
  for (const [pattern, action] of Object.entries(bash)) {
1496
1670
  if (action === 'allow')
1497
1671
  allow.add(pattern);
1498
1672
  else if (action === 'deny')
1499
1673
  deny.add(pattern);
1674
+ else if (action === 'ask')
1675
+ ask.add(pattern);
1500
1676
  }
1501
- return { allow, deny };
1677
+ return { allow, deny, ask };
1502
1678
  }
1503
1679
  default:
1504
1680
  return null;
@@ -1508,41 +1684,48 @@ function expectedNativePermissionRules(agent, set) {
1508
1684
  switch (agent) {
1509
1685
  case 'claude': {
1510
1686
  const c = convertToClaudeFormat(set);
1511
- return { allow: new Set(c.permissions.allow), deny: new Set(c.permissions.deny) };
1687
+ return { allow: new Set(c.permissions.allow), deny: new Set(c.permissions.deny), ask: new Set(c.permissions.ask ?? []) };
1512
1688
  }
1513
1689
  case 'cursor': {
1514
1690
  const c = convertToCursorFormat(set);
1515
- return { allow: new Set(c.permissions.allow), deny: new Set(c.permissions.deny ?? []) };
1691
+ return { allow: new Set(c.permissions.allow), deny: new Set(c.permissions.deny ?? []), ask: new Set() };
1516
1692
  }
1517
1693
  case 'droid': {
1518
1694
  const c = convertToDroidFormat(set);
1519
- return { allow: new Set(c.commandAllowlist), deny: new Set(c.commandDenylist) };
1695
+ return {
1696
+ allow: new Set(c.commandAllowlist),
1697
+ deny: new Set(c.commandDenylist),
1698
+ ask: new Set((c.askRules ?? []).map((rule) => rule.id)),
1699
+ };
1520
1700
  }
1521
1701
  case 'openclaw': {
1522
1702
  const c = convertToOpenClawFormat(set);
1523
- return { allow: new Set(c.alsoAllow), deny: new Set(c.deny) };
1703
+ return { allow: new Set(c.alsoAllow), deny: new Set(c.deny), ask: new Set() };
1524
1704
  }
1525
1705
  case 'opencode': {
1526
1706
  const c = convertToOpenCodeFormat(set);
1527
1707
  const allow = new Set();
1528
1708
  const deny = new Set();
1709
+ const ask = new Set();
1529
1710
  for (const [pattern, action] of Object.entries(c.permission.bash)) {
1530
1711
  if (action === 'allow')
1531
1712
  allow.add(pattern);
1532
1713
  else if (action === 'deny')
1533
1714
  deny.add(pattern);
1715
+ else if (action === 'ask')
1716
+ ask.add(pattern);
1534
1717
  }
1535
- return { allow, deny };
1718
+ return { allow, deny, ask };
1536
1719
  }
1537
1720
  default:
1538
- return { allow: new Set(), deny: new Set() };
1721
+ return { allow: new Set(), deny: new Set(), ask: new Set() };
1539
1722
  }
1540
1723
  }
1541
1724
  export function permissionsGroupMatches(agent, versionHome, groupName) {
1542
1725
  if (!PERMISSIONS_REPRESENTABLE.has(agent))
1543
1726
  return true;
1544
1727
  const expected = expectedNativePermissionRules(agent, buildPermissionsFromGroups([groupName]));
1545
- if (expected.allow.size === 0 && expected.deny.size === 0)
1728
+ if (expected.allow.size === 0 && expected.deny.size === 0 && expected.ask.size === 0)
1546
1729
  return true;
1547
1730
  const home = homeNativePermissionRules(agent, versionHome);
1548
1731
  if (!home)
@@ -1553,5 +1736,8 @@ export function permissionsGroupMatches(agent, versionHome, groupName) {
1553
1736
  for (const r of expected.deny)
1554
1737
  if (!home.deny.has(r))
1555
1738
  return false;
1739
+ for (const r of expected.ask)
1740
+ if (!home.ask.has(r))
1741
+ return false;
1556
1742
  return true;
1557
1743
  }
@@ -1,4 +1,4 @@
1
- import type { RecordingCandidate, RecordingLedgerRow } from './model.js';
1
+ import type { RecordingCandidate, RecordingLedgerRow, TranscodeJob } from './model.js';
2
2
  export declare class RecordingLedger {
3
3
  readonly filePath: string;
4
4
  constructor(filePath?: string);
@@ -9,7 +9,8 @@ export declare class RecordingLedger {
9
9
  queue(candidate: RecordingCandidate): Promise<RecordingLedgerRow>;
10
10
  update(stem: string, sourcePath: string, patch: Partial<RecordingLedgerRow>): Promise<RecordingLedgerRow | null>;
11
11
  claim(stem: string, sourcePath: string, now?: number): Promise<boolean>;
12
- recoverInterrupted(now?: number): Promise<void>;
12
+ recoverInterrupted(isOwnerAlive: (pid: number) => boolean, now?: number): Promise<TranscodeJob[]>;
13
+ forgetTranscode(job: TranscodeJob): Promise<void>;
13
14
  pending(now?: number): Promise<RecordingLedgerRow[]>;
14
15
  shouldPostAttention(reason: string): Promise<boolean>;
15
16
  clearAttention(): Promise<void>;
@@ -101,15 +101,29 @@ export class RecordingLedger {
101
101
  return true;
102
102
  });
103
103
  }
104
- async recoverInterrupted(now = Date.now()) {
105
- await this.transaction((ledger) => {
104
+ async recoverInterrupted(isOwnerAlive, now = Date.now()) {
105
+ return this.transaction((ledger) => {
106
+ const orphaned = [];
106
107
  for (const row of ledger.rows) {
108
+ if (row.transcode && isOwnerAlive(row.transcode.ownerPid))
109
+ continue;
110
+ if (row.transcode)
111
+ orphaned.push(row.transcode);
107
112
  if (row.status !== 'transcoding' && row.status !== 'uploading')
108
113
  continue;
109
114
  row.status = 'queued';
110
115
  row.error = 'Interrupted before completion; retrying.';
111
116
  row.updatedAt = new Date(now).toISOString();
112
117
  }
118
+ return orphaned;
119
+ });
120
+ }
121
+ async forgetTranscode(job) {
122
+ await this.transaction((ledger) => {
123
+ for (const row of ledger.rows) {
124
+ if (row.transcode?.workDir === job.workDir)
125
+ delete row.transcode;
126
+ }
113
127
  });
114
128
  }
115
129
  async pending(now = Date.now()) {
@@ -8,6 +8,11 @@ export interface RecordingCandidate {
8
8
  recordedAt: string;
9
9
  sessionId?: string;
10
10
  }
11
+ export interface TranscodeJob {
12
+ pid: number;
13
+ workDir: string;
14
+ ownerPid: number;
15
+ }
11
16
  export interface RecordingLedgerRow {
12
17
  path: string;
13
18
  stem: string;
@@ -21,6 +26,7 @@ export interface RecordingLedgerRow {
21
26
  sessionId?: string;
22
27
  updatedAt: string;
23
28
  retryAt?: string;
29
+ transcode?: TranscodeJob;
24
30
  }
25
31
  export declare function isRecordingFile(filePath: string): boolean;
26
32
  export declare function cleanShotStem(filePath: string): string;