@cmodjs/core 4.3.4 → 5.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/docs/commands.md +19 -30
- package/docs/dependencies.md +7 -5
- package/docs/index.md +4 -5
- package/docs/install-steps.md +12 -14
- package/docs/jobs.md +3 -11
- package/docs/mod.md +18 -21
- package/docs/session.md +11 -11
- package/docs/state.md +1 -1
- package/docs/testing.md +3 -5
- package/docs/ui.md +3 -3
- package/jobs/program.d.ts.map +1 -1
- package/jobs/program.js +3 -17
- package/mod.d.ts +0 -16
- package/mod.d.ts.map +1 -1
- package/package.json +2 -2
- package/records.d.ts +4 -11
- package/records.d.ts.map +1 -1
- package/records.js +17 -48
- package/runtime/announce.d.ts +1 -1
- package/runtime/announce.d.ts.map +1 -1
- package/runtime/announce.js +2 -3
- package/runtime/conversations.d.ts.map +1 -1
- package/runtime/conversations.js +3 -46
- package/runtime/engine.d.ts +2 -2
- package/runtime/engine.d.ts.map +1 -1
- package/runtime/installer.d.ts +0 -9
- package/runtime/installer.d.ts.map +1 -1
- package/runtime/installer.js +1 -15
- package/runtime/lifecycle.d.ts +1 -2
- package/runtime/lifecycle.d.ts.map +1 -1
- package/runtime/lifecycle.js +37 -191
- package/runtime/metadata.d.ts +1 -2
- package/runtime/metadata.d.ts.map +1 -1
- package/runtime/metadata.js +1 -2
- package/runtime/sessions.d.ts +3 -7
- package/runtime/sessions.d.ts.map +1 -1
- package/runtime/sessions.js +10 -34
- package/runtime/toaster.d.ts.map +1 -1
- package/runtime/toaster.js +6 -9
- package/src/jobs/program.ts +3 -17
- package/src/mod.ts +0 -18
- package/src/records.ts +20 -55
- package/src/runtime/announce.ts +2 -3
- package/src/runtime/conversations.ts +3 -45
- package/src/runtime/engine.ts +2 -2
- package/src/runtime/installer.ts +1 -37
- package/src/runtime/lifecycle.ts +38 -188
- package/src/runtime/metadata.ts +0 -3
- package/src/runtime/sessions.ts +10 -39
- package/src/runtime/toaster.ts +6 -9
- package/src/testing.ts +9 -14
- package/testing.d.ts +0 -1
- package/testing.d.ts.map +1 -1
- package/testing.js +9 -13
- package/docs/permissions.md +0 -97
- package/runtime/grants.d.ts +0 -34
- package/runtime/grants.d.ts.map +0 -1
- package/runtime/grants.js +0 -326
- package/src/runtime/grants.ts +0 -348
package/src/testing.ts
CHANGED
|
@@ -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
|
|
@@ -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
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
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,EAAE,KAAK,QAAQ,EAAE,MAAM,0BAA0B,CAAA;AAG3H,OAAO,EAAgB,KAAK,WAAW,EAAE,KAAK,YAAY,EAAE,KAAK,YAAY,EAAE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K,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAC7C,MAAM,CAAC,WAAW,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IACxD,QAAQ,CAAC,GAAG,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,EAAE,OAAO,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAA;IAC7E,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAA;IAC/B,QAAQ,CAAC,KAAK,EAAE,SAAS,QAAQ,EAAE,CAAA;IACnC,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAA;IACrB,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAA;CACtB,CAAA;AAqBD,wBAAgB,OAAO,CAAC,KAAK,SAAS,MAAM,EAAE,QAAQ,SAAS,OAAO,GAAG,OAAO,EAAE,UAAU,EAAE,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,OAAO,GAAE,WAAW,CAAC,KAAK,EAAE,QAAQ,CAAM,GAAG,SAAS,CAAC,KAAK,CAAC,CAgiBlM"}
|
package/testing.js
CHANGED
|
@@ -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
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
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;
|
package/docs/permissions.md
DELETED
|
@@ -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)).
|
package/runtime/grants.d.ts
DELETED
|
@@ -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
|
package/runtime/grants.d.ts.map
DELETED
|
@@ -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,qBAA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,UAAU,GAAG,MAAM,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAI9G;AA0BD,MAAM,MAAM,WAAW,GAAG;IACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAA;IAChC,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAAA;CAC1C,CAAA;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAEzD;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,WAAW,GAAG,OAAO,CAa9G;AAED,wBAAsB,aAAa,CAAC,KAAK,EAAE,WAAW,EAAE,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC,CA+BxJ"}
|
package/runtime/grants.js
DELETED
|
@@ -1,326 +0,0 @@
|
|
|
1
|
-
import { grantFix, isObject, isSettingCovered, permissionWords, settingPaths } from '../records.js';
|
|
2
|
-
import { relativePath } from '../utils/paths.js';
|
|
3
|
-
import { cmodPluginName } from './dependencies.js';
|
|
4
|
-
import { actPermission, conversationMethods, isAct, toolPermission } from './sessions.js';
|
|
5
|
-
export class PermissionRefused extends Error {
|
|
6
|
-
}
|
|
7
|
-
const addressesOfPrograms = new WeakMap();
|
|
8
|
-
export function programAddresses(mod) {
|
|
9
|
-
const known = addressesOfPrograms.get(mod) ?? new Set();
|
|
10
|
-
addressesOfPrograms.set(mod, known);
|
|
11
|
-
return known;
|
|
12
|
-
}
|
|
13
|
-
const projectSettingsFiles = ['.claude/settings.json', '.claude/settings.local.json', '.mcp.json'];
|
|
14
|
-
export const conversationCalls = {
|
|
15
|
-
[conversationMethods.sessions]: 'sessions.list',
|
|
16
|
-
[conversationMethods.search]: 'sessions.search',
|
|
17
|
-
[conversationMethods.messages]: 'messages',
|
|
18
|
-
[conversationMethods.turns]: 'turns',
|
|
19
|
-
[conversationMethods.contexts]: 'contexts',
|
|
20
|
-
[conversationMethods.tasks]: 'tasks',
|
|
21
|
-
[conversationMethods.goal]: 'goal',
|
|
22
|
-
[conversationMethods.updateGoal]: 'goal.update',
|
|
23
|
-
[conversationMethods.subscribe]: 'on',
|
|
24
|
-
[conversationMethods.watchBefore]: 'before',
|
|
25
|
-
[conversationMethods.act]: 'act',
|
|
26
|
-
};
|
|
27
|
-
export async function checkGrant(grants, call, item) {
|
|
28
|
-
if (item === undefined)
|
|
29
|
-
return;
|
|
30
|
-
await grants.refresh();
|
|
31
|
-
if (!isCovered(grants.granted(), item, grants.home))
|
|
32
|
-
throw new PermissionRefused(refusal(grants, call, item));
|
|
33
|
-
}
|
|
34
|
-
export async function checkRun(grants, call, argv) {
|
|
35
|
-
await checkGrant(grants, `${call}(${argv.join(' ')})`, `run:${programOf(argv)}`);
|
|
36
|
-
}
|
|
37
|
-
export async function checkWrite(grants, call, path) {
|
|
38
|
-
await checkGrant(grants, call, writeItem(grants, path));
|
|
39
|
-
}
|
|
40
|
-
export async function checkSettings(grants, source, values) {
|
|
41
|
-
for (const path of settingPaths(values).map((each) => each.join('.')))
|
|
42
|
-
await checkGrant(grants, `settings.${source}.update(${path})`, `config:${path}`);
|
|
43
|
-
}
|
|
44
|
-
export function checkingGrants(claude, grants) {
|
|
45
|
-
const gate = (call, item) => checkGrant(grants, call, item);
|
|
46
|
-
return {
|
|
47
|
-
...claude,
|
|
48
|
-
process: {
|
|
49
|
-
async run(argv, init) {
|
|
50
|
-
await checkRun(grants, 'process.run', argv);
|
|
51
|
-
return claude.process.run(argv, init);
|
|
52
|
-
},
|
|
53
|
-
spawn(request) {
|
|
54
|
-
const started = checkRun(grants, 'process.spawn', request.argv).then(() => claude.process.spawn(request));
|
|
55
|
-
return spawned(started);
|
|
56
|
-
},
|
|
57
|
-
},
|
|
58
|
-
fs: {
|
|
59
|
-
...claude.fs,
|
|
60
|
-
async read(path) {
|
|
61
|
-
await gate(`fs.read(${path})`, readItem(grants, path));
|
|
62
|
-
return claude.fs.read(path);
|
|
63
|
-
},
|
|
64
|
-
async write(path, text) {
|
|
65
|
-
await gate(`fs.write(${path})`, writeItem(grants, path));
|
|
66
|
-
return claude.fs.write(path, text);
|
|
67
|
-
},
|
|
68
|
-
},
|
|
69
|
-
http: {
|
|
70
|
-
async fetch(url, init) {
|
|
71
|
-
if (!grants.freeAddresses().has(init?.socketPath ?? addressOf(url)))
|
|
72
|
-
await gate(`http.fetch(${url})`, `network:${init?.socketPath ?? hostOf(url)}`);
|
|
73
|
-
return claude.http.fetch(url, init);
|
|
74
|
-
},
|
|
75
|
-
},
|
|
76
|
-
session: {
|
|
77
|
-
...claude.session,
|
|
78
|
-
append: async (args) => {
|
|
79
|
-
await gate('send', 'prompt');
|
|
80
|
-
return claude.session.append(args);
|
|
81
|
-
},
|
|
82
|
-
send: async (args) => {
|
|
83
|
-
await gate('send', 'prompt');
|
|
84
|
-
return claude.session.send(args);
|
|
85
|
-
},
|
|
86
|
-
},
|
|
87
|
-
prompt: {
|
|
88
|
-
submit: async (args) => {
|
|
89
|
-
await gate('send', 'prompt');
|
|
90
|
-
return claude.prompt.submit(args);
|
|
91
|
-
},
|
|
92
|
-
},
|
|
93
|
-
command: {
|
|
94
|
-
...claude.command,
|
|
95
|
-
run: async (args) => {
|
|
96
|
-
await gate(`commands.run(${args.command})`, 'prompt');
|
|
97
|
-
return claude.command.run(args);
|
|
98
|
-
},
|
|
99
|
-
},
|
|
100
|
-
cmod: {
|
|
101
|
-
async call(args) {
|
|
102
|
-
const named = args.to === cmodPluginName ? conversationCalls[args.method] : undefined;
|
|
103
|
-
const given = args.method === conversationMethods.act && isObject(args.input) ? String(args.input['action']) : undefined;
|
|
104
|
-
const action = given !== undefined && isAct(given) ? given : undefined;
|
|
105
|
-
const isThisSession = isObject(args.input) && args.input['session'] === (await claude.session.id());
|
|
106
|
-
const isDropping = (args.method === conversationMethods.subscribe || args.method === conversationMethods.watchBefore) && isObject(args.input) && Array.isArray(args.input['subscriptions']) && args.input['subscriptions'].length === 0;
|
|
107
|
-
if (named !== undefined && action !== undefined)
|
|
108
|
-
await gate(action, actPermission(action, isObject(args.input) ? args.input['input'] : undefined));
|
|
109
|
-
else if (named !== undefined && !isThisSession && !isDropping)
|
|
110
|
-
await gate(named, 'conversation');
|
|
111
|
-
return claude.cmod.call(args);
|
|
112
|
-
},
|
|
113
|
-
},
|
|
114
|
-
model: {
|
|
115
|
-
complete: async (...args) => {
|
|
116
|
-
await gate('model.complete', 'model');
|
|
117
|
-
return claude.model.complete(...args);
|
|
118
|
-
},
|
|
119
|
-
},
|
|
120
|
-
agent: {
|
|
121
|
-
...claude.agent,
|
|
122
|
-
async spawn(args) {
|
|
123
|
-
await gate('startTask', 'tasks');
|
|
124
|
-
return claude.agent.spawn(args);
|
|
125
|
-
},
|
|
126
|
-
},
|
|
127
|
-
tool: {
|
|
128
|
-
...claude.tool,
|
|
129
|
-
call: async (input) => {
|
|
130
|
-
await gate(`tool.call(${input.tool})`, toolPermission(input.tool));
|
|
131
|
-
return claude.tool.call(input);
|
|
132
|
-
},
|
|
133
|
-
},
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
function spawned(started) {
|
|
137
|
-
const result = started.then((stream) => stream.result);
|
|
138
|
-
result.catch(() => undefined);
|
|
139
|
-
const stream = {
|
|
140
|
-
next: async () => (await started).next(),
|
|
141
|
-
async return(value) {
|
|
142
|
-
const [start] = await Promise.allSettled([started]);
|
|
143
|
-
return start.status === 'fulfilled' ? start.value.return(value) : { done: true, value };
|
|
144
|
-
},
|
|
145
|
-
[Symbol.asyncIterator]: () => stream,
|
|
146
|
-
result,
|
|
147
|
-
};
|
|
148
|
-
return stream;
|
|
149
|
-
}
|
|
150
|
-
export function itemOf(name, value) {
|
|
151
|
-
return value === undefined ? name : `${name}:${value}`;
|
|
152
|
-
}
|
|
153
|
-
export function isCovered(granted, item, home) {
|
|
154
|
-
if (granted.has(item))
|
|
155
|
-
return true;
|
|
156
|
-
const split = item.indexOf(':');
|
|
157
|
-
if (split === -1)
|
|
158
|
-
return false;
|
|
159
|
-
const name = item.slice(0, split);
|
|
160
|
-
if (name === 'config')
|
|
161
|
-
return isSettingCovered(granted, item.slice(split + 1));
|
|
162
|
-
const target = expanded(item.slice(split + 1), home);
|
|
163
|
-
const values = [...granted].filter((each) => each.startsWith(`${name}:`)).map((each) => expanded(each.slice(name.length + 1), home));
|
|
164
|
-
if (name === 'run')
|
|
165
|
-
return values.includes('*') || values.includes(target);
|
|
166
|
-
if (name === 'files')
|
|
167
|
-
return values.some((each) => relativePath(each, target) !== undefined);
|
|
168
|
-
return values.includes(target);
|
|
169
|
-
}
|
|
170
|
-
function readItem(grants, path) {
|
|
171
|
-
if (grants.configRoot === undefined)
|
|
172
|
-
return undefined;
|
|
173
|
-
return relativePath(`${grants.configRoot}/projects`, path) === undefined ? undefined : 'conversation';
|
|
174
|
-
}
|
|
175
|
-
function writeItem(grants, path) {
|
|
176
|
-
const root = grants.projectRoot();
|
|
177
|
-
const settingsFiles = [...projectSettingsFiles.map((file) => `${root}/${file}`), ...(grants.configRoot === undefined ? [] : [`${grants.configRoot}/settings.json`])];
|
|
178
|
-
if (settingsFiles.includes(path)) {
|
|
179
|
-
throw new PermissionRefused(`${grants.name} writes ${path} by hand. Change Claude Code's settings with settings.user.update, settings.project.update, or settings.local.update, which keep the person's own edits and take the mod's values out when it is removed.`);
|
|
180
|
-
}
|
|
181
|
-
if (grants.freeFolders().some((folder) => relativePath(folder, path) !== undefined))
|
|
182
|
-
return undefined;
|
|
183
|
-
return `files:${path}`;
|
|
184
|
-
}
|
|
185
|
-
export function refusal(grants, call, item) {
|
|
186
|
-
const { name } = grants;
|
|
187
|
-
if (isCovered(new Set(grants.declared), item, grants.home))
|
|
188
|
-
return `${name} calls ${call} without your grant to "${permissionWords(item)}". ${grantFix}`;
|
|
189
|
-
return `${name} calls ${call}, which needs ${declaration(item, grants.home)} in package.json "cmod".`;
|
|
190
|
-
}
|
|
191
|
-
function declaration(item, home) {
|
|
192
|
-
const split = item.indexOf(':');
|
|
193
|
-
if (split === -1)
|
|
194
|
-
return `"permissions": { "${item}": true }`;
|
|
195
|
-
const name = item.slice(0, split);
|
|
196
|
-
const target = item.slice(split + 1);
|
|
197
|
-
const fromHome = home === undefined ? undefined : relativePath(home, target);
|
|
198
|
-
const shown = name !== 'run' && fromHome !== undefined ? `~/${fromHome}` : target;
|
|
199
|
-
return `"permissions": { "${name}": ["${shown}"] }`;
|
|
200
|
-
}
|
|
201
|
-
const classicParts = {
|
|
202
|
-
additionalContext: 'prompt',
|
|
203
|
-
initialUserMessage: 'prompt',
|
|
204
|
-
updatedToolOutput: 'prompt',
|
|
205
|
-
updatedMCPToolOutput: 'prompt',
|
|
206
|
-
retry: 'approve',
|
|
207
|
-
};
|
|
208
|
-
const blocksKeepWorking = ['classic.Stop', 'classic.PostToolUse'];
|
|
209
|
-
const reservedToolKeys = ['tool', 'tool_use_id'];
|
|
210
|
-
export function checksAnswers(event) {
|
|
211
|
-
return event.startsWith('classic.') || event === 'tool.check' || event === 'tool.call' || event === 'prompt.context' || event === 'prompt.submit';
|
|
212
|
-
}
|
|
213
|
-
export function passedDown(event, original, passed, check) {
|
|
214
|
-
if (passed === original)
|
|
215
|
-
return passed;
|
|
216
|
-
if (event === 'tool.call') {
|
|
217
|
-
if (sameExcept(original, passed, reservedToolKeys) || check.isGranted('tools'))
|
|
218
|
-
return passed;
|
|
219
|
-
check.dropped('tools', 'a changed tool input');
|
|
220
|
-
return original;
|
|
221
|
-
}
|
|
222
|
-
if (event === 'prompt.context' || event === 'prompt.submit') {
|
|
223
|
-
if (same(original, passed) || check.isGranted('prompt'))
|
|
224
|
-
return passed;
|
|
225
|
-
check.dropped('prompt', event === 'prompt.submit' ? 'a rewritten prompt' : 'changed context');
|
|
226
|
-
return original;
|
|
227
|
-
}
|
|
228
|
-
return passed;
|
|
229
|
-
}
|
|
230
|
-
export async function checkedAnswer(event, e, answer, below, check) {
|
|
231
|
-
if (!isFields(answer))
|
|
232
|
-
return answer;
|
|
233
|
-
if (event === 'tool.check')
|
|
234
|
-
return decided(answer['decision'], answer, below, check);
|
|
235
|
-
if (event === 'classic.PermissionRequest') {
|
|
236
|
-
const decision = isFields(answer['decision']) ? answer['decision']['behavior'] : undefined;
|
|
237
|
-
return decided(decision, answer, below, check);
|
|
238
|
-
}
|
|
239
|
-
if (event.startsWith('classic.'))
|
|
240
|
-
return classicAnswer(event, answer, below, check);
|
|
241
|
-
if (event === 'tool.call') {
|
|
242
|
-
if (answer['deny'] !== undefined || check.isGranted('prompt'))
|
|
243
|
-
return answer;
|
|
244
|
-
const tool = isFields(e) ? e['tool'] : undefined;
|
|
245
|
-
if (typeof tool === 'string' && tool.startsWith(`mcp__${check.plugin}__`)) {
|
|
246
|
-
if (answer['context'] === undefined)
|
|
247
|
-
return answer;
|
|
248
|
-
check.dropped('prompt', 'context after a tool call');
|
|
249
|
-
const { context: _context, ...rest } = answer;
|
|
250
|
-
return rest;
|
|
251
|
-
}
|
|
252
|
-
const theirs = await below();
|
|
253
|
-
if (same(answer, theirs))
|
|
254
|
-
return answer;
|
|
255
|
-
check.dropped('prompt', same(contextOf(answer), contextOf(theirs)) ? 'a changed tool result' : 'context after a tool call');
|
|
256
|
-
return theirs;
|
|
257
|
-
}
|
|
258
|
-
if (event === 'prompt.submit' && answer['drop'] !== undefined)
|
|
259
|
-
return answer;
|
|
260
|
-
if (event === 'prompt.context' || event === 'prompt.submit') {
|
|
261
|
-
if (check.isGranted('prompt'))
|
|
262
|
-
return answer;
|
|
263
|
-
const theirs = await below();
|
|
264
|
-
if (same(answer, theirs))
|
|
265
|
-
return answer;
|
|
266
|
-
check.dropped('prompt', event === 'prompt.submit' ? 'a rewritten prompt' : 'changed context');
|
|
267
|
-
return theirs;
|
|
268
|
-
}
|
|
269
|
-
return answer;
|
|
270
|
-
}
|
|
271
|
-
async function decided(decision, answer, below, check) {
|
|
272
|
-
if ((decision !== 'allow' && decision !== 'ask') || check.isGranted('approve'))
|
|
273
|
-
return answer;
|
|
274
|
-
const theirs = await below();
|
|
275
|
-
if (same(answer, theirs))
|
|
276
|
-
return answer;
|
|
277
|
-
check.dropped('approve', `${decision} on a tool call`);
|
|
278
|
-
return theirs;
|
|
279
|
-
}
|
|
280
|
-
async function classicAnswer(event, answer, below, check) {
|
|
281
|
-
const blocks = blocksKeepWorking.includes(event) ? [['block', 'prompt']] : [];
|
|
282
|
-
const parts = [...Object.entries(classicParts), ...blocks].filter(([part, item]) => answer[part] !== undefined && !check.isGranted(item));
|
|
283
|
-
if (parts.length === 0)
|
|
284
|
-
return answer;
|
|
285
|
-
const theirs = await below();
|
|
286
|
-
const kept = { ...answer };
|
|
287
|
-
const theirFields = isFields(theirs) ? theirs : {};
|
|
288
|
-
for (const [part, item] of parts) {
|
|
289
|
-
if (same(answer[part], theirFields[part]))
|
|
290
|
-
continue;
|
|
291
|
-
check.dropped(item, part);
|
|
292
|
-
if (theirFields[part] === undefined)
|
|
293
|
-
delete kept[part];
|
|
294
|
-
else
|
|
295
|
-
kept[part] = theirFields[part];
|
|
296
|
-
}
|
|
297
|
-
return kept;
|
|
298
|
-
}
|
|
299
|
-
function contextOf(answer) {
|
|
300
|
-
return isFields(answer) ? answer['context'] : undefined;
|
|
301
|
-
}
|
|
302
|
-
function same(left, right) {
|
|
303
|
-
return left === right || JSON.stringify(left) === JSON.stringify(right);
|
|
304
|
-
}
|
|
305
|
-
function sameExcept(left, right, keys) {
|
|
306
|
-
if (!isFields(left) || !isFields(right))
|
|
307
|
-
return same(left, right);
|
|
308
|
-
const without = (fields) => Object.fromEntries(Object.entries(fields).filter(([key]) => !keys.includes(key)));
|
|
309
|
-
return same(without(left), without(right));
|
|
310
|
-
}
|
|
311
|
-
function isFields(value) {
|
|
312
|
-
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
313
|
-
}
|
|
314
|
-
function programOf(argv) {
|
|
315
|
-
const command = argv[0] ?? '';
|
|
316
|
-
return command.slice(command.lastIndexOf('/') + 1);
|
|
317
|
-
}
|
|
318
|
-
function hostOf(url) {
|
|
319
|
-
return URL.canParse(url) ? new URL(url).hostname : url;
|
|
320
|
-
}
|
|
321
|
-
function addressOf(url) {
|
|
322
|
-
return URL.canParse(url) ? new URL(url).host : url;
|
|
323
|
-
}
|
|
324
|
-
function expanded(path, home) {
|
|
325
|
-
return path.startsWith('~/') && home !== undefined ? `${home}${path.slice(1)}` : path;
|
|
326
|
-
}
|