@cmodjs/core 4.3.3 → 5.0.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.
Files changed (64) hide show
  1. package/README.md +1 -1
  2. package/docs/commands.md +20 -31
  3. package/docs/dependencies.md +7 -5
  4. package/docs/index.md +4 -5
  5. package/docs/install-steps.md +12 -14
  6. package/docs/jobs.md +3 -11
  7. package/docs/mod.md +18 -21
  8. package/docs/session.md +11 -11
  9. package/docs/state.md +1 -1
  10. package/docs/testing.md +3 -5
  11. package/docs/ui.md +4 -4
  12. package/jobs/program.d.ts.map +1 -1
  13. package/jobs/program.js +3 -17
  14. package/mod.d.ts +0 -16
  15. package/mod.d.ts.map +1 -1
  16. package/package.json +1 -1
  17. package/records.d.ts +4 -11
  18. package/records.d.ts.map +1 -1
  19. package/records.js +17 -48
  20. package/runtime/announce.d.ts +1 -1
  21. package/runtime/announce.d.ts.map +1 -1
  22. package/runtime/announce.js +2 -3
  23. package/runtime/conversations.d.ts.map +1 -1
  24. package/runtime/conversations.js +3 -46
  25. package/runtime/engine.d.ts +2 -2
  26. package/runtime/engine.d.ts.map +1 -1
  27. package/runtime/installer.d.ts +0 -9
  28. package/runtime/installer.d.ts.map +1 -1
  29. package/runtime/installer.js +1 -15
  30. package/runtime/lifecycle.d.ts +1 -2
  31. package/runtime/lifecycle.d.ts.map +1 -1
  32. package/runtime/lifecycle.js +37 -191
  33. package/runtime/metadata.d.ts +1 -2
  34. package/runtime/metadata.d.ts.map +1 -1
  35. package/runtime/metadata.js +1 -2
  36. package/runtime/sessions.d.ts +3 -7
  37. package/runtime/sessions.d.ts.map +1 -1
  38. package/runtime/sessions.js +10 -34
  39. package/runtime/toaster.d.ts.map +1 -1
  40. package/runtime/toaster.js +6 -9
  41. package/runtime/ui.d.ts +1 -0
  42. package/runtime/ui.d.ts.map +1 -1
  43. package/runtime/ui.js +31 -12
  44. package/src/jobs/program.ts +3 -17
  45. package/src/mod.ts +0 -18
  46. package/src/records.ts +20 -55
  47. package/src/runtime/announce.ts +2 -3
  48. package/src/runtime/conversations.ts +3 -45
  49. package/src/runtime/engine.ts +2 -2
  50. package/src/runtime/installer.ts +1 -37
  51. package/src/runtime/lifecycle.ts +38 -188
  52. package/src/runtime/metadata.ts +0 -3
  53. package/src/runtime/sessions.ts +10 -39
  54. package/src/runtime/toaster.ts +6 -9
  55. package/src/runtime/ui.ts +32 -13
  56. package/src/testing.ts +11 -16
  57. package/testing.d.ts +0 -1
  58. package/testing.d.ts.map +1 -1
  59. package/testing.js +11 -15
  60. package/docs/permissions.md +0 -97
  61. package/runtime/grants.d.ts +0 -34
  62. package/runtime/grants.d.ts.map +0 -1
  63. package/runtime/grants.js +0 -326
  64. package/src/runtime/grants.ts +0 -348
@@ -37,21 +37,8 @@ export function pickedColor(args) {
37
37
  const picked = args.trim().toLowerCase();
38
38
  return resetColors.includes(picked) ? undefined : picked;
39
39
  }
40
- const actPermissions = { send: 'prompt', startTask: 'tasks', fork: 'tasks', clone: 'tasks', startBackgroundTask: 'tasks', usage: 'conversation', surfaces: 'conversation', abort: 'prompt' };
41
- const startsTurns = ['CronCreate'];
42
- const ownSchedule = ['CronDelete', 'CronList'];
43
- export const beforePermission = (event) => (event === 'toolCall' ? 'tools' : event === TaskStart ? 'tasks' : 'prompt');
44
- const answerPermissions = (event, answer) => [
45
- ...(Object.keys(answer).some((key) => key !== 'note') ? [beforePermission(event)] : []),
46
- ...(answer.note === undefined ? [] : ['prompt']),
47
- ];
48
- export const isAct = (action) => action === 'callTool' || action in actPermissions;
49
- export function toolPermission(tool) {
50
- return startsTurns.includes(tool) ? 'prompt' : ownSchedule.includes(tool) ? undefined : 'tools';
51
- }
52
- export function actPermission(action, input) {
53
- return action === 'callTool' ? (toolPermission(String(input?.name)) ?? 'tools') : actPermissions[action];
54
- }
40
+ const acts = ['send', 'startTask', 'fork', 'clone', 'startBackgroundTask', 'callTool', 'usage', 'surfaces', 'abort'];
41
+ export const isAct = (action) => acts.includes(action);
55
42
  export async function usageOf(claude) {
56
43
  const [model, usage] = await Promise.all([claude.session.model(), claude.session.usage()]);
57
44
  const { tokens, window, percent } = usage.context;
@@ -126,7 +113,7 @@ export function isInScope(scope, session, change, isUnder) {
126
113
  export function withoutPermissionCheck(name, hearer) {
127
114
  return `${name}: ${hearer} hears Claude Code's permission check, so hooks/register.ts must call registerPermissionCheck(addHook) after registerMod.`;
128
115
  }
129
- export function createSessionsClient({ name, claude, report, isGranted, permissionRefusal, hookOn, routeOn, permissionRoutes }) {
116
+ export function createSessionsClient({ name, claude, report, hookOn, routeOn, permissionRoutes }) {
130
117
  const call = (method, input) => claude.cmod.call({ to: cmodPluginName, method, input });
131
118
  const listening = new Map();
132
119
  const deciding = new Map();
@@ -200,20 +187,13 @@ export function createSessionsClient({ name, claude, report, isGranted, permissi
200
187
  });
201
188
  const decidersOf = (session, event, isInProject) => [...(deciding.get(session) ?? []), ...(isInProject ? (deciding.get(everySession) ?? []) : [])].filter((entry) => entry.event === event);
202
189
  const decides = (entry, session, change) => isInScope(entry.scope, session, change, isUnderIn(session)) && (entry.matcher === undefined || matches(payloadOf(change), entry.matcher));
203
- const mayDecide = (session) => session === current.id || isGranted('conversation');
204
190
  const combined = async (session, event, change, isInProject) => {
205
191
  const askers = decidersOf(session, event, isInProject)
206
192
  .map((entry) => async (latest) => {
207
193
  if (!decides(entry, session, latest))
208
194
  return undefined;
209
195
  const payload = await payloadFor(session, latest);
210
- const answer = await invoke(entry.method, entry.options, async (time) => takenAnswer(entry.method, beforeAnswerKeys[event], await entry.listener(payload, time)), beforeAnswerKeys[event]);
211
- if (answer === undefined || answer === null || (typeof answer === 'object' && 'refuse' in answer))
212
- return answer;
213
- const missing = answerPermissions(event, answer).find((permission) => !isGranted(permission));
214
- if (missing === undefined)
215
- return answer;
216
- throw new Error(permissionRefusal(`${entry.method} with the answer { ${Object.keys(answer).join(', ')} }`, missing));
196
+ return invoke(entry.method, entry.options, async (time) => takenAnswer(entry.method, beforeAnswerKeys[event], await entry.listener(payload, time)), beforeAnswerKeys[event]);
217
197
  });
218
198
  const answer = await foldBefore(event, change, askers, (error) => report(`session:${methodOf('before', event)}`, `The ${methodOf('before', event)} listener failed`, error));
219
199
  return answer?.note === undefined ? answer : { ...answer, note: modNote(name, answer.note) };
@@ -464,15 +444,12 @@ export function createSessionsClient({ name, claude, report, isGranted, permissi
464
444
  const answer = commandListeners.beforeRun.size === 0 ? undefined : await raise('beforeRun', run);
465
445
  if (typeof answer?.['refuse'] === 'string')
466
446
  return { text: answer['refuse'] };
467
- const changes = answer !== undefined && isGranted('prompt') ? answer : undefined;
468
- if (answer !== undefined && changes === undefined)
469
- report('session:beforeRun', 'The beforeRun listener failed', new Error(permissionRefusal(`beforeRun with the answer { ${Object.keys(answer).join(', ')} }`, 'prompt')));
470
- if (typeof changes?.['result'] === 'string')
471
- return { text: changes['result'], ...(typeof changes['exitCode'] === 'number' ? { exitCode: changes['exitCode'] } : {}) };
472
- const args = typeof changes?.['args'] === 'string' ? changes['args'] : e.args;
447
+ if (typeof answer?.['result'] === 'string')
448
+ return { text: answer['result'], ...(typeof answer['exitCode'] === 'number' ? { exitCode: answer['exitCode'] } : {}) };
449
+ const args = typeof answer?.['args'] === 'string' ? answer['args'] : e.args;
473
450
  const ran = await next(args === e.args ? e : { ...e, args });
474
451
  void raise('onRun', { ...run, args });
475
- return typeof changes?.['note'] === 'string' ? { ...ran, context: [...(ran.context ?? []), modNote(name, changes['note'])] } : ran;
452
+ return typeof answer?.['note'] === 'string' ? { ...ran, context: [...(ran.context ?? []), modNote(name, answer['note'])] } : ran;
476
453
  }, async (e, error) => {
477
454
  const refusal = commandListeners.beforeRun.size === 0 ? undefined : refusalFor('beforeRun', await commandRun(e), error);
478
455
  return refusal === undefined ? undefined : { text: refusal.refuse };
@@ -561,9 +538,8 @@ export function createSessionsClient({ name, claude, report, isGranted, permissi
561
538
  caption: (toolCall, text) => claude.ui.notice(toolCall.callId, text),
562
539
  });
563
540
  const every = eventMethods(() => ({}), false);
564
- const answerBefore = async (session, event, change, isInProject) => (mayDecide(session) ? combined(session, event, change, isInProject) : undefined);
565
541
  const failedBefore = (session, event, change, isInProject, error) => {
566
- const asked = mayDecide(session) ? decidersOf(session, event, isInProject).filter((entry) => decides(entry, session, change)) : [];
542
+ const asked = decidersOf(session, event, isInProject).filter((entry) => decides(entry, session, change));
567
543
  return asked.map((entry) => refusalOf(entry.options, beforeAnswerKeys[event], error)).find((answer) => answer !== undefined);
568
544
  };
569
545
  return {
@@ -597,7 +573,7 @@ export function createSessionsClient({ name, claude, report, isGranted, permissi
597
573
  }
598
574
  }
599
575
  },
600
- answerBefore,
576
+ answerBefore: combined,
601
577
  failedBefore,
602
578
  raise,
603
579
  listen,
@@ -1 +1 @@
1
- {"version":3,"file":"toaster.d.ts","sourceRoot":"","sources":["../src/runtime/toaster.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,aAAa,EAAS,MAAM,aAAa,CAAA;AACpF,OAAO,KAAK,EAAE,KAAK,EAAE,OAAO,EAAgB,SAAS,EAAE,MAAM,WAAW,CAAA;AAIxE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAIzC,MAAM,MAAM,UAAU,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAA;CAAE,CAAA;AAE9G,MAAM,MAAM,OAAO,GAAG;IAAE,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,OAAO,CAAC;IAAC,QAAQ,CAAC,UA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MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,SAAS,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAQhG"}
@@ -1,5 +1,5 @@
1
1
  import { Box, Button, drawWith, Link, Text } from '../ui/elements.js';
2
- import { coreVersion, grantFix, installFix, isObject, secretFix } from '../records.js';
2
+ import { coreVersion, installFix, isObject, secretFix } from '../records.js';
3
3
  import { firstLine, messageOf } from '../utils/text.js';
4
4
  import { beforeDeadline } from './deadline.js';
5
5
  import { cmodPluginName } from './dependencies.js';
@@ -172,16 +172,13 @@ export function createToaster(claude, name, version) {
172
172
  .catch((failure) => `unknown (${messageOf(failure)})`);
173
173
  return `${name} ${modVersion}, @cmodjs/core ${coreVersion}, at ${failedAt.toISOString()}\n${message}${description === undefined ? '' : `\n${description}`}${stack}`;
174
174
  };
175
- const text = `${message}\n${description ?? ''}`;
176
- const isGrantRefusal = text.includes(grantFix);
177
- const isShownAtOnce = isCritical && !isGrantRefusal;
178
175
  const logged = async () => {
179
176
  const contact = await contactOf(claude);
180
177
  const failure = { mod: name, id, message, details: await details(at), at: at.toISOString(), isCritical, root: claude.plugin.root, ...(contact === undefined ? {} : { contact }) };
181
- const shows = await showsToast(failure, isShownAtOnce);
182
- if (isShownAtOnce)
178
+ const shows = await showsToast(failure, isCritical);
179
+ if (isCritical)
183
180
  return;
184
- if (shows === undefined || (shows && !isGrantRefusal))
181
+ if (shows !== false)
185
182
  return show();
186
183
  claude.ui.log(`${name}: ${message}${description === undefined ? '' : `: ${description}`}`, { to: 'debug' });
187
184
  };
@@ -232,8 +229,8 @@ export function createToaster(claude, name, version) {
232
229
  const fixes = [
233
230
  { sentence: installFix, label: 'Plugins', onClick: () => claude.command.run({ command: 'plugin' }) },
234
231
  { sentence: secretFix, label: 'Open /config', onClick: () => claude.command.run({ command: 'config' }) },
235
- ].filter(({ sentence }) => text.includes(sentence));
236
- if (isShownAtOnce)
232
+ ].filter(({ sentence }) => `${message}\n${description ?? ''}`.includes(sentence));
233
+ if (isCritical)
237
234
  show();
238
235
  claude.clock.after(0, () => void logged());
239
236
  return id;
package/runtime/ui.d.ts CHANGED
@@ -88,6 +88,7 @@ export type ShownPages = {
88
88
  readonly shown: string | null;
89
89
  readonly isFocused: boolean;
90
90
  };
91
+ export declare function inheriting(props: MarkdownProps, draw: (drawn: MarkdownProps) => RenderElement, laterKey?: () => string | undefined): (left: MarkdownProps) => RenderElement;
91
92
  export declare function merged(updates: readonly PartsUpdate[]): PartsUpdate;
92
93
  export type UiOptions<State extends object> = {
93
94
  readonly name: string;
@@ -1 +1 @@
1
- {"version":3,"file":"ui.d.ts","sourceRoot":"","sources":["../src/runtime/ui.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,YAAY,EAAE,MAAM,EAAE,aAAa,EAAgB,aAAa,EAAE,MAAM,aAAa,CAAA;AACzG,OAAO,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAE1C,OAAO,EAAW,KAAK,IAAI,EAAmC,KAAK,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAGrG,OAAO,EAAwG,KAAK,aAAa,EAAE,KAAK,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAC5K,OAAO,EAA8C,KAAK,QAAQ,EAAkB,MAAM,iBAAiB,CAAA;AAG3G,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEzC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACzC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAE3C,eAAO,MAAM,WAAW;aACtB,IAAI,EAAE,YAAY;aAClB,IAAI,EAAE,WAAW;aACjB,KAAK,EAAE,YAAY;aACnB,KAAK,EAAE,YAAY;aACnB,OAAO,EAAE,mBAAmB;aAC5B,OAAO,EAAE,sBAAsB;CACvB,CAAA;AAEV,eAAO,MAAM,UAAU,yEAAyE,CAAA;AAEhG,MAAM,MAAM,SAAS,GAAG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AAE,MAAM,EAAE,QAAQ,EAAE,GAAG,EAAE,QAAQ,EAAE,QAAQ,EAAE,EAAE,SAAS,CAAC,KAAK,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,CAgjBnJ"}
package/runtime/ui.js CHANGED
@@ -42,6 +42,27 @@ function pieceProps(props, given, isFirst) {
42
42
  const merged = { ...props, ...given };
43
43
  return isFirst || !('isFirstOfReply' in merged) ? merged : { ...merged, isFirstOfReply: false };
44
44
  }
45
+ function laterKeys(key) {
46
+ let used = 0;
47
+ return () => (key === undefined ? undefined : `${key}:${(used += 1)}`);
48
+ }
49
+ export function inheriting(props, draw, laterKey = laterKeys(props.key)) {
50
+ const { dimColor, onLinkPress, pressableLinks } = props;
51
+ const inherited = { ...(dimColor === undefined ? {} : { dimColor }), ...(onLinkPress === undefined ? {} : { onLinkPress }), ...(pressableLinks === undefined ? {} : { pressableLinks }) };
52
+ let isKeyTaken = false;
53
+ const keyOf = (left) => {
54
+ if (left.key !== undefined)
55
+ return left.key;
56
+ if (isKeyTaken)
57
+ return laterKey();
58
+ isKeyTaken = true;
59
+ return props.key;
60
+ };
61
+ return (left) => {
62
+ const key = keyOf(left);
63
+ return draw({ ...inherited, ...(key === undefined ? {} : { key }), ...left });
64
+ };
65
+ }
45
66
  function threw(error) {
46
67
  return `threw, so Claude Code draws its own: ${messageOf(error)}`;
47
68
  }
@@ -242,18 +263,18 @@ export function createUi({ name, claude, router, report, announce, mod, borrowed
242
263
  const renderOf = (type) => markdownRenders.get(type);
243
264
  const drawnBlock = (piece, at, drawClaudes, keyPrefix, table) => {
244
265
  if ('text' in piece)
245
- return drawClaudes(piece.text);
266
+ return drawClaudes({ text: piece.text });
246
267
  const { render, props: block } = piece;
247
- const draw = () => drawKeyed(keyPrefix, () => render.Component({ ...block, ...at, Default: ({ source = block.source }) => drawClaudes(source) }));
268
+ const draw = () => drawKeyed(keyPrefix, () => render.Component({ ...block, ...at, Default: ({ source = block.source }) => drawClaudes({ text: source }) }));
248
269
  try {
249
- return table === undefined ? draw() : drawWith(table, draw);
270
+ return table === undefined ? draw() : drawWith(table, draw, drawClaudes);
250
271
  }
251
272
  catch (error) {
252
273
  render.log(threw(error));
253
- return drawClaudes(block.source);
274
+ return drawClaudes({ text: block.source });
254
275
  }
255
276
  };
256
- const othersFrom = (table, at, from, unkeyedScope) => (props) => {
277
+ const othersFrom = (table, at, from, unkeyedScope) => (props, laterKey = laterKeys(props.key)) => {
257
278
  if (from >= stylers.length)
258
279
  return table.Markdown(props);
259
280
  const scope = props.key ?? unkeyedScope();
@@ -261,7 +282,8 @@ export function createUi({ name, claude, router, report, announce, mod, borrowed
261
282
  if (index < from)
262
283
  continue;
263
284
  const cached = `${stylersSeen}\u0000${at.surface}\u0000${at.columns}\u0000${props.text}`;
264
- const drawn = drawWith(table, () => borrowed(styler, cached, { markdown: props.text, ...at }, scope), othersFrom(table, at, index + 1, unkeyedScope));
285
+ const next = othersFrom(table, at, index + 1, unkeyedScope);
286
+ const drawn = drawWith(table, () => borrowed(styler, cached, { markdown: props.text, ...at }, scope), inheriting(props, (part) => next(part, laterKey), laterKey));
265
287
  if (drawn !== undefined)
266
288
  return drawn;
267
289
  }
@@ -279,11 +301,8 @@ export function createUi({ name, claude, router, report, announce, mod, borrowed
279
301
  if (pieces.every((piece) => 'text' in piece))
280
302
  return others(props);
281
303
  const scope = props.key ?? unkeyedScope();
282
- let drawn = 0;
283
- const drawClaudes = (text) => {
284
- const index = drawn++;
285
- return others(index === 0 || props.key === undefined ? { ...props, text } : { ...props, text, key: `${props.key}:${index}` });
286
- };
304
+ const laterKey = laterKeys(props.key);
305
+ const drawClaudes = inheriting(props, (part) => others(part, laterKey), laterKey);
287
306
  const drawings = pieces.map((piece, index) => drawnBlock(piece, at, drawClaudes, `${scope}:${index}:`, table));
288
307
  return drawPieces(drawings.map((drawing) => ({ drawing, isClaudesRow: false })), 'pane');
289
308
  };
@@ -292,7 +311,7 @@ export function createUi({ name, claude, router, report, announce, mod, borrowed
292
311
  const pieces = read === undefined ? [] : read(text, renderOf);
293
312
  if (pieces.every((piece) => 'text' in piece))
294
313
  return Markdown({ text });
295
- return drawPieces(pieces.map((piece, index) => ({ drawing: drawnBlock(piece, at, (source) => Markdown({ text: source }), `${index}:`), isClaudesRow: false })), 'pane');
314
+ return drawPieces(pieces.map((piece, index) => ({ drawing: drawnBlock(piece, at, Markdown, `${index}:`), isClaudesRow: false })), 'pane');
296
315
  };
297
316
  const routeMarkdown = (createReader) => {
298
317
  if (read !== undefined)
@@ -1,5 +1,4 @@
1
1
  import type { Job } from '../mod.js'
2
- import { PermissionRefused, programAddresses } from '../runtime/grants.js'
3
2
  import { engineOf } from '../runtime/engine.js'
4
3
  import { messageOf } from '../utils/text.js'
5
4
  import { basename } from '../vendor.js'
@@ -26,17 +25,11 @@ export function program(options: { readonly command: readonly string[]; readonly
26
25
  let failure: Error | undefined
27
26
  let exits = 0
28
27
  const waiting: { resolve: (address: Address) => void; reject: (error: Error) => void }[] = []
29
- const ownAddresses = programAddresses(mod)
30
28
 
31
- const spawn = async () => (singleInstance ? spawnCmod(['program', mod.name, '--', ...command], request) : claude.process.spawn(request))
32
-
33
- const forget = () => {
34
- if (address !== undefined) ownAddresses.delete(freeAddressOf(address))
35
- address = undefined
36
- }
29
+ const spawn = () => (singleInstance ? spawnCmod(['program', mod.name, '--', ...command], environment) : claude.process.spawn(request))
37
30
 
38
31
  const stop = (reason: string) => {
39
- forget()
32
+ address = undefined
40
33
  state = 'fatal'
41
34
  failure = new Error(`${mod.name}: the ${executable} program stopped: ${reason}`)
42
35
  const retry = () => {
@@ -49,11 +42,9 @@ export function program(options: { readonly command: readonly string[]; readonly
49
42
  }
50
43
 
51
44
  const show = (next: Address) => {
52
- forget()
53
45
  address = next
54
46
  state = 'running'
55
47
  exits = 0
56
- ownAddresses.add(freeAddressOf(next))
57
48
  for (const waiter of waiting.splice(0)) waiter.resolve(next)
58
49
  }
59
50
 
@@ -80,10 +71,9 @@ export function program(options: { readonly command: readonly string[]; readonly
80
71
  }
81
72
  }
82
73
  } catch (error) {
83
- if (error instanceof PermissionRefused) return stop(messageOf(error))
84
74
  lastError = messageOf(error)
85
75
  }
86
- forget()
76
+ address = undefined
87
77
  exits += 1
88
78
  const wait = backoffSeconds[exits - 1]
89
79
  if (wait === undefined) {
@@ -120,7 +110,3 @@ function addressOf(line: string): Address | undefined {
120
110
  if (unix?.[1] !== undefined) return { url: 'http://localhost', socketPath: unix[1] }
121
111
  return undefined
122
112
  }
123
-
124
- function freeAddressOf(address: Address): string {
125
- return address.socketPath ?? new URL(address.url).host
126
- }
package/src/mod.ts CHANGED
@@ -83,23 +83,6 @@ export type Stat = Omit<Entry, 'name'> & {
83
83
 
84
84
  export type FileChange = { readonly path: string; readonly type: 'change' | 'add' | 'unlink' }
85
85
 
86
- export type Allowed = {
87
- allows(value: string): boolean
88
- }
89
-
90
- export type Permissions = {
91
- readonly conversation: boolean
92
- readonly prompt: boolean
93
- readonly model: boolean
94
- readonly tasks: boolean
95
- readonly tools: boolean
96
- readonly approve: boolean
97
- readonly network: Allowed
98
- readonly run: Allowed
99
- readonly files: Allowed
100
- readonly config: Allowed
101
- }
102
-
103
86
  export type SettingsFile = {
104
87
  read(): Promise<Settings>
105
88
  update(values: Readonly<Record<string, unknown>>): Promise<void>
@@ -222,7 +205,6 @@ export type Mod<State extends object = Record<never, never>, Declared extends Op
222
205
  readonly dataFolder: string
223
206
  readonly state: Readonly<State>
224
207
  readonly options: OptionValues<Declared>
225
- readonly permissions: Permissions
226
208
  readonly hotkeys: { readonly [Key in keyof Keys]: Hotkey }
227
209
  every(ms: number, listener: () => unknown): Timer
228
210
  after(ms: number, listener: () => unknown): Timer
package/src/records.ts CHANGED
@@ -19,13 +19,13 @@ export type Steps = {
19
19
  uninstall?: string
20
20
  program?: string
21
21
  hotkeys?: Hotkeys
22
+ approve?: true
22
23
  permissions?: readonly string[]
23
24
  }
24
25
 
25
- export const listPermissions = ['network', 'run', 'files', 'config'] as const
26
- export const flagPermissions = ['conversation', 'prompt', 'model', 'tasks', 'tools', 'approve'] as const
27
- export type ListPermission = (typeof listPermissions)[number]
28
- export type FlagPermission = (typeof flagPermissions)[number]
26
+ const listPermissions = ['network', 'run', 'files', 'config'] as const
27
+ const flagPermissions = ['conversation', 'prompt', 'model', 'tasks', 'tools', 'approve'] as const
28
+ type ListPermission = (typeof listPermissions)[number]
29
29
  const permissionNames: readonly string[] = [...listPermissions, ...flagPermissions]
30
30
  const hostName = /^[A-Za-z0-9]([A-Za-z0-9-]*[A-Za-z0-9])?(\.[A-Za-z0-9]([A-Za-z0-9-]*[A-Za-z0-9])?)*$/
31
31
  const programName = /^[A-Za-z0-9][A-Za-z0-9._+-]*$/
@@ -159,12 +159,15 @@ export function readSteps(pkg: unknown): Steps | undefined {
159
159
  if (!isObject(steps)) throw new Error('package.json has a "cmod" key that is not an object. Write "cmod": { "install": "./setup/install.sh", "uninstall": "./setup/uninstall.sh" }.')
160
160
  const program = steps['program']
161
161
  if (program !== undefined && (typeof program !== 'string' || !pluginName.test(program))) throw new Error('package.json "cmod.program" must be the program\'s command, such as "hello".')
162
+ const approve = steps['approve']
163
+ if (approve !== undefined && approve !== true) throw new Error(`package.json "cmod.approve" is ${JSON.stringify(approve)}. Write "approve": true, or leave it out.`)
162
164
  const permissions = readPermissions(steps)
163
165
  return {
164
166
  ...readCommand(steps, 'install'),
165
167
  ...readCommand(steps, 'uninstall'),
166
168
  ...(program === undefined ? {} : { program }),
167
169
  ...readHotkeys(steps['hotkeys']),
170
+ ...(approve === true || permissions.includes('approve') ? { approve: true as const } : {}),
168
171
  ...(permissions.length === 0 ? {} : { permissions }),
169
172
  }
170
173
  }
@@ -198,50 +201,14 @@ function readPermissions(steps: Record<string, unknown>): string[] {
198
201
  return items
199
202
  }
200
203
 
201
- export const grantFix = 'Turn it on in Settings.'
202
-
203
204
  export const installFix = 'Install it in Plugins.'
204
205
 
205
206
  export const secretFix = 'Set it in /config, where Claude Code keeps it in your keychain.'
206
207
 
207
- export function permissionWords(item: string): string {
208
- const split = item.indexOf(':')
209
- const target = item.slice(split + 1)
210
- switch (split === -1 ? item : item.slice(0, split)) {
211
- case 'network':
212
- return `Connect to ${target}`
213
- case 'run':
214
- return target === '*' ? 'Run any program on your computer' : `Run ${target} on your computer`
215
- case 'files':
216
- return `Change ${target}`
217
- case 'conversation':
218
- return 'Read your Claude Code conversations'
219
- case 'prompt':
220
- return 'Add text Claude reads and start turns'
221
- case 'model':
222
- return 'Ask a model, which uses your plan'
223
- case 'tasks':
224
- return 'Start tasks that work beside Claude'
225
- case 'tools':
226
- return "Use and change Claude's tool calls"
227
- case 'config':
228
- return `Change ${target} in your Claude Code settings`
229
- case 'approve':
230
- return "Approve Claude's tool calls for you"
231
- default:
232
- return item
233
- }
234
- }
235
-
236
208
  export function settingPaths(values: Readonly<Record<string, unknown>>): string[][] {
237
209
  return Object.entries(values).flatMap(([key, value]) => (isObject(value) && Object.keys(value).length > 0 ? settingPaths(value).map((path) => [key, ...path]) : [[key]]))
238
210
  }
239
211
 
240
- export function isSettingCovered(granted: Iterable<string>, path: string): boolean {
241
- const item = `config:${path}`
242
- return [...granted].some((each) => item === each || item.startsWith(`${each}.`))
243
- }
244
-
245
212
  export const pendingStepsMethod = 'cmod:pendingSteps'
246
213
 
247
214
  export const finishStepsMethod = 'cmod:finishSteps'
@@ -316,18 +283,18 @@ export function preferencesPath(store: string): string {
316
283
  return `${store}/preferences.json`
317
284
  }
318
285
 
319
- export type Preferences = { readonly asksBeforeUpdatePermissions: boolean; readonly showsInstalledModErrors: boolean }
286
+ export type Preferences = { readonly showsInstalledModErrors: boolean }
320
287
 
321
288
  export function parsePreferences(value: unknown, path: string): Preferences {
322
- if (value === undefined) return { asksBeforeUpdatePermissions: false, showsInstalledModErrors: false }
323
- if (!isObject(value) || ['asksBeforeUpdatePermissions', 'showsInstalledModErrors'].some((key) => value[key] !== undefined && typeof value[key] !== 'boolean')) throw new Error(`${path} is not a map of cmod's preferences to true or false. Delete it, and cmod uses its defaults.`)
324
- return { asksBeforeUpdatePermissions: value['asksBeforeUpdatePermissions'] === true, showsInstalledModErrors: value['showsInstalledModErrors'] === true }
289
+ if (value === undefined) return { showsInstalledModErrors: false }
290
+ if (!isObject(value) || (value['showsInstalledModErrors'] !== undefined && typeof value['showsInstalledModErrors'] !== 'boolean')) throw new Error(`${path} is not a map of cmod's preferences to true or false. Delete it, and cmod uses its defaults.`)
291
+ return { showsInstalledModErrors: value['showsInstalledModErrors'] === true }
325
292
  }
326
293
 
327
294
  export function parseConsent(value: unknown, path: string): Record<string, string[]> {
328
295
  if (value === undefined) return Object.create(null)
329
296
  if (!isObject(value) || !Object.values(value).every(isTextList)) {
330
- throw new Error(`${path} is not a map of plugin names to what each was approved for. Delete it, and cmod asks again.`)
297
+ throw new Error(`${path} is not a map of plugin names to what each was approved for. Delete it, and cmod writes it again at each mod's next setup.`)
331
298
  }
332
299
  return Object.assign(Object.create(null), value) as Record<string, string[]>
333
300
  }
@@ -339,7 +306,9 @@ function readHotkeys(hotkeys: unknown): Steps {
339
306
  return { hotkeys: checkHotkeys('package.json "cmod"', hotkeys as Record<string, HotkeyInit>) }
340
307
  }
341
308
 
342
- export const coreVersion = '4.3.3'
309
+ export const coreVersion = '5.0.0'
310
+
311
+ export const oldestCmodVersion = '5.0.0'
343
312
 
344
313
  export function hotkeyCommand(mod: string, hotkey: string): string {
345
314
  return `${mod}--${hotkey}`
@@ -359,22 +328,18 @@ export function boundCombos(keybindings: unknown): Map<string, string> {
359
328
  return combos
360
329
  }
361
330
 
362
- export function hotkeyWords(hotkeys: Hotkeys | undefined): string {
363
- return listed(Object.values(hotkeys ?? {}).flatMap(({ title, default: combo }) => (combo === undefined ? [] : [`${combo} to ${title}`])))
364
- }
365
-
366
331
  function readCommand(steps: Record<string, unknown>, key: 'install' | 'uninstall'): Steps {
367
332
  const command = steps[key]
368
333
  if (command === undefined) return {}
369
334
  if (typeof command !== 'string' || command.trim() === '') throw new Error(`package.json "cmod.${key}" must be a command, such as "./setup/${key}.sh".`)
370
335
  if (/[\n\t]/.test(command)) throw new Error(`package.json "cmod.${key}" holds a line break or a tab. Write one command, such as "./setup/${key}.sh".`)
371
336
  const atRoot = scriptPaths(command).find((path) => folderOf(path) === '.')
372
- if (atRoot !== undefined) throw new Error(`package.json "cmod.${key}" names ${atRoot}, a script at the plugin root. Move it into a folder, such as ./setup/${key}.sh: cmod asks consent for the whole folder of each script.`)
337
+ if (atRoot !== undefined) throw new Error(`package.json "cmod.${key}" names ${atRoot}, a script at the plugin root. Move it into a folder, such as ./setup/${key}.sh: cmod runs the steps again whenever anything in a script's folder changes.`)
373
338
  return { [key]: command }
374
339
  }
375
340
 
376
- export function bundleDefines(permissions: readonly string[]): Record<string, string> {
377
- return permissions.includes('approve') ? {} : { 'globalThis.cmodWithoutApprove': 'true' }
341
+ export function bundleDefines(steps: Steps): Record<string, string> {
342
+ return steps.approve === true ? {} : { 'globalThis.cmodWithoutApprove': 'true' }
378
343
  }
379
344
 
380
345
  export function scriptPaths(command: string): string[] {
@@ -398,7 +363,7 @@ export async function scriptsSha256(steps: Steps, files: { read: ReadFile; list:
398
363
  for (const path of scriptPaths(command)) {
399
364
  if ((await files.read(path)) !== undefined) scriptFolders.push(folderOf(path))
400
365
  }
401
- if (scriptFolders.length === 0) throw new Error(`package.json "cmod.${key}" runs "${command}", which names no script file in the mod, so consent cannot cover what it runs. Put the commands in a script, such as ./setup/${key}.sh.`)
366
+ if (scriptFolders.length === 0) throw new Error(`package.json "cmod.${key}" runs "${command}", which names no script file in the mod, so cmod cannot tell when what it runs changes. Put the commands in a script, such as ./setup/${key}.sh.`)
402
367
  for (const folder of scriptFolders) folders.add(folder)
403
368
  }
404
369
  let text = [
@@ -412,7 +377,7 @@ export async function scriptsSha256(steps: Steps, files: { read: ReadFile; list:
412
377
  for (const name of (await files.list(folder)).sort()) {
413
378
  const path = `${folder}/${name}`
414
379
  const content = await files.read(path)
415
- if (content === undefined) throw new Error(`${path} links to a folder or to nothing, so consent cannot cover it. Point the link at a file, or delete it.`)
380
+ if (content === undefined) throw new Error(`${path} links to a folder or to nothing, so cmod cannot tell when it changes. Point the link at a file, or delete it.`)
416
381
  text += `\0${path}\0${content}`
417
382
  }
418
383
  }
@@ -1,4 +1,4 @@
1
- import { isObject, permissionWords } from '../records.js'
1
+ import { isObject } from '../records.js'
2
2
  import { ifMissing } from '../utils/paths.js'
3
3
  import { listed } from '../utils/text.js'
4
4
  import type { Claude } from './claude.js'
@@ -8,7 +8,7 @@ export type Announcement = { readonly message: string; readonly description?: st
8
8
 
9
9
  export const announcementMs = 10_000
10
10
 
11
- export async function announcementOf(claude: Claude, plugin: Plugin, granted: ReadonlySet<string>, added: readonly string[], openSettings: () => Promise<void>): Promise<Announcement> {
11
+ export async function announcementOf(claude: Claude, plugin: Plugin, added: readonly string[], openSettings: () => Promise<void>): Promise<Announcement> {
12
12
  const manifest = jsonOf(await claude.fs.read(`${plugin.root}/.claude-plugin/plugin.json`).catch(ifMissing(undefined)))
13
13
  const { program, hotkeys } = plugin.steps
14
14
  const rules = (await claude.fs.list(`${plugin.root}/rules`).catch(ifMissing([]))).filter((entry) => entry.kind === 'file' && entry.name.endsWith('.md')).map((entry) => entry.name.slice(0, -'.md'.length)).toSorted()
@@ -18,7 +18,6 @@ export async function announcementOf(claude: Claude, plugin: Plugin, granted: Re
18
18
  rules.length > 0 ? `Adds ${rules.length} ${rules.length === 1 ? 'rule' : 'rules'}: ${listed(rules)}.` : undefined,
19
19
  program === undefined ? undefined : `Installed the ${program} program.`,
20
20
  ...Object.values(hotkeys ?? {}).flatMap(({ title, default: combo }) => (combo === undefined ? [] : [`Binds ${combo} to ${title}.`])),
21
- ...[...granted].map((item) => `${permissionWords(item)}.`),
22
21
  ].filter((line) => line !== undefined)
23
22
  return { message: 'Installed', ...(lines.length === 0 ? {} : { description: lines.join('\n') }), action: { label: 'Settings', onClick: () => openSettings() } }
24
23
  }