@cmodjs/core 8.9.1 → 8.10.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 +13 -11
- package/docs/dependencies.md +6 -3
- package/docs/index.md +1 -1
- package/docs/jobs.md +1 -1
- package/docs/mod.md +1 -1
- package/docs/session.md +8 -7
- package/docs/testing.md +2 -2
- package/docs/ui.md +6 -5
- package/jobs/program.d.ts.map +1 -1
- package/jobs/program.js +5 -4
- package/mod.d.ts +34 -5
- package/mod.d.ts.map +1 -1
- package/package.json +1 -1
- package/records.d.ts +4 -2
- package/records.d.ts.map +1 -1
- package/records.js +6 -3
- package/register.d.ts.map +1 -1
- package/register.js +14 -5
- package/rpc.d.ts.map +1 -1
- package/rpc.js +1 -0
- package/runtime/bun.d.ts +7 -2
- package/runtime/bun.d.ts.map +1 -1
- package/runtime/bun.js +61 -7
- package/runtime/conversations.d.ts +3 -1
- package/runtime/conversations.d.ts.map +1 -1
- package/runtime/conversations.js +43 -36
- package/runtime/device.d.ts +2 -1
- package/runtime/device.d.ts.map +1 -1
- package/runtime/device.js +22 -1
- package/runtime/drawing-rules.d.ts +9 -0
- package/runtime/drawing-rules.d.ts.map +1 -0
- package/runtime/drawing-rules.js +46 -0
- package/runtime/engine.d.ts +3 -1
- package/runtime/engine.d.ts.map +1 -1
- package/runtime/hooks.d.ts +1 -1
- package/runtime/hooks.d.ts.map +1 -1
- package/runtime/hotkeys.d.ts.map +1 -1
- package/runtime/hotkeys.js +0 -7
- package/runtime/installer.js +3 -3
- package/runtime/interfaces.d.ts +47 -8
- package/runtime/interfaces.d.ts.map +1 -1
- package/runtime/interfaces.js +151 -15
- package/runtime/lifecycle.d.ts.map +1 -1
- package/runtime/lifecycle.js +61 -29
- package/runtime/parts.d.ts +2 -2
- package/runtime/parts.d.ts.map +1 -1
- package/runtime/parts.js +61 -35
- package/runtime/rpc.d.ts +11 -3
- package/runtime/rpc.d.ts.map +1 -1
- package/runtime/rpc.js +56 -19
- package/runtime/sessions.d.ts +2 -1
- package/runtime/sessions.d.ts.map +1 -1
- package/runtime/sessions.js +11 -4
- package/runtime/ui.d.ts +1 -0
- package/runtime/ui.d.ts.map +1 -1
- package/runtime/ui.js +62 -45
- package/runtime/widgets.d.ts +4 -2
- package/runtime/widgets.d.ts.map +1 -1
- package/runtime/widgets.js +6 -5
- package/session/session.d.ts +5 -1
- package/session/session.d.ts.map +1 -1
- package/src/jobs/program.ts +5 -4
- package/src/mod.ts +12 -4
- package/src/records.ts +8 -4
- package/src/register.ts +15 -5
- package/src/rpc.ts +2 -1
- package/src/runtime/bun.ts +58 -6
- package/src/runtime/conversations.ts +45 -36
- package/src/runtime/device.ts +21 -1
- package/src/runtime/drawing-rules.ts +42 -0
- package/src/runtime/engine.ts +3 -1
- package/src/runtime/hooks.ts +0 -1
- package/src/runtime/hotkeys.ts +0 -7
- package/src/runtime/installer.ts +3 -3
- package/src/runtime/interfaces.ts +187 -22
- package/src/runtime/lifecycle.ts +63 -29
- package/src/runtime/parts.ts +61 -33
- package/src/runtime/rpc.ts +65 -20
- package/src/runtime/sessions.ts +11 -5
- package/src/runtime/ui.ts +61 -38
- package/src/runtime/widgets.ts +9 -5
- package/src/session/session.ts +3 -1
- package/src/testing/fake-elements.ts +7 -23
- package/src/testing/fake-serve.ts +51 -9
- package/src/testing/fake-sessions.ts +5 -3
- package/src/testing.ts +9 -3
- package/src/ui/components.ts +13 -14
- package/src/ui/elements.ts +4 -4
- package/src/ui/palette.ts +38 -0
- package/src/ui/styles.ts +2 -0
- package/testing/fake-elements.d.ts.map +1 -1
- package/testing/fake-elements.js +9 -26
- package/testing/fake-serve.d.ts +6 -1
- package/testing/fake-serve.d.ts.map +1 -1
- package/testing/fake-serve.js +42 -5
- package/testing/fake-sessions.d.ts +1 -0
- package/testing/fake-sessions.d.ts.map +1 -1
- package/testing/fake-sessions.js +4 -2
- package/testing.d.ts.map +1 -1
- package/testing.js +12 -4
- package/ui/components.d.ts.map +1 -1
- package/ui/components.js +12 -13
- package/ui/elements.d.ts +2 -1
- package/ui/elements.d.ts.map +1 -1
- package/ui/elements.js +3 -3
- package/ui/palette.d.ts +17 -0
- package/ui/palette.d.ts.map +1 -0
- package/ui/palette.js +20 -0
- package/ui/styles.d.ts +1 -0
- package/ui/styles.d.ts.map +1 -1
- package/ui/styles.js +1 -0
package/docs/commands.md
CHANGED
|
@@ -144,7 +144,7 @@ It needs, and refuses to start without:
|
|
|
144
144
|
|
|
145
145
|
## Install mods
|
|
146
146
|
|
|
147
|
-
`cmod install`, `cmod update`, `cmod remove`, `cmod enable`, `cmod disable`, `cmod link`, `cmod unlink`, and `cmod try` write the time to `plugins-changed` in the cmod store, then write `store-changed` beside it, when they finish, also when they fail partway, such as an update that updated some mods.
|
|
147
|
+
`cmod install`, `cmod update`, `cmod remove`, `cmod enable`, `cmod disable`, `cmod link`, `cmod unlink`, and `cmod try` write the time to `plugins-changed` in the cmod store, then write `store-changed` beside it and tell `cmod serve` that the plugins changed, when they finish, also when they fail partway, such as an update that updated some mods. `cmod serve` tells the cmod plugin of every running session through `cmod/Store` ([dependencies.md](dependencies.md#interfaces-several-mods-answer-one-name)), and tells it the same when Claude Code's `installed_plugins.json` changes, so the session reads them again, and reads the `enabledPlugins` of the user's `settings.json` each time Claude Code reports that file changed and at each prompt, whether a `cmod` command, `/plugin`, `claude plugin`, or Claude Code's automatic update changed them. While `plugins-changed`, `installed_plugins.json`, or `enabledPlugins` differs from what the session loaded, the session keeps running the plugins it loaded and shows one `Plugins changed` toast with a Reload button. It names each change, such as `my-mod updated to 1.3.0` or `my-mod turned on`, or counts them past 3, and each further change updates the same toast. The person presses Reload, which runs `/reload-plugins`, or when the turn ends if Claude is working, and the prompt the person is typing stays. A change back to what the session loaded, or the person's own `/reload-plugins`, takes the toast away. A session no app shows, such as `claude -p`, shows nothing. A reload keeps the prompt cache: the next request reads the whole conversation from the cache and pays only for the plugins' new content. A reload clears each mod's `memory` state. A device where cmod set up no mod has no store, and these commands write nothing there.
|
|
148
148
|
|
|
149
149
|
### cmod install
|
|
150
150
|
|
|
@@ -212,8 +212,9 @@ cmod sessions read tasks [<session>] [--task <id> | --nested] [--json]
|
|
|
212
212
|
cmod sessions read goal [<session>] [--task <id>] [--json]
|
|
213
213
|
cmod sessions read usage [<session>] [--task <id>] [--json]
|
|
214
214
|
cmod sessions read state [<session>] [--json]
|
|
215
|
+
cmod sessions read mail [<session>] [--last <n>] [--json]
|
|
215
216
|
cmod sessions read <part> <session> --transcripts <folder> [--json]
|
|
216
|
-
cmod sessions send <session> <text> [--note]
|
|
217
|
+
cmod sessions send <session> <text> [--note] [--reply-to <mail>]
|
|
217
218
|
cmod sessions start <prompt> --title <title> [--agent-type <type>] [--model <model>] [--cwd <folder>] [--device <name>] [--json]
|
|
218
219
|
cmod sessions fork <prompt> --title <title> [--session <id>] [--at <message>] [--json]
|
|
219
220
|
cmod sessions stop <session>
|
|
@@ -224,9 +225,9 @@ cmod sessions follow [<session>...] [--running] [--json]
|
|
|
224
225
|
cmod sessions index
|
|
225
226
|
```
|
|
226
227
|
|
|
227
|
-
Reads every conversation Claude Code saved, as the sessions, contexts, turns, tasks, and messages `sessions` answers a mod ([session.md](session.md)), and acts on them, so a person or an agent reads and drives them in a terminal as a mod does. `list`, `search`, `read`, and each action go through `cmod serve`, as a mod's `sessions` import does, so they reach the sessions of this computer and of each device a sessions provider serves. A `<session>` left out is the one the command runs in, which Claude Code names in `CLAUDE_CODE_SESSION_ID`.
|
|
228
|
+
Reads every conversation Claude Code saved, as the sessions, contexts, turns, tasks, and messages `sessions` answers a mod ([session.md](session.md)), and acts on them, so a person or an agent reads and drives them in a terminal as a mod does. `list`, `search`, `read`, and each action go through `cmod serve`, as a mod's `sessions` import does, so they reach the sessions of this computer and of each device a sessions provider serves. A `<session>` is the id `list` prints, or any start of it that no other session shares, as git takes a commit, and a start two sessions share fails and lists both. A `<session>` left out is the one the command runs in, which Claude Code names in `CLAUDE_CODE_SESSION_ID`.
|
|
228
229
|
|
|
229
|
-
- `list` lists the conversations of the current folder's project, or `--project`'s, newest first, each with its time, id, title, whether it runs or waits on a dialog, and its device. `--every-project` lists every project's, `--since` keeps those active in the last `30m`, `6h`, `2d`, or `1w`, or since a date such as `2026-10-01`, and `--running` keeps those open in Claude Code now.
|
|
230
|
+
- `list` lists the conversations of the current folder's project, or `--project`'s, newest first, each with its time, id, title, whether it runs or waits on a dialog, and its device. `--every-project` lists every project's, `--since` keeps those active in the last `30m`, `6h`, `2d`, or `1w`, or since a date such as `2026-10-01`, and `--running` keeps those open in Claude Code now, in every project unless `--project` names one, as `hc ls` lists every live terminal.
|
|
230
231
|
- `search` prints the newest 50 messages whose text or tool input contains the text, at least 3 characters, any case, each with its time, session, message id, and the words around the match, and leaves out earlier `cmod sessions search` calls. Each tool input value is searched in its first 1,024 characters, and tool results are not searched. `--every-project`, `--since`, and `--running` scope it as they scope `list`, `--limit` changes the 50, and `--before <session>:<id>` prints the page after the message it names, the last one of the page before. `--session` searches one conversation, and inside it `--task` searches a task and the tasks it started, `--turn` one turn, `--context` one context, and `--agent` keeps the main agent's messages, or with `--task` that task's own, without the tasks it started.
|
|
231
232
|
- `read messages` prints one conversation's messages in order, each with its id: the session named, or the one the command runs in when Claude Code runs it. `--task` reads a task's messages instead, `--turn` keeps one turn's, `--after` starts after a message id, and `--last` keeps that many from the end.
|
|
232
233
|
- `read turns` prints the conversation's turns, each opened by a prompt and closed when Claude finishes. `--context` keeps one context's, and `--last` keeps that many from the end. With `--json`, a turn names the `device` it ran on, as `Turn.device` does ([session.md](session.md#turn-context-goal-and-task)).
|
|
@@ -237,7 +238,8 @@ Reads every conversation Claude Code saved, as the sessions, contexts, turns, ta
|
|
|
237
238
|
- `--task` reads the `turns`, `contexts`, `goal`, and `usage` of the session a task's owner runs, the way they read the conversation's.
|
|
238
239
|
- `read state` prints what a running conversation on this computer resumes from. It reads the index without writing to it, so it never waits for another cmod that is writing the index.
|
|
239
240
|
- `read --transcripts <folder>` reads the conversation from the transcripts in `<folder>/projects`, a Claude Code folder such as one copied from a computer that is off, through an index of its own that lives only while the command runs. So the index of this computer's conversations never lists it, and a mod that serves another device's sessions answers `cmod/Sessions` `read` in cmod's own shapes. It takes every flag each part takes.
|
|
240
|
-
- `
|
|
241
|
+
- `read mail` prints the mail sent to the session and sent by it, oldest first, each with its time, id, whether it is `delivered` or still `queued`, its sender and recipient, and its first line. `--last` keeps that many from the end.
|
|
242
|
+
- `send` sends the session a prompt, which it answers as its next turn, or with `--note` a note it reads with its next prompt, and prints `Delivered message <id> to session <id start> (<title>).`, or `Queued message <id> for session <id start> (<title>).` with why it waits: the session's cmod plugin has not reached `cmod serve`, as when Claude Code turns a session's mods off after its hooks worker crashes, and it gets the message once the session is resumed. The `cmod serve` of the session's device stores the mail in `mail.sqlite` in the cmod store before it delivers it, so a restart of either side never drops it, and the session's cmod plugin gets each queued mail, in order, when it reaches `cmod serve` again. Inside Claude Code the mail goes from this session: the session reads it inside `<cmod-message from="<id>" title="<title>" reply="cmod sessions send <id start> --reply-to <mail>">`, which names this session and the command that answers it. `--reply-to <mail>` marks the mail as the answer to that one. A session that ended resumes on the prompt.
|
|
241
243
|
- `start` starts a background session on a task this session owns, and `fork` one on a copy of this conversation, or of `--session`'s, whole or through the message `--at` names, owned by the session it copies. Each prints the task, as one line of JSON with `--json`. `--agent-type`, `--model`, `--cwd`, and `--device` pick a started session's agent, model, folder, and device.
|
|
242
244
|
- `stop` stops the session's running turn, as Esc does. `end` ends its Claude Code once its turn ends. `compact` compacts its conversation once its turn ends, keeping what `--keep` names, then prompts Claude to carry on, and waits for the next turn when the person stopped this one with Esc. `delete` deletes a session that ended.
|
|
243
245
|
- `follow` prints each message, turn, context, task, and goal change of this computer's sessions named as Claude Code saves it, until stopped with Ctrl+C. `--running` follows every running session of the project too, and each one that starts later.
|
|
@@ -310,7 +312,7 @@ Opens the browser app at `http://127.0.0.1:<port>/` and prints that address. The
|
|
|
310
312
|
cmod watch
|
|
311
313
|
```
|
|
312
314
|
|
|
313
|
-
Tells every running session once a checkout `cmod link` linked builds after a change, so each one still running the old build offers Reload. It watches each linked folder, outside `node_modules` and `.git
|
|
315
|
+
Tells every running session once a checkout `cmod link` linked builds after a change, so each one still running the old build offers Reload. It watches each file git lists in a linked folder, or each file outside `node_modules` and `.git` when the folder is no git repository. It compares each file's modification time and size with its last look whenever a file event hints at a change, every 400 ms for a minute after a change, and every 30 seconds after that, because macOS drops file events under load. It skips a change to a file git ignores, such as the `.claude-plugin/types/` Claude Code writes each time it loads the mod, a change inside the program's `output` folder, and a change to a file that is gone again and git does not track, such as a build's temporary file. Once a folder has had no change for 2 seconds, it bundles the mod's hooks module as `cmod publish` does. When a changed file is one the program's build reads, a file in `cli/` or one the JavaScript or TypeScript file `cli/package.json` `bin` names imports, such as the mod's own `src/`, it also builds the program `cli/` declares and links it as `cmod link` does, so the program in cmod's programs folder is never older than the mod. A change no program build reads builds no program. A program whose build failed builds again at the next change, whatever it changed. A build that changes the program stops its running copy, so a `singleInstance` or `isService` program restarts on the new build ([cmod program](#cmod-program)), and a build that writes the same program leaves the file and the copy as they are. A mod that builds writes the time of its last change to `plugins-changed`, then tells `cmod serve` through `cmod/Store`. A session that has not started the mod since then shows the `Plugins changed` toast once 35 seconds passed since the change and no turn runs, the time Claude Code takes at most to restart a `--plugin-dir` copy by itself, and no session reloads by itself. A bundle or program build that still fails 10 seconds after the last change is written to `build-failures.json`, told through `cmod/Store` too, and shows `<mod> does not build` with the error as one toast in each session working inside the checkout, the last program that built keeps running, and the toast goes once the mod builds. So an agent's half-written file offers nothing and shows nothing. At its start it bundles again each mod whose failure it finds in `build-failures.json`, so a failure an older cmod wrote goes once the mod builds. The cmod plugin starts one only in a session that an app shows, once a mod is linked, at the session's start or later, so a device with no linked mod runs none. The first holds `watch.lock` in the cmod store, watches, and touches its file there every 5 seconds. Another one exits at once while it runs, and the cmod plugin of each such session starts one again once that file is gone or 15 seconds old, so a device runs one watcher however many sessions it has open. Once it listens to `cmod serve`, or finds no `cmod serve` to reach, each time it connects again or loses `cmod serve`, and on each `cmod/Store` change of the links or the plugins, it reads the linked folders and the newest cmod in the cmod store, the newest version folder of `bin/cmod` that the launcher runs. The launcher tells that a newer cmod landed, as a `cmod/Store` change of the plugins, the first time it runs it. A `cmod watch` older than that exits and lets go of `watch.lock`, so after a cmod update the new cmod's watcher judges the linked mods by its own rules. It also exits once the process that started it ends, so a session that crashed leaves no watcher behind.
|
|
314
316
|
|
|
315
317
|
A cmod before 4.1.0 linked a checkout by writing it into `CLAUDE_CODE_PLUGIN_DIRS` in the `env` block of Claude Code's `settings.json`. `cmod watch` at its start, and `cmod setup`, link each folder still in that list as `cmod link` does now and take it out of the list. A folder that fails to link stays in the list, and its error prints on stderr.
|
|
316
318
|
|
|
@@ -433,11 +435,11 @@ Starts a task in a new background Claude Code session, for a mod's `startTask` w
|
|
|
433
435
|
cmod program <mod> [--web-app] [--no-wait | --service [--env <name>]... [--process-type <type>] | --remove-service] -- <command…>
|
|
434
436
|
```
|
|
435
437
|
|
|
436
|
-
Runs one copy of a mod's program for the whole computer, for a `program` job with `singleInstance` ([jobs.md](jobs.md#program)). The first one takes `instances/<mod>/<program>.json.lock` in the cmod store, runs the command without `CLAUDE_CODE_SESSION_ID`, because the copy serves every session, and with `CMOD_MOD`, the mod's name, and `CMOD_PROGRAM`, the program's, which `connect()` reads to provide interfaces ([dependencies.md](dependencies.md#connect-a-program-s-connection-to-cmod-serve)), and `CMOD_DATA` and `CMOD_CACHE`, the mod's data and cache folders, which an install step gets too ([install-steps.md](install-steps.md#how-a-step-runs)), writes its first line on standard output, its address, with the copy's pid and start time to `instances/<mod>/<program>.json`, and prints it. For a program that prints nothing and only provides interfaces through `connect()`, it writes the copy's pid and start time there, with no address, once `cmod serve` says the copy provided one, so every command that stops a copy finds both kinds, and prints `provided`, which the session reads as the copy's start. It asks `cmod serve` again every 5 seconds while `cmod serve` is down or starts again. It touches its file in the lock every 5 seconds. With `--no-wait`, which a mod's session passes, another one touches the holder's file, prints `held`, and exits 0, and the session reads the address from `instances/<mod>/<program>.json` and runs `cmod program` again once that file is gone or the holder's file is 15 seconds old. Without it, as a mod built on `@cmodjs/core` before 5.3.0 runs it, another one prints the address in that file, then each new one as it changes, and tries the lock again
|
|
438
|
+
Runs one copy of a mod's program for the whole computer, for a `program` job with `singleInstance` ([jobs.md](jobs.md#program)). The first one takes `instances/<mod>/<program>.json.lock` in the cmod store, runs the command without `CLAUDE_CODE_SESSION_ID`, because the copy serves every session, and with `CMOD_MOD`, the mod's name, and `CMOD_PROGRAM`, the program's, which `connect()` reads to provide interfaces ([dependencies.md](dependencies.md#connect-a-program-s-connection-to-cmod-serve)), and `CMOD_DATA` and `CMOD_CACHE`, the mod's data and cache folders, which an install step gets too ([install-steps.md](install-steps.md#how-a-step-runs)), writes its first line on standard output, its address, with the copy's pid and start time to `instances/<mod>/<program>.json`, and prints it. It tells `cmod serve` through `cmod/Programs` each time it writes or deletes that file, so every session reads it again at once. For a program that prints nothing and only provides interfaces through `connect()`, it writes the copy's pid and start time there, with no address, once `cmod serve` says the copy provided one, so every command that stops a copy finds both kinds, and prints `provided`, which the session reads as the copy's start. It asks `cmod serve` again every 5 seconds while `cmod serve` is down or starts again. It touches its file in the lock every 5 seconds. With `--no-wait`, which a mod's session passes, another one touches the holder's file, prints `held`, and exits 0, and the session reads the address from `instances/<mod>/<program>.json` and runs `cmod program` again once that file is gone or the holder's file is 15 seconds old. Without it, as a mod built on `@cmodjs/core` before 5.3.0 runs it, another one prints the address in that file, then each new one as it changes, and reads the file and tries the lock again each time that file changes and every 5 seconds, so it takes over once a holder that was killed leaves its lock stale. A lock whose process is gone counts as free. The holder stops its copy and gives up the lock on SIGTERM, SIGINT, or SIGHUP, and when the session that started it exits, which it checks every 5 seconds. When the copy exits on its own, the holder exits with the copy's exit code, and the copy's standard error passes through. The cmod command that replaces the program's file in the cmod store's `programs` folder stops the copy itself: `cmod setup` when it links a new version, or links the old one back after a failed install step, `cmod link` and `cmod watch` when a build of the linked checkout changes the program, and `cmod download`. It sends SIGTERM, then SIGKILL after 5 seconds, to the copy each `instances/<mod>/<program>.json` names, once its process and start time match, so the copy restarts whatever cmod program holds it, an older one included. The holder then deletes that file and exits with the copy. The session that ran it runs `cmod program` again a second later, and every other session does too once that file is gone, so one of them starts the new file and the others follow its address. A service's holder exits the same way, and launchd or systemd starts it again. A build with the same bytes, and a link placed again at the same file, leave the program as it was, so the copy keeps running. A new holder that finds a copy an earlier holder left running sends it SIGTERM, then SIGKILL after 5 seconds, and starts its own copy only once that one is gone, so two copies never run at once.
|
|
437
439
|
|
|
438
|
-
With `--service`, which a session passes for a `program` job with `isService`, it makes the holder a service of the computer named `com.claudemodmanager.<mod>.<program>`: a launchd agent in `~/Library/LaunchAgents` on macOS, loaded into the person's login session, and a systemd user service in `~/.config/systemd/user` on Linux, enabled for `default.target`. Its file is mode 600, because it holds the program's environment. The service runs `cmod program <mod> -- <command…>` through the cmod store's `programs/cmod` at login and again whenever it exits, launchd at most once every 10 seconds and systemd 10 seconds after the exit, with `HOME`, `XDG_DATA_HOME`, `XDG_CACHE_HOME`, `XDG_CONFIG_HOME`, `CLAUDE_CONFIG_DIR`, and `HERDR_APP_HOME` as the session has them, so the program reads the same folders the session does, such as its `CMOD_DATA` and `CMOD_CACHE` and the Herdr home `cmod serve` places its Herdr mod in, a `PATH` of the cmod store's `programs` folder, `/usr/local/bin`, `/opt/homebrew/bin`, `/usr/bin`, `/bin`, `/usr/sbin`, and `/sbin`, `CLAUDE_CODE_EXECPATH`, and each `--env` variable, which the job passes for each key of its `environment`, `PATH` included. The `PATH` is fixed, because sessions started from different shells hold different ones, and a service rewritten for each would restart at every session start. `CLAUDE_CODE_EXECPATH` names the Claude Code of the session that wrote the service, so a `cmod` command the program runs finds Claude Code though the `PATH` holds none. It names the path Claude Code's updates keep, `~/.local/bin/claude` when that launcher runs the same install, because the updater deletes old versions and a service rewritten for each version would restart at every update. cmod records it in `services/<mod>/<program>.json` in the cmod store. On macOS the launchd agent writes the service's standard error, the program's and cmod's own, to `services/<mod>/<program>.log` beside that record, because launchd keeps no output of its own. Each holder that starts the program first cuts a log over 1 MiB to the whole lines of its last 512 KiB, so a program that fails at every restart, which launchd starts again every 10 seconds, never fills the disk. Linux keeps the program's output in the systemd journal, so the systemd user service writes no log. It holds the mod's lock in the cmod store while it writes and loads the service and waits for it, so sessions that start the mod at once, as every session does after an update, never load it beside each other or beside `cmod setup` or `cmod teardown` of the mod. It loads the service when it is new, changed, or not loaded, waits up to 15 seconds for the program to start, prints `held`, and exits 0, so the session follows the instance file as with `--no-wait`. The program has started once `instances/<mod>/<program>.json` names its running copy, which the holder writes when the program prints its address or `cmod serve` holds an interface its connection provided, so a program that only provides releases the mod's lock at its first `provide`. A program that has done neither after 15 seconds still counts as started while a holder holds `instances/<mod>/<program>.json.lock`, so a program slow to listen keeps its service. A service with neither, such as a program that exits at once and whose holder therefore held the lock only for a moment, is stopped, disabled, and deleted with its record, as `cmod remove` does, and it fails with what shows why: on macOS the service's log in the cmod store, which the removal keeps, and on Linux `journalctl --user -u <label>.service`. When the computer does not take the service, such as a Linux device without a systemd user session, it deletes what it wrote, says why on standard error, and runs as `--no-wait` does. When the computer took the service, a loaded launchd agent or an enabled systemd user service, and starting it still failed, such as systemd refusing a program that exited too often, it stops, disables, and deletes the service and its record as `cmod remove` does, and fails with the service manager's error and what shows why, because the program fails and the person needs that error. The service restarts on a new program as every copy does, and `cmod teardown` stops and deletes each one.
|
|
440
|
+
With `--service`, which a session passes for a `program` job with `isService`, it makes the holder a service of the computer named `com.claudemodmanager.<mod>.<program>`: a launchd agent in `~/Library/LaunchAgents` on macOS, loaded into the person's login session, and a systemd user service in `~/.config/systemd/user` on Linux, enabled for `default.target`. Its file is mode 600, because it holds the program's environment. The service runs `cmod program <mod> -- <command…>` through the cmod store's `programs/cmod` at login and again whenever it exits, launchd at most once every 10 seconds and systemd 10 seconds after the exit, with `HOME`, `XDG_DATA_HOME`, `XDG_CACHE_HOME`, `XDG_CONFIG_HOME`, `CLAUDE_CONFIG_DIR`, and `HERDR_APP_HOME` as the session has them, so the program reads the same folders the session does, such as its `CMOD_DATA` and `CMOD_CACHE` and the Herdr home `cmod serve` places its Herdr mod in, a `PATH` of the cmod store's `programs` folder, `/usr/local/bin`, `/opt/homebrew/bin`, `/usr/bin`, `/bin`, `/usr/sbin`, and `/sbin`, `CLAUDE_CODE_EXECPATH`, and each `--env` variable, which the job passes for each key of its `environment`, `PATH` included. The `PATH` is fixed, because sessions started from different shells hold different ones, and a service rewritten for each would restart at every session start. `CLAUDE_CODE_EXECPATH` names the Claude Code of the session that wrote the service, so a `cmod` command the program runs finds Claude Code though the `PATH` holds none. It names the path Claude Code's updates keep, `~/.local/bin/claude` when that launcher runs the same install, because the updater deletes old versions and a service rewritten for each version would restart at every update. cmod records it in `services/<mod>/<program>.json` in the cmod store. On macOS the launchd agent writes the service's standard error, the program's and cmod's own, to `services/<mod>/<program>.log` beside that record, because launchd keeps no output of its own. Each holder that starts the program first cuts a log over 1 MiB to the whole lines of its last 512 KiB, so a program that fails at every restart, which launchd starts again every 10 seconds, never fills the disk. Linux keeps the program's output in the systemd journal, so the systemd user service writes no log. It holds the mod's lock in the cmod store while it writes and loads the service and waits for it, so sessions that start the mod at once, as every session does after an update, never load it beside each other or beside `cmod setup` or `cmod teardown` of the mod. It loads the service when it is new, changed, or not loaded, waits up to 15 seconds for the program to start, reading the instance file again each time it changes, whether or not `cmod serve` runs, prints `held`, and exits 0, so the session follows the instance file as with `--no-wait`. The program has started once `instances/<mod>/<program>.json` names its running copy, which the holder writes when the program prints its address or `cmod serve` holds an interface its connection provided, so a program that only provides releases the mod's lock at its first `provide`. A program that has done neither after 15 seconds still counts as started while a holder holds `instances/<mod>/<program>.json.lock`, so a program slow to listen keeps its service. A service with neither, such as a program that exits at once and whose holder therefore held the lock only for a moment, is stopped, disabled, and deleted with its record, as `cmod remove` does, and it fails with what shows why: on macOS the service's log in the cmod store, which the removal keeps, and on Linux `journalctl --user -u <label>.service`. When the computer does not take the service, such as a Linux device without a systemd user session, it deletes what it wrote, says why on standard error, and runs as `--no-wait` does. When the computer took the service, a loaded launchd agent or an enabled systemd user service, and starting it still failed, such as systemd refusing a program that exited too often, it stops, disables, and deletes the service and its record as `cmod remove` does, and fails with the service manager's error and what shows why, because the program fails and the person needs that error. The service restarts on a new program as every copy does, and `cmod teardown` stops and deletes each one.
|
|
439
441
|
|
|
440
|
-
With `--web-app`, which a session passes for a `program` job with `isWebApp`, the holder puts the copy on the person's tailnet while `servesTailnet` in `preferences.json` in the cmod store is on, as it is unless the person turned it off, and `tailscale status --json` says Tailscale is signed in with HTTPS on. It finds `tailscale` on its `PATH`, then at `/Applications/Tailscale.app/Contents/MacOS/Tailscale`, the macOS app's own copy. It runs the copy with `CMOD_TAILNET_NAME`, the computer's tailnet name, and `CMOD_TAILNET_LOGIN`, the login of the computer's owner, and once the copy prints `127.0.0.1:<port>`, runs `tailscale serve --bg --https=<tailnet port> http://127.0.0.1:<port>` before it writes the address, so the instance file carries `tailnetUrl`, `https://<name>:<tailnet port>/`, from the moment a session reads it. The tailnet port is the first port the copy listened on, which `tailnet/<mod>/<program>.json` in the cmod store keeps with the address, or the reason the copy is not on the tailnet, such as Tailscale signed out, HTTPS off, or that port already serving something else on the tailnet, which Settings shows. When the copy exits, the holder runs `tailscale serve --https=<tailnet port> off`, so no address on the tailnet points at a port the copy left. It stops the copy, which starts again as after any exit, when `
|
|
442
|
+
With `--web-app`, which a session passes for a `program` job with `isWebApp`, the holder puts the copy on the person's tailnet while `servesTailnet` in `preferences.json` in the cmod store is on, as it is unless the person turned it off, and `tailscale status --json` says Tailscale is signed in with HTTPS on. It finds `tailscale` on its `PATH`, then at `/Applications/Tailscale.app/Contents/MacOS/Tailscale`, the macOS app's own copy. It runs the copy with `CMOD_TAILNET_NAME`, the computer's tailnet name, and `CMOD_TAILNET_LOGIN`, the login of the computer's owner, and once the copy prints `127.0.0.1:<port>`, runs `tailscale serve --bg --https=<tailnet port> http://127.0.0.1:<port>` before it writes the address, so the instance file carries `tailnetUrl`, `https://<name>:<tailnet port>/`, from the moment a session reads it. The tailnet port is the first port the copy listened on, which `tailnet/<mod>/<program>.json` in the cmod store keeps with the address, or the reason the copy is not on the tailnet, such as Tailscale signed out, HTTPS off, or that port already serving something else on the tailnet, which Settings shows. When the copy exits, the holder runs `tailscale serve --https=<tailnet port> off`, so no address on the tailnet points at a port the copy left. It stops the copy, which starts again as after any exit, when `cmod/Store` tells that `servesTailnet` changed, and when Tailscale becomes ready for a copy that started without it, which it checks every minute. A service passes `--web-app` on to the `cmod program` its service runs.
|
|
441
443
|
|
|
442
444
|
With `--process-type`, which a session passes for a `program` job with `processType`, the launchd agent carries that `ProcessType`: `Interactive` runs the program at the priority of an app, where launchd throttles a service with none on a loaded Mac, and `Background` runs it at the lowest. systemd has no such class, so a Linux service carries none.
|
|
443
445
|
|
|
@@ -452,10 +454,10 @@ cmod web serve
|
|
|
452
454
|
|
|
453
455
|
Serves this computer's sessions to every session, script, and browser on it. The cmod plugin runs it as a service of the computer, `com.claudemodmanager.cmod.cmod`, of launchd's `Interactive` class on macOS, because every session waits on it ([cmod program](#cmod-program)). It listens on `serve.sock` in the cmod store, which only the person can open, and prints `unix:<socket>` once it listens. `cmod web serve` runs the same server, for a session whose cmod plugin is from before 7.0.0.
|
|
454
456
|
|
|
455
|
-
On that socket it answers the `cmod/Sessions` interface as JSON-RPC ([dependencies.md](dependencies.md#interfaces-several-mods-answer-one-name)): it lists and reads every session from the conversation index it keeps open, as [`cmod sessions`](#cmod-sessions) does, carries each action on a session to the cmod plugin of the session that runs it, and tells a `Change` for each session that starts or stops running, is visited or deleted, or changes its tasks, goal, or status. It lists each running session's `status` and `waitingFor` from Claude Code's record of it, `sessions/<pid>.json`,
|
|
457
|
+
On that socket it answers the `cmod/Sessions` interface as JSON-RPC ([dependencies.md](dependencies.md#interfaces-several-mods-answer-one-name)): it lists and reads every session from the conversation index it keeps open, as [`cmod sessions`](#cmod-sessions) does, carries each action on a session to the cmod plugin of the session that runs it, and tells a `Change` for each session that starts or stops running, is visited or deleted, or changes its tasks, goal, or status, and of `part: 'messages'` for each session whose transcript changed, only while a listener's matcher names that part. It lists each running session's `status` and `waitingFor` from Claude Code's record of it, `sessions/<pid>.json`, and adds what only the session's cmod plugin hears: a turn's start and end, the tool call a permission prompt or a question waits on, `contextPercent`, and `lastTurn`. It answers a session it does not hold with the not-held code, `-32098`, and a listener on anything but `Change` with `cmod/Sessions tells only Change, because a mod hears only the session it runs in.` It answers the same calls under `cmod/SessionStore` and `cmod/Session`, the names a cmod plugin from 7.0.0 calls it by. Each session's cmod plugin holds one connection to it and names its session. It provides `cmod/Store` and `cmod/Programs` itself, and tells their `Change` when Claude Code's `installed_plugins.json` changes and whenever a cmod command or session tells it it wrote a file of the cmod store or an instance file. It watches every file it follows as `cmod watch` does: a file event is only a hint to compare each file's modification time and size with its last look, which it also does every 400 ms for a minute after a change and every 30 seconds after that. It also holds every interface a program on this computer provides through `connect()`, and carries each call and listener to the connection that provides it, so each session reaches a program through its one connection to `cmod serve`. A program's providers end with its connection. It reaches a program from a 7.0.0 core, which serves its own wire and names its interfaces as `provides` in `instances/<mod>/<program>.json`, by connecting to the address there. It connects to the `cmod serve` of each device a `cmod/Devices` provider names, at the address the provider gives, or over the messages the provider carries with its `send` and `Message` ([dependencies.md](dependencies.md#cmod-devices-providers-on-your-other-devices)), lists that device's providers with its `device`, and carries each call and listener on one of them there. It offers another device only this computer's providers, and starts a background task whose `device` names this computer. A `Prompt` to a session that has ended resumes it with `claude --bg --resume`, `delete` deletes an ended session, and `visit` keeps when each session's reply was last read in `visited.json` in the cmod store. At its start it deletes each file of the cmod plugin's `before` folder, where a cmod plugin from before 7.0.0 kept its session's `before` listeners, whose session no longer runs, and moves `web-read.json`, the replies `cmod web serve` before 7.0.0 marked read, to `visited.json`.
|
|
456
458
|
|
|
457
459
|
An app on this computer that is no session, such as cmod's Herdr mod, reaches the same calls over a WebSocket, as an editor reaches its language server. `cmod serve` listens for it on 127.0.0.1 at `/ui`, on a port the system picks, and writes the address and a token made at each start to `serve.json` in the cmod store, which only the person can read, as `{ "url", "token" }`. It answers a connection only with `?token=<token>` in its address, and deletes `serve.json` when it stops.
|
|
458
460
|
|
|
459
461
|
At its start it also places cmod's Herdr mod, which draws every session's widgets, views, and pages in the Herdr app over that WebSocket ([ui.md](ui.md#herdr-draws-them-through-cmod-ui)), in `mods/cmod/` of Herdr's home: `$HERDR_APP_HOME`, else `$XDG_CONFIG_HOME/herdr-app`, else `~/.config/herdr-app`, when that folder exists. It writes only a file that differs from the one the cmod program carries, records the hash of each file it wrote in `herdr.json` in the cmod store, and replaces or deletes only a file that still holds what it wrote. A `mods/cmod/` folder whose files it did not write stays as it is, and it says so on standard error and places nothing. `cmod teardown cmod` deletes each file it wrote that still holds what it wrote, and the folder once only what Herdr and the mod write while they run is left in it.
|
|
460
462
|
|
|
461
|
-
While `Show the Sidebar in your browser` is on in Settings, under cmod, Preferences, it serves the browser app that [`cmod web`](#cmod-web) opens, on 127.0.0.1 only, and on the person's tailnet while Tailscale is signed in with HTTPS on. It reads every running session itself: Claude Code's `sessions/<pid>.json` records, a process counting as running only while its pid runs with the start time Claude Code recorded, and leaving out each `sdk-cli` process, then each session's transcript through the conversation index
|
|
463
|
+
While `Show the Sidebar in your browser` is on in Settings, under cmod, Preferences, it serves the browser app that [`cmod web`](#cmod-web) opens, on 127.0.0.1 only, and on the person's tailnet while Tailscale is signed in with HTTPS on. It reads every running session itself: Claude Code's `sessions/<pid>.json` records, a process counting as running only while its pid runs with the start time Claude Code recorded, and leaving out each `sdk-cli` process, then each session's transcript through the conversation index, again on each `cmod/Sessions` `Change` of `part: 'messages'`. It lists the running sessions of each other sessions provider, another device's `cmod serve` or a mod's program, beside them, and reads them again on each `Change` that provider tells, and sends a prompt or a Stop there as that provider's `cmod/Sessions` `send` and `abort`. A session Claude Code records as waiting on a permission prompt or a question moves to Needs you as soon as the dialog opens, and a turn stopped while a command it ran keeps running in the background says so. It reaches each session as every other app does: its status, the permission prompt or question it waits on, how its last turn ended, and its context fill through `cmod/Sessions` `sessions` and `Change`, its views and pages, the cmod plugin's own Dashboard, History, and Settings among them, through `cmod/UI` with `surface: 'browser'`, which it draws, presses, opens, and closes there and follows by `Change`, `Redraw`, `Open`, and `Close`, and a prompt or a Stop through `cmod/Sessions` `send` and `abort`. A session whose cmod plugin is older shows only what its transcript says. A cmod plugin from 7.0.0 posts to `/api/sessions/<session>` and polls `/api/sessions/<session>/events`, and `cmod serve` answers the post with `{}` and the poll after 8 seconds with no views and no actions, so that session warns nothing until it reloads. It keeps `web.json` in the cmod store with the page's port, and listens on that port again while it is free, so a browser tab left open reconnects after a restart. It refuses a request for any host but `127.0.0.1` and `localhost` with its port, and a change from any other page. Through the tailnet it answers a request only when its host is `CMOD_TAILNET_NAME` and its `Tailscale-User-Login` is `CMOD_TAILNET_LOGIN`, the person's own, and answers no session call, which comes only through `serve.sock`. It closes the page once the preference is off, and opens it again when it is on.
|
package/docs/dependencies.md
CHANGED
|
@@ -98,9 +98,11 @@ isLoaded(name: string): Promise<boolean>
|
|
|
98
98
|
|
|
99
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
100
|
|
|
101
|
-
An interface is named `<mod>/<Name>`, after the mod that defines it, such as `demo/Platform`, and cmod defines
|
|
101
|
+
An interface is named `<mod>/<Name>`, after the mod that defines it, such as `demo/Platform`, and cmod defines eight:
|
|
102
102
|
|
|
103
|
-
- `cmod/Sessions` lists, searches, finds one by its id with `session`, 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)).
|
|
103
|
+
- `cmod/Sessions` lists, searches, finds one by its id with `session`, 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, and for each session whose messages changed when the listener's matcher names `part: 'messages'`, 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/Store` tells a `Change { part }` each time a cmod command or session writes a file of the cmod store a session reads, where `part` is `plugins`, `widgets`, `buildFailures`, `preferences`, or `links`, and when Claude Code's `installed_plugins.json` changes. Its `changed(part)` is how a writer tells it. `cmod serve` provides it, so a reader reads the file again on each `Change` and each time it connects, and watches no file.
|
|
105
|
+
- `cmod/Programs` tells a `Change { mod, program }` each time the holder of a `singleInstance` or `isService` program writes or deletes `instances/<mod>/<program>.json`, so a session reads that file again at once. `cmod serve` provides it.
|
|
104
106
|
- `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
107
|
- `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
108
|
- `cmod/Terminal` reads a session's screen, types keys into it, and shows it in a pane. `cmod serve` provides it, first in the list, for each session that runs in a terminal of herdr-core, the terminals the Herdr app shows, and answers not held for any other, so a mod whose program hosts other terminals provides it for those. Its provider tells `Shown { session, place }` after each `show` and `Pressed { session }` after each `press`, so a program that keeps track of which sessions are in use hears an agent's use of one.
|
|
@@ -230,7 +232,7 @@ for (const platform of await providers('demo/Platform')) {
|
|
|
230
232
|
- 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.
|
|
231
233
|
- 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)).
|
|
232
234
|
- 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`.
|
|
233
|
-
- 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>.`
|
|
235
|
+
- 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, and one whose copy has exited once a message waits for it between two polls. A slow program that polls late keeps its connection for 30 seconds. A call to a provider that left fails with `<mod>'s <program> program does not run, so it answers no <interface>.`
|
|
234
236
|
|
|
235
237
|
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:
|
|
236
238
|
|
|
@@ -241,6 +243,7 @@ A program in a language with no `connect()` speaks the wire `connect()` speaks,
|
|
|
241
243
|
- `$/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.
|
|
242
244
|
- 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.
|
|
243
245
|
- `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.
|
|
246
|
+
- A `$/listen` or call that names a program that does not run, or a device `cmod serve` does not reach, fails with the JSON-RPC error code `-32097`. `cmod serve` tells `cmod/Providers` `Change` with `{ interface, device }` once a provider of that interface comes, and `connect()` sends each listener that failed so again then.
|
|
244
247
|
- `$/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.
|
|
245
248
|
- `$/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.
|
|
246
249
|
|
package/docs/index.md
CHANGED
|
@@ -132,7 +132,7 @@ A mod imports from the files below, and every other file in this package is inte
|
|
|
132
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) |
|
|
133
133
|
| `mod.js` | `Hotkey`, `HotkeyInit`, `Combo`, `Key` | [mod.md](mod.md#hotkeys) |
|
|
134
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) |
|
|
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) |
|
|
135
|
+
| `mod.js` | `sessions`, `Sessions`, `Session`, `CurrentSession`, `TaskOwner`, `RecordPart`, `OnMethods`, `BeforeMethods`, `Listener`, `ListenerTime`, `ReadOptions`, `AnswerOptions`, `Refusal`, `SearchOptions`, `SessionScope`, `SessionSend`, `SendReceipt`, `TaskStartArgs`, `ForkArgs`, `ToolCallArgs`, `Usage`, `RateLimit`, `TaskStatus`, `Surface`, `Matcher` | [session.md](session.md) |
|
|
136
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) |
|
|
137
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) |
|
|
138
138
|
| `mod.js` | `Context`, `Turn`, `Goal`, `Task` | [session.md](session.md#turn-context-goal-and-task) |
|
package/docs/jobs.md
CHANGED
|
@@ -335,7 +335,7 @@ type Program = {
|
|
|
335
335
|
- The program has started once it prints its address, or, with `singleInstance` or `isService`, once it provides any interface through `connect()`. `state` is `'starting'` until then, and `'running'` after. Only an address resolves `ready()`, so once a program that only provides is running, `ready()` rejects with `<mod>: the <program> program printed no address, because it only provides interfaces. Reach them through provider(name).`
|
|
336
336
|
- When the program exits, cmod starts it again after 1, 2, 4, 8, and 16 seconds. After 5 failed tries, or a first line that is not an address, the state is `fatal`, `ready()` rejects, and cmod logs `<mod>: the <program> program stopped: <reason>`, which shows `The <program> program stopped` with `Retry` where the mod's errors toast ([ui.md](ui.md#toasts)).
|
|
337
337
|
- `singleInstance: true` runs one copy on the computer, however many sessions load the mod, such as a server that is the only writer of its data. The first session starts the copy through [`cmod program`](commands.md#cmod-program), every other session reads the copy's address from the cmod store and runs no process of its own, and every session's `ready()` resolves that copy's address. When the session running the copy ends, another open session starts a new copy within a few seconds, or within 20 seconds when the copy's session was killed with its `cmod program`, and from then on `ready()` resolves the new address in every session, so ask `ready()` before each use rather than keeping its answer. The cmod store records the running copy's pid and start time, with its address once it prints one, or with no address once it provides an interface, for a program that only provides. A copy a killed session left running is stopped before the new one starts. When cmod installs a new version of the mod, or builds a new program from its linked checkout, it stops the recorded copy, whichever cmod started it, so the copy restarts on the new program a few seconds later, and `ready()` resolves the new copy's address, or `provider(name)` its provider. Two `singleInstance` programs with the same program name in one mod throw at `mod.use`.
|
|
338
|
-
- `isService: true` makes the program a service of the computer, so it runs whenever the person is logged in, with no Claude Code open, such as a program that records sessions Claude Code never sees. The first session that starts the mod has [`cmod program`](commands.md#cmod-program) write a launchd agent on macOS, or a systemd user service on Linux, which starts the program at login and again whenever it exits, with `environment`. The service's `PATH` is cmod's programs folder, `/usr/local/bin`, `/opt/homebrew/bin`, and the system folders, unless `environment` sets `PATH`, and its `CLAUDE_CODE_EXECPATH` names the session's Claude Code by the path its updates keep, so a `cmod` command the program runs, such as `cmod options get`, finds Claude Code. Every session reads the service's address from the cmod store, as a `singleInstance` program's sessions do, and `ready()` resolves it. The service runs one copy, so `isService` needs no `singleInstance` beside it. The mod writes no service file: the service restarts on the new program when cmod installs a new version of the mod or builds a new program from its linked checkout, and cmod stops and deletes it when the mod is removed. When a new version's setup no longer adds the `isService` program, because it dropped `isService` or renamed the program, the first session that starts that version stops and deletes the old service, so the computer stops running a program the mod no longer ships. Settings shows `Runs as a service of this computer` in the mod's entry, and [`cmod list`](commands.md#cmod-list) names the program. On a computer that does not take the service, such as a Linux device without a systemd user session, the program runs as a `singleInstance` program does. A service the computer took but could not start is removed, and the program fails with the service manager's error, as an exiting program does. A service whose program has not started within 15 seconds and no longer runs is removed the same way. On macOS the program's standard error goes to `services/<mod>/<program>.log` in the cmod store, which that error names, and on Linux to the systemd journal. Two `isService` programs with the same program name in one mod throw at `mod.use`.
|
|
338
|
+
- `isService: true` makes the program a service of the computer, so it runs whenever the person is logged in, with no Claude Code open, such as a program that records sessions Claude Code never sees. The first session that starts the mod has [`cmod program`](commands.md#cmod-program) write a launchd agent on macOS, or a systemd user service on Linux, which starts the program at login and again whenever it exits, with `environment`. cmod writes the service again, which restarts it, only when the program's command, its `environment`, or `processType` change, so the service keeps the session's folders and Claude Code it was written with, and a session with other ones never restarts it. The service's `PATH` is cmod's programs folder, `/usr/local/bin`, `/opt/homebrew/bin`, and the system folders, unless `environment` sets `PATH`, and its `CLAUDE_CODE_EXECPATH` names the session's Claude Code by the path its updates keep, so a `cmod` command the program runs, such as `cmod options get`, finds Claude Code. Every session reads the service's address from the cmod store, as a `singleInstance` program's sessions do, and `ready()` resolves it. The service runs one copy, so `isService` needs no `singleInstance` beside it. The mod writes no service file: the service restarts on the new program when cmod installs a new version of the mod or builds a new program from its linked checkout, and cmod stops and deletes it when the mod is removed. When a new version's setup no longer adds the `isService` program, because it dropped `isService` or renamed the program, the first session that starts that version stops and deletes the old service, so the computer stops running a program the mod no longer ships. Settings shows `Runs as a service of this computer` in the mod's entry, and [`cmod list`](commands.md#cmod-list) names the program. On a computer that does not take the service, such as a Linux device without a systemd user session, the program runs as a `singleInstance` program does. A service the computer took but could not start is removed, and the program fails with the service manager's error, as an exiting program does. A service whose program has not started within 15 seconds and no longer runs is removed the same way. On macOS the program's standard error goes to `services/<mod>/<program>.log` in the cmod store, which that error names, and on Linux to the systemd journal. Two `isService` programs with the same program name in one mod throw at `mod.use`.
|
|
339
339
|
- `isWebApp: true` puts a program the person opens in a browser on their tailnet, so it opens from each of their devices, with `singleInstance` or `isService` beside it, because the tailnet reaches one copy per computer. A web app with neither throws at `mod.use`. While Tailscale is signed in on the computer with HTTPS on, the program runs with `CMOD_TAILNET_NAME`, the computer's tailnet name, such as `my-computer.my-tailnet.ts.net`, and `CMOD_TAILNET_LOGIN`, the person's Tailscale login, and once it prints `127.0.0.1:<port>`, cmod runs `tailscale serve`, so `https://<CMOD_TAILNET_NAME>:<port>/` reaches it, and `ready()` resolves that address as `tailnetUrl`. The tailnet port stays the first port the program listened on, so the address stays the same when it listens on another port later. Tailscale forwards each request with its own `Host` and sets `Tailscale-User-Login` to the login of the person who sent it, replacing any the request carried. So the program answers a request through the tailnet only when the host name of its `Host` is `CMOD_TAILNET_NAME` and its `Tailscale-User-Login` is `CMOD_TAILNET_LOGIN`, because a work tailnet or a device someone shared reaches other people's devices. The program keeps listening on `127.0.0.1` only. cmod takes the program off the tailnet when it exits, stops and starts it again when the person turns `Open web apps from your other devices` in Settings, under cmod, Preferences, off or on, or when Tailscale becomes ready, which it checks every minute, and takes it off when the mod is removed. Without Tailscale, the program runs on `127.0.0.1` alone, and Settings shows the reason in the mod's entry, or its tailnet address when it is on the tailnet. A program that listens on a `unix:` socket stays off the tailnet.
|
|
340
340
|
- Every program runs with `CMOD_DATA` and `CMOD_CACHE`, the folders `mod.dataFolder` and `mod.cacheFolder` name, as an install step gets them ([install-steps.md](install-steps.md#how-a-step-runs)), so it keeps its files where its mod does without asking `cmod data`. A service gets the folders of the session that wrote it. A program with `singleInstance` or `isService` also runs with `CMOD_MOD`, the mod's name, and `CMOD_PROGRAM`, the program's, so it provides interfaces for every session on the computer: it calls `connect()` from `rpc.js`, then `provide` from `mod.js` ([dependencies.md](dependencies.md#interfaces-several-mods-answer-one-name)).
|
|
341
341
|
- `provider(name)` starts the program as `ready()` does, and resolves with this program's provider of `name` on this computer once the program provides it, typed from the interface as `providers` types it ([dependencies.md](dependencies.md#interfaces-several-mods-answer-one-name)). Another mod's program that provides the same name never answers it. It rejects as `ready()` rejects once the program is `fatal`. A program with neither `singleInstance` nor `isService` runs a copy per session, and only one copy of a program can provide an interface, so its `provider(name)` rejects at once with `<mod>: provider(<name>) needs the <program> program to run as singleInstance or isService, because only one copy of a program can provide an interface.` A program that only provides prints no address, so its mod waits for it with `provider(name)` instead of `ready()`. A provider that stops and provides again, such as a restarted service, is a new provider: a call on the old one fails with `<mod>'s <program> program does not run, so it answers no <interface>.`, and the mod asks `provider(name)` again, so ask it before each use rather than keeping its answer.
|
package/docs/mod.md
CHANGED
|
@@ -548,7 +548,7 @@ device.read(): Promise<Device>
|
|
|
548
548
|
type Device = { id: string; name: string; os: 'darwin' | 'linux'; arch: 'arm64' | 'x64' }
|
|
549
549
|
```
|
|
550
550
|
|
|
551
|
-
- `id` is the same on one computer for every session, mod, and reinstall, and differs between computers. cmod reads
|
|
551
|
+
- `id` is the same on one computer for every session, mod, and reinstall, and differs between computers. `cmod serve` reads the device from the operating system at each start and writes it to `device.json` in the cmod store, so a renamed computer shows its new name after the next start. Every other reader reads that file, and the operating system only while the file is missing: the IOPlatformUUID on macOS, and on Linux `/etc/machine-id`, or `/var/lib/dbus/machine-id` when that holds none, as systemd and D-Bus read them, hashed for cmod the way systemd's `sd_id128_get_machine_app_specific` hashes a machine id for an app, so the id never shows the computer's own.
|
|
552
552
|
- `name` is the name the computer goes by on its network: its LocalHostName on macOS, such as `Mac-mini`, and its hostname on Linux.
|
|
553
553
|
- `os` and `arch` are the names cmod's builds use, such as `darwin` and `arm64`.
|
|
554
554
|
- `read` reads the computer the first time the mod calls it, and answers the same device after that. It rejects on a computer other than macOS or Linux on arm64 or x64. It also rejects on a Linux computer where neither `/etc/machine-id` nor `/var/lib/dbus/machine-id` holds a machine id, as in many containers, with a sentence that names both files.
|
package/docs/session.md
CHANGED
|
@@ -91,7 +91,7 @@ type Session = {
|
|
|
91
91
|
turns(options?: { last?: number }): Promise<Turn[]>
|
|
92
92
|
messages(options?: { after?: string; last?: number }): Promise<Message[]>
|
|
93
93
|
search(text: string, matcher?: Matcher<Message>): AsyncIterable<Message>
|
|
94
|
-
send(message: { type: Prompt | Note; text: string; as?: Person | Session }): Promise<
|
|
94
|
+
send(message: { type: Prompt | Note; text: string; as?: Person | Session }): Promise<SendReceipt>
|
|
95
95
|
startTask(task: { prompt: string; title: string; agentType?: string; model?: string; name?: string; cwd?: string; isBackground?: boolean; device?: string }): Promise<Task>
|
|
96
96
|
fork(task: { prompt: string; title: string; isBackground?: boolean; at?: string }): Promise<Task>
|
|
97
97
|
callTool(call: { name: string; input: Record<string, unknown> }): Promise<ToolResult>
|
|
@@ -275,12 +275,13 @@ sessions.current.onCwdChange(({ cwd, previous }) => mod.log(`moved from ${previo
|
|
|
275
275
|
|
|
276
276
|
Every action works on the current session and on every other running session, on this computer or through a sessions provider. cmod carries an action to another session, and that session's cmod does it there.
|
|
277
277
|
|
|
278
|
-
- `send` adds a message to the session
|
|
279
|
-
- A `Note` is text the agent reads on its next call to the model and the person does not see. It starts no turn.
|
|
280
|
-
- A `Prompt` is the next prompt, so the agent answers it as a turn of its own. Claude Code holds it until the session is idle, so it never cuts into a turn, and frames it as `The <mod> plugin sent a message:`. With `as: Person`, the agent reads it bare, as the person's own words, while every hook still sees that the mod sent it.
|
|
281
|
-
-
|
|
282
|
-
-
|
|
283
|
-
- To
|
|
278
|
+
- `send` adds a message to the session, and resolves a `SendReceipt`, `{ id?, state }`.
|
|
279
|
+
- A `Note` is text the agent reads on its next call to the model and the person does not see. It starts no turn. To the current session it rejects with `<mod>: Claude Code refused the note: <reason>` when a plugin refuses it.
|
|
280
|
+
- A `Prompt` is the next prompt, so the agent answers it as a turn of its own. Claude Code holds it until the session is idle, so it never cuts into a turn, and frames it as `The <mod> plugin sent a message:`. With `as: Person`, the agent reads it bare, as the person's own words, while every hook still sees that the mod sent it. To the current session it rejects with `<mod>: Claude Code dropped the prompt: <reason>` when a plugin drops it.
|
|
281
|
+
- To another session, the message is mail: the `cmod serve` of the device the session runs on stores it in `mail.sqlite` before it delivers it, so a restart of either side never drops it. `id` names the mail, and `state` is `'delivered'` once the session's cmod plugin took it, or `'queued'` while no cmod plugin in the session reaches `cmod serve`, or while the plugin refused it. The plugin gets each queued mail, in the order it was sent, each time it reaches `cmod serve` again, as it does at its start and at a reload. `cmod sessions read mail` lists a session's mail with its state ([commands.md](commands.md#cmod-sessions)).
|
|
282
|
+
- `as: Session` sends it from the current session, which its cmod plugin names with the session's id and title: the session reads it inside `<cmod-message from="<id>" title="<title>" reply="cmod sessions send <id start> --reply-to <mail>">`, which names the sender and the command that answers it. To the current session itself it rejects with `<mod>: session <id> cannot send as itself to itself.`
|
|
283
|
+
- To the current session and to a task's owner, which takes the text in its running subagent, a message is no mail, and `send` resolves `{ state: 'delivered' }`.
|
|
284
|
+
- To a session that has ended, the mail resumes it in a new background Claude Code session, as `claude --bg --resume` does, which answers it. A session Claude Code still runs is never resumed, so a message never starts a second copy of it: its mail stays queued until a cmod plugin in it reaches `cmod serve`.
|
|
284
285
|
- `startTask` starts a task in the session, the way the Agent tool starts one, and resolves the `Task` once it started. It does not wait for the task to finish. `title` is the task's title, `agentType` names the owner's agent type, such as `Explore`, `name` is the address a teammate's `SendMessage` reaches it by, and `model` and `cwd` change what it runs on and where. It rejects with `<mod>: Claude Code refused the task: <reason>` when a hook refuses it.
|
|
285
286
|
- With `isBackground: true`, the owner is a new background Claude Code session, as `claude --bg` starts, which starts fresh on the prompt and keeps running after this session ends. It takes no `name`, and rejects with `<mod>: a background task takes no name.` for one.
|
|
286
287
|
- `device` names the device the background session runs on, by its name or its cmod device id. A `device` other than this computer starts through the sessions provider that serves it ([Sessions providers](#sessions-providers)): cmod asks the `startTask` of each provider on that device, its `cmod serve` among them, or of every provider when none runs there, in turn, with the whole task, `device` included, and the first that does not answer not-held starts the session there and answers its task. A device's `cmod serve` starts it in the task's `cwd`, or the project of this session when the task names none, and rejects with `<device> has no folder <cwd>, so the task did not start. Give the task a cwd on <device>.` when that device lacks the folder. With no such provider, the call rejects with `<mod>: no mod starts sessions on <device>, so the task did not start. Leave device out to start it on <this computer>.`
|
package/docs/testing.md
CHANGED
|
@@ -219,7 +219,7 @@ test('/recall finds the earlier session about the deploy', async () => {
|
|
|
219
219
|
})
|
|
220
220
|
```
|
|
221
221
|
|
|
222
|
-
`shown.sent` lists what the mod sent to other sessions and to tasks' owners, each with its `session`,
|
|
222
|
+
`shown.sent` lists what the mod sent to other sessions and to tasks' owners, each with its `session`, its `task` for an owner, and `from`, the current session's id, which the test kit's cmod plugin adds to one sent with `as: Session`, as the cmod plugin does. Each `send` to a session resolves `{ id, state: 'delivered' }`, with the place of the message in `shown.sent` counted from 1. `fakes.agent.spawn` answers the current session's `startTask` and `fork`, such as `async () => ({ agentId: 'agent-7', model: 'test-model' })`, and `fakes.tool.call` its `callTool`. A background `startTask` and a background `fork` start their task in the fake session, after asking the mod's `beforeTaskStart` listeners, and so do another session's `startTask` and `fork`.
|
|
223
223
|
|
|
224
224
|
A `before` listener on the current session answers what `raise` asks, such as `tested.raise.beforePrompt({ text: 'Deploy to prod' })` or `tested.raise.beforeToolCall({ name: 'Bash', input: { command: 'rm -rf build' } })`.
|
|
225
225
|
|
|
@@ -385,7 +385,7 @@ type Shown = {
|
|
|
385
385
|
readonly commands: string[]
|
|
386
386
|
readonly tools: string[]
|
|
387
387
|
readonly schedules: { readonly id: string; readonly cron: string; readonly prompt: string }[]
|
|
388
|
-
readonly sent: { readonly session: string; readonly type: string; readonly text: string; readonly as?: string }[]
|
|
388
|
+
readonly sent: { readonly session: string; readonly task?: string; readonly type: string; readonly text: string; readonly as?: string; readonly from?: string }[]
|
|
389
389
|
readonly view: ShownPart
|
|
390
390
|
readonly page: ShownPart
|
|
391
391
|
readonly pane: ShownPart
|
package/docs/ui.md
CHANGED
|
@@ -107,7 +107,8 @@ Progress(props: ({ value: number; tone?: Tone } | { sections: readonly ({ value:
|
|
|
107
107
|
- `Help` draws a `?` that shows `text` the same way. A press of `?` keeps the card open until the next press, so the keyboard reaches it too. Keep `isOpen` in `mod.state`.
|
|
108
108
|
- `Dialog` lays out a dialog's title, body, and `actions`, the buttons in a row. Put the safe action first, as the `primary` Button with `autoFocus`.
|
|
109
109
|
- `Pagination` draws `p: Previous 2 of 5 n: Next`. `p` and `n` are its hotkeys, and an end it cannot pass is dim text.
|
|
110
|
-
- `Progress` fills `value` percent of `width` columns, 24 unless given, in its `tone`'s color, and `label` names the bar for a screen reader. Put the count beside it in a `Text`, or pass it as a loading toast's `description`. Give it `sections` instead to fill several parts left to right, each `value` percent wide in its own `tone`, as a usage bar draws what is used under the expected pace in one color and what is past it in `'warning'`. The parts stop at 100 percent, a part with no `tone` draws in the bar's own color, a `'neutral'` part draws gray, and a part given a `color`, one of the Claude Code colors `Text` takes, draws in it, as a nearly empty usage bar draws what is past its pace in `'diffRemoved'` beside a `'critical'` part. `buffer` is the percent a lighter part of the track reaches past the fill, as Material's buffer bar draws what is loaded ahead of what plays, or a usage bar draws the headroom under the expected pace. In the terminal, each boundary between two parts falls on an eighth of a column, the track has the fill's height, and the ends are rounded in a terminal whose font has Nerd Font's half circles: Herdr, Ghostty, and WezTerm, by `TERM_PROGRAM`, or inside tmux by Ghostty's `GHOSTTY_RESOURCES_DIR` or
|
|
110
|
+
- `Progress` fills `value` percent of `width` columns, 24 unless given, in its `tone`'s color, and `label` names the bar for a screen reader. Put the count beside it in a `Text`, or pass it as a loading toast's `description`. Give it `sections` instead to fill several parts left to right, each `value` percent wide in its own `tone`, as a usage bar draws what is used under the expected pace in one color and what is past it in `'warning'`. The parts stop at 100 percent, a part with no `tone` draws in the bar's own color, a `'neutral'` part draws gray, and a part given a `color`, one of the Claude Code colors `Text` takes, draws in it, as a nearly empty usage bar draws what is past its pace in `'diffRemoved'` beside a `'critical'` part. `buffer` is the percent a lighter part of the track reaches past the fill, as Material's buffer bar draws what is loaded ahead of what plays, or a usage bar draws the headroom under the expected pace. In the terminal, each boundary between two parts falls on an eighth of a column, the track has the fill's height, and the ends are rounded in a terminal whose font has Nerd Font's half circles: Herdr, Ghostty, and WezTerm, by `TERM_PROGRAM`, kitty, by `KITTY_WINDOW_ID`, or inside tmux by Ghostty's `GHOSTTY_RESOURCES_DIR`, WezTerm's `WEZTERM_EXECUTABLE`, or kitty's `KITTY_WINDOW_ID`, and in every terminal once the person turns on `Round the ends of bars in every terminal` in Settings, as for a session over ssh, where nothing names the terminal that shows it. Herdr and the browser draw their own rounded bar.
|
|
111
|
+
- Each component draws its colors from a palette of tokens named as shadcn names them, `foreground`, `mutedForeground`, `border`, `input`, `primary`, `accent`, and the tones, and each place a part draws fills them its own way: Herdr from its theme, the browser from its stylesheet, and the terminal from the person's Claude Code theme. A theme with full color fills them with the Claude Code colors, and Claude Code's `Dark mode (ANSI colors only)` and `Light mode (ANSI colors only)` fill the three grays of 16 colors, which those themes give one gray, so a bar's fill, buffer, and track stay apart. A mod draws with the theme and the bar ends the session has now: a draw 2 seconds after the last read reads them again, and draws once more when either changed.
|
|
111
112
|
- `Tabs`, `Toggle`, `Help`, `Pagination`, and a tree `ListItem` hold no state of their own. Keep their value in `mod.state` and set it in the callback, as in React's controlled components.
|
|
112
113
|
|
|
113
114
|
## Views and pages
|
|
@@ -226,10 +227,10 @@ event Close { session, mod, id }
|
|
|
226
227
|
```
|
|
227
228
|
|
|
228
229
|
- `views` lists the views that show beside the session, and leaves out the views in Settings. The cmod plugin's own Dashboard, History, and Settings are its views `dashboard`, `history`, and `settings`, so an app lists and draws them as it does every mod's.
|
|
229
|
-
- `draw` returns the part's elements as data, the shape `elementData` writes, with each handler as `{ $cmodHandler: <number> }`. A widget draws for `area`, the area the app shows it in, which its `render` reads as `context.area`, and for `surface`, which it reads as `context.surface`, and an area the widget does not list rejects. For `TurnEnd`, `context.turn` is the session's last finished turn, and the widget draws `null` until the first turn finishes, as Claude Code draws no turn's end before it. Each turn that finishes tells `Redraw` for every widget that lists `TurnEnd`. Without `area`, it draws for the Dashboard when it lists the Dashboard, else for its first area. A view or page draws with the params it was opened with.
|
|
230
|
+
- `draw` returns the part's elements as data, the shape `elementData` writes, with each handler as `{ $cmodHandler: <number> }`. A widget draws for `area`, the area the app shows it in, which its `render` reads as `context.area`, and for `surface`, which it reads as `context.surface`, and an area the widget does not list rejects. For `TurnEnd`, `context.turn` is the session's last finished turn, and the widget draws `null` until the first turn finishes, as Claude Code draws no turn's end before it. Each turn that finishes tells `Redraw` for every widget that lists `TurnEnd`. Without `area`, it draws for the Dashboard when it lists the Dashboard, else for its first area. A view or page draws with the params it was opened with. `draw` returns `null` only for a part that has not drawn yet, and a `Redraw` follows. A part that drew nothing returns an empty `Box`, and a part with an earlier drawing returns that drawing while a new one fills.
|
|
230
231
|
- `press` runs the handler with that number, with a `Press` whose `surface` is the one `input` gives, and `input`'s `key`, `kind`, `value`, and `link`. Its `component` is the one the part draws in within Claude Code: `'Pane'` for a view, a page, or a widget drawn for `Dashboard`, and for a widget drawn for another area, `'AbovePrompt'`, `'PromptHint'`, `'Spinner'`, or `'TurnDuration'`. A number from a drawing two draws back or older runs nothing and rejects.
|
|
231
232
|
- `show` tells which views and pages one place an app draws in shows, as VS Code's workbench sets each view's visibility for the extension host, so each one counts as `isShown` in its mod. `client` names that place, a name the app picks, such as one browser tab. Each `show` replaces that client's last list for the session, and an empty list clears it. A list lapses 16 seconds after its client's last `show`, so an app sends it again before then, every 5 seconds as the browser does, and clears it when the place closes. `isHost: true` says the place hosts the session's views, as a panel beside the session's terminal does, even with no part in the list. While a place hosts the session, the cmod plugin opens Claude Code's own Sidebar for no view or page, and the place shows itself on each `Open` with `isAsked`.
|
|
232
|
-
- `Change` tells that a mod added or removed a widget, view, or page, and `Redraw` that a part of a mod may draw new data, after a state change the mod drew differently.
|
|
233
|
+
- `Change` tells that a mod added or removed a widget, view, or page, and `Redraw` that a part of a mod may draw new data, after a state change the mod drew differently. A mod names only the parts whose drawing changed, at most once every 100 ms.
|
|
233
234
|
- `Open` and `Close` tell that a mod opened or closed one of its views or pages itself, with `open()` or `close()` on it, from a press, a slash command, or a timer, as a VS Code extension's `reveal` asks the workbench to show its view. An app shows the part on `Open` and takes it away on `Close`. An app's own `open` and `close` tell neither. A view in Settings, and a request for Settings, tell `Open` of the cmod plugin's `settings` view. An `Open` the person asked for, from a slash command, a hotkey, or a press in Claude Code, carries `isAsked: true`, and so does the cmod plugin's own open of its History or Settings while a place hosts the session, as VS Code's `reveal` with focus brings a view's container forward.
|
|
234
235
|
|
|
235
236
|
### Herdr draws them through cmod/UI
|
|
@@ -240,9 +241,9 @@ It shows the session of the focused terminal: the terminal's foreground process,
|
|
|
240
241
|
|
|
241
242
|
It never docks itself, because Herdr writes a dock into whichever layout file shows when it first sees the mod, once per Herdr home, and a layout another mod rewrites loses it for good. Herdr shows it in two ways. `mod.open` with `{ "name": "cmod" }` opens the dock as a window over any layout, Herdr's own included, and closes it when run again: from `herdr-app do mod.open:cmod`, a `keys.json` binding such as `"ctrl-shift-m": "mod.open:cmod"`, or another mod's `run`. The window takes no keyboard, so the dock keeps following the focused terminal, and Herdr remembers where it was dragged. A layout author places it anywhere a mod goes instead, with the `props` that say what it shows:
|
|
242
243
|
|
|
243
|
-
- `{ "mod": "cmod" }`, or `{ "show": "views" }`, shows the focused session's views as tabs, and hosts the focused session, in a layout and in the `mod.open` window alike: its `show` carries `isHost`, so the session opens no Sidebar of its own. An `Open` with `isAsked` selects the view's tab, and a dock in a layout also shows its own block: it selects the block's branch of each stack above it and shows each hidden node on the way, with `layout.select` and `layout.show`, wherever the layout puts it. It shows the views in the order `views` lists them, the cmod plugin's own `history` and `settings` among them, with `dashboard` only while a widget is on the Dashboard, each label starting with a capital, and the session's open pages after them in the same row, which scrolls. It draws every view the session lists once, then draws again only the view it shows, on its `Redraw` and each time its tab is chosen, so a switch of tab shows the view's last drawing at once and a fresh one behind it, and a view out of sight costs Herdr nothing. A `Redraw` that comes while the shown view's drawing is on its way draws it once more after it lands. Every redraw of a Herdr mod redraws Herdr's whole window, so the dock redraws only when what it shows changed. A page opens as a Herdr tab, `tab.new` with `{ "show": "page", "session", "mod", "id", "title" }`. A page a mod opens itself opens the same way on `Open`, and its tab closes on `Close`. A view a mod opens becomes the shown tab, and a `Close` of the shown view goes back to the first one, as the Sidebar takes a closed view away.
|
|
244
|
+
- `{ "mod": "cmod" }`, or `{ "show": "views" }`, shows the focused session's views as tabs, and hosts the focused session, in a layout and in the `mod.open` window alike: its `show` carries `isHost`, so the session opens no Sidebar of its own. An `Open` with `isAsked` selects the view's tab, and a dock in a layout also shows its own block: it selects the block's branch of each stack above it and shows each hidden node on the way, with `layout.select` and `layout.show`, wherever the layout puts it. It shows the views in the order `views` lists them, the cmod plugin's own `history` and `settings` among them, with `dashboard` only while a widget is on the Dashboard, each label starting with a capital, and the session's open pages after them in the same row, which scrolls. It draws every view the session lists once, then draws again only the view it shows, on its `Redraw` and each time its tab is chosen, so a switch of tab shows the view's last drawing at once and a fresh one behind it, and a view out of sight costs Herdr nothing. A `Redraw` that comes while the shown view's drawing is on its way draws it once more after it lands. Every redraw of a Herdr mod redraws Herdr's whole window, so the dock redraws only when what it shows changed. A page opens as a Herdr tab, `tab.new` with `{ "show": "page", "session", "mod", "id", "title" }`. A page a mod opens itself opens the same way on `Open`, and its tab closes on `Close`. An `Open` with `isAsked`, or a press on the page in the row, selects the page's tab once it is open. An `Open` without it opens the tab with `focus: false` and leaves an open one where it is. A view a mod opens becomes the shown tab, and a `Close` of the shown view goes back to the first one, as the Sidebar takes a closed view away.
|
|
244
245
|
- `{ "show": "widgets", "area": "belowPrompt" }` draws in a row each widget that lists that area, drawn for that area, for a status bar block. `area` is the value of an area constant: `abovePrompt`, `belowPrompt`, `working`, `turnEnd`, or `dashboard`, the default. In a pane header Herdr gives `props().terminal`, so each pane's header draws its own session's widgets.
|
|
245
|
-
- `{ "show": "page", "session": "<id>", "mod": "<mod>", "id": "<page>" }` draws one page of one session, as a page in the dock's row opens it.
|
|
246
|
+
- `{ "show": "page", "session": "<id>", "mod": "<mod>", "id": "<page>" }` draws one page of one session, as a page in the dock's row opens it. A page tab whose session no cmod plugin holds says why above the page, and drops that note and the page's error on its own at its next `show` or `draw` that succeeds, drawing the page again, as a dock shows a session's views once its cmod plugin holds it again.
|
|
246
247
|
|
|
247
248
|
Each dock and page tab tells `show` the views or page it draws, under a client name it makes once: a dock tells the one view it shows. It tells again when its tab or its focused session changes, renews the list every 5 seconds, and clears it when its focused session changes or the placement closes. A `{ "show": "widgets" }` block tells nothing, because `isShown` is about views and pages.
|
|
248
249
|
|
package/jobs/program.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"program.d.ts","sourceRoot":"","sources":["../src/jobs/program.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,iBAAiB,EAAE,GAAG,EAAE,MAAM,WAAW,CAAA;AACtE,OAAO,EAA8B,KAAK,WAAW,EAAE,MAAM,eAAe,CAAA;AAS5E,MAAM,MAAM,OAAO,GAAG;IACpB,QAAQ,CAAC,KAAK,EAAE,SAAS,GAAG,UAAU,GAAG,SAAS,GAAG,SAAS,GAAG,OAAO,CAAA;IACxE,KAAK,IAAI,OAAO,CAAC;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,UAAU,CAAC,EAAE,MAAM,CAAC;QAAC,UAAU,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;IAC3E,QAAQ,CAAC,IAAI,SAAS,aAAa,EAAE,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC,CAAA;CACnF,CAAA;AAYD,wBAAgB,OAAO,CAAC,OAAO,EAAE;IAC/B,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAA;IACnC,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC7C,QAAQ,CAAC,cAAc,CAAC,EAAE,OAAO,CAAA;IACjC,QAAQ,CAAC,SAAS,CAAC,EAAE,OAAO,CAAA;IAC5B,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;IAC3B,QAAQ,CAAC,WAAW,CAAC,EAAE,WAAW,CAAA;CACnC,GAAG,GAAG,CAAC,OAAO,CAAC,
|
|
1
|
+
{"version":3,"file":"program.d.ts","sourceRoot":"","sources":["../src/jobs/program.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,iBAAiB,EAAE,GAAG,EAAE,MAAM,WAAW,CAAA;AACtE,OAAO,EAA8B,KAAK,WAAW,EAAE,MAAM,eAAe,CAAA;AAS5E,MAAM,MAAM,OAAO,GAAG;IACpB,QAAQ,CAAC,KAAK,EAAE,SAAS,GAAG,UAAU,GAAG,SAAS,GAAG,SAAS,GAAG,OAAO,CAAA;IACxE,KAAK,IAAI,OAAO,CAAC;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,UAAU,CAAC,EAAE,MAAM,CAAC;QAAC,UAAU,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;IAC3E,QAAQ,CAAC,IAAI,SAAS,aAAa,EAAE,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC,CAAA;CACnF,CAAA;AAYD,wBAAgB,OAAO,CAAC,OAAO,EAAE;IAC/B,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAA;IACnC,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC7C,QAAQ,CAAC,cAAc,CAAC,EAAE,OAAO,CAAA;IACjC,QAAQ,CAAC,SAAS,CAAC,EAAE,OAAO,CAAA;IAC5B,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;IAC3B,QAAQ,CAAC,WAAW,CAAC,EAAE,WAAW,CAAA;CACnC,GAAG,GAAG,CAAC,OAAO,CAAC,CAyMf"}
|
package/jobs/program.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { instancePath, processTypes } from '../records.js';
|
|
2
2
|
import { cmodPluginName, isUnanswered } from '../runtime/dependencies.js';
|
|
3
3
|
import { engineOf } from '../runtime/engine.js';
|
|
4
|
-
import { interfaceMethods } from '../runtime/interfaces.js';
|
|
4
|
+
import { interfaceMethods, programsInterface } from '../runtime/interfaces.js';
|
|
5
5
|
import { cmodStore, isHeld } from '../runtime/programs.js';
|
|
6
6
|
import { ifMissing } from '../utils/paths.js';
|
|
7
7
|
import { messageOf } from '../utils/text.js';
|
|
@@ -13,7 +13,7 @@ const retryWithinMs = 1000;
|
|
|
13
13
|
export function program(options) {
|
|
14
14
|
const { command, environment, singleInstance = false, isService = false, isWebApp = false, processType } = options;
|
|
15
15
|
return ({ mod, announce, reserveName }) => {
|
|
16
|
-
const { claude, report, spawnCmod, isInstalledCopy,
|
|
16
|
+
const { claude, report, spawnCmod, isInstalledCopy, interfaces } = engineOf(mod);
|
|
17
17
|
const [executable] = command;
|
|
18
18
|
if (executable === undefined)
|
|
19
19
|
throw new Error(`${mod.name}: the program has no command. Name the program on PATH and its arguments, such as ['preview-server', '--port', '0'].`);
|
|
@@ -133,8 +133,9 @@ export function program(options) {
|
|
|
133
133
|
isFollowing = true;
|
|
134
134
|
if (!isWatching) {
|
|
135
135
|
isWatching = true;
|
|
136
|
-
|
|
137
|
-
|
|
136
|
+
const programs = interfaces.serveProvider(programsInterface);
|
|
137
|
+
programs.onChange({ mod: mod.name, program: basename(executable) }, () => following(track(file)));
|
|
138
|
+
claude.clock.every(leaseCheckMs, () => following(checkLease(file).then(() => (isFollowing && state === 'starting' ? track(file) : undefined))));
|
|
138
139
|
}
|
|
139
140
|
await track(file);
|
|
140
141
|
};
|
package/mod.d.ts
CHANGED
|
@@ -192,7 +192,7 @@ declare module 'claude-code' {
|
|
|
192
192
|
isAgent?: true;
|
|
193
193
|
};
|
|
194
194
|
}): unknown[];
|
|
195
|
-
read(session: string, part: 'messages' | 'turns' | 'contexts' | 'tasks' | 'goal' | 'usage' | 'state', options?: {
|
|
195
|
+
read(session: string, part: 'messages' | 'turns' | 'contexts' | 'tasks' | 'goal' | 'usage' | 'state' | 'mail', options?: {
|
|
196
196
|
project?: string;
|
|
197
197
|
task?: string;
|
|
198
198
|
turn?: string;
|
|
@@ -204,12 +204,20 @@ declare module 'claude-code' {
|
|
|
204
204
|
send(session: string, message: {
|
|
205
205
|
type: 'prompt' | 'note';
|
|
206
206
|
text: string;
|
|
207
|
-
as?: 'person'
|
|
207
|
+
as?: 'person';
|
|
208
|
+
from?: {
|
|
209
|
+
session: string;
|
|
210
|
+
title: string;
|
|
211
|
+
};
|
|
212
|
+
replyTo?: number;
|
|
208
213
|
}, context?: {
|
|
209
214
|
project?: string;
|
|
210
215
|
caller?: string;
|
|
211
216
|
task?: string;
|
|
212
|
-
}):
|
|
217
|
+
}): {
|
|
218
|
+
id?: number;
|
|
219
|
+
state: 'queued' | 'delivered';
|
|
220
|
+
};
|
|
213
221
|
abort(session: string, input: {
|
|
214
222
|
turn?: string;
|
|
215
223
|
} | null, context?: {
|
|
@@ -291,7 +299,28 @@ declare module 'claude-code' {
|
|
|
291
299
|
events: {
|
|
292
300
|
Change: {
|
|
293
301
|
readonly session: string;
|
|
294
|
-
readonly part: 'visit' | 'running' | 'tasks' | 'goal' | 'status' | 'deleted';
|
|
302
|
+
readonly part: 'visit' | 'running' | 'tasks' | 'goal' | 'status' | 'deleted' | 'messages';
|
|
303
|
+
};
|
|
304
|
+
};
|
|
305
|
+
};
|
|
306
|
+
'cmod/Store': {
|
|
307
|
+
methods: {
|
|
308
|
+
changed(part: 'plugins' | 'widgets' | 'buildFailures' | 'preferences' | 'links'): void;
|
|
309
|
+
};
|
|
310
|
+
events: {
|
|
311
|
+
Change: {
|
|
312
|
+
readonly part: 'plugins' | 'widgets' | 'buildFailures' | 'preferences' | 'links';
|
|
313
|
+
};
|
|
314
|
+
};
|
|
315
|
+
};
|
|
316
|
+
'cmod/Programs': {
|
|
317
|
+
methods: {
|
|
318
|
+
changed(mod: string, program: string): void;
|
|
319
|
+
};
|
|
320
|
+
events: {
|
|
321
|
+
Change: {
|
|
322
|
+
readonly mod: string;
|
|
323
|
+
readonly program: string;
|
|
295
324
|
};
|
|
296
325
|
};
|
|
297
326
|
};
|
|
@@ -609,7 +638,7 @@ export { AbovePrompt, BelowPrompt, Dashboard, TurnEnd, Working, type Area, type
|
|
|
609
638
|
export type { Step } from './installer.js';
|
|
610
639
|
export type { SlashCommand } from './jobs/slash-command.js';
|
|
611
640
|
export type { Tool } from './jobs/tool.js';
|
|
612
|
-
export { Session, type AnswerOptions, type BeforeMethods, type Surface, type Listener, type ListenerTime, type OnMethods, type ReadOptions, type RecordPart, type Refusal, type SearchOptions, type SessionScope, type SessionSend, type Sessions, type ForkArgs, type CurrentSession, type Placement, type ProjectSetup, type SessionStartAsked, type SessionStarted, type SessionEnded, type ModelChange, type CwdChange, type DirectoryAdd, type Worktree, type Notification, type Elicitation, type ElicitationResponse, type McpServer, type PermissionUpdate, type PermissionCheck, type PermissionRequest, type PermissionDenial, type BatchedCall, type ToolBatch, type Todo, type ReplyDisplay, type TaskOwner, type TaskStartArgs, type ToolCallArgs, type Usage, type RateLimit, type CommandRun, type CommandRunAnswer } from './session/session.js';
|
|
641
|
+
export { Session, type AnswerOptions, type BeforeMethods, type Surface, type Listener, type ListenerTime, type OnMethods, type ReadOptions, type RecordPart, type Refusal, type SearchOptions, type SessionScope, type SessionSend, type SendReceipt, type Sessions, type ForkArgs, type CurrentSession, type Placement, type ProjectSetup, type SessionStartAsked, type SessionStarted, type SessionEnded, type ModelChange, type CwdChange, type DirectoryAdd, type Worktree, type Notification, type Elicitation, type ElicitationResponse, type McpServer, type PermissionUpdate, type PermissionCheck, type PermissionRequest, type PermissionDenial, type BatchedCall, type ToolBatch, type Todo, type ReplyDisplay, type TaskOwner, type TaskStartArgs, type ToolCallArgs, type Usage, type RateLimit, type CommandRun, type CommandRunAnswer } from './session/session.js';
|
|
613
642
|
export type { Context } from './session/context/context.js';
|
|
614
643
|
export type { Turn } from './session/context/turn/turn.js';
|
|
615
644
|
export type { Device } from './session/context/turn/device.js';
|