@cmodjs/core 6.3.0 → 8.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/docs/commands.md +123 -65
- package/docs/dependencies.md +189 -4
- package/docs/index.md +56 -12
- package/docs/install-steps.md +20 -17
- package/docs/jobs.md +43 -16
- package/docs/mod.md +43 -27
- package/docs/options.md +2 -2
- package/docs/session.md +58 -32
- package/docs/testing.md +88 -24
- package/docs/ui.md +128 -58
- package/installer.d.ts +2 -2
- package/jobs/context.js +1 -1
- package/jobs/program.d.ts +4 -1
- package/jobs/program.d.ts.map +1 -1
- package/jobs/program.js +79 -20
- package/mod.d.ts +59 -9
- package/mod.d.ts.map +1 -1
- package/mod.js +5 -3
- package/package.json +1 -1
- package/records.d.ts +15 -2
- package/records.d.ts.map +1 -1
- package/records.js +24 -10
- package/register.d.ts.map +1 -1
- package/register.js +7 -4
- package/rpc.d.ts +7 -0
- package/rpc.d.ts.map +1 -0
- package/rpc.js +59 -0
- package/runtime/bound.d.ts +1 -0
- package/runtime/bound.d.ts.map +1 -1
- package/runtime/bound.js +10 -0
- package/runtime/bun.d.ts +20 -0
- package/runtime/bun.d.ts.map +1 -0
- package/runtime/bun.js +20 -0
- package/runtime/claude.d.ts +1 -0
- package/runtime/claude.d.ts.map +1 -1
- package/runtime/conversations.d.ts +12 -1
- package/runtime/conversations.d.ts.map +1 -1
- package/runtime/conversations.js +472 -362
- package/runtime/deadline.d.ts +4 -3
- package/runtime/deadline.d.ts.map +1 -1
- package/runtime/deadline.js +10 -4
- package/runtime/engine.d.ts +5 -4
- package/runtime/engine.d.ts.map +1 -1
- package/runtime/installer.d.ts +3 -3
- package/runtime/installer.d.ts.map +1 -1
- package/runtime/installer.js +10 -9
- package/runtime/interfaces.d.ts +262 -0
- package/runtime/interfaces.d.ts.map +1 -0
- package/runtime/interfaces.js +935 -0
- package/runtime/lifecycle.d.ts +3 -3
- package/runtime/lifecycle.d.ts.map +1 -1
- package/runtime/lifecycle.js +83 -52
- package/runtime/options.d.ts.map +1 -1
- package/runtime/options.js +2 -6
- package/runtime/parts.d.ts +64 -1
- package/runtime/parts.d.ts.map +1 -1
- package/runtime/parts.js +311 -4
- package/runtime/programs.d.ts +1 -0
- package/runtime/programs.d.ts.map +1 -1
- package/runtime/programs.js +5 -3
- package/runtime/rpc.d.ts +111 -0
- package/runtime/rpc.d.ts.map +1 -0
- package/runtime/rpc.js +387 -0
- package/runtime/sessions.d.ts +6 -4
- package/runtime/sessions.d.ts.map +1 -1
- package/runtime/sessions.js +59 -80
- package/runtime/toaster.js +1 -1
- package/runtime/ui.d.ts +23 -10
- package/runtime/ui.d.ts.map +1 -1
- package/runtime/ui.js +63 -52
- package/runtime/web.d.ts +0 -73
- package/runtime/web.d.ts.map +1 -1
- package/runtime/web.js +9 -5
- package/runtime/widgets.d.ts +4 -2
- package/runtime/widgets.d.ts.map +1 -1
- package/runtime/widgets.js +17 -16
- package/session/conversation.d.ts +7 -1
- package/session/conversation.d.ts.map +1 -1
- package/session/session.d.ts +31 -7
- package/session/session.d.ts.map +1 -1
- package/session/session.js +1 -0
- package/src/installer.ts +2 -2
- package/src/jobs/context.ts +1 -1
- package/src/jobs/program.ts +76 -21
- package/src/mod.ts +51 -10
- package/src/records.ts +33 -9
- package/src/register.ts +7 -4
- package/src/rpc.ts +67 -0
- package/src/runtime/bound.ts +10 -0
- package/src/runtime/bun.ts +40 -0
- package/src/runtime/claude.ts +1 -0
- package/src/runtime/conversations.ts +470 -352
- package/src/runtime/deadline.ts +13 -6
- package/src/runtime/engine.ts +5 -4
- package/src/runtime/installer.ts +13 -12
- package/src/runtime/interfaces.ts +1161 -0
- package/src/runtime/lifecycle.ts +102 -59
- package/src/runtime/options.ts +2 -5
- package/src/runtime/parts.ts +364 -5
- package/src/runtime/programs.ts +6 -3
- package/src/runtime/rpc.ts +457 -0
- package/src/runtime/sessions.ts +63 -83
- package/src/runtime/toaster.ts +1 -1
- package/src/runtime/ui.ts +82 -61
- package/src/runtime/web.ts +10 -39
- package/src/runtime/widgets.ts +20 -18
- package/src/session/conversation.ts +7 -1
- package/src/session/session.ts +22 -7
- package/src/testing/fake-claude.ts +38 -7
- package/src/testing/fake-serve.ts +144 -0
- package/src/testing/fake-sessions.ts +21 -6
- package/src/testing.ts +156 -68
- package/src/ui/areas.ts +2 -2
- package/src/ui/elements.ts +21 -16
- package/src/ui/panes.ts +14 -7
- package/testing/fake-claude.d.ts +6 -0
- package/testing/fake-claude.d.ts.map +1 -1
- package/testing/fake-claude.js +34 -7
- package/testing/fake-serve.d.ts +39 -0
- package/testing/fake-serve.d.ts.map +1 -0
- package/testing/fake-serve.js +110 -0
- package/testing/fake-sessions.d.ts.map +1 -1
- package/testing/fake-sessions.js +22 -6
- package/testing.d.ts +21 -4
- package/testing.d.ts.map +1 -1
- package/testing.js +138 -56
- package/ui/areas.d.ts +3 -1
- package/ui/areas.d.ts.map +1 -1
- package/ui/elements.d.ts +18 -9
- package/ui/elements.d.ts.map +1 -1
- package/ui/elements.js +9 -8
- package/ui/panes.d.ts +10 -6
- package/ui/panes.d.ts.map +1 -1
- package/ui/panes.js +5 -3
- package/runtime/pages.d.ts +0 -32
- package/runtime/pages.d.ts.map +0 -1
- package/runtime/pages.js +0 -142
- package/src/runtime/pages.ts +0 -183
package/docs/commands.md
CHANGED
|
@@ -12,7 +12,7 @@ Each command below restates what `cmod <command> --help` prints, for a mod autho
|
|
|
12
12
|
cmod new <name> [--project]
|
|
13
13
|
```
|
|
14
14
|
|
|
15
|
-
Creates a mod in `./<name>`: a `defineMod` with one listener, a
|
|
15
|
+
Creates a mod in `./<name>`: a `defineMod` with one listener, a view, a widget, and a hotkey that shows the view, a Skill, a test, and a `CHANGELOG.md` ([mod.md](mod.md#release-notes)). Then installs its packages.
|
|
16
16
|
|
|
17
17
|
- `<name>` is lowercase letters, digits, and `-`, starting with a letter.
|
|
18
18
|
- `--project` creates a project-scope plugin in `./.claude/skills/<name>/` of the repository in the current folder, which loads for everyone who trusts the repository. Run it in the repository's root.
|
|
@@ -52,7 +52,7 @@ Stops loading the checkout at `path` (default: the current folder) in every Clau
|
|
|
52
52
|
cmod check [path]
|
|
53
53
|
```
|
|
54
54
|
|
|
55
|
-
Runs every check this
|
|
55
|
+
Runs every check this device can run on the mod at `path` (default: the current folder), each failure with its fix:
|
|
56
56
|
|
|
57
57
|
1. Installs its packages.
|
|
58
58
|
2. Checks its layout.
|
|
@@ -61,7 +61,7 @@ Runs every check this machine can run on the mod at `path` (default: the current
|
|
|
61
61
|
5. Checks the permission check. It adds `"approve": true` to `package.json` `"cmod"` when the mod allows or asks on Claude Code's permission check and `hooks/register.ts` calls `registerPermissionCheck`. It fails a mod whose `src/` hears the permission check while `register.ts` does not call `registerPermissionCheck`, and a mod on `@cmodjs/core` 5.0.0 or later whose `package.json` `"cmod"` still declares `"permissions"`, with the fix `Delete "permissions" from package.json "cmod", and write "approve": true there if the mod approves tool calls.`
|
|
62
62
|
6. Reads the metadata of every file in the mod, and names each file whose metadata cmod cannot read.
|
|
63
63
|
7. Writes the options `defineMod` declares into `.claude-plugin/plugin.json` `userConfig`, and its hotkeys into `package.json` `"cmod"` `hotkeys`, keeping each file's own formatting, so Claude Code shows the options in `/config` ([options.md](options.md)). It loads `hooks/register.ts` to read them, without starting the mod.
|
|
64
|
-
8. Writes the `cmod` dependency in `.claude-plugin/plugin.json` as `>=` the oldest cmod the `@cmodjs/core` the mod installed runs on, `oldestCmodVersion` in its `records.js`, such as `>=
|
|
64
|
+
8. Writes the `cmod` dependency in `.claude-plugin/plugin.json` as `>=` the oldest cmod the `@cmodjs/core` the mod installed runs on, `oldestCmodVersion` in its `records.js`, such as `>=8.0.0`, so every newer cmod runs the mod. When the mod needs a newer cmod than that, such as one whose cmod plugin carries out a call the mod makes, write that minimum yourself as `>=` its version, such as `>=8.1.0`, and `cmod check` keeps it. It raises only a minimum below that oldest cmod, and writes any other range as `>=` that oldest cmod. A `@cmodjs/core` that does not export `oldestCmodVersion` runs on the cmod of its own version, so the range is `>=` that version, such as `>=4.3.4`. A mod still on `@cmodjs/core` 3 keeps its own range ([dependencies.md](dependencies.md#call-the-methods-mod-dependencies)). Claude Code turns a mod off when its cmod is older than that dependency, so `cmod check` first compares it with every cmod plugin Claude Code installed on this device. When an installed copy is older, it updates them as `cmod update cmod` does. When one is still older, as when your `@cmodjs/core` needs a cmod newer than every published one, the check fails, keeps the old dependency, and names the `@cmodjs/core` to install instead. When a cmod linked from a checkout is older, the check fails the same way and says to pull that checkout, because no update reaches it. On a device without Claude Code or without a cmod plugin, such as CI, it writes the dependency at once.
|
|
65
65
|
9. Checks the imports of every file the release ships, the files `cmod publish` would release. It fails a file that imports the `claude-code` module, because every type a mod writes comes from `@cmodjs/core` ([index.md](index.md#what-a-mod-is)). A provider's types file adds to that module with `declare module 'claude-code'`, which imports nothing, so the check keeps it. A folder the release leaves out, such as a library its `"files"` list does not name, may import anything.
|
|
66
66
|
10. Looks for prebuilt binaries outside `cli/`.
|
|
67
67
|
11. Builds the release in a temporary folder as `cmod publish` builds it, with its `"files"` list and its bundled hooks module, and validates the release with Claude Code, `claude plugin validate --strict`. So it fails on a path `plugin.json` names that `"files"` leaves out, a `"files"` path that matches no file in the mod, and each reason a bundle fails, and prints every line the validator writes. Then it deletes the folder.
|
|
@@ -73,7 +73,7 @@ Runs every check this machine can run on the mod at `path` (default: the current
|
|
|
73
73
|
|
|
74
74
|
The checks that read the mod's files, the metadata, imports, binaries, permission check, and test files, skip every file git ignores, such as scratch work in an ignored folder, because no release holds it.
|
|
75
75
|
|
|
76
|
-
`cmod check` fetches `tsc` 7.0.2 and `oxlint` 1.86.0 into the cmod store the first time. A check it cannot run, such as one that needs Claude Code on a
|
|
76
|
+
`cmod check` fetches `tsc` 7.0.2 and `oxlint` 1.86.0 into the cmod store the first time. A check it cannot run, such as one that needs Claude Code on a device without it, fails with the reason, and the later checks still run. It ends with a count of passed, failed, and skipped checks, and exits 1 when one failed.
|
|
77
77
|
|
|
78
78
|
### cmod try
|
|
79
79
|
|
|
@@ -92,7 +92,7 @@ Starts one throwaway Claude Code session with mods set up, for trying a mod by h
|
|
|
92
92
|
- The session keeps how Claude Code reaches the model and what it must never do, so a try is as safe as your own session. From your `settings.json` it keeps `env` (a proxy or `ANTHROPIC_BASE_URL`), the credential helpers (`apiKeyHelper`, `awsAuthRefresh`, `awsCredentialExport`, `gcpAuthRefresh`, `otelHeadersHelper`, `proxyAuthHelper`), the login pins (`forceLoginMethod`, `forceLoginOrgUUID`, `forceLoginGatewayUrl`, `gatewayInternalNetworks`), `sandbox`, and `permissions.deny`. From `~/.claude.json` it keeps your account and the API keys you approved. A `~/` in a helper still means your own home. Hooks, plugins, allow rules, the model, and every other preference stay behind. Managed settings apply as always.
|
|
93
93
|
- `--home <folder>` runs in that folder and keeps it, so the next `cmod try --home <folder>` starts from it. `--home ~` runs in your own home, with your settings and mods.
|
|
94
94
|
- A checkout's program is built from its `cli/` the way `cmod link` builds it, with your own home and environment, so the build finds your toolchains and caches. A GitHub mod's program downloads from the GitHub release of the mod's version, so it fails until `cmod publish` has released that version.
|
|
95
|
-
- When the session ends, even when its terminal closes, it runs each mod's uninstall step and deletes its record, data folder, approval, key bindings, and program, so the mod stays uninstalled. A checkout already set up from the same folder keeps its setup.
|
|
95
|
+
- When the session ends, even when its terminal closes, it runs each mod's uninstall step and deletes its record, data folder, cache folder, approval, key bindings, and program, so the mod stays uninstalled. A checkout already set up from the same folder keeps its setup.
|
|
96
96
|
- A GitHub mod is cloned into a temporary folder, which is deleted too.
|
|
97
97
|
- A mod another folder has set up in that home is refused, so `cmod try` never replaces an installed copy.
|
|
98
98
|
- Arguments after `--` go to `claude`, such as `-- -p "hello"`. An agent tests a mod with one `cmod try <path> -- -p "<prompt>"` run.
|
|
@@ -103,7 +103,7 @@ Starts one throwaway Claude Code session with mods set up, for trying a mod by h
|
|
|
103
103
|
cmod log [<mod>] [--json]
|
|
104
104
|
```
|
|
105
105
|
|
|
106
|
-
Prints the Log that Settings shows
|
|
106
|
+
Prints the Log that Settings shows in cmod's entry, newest first: each failure and warning a mod or cmod met in any session on this computer, with the text `Copy` gives, the versions of the mod, its `@cmodjs/core`, cmod, and Claude Code it happened on, and how often it repeated in its session ([ui.md](ui.md#toasts)). `<mod>` keeps one mod's entries, so an agent working on a mod reads what went wrong in every session without opening Settings. `--json` prints the entries as a list of `{ mod, id, level, message, details, at, firstAt, count, session, versions }`.
|
|
107
107
|
|
|
108
108
|
### cmod publish
|
|
109
109
|
|
|
@@ -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. The cmod plugin of every running session watches `store-changed` and Claude Code's `installed_plugins.json`, 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
|
|
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. The cmod plugin of every running session watches `store-changed` and Claude Code's `installed_plugins.json`, 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
|
|
|
@@ -200,45 +200,85 @@ Lists every plugin Claude Code has installed or linked, with its version. A mod
|
|
|
200
200
|
|
|
201
201
|
## Read your conversations
|
|
202
202
|
|
|
203
|
-
### cmod
|
|
203
|
+
### cmod sessions
|
|
204
204
|
|
|
205
205
|
```text
|
|
206
|
-
cmod
|
|
207
|
-
cmod
|
|
208
|
-
cmod
|
|
209
|
-
cmod
|
|
210
|
-
cmod
|
|
211
|
-
cmod
|
|
212
|
-
cmod
|
|
213
|
-
cmod
|
|
214
|
-
cmod
|
|
215
|
-
cmod
|
|
216
|
-
cmod
|
|
217
|
-
```
|
|
218
|
-
|
|
219
|
-
Reads every conversation Claude Code saved, as the sessions, contexts, turns, tasks, and messages `sessions` answers a mod ([session.md](session.md)), so a person or an agent reads them in a terminal without parsing a transcript.
|
|
220
|
-
|
|
221
|
-
- `
|
|
222
|
-
- `search` prints the newest 50 messages whose text or tool input contains the text, at least 3 characters, any case, each with its time and session. Each tool input value is searched in its first 1,024 characters, and tool results are not searched. `--
|
|
223
|
-
- `messages` prints one conversation's messages in order: 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.
|
|
224
|
-
- `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)).
|
|
225
|
-
- `contexts` prints the conversation's contexts, a new one after each compaction.
|
|
226
|
-
- `tasks` prints the tasks the conversation started, with `--task` the tasks that task started, and with `--nested` every task at any depth.
|
|
227
|
-
- `goal` prints what the conversation is for: the goal a mod set, or its first prompt.
|
|
228
|
-
- `usage` prints the model and the context's tokens as of the last reply.
|
|
229
|
-
- `--task` reads `turns`, `contexts`, `goal`, and `usage` of the session a task's owner runs, the way they read the conversation's.
|
|
230
|
-
- `state` prints what a running conversation resumes from. It reads the index without writing to it, so it never waits for another cmod that is writing the index.
|
|
231
|
-
- `follow` prints each message, turn, context, task, and goal change of the 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.
|
|
206
|
+
cmod sessions list [--every-project] [--since 2d] [--running] [--project <folder>] [--json]
|
|
207
|
+
cmod sessions search <text> [--every-project] [--since 2d] [--running] [--project <folder>] [--session <id> [--task <id>] [--turn <id>] [--context <n>] [--agent]] [--limit <n>] [--before <session>:<id>] [--json]
|
|
208
|
+
cmod sessions read messages [<session>] [--task <id>] [--turn <id>] [--after <id>] [--last <n>] [--json]
|
|
209
|
+
cmod sessions read turns [<session>] [--task <id>] [--context <n>] [--last <n>] [--json]
|
|
210
|
+
cmod sessions read contexts [<session>] [--task <id>] [--json]
|
|
211
|
+
cmod sessions read tasks [<session>] [--task <id> | --nested] [--json]
|
|
212
|
+
cmod sessions read goal [<session>] [--task <id>] [--json]
|
|
213
|
+
cmod sessions read usage [<session>] [--task <id>] [--json]
|
|
214
|
+
cmod sessions read state [<session>] [--json]
|
|
215
|
+
cmod sessions follow [<session>...] [--running] [--json]
|
|
216
|
+
cmod sessions index
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
Reads every conversation Claude Code saved, as the sessions, contexts, turns, tasks, and messages `sessions` answers a mod ([session.md](session.md)), so a person or an agent reads them in a terminal without parsing a transcript. `list`, `search`, and `read` are the `sessions`, `search`, and `read` calls of the `cmod/Sessions` interface.
|
|
220
|
+
|
|
221
|
+
- `list` lists the conversations of the current folder's project, or `--project`'s, newest first, each with its time, id, and title. `--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.
|
|
222
|
+
- `search` prints the newest 50 messages whose text or tool input contains the text, at least 3 characters, any case, each with its time and session. 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.
|
|
223
|
+
- `read messages` prints one conversation's messages in order: 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.
|
|
224
|
+
- `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)).
|
|
225
|
+
- `read contexts` prints the conversation's contexts, a new one after each compaction.
|
|
226
|
+
- `read tasks` prints the tasks the conversation started, with `--task` the tasks that task started, and with `--nested` every task at any depth.
|
|
227
|
+
- `read goal` prints what the conversation is for: the goal a mod set, or its first prompt.
|
|
228
|
+
- `read usage` prints the model and the context's tokens as of the last reply.
|
|
229
|
+
- `--task` reads the `turns`, `contexts`, `goal`, and `usage` of the session a task's owner runs, the way they read the conversation's.
|
|
230
|
+
- `read state` prints what a running conversation resumes from. It reads the index without writing to it, so it never waits for another cmod that is writing the index.
|
|
231
|
+
- `follow` prints each message, turn, context, task, and goal change of the 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.
|
|
232
232
|
- `--json` prints JSON instead of one line each.
|
|
233
233
|
- `index` reads every saved conversation into the index at `~/.local/share/cmod/history-12.sqlite`, which holds where each message is in its transcript, not a copy of it, and each conversation's turns, with the device each ran on, contexts, and tasks. While cmod has set up a mod other than cmod, the cmod plugin runs it in the background at each session's start, and a second run while one is running exits at once. The index forgets a conversation whose transcript is deleted.
|
|
234
234
|
|
|
235
|
+
A cmod plugin before 8.0.0 runs `cmod history`, with `sessions` for `list`, each part of `read` without `read`, and `--all` for `--every-project`, which still works.
|
|
236
|
+
|
|
237
|
+
### cmod ui
|
|
238
|
+
|
|
239
|
+
```text
|
|
240
|
+
cmod ui list <widgets|views|pages> <session>
|
|
241
|
+
cmod ui draw <session> <mod> <id> [--columns <n>] [--surface <surface>] [--area <area>]
|
|
242
|
+
cmod ui press <session> <handler> [<json>]
|
|
243
|
+
cmod ui open <session> <mod> <id>
|
|
244
|
+
cmod ui close <session> <mod> <id>
|
|
245
|
+
cmod ui show <session> <client> [<mod>/<id>...]
|
|
246
|
+
cmod ui follow [<session>...] [--after <cursor>]
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
Reaches each running session's widgets, views, and pages as an app that draws them does, such as cmod's Herdr mod ([ui.md](ui.md#herdr-draws-them-through-cmod-ui)). Each one is a call of the `cmod/UI` interface ([ui.md](ui.md#every-app-reaches-them-through-cmod-ui)) through `cmod serve`, which sends it to the cmod plugin of the session it names, and prints the answer as JSON. A session no cmod plugin on this computer holds fails with `No session <session> runs on this computer, so it shows no UI.`
|
|
250
|
+
|
|
251
|
+
- `list` prints the session's widgets, each `{ mod, id, areas }`, or its views or pages, each `{ mod, id, title }`.
|
|
252
|
+
- `draw` prints the widget, view, or page as element data, with each handler as `{ "$cmodHandler": <number> }`, or `null` while the mod has not drawn it yet. `--columns` is the width it draws in, 80 unless given, and `--surface` the app that draws it: `terminal`, the default, `desktop`, `mobile`, `vscode`, `browser`, or `herdr`. `--area` is the area a widget shows in, one of the areas it lists: `abovePrompt`, `belowPrompt`, `working`, `turnEnd`, or `dashboard`. Without it, a widget draws for the Dashboard when it lists the Dashboard, else for its first area. For `turnEnd`, it draws the session's last finished turn, and prints `null` before the first one finishes.
|
|
253
|
+
- `press` runs the handler with that number from one of the part's last two drawings, with the press `<json>` gives: `{ surface, key, kind, value, link }`, whose `surface` is `terminal` unless it names one.
|
|
254
|
+
- `open` and `close` show or take away the view or page in the session's Sidebar.
|
|
255
|
+
- `show` tells which views and pages one place an app draws in shows, as `cmod/UI` `show` does ([ui.md](ui.md#every-app-reaches-them-through-cmod-ui)), so each one counts as `isShown` in its mod. `<client>` names that place, and each part is `<mod>/<id>`. It replaces that client's last list, a run with no parts clears it, and `cmod serve` forgets a list 16 seconds after its client's last `show`, so an app runs it again before then.
|
|
256
|
+
- `follow` prints the next batch of `Change`, `Redraw`, `Open`, and `Close` events of the sessions named, or of every session, as `{ cursor, events, missed }`, and exits: at once when events came after the `--after` cursor, else on the next event, else after 8 seconds, the time `cmod serve` answers each poll within. Each event is `{ event: "Change", session, part }`, `{ event: "Redraw", session, mod, id }`, or `{ event: "Open" or "Close", session, mod, id }` for a view or page its mod opened or closed itself. Pass the `cursor` it printed to `--after` on the next run, so a loop that runs it again misses no event. `missed` is true when the events before the cursor are unknown: on a run without `--after`, once `cmod serve` started again, or once more events passed than `cmod serve` keeps, 500 of each. Then read every list and drawing again.
|
|
257
|
+
|
|
258
|
+
### cmod run
|
|
259
|
+
|
|
260
|
+
```text
|
|
261
|
+
cmod run <file> [arguments…]
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
Runs a TypeScript script that reads and drives sessions, for a person or an agent at a terminal. The script imports `sessions` from `@cmodjs/core/mod.js`, as a mod does, and `cmod run` connects it to `cmod serve` ([cmod serve](#cmod-serve)): `sessions.list`, `sessions.get`, and `sessions.search` read every session on this computer and through each sessions provider ([session.md](session.md#sessions-providers)), and a session's `send`, `fork`, and `end` reach the session that runs it. A script hears no session, because a listener lives in the session it listens to, as a mod hears only the session it runs in, so its `on` and `before` methods throw `<script>: <method> works only in a mod's own session.` The script also imports `provide` and `providers`, which reach the programs that provide interfaces on this computer through the same connection to `cmod serve`, and a `provide` answers every session while the script runs ([dependencies.md](dependencies.md#interfaces-several-mods-answer-one-name)). The script reads its arguments from `Bun.argv[2]` on. Any other import of `mod.js` throws `a cmod run script imports only sessions, provide and providers from @cmodjs/core/mod.js`, because it belongs to a Claude Code session. `cmod run` ends once the script's top level has run.
|
|
265
|
+
|
|
266
|
+
```ts
|
|
267
|
+
import { Prompt, sessions } from '@cmodjs/core/mod.js'
|
|
268
|
+
|
|
269
|
+
const session = await sessions.get(Bun.argv[2])
|
|
270
|
+
const [last] = await session.messages({ last: 1 })
|
|
271
|
+
console.log(last?.type === 'reply' ? last.text : session.title)
|
|
272
|
+
await session.send({ type: Prompt, text: 'Run the tests again.' })
|
|
273
|
+
```
|
|
274
|
+
|
|
235
275
|
### cmod web
|
|
236
276
|
|
|
237
277
|
```text
|
|
238
278
|
cmod web
|
|
239
279
|
```
|
|
240
280
|
|
|
241
|
-
Opens the browser app at `http://127.0.0.1:<port>/` and prints that address. The browser app lists every Claude Code session that runs on the computer, in every project, in four groups: Needs you (a permission prompt, a question, or a turn that failed or was stopped), Replied (an answer the person has not opened), Working, and Idle. A session opens its conversation with a prompt box under it, which sends the text as the person's own prompt in that session, a Stop button while it works, and a tab for each
|
|
281
|
+
Opens the browser app at `http://127.0.0.1:<port>/` and prints that address. The browser app lists every Claude Code session that runs on the computer, in every project, and every running session of each sessions provider, in four groups: Needs you (a permission prompt, a question, or a turn that failed or was stopped), Replied (an answer the person has not opened), Working, and Idle. A session opens its conversation with a prompt box under it, which sends the text as the person's own prompt in that session, a Stop button while it works, and a tab for each of its views, the cmod plugin's Dashboard, History, and Settings among them, and each page open in it, where a press, a text, or a pick runs the mod's handler in that session. `j` and `k` move between sessions, `Enter` opens one and puts the cursor in its prompt box, `Esc` returns to the list, `e` marks a reply done, and `u` marks it unread. A permission prompt or a question is answered in the session's terminal. The browser app runs while `Show the Sidebar in your browser` is on in Settings, under cmod, Preferences, which `open in browser` on the Sidebar's key bar turns on and runs this command. When it does not run, `cmod web` exits 1 and says so. It opens the address by the rule a `Button` with `href` follows ([ui.md](ui.md#a-button-opens-a-web-page-with-href)): with the program `BROWSER` names, else `open` on macOS and `xdg-open` on Linux. Over ssh, on Linux with no display, or with `BROWSER` set to `true`, it opens nothing, prints the address, and exits 1 with `this computer has no browser to open, so open the address above yourself.` When the opener fails, it exits 1 after it printed the address. While the browser app is on the person's tailnet ([cmod program](#cmod-program)), it also prints `From your other devices: https://<computer>.<tailnet>.ts.net:<port>/`, which opens the browser app from each of the person's devices.
|
|
242
282
|
|
|
243
283
|
## Run in an install script
|
|
244
284
|
|
|
@@ -248,7 +288,7 @@ Opens the browser app at `http://127.0.0.1:<port>/` and prints that address. The
|
|
|
248
288
|
cmod watch
|
|
249
289
|
```
|
|
250
290
|
|
|
251
|
-
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`, and 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`. 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 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
|
|
291
|
+
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`, and 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`. 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 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. Before each touch it reads the newest cmod in the cmod store, the newest version folder of `bin/cmod` that the launcher runs. 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 within 15 seconds. It also exits once the process that started it ends, so a session that crashed leaves no watcher behind.
|
|
252
292
|
|
|
253
293
|
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.
|
|
254
294
|
|
|
@@ -258,7 +298,7 @@ A cmod before 4.1.0 linked a checkout by writing it into `CLAUDE_CODE_PLUGIN_DIR
|
|
|
258
298
|
cmod download <program> <machine> <url> <sha256> [<machine> <url> <sha256> …]
|
|
259
299
|
```
|
|
260
300
|
|
|
261
|
-
Downloads a program for an install script: fetches the download for this machine, checks its SHA-256, unpacks it, and moves `<program>` to `$CMOD_DATA/bin/<program
|
|
301
|
+
Downloads a program for an install script: fetches the download for this machine, checks its SHA-256, unpacks it, and moves `<program>` to `$CMOD_CACHE/bin/<program>`, the mod's cache folder. It links cmod's programs folder and `$CMOD_DATA/bin/<program>`, where cmod 7 put it, to that file. Before the install step, `cmod setup` moves each program cmod 7 downloaded to `$CMOD_DATA/bin/` there and leaves that link in its place. [install-steps.md](install-steps.md#download-a-program-in-an-install-step) explains it.
|
|
262
302
|
|
|
263
303
|
## Run from a mod's program
|
|
264
304
|
|
|
@@ -267,15 +307,20 @@ A mod's own program runs outside any session, as one copy per computer or over `
|
|
|
267
307
|
### cmod options
|
|
268
308
|
|
|
269
309
|
```text
|
|
270
|
-
cmod options <mod> [--project <folder>]... [--json]
|
|
310
|
+
cmod options get <mod> [--project <folder>]... [--json]
|
|
311
|
+
cmod options set <mod> <key> <value>
|
|
271
312
|
```
|
|
272
313
|
|
|
273
|
-
|
|
314
|
+
`get` prints a mod's option values in two levels. `person` holds the values the person set in `/config`. `projects` holds the values each project's committed `.claude/cmods/<mod>/options.json` sets, keyed by the project's git root as `git rev-parse --show-toplevel` prints it, or by the project's own folder outside git. With no `--project`, it reads every project cmod's conversation index holds a session of, and lists only those whose `options.json` exists. It leaves out secrets, and the entries a session would ignore, and names each of those on stderr. A session uses a project's value over the person's, and a value the person's organization locks over both, which this command cannot read outside Claude Code. `--json` prints `{ person, projects }`:
|
|
274
315
|
|
|
275
316
|
```json
|
|
276
317
|
{ "person": { "<option>": "<value>" }, "projects": { "<project>": { "<option>": "<value>" } } }
|
|
277
318
|
```
|
|
278
319
|
|
|
320
|
+
`set` sets one option of an installed plugin through `claude plugin configure`, the way `/config` sets it, such as `cmod options set my-mod branch main`. A list option takes its items separated by commas. It refuses a key the plugin's `plugin.json` `userConfig` does not declare. A field in Settings and the option questions a mod asks at its first start run it, and the mod reads the new value at its next start ([options.md](options.md)).
|
|
321
|
+
|
|
322
|
+
A mod built on `@cmodjs/core` before 8.0.0 runs `cmod options <mod>` for `get` and `cmod option <mod> <key> <value>` for `set`, and both still work.
|
|
323
|
+
|
|
279
324
|
### cmod device
|
|
280
325
|
|
|
281
326
|
```text
|
|
@@ -284,6 +329,18 @@ cmod device [--json]
|
|
|
284
329
|
|
|
285
330
|
Prints the computer as a mod's `device.read()` gives it: its id, name, operating system, and architecture ([mod.md](mod.md#device-the-computer-the-session-runs-on)). It runs the same reader, so a program names each computer by the id its mod sees. `--json` prints `{ id, name, os, arch }`. On a computer with no machine id, it exits 1 and says so.
|
|
286
331
|
|
|
332
|
+
### cmod data
|
|
333
|
+
|
|
334
|
+
```text
|
|
335
|
+
cmod data [--json]
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
Prints the data folder of each mod cmod set up, the folder its `mod.dataFolder` names, so a program that moves a person's work to another computer knows what to copy. It reads the mods from the install records in the cmod store, as `cmod list` does, adds the cmod plugin, which has no install record but keeps each session's goal, tasks, and Log in its data folder, and leaves out a mod whose data folder does not exist. It leaves out each `mod.cacheFolder`, such as the programs `cmod download` fetches, because a mod builds that folder again wherever it is missing ([mod.md](mod.md#mod-this-mod)). It leaves out `secrets.json`, which sits at the root of the cmod store, outside every data folder. It prints one `<mod> <folder>` line for each mod, and `--json` prints a list:
|
|
339
|
+
|
|
340
|
+
```json
|
|
341
|
+
[{ "mod": "<mod>", "folder": "<absolute path of its data folder>" }]
|
|
342
|
+
```
|
|
343
|
+
|
|
287
344
|
## Run by cmod
|
|
288
345
|
|
|
289
346
|
cmod runs these itself. A person runs them to see a step's whole log, or to finish a step.
|
|
@@ -302,78 +359,79 @@ Refuses a machine the `os` and `cpu` keys of the mod's `package.json` leave out.
|
|
|
302
359
|
cmod teardown <plugin-name> [--events]
|
|
303
360
|
```
|
|
304
361
|
|
|
305
|
-
Runs a removed mod's saved uninstall step, then deletes its install record, the saved step, every version of its program, its data folder, and `instances/<plugin-name>/`, where its `singleInstance` and `isService` programs keep
|
|
362
|
+
Runs a removed mod's saved uninstall step, then deletes its install record, the saved step, every version of its program, its data folder, its cache folder, and `instances/<plugin-name>/`, where its `singleInstance` and `isService` programs keep each running copy's pid and address, stops and deletes each service of the computer it runs a program as, with its record and log in `services/<plugin-name>/` ([cmod program](#cmod-program)), takes each web app it put on the person's tailnet off it and deletes `tailnet/<plugin-name>/`, takes out each Claude Code setting it changed that still has the value it set, deletes its secrets ([cmod secrets](#cmod-secrets)), and deletes its entry in `consent.json`. It keeps the mod's config folder, `~/.claude/cmods/<plugin-name>`. A failed uninstall step keeps the record, so `cmod teardown` can run again.
|
|
306
363
|
|
|
307
|
-
### cmod
|
|
364
|
+
### cmod hotkeys
|
|
308
365
|
|
|
309
366
|
```text
|
|
310
|
-
cmod
|
|
367
|
+
cmod hotkeys set <mod | plugin-root> <hotkey> <combo>
|
|
311
368
|
```
|
|
312
369
|
|
|
313
|
-
|
|
370
|
+
`set` binds one hotkey of a mod to a new combo in Claude Code's `keybindings.json`, such as `cmod hotkeys set my-mod toggle ctrl+shift+n`, and removes the combo it had. It binds a hotkey without a default combo the same way. A plugin root holds a `/`, such as `./my-mod`, so a mod Claude Code loads with `--plugin-dir`, which has no install record, binds its hotkeys too. A combo in Settings, under the mod, Hotkeys, runs it, and so does the cmod plugin for its own two hotkeys at its first start, with its own plugin folder. It refuses a combo that is not one, and a combo the person already bound to something else, with `<combo> already runs something else in ~/.claude/keybindings.json. Pick another combo.` The mod's next update keeps the combo ([mod.md](mod.md#hotkeys)). A cmod plugin before 8.0.0 runs `cmod hotkey` with the same arguments, which still works.
|
|
314
371
|
|
|
315
|
-
### cmod
|
|
372
|
+
### cmod secrets
|
|
316
373
|
|
|
317
374
|
```text
|
|
318
|
-
cmod
|
|
319
|
-
cmod
|
|
320
|
-
cmod
|
|
375
|
+
cmod secrets store <mod> <key>
|
|
376
|
+
cmod secrets get <mod> <key>
|
|
377
|
+
cmod secrets delete <mod> <key>
|
|
321
378
|
```
|
|
322
379
|
|
|
323
|
-
Keeps a mod's secrets, for `mod.secrets` and the mod's own programs ([mod.md](mod.md#mod-secrets)). `store` reads the value from stdin, such as `printf '%s' "$TOKEN" | cmod
|
|
380
|
+
Keeps a mod's secrets, for `mod.secrets` and the mod's own programs ([mod.md](mod.md#mod-secrets)). `store` reads the value from stdin, such as `printf '%s' "$TOKEN" | cmod secrets store my-mod token`, and refuses a terminal, where the value would show, and an empty value. `get` prints the value to stdout as it was stored, with no newline added, and prints nothing for a secret the mod does not have. `delete` removes one secret. A value never goes in the arguments, where every process on the computer can read it. A mod built on `@cmodjs/core` before 8.0.0 runs `cmod secret` with the same arguments, which still works.
|
|
324
381
|
|
|
325
|
-
Every mod's secrets live in `secrets.json`
|
|
382
|
+
Every mod's secrets live as plain values in `secrets.json` at the root of the cmod store, mode 600, as `{ "<mod>": { "<key>": "<value>" } }`, on every platform and with no keychain. A value cmod 7.0.0 or older sealed on macOS is opened once with the `cmod Safe Storage` key in the login keychain and written back plain, the first time it is read or the file changes. `cmod teardown` deletes the secrets of a removed mod.
|
|
326
383
|
|
|
327
384
|
### cmod settings
|
|
328
385
|
|
|
329
386
|
```text
|
|
330
|
-
cmod settings <mod> <user|project|local> <json> [--project <folder>]
|
|
387
|
+
cmod settings update <mod> <user|project|local> <json> [--project <folder>]
|
|
331
388
|
```
|
|
332
389
|
|
|
333
|
-
|
|
390
|
+
`update` changes Claude Code settings for a set-up mod, as its `settings.user.update`, `settings.project.update`, and `settings.local.update` do ([mod.md](mod.md#settings-claude-code-s-settings-files)), such as `cmod settings update my-mod user '{"env":{"EDITOR":"vim"}}'`. It merges the JSON object into the user, project, or local settings as a JSON Merge Patch: an object merges into the object already there, `null` removes the key, and an array or any other value replaces it. The project and local settings are those of `--project`, the current folder when it is left out, and `mcpServers` in the project settings goes to `.mcp.json`. cmod keeps every other key and the file's formatting, and `cmod teardown` takes out each value the mod set that is still the same, then each object that leaves empty. A cmod plugin before 8.0.0 runs `cmod settings <mod> <user|project|local> <json>`, with no `update`, which still works.
|
|
334
391
|
|
|
335
392
|
### cmod rules
|
|
336
393
|
|
|
337
394
|
```text
|
|
338
|
-
cmod rules [--project <folder>] [--json]
|
|
395
|
+
cmod rules sync [--project <folder>] [--plugin <folder>] [--json]
|
|
339
396
|
```
|
|
340
397
|
|
|
341
|
-
|
|
398
|
+
`sync` links the `rules/` folder of each mod that is on into Claude Code's rules folder, and removes the link of each that is off or removed ([mod.md](mod.md#rules)). A mod the person installed links at `<config>/rules/<mod>`, and one turned on only for `--project`, the current folder when it is left out, links at `<project>/.claude/rules/<mod>`. It prints the rules it linked. With `--json` it prints `{ linked, placed, removed, watched }`, where `placed` and `removed` name the mods whose link this run made or took away, and `watched` lists the files and folders whose change can change the next run. `--plugin` names the cmod plugin's own folder, whose `rules/` links for every project, because the cmod plugin has no install record. `cmod install`, `update`, `remove`, `enable`, `disable`, `setup`, `teardown`, `link`, and `unlink` run it after they succeed. The cmod plugin runs it with `--plugin` when a session starts and before a prompt, each time only when a `watched` path changed since its last run. A cmod plugin before 8.0.0 runs `cmod rules` with no `sync`, which still works.
|
|
342
399
|
|
|
343
400
|
### cmod task
|
|
344
401
|
|
|
345
402
|
```text
|
|
346
|
-
cmod task start <prompt> --title <title> [--clone] [--agent <type>] [--model <model>] [--cwd <folder>] [--json]
|
|
403
|
+
cmod task start <prompt> --title <title> [--clone [--at <message>]] [--agent <type>] [--model <model>] [--cwd <folder>] [--json]
|
|
347
404
|
```
|
|
348
405
|
|
|
349
|
-
Starts a task in a new background Claude Code session, for a mod's `startTask` with `isBackground` and its `
|
|
406
|
+
Starts a task in a new background Claude Code session, for a mod's `startTask` with `isBackground` and its `fork` with `isBackground` ([session.md](session.md#act-on-a-session)). The task belongs to the session Claude Code names in `CLAUDE_CODE_SESSION_ID`, which the cmod plugin sets when it runs the command. It runs `claude --bg` on the prompt in `--cwd`, the current folder when it is left out. With `--clone` it first writes a fork of that session's conversation as a new transcript beside it, as Claude Code's own fork writes one: each message of the conversation's current branch, from its first through its last, or through the message `--at` names and nothing after it, each naming the message it copies in `forkedFrom`. It then runs `claude --bg --resume <fork>`, so the new session carries on from the copy. `--agent` and `--model` pick the agent definition and the model of a fresh session. It finds the new session's id from the 8 characters `claude --bg` prints, through `claude agents --json --all`, and passes the starting session and the task in the new session's `--settings` env, so its cmod plugin tells the starting session at its first stop that the task answered. It saves the task in cmod's data folder, so `cmod sessions read tasks` of the starting session lists it, with the status `claude agents` gives it. It prints the task, as one line of JSON with `--json`.
|
|
350
407
|
|
|
351
408
|
### cmod program
|
|
352
409
|
|
|
353
410
|
```text
|
|
354
|
-
cmod program <mod> [--web-app] [--no-wait | --service [--env <name>]... | --remove-service] -- <command…>
|
|
411
|
+
cmod program <mod> [--web-app] [--no-wait | --service [--env <name>]... [--process-type <type>] | --remove-service] -- <command…>
|
|
355
412
|
```
|
|
356
413
|
|
|
357
|
-
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, writes its first line on standard output, its address, with the copy's
|
|
414
|
+
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 whenever that folder changes and every 5 seconds, so it takes over once the holder exits. 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.
|
|
358
415
|
|
|
359
|
-
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`,
|
|
416
|
+
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.
|
|
360
417
|
|
|
361
418
|
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 `servesTailnet` changes, which it reads every 5 seconds, 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.
|
|
362
419
|
|
|
420
|
+
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.
|
|
421
|
+
|
|
363
422
|
With `--remove-service`, it stops the program's service, deletes its file, its record in `services/<mod>/<program>.json`, and its log, and exits 0, holding the mod's lock in the cmod store so it never runs beside `cmod setup` or `cmod teardown` of the mod. A program with no service changes nothing. A session that starts a mod runs it for each record in `services/<mod>/` whose program the mod's setup no longer adds as an `isService` program, so a new version that dropped `isService` or renamed the program leaves no service of the old one. A session reads that folder without a process, so a mod with no `services/<mod>/` folder runs nothing for it.
|
|
364
423
|
|
|
365
|
-
### cmod
|
|
424
|
+
### cmod serve
|
|
366
425
|
|
|
367
426
|
```text
|
|
427
|
+
cmod serve
|
|
368
428
|
cmod web serve
|
|
369
429
|
```
|
|
370
430
|
|
|
371
|
-
Serves
|
|
431
|
+
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.
|
|
372
432
|
|
|
373
|
-
|
|
433
|
+
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`, which it reads again 300 ms after that folder changes, 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 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`.
|
|
374
434
|
|
|
375
|
-
|
|
376
|
-
cmod option <name> <key> <value>
|
|
377
|
-
```
|
|
435
|
+
At its start it also places cmod's Herdr mod, which draws every session's widgets, views, and pages in the Herdr app through [`cmod ui`](#cmod-ui) ([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.
|
|
378
436
|
|
|
379
|
-
|
|
437
|
+
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. It lists the running sessions of each other sessions provider, another device's `cmod serve` or a mod's program, beside them, 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.
|