switchman-dev 0.1.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/CLAUDE.md +98 -0
- package/README.md +243 -0
- package/examples/README.md +117 -0
- package/examples/setup.sh +102 -0
- package/examples/taskapi/.switchman/switchman.db +0 -0
- package/examples/taskapi/package-lock.json +4736 -0
- package/examples/taskapi/package.json +18 -0
- package/examples/taskapi/src/db.js +179 -0
- package/examples/taskapi/src/middleware/auth.js +96 -0
- package/examples/taskapi/src/middleware/validate.js +133 -0
- package/examples/taskapi/src/routes/tasks.js +65 -0
- package/examples/taskapi/src/routes/users.js +38 -0
- package/examples/taskapi/src/server.js +7 -0
- package/examples/taskapi/tests/api.test.js +112 -0
- package/examples/teardown.sh +37 -0
- package/examples/walkthrough.sh +172 -0
- package/examples/worktrees/agent-rate-limiting/package-lock.json +4736 -0
- package/examples/worktrees/agent-rate-limiting/package.json +18 -0
- package/examples/worktrees/agent-rate-limiting/src/db.js +179 -0
- package/examples/worktrees/agent-rate-limiting/src/middleware/auth.js +96 -0
- package/examples/worktrees/agent-rate-limiting/src/middleware/validate.js +133 -0
- package/examples/worktrees/agent-rate-limiting/src/routes/tasks.js +65 -0
- package/examples/worktrees/agent-rate-limiting/src/routes/users.js +38 -0
- package/examples/worktrees/agent-rate-limiting/src/server.js +7 -0
- package/examples/worktrees/agent-rate-limiting/tests/api.test.js +112 -0
- package/examples/worktrees/agent-tests/package-lock.json +4736 -0
- package/examples/worktrees/agent-tests/package.json +18 -0
- package/examples/worktrees/agent-tests/src/db.js +179 -0
- package/examples/worktrees/agent-tests/src/middleware/auth.js +96 -0
- package/examples/worktrees/agent-tests/src/middleware/validate.js +133 -0
- package/examples/worktrees/agent-tests/src/routes/tasks.js +65 -0
- package/examples/worktrees/agent-tests/src/routes/users.js +38 -0
- package/examples/worktrees/agent-tests/src/server.js +7 -0
- package/examples/worktrees/agent-tests/tests/api.test.js +112 -0
- package/examples/worktrees/agent-validation/package-lock.json +4736 -0
- package/examples/worktrees/agent-validation/package.json +18 -0
- package/examples/worktrees/agent-validation/src/db.js +179 -0
- package/examples/worktrees/agent-validation/src/middleware/auth.js +96 -0
- package/examples/worktrees/agent-validation/src/middleware/validate.js +133 -0
- package/examples/worktrees/agent-validation/src/routes/tasks.js +65 -0
- package/examples/worktrees/agent-validation/src/routes/users.js +38 -0
- package/examples/worktrees/agent-validation/src/server.js +7 -0
- package/examples/worktrees/agent-validation/tests/api.test.js +112 -0
- package/package.json +29 -0
- package/src/cli/index.js +602 -0
- package/src/core/db.js +240 -0
- package/src/core/detector.js +172 -0
- package/src/core/git.js +265 -0
- package/src/mcp/server.js +555 -0
- package/tests/test.js +259 -0
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# examples/walkthrough.sh
|
|
3
|
+
#
|
|
4
|
+
# Walks through the Switchman workflow step by step.
|
|
5
|
+
# Simulates 3 agents working in parallel — including a real conflict.
|
|
6
|
+
#
|
|
7
|
+
# Run AFTER setup.sh:
|
|
8
|
+
# bash examples/walkthrough.sh
|
|
9
|
+
|
|
10
|
+
set -e
|
|
11
|
+
|
|
12
|
+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
13
|
+
TASKAPI_DIR="$SCRIPT_DIR/taskapi"
|
|
14
|
+
WT_RATE="$SCRIPT_DIR/worktrees/agent-rate-limiting"
|
|
15
|
+
WT_VALID="$SCRIPT_DIR/worktrees/agent-validation"
|
|
16
|
+
WT_TESTS="$SCRIPT_DIR/worktrees/agent-tests"
|
|
17
|
+
|
|
18
|
+
# Colours
|
|
19
|
+
CYAN='\033[0;36m'
|
|
20
|
+
GREEN='\033[0;32m'
|
|
21
|
+
YELLOW='\033[1;33m'
|
|
22
|
+
RED='\033[0;31m'
|
|
23
|
+
BOLD='\033[1m'
|
|
24
|
+
RESET='\033[0m'
|
|
25
|
+
|
|
26
|
+
step() { echo ""; echo -e "${BOLD}── $1 ──────────────────────────────────────${RESET}"; echo ""; }
|
|
27
|
+
agent() { echo -e "${CYAN}[Agent: $1]${RESET} $2"; }
|
|
28
|
+
info() { echo -e " ${YELLOW}→${RESET} $1"; }
|
|
29
|
+
ok() { echo -e " ${GREEN}✓${RESET} $1"; }
|
|
30
|
+
|
|
31
|
+
cd "$TASKAPI_DIR"
|
|
32
|
+
|
|
33
|
+
echo ""
|
|
34
|
+
echo -e "${BOLD}━━━ Switchman Walkthrough ━━━━━━━━━━━━━━━━━━━━━${RESET}"
|
|
35
|
+
echo ""
|
|
36
|
+
echo "This walkthrough simulates 3 parallel Claude Code agents"
|
|
37
|
+
echo "coordinating through Switchman on the taskapi project."
|
|
38
|
+
echo ""
|
|
39
|
+
echo "Press ENTER to step through each action."
|
|
40
|
+
read -r
|
|
41
|
+
|
|
42
|
+
# ── Step 1: Show the starting state ──────────────────────────────────────────
|
|
43
|
+
|
|
44
|
+
step "1. Starting state"
|
|
45
|
+
info "4 tasks waiting in the queue, 3 worktrees ready"
|
|
46
|
+
echo ""
|
|
47
|
+
switchman status
|
|
48
|
+
|
|
49
|
+
read -r
|
|
50
|
+
|
|
51
|
+
# ── Step 2: Agent 1 picks up a task ──────────────────────────────────────────
|
|
52
|
+
|
|
53
|
+
step "2. Agent 1 picks up the highest-priority task"
|
|
54
|
+
agent "agent-rate-limiting" "calling: switchman task next --json"
|
|
55
|
+
echo ""
|
|
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 "")
|
|
59
|
+
|
|
60
|
+
if [ -z "$TASK1_ID" ]; then
|
|
61
|
+
echo " No pending tasks found. Run setup.sh first."
|
|
62
|
+
exit 1
|
|
63
|
+
fi
|
|
64
|
+
|
|
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"
|
|
69
|
+
|
|
70
|
+
read -r
|
|
71
|
+
|
|
72
|
+
# ── Step 3: Agent 1 claims its files ─────────────────────────────────────────
|
|
73
|
+
|
|
74
|
+
step "3. Agent 1 claims the files it needs"
|
|
75
|
+
agent "agent-rate-limiting" "I'll be editing the middleware and server files"
|
|
76
|
+
echo ""
|
|
77
|
+
|
|
78
|
+
switchman claim "$TASK1_ID" agent-rate-limiting \
|
|
79
|
+
src/middleware/auth.js \
|
|
80
|
+
src/server.js
|
|
81
|
+
|
|
82
|
+
ok "Files claimed — no conflicts"
|
|
83
|
+
|
|
84
|
+
read -r
|
|
85
|
+
|
|
86
|
+
# ── Step 4: Agent 2 picks up a task ──────────────────────────────────────────
|
|
87
|
+
|
|
88
|
+
step "4. Agent 2 picks up the next task"
|
|
89
|
+
agent "agent-validation" "calling: switchman task next --json"
|
|
90
|
+
echo ""
|
|
91
|
+
|
|
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"
|
|
97
|
+
|
|
98
|
+
read -r
|
|
99
|
+
|
|
100
|
+
# ── Step 5: Agent 2 tries to claim a file already owned by Agent 1 ───────────
|
|
101
|
+
|
|
102
|
+
step "5. Agent 2 tries to claim src/middleware/auth.js — CONFLICT"
|
|
103
|
+
agent "agent-validation" "Input validation also touches auth.js..."
|
|
104
|
+
echo ""
|
|
105
|
+
|
|
106
|
+
# This should warn about the conflict
|
|
107
|
+
switchman claim "$TASK2_ID" agent-validation \
|
|
108
|
+
src/middleware/auth.js \
|
|
109
|
+
src/middleware/validate.js \
|
|
110
|
+
src/routes/tasks.js || true
|
|
111
|
+
|
|
112
|
+
echo ""
|
|
113
|
+
info "Switchman blocked the conflicting claim."
|
|
114
|
+
info "Agent 2 should pick different files or coordinate with Agent 1."
|
|
115
|
+
|
|
116
|
+
read -r
|
|
117
|
+
|
|
118
|
+
# ── Step 6: Agent 2 claims only the safe files ───────────────────────────────
|
|
119
|
+
|
|
120
|
+
step "6. Agent 2 claims only the files that aren't taken"
|
|
121
|
+
agent "agent-validation" "Claiming only validate.js and routes/tasks.js instead"
|
|
122
|
+
echo ""
|
|
123
|
+
|
|
124
|
+
switchman claim "$TASK2_ID" agent-validation \
|
|
125
|
+
src/middleware/validate.js \
|
|
126
|
+
src/routes/tasks.js
|
|
127
|
+
|
|
128
|
+
ok "Clean claim — no conflicts"
|
|
129
|
+
|
|
130
|
+
read -r
|
|
131
|
+
|
|
132
|
+
# ── Step 7: Run a full conflict scan ─────────────────────────────────────────
|
|
133
|
+
|
|
134
|
+
step "7. Full conflict scan across all worktrees"
|
|
135
|
+
info "This is what you'd run before any merge"
|
|
136
|
+
echo ""
|
|
137
|
+
|
|
138
|
+
switchman scan
|
|
139
|
+
|
|
140
|
+
read -r
|
|
141
|
+
|
|
142
|
+
# ── Step 8: Agent 1 finishes its task ────────────────────────────────────────
|
|
143
|
+
|
|
144
|
+
step "8. Agent 1 finishes — marks task done and releases files"
|
|
145
|
+
agent "agent-rate-limiting" "Rate limiting implemented and committed."
|
|
146
|
+
echo ""
|
|
147
|
+
|
|
148
|
+
switchman task done "$TASK1_ID" --release-files
|
|
149
|
+
ok "Task done. src/middleware/auth.js and src/server.js are now free."
|
|
150
|
+
|
|
151
|
+
read -r
|
|
152
|
+
|
|
153
|
+
# ── Step 9: Final status ──────────────────────────────────────────────────────
|
|
154
|
+
|
|
155
|
+
step "9. Final status"
|
|
156
|
+
switchman status
|
|
157
|
+
|
|
158
|
+
echo ""
|
|
159
|
+
echo -e "${BOLD}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${RESET}"
|
|
160
|
+
echo ""
|
|
161
|
+
echo -e "${GREEN}✓ Walkthrough complete.${RESET}"
|
|
162
|
+
echo ""
|
|
163
|
+
echo "What you saw:"
|
|
164
|
+
echo " • 2 agents picked up tasks from the shared queue"
|
|
165
|
+
echo " • Agent 2 was blocked from claiming a file already owned by Agent 1"
|
|
166
|
+
echo " • Agent 2 adapted by claiming different files"
|
|
167
|
+
echo " • Agent 1 completed and released its claims"
|
|
168
|
+
echo " • The queue updated in real time throughout"
|
|
169
|
+
echo ""
|
|
170
|
+
echo "To reset and run again:"
|
|
171
|
+
echo " bash examples/teardown.sh && bash examples/setup.sh"
|
|
172
|
+
echo ""
|