claude-dev-env 8.114.8 → 8.114.10

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 (34) hide show
  1. package/.agents/skills/build-eval/reference/context-budget.md +2 -0
  2. package/.agents/skills/pr-lifecycle/SKILL.md +1 -1
  3. package/docs/rule-guides/verified-work.md +9 -1
  4. package/hooks/blocking/final_reply_gate.py +4 -3
  5. package/hooks/blocking/merge_review_gate.py +98 -1
  6. package/hooks/blocking/owned_pr_merge_stop_gate.py +50 -20
  7. package/hooks/blocking/reply_length_gate.py +52 -10
  8. package/hooks/blocking/test_final_reply_gate.py +136 -0
  9. package/hooks/blocking/test_merge_review_gate.py +48 -0
  10. package/hooks/blocking/test_owned_pr_merge_stop_gate.py +97 -6
  11. package/hooks/blocking/test_reply_length_gate.py +39 -0
  12. package/hooks/context_budget/model.py +3 -0
  13. package/hooks/context_budget/policy_changes.py +54 -5
  14. package/hooks/context_budget/policy_file.py +1 -0
  15. package/hooks/context_budget/tests/test_model.py +1 -0
  16. package/hooks/context_budget/tests/test_policy_changes.py +121 -1
  17. package/hooks/context_budget/tests/test_policy_file.py +11 -0
  18. package/hooks/features/bash-dispatchers.md +2 -2
  19. package/hooks/features/conduct-gates.md +3 -3
  20. package/hooks/hooks_constants/context_budget_constants.py +1 -0
  21. package/hooks/hooks_constants/merge_review_gate_constants.py +28 -1
  22. package/hooks/hooks_constants/owned_pr_merge_stop_gate_constants.py +4 -1
  23. package/hooks/hooks_constants/owned_pr_review_loop_constants.py +4 -0
  24. package/hooks/hooks_constants/reply_length_gate_constants.py +17 -1
  25. package/hooks/hooks_constants/test_reply_length_gate_constants.py +20 -0
  26. package/hooks/hooks_constants/test_visual_reply_rules_constants.py +5 -0
  27. package/hooks/hooks_constants/visual_reply_rules_constants.py +11 -0
  28. package/hooks/owned_pr_session_record.py +76 -1
  29. package/hooks/test_owned_pr_session_record.py +26 -0
  30. package/hooks/test_visual_reply_rules.py +27 -0
  31. package/hooks/visual_reply_rules.py +64 -0
  32. package/package.json +1 -1
  33. package/scripts/tests/test_policy_lint_rules_context_budget.py +15 -0
  34. package/scripts/tests/test_verified_work_rule.py +49 -0
@@ -154,13 +154,29 @@ UNVALIDATED_CLAIM_MESSAGE = (
154
154
  " this turn, report it as `Open: <check> - <next step>`."
155
155
  )
156
156
  CITED_NUMBER_PATTERN = re.compile(
157
- r"/actions/runs/(\d+)|/pull/(\d+)|\b(?:run|job|check)\s+#?(\d{5,})\b", re.IGNORECASE
157
+ r"/actions/runs/(\d+)|/pull/(?P<pull_number>\d+)|\b(?:run|job|check)\s+#?(\d{5,})\b",
158
+ re.IGNORECASE,
158
159
  )
160
+ CITED_PULL_NUMBER_GROUP = "pull_number"
159
161
  CITED_NUMBER_IN_RESULT_TEMPLATE = r"(?<!\d){number}(?!\d)"
162
+ PULL_LINK_IN_HOOK_TEXT_TEMPLATE = r"/pull/{number}(?!\d)"
160
163
  UNSEEN_CITATION_MESSAGE = (
161
164
  'The text cites "{citation}", and no tool result in this session shows it.'
162
165
  " Read it yourself or through a subagent first."
163
166
  )
167
+ ALL_REPLY_QUOTING_MESSAGES = (
168
+ UNSEEN_CITATION_MESSAGE,
169
+ UNVALIDATED_CLAIM_MESSAGE,
170
+ UNSOURCED_CAUSE_MESSAGE,
171
+ LONG_SENTENCE_MESSAGE,
172
+ )
173
+ MESSAGE_PLACEHOLDER_PATTERN = re.compile(r"\\\{\w+\\\}")
174
+ REPLY_ECHO_PATTERN = re.compile(
175
+ "|".join(
176
+ MESSAGE_PLACEHOLDER_PATTERN.sub(".*?", re.escape(each_message))
177
+ for each_message in ALL_REPLY_QUOTING_MESSAGES
178
+ )
179
+ )
164
180
 
165
181
  ADDITIONAL_CONTEXT_KEY = "additionalContext"
166
182
  ALL_CHECKED_MCP_TOOL_NAMES = frozenset(
@@ -11,6 +11,26 @@ def test_gate_checks_the_three_chat_tools_that_post_to_the_user() -> None:
11
11
  )
12
12
 
13
13
 
14
+ def test_reply_echo_pattern_matches_each_message_that_quotes_the_reply() -> None:
15
+ quoted = 'See "the /pull/8127 link" there'
16
+ all_messages = [
17
+ constants.UNSEEN_CITATION_MESSAGE.format(citation="/pull/8127"),
18
+ constants.UNVALIDATED_CLAIM_MESSAGE.format(claim=quoted),
19
+ constants.UNSOURCED_CAUSE_MESSAGE.format(sentence=quoted),
20
+ constants.LONG_SENTENCE_MESSAGE.format(word_count=40, word_limit=35, sentence_preview=quoted),
21
+ ]
22
+ for each_message in all_messages:
23
+ assert constants.REPLY_ECHO_PATTERN.sub("", f"before {each_message} after") == "before after"
24
+
25
+
26
+ def test_cited_number_pattern_names_the_pull_request_group() -> None:
27
+ all_pull_numbers = [
28
+ each_match[constants.CITED_PULL_NUMBER_GROUP]
29
+ for each_match in constants.CITED_NUMBER_PATTERN.finditer("see https://github.com/o/r/pull/42, run 123456")
30
+ ]
31
+ assert all_pull_numbers == ["42", None]
32
+
33
+
14
34
  def test_gate_exit_codes_match_the_hook_contract() -> None:
15
35
  assert (constants.ALLOW_EXIT_CODE, constants.BLOCK_EXIT_CODE) == (0, 2)
16
36
 
@@ -4,6 +4,11 @@ import re
4
4
  from hooks_constants import visual_reply_rules_constants as constants
5
5
 
6
6
 
7
+ def test_hook_text_attachment_types_leave_out_blocking_errors() -> None:
8
+ assert "hook_blocking_error" not in constants.ALL_HOOK_TEXT_ATTACHMENT_TYPES
9
+ assert "hook_additional_context" in constants.ALL_HOOK_TEXT_ATTACHMENT_TYPES
10
+
11
+
7
12
  def test_rules_file_path_points_at_the_shipped_rule_list() -> None:
8
13
  assert constants.RULES_FILE_PATH.is_file()
9
14
 
@@ -81,6 +81,17 @@ IS_ERROR_KEY = "is_error"
81
81
  IS_META_KEY = "isMeta"
82
82
  BLOCK_TEXT_KEY = "text"
83
83
  RESULT_TEXT_SEPARATOR = "\n"
84
+ ATTACHMENT_ENTRY_TYPE = "attachment"
85
+ ATTACHMENT_KEY = "attachment"
86
+ QUEUED_COMMAND_ATTACHMENT_TYPE = "queued_command"
87
+ ALL_HOOK_TEXT_ATTACHMENT_TYPES = frozenset(
88
+ {"hook_additional_context", "hook_system_message", QUEUED_COMMAND_ATTACHMENT_TYPE}
89
+ )
90
+ ALL_ATTACHMENT_TEXT_KEYS = ("content", "prompt")
91
+ ALL_HOOK_MESSAGE_PREFIXES = ("Stop hook feedback:", "<system-reminder>")
92
+ ORIGIN_KEY = "origin"
93
+ ORIGIN_KIND_KEY = "kind"
94
+ TASK_NOTIFICATION_ORIGIN_KIND = "task-notification"
84
95
 
85
96
  ABBREVIATION_MESSAGE = 'Abbreviation "{abbreviation}" in the text. {reminder}'
86
97
  TRACKER_NUMBER_MESSAGE = 'Tracker number "{reference}" in the text. {reminder}'
@@ -10,6 +10,12 @@ request Stop gate reads the same file back::
10
10
 
11
11
  Both Claude Code and Codex send ``session_id`` to PostToolUse and Stop hooks,
12
12
  so the file links the two hooks on either host.
13
+
14
+ The Stop gate keeps its own file of the head it last blocked on for each
15
+ pull request, so it blocks once per head::
16
+
17
+ owned-pr-stop-blocks-<session id>.json
18
+ {"https://github.com/acme/widgets/pull/42": "<head sha>"}
13
19
  """
14
20
 
15
21
  from __future__ import annotations
@@ -25,10 +31,19 @@ from hooks_constants.owned_pr_review_loop_constants import (
25
31
  NAME_DIGEST_TEXT_ENCODING,
26
32
  SESSION_RECORD_FILE_TEMPLATE,
27
33
  SESSION_RECORD_TEMPORARY_PREFIX,
34
+ STOP_BLOCK_RECORD_FILE_TEMPLATE,
35
+ STOP_BLOCK_RECORD_TEMPORARY_PREFIX,
28
36
  )
29
37
  from hooks_constants.session_file_id import session_file_id
30
38
 
31
- __all__ = ["session_record_path", "all_recorded_pull_requests", "record_pull_request"]
39
+ __all__ = [
40
+ "session_record_path",
41
+ "all_recorded_pull_requests",
42
+ "record_pull_request",
43
+ "stop_block_record_path",
44
+ "all_blocked_heads",
45
+ "record_blocked_heads",
46
+ ]
32
47
 
33
48
 
34
49
  def session_record_path(session_id: object) -> Path:
@@ -102,3 +117,63 @@ def record_pull_request(session_id: object, all_pull_request_fields: dict[str, s
102
117
  )
103
118
  except (OSError, UnicodeError):
104
119
  return
120
+
121
+
122
+ def stop_block_record_path(session_id: object) -> Path:
123
+ """Return the file that maps each pull request url to the head the Stop gate last blocked on.
124
+
125
+ Args:
126
+ session_id: The ``session_id`` field of the hook payload.
127
+ """
128
+ file_name = STOP_BLOCK_RECORD_FILE_TEMPLATE.format(session_file_id=session_file_id(session_id))
129
+ return Path(tempfile.gettempdir()) / file_name
130
+
131
+
132
+ def all_blocked_heads(session_id: object) -> dict[str, str]:
133
+ """Return the head sha the Stop gate last blocked on, keyed by pull request url.
134
+
135
+ A payload with no session id, or a missing, unreadable, or malformed
136
+ file, reads as no blocks.
137
+
138
+ Args:
139
+ session_id: The ``session_id`` field of the hook payload.
140
+ """
141
+ if not _is_session_id(session_id):
142
+ return {}
143
+ try:
144
+ record_text = stop_block_record_path(session_id).read_text(encoding=NAME_DIGEST_TEXT_ENCODING)
145
+ all_heads_by_url = json.loads(record_text)
146
+ except (OSError, ValueError):
147
+ return {}
148
+ if not isinstance(all_heads_by_url, dict):
149
+ return {}
150
+ return {
151
+ each_url: each_head
152
+ for each_url, each_head in all_heads_by_url.items()
153
+ if isinstance(each_url, str) and isinstance(each_head, str)
154
+ }
155
+
156
+
157
+ def record_blocked_heads(session_id: object, all_heads_by_url: dict[str, str]) -> None:
158
+ """Record the head sha each pull request was blocked on, keeping the other entries.
159
+
160
+ A payload with no session id records nothing. A write that fails leaves
161
+ the record as it was, so the gate blocks again on the next stop.
162
+
163
+ Args:
164
+ session_id: The ``session_id`` field of the hook payload.
165
+ all_heads_by_url: The head sha to record for each pull request url.
166
+ """
167
+ if not _is_session_id(session_id):
168
+ return
169
+ try:
170
+ write_text_atomically(
171
+ stop_block_record_path(session_id),
172
+ json.dumps({**all_blocked_heads(session_id), **all_heads_by_url}),
173
+ NAME_DIGEST_TEXT_ENCODING,
174
+ STOP_BLOCK_RECORD_TEMPORARY_PREFIX,
175
+ ATOMIC_WRITE_TEMPORARY_SUFFIX,
176
+ False,
177
+ )
178
+ except (OSError, UnicodeError):
179
+ return
@@ -22,6 +22,32 @@ def isolated_temp_folder(monkeypatch: pytest.MonkeyPatch, tmp_path: Path) -> Non
22
22
  monkeypatch.setattr(owned_pr_session_record.tempfile, "gettempdir", lambda: str(tmp_path))
23
23
 
24
24
 
25
+ def test_record_blocked_heads_should_keep_the_other_pull_requests() -> None:
26
+ owned_pr_session_record.record_blocked_heads(SESSION_ID, {PULL_REQUEST["url"]: "abc123"})
27
+ owned_pr_session_record.record_blocked_heads(SESSION_ID, {"https://github.com/o/r/pull/2": "def456"})
28
+ owned_pr_session_record.record_blocked_heads(SESSION_ID, {PULL_REQUEST["url"]: "fed789"})
29
+ assert owned_pr_session_record.all_blocked_heads(SESSION_ID) == {
30
+ PULL_REQUEST["url"]: "fed789",
31
+ "https://github.com/o/r/pull/2": "def456",
32
+ }
33
+
34
+
35
+ def test_all_blocked_heads_should_read_a_malformed_record_as_empty() -> None:
36
+ owned_pr_session_record.stop_block_record_path(SESSION_ID).write_text("[1, 2]", encoding="utf-8")
37
+ assert owned_pr_session_record.all_blocked_heads(SESSION_ID) == {}
38
+
39
+
40
+ def test_record_blocked_heads_should_skip_a_payload_with_no_session_id(tmp_path: Path) -> None:
41
+ owned_pr_session_record.record_blocked_heads(None, {PULL_REQUEST["url"]: "abc123"})
42
+ assert list(tmp_path.iterdir()) == []
43
+
44
+
45
+ def test_stop_block_record_path_should_stay_apart_from_the_pull_request_record() -> None:
46
+ assert owned_pr_session_record.stop_block_record_path(SESSION_ID) != (
47
+ owned_pr_session_record.session_record_path(SESSION_ID)
48
+ )
49
+
50
+
25
51
  def test_session_record_path_should_name_the_session_in_the_temp_folder(tmp_path: Path) -> None:
26
52
  assert (
27
53
  owned_pr_session_record.session_record_path("a/b c") == tmp_path / "owned-pr-loop-abc.json"
@@ -12,6 +12,7 @@ from hooks_constants.visual_reply_rules_constants import RULES_FILE_PATH
12
12
  from visual_reply_rules import (
13
13
  abbreviation_violation,
14
14
  attaches_picture,
15
+ hook_supplied_text,
15
16
  load_rules,
16
17
  mode_enabled,
17
18
  replies_sent_this_turn,
@@ -267,6 +268,32 @@ def test_successful_result_text_joins_only_results_without_an_error(tmp_path: Pa
267
268
  assert successful_result_text(str(tmp_path / "missing.jsonl")) is None
268
269
 
269
270
 
271
+ def test_hook_supplied_text_joins_hook_and_harness_text_only(tmp_path: Path) -> None:
272
+ all_entries = [
273
+ {"type": "user", "message": {"content": "pull/1 from the prompt"}},
274
+ {"type": "user", "isMeta": True, "message": {"content": "Stop hook feedback:\npull/2 open"}},
275
+ {"type": "user", "isMeta": True, "message": {"content": [{"type": "text", "text": "Base directory for this skill: pull/11"}]}},
276
+ {"type": "user", "isMeta": True, "message": {"content": "<system-reminder>\npull/12 watched\n</system-reminder>"}},
277
+ {"type": "user", "origin": {"kind": "task-notification"}, "message": {"content": "pull/3 done"}},
278
+ {"type": "attachment", "attachment": {"type": "hook_additional_context", "content": ["pull/4 ctx"]}},
279
+ {"type": "attachment", "attachment": {"type": "hook_system_message", "content": "pull/5 msg"}},
280
+ {
281
+ "type": "attachment",
282
+ "attachment": {"type": "queued_command", "origin": {"kind": "task-notification"}, "prompt": "pull/6 queued"},
283
+ },
284
+ {"type": "attachment", "attachment": {"type": "queued_command", "origin": {"kind": "human"}, "prompt": "pull/9 typed"}},
285
+ {"type": "attachment", "attachment": {"type": ["hook_additional_context"], "content": "pull/10 odd"}},
286
+ {"type": "attachment", "attachment": {"type": "hook_blocking_error", "blockingError": {"blockingError": "pull/7"}}},
287
+ {"type": "user", "message": {"content": [{"type": "tool_result", "content": "pull/8 result"}]}},
288
+ ]
289
+ transcript_path = tmp_path / "s.jsonl"
290
+ transcript_path.write_text("\n".join(json.dumps(each) for each in all_entries), encoding="utf-8")
291
+ assert hook_supplied_text(str(transcript_path)) == (
292
+ "Stop hook feedback:\npull/2 open\n<system-reminder>\npull/12 watched\n</system-reminder>\npull/3 done\npull/4 ctx\npull/5 msg\npull/6 queued"
293
+ )
294
+ assert hook_supplied_text(str(tmp_path / "missing.jsonl")) is None
295
+
296
+
270
297
  def test_reports_results_flags_a_markdown_table_and_three_figures() -> None:
271
298
  assert reports_results("| Check | Result |\n|---|---|\n| Unit tests | passed |")
272
299
  assert reports_results("The run shows 65 passed, 0 failed, and 3 skipped.")
@@ -21,10 +21,15 @@ from hooks_constants.visual_reply_rules_constants import (
21
21
  ABBREVIATION_MESSAGE,
22
22
  VIOLATION_LINE_SEPARATOR,
23
23
  ABBREVIATIONS_RULE_KEY,
24
+ ALL_ATTACHMENT_TEXT_KEYS,
25
+ ALL_HOOK_MESSAGE_PREFIXES,
26
+ ALL_HOOK_TEXT_ATTACHMENT_TYPES,
24
27
  ALL_REPLY_TOOL_NAME_SUFFIXES,
25
28
  ALL_VISUAL_TOOL_NAME_SUFFIXES,
26
29
  ALLOWED_CAPITALIZED_WORDS_KEY,
27
30
  ASSISTANT_ENTRY_TYPE,
31
+ ATTACHMENT_ENTRY_TYPE,
32
+ ATTACHMENT_KEY,
28
33
  BLOCK_ID_KEY,
29
34
  BLOCK_NAME_KEY,
30
35
  BLOCK_TEXT_KEY,
@@ -44,6 +49,9 @@ from hooks_constants.visual_reply_rules_constants import (
44
49
  NO_PICTURE_RULE_KEY,
45
50
  NO_VISUAL_MESSAGE,
46
51
  ONE_ITEM_RULE_KEY,
52
+ ORIGIN_KEY,
53
+ ORIGIN_KIND_KEY,
54
+ QUEUED_COMMAND_ATTACHMENT_TYPE,
47
55
  RULE_KEY_FIELD,
48
56
  RULE_LABEL_FIELD,
49
57
  RULE_REMINDER_FIELD,
@@ -52,6 +60,7 @@ from hooks_constants.visual_reply_rules_constants import (
52
60
  RULES_FILE_PATH,
53
61
  RULES_LIST_KEY,
54
62
  SECOND_REPLY_MESSAGE,
63
+ TASK_NOTIFICATION_ORIGIN_KIND,
55
64
  TEXT_BLOCK_TYPE,
56
65
  TOOL_RESULT_BLOCK_TYPE,
57
66
  TOOL_USE_BLOCK_TYPE,
@@ -326,6 +335,61 @@ def successful_result_text(transcript_path: object) -> str | None:
326
335
  )
327
336
 
328
337
 
338
+ def _attachment_texts(all_entry_fields: dict[str, object]) -> list[str]:
339
+ attachment = all_entry_fields.get(ATTACHMENT_KEY)
340
+ if not isinstance(attachment, dict):
341
+ return []
342
+ attachment_type = attachment.get(BLOCK_TYPE_KEY)
343
+ if not isinstance(attachment_type, str) or attachment_type not in ALL_HOOK_TEXT_ATTACHMENT_TYPES:
344
+ return []
345
+ if attachment_type == QUEUED_COMMAND_ATTACHMENT_TYPE and not _is_task_notification(attachment):
346
+ return []
347
+ all_texts = []
348
+ for each_key in ALL_ATTACHMENT_TEXT_KEYS:
349
+ field_value = attachment.get(each_key)
350
+ all_texts.extend(_result_texts(field_value))
351
+ if isinstance(field_value, list):
352
+ all_texts.extend(each_item for each_item in field_value if isinstance(each_item, str))
353
+ return all_texts
354
+
355
+
356
+ def _is_task_notification(all_entry_fields: dict[str, object]) -> bool:
357
+ origin = all_entry_fields.get(ORIGIN_KEY)
358
+ return isinstance(origin, dict) and origin.get(ORIGIN_KIND_KEY) == TASK_NOTIFICATION_ORIGIN_KIND
359
+
360
+
361
+ def _hook_texts(all_entry_fields: dict[str, object]) -> list[str]:
362
+ entry_type = all_entry_fields.get(ENTRY_TYPE_KEY)
363
+ if entry_type == ATTACHMENT_ENTRY_TYPE:
364
+ return _attachment_texts(all_entry_fields)
365
+ if entry_type != USER_ENTRY_TYPE:
366
+ return []
367
+ message = all_entry_fields.get(MESSAGE_KEY)
368
+ all_texts = _result_texts(message.get(CONTENT_KEY) if isinstance(message, dict) else None)
369
+ if _is_task_notification(all_entry_fields):
370
+ return all_texts
371
+ if not all_entry_fields.get(IS_META_KEY):
372
+ return []
373
+ return [each_text for each_text in all_texts if each_text.lstrip().startswith(ALL_HOOK_MESSAGE_PREFIXES)]
374
+
375
+
376
+ def hook_supplied_text(transcript_path: object) -> str | None:
377
+ """Join the text hooks and the harness put in the session outside tool results.
378
+
379
+ It covers stop-hook feedback, system reminders, a background agent's task
380
+ notification, and hook additional context, hook system message, and queued
381
+ task notification attachments. A skill body, or a prompt the user typed
382
+ while the session worked, does not count. Returns None when the transcript
383
+ cannot be read.
384
+ """
385
+ all_lines = _read_transcript_lines(transcript_path)
386
+ if all_lines is None:
387
+ return None
388
+ return RESULT_TEXT_SEPARATOR.join(
389
+ each_text for each_entry in _parsed_entries(all_lines) for each_text in _hook_texts(each_entry)
390
+ )
391
+
392
+
329
393
  def visual_shown_this_turn(all_transcript_lines: Iterable[str]) -> bool:
330
394
  """Return True when a widget or page call after the last prompt did not come back with an error."""
331
395
  all_entries = _entries_this_turn(all_transcript_lines)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-dev-env",
3
- "version": "8.114.8",
3
+ "version": "8.114.10",
4
4
  "description": "Claude Code development standards — rules, hooks, agents, commands, and skills",
5
5
  "type": "module",
6
6
  "bin": {
@@ -125,6 +125,21 @@ def test_raising_a_baseline_entry_is_a_shrink_only_finding(tmp_path: Path) -> No
125
125
  assert "the over-budget list may only shrink" in all_diagnostics[0].message
126
126
 
127
127
 
128
+ def test_a_first_baseline_on_a_policy_without_the_key_passes(tmp_path: Path) -> None:
129
+ raw_prior = _policy()
130
+ del raw_prior["baseline"]
131
+ current_text = json.dumps(_policy({_SKILL_PATH: {"lines": 300, "sections": []}}))
132
+ (tmp_path / _SKILL_PATH).parent.mkdir(parents=True)
133
+ (tmp_path / _SKILL_PATH).write_text("line\n" * 300, encoding="utf-8")
134
+
135
+ assert (
136
+ adapters.context_budget_policy_diagnostics(
137
+ _document(_POLICY_PATH, current_text, json.dumps(raw_prior)), tmp_path
138
+ )
139
+ == ()
140
+ )
141
+
142
+
128
143
  def test_a_new_or_shrunk_policy_file_passes_and_a_malformed_one_reports(
129
144
  tmp_path: Path,
130
145
  ) -> None:
@@ -5,6 +5,7 @@ from pathlib import Path
5
5
  PACKAGE_ROOT = Path(__file__).resolve().parents[2]
6
6
  INDEX_PATH = PACKAGE_ROOT / "rules" / "index.md"
7
7
  GUIDE_PATH = PACKAGE_ROOT / "docs" / "rule-guides" / "verified-work.md"
8
+ PR_LIFECYCLE_PATH = PACKAGE_ROOT / ".agents" / "skills" / "pr-lifecycle" / "SKILL.md"
8
9
 
9
10
 
10
11
  def test_the_index_points_every_session_at_the_verified_work_guide() -> None:
@@ -38,3 +39,51 @@ def test_the_guide_keeps_the_verifier_apart_and_asks_before_new_scope() -> None:
38
39
  assert "A fix whose issue did not reproduce does not pass." in guide_text
39
40
  assert "New scope goes to the user as one question before any of it is built" in guide_text
40
41
  assert "In-scope work runs with no ask." in guide_text
42
+
43
+
44
+ def _delivery_section(guide_text: str) -> str:
45
+ return guide_text.split("## Delivery", 1)[1].split("\n## ", 1)[0]
46
+
47
+
48
+ def test_the_guide_delivers_each_passed_piece_as_its_own_stack_level() -> None:
49
+ delivery_text = _delivery_section(GUIDE_PATH.read_text(encoding="utf-8"))
50
+ assert "When a piece's verifier passes, commit that piece alone, as its own stack level." in delivery_text
51
+ assert "The subject names that one behaviour." in delivery_text
52
+ assert "Start the next piece on top of it." in delivery_text
53
+ assert "A piece that depends on nothing earlier goes on its own branch from trunk." in delivery_text
54
+
55
+
56
+ def test_the_guide_names_the_stacking_command_for_each_setup() -> None:
57
+ delivery_text = _delivery_section(GUIDE_PATH.read_text(encoding="utf-8"))
58
+ assert "`gt create`" in delivery_text
59
+ assert "a plain branch from the previous level" in delivery_text
60
+
61
+
62
+ def test_the_guide_keeps_six_steps_and_sets_delivery_after_them() -> None:
63
+ guide_text = GUIDE_PATH.read_text(encoding="utf-8")
64
+ assert "## The six steps" in guide_text
65
+ assert guide_text.index("6. **Verify the fix.**") < guide_text.index("## Delivery")
66
+ assert guide_text.index("## Delivery") < guide_text.index("## The verifier")
67
+
68
+
69
+ def test_the_guide_sets_no_line_or_file_count_on_a_level() -> None:
70
+ delivery_text = _delivery_section(GUIDE_PATH.read_text(encoding="utf-8")).lower()
71
+ assert "lines" not in delivery_text
72
+ assert "files" not in delivery_text
73
+
74
+
75
+ def test_the_guide_limits_delivery_commits_to_where_the_brief_and_user_allow_them() -> None:
76
+ delivery_text = _delivery_section(GUIDE_PATH.read_text(encoding="utf-8"))
77
+ assert "This applies where the brief and the user allow commits." in delivery_text
78
+ assert "A worker whose brief bars git writes hands the piece back uncommitted and says so." in delivery_text
79
+
80
+
81
+ def test_the_pull_request_skill_points_its_decision_tree_at_the_delivery_section() -> None:
82
+ skill_text = PR_LIFECYCLE_PATH.read_text(encoding="utf-8")
83
+ decision_tree = skill_text.split("### Workflow decision tree", 1)[1].split("\n### ", 1)[0]
84
+ assert "Feature B depends on Feature A's implementation." in decision_tree
85
+ assert "Delivery section of `~/.claude/docs/rule-guides/verified-work.md`" in decision_tree
86
+ assert "its own stack level" not in decision_tree
87
+ assert "independent piece" not in decision_tree
88
+ assert "`gt create`" not in decision_tree
89
+ assert "a plain branch from the previous level" not in decision_tree