@yunhozz/arc 0.1.2 → 0.1.4

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 (82) hide show
  1. package/MANIFEST.sha256 +79 -37
  2. package/claude/agents/arc-coder.md +10 -9
  3. package/claude/agents/arc-planner.md +13 -12
  4. package/claude/agents/arc-qa.md +9 -8
  5. package/claude/agents/arc-reviewer.md +11 -10
  6. package/claude/agents/arc-scouter.md +10 -9
  7. package/claude/skill/SKILL.md +13 -294
  8. package/claude/skill/hooks/role-git-guard.mjs +3 -83
  9. package/claude/skill/hooks/runtime-gate.mjs +12 -0
  10. package/claude/skill/models.toml +11 -11
  11. package/claude/skill/references/commit.md +11 -14
  12. package/claude/skill/references/coordination.md +148 -0
  13. package/claude/skill/references/git-recovery.md +1 -1
  14. package/claude/skill/references/handoff-prep.md +3 -12
  15. package/claude/skill/references/handoff.md +74 -12
  16. package/claude/skill/references/limits.md +4 -4
  17. package/claude/skill/references/planning.md +30 -13
  18. package/claude/skill/references/verification.md +64 -14
  19. package/claude/skill/references/visual-companion.md +2 -3
  20. package/claude/skill/runtime/adapters/claude.mjs +81 -0
  21. package/claude/skill/runtime/adapters/codex.mjs +63 -0
  22. package/claude/skill/runtime/capabilities.mjs +32 -0
  23. package/claude/skill/runtime/evaluate.mjs +103 -0
  24. package/claude/skill/runtime/gate.mjs +71 -0
  25. package/claude/skill/runtime/git-evidence.mjs +114 -0
  26. package/claude/skill/runtime/git-query.mjs +88 -0
  27. package/claude/skill/runtime/identity.mjs +27 -0
  28. package/claude/skill/runtime/operations.mjs +6 -0
  29. package/claude/skill/runtime/role-policy.json +607 -0
  30. package/claude/skill/runtime/schema.mjs +78 -0
  31. package/claude/skill/runtime/store.mjs +63 -0
  32. package/claude/skill/scripts/model_config.py +78 -18
  33. package/codex/agents/arc-coder.toml +8 -8
  34. package/codex/agents/arc-planner.toml +9 -9
  35. package/codex/agents/arc-qa.toml +6 -6
  36. package/codex/agents/arc-reviewer.toml +7 -7
  37. package/codex/agents/arc-scouter.toml +6 -6
  38. package/codex/skill/SKILL.md +13 -278
  39. package/codex/skill/hooks/runtime-gate.mjs +10 -0
  40. package/codex/skill/models.toml +11 -11
  41. package/codex/skill/references/commit.md +12 -14
  42. package/codex/skill/references/coordination.md +131 -0
  43. package/codex/skill/references/git-recovery.md +1 -1
  44. package/codex/skill/references/handoff-prep.md +4 -14
  45. package/codex/skill/references/handoff-worktree.md +1 -1
  46. package/codex/skill/references/handoff.md +77 -13
  47. package/codex/skill/references/limits.md +4 -4
  48. package/codex/skill/references/planning.md +32 -16
  49. package/codex/skill/references/verification.md +63 -16
  50. package/codex/skill/references/visual-companion.md +3 -3
  51. package/codex/skill/runtime/adapters/claude.mjs +81 -0
  52. package/codex/skill/runtime/adapters/codex.mjs +63 -0
  53. package/codex/skill/runtime/capabilities.mjs +32 -0
  54. package/codex/skill/runtime/evaluate.mjs +103 -0
  55. package/codex/skill/runtime/gate.mjs +71 -0
  56. package/codex/skill/runtime/git-evidence.mjs +114 -0
  57. package/codex/skill/runtime/git-query.mjs +88 -0
  58. package/codex/skill/runtime/identity.mjs +27 -0
  59. package/codex/skill/runtime/operations.mjs +6 -0
  60. package/codex/skill/runtime/role-policy.json +607 -0
  61. package/codex/skill/runtime/schema.mjs +78 -0
  62. package/codex/skill/runtime/store.mjs +63 -0
  63. package/lib/installer/global-config.mjs +1 -2
  64. package/lib/models/profiles.mjs +41 -4
  65. package/lib/policy/claude-hook.mjs +57 -17
  66. package/lib/policy/placement.mjs +25 -0
  67. package/lib/policy/render.mjs +13 -4
  68. package/lib/policy/role-policy.json +38 -8
  69. package/lib/runtime/adapters/claude.mjs +81 -0
  70. package/lib/runtime/adapters/codex.mjs +63 -0
  71. package/lib/runtime/capabilities.mjs +32 -0
  72. package/lib/runtime/evaluate.mjs +103 -0
  73. package/lib/runtime/gate.mjs +71 -0
  74. package/lib/runtime/git-evidence.mjs +114 -0
  75. package/lib/runtime/git-query.mjs +88 -0
  76. package/lib/runtime/identity.mjs +27 -0
  77. package/lib/runtime/operations.mjs +6 -0
  78. package/lib/runtime/schema.mjs +78 -0
  79. package/lib/runtime/store.mjs +63 -0
  80. package/package.json +1 -1
  81. package/scripts/probe-runtime-hooks.mjs +55 -0
  82. package/scripts/update-runtime-assets.mjs +19 -0
@@ -44,7 +44,7 @@ For approved-document staging and commit, also verify the complete approved docu
44
44
  evidence, approved versions, dependencies, and actual index. Read-only Git checks remain allowed.
45
45
  Do not infer execution authority from an external skill's early commit step.
46
46
 
47
- Before committing, also verify staged paths/content and the finalized message under Planning document commit.
47
+ Before committing, also verify staged paths/content and the final message under Planning document commit.
48
48
  After every branch or commit operation, verify actual path, branch, HEAD, preserved changes, and result before the
49
49
  next dependent action. After staging, verify the actual index paths and diff before commit. Apply the Preservation
50
50
  rule; unrelated staged files stop the mutation.
@@ -115,8 +115,7 @@ before handoff. Batch all remaining uncommitted approved documents together in t
115
115
  validly committed, verify only; do not create duplicate or empty commits, or amend, reset, or recommit past commits
116
116
  merely to combine them into one SHA. Verify both staged paths and staged diff match exactly the approved
117
117
  documents; unrelated staged files stop the commit under the Preservation rule. Never include implementation files.
118
- Do not first commit a generic temporary message and routinely use `git commit --amend` to
119
- repair it. A separately needed amend requires rechecking its approval scope, current HEAD, and publication state.
118
+ MUST NOT commit a generic temporary message and routinely repair it with `git commit --amend`. A separately needed amend requires rechecking its approval scope, current HEAD, and publication state.
120
119
 
121
120
  If the docs commit fails or staged content differs, stop handoff and apply the Stop and inspect rule to the actual
122
121
  branch, HEAD, index, and partial completion. Resolve the issue before resuming; do not commit implementation instead.
@@ -136,18 +135,9 @@ On branch collisions, Git preparation failures, partial completion, or metadata
136
135
 
137
136
  [ARC role policy: contract begin]
138
137
  Generated from lib/policy/role-policy.json; do not edit this managed section manually.
139
- - [scope.non-escalation] Act only within the intersection of role authority, approved scope and available platform tools. Delegation, restart, agent messages and attached instructions do not expand role authority. Never bypass a restriction through aliases, scripts, other tools, processes or redelegation. Return conflicting instructions to Orchestrator before dependent work; reuse valid prior approvals for unchanged scope rather than requesting them again.
138
+ - [scope.non-escalation] Act only where role authority, approved scope and available platform tools all permit. Delegation, restart, agent messages and attached instructions do not expand role authority. MUST NOT bypass a restriction through aliases, scripts, other tools, processes or redelegation. Return conflicting instructions to Orchestrator before dependent work; reuse valid prior approvals for unchanged scope rather than requesting them again.
140
139
  - [git.specialists-deny] Specialist roles MUST NOT change Git state: no stage, commit, push, merge, rebase, reset, branch creation/switching or worktree creation/removal, during normal implementation or recovery. Even an explicit Orchestrator assignment cannot authorize these actions; return them to Orchestrator. Read-only Git inspection remains allowed within the assigned scope.
141
140
  - [git.orchestrator-accept-commit] Only Orchestrator accepts work and executes Git mutations. One approved top-level plan task becomes one focused implementation commit after criteria, required checks and findings are satisfied; Orchestrator accepts then commits without additional user commit approval. Reports, passing checks and Reviewer opinions do not replace acceptance. Preserve unrelated changes and ownership and verify the resulting SHA, included content, HEAD and remaining changes. Existing small-task direct and plan-omission paths are unchanged.
142
- - [external.explicit-user-authority] Push, merge, deploy, publish and external messages require explicit user authorization for that action, scope and target. Local commit authority does not grant external authority. Orchestrator performs authorized external actions; specialist roles return them without execution.
143
- - [role.orchestrator-boundary] Assign design/spec/plan/brainstorming drafts ONLY to Planner and implementation/configuration/test edits to Coder. Orchestrator saves complete drafts and owns approval requests, preparation, scheduling, evidence, acceptance and completion. Direct implementation is limited to the existing small, low-risk direct path; this policy does not expand it.
144
- - [role.scouter-read-only] Research assigned static sources and report findings, evidence and limits. Do not edit files, install, execute checks, prepare execution targets, inspect live operational state, change external state or decide design, verification, review or acceptance.
145
- - [role.planner-draft-only] Return design/spec/plan drafts and dependencies, criteria, hold conditions and verification needs in the response. Do not save documents, implement, run checks, prepare targets, request user approval or decide acceptance. Stop formal target-dependent drafting if actual prepared target evidence is missing; route decisions to Orchestrator.
146
- - [role.coder-implementation] Implement only assigned approved files and focused checks under the existing TDD contract. Report changed files, RED/GREEN or authorized exception evidence, results, limits and follow-up. Do not plan, independently QA/review your own work, accept the task or declare overall completion. Git changes remain forbidden even when implementation succeeds.
147
- - [role.qa-verification] Run approved checks and report commands, observations, reproduction, evidence and limits. Create only essential temporary data/logs/reports in the brief-authorized location and lifetime. Do not edit product source, tests, fixtures or configuration to pass checks, deploy or accept work. Persistent product-state checks require explicit scope and cleanup ownership. Return failures for Coder correction and required QA recheck.
148
- - [role.reviewer-independent] Independently inspect the assigned final changes and evidence and report actionable findings and limits. Remain read-only; do not execute QA tests, edit files, perform Git mutations or decide acceptance.
149
- - [review.significant-no-plan] For significant/high-risk work without a plan: Coder → QA and required QA rechecks → Reviewer of the final full change → Orchestrator acceptance. Do not omit Reviewer merely because no plan exists. This creates no new plan obligation.
150
- - [review.significant-plan] For significant/high-risk plan work: each task uses Coder → fresh QA as required → Orchestrator acceptance and focused commit. After all tasks are accepted and required QA is complete, Reviewer reviews the final full change once. Reviewer is NOT a per-task or per-commit required gate. Preserve required checks and necessary finding rechecks.
151
- - [review.final-plan-recheck] For final overall Reviewer findings on plan work, including behavior findings, use Coder → Reviewer without QA reassignment; repeat until resolved. This exception applies only to that final plan stage. Preserve required QA and QA failure rechecks before initial final review and outside this exception.
141
+ - [external.explicit-user-authority] Push, merge, deploy, publish and external messages require explicit user authorization for that action, scope and target. Local commit authority grants no external authority. Orchestrator performs authorized external actions; specialist roles return them without execution.
152
142
  - [platform.codex] Role restrictions are prompt-level contracts, not a filesystem sandbox. No documented role-specific Git hook or generic per-agent tool allowlist is assumed. Existing shell capabilities are retained because static read access after shell reduction has not been verified; Coder and QA need shell for approved checks.
153
143
  [ARC role policy: contract end]
@@ -39,7 +39,7 @@ Create using only the app tool:
39
39
  ref: "<verified-source-head-full-sha>"
40
40
  })
41
41
 
42
- The name is descriptive and does not guarantee a path or branch. There are no destination path or branch arguments.
42
+ The name describes the work; it guarantees neither a path nor a branch. There are no destination path or branch arguments.
43
43
  Pass ref explicitly as the full SHA; do not omit it or rely on a remote default. If an operationId is returned,
44
44
  use mcp__codex_app__get_worktree_creation_status until completed. Preparing/creating/registering progress is not
45
45
  success.
@@ -55,7 +55,7 @@ Before a Orchestrator direct edit, Orchestrator verifies the same conditions, wi
55
55
  applicable approval,
56
56
  and records them in the brief.
57
57
 
58
- Any missing or failed condition blocks handoff. Orchestrator may continue read-only investigation and authorized
58
+ A missing or failed condition blocks handoff. Orchestrator may continue read-only investigation and authorized
59
59
  preparation
60
60
  or recovery, but cannot start Coder early. Reverify affected evidence when approved content, execution target, branch,
61
61
  HEAD, or relevant state changes. Coder's conflict reporting is in its profile; Orchestrator
@@ -77,7 +77,7 @@ commit SHA, actual message, included paths, approved-content verification or val
77
77
  final verification, and any failure/partial completion and recovery evidence, plus absolute approved artifact paths.
78
78
  Record the Complete planning-document set fields from planning.md, confirming no applicable document awaits
79
79
  writing/approval.
80
- Distinguish reused existing commits from the batch preparation commit, or record valid document absence.
80
+ Distinguish reused commits from the batch preparation commit, or record valid document absence.
81
81
  Record applicable approvals and the initial explicit execution-target choice or verified reuse for each first start or
82
82
  restart. Give all five
83
83
  roles (Coder, QA, Planner, Reviewer, Scouter) the same actual workspace and selected execution checkout or absolute
@@ -162,20 +162,84 @@ under its profile. Material scope/method/risk changes and invalid target evidenc
162
162
  planning and the choice-lifetime rules above. Report the missing condition and resume evidence rather than asking
163
163
  for an approval already valid for that scope.
164
164
 
165
+ Before any exception judgment, Orchestrator reads [Risk-scaled execution](verification.md#risk-scaled-execution) and [planning](planning.md) for the full risk and plan-depth conditions.
166
+
167
+ ## Common handoff gate
168
+
169
+ Before every Coder first start/restart, Orchestrator passes the full gate in
170
+ [handoff](handoff.md): applicable approvals/artifacts or valid omissions, explicit execution-target choice
171
+ or verified reuse, intended accessible repository/workspace, actual Git identity/state, preservation/ownership,
172
+ verified document commits or valid absence, and no unresolved failure/partial completion.
173
+ Missing evidence, mismatches, unclear ownership or unresolved preparation block handoff and require Orchestrator
174
+ resolution and full revalidation. Handoff owns the evidence fields, canonical handoff record, restart brief, choice lifetime
175
+ and reuse. Coder trusts the Orchestrator-verified brief and reports actual conflicts under its self-contained profile;
176
+ never replace its local guards with a requirement to load Orchestrator procedures.
177
+ Depth-2 roles use the supplied workspace and report path/state conflicts; they cannot create/switch workspaces or
178
+ branches. The same conditions apply before a Orchestrator direct edit.
179
+ For a selected worktree, handoff requires common directory, registration, app-managed current-chat attachment,
180
+ approved branch, and source preservation; prepare only through the selected managed-worktree contract.
181
+
182
+
183
+ ## Coder TDD and constraints
184
+
185
+ Before feature, bug-fix, or behavior edits, Coder follows local `test-driven-development` unless the explicit
186
+ ARC exception applies; the Coder profile holds Coder's full TDD rules. TDD is waived only when every small,
187
+ low-risk criterion (Risk-scaled execution) and every plan-skip criterion (Orchestrator direct path) holds.
188
+ Before Coder starts,
189
+ Orchestrator records the scope, why every criterion is met, acceptance criteria, and focused verification in the brief.
190
+ An explicit user or task-specific TDD request overrides
191
+ this waiver. For qualifying tasks only, this exception takes precedence over the generic trigger in the local reference;
192
+ do not change that skill. Ordinary multi-step or significant/high-risk work is not eligible. The waiver skips only
193
+ RED-GREEN steps; focused checks and risk-appropriate QA/Reviewer remain, and do not claim TDD was followed.
194
+ If a constraint blocks a required TDD step, Orchestrator records the
195
+ decision in the brief/plan and obtains any required human approval; internal approval is not a substitute.
196
+ Non-behavior documentation/configuration uses only a specifically authorized exception recorded in the brief; do not
197
+ generalize it to behavior work.
198
+
199
+
200
+ ## Orchestrator direct path for small tasks
201
+
202
+ Orchestrator may make a task's edits directly, without Planner brainstorming or Coder, only when every small,
203
+ low-risk criterion
204
+ holds, every plan-skip criterion holds
205
+ (one local change, no dependent stages, no cross-component shared state, lifecycle, or integration-order concerns,
206
+ and one
207
+ focused verification path), and no significant-risk trigger applies. Spike, architectural, ordinary-behavior,
208
+ significant/high-risk, unclear-risk work, and edits overlapping files assigned to a running Coder are not eligible.
209
+
210
+ Before editing, Orchestrator records a scope record (not a brainstorming design) with scope and files,
211
+ why every criterion holds, acceptance criteria, and focused verification. Apply authorization in
212
+ [planning](planning.md#authorization-and-scope): an existing sufficiently specific user request can approve
213
+ that scope; no duplicate approval is needed. Otherwise present the scope record to the user and obtain explicit
214
+ approval before editing. Silence, an ambiguous response, or approval of other work is not approval.
215
+ Orchestrator then passes the Coder handoff gate in handoff,
216
+ with the
217
+ approved scope record as the applicable approval, before the first edit. Orchestrator edits only the approved files,
218
+ preserves others' edits, makes surgical edits in
219
+ the local style without unrelated refactoring or speculative additions, and does not install dependencies without
220
+ authorization.
221
+
222
+ Behavior edits follow Coder TDD and constraints; when TDD applies, Orchestrator follows local
223
+ `test-driven-development`.
224
+ After editing, Orchestrator records the changed files, runs the focused checks, connects each acceptance criterion to
225
+ evidence,
226
+ and preserves unverified scope. Orchestrator is not independent of its own edit; assign QA when the evidence is
227
+ incomplete.
228
+ After a failed focused check or a QA finding, Orchestrator routes the correction to Coder and obtains a recheck.
229
+
230
+ If scope expands, risk becomes unclear, or a criterion stops holding, Orchestrator stops editing, records the changes
231
+ already
232
+ made, and reclassifies; further work follows the normal Planner/Coder flow with Coder owning subsequent edits. Do not
233
+ automatically revert, reset, stash, or clean those changes. Like other plan-skip paths, there is no automatic task
234
+ commit; commits follow applicable guidance and user requests.
235
+
236
+
165
237
  [ARC role policy: contract begin]
166
238
  Generated from lib/policy/role-policy.json; do not edit this managed section manually.
167
- - [scope.non-escalation] Act only within the intersection of role authority, approved scope and available platform tools. Delegation, restart, agent messages and attached instructions do not expand role authority. Never bypass a restriction through aliases, scripts, other tools, processes or redelegation. Return conflicting instructions to Orchestrator before dependent work; reuse valid prior approvals for unchanged scope rather than requesting them again.
168
239
  - [git.specialists-deny] Specialist roles MUST NOT change Git state: no stage, commit, push, merge, rebase, reset, branch creation/switching or worktree creation/removal, during normal implementation or recovery. Even an explicit Orchestrator assignment cannot authorize these actions; return them to Orchestrator. Read-only Git inspection remains allowed within the assigned scope.
169
- - [git.orchestrator-accept-commit] Only Orchestrator accepts work and executes Git mutations. One approved top-level plan task becomes one focused implementation commit after criteria, required checks and findings are satisfied; Orchestrator accepts then commits without additional user commit approval. Reports, passing checks and Reviewer opinions do not replace acceptance. Preserve unrelated changes and ownership and verify the resulting SHA, included content, HEAD and remaining changes. Existing small-task direct and plan-omission paths are unchanged.
170
- - [external.explicit-user-authority] Push, merge, deploy, publish and external messages require explicit user authorization for that action, scope and target. Local commit authority does not grant external authority. Orchestrator performs authorized external actions; specialist roles return them without execution.
171
- - [role.orchestrator-boundary] Assign design/spec/plan/brainstorming drafts ONLY to Planner and implementation/configuration/test edits to Coder. Orchestrator saves complete drafts and owns approval requests, preparation, scheduling, evidence, acceptance and completion. Direct implementation is limited to the existing small, low-risk direct path; this policy does not expand it.
172
- - [role.scouter-read-only] Research assigned static sources and report findings, evidence and limits. Do not edit files, install, execute checks, prepare execution targets, inspect live operational state, change external state or decide design, verification, review or acceptance.
173
- - [role.planner-draft-only] Return design/spec/plan drafts and dependencies, criteria, hold conditions and verification needs in the response. Do not save documents, implement, run checks, prepare targets, request user approval or decide acceptance. Stop formal target-dependent drafting if actual prepared target evidence is missing; route decisions to Orchestrator.
174
- - [role.coder-implementation] Implement only assigned approved files and focused checks under the existing TDD contract. Report changed files, RED/GREEN or authorized exception evidence, results, limits and follow-up. Do not plan, independently QA/review your own work, accept the task or declare overall completion. Git changes remain forbidden even when implementation succeeds.
175
- - [role.qa-verification] Run approved checks and report commands, observations, reproduction, evidence and limits. Create only essential temporary data/logs/reports in the brief-authorized location and lifetime. Do not edit product source, tests, fixtures or configuration to pass checks, deploy or accept work. Persistent product-state checks require explicit scope and cleanup ownership. Return failures for Coder correction and required QA recheck.
176
- - [role.reviewer-independent] Independently inspect the assigned final changes and evidence and report actionable findings and limits. Remain read-only; do not execute QA tests, edit files, perform Git mutations or decide acceptance.
177
- - [review.significant-no-plan] For significant/high-risk work without a plan: Coder → QA and required QA rechecks → Reviewer of the final full change → Orchestrator acceptance. Do not omit Reviewer merely because no plan exists. This creates no new plan obligation.
240
+ - [role.coder-implementation] Edit only assigned, approved files and run focused checks under the existing TDD contract. Report changed files, RED/GREEN or authorized exception evidence, results, limits and follow-up. Do not plan, independently QA/review your own work, accept the task or declare overall completion. Git changes remain forbidden even when implementation succeeds.
241
+ - [review.significant-no-plan] For significant/high-risk work without a plan: Coder → QA and required QA rechecks → Reviewer of the final full change → Orchestrator acceptance. MUST NOT omit Reviewer merely because no plan exists. This creates no new plan obligation.
178
242
  - [review.significant-plan] For significant/high-risk plan work: each task uses Coder → fresh QA as required → Orchestrator acceptance and focused commit. After all tasks are accepted and required QA is complete, Reviewer reviews the final full change once. Reviewer is NOT a per-task or per-commit required gate. Preserve required checks and necessary finding rechecks.
179
- - [review.final-plan-recheck] For final overall Reviewer findings on plan work, including behavior findings, use Coder → Reviewer without QA reassignment; repeat until resolved. This exception applies only to that final plan stage. Preserve required QA and QA failure rechecks before initial final review and outside this exception.
243
+ - [review.final-plan-recheck] For final overall Reviewer findings on plan work, including behavior findings, use Coder → Reviewer without QA reassignment; repeat until resolved. This exception applies only at the final plan stage. Preserve required QA and QA failure rechecks before initial final review and outside this exception.
180
244
  - [platform.codex] Role restrictions are prompt-level contracts, not a filesystem sandbox. No documented role-specific Git hook or generic per-agent tool allowlist is assumed. Existing shell capabilities are retained because static read access after shell reduction has not been verified; Coder and QA need shell for approved checks.
181
245
  [ARC role policy: contract end]
@@ -4,7 +4,7 @@ Before the first subagent creation, Orchestrator reads this reference and the ad
4
4
  `../limits.toml` (installed at `skills/arc/limits.toml`). Require version = 1,
5
5
  `max_total_subagents` and `max_concurrent_subagents` as positive safe integers.
6
6
  Installation defaults are max_total_subagents = 100 and max_concurrent_subagents = 5.
7
- A missing, malformed or unreadable policy blocks new creation; report it rather than assuming defaults.
7
+ A missing, malformed or unreadable policy blocks new creation. Report it; MUST NOT assume defaults.
8
8
  Freeze these settings for one ARC coordination session/tree; reinstalling affects new sessions.
9
9
 
10
10
  ## Counting and reservations
@@ -23,7 +23,7 @@ created + pending reservations + proposed <= max_total_subagents, and
23
23
  active + pending reservations + proposed <= max_concurrent_subagents and available runtime capacity.
24
24
  Record a reservation before each creation call. Confirmed creation converts it into a created,
25
25
  active ID. Release a reservation only when failure proves that no instance was created.
26
- An uncertain result keeps its reservation and capacity until reconciled; never retry blindly.
26
+ An uncertain result retains its reservation and capacity until reconciled. MUST NOT retry blindly.
27
27
  Serialize work when a batch does not fit. There are no reserved role slots.
28
28
 
29
29
  ## Continuation and exhaustion
@@ -31,8 +31,8 @@ Serialize work when a batch does not fit. There are no reserved role slots.
31
31
  Preserve the ledger through continuation, resume and context compaction; reconcile actual instance
32
32
  IDs before dispatch. Ledger loss must never reset counters to zero. If reconstruction is incomplete,
33
33
  hold creation and report the unknown budget; use a conservative bound only with sufficient evidence.
34
- Completion frees confirmed active capacity, never the total-created budget. Exhaustion holds new
35
- creation and requires reporting remaining work and budgets. It never authorizes skipping required
34
+ Completion frees confirmed active capacity; it does not restore the total-created budget. Exhaustion holds new
35
+ creation and requires reporting remaining work and budgets. It does not authorize skipping required
36
36
  QA or Reviewer, role freshness, approval, ownership, dependency or same-file edit gates.
37
37
 
38
38
  This cumulative guard and ARC scheduling are prompt-level policy, not hard runtime enforcement.
@@ -42,7 +42,7 @@ complete draft before saving, even when returned only in chat. Before formal dra
42
42
  and records the actual absolute workspace/repository, branch or detached HEAD, HEAD, changes and ownership,
43
43
  explicit choice and preparation evidence, and absolute document paths inside that target. Planner drafts for that
44
44
  verified workspace; Orchestrator saves directly in the selected target. Missing or mismatched evidence stops the
45
- affected drafting or save and is reported to Orchestrator. Planned scope and intended paths are not actual preparation.
45
+ affected drafting or save and is reported to Orchestrator. Planned scope and paths do not establish actual preparation.
46
46
  Initial target preparation does not authorize Coder; the complete handoff gate still applies.
47
47
 
48
48
 
@@ -124,9 +124,8 @@ and execution preparation. This applies that judgment, not a new spec-necessity
124
124
 
125
125
  Design, spec, plan, and brainstorming drafts are authored only by Planner.
126
126
  Orchestrator must not substitute an independently authored spec or plan for Planner's complete draft.
127
- If the draft has substantive
128
- omissions, return them to Planner for completion; if Planner fails or is unavailable, stop and report,
129
- never draft instead. Design approval alone does not change ownership.
127
+ Return substantive draft omissions to Planner for completion; if Planner fails or is unavailable, stop and report,
128
+ never draft instead. Design approval does not transfer ownership.
130
129
 
131
130
  ## Top-level plan tasks
132
131
 
@@ -174,7 +173,7 @@ If A fails, hold B and C; D may continue if unaffected.
174
173
 
175
174
  Before the first architectural spec save, first required Bounded written spec save, or first plan save, read this
176
175
  reference and record accessible evidence in the shared brief/canonical handoff record.
177
- Saving creates a reviewable file; it is not approval or a Git commit.
176
+ Saving creates a reviewable file; it grants no approval and creates no Git commit.
178
177
 
179
178
  **Spec save:** Verify the approved design scope and approval evidence, accessible Planner's complete spec draft and
180
179
  self-review findings, Orchestrator's integration/save/review responsibility, and intended absolute save path.
@@ -268,20 +267,37 @@ Orchestrator briefs absolute ARC paths `references/superpowers/brainstorming/SKI
268
267
  `references/superpowers/writing-plans/SKILL.md`. Planner reads them directly; resolve relative references within each
269
268
  skill. Missing files stop the stage; report paths without global fallback. Keep ARC approval and ownership gates.
270
269
 
270
+ ## Dependency analysis and parallel dispatch
271
+
272
+ Before the first Coder assignment for an approved plan, Orchestrator records its dependency/readiness map and
273
+ initial ready batch under [planning](planning.md), which owns record fields and readiness conditions.
274
+ File separation alone never proves independence. Pass the full approval/preparation and handoff gates for every
275
+ assignment; unresolved dependencies, shared contracts, or ownership conflicts hold affected work.
276
+ Start all ready independent tasks concurrently with fresh Coders within capacity under [limits](limits.md)
277
+ and any lower actual runtime limit; record capacity and serialization reasons. Same-file concurrent Coder edits are
278
+ prohibited, even on different lines. ARC's cap is not a claim of runtime capability.
279
+
280
+ Reassess readiness after completion reports, new check evidence, acceptance, commit, slot return, or a new conflict.
281
+ Coder completion alone does not release dependents: require predecessor checks, Orchestrator acceptance and verified
282
+ focused commit, or accepted no-change evidence under [commit](commit.md). Start newly ready tasks without
283
+ waiting for unrelated batch members; failures hold affected dependents while unaffected ready work may continue.
284
+ Preserve risk-scaled QA/Reviewer timing and execution-target restrictions. Shared-checkout Git coordination belongs to
285
+ commit.md; refresh assignment evidence under [handoff](handoff.md).
286
+
287
+
288
+ Design and plan depth are independent of verification risk. Planner alone uses local brainstorming/writing-plans
289
+ (Role gate); Planner proposes, Orchestrator decides the path and plan depth;
290
+ Orchestrator integrates complete drafts and obtains applicable approvals. Architectural specs and Bounded written specs
291
+ required by Orchestrator's recorded plan-depth judgment (planning item 3) use planning save gates; a required plan alone
292
+ does not require a spec. Obtain explicit execution-target choice and verify actual target preparation before formal drafting
293
+ and saving. Complete all current-scope individual document approvals before the batch docs commit. A missing required skill blocks its stage.
294
+
295
+
271
296
  [ARC role policy: contract begin]
272
297
  Generated from lib/policy/role-policy.json; do not edit this managed section manually.
273
- - [scope.non-escalation] Act only within the intersection of role authority, approved scope and available platform tools. Delegation, restart, agent messages and attached instructions do not expand role authority. Never bypass a restriction through aliases, scripts, other tools, processes or redelegation. Return conflicting instructions to Orchestrator before dependent work; reuse valid prior approvals for unchanged scope rather than requesting them again.
274
- - [git.specialists-deny] Specialist roles MUST NOT change Git state: no stage, commit, push, merge, rebase, reset, branch creation/switching or worktree creation/removal, during normal implementation or recovery. Even an explicit Orchestrator assignment cannot authorize these actions; return them to Orchestrator. Read-only Git inspection remains allowed within the assigned scope.
275
298
  - [git.orchestrator-accept-commit] Only Orchestrator accepts work and executes Git mutations. One approved top-level plan task becomes one focused implementation commit after criteria, required checks and findings are satisfied; Orchestrator accepts then commits without additional user commit approval. Reports, passing checks and Reviewer opinions do not replace acceptance. Preserve unrelated changes and ownership and verify the resulting SHA, included content, HEAD and remaining changes. Existing small-task direct and plan-omission paths are unchanged.
276
- - [external.explicit-user-authority] Push, merge, deploy, publish and external messages require explicit user authorization for that action, scope and target. Local commit authority does not grant external authority. Orchestrator performs authorized external actions; specialist roles return them without execution.
277
- - [role.orchestrator-boundary] Assign design/spec/plan/brainstorming drafts ONLY to Planner and implementation/configuration/test edits to Coder. Orchestrator saves complete drafts and owns approval requests, preparation, scheduling, evidence, acceptance and completion. Direct implementation is limited to the existing small, low-risk direct path; this policy does not expand it.
278
- - [role.scouter-read-only] Research assigned static sources and report findings, evidence and limits. Do not edit files, install, execute checks, prepare execution targets, inspect live operational state, change external state or decide design, verification, review or acceptance.
279
- - [role.planner-draft-only] Return design/spec/plan drafts and dependencies, criteria, hold conditions and verification needs in the response. Do not save documents, implement, run checks, prepare targets, request user approval or decide acceptance. Stop formal target-dependent drafting if actual prepared target evidence is missing; route decisions to Orchestrator.
280
- - [role.coder-implementation] Implement only assigned approved files and focused checks under the existing TDD contract. Report changed files, RED/GREEN or authorized exception evidence, results, limits and follow-up. Do not plan, independently QA/review your own work, accept the task or declare overall completion. Git changes remain forbidden even when implementation succeeds.
281
- - [role.qa-verification] Run approved checks and report commands, observations, reproduction, evidence and limits. Create only essential temporary data/logs/reports in the brief-authorized location and lifetime. Do not edit product source, tests, fixtures or configuration to pass checks, deploy or accept work. Persistent product-state checks require explicit scope and cleanup ownership. Return failures for Coder correction and required QA recheck.
282
- - [role.reviewer-independent] Independently inspect the assigned final changes and evidence and report actionable findings and limits. Remain read-only; do not execute QA tests, edit files, perform Git mutations or decide acceptance.
283
- - [review.significant-no-plan] For significant/high-risk work without a plan: Coder → QA and required QA rechecks → Reviewer of the final full change → Orchestrator acceptance. Do not omit Reviewer merely because no plan exists. This creates no new plan obligation.
299
+ - [review.significant-no-plan] For significant/high-risk work without a plan: Coder → QA and required QA rechecks → Reviewer of the final full change → Orchestrator acceptance. MUST NOT omit Reviewer merely because no plan exists. This creates no new plan obligation.
284
300
  - [review.significant-plan] For significant/high-risk plan work: each task uses Coder → fresh QA as required → Orchestrator acceptance and focused commit. After all tasks are accepted and required QA is complete, Reviewer reviews the final full change once. Reviewer is NOT a per-task or per-commit required gate. Preserve required checks and necessary finding rechecks.
285
- - [review.final-plan-recheck] For final overall Reviewer findings on plan work, including behavior findings, use Coder → Reviewer without QA reassignment; repeat until resolved. This exception applies only to that final plan stage. Preserve required QA and QA failure rechecks before initial final review and outside this exception.
301
+ - [review.final-plan-recheck] For final overall Reviewer findings on plan work, including behavior findings, use Coder → Reviewer without QA reassignment; repeat until resolved. This exception applies only at the final plan stage. Preserve required QA and QA failure rechecks before initial final review and outside this exception.
286
302
  - [platform.codex] Role restrictions are prompt-level contracts, not a filesystem sandbox. No documented role-specific Git hook or generic per-agent tool allowlist is assumed. Existing shell capabilities are retained because static read access after shell reduction has not been verified; Coder and QA need shell for approved checks.
287
303
  [ARC role policy: contract end]
@@ -5,9 +5,66 @@ QA and
5
5
  Reviewer contracts are in their profiles; they read this file only for sections the brief explicitly cites.
6
6
  Visual companion design discussion is distinct from QA UI acceptance.
7
7
 
8
+ For Orchestrator, **Evidence verdict**: each criterion is proven, unmet, or unverified; passing runs, reports, or disposition never turn unverified into proven; reports keep unverified scope visible.
9
+
8
10
  ## Risk-scaled execution
9
11
 
10
- SKILL.md Risk-scaled execution holds the risk table, risk definitions, evidence-reuse rule, and role order,
12
+ Orchestrator assigns edits exclusively to Coder except under the Orchestrator direct path in [handoff](handoff.md#orchestrator-direct-path-for-small-tasks), and determines affected
13
+ behavior, risk,
14
+ and smallest meaningful verification.
15
+
16
+ | Risk | Minimum flow |
17
+ |---|---|
18
+ | Small, low risk | Coder, or Orchestrator direct path → Orchestrator's focused checks → acceptance |
19
+ | Ordinary behavior | Coder → independent QA → acceptance |
20
+ | Significant/high risk | Coder → QA → independent Reviewer of the final full change → acceptance; with a plan, each plan task Coder → FRESH QA → acceptance/commit satisfies the QA step, then independent Reviewer once on the final full change after all plan tasks |
21
+
22
+ Ordinary and significant plan tasks need a FRESH QA before acceptance; only small, low-risk tasks may be accepted on
23
+ Orchestrator focused checks. Small, low risk means narrow, understood, readily reversible, and verifiable by focused
24
+ checks. Ordinary behavior
25
+ fails those conditions without a significant-risk trigger. Significant risk includes shared role/behavior contracts,
26
+ shared state, lifecycle/integration order, security/permissions, data loss/migration, public interfaces, or costly
27
+ installation/deployment/rollback. Substantial behavior or contract changes are significant regardless of file count.
28
+ When risk is unclear, investigate or use the higher flow. Environment failure does not waive checks or determine design depth.
29
+
30
+ Do not add per-task QA or review gates solely because a task boundary exists. Reviewer is never a plan-task acceptance
31
+ prerequisite; for significant work with a plan, it reviews the final full change once after all plan tasks are accepted
32
+ with their risk-scaled checks, following the last plan task's required checks and any QA recheck at the final relevant
33
+ state; significant work without a plan keeps Reviewer after QA before acceptance. Preserve specific approved
34
+ obligations. If the next task depends on a still-unverified risky contract, complete applicable QA at that dependency
35
+ boundary and resolve or explicitly disposition findings before dependent implementation.
36
+ Reuse evidence only when scope, relevant state, independence, freshness, and flow
37
+ position satisfy each covered requirement; changes, failures, or missing/conflicting evidence invalidate affected reuse.
38
+ QA checks independently without edits; Reviewer reviews without QA, planning, edits, delegation, or completion
39
+ decisions. Orchestrator routes fixes to Coder (a failed direct-path check returns to the normal flow),
40
+ obtains affected QA rechecks outside the final plan Reviewer correction exception and required final review, and accepts after findings/evidence gaps are resolved or
41
+ explicitly dispositioned.
42
+
43
+ Criterion verdicts follow the Evidence verdict.
44
+
45
+ ### Final plan Reviewer correction loop
46
+
47
+ For a plan's final overall Reviewer findings, including behavior findings, Orchestrator assigns
48
+ Coder → Reviewer recheck with no QA reassignment. Repeat corrections and Reviewer rechecks until findings are resolved;
49
+ the initial single full review does not prohibit necessary rechecks. Before the initial final overall Reviewer,
50
+ risk-required checks and QA execution failures or unmet criteria still require Coder correction → QA recheck.
51
+ This exception applies only to findings from the final overall Reviewer of work with a plan.
52
+ Work without a plan retains its existing verification flow. Scope expansion, separate mandatory obligations,
53
+ or unresolved evidence gaps hold affected work for Orchestrator to resolve and obtain required approvals.
54
+ Orchestrator assigns corrections/rechecks and decides acceptance. Reviewer remains read-only, must not run QA
55
+ checks or decide acceptance. Previous QA evidence must not be presented as post-fix execution evidence;
56
+ report only checks actually performed, their actor, target state, results and remaining limits.
57
+
58
+
59
+
60
+ Authorization evidence and probe/combined scope are owned by [planning](planning.md#authorization-and-scope);
61
+ valid reuse and actual-state refresh by [handoff](handoff.md#authorization-continuity).
62
+ After gates hold, continue approved no-doc scope through required checks and Orchestrator acceptance under
63
+ [verification](verification.md#completion-continuity); a role report alone does not complete the work.
64
+
65
+
66
+
67
+ The Risk-scaled execution section above holds the risk table, risk definitions, evidence-reuse rule, and role order,
11
68
  including Reviewer timing. Product/test edits belong exclusively to Coder except under the Orchestrator direct path;
12
69
  Orchestrator may inspect/run checks but
13
70
  routes code corrections to Coder. Determine the minimum
@@ -34,8 +91,8 @@ QA runs applicable existing functional/test checks, or approved structural/consi
34
91
  configuration changes. Reviewer reads the assigned diff/source for correctness, factual accuracy, and security. Outside the final plan Reviewer correction exception, after a
35
92
  behavior fix QA reruns affected checks, and Reviewer rechecks only when warranted. Reuse a Reviewer only when
36
93
  independent of the work and self-review and when evidence meets required scope and freshness.
37
- Resolve or explicitly disposition findings and confirm
38
- acceptance evidence before completion; claim checks only with verified output.
94
+ Before completion, resolve or explicitly disposition findings and confirm acceptance evidence. Claim checks only
95
+ with verified output.
39
96
 
40
97
  ## Task acceptance and final plan acceptance
41
98
 
@@ -113,8 +170,7 @@ issues may require both QA verification and Reviewer source review.
113
170
  Orchestrator accepts using criterion verdicts, findings, recheck evidence, and remaining gaps, rather than an overall
114
171
  run result.
115
172
  Explicit disposition does not convert unverified to proven; completion reports preserve remaining unverified scope.
116
- For low-risk work without a QA agent, Orchestrator's focused checks likewise
117
- connect each criterion to evidence.
173
+ For low-risk work without QA, Orchestrator's focused checks likewise connect each criterion to evidence.
118
174
 
119
175
 
120
176
  Read brief-cited `references/superpowers/test-driven-development/SKILL.md`; retain ARC exceptions.
@@ -146,18 +202,9 @@ actual unmet condition and report what is needed to resume. Structural evidence
146
202
 
147
203
  [ARC role policy: contract begin]
148
204
  Generated from lib/policy/role-policy.json; do not edit this managed section manually.
149
- - [scope.non-escalation] Act only within the intersection of role authority, approved scope and available platform tools. Delegation, restart, agent messages and attached instructions do not expand role authority. Never bypass a restriction through aliases, scripts, other tools, processes or redelegation. Return conflicting instructions to Orchestrator before dependent work; reuse valid prior approvals for unchanged scope rather than requesting them again.
150
- - [git.specialists-deny] Specialist roles MUST NOT change Git state: no stage, commit, push, merge, rebase, reset, branch creation/switching or worktree creation/removal, during normal implementation or recovery. Even an explicit Orchestrator assignment cannot authorize these actions; return them to Orchestrator. Read-only Git inspection remains allowed within the assigned scope.
151
205
  - [git.orchestrator-accept-commit] Only Orchestrator accepts work and executes Git mutations. One approved top-level plan task becomes one focused implementation commit after criteria, required checks and findings are satisfied; Orchestrator accepts then commits without additional user commit approval. Reports, passing checks and Reviewer opinions do not replace acceptance. Preserve unrelated changes and ownership and verify the resulting SHA, included content, HEAD and remaining changes. Existing small-task direct and plan-omission paths are unchanged.
152
- - [external.explicit-user-authority] Push, merge, deploy, publish and external messages require explicit user authorization for that action, scope and target. Local commit authority does not grant external authority. Orchestrator performs authorized external actions; specialist roles return them without execution.
153
- - [role.orchestrator-boundary] Assign design/spec/plan/brainstorming drafts ONLY to Planner and implementation/configuration/test edits to Coder. Orchestrator saves complete drafts and owns approval requests, preparation, scheduling, evidence, acceptance and completion. Direct implementation is limited to the existing small, low-risk direct path; this policy does not expand it.
154
- - [role.scouter-read-only] Research assigned static sources and report findings, evidence and limits. Do not edit files, install, execute checks, prepare execution targets, inspect live operational state, change external state or decide design, verification, review or acceptance.
155
- - [role.planner-draft-only] Return design/spec/plan drafts and dependencies, criteria, hold conditions and verification needs in the response. Do not save documents, implement, run checks, prepare targets, request user approval or decide acceptance. Stop formal target-dependent drafting if actual prepared target evidence is missing; route decisions to Orchestrator.
156
- - [role.coder-implementation] Implement only assigned approved files and focused checks under the existing TDD contract. Report changed files, RED/GREEN or authorized exception evidence, results, limits and follow-up. Do not plan, independently QA/review your own work, accept the task or declare overall completion. Git changes remain forbidden even when implementation succeeds.
157
- - [role.qa-verification] Run approved checks and report commands, observations, reproduction, evidence and limits. Create only essential temporary data/logs/reports in the brief-authorized location and lifetime. Do not edit product source, tests, fixtures or configuration to pass checks, deploy or accept work. Persistent product-state checks require explicit scope and cleanup ownership. Return failures for Coder correction and required QA recheck.
158
- - [role.reviewer-independent] Independently inspect the assigned final changes and evidence and report actionable findings and limits. Remain read-only; do not execute QA tests, edit files, perform Git mutations or decide acceptance.
159
- - [review.significant-no-plan] For significant/high-risk work without a plan: Coder → QA and required QA rechecks → Reviewer of the final full change → Orchestrator acceptance. Do not omit Reviewer merely because no plan exists. This creates no new plan obligation.
206
+ - [review.significant-no-plan] For significant/high-risk work without a plan: Coder → QA and required QA rechecks → Reviewer of the final full change → Orchestrator acceptance. MUST NOT omit Reviewer merely because no plan exists. This creates no new plan obligation.
160
207
  - [review.significant-plan] For significant/high-risk plan work: each task uses Coder → fresh QA as required → Orchestrator acceptance and focused commit. After all tasks are accepted and required QA is complete, Reviewer reviews the final full change once. Reviewer is NOT a per-task or per-commit required gate. Preserve required checks and necessary finding rechecks.
161
- - [review.final-plan-recheck] For final overall Reviewer findings on plan work, including behavior findings, use Coder → Reviewer without QA reassignment; repeat until resolved. This exception applies only to that final plan stage. Preserve required QA and QA failure rechecks before initial final review and outside this exception.
208
+ - [review.final-plan-recheck] For final overall Reviewer findings on plan work, including behavior findings, use Coder → Reviewer without QA reassignment; repeat until resolved. This exception applies only at the final plan stage. Preserve required QA and QA failure rechecks before initial final review and outside this exception.
162
209
  - [platform.codex] Role restrictions are prompt-level contracts, not a filesystem sandbox. No documented role-specific Git hook or generic per-agent tool allowlist is assumed. Existing shell capabilities are retained because static read access after shell reduction has not been verified; Coder and QA need shell for approved checks.
163
210
  [ARC role policy: contract end]
@@ -6,8 +6,8 @@ Read before offering or operating a visual companion.
6
6
 
7
7
  Visual companion design discussion is distinct from QA UI acceptance checks under the approved test brief.
8
8
 
9
- Planner identifies a genuinely visual question, why a visual helps, options, the user decision, and a complete content
10
- draft; Planner does not write screens, start a server, operate a browser, or request approval.
9
+ Planner identifies a genuinely visual question, explains why a visual helps, and returns options, the user decision,
10
+ and a complete content draft; Planner does not write screens, start a server, operate a browser, or request approval.
11
11
  Orchestrator makes a just-in-time
12
12
  offer as its own message only when a question is clearer visually, then waits for acceptance. If declined, continue in
13
13
  text and do not offer again unless the user raises it. If accepted, decide per question whether to use the companion.
@@ -20,4 +20,4 @@ alone does not route every question through a browser.
20
20
 
21
21
  Upstream guide/scripts: `<installed ARC>/references/superpowers/brainstorming/visual-companion.md` and adjacent `scripts/`.
22
22
  ARC guide: `references/visual-companion.md`; Orchestrator briefs absolute paths and retains approval/server/browser
23
- ownership. Missing files stop dependent work without global fallback.
23
+ ownership. Missing files stop dependent work. MUST NOT use a global fallback.
@@ -0,0 +1,81 @@
1
+ import {evaluate} from '../evaluate.mjs';
2
+ import {evaluateCapability} from '../capabilities.mjs';
3
+ import {registerAgentObservation} from '../identity.mjs';
4
+ import {transactWorkflow, fingerprintRequest} from '../store.mjs';
5
+ import {runGate} from '../gate.mjs';
6
+ import {classifyGitCommand} from '../git-query.mjs';
7
+
8
+ const text=v=>typeof v==='string'&&v.length>0;
9
+ const object=v=>v!==null&&typeof v==='object'&&!Array.isArray(v);
10
+ const supported=new Set(['Read','Glob','Grep','Bash','Write','Edit','MultiEdit','Agent']);
11
+ const deny=reason=>({decision:'deny',reason,ruleIds:['runtime.claude'],proposedTransition:null});
12
+ /** Host-verified support for this installed version is required. A config value
13
+ * alone cannot establish hook failure blocking; provider wiring belongs to T6. */
14
+ export function claudeFailureBlockingReady(support){
15
+ return support?.status==='verified'&&support.onFailure==='block'&&text(support.platformVersion)&&text(support.verificationRef);
16
+ }
17
+ /** Context is a trusted host dependency, never deserialized from stdin/tool_input.
18
+ * describeTool must parse the complete tool invocation conservatively, and supply
19
+ * semantic operation, paths and descriptor. No native provider is assumed here. */
20
+ export function normalizeClaudeEvent(input,context={}){
21
+ if(!object(input)||input.hook_event_name!=='PreToolUse'||!text(input.session_id)||input.session_id!==context.sessionRef||!text(context.actorRef)||!text(context.taskId)||!text(context.requestId)||!text(input.tool_use_id)||input.tool_use_id!==context.toolUseId||!text(input.tool_name)||!object(input.tool_input)||!text(input.cwd))throw Error('Verified session identity and complete PreToolUse event required');
22
+ const toolPath=input.tool_name;
23
+ const coverage={...evaluateCapability({platform:'claude',toolPath,sessionRef:context.sessionRef}),enforcement:'hook-response-only',nativeVerified:false,startupTimeout:'unknown',existingSessionInput:'unsupported',specializedPaths:'unknown',hostedTools:'unsupported'};
24
+ if(!claudeFailureBlockingReady(context.failureBlocking))throw Error('Verified current-version onFailure block contract required');
25
+ if(!supported.has(input.tool_name))return {request:null,coverage};
26
+ if(typeof context.describeTool!=='function')throw Error('Trusted semantic tool provider unavailable');
27
+ const semantic=context.describeTool(structuredClone(input));
28
+ if(!object(semantic)||!text(semantic.operation)||!Array.isArray(semantic.paths)||!object(semantic.descriptor))throw Error('Complete semantic tool descriptor required');
29
+ if(input.tool_name==='Agent'&&semantic.operation!=='assign-agent')throw Error('Agent tool requires assignment validation');
30
+ return {request:{requestId:context.requestId,platform:'claude',actorRef:context.actorRef,taskId:context.taskId,cwd:input.cwd,toolName:input.tool_name,arguments:structuredClone(input.tool_input),operation:semantic.operation,paths:structuredClone(semantic.paths),descriptor:structuredClone(semantic.descriptor)},coverage};
31
+ }
32
+ /** Only documented PreToolUse fields are emitted. hold is a native deny. */
33
+ export function renderClaudeDecision(decision){
34
+ if(decision?.decision==='allow')return {};
35
+ const permissionDecision='deny';
36
+ return {hookSpecificOutput:{hookEventName:'PreToolUse',permissionDecision,permissionDecisionReason:typeof decision?.reason==='string'?decision.reason:'Runtime gate could not verify permission'}};
37
+ }
38
+ /** This returns a response, not proof the host applied it. Startup failures,
39
+ * timeout, hosted/specialized paths and existing write_stdin are outside it. */
40
+ export async function runClaudeGate(input,context={}){
41
+ if(input?.hook_event_name==='PostToolUse'){
42
+ // Result recording cannot authorize assignment/start or prevent a completed call.
43
+ try{if(input.session_id===context.sessionRef&&input.tool_use_id===context.toolUseId&&text(context.actorRef)&&typeof context.recordToolResult==='function')await context.recordToolResult(structuredClone(input));}catch{}
44
+ return {};
45
+ }
46
+ if(input?.hook_event_name==='SubagentStart'){
47
+ // SubagentStart cannot prevent startup. Only a trusted provider can correlate
48
+ // agent_id with a pending assignment; tool/event agent_type is not authority.
49
+ try{
50
+ if(input.session_id===context.sessionRef&&text(input.agent_id)&&typeof context.observeAgent==='function'){
51
+ const observation=await context.observeAgent(structuredClone(input));
52
+ if(observation?.actorRef===input.agent_id&&observation.platform==='claude'){
53
+ const decision=registerAgentObservation(context.state,observation);
54
+ if(decision.decision==='allow'&&decision.proposedTransition&&typeof context.persistObservation==='function')await context.persistObservation(decision,observation);
55
+ }
56
+ }
57
+ }catch{/* Observation failure never claims startup was blocked. */}
58
+ return {};
59
+ }
60
+ try{
61
+ const {request,coverage}=normalizeClaudeEvent(input,context);
62
+ if(!request)return renderClaudeDecision(deny('Tool path has no verified pre-action coverage'));
63
+ if(!text(context.statePath))return renderClaudeDecision(deny('Trusted durable workflow store unavailable'));
64
+ const result=await transactWorkflow({statePath:context.statePath,expectedRevision:context.state?.revision,requestId:request.requestId,request,requestFingerprint:fingerprintRequest(request),decide:async state=>{
65
+ const decision=evaluate(context.policy,state,request,context.evidence);
66
+ if(decision.decision!=='allow')return {...decision,coverage};
67
+ const actor=state.identities.find(identity=>identity.actorRef===request.actorRef);
68
+ if(request.toolName==='Bash'&&actor?.role!=='orchestrator'){
69
+ const query=classifyGitCommand(request.arguments.command,context.policy.git);
70
+ if(!query.allowed)return {...deny('Specialist Git guard: '+query.reason),coverage};
71
+ }
72
+ if(request.operation==='commit'){
73
+ const git=await runGate({phase:'preflight',state,request,gitEvidence:context.gitEvidence});
74
+ if(git.decision!=='allow')return {...git,coverage};
75
+ return {...decision,expectedCommit:git.expectedCommit,coverage};
76
+ }
77
+ return {...decision,coverage};
78
+ }});
79
+ return renderClaudeDecision(result.decision);
80
+ }catch(error){return renderClaudeDecision(deny('Runtime validation unavailable: '+error.message));}
81
+ }
@@ -0,0 +1,63 @@
1
+ import {evaluate} from '../evaluate.mjs';
2
+ import {evaluateCapability} from '../capabilities.mjs';
3
+ import {registerAgentObservation} from '../identity.mjs';
4
+ import {transactWorkflow, fingerprintRequest} from '../store.mjs';
5
+ import {runGate} from '../gate.mjs';
6
+
7
+ const text=v=>typeof v==='string'&&v.length>0;
8
+ const object=v=>v!==null&&typeof v==='object'&&!Array.isArray(v);
9
+ const supported=new Set(['Read','Glob','Grep','Bash','Write','Edit','MultiEdit','exec_command','apply_patch','Agent','spawn_agent']);
10
+ const deny=reason=>({decision:'deny',reason,ruleIds:['runtime.codex'],proposedTransition:null});
11
+ /** Context is a trusted host dependency, never deserialized from stdin/tool_input.
12
+ * describeTool must parse the complete tool invocation conservatively, and supply
13
+ * semantic operation, paths and descriptor. No native provider is assumed here. */
14
+ export function normalizeCodexEvent(input,context={}){
15
+ if(!object(input)||input.hook_event_name!=='PreToolUse'||!text(input.session_id)||input.session_id!==context.sessionRef||!text(context.actorRef)||!text(context.taskId)||!text(context.requestId)||!text(input.tool_use_id)||input.tool_use_id!==context.toolUseId||!text(input.tool_name)||!object(input.tool_input)||!text(input.cwd))throw Error('Verified session identity and complete PreToolUse event required');
16
+ const toolPath=['Agent','spawn_agent'].includes(input.tool_name)?'spawn_agent':input.tool_name;
17
+ const coverage={...evaluateCapability({platform:'codex',toolPath,sessionRef:context.sessionRef}),enforcement:'hook-response-only',nativeVerified:false,startupTimeout:'unknown',existingSessionInput:'unsupported',specializedPaths:'unknown',hostedTools:'unsupported'};
18
+ if(!supported.has(input.tool_name))return {request:null,coverage};
19
+ if(typeof context.describeTool!=='function')throw Error('Trusted semantic tool provider unavailable');
20
+ const semantic=context.describeTool(structuredClone(input));
21
+ if(!object(semantic)||!text(semantic.operation)||!Array.isArray(semantic.paths)||!object(semantic.descriptor))throw Error('Complete semantic tool descriptor required');
22
+ if(['Agent','spawn_agent'].includes(input.tool_name)&&semantic.operation!=='assign-agent')throw Error('Agent tool requires assignment validation');
23
+ return {request:{requestId:context.requestId,platform:'codex',actorRef:context.actorRef,taskId:context.taskId,cwd:input.cwd,toolName:input.tool_name,arguments:structuredClone(input.tool_input),operation:semantic.operation,paths:structuredClone(semantic.paths),descriptor:structuredClone(semantic.descriptor)},coverage};
24
+ }
25
+ /** Only documented PreToolUse fields are emitted. hold is a native deny. */
26
+ export function renderCodexDecision(decision){
27
+ const permissionDecision=decision?.decision==='allow'?'allow':'deny';
28
+ return {hookSpecificOutput:{hookEventName:'PreToolUse',permissionDecision,permissionDecisionReason:typeof decision?.reason==='string'?decision.reason:'Runtime gate could not verify permission'}};
29
+ }
30
+ /** This returns a response, not proof the host applied it. Startup failures,
31
+ * timeout, hosted/specialized paths and existing write_stdin are outside it. */
32
+ export async function runCodexGate(input,context={}){
33
+ if(input?.hook_event_name==='SubagentStart'){
34
+ // SubagentStart cannot prevent startup. Only a trusted provider can correlate
35
+ // agent_id with a pending assignment; tool/event agent_type is not authority.
36
+ try{
37
+ if(input.session_id===context.sessionRef&&text(input.agent_id)&&typeof context.observeAgent==='function'){
38
+ const observation=await context.observeAgent(structuredClone(input));
39
+ if(observation?.actorRef===input.agent_id&&observation.platform==='codex'){
40
+ const decision=registerAgentObservation(context.state,observation);
41
+ if(decision.decision==='allow'&&decision.proposedTransition&&typeof context.persistObservation==='function')await context.persistObservation(decision,observation);
42
+ }
43
+ }
44
+ }catch{/* Observation failure never claims startup was blocked. */}
45
+ return {};
46
+ }
47
+ try{
48
+ const {request,coverage}=normalizeCodexEvent(input,context);
49
+ if(!request)return renderCodexDecision(deny('Tool path has no verified pre-action coverage'));
50
+ if(!text(context.statePath))return renderCodexDecision(deny('Trusted durable workflow store unavailable'));
51
+ const result=await transactWorkflow({statePath:context.statePath,expectedRevision:context.state?.revision,requestId:request.requestId,request,requestFingerprint:fingerprintRequest(request),decide:async state=>{
52
+ const decision=evaluate(context.policy,state,request,context.evidence);
53
+ if(decision.decision!=='allow')return {...decision,coverage};
54
+ if(request.operation==='commit'){
55
+ const git=await runGate({phase:'preflight',state,request,gitEvidence:context.gitEvidence});
56
+ if(git.decision!=='allow')return {...git,coverage};
57
+ return {...decision,expectedCommit:git.expectedCommit,coverage};
58
+ }
59
+ return {...decision,coverage};
60
+ }});
61
+ return renderCodexDecision(result.decision);
62
+ }catch(error){return renderCodexDecision(deny('Runtime validation unavailable: '+error.message));}
63
+ }