switchman-dev 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -23,6 +23,80 @@ npm install -g @switchman-dev
23
23
 
24
24
  ---
25
25
 
26
+ ## First successful run: 3 agents on one repo
27
+
28
+ If you only try one thing, try this.
29
+
30
+ ### 1. Create a test repo and three agent worktrees
31
+
32
+ ```bash
33
+ cd my-project
34
+ switchman setup --agents 3
35
+ ```
36
+
37
+ This gives you:
38
+ - one shared Switchman database in `.switchman/`
39
+ - three linked worktrees
40
+ - local `.mcp.json` files so Claude Code can discover Switchman automatically
41
+
42
+ ### 2. Add three small, separate tasks
43
+
44
+ ```bash
45
+ switchman task add "Implement auth helper" --priority 9
46
+ switchman task add "Add auth tests" --priority 8
47
+ switchman task add "Update auth docs" --priority 7
48
+ ```
49
+
50
+ Use real tasks from your repo. If a task looks broad enough to fan out across many files or shared areas, Switchman will warn and suggest using `switchman pipeline start` instead.
51
+
52
+ ### 3. Open one Claude Code window per worktree
53
+
54
+ Open each generated worktree folder in its own Claude Code window.
55
+
56
+ If Claude Code sees the local `.mcp.json`, each agent can use Switchman without extra setup.
57
+
58
+ ### 4. Tell each agent to work through Switchman
59
+
60
+ Use this exact instruction:
61
+
62
+ ```text
63
+ Use Switchman for all task coordination in this repo.
64
+
65
+ 1. Run `switchman lease next --json` to get your task and lease.
66
+ 2. Before editing anything, run `switchman claim <taskId> <worktree> <files...>`.
67
+ 3. Only edit files you have claimed.
68
+ 4. If a claim is blocked, do not use --force. Pick a different file or different approach.
69
+ 5. When finished, run `switchman task done <taskId>`.
70
+
71
+ Do not read or write `.switchman/switchman.db` directly.
72
+ Do not bypass Switchman for file coordination.
73
+ ```
74
+
75
+ ### 5. Watch the run
76
+
77
+ In the repo root:
78
+
79
+ ```bash
80
+ switchman status
81
+ switchman scan
82
+ ```
83
+
84
+ What a good first run looks like:
85
+ - all three tasks end in `done`
86
+ - `switchman scan` reports no conflicts
87
+ - `switchman gate ci` passes
88
+
89
+ ### 6. If you want a built-in local demo instead
90
+
91
+ ```bash
92
+ bash examples/setup.sh
93
+ bash examples/walkthrough.sh
94
+ ```
95
+
96
+ That runs the included 3-agent demo against the example API in [examples/README.md](/Users/ned/Documents/GitHub/switchman/examples/README.md).
97
+
98
+ ---
99
+
26
100
  ## Pick your setup
27
101
 
28
102
  ### Option A — Claude Code (recommended)
@@ -40,7 +114,9 @@ That's it. Switchman creates three isolated workspaces, one per agent, and initi
40
114
 
41
115
  **Step 2 — Add Switchman to Claude Code**
42
116
 
43
- Add this to `~/.claude/claude_desktop_config.json`:
117
+ `switchman setup` now writes a project-local `.mcp.json` into the repo root and each generated worktree, so Claude Code can discover Switchman automatically when you open those folders.
118
+
119
+ If you prefer a global fallback, add this to `~/.claude/claude_desktop_config.json`:
44
120
 
45
121
  ```json
46
122
  {
@@ -53,7 +129,7 @@ Add this to `~/.claude/claude_desktop_config.json`:
53
129
  }
54
130
  ```
55
131
 
56
- Then restart Claude Code.
132
+ Then restart Claude Code. The project-local `.mcp.json` is the preferred path because it travels with the repo and the generated worktrees.
57
133
 
58
134
  **Step 3 — Copy CLAUDE.md into your repo root**
59
135
 
@@ -61,7 +137,7 @@ Then restart Claude Code.
61
137
  curl -O https://raw.githubusercontent.com/switchman-dev/switchman/main/CLAUDE.md
62
138
  ```
63
139
 
64
- This tells your agents how to use Switchman. Without it they won't know to coordinate.
140
+ This tells your agents how to use Switchman. Without it they may bypass Switchman entirely, so keep it in the repo root and do not let agents talk to `.switchman/switchman.db` directly.
65
141
 
66
142
  **Step 4 — Add your tasks**
67
143
 
@@ -73,7 +149,7 @@ switchman task add "Update README" --priority 2
73
149
 
74
150
  **Step 5 — Open Claude Code in each workspace**
75
151
 
76
- Open a separate Claude Code window in each folder that `switchman setup` created. Each agent will automatically pick up a task, lock the files it needs, and release them when it's done.
152
+ Open a separate Claude Code window in each folder that `switchman setup` created. Each agent should automatically see the local MCP config, pick up a task, lock the files it needs, and release them when it's done.
77
153
 
78
154
  **Step 6 — Check before merging**
79
155
 
@@ -157,12 +233,74 @@ switchman status
157
233
 
158
234
  ---
159
235
 
236
+ ## If something goes wrong
237
+
238
+ Start here before digging into the internals.
239
+
240
+ ### `switchman status`
241
+
242
+ Use this first when a run feels stuck.
243
+
244
+ It answers:
245
+ - what is running
246
+ - what is blocked
247
+ - what failed
248
+ - what needs attention next
249
+
250
+ ### `switchman scan`
251
+
252
+ Use this before merge, or any time you suspect agents overlapped.
253
+
254
+ It tells you:
255
+ - changed files per worktree
256
+ - unclaimed or unmanaged changes
257
+ - conflict signals across worktrees
258
+
259
+ ### `switchman gate ci`
260
+
261
+ Use this as the final repo-level check.
262
+
263
+ ```bash
264
+ switchman gate ci
265
+ ```
266
+
267
+ If it fails, Switchman has detected unmanaged changes, stale state, or merge-governance problems.
268
+
269
+ ### Common recovery cases
270
+
271
+ `A file claim is blocked`
272
+ - another task already owns that file
273
+ - do not use `--force`
274
+ - choose a different file or let the other task finish first
275
+
276
+ `A task is still in progress but the agent is gone`
277
+ - inspect with `switchman status`
278
+ - if the lease is stale, run:
279
+
280
+ ```bash
281
+ switchman lease reap
282
+ ```
283
+
284
+ `A pipeline task failed`
285
+ - run:
286
+
287
+ ```bash
288
+ switchman pipeline status <pipelineId>
289
+ ```
290
+
291
+ Switchman now prints:
292
+ - `why:` what failed
293
+ - `next:` what to do next
294
+
295
+ ---
296
+
160
297
  ## Commands
161
298
 
162
299
  ### `switchman setup`
163
300
  One-command setup — creates agent workspaces and initialises the database.
164
301
  - `--agents 3` — number of workspaces to create (default: 3, max: 10)
165
302
  - `--prefix switchman` — branch name prefix (default: switchman)
303
+ - Writes `.mcp.json` to the repo root and each generated worktree so Claude Code can attach the Switchman MCP server automatically
166
304
 
167
305
  ### `switchman init`
168
306
  Initialise in the current git repo without creating worktrees. Creates `.switchman/switchman.db` and auto-detects existing worktrees.
@@ -196,10 +334,12 @@ Expire stale leases, release their claims, and return their tasks to `pending`.
196
334
  - `--stale-after-minutes <n>` — staleness threshold (default: 15)
197
335
 
198
336
  ### `switchman task done <taskId>`
199
- Mark a task complete and release all file claims.
337
+ Mark a task complete and automatically release all file claims.
338
+ When the task has an active lease, Switchman finalises the execution through that lease so provenance stays tied to the live session.
200
339
 
201
340
  ### `switchman task fail <taskId>`
202
- Mark a task failed and release all file claims.
341
+ Mark a task failed and automatically release all file claims.
342
+ When the task has an active lease, Switchman records the failure against that lease so execution history stays lease-first.
203
343
 
204
344
  ### `switchman claim <taskId> <worktree> [files...]`
205
345
  Lock files before editing. Warns immediately if any file is already claimed by another agent.
@@ -209,9 +349,10 @@ Release all file claims for a task.
209
349
 
210
350
  ### `switchman scan`
211
351
  Check all worktrees for conflicts — both uncommitted file overlaps and branch-level merge conflicts. Run this before merging.
352
+ By default, common generated paths such as `node_modules/`, `dist/`, `build/`, and `coverage/` are ignored.
212
353
 
213
354
  ### `switchman status`
214
- Full overview: task counts, active leases, stale leases, locked files, and a quick conflict scan.
355
+ Full overview: task counts, active leases, stale leases, locked files, a quick conflict scan, and readable failure explanations.
215
356
 
216
357
  ### `switchman worktree list`
217
358
  List all git worktrees with their registered agents and status.
@@ -221,6 +362,159 @@ Re-sync git worktrees into the Switchman database (useful if you add worktrees a
221
362
 
222
363
  ---
223
364
 
365
+ ## Pipelines and PRs
366
+
367
+ Switchman can now take a backlog item through planning, governed execution, review, and PR handoff.
368
+
369
+ ### Happy-path pipeline flow
370
+
371
+ ```bash
372
+ switchman pipeline start "Harden auth API permissions" \
373
+ --description "Update login permissions for the public API and add migration checks"
374
+
375
+ switchman pipeline exec pipe-123 "/path/to/your-agent-command"
376
+ switchman pipeline status pipe-123
377
+ switchman pipeline pr pipe-123
378
+ switchman pipeline publish pipe-123 --base main --draft
379
+ ```
380
+
381
+ The intended operator loop is:
382
+ 1. start the pipeline
383
+ 2. run it
384
+ 3. inspect `pipeline status` if anything blocks
385
+ 4. review the PR artifact or publish the PR
386
+
387
+ ### Create a pipeline from one issue
388
+
389
+ ```bash
390
+ switchman pipeline start "Harden auth API permissions" \
391
+ --description "Update login permissions for the public API and add migration checks"
392
+ ```
393
+
394
+ This creates structured subtasks with task specs, dependencies, and suggested worktrees.
395
+
396
+ ### Run the pipeline
397
+
398
+ ```bash
399
+ switchman pipeline exec pipe-123 "/path/to/your-agent-command"
400
+ ```
401
+
402
+ This dispatches dependency-ready tasks, launches agents with `SWITCHMAN_*` task context, applies retries/timeouts from the task spec, and runs review follow-ups until the pipeline is ready or blocked.
403
+
404
+ ### Generate a reviewer-facing PR summary
405
+
406
+ ```bash
407
+ switchman pipeline pr pipe-123
408
+ switchman pipeline pr pipe-123 --json
409
+ ```
410
+
411
+ Use this to inspect the current PR-ready summary, gate results, risk notes, and provenance.
412
+ Completed work provenance now includes the lease that executed the work, not just the task and worktree.
413
+
414
+ ### Export a PR bundle
415
+
416
+ ```bash
417
+ switchman pipeline bundle pipe-123 .switchman/pr-bundles/auth-hardening
418
+ ```
419
+
420
+ This writes:
421
+
422
+ - `pr-summary.json`
423
+ - `pr-summary.md`
424
+ - `pr-body.md`
425
+
426
+ The exported reviewer bundle includes lease-aware provenance, so a reviewer can see which execution session produced each completed task.
427
+
428
+ ### Publish a GitHub PR
429
+
430
+ ```bash
431
+ switchman pipeline publish pipe-123 --base main --draft
432
+ ```
433
+
434
+ This uses `gh pr create` with the generated PR title and body. Requirements:
435
+
436
+ - GitHub CLI (`gh`) installed
437
+ - `gh auth login` already completed
438
+ - the pipeline worktree branch pushed or otherwise available as the PR head branch
439
+
440
+ ---
441
+
442
+ ## CI and GitHub Actions
443
+
444
+ Switchman can publish CI-friendly gate output and install a ready-to-run GitHub Actions workflow.
445
+
446
+ ### Run the repo gate in CI
447
+
448
+ ```bash
449
+ switchman gate ci
450
+ switchman gate ci --json
451
+ switchman gate ci --github
452
+ ```
453
+
454
+ `switchman gate ci` fails non-zero when the repo contains unmanaged changes, stale compliance problems, or merge-governance issues.
455
+
456
+ When run under GitHub Actions with `--github`, Switchman writes:
457
+
458
+ - a step summary markdown report
459
+ - `GITHUB_OUTPUT` values such as `switchman_ok=true|false`
460
+
461
+ You can also point these explicitly:
462
+
463
+ ```bash
464
+ switchman gate ci \
465
+ --github-step-summary /path/to/summary.md \
466
+ --github-output /path/to/output.txt
467
+ ```
468
+
469
+ ### Install the GitHub Actions workflow
470
+
471
+ ```bash
472
+ switchman gate install-ci
473
+ ```
474
+
475
+ This writes `.github/workflows/switchman-gate.yml`, which runs the Switchman CI gate on pushes and pull requests.
476
+
477
+ ---
478
+
479
+ ## Tamper-evident audit trail
480
+
481
+ Switchman now keeps a signed audit trail for governed work.
482
+
483
+ Every audit event is:
484
+ - appended with a monotonic sequence number
485
+ - chained to the previous event with `prev_hash`
486
+ - hashed into its own `entry_hash`
487
+ - signed with a per-project audit key stored at `.switchman/audit.key`
488
+
489
+ That means Switchman can detect if someone edits stored audit history after the fact.
490
+
491
+ ### Verify the audit trail
492
+
493
+ ```bash
494
+ switchman audit verify
495
+ switchman audit verify --json
496
+ ```
497
+
498
+ Use this when you want proof that the recorded history still matches the project audit key and the stored event chain.
499
+
500
+ What a successful verification means:
501
+ - every event is still in the expected sequence
502
+ - every `prev_hash` still matches the prior event
503
+ - every event payload still matches its stored `entry_hash`
504
+ - every signature still matches the project audit key
505
+
506
+ If verification fails, Switchman exits non-zero and reports the reason, for example:
507
+ - `sequence_gap`
508
+ - `prev_hash_mismatch`
509
+ - `entry_hash_mismatch`
510
+ - `signature_mismatch`
511
+
512
+ This is different from normal CI:
513
+ - `switchman gate ci` answers whether the repo is safe and governed right now
514
+ - `switchman audit verify` answers whether the recorded audit history has been tampered with
515
+
516
+ ---
517
+
224
518
  ## MCP tools (Claude Code)
225
519
 
226
520
  | Tool | What it does |
@@ -25,6 +25,8 @@ examples/
25
25
 
26
26
  ## Quick start
27
27
 
28
+ This is the fastest way to understand Switchman as a new user.
29
+
28
30
  Make sure Switchman is installed globally first:
29
31
  ```bash
30
32
  npm install -g . # from the switchman repo root
@@ -36,16 +38,30 @@ bash examples/setup.sh
36
38
  bash examples/walkthrough.sh
37
39
  ```
38
40
 
41
+ If you want the shortest path:
42
+ - `setup.sh` creates the repo, worktrees, and seed tasks
43
+ - `walkthrough.sh` shows one complete 3-agent happy path, including a real claim conflict
44
+
39
45
  ## What the walkthrough shows
40
46
 
41
47
  1. **3 worktrees created** — simulating 3 parallel Claude Code instances each on their own branch
42
- 2. **Agent 1 picks up a task** — `switchman task next` returns the highest-priority item
48
+ 2. **Agent 1 picks up a task** — `switchman lease next` returns the highest-priority item and lease
43
49
  3. **Agent 1 claims files** — declares which files it will edit before touching them
44
50
  4. **Agent 2 picks up a task** — takes the next item from the queue
45
51
  5. **Agent 2 tries to claim a conflicting file** — Switchman blocks it
46
52
  6. **Agent 2 adapts** — claims only the safe files instead
47
53
  7. **Agent 1 finishes** — marks task done, releases file claims
48
- 8. **Final status** — queue updated, no lingering conflicts
54
+
55
+ Under the hood, Switchman now treats the lease as the execution record. That means reviewer artifacts and audit history can point back to the exact lease that performed the work, not just the task title.
56
+ 8. **Final status** — queue updated, readable status output, no lingering conflicts
57
+
58
+ ## What a good demo run looks like
59
+
60
+ At the end of the walkthrough, you want to see:
61
+ - tasks moving from `pending` -> `in_progress` -> `done`
62
+ - one agent blocked from claiming a file already owned by another
63
+ - `switchman scan` showing no unclaimed changes
64
+ - `switchman status` giving a clean overview of what happened
49
65
 
50
66
  ## The taskapi project
51
67
 
@@ -2,7 +2,7 @@
2
2
  # examples/walkthrough.sh
3
3
  #
4
4
  # Walks through the Switchman workflow step by step.
5
- # Simulates 3 agents working in parallel including a real conflict.
5
+ # Simulates 3 agents working in parallel, including a real file-claim conflict.
6
6
  #
7
7
  # Run AFTER setup.sh:
8
8
  # bash examples/walkthrough.sh
@@ -51,11 +51,11 @@ read -r
51
51
  # ── Step 2: Agent 1 picks up a task ──────────────────────────────────────────
52
52
 
53
53
  step "2. Agent 1 picks up the highest-priority task"
54
- agent "agent-rate-limiting" "calling: switchman task next --json"
54
+ agent "agent-rate-limiting" "calling: switchman lease next --json"
55
55
  echo ""
56
56
 
57
- TASK1=$(switchman task next --json 2>/dev/null || echo "null")
58
- TASK1_ID=$(echo "$TASK1" | python3 -c "import sys,json; d=json.load(sys.stdin); print(d['id'])" 2>/dev/null || echo "")
57
+ TASK1=$(switchman lease next --json --worktree agent-rate-limiting --agent claude-code 2>/dev/null || echo "null")
58
+ TASK1_ID=$(echo "$TASK1" | python3 -c "import sys,json; d=json.load(sys.stdin); print(d['task']['id'])" 2>/dev/null || echo "")
59
59
 
60
60
  if [ -z "$TASK1_ID" ]; then
61
61
  echo " No pending tasks found. Run setup.sh first."
@@ -63,9 +63,7 @@ if [ -z "$TASK1_ID" ]; then
63
63
  fi
64
64
 
65
65
  echo "$TASK1" | python3 -m json.tool 2>/dev/null || echo "$TASK1"
66
- echo ""
67
- switchman task assign "$TASK1_ID" agent-rate-limiting --agent claude-code
68
- ok "Task assigned to agent-rate-limiting"
66
+ ok "Task + lease assigned to agent-rate-limiting"
69
67
 
70
68
  read -r
71
69
 
@@ -86,14 +84,12 @@ read -r
86
84
  # ── Step 4: Agent 2 picks up a task ──────────────────────────────────────────
87
85
 
88
86
  step "4. Agent 2 picks up the next task"
89
- agent "agent-validation" "calling: switchman task next --json"
87
+ agent "agent-validation" "calling: switchman lease next --json"
90
88
  echo ""
91
89
 
92
- TASK2=$(switchman task next --json 2>/dev/null || echo "null")
93
- TASK2_ID=$(echo "$TASK2" | python3 -c "import sys,json; d=json.load(sys.stdin); print(d['id'])" 2>/dev/null || echo "")
94
-
95
- switchman task assign "$TASK2_ID" agent-validation --agent cursor
96
- ok "Task assigned to agent-validation"
90
+ TASK2=$(switchman lease next --json --worktree agent-validation --agent claude-code 2>/dev/null || echo "null")
91
+ TASK2_ID=$(echo "$TASK2" | python3 -c "import sys,json; d=json.load(sys.stdin); print(d['task']['id'])" 2>/dev/null || echo "")
92
+ ok "Task + lease assigned to agent-validation"
97
93
 
98
94
  read -r
99
95
 
@@ -145,7 +141,7 @@ step "8. Agent 1 finishes — marks task done and releases files"
145
141
  agent "agent-rate-limiting" "Rate limiting implemented and committed."
146
142
  echo ""
147
143
 
148
- switchman task done "$TASK1_ID" --release-files
144
+ switchman task done "$TASK1_ID"
149
145
  ok "Task done. src/middleware/auth.js and src/server.js are now free."
150
146
 
151
147
  read -r
@@ -161,11 +157,11 @@ echo ""
161
157
  echo -e "${GREEN}✓ Walkthrough complete.${RESET}"
162
158
  echo ""
163
159
  echo "What you saw:"
164
- echo " • 2 agents picked up tasks from the shared queue"
160
+ echo " • 2 agents picked up tasks from the shared queue with real leases"
165
161
  echo " • Agent 2 was blocked from claiming a file already owned by Agent 1"
166
162
  echo " • Agent 2 adapted by claiming different files"
167
163
  echo " • Agent 1 completed and released its claims"
168
- echo " • The queue updated in real time throughout"
164
+ echo " • switchman status and switchman scan stayed readable throughout"
169
165
  echo ""
170
166
  echo "To reset and run again:"
171
167
  echo " bash examples/teardown.sh && bash examples/setup.sh"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "switchman-dev",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "Route your AI agents so they don't collide",
5
5
  "type": "module",
6
6
  "main": "src/index.js",