kith-coord 0.1.8 → 0.2.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/CHANGELOG.md +17 -0
- package/CONTRIBUTING.md +7 -1
- package/README.md +81 -142
- package/assets/demo/claim.jq +5 -0
- package/assets/demo/claims.gif +0 -0
- package/assets/demo/claims.tape +59 -0
- package/assets/demo/prepare.sh +63 -0
- package/bin/kith-menubar +0 -0
- package/dist/cli/index.js +4257 -941
- package/dist/cli/index.js.map +1 -1
- package/dist/command-worker.js +31 -2
- package/dist/command-worker.js.map +1 -1
- package/dist/index.d.ts +216 -11
- package/dist/index.js +3015 -461
- package/dist/index.js.map +1 -1
- package/docs/architecture.md +5 -2
- package/docs/install.md +183 -0
- package/docs/integrations.md +8 -4
- package/docs/protocol/tools.v1.json +53 -0
- package/docs/protocol.md +13 -2
- package/docs/reliability.md +1 -1
- package/docs/roadmap.md +2 -0
- package/docs/sessions-and-mutexes.md +29 -3
- package/docs/usage.md +45 -0
- package/package.json +35 -25
- package/server.json +3 -3
package/docs/architecture.md
CHANGED
|
@@ -13,12 +13,13 @@ Kith runs locally. There is no coordination server: CLI and MCP clients share `.
|
|
|
13
13
|
| `intents.ts` | Work declarations, task dependencies, transactional claims |
|
|
14
14
|
| `ast-analyzer.ts`, `dep-graph.ts` | Advisory source-derived contracts and import relationships |
|
|
15
15
|
| `shadow-git.ts` | Per-agent indexes, synthetic commits, dirty-tree merge probes |
|
|
16
|
-
| `worktree-cow.ts` | Isolated worktree creation
|
|
16
|
+
| `worktree-cow.ts` | Isolated worktree creation, dependency hydration, and removal of worktrees Kith created |
|
|
17
|
+
| `worktree-adopt.ts` | Adopt an existing linked worktree (Claude Code's `.claude/worktrees/<name>` layout, or any `git worktree list` entry), and record created/adopted provenance |
|
|
17
18
|
| `merge-train.ts` | Serialized integration through a disposable staging worktree |
|
|
18
19
|
| `brief.ts` | The read-only situational summary shared by the offline reader, the CLI and the MCP tool |
|
|
19
20
|
| `mode.ts` | Repository workflow mode: `worktrees` or `main` |
|
|
20
21
|
| `handoffs.ts`, `handoff-store.ts` | Notes that survive a session boundary: written by agents, recorded by Kith when a session ends without one, delivered by task and scope overlap; storage is DB-only so it is safe inside reclaim and completion transactions |
|
|
21
|
-
| `bash-guard.ts` | Best-effort snapshots
|
|
22
|
+
| `bash-guard.ts` | Best-effort snapshots, quarantine recovery, and the shared-ref firewall |
|
|
22
23
|
| `broker.ts` | Port reservations, FIFO mutex tickets, renewable command leases and process-group guards |
|
|
23
24
|
|
|
24
25
|
`engine.ts` shares begin/complete orchestration across adapters. `src/cli` adapts commands and hook payloads. `src/mcp/server.ts` exposes tools. Library consumers use `src/index.ts` exports and close engines explicitly.
|
|
@@ -33,6 +34,8 @@ Git clients launched from subdirectories, symlink aliases and linked checkouts d
|
|
|
33
34
|
|
|
34
35
|
Session capabilities are held in each engine's memory and hashed in the separate `agent_sessions` table. Agent records/status do not expose them. Mutation boundaries assert ownership inside writer transactions where applicable. `mutex_waiters` preserves handoff order independently of a resource row, and `mutex_runs` preserves execution exclusion even if session/resource rows expire. A private IPC handshake records a worker process group before it can execute a command. See [session and command lifecycle](sessions-and-mutexes.md).
|
|
35
36
|
|
|
37
|
+
A session that is already inside a linked worktree can register that checkout instead of creating one under `.coord/worktrees`. Hooks do this when the hook `cwd` is unambiguously that worktree. `kith adopt` and `kith_adopt_worktree` do it explicitly. The registration records whether Kith created the worktree. Garbage collection and `kith worktree remove` delete only worktrees Kith created; an adopted directory stays until `kith worktree remove --delete-adopted`. Integration of an adopted branch still goes through the merge train and the verification command. A detached HEAD and a branch checked out in another worktree are refused at that gate.
|
|
38
|
+
|
|
36
39
|
Worktree edit reports read source bytes from the registered worktree and store repository-relative contracts. Git checkpoint/merge subprocesses receive the owning capability in their environment so generated pre-commit guards can authorize them. Generated pre-commit guards inspect the invoking Git checkout/index even when `--repo` selects shared state through another checkout.
|
|
37
40
|
|
|
38
41
|
## Adaptation
|
package/docs/install.md
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
# Install
|
|
2
|
+
|
|
3
|
+
Kith needs **Git 2.38+** and **Node.js 22.13+ on 22.x, or Node.js 24+**. Full workflows target macOS and Linux. Native Windows MCP checks cover claims, worktrees, ports, integration and recovery; supervised mutex commands and shell hooks require macOS/Linux or WSL. See the [support evidence](client-validation.md#native-windows).
|
|
4
|
+
|
|
5
|
+
Git recording and integration require a commit identity configured for the repository (`user.name` and `user.email`). Kith does not change your global Git identity.
|
|
6
|
+
|
|
7
|
+
## Which to use
|
|
8
|
+
|
|
9
|
+
| You want | Use |
|
|
10
|
+
| --- | --- |
|
|
11
|
+
| Claude Code only | The [Claude Code plugin](#claude-code-plugin). No global npm install. |
|
|
12
|
+
| Cursor, Codex, Claude Desktop, or the macOS menu bar | `npm i -g kith-coord && kith install` |
|
|
13
|
+
| Both | Keep both. The plugin hooks exit when `kith install` or `kith init` has already registered that Claude hook, so the tool call is checked once. `kith doctor` reports this and does not fail. |
|
|
14
|
+
|
|
15
|
+
`kith install` pins a runtime outside the npx cache. The plugin resolves `kith-coord` through `npx -y` on each hook and MCP start. The first call can be slower while npx fetches the package. Prefer `kith install` when you want that pin, Cursor hooks, or Radar.
|
|
16
|
+
|
|
17
|
+
## Claude Code plugin
|
|
18
|
+
|
|
19
|
+
In Claude Code:
|
|
20
|
+
|
|
21
|
+
```text
|
|
22
|
+
/plugin marketplace add connorhriley/kith
|
|
23
|
+
/plugin install kith@kith
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
The same steps from a shell:
|
|
27
|
+
|
|
28
|
+
```sh
|
|
29
|
+
claude plugin marketplace add connorhriley/kith
|
|
30
|
+
claude plugin install kith@kith
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
The marketplace file is [`.claude-plugin/marketplace.json`](../.claude-plugin/marketplace.json). The plugin is [`plugins/kith`](../plugins/kith): [`.claude-plugin/plugin.json`](../plugins/kith/.claude-plugin/plugin.json), [`hooks/hooks.json`](../plugins/kith/hooks/hooks.json), and [`.mcp.json`](../plugins/kith/.mcp.json). Hooks and the MCP server run the published package:
|
|
34
|
+
|
|
35
|
+
```text
|
|
36
|
+
npx -y kith-coord hook pre --client claude --auto
|
|
37
|
+
npx -y kith-coord mcp --compact
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
`hooks/run.mjs` is the hook command Claude Code actually starts. It forwards stdin, including the hook `cwd`, to that `npx` command. If `~/.claude/settings.json`, or the project `.claude/settings.json` for `CLAUDE_PROJECT_DIR`, already contains the matching `kith hook` command, the script exits 0 and does not start a second check. PreToolUse uses `onFailure: "block"`, matching `kith install`.
|
|
41
|
+
|
|
42
|
+
When that session has joined and its `cwd` is a linked worktree, the hook adopts the checkout instead of creating another one. Claude Code's `claude --worktree` uses `.claude/worktrees/<name>`. The same adoption applies to any other `git worktree list` entry. Kith does not delete a worktree it did not create. `${CLAUDE_PROJECT_DIR}` stays on the original checkout and is not treated as the worktree. See [Adopt a worktree](usage.md#adopt-a-worktree-that-already-exists).
|
|
43
|
+
|
|
44
|
+
The plugin does not write `~/.claude/settings.json`, does not install Cursor hooks, and does not register the menu bar. Uninstall it from Claude Code's `/plugin` list. That does not remove hooks written by `kith install`; `kith uninstall` does.
|
|
45
|
+
|
|
46
|
+
The version field is omitted from the manifest, so a GitHub marketplace install tracks the commit Claude Code last fetched. The hook script still runs whatever `npx -y kith-coord` resolves, which is the current published package, not the git checkout.
|
|
47
|
+
|
|
48
|
+
## `kith install`
|
|
49
|
+
|
|
50
|
+
```sh
|
|
51
|
+
npm i -g kith-coord && kith install
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
`kith install` puts `kith` on your `PATH` and keeps that runtime outside the npx cache. It writes a global MCP entry for each detected client, using the compact tool profile (`kith mcp --compact`), and installs silent-solo `--auto` hooks for Claude Code and Cursor. One agent stays at **Watching only** and does not write coordination state. When another writer overlaps, the hooks join Kith. If that session is already inside a linked worktree, joining adopts it. Otherwise the hooks isolate the work into a worktree Kith creates, or into a claim. On macOS it also loads a login LaunchAgent (`dev.kith.radar`) unless you pass `--no-autostart` or `--no-radar`. It does not claim any files. An agent claims when it starts a task.
|
|
55
|
+
|
|
56
|
+
Codex CLI has no native tool hooks, so it uses the MCP tools. Linux and Windows skip the menu bar; use `kith watch`.
|
|
57
|
+
|
|
58
|
+
Directories that scan a repository for an MCP server read the committed [`.mcp.json`](../.mcp.json): `npx -y kith-coord mcp` over stdio. That entry does not pin a checkout and does not install hooks. `kith install` does not read or edit it.
|
|
59
|
+
|
|
60
|
+
### Upgrading
|
|
61
|
+
|
|
62
|
+
Stop existing Kith connections first. Back up stopped coordination state (including SQLite sidecars) and retain worktrees; upgrade all coordinators sharing a repository together. The storage schema stays 3 and the protocol stays 1.6.0. Databases already on schema 3 open without a version migration. The first open on 0.2.0 creates an optional `worktree_registrations` table; binaries from 0.1.6 through 0.1.9 ignore it. The first open on 0.1.8 or later creates an optional `handoffs` table; binaries from 0.1.6 and 0.1.7 ignore that table and keep working, but they do not read or write handoff notes. An upgrade from schema 2 still applies the 0.1.6 migration to schema 3, which older binaries refuse. After upgrading, run `kith install` so hooks and client entries use this runtime. `kith doctor` reports a hook or MCP entry still pinned to an older runtime. Existing custom launchers are preserved; review their pinned version before reconnecting. On macOS, `kith install` and `kith setup` register a login LaunchAgent unless `--no-autostart` or `--no-radar` is passed. See [recovery guidance](reliability.md#recovery).
|
|
63
|
+
|
|
64
|
+
### VS Code or Cursor
|
|
65
|
+
|
|
66
|
+
Install **Kith** (`kith-coord.kith`) from the [VS Code Marketplace](https://marketplace.visualstudio.com/items?itemName=kith-coord.kith) or [Cursor / Open VSX](https://open-vsx.org/extension/kith-coord/kith). You can also search for `kith-coord.kith` in the editor's Extensions view.
|
|
67
|
+
|
|
68
|
+
To select release **0.2.0** explicitly with an editor CLI already on your `PATH`:
|
|
69
|
+
|
|
70
|
+
```sh
|
|
71
|
+
code --install-extension kith-coord.kith@0.2.0
|
|
72
|
+
cursor --install-extension kith-coord.kith@0.2.0
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Use the command for your editor. A marketplace lookup can temporarily select an older version; the [extension guide](../extensions/editor/README.md#install) also links the published 0.2.0 VSIX.
|
|
76
|
+
|
|
77
|
+
Open a trusted local Git checkout and approve Kith's MCP server through the editor. The extension bundles the coordination server, detects Node, and preserves existing MCP entries, hooks and tool permissions. **No global npm install is needed.** It registers the compact tool profile (`kith.mcp.profile`, `compact` by default, or `full`), shows a read-only global hook status note in Output, and adds **Kith: Install Global Hooks & Autostart** (`kith.installGlobal`). The bundled extension does not include the macOS menu-bar helper; run `kith install` from the CLI on macOS for Radar login autostart. Each agent still needs to use Kith's tools; installing the extension alone does not enforce claims on other writers.
|
|
78
|
+
|
|
79
|
+
Start with a scoped task:
|
|
80
|
+
|
|
81
|
+
```text
|
|
82
|
+
Use Kith to begin an isolated task in this repository with a unique agent ID.
|
|
83
|
+
Claim only the files this task needs, edit the returned worktree, and report edits.
|
|
84
|
+
Run the project checks and complete through Kith with that verification command.
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
The [extension guide](../extensions/editor/README.md) covers settings and existing configurations; [recorded editor checks](client-validation.md#editor-marketplaces-and-signed-in-chats) distinguish installation, native MCP registration and signed-in task results.
|
|
88
|
+
|
|
89
|
+
### CLI and other MCP clients
|
|
90
|
+
|
|
91
|
+
Configure detected clients and add project instructions with:
|
|
92
|
+
|
|
93
|
+
```sh
|
|
94
|
+
npx --yes --package kith-coord@0.2.0 kith setup
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
**`kith install`** is the one-command onboarding path. `kith setup` remains a compatible alias:
|
|
98
|
+
|
|
99
|
+
- Configures global MCP servers with the concise **`--compact`** tool profile by default (`kith mcp --compact`, or `--full` for the complete surface).
|
|
100
|
+
- Installs global silent-solo `--auto` hooks for **Claude Code** (`~/.claude/settings.json`) and **Cursor** (`~/.cursor/hooks.json`). Solo work stays zero-write (`Watching only`); when concurrent activity overlaps, hooks auto-join Kith and isolate writers into worktrees or leases.
|
|
101
|
+
- On **macOS**, installs and starts a login `LaunchAgent` (`dev.kith.radar`) for background menu-bar Radar, and opens the read-only view. `--no-autostart` or `--no-radar` skips the login item. Repeat setup keeps the existing workspace.
|
|
102
|
+
- **`kith uninstall`** removes the macOS `LaunchAgent`, global Kith hooks, global MCP entries, retained runtimes and launcher symlinks.
|
|
103
|
+
|
|
104
|
+
Note the platform and client boundaries: **Codex CLI** does not expose native pre/post tool hooks, so it coordinates through `--compact` MCP tools and Radar/watcher observations rather than automatic hook interception. **Linux and Windows** skip macOS menu-bar autostart and use `kith watch` for passive supervision.
|
|
105
|
+
|
|
106
|
+
Durable setup starts with **0.1.7** (retaining an exact self-contained runtime outside npx's cache, verifying MCP discovery, and backing up modified files). Existing custom Kith launchers, peer servers, hooks and permissions are preserved. Reconnect the client and approve its MCP server through the client's normal controls.
|
|
107
|
+
|
|
108
|
+
Day to day, run `kith` (a read-only status overview in a terminal), `kith status`, `kith brief`, `kith run`, `kith gc`, `kith doctor [path]`, or `kith help --all`. The view says **Watching only** until a task or concurrent overlap is recorded. `kith install --dry-run` and `kith setup --dry-run` preview without writes.
|
|
109
|
+
|
|
110
|
+
[`.mcp.json`](../.mcp.json) is the directory discovery entry: `npx -y kith-coord mcp`. It is not a pin to this repository. `kith install` does not read or edit it, and `kith doctor` only reports that the launcher file is present; neither command starts the server or creates `.coord` state. A client that loads project MCP config, such as Claude Code, can start that published package from the file. Because `--repo` is omitted, the process does not pin this checkout or open the database until a tool call names one. `kith init` still replaces the `kith` server in a project `.mcp.json` with a launcher for the machine you are on; do not commit that rewrite over the discovery entry.
|
|
111
|
+
|
|
112
|
+
For source installation and the disposable demo, use the pinned **pnpm 10.20.0**:
|
|
113
|
+
|
|
114
|
+
```sh
|
|
115
|
+
git clone https://github.com/connorhriley/kith.git
|
|
116
|
+
cd kith
|
|
117
|
+
corepack enable
|
|
118
|
+
pnpm install --frozen-lockfile
|
|
119
|
+
pnpm build
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### See it work
|
|
123
|
+
|
|
124
|
+
```sh
|
|
125
|
+
pnpm demo
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
The demo starts **two real MCP clients**, gives each a separate Git worktree in a temporary repository, refuses an overlapping claim, records their edits, runs commands under a mutex, and verifies/integrates both changes. It removes the temporary repository afterward. No model calls or client credentials are needed.
|
|
129
|
+
|
|
130
|
+
```text
|
|
131
|
+
auth: claimed src/auth.mjs in an isolated worktree
|
|
132
|
+
billing: overlapping claim on src/auth.mjs refused
|
|
133
|
+
billing: claimed src/billing.mjs in an isolated worktree
|
|
134
|
+
auth: checked its worktree through the MCP command supervisor
|
|
135
|
+
auth: isolated edit reported, verified, and integrated
|
|
136
|
+
billing: checked its worktree through the MCP command supervisor
|
|
137
|
+
billing: isolated edit reported, verified, and integrated
|
|
138
|
+
Two real MCP clients completed work in separate worktrees. Disposable example passed.
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
The implementation is in [examples/two-agents.mjs](../examples/two-agents.mjs). This demonstrates the coordination protocol; [native-client validation](client-validation.md) separately exercises installed coding clients.
|
|
142
|
+
|
|
143
|
+
### Client support
|
|
144
|
+
|
|
145
|
+
The editor extension bundles the server and offers it through native MCP registration; no global npm install is needed. Installing an extension or writing MCP configuration alone does not enforce claims on writers that do not call Kith tools unless global `--auto` hooks are installed for that client. Existing custom Kith entries retain precedence.
|
|
146
|
+
|
|
147
|
+
| Client | Setup and behaviour |
|
|
148
|
+
| --- | --- |
|
|
149
|
+
| VS Code / Cursor | Marketplace extension with `kith.mcp.profile` set to `compact` by default; **Kith: Install Global Hooks & Autostart** runs `kith install` |
|
|
150
|
+
| Claude Code | Plugin (`kith@kith`), or `kith install` / `kith setup` with silent-solo `--auto` hooks. The plugin defers when the install hooks are present |
|
|
151
|
+
| Cursor | Detected client configuration through `kith install` or `kith setup`; silent-solo `--auto` hooks join when work overlaps |
|
|
152
|
+
| Codex CLI | Detected global MCP configuration (`--compact` by default). Codex CLI has no native tool hooks, so coordination uses MCP tools and Radar or `kith watch` |
|
|
153
|
+
| Claude Desktop | Detected MCP configuration via `kith install` / `kith setup` |
|
|
154
|
+
| Other MCP clients | stdio server via `kith mcp` (`--compact` or `--full`); client-specific validation required |
|
|
155
|
+
|
|
156
|
+
Native evidence is version-specific. See [client validation](client-validation.md), [advanced integration setup](integrations.md) and [session ownership](sessions-and-mutexes.md). The npm package is **`kith-coord`** and the command is **`kith`**; the unrelated npm package `kith` is not this project.
|
|
157
|
+
|
|
158
|
+
## Dev servers and shared config
|
|
159
|
+
|
|
160
|
+
`kith dev` runs a server with its allocated `PORT` and supports explicit `{port}` arguments. It scans from 3000 unless `--base` is set. `kith port` scans from 3100. File claims also accept an optional bounded wait:
|
|
161
|
+
|
|
162
|
+
```sh
|
|
163
|
+
kith dev --agent web-a -- npm run dev -- --port '{port}'
|
|
164
|
+
# Within an existing owned session:
|
|
165
|
+
kith lock acquire --agent worker-1 --scope package.json --wait --wait-ms 30000
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
See [dev-server launch and waiting claims](usage.md#launch-a-dev-server-on-its-allocated-port) for framework flags, session setup, cancellation, and MCP usage.
|
|
169
|
+
|
|
170
|
+
## Read-only Radar
|
|
171
|
+
|
|
172
|
+
From 0.1.8, macOS `kith install` and `kith setup` load a `LaunchAgent` (`dev.kith.radar`) so menu-bar Radar runs in the background and restarts across logins for the selected checkout or workspace. It uses the retained installation, so clearing the npx cache does not break it. Repeat runs keep an existing Radar workspace selected. Use **Switch Workspace** in its menu to change it.
|
|
173
|
+
|
|
174
|
+
`kith install --no-autostart` (or `--no-radar`) configures MCP and hooks without loading the macOS login agent (useful on headless machines); `--dry-run` never writes or launches anything. Linux and Windows skip the macOS menu-bar app and `LaunchAgent`, using `kith watch` for passive monitoring instead (external IDE `presence.db` discovery is opt-in via `--include-presence`). Remove the login item anytime with `kith uninstall`, or inspect manually with:
|
|
175
|
+
|
|
176
|
+
```sh
|
|
177
|
+
kith watch /path/to/workspace --once --json
|
|
178
|
+
kith menubar /path/to/workspace # macOS 12+, Intel or Apple Silicon
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
The menu and editor lead with recorded tasks, current file claims, shared-resource waits and integrations that need inspection. A registered session without a task is shown separately. Saved checkouts and path comparisons stay in details; nothing is automatically deleted. The menu's default view omits the file-timestamp feed.
|
|
182
|
+
|
|
183
|
+
**Watching only** means no active Kith task is recorded. Shared dirty paths are files to review before integration, not a proven merge conflict. **Status unavailable** remains explicit when state cannot be inspected safely. Reads use private snapshots without renewing owners or migrating the original database. See [observation limits](usage.md#optional-read-only-worktree-observations).
|
package/docs/integrations.md
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
For CLI-generated configuration, install Kith persistently or build and link the checkout first. On macOS/Linux, generated configurations use the `kith` executable already on PATH; they do not download an unverified package at hook execution time.
|
|
4
4
|
|
|
5
|
+
Claude Code can load the same hooks and MCP server as a plugin (`/plugin marketplace add connorhriley/kith`, then `/plugin install kith@kith`). The plugin runs `npx -y kith-coord` and defers when `kith install` or `kith init` has already registered the Claude hook. Use one or both; `kith doctor` does not fail when both are present. Cursor, Codex, and the menu bar still come from `kith install`. See [which to use](install.md#which-to-use).
|
|
6
|
+
|
|
5
7
|
| Selection | Files and behavior |
|
|
6
8
|
| --- | --- |
|
|
7
9
|
| `claude` | Merges Kith into `.mcp.json`; adds Claude edit hooks only when selected explicitly with `--only` and without `--mcp-only` |
|
|
@@ -41,6 +43,8 @@ Select clients explicitly without `--mcp-only` to add edit hooks, for example `k
|
|
|
41
43
|
|
|
42
44
|
Before launching a hook client, run `eval "$(kith session start --agent <id> --owner-pid "$$" --shell)"`. The client, its MCP process, and hooks must inherit both `KITH_AGENT_ID` and `KITH_SESSION_TOKEN`. Use that same agent ID in MCP calls. A missing/forged/expired token blocks hook mutations for a session that presents an identity. See [session setup](sessions-and-mutexes.md).
|
|
43
45
|
|
|
46
|
+
**Hooks adopt an existing worktree when the context is unambiguous.** Claude Code sets the hook `cwd` to the worktree root while `${CLAUDE_PROJECT_DIR}` stays on the checkout where the session started. A joined `pre`, `post`, or `pre-commit` hook registers that linked worktree for the session when it is the only match in `git worktree list`, the session has no different worktree, and no other live agent owns the path. A hook whose `cwd` is the primary checkout does not adopt anything. The same registration is `kith adopt` or `kith_adopt_worktree` when you want it explicit. Kith does not delete that directory.
|
|
47
|
+
|
|
44
48
|
**Hooks govern sessions that joined.** A process with no Kith identity at all (no `--agent`, no `--session-token`, and neither `KITH_AGENT_ID` nor `KITH_SESSION_TOKEN` in its environment) is not a participant: it cannot hold a claim, so there is nothing to enforce. Its `pre`, `post` and `pre-commit` hooks allow immediately, print nothing, and never open the coordination database. An editor, a plain terminal, CI or another agent client is therefore never blocked by a repository that has Kith hooks installed. A process that names an agent but cannot prove it (missing or forged token) is still refused. Pass `--require-session` to a hook command, or set `KITH_REQUIRE_SESSION=1`, to restore fail-closed behaviour for processes with no identity. Separate stateless shell calls cannot retain this setup. Prefer MCP and isolated worktrees when a persistent launcher environment is unavailable; AGENTS.md guidance alone cannot enforce writes.
|
|
45
49
|
|
|
46
50
|
Shims are inactive until `.coord/bin` is prepended to PATH. Use an absolute path, for example `export PATH="$PWD/.coord/bin:$PATH"` at the repository root. Wrappers remove that directory from PATH before invoking the real package manager, avoiding recursive self-invocation. They serialize selected install/add/remove commands through the resource broker; leases renew while commands run, and FIFO tickets persist across releases. Protected work must remain in the supervised command group.
|
|
@@ -61,7 +65,7 @@ kith init --only claude,cursor,git,agents --enforcement block --dry-run
|
|
|
61
65
|
kith init --only claude,cursor,git,agents --enforcement block
|
|
62
66
|
```
|
|
63
67
|
|
|
64
|
-
`block` is the default for optional hooks: conflicting native file writes are denied; unclaimed files are claimed before writes. Risky recognized Git commands are refused while they could replace a peer's shared checkout or shared refs. `warn` permits policy conflicts and returns warnings; it never steals the peer's claim or attributes their file to the warning agent. `off` skips claim/risky-command enforcement. All modes still require valid session ownership and contained file paths. This switch affects hooks, not MCP/CLI ownership, locks or integration checks. Rerun init with a different mode to update recognized Kith hooks without duplicating them or deleting unrelated hooks.
|
|
68
|
+
`block` is the default for optional hooks: conflicting native file writes are denied; unclaimed files are claimed before writes. Risky recognized Git commands are refused while they could replace a peer's shared checkout or shared refs. In an isolated worktree, `git update-ref` of `HEAD` or that worktree's own branch is allowed when no other active agent shares the worktree or the branch. In a shared checkout, a compare-and-swap `update-ref` of `HEAD` or the current branch is allowed only when it is a one-commit fast-forward of the caller's own files; shell variables in that shape are checked after the command and reverted when the check fails. Updates to another agent's branch, stdin batches, merges, missing compare-and-swap values, and ref commands the guard cannot parse stay refused. See [committing while other sessions are active](sessions-and-mutexes.md). `warn` permits policy conflicts and returns warnings; it never steals the peer's claim or attributes their file to the warning agent. `off` skips claim/risky-command enforcement. All modes still require valid session ownership and contained file paths. This switch affects hooks, not MCP/CLI ownership, locks or integration checks. Rerun init with a different mode to update recognized Kith hooks without duplicating them or deleting unrelated hooks.
|
|
65
69
|
|
|
66
70
|
Cursor's native `preToolUse`/`postToolUse` adapter handles `Shell`, `Write` and `Delete` matcher payloads, returns Cursor permission/context JSON, and sets `failClosed:true` on pre-hooks. The generated Claude pre-hook uses `onFailure:"block"`. These fields depend on client versions; see [Cursor's hook reference](https://cursor.com/docs/hooks), [Claude's hook reference](https://code.claude.com/docs/en/hooks), and the [validation matrix](client-validation.md). A pattern-based shell guard cannot parse every shell program or prevent bypasses. Worktrees remain the recommended default.
|
|
67
71
|
|
|
@@ -81,12 +85,12 @@ Uninstall restores the exact original bytes/permissions or deletes files created
|
|
|
81
85
|
|
|
82
86
|
## Registry installation
|
|
83
87
|
|
|
84
|
-
The package is `kith-coord`, and its binary remains `kith`. Install it persistently (`npm install --global kith-coord@0.
|
|
88
|
+
The package is `kith-coord`, and its binary remains `kith`. Install it persistently (`npm install --global kith-coord@0.2.0`) before `kith init`, because generated configurations launch `kith` on PATH. Invoking init through npx alone does not create that persistent executable.
|
|
85
89
|
|
|
86
90
|
An MCP client can instead use a pinned registry launcher without a global install:
|
|
87
91
|
|
|
88
92
|
```json
|
|
89
|
-
{"mcpServers":{"kith":{"command":"npx","args":["--yes","--package","kith-coord@0.
|
|
93
|
+
{"mcpServers":{"kith":{"command":"npx","args":["--yes","--package","kith-coord@0.2.0","kith","mcp","--repo","/absolute/checkout"]}}}
|
|
90
94
|
```
|
|
91
95
|
|
|
92
96
|
Use a version you have verified; the unrelated npm package named `kith` is not Kith's distribution. Hook commands still need their configured executable to remain available. The clean-package smoke check exercises the installed binary, library, supervised worker and actual MCP discovery/status in a separate consumer.
|
|
@@ -99,7 +103,7 @@ Version 0.1.1 generates MCP configuration using the current absolute Node execut
|
|
|
99
103
|
|
|
100
104
|
## Configure detected local clients
|
|
101
105
|
|
|
102
|
-
From 0.1.7, `npx --yes --package kith-coord@0.
|
|
106
|
+
From 0.1.7, `npx --yes --package kith-coord@0.2.0 kith setup /absolute/checkout` is the single setup path. Versions through 0.1.6 need a persistent npm installation first. Setup retains the exact bundled runtime under `~/.local/share/kith/runtimes/`, validates actual MCP discovery without selecting a repository, configures supported detected clients and adds marked project guidance. Clearing the original npx cache does not break its launcher. Repeat setup reuses identical content. `kith install` removes retained runtimes under `~/.local/share/kith/runtimes/` that no live hook, MCP entry, or login agent still names, and keeps a runtime any of those configs still point at. A damaged selected runtime is refused rather than overwritten. Custom launchers remain custom. `kith doctor` fails when one of those configs points at a different Kith version than the CLI you just ran, and tells you to run `kith install`.
|
|
103
107
|
|
|
104
108
|
**From 0.1.8,** `kith install` is the single onboarding command and `kith setup` remains an alias. Both retain the runtime above, and on macOS they open read-only Radar and register a login LaunchAgent (`dev.kith.radar`) unless `--no-radar` or `--no-autostart` is passed. Repeating setup keeps an existing view and its selected workspace; use its **Switch Workspace** menu to change projects. `--dry-run` previews without launching. Linux and Windows skip the menu-bar view and use `kith watch`. Radar makes no model calls. A Radar startup failure is reported with a nonzero exit while preserving completed client setup; rerun after resolving the error. `kith uninstall` removes the LaunchAgent, global hooks and global MCP entries it recorded.
|
|
105
109
|
|
|
@@ -94,6 +94,14 @@
|
|
|
94
94
|
"type": "boolean",
|
|
95
95
|
"description": "Recommended: true, giving each parallel agent a separate Git worktree"
|
|
96
96
|
},
|
|
97
|
+
"adoptWorktree": {
|
|
98
|
+
"type": "boolean",
|
|
99
|
+
"description": "Register an existing linked worktree instead of creating one. Pass worktreePath when this server is not already inside it."
|
|
100
|
+
},
|
|
101
|
+
"worktreePath": {
|
|
102
|
+
"type": "string",
|
|
103
|
+
"description": "Absolute path of an existing linked worktree to adopt, such as a Claude Code .claude/worktrees/<name> checkout"
|
|
104
|
+
},
|
|
97
105
|
"waitTimeoutMs": {
|
|
98
106
|
"type": "integer",
|
|
99
107
|
"minimum": 0,
|
|
@@ -140,6 +148,14 @@
|
|
|
140
148
|
"type": "boolean",
|
|
141
149
|
"description": "Recommended: true, giving the claiming agent an isolated Git worktree"
|
|
142
150
|
},
|
|
151
|
+
"adoptWorktree": {
|
|
152
|
+
"type": "boolean",
|
|
153
|
+
"description": "Register an existing linked worktree instead of creating one"
|
|
154
|
+
},
|
|
155
|
+
"worktreePath": {
|
|
156
|
+
"type": "string",
|
|
157
|
+
"description": "Absolute path of an existing linked worktree to adopt"
|
|
158
|
+
},
|
|
143
159
|
"waitTimeoutMs": {
|
|
144
160
|
"type": "integer",
|
|
145
161
|
"minimum": 0,
|
|
@@ -164,6 +180,43 @@
|
|
|
164
180
|
"$schema": "http://json-schema.org/draft-07/schema#"
|
|
165
181
|
}
|
|
166
182
|
},
|
|
183
|
+
{
|
|
184
|
+
"name": "kith_adopt_worktree",
|
|
185
|
+
"description": "Register an existing linked Git worktree as this agent's workspace. Use this for Claude Code --worktree checkouts under .claude/worktrees/<name> and for any other git worktree list entry. Kith does not create, clean, or delete that directory.",
|
|
186
|
+
"inputSchema": {
|
|
187
|
+
"type": "object",
|
|
188
|
+
"properties": {
|
|
189
|
+
"agentId": {
|
|
190
|
+
"type": "string"
|
|
191
|
+
},
|
|
192
|
+
"sessionToken": {
|
|
193
|
+
"type": "string"
|
|
194
|
+
},
|
|
195
|
+
"client": {
|
|
196
|
+
"type": "string"
|
|
197
|
+
},
|
|
198
|
+
"worktreePath": {
|
|
199
|
+
"type": "string",
|
|
200
|
+
"description": "Absolute path of the linked worktree. Defaults to the server cwd when that cwd is already the worktree."
|
|
201
|
+
},
|
|
202
|
+
"operationKey": {
|
|
203
|
+
"type": "string",
|
|
204
|
+
"minLength": 1,
|
|
205
|
+
"maxLength": 128,
|
|
206
|
+
"description": "Unique key per mutation attempt; retry exact arguments/key after timeout. Not a credential. Use a new key after repair/backoff."
|
|
207
|
+
},
|
|
208
|
+
"repository": {
|
|
209
|
+
"type": "string",
|
|
210
|
+
"description": "Absolute original Git checkout; required without project context. Keep it unchanged for this task."
|
|
211
|
+
}
|
|
212
|
+
},
|
|
213
|
+
"required": [
|
|
214
|
+
"agentId"
|
|
215
|
+
],
|
|
216
|
+
"additionalProperties": false,
|
|
217
|
+
"$schema": "http://json-schema.org/draft-07/schema#"
|
|
218
|
+
}
|
|
219
|
+
},
|
|
167
220
|
{
|
|
168
221
|
"name": "kith_add_task",
|
|
169
222
|
"description": "Add a task to the orchestrated DAG queue with optional task dependencies and file scope globs.",
|
package/docs/protocol.md
CHANGED
|
@@ -6,7 +6,7 @@ Kith is a local ledger for cooperating coding agents. Clients share one reposito
|
|
|
6
6
|
|
|
7
7
|
Protocol 1.1 ships with package 0.1.2. Earlier `kith-coord@0.1.1` reports protocol 1.0 and includes full contracts in MCP status; the compact default and `includeContracts` input below require 0.1.2.
|
|
8
8
|
|
|
9
|
-
`KITH_PROTOCOL_VERSION` and status responses advertise `1.6.0` starting with package 0.1.8; package 0.1.7 advertises `1.5.0`, and package 0.1.6 advertises `1.4.0`. Protocol 1.6 adds optional tools (`kith_write_handoff`, `kith_read_handoffs`, `kith_brief`) and additive result fields (handoffs, `workflowMode`, `session.leaseExpiresAt`, `completedIntegrationCount`). The storage schema stays 3. Opening the database creates an optional `handoffs` table that older binaries ignore. Package releases (`kith-coord`, beginning at 0.1.0) and the SQLite storage schema have independent versions. The [tool snapshot](protocol/tools.v1.json) contains
|
|
9
|
+
`KITH_PROTOCOL_VERSION` and status responses advertise `1.6.0` starting with package 0.1.8; package 0.1.7 advertises `1.5.0`, and package 0.1.6 advertises `1.4.0`. Protocol 1.6 adds optional tools (`kith_write_handoff`, `kith_read_handoffs`, `kith_brief`) and additive result fields (handoffs, `workflowMode`, `session.leaseExpiresAt`, `completedIntegrationCount`). The storage schema stays 3. Opening the database creates an optional `handoffs` table that older binaries ignore. Package releases (`kith-coord`, beginning at 0.1.0) and the SQLite storage schema have independent versions. The [tool snapshot](protocol/tools.v1.json) contains every full-profile tool name, description and JSON input schema, exported from an actual MCP `tools/list` response. Package 0.2.0 adds `kith_adopt_worktree`, so the snapshot lists 18 tools. The advertised protocol version remains 1.6.0. `pnpm protocol:check` rejects snapshot drift in CI. Update deliberately using `pnpm protocol:export`.
|
|
10
10
|
|
|
11
11
|
For protocol 1.x, existing tool names, required input fields and the ownership/claim semantics below remain compatible. New optional fields/tools and additive result fields use a minor version; compatible repairs use a patch version. Removing tools, adding required inputs or changing ownership semantics requires a major version. Clients should ignore unknown result fields. The snapshot describes inputs; it is not a machine-validated schema for every result or a guarantee of source-level library compatibility.
|
|
12
12
|
|
|
@@ -44,7 +44,18 @@ A session boundary used to erase what an agent learned: its claims were released
|
|
|
44
44
|
|
|
45
45
|
A repository is in one of two modes, shared by every agent and worktree and stored with the coordination state (`worktrees` unless changed). In `worktrees` mode each agent may work in an isolated worktree and integrates through the merge train. In `main` mode every agent works in the one checkout and coordinates through scope claims: `kith_begin_work` and `kith_claim_next_task` never create a worktree, they ignore `isolateWorktree` and say so in `notes`, and completing work releases the claims with no integration step (so a `verificationCmd` is not run). Both tools and `kith_get_status` report `workflowMode`. Set it with `kith mode main|worktrees` or `kith init --mode`; `kith mode` shows it. Generated agent guidance describes the recorded mode.
|
|
46
46
|
|
|
47
|
-
`kith mcp --compact`, the default used by `kith install`, advertises six workflow tools instead of the
|
|
47
|
+
`kith mcp --compact`, the default used by `kith install`, advertises six workflow tools instead of the full snapshot: `kith_brief`, `kith_work`, `kith_claim`, `kith_handoff`, `kith_finish` and `kith_resource`. `kith_work` with `action: "adopt"` registers an existing linked worktree. `kith mcp --full` restores the full list, including `kith_adopt_worktree`. Both advertise protocol 1.6.0.
|
|
48
|
+
|
|
49
|
+
## 0.2.0: adopting an existing worktree
|
|
50
|
+
|
|
51
|
+
These fields ship in package 0.2.0 and do not change the advertised protocol version.
|
|
52
|
+
|
|
53
|
+
- `kith_adopt_worktree` registers a linked worktree (`worktreePath`, or the server cwd when that cwd is already the worktree) for an agent. It does not create the directory, clean it, or delete it.
|
|
54
|
+
- `kith_begin_work` and `kith_claim_next_task` accept optional `adoptWorktree` and `worktreePath`. When either is set, Kith adopts that checkout instead of creating one. `isolateWorktree` is not also applied.
|
|
55
|
+
- The worktree object adds `provenance` (`created` or `adopted`), `source` (`kith`, `claude-code`, or `external`), `detached`, `dirty`, `branchCheckedOutElsewhere`, and `notes`. `branch` is null when HEAD is detached.
|
|
56
|
+
- `kith_get_status` adds `worktreeRegistrations`. Storage stays schema 3. Opening the database creates an optional `worktree_registrations` table that older binaries ignore.
|
|
57
|
+
|
|
58
|
+
A detached adopted HEAD is not integrated. A branch checked out in another worktree is not committed or integrated. An adopted branch that is unique still uses the verification gate below. Clients should keep sending the original checkout as `repository`.
|
|
48
59
|
|
|
49
60
|
## Workspace observation and integration
|
|
50
61
|
|
package/docs/reliability.md
CHANGED
|
@@ -9,7 +9,7 @@ Scope intersection is exact within the documented grammar; unsupported scopes ar
|
|
|
9
9
|
- Conflicting exclusive file locks and task claims have unique owners under simultaneous process contention.
|
|
10
10
|
- Port reservations are rechecked atomically after asynchronous OS probes; exhaustion returns an error.
|
|
11
11
|
- Setup previews without writes, preserves unrelated JSON settings, and rejects malformed config before writing selected configuration.
|
|
12
|
-
- Worktree creation refuses an existing path or branch; removal refuses local, untracked, or ignored changes.
|
|
12
|
+
- Worktree creation refuses an existing path or branch; removal refuses local, untracked, or ignored changes. An adopted worktree is not deleted or pruned by garbage collection or `kith worktree remove`. Explicit `--delete-adopted` still refuses a dirty tree. Integration of an adopted branch stays behind the verification command; a detached HEAD and a branch checked out elsewhere are refused before that command runs.
|
|
13
13
|
- Integration refuses a dirty target and concurrent Kith integrations; failed or mutating verification preserves the target and source worktree for retry. Checks cannot change the candidate commit, tracked/index contents, or leave new nonignored files behind.
|
|
14
14
|
- Unresolved Git conflicts fail integration without custom source/JSON rewriting. Source and target work remain available for explicit repair and retry.
|
|
15
15
|
- Shadow-tree deletions reach Git; invalid merge inputs surface errors.
|
package/docs/roadmap.md
CHANGED
|
@@ -16,6 +16,8 @@ MCP is the default agent interface. Keep one shared ownership ledger per Git com
|
|
|
16
16
|
|
|
17
17
|
Published 0.1.7 / protocol 1.5 is on npm, including durable setup and compact MCP replies. Kith 0.1.8 advances the additive protocol to 1.6 (handoffs, the brief, workflow mode, lease receipts and quieter status) and keeps storage schema 3, with an optional handoffs table that older binaries ignore. Each candidate must pass its own combined core/platform, bundled-server and clean-install gates before publication; a green prior release does not certify a new branch.
|
|
18
18
|
|
|
19
|
+
0.2.0 registers a linked worktree an agent already has — Claude Code's `.claude/worktrees/<name>` layout first, and any other `git worktree list` entry — instead of always creating one. Publish that package from the merged release commit; a green pull request is not a registry release.
|
|
20
|
+
|
|
19
21
|
## Deferred
|
|
20
22
|
|
|
21
23
|
No new dashboard, fleet spawning, model router, automatic merges, semantic scoring, writer-PID attribution, whole-Mac crawler or new adapters are planned in this reliability pass. Prioritize concrete blocked workflows over feature requests. Actual external task completion remains a separate product-validation gate.
|
|
@@ -30,7 +30,7 @@ CLI sessions are anchored to their parent process unless `--owner-pid` is suppli
|
|
|
30
30
|
eval "$(kith session start --agent auth-worker --new --owner-pid "$$" --shell)"
|
|
31
31
|
```
|
|
32
32
|
|
|
33
|
-
`--new` does not steal a live session. Worktree paths are retained across generations. After successful worktree integration, use a new maintenance session to run `kith worktree remove`; changed, untracked, and ignored files still prevent removal.
|
|
33
|
+
`--new` does not steal a live session. Worktree paths are retained across generations. After successful worktree integration, use a new maintenance session to run `kith worktree remove`; changed, untracked, and ignored files still prevent removal. That removal applies to a worktree Kith created. An adopted worktree (Claude Code's `.claude/worktrees/<name>`, or any other linked worktree registered with `kith adopt`) is not deleted by `kith worktree remove` or `kith gc`. Unregister it with `kith worktree forget`, or pass `--delete-adopted` when you mean to remove that directory.
|
|
34
34
|
|
|
35
35
|
## Git-ignored files and clearing a stuck auto-session
|
|
36
36
|
|
|
@@ -47,9 +47,11 @@ kith session clear --conflicts # only delete recorded conflicts, ke
|
|
|
47
47
|
|
|
48
48
|
When a client with `--auto` hooks also registers an MCP session (`kith_begin_work` or `kith_work`), Kith automatically binds the MCP capability to the parent client's `presence.db` session and transfers any locks held by its `auto-*` agent ID so subsequent hook calls and MCP calls share a single session.
|
|
49
49
|
|
|
50
|
-
## Committing
|
|
50
|
+
## Committing while other sessions are active
|
|
51
51
|
|
|
52
|
-
|
|
52
|
+
The Bash guard refuses Git commands that can replace another session's checkout or refs.
|
|
53
|
+
|
|
54
|
+
In a shared checkout (`kith mode main`, or any checkout another active session is also using), `git reset`, `git checkout`, and the other recognized checkout-rewriting commands are blocked while a peer is active. A compare-and-swap `git update-ref` of `HEAD` or `refs/heads/<the current branch>` is allowed when the pre-hook can prove it is a fast-forward of exactly one commit and every changed path belongs to the caller. The same shape with shell variables is checked after the command and reverted if that proof fails. Anything else, including an `update-ref` with no old value, stays blocked. To commit only your own files there, run:
|
|
53
55
|
|
|
54
56
|
```sh
|
|
55
57
|
kith commit -m "feat: scoped change" [files...]
|
|
@@ -57,6 +59,30 @@ kith commit -m "feat: scoped change" [files...]
|
|
|
57
59
|
|
|
58
60
|
If `[files...]` is omitted, `kith commit` collects the caller session's recorded modified files (from active file/narrow-glob locks, `presence.db` touched files, and active task scopes), verifies no target file is locked by another live agent, stages only those paths in a temporary index under `.coord/commit.lock`, advances `HEAD` with compare-and-swap `git update-ref`, and runs `git reset -q HEAD -- <files>` so `.git/index` stays synchronized with `HEAD` without touching peers' dirty files. You can also run `kith commit` inside `kith_run_with_mutex` / `kith_resource` (`action: "mutex"`) or pass `commitMessage` (and optional `commitFiles`) to `kith_finish`.
|
|
59
61
|
|
|
62
|
+
In an isolated worktree the guard allows `git update-ref` when the ref belongs only to the caller. That means the caller has `worktree_path`, the ref is `HEAD` or `refs/heads/<that worktree's branch>` checked out in the worktree, and no other active agent shares the worktree or the branch. A temporary-index commit in that worktree (`git commit-tree`, then `git update-ref HEAD <new> <old>`) is allowed, including with `-m <msg>`, `--no-deref`, and `--create-reflog`. `git -C <dir>` is resolved from the worktree; a `-C` or `cd` that leaves the worktree does not count as owned. `git update-ref -d` is allowed only for a ref the caller owns.
|
|
63
|
+
|
|
64
|
+
In a shared checkout the same temporary-index shape is allowed only after the pre-hook checks all of the following, before the command runs:
|
|
65
|
+
|
|
66
|
+
- the command is `git update-ref` with optional `-m`, `--no-deref`, and `--create-reflog`, and the ref is `HEAD` or `refs/heads/<the branch checked out in that directory>`
|
|
67
|
+
- `<old>` is present and resolves to the ref's current value (a compare-and-swap)
|
|
68
|
+
- `<new>` resolves to a commit with exactly one parent, and that parent is `<old>` (one fast-forward commit; merges and history rewrites are refused)
|
|
69
|
+
- every path in `git diff-tree -r --name-only` from `<old>` to `<new>`, including deletions and both sides of a rename, is a file the caller has claimed, locked, or recorded the way `kith commit` records files (active file and narrow-glob locks, `presence.db` touched files, and active task scopes; a `**` lock does not count). No changed path may be locked or claimed by another active agent
|
|
70
|
+
|
|
71
|
+
`<new>` and `<old>` may be literal SHAs or other revisions that resolve at check time. Shell variables and command substitutions such as `$(git commit-tree ...)` are not executed during the pre-hook, so the commit they will create cannot be read yet. When the command is still exactly that compare-and-swap shape, the pre-hook records the current ref value and lets the command run. The post-hook then applies the same parent and path checks to the commit that landed. If they fail, it compare-and-swaps the ref back to the recorded value and prints the reason, including a `kith commit -m "<message>" <files>` command built from the caller's recorded files. A short lease keeps other agents from moving the same ref until that post-hook finishes: their ref-moving commands are refused, and `kith commit` waits, so a peer does not build on a commit that is about to be reverted. If the reverting compare-and-swap loses to a later update, the hook reports that and does not force the ref.
|
|
72
|
+
|
|
73
|
+
A blocked command keeps the existing `kith commit` guidance and adds the specific reason, for example `No compare-and-swap old value` or `path src/x.ts is claimed by agent peer`. When the caller has recorded dirty files, the message includes a ready-to-run `kith commit -m "<message>" <those files>`.
|
|
74
|
+
|
|
75
|
+
These stay blocked while a peer is active:
|
|
76
|
+
|
|
77
|
+
- updates to the integration branch from an isolated worktree, or to another agent's branch
|
|
78
|
+
- a shared-checkout `update-ref` with no `<old>`, a merge or multi-commit jump, a path the caller does not own, or a path another agent claims
|
|
79
|
+
- `HEAD` updates that are not the one-commit fast-forward above, including `--no-deref` on a symbolic `HEAD` (that would retarget the symlink instead of the branch)
|
|
80
|
+
- `git update-ref --stdin` batches, `update-ref -d`, and any ref command the parser cannot classify
|
|
81
|
+
- `git symbolic-ref`, except a read or pointing the caller's own `HEAD` at `refs/heads/<the caller's branch>`
|
|
82
|
+
- `git worktree remove`, `git worktree prune`, and `git branch` `-d`/`-D`/`-m`/`-M`/`-f`/`--delete`/`--move`/`--force`
|
|
83
|
+
|
|
84
|
+
After `update-ref`, the post-hook resyncs the index of the checkout that command ran in: the caller's worktree, the directory selected with `-C` when that checkout belongs to the same repository, or the checkout named by a compare-and-swap `update-ref` whose values are shell variables.
|
|
85
|
+
|
|
60
86
|
## MCP ownership
|
|
61
87
|
|
|
62
88
|
`kith_begin_work`, `kith_claim_next_task`, and `kith_start_session` return a session token when they register or resume a session. A single stdio connection retains its granted capabilities internally. Another connection must explicitly present the capability to resume the same live ID. All agent-scoped mutation tools accept an optional `sessionToken`; a mixed CLI/hook/MCP client can inherit `KITH_AGENT_ID` and `KITH_SESSION_TOKEN` instead.
|
package/docs/usage.md
CHANGED
|
@@ -24,6 +24,30 @@ kith_brief {"scopeGlobs":["src/auth/**"]} # the same, over MCP
|
|
|
24
24
|
|
|
25
25
|
Run it before beginning work. With `kith init --only brief` Claude Code runs it for you at the start of every session.
|
|
26
26
|
|
|
27
|
+
## Adopt a worktree that already exists
|
|
28
|
+
|
|
29
|
+
Claude Code's `claude --worktree <name>` creates `.claude/worktrees/<name>` on a branch named `worktree-<name>`. Subagent worktree isolation and `EnterWorktree` use that same directory. Other tools create ordinary linked worktrees anywhere `git worktree list` shows them. Kith can register that checkout as the agent's workspace.
|
|
30
|
+
|
|
31
|
+
A joined hook does this on its own when the hook input `cwd` (not `CLAUDE_PROJECT_DIR`, which stays on the original checkout) is inside exactly one linked worktree of this repository, the session does not already have a different worktree, and no other live agent has that path. The primary checkout is never adopted. Anything ambiguous is left alone. The [Claude Code plugin](install.md#claude-code-plugin) runs `kith hook pre|post --client claude --auto` and forwards that `cwd`. Once the auto session has joined, the worktree is adopted, and a later MCP call from the same client keeps that workspace. `kith install` hooks do the same check.
|
|
32
|
+
|
|
33
|
+
```sh
|
|
34
|
+
kith adopt # current directory, when it is a linked worktree
|
|
35
|
+
kith adopt /path/to/worktree
|
|
36
|
+
kith worktree adopt /path/to/worktree
|
|
37
|
+
kith begin --adopt /path/to/worktree --scope 'src/auth/**'
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
`--repo` stays the integration checkout. Pass it when you run the command from inside the worktree and the target is the primary checkout. On MCP, pass the original checkout as `repository` and the worktree as `worktreePath`:
|
|
41
|
+
|
|
42
|
+
```text
|
|
43
|
+
kith_adopt_worktree {"agentId":"auth-worker","worktreePath":"/repo/.claude/worktrees/feature-auth"}
|
|
44
|
+
kith_begin_work {"agentId":"auth-worker","title":"Refresh authentication","scopeGlobs":["src/auth/**"],"adoptWorktree":true,"worktreePath":"/repo/.claude/worktrees/feature-auth"}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Compact MCP uses `kith_work` with `action: "adopt"`. A dirty tree is adopted unchanged. `kith commit` records commits on a detached HEAD; integration waits until that HEAD is a branch. Integration and `kith commit` both refuse a branch that is also checked out in another worktree. A unique branch still integrates only when the verification command passes, and a failure leaves the target unchanged. In main-checkout mode the adopted directory is the workspace for claims and `kith commit`, and completion does not integrate.
|
|
48
|
+
|
|
49
|
+
`kith worktree forget` drops the registration and leaves the directory. `kith worktree remove` refuses an adopted worktree. `kith worktree remove --delete-adopted` removes a clean one. `kith gc` never deletes or prunes a worktree Kith did not create.
|
|
50
|
+
|
|
27
51
|
## Working in the main checkout
|
|
28
52
|
|
|
29
53
|
Some teams work on the main branch with one checkout and treat worktrees as overhead. Say so once:
|
|
@@ -203,3 +227,24 @@ Never include session tokens in issues, terminal recordings, or shared logs. See
|
|
|
203
227
|
The read-only watcher excludes byte-identical dirty copies (including matching executable modes) across linked worktrees. Remaining shared dirty paths are advisories, not proven merge conflicts. Files over 8 MiB and non-file objects remain unverified rather than being treated as identical. The menu shows at most eight overlap rows; `kith watch --once` provides the full observations.
|
|
204
228
|
|
|
205
229
|
Omit `--once` for continuous observation. `--notify=false` suppresses optional macOS notifications. From 0.1.8, macOS `kith install` and `kith setup` open Radar and register a login LaunchAgent unless `--no-radar` or `--no-autostart` is passed. Dry runs never launch it. An existing view keeps its selected workspace; choose **Switch Workspace** in its menu to change it. Radar polls local state without model calls or MCP conversation traffic. On macOS 12 or newer, `kith menubar /absolute/checkout` opens the same limited read-only view. The package includes an Intel/Apple Silicon executable, launched with this installation's Node and CLI paths; unavailable/failed scans remain visibly unavailable. Other platforms use `kith watch`. Source contributors can rebuild with `pnpm build:menubar` using Apple's command-line tools, and run the pipe/timeout regressions with `pnpm test:menubar`.
|
|
230
|
+
|
|
231
|
+
## How a task moves through Kith
|
|
232
|
+
|
|
233
|
+
0. **Look first.** `kith brief` (or `kith_brief`) shows who is active on what, claims that overlap your scope, open handoffs and conflicts. It is read-only and needs no session.
|
|
234
|
+
1. **Begin through MCP.** Call `kith_begin_work` with a unique `agentId`, explicit `scopeGlobs`, and `isolateWorktree: true`. The connection retains session ownership; no shell exports are needed for this MCP-only workflow.
|
|
235
|
+
2. **Claim a scope.** Cooperating clients receive a conflict when an exclusive claim overlaps another claim.
|
|
236
|
+
3. **Do the work.** Edit the returned `worktree.worktreePath`, report edits with `kith_record_file_edit`, and use `kith_run_with_mutex` for serialised commands. Heartbeat before expiry and keep the owning connection open.
|
|
237
|
+
4. **Leave a handoff.** When you finish, get blocked or must stop, call `kith_write_handoff` with what is done, what remains, what failed and what you learned. `releaseTask` hands the task back to the queue. If a session ends without a note, Kith records what it observed. The next agent on the same scope receives these notes from `kith_begin_work` or `kith_claim_next_task`, labelled as untrusted information to verify.
|
|
238
|
+
5. **Verify and complete.** For a worktree, Kith checkpoints changes and integrates through a separate staging worktree. The target may hold unrelated uncommitted work, but not edits to files the integration changes. Supply a check to require more than Git mergeability. With no check, a clean merge is the gate.
|
|
239
|
+
|
|
240
|
+
Failed verification leaves the target unchanged and keeps the worktree for repair. Successful integration also retains the worktree until explicit cleanup. External Git writers must still coordinate.
|
|
241
|
+
|
|
242
|
+
Inspect through `kith_get_status` or `kith status`: worktree paths and branches, dirty-file overlap, ahead/behind, heartbeat and commit age, and FIFO waiters are included. Use `kith_preview_integrate` for committed-tree conflict paths before completing. Normal status may reap expired owners. For non-mutating recovery inspection use:
|
|
243
|
+
|
|
244
|
+
```sh
|
|
245
|
+
kith status --offline
|
|
246
|
+
kith recover
|
|
247
|
+
kith doctor
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
Optional Claude and Cursor hooks support `--enforcement block` (default), `warn` and `off`; see [setup and safe uninstall](integrations.md). The [versioned protocol](protocol.md) records the tool schemas and ownership semantics.
|