Skip to content

feat(#497): sequant init --agent codex — .agents/skills symlink, .codex hooks wrapper, doctor, README #1059

Closed

Description

@admarble

Epic: #497 Blocked by: #1058 Tier: mechanical Doc: docs/investigations/codex-driver-probe-2026-09.md §AC-2, §AC-4, "What changes in #497" Graph node: 2 of 3

Summary

Everything a downstream project needs on disk for the Codex driver to find sequant's skills and run sequant's guard hooks. No new hook scripts — the probe showed Codex's PreToolUse stdin payload is a superset of Claude Code's (tool_name: "Bash", tool_input.command, cwd, session_id), so the existing .claude/hooks/*.sh are wired behind a Codex config wrapper.

Design constraints (from the probe)

  • Skills: a relative in-repo symlink .agents/skills -> ../.claude/skills. All 19 skills are discovered under bare names this way; an absolute symlink into another checkout gets namespaced <repo-dir>:<name> and breaks $<phase> invocation (doc §AC-2).
  • Hooks: .codex/config.toml with [[hooks.PreToolUse]] / [[hooks.PostToolUse]] entries whose command points at the existing scripts. Project-layer hooks only load when the project is trusted ([projects."<abs path>"] trust_level = "trusted" in the user config) — init must say so, since an untrusted repo's hooks are skipped with zero output.
  • Sync: the symlink must survive sequant update/sync (copy-mode currently leaves foreign symlinks alone but must not delete or dereference this one).

Acceptance criteria

  • AC-1: symlink — Verify: sequant init --agent codex in a temp git repo creates .agents/skills as a symlink whose target reads exactly ../.claude/skills (readlink .agents/skills); re-running is idempotent (no error, no change).
  • AC-2: hooks wrapper from one template — Verify: init writes .codex/config.toml containing PreToolUse and PostToolUse command hooks pointing at .claude/hooks/pre-tool.sh / post-tool.sh; grep -rl 'hooks.PreToolUse' src templates | wc -l → the template lives in exactly one place; .claude/hooks/*.sh unchanged (git diff --stat -- .claude/hooks templates/hooks empty).
  • AC-3: payload compatibility (gate test) — Verify: npx vitest run -t "497 AC-3": feeding the recorded Codex PreToolUse payload from the doc §AC-4 (with tool_input.command swapped to git push --force) to pre-tool.sh exits 2; with echo ok exits 0. Mutation-verified per the repo rule.
  • AC-4: doctor — Verify: npx vitest run src/commands/doctor.test.ts -t "codex": with run.agent: "codex" doctor checks the binary, the CODEX_MIN_VERSION floor, and auth (CODEX_API_KEY set or codex login status reports logged in), failing with an install/login hint otherwise.
  • AC-5: trust notice — Verify: init's completion output and the README section both state the trust_level = "trusted" requirement with the exact TOML; -t "497 AC-5" asserts the string in init output.
  • AC-6: sync preserves the symlink — Verify: -t "497 AC-6": after sequant update (copy and symlink modes) in the temp repo, readlink .agents/skills still reads ../.claude/skills and .agents/skills/qa/SKILL.md resolves.
  • AC-7: README — Verify: the multi-agent section gains a Codex subsection covering install, CODEX_API_KEY vs codex login, the symlink, trust, and why the driver passes --dangerously-bypass-hook-trust (sequant generates the hooks it vets); content check, not file-existence.
  • AC-8: --agent codex end-to-end dry run — Verify: in the temp repo after init, node dist/bin/cli.js run 1 --agent codex --dry-run resolves the driver and prints the $spec 1 prompt.

Non-goals

Codex MCP config ([mcp_servers] pointing at sequant serve) and .codex/agents subagent definitions — wait for the gate. Windows symlink semantics — note as a limitation, do not solve.

Related

#497 (epic) · #1058 (driver core) · #990/#991 (sync clobbering, foreign symlinks) · #1057 (probe doc)

Activity

  1. added
    enhancement
    planned
    multi-agent
    backlog
    on Sep 14, 2026
  2. admarble commented on Sep 15, 2026

    @admarble
    ContributorAuthor

    Context for the phase agents (graph-run, 2026-09-15)

    Repo state since this issue was written — #1058 merged as bf35818 (PR #1062):

    • CODEX_MIN_VERSION ("0.154.0") and the version-floor check already live in src/lib/workflow/drivers/codex.ts — import them for AC-4, do not redefine. The driver already passes --dangerously-bypass-hook-trust (AC-7 README explains why; see the header comment in codex.ts).
    • Precedent to mirror: opencode. src/commands/init.ts (writeOpencodeCommands / writeOpencodeAgents, one template under templates/opencode/) and src/commands/doctor.ts (OPENCODE_MIN_VERSION import, opencode checks). Codex should follow the same shape: one template under templates/codex/, a writer in init, a doctor block keyed on run.agent: "codex".
    • bin/cli.ts --agent <name> help text on init lists (claude-code, aider, opencode) — add codex there too.
    • AC-3 payload: use the recorded Codex PreToolUse stdin payload verbatim from docs/investigations/codex-driver-probe-2026-09.md §AC-4 as a fixture; swap only tool_input.command.

    Hard constraints (from the probe — do not re-derive)

    • Symlink must be relative: .agents/skills -> ../.claude/skills. An absolute target into another checkout namespaces skills as <repo-dir>:<name>.
    • Project-layer Codex hooks load only when the repo is trusted in the user config ([projects."<abs path>"] trust_level = "trusted"); untrusted = silently skipped. That's why AC-5 exists.
    • .claude/hooks/*.sh and templates/hooks/*.sh must be unchanged (AC-2).
    • sequant does not load .env; nothing in this issue should need a live CODEX_API_KEY — keep tests hermetic.

    Execution rules (MCP 30-min phase wall)

    • Commit chore(#1059): wip checkpoint roughly every 10 minutes of exec work.
    • Run the full suite once, in the foreground, wrapped in timeout, after a WIP commit. No run_in_background / Monitor.
    • AC-3 is a gate test: commit first, then mutation-verify (break the payload/exit path, confirm exactly the 497 AC-3 test fails, restore) and put the Mutation-verified: AC-3 — … record plus the <!-- SEQUANT_MUTATION: … --> anchor in the PR body.
    • AC-8 needs npm run build in the worktree before node dist/bin/cli.js.
    • Fresh worktrees can miss native npm deps — if many unrelated tests fail, check node_modules and the Node version (≥22.13) before trusting the failures.
  3. admarble commented on Sep 15, 2026

    @admarble
    ContributorAuthor

    /spec Plan — #1059

    Complexity: Standard (8 ACs)

    AC Checklist + Verification

    • AC-1 (Integration Test): .agents/skills relative symlink to ../.claude/skills, idempotent re-run.
    • AC-2 (Integration Test): .codex/config.toml hooks wrapper from one template; .claude/hooks/*.sh unchanged.
    • AC-3 (Integration Test, gate/mutation-verified): recorded Codex PreToolUse payload through pre-tool.sh — force-push blocked, benign command passes.
    • AC-4 (Unit Test): doctor checks codex binary, CODEX_MIN_VERSION (imported, not redefined), and auth.
    • AC-5 (Integration Test): init output + README state the exact trust_level = "trusted" TOML.
    • AC-6 (Integration Test): sequant update preserves the symlink in both symlink and --no-symlinks modes.
    • AC-7 (Manual/content check): README Codex subsection — install, auth, symlink, trust, --dangerously-bypass-hook-trust rationale.
    • AC-8 (Integration Test): run 1 --agent codex --dry-run resolves the (already-registered) CodexDriver and prints the spec prompt.

    Implementation Plan

    1. Provisioning (init.ts): writeCodexProvisioning() — relative symlink + .codex/config.toml, mirroring writeOpencodeCommands/writeOpencodeAgents. Add templates/codex/ → null in templateDestination() (templates.ts) so sync/diff doesn't flag it as drift.
    2. Doctor (doctor.ts): codex block mirroring the opencode block — binary, CODEX_MIN_VERSION floor, auth (env or codex login status), never logging the key value.
    3. README (README.md): Codex subsection in Prerequisites, alongside Aider/opencode.
    4. Tests: temp-repo integration tests for AC-1/2/5/6/8, doctor unit test for AC-4, mutation-verified gate test for AC-3.

    Key Decisions

    • No new hook-guard logic — the existing .claude/hooks/*.sh scripts are reused as-is; Codex's PreToolUse payload is already a superset (per the feat: add OpenAI Codex CLI agent driver #497 probe).
    • .agents/skills symlink is unconditional — no copy-fallback (a copy would break Codex's skill discovery, not just degrade it); Windows is an explicit non-goal.
    • Scope tool's automated SCOPE_SPLIT_RECOMMENDED verdict is overridden — the "3 features" it detected are a keyword-clustering artifact on Verify: command text, not independent deliverables. Keeping this as one issue; quality loop stays enabled given real AC count (8).

    Open Questions

    1. Foreign-file handling for .agents/skills (exists but not the expected symlink) — recommend warn-and-skip with --force override, matching existing copyTemplates precedent.
    2. Whether --no-symlinks should affect .agents/skills — recommend no; it's unconditional given no valid copy-fallback semantics exist for it.

    Phases: testgen → exec → qa
    Quality Loop: enabled

  4. admarble commented on Sep 15, 2026

    @admarble
    ContributorAuthor

    Resume note (graph-run) — the first exec hit the MCP 30-minute phase wall

    The worktree was reaped, but the wip-checkpoint discipline worked: three commits survive on feature/1059-feat-497-sequant-init-agent-codex-agents-skills-sy (dd93559c, f4dc4e77, 20ee1ff1) — 710 insertions across init, doctor, the codex config template, README and tests. Start from that branch; do not redo the implementation.

    Coverage already on the branch: AC-1/AC-2/AC-6 (src/commands/init.codex.integration.test.ts), AC-3 (__tests__/pre-tool-hook.integration.test.ts), AC-4 (src/commands/doctor.test.ts), AC-5 (src/commands/init.test.ts), AC-7 (README), AC-8 (src/commands/cli.integration.test.ts).

    What is left:

    1. npm run build in the worktree, then run the suite once, foreground, under timeout — after a wip commit.
    2. Mutation-verify AC-3 (git status --short | wc -l must be 0 first): break the codex payload handling, confirm exactly the 497 AC-3 tests fail, restore, and put the Mutation-verified: AC-3 — … record plus the <!-- SEQUANT_MUTATION: … --> anchor in the PR body.
    3. Fix whatever the suite surfaces, then open the PR.

    Keep committing chore(#1059): wip checkpoint every ~10 minutes — this phase died at the wall once already.

  5. added 2 commits that reference this issue on Sep 15, 2026
  6. admarble commented on Sep 15, 2026

    @admarble
    ContributorAuthor

    QA round 2 — AC_NOT_MET (posted by graph-run; the QA phase itself posted nothing to this issue in either round)

    PR #1066. Round 1 blocked on the mutation records; those are fixed and re-verified (AC-1/AC-3/AC-5 markers now classify valid through the repo's own classifyMutationMarker, with the AC-3 mutation re-done against the codex payload fixture instead of the shared hook). Round 2 blocks on one substantive finding.

    F1 (blocking) — AC-8: the codex path never emits $spec

    AC-8 reads "prints the $spec 1 prompt". The codex run emits the Claude-shaped prose prompt (Run the /spec 1 workflow.) from phase-registry.ts's default promptTemplate; nothing in src/ or bin/ ever emits $spec. driverOverrides exists but registers aider only.

    This is not notation drift. The founding doc says so in two places — line 13 ("Does explicit $skill work in headless codex exec? Yes → symlink .agents/skills → ../.claude/skills; resolvesSkills = true") and §"What changes in #497" P0 line 296 ("Prompt is $<phase> <issue> — the skill name, not a rewritten prompt"). If codex is sent /spec 1 as prose, the .agents/skills symlink this issue exists to create is never exercised.

    The AC-8 test at src/commands/cli.integration.test.ts:378 asserts "/spec 1" and adds a --verbose flag the AC's command does not carry — written to the implementation's output rather than the AC's text, which turned a product question into a green checkbox.

    Note the same doc line rules out the obvious fix shape: "Drop CODEX_PHASE_PROMPTS / driverOverrides.codex" — so copying the aider driverOverrides pattern across all eight phases contradicts the design the probe settled on. The prompt should come from the driver, not from per-phase overrides. This is a design call, so it is parked here for a human decision rather than patched.

    F4 (documented) — doctor runs zero codex checks after the documented setup path

    init never persists run.agent, so after sequant init --agent codex the run.agent key is unset and doctor emits neither the codex CLI nor the codex auth check. The README this PR adds states "sequant doctor checks for either" — true only if the user hand-edits .sequant/settings.json. Pre-existing pattern shared with --agent opencode, so not a regression, but this PR's README makes it newly user-visible.

    Also documented, not fixed

    • AC-2's literal grep (grep -rl 'hooks.PreToolUse' src templates | wc -l) now returns 3, not 1 — the extra hits are a JSDoc comment describing the check and the test asserting it. The substantive requirement (one real TOML template) holds and the test filters to /templates/ first.
    • AC-6's stated verify command (-t "497 AC-6") runs feat(#497): CodexDriver core — subprocess codex exec --json, SDK-typed parser, three-level outcome evaluator #1058's tests, not this issue's, which are named 1059 AC-6. The AC's own command proves nothing about symlink preservation; the correct command is npx vitest run src/commands/init.codex.integration.test.ts.
    • AC-7 (README) has no gate test and no mutation record.
    • templates/codex/ null-routing has no direct templateDestination test.
    • getCodexVersion / isCodexAuthenticated call execSync with no timeout (mirrors the pre-existing getOpencodeVersion).

    Verified green

    Full suite re-run in the worktree after the fixes: 317 files, 6424 passed, 0 failed, 1 expected fail, 3 skipped. Lint, build and tsc clean.

  7. added 2 commits that reference this issue on Sep 16, 2026
  8. admarble commented on Sep 16, 2026

    @admarble
    ContributorAuthor

    QA Verdict: AC_MET_BUT_NOT_A_PLUS

    AC coverage: 0/1 met

    Gaps:

    • createSymlink's failure return is discarded, so on Windows without privileges init reports a symlink it did not create and codex skill discovery silently fails
    • The issue's Non-Goal to note the Windows symlink limitation was not followed anywhere in docs or code
    • The F4 run.agent persistence fix has no automated coverage and was verified only by hand
    • Orphaned JSDoc block left by the round-3 insertion
    • A hanging codex binary would hang sequant doctor indefinitely
    • AC-2's prescribed measurement diverges from its stated requirement; only one hit is a real template so the requirement holds
    • AC-6's stated verification command selects the wrong tests and names an update flag that does not exist; the underlying requirement was verified by other means
    • createSymlink's return value is discarded — src/commands/init.ts. createSymlink (src/lib/fs.ts:101) returns false on EPERM/EACCES instead of throwing, signalling "caller should fall back to copy". writeCodexSkillsSymlink calls await createSymlink(...) and unconditionally return "created". Its sibling consumer copyTemplates (src/lib/templates.ts:546) does check the boolean (const symlinkCreated = await createSymlink(...)). On Windows without privileges, init would print ✔ Symlinked .agents/skills -> ../.claude/skills with no symlink on disk, and codex skill discovery would silently fail. This is the same "claims work it had not done" defect the PR already fixed for the idempotent-re-run path; the EPERM branch is the missed sibling. The status union has no failure variant to express it.
    • The Windows limitation is not noted anywhere. The issue's Non-goals say "Windows symlink semantics — note as a limitation, do not solve." Solving is correctly out of scope, but the note is missing: no Windows caveat in the README's Codex subsection, none in init's output, none in writeCodexSkillsSymlink's JSDoc. Checking the boolean and warning is not "solving Windows symlink semantics" — it is declining to report success that did not happen.
    • createDefaultSettings(agent) (the F4 fix) has no automated test. init.test.ts mocks createDefaultSettings, so nothing asserts that initCommand forwards options.agent, and no test covers generateSettingsJsonc's new conditional "agent" line. This behavior is load-bearing for the README's claim that doctor checks codex auth. I confirmed it manually (generated settings carried "agent": "codex", and a real doctor run consequently emitted both codex checks), so it works — but it is unpinned against regression.
    • Orphaned JSDoc — src/lib/workflow/phase-executor.ts:1269. The new tryBuildSkillPrompt JSDoc was inserted between resolveDriverName's existing JSDoc and the new function, so resolveDriverName now has no doc comment and tryBuildSkillPrompt carries two stacked blocks, the first describing a different function. Cosmetic, mechanical to fix.

    Suggestions:

    • Add a "symlink-unsupported" status to CodexSkillsSymlinkStatus, returned when createSymlink yields false, and warn with a pointer to the Windows limitation. That satisfies the Non-goal's "note as a limitation" without solving it.
    • Add one test asserting createDefaultSettings("codex") writes "agent": "codex", and one asserting initCommand({agent:"codex"}) forwards it (un-mock or spy on the argument).
  9. added 2 commits that reference this issue on Sep 16, 2026
  10. admarble commented on Sep 16, 2026

    @admarble
    ContributorAuthor

    QA round 3 — AC_MET_BUT_NOT_A_PLUS (posted by graph-run; the QA phase again posted nothing to this issue)

    All eight ACs met. Four quality gaps, all fixed in f6da00f6, plus one process problem worth recording.

    Fixed

    1. createSymlink's return value was discarded. It answers EPERM/EACCES (Windows without privileges) with false rather than throwing — the case its sibling consumer copyTemplates handles with a copy fallback. writeCodexSkillsSymlink returned "created" regardless, so init would print ✔ Symlinked .agents/skills -> ../.claude/skills with no symlink on disk, and codex skill discovery would fail silently. Now a distinct "unsupported" status with a warning naming the cause. No copy fallback here: a copied skill tree goes stale the moment .claude/skills changes. Mutation-verified.
    2. The Windows limitation was noted nowhere — the issue's Non-goals ask for it to be noted, not solved. Added to the README's Codex subsection and to the JSDoc.
    3. The F4 settings fix was unpinned (init.test.ts mocks createDefaultSettings). Now tested: init forwards --agent, and generateSettingsJsonc emits run.agent only when set.
    4. resolveDriverName's JSDoc had been left attached to the wrong function by the round-2 commit.

    Process: the QA phase rebased a pushed branch

    The run log records ✔ Branch rebased onto origin/main. Main had advanced to #1065, and the rebase rewrote seven already-pushed commits — landing them would have required a force-push, which this repo's hooks block and its convention forbids. Undone: reset to the pushed branch, then git merge origin/main (35dc1109). Content is identical either way. A QA phase rewriting pushed history is a bug worth filing against sequant.

    Related: the QA phase has now finished three times on this issue and posted its review to the issue in none of them. The verdict reaches the run log and .sequant/state.json, but a reader of the issue sees nothing. Worth filing alongside the rebase.

    Verified by hand, end to end

    In a scratch repo, against the built CLI from the worktree:

    • AC-1 readlink .agents/skills → ../.claude/skills; re-run reports already in place (no false "Symlinked" claim).
    • AC-2 .codex/config.toml carries both hook tables pointing at the unmodified guard scripts.
    • AC-4 after a plain init --agent codex, doctor emits both the codex CLI and codex auth checks (it emitted neither before the F4 fix).
    • AC-5 init's output prints the exact [projects."<path>"] trust_level = "trusted" TOML.
    • AC-6 after sequant update, the symlink still reads ../.claude/skills and .agents/skills/qa/SKILL.md resolves.
    • AC-8 run 1 --agent codex --dry-run → Driver: codex / Would execute: $spec 1 (and $exec 1 for the next phase) — the AC's command verbatim, no --verbose.

    Full suite: 318 files, 6432 passed, 0 failed, 1 expected fail, 3 skipped. Five mutation records (AC-1, AC-1b, AC-3, AC-5, AC-8) all classify valid through the repo's own classifyMutationMarker.

    PR #1066 is ready for a merge decision. Gate #1060 stays parked for a human.

  11. added a commit that references this issue on Sep 16, 2026
  12. admarble commented on Sep 16, 2026

    @admarble
    ContributorAuthor

    Correction to my round-2 and round-3 notes

    I wrote twice above that the QA phase posted nothing to this issue. That was wrong for round 3: it posted a full ## QA Verdict: AC_MET_BUT_NOT_A_PLUS comment at 01:58:42Z, ten minutes before my summary claiming it hadn't. I had checked the thread before that round finished and never re-checked.

    The accurate behavior, now filed as #1070: postQaVerdictComment is gated on result.success && result.verdict (batch-executor.ts:1758). AC_NOT_MET makes the phase a failure, so rounds 1 and 2 posted nothing, while round 3's passing verdict posted normally. Failing reviews are suppressed; passing ones are not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    backlogenhancementmulti-agentplanned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions