@cmodjs/core 6.3.0 → 8.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.
- package/docs/commands.md +123 -65
- package/docs/dependencies.md +189 -4
- package/docs/index.md +56 -12
- package/docs/install-steps.md +20 -17
- package/docs/jobs.md +43 -16
- package/docs/mod.md +43 -27
- package/docs/options.md +2 -2
- package/docs/session.md +58 -32
- package/docs/testing.md +88 -24
- package/docs/ui.md +128 -58
- package/installer.d.ts +2 -2
- package/jobs/context.js +1 -1
- package/jobs/program.d.ts +4 -1
- package/jobs/program.d.ts.map +1 -1
- package/jobs/program.js +79 -20
- package/mod.d.ts +59 -9
- package/mod.d.ts.map +1 -1
- package/mod.js +5 -3
- package/package.json +1 -1
- package/records.d.ts +15 -2
- package/records.d.ts.map +1 -1
- package/records.js +24 -10
- package/register.d.ts.map +1 -1
- package/register.js +7 -4
- package/rpc.d.ts +7 -0
- package/rpc.d.ts.map +1 -0
- package/rpc.js +59 -0
- package/runtime/bound.d.ts +1 -0
- package/runtime/bound.d.ts.map +1 -1
- package/runtime/bound.js +10 -0
- package/runtime/bun.d.ts +20 -0
- package/runtime/bun.d.ts.map +1 -0
- package/runtime/bun.js +20 -0
- package/runtime/claude.d.ts +1 -0
- package/runtime/claude.d.ts.map +1 -1
- package/runtime/conversations.d.ts +12 -1
- package/runtime/conversations.d.ts.map +1 -1
- package/runtime/conversations.js +472 -362
- package/runtime/deadline.d.ts +4 -3
- package/runtime/deadline.d.ts.map +1 -1
- package/runtime/deadline.js +10 -4
- package/runtime/engine.d.ts +5 -4
- package/runtime/engine.d.ts.map +1 -1
- package/runtime/installer.d.ts +3 -3
- package/runtime/installer.d.ts.map +1 -1
- package/runtime/installer.js +10 -9
- package/runtime/interfaces.d.ts +262 -0
- package/runtime/interfaces.d.ts.map +1 -0
- package/runtime/interfaces.js +935 -0
- package/runtime/lifecycle.d.ts +3 -3
- package/runtime/lifecycle.d.ts.map +1 -1
- package/runtime/lifecycle.js +83 -52
- package/runtime/options.d.ts.map +1 -1
- package/runtime/options.js +2 -6
- package/runtime/parts.d.ts +64 -1
- package/runtime/parts.d.ts.map +1 -1
- package/runtime/parts.js +311 -4
- package/runtime/programs.d.ts +1 -0
- package/runtime/programs.d.ts.map +1 -1
- package/runtime/programs.js +5 -3
- package/runtime/rpc.d.ts +111 -0
- package/runtime/rpc.d.ts.map +1 -0
- package/runtime/rpc.js +387 -0
- package/runtime/sessions.d.ts +6 -4
- package/runtime/sessions.d.ts.map +1 -1
- package/runtime/sessions.js +59 -80
- package/runtime/toaster.js +1 -1
- package/runtime/ui.d.ts +23 -10
- package/runtime/ui.d.ts.map +1 -1
- package/runtime/ui.js +63 -52
- package/runtime/web.d.ts +0 -73
- package/runtime/web.d.ts.map +1 -1
- package/runtime/web.js +9 -5
- package/runtime/widgets.d.ts +4 -2
- package/runtime/widgets.d.ts.map +1 -1
- package/runtime/widgets.js +17 -16
- package/session/conversation.d.ts +7 -1
- package/session/conversation.d.ts.map +1 -1
- package/session/session.d.ts +31 -7
- package/session/session.d.ts.map +1 -1
- package/session/session.js +1 -0
- package/src/installer.ts +2 -2
- package/src/jobs/context.ts +1 -1
- package/src/jobs/program.ts +76 -21
- package/src/mod.ts +51 -10
- package/src/records.ts +33 -9
- package/src/register.ts +7 -4
- package/src/rpc.ts +67 -0
- package/src/runtime/bound.ts +10 -0
- package/src/runtime/bun.ts +40 -0
- package/src/runtime/claude.ts +1 -0
- package/src/runtime/conversations.ts +470 -352
- package/src/runtime/deadline.ts +13 -6
- package/src/runtime/engine.ts +5 -4
- package/src/runtime/installer.ts +13 -12
- package/src/runtime/interfaces.ts +1161 -0
- package/src/runtime/lifecycle.ts +102 -59
- package/src/runtime/options.ts +2 -5
- package/src/runtime/parts.ts +364 -5
- package/src/runtime/programs.ts +6 -3
- package/src/runtime/rpc.ts +457 -0
- package/src/runtime/sessions.ts +63 -83
- package/src/runtime/toaster.ts +1 -1
- package/src/runtime/ui.ts +82 -61
- package/src/runtime/web.ts +10 -39
- package/src/runtime/widgets.ts +20 -18
- package/src/session/conversation.ts +7 -1
- package/src/session/session.ts +22 -7
- package/src/testing/fake-claude.ts +38 -7
- package/src/testing/fake-serve.ts +144 -0
- package/src/testing/fake-sessions.ts +21 -6
- package/src/testing.ts +156 -68
- package/src/ui/areas.ts +2 -2
- package/src/ui/elements.ts +21 -16
- package/src/ui/panes.ts +14 -7
- package/testing/fake-claude.d.ts +6 -0
- package/testing/fake-claude.d.ts.map +1 -1
- package/testing/fake-claude.js +34 -7
- package/testing/fake-serve.d.ts +39 -0
- package/testing/fake-serve.d.ts.map +1 -0
- package/testing/fake-serve.js +110 -0
- package/testing/fake-sessions.d.ts.map +1 -1
- package/testing/fake-sessions.js +22 -6
- package/testing.d.ts +21 -4
- package/testing.d.ts.map +1 -1
- package/testing.js +138 -56
- package/ui/areas.d.ts +3 -1
- package/ui/areas.d.ts.map +1 -1
- package/ui/elements.d.ts +18 -9
- package/ui/elements.d.ts.map +1 -1
- package/ui/elements.js +9 -8
- package/ui/panes.d.ts +10 -6
- package/ui/panes.d.ts.map +1 -1
- package/ui/panes.js +5 -3
- package/runtime/pages.d.ts +0 -32
- package/runtime/pages.d.ts.map +0 -1
- package/runtime/pages.js +0 -142
- package/src/runtime/pages.ts +0 -183
package/docs/dependencies.md
CHANGED
|
@@ -46,7 +46,7 @@ declare module 'claude-code' {
|
|
|
46
46
|
A mod that calls the provider lists it in its own `.claude-plugin/plugin.json`, and Claude Code installs it with the mod:
|
|
47
47
|
|
|
48
48
|
```json
|
|
49
|
-
"dependencies": [{ "name": "cmod", "version": ">=
|
|
49
|
+
"dependencies": [{ "name": "cmod", "version": ">=8.0.0" }, "provider"]
|
|
50
50
|
```
|
|
51
51
|
|
|
52
52
|
Write the dependency bare, by its name alone. Claude Code looks for a bare dependency only in the mod's own marketplace, so `cmod publish` lists the provider there, from the `release` branch of the GitHub repository that the `"repository"` of the provider's `plugin.json` names. Install or link the provider before you publish, or `cmod publish` stops and says to. A dependency that names its `"marketplace"` loads for the people who install your mod, but not from the marketplace `cmod link` writes for your checkout.
|
|
@@ -54,12 +54,12 @@ Write the dependency bare, by its name alone. Claude Code looks for a bare depen
|
|
|
54
54
|
A provider that changes or removes a method breaks every mod that calls it, and with automatic updates the provider can update first. Name the versions you tested with a range, and Claude Code turns your mod off with a clear error instead of letting its calls fail one by one:
|
|
55
55
|
|
|
56
56
|
```json
|
|
57
|
-
"dependencies": [{ "name": "cmod", "version": ">=
|
|
57
|
+
"dependencies": [{ "name": "cmod", "version": ">=8.0.0" }, { "name": "provider", "version": "^1.0" }]
|
|
58
58
|
```
|
|
59
59
|
|
|
60
60
|
Claude Code checks the range against the provider's `version` when it loads your mod. Every mod's marketplace lists cmod and each provider from its git repository, so Claude Code also installs it at the highest `<name>--v<version>` tag inside the range, which `cmod publish` pushes for every release ([Claude Code's plugin dependencies](https://code.claude.com/docs/en/plugins/dependencies)).
|
|
61
61
|
|
|
62
|
-
cmod is a provider too, with one difference: every newer cmod runs every mod built on an older `@cmodjs/core`. So a mod names only the oldest cmod it runs on, which the `@cmodjs/core` it bundles names as `oldestCmodVersion` in its `records.js`, as `>=
|
|
62
|
+
cmod is a provider too, with one difference: every newer cmod runs every mod built on an older `@cmodjs/core`. So a mod names only the oldest cmod it runs on, which the `@cmodjs/core` it bundles names as `oldestCmodVersion` in its `records.js`, as `>=8.0.0`. When the mod needs a newer cmod, such as one whose cmod plugin carries out a call the mod makes, write that minimum as `>=` its version, as `>=8.1.0`. `cmod check` writes the newer of the two whenever the mod's `@cmodjs/core` changes, and `cmod publish` refuses a release whose range is not `>=` a version at or above `oldestCmodVersion`. A caret range such as `^8.0.0` stops Claude Code from updating cmod past 8.x for every mod on the computer, so leave it to `cmod check`.
|
|
63
63
|
|
|
64
64
|
Each mod's marketplace lists its own copy of cmod and of each provider, and Claude Code loads only one copy of each. When a mod needs a newer cmod than a copy Claude Code installed, the cmod plugin updates every copy of cmod, and when two copies of any plugin differ, it updates every copy of that plugin. Then each session offers Reload, so a mod never waits for the person to update its providers, only to press Reload.
|
|
65
65
|
|
|
@@ -94,6 +94,189 @@ isLoaded(name: string): Promise<boolean>
|
|
|
94
94
|
- Claude Code lays a provider's types file beside your mod's only for a listed dependency, so type the methods you call in your own `types/index.d.ts`, with the shape the provider's types file exports, such as `interface CmodDependencies { provider: Provider }`.
|
|
95
95
|
- A mod that calls `mods.isLoaded` runs on cmod 5.4.0 or later, which the `cmod` range `cmod check` writes says.
|
|
96
96
|
|
|
97
|
+
## Interfaces: several mods answer one name
|
|
98
|
+
|
|
99
|
+
A provider is a mod, or a mod's program, that implements a feature an interface defines. It follows VS Code's providers: an extension registers a `HoverProvider` with `registerHoverProvider`, and VS Code asks every registered `HoverProvider` for its hover. A caller asks `providers(name)` for every provider that runs and calls each one, where a dependency is one mod your mod calls by name. So a terminal app, a remote device, or a Markdown styler can each come from any mod.
|
|
100
|
+
|
|
101
|
+
An interface is named `<mod>/<Name>`, after the mod that defines it, such as `demo/Platform`, and cmod defines five:
|
|
102
|
+
|
|
103
|
+
- `cmod/Sessions` lists, searches, and reads sessions, acts on them, and tells a `Change` for each session that starts or stops running, is visited or deleted, or changes its tasks, goal, or status, as one VS Code `FileSystemProvider` reads, writes, and reports changes for its scheme. `cmod serve` provides it for this computer, the `cmod serve` of each device a `cmod/Devices` provider names provides it for that device, and a mod whose program serves another device's sessions provides it for that device ([session.md](session.md#sessions-providers)).
|
|
104
|
+
- `cmod/Devices` says where the `cmod serve` of each of your other devices listens, or carries its messages, so `cmod serve` reaches the providers there ([cmod/Devices](#cmod-devices-providers-on-your-other-devices)).
|
|
105
|
+
- `cmod/UI` lists, draws, and presses each session's widgets, views, and pages, and tells a `Change` when a mod adds or removes one and a `Redraw` when one may draw new data, so an app such as the browser app draws every mod's UI. Each session's cmod plugin answers it for its own session, and `cmod serve` sends each call to the plugin that holds the session the call names ([ui.md](ui.md#every-app-reaches-them-through-cmod-ui)).
|
|
106
|
+
- `cmod/Terminal` reads a session's screen, types keys into it, and shows it in a pane. A mod whose program hosts the terminals sessions run in provides it.
|
|
107
|
+
- `cmod/Style` draws Markdown in a mod's own style. Every mod with a Markdown style provides it, with no `provide` call ([ui.md](ui.md#styles-change-how-claude-code-draws)).
|
|
108
|
+
|
|
109
|
+
The mod that defines an interface types it in its types file, on `CmodInterfaces`, with its methods and the events it tells:
|
|
110
|
+
|
|
111
|
+
```ts
|
|
112
|
+
declare module 'claude-code' {
|
|
113
|
+
interface CmodInterfaces {
|
|
114
|
+
'demo/Platform': {
|
|
115
|
+
methods: { machines(region: string): string[] }
|
|
116
|
+
events: { MachineChange: { readonly name: string } }
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
A mod provides an interface with `provide`, imported from `mod.js` beside `providers`, as VS Code's `registerXProvider` is a function of its namespace. `provide` returns a `Provided`: its `remove()` stops providing, its `tell` tells one of the interface's events to every `onE` listener on this provider, as a VS Code provider fires its own `onDidChange` event, and its `ask` asks every `beforeE` listener before the provider acts, as VS Code's `onWillSaveTextDocument` waits for its listeners.
|
|
123
|
+
|
|
124
|
+
```ts
|
|
125
|
+
provide<Name extends InterfaceName>(name: Name, methods: InterfaceMethods<Name>): Provided<Name>
|
|
126
|
+
|
|
127
|
+
type Provided<Name> = Subscription & {
|
|
128
|
+
tell<Event>(event: Event, payload: EventsOf<Name>[Event]): void
|
|
129
|
+
ask<Event>(event: Event, payload: EventsOf<Name>[Event]): Promise<unknown[]>
|
|
130
|
+
}
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
`ask` asks the listeners one at a time and resolves with each answer in the order it asked, leaving out a listener that answered nothing. It stops at the first answer that holds `refuse`, so no listener after it is asked. Each listener runs within its own `timeoutMs`, 10 seconds when it gives none, and a listener that throws, passes its `timeoutMs`, or cannot be reached counts as its `onFailure` says: `'pass'`, the default, leaves its answer out, and `'refuse'` answers `{ refuse: '<its error>' }`. A provider reads the answers as its interface defines them:
|
|
134
|
+
|
|
135
|
+
```ts
|
|
136
|
+
const rules = provide('demo/Rules', {})
|
|
137
|
+
const answers = (await rules.ask('Check', { tool: 'Bash' })) as { readonly refuse?: string; readonly rules?: Record<string, 'off' | 'warn'> }[]
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
Another mod in the session answers with a `beforeE` listener on that provider:
|
|
141
|
+
|
|
142
|
+
```ts
|
|
143
|
+
const [rules] = await providers('demo/Rules')
|
|
144
|
+
rules?.beforeCheck((check) => (check.tool === 'Bash' ? { rules: { 'no-rm': 'off' } } : undefined), { timeoutMs: 2000 })
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
From session code, `provide` answers the methods while the mod runs in that session, and only callers in that session reach it and hear what it tells, as a VS Code window's provider serves only that window. The cmod plugin carries each `tell` and `ask` to the session's listeners, as `cmod serve` carries a program's, so a `tell` inside a method that answers a call, or an `ask` inside the mod's own `beforeToolCall` listener, still reaches the caller:
|
|
148
|
+
|
|
149
|
+
```ts
|
|
150
|
+
const platform = provide('demo/Platform', { machines: async (region) => listMachines(region) })
|
|
151
|
+
platform.tell('MachineChange', { name: 'eu-1' })
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
From a program that a `program` job with `singleInstance` or `isService` runs ([jobs.md](jobs.md#program)), `provide` answers the methods and tells the events for the whole computer, through the program's connection to `cmod serve`, which `connect()` opens:
|
|
155
|
+
|
|
156
|
+
```ts
|
|
157
|
+
import { provide } from '@cmodjs/core/mod.js'
|
|
158
|
+
import { connect } from '@cmodjs/core/rpc.js'
|
|
159
|
+
|
|
160
|
+
await connect()
|
|
161
|
+
const platform = provide('demo/Platform', { machines: async (region) => listMachines(region) })
|
|
162
|
+
platform.tell('MachineChange', { name: 'eu-1' })
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
### connect: a program's connection to cmod serve
|
|
166
|
+
|
|
167
|
+
`connect`, imported from `rpc.js`, opens the program's one connection to this computer's `cmod serve`, the hub that holds every program's providers and carries each call to the provider it names, as VS Code's window holds every extension's providers:
|
|
168
|
+
|
|
169
|
+
```ts
|
|
170
|
+
connect(): Promise<Connection>
|
|
171
|
+
|
|
172
|
+
type Connection = {
|
|
173
|
+
call(name: string, method: string, params: readonly unknown[]): Promise<unknown>
|
|
174
|
+
listen(name: string, event: string, listener: (payload: unknown, signal: AbortSignal) => unknown): Subscription
|
|
175
|
+
tell(name: string, event: string, payload: unknown): void
|
|
176
|
+
ask(name: string, event: string, payload: unknown): Promise<unknown[]>
|
|
177
|
+
close(): Promise<void>
|
|
178
|
+
}
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
- It names the mod by `CMOD_MOD` and the program by `CMOD_PROGRAM`, which `cmod program` sets for each program it starts, and rejects with `connect() names its mod by CMOD_MOD, which cmod program sets for every program it starts, and CMOD_MOD is not set.` outside one.
|
|
182
|
+
- It resolves once `cmod serve` answers on `serve.sock` in the cmod store, and connects again, and provides again, whenever `cmod serve` starts again.
|
|
183
|
+
- After it, the program imports `provide` and `providers` from `mod.js`. Every other import throws `<mod>'s program imports only provide and providers from @cmodjs/core/mod.js, because <import> belongs to a Claude Code session.`
|
|
184
|
+
- `tell` is what `Provided`'s `tell` runs: it tells every `onE` listener on this program's provider of `name`.
|
|
185
|
+
- `ask` is what `Provided`'s `ask` runs: it asks every `beforeE` listener on this program's provider of `name`, in a session or a program, on this computer or a device `cmod serve` reaches.
|
|
186
|
+
- `call` and `listen` reach an interface without picking a provider: `cmod serve` answers `cmod/Sessions` and `cmod/UI` itself, sends any other interface to its one provider, on this computer or a device it reaches, and refuses when no program or several provide it. `providers` picks one.
|
|
187
|
+
- `call` rejects with `<interface>.<method> passed its 30 s deadline` when the provider has not answered after 30 seconds, such as a provider on a device that went to sleep mid-call. It then sends `$/cancelRequest`, so the provider's handler sees its signal abort.
|
|
188
|
+
- `close` ends the connection, and `cmod serve` drops the program's providers with it.
|
|
189
|
+
- A program that only provides prints no address, so its job's `ready()` rejects once it runs. Its mod waits with the job's `provider(name)` instead, which resolves with that program's provider of `name` once the program provides it ([jobs.md](jobs.md#program)).
|
|
190
|
+
|
|
191
|
+
A `cmod/Sessions` provider answers every method its type in the cmod plugin's types file names. Each method on one session takes the session's id first. For a session the provider does not hold, the method throws `NotHeld`, imported from `rpc.js`, so cmod asks the next provider, as a VS Code `FileSystemProvider` throws `FileSystemError.FileNotFound`. Its message is `This provider holds no session <id>.`, which the caller reads when no provider holds the session. Any other error ends the call with its message, and cmod asks no further provider:
|
|
192
|
+
|
|
193
|
+
```ts
|
|
194
|
+
import { provide } from '@cmodjs/core/mod.js'
|
|
195
|
+
import { connect, NotHeld } from '@cmodjs/core/rpc.js'
|
|
196
|
+
|
|
197
|
+
await connect()
|
|
198
|
+
provide('cmod/Sessions', {
|
|
199
|
+
read: async (session, part, options) => {
|
|
200
|
+
const device = await deviceOf(session)
|
|
201
|
+
if (device === undefined) throw new NotHeld(session)
|
|
202
|
+
return device.read(session, part, options)
|
|
203
|
+
},
|
|
204
|
+
...
|
|
205
|
+
})
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
`startTask` takes the whole task, `device` included: a provider that serves the device the task names starts the session there and answers its task, and any other throws `NotHeld`. The provider tells a `Change` with `part: 'running'` when one of its sessions stops running, which closes the task of the session that started it.
|
|
209
|
+
|
|
210
|
+
A caller asks `providers`, imported from `mod.js`, for the providers that run now, and calls each one's methods, typed from the interface:
|
|
211
|
+
|
|
212
|
+
```ts
|
|
213
|
+
providers<Name extends InterfaceName>(name: Name): Promise<InterfaceProvider<Name>[]>
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
```ts
|
|
217
|
+
for (const platform of await providers('demo/Platform')) {
|
|
218
|
+
mod.log(`${platform.mod}: ${(await platform.machines('eu')).join(', ')}`)
|
|
219
|
+
platform.onMachineChange((machine) => mod.log(`${machine.name} changed`))
|
|
220
|
+
}
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
- Each provider names its `mod`, its `program` when a program provides it, and its `device`, the `{ id, name }` of the computer it runs on, in the shape `device.read()` answers ([mod.md](mod.md#device-the-computer-the-session-runs-on)). The list holds every mod that provides the interface in this session, every program that provides it on this computer, which `cmod serve` holds, and every program that provides it on a device `cmod serve` reaches ([cmod/Devices](#cmod-devices-providers-on-your-other-devices)), in no set order.
|
|
224
|
+
- Each method returns a promise of what the provider's method returns, and rejects with the provider's error. A method the provider lacks rejects with `This program answers no <interface>.<method>.`, or `<mod> provides no <interface>.<method>.` from session code. A method that has not answered after 30 seconds rejects with `<interface>.<method> passed its 30 s deadline`, as a `mod.dependencies` call does ([When a call fails](#when-a-call-fails)).
|
|
225
|
+
- Each event `E` has an `onE` and a `beforeE` method, as the session's listeners do ([session.md](session.md#listen-to-a-record)): an `onE` listener hears what the provider tells with `Provided`'s `tell`, and a `beforeE` listener's answer reaches the provider that asks it with `Provided`'s `ask`, or a program that asks it with `$/before`, which reads it as it defines. Both take a matcher, `timeoutMs`, and `onFailure`.
|
|
226
|
+
- A provider that stops running leaves the list at the next call of `providers`. A program's providers leave when its connection closes, and a program that dies closes it at once, because `cmod serve` closes a connection whose poll the program left. A call to a provider that left fails with `<mod>'s <program> program does not run, so it answers no <interface>.`
|
|
227
|
+
|
|
228
|
+
A program in a language with no `connect()` speaks the wire `connect()` speaks, JSON-RPC 2.0 over HTTP on `serve.sock` in the cmod store:
|
|
229
|
+
|
|
230
|
+
- `POST /rpc/connect` opens a connection and answers `{ "connection": <id> }`.
|
|
231
|
+
- `POST /rpc/<id>` takes a JSON-RPC message or batch from the program and answers 204.
|
|
232
|
+
- `GET /rpc/<id>` answers the messages `cmod serve` has for the program, as a list, within 8 seconds, empty when it has none: the answers to its requests, and the requests and notifications of its callers.
|
|
233
|
+
- `DELETE /rpc/<id>` closes the connection, and so does a `GET` the program leaves before its answer, or no poll for 30 seconds. A call on a closed connection answers 410, and the program connects again.
|
|
234
|
+
- `$/provide` with `{ interface, mod, program }` makes the connection that program's provider of the interface, and `$/unprovide` with `{ interface }` stops it. `cmod serve` sends the program each call as a request that names `<interface>.<method>`, such as `demo/Platform.machines`, with the method's arguments as its `params` array.
|
|
235
|
+
- A `cmod/Sessions` provider answers a call on a session it does not hold with the JSON-RPC error code `-32098`, the answer `NotHeld` sends, and cmod asks the next provider. Any other error code ends the call with the error's message.
|
|
236
|
+
- `cmod serve` sends each listener as `$/listen` with `{ id, interface, kind, event, args?, matcher?, after? }`, and `$/unlisten` with `{ id }` removes it. The program tells an `on` listener with the notification `$/on` `{ id, payload, cursor }`, and asks a `before` listener with the request `$/before` `{ id, payload }`, whose result is its answer. A listener that names `after`, a cursor it last heard, hears the events since. `$/cancelRequest` with `{ id }` cancels a request.
|
|
237
|
+
- `$/providers` with `{ interface }` answers each program that provides it as `{ mod, program, device }`, and `$/call` with `{ interface, method, args, mod, program, device }` calls that program's method. `$/providers` with `{ interface, device }` answers only the providers of this computer, and only when `device` is its id, which is how one `cmod serve` asks another.
|
|
238
|
+
- `$/provider` with `{ interface, mod, program }` answers `{ mod, program, device }` once that program on this computer provides the interface, at once when it already does. `$/cancelRequest` stops the wait.
|
|
239
|
+
|
|
240
|
+
### cmod/Devices: providers on your other devices
|
|
241
|
+
|
|
242
|
+
A mod that links your devices, such as one that reaches them over ssh, a tailnet, or a relay, provides `cmod/Devices` from its program. For each other device it gives where that device's `cmod serve` listens, or carries that `cmod serve`'s messages itself, as a VS Code `RemoteAuthorityResolver` answers an address or a `ManagedMessagePassing`:
|
|
243
|
+
|
|
244
|
+
```ts
|
|
245
|
+
'cmod/Devices': {
|
|
246
|
+
methods: {
|
|
247
|
+
devices(): { id: string; name: string; address?: string }[]
|
|
248
|
+
send(device: string, message: unknown): void
|
|
249
|
+
}
|
|
250
|
+
events: { Change: { readonly device: string }; Message: { readonly device: string; readonly message: unknown } }
|
|
251
|
+
}
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
- `id` is the device's cmod device id, which `cmod device --json` prints on that device, and `name` its name.
|
|
255
|
+
- `cmod serve` asks every `cmod/Devices` provider on this computer for its devices when it provides the interface, reaches the `cmod serve` of each device, and lists that device's providers beside this computer's, each with its `device`.
|
|
256
|
+
- The provider tells `Change`, with the id of the device that changed, whenever its list changes. `cmod serve` then reads every list again: it reaches a new device, reaches again a device whose address or provider changed, and drops a device no list holds.
|
|
257
|
+
|
|
258
|
+
A device with an `address` is reached there. The address is where that device's `cmod serve` answers the wire above: a unix socket path, such as the end of an ssh tunnel, or an `http://` URL. The mod opens the link its own way, and cmod reaches the address with its own JSON-RPC over HTTP, which polls every 8 seconds.
|
|
259
|
+
|
|
260
|
+
A device with no `address` is reached through its provider, over one message channel. `cmod serve` sends each JSON-RPC message for that device's `cmod serve` with `send`, and the provider tells each message from that device as `Message`, in the order they came, and never reads one. A provider that links devices through a relay carries them both ways:
|
|
261
|
+
|
|
262
|
+
```ts
|
|
263
|
+
await connect()
|
|
264
|
+
const devices = provide('cmod/Devices', {
|
|
265
|
+
devices: () => relay.peers().map(({ id, name }) => ({ id, name })),
|
|
266
|
+
send: (device, message) => relay.send(device, message),
|
|
267
|
+
})
|
|
268
|
+
relay.onMessage((device, message) => devices.tell('Message', { device, message }))
|
|
269
|
+
relay.onPeersChange((device) => devices.tell('Change', { device }))
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
- The channel is a peer link: the same `cmod serve` both asks and answers over it, so each device's provider lists the other.
|
|
273
|
+
- Nothing polls across it. It carries a message only when a call, a listener, or an event needs one.
|
|
274
|
+
- Each `cmod serve` opens its end with the notification `$/link` `{ link }`, and answers the other end's with `$/link` `{ link, answers }`. It lists that device's providers once the two ends linked, so a device whose `cmod serve` never answers stays out of `providers`.
|
|
275
|
+
- A `$/link` from a device it already linked with means that device's `cmod serve` started again. `cmod serve` fails each call still waiting on the old link with `The connection closed: the cmod serve of <device> linked again`, and listens there again.
|
|
276
|
+
- A call whose message `send` fails rejects with `<mod>'s <program> program carried no message to <device>: <its error>`.
|
|
277
|
+
- `cmod serve` carries each call and listener on another device's provider to that device's `cmod serve`. Each `cmod serve` offers another device only its own computer's providers, never ones it carries, so a call takes one hop even when two devices list each other.
|
|
278
|
+
- A session's own providers stay in that session, as a VS Code window's do.
|
|
279
|
+
|
|
97
280
|
## When a call fails
|
|
98
281
|
|
|
99
282
|
A call that cannot answer rejects with one of these reasons:
|
|
@@ -110,7 +293,7 @@ A call that cannot answer rejects with one of these reasons:
|
|
|
110
293
|
- `<provider> is not set up` covers a provider the person declined to install and one whose install failed, and names why. The provider's own toast shows the same reason, with `Retry` or `Install`.
|
|
111
294
|
- `<provider> is installing` covers a provider whose install step still runs 5 seconds after the call. A provider that is installing or only starting makes the call wait for it, up to 5 seconds.
|
|
112
295
|
- When the provider is disabled, Claude Code unloads the mod that lists it, with its own error, which starts `Dependency "<provider>" is disabled`.
|
|
113
|
-
- A call fails with `mod.dependencies.<provider>.<method> passed its 30 s deadline` when the other mod takes longer than 30 seconds. A job bounds the whole function that makes the call by its own deadline ([jobs.md](jobs.md)), so a slow call inside `slashCommand` can fail the command first, with `/<command> passed the 30 s deadline of slashCommand`.
|
|
296
|
+
- A call fails with `mod.dependencies.<provider>.<method> passed its 30 s deadline` when the other mod takes longer than 30 seconds. A call to a provider's method keeps the same 30 s deadline, from session code and from a program, and fails with `<interface>.<method> passed its 30 s deadline`, such as `demo/Platform.machines passed its 30 s deadline`, and cancels the request it left with the provider. A listener is no call, so it keeps no deadline, and `Provided`'s `ask` bounds each listener by its own `timeoutMs`. A job bounds the whole function that makes the call by its own deadline ([jobs.md](jobs.md)), so a slow call inside `slashCommand` can fail the command first, with `/<command> passed the 30 s deadline of slashCommand`.
|
|
114
297
|
|
|
115
298
|
```ts
|
|
116
299
|
notInstalled(name: string): string
|
|
@@ -122,6 +305,8 @@ notInstalled(name: string): string
|
|
|
122
305
|
|
|
123
306
|
`testMod(myMod, { dependencies: { provider: { lines: async () => 3 } } })` answers the provider's methods with the functions given. A call to a mod the test does not fake fails with `<provider> is not installed. Install it in Plugins.`, as in Claude Code. [testing.md](testing.md) covers it.
|
|
124
307
|
|
|
308
|
+
`testMod(myMod, { providers: [{ name: 'demo/Platform', mod: 'demo', program: 'platform', methods: { machines: () => ['eu-1'] } }] })` fakes a provider of an interface, on this computer or on a device it names, and `tested.providers` tells its events and asks its `beforeE` listeners ([testing.md](testing.md#providers)).
|
|
309
|
+
|
|
125
310
|
A test of the provider's own methods fires `cmod.call`, as a caller's `mod.dependencies` does. The answer is `{ value }` with what the method returned, or `{ deny }` with the reason it failed:
|
|
126
311
|
|
|
127
312
|
```ts
|
package/docs/index.md
CHANGED
|
@@ -10,27 +10,29 @@ A mod is a Claude Code plugin built with `@cmodjs/core`. Claude Mod Manager (cmo
|
|
|
10
10
|
|
|
11
11
|
```text
|
|
12
12
|
my-mod/
|
|
13
|
-
├── .claude-plugin/plugin.json name, version, and "dependencies": [{ "name": "cmod", "version": ">=
|
|
13
|
+
├── .claude-plugin/plugin.json name, version, and "dependencies": [{ "name": "cmod", "version": ">=8.0.0" }]
|
|
14
14
|
├── .claude/CLAUDE.md facts for coding agents, starting with these docs
|
|
15
15
|
├── .gitignore node_modules/ and .claude-plugin/types/
|
|
16
16
|
├── .oxlintrc.json leaves .claude-plugin/types/ out of the lint
|
|
17
|
+
├── CHANGELOG.md the release notes, a section per version, which cmod publish requires
|
|
17
18
|
├── hooks/hooks.json names hooks/register.ts as the hooks module
|
|
18
19
|
├── hooks/register.ts registerMod(addHook, myMod, options), and nothing else
|
|
19
20
|
├── src/mod.tsx defineMod: the state, the hotkeys, the setup, the listeners
|
|
20
21
|
├── src/state.ts the starting state
|
|
21
|
-
├── src/
|
|
22
|
+
├── src/views/prompts.tsx one view per file
|
|
22
23
|
├── src/widgets/prompts.tsx one widget per file
|
|
23
|
-
├── src/components/prompt-count.tsx what the
|
|
24
|
+
├── src/components/prompt-count.tsx what the view and the widget draw with
|
|
24
25
|
├── skills/my-mod/SKILL.md a Skill the mod ships
|
|
25
26
|
├── rules/prompt-count.md a rule Claude reads
|
|
26
27
|
├── tests/mod.test.ts testMod tests, run with bun test
|
|
28
|
+
├── tests/tsconfig.json adds Bun's types for the tests
|
|
27
29
|
├── package.json depends on @cmodjs/core, and lists the hotkeys
|
|
28
30
|
└── tsconfig.json extends .claude-plugin/types/tsconfig.json, with the JSX options
|
|
29
31
|
```
|
|
30
32
|
|
|
31
33
|
`cmod new --project` writes the same files, less `.claude/CLAUDE.md`, into `.claude/skills/<name>/` of the repository.
|
|
32
34
|
|
|
33
|
-
The template is a working example to replace. It counts the prompts of the session in `state.session.prompts`, shows the count below the prompt and in a
|
|
35
|
+
The template is a working example to replace. It counts the prompts of the session in `state.session.prompts`, shows the count below the prompt and in a view that the `alt+shift+p` hotkey shows or hides, and tests all three. Replace the counter, the view, the widget, the component, the Skill, the rule, and the tests with the mod's own.
|
|
34
36
|
|
|
35
37
|
A mod imports `@cmodjs/core` by path, such as `../node_modules/@cmodjs/core/mod.js`, because Claude Code loads a plugin's own files only. Every type a mod writes comes from `@cmodjs/core` too, never from the `claude-code` module. A component returns `JSX.Element` and takes `JSX.Children`, which need no import. Element props, such as `BoxProps` and `Color`, come from `ui/elements.js`. The two types of `register`'s parameters, `AddHook` and `PluginOptions`, come from `register.js`, and the rest from `mod.js`.
|
|
36
38
|
|
|
@@ -40,6 +42,46 @@ A mod imports `@cmodjs/core` by path, such as `../node_modules/@cmodjs/core/mod.
|
|
|
40
42
|
|
|
41
43
|
Claude Code links the types of each plugin the mod depends on, such as `cmod`, into the folder where that plugin is installed. `cmod try` installs the cmod plugin into a home it deletes when the session ends, which leaves those links leading nowhere, so `tsc` alone fails with `Cannot find type definition file for 'cmod'`. `cmod check` deletes a types folder with such a link and has Claude Code write it again.
|
|
42
44
|
|
|
45
|
+
## How cmod is built
|
|
46
|
+
|
|
47
|
+
cmod follows VS Code's extension architecture, with a Claude Code session where VS Code has a window. Each part below is named for cmod, then for its VS Code counterpart:
|
|
48
|
+
|
|
49
|
+
```text
|
|
50
|
+
computer
|
|
51
|
+
├── cmod serve the shared process: one per computer, serves every session on it, holds every program's providers, and carries calls to other devices' cmod serve
|
|
52
|
+
├── a mod's program a language server: one copy per computer, with singleInstance or isService
|
|
53
|
+
│ ├── provide, after connect() registerXProvider, from a program, registered with cmod serve
|
|
54
|
+
│ └── provide('cmod/Devices') a RemoteAuthorityResolver: answers where another device's cmod serve listens, or carries its messages
|
|
55
|
+
└── Claude Code session a window
|
|
56
|
+
└── the session's hooks worker the extension host: loads every mod of the session
|
|
57
|
+
└── mod an extension: 30 sessions run 30 copies of its code
|
|
58
|
+
├── sessions.current window events: the session the mod runs in
|
|
59
|
+
├── state.project workspaceState
|
|
60
|
+
├── state.global globalState
|
|
61
|
+
├── state.memory cmod's own, because VS Code has no conversations
|
|
62
|
+
├── state.session cmod's own, for the same reason
|
|
63
|
+
├── mod.secrets SecretStorage: get, store, delete
|
|
64
|
+
├── options contributed configuration, shown in /config
|
|
65
|
+
├── what setup returns extension exports, called through mod.dependencies
|
|
66
|
+
├── provide registerXProvider, from session code, for its window alone
|
|
67
|
+
├── slash commands commands
|
|
68
|
+
├── hotkeys keybindings
|
|
69
|
+
├── widgets status bar items
|
|
70
|
+
├── views views in a view container
|
|
71
|
+
├── pages editors
|
|
72
|
+
└── panes webviews, which only Claude Code draws
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Each app places a mod's widgets, views, and pages, as each VS Code workbench places an extension's parts: Claude Code, the browser app, and any app that reaches the `cmod/UI` interface ([ui.md](ui.md#every-app-reaches-them-through-cmod-ui)). A mod draws them with cmod's own element data rather than HTML, because Claude Code's terminal draws no HTML.
|
|
76
|
+
|
|
77
|
+
Three parts depart from VS Code:
|
|
78
|
+
|
|
79
|
+
- A mod hears only the session it runs in, as an extension hears only its own window. It also reads and acts on every other session on the computer, through `cmod serve`, and on every session of another device `cmod serve` reaches or a sessions provider serves ([session.md](session.md#sessions-providers)), where an extension reaches no other window. A task that ends on another device reaches the mod as its own task's end.
|
|
80
|
+
- cmod knows an address or a message channel a `cmod/Devices` provider gives, never the transport. The provider opens the link its own way, such as an ssh tunnel, a tailnet, or a relay. It answers a unix socket path or an `http://` URL, which `cmod serve` reaches with its own JSON-RPC over HTTP, or no address, and then carries each JSON-RPC message for that device with its `send` and tells each message from it as `Message`. A VS Code `RemoteAuthorityResolver` answers an address or a `ManagedMessagePassing` that carries bytes. cmod's channel carries whole JSON-RPC messages instead, so a provider frames nothing and every device speaks one protocol ([dependencies.md](dependencies.md#cmod-devices-providers-on-your-other-devices)).
|
|
81
|
+
- `mod.secrets` keeps every mod's secrets as plain values in `secrets.json` in the cmod store, which only the person can read, on every platform, as Claude Code keeps its own login on Linux. VS Code's `SecretStorage` seals them with a key in the keychain or the Secret Service instead, which cmod leaves out because the keychain can raise a prompt that nobody answers on a computer nobody sits at ([mod.md](mod.md#mod-secrets)).
|
|
82
|
+
|
|
83
|
+
cmod runs on every device, as VS Code's Remote Development runs a server on each remote machine. A mod connects the devices when its program provides `cmod/Devices`, which names where each other device's `cmod serve` listens, or carries its messages. `cmod serve` then lists that device's providers beside this computer's and carries each call and listener to the device that holds the provider, as VS Code's window carries each call to a remote extension host ([dependencies.md](dependencies.md#cmod-devices-providers-on-your-other-devices)).
|
|
84
|
+
|
|
43
85
|
## Where a mod runs
|
|
44
86
|
|
|
45
87
|
Mod code runs inside Claude Code's hooks environment, not in Node or Bun. It has no Node or Bun modules, no DOM, and no `import()`: Claude Code refuses a module that holds one. `fs` reaches files, `process` runs programs, `http` reaches the network, and `sessions` reads the conversations, each an import from `mod.js` ([mod.md](mod.md)). `mod.folder` is the plugin's own folder.
|
|
@@ -67,16 +109,17 @@ A program the mod needs lives as source in `cli/`. `cmod publish` builds it and
|
|
|
67
109
|
| Where does my mod keep a token it gets by itself, such as from a sign-in, out of its files? | [mod.md](mod.md#mod-secrets) |
|
|
68
110
|
| How does my mod find files and keep its own keys on each one, such as on a Skill? | [mod.md](mod.md#metadata-a-file-s-own-keys) |
|
|
69
111
|
| How does the person finish a setup step only they can do, such as signing in? | [install-steps.md](install-steps.md#steps-in-claude-code) |
|
|
70
|
-
| How do I add my mod's own
|
|
112
|
+
| How do I add my mod's own view to Settings, or change Claude Code's settings? | [ui.md](ui.md#views-in-settings), [mod.md](mod.md#settings-claude-code-s-settings-files) |
|
|
71
113
|
| How do I give my mod a hotkey the person can change? | [mod.md](mod.md#hotkeys) |
|
|
72
114
|
| How does my mod read and follow this conversation, its tasks, or earlier ones, search them, or start a task? | [session.md](session.md) |
|
|
73
115
|
| How does my mod hear a prompt, a tool call, a permission dialog, or a model switch, and change or refuse it? | [session.md](session.md#listen-to-a-record), [session.md](session.md#the-session-s-own-events) |
|
|
74
116
|
| How does my mod hear, change, or run any slash command, a built-in such as `/compact` included? | [mod.md](mod.md#commands-slash-commands) |
|
|
75
|
-
| How do I draw a
|
|
117
|
+
| How do I draw a view beside the session, a page, a pane, change how Claude Code draws a row, or ask the person something? | [ui.md](ui.md) |
|
|
118
|
+
| How does an app, such as the browser app, list, draw, and press every session's widgets, views, and pages? | [ui.md](ui.md#every-app-reaches-them-through-cmod-ui) |
|
|
76
119
|
| How do I show a status, such as the branch or a CI result, by the prompt, while Claude works, after each turn, or on the Dashboard? | [ui.md](ui.md#widgets) |
|
|
77
120
|
| How do I add a slash command, a tool, a permission rule, a check, a prompt, a schedule, or a background program? | [jobs.md](jobs.md) |
|
|
78
|
-
| How does one mod call another? | [dependencies.md](dependencies.md) |
|
|
79
|
-
| How does a mod change the
|
|
121
|
+
| How does one mod call another, or call whichever mods answer an interface? | [dependencies.md](dependencies.md) |
|
|
122
|
+
| How does a mod change the device, ship a program, or clean up after itself? | [install-steps.md](install-steps.md) |
|
|
80
123
|
| How do I test a mod without Claude Code? | [testing.md](testing.md) |
|
|
81
124
|
| Which `cmod` command links, checks, tries in a clean Claude Code, or publishes a mod? | [commands.md](commands.md) |
|
|
82
125
|
|
|
@@ -89,20 +132,21 @@ A mod imports from the files below, and every other file in this package is inte
|
|
|
89
132
|
| `mod.js` | `defineMod`, `ModDefinition`, `Mod`, `Subscription`, `Timer`, `Reservation`, `JobContext`, `Job`, `SlashCommand`, `Tool`, `Step`, `longestMs`, `messageOf` | [mod.md](mod.md), [jobs.md](jobs.md), [install-steps.md](install-steps.md#steps-in-claude-code) |
|
|
90
133
|
| `mod.js` | `Hotkey`, `HotkeyInit`, `Combo`, `Key` | [mod.md](mod.md#hotkeys) |
|
|
91
134
|
| `mod.js` | `settings`, `Settings`, `SettingsFile`, `SettingsFileChange`, `SettingsFileChangeListener`, `config`, `ConfigRow`, `commands`, `CommandInfo`, `CommandRun`, `CommandRunAnswer`, `CommandRunResult`, `model`, `ModelCompleteRequest`, `ModelCompleteOptions`, `ModelCompleteResult`, `fs`, `Entry`, `Stat`, `StatOptions`, `FileMatch`, `FileChange`, `metadata`, `Metadata`, `process`, `ProcessRunOptions`, `ProcessRunResult`, `ProcessSpawnOptions`, `Subprocess`, `http`, `HttpOptions`, `HttpResponse`, `clipboard`, `AskOptions`, `Imports` | [mod.md](mod.md) |
|
|
92
|
-
| `mod.js` | `sessions`, `Sessions`, `Session`, `CurrentSession`, `TaskOwner`, `RecordPart`, `OnMethods`, `BeforeMethods`, `Listener`, `ListenerTime`, `ReadOptions`, `AnswerOptions`, `Refusal`, `SearchOptions`, `SessionScope`, `SessionSend`, `TaskStartArgs`, `ToolCallArgs`, `Usage`, `RateLimit`, `TaskStatus`, `Surface`, `Matcher` | [session.md](session.md) |
|
|
135
|
+
| `mod.js` | `sessions`, `Sessions`, `Session`, `CurrentSession`, `TaskOwner`, `RecordPart`, `OnMethods`, `BeforeMethods`, `Listener`, `ListenerTime`, `ReadOptions`, `AnswerOptions`, `Refusal`, `SearchOptions`, `SessionScope`, `SessionSend`, `TaskStartArgs`, `ForkArgs`, `ToolCallArgs`, `Usage`, `RateLimit`, `TaskStatus`, `Surface`, `Matcher` | [session.md](session.md) |
|
|
93
136
|
| `mod.js` | `Placement`, `ProjectSetup`, `SessionStartAsked`, `SessionStarted`, `SessionEnded`, `ModelChange`, `CwdChange`, `DirectoryAdd`, `Worktree`, `Notification`, `Elicitation`, `ElicitationResponse`, `McpServer`, `PermissionUpdate`, `PermissionCheck`, `PermissionRequest`, `PermissionDenial`, `BatchedCall`, `ToolBatch`, `Todo`, `ReplyDisplay` | [session.md](session.md#the-session-s-own-events) |
|
|
94
137
|
| `mod.js` | `Message`, `MessageType`, `Prompt`, `Note`, `Reply`, `ToolCall`, `ToolResult`, `Skill`, `InstructionFile`, `AttachedFile`, `AttachmentType`, `Notice`, `Sender`, `SenderType`, `Person`, `Mod`, `Schedule`, `Channel`, `Sdk`, `Engine` | [session.md](session.md#message) |
|
|
95
138
|
| `mod.js` | `Context`, `Turn`, `Goal`, `Task` | [session.md](session.md#turn-context-goal-and-task) |
|
|
96
139
|
| `mod.js` | `Toast`, `ToastId`, `ToastType`, `ToastOptions` | [ui.md](ui.md#toasts) |
|
|
97
|
-
| `mod.js` | `PageInit`, `Page`, `PageProps`, `PaneInit`, `Pane`, `PaneProps`, `PaneScroll`, `PaneClose`, `OpenOptions`, `ScrollTarget`, `ScrollOptions` | [ui.md](ui.md#
|
|
140
|
+
| `mod.js` | `ViewInit`, `View`, `ViewProps`, `PageInit`, `Page`, `PageProps`, `PaneInit`, `Pane`, `PaneProps`, `PaneScroll`, `PaneClose`, `OpenOptions`, `ScrollTarget`, `ScrollOptions` | [ui.md](ui.md#views-and-pages) |
|
|
98
141
|
| `mod.js` | `WidgetInit`, `Widget`, `WidgetContext`, `Area`, `AbovePrompt`, `BelowPrompt`, `Working`, `TurnEnd`, `Dashboard` | [ui.md](ui.md#widgets) |
|
|
99
142
|
| `mod.js` | `StyleInit`, `Style`, `StyleProps`, `Kind`, `Row`, `Block`, `ToolGroup`, `ToolProgress`, `CommandOutput`, `AskUserQuestion` | [ui.md](ui.md#styles-change-how-claude-code-draws) |
|
|
100
|
-
| `mod.js` | `notInstalled` | [dependencies.md](dependencies.md) |
|
|
143
|
+
| `mod.js` | `notInstalled`, `provide`, `Provided`, `providers`, `InterfaceName`, `InterfaceMethods`, `InterfaceProvider`, `ProviderOn`, `ProviderBefore`, `ProviderListenOptions` | [dependencies.md](dependencies.md) |
|
|
101
144
|
| `register.js` | `registerMod`, `registerPermissionCheck`, `registeredMod`, `AddHook`, `PluginOptions` | [mod.md](mod.md) |
|
|
145
|
+
| `rpc.js` | `connect`, `Connection`, `NotHeld` | [dependencies.md](dependencies.md#connect-a-program-s-connection-to-cmod-serve) |
|
|
102
146
|
| `options.js` | `option`, `Option`, `Options`, `OptionValues`, `OptionValue`, `OptionType`, `UserConfigField`, `userConfigOf` | [options.md](options.md) |
|
|
103
147
|
| `shell.js` | `parseShell`, `ParsedShell`, `ShellCommand` | [mod.md](mod.md#shell-js-and-path-js-read-a-command-line) |
|
|
104
148
|
| `path.js` | `resolve`, `join`, `dirname`, `basename`, `extname`, `relative`, `isAbsolute`, `normalize` | [mod.md](mod.md#shell-js-and-path-js-read-a-command-line) |
|
|
105
|
-
| `testing.js` | `testMod`, `TestOptions`, `TestedMod`, `Raise`, `Fakes`, `Shown`, `ShownToast`, `TestCall`, `FakeSession`, `MessageDraft`, `RoutedEvent` | [testing.md](testing.md) |
|
|
149
|
+
| `testing.js` | `testMod`, `TestOptions`, `TestedMod`, `Raise`, `Fakes`, `Shown`, `ShownToast`, `TestCall`, `FakeSession`, `FakeProvider`, `MessageDraft`, `RoutedEvent` | [testing.md](testing.md) |
|
|
106
150
|
| `ui/elements.js` | `Box`, `Text`, `Button`, `Code`, `Markdown`, `Input`, `Select`, `Image`, `Raster`, `Svg`, `Client`, `drawWith` | [ui.md](ui.md) |
|
|
107
151
|
| `ui/elements.js` | `BoxProps`, `TextProps`, `ButtonProps`, `CodeProps`, `MarkdownProps`, `InputProps`, `SelectProps`, `ImageProps`, `RasterProps`, `SvgProps`, `ClientProps`, `Color`, `Press` | [ui.md](ui.md#elements) |
|
|
108
152
|
| `ui/components.js` | `Tabs`, `Tab`, `Split`, `Panel`, `Toggle`, `Tooltip`, `Help`, `Dialog`, `Pagination`, `Progress` | [ui.md](ui.md) |
|
package/docs/install-steps.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Install steps
|
|
2
2
|
|
|
3
|
-
A mod that changes the
|
|
3
|
+
A mod that changes the device, such as by adding a shell alias or downloading a program, names its install and uninstall steps in its `package.json`. The cmod program of Claude Mod Manager (cmod) runs the install step when the person installs the mod, and the uninstall step after the person removes it. The library never runs them.
|
|
4
4
|
|
|
5
5
|
## The cmod key
|
|
6
6
|
|
|
@@ -51,7 +51,7 @@ In Claude Code, the mod sets itself up through the `cmod` program the cmod plugi
|
|
|
51
51
|
|
|
52
52
|
## Steps in Claude Code
|
|
53
53
|
|
|
54
|
-
Some setup only the person can do, such as signing in to a service. A mod lists those steps in `installer`, and its install
|
|
54
|
+
Some setup only the person can do, such as signing in to a service. A mod lists those steps in `installer`, and its install view shows each one after the options, once the mod has started:
|
|
55
55
|
|
|
56
56
|
```tsx
|
|
57
57
|
import { defineMod, type Step } from '../node_modules/@cmodjs/core/mod.js'
|
|
@@ -72,16 +72,16 @@ export const myMod = defineMod({ name: 'my-mod', installer: [signIn], setup(mod)
|
|
|
72
72
|
type Step<State> = {
|
|
73
73
|
readonly id: string
|
|
74
74
|
readonly title: string
|
|
75
|
-
render(mod: Mod<State>, props:
|
|
75
|
+
render(mod: Mod<State>, props: ViewProps<undefined>): JSX.Element
|
|
76
76
|
isDone(mod: Mod<State>): boolean | Promise<boolean>
|
|
77
77
|
}
|
|
78
78
|
```
|
|
79
79
|
|
|
80
80
|
- `id` is 1 to 64 letters, digits, `_`, or `-`, unique among the steps. `title` is the line above the step, with `(1 of 2)`. `defineMod` throws for an id that is not one, a blank title, or two steps with one id.
|
|
81
|
-
- `render` draws the step's body, the way a
|
|
82
|
-
- `isDone` says whether the step is finished. A step that is done is skipped, so the
|
|
81
|
+
- `render` draws the step's body, the way a view's `render` does, with the elements a view draws ([ui.md](ui.md#views-and-pages)). Give the step a `Button` that does the work or opens the place to do it, never a command to type.
|
|
82
|
+
- `isDone` says whether the step is finished. A step that is done is skipped, so the view opens only for what is left. `Next` checks `isDone`, and shows `Finish <title> first.` while it is false. The last step's button says `Finish`.
|
|
83
83
|
- An `isDone` that throws or rejects opens no step: the mod shows `The <title> step's isDone failed` with the error, and the step stays listed as left to do. Pressed on a step already open, `Next` shows `The <title> step's isDone failed: <error>`.
|
|
84
|
-
- `Not now` closes the
|
|
84
|
+
- `Not now` closes the view, and the mod keeps running. A toast stays above the prompt, `Needs one more step` with `Starting with <title>.` under it, and its `Finish` button opens the view on the first step left. Settings shows `Needs setup: <title>` with a `Finish setup` button too.
|
|
85
85
|
|
|
86
86
|
## Hotkeys
|
|
87
87
|
|
|
@@ -93,8 +93,8 @@ A plugin cannot bind a key in Claude Code: Claude Code reads key bindings only f
|
|
|
93
93
|
|
|
94
94
|
- cmod writes each combo into the `Chat` bindings of `~/.claude/keybindings.json`, or of `$CLAUDE_CONFIG_DIR/keybindings.json` when that variable is set. When the file is a symbolic link, cmod writes the file it points to. Claude Code reads the change at once, with no restart.
|
|
95
95
|
- A combo the person already bound to something else stays theirs, and the hotkey has no combo. The person picks one in Settings, under the mod, Hotkeys.
|
|
96
|
-
- A hotkey without a default combo binds nothing at setup. Settings lists it as unbound, and the person binds it there or with `cmod
|
|
97
|
-
- The combo the person picks in Settings runs `cmod
|
|
96
|
+
- A hotkey without a default combo binds nothing at setup. Settings lists it as unbound, and the person binds it there or with `cmod hotkeys set`.
|
|
97
|
+
- The combo the person picks in Settings runs `cmod hotkeys set <mod> <hotkey> <combo>`. An update keeps the combo each hotkey has in `keybindings.json`, whether Settings or the person's own edit bound it ([commands.md](commands.md#cmod-hotkeys)).
|
|
98
98
|
- An upgrade that drops a hotkey removes its binding. Removing the mod removes every binding that runs one of its hotkeys, and a `Chat` block that leaves empty. A binding the person moved to another action stays.
|
|
99
99
|
- A hotkey bound to `shift+tab` replaces Claude Code's own mode switch, and Claude Code then drops its `shift+tab` hint.
|
|
100
100
|
|
|
@@ -107,7 +107,8 @@ The step gets these environment variables:
|
|
|
107
107
|
| Variable | Value |
|
|
108
108
|
| --- | --- |
|
|
109
109
|
| `CMOD_PLUGIN_ROOT` | The mod's folder |
|
|
110
|
-
| `CMOD_DATA` | The mod's data folder, which cmod creates first. It is the folder `mod.dataFolder` names. |
|
|
110
|
+
| `CMOD_DATA` | The mod's data folder, which cmod creates first. It is the folder `mod.dataFolder` names. It holds what the mod cannot build again. |
|
|
111
|
+
| `CMOD_CACHE` | The mod's cache folder, which cmod creates first. It is the folder `mod.cacheFolder` names. It holds what the mod can build or download again, such as a program `cmod download` fetches. |
|
|
111
112
|
| `CMOD_VERSION` | The mod's version from `plugin.json` |
|
|
112
113
|
| `PATH` | The person's `PATH`, with the cmod program's own folder first, so the step can run `cmod download`, then cmod's programs folder |
|
|
113
114
|
|
|
@@ -135,8 +136,8 @@ When the install step succeeds, cmod saves a copy of every script folder the uni
|
|
|
135
136
|
- After the person removes the mod with `/plugin uninstall`, the cmod plugin runs the uninstall step at the next session start or prompt.
|
|
136
137
|
- `cmod remove <mod>` uninstalls the mod and runs the step at once.
|
|
137
138
|
- The step runs only once Claude Code has no copy of the mod left. When `cmod remove`, `cmod unlink`, or `/plugin uninstall` takes away one copy and another stays, such as an installed copy beside a linked checkout, cmod sets up the copy that stays and keeps the mod's data and secrets.
|
|
138
|
-
- In the copy, `CMOD_PLUGIN_ROOT` is the copy's folder, and `CMOD_DATA` and `CMOD_VERSION` are the same as at install.
|
|
139
|
-
- After the step, cmod deletes the mod's install record, its program, its data folder, and the approvals of its scripts. It keeps the mod's config folders, because the files there are the person's.
|
|
139
|
+
- In the copy, `CMOD_PLUGIN_ROOT` is the copy's folder, and `CMOD_DATA`, `CMOD_CACHE`, and `CMOD_VERSION` are the same as at install.
|
|
140
|
+
- After the step, cmod deletes the mod's install record, its program, its data folder, its cache folder, and the approvals of its scripts. It keeps the mod's config folders, because the files there are the person's.
|
|
140
141
|
- A failed uninstall step keeps the record. `cmod teardown <mod>` runs it again.
|
|
141
142
|
|
|
142
143
|
## Example
|
|
@@ -172,9 +173,11 @@ cmod deletes `$CMOD_DATA` itself after the uninstall step.
|
|
|
172
173
|
cmod download <program> <machine> <url> <sha256> [<machine> <url> <sha256> …]
|
|
173
174
|
```
|
|
174
175
|
|
|
175
|
-
An install script runs `cmod download` to fetch a program built by someone else. It picks the download for this machine, checks its SHA-256, unpacks a `.tar.gz` or a `.zip` or takes the file as it is, and moves the file named `<program>` to `$
|
|
176
|
+
An install script runs `cmod download` to fetch a program built by someone else. It picks the download for this machine, checks its SHA-256, unpacks a `.tar.gz` or a `.zip` or takes the file as it is, and moves the file named `<program>` to `$CMOD_CACHE/bin/<program>`, which Claude Code then runs by its name. The program goes in the cache folder because cmod can download it again, and a program built for one machine is no use on another. A download whose SHA-256 differs installs nothing. Machines are `darwin-arm64`, `darwin-x64`, `linux-arm64`, and `linux-x64`.
|
|
176
177
|
|
|
177
|
-
|
|
178
|
+
Run the program by its name. cmod links it into its programs folder, so mod code runs it as `process.run(['mermaid-ascii', '--help'])`, and the `command` of a `program` job names it as `['mermaid-ascii']` ([Run a program by its name](#run-a-program-by-its-name)).
|
|
179
|
+
|
|
180
|
+
cmod 7 put the program at `$CMOD_DATA/bin/<program>`, `${mod.dataFolder}/bin/<program>` in mod code, and that path still runs it: `cmod download` links it to the file in the cache folder. When cmod 8 sets the mod up, it moves each program cmod 7 downloaded to the cache folder and leaves that link in its place. It moves no other file in `$CMOD_DATA/bin/`, so a file the install step wrote there itself stays where it is.
|
|
178
181
|
|
|
179
182
|
```sh
|
|
180
183
|
cmod download mermaid-ascii \
|
|
@@ -211,10 +214,10 @@ Then:
|
|
|
211
214
|
|
|
212
215
|
## Run a program by its name
|
|
213
216
|
|
|
214
|
-
cmod links every program it installs into its programs folder, `~/.local/share/cmod/programs/<program>` (under `$XDG_DATA_HOME` when it is set): the program `cmod.program` names, each program `cmod download` installs, and `cmod` itself. Claude Code runs the one there by its name, whatever else `PATH` holds, so a mod's `
|
|
217
|
+
cmod links every program it installs into its programs folder, `~/.local/share/cmod/programs/<program>` (under `$XDG_DATA_HOME` when it is set): the program `cmod.program` names, each program `cmod download` installs, and `cmod` itself. Claude Code runs the one there by its name, whatever else `PATH` holds, so a mod's `hello` wins over `/usr/bin/hello`:
|
|
215
218
|
|
|
216
219
|
- The cmod plugin's `SessionStart` hook puts the programs folder first on `PATH` for every Bash command Claude runs.
|
|
217
|
-
- `process.run` and `process.spawn` run `[name, ...args]` from the programs folder when it holds `name`. A path such as `/usr/bin/
|
|
220
|
+
- `process.run` and `process.spawn` run `[name, ...args]` from the programs folder when it holds `name`. A path such as `/usr/bin/hello` runs as given.
|
|
218
221
|
- Install and uninstall steps find the programs folder on `PATH` after cmod's own `bun`.
|
|
219
222
|
|
|
220
223
|
cmod also links the program into `~/.local/bin/<program>` so a terminal runs it, unless a file there is not cmod's. Setup then logs which program a terminal runs, and changes nothing outside cmod's folders.
|
|
@@ -224,10 +227,10 @@ cmod also links the program into `~/.local/bin/<program>` so a terminal runs it,
|
|
|
224
227
|
A mod runs on macOS and Linux, on arm64 and x64, unless the `os` and `cpu` keys of its `package.json` say less. They read as npm reads them, and a `!` in front leaves a value out:
|
|
225
228
|
|
|
226
229
|
```json
|
|
227
|
-
{ "name": "
|
|
230
|
+
{ "name": "my-mod", "os": ["darwin"], "cpu": ["arm64"] }
|
|
228
231
|
```
|
|
229
232
|
|
|
230
|
-
- Setup refuses a machine the mod leaves out before any script runs, with `
|
|
233
|
+
- Setup refuses a machine the mod leaves out before any script runs, with `my-mod runs on macOS on arm64, and this is Linux, so cmod set up nothing.`, in the terminal and in the mod's error toast in Claude Code.
|
|
231
234
|
- `cmod publish` builds the program for each machine the mod runs on.
|
|
232
235
|
- `cmod check` fails when a `cmod download` line in the install step has no download for one of those machines, and when `os` or `cpu` names a value cmod does not run mods on, such as `win32`.
|
|
233
236
|
|