@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
package/src/runtime/ui.ts CHANGED
@@ -91,6 +91,27 @@ function pieceProps(props: object, given: object, isFirst: boolean): object {
91
91
  return isFirst || !('isFirstOfReply' in merged) ? merged : { ...merged, isFirstOfReply: false }
92
92
  }
93
93
 
94
+ function laterKeys(key: string | undefined): () => string | undefined {
95
+ let used = 0
96
+ return () => (key === undefined ? undefined : `${key}:${(used += 1)}`)
97
+ }
98
+
99
+ export function inheriting(props: MarkdownProps, draw: (drawn: MarkdownProps) => RenderElement, laterKey = laterKeys(props.key)): (left: MarkdownProps) => RenderElement {
100
+ const { dimColor, onLinkPress, pressableLinks } = props
101
+ const inherited = { ...(dimColor === undefined ? {} : { dimColor }), ...(onLinkPress === undefined ? {} : { onLinkPress }), ...(pressableLinks === undefined ? {} : { pressableLinks }) }
102
+ let isKeyTaken = false
103
+ const keyOf = (left: MarkdownProps) => {
104
+ if (left.key !== undefined) return left.key
105
+ if (isKeyTaken) return laterKey()
106
+ isKeyTaken = true
107
+ return props.key
108
+ }
109
+ return (left) => {
110
+ const key = keyOf(left)
111
+ return draw({ ...inherited, ...(key === undefined ? {} : { key }), ...left })
112
+ }
113
+ }
114
+
94
115
  function threw(error: unknown): string {
95
116
  return `threw, so Claude Code draws its own: ${messageOf(error)}`
96
117
  }
@@ -324,27 +345,28 @@ export function createUi<State extends object>({ name, claude, router, report, a
324
345
 
325
346
  const renderOf = (type: string) => markdownRenders.get(type)
326
347
 
327
- const drawnBlock = (piece: MarkdownPiece<MarkdownRender>, at: StyledAt, drawClaudes: (text: string) => RenderElement, keyPrefix: string, table?: ElementTable): RenderElement => {
328
- if ('text' in piece) return drawClaudes(piece.text)
348
+ const drawnBlock = (piece: MarkdownPiece<MarkdownRender>, at: StyledAt, drawClaudes: (part: MarkdownProps) => RenderElement, keyPrefix: string, table?: ElementTable): RenderElement => {
349
+ if ('text' in piece) return drawClaudes({ text: piece.text })
329
350
  const { render, props: block } = piece
330
- const draw = () => drawKeyed(keyPrefix, () => render.Component({ ...block, ...at, Default: ({ source = block.source }: { readonly source?: string }) => drawClaudes(source) }))
351
+ const draw = () => drawKeyed(keyPrefix, () => render.Component({ ...block, ...at, Default: ({ source = block.source }: { readonly source?: string }) => drawClaudes({ text: source }) }))
331
352
  try {
332
- return table === undefined ? draw() : drawWith(table, draw)
353
+ return table === undefined ? draw() : drawWith(table, draw, drawClaudes)
333
354
  } catch (error) {
334
355
  render.log(threw(error))
335
- return drawClaudes(block.source)
356
+ return drawClaudes({ text: block.source })
336
357
  }
337
358
  }
338
359
 
339
360
  const othersFrom =
340
361
  (table: ElementTable, at: StyledAt, from: number, unkeyedScope: () => string) =>
341
- (props: MarkdownProps): RenderElement => {
362
+ (props: MarkdownProps, laterKey = laterKeys(props.key)): RenderElement => {
342
363
  if (from >= stylers.length) return table.Markdown(props)
343
364
  const scope = props.key ?? unkeyedScope()
344
365
  for (const [index, styler] of stylers.entries()) {
345
366
  if (index < from) continue
346
367
  const cached = `${stylersSeen}\u0000${at.surface}\u0000${at.columns}\u0000${props.text}`
347
- const drawn = drawWith(table, () => borrowed(styler, cached, { markdown: props.text, ...at }, scope), othersFrom(table, at, index + 1, unkeyedScope))
368
+ const next = othersFrom(table, at, index + 1, unkeyedScope)
369
+ const drawn = drawWith(table, () => borrowed(styler, cached, { markdown: props.text, ...at }, scope), inheriting(props, (part) => next(part, laterKey), laterKey))
348
370
  if (drawn !== undefined) return drawn
349
371
  }
350
372
  return table.Markdown(props)
@@ -360,11 +382,8 @@ export function createUi<State extends object>({ name, claude, router, report, a
360
382
  const pieces = reader(props.text, renderOf)
361
383
  if (pieces.every((piece) => 'text' in piece)) return others(props)
362
384
  const scope = props.key ?? unkeyedScope()
363
- let drawn = 0
364
- const drawClaudes = (text: string) => {
365
- const index = drawn++
366
- return others(index === 0 || props.key === undefined ? { ...props, text } : { ...props, text, key: `${props.key}:${index}` })
367
- }
385
+ const laterKey = laterKeys(props.key)
386
+ const drawClaudes = inheriting(props, (part) => others(part, laterKey), laterKey)
368
387
  const drawings = pieces.map((piece, index) => drawnBlock(piece, at, drawClaudes, `${scope}:${index}:`, table))
369
388
  return drawPieces(drawings.map((drawing) => ({ drawing, isClaudesRow: false })), 'pane')
370
389
  }
@@ -373,7 +392,7 @@ export function createUi<State extends object>({ name, claude, router, report, a
373
392
  const markdownDrawing = (text: string, at: StyledAt): RenderElement => {
374
393
  const pieces = read === undefined ? [] : read(text, renderOf)
375
394
  if (pieces.every((piece) => 'text' in piece)) return Markdown({ text })
376
- return drawPieces(pieces.map((piece, index) => ({ drawing: drawnBlock(piece, at, (source) => Markdown({ text: source }), `${index}:`), isClaudesRow: false })), 'pane')
395
+ return drawPieces(pieces.map((piece, index) => ({ drawing: drawnBlock(piece, at, Markdown, `${index}:`), isClaudesRow: false })), 'pane')
377
396
  }
378
397
 
379
398
  const routeMarkdown = (createReader: () => MarkdownReader) => {
package/src/testing.ts CHANGED
@@ -56,7 +56,7 @@ import { drawnParts } from './runtime/parts.js'
56
56
  import { serveWidgets, type Widgets } from './runtime/widgets.js'
57
57
  import { engineOf } from './runtime/engine.js'
58
58
  import { pagesOf, servePages } from './runtime/pages.js'
59
- import { partMethods, type DrawnPart, type PageRequest, type PartPress, type PartsUpdate } from './runtime/ui.js'
59
+ import { inheriting, partMethods, type DrawnPart, type PageRequest, type PartPress, type PartsUpdate } from './runtime/ui.js'
60
60
 
61
61
  export type { Fakes, TestCall } from './testing/fake-claude.js'
62
62
  export type { FakeSession, MessageDraft, StartedTask } from './testing/fake-sessions.js'
@@ -77,7 +77,6 @@ export type Shown = ShownByClaude & { readonly toasts: readonly ShownToast[]; re
77
77
  export type TestOptions<State extends object, Declared extends Options = Options> = {
78
78
  readonly state?: { readonly [Lifetime in keyof State]?: Partial<State[Lifetime]> }
79
79
  readonly options?: Partial<OptionValues<Declared>>
80
- readonly permissions?: readonly string[]
81
80
  readonly scope?: 'user' | 'project'
82
81
  readonly projectRoot?: string
83
82
  readonly cwd?: string
@@ -236,7 +235,7 @@ export function testMod<State extends object, Declared extends Options = Options
236
235
  if (drawn === undefined) missedMarkdown.set(drawnAt, { markdown: props.text, ...at })
237
236
  if (drawn === undefined || drawn === null || drawn.tree === null) return table.Markdown(props)
238
237
  const { draw, tree } = drawn
239
- return drawWith(table, () => elementOf(tree, keyPrefix, (handler, args) => void pressPart({ draw, handler, args }))) as RenderElement
238
+ return drawWith(table, () => elementOf(tree, keyPrefix, (handler, args) => void pressPart({ draw, handler, args })), inheriting(props, table.Markdown)) as RenderElement
240
239
  }
241
240
  }
242
241
  const withOwnMarkdown = async <Drawn>(draw: () => Promise<Drawn>): Promise<Drawn> => {
@@ -302,19 +301,15 @@ export function testMod<State extends object, Declared extends Options = Options
302
301
  let isColorTold = false
303
302
 
304
303
  const start = async () => {
305
- started ??= lifecycle.start(fake.claude, async (claude) => {
306
- const steps = await modSteps()
307
- return {
308
- name,
309
- root,
310
- version: '0.0.0',
311
- store: storeFolder({ HOME: await claude.env.home(), XDG_DATA_HOME: await claude.env.dataHome() }),
312
- isInstalled: true,
313
- shouldRecord: false,
314
- steps,
315
- granted: options.permissions ?? steps.permissions ?? [],
316
- }
317
- })
304
+ started ??= lifecycle.start(fake.claude, async (claude) => ({
305
+ name,
306
+ root,
307
+ version: '0.0.0',
308
+ store: storeFolder({ HOME: await claude.env.home(), XDG_DATA_HOME: await claude.env.dataHome() }),
309
+ isInstalled: true,
310
+ shouldRecord: false,
311
+ steps: await modSteps(),
312
+ }))
318
313
  await started
319
314
  await fake.settle()
320
315
  const { failure } = lifecycle
package/testing.d.ts CHANGED
@@ -35,7 +35,6 @@ export type TestOptions<State extends object, Declared extends Options = Options
35
35
  readonly [Lifetime in keyof State]?: Partial<State[Lifetime]>;
36
36
  };
37
37
  readonly options?: Partial<OptionValues<Declared>>;
38
- readonly permissions?: readonly string[];
39
38
  readonly scope?: 'user' | 'project';
40
39
  readonly projectRoot?: string;
41
40
  readonly cwd?: string;
package/testing.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["src/testing.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,IAAI,EAEJ,gBAAgB,EAIhB,WAAW,EAUX,eAAe,EAGhB,MAAM,aAAa,CAAA;AACpB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAA;AAC3D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAC7C,OAAO,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAazD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AACtD,OAAO,EAAE,OAAO,EAAE,MAAM,2CAA2C,CAAA;AAKnE,OAAO,EAAW,KAAK,IAAI,EAAE,MAAM,gCAAgC,CAAA;AACnE,OAAO,EAA+B,aAAa,EAAE,KAAK,QAAQ,EAAoB,KAAK,UAAU,EAAE,KAAK,UAAU,EAAE,KAAK,gBAAgB,EAAE,KAAK,SAAS,EAAE,KAAK,aAAa,EAAE,KAAK,YAAY,EAAE,KAAK,WAAW,EAAE,KAAK,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAGzQ,OAAO,EAA4B,KAAK,KAAK,EAAE,KAAK,KAAK,IAAI,aAAa,EAA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K,EAAE,QAAQ,CAAM,GAAG,SAAS,CAAC,KAAK,CAAC,CAgiBlM"}
package/testing.js CHANGED
@@ -28,7 +28,7 @@ import { drawnParts } from './runtime/parts.js';
28
28
  import { serveWidgets } from './runtime/widgets.js';
29
29
  import { engineOf } from './runtime/engine.js';
30
30
  import { pagesOf, servePages } from './runtime/pages.js';
31
- import { partMethods } from './runtime/ui.js';
31
+ import { inheriting, partMethods } from './runtime/ui.js';
32
32
  const defaultColumns = 80;
33
33
  const defaultRows = 24;
34
34
  const presentation = { isFullscreen: false, columns: defaultColumns };
@@ -136,7 +136,7 @@ export function testMod(definition, options = {}) {
136
136
  if (drawn === undefined || drawn === null || drawn.tree === null)
137
137
  return table.Markdown(props);
138
138
  const { draw, tree } = drawn;
139
- return drawWith(table, () => elementOf(tree, keyPrefix, (handler, args) => void pressPart({ draw, handler, args })));
139
+ return drawWith(table, () => elementOf(tree, keyPrefix, (handler, args) => void pressPart({ draw, handler, args })), inheriting(props, table.Markdown));
140
140
  };
141
141
  };
142
142
  const withOwnMarkdown = async (draw) => {
@@ -207,19 +207,15 @@ export function testMod(definition, options = {}) {
207
207
  let started;
208
208
  let isColorTold = false;
209
209
  const start = async () => {
210
- started ??= lifecycle.start(fake.claude, async (claude) => {
211
- const steps = await modSteps();
212
- return {
213
- name,
214
- root,
215
- version: '0.0.0',
216
- store: storeFolder({ HOME: await claude.env.home(), XDG_DATA_HOME: await claude.env.dataHome() }),
217
- isInstalled: true,
218
- shouldRecord: false,
219
- steps,
220
- granted: options.permissions ?? steps.permissions ?? [],
221
- };
222
- });
210
+ started ??= lifecycle.start(fake.claude, async (claude) => ({
211
+ name,
212
+ root,
213
+ version: '0.0.0',
214
+ store: storeFolder({ HOME: await claude.env.home(), XDG_DATA_HOME: await claude.env.dataHome() }),
215
+ isInstalled: true,
216
+ shouldRecord: false,
217
+ steps: await modSteps(),
218
+ }));
223
219
  await started;
224
220
  await fake.settle();
225
221
  const { failure } = lifecycle;
@@ -1,97 +0,0 @@
1
- # Permissions
2
-
3
- A mod declares what it does beyond drawing and listening: the hosts it connects to, the programs it runs, the files it changes outside its project, and whether it reads the conversation, adds text Claude reads, asks a model, starts tasks, uses Claude's tools, changes Claude Code's settings, or approves tool calls. The person sees each permission as one sentence when they install the mod, turns each one on or off in Settings, and cmod checks every call and every answer against what they granted.
4
-
5
- Permissions bind every mod built on `@cmodjs/core`, and the plugin directory reads them from `package.json`. They are a contract, not a sandbox: a Claude Code plugin can skip cmod and call Claude Code directly.
6
-
7
- ## Declare the permissions
8
-
9
- They sit in the `package.json` `cmod` key, beside `install` and `keys`, because the person reads them before any of the mod's code runs:
10
-
11
- ```json
12
- "cmod": {
13
- "permissions": { "network": ["api.github.com"], "run": ["gh"], "prompt": true, "model": true }
14
- }
15
- ```
16
-
17
- | Permission | The person reads | cmod checks |
18
- | --- | --- | --- |
19
- | `"network": ["api.github.com"]` | Connect to api.github.com | `http.fetch` to that host. A path starting with `/` or `~/` names a socket, such as `"~/.docker/run/docker.sock"`. The address of the mod's own running `program` job needs none |
20
- | `"run": ["gh"]`, or `"run": "*"` | Run gh on your computer | `process.run`, `process.spawn`, and the `program` and `check` jobs. A program matches by its file name, so `"mermaid-ascii"` covers `${mod.dataFolder}/bin/mermaid-ascii` and the copy in cmod's programs folder |
21
- | `"files": ["~/.zshrc"]` | Change ~/.zshrc | `fs.write` and `metadata.update` outside the project and the mod's data folder. A folder covers every file below it |
22
- | `"conversation": true` | Read your other Claude Code conversations | Every session but the one the mod runs in: its messages, turns, contexts, goals, tasks, and events, `sessions.list`, `sessions.search`, the `on` methods of `sessions`, and a `before` method on another session. Also reading Claude Code's transcript files. Hearing and reading the mod's own session needs no permission |
23
- | `"prompt": true` | Add text Claude reads and start turns | A session's `send`, `commands.run`, a `Turn`'s `abort`, the mod's `rules/`, the `prompt` and `schedule` jobs, and the `before` answers listed below |
24
- | `"model": true` | Ask a model, which uses your plan | `model.complete` |
25
- | `"tasks": true` | Start tasks that work beside Claude | A session's `startTask`, and a `beforeTaskStart` answer |
26
- | `"tools": true` | Use and change Claude's tool calls | A session's `callTool`, and the `before` answers listed below |
27
- | `"config": ["env.ANTHROPIC_BASE_URL"]` | Change env.ANTHROPIC_BASE_URL in your Claude Code settings | Each value `settings.user.update`, `settings.project.update`, and `settings.local.update` change. A key path covers its own value and every key below it, so `"env"` covers every key in `env`, and `await settings.user.update({ env: { ANTHROPIC_BASE_URL: 'http://127.0.0.1:8317' } })` needs `"env.ANTHROPIC_BASE_URL"` or `"env"`. `mcpServers` covers the project's `.mcp.json` |
28
- | `"approve": true` | Approve Claude's tool calls for you | an allow or an ask from the mod's permission rules or listeners, and a `retry`. A refusal needs no permission |
29
-
30
- Reading files, drawing panes and renders, toasts, slash commands, tools of the mod's own, listeners on the mod's own session, and a `refuse` answer need no permission. Writing a Claude Code settings file with `fs.write` is refused with every permission, and names the `settings` call to use instead ([mod.md](mod.md#settings-claude-code-s-settings-files)).
31
-
32
- `cmod check` adds `"approve": true` to `package.json` when the mod allows or asks, with a `beforePermissionCheck` or `beforePermissionRequest` answer or an `ask` rule of the `permissions` job, and the line is missing, and says so. A mod that only refuses, or only listens with `onPermissionCheck` or `onPermissionRequest`, needs no `approve`.
33
-
34
- Anthropic's plugin directory does not list a mod that can approve Claude's tool calls. So `cmod publish` leaves the code that allows and asks out of the bundle of a mod that does not declare `"approve": true`, and that mod can be listed. A mod that declares it installs through cmod and the [Mods page](https://claudemodmanager.com/mods), and `cmod check` says the directory does not list it.
35
-
36
- ## What the person sees
37
-
38
- The install opens the mod's install page in the Sidebar of Claude Code and lists every permission in `permissions`, with the install step, the program, and the hotkeys. An update grants a permission it adds without asking, and the `<mod> updated to <version>` toast names it. With `Ask before an update adds a permission` on, in Settings on cmod's page under Preferences, the update asks instead, and lists only the new permissions ([install-steps.md](install-steps.md#consent)). A permission the person turned off stays off across updates. Removing the mod revokes everything it was granted.
39
-
40
- Settings lists the same permissions as toggles, under the mod, Permissions. A toggle runs `cmod permission <mod> <name> [value] on|off`, and the mod sees the change before its next call, with no reload.
41
-
42
- `cmod check` prints the sentences, so you read what the person will see:
43
-
44
- ```text
45
- ✔ At install the person grants: Connect to api.github.com; Run gh on your computer; Ask a model, which uses your plan
46
- ```
47
-
48
- ## Check a permission before a feature uses it
49
-
50
- ```ts
51
- type Permissions = {
52
- readonly conversation: boolean
53
- readonly prompt: boolean
54
- readonly model: boolean
55
- readonly tasks: boolean
56
- readonly tools: boolean
57
- readonly approve: boolean
58
- readonly network: { allows(host: string): boolean }
59
- readonly run: { allows(program: string): boolean }
60
- readonly files: { allows(path: string): boolean }
61
- readonly config: { allows(keyPath: string): boolean }
62
- }
63
- ```
64
-
65
- `mod.permissions` says whether the person has each permission turned on, so a mod hides a feature instead of failing it. A flag is `true` while it is granted, and `allows` answers for one host, program, path, or settings key path, such as `env.ANTHROPIC_BASE_URL`:
66
-
67
- ```ts
68
- if (mod.permissions.model) {
69
- const verdict = await model.complete({ model: 'haiku', prompt: 'Is this reply a waste of time?' })
70
- }
71
- if (mod.permissions.run.allows('gh')) mod.every(60_000, refreshRuns)
72
- ```
73
-
74
- ## When a call has no grant
75
-
76
- The call rejects, and the error names the fix:
77
-
78
- - An undeclared call names the line to add: `ci-watch calls http.fetch(https://api.github.com/repos), which needs "permissions": { "network": ["api.github.com"] } in package.json "cmod".`
79
- - A declared call the person turned off names where to turn it on: `ci-watch calls model.complete without your grant to "Ask a model, which uses your plan". Turn it on in Settings.` The person chose this, so the failure goes to the Log in Settings and to Claude Code's debug log, with no toast, unless the cmod running it is older than 4.3.0 ([ui.md](ui.md#toasts)).
80
- - A `program` job without its grant stops at once with the same line, with no restarts.
81
-
82
- ## When a before answer has no grant
83
-
84
- cmod checks the answer each `before` listener returns, part by part. A part without its grant changes nothing, and cmod reports the failure `The <method> listener failed`, or once which part it dropped and the permission to turn on, where errors go ([ui.md](ui.md#toasts)).
85
-
86
- | Answer part | Permission |
87
- | --- | --- |
88
- | `text`, `note`, `title`, and `firstPrompt`, a `prompt` job's text, a `beforeToolResult` answer, a `beforeTurnEnd` refusal, which keeps Claude going, and every `commands.beforeRun` answer but a refusal | `prompt` |
89
- | a `beforeToolCall` answer | `tools` |
90
- | a `beforeTaskStart` answer | `tasks` |
91
- | an `allow`, with the `input` and `updates` a `beforePermissionRequest` allow carries, an `ask`, and `retry` | `approve` |
92
-
93
- Any other `refuse` needs no permission. A tool of the mod's own, `mcp__<mod>__*`, answers freely.
94
-
95
- ## Test permissions
96
-
97
- `testMod` grants what the mod's `package.json` declares, so tests run as an installed mod does. An undeclared call fails the test with the line to add. `testMod(mod, { permissions: ['network:api.github.com'] })` grants exactly the list instead, so a test checks what happens with a permission turned off ([testing.md](testing.md)).
@@ -1,34 +0,0 @@
1
- import type { Claude } from './claude.js';
2
- import type { RoutedEvent } from './hooks.js';
3
- export type Grants = {
4
- readonly name: string;
5
- readonly declared: readonly string[];
6
- readonly granted: () => ReadonlySet<string>;
7
- readonly refresh: () => Promise<void>;
8
- readonly home: string | undefined;
9
- readonly configRoot: string | undefined;
10
- readonly projectRoot: () => string;
11
- readonly freeFolders: () => readonly string[];
12
- readonly freeAddresses: () => ReadonlySet<string>;
13
- };
14
- export declare class PermissionRefused extends Error {
15
- }
16
- export declare function programAddresses(mod: object): Set<string>;
17
- export declare const conversationCalls: Readonly<Record<string, string>>;
18
- export declare function checkGrant(grants: Grants, call: string, item: string | undefined): Promise<void>;
19
- export declare function checkRun(grants: Grants, call: 'process.run' | 'process.spawn', argv: readonly string[]): Promise<void>;
20
- export declare function checkWrite(grants: Grants, call: string, path: string): Promise<void>;
21
- export declare function checkSettings(grants: Grants, source: 'user' | 'project' | 'local', values: Readonly<Record<string, unknown>>): Promise<void>;
22
- export declare function checkingGrants(claude: Claude, grants: Grants): Claude;
23
- export declare function itemOf(name: string, value?: string): string;
24
- export declare function isCovered(granted: ReadonlySet<string>, item: string, home: string | undefined): boolean;
25
- export declare function refusal(grants: Pick<Grants, 'name' | 'declared' | 'home'>, call: string, item: string): string;
26
- export type AnswerCheck = {
27
- readonly plugin: string;
28
- isGranted(item: string): boolean;
29
- dropped(item: string, part: string): void;
30
- };
31
- export declare function checksAnswers(event: RoutedEvent): boolean;
32
- export declare function passedDown(event: RoutedEvent, original: unknown, passed: unknown, check: AnswerCheck): unknown;
33
- export declare function checkedAnswer(event: RoutedEvent, e: unknown, answer: unknown, below: () => Promise<unknown>, check: AnswerCheck): Promise<unknown>;
34
- //# sourceMappingURL=grants.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"grants.d.ts","sourceRoot":"","sources":["../src/runtime/grants.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEzC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAG7C,MAAM,MAAM,MAAM,GAAG;IACnB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAA;IACpC,QAAQ,CAAC,OAAO,EAAE,MAAM,WAAW,CAAC,MAAM,CAAC,CAAA;IAC3C,QAAQ,CAAC,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;IACrC,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,CAAA;IACjC,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,SAAS,CAAA;IACvC,QAAQ,CAAC,WAAW,EAAE,MAAM,MAAM,CAAA;IAClC,QAAQ,CAAC,WAAW,EAAE,MAAM,SAAS,MAAM,EAAE,CAAA;IAC7C,QAAQ,CAAC,aAAa,EAAE,MAAM,WAAW,CAAC,MAAM,CAAC,CAAA;CAClD,CAAA;AAED,qBAAa,iBAAkB,SAAQ,KAAK;CAAG;AAI/C,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,CAIzD;AAID,eAAO,MAAM,iBAAiB,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,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