Skip to content

fix(runtime): carry the runtime directory to the stage hook in policy.json (#319) - #320

Merged
datacas merged 1 commit into
mainfrom
task-319
Oct 23, 2026
Merged

datacas merged 1 commit into
mainfrom
task-319

Conversation

@datacas

@datacas datacas commented Oct 23, 2026 •

Copy link
Copy Markdown
Owner

Closes #319

Diagnosis

Work units

Unit Behaviour Files Tests Verification Rollback
WU-1 StagePolicy.runtime_dir is set in the runtime and carried in policy.json; the validator path and the permissions command derive from it scripts/stage_permissions.py, tests/test_stage_permissions.py, docs/host-permissions.md test_a_copied_hook_allows_the_commands_the_runtime_advertises, test_the_runtime_paths_survive_the_policy_file python3 -m unittest discover -s tests (1767 tests, OK), python3 scripts/validate-package.py (VALID) independent

Verification

Agent-reported, run locally on this branch:

  • python3 -m unittest discover -s tests: exit 0, 1767 tests.
  • python3 scripts/validate-package.py: exit 0, VALID.
  • python3 -m unittest: exit 0, 0 tests (no discovery at the root).

The tests share no user-global state with CI: they use temporary directories and no Git identity.

Documentation

docs/host-permissions.md now states that the runtime resolves both script paths once and carries them in policy.json; the hook never derives them from its own location.

….json (#319)

The Claude stage hook runs a copy of stage_permissions.py from a temporary code-cycle-policy-* directory. The triage validator and the permission view derived their script paths from __file__, so the hook expected the copy's directory and refused the commands the runtime had advertised. StagePolicy now records runtime_dir when built in the runtime process, and the hook resolves both paths from policy.json.
@datacas

datacas commented Oct 23, 2026

Copy link
Copy Markdown
Owner Author

Code Cycle initial review — PR #320

[CCR-20261023-001] · senior_reviewer · anthropic/claude-opus-5-5→? · high · schema:2

Verdict: APPROVED for head c79abdcab13ce56ed2cda7989d46e624809f0c35. No findings; every check of this head passed.

Summary and scope

Reviewed the accumulated diff origin/main...c79abdc (merge base 06b08dffc8ca46b5b60561a98735f83cbfe4a0c9, 166 lines, 3 files): scripts/stage_permissions.py, tests/test_stage_permissions.py, docs/host-permissions.md.

The change fixes #319: the stage hook runs a copy of stage_permissions.py from a code-cycle-policy-* directory, so deriving the validator and cycle_journal.py paths from Path(__file__) made the hook accept paths different from those the runtime advertised. StagePolicy.runtime_dir is now fixed in the runtime process (default_factory → Path(__file__).resolve().parent), serialised in policy.json by asdict, and read back by from_json (whose unknown-key check accepts it because it is a dataclass field). The prompt note, the allowedTools patterns and the hook's _check_words now all read policy.triage_validator_path / policy.permissions_command, so there is one source.

Checked beyond the diff:

  • scripts/executors.py:2496-2549 (policy_files): the runtime builds the policy, writes policy.json into a directory that must not overlap the workspace or TMPDIR, then sets it 0o500 and the file 0o400. A stage therefore cannot rewrite runtime_dir.
  • No other Path(__file__)-derived runtime path remains in stage_permissions.py; the removed _triage_validator_path() has no remaining callers.
  • A policy.json without runtime_dir falls back to the hook module's own directory, which is the previous behaviour. The runtime writes the policy and copies the hook together, so it never reads an older policy.

Findings

None.

Security triage

.code-cycle.yml declares no security_review.always_when rule, so the default triggers applied. My own reading found a sensitive change, because this module is the per-stage command-authorisation hook (security tooling). Security audit: performed inline, with the cc-security-review criteria applied in this review rather than as a separate pass.

  • Trust boundary: runtime_dir comes only from the runtime-written, read-only policy.json. An agent cannot change it.
  • No widening: the hook still accepts only the exact python3 <runtime_dir>/validate-triage-comment.py <TMPDIR>/pr-comment.md form and the exact permissions_command tuple. The new test confirms that a validator planted beside the hook copy, /elsewhere/validate-triage-comment.py, a non-pr-comment.md helper, and the permissions command rewritten to the copy's directory are all denied.
  • No confirmed vulnerabilities.

Executed verification

Command Result
python3 -m unittest discover -s tests exit 0, Ran 1767 tests … OK (includes test_a_copied_hook_allows_the_commands_the_runtime_advertises and test_the_runtime_paths_survive_the_policy_file)
python3 scripts/validate-package.py exit 0, VALID: 16 skills (7 cycle, 9 supporting), shared sections in sync, cross-agent manifests aligned
python3 -m unittest exit 0, Ran 0 tests (no discovery at the root, as the PR states)
python3 …/cycle_journal.py --database … permissions --repo datacas/code-cycle-toolkit --branch task-319 accepted by this dispatch's hook; No permission decisions are recorded as in force

Unverified

CI

CI policy: parallel. gh pr checks 320: 6 passed, 0 failed, 0 pending. The checks are Skills, manifests, and Bash installer, Windows test shard (windows-1…4) and PowerShell installer, all SUCCESS. These are every job in .github/workflows/validate.yml. release.yml does not run on pull requests.

Residual risk

  • If the runtime were ever run from the same working tree a writing stage edits, runtime_dir would point into a stage-writable path and the resolve stage could run a modified validator. Normal installs use ~/.code-cycle/runtime, outside every stage's writable roots, so this was not observed.
  • Documentation: docs/host-permissions.md updates the page that owns this behaviour. The added sentence is one over-long source line, which is cosmetic.

@datacas
datacas merged commit 41ff2c6 into main Oct 23, 2026
6 checks passed
@datacas
datacas deleted the task-319 branch October 26, 2026 09:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Stage hook resolves the triage validator and permissions command beside its own copy, denying the commands it advertises

1 participant