claude-dev-env 8.6.1 → 8.8.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 (119) hide show
  1. package/.agents/skills/privacy-hygiene/reference/sweep-procedure.md +1 -1
  2. package/.agents/skills/team-advisor/SKILL.md +2 -2
  3. package/_shared/advisor/reference/identity.md +1 -1
  4. package/_shared/advisor/reference/spawn-walk-log.md +1 -1
  5. package/_shared/advisor/reference/warm-up.md +3 -1
  6. package/_shared/advisor/scripts/config/advisor_scripts_constants/model_tier_run_validator_constants.py +16 -0
  7. package/_shared/advisor/scripts/model_tier_run_validator.py +23 -5
  8. package/_shared/advisor/scripts/tests/test_model_tier_run_validator.py +85 -6
  9. package/_shared/pr-loop/scripts/terminology_sweep.py +10 -9
  10. package/_shared/pr-loop/scripts/tests/test_terminology_sweep.py +13 -0
  11. package/bin/install.test.mjs +25 -0
  12. package/docs/high-trust-agent-delivery.md +132 -0
  13. package/docs/references/advisor-tool.md +3 -2
  14. package/docs/second-claude-account.md +50 -0
  15. package/hooks/advisory/refactor_guard.py +2 -2
  16. package/hooks/advisory/test_refactor_guard.py +21 -0
  17. package/hooks/blocking/code_rules_enforcer_test_support.py +10 -0
  18. package/hooks/blocking/code_rules_shared.py +4 -7
  19. package/hooks/blocking/conftest.py +22 -0
  20. package/hooks/blocking/state_description_blocker.py +10 -8
  21. package/hooks/blocking/test_code_rules_enforcer_duplicate_body.py +2 -11
  22. package/hooks/blocking/test_code_rules_enforcer_duplicate_body_hook_routing.py +4 -29
  23. package/hooks/blocking/test_code_rules_enforcer_test_support.py +21 -0
  24. package/hooks/blocking/test_code_rules_enforcer_zero_payload_alias_hook_routing.py +3 -19
  25. package/hooks/blocking/test_code_rules_shared.py +18 -0
  26. package/hooks/blocking/test_conftest.py +35 -0
  27. package/hooks/blocking/test_pii_scanner.py +8 -0
  28. package/hooks/blocking/test_state_description_blocker.py +16 -0
  29. package/hooks/git-hooks/git_hooks_constants/__init__.py +1 -14
  30. package/hooks/git-hooks/pull_request_handoff.py +2 -2
  31. package/hooks/git-hooks/test_config.py +10 -3
  32. package/hooks/git-hooks/test_pull_request_handoff.py +49 -0
  33. package/hooks/git-hooks/test_verification_notice_state.py +50 -0
  34. package/hooks/git-hooks/verification_notice_state.py +3 -1
  35. package/hooks/hooks_constants/code_rules_enforcer_constants.py +13 -5
  36. package/hooks/hooks_constants/pii_prevention_constants.py +1 -0
  37. package/hooks/hooks_constants/refactor_guard_constants.py +2 -0
  38. package/hooks/hooks_constants/session_edit_stage_gate_constants.py +3 -4
  39. package/hooks/hooks_constants/state_description_blocker_constants.py +0 -3
  40. package/hooks/hooks_constants/test_state_description_blocker_constants.py +9 -7
  41. package/hooks/validators/exempt_paths.py +3 -18
  42. package/hooks/validators/test_exempt_paths.py +20 -0
  43. package/hooks/validators/test_python_antipattern_checks.py +14 -0
  44. package/package.json +1 -1
  45. package/rules/agent-merges-its-own-green-pull-request.md +54 -0
  46. package/rules/archiving-agent-config.md +10 -0
  47. package/rules/code-standards.md +1 -0
  48. package/rules/correction-lens.md +134 -0
  49. package/rules/flag-non-breaking-findings.md +11 -0
  50. package/rules/long-horizon-autonomy.md +11 -0
  51. package/rules/no-contrast-framing.md +68 -0
  52. package/rules/review-closure-is-a-check.md +44 -0
  53. package/scripts/Invoke-PesterSuites.ps1 +42 -0
  54. package/scripts/agent_merge_check.py +381 -0
  55. package/scripts/check.ps1 +12 -1
  56. package/scripts/ci/install-playtest.mjs +291 -0
  57. package/scripts/ci/install-playtest.test.mjs +84 -0
  58. package/scripts/ci/installer-lifecycle.mjs +11 -30
  59. package/scripts/ci/installer-lifecycle.test.mjs +14 -0
  60. package/scripts/ci/pstack-command-shim.test.mjs +33 -0
  61. package/scripts/ci/scratch-home-install.mjs +73 -0
  62. package/scripts/ci/scratch-home-install.test.mjs +49 -0
  63. package/scripts/claude_account_choice.py +246 -0
  64. package/scripts/claude_account_profile.py +371 -0
  65. package/scripts/claude_chain_usage.py +49 -5
  66. package/scripts/codex_compat_materializer.py +33 -16
  67. package/scripts/contrast_framing.py +101 -0
  68. package/scripts/dev_env_scripts_constants/agent_merge_check_constants.py +121 -0
  69. package/scripts/dev_env_scripts_constants/claude_account_constants.py +166 -0
  70. package/scripts/dev_env_scripts_constants/contrast_framing_constants.py +82 -0
  71. package/scripts/dev_env_scripts_constants/merge_gate_check_constants.py +23 -0
  72. package/scripts/dev_env_scripts_constants/review_closure_constants.py +241 -0
  73. package/scripts/dev_env_scripts_constants/test_claude_account_constants.py +21 -0
  74. package/scripts/dev_env_scripts_constants/test_code_review_constants.py +12 -0
  75. package/scripts/dev_env_scripts_constants/test_contrast_framing_constants.py +60 -0
  76. package/scripts/durable_post_lint.py +30 -4
  77. package/scripts/followup_cli.py +6 -10
  78. package/scripts/merge_gate_checks.py +236 -0
  79. package/scripts/policy_lint/adapter_contrast_framing.py +59 -0
  80. package/scripts/policy_lint/adapters.py +30 -0
  81. package/scripts/policy_lint/config/constants.py +2 -0
  82. package/scripts/policy_lint/registry.py +5 -0
  83. package/scripts/repository_checks/config/constants.py +12 -0
  84. package/scripts/repository_checks/config/policy_document.py +28 -2
  85. package/scripts/repository_checks/followups.py +54 -0
  86. package/scripts/repository_checks/match_exemptions.py +67 -0
  87. package/scripts/repository_checks/models.py +46 -2
  88. package/scripts/repository_checks/reporting.py +23 -7
  89. package/scripts/repository_checks/tracked_secrets.py +2 -2
  90. package/scripts/repository_policy.py +4 -2
  91. package/scripts/review_closure.py +134 -0
  92. package/scripts/review_closure_github.py +345 -0
  93. package/scripts/review_closure_model.py +360 -0
  94. package/scripts/test_agent_merge_check.py +317 -0
  95. package/scripts/test_claude_account_choice.py +217 -0
  96. package/scripts/test_claude_account_profile.py +220 -0
  97. package/scripts/test_claude_chain_usage.py +40 -0
  98. package/scripts/test_durable_post_lint.py +46 -0
  99. package/scripts/test_followup_cli.py +40 -0
  100. package/scripts/test_merge_gate_checks.py +92 -0
  101. package/scripts/tests/test_code_review_constants.py +78 -0
  102. package/scripts/tests/test_codex_compat_materializer.py +48 -4
  103. package/scripts/tests/test_contrast_framing.py +117 -0
  104. package/scripts/tests/test_followups.py +88 -0
  105. package/scripts/tests/test_match_exemptions.py +291 -0
  106. package/scripts/tests/test_models.py +67 -2
  107. package/scripts/tests/test_package_inventory.py +6 -4
  108. package/scripts/tests/test_pester_suites_run.py +53 -0
  109. package/scripts/tests/test_policy_document.py +39 -1
  110. package/scripts/tests/test_policy_lint_rules_contrast_framing.py +68 -0
  111. package/scripts/tests/test_reporting.py +18 -0
  112. package/scripts/tests/test_repository_policy.py +43 -1
  113. package/scripts/tests/test_review_closure.py +126 -0
  114. package/scripts/tests/test_review_closure_github.py +240 -0
  115. package/scripts/tests/test_review_closure_model.py +299 -0
  116. package/scripts/tests/test_tracked_secrets.py +42 -0
  117. package/hooks/hooks_constants/precommit_code_rules_gate_constants.py +0 -12
  118. package/scripts/repository_checks/email_exemptions.py +0 -39
  119. package/scripts/tests/test_email_exemptions.py +0 -158
@@ -49,7 +49,7 @@ Review each hit. Ignore:
49
49
 
50
50
  - Stage only clean files
51
51
  - Prefer `--body-file` for `gh` posts (also required by the gh-cli-conventions rule)
52
- - Let `pii_prevention_blocker` re-run on the next Write / commit / post
52
+ - No hook re-scans the next Write, commit, or post; `pii_prevention_blocker` was retired. Re-run this sweep before the next commit or post.
53
53
 
54
54
  ## Accepted residual (do not over-scrub)
55
55
 
@@ -25,7 +25,7 @@ One warm advisor at the strongest tier this session can reach. This session is t
25
25
 
26
26
  1. Name the session identity first (protocol **Host profiles**), then walk the model floor.
27
27
  2. Claude: when `advisor` is in this session's tool list, the built-in advisor tool is the advisor. Spawn nothing and call `advisor()` at each consult point. Otherwise spawn or resume `pstack:poteto-agent` at `ADVISOR_EFFORT` (default low) with the advisor response contract in the prompt. When the bound model is out of usage, use the configured fallback at the same effort. Codex: use the native advisor path. Third-party: use the headless advisor path. When the host's walk fails, fail closed.
28
- 3. Name the warm instance `team-advisor-agent` and keep its advisor response contract in every first prompt. When a native Codex subagent spawn is the advisor path, pass `flags: ["--advisor"]` with Astra.
28
+ 3. Name the warm instance `team-advisor-agent` and keep its advisor response contract in every first prompt. When a native Codex subagent spawn is the advisor path and the spawn tool has a `flags` field, pass `flags: ["--advisor"]` with Astra and record `advisor_flag: passed`. A spawn that skips an offered flag is a failed bind. When the spawn tool has no `flags` field, as in `codex exec`, spawn `gpt-6-astra` plainly, record `advisor_flag: unavailable`, and treat it as bound.
29
29
  4. Skip the multi-consumer "who you are" opener. This session is the sole consumer.
30
30
  5. When the bind or reply path fails, fail closed and report to the user. On a third-party host, only the bound advisor issues ENDORSE / CORRECTION / PLAN / STOP.
31
31
 
@@ -49,7 +49,7 @@ Aim for two consults on a normal task: one after orientation and one after write
49
49
  - Bind at or above the protocol floor for this host.
50
50
  - The advisor only answers (messaging); the session runs tools and posts.
51
51
  - Keep an optional reference gap in the reference record: path, status, repair action, and repair result. A reference gap leaves bind status separate.
52
- - On Codex, select native Astra when its bind and reply validation pass. Record `selected_tier: Astra` and `reply_path: native`.
52
+ - On Codex, select native Astra when its bind and reply validation pass. Record `selected_tier: Astra` and `reply_path: native`, plus `advisor_flag: passed` or `advisor_flag: unavailable`.
53
53
  - Mark `fallback_kind: broken` only when the selected bind or reply path fails. Record the selected tier, fallback reason, and reply path in the same evidence object.
54
54
  - Record first, recovery, and completion consults with changed evidence, validation, unresolved risks, and report-back status.
55
55
  - Write the evidence object to the session-controlled `model-tier-run.json` record described in `advisor-tool.md`.
@@ -19,7 +19,7 @@ When both `codex` and `claude` tokens appear, Codex wins. Empty text is ThirdPar
19
19
 
20
20
  **Claude.** Spawn `subagent_type: session-advisor` at Fable through the Agent tool. When Fable is out of usage, bind Astra through the Codex helper if `ADVISOR_ASTRA` is on. Fail closed when neither binds.
21
21
 
22
- **Codex.** Spawn a native in-session Astra subagent at `resolve_codex_model_id("Astra")` (`gpt-6-astra`). Walk `candidate_tiers = ["Astra"]`. Record `{tier: "Astra", result: "spawned"}` on success. The `ADVISOR_ASTRA` flag is not required. Fail closed when Astra does not bind. Do not walk Fable on a Codex host.
22
+ **Codex.** Spawn a native in-session Astra subagent at `resolve_codex_model_id("Astra")` (`gpt-6-astra`). Walk `candidate_tiers = ["Astra"]`. When the spawn tool has a `flags` field, pass `flags: ["--advisor"]` and record `fallback.advisor_flag: "passed"`. When it has none, as in `codex exec`, spawn `gpt-6-astra` plainly and record `fallback.advisor_flag: "unavailable"`. Both count as a bind. Record `{tier: "Astra", result: "spawned"}` on success. The `ADVISOR_ASTRA` flag is not required. Fail closed when Astra does not bind, or when the spawn skips a flag the host offers. Do not walk Fable on a Codex host.
23
23
 
24
24
  **ThirdParty.** Bind Fable through the CLI Claude-chain. When Fable is out of usage, bind Astra through the Codex helper if `ADVISOR_ASTRA` is on. Fail closed when neither binds.
25
25
 
@@ -29,5 +29,5 @@ Exit code `1` means a ladder invariant failed.
29
29
  Exit code `2` means the path or JSON was unusable.
30
30
  The same checks are available in-process via `validate_model_tier_run(run)`.
31
31
 
32
- The validator checks ladder shape and validates `evidence` when it is present. On Claude and ThirdParty, Astra is attempted after Fable when `astra_enabled` is enabled, and `selected_tier: "Astra"` requires `result: "codex"`. On Codex, the walk is Astra only, and `result: "spawned"` or `result: "codex"` counts as success. A Codex success record uses `reply_path: "native"`.
32
+ The validator checks ladder shape and validates `evidence` when it is present. On Claude and ThirdParty, Astra is attempted after Fable when `astra_enabled` is enabled, and `selected_tier: "Astra"` requires `result: "codex"`. On Codex, the walk is Astra only, and `result: "spawned"` or `result: "codex"` counts as success. A Codex success record uses `reply_path: "native"` and `advisor_flag: "passed"` or `advisor_flag: "unavailable"`. A missing `advisor_flag` or `advisor_flag: "omitted"` fails validation.
33
33
  Host policy sits on top of it. See the Model floor section of the protocol.
@@ -31,7 +31,9 @@ The agent finishes its first turn standing by. `SendMessage` alone resumes it; b
31
31
  ## Codex host
32
32
 
33
33
  Spawn a native in-session Astra subagent at `resolve_codex_model_id("Astra")` (`gpt-6-astra`) with the charter as its prompt.
34
- Record `{tier: "Astra", result: "spawned"}` on success. Fail closed when that spawn does not bind.
34
+ When the spawn tool has a `flags` field, pass `flags: ["--advisor"]` and record `fallback.advisor_flag: "passed"`.
35
+ When the spawn tool has no `flags` field, as in `codex exec`, spawn `gpt-6-astra` plainly, record `fallback.advisor_flag: "unavailable"`, and treat the advisor as bound.
36
+ Record `{tier: "Astra", result: "spawned"}` on success. Fail closed when that spawn does not bind, or when it skips a flag the host offers.
35
37
  The `ADVISOR_ASTRA` flag is not required. Do not walk Fable. Consults stay in-session with that Astra subagent.
36
38
  Identity routing: [`identity.md`](identity.md).
37
39
 
@@ -105,3 +105,19 @@ CLI_SUCCESS_EXIT_CODE: int = 0
105
105
  ALL_ADVISOR_REPLY_PATHS: frozenset[str] = frozenset(
106
106
  {"native", "sendmessage", "cli", "codex", "none"}
107
107
  )
108
+ EVIDENCE_MUST_BE_OBJECT_MESSAGE: str = "evidence must be an object"
109
+ ADVISOR_FLAG_PASSED: str = "passed"
110
+ ADVISOR_FLAG_UNAVAILABLE: str = "unavailable"
111
+ ADVISOR_FLAG_OMITTED: str = "omitted"
112
+ ALL_ADVISOR_FLAG_STATES: frozenset[str] = frozenset(
113
+ {ADVISOR_FLAG_PASSED, ADVISOR_FLAG_UNAVAILABLE, ADVISOR_FLAG_OMITTED}
114
+ )
115
+ UNKNOWN_ADVISOR_FLAG_MESSAGE: str = (
116
+ "evidence.fallback.advisor_flag must be passed, unavailable, or omitted"
117
+ )
118
+ MISSING_ADVISOR_FLAG_MESSAGE: str = (
119
+ "Codex Astra success requires evidence.fallback.advisor_flag"
120
+ )
121
+ OMITTED_ADVISOR_FLAG_MESSAGE: str = (
122
+ "Codex Astra spawn skipped the --advisor flag the host offers"
123
+ )
@@ -67,6 +67,8 @@ from advisor_scripts_constants.astra_advisor_constants import (
67
67
  ASTRA_FALLBACK_KIND_DECLINED,
68
68
  )
69
69
  from advisor_scripts_constants.model_tier_run_validator_constants import (
70
+ ADVISOR_FLAG_OMITTED,
71
+ ALL_ADVISOR_FLAG_STATES,
70
72
  ALL_ADVISOR_REPLY_PATHS,
71
73
  ATTEMPT_ORDER_MISMATCH_MESSAGE,
72
74
  ATTEMPT_TIER_OUT_OF_SLICE_MESSAGE,
@@ -76,15 +78,19 @@ from advisor_scripts_constants.model_tier_run_validator_constants import (
76
78
  CLI_SUCCESS_EXIT_CODE,
77
79
  CLI_USAGE_MESSAGE,
78
80
  CLI_VALIDATION_FAILURE_EXIT_CODE,
81
+ EVIDENCE_MUST_BE_OBJECT_MESSAGE,
79
82
  HOST_PROFILE_CLAUDE,
80
83
  HOST_PROFILE_CODEX,
81
84
  HOST_PROFILE_JSON_KEY,
82
85
  HOST_PROFILE_MUST_BE_STRING_MESSAGE,
83
86
  INCOMPLETE_FALLBACK_WALK_MESSAGE,
87
+ MISSING_ADVISOR_FLAG_MESSAGE,
84
88
  MISSING_FALLBACK_REASON_MESSAGE,
89
+ OMITTED_ADVISOR_FLAG_MESSAGE,
85
90
  SELECTED_TIER_MISMATCH_MESSAGE,
86
91
  SELECTED_TIER_NOT_NULL_MESSAGE,
87
92
  THIRD_PARTY_MODEL_TIER,
93
+ UNKNOWN_ADVISOR_FLAG_MESSAGE,
88
94
  UNKNOWN_HOST_PROFILE_ERROR,
89
95
  UNKNOWN_OWN_TIER_MESSAGE,
90
96
  )
@@ -211,14 +217,26 @@ def _validate_fallback_reply_path(
211
217
  raise ModelTierRunError(
212
218
  "evidence.fallback.reply_path is not a known advisor path"
213
219
  )
214
- if (
220
+ is_codex_astra_success = (
215
221
  canonical_host_profile(run.host_profile) == HOST_PROFILE_CODEX
216
222
  and maybe_run_selected_tier == ADVISOR_MODEL_TIER
217
- and reply_path != "native"
218
- ):
223
+ )
224
+ if is_codex_astra_success and reply_path != "native":
219
225
  raise ModelTierRunError(
220
226
  "Codex Astra success requires the native reply path"
221
227
  )
228
+ raw_advisor_flag = fallback_by_name.get("advisor_flag")
229
+ if raw_advisor_flag is None:
230
+ if is_codex_astra_success:
231
+ raise ModelTierRunError(MISSING_ADVISOR_FLAG_MESSAGE)
232
+ return
233
+ if (
234
+ not isinstance(raw_advisor_flag, str)
235
+ or raw_advisor_flag not in ALL_ADVISOR_FLAG_STATES
236
+ ):
237
+ raise ModelTierRunError(UNKNOWN_ADVISOR_FLAG_MESSAGE)
238
+ if is_codex_astra_success and raw_advisor_flag == ADVISOR_FLAG_OMITTED:
239
+ raise ModelTierRunError(OMITTED_ADVISOR_FLAG_MESSAGE)
222
240
 
223
241
 
224
242
  def _validate_fallback_evidence(
@@ -242,7 +260,7 @@ def _validate_advisor_evidence(
242
260
  run: ModelTierRun,
243
261
  ) -> None:
244
262
  if not isinstance(evidence, Mapping):
245
- raise ModelTierRunError("evidence must be an object")
263
+ raise ModelTierRunError(EVIDENCE_MUST_BE_OBJECT_MESSAGE)
246
264
  raw_schema_version = evidence.get("schema_version")
247
265
  if isinstance(raw_schema_version, bool) or raw_schema_version != 1:
248
266
  raise ModelTierRunError("evidence.schema_version must be 1")
@@ -415,7 +433,7 @@ def load_model_tier_run_from_json_path(from_path: Path) -> ModelTierRun:
415
433
  raise TypeError(HOST_PROFILE_MUST_BE_STRING_MESSAGE)
416
434
  raw_evidence = parsed_payload.get("evidence")
417
435
  if raw_evidence is not None and not isinstance(raw_evidence, dict):
418
- raise TypeError("evidence must be an object")
436
+ raise TypeError(EVIDENCE_MUST_BE_OBJECT_MESSAGE)
419
437
  return ModelTierRun(
420
438
  own_tier=parsed_payload["own_tier"],
421
439
  candidate_tiers=list(parsed_payload["candidate_tiers"]),
@@ -35,13 +35,25 @@ load_model_tier_run_from_json_path = (
35
35
  )
36
36
  ADVISOR_MODEL_TIER = model_tier_run_validator.ADVISOR_MODEL_TIER
37
37
  CODEX_BIND_SUCCESS_TOKEN = model_tier_run_validator.CODEX_BIND_SUCCESS_TOKEN
38
+ EVIDENCE_MUST_BE_OBJECT_MESSAGE = (
39
+ model_tier_run_validator.EVIDENCE_MUST_BE_OBJECT_MESSAGE
40
+ )
38
41
 
39
42
 
40
43
  def _native_codex_evidence(
41
44
  *,
42
45
  reply_path: str = "native",
43
46
  reference_status: str = "missing",
47
+ advisor_flag: str | None = "passed",
44
48
  ) -> dict[str, object]:
49
+ fallback: dict[str, object] = {
50
+ "selected_tier": "Astra",
51
+ "fallback_kind": None,
52
+ "fallback_reason": None,
53
+ "reply_path": reply_path,
54
+ }
55
+ if advisor_flag is not None:
56
+ fallback["advisor_flag"] = advisor_flag
45
57
  return {
46
58
  "schema_version": 1,
47
59
  "reference": {
@@ -50,12 +62,7 @@ def _native_codex_evidence(
50
62
  "repair_action": "use the projected docs root",
51
63
  "repair_result": "read",
52
64
  },
53
- "fallback": {
54
- "selected_tier": "Astra",
55
- "fallback_kind": None,
56
- "fallback_reason": None,
57
- "reply_path": reply_path,
58
- },
65
+ "fallback": fallback,
59
66
  "consult": {
60
67
  "changed_evidence": ["native bind returned a reply"],
61
68
  "validation": ["signal and session id read back"],
@@ -93,6 +100,46 @@ def test_codex_native_success_rejects_non_native_reply_path() -> None:
93
100
  validate_model_tier_run(run)
94
101
 
95
102
 
103
+ def _codex_astra_success_run(evidence: dict[str, object]) -> ModelTierRun:
104
+ return ModelTierRun(
105
+ own_tier="Opus",
106
+ candidate_tiers=[ADVISOR_MODEL_TIER],
107
+ attempts=[{"tier": ADVISOR_MODEL_TIER, "result": "spawned"}],
108
+ selected_tier=ADVISOR_MODEL_TIER,
109
+ host_profile="Codex",
110
+ evidence=evidence,
111
+ )
112
+
113
+
114
+ def test_codex_plain_astra_spawn_binds_when_host_lacks_advisor_flag() -> None:
115
+ run = _codex_astra_success_run(
116
+ _native_codex_evidence(advisor_flag="unavailable")
117
+ )
118
+
119
+ assert validate_model_tier_run(run) is None
120
+
121
+
122
+ def test_codex_astra_spawn_that_skips_offered_advisor_flag_fails_closed() -> None:
123
+ run = _codex_astra_success_run(_native_codex_evidence(advisor_flag="omitted"))
124
+
125
+ with pytest.raises(ModelTierRunError, match="--advisor"):
126
+ validate_model_tier_run(run)
127
+
128
+
129
+ def test_codex_astra_success_without_advisor_flag_record_fails_closed() -> None:
130
+ run = _codex_astra_success_run(_native_codex_evidence(advisor_flag=None))
131
+
132
+ with pytest.raises(ModelTierRunError, match="advisor_flag"):
133
+ validate_model_tier_run(run)
134
+
135
+
136
+ def test_unknown_advisor_flag_state_is_rejected() -> None:
137
+ run = _codex_astra_success_run(_native_codex_evidence(advisor_flag="skipped"))
138
+
139
+ with pytest.raises(ModelTierRunError, match="advisor_flag"):
140
+ validate_model_tier_run(run)
141
+
142
+
96
143
  def test_broken_bind_keeps_fallback_evidence_separate_from_reference_gap() -> None:
97
144
  evidence = _native_codex_evidence()
98
145
  evidence["fallback"] = {
@@ -136,6 +183,38 @@ def test_cli_reads_versioned_advisor_evidence(tmp_path: Path) -> None:
136
183
  assert loaded_run.evidence["consult"]["report_back_status"] == "recorded"
137
184
 
138
185
 
186
+ def test_non_object_evidence_reports_the_same_message_at_validate_and_load(
187
+ tmp_path: Path,
188
+ ) -> None:
189
+ run = ModelTierRun(
190
+ own_tier="Opus",
191
+ candidate_tiers=[ADVISOR_MODEL_TIER],
192
+ attempts=[{"tier": ADVISOR_MODEL_TIER, "result": "spawned"}],
193
+ selected_tier=ADVISOR_MODEL_TIER,
194
+ host_profile="Codex",
195
+ evidence=["not", "an", "object"],
196
+ )
197
+ with pytest.raises(ModelTierRunError, match=EVIDENCE_MUST_BE_OBJECT_MESSAGE):
198
+ validate_model_tier_run(run)
199
+
200
+ log_path = tmp_path / "model-tier-run.json"
201
+ log_path.write_text(
202
+ json.dumps(
203
+ {
204
+ "own_tier": "Opus",
205
+ "candidate_tiers": [ADVISOR_MODEL_TIER],
206
+ "attempts": [{"tier": ADVISOR_MODEL_TIER, "result": "spawned"}],
207
+ "selected_tier": ADVISOR_MODEL_TIER,
208
+ "host_profile": "Codex",
209
+ "evidence": "not an object",
210
+ }
211
+ ),
212
+ encoding="utf-8",
213
+ )
214
+ with pytest.raises(TypeError, match=EVIDENCE_MUST_BE_OBJECT_MESSAGE):
215
+ load_model_tier_run_from_json_path(from_path=log_path)
216
+
217
+
139
218
  def test_clean_single_spawn_at_top_of_slice_passes() -> None:
140
219
  run = ModelTierRun(
141
220
  own_tier="Opus",
@@ -175,9 +175,7 @@ def _collect_introduced_identifiers(
175
175
  """
176
176
  all_identifier_tuples: set[IdentifierTuple] = set()
177
177
  for each_file_path, _, each_text in all_added_lines:
178
- if _file_extension(
179
- each_file_path
180
- ) in ALL_SWEEP_CODE_FILE_EXTENSIONS and not _is_test_file(each_file_path):
178
+ if _is_swept_non_test_code_file(each_file_path):
181
179
  all_identifier_tuples.update(_identifier_tuples_in_text(each_text))
182
180
  return frozenset(all_identifier_tuples)
183
181
 
@@ -301,6 +299,13 @@ def _is_test_file(file_path: str) -> bool:
301
299
  )
302
300
 
303
301
 
302
+ def _is_swept_non_test_code_file(file_path: str) -> bool:
303
+ """Return whether a diff path names a swept code file outside a test module."""
304
+ return _file_extension(
305
+ file_path
306
+ ) in ALL_SWEEP_CODE_FILE_EXTENSIONS and not _is_test_file(file_path)
307
+
308
+
304
309
  def _comment_fragments(line_text: str) -> list[str]:
305
310
  """Return the comment tail of a code line, or an empty list when absent."""
306
311
  all_fragments: list[str] = []
@@ -616,9 +621,7 @@ def _stem_identifier_tuple_for_code_file(each_file_path: str) -> IdentifierTuple
616
621
  ``None`` when the path is not a swept code file, is a test file, or its
617
622
  stem carries fewer than the minimum identifier token count.
618
623
  """
619
- if _file_extension(each_file_path) not in ALL_SWEEP_CODE_FILE_EXTENSIONS or _is_test_file(
620
- each_file_path
621
- ):
624
+ if not _is_swept_non_test_code_file(each_file_path):
622
625
  return None
623
626
  stem_tuple = _identifier_token_tuple(Path(each_file_path).stem)
624
627
  if len(stem_tuple) < MINIMUM_IDENTIFIER_TOKEN_COUNT:
@@ -747,9 +750,7 @@ def _identifier_names_on_added_code_lines(diff_text: str) -> frozenset[str]:
747
750
  """
748
751
  all_names: set[str] = set()
749
752
  for each_file_path, _, each_text in _parse_added_lines(diff_text):
750
- if _file_extension(
751
- each_file_path
752
- ) not in ALL_SWEEP_CODE_FILE_EXTENSIONS or _is_test_file(each_file_path):
753
+ if not _is_swept_non_test_code_file(each_file_path):
753
754
  continue
754
755
  all_found_names = SNAKE_CASE_IDENTIFIER_PATTERN.findall(each_text)
755
756
  all_found_names += CAMEL_CASE_IDENTIFIER_PATTERN.findall(each_text)
@@ -759,3 +759,16 @@ def test_flags_near_miss_when_second_leading_token_is_plural_variant() -> None:
759
759
  findings = sweep_diff(diff)
760
760
  assert len(findings) == 1
761
761
  assert "retry policies limit" in findings[0]
762
+
763
+
764
+ def test_a_swept_code_file_outside_the_test_modules_reads_as_swept() -> None:
765
+ assert sweep_module._is_swept_non_test_code_file("api/store.py") is True
766
+
767
+
768
+ def test_a_test_module_does_not_read_as_a_swept_code_file() -> None:
769
+ assert sweep_module._is_swept_non_test_code_file("api/test_store.py") is False
770
+ assert sweep_module._is_swept_non_test_code_file("api/tests/store.py") is False
771
+
772
+
773
+ def test_a_markdown_document_does_not_read_as_a_swept_code_file() -> None:
774
+ assert sweep_module._is_swept_non_test_code_file("docs/README.md") is False
@@ -2928,6 +2928,31 @@ test('retired skills leave install groups and stay in the cleanup registry', ()
2928
2928
  }
2929
2929
  });
2930
2930
 
2931
+ test('the README agents section names the shipped agent, not archived personal agents', () => {
2932
+ const readme = readFileSync(new URL('../../../README.md', import.meta.url), 'utf8');
2933
+ const agentsSection = readme.slice(
2934
+ readme.indexOf('### Agents'),
2935
+ readme.indexOf('### Commands'),
2936
+ );
2937
+ assert.match(agentsSection, /`poteto-agent`/);
2938
+ for (const archivedAgentName of [
2939
+ 'clean-coder',
2940
+ 'code-quality-agent',
2941
+ 'git-commit-crafter',
2942
+ 'issue-tracker',
2943
+ 'plan-packet-validator',
2944
+ 'pr-description-writer',
2945
+ 'session-advisor',
2946
+ 'skill-writer-agent',
2947
+ ]) {
2948
+ assert.equal(
2949
+ agentsSection.includes(`\`${archivedAgentName}\``),
2950
+ false,
2951
+ `${archivedAgentName} is archived and should not appear as a shipped agent`,
2952
+ );
2953
+ }
2954
+ });
2955
+
2931
2956
  test('the README names current session tools', () => {
2932
2957
  const readme = readFileSync(new URL('../../../README.md', import.meta.url), 'utf8');
2933
2958
  assert.doesNotMatch(readme, /--only journal|session-log|session-tidy/);
@@ -0,0 +1,132 @@
1
+ # Building a high trust system for agent driven software delivery
2
+
3
+ Source: https://x.com/poteto/status/2102050467505430555/video/1
4
+
5
+ This document carries the model behind [`rules/correction-lens.md`](../rules/correction-lens.md).
6
+
7
+ ## The central idea
8
+
9
+ Lauren's 2,000 pull requests came after she built a system that let agents do useful work while she was away.
10
+
11
+ The system had several parts. The codebase showed agents the preferred patterns. Tools let agents run the product and gather evidence. Continuous integration, or CI, checked every proposed change. Rules and review bots caught repeated mistakes. Skills taught agents how to perform work in the team's preferred way. Automations connected incoming problems to agents that could investigate them.
12
+
13
+ These parts created trust over time. An agent earned more freedom by showing that it could make a change, check the result, respond to failures, and open a pull request that met the repository's standards.
14
+
15
+ The goal for a repository is clear. An agent should be able to take a task through the full path to a pull request. The repository should provide enough evidence for a merge decision without requiring a person to inspect every changed line.
16
+
17
+ ## Why high volume exposes weak systems
18
+
19
+ When people first work with agents, they often watch every conversation. They correct the agent's approach, stop mistakes, and supply missing context. That works for a small number of tasks. It breaks when many agents work at the same time.
20
+
21
+ A large group of agents multiplies whatever the repository already permits. If the checks are weak, the team receives many noisy pull requests. Regressions and bugs spread faster. The team spends its time repairing agent output, and the product waits.
22
+
23
+ The answer is to build trust before adding more agents. Start with a small workflow that an agent can repeat. Watch the failures. Turn each repeated correction into a stronger control. Increase the number of agents after the controls catch the common mistakes.
24
+
25
+ The high pull request count is the result of this work. The first target is a system that can check changes without waiting for one person.
26
+
27
+ ## Verification gives the agent evidence
28
+
29
+ Verification asks whether the code does what the feature needs. A checkout button should complete a checkout. A changed screen should respond to the user's action. A performance change should meet a measured limit.
30
+
31
+ Teach the agent how to start the product, reach a feature, perform the relevant action, and inspect the result. The agent can collect a browser trace, a memory snapshot, a test result, or a performance measurement. The evidence should come from a repeatable procedure.
32
+
33
+ A useful verification setup has two parts. The first is a command line tool that runs the product and collects the required evidence. The second is a feature map that explains how the product works.
34
+
35
+ The command line tool gives every agent session the same procedure. Agents do not invent a new test script for every task. The tool supplies the commands, inputs, and output format. Invest in the important product paths so the tool can handle the work agents perform often.
36
+
37
+ The feature map gives the agent context that a short bug report often lacks. It describes the product's features, the paths a user takes to reach them, the controls that matter, and the expected result. Keep the map with the repository and maintain it as the product changes.
38
+
39
+ The tool and the map work together. The agent can reproduce a report, inspect the product, collect evidence, and explain the result. This turns verification into a shared team capability.
40
+
41
+ Verification does not answer every quality question. It shows that the feature works during the check. It does not by itself show that the code is easy to maintain, that the performance will stay within limits, or that the change follows the team's design rules.
42
+
43
+ Add skills for those questions. A skill can teach an agent how to debug, develop a feature, refactor code, inspect performance, or review a change. Keep the skills in a shared repository. Combine them with verification so the agent can check behavior and code quality.
44
+
45
+ Measured data makes this process stronger. Performance numbers, memory measurements, error counts, and test results give the agent something to inspect. The agent can respond to a number more reliably than to a vague instruction such as "make this faster."
46
+
47
+ ## The codebase is part of the control system
48
+
49
+ Agents extend the patterns they find in the files they read. The codebase becomes working memory for the agent. An agent usually adapts an existing structure to a new task. It rarely redesigns the whole system during each pull request.
50
+
51
+ This gives the codebase a direct effect on future changes. One clear pattern reduces guessing. Several conflicting patterns force the agent to choose. The repository should make the safe choice easy to find and easy to repeat.
52
+
53
+ Start with the code structure. Change the design so that a bad pattern cannot be expressed, or so that the preferred pattern is the easiest path. Good data structures and clear boundaries can remove entire classes of errors.
54
+
55
+ Make each feature easy to locate. Define where its code lives. Define how it connects to other parts of the product. Define which parts may import each other. A clear layout gives the agent a smaller search space and fewer decisions.
56
+
57
+ The framework Lauren describes follows this idea. It sets conventions for code location and dependency boundaries. A performance problem caused by code crossing into the wrong process can become impossible through import rules. The method carries. Put team knowledge into code structure so agents find it while they work.
58
+
59
+ Strict conventions may feel inconvenient to people who already know the system. They help agents and new contributors because the repository answers more questions by itself. A designer, product manager, or busy engineer can ask an agent to make a change and still benefit from the same safe paths.
60
+
61
+ ## Build controls in layers
62
+
63
+ The controls work best in a clear order. Each layer handles a different kind of mistake.
64
+
65
+ First, make the mistake impossible through the code structure, architecture, or data model. This is the strongest control because the agent cannot choose the bad pattern.
66
+
67
+ Second, add static checks. Linters, compiler diagnostics, type checks, and CI inspect every proposed change. Continuous integration means that the repository runs the required checks for each pull request. When an agent repeats a mistake, turn the mistake into a check that runs every time.
68
+
69
+ Third, add rules, automated review, and skills. These explain how the team wants work done. They help with decisions that are difficult to encode in code or static checks. A rule can describe a preferred pattern. A review bot can point out a problem. A skill can give the agent a repeatable procedure.
70
+
71
+ Fourth, keep human review for judgment that the lower layers cannot express. People can decide whether a change fits the product, whether the design is sound, or whether a tradeoff is acceptable. People should not spend every review repeating the same correction that a check could catch.
72
+
73
+ Every repeated review comment is evidence that a lower layer needs improvement. Move that lesson into the code structure, a static check, CI, an automated review, or a skill. This gives the next agent the lesson without requiring a person to repeat it.
74
+
75
+ ## Turn corrections into repository improvements
76
+
77
+ An agent correction should change the system when the same mistake can happen again. Fixing one pull request removes one symptom. Adding a control protects later pull requests.
78
+
79
+ Suppose an agent copies a workaround. Remove the workaround where possible. Add a rule that prevents new copies. Add a skill that explains the preferred solution. Ask an agent to clean the old copies so the repository presents better examples.
80
+
81
+ Lauren gives comments as one example. Comments can explain an edge case or a temporary workaround. In the Cursor codebase, agents began using comments as permission to keep workarounds, and the underlying problem stayed. The team chose to ban comments in Dune so agents would stop copying that pattern.
82
+
83
+ The same reasoning applies to any pattern that creates poor code. When a pattern keeps appearing, decide which control should own the correction. Put the knowledge in the repository, where every later session reads it.
84
+
85
+ This maintenance role is like gardening. Someone needs to look for small workarounds, weak patterns, and new code debt before they spread. That person removes old debt, keeps one conventional path for common work, and adds a check when a bad pattern appears.
86
+
87
+ The standard is simple. Keep the repository in a state that you would want an agent to copy. Every example teaches the next agent what to do.
88
+
89
+ ## The inner delivery loop
90
+
91
+ The inner loop is the path from a task to a pull request. A dependable repository gives the agent a repeatable sequence.
92
+
93
+ 1. The agent receives a task with enough context to identify the relevant feature and code.
94
+ 2. The agent makes the smallest change that solves the task.
95
+ 3. The agent runs the product or the relevant tests through the shared verification tools.
96
+ 4. The agent collects evidence about behavior, performance, and other required limits.
97
+ 5. CI, static checks, repository rules, and automated review inspect the change.
98
+ 6. The agent responds to failures, repairs the change, and runs the checks again.
99
+ 7. The agent opens or updates the pull request with the evidence.
100
+ 8. The repository grants merge permission after the required checks pass and the remaining judgment calls are settled.
101
+
102
+ The agent earns freedom through this loop. The system depends on the agent producing evidence that the repository can inspect.
103
+
104
+ ## The outer delivery loop
105
+
106
+ Work can begin outside the code editor. A message, error report, performance alert, or product signal can start the next task.
107
+
108
+ Connect an agent to the tools that hold this information. The talk mentions Slack, an error tracker, performance data, and a database service. The exact tools depend on the repository. The important point is that the agent can gather enough context to decide what happened and what task should follow.
109
+
110
+ A routine can watch a message or an alert and start an agent. The agent can reproduce the problem, make a change, run the checks, and open a pull request. Other bots can call the same verification tools, repository rules, and skills for more complex work.
111
+
112
+ A set of small connections can start useful work. The repository supplies the controls. The agent calls the tools. CI and review inspect the result.
113
+
114
+ ## How the pieces compound
115
+
116
+ Each control improves the next one. A clear code pattern gives the agent a safe starting point. The verification tool gives it product evidence. CI catches repeatable mistakes. Automated review finds code quality problems. Skills give the agent procedures for work that needs more judgment. The outer loop supplies new tasks.
117
+
118
+ Together, these controls let many agents work in parallel. The agents do not need a person to approve every small action because the environment checks the work. People can focus on product decisions, system design, and questions that the checks cannot settle.
119
+
120
+ The result is a repository where an agent with limited context can still make a good change. The environment carries the team's knowledge. The agent follows the safe paths. The pull request provides evidence for its merge decision.
121
+
122
+ ## A practical way to apply the model
123
+
124
+ Start with one recurring task. Give an agent a fixed way to run the relevant part of the product and collect evidence. Record the expected result. Run the same procedure for several changes and study the failures.
125
+
126
+ When a failure repeats, ask where the correction belongs. Change the code structure if the pattern can be removed. Add a static check or CI step if the problem can be detected. Add a rule, review bot, or skill when the decision needs guidance. Improve human review when the question still needs judgment.
127
+
128
+ Keep the codebase clean as the agent population grows. Remove workarounds. Reduce competing patterns. Add one clear path for common work. Maintain the feature map and verification tools as part of the repository.
129
+
130
+ Then connect incoming signals to the same workflow. Let an agent start from a bug report or alert, reproduce the problem, make the change, run the checks, and open the pull request. Increase parallel work after the system can catch the mistakes that matter.
131
+
132
+ The key lesson is to move knowledge out of individual conversations and into the environment. A person teaches the system once. The repository, checks, tools, and skills carry that lesson into every later pull request.
@@ -40,7 +40,7 @@ Work a disagreement in this order: keep the observed evidence in the record, nam
40
40
 
41
41
  ## Recovery record
42
42
 
43
- Keep one versioned `evidence` object in the session-controlled `model-tier-run.json` record. A missing optional reference belongs in `reference.status`; it keeps the bind result independent. `fallback_kind: "broken"` identifies a bind or reply failure. On a Codex host, a successful native route records `selected_tier: "Astra"` and `reply_path: "native"`.
43
+ Keep one versioned `evidence` object in the session-controlled `model-tier-run.json` record. A missing optional reference belongs in `reference.status`; it keeps the bind result independent. `fallback_kind: "broken"` identifies a bind or reply failure. On a Codex host, a successful native route records `selected_tier: "Astra"`, `reply_path: "native"`, and `advisor_flag`. The value is `"passed"` when the spawn tool offers the `--advisor` flag and the spawn passed it, or `"unavailable"` when the spawn tool has no flag field. `"omitted"` fails the bind.
44
44
 
45
45
  ```json
46
46
  {
@@ -56,7 +56,8 @@ Keep one versioned `evidence` object in the session-controlled `model-tier-run.j
56
56
  "selected_tier": "Astra",
57
57
  "fallback_kind": null,
58
58
  "fallback_reason": null,
59
- "reply_path": "native"
59
+ "reply_path": "native",
60
+ "advisor_flag": "passed"
60
61
  },
61
62
  "consult": {
62
63
  "changed_evidence": ["native bind returned a reply"],
@@ -0,0 +1,50 @@
1
+ # Second Claude account
2
+
3
+ A second Claude subscription runs agents on the same machine as the main one. It
4
+ shares every skill, rule, plugin, setting and doc in the main Claude home, and it
5
+ keeps its own sign-in and history.
6
+
7
+ ## Pieces
8
+
9
+ | File | What it does |
10
+ |---|---|
11
+ | `scripts/claude_account_profile.py` | Links each shared entry of `~/.claude` into the profile `~/.claude-profiles/ev`, moves stale copies into `.replaced/<time>/`, and writes the `claude-ev.cmd` launcher into `~/.local/bin` |
12
+ | `scripts/claude_account_choice.py` | Reads both accounts' 5-hour and weekly meters and prints which account a job runs on |
13
+ | `scripts/dev_env_scripts_constants/claude_account_constants.py` | The profile name, the entries that stay per account, and the picker thresholds |
14
+
15
+ The launcher sets `CLAUDE_CONFIG_DIR` to the profile and passes every argument to
16
+ `claude`, so `claude-ev -p "..."` runs like `claude -p "..."` on the second
17
+ account.
18
+
19
+ These entries stay per account and are never linked: `.credentials.json` and
20
+ `.claude.json` with their backups, `projects`, `sessions`, `todos`, `history.jsonl`,
21
+ and the other state folders named in the constants file.
22
+
23
+ ## Sign in once
24
+
25
+ ```
26
+ python packages/claude-dev-env/scripts/claude_account_profile.py
27
+ claude-ev auth login
28
+ ```
29
+
30
+ The sign-in lives in `~/.claude-profiles/ev/.credentials.json` on that machine.
31
+ Claude refreshes it on each run.
32
+
33
+ ## Which account a job uses
34
+
35
+ The main account belongs to the person who works on it, so a job borrows it only
36
+ to spend leftover usage that expires soon.
37
+
38
+ | Condition | Account |
39
+ |---|---|
40
+ | Main week resets within 24 hours, main under 90% of its week, main under 50% of its 5-hour window | main |
41
+ | Otherwise, second under 95% of its week and under 90% of its 5-hour window | second |
42
+ | Second meter unreadable | second, whose own run refreshes the sign-in |
43
+ | Otherwise | wait, with the next reset time |
44
+
45
+ An unreadable main meter never picks main.
46
+
47
+ ```
48
+ python packages/claude-dev-env/scripts/claude_account_choice.py
49
+ {"account": "second", "config_dir": "C:\\Users\\me\\.claude-profiles\\ev", "reason": "..."}
50
+ ```
@@ -23,14 +23,14 @@ try:
23
23
  sys.path.insert(0, hooks_root_directory)
24
24
 
25
25
  from hooks_constants.multi_edit_reconstruction import edits_for_tool
26
- from hooks_constants.precommit_code_rules_gate_constants import GIT_COMMAND_TIMEOUT_SECONDS
27
26
  from hooks_constants.refactor_guard_constants import (
28
27
  ALL_PYTHON_KEYWORDS,
29
28
  CHANGED_SURFACE_MATCH_RATIO,
29
+ GIT_COMMAND_TIMEOUT_SECONDS,
30
+ GIT_EXECUTABLE_TOKEN,
30
31
  MAXIMUM_REFACTOR_LINE_DELTA,
31
32
  REFACTOR_LINE_DELTA_DIVISOR,
32
33
  )
33
- from hooks_constants.session_edit_stage_gate_constants import GIT_EXECUTABLE_TOKEN
34
34
  except ImportError as import_error:
35
35
  raise ImportError(
36
36
  "refactor_guard: cannot import its sibling modules; "
@@ -125,3 +125,24 @@ def test_untracked_probe_should_start_without_a_console_window(
125
125
 
126
126
  assert refactor_guard.is_new_file(str(tmp_path / "module.py")) is True
127
127
  assert all_recorded_keyword_arguments["creationflags"] == EXPECTED_HIDDEN_WINDOW_FLAGS
128
+
129
+
130
+ def test_the_git_query_carries_the_advisory_s_own_executable_and_timeout(
131
+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch
132
+ ) -> None:
133
+ """refactor_guard_constants supplies both names the git call is built from."""
134
+ all_calls: list[tuple[list[str], object]] = []
135
+
136
+ def record_call(
137
+ command: list[str], **keyword_arguments: object
138
+ ) -> subprocess.CompletedProcess[str]:
139
+ all_calls.append((command, keyword_arguments["timeout"]))
140
+ return subprocess.CompletedProcess(command, 1, "", "")
141
+
142
+ monkeypatch.setattr(refactor_guard.subprocess, "run", record_call)
143
+
144
+ refactor_guard.is_new_file(str(tmp_path / "module.py"))
145
+
146
+ command, timeout = all_calls[0]
147
+ assert command[:2] == ["git", "ls-files"]
148
+ assert timeout == refactor_guard.GIT_COMMAND_TIMEOUT_SECONDS