claude-dev-env 2.3.0 → 2.4.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.
Files changed (136) hide show
  1. package/CLAUDE.md +3 -2
  2. package/agents/CLAUDE.md +1 -0
  3. package/agents/code-verifier.md +3 -3
  4. package/agents/skill-writer-agent.md +84 -0
  5. package/audit-rubrics/category_rubrics/category-o-docstring-vs-impl-drift.md +141 -41
  6. package/audit-rubrics/prompts/category-o-docstring-vs-impl-drift.md +29 -13
  7. package/docs/CLAUDE.md +1 -0
  8. package/docs/references/CLAUDE.md +1 -0
  9. package/docs/references/code-review-enforcement.md +97 -0
  10. package/docs/wsl-docker-cowork-starter-matrix.md +89 -0
  11. package/hooks/blocking/CLAUDE.md +8 -1
  12. package/hooks/blocking/code_review_enforcement_config_bootstrap.py +53 -0
  13. package/hooks/blocking/code_review_gate_deny.py +74 -0
  14. package/hooks/blocking/code_review_pr_create_gate.py +194 -0
  15. package/hooks/blocking/code_review_push_gate.py +140 -0
  16. package/hooks/blocking/code_review_stamp_directory_write_blocker.py +340 -0
  17. package/hooks/blocking/code_review_stamp_store.py +233 -0
  18. package/hooks/blocking/code_review_stamp_write_blocker_parts/__init__.py +7 -0
  19. package/hooks/blocking/code_review_stamp_write_blocker_parts/conftest.py +15 -0
  20. package/hooks/blocking/code_review_stamp_write_blocker_parts/obfuscated_stamp_path_reference.py +212 -0
  21. package/hooks/blocking/code_review_stamp_write_blocker_parts/split_directory_change_into_stamp.py +138 -0
  22. package/hooks/blocking/code_review_stamp_write_blocker_parts/test_obfuscated_stamp_path_reference.py +49 -0
  23. package/hooks/blocking/code_review_stamp_write_blocker_parts/test_split_directory_change_into_stamp.py +38 -0
  24. package/hooks/blocking/code_verifier_spawn_preflight_gate.py +39 -27
  25. package/hooks/blocking/config/code_review_enforcement_constants.py +110 -0
  26. package/hooks/blocking/config/test_code_review_enforcement_constants.py +108 -0
  27. package/hooks/blocking/config/verified_commit_constants.py +13 -9
  28. package/hooks/blocking/conftest.py +2 -0
  29. package/hooks/blocking/convergence_gate_blocker.py +112 -23
  30. package/hooks/blocking/destructive_command_blocker.py +19 -6
  31. package/hooks/blocking/pr_description_proof_of_work.py +52 -34
  32. package/hooks/blocking/test_bash_pre_tool_use_dispatcher.py +4 -1
  33. package/hooks/blocking/test_code_review_enforcement_config_bootstrap.py +62 -0
  34. package/hooks/blocking/test_code_review_gate_deny.py +54 -0
  35. package/hooks/blocking/test_code_review_pr_create_gate.py +185 -0
  36. package/hooks/blocking/test_code_review_push_gate.py +189 -0
  37. package/hooks/blocking/test_code_review_stamp_directory_write_blocker.py +180 -0
  38. package/hooks/blocking/test_code_review_stamp_store.py +205 -0
  39. package/hooks/blocking/test_code_verifier_spawn_preflight_gate.py +124 -2
  40. package/hooks/blocking/test_convergence_gate_blocker.py +153 -5
  41. package/hooks/blocking/test_destructive_command_blocker.py +1 -1
  42. package/hooks/blocking/test_destructive_command_blocker_deny_mode.py +45 -0
  43. package/hooks/blocking/test_pr_description_proof_of_work.py +151 -0
  44. package/hooks/blocking/test_pre_tool_use_dispatcher.py +8 -8
  45. package/hooks/blocking/test_verification_verdict_store.py +920 -903
  46. package/hooks/blocking/test_volatile_path_in_post_blocker.py +114 -2
  47. package/hooks/blocking/verification_verdict_store.py +27 -5
  48. package/hooks/blocking/verified_commit_gate_parts/gated_invocations.py +29 -17
  49. package/hooks/blocking/verified_commit_gate_parts/tests/test_gated_invocations.py +35 -0
  50. package/hooks/blocking/volatile_path_in_post_blocker.py +69 -8
  51. package/hooks/git-hooks/git_hooks_constants/__init__.py +6 -0
  52. package/hooks/git-hooks/pre_push.py +89 -2
  53. package/hooks/git-hooks/test_pre_push.py +103 -0
  54. package/hooks/hooks.json +16 -1
  55. package/hooks/hooks_constants/CLAUDE.md +1 -0
  56. package/hooks/hooks_constants/bash_pre_tool_use_dispatcher_constants.py +8 -0
  57. package/hooks/hooks_constants/code_rules_path_utils_constants.py +1 -0
  58. package/hooks/hooks_constants/code_verifier_spawn_preflight_gate_constants.py +26 -11
  59. package/hooks/hooks_constants/convergence_gate_blocker_constants.py +20 -3
  60. package/hooks/hooks_constants/destructive_command_segment_constants.py +3 -1
  61. package/hooks/hooks_constants/pr_description_proof_of_work_constants.py +0 -4
  62. package/hooks/hooks_constants/pre_tool_use_dispatcher_constants.py +4 -0
  63. package/hooks/hooks_constants/pyproject_config_discovery_constants.py +16 -0
  64. package/hooks/hooks_constants/test_bash_pre_tool_use_dispatcher_constants.py +24 -0
  65. package/hooks/hooks_constants/test_pre_tool_use_dispatcher_constants.py +6 -0
  66. package/hooks/hooks_constants/volatile_path_in_post_blocker_constants.py +8 -1
  67. package/hooks/validators/CLAUDE.md +1 -0
  68. package/hooks/validators/mypy_integration.py +63 -50
  69. package/hooks/validators/pyproject_config_discovery.py +101 -0
  70. package/hooks/validators/ruff_integration.py +211 -23
  71. package/hooks/validators/run_all_validators.py +21 -14
  72. package/hooks/validators/test_mypy_integration.py +32 -0
  73. package/hooks/validators/test_pyproject_config_discovery.py +94 -0
  74. package/hooks/validators/test_ruff_integration.py +68 -1
  75. package/hooks/validators/test_run_all_validators.py +25 -0
  76. package/hooks/validators/test_run_all_validators_config_discovery.py +123 -0
  77. package/package.json +1 -1
  78. package/rules/docstring-prose-matches-implementation.md +20 -43
  79. package/rules/durable-post-artifacts.md +7 -0
  80. package/scripts/codec_forwarding_test_support.py +83 -0
  81. package/scripts/conftest.py +8 -0
  82. package/scripts/dev_env_scripts_constants/CLAUDE.md +1 -1
  83. package/scripts/dev_env_scripts_constants/claude_chain_constants.py +44 -1
  84. package/scripts/dev_env_scripts_constants/code_review_constants.py +129 -12
  85. package/scripts/dev_env_scripts_constants/test_code_review_constants.py +55 -0
  86. package/scripts/invoke_code_review.py +550 -38
  87. package/scripts/resolve_worker_spawn.py +8 -1
  88. package/scripts/test_invoke_code_review.py +298 -4
  89. package/scripts/test_invoke_code_review_codec.py +77 -0
  90. package/scripts/test_resolve_worker_spawn_codec.py +101 -0
  91. package/skills/autoconverge/SKILL.md +9 -3
  92. package/skills/autoconverge/reference/convergence.md +2 -1
  93. package/skills/autoconverge/reference/multi-pr.md +6 -1
  94. package/skills/autoconverge/reference/stop-conditions.md +16 -10
  95. package/skills/autoconverge/workflow/converge.clean-audit.test.mjs +1 -1
  96. package/skills/autoconverge/workflow/converge.codex-gate.test.mjs +175 -3
  97. package/skills/autoconverge/workflow/converge.contract.test.mjs +19 -0
  98. package/skills/autoconverge/workflow/converge.mjs +24 -8
  99. package/skills/autoconverge/workflow/converge_multi.mjs +7 -3
  100. package/skills/autoconverge/workflow/converge_multi.run-input.test.mjs +5 -0
  101. package/skills/fresh-branch/CLAUDE.md +2 -0
  102. package/skills/fresh-branch/SKILL.md +2 -0
  103. package/skills/fresh-branch/scripts/create_fresh_branch.py +78 -180
  104. package/skills/fresh-branch/scripts/fresh_branch_git_commands.py +285 -0
  105. package/skills/fresh-branch/scripts/fresh_branch_scripts_constants/fresh_branch_cli_constants.py +1 -0
  106. package/skills/fresh-branch/scripts/pytest.ini +4 -0
  107. package/skills/fresh-branch/scripts/test_create_fresh_branch.py +98 -0
  108. package/skills/fresh-branch/scripts/test_fresh_branch_git_commands.py +310 -0
  109. package/skills/prototype/SKILL.md +86 -0
  110. package/skills/prototype/reference/honest-limitations.md +23 -0
  111. package/skills/prototype/reference/promotion-tasks.md +23 -0
  112. package/skills/prototype/scripts/build_sandbox_settings.py +249 -0
  113. package/skills/prototype/scripts/conftest.py +15 -0
  114. package/skills/prototype/scripts/launch_sandbox.py +205 -0
  115. package/skills/prototype/scripts/probe_sandbox_safety.py +311 -0
  116. package/skills/prototype/scripts/prototype_scripts_constants/__init__.py +1 -0
  117. package/skills/prototype/scripts/prototype_scripts_constants/config/__init__.py +0 -0
  118. package/skills/prototype/scripts/prototype_scripts_constants/config/build_sandbox_settings_constants.py +41 -0
  119. package/skills/prototype/scripts/prototype_scripts_constants/config/launch_sandbox_constants.py +23 -0
  120. package/skills/prototype/scripts/prototype_scripts_constants/config/probe_sandbox_safety_constants.py +45 -0
  121. package/skills/prototype/scripts/prototype_scripts_constants/config/prototype_common_constants.py +10 -0
  122. package/skills/prototype/scripts/test_build_sandbox_settings.py +275 -0
  123. package/skills/prototype/scripts/test_launch_sandbox.py +303 -0
  124. package/skills/prototype/scripts/test_probe_sandbox_safety.py +284 -0
  125. package/skills/prototype/workflows/promotion.md +27 -0
  126. package/skills/prototype/workflows/sandbox.md +35 -0
  127. package/skills/skill-builder/CLAUDE.md +3 -3
  128. package/skills/skill-builder/SKILL.md +5 -5
  129. package/skills/skill-builder/references/CLAUDE.md +1 -1
  130. package/skills/skill-builder/references/delegation-map.md +3 -3
  131. package/skills/skill-builder/references/description-field.md +1 -1
  132. package/skills/skill-builder/references/skill-modularity.md +2 -3
  133. package/skills/skill-builder/workflows/CLAUDE.md +1 -1
  134. package/skills/skill-builder/workflows/improve-skill.md +1 -1
  135. package/skills/skill-builder/workflows/new-skill.md +2 -2
  136. package/skills/team-advisor/SKILL.md +2 -2
@@ -146,6 +146,21 @@ def build_repo_with_origin(workspace_path: Path) -> Path:
146
146
  return clone_path
147
147
 
148
148
 
149
+ def read_branch_config(
150
+ repository_path: Path,
151
+ branch_name: str,
152
+ config_leaf: str,
153
+ ) -> str:
154
+ completed = subprocess.run(
155
+ ["git", "config", "--get", f"branch.{branch_name}.{config_leaf}"],
156
+ cwd=str(repository_path),
157
+ check=False,
158
+ capture_output=True,
159
+ text=True,
160
+ )
161
+ return completed.stdout.strip()
162
+
163
+
149
164
  def read_head_branch(repository_path: Path) -> str:
150
165
  completed = run_git(["rev-parse", "--abbrev-ref", "HEAD"], repository_path)
151
166
  return completed.stdout.strip()
@@ -156,6 +171,14 @@ def read_head_commit(repository_path: Path) -> str:
156
171
  return completed.stdout.strip()
157
172
 
158
173
 
174
+ def read_remote_main_commit(repository_path: Path) -> str:
175
+ completed = run_git(
176
+ ["ls-remote", REMOTE_NAME, f"refs/heads/{MAIN_BRANCH_NAME}"],
177
+ repository_path,
178
+ )
179
+ return completed.stdout.split()[0]
180
+
181
+
159
182
  class TestResolveAgentSlug:
160
183
  def should_prefer_flag_over_environment(
161
184
  self,
@@ -512,6 +535,81 @@ class TestCreateFreshBranchIntegration:
512
535
  assert read_head_commit(worktree_path) != local_main_commit
513
536
 
514
537
 
538
+ class TestWorktreeBranchTracking:
539
+ def should_leave_new_branch_without_an_upstream(
540
+ self,
541
+ tmp_path: Path,
542
+ monkeypatch: pytest.MonkeyPatch,
543
+ ) -> None:
544
+ module = load_create_fresh_branch_module()
545
+ repository_path = build_repo_with_origin(tmp_path / "repo")
546
+ agent_scratch_parent = tmp_path / "agent-scratch"
547
+ monkeypatch.setattr(module.sys, "platform", "linux")
548
+ monkeypatch.setattr(
549
+ module.tempfile,
550
+ "gettempdir",
551
+ lambda: str(agent_scratch_parent),
552
+ )
553
+ success_payload = module.create_fresh_branch(
554
+ branch_name="fix/no-upstream",
555
+ repo_path=repository_path,
556
+ agent_slug="claude",
557
+ base_ref=DEFAULT_BASE_REF,
558
+ )
559
+ worktree_path = Path(success_payload[PAYLOAD_KEY_WORKTREE_PATH])
560
+ assert read_head_branch(worktree_path) == "fix/no-upstream"
561
+ assert read_branch_config(repository_path, "fix/no-upstream", "merge") == ""
562
+ assert read_branch_config(repository_path, "fix/no-upstream", "remote") == ""
563
+
564
+ def should_not_aim_a_bare_push_at_main_under_push_default_upstream(
565
+ self,
566
+ tmp_path: Path,
567
+ monkeypatch: pytest.MonkeyPatch,
568
+ ) -> None:
569
+ module = load_create_fresh_branch_module()
570
+ repository_path = build_repo_with_origin(tmp_path / "repo")
571
+ empty_hooks_path = tmp_path / "repo" / "empty-hooks"
572
+ run_git(
573
+ ["config", "push.default", "upstream"],
574
+ repository_path,
575
+ empty_hooks_path=empty_hooks_path,
576
+ )
577
+ agent_scratch_parent = tmp_path / "agent-scratch"
578
+ monkeypatch.setattr(module.sys, "platform", "linux")
579
+ monkeypatch.setattr(
580
+ module.tempfile,
581
+ "gettempdir",
582
+ lambda: str(agent_scratch_parent),
583
+ )
584
+ success_payload = module.create_fresh_branch(
585
+ branch_name="feature/silent-push",
586
+ repo_path=repository_path,
587
+ agent_slug="claude",
588
+ base_ref=DEFAULT_BASE_REF,
589
+ )
590
+ worktree_path = Path(success_payload[PAYLOAD_KEY_WORKTREE_PATH])
591
+ (worktree_path / SEED_FILE_NAME).write_text("drive-by\n", encoding="utf-8")
592
+ run_git(["add", SEED_FILE_NAME], worktree_path, empty_hooks_path=empty_hooks_path)
593
+ run_git(
594
+ ["commit", "-m", "work on the feature branch"],
595
+ worktree_path,
596
+ empty_hooks_path=empty_hooks_path,
597
+ )
598
+ origin_main_before = read_remote_main_commit(repository_path)
599
+ push_attempt = subprocess.run(
600
+ ["git", "-c", f"core.hooksPath={empty_hooks_path}", "push"],
601
+ cwd=str(worktree_path),
602
+ check=False,
603
+ capture_output=True,
604
+ text=True,
605
+ )
606
+ assert push_attempt.returncode != 0, (
607
+ "bare push should be refused, but it succeeded:\n"
608
+ f"{push_attempt.stdout}{push_attempt.stderr}"
609
+ )
610
+ assert read_remote_main_commit(repository_path) == origin_main_before
611
+
612
+
515
613
  class TestMainCli:
516
614
  def should_print_success_json_and_exit_zero(
517
615
  self,
@@ -0,0 +1,310 @@
1
+ """Behavioral tests for fresh_branch_git_commands using real temporary git repos."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import subprocess
6
+ import sys
7
+ from pathlib import Path
8
+
9
+ import pytest
10
+
11
+ SCRIPTS_DIRECTORY = Path(__file__).resolve().parent
12
+ if str(SCRIPTS_DIRECTORY) not in sys.path:
13
+ sys.path.insert(0, str(SCRIPTS_DIRECTORY))
14
+
15
+ from fresh_branch_git_commands import (
16
+ assert_git_accepts_branch_name,
17
+ build_worktree_add_arguments,
18
+ create_worktree_branch,
19
+ fetch_base_ref,
20
+ is_ref_present,
21
+ read_failure_text,
22
+ resolve_base_commit,
23
+ resolve_repo_root,
24
+ run_git,
25
+ split_remote_ref,
26
+ )
27
+
28
+ GIT_USER_NAME = "fresh-branch-test"
29
+ GIT_USER_EMAIL = "fresh-branch-test@example.com"
30
+ MAIN_BRANCH_NAME = "main"
31
+ SEED_FILE_NAME = "README.md"
32
+ SEED_FILE_CONTENTS = "seed\n"
33
+
34
+
35
+ def build_repo(workspace_path: Path) -> Path:
36
+ workspace_path.mkdir(parents=True, exist_ok=True)
37
+ empty_hooks_path = workspace_path / "empty-hooks"
38
+ empty_hooks_path.mkdir()
39
+ hooks_argument = ["-c", f"core.hooksPath={empty_hooks_path}"]
40
+ subprocess.run(
41
+ ["git", *hooks_argument, "init", "-b", MAIN_BRANCH_NAME, str(workspace_path)],
42
+ check=True,
43
+ capture_output=True,
44
+ text=True,
45
+ )
46
+ for each_pair in (
47
+ ("user.name", GIT_USER_NAME),
48
+ ("user.email", GIT_USER_EMAIL),
49
+ ("commit.gpgsign", "false"),
50
+ ):
51
+ subprocess.run(
52
+ ["git", *hooks_argument, "config", *each_pair],
53
+ cwd=str(workspace_path),
54
+ check=True,
55
+ capture_output=True,
56
+ text=True,
57
+ )
58
+ (workspace_path / SEED_FILE_NAME).write_text(SEED_FILE_CONTENTS, encoding="utf-8")
59
+ subprocess.run(
60
+ ["git", *hooks_argument, "add", SEED_FILE_NAME],
61
+ cwd=str(workspace_path),
62
+ check=True,
63
+ capture_output=True,
64
+ text=True,
65
+ )
66
+ subprocess.run(
67
+ ["git", *hooks_argument, "commit", "-m", "initial commit"],
68
+ cwd=str(workspace_path),
69
+ check=True,
70
+ capture_output=True,
71
+ text=True,
72
+ )
73
+ return workspace_path
74
+
75
+
76
+ def build_clone_with_origin(workspace_path: Path) -> tuple[Path, Path]:
77
+ seed_path = build_repo(workspace_path / "seed")
78
+ empty_hooks_path = seed_path / "empty-hooks"
79
+ hooks_argument = ["-c", f"core.hooksPath={empty_hooks_path}"]
80
+ bare_origin = workspace_path / "origin.git"
81
+ subprocess.run(
82
+ ["git", *hooks_argument, "clone", "--bare", str(seed_path), str(bare_origin)],
83
+ check=True,
84
+ capture_output=True,
85
+ text=True,
86
+ )
87
+ clone_path = workspace_path / "clone"
88
+ subprocess.run(
89
+ ["git", *hooks_argument, "clone", str(bare_origin), str(clone_path)],
90
+ check=True,
91
+ capture_output=True,
92
+ text=True,
93
+ )
94
+ for each_pair in (
95
+ ("user.name", GIT_USER_NAME),
96
+ ("user.email", GIT_USER_EMAIL),
97
+ ("commit.gpgsign", "false"),
98
+ ):
99
+ subprocess.run(
100
+ ["git", *hooks_argument, "config", *each_pair],
101
+ cwd=str(clone_path),
102
+ check=True,
103
+ capture_output=True,
104
+ text=True,
105
+ )
106
+ return clone_path, bare_origin
107
+
108
+
109
+ def advance_origin_main(workspace_path: Path, bare_origin: Path) -> str:
110
+ pusher_path = workspace_path / "pusher"
111
+ empty_hooks_path = workspace_path / "seed" / "empty-hooks"
112
+ hooks_argument = ["-c", f"core.hooksPath={empty_hooks_path}"]
113
+ subprocess.run(
114
+ ["git", *hooks_argument, "clone", str(bare_origin), str(pusher_path)],
115
+ check=True,
116
+ capture_output=True,
117
+ text=True,
118
+ )
119
+ for each_pair in (
120
+ ("user.name", GIT_USER_NAME),
121
+ ("user.email", GIT_USER_EMAIL),
122
+ ("commit.gpgsign", "false"),
123
+ ):
124
+ subprocess.run(
125
+ ["git", *hooks_argument, "config", *each_pair],
126
+ cwd=str(pusher_path),
127
+ check=True,
128
+ capture_output=True,
129
+ text=True,
130
+ )
131
+ (pusher_path / SEED_FILE_NAME).write_text("advanced\n", encoding="utf-8")
132
+ subprocess.run(
133
+ ["git", *hooks_argument, "commit", "-am", "advance main"],
134
+ cwd=str(pusher_path),
135
+ check=True,
136
+ capture_output=True,
137
+ text=True,
138
+ )
139
+ subprocess.run(
140
+ ["git", *hooks_argument, "push", "origin", MAIN_BRANCH_NAME],
141
+ cwd=str(pusher_path),
142
+ check=True,
143
+ capture_output=True,
144
+ text=True,
145
+ )
146
+ completed = subprocess.run(
147
+ ["git", "rev-parse", "HEAD"],
148
+ cwd=str(pusher_path),
149
+ check=True,
150
+ capture_output=True,
151
+ text=True,
152
+ )
153
+ return completed.stdout.strip()
154
+
155
+
156
+ def read_branch_config(
157
+ repository_path: Path,
158
+ branch_name: str,
159
+ config_leaf: str,
160
+ ) -> str:
161
+ completed = subprocess.run(
162
+ ["git", "config", "--get", f"branch.{branch_name}.{config_leaf}"],
163
+ cwd=str(repository_path),
164
+ check=False,
165
+ capture_output=True,
166
+ text=True,
167
+ )
168
+ return completed.stdout.strip()
169
+
170
+
171
+ class TestBuildWorktreeAddArguments:
172
+ def test_pass_no_track_so_the_new_branch_gets_no_upstream(self) -> None:
173
+ all_arguments = build_worktree_add_arguments(
174
+ "fix/x",
175
+ Path("/tmp/agent/fix/x"),
176
+ "origin/main",
177
+ )
178
+ assert "--no-track" in all_arguments
179
+
180
+ def test_order_arguments_the_way_git_worktree_add_expects(self) -> None:
181
+ all_arguments = build_worktree_add_arguments(
182
+ "fix/x",
183
+ Path("/tmp/agent/fix/x"),
184
+ "origin/main",
185
+ )
186
+ assert all_arguments[:4] == ["worktree", "add", "-b", "fix/x"]
187
+ assert all_arguments[-1] == "origin/main"
188
+ assert all_arguments[-2] == str(Path("/tmp/agent/fix/x"))
189
+
190
+
191
+ class TestSplitRemoteRef:
192
+ def test_split_an_origin_ref(self) -> None:
193
+ assert split_remote_ref("origin/main") == ("origin", "main")
194
+
195
+ def test_split_a_non_origin_remote_ref(self) -> None:
196
+ assert split_remote_ref("upstream/dev") == ("upstream", "dev")
197
+
198
+ def test_default_a_bare_name_to_origin(self) -> None:
199
+ assert split_remote_ref("main") == ("origin", "main")
200
+
201
+ def test_keep_slashes_inside_the_branch_name(self) -> None:
202
+ assert split_remote_ref("origin/fix/nested") == ("origin", "fix/nested")
203
+
204
+
205
+ class TestAssertGitAcceptsBranchName:
206
+ def test_accept_a_conventional_branch_name(self) -> None:
207
+ assert assert_git_accepts_branch_name("fix/example-one") is None
208
+
209
+ def test_reject_a_name_git_refuses(self) -> None:
210
+ with pytest.raises(ValueError, match="relative path"):
211
+ assert_git_accepts_branch_name("fix..example")
212
+
213
+
214
+ class TestResolveRepoRoot:
215
+ def test_return_the_toplevel_for_a_nested_path(self, tmp_path: Path) -> None:
216
+ repository_path = build_repo(tmp_path / "repo")
217
+ nested_path = repository_path / "nested"
218
+ nested_path.mkdir()
219
+ assert resolve_repo_root(nested_path).resolve() == repository_path.resolve()
220
+
221
+ def test_raise_outside_a_repository(self, tmp_path: Path) -> None:
222
+ plain_directory = tmp_path / "plain"
223
+ plain_directory.mkdir()
224
+ with pytest.raises(RuntimeError, match="git repository"):
225
+ resolve_repo_root(plain_directory)
226
+
227
+
228
+ class TestIsRefPresent:
229
+ def test_find_a_local_branch(self, tmp_path: Path) -> None:
230
+ repository_path = build_repo(tmp_path / "repo")
231
+ assert is_ref_present(repository_path, MAIN_BRANCH_NAME) is True
232
+
233
+ def test_not_find_an_absent_ref(self, tmp_path: Path) -> None:
234
+ repository_path = build_repo(tmp_path / "repo")
235
+ assert is_ref_present(repository_path, "origin/nowhere") is False
236
+
237
+
238
+ class TestReadFailureText:
239
+ def test_prefer_stderr(self, tmp_path: Path) -> None:
240
+ repository_path = build_repo(tmp_path / "repo")
241
+ completed = run_git(["rev-parse", "does-not-exist"], repository_path)
242
+ assert completed.returncode != 0
243
+ assert "does-not-exist" in read_failure_text(completed)
244
+
245
+
246
+ class TestFetchBaseRef:
247
+ def test_bring_the_remote_tip_into_the_clone(self, tmp_path: Path) -> None:
248
+ clone_path, bare_origin = build_clone_with_origin(tmp_path / "workspace")
249
+ advanced_commit = advance_origin_main(tmp_path / "workspace", bare_origin)
250
+ fetch_base_ref(clone_path, "origin/main")
251
+ assert is_ref_present(clone_path, "origin/main") is True
252
+ assert resolve_base_commit(clone_path, "origin/main") == advanced_commit
253
+
254
+ def test_raise_for_a_remote_branch_that_does_not_exist(
255
+ self,
256
+ tmp_path: Path,
257
+ ) -> None:
258
+ clone_path, _bare_origin = build_clone_with_origin(tmp_path / "workspace")
259
+ with pytest.raises(RuntimeError, match="git fetch failed"):
260
+ fetch_base_ref(clone_path, "origin/nowhere")
261
+
262
+
263
+ class TestResolveBaseCommit:
264
+ def test_return_the_sha_at_the_ref(self, tmp_path: Path) -> None:
265
+ repository_path = build_repo(tmp_path / "repo")
266
+ head_commit = run_git(["rev-parse", "HEAD"], repository_path).stdout.strip()
267
+ assert resolve_base_commit(repository_path, MAIN_BRANCH_NAME) == head_commit
268
+
269
+ def test_raise_for_an_unresolvable_ref(self, tmp_path: Path) -> None:
270
+ repository_path = build_repo(tmp_path / "repo")
271
+ with pytest.raises(RuntimeError, match="could not resolve base commit"):
272
+ resolve_base_commit(repository_path, "refs/heads/nowhere")
273
+
274
+
275
+ class TestCreateWorktreeBranch:
276
+ def test_create_the_branch_at_the_base_ref_with_no_upstream(
277
+ self,
278
+ tmp_path: Path,
279
+ ) -> None:
280
+ clone_path, _bare_origin = build_clone_with_origin(tmp_path / "workspace")
281
+ origin_tip = resolve_base_commit(clone_path, "origin/main")
282
+ worktree_path = tmp_path / "worktrees" / "fix" / "created"
283
+ create_worktree_branch(
284
+ clone_path,
285
+ branch_name="fix/created",
286
+ worktree_path=worktree_path,
287
+ base_ref="origin/main",
288
+ )
289
+ assert worktree_path.is_dir()
290
+ assert resolve_base_commit(worktree_path, "HEAD") == origin_tip
291
+ assert read_branch_config(clone_path, "fix/created", "merge") == ""
292
+ assert read_branch_config(clone_path, "fix/created", "remote") == ""
293
+
294
+ def test_raise_when_the_branch_already_exists(self, tmp_path: Path) -> None:
295
+ clone_path, _bare_origin = build_clone_with_origin(tmp_path / "workspace")
296
+ first_path = tmp_path / "worktrees" / "dup-one"
297
+ second_path = tmp_path / "worktrees" / "dup-two"
298
+ create_worktree_branch(
299
+ clone_path,
300
+ branch_name="fix/dup",
301
+ worktree_path=first_path,
302
+ base_ref="origin/main",
303
+ )
304
+ with pytest.raises(RuntimeError, match="worktree add failed"):
305
+ create_worktree_branch(
306
+ clone_path,
307
+ branch_name="fix/dup",
308
+ worktree_path=second_path,
309
+ base_ref="origin/main",
310
+ )
@@ -0,0 +1,86 @@
1
+ ---
2
+ name: prototype
3
+ description: >-
4
+ Isolated hookless worktree sandbox for zero-friction proof-of-concept builds, then a clean-room re-verification that promotes a successful POC into a real deploy. Triggers: prototype, /prototype, proof of concept, POC, spike, throwaway build, build without hooks, sandbox this idea, hookless worktree, prototype then ship, promote the prototype.
5
+ ---
6
+
7
+ # Prototype
8
+
9
+ ## Principle
10
+
11
+ Give a build the freedom to move fast, then make it earn the right to ship. Two phases, one hard wall between them:
12
+
13
+ - **Sandbox** — an isolated worktree where an agent runs under `claude --bare`, so none of the standards gates (TDD, code rules, verified-commit, plain-language, stage) fire. The agent builds a proof-of-concept with zero friction.
14
+ - **Promotion** — back in the normal, fully-hooked session, the successful POC goes through a clean-room re-verification before it becomes a commit and a pull request. Nothing from the sandbox rides along un-checked.
15
+
16
+ Two safety gates stay live even in the sandbox: personal-data blocking and destructive-command blocking. A worktree shares the real repo's `.git` store and `rm` reaches the whole disk, so these are containment, not the "delays" the sandbox is meant to shed.
17
+
18
+ ## Gotchas
19
+
20
+ Highest-signal content. Append a bullet each time a run fails in a new way.
21
+
22
+ - A `--settings` file's hooks still load under `--bare` (the file is passed explicitly). That is the mechanism for keeping the two safety gates, not a bug.
23
+ - The two safety hooks must point at the real installed scripts and import their `*_constants` packages at runtime. `scripts/build_sandbox_settings.py` resolves each hook's command from the live `~/.claude/settings.json` and registers it on the matchers the sandbox needs — personal-data on Write, Edit, MultiEdit, and Bash; destructive-command on Bash — so the paths stay correct on any machine and both gates cover the write surface. Do not hand-write the hook paths or matchers, and do not inherit whatever matcher the live config happens to use (a personal-data gate wired only to a narrow tool leaves disk writes ungated).
24
+ - Under `--dangerously-skip-permissions` an `ask` decision is auto-resolved, so only a hard `deny` blocks a destructive command. The settings file carries an `env` block that sets `CLAUDE_DESTRUCTIVE_DENY_MODE`, which turns the destructive gate's terminal `ask` into a `deny`. The probe runs the gate under that env block and passes only on the hard deny.
25
+
26
+ **Refusal cases — first match wins:**
27
+
28
+ - **Not in a git repository.** Respond: `Prototype needs a git repo to branch a worktree from. Run this from inside one.`
29
+ - **The `fresh-branch` skill is not installed.** Respond: `Prototype composes fresh-branch to make the sandbox worktree, and it is not installed. Install claude-dev-env first.`
30
+ - **The `claude` CLI is not on PATH.** Respond: `The sandbox launches a headless claude session, and the claude CLI is not on PATH.`
31
+
32
+ ## Process
33
+
34
+ Two phases. Run the sandbox phase first; run the promotion phase only when the POC succeeds and the user wants it shipped.
35
+
36
+ ### Phase 1 — Sandbox
37
+
38
+ Follow `workflows/sandbox.md`. In short:
39
+
40
+ 1. Invoke the `fresh-branch` skill to create an isolated worktree off `origin/main`. Keep its returned `worktree_path` and `base_commit`.
41
+ 2. Run `scripts/build_sandbox_settings.py` to emit the minimal safety settings (personal-data and destructive-command gates only).
42
+ 3. Run `scripts/probe_sandbox_safety.py --settings <path>` and confirm both gates block. Do not continue on a non-zero exit.
43
+ 4. Run `scripts/launch_sandbox.py` to start the hookless `claude -p --bare` session in the worktree with those settings and the POC task.
44
+ 5. Read what the sandbox built. Decide whether the POC proves the idea.
45
+
46
+ ### Phase 2 — Promotion
47
+
48
+ Run only in the normal, fully-hooked session — never inside the sandbox. Follow `workflows/promotion.md`, which drives the clean-room task seeds in `reference/promotion-tasks.md`: fresh branch off live `origin/main`, POC content as an uncommitted diff, cleanup and privacy sweep, `code-verifier` in a fresh context, then `/commit` and a draft PR handed to a PR-loop skill. State the two honest limitations from `reference/honest-limitations.md`.
49
+
50
+ ## Task seeding
51
+
52
+ At the start of Phase 2, register every item in `reference/promotion-tasks.md` as a session task (`TaskCreate`, or `TodoWrite` if that is the host tool). Work only from the task list. Mark each complete with evidence. Do not track promotion as a markdown checklist.
53
+
54
+ ## Sub-skills
55
+
56
+ | Skill / agent | When | Produces | If missing |
57
+ |---|---|---|---|
58
+ | `fresh-branch` | Sandbox step 1; Promotion step 2 | isolated worktree JSON (`worktree_path`, `base_commit`, `repo_root`) | Refuse — see refusal cases |
59
+ | `privacy-hygiene` | Promotion step 5 | personal-data and secret sweep of the diff | Warn; do a manual review before continuing |
60
+ | `code-verifier` (agent) | Promotion step 6 | fresh-context verdict against the real diff; mints the commit-gate verdict | Stop; the commit gate will block anyway |
61
+ | `/commit` (command) | Promotion step 7 | conventional commit + push | Commit and push by hand per `git-workflow` |
62
+ | `autoconverge` (default; `pr-converge` or `bugteam` as alternatives) | Promotion step 9 | the PR converged to ready | Stop after the draft PR; tell the user to converge manually |
63
+
64
+ ## Degree of freedom
65
+
66
+ Low on the skill's own mechanics — the launch flags and the promotion order are fragile with cliffs, so they live in scripts and a fixed task list, not in prose the agent reconstructs. High inside the sandbox — the sandboxed agent's build freedom is the whole point.
67
+
68
+ ## File index
69
+
70
+ | File | Purpose |
71
+ |---|---|
72
+ | `SKILL.md` | This hub — principle, gotchas, when-applies, process, sub-skills, file index |
73
+ | `workflows/sandbox.md` | Phase 1 steps: worktree, safety settings, probe, hookless launch |
74
+ | `workflows/promotion.md` | Phase 2 steps: the clean-room re-verification that drives the promotion task seeds |
75
+ | `reference/promotion-tasks.md` | Task-seed catalog for the clean-room protocol (register via the task tool) |
76
+ | `reference/honest-limitations.md` | The two fixed statements to make on every promotion |
77
+ | `scripts/build_sandbox_settings.py` | Emit the minimal safety `--settings`: resolve each hook's command from live settings, register it on the required matchers |
78
+ | `scripts/launch_sandbox.py` | Launch the hookless `claude -p --bare` sandbox session in the worktree |
79
+ | `scripts/probe_sandbox_safety.py` | Prove both safety gates block before trusting the sandbox |
80
+
81
+ ## Folder map
82
+
83
+ - `SKILL.md` — hub.
84
+ - `workflows/` — the two phase workflows.
85
+ - `reference/` — promotion task seeds and the honest-limitation statements.
86
+ - `scripts/` — the settings builder, the launcher, the safety probe, their `prototype_scripts_constants` package, and paired tests.
@@ -0,0 +1,23 @@
1
+ # Honest limitations of a promoted prototype
2
+
3
+ State both of these to the user, in these terms, whenever a proof-of-concept is promoted. Do not soften or drop them. They are the price of building without standards gates.
4
+
5
+ ## 1. Write-time code rules never ran on this code
6
+
7
+ `code_rules_enforcer` is a Write/Edit gate: it checks content as it is written. Prototype code is built under `--bare`, so that gate never fired, and content brought into promotion as a git diff (apply, checkout, cherry-pick) does not pass through it either.
8
+
9
+ Standards re-engage on promotion through three surfaces that stand in for the write-time hook:
10
+
11
+ - the `code-verifier` agent, in a fresh context, deriving and running the named gates against the real diff;
12
+ - the `privacy-hygiene` sweep for personal data and secrets;
13
+ - the pull-request review (AGENTS.md criteria and any PR-loop reviewers).
14
+
15
+ Say plainly: the write-time rule engine did not see this code; the verifier and review are what cover it.
16
+
17
+ ## 2. TDD ordering is waived on promoted prototype lines
18
+
19
+ The sandbox agent wrote code first and tests, if any, after. Red-green-refactor ordering did not happen. So the honest claim on promoted prototype code is exactly this, and nothing more:
20
+
21
+ > code-verifier passed, privacy swept, review passed — TDD ordering waived.
22
+
23
+ Do not claim red-green compliance on these lines. A prototype is a reference build, not a test-first build. Fred Brooks: plan to throw one away. Promotion re-verifies the code and often rewrites it to standard; expect real work in the verifier repair loop, not a rubber stamp.
@@ -0,0 +1,23 @@
1
+ # Promotion task seeds (clean-room protocol)
2
+
3
+ Register every numbered item below as a session task (`TaskCreate`, or `TodoWrite` if that is the host tool) at the start of the promotion phase. Work only from the task list. Mark each complete only with evidence — a command result, a path, a verdict, or a skill's return. This is not a checkbox board; it is a seed catalog for the task tool.
4
+
5
+ Promotion runs in the **normal, fully-hooked session** — never inside the `--bare` sandbox. Nothing from the sandbox history is carried; only its file content is re-applied and re-verified.
6
+
7
+ 1. **Confirm the prototype is worth promoting.** The sandbox build works and the user (or the standing goal) wants it shipped. Evidence: the working behavior observed, one sentence on what the POC proves.
8
+
9
+ 2. **Fresh branch off live upstream.** Re-fetch `origin/main` and branch from it via the `fresh-branch` skill. Evidence: the returned `base_commit` matches current `origin/main`. This starts clean history and keeps the work based on live upstream.
10
+
11
+ 3. **Bring prototype content as an uncommitted working-tree diff, by allowlist.** Take the sandbox diff against its `base_commit` and copy only the product files you intend to ship into the fresh branch's working tree. Do NOT cherry-pick or merge the sandbox commits, and do NOT bulk-copy the worktree. Exclude the sandbox settings file (`.prototype-sandbox-settings.json`) and every scratch, debug, or artifact file the POC produced — name the files you are bringing, not the ones you are dropping. Evidence: the allowlist of copied paths; `git status` shows only those unstaged; `git log` shows no sandbox commits.
12
+
13
+ 4. **Cleanup pass.** Remove every scratch file, debug dump, and temp helper the prototype created (see the `cleanup-temp-files` rule). Evidence: the removed paths, or a stated "none created".
14
+
15
+ 5. **Privacy sweep.** Run the `privacy-hygiene` skill over the full applied working tree, not only the diff — a POC that pulled live data can leave a secret in a file the diff view hides. Evidence: its clean report, or the leak it found and how it was removed. If the skill is missing, do a manual PII and secret review and say so.
16
+
17
+ 6. **Verify in a fresh context.** Spawn the `code-verifier` agent against the real diff. Expect findings and a repair loop — the code was un-TDD'd. Evidence: the verifier's clean verdict, and a note of what it made you fix. Do not skip this on the belief that the sandbox agent already tested it.
18
+
19
+ 7. **Commit and open a draft PR.** Only on a clean verdict, run `/commit` (which mints the commit-gate verdict and pushes), then open a draft PR per the `git-workflow` rule. Evidence: the commit hash and the PR URL.
20
+
21
+ 8. **State the honest limitations.** Post the two statements from `reference/honest-limitations.md` — write-time rules never ran; TDD ordering waived — in the PR body or to the user. Evidence: the text was included.
22
+
23
+ 9. **Hand to a PR-loop skill.** Hand the PR to `autoconverge` by default — one autonomous run to ready. Reach for `pr-converge` when paced ticks fit better, or `bugteam` for an open-loop audit-fix. Evidence: the skill was invoked, or the user chose to converge manually.