wtcraft 0.3.0__py3-none-any.whl

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.
wtcraft/__init__.py ADDED
@@ -0,0 +1,2 @@
1
+ # wtcraft — git-native harness helper
2
+ __version__ = "0.3.0"
wtcraft/_cli.py ADDED
@@ -0,0 +1,41 @@
1
+ """
2
+ Entry point for pip / pipx installations.
3
+
4
+ Locates the bundled shell script and templates, injects WTCRAFT_TEMPLATE_DIR
5
+ into the environment, then exec-replaces itself with bash.
6
+ """
7
+
8
+ import os
9
+ import sys
10
+
11
+
12
+ def main() -> None:
13
+ pkg_dir = os.path.dirname(os.path.abspath(__file__))
14
+
15
+ shell_path = os.path.join(pkg_dir, "_shell.sh")
16
+ tmpl_dir = os.path.join(pkg_dir, "templates")
17
+
18
+ # Editable / source installs: fall back to the repo layout
19
+ if not os.path.isfile(shell_path):
20
+ shell_path = os.path.join(pkg_dir, "..", "..", "scripts", "wtcraft")
21
+ if not os.path.isdir(tmpl_dir):
22
+ tmpl_dir = os.path.join(pkg_dir, "..", "..", "templates")
23
+
24
+ shell_path = os.path.realpath(shell_path)
25
+ tmpl_dir = os.path.realpath(tmpl_dir)
26
+
27
+ if not os.path.isfile(shell_path):
28
+ print(f"wtcraft: cannot locate shell script at {shell_path}", file=sys.stderr)
29
+ sys.exit(1)
30
+ if not os.path.isdir(tmpl_dir):
31
+ print(f"wtcraft: cannot locate templates at {tmpl_dir}", file=sys.stderr)
32
+ sys.exit(1)
33
+
34
+ env = os.environ.copy()
35
+ env["WTCRAFT_TEMPLATE_DIR"] = tmpl_dir
36
+
37
+ os.execve("/bin/bash", ["/bin/bash", shell_path] + sys.argv[1:], env)
38
+
39
+
40
+ if __name__ == "__main__":
41
+ main()
wtcraft/_shell.sh ADDED
@@ -0,0 +1,537 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+
4
+ SELF_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
5
+ ROOT_DIR="$(cd "${SELF_DIR}/.." && pwd)"
6
+ # WTCRAFT_TEMPLATE_DIR overrides the default; pip/Homebrew installs set this.
7
+ TEMPLATE_DIR="${WTCRAFT_TEMPLATE_DIR:-${ROOT_DIR}/templates}"
8
+
9
+ usage() {
10
+ cat <<'EOF'
11
+ wtcraft - git-native harness helper
12
+
13
+ Usage:
14
+ wtcraft init [--patch-agent-files]
15
+ wtcraft status
16
+ wtcraft new <type/name>
17
+ wtcraft check <worktree-path-or-name>
18
+ wtcraft verify <worktree-path-or-name>
19
+ wtcraft help [command]
20
+ EOF
21
+ }
22
+
23
+ usage_init() {
24
+ cat <<'EOF'
25
+ wtcraft init [--patch-agent-files]
26
+
27
+ Scaffold harness files into the current git repository.
28
+ Existing files are never overwritten.
29
+
30
+ Options:
31
+ --patch-agent-files Append a wtcraft routing stub to CLAUDE.md and
32
+ AGENTS.md (opt-in only; never overwrites content)
33
+
34
+ Creates:
35
+ .agent-harness/planner.md
36
+ .agent-harness/executor.md
37
+ .agent-harness/finisher.md
38
+ .claude/commands/planwt.md
39
+ .claude/commands/finishwt.md
40
+ .worktree-task.template.md
41
+ EOF
42
+ }
43
+
44
+ usage_status() {
45
+ cat <<'EOF'
46
+ wtcraft status
47
+
48
+ List active worktree task files and their frontmatter metadata.
49
+ Shows: task file path, status, agent, and priority.
50
+ EOF
51
+ }
52
+
53
+ usage_new() {
54
+ cat <<'EOF'
55
+ wtcraft new <type/name>
56
+
57
+ Create a new git worktree from the base branch and seed it with a
58
+ .worktree-task.md contract file.
59
+
60
+ Arguments:
61
+ <type/name> Branch and worktree path (e.g. feat/auth-refactor)
62
+
63
+ Environment:
64
+ WTCRAFT_BASE_BRANCH Base branch to branch from (default: develop)
65
+ EOF
66
+ }
67
+
68
+ usage_check() {
69
+ cat <<'EOF'
70
+ wtcraft check <worktree-path-or-name>
71
+
72
+ Compare files changed in the worktree against the Scope and Off-limits
73
+ sections of the .worktree-task.md contract.
74
+
75
+ Scope pattern syntax:
76
+ - Exact file path: src/index.ts
77
+ - Directory prefix: src/components (matches anything under it)
78
+ - Glob (* any chars): *.md, src/*.ts (* matches path separators too)
79
+ - Recursive glob: src/**/*.ts
80
+
81
+ Exit codes:
82
+ 0 No violations detected
83
+ 2 One or more Scope or Off-limits violations found
84
+ EOF
85
+ }
86
+
87
+ usage_verify() {
88
+ cat <<'EOF'
89
+ wtcraft verify <worktree-path-or-name>
90
+
91
+ Run verification commands listed in the Verification section of the
92
+ .worktree-task.md contract. Each command runs inside the worktree directory.
93
+
94
+ Output includes per-command timing, exit codes, and a summary table.
95
+
96
+ Exit codes:
97
+ 0 All commands passed
98
+ 3 One or more commands failed
99
+ EOF
100
+ }
101
+
102
+ cmd_help() {
103
+ if [ $# -eq 0 ]; then
104
+ usage
105
+ return 0
106
+ fi
107
+ case "$1" in
108
+ init) usage_init ;;
109
+ status) usage_status ;;
110
+ new) usage_new ;;
111
+ check) usage_check ;;
112
+ verify) usage_verify ;;
113
+ help) usage ;;
114
+ *) die "no help topic for: $1" ;;
115
+ esac
116
+ }
117
+
118
+ die() {
119
+ echo "Error: $*" >&2
120
+ exit 1
121
+ }
122
+
123
+ ensure_repo_root() {
124
+ git rev-parse --show-toplevel >/dev/null 2>&1 || die "not inside a git repository"
125
+ }
126
+
127
+ copy_if_missing() {
128
+ local src="$1"
129
+ local dst="$2"
130
+ if [ -e "$dst" ]; then
131
+ return 0
132
+ fi
133
+ mkdir -p "$(dirname "$dst")"
134
+ cp "$src" "$dst"
135
+ }
136
+
137
+ append_managed_block_if_missing() {
138
+ local file="$1"
139
+ local block="$2"
140
+ local start_marker="$3"
141
+
142
+ if [ ! -f "$file" ]; then
143
+ echo "Skipped (not found): ${file}"
144
+ return 0
145
+ fi
146
+
147
+ if grep -qF "$start_marker" "$file"; then
148
+ echo "Already patched: ${file}"
149
+ return 0
150
+ fi
151
+
152
+ printf "\n%s\n" "$block" >>"$file"
153
+ echo "Patched: ${file}"
154
+ }
155
+
156
+ patch_agent_files() {
157
+ local repo_root="$1"
158
+ local claude_file="${repo_root}/CLAUDE.md"
159
+ local agents_file="${repo_root}/AGENTS.md"
160
+
161
+ local claude_start="<!-- wtcraft:claude:start -->"
162
+ local agents_start="<!-- wtcraft:agents:start -->"
163
+
164
+ local claude_block
165
+ claude_block="$(cat <<'EOF'
166
+ <!-- wtcraft:claude:start -->
167
+ ## wtcraft routing
168
+ For complex or parallel tasks, read `.agent-harness/planner.md`.
169
+ For worktree finishing, read `.agent-harness/finisher.md`.
170
+ <!-- wtcraft:claude:end -->
171
+ EOF
172
+ )"
173
+
174
+ local agents_block
175
+ agents_block="$(cat <<'EOF'
176
+ <!-- wtcraft:agents:start -->
177
+ ## wtcraft routing
178
+ If `.worktree-task.md` exists in the current worktree root, read `.agent-harness/executor.md` first and follow task Scope, Off-limits, and Verification.
179
+ <!-- wtcraft:agents:end -->
180
+ EOF
181
+ )"
182
+
183
+ append_managed_block_if_missing "$claude_file" "$claude_block" "$claude_start"
184
+ append_managed_block_if_missing "$agents_file" "$agents_block" "$agents_start"
185
+ }
186
+
187
+ cmd_init() {
188
+ ensure_repo_root
189
+ local patch_agent=false
190
+ while [ $# -gt 0 ]; do
191
+ case "$1" in
192
+ --patch-agent-files) patch_agent=true ;;
193
+ *) die "unknown init option: $1" ;;
194
+ esac
195
+ shift
196
+ done
197
+
198
+ local repo_root
199
+ repo_root="$(git rev-parse --show-toplevel)"
200
+
201
+ copy_if_missing "${TEMPLATE_DIR}/.agent-harness/planner.md" "${repo_root}/.agent-harness/planner.md"
202
+ copy_if_missing "${TEMPLATE_DIR}/.agent-harness/executor.md" "${repo_root}/.agent-harness/executor.md"
203
+ copy_if_missing "${TEMPLATE_DIR}/.agent-harness/finisher.md" "${repo_root}/.agent-harness/finisher.md"
204
+ copy_if_missing "${TEMPLATE_DIR}/.claude/commands/planwt.md" "${repo_root}/.claude/commands/planwt.md"
205
+ copy_if_missing "${TEMPLATE_DIR}/.claude/commands/finishwt.md" "${repo_root}/.claude/commands/finishwt.md"
206
+ copy_if_missing "${TEMPLATE_DIR}/worktrees/.worktree-task.md" "${repo_root}/.worktree-task.template.md"
207
+
208
+ cat <<'EOF'
209
+ Initialized wtcraft harness files (existing files were left untouched):
210
+ .agent-harness/planner.md
211
+ .agent-harness/executor.md
212
+ .agent-harness/finisher.md
213
+ .claude/commands/planwt.md
214
+ .claude/commands/finishwt.md
215
+ .worktree-task.template.md
216
+ EOF
217
+
218
+ if [ "$patch_agent" = true ]; then
219
+ echo
220
+ echo "Applying optional routing stubs to agent files..."
221
+ patch_agent_files "$repo_root"
222
+ else
223
+ echo
224
+ echo "Agent files were not modified (default behavior)."
225
+ echo "Use: wtcraft init --patch-agent-files"
226
+ fi
227
+ }
228
+
229
+ extract_frontmatter() {
230
+ local file="$1"
231
+ local key="$2"
232
+ awk -v key="$key" '
233
+ BEGIN { in_fm=0 }
234
+ /^---$/ {
235
+ if (in_fm==0) { in_fm=1; next }
236
+ else { in_fm=0; exit }
237
+ }
238
+ in_fm==1 {
239
+ if ($0 ~ "^" key ":") {
240
+ sub("^" key ":[[:space:]]*", "", $0)
241
+ print $0
242
+ exit
243
+ }
244
+ }
245
+ ' "$file"
246
+ }
247
+
248
+ cmd_status() {
249
+ ensure_repo_root
250
+ local repo_root
251
+ repo_root="$(git rev-parse --show-toplevel)"
252
+
253
+ printf "%-45s %-12s %-10s %-8s\n" "Task File" "Status" "Agent" "Priority"
254
+ printf "%-45s %-12s %-10s %-8s\n" "---------" "------" "-----" "--------"
255
+
256
+ local found=0
257
+ while IFS= read -r wt; do
258
+ [ -z "$wt" ] && continue
259
+ # Skip the primary worktree (repo root), keep only linked worktrees.
260
+ [ "$wt" = "$repo_root" ] && continue
261
+ local task rel status agent priority
262
+ task="${wt}/.worktree-task.md"
263
+ [ -f "$task" ] || continue
264
+ found=1
265
+ rel="${task#"${repo_root}"/}"
266
+ status="$(extract_frontmatter "$task" "status")"
267
+ agent="$(extract_frontmatter "$task" "agent")"
268
+ priority="$(extract_frontmatter "$task" "priority")"
269
+ status="${status:-unknown}"
270
+ agent="${agent:-unknown}"
271
+ priority="${priority:-unknown}"
272
+ printf "%-45s %-12s %-10s %-8s\n" "$rel" "$status" "$agent" "$priority"
273
+ done < <(git -C "$repo_root" worktree list --porcelain | awk '/^worktree /{sub(/^worktree /,"",$0); print}')
274
+
275
+ if [ "$found" -eq 0 ]; then
276
+ echo "No worktree task files found under worktrees/."
277
+ fi
278
+ }
279
+
280
+ cmd_new() {
281
+ ensure_repo_root
282
+ [ $# -eq 1 ] || die "new expects exactly one argument: <type/name>"
283
+ local branch="$1"
284
+ local repo_root base_branch wt_path
285
+ repo_root="$(git rev-parse --show-toplevel)"
286
+ base_branch="${WTCRAFT_BASE_BRANCH:-develop}"
287
+ wt_path="${repo_root}/worktrees/${branch}"
288
+
289
+ [ ! -e "$wt_path" ] || die "worktree path already exists: ${wt_path}"
290
+ git -C "$repo_root" show-ref --verify --quiet "refs/heads/${branch}" && die "branch already exists: ${branch}"
291
+
292
+ mkdir -p "${repo_root}/worktrees"
293
+ git -C "$repo_root" worktree add "$wt_path" -b "$branch" "$base_branch"
294
+
295
+ local task_file="${wt_path}/.worktree-task.md"
296
+ cp "${TEMPLATE_DIR}/worktrees/.worktree-task.md" "$task_file"
297
+
298
+ local today
299
+ today="$(date +%F)"
300
+ sed -i.bak "s|^branch: .*|branch: ${branch}|" "$task_file"
301
+ sed -i.bak "s|^created: .*|created: ${today}|" "$task_file"
302
+ sed -i.bak "s|^base: .*|base: ${base_branch}|" "$task_file"
303
+ rm -f "${task_file}.bak"
304
+
305
+ cat <<EOF
306
+ Created worktree:
307
+ ${wt_path}
308
+ Created task contract:
309
+ ${task_file}
310
+ EOF
311
+ }
312
+
313
+ collect_section_items() {
314
+ local file="$1"
315
+ local section="$2"
316
+ awk -v section="$section" '
317
+ BEGIN { in_section=0 }
318
+ $0 ~ "^##[[:space:]]+" section "$" { in_section=1; next }
319
+ in_section==1 && $0 ~ "^##[[:space:]]+" { in_section=0 }
320
+ in_section==1 {
321
+ line=$0
322
+ gsub(/^[[:space:]]*-[[:space:]]*/, "", line)
323
+ gsub(/`/, "", line)
324
+ gsub(/[[:space:]]+$/, "", line)
325
+ if (line != "" && line !~ /^#/) print line
326
+ }
327
+ ' "$file"
328
+ }
329
+
330
+ collect_verification_commands() {
331
+ local file="$1"
332
+ awk '
333
+ BEGIN { in_section=0 }
334
+ /^##[[:space:]]+Verification$/ { in_section=1; next }
335
+ in_section==1 && /^##[[:space:]]+/ { in_section=0 }
336
+ in_section==1 {
337
+ line=$0
338
+ if (line ~ /^[[:space:]]*-[[:space:]]*\[[ xX]\][[:space:]]+/) {
339
+ sub(/^[[:space:]]*-[[:space:]]*\[[ xX]\][[:space:]]+/, "", line)
340
+ gsub(/`/, "", line)
341
+ gsub(/[[:space:]]+$/, "", line)
342
+ if (line != "") print line
343
+ }
344
+ }
345
+ ' "$file"
346
+ }
347
+
348
+ resolve_worktree_path() {
349
+ local arg="$1"
350
+ if [ -d "$arg" ]; then
351
+ (cd "$arg" && pwd)
352
+ return 0
353
+ fi
354
+ local repo_root
355
+ repo_root="$(git rev-parse --show-toplevel)"
356
+ if [ -d "${repo_root}/worktrees/${arg}" ]; then
357
+ echo "${repo_root}/worktrees/${arg}"
358
+ return 0
359
+ fi
360
+ return 1
361
+ }
362
+
363
+ # file_matches_scope_item <file> <pattern>
364
+ #
365
+ # Returns 0 (match) when the file path satisfies the pattern, 1 otherwise.
366
+ #
367
+ # Pattern types:
368
+ # No wildcard — exact match OR directory-prefix match (pattern/ prefix)
369
+ # With * — bash glob matching; * matches any chars including '/'
370
+ # so src/*.ts also matches src/sub/dir/file.ts
371
+ # and *.md matches docs/readme.md at any depth
372
+ file_matches_scope_item() {
373
+ local file="$1"
374
+ local pattern="$2"
375
+ [ -z "$pattern" ] && return 1
376
+
377
+ # No wildcards: exact or directory-prefix match (original behaviour)
378
+ if [[ "$pattern" != *"*"* ]]; then
379
+ [ "$file" = "$pattern" ] && return 0
380
+ [[ "$file" == "$pattern/"* ]] && return 0
381
+ return 1
382
+ fi
383
+
384
+ # Glob pattern: in bash [[ ]], * matches any characters including '/'
385
+ # This makes src/*.ts, src/**/*.ts, and *.md all work as expected.
386
+ # shellcheck disable=SC2254
387
+ [[ "$file" == $pattern ]] && return 0
388
+ return 1
389
+ }
390
+
391
+ cmd_check() {
392
+ ensure_repo_root
393
+ [ $# -eq 1 ] || die "check expects exactly one argument"
394
+ local wt_path
395
+ wt_path="$(resolve_worktree_path "$1")" || die "worktree not found: $1"
396
+
397
+ local task_file="${wt_path}/.worktree-task.md"
398
+ [ -f "$task_file" ] || die "missing task file: ${task_file}"
399
+
400
+ local base_branch
401
+ base_branch="$(extract_frontmatter "$task_file" "base")"
402
+ base_branch="${base_branch:-develop}"
403
+
404
+ local changed_files=()
405
+ local scope_items=()
406
+ local offlimits_items=()
407
+ local line
408
+
409
+ while IFS= read -r line; do
410
+ changed_files+=("$line")
411
+ done < <(git -C "$wt_path" diff --name-only "${base_branch}...HEAD")
412
+
413
+ while IFS= read -r line; do
414
+ scope_items+=("$line")
415
+ done < <(collect_section_items "$task_file" "Scope")
416
+
417
+ while IFS= read -r line; do
418
+ offlimits_items+=("$line")
419
+ done < <(collect_section_items "$task_file" "Off-limits")
420
+
421
+ local has_violations=0
422
+
423
+ for f in "${changed_files[@]:-}"; do
424
+ [ -z "$f" ] && continue
425
+
426
+ local in_scope=0
427
+ for s in "${scope_items[@]:-}"; do
428
+ [ -z "$s" ] && continue
429
+ if file_matches_scope_item "$f" "$s"; then
430
+ in_scope=1
431
+ break
432
+ fi
433
+ done
434
+ if [ "${#scope_items[@]}" -gt 0 ] && [ "$in_scope" -eq 0 ]; then
435
+ echo "Scope violation: ${f}"
436
+ has_violations=1
437
+ fi
438
+
439
+ for o in "${offlimits_items[@]:-}"; do
440
+ [ -z "$o" ] && continue
441
+ if file_matches_scope_item "$f" "$o"; then
442
+ echo "Off-limits violation: ${f} (matched ${o})"
443
+ has_violations=1
444
+ fi
445
+ done
446
+ done
447
+
448
+ if [ "$has_violations" -eq 0 ]; then
449
+ echo "Check passed: no Scope/Off-limits violations detected against ${base_branch}...HEAD."
450
+ else
451
+ exit 2
452
+ fi
453
+ }
454
+
455
+ cmd_verify() {
456
+ ensure_repo_root
457
+ [ $# -eq 1 ] || die "verify expects exactly one argument"
458
+ local wt_path
459
+ wt_path="$(resolve_worktree_path "$1")" || die "worktree not found: $1"
460
+
461
+ local task_file="${wt_path}/.worktree-task.md"
462
+ [ -f "$task_file" ] || die "missing task file: ${task_file}"
463
+
464
+ local commands=()
465
+ local line
466
+ while IFS= read -r line; do
467
+ commands+=("$line")
468
+ done < <(collect_verification_commands "$task_file")
469
+
470
+ if [ "${#commands[@]}" -eq 0 ]; then
471
+ die "no verification commands found in ${task_file}"
472
+ fi
473
+
474
+ local failures=0
475
+ local total="${#commands[@]}"
476
+ local result_lines=()
477
+ local i=0
478
+
479
+ for cmd in "${commands[@]}"; do
480
+ i=$((i + 1))
481
+ local start=$SECONDS
482
+ echo ""
483
+ echo "[${i}/${total}] Running: ${cmd}"
484
+ echo "----------------------------------------------------------------"
485
+ set +e
486
+ (cd "$wt_path" && bash -lc "$cmd")
487
+ local exit_code=$?
488
+ set -e
489
+ local elapsed=$((SECONDS - start))
490
+ echo "----------------------------------------------------------------"
491
+ if [ "$exit_code" -ne 0 ]; then
492
+ failures=$((failures + 1))
493
+ echo "FAILED (exit ${exit_code}, ${elapsed}s)"
494
+ result_lines+=(" FAIL [exit ${exit_code}] (${elapsed}s) ${cmd}")
495
+ else
496
+ echo "PASSED (${elapsed}s)"
497
+ result_lines+=(" PASS [exit 0] (${elapsed}s) ${cmd}")
498
+ fi
499
+ done
500
+
501
+ echo ""
502
+ echo "================================================================"
503
+ echo "Verification summary: $((total - failures)) passed, ${failures} failed of ${total}"
504
+ echo "================================================================"
505
+ for r in "${result_lines[@]}"; do
506
+ echo "$r"
507
+ done
508
+ echo "================================================================"
509
+
510
+ if [ "$failures" -ne 0 ]; then
511
+ echo ""
512
+ echo "Verification FAILED: ${failures} of ${total} command(s) failed."
513
+ exit 3
514
+ fi
515
+
516
+ echo ""
517
+ echo "Verification PASSED: all ${total} command(s) succeeded."
518
+ }
519
+
520
+ main() {
521
+ [ $# -ge 1 ] || { usage; exit 1; }
522
+ local cmd="$1"
523
+ shift
524
+
525
+ case "$cmd" in
526
+ init) cmd_init "$@" ;;
527
+ status) cmd_status "$@" ;;
528
+ new) cmd_new "$@" ;;
529
+ check) cmd_check "$@" ;;
530
+ verify) cmd_verify "$@" ;;
531
+ help) cmd_help "$@" ;;
532
+ -h|--help) usage ;;
533
+ *) usage; die "unknown command: ${cmd}" ;;
534
+ esac
535
+ }
536
+
537
+ main "$@"
@@ -0,0 +1,33 @@
1
+ # Executor Role
2
+
3
+ You are the execution agent for a bounded worktree task.
4
+
5
+ ## Responsibilities
6
+
7
+ 1. Read `.worktree-task.md` before making any edits.
8
+ 2. Edit only files listed in `Scope`.
9
+ 3. Do not modify anything listed in `Off-limits`.
10
+ 4. Execute `Verification` commands before reporting done.
11
+
12
+ ## If Ambiguity Exists
13
+
14
+ - Stop and report the gap.
15
+ - Ask for planner clarification instead of widening scope implicitly.
16
+
17
+ ## Model Selection
18
+
19
+ Use the most capable model available in your current environment:
20
+
21
+ | Environment | Preferred model |
22
+ |---|---|
23
+ | Claude Code (Anthropic CLI) | claude-sonnet-4-6 or claude-opus-4-6 |
24
+ | Codex CLI (OpenAI) | codex (default), or gpt-4.1-mini as fallback |
25
+ | Other / unknown | Default to the host CLI's configured model |
26
+
27
+ **Codex fallback:** if the Codex CLI is invoked without an explicit `--model`
28
+ flag and the default model is unavailable, pass `--model gpt-4.1-mini` as a
29
+ fallback. Do not attempt to call the Anthropic API from inside Codex; use
30
+ whichever OpenAI model the CLI supports.
31
+
32
+ The executor role is model-agnostic — these are recommendations, not hard
33
+ requirements. Follow the Scope and Verification contract regardless of model.
@@ -0,0 +1,16 @@
1
+ # Finisher Role
2
+
3
+ You are the finisher for a worktree task.
4
+
5
+ ## Responsibilities
6
+
7
+ 1. Read `.worktree-task.md`.
8
+ 2. Run all verification commands.
9
+ 3. Check diff scope against `Scope` and `Off-limits`.
10
+ 4. Push and open PR only if checks pass.
11
+ 5. Update task status to `done` locally after successful verification.
12
+
13
+ ## Safety
14
+
15
+ - If verification fails, stop and report.
16
+ - If unexpected files changed, stop and report.
@@ -0,0 +1,19 @@
1
+ # Planner Role
2
+
3
+ You are the planner for a bounded worktree task.
4
+
5
+ ## Responsibilities
6
+
7
+ 1. Read the user request and inspect the codebase before proposing edits.
8
+ 2. Create or update `.worktree-task.md` with explicit Scope, Steps, Off-limits, Context, and Verification.
9
+ 3. Keep task boundaries strict enough for safe execution by a separate agent.
10
+ 4. Split tasks as a DAG:
11
+ - shared foundation first
12
+ - file-disjoint tasks in parallel
13
+ - shared-file tasks serialized
14
+
15
+ ## Constraints
16
+
17
+ - Prefer minimal file scope.
18
+ - Do not include unrelated refactors.
19
+ - Keep verification commands concrete and runnable.
@@ -0,0 +1,7 @@
1
+ You are finishing a worktree task.
2
+
3
+ Read:
4
+ - `.agent-harness/finisher.md`
5
+ - `worktrees/$ARGUMENTS/.worktree-task.md`
6
+
7
+ Run verification, check boundaries, and report results.
@@ -0,0 +1,8 @@
1
+ You are planning a worktree task.
2
+
3
+ Read:
4
+ - `.agent-harness/planner.md`
5
+
6
+ For the user request below, produce or update a bounded `.worktree-task.md`:
7
+
8
+ $ARGUMENTS
@@ -0,0 +1,33 @@
1
+ ---
2
+ branch: feat/example-task
3
+ agent: codex
4
+ status: ready
5
+ created: YYYY-MM-DD
6
+ priority: medium
7
+ base: develop
8
+ ---
9
+
10
+ ## Scope
11
+
12
+ - src/example.ts
13
+
14
+ ## Steps
15
+
16
+ - [ ] [D] Read files listed in Scope and Context.
17
+ - [ ] [A] Implement only the requested change.
18
+ - [ ] [D] Run verification checks and capture outcomes.
19
+
20
+ ## Off-limits
21
+
22
+ - pnpm-lock.yaml
23
+ - contracts/
24
+ - CLAUDE.md
25
+ - AGENTS.md
26
+
27
+ ## Context
28
+
29
+ Add only task-specific context that is not obvious from code.
30
+
31
+ ## Verification
32
+
33
+ - [ ] pnpm tsc --noEmit
@@ -0,0 +1,157 @@
1
+ Metadata-Version: 2.4
2
+ Name: wtcraft
3
+ Version: 0.3.0
4
+ Summary: Craft bounded multi-agent workflows with git-native worktrees
5
+ License: MIT
6
+ Project-URL: Repository, https://github.com/zywkloo/wtcraft
7
+ Project-URL: Issues, https://github.com/zywkloo/wtcraft/issues
8
+ Keywords: git,worktree,agents,orchestration,multi-agent,claude,codex
9
+ Requires-Python: >=3.9
10
+ Description-Content-Type: text/markdown
11
+ License-File: LICENSE
12
+ Dynamic: license-file
13
+
14
+ # wtcraft - Worktree Craft
15
+
16
+ <p align="center">
17
+ <img src="https://raw.githubusercontent.com/zywkloo/wtcraft/main/wtcraft-icon.PNG" alt="wtcraft icon" width="120" />
18
+ </p>
19
+
20
+ ```bash
21
+ npm install -g wtcraft
22
+ ```
23
+
24
+ `wtcraft` is a lightweight, git-native harness for solo developers orchestrating multiple coding agents on a limited budget.
25
+
26
+ **Keywords:** `Solo Dev` · `Budget-Aware` · `Agent Handoff` · `Boundaries` · `Lightweight`
27
+
28
+ The goal is simple:
29
+ - keep agent work isolated with `git worktree`
30
+ - make agent handoffs explicit with a task contract
31
+ - keep file and task boundaries easy to verify
32
+ - stay usable from CLI + any IDE
33
+
34
+ No hosted platform is required. No custom runtime is required.
35
+
36
+ ## Why
37
+
38
+ Parallel agents are useful, but raw parallelism creates four common problems:
39
+ - unclear handoff between planner and executor agents
40
+ - context pollution across tasks
41
+ - file ownership collisions
42
+ - review overload from too many noisy PRs
43
+
44
+ `wtcraft` focuses on handoff, boundaries, and budget-aware sequencing, not maximum concurrency.
45
+
46
+ For the design story behind this project, read:
47
+ [Beyond Worktrees: A Budget-Aware Multi-Agent Coding Harness for Solo Developers](https://zywkloo.github.io/blog/beyond-worktrees-budget-aware-multi-agent-coding-harness/).
48
+
49
+ ## Core Model
50
+
51
+ 1. Planner defines a bounded task contract.
52
+ 2. Executor works only inside that contract.
53
+ 3. Verifier checks scope, off-limits, and completion gates.
54
+ 4. Finisher handles push/PR/cleanup.
55
+
56
+ This supports a DAG workflow:
57
+ - merge shared foundation tasks first
58
+ - run file-disjoint tasks in parallel
59
+ - serialize tasks that touch shared files
60
+
61
+ ## Project Status
62
+
63
+ Early public bootstrap.
64
+
65
+ Current scope:
66
+ - open documentation for workflow and roadmap
67
+ - starter contract and command specs
68
+ - CLI MVP available (`init`, `status`, `check`)
69
+
70
+ ## Requirements
71
+
72
+ | Dependency | Required | Notes |
73
+ |---|---|---|
74
+ | bash | yes | macOS / Linux |
75
+ | git | yes | worktree support (git ≥ 2.5) |
76
+ | Claude Code CLI | no | optional planner / finisher agent |
77
+ | Codex CLI | no | optional executor agent |
78
+ | Node.js / npm | no | only needed for `npm install` distribution |
79
+
80
+ Claude Code and Codex are agent tools that *use* wtcraft — they are not
81
+ prerequisites for the CLI itself.
82
+
83
+ ## Install
84
+
85
+ **npm (global):**
86
+
87
+ ```bash
88
+ npm install -g wtcraft
89
+ ```
90
+
91
+ **pip / pipx:**
92
+
93
+ ```bash
94
+ pipx install wtcraft # recommended — isolated venv, no conflicts
95
+ # or
96
+ pip install --user wtcraft
97
+ ```
98
+
99
+ **Homebrew (tap):**
100
+
101
+ ```bash
102
+ brew tap zywkloo/wtcraft https://github.com/zywkloo/wtcraft
103
+ brew install wtcraft
104
+ ```
105
+
106
+ **From source (no package manager needed):**
107
+
108
+ ```bash
109
+ git clone https://github.com/zywkloo/wtcraft.git
110
+ chmod +x wtcraft/scripts/wtcraft
111
+ # add wtcraft/scripts to PATH, or run directly:
112
+ wtcraft/scripts/wtcraft init
113
+ ```
114
+
115
+ ## Quick Start
116
+
117
+ ```bash
118
+ wtcraft init # scaffold harness into current repo
119
+ wtcraft init --patch-agent-files # also append routing stubs to CLAUDE.md / AGENTS.md
120
+ wtcraft new feat/my-task # create worktree + task contract
121
+ wtcraft status # list active worktree contracts
122
+ wtcraft check <worktree-name-or-path> # verify Scope / Off-limits
123
+ wtcraft verify <worktree-name-or-path> # run Verification commands
124
+ wtcraft help [command] # per-command usage
125
+ ```
126
+
127
+ What `init` scaffolds:
128
+ - `.agent-harness/planner.md`
129
+ - `.agent-harness/executor.md`
130
+ - `.agent-harness/finisher.md`
131
+ - `.claude/commands/planwt.md`
132
+ - `.claude/commands/finishwt.md`
133
+ - `.worktree-task.template.md`
134
+
135
+ `init` is non-destructive: existing files are not overwritten.
136
+ By default `init` does not modify `CLAUDE.md` or `AGENTS.md`.
137
+ Use `--patch-agent-files` to append managed routing stubs to existing files.
138
+
139
+ `new` defaults to base branch `develop`. Set `WTCRAFT_BASE_BRANCH=main` (or another branch) when needed.
140
+
141
+ ## Docs
142
+
143
+ - [Roadmap](./docs/roadmap.md)
144
+ - [Principles](./docs/principles.md)
145
+ - [Migration Notes](./docs/migration.md)
146
+ - [Changelog](./CHANGELOG.md)
147
+
148
+ ## Testing
149
+
150
+ ```bash
151
+ chmod +x tests/smoke.sh
152
+ tests/smoke.sh
153
+ ```
154
+
155
+ ## License
156
+
157
+ Apache-2.0. See [LICENSE](./LICENSE).
@@ -0,0 +1,15 @@
1
+ wtcraft/__init__.py,sha256=yS8DBdN2QliN0HEfybR8UtLyVmVo8YLHwRvp2TBcvQc,62
2
+ wtcraft/_cli.py,sha256=oJi1K1R54btjnvizSmtkf2Q_AuHBsqMgTOE9cEZjErQ,1234
3
+ wtcraft/_shell.sh,sha256=N1t35zu0lpwjh9q1ZEle_KzpYMJjABjDlI9NpyrzDqw,14639
4
+ wtcraft/templates/.agent-harness/executor.md,sha256=Rv9XWSGC_uo88RPQx-n6Vn2A7zuc2FQx6DnLKlOrbso,1180
5
+ wtcraft/templates/.agent-harness/finisher.md,sha256=4Byg3gnGCc2ng6avwXfV4rzeACNrkaa0ktIYs0WS0r4,412
6
+ wtcraft/templates/.agent-harness/planner.md,sha256=cfmq8K-v657u-2cQoViIuqGlwVEwWKk7j4xnJHv5Mhk,598
7
+ wtcraft/templates/.claude/commands/finishwt.md,sha256=eD1RJ5PEi_1fw15Qf4OfhfB7MmSAj_7HUmiaSofx8jg,173
8
+ wtcraft/templates/.claude/commands/planwt.md,sha256=XCgy6NTWNJ9Yw934DwGQHDYpuJGj_ixL-c6PulV3m2E,161
9
+ wtcraft/templates/worktrees/.worktree-task.md,sha256=gpj7czQeGffnQ2stbTcB58MbQptQ-r-cASYVldImRuI,491
10
+ wtcraft-0.3.0.dist-info/licenses/LICENSE,sha256=bPY9h1hsfCXDq45i7vXHW7qpgrCm-cAMWeJyAlWqyew,9156
11
+ wtcraft-0.3.0.dist-info/METADATA,sha256=4WmrRcZA9l72vHTLMSKmqmvv-GJ1UEHbU49wfg2hTNc,4522
12
+ wtcraft-0.3.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
13
+ wtcraft-0.3.0.dist-info/entry_points.txt,sha256=1AmGZWIINFDnGZOgPx7RverW_RZHeTSTBYqCQaJfnZs,46
14
+ wtcraft-0.3.0.dist-info/top_level.txt,sha256=9Ysbf1Qd8sYmgCc8yCeBBvakZN2nnpi2wBOP496nNOE,8
15
+ wtcraft-0.3.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (82.0.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ wtcraft = wtcraft._cli:main
@@ -0,0 +1,176 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
@@ -0,0 +1 @@
1
+ wtcraft