Skip to content

dev: add Codex Cloud Worktrunk setup - #978

Merged
max-sixty merged 6 commits into
mainfrom
codex/codex-cloud-worktrunk
Aug 14, 2026
Merged

max-sixty merged 6 commits into
mainfrom
codex/codex-cloud-worktrunk

Conversation

@max-sixty

@max-sixty max-sixty commented Aug 13, 2026 •

Copy link
Copy Markdown
Owner

Add a repo-owned Codex Cloud setup command that installs pinned Worktrunk, verifies Tend's project-command approvals, syncs the generator, site, and worker dependencies, and installs pre-commit without installing Git hooks. Document the Cloud environment settings and validation command, expose CLAUDE.md to Codex through an AGENTS.md symlink, and include the setup script in shellcheck.

The symlink exposed unsafe fork-controlled instruction-file writes in the Codex action. Move that step into a tested script that restores files through Git without following destination symlinks, preserving trusted base-branch symlinks while preventing writes outside the checkout.

Tested with 549 Python tests, 31 worker tests, worker typecheck, pre-commit run --all-files, and an isolated execution of the Cloud script that installed Worktrunk 0.73.0 and reported every .config/wt.toml command approved.

This was written by Codex on behalf of max-sixty

@tend-agent tend-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The AGENTS.md symlink makes an existing symlink-unsafe path in codex/action.yaml reachable. Its Pin instruction files to base branch (fork PRs) step iterates find . -name AGENTS.md and does cp "/tmp/base-agents.md" "$f" — cp follows a symlink destination, so on a fork PR under the Codex harness the root AGENTS.md -> CLAUDE.md link makes that write land in CLAUDE.md, replacing the guidance the step pinned two lines earlier with the literal string CLAUDE.md. The step exists to preserve the instruction file against fork-controlled content, and against this layout it destroys it instead.

The destination is fork-controlled too: a fork can repoint AGENTS.md at any path and the step writes base-tree content there — including $HOME/.codex/AGENTS.md, which the earlier Stage AGENTS.md step just wrote, so a fork can strip tend's staged system prompt before the session starts. Same shape at cp /tmp/base-claude.md CLAUDE.md a few lines up (a fork can make CLAUDE.md the symlink), and at the restore loop's git show ... > "$rel", which fires on a dangling link because [ ! -f "$rel" ] is true for one.

Tend's own workflows run the Claude harness today, so nothing is live here — but AGENTS.md -> CLAUDE.md is a common adopter layout, so the action's exposure isn't specific to this repo. The fix is rm -f on each destination before writing (or cp --remove-destination) in all three places. Happy to push that here, or open it separately against codex/action.yaml if you'd rather keep this PR to the Cloud setup.

Two smaller things, both inline:

  • The README's "keep its approved-commands list identical to the hooks and aliases in .config/wt.toml" rule has no enforcement, and both ways it can break are silent — a drifted list, or .project.identifier coming back absent so the heredoc emits [projects.null] and approves nothing under the real project key. Either way the container looks set up and the first unattended wt switch fails on approval instead. The rebase onto #977 already forced one hand-edit of that list, which is the drift case arriving on day one. Worktrunk exposes the check directly — wt config approvals list --format=json, whose state its own docs describe as the field a caller branches on before an unattended run.
  • The rebase dropped doesn't see them. Run from the shellcheck comment, leaving ...built-in shellcheck / shellcheck directly to keep that coverage.

Unrelated to correctness: WORKTRUNK_VERSION=0.71.0 is behind the current v0.73.0, and isn't in running-tend's weekly pin-bump table, so it'll only move when someone notices.

Comment thread .config/codex-cloud/environment.sh Resolved
Comment thread .pre-commit-config.yaml Resolved
@tend-agent

Copy link
Copy Markdown
Collaborator

All three land — thanks. The git restore route does close the escape, and I checked one case beyond the new test: a fork that replaces a base AGENTS.md's parent directory with a symlink pointing outside the checkout. git replaces the symlink with a real directory and writes the trusted content inside it, so the outside file is untouched there too.

One small pre-existing divergence I noticed while reading the new script, not a blocker: it pins to repository.default_branch, while the Claude harness's restore-sensitive-config.sh uses the PR's own pull_request.base.ref. On a PR whose base isn't the default branch, the Codex step restores the default branch's instruction files and deletes any AGENTS.md the base branch carries but the default doesn't. Both refs are base-repo controlled, so it's a question of which trusted tree wins rather than a hole — it just predates the move into a script, and now there's a test file to pin it in.

What I ran

Workspace at 593810f.

uv run pytest generator/tests/test_shared_steps.py -q — 67 passed, including test_pin_instruction_files_does_not_follow_fork_symlinks.

The leading-directory variant, on git 2.54.0: base tree has CLAUDE.md, AGENTS.md -> CLAUDE.md, nested/AGENTS.md; the fork commit does git rm -r nested then ln -s /outside nested, where /outside/AGENTS.md holds sentinel content.

Pinned CLAUDE.md to main
Pinned AGENTS.md to main
Pinned nested/AGENTS.md to main
--- outside file content:
must not change
--- nested is:
drwxrwxr-x 2 ... nested
trusted nested

find -P never descends the symlink, so the removal loop skips it; the restore loop's mkdir -p hits EEXIST, and git's own checkout path unlinks the symlink and creates a real directory rather than writing through it.

Refs: pin-instruction-files.sh#L9 vs restore-sensitive-config.sh#L31.

@tend-agent tend-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The symlink fix holds, and I checked the mechanism rather than taking git restore on trust: on git 2.54 it unlinks the destination instead of writing through a fork-controlled symlink, and it replaces a symlinked leading directory with a real one, so neither the file case nor the directory case escapes the checkout. Dropping the || true on the restore loop makes it fail-closed too. The Cloud script's @json project key, the state == approved gate, and the 0.73.0 pin all check out against Worktrunk's own JsonApprovals/Approvals types — state is a top-level string, and both sides of the approval comparison run through normalize_template_vars, so the hand-written templates match. The approved-commands list is currently identical to .config/wt.toml's four hooks and four alias commands.

One new finding and two smaller ones, all inline and all in the restore path. The substantive one: mkdir -p is the only line in that loop a fork can make fail, and it isn't doing anything git restore doesn't already do itself.

Separately — not part of this diff, and no action needed: I checked whether the new root AGENTS.md symlink opens the same vector under the Claude harness that tend actually runs. It doesn't. Claude Code reads CLAUDE.md, not AGENTS.md (docs), and restore-sensitive-config.sh already pins CLAUDE.md by rm -rf + git checkout, which is symlink-safe by the same argument as above.

Comment thread shared/steps/pin-instruction-files.sh Resolved
Comment thread shared/steps/pin-instruction-files.sh Resolved
Comment thread shared/steps/pin-instruction-files.sh Resolved
@tend-agent

Copy link
Copy Markdown
Collaborator

All three are in at 1e83cbd. I checked the expanded test actually pins the behaviour rather than passing either way: reverting rm -rf back to rm -f fails the run with rm: cannot remove './directory/AGENTS.md': Is a directory, and putting the mkdir -p back fails with mkdir: cannot create directory 'nested': File exists — so each new fixture case maps to one of the two fixes. The core.quotepath=off removal is behaviour-neutral by construction, so nothing covers it, as expected. uv run pytest generator/tests/test_shared_steps.py is green (67 passed).

@tend-agent tend-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The three applied fixes hold, and I re-derived the mechanism rather than trusting the commit message: on git 2.54 git restore replaces a fork-committed directory at AGENTS.md with the base symlink (children and all), replaces a file or an outside-pointing symlink standing in for a trusted parent directory with a real directory, and writes through none of them. rm -rf on a symlink unlinks the link, not its target. ls-tree -z never quotes, so dropping core.quotepath=off is a no-op as expected. uv run pytest generator/tests/test_shared_steps.py -q — 67 passed at 1e83cbd.

One new finding, inline: the rm -f on line 18 is the same directory case you just fixed in the loop below, and it was left behind. It fails closed rather than open — the step exits non-zero and the session never starts — so it's a fork-triggerable nuisance, not a hole. Worth folding the case into test_pin_instruction_files_does_not_follow_fork_symlinks too, since the test's base tree currently always carries a CLAUDE.md and so never reaches that branch.

What I ran

Base tree with no CLAUDE.md, fork commits CLAUDE.md/ as a directory:

rm: cannot remove 'CLAUDE.md': Is a directory
EXIT=1

I also probed the one thing rm -rf inside a find | while pipeline could plausibly break — find erroring out after the consumer deletes a directory it just printed, which pipefail would turn into a failed step. It doesn't: GNU find holds the directory fd across the print, so even with stdbuf -o0 forcing an unbuffered stream and a 2000-entry AGENTS.md/ directory, the pipeline exits 0 with empty stderr. No change needed there.

Cases I ran clean against the current script, all fork-side: AGENTS.md directory replacing the base symlink (restored, AGENTS.md/child gone); dangling symlinks at both a base-tracked docs/AGENTS.md and an untracked root AGENTS.md; CLAUDE.md directory where the base does have CLAUDE.md.

Comment thread shared/steps/pin-instruction-files.sh Resolved
@max-sixty
max-sixty merged commit d62bce5 into main Aug 14, 2026
15 checks passed
@max-sixty
max-sixty deleted the codex/codex-cloud-worktrunk branch August 14, 2026 00:42
max-sixty added a commit that referenced this pull request Aug 14, 2026
The weekly bump section was a table of four action inputs, so every other pin in the repo drifted unswept — a pin entered scope only when someone remembered to add a row for it, and `WORKTRUNK_VERSION` arrived exactly that way in #978. What the closed table was hiding, measured on this tree: ruff `v0.14.11` → `v0.16.3`, uv-pre-commit `0.7.12` → `0.12.4`, typos `v1.42.0` → `v1.49.0`, vitest 2 → 4, typescript 5 → 7, wrangler 4.90 → 4.123, astro 5 → 7, plus the `uv_build` range that has excluded the local uv since 0.12.

Each ecosystem now enumerates its own pins, so the next one added shows up without an edit to this file:

```bash
yq -r '.inputs | to_entries[] | select(.key | test("_version$")) | ...' */action.yaml
git grep -nE '(==|~=|<=?)[0-9]' -- '*pyproject.toml'   # freeze-pins; floors like click>=8.0 stay
uv lock --upgrade --dry-run
uvx pre-commit autoupdate
npm --prefix worker outdated; npm --prefix site outdated
git grep -nE '^[A-Za-z_]*VERSION=' -- '*.sh'
```

The table survives only for pins whose rule isn't "move to latest and let CI decide" — `claude_version` tracking `latest` over `stable`, mitmproxy dragging the workspace `==` pin with it — and, after the review, for every pin CI can't verify at all: `uv_build`'s stale range only *warns* during `uv build`, `publish-site.yaml` builds `site/` on push to main rather than on the PR, and nothing anywhere runs `.config/codex-cloud/environment.sh`, which dies under `set -euo pipefail` in a maintainer's Codex Cloud setup rather than in a job. Those three were carved out in three different places in the first push; they're one table now, so the default rule means what it says. The PR-splitting rule that used to sit under `uses:` refs (ships-to-adopters / ours-alone) now governs all pins, with majors getting their own PR from either bucket.

`WORKTRUNK_VERSION` is the test of whether the frame works: #978's row and `sed` lookup are gone, and the shell-script sweep finds the pin on its own. It keeps a row, but for what CI can't check rather than for existing.

Runner images, `node-version` and `requires-python` are named as out of scope rather than silently omitted — platform choices carrying their own rationale, moved when a reason arrives.

<details>
<summary>Verification</summary>

Every command run against this tree before it went in:

- the `yq` sweep prints all four action inputs with their file
- the Python grep returns exactly the two freeze-pins (`mitmproxy==`, `uv_build`'s cap) and no floors or `requires-python`
- `uvx pre-commit autoupdate` works with only uv installed (the weekly job's whole toolchain) — run against a scratch copy of the config, which is where the three rev numbers above come from
- `npm outdated` exits 1 with rows, which is why the comment says so
- the shell-script grep returns `WORKTRUNK_VERSION` and nothing else
- `uv build --package tend` warns on the stale `uv_build` range and still succeeds, so the "only this sweep catches it" claim is the observed behavior
- `pre-commit run --all-files` passes

</details>

> _This was written by Claude Code on behalf of max-sixty_
max-sixty added a commit that referenced this pull request Aug 14, 2026
Release 0.1.17: the version bump, the lockfile sync, and the
`CHANGELOG.md` section that `pypi-release.yaml` publishes verbatim as
the release notes.

8 commits since 0.1.16. On the shipped surface: `tend check` reads the
bot's own bypass verdict where GitHub withholds the ruleset actor list,
so `credential-environments` resolves instead of parking at SKIP on
every adopter whose credential environments admit tags (#976); the
Codex harness pins `.claude/` to the base branch on a fork PR, and
restores instruction files through git without following destination
symlinks (#978, #980); and 👀 now means one thing across triage,
review, and mention — a session is working on this — released under
`always()` when the run ends (#974, #979).

After merge: tag `0.1.17` to publish, then regenerate tend's own
workflows with `uvx tend@latest init` and restamp
`review-reviewers.yaml`, whose action pin `init` never rewrites.

> _This was written by Claude Code on behalf of max-sixty_

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
max-sixty added a commit that referenced this pull request Aug 14, 2026
Release 0.1.17: the version bump, the lockfile sync, and the
`CHANGELOG.md` section that `pypi-release.yaml` publishes verbatim as
the release notes.

8 commits since 0.1.16. On the shipped surface:

- **`tend check` resolves `credential-environments` from the bot's own
token** ([#976](#976)). GitHub
serves a ruleset's `bypass_actors` only to repo admins, so the check
parked at SKIP on every adopter whose credential-holding environments
admit tags, and the nightly's drift issue stayed open indefinitely.
- **The Codex harness pins `.claude/` to the base branch on a fork PR**,
and restores instruction files through git without following destination
symlinks ([#978](#978),
[#980](#980)).
- **👀 means one thing across triage, review, and mention** — a session
is working on this — and is released under `always()` when the run ends
([#974](#974),
[#979](#979)).

Verified ahead of the tag: the in-tree generator's `check`, run under
each repo's own bot token, reports 8/8 PASS on `max-sixty/worktrunk`,
`numbagg/numbagg`, and `max-sixty/cargo-affected`, where published
0.1.16 under the same tokens reports the `credential-environments` SKIP
those three drift issues track
([worktrunk#3729](max-sixty/worktrunk#3729),
[numbagg#716](numbagg/numbagg#716),
[cargo-affected#34](max-sixty/cargo-affected#34)).
Their nightlies close the issues on an all-PASS run.

After merge: tag `0.1.17` to publish, then regenerate tend's own
workflows with `uvx tend@latest init` and restamp
`review-reviewers.yaml`, whose action pin `init` never rewrites.

> _This was written by Claude Code on behalf of max-sixty_

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
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.

2 participants