Skip to content

Codex/OpenCode lead parity, per-role OpenCode sessions, task branches - #2

Closed
abdoharb wants to merge 11 commits into
MShokry:mainfrom
abdoharb:per-role-sessions
Closed

abdoharb wants to merge 11 commits into
MShokry:mainfrom
abdoharb:per-role-sessions

Conversation

@abdoharb

@abdoharb abdoharb commented Oct 8, 2026

Copy link
Copy Markdown

What changed

Brings the Codex lead to near-parity with the Claude lead, adds an OpenCode lead path, and changes the OpenCode session policy. Full detail is in CHANGELOG.md → Unreleased.

Session and branch model ([contract], migration migrations/04-per-role-sessions.md)

  • OpenCode sessions are now scoped per role per task. The state file's single OpenCode session id is replaced by builder / reviewer / tester session ids (plus Codex tester thread id).
  • Why: on opencode v2 a session pins the tool set of the agent that opened it, so a tester dispatched into the builder's session couldn't write its results. A shared session also gave the reviewer the builder's reasoning, which weakens review independence.
  • Every task gets its own branch (T-<id>-<slug>) before an implementer runs.
  • init.sh --builder-auto ask|on records a standing decision for the builder's --auto.

Codex lead parity

  • scripts/bg-dispatch.sh (start / wait) runs dispatches detached. Codex has no background-watch tool, so without it dispatches die at the lead's exec timeout.
  • scripts/claude-review.sh runs a claude/* reviewer headlessly with a read-only tool list, for leads that can't spawn Claude subagents.
  • oc.sh --status / --interrupt (v2 endpoints) replace raw opencode api calls in the flow.
  • New optional Codex tester role (--tester-model codex/<model> → .codex/agents/tester.toml).
  • codex-preflight.sh checks the new wrappers, the Codex tester, and Claude reviewer prerequisites.
  • The Codex feature skill gains matching adaptations: no Monitor, no structured question tool, headless Claude review, per-task branches, sandboxed oc.sh.

Canonical flow additions (all three flow copies)

  • Where the team stopped status check, the merge record, and the mid-task model/implementer switch procedure.
  • Verify a role's "concurrent writer" claim before acting on it.
  • The exact ### Pass N verdict heading.
  • What to do when the lead can't spawn the configured tester.

OpenCode lead

  • leader and planner adapters plus /feature and /toolkit-update commands pointing at the canonical flow.

Fixes

  • promote-findings.sh skips a directory tag instead of aborting and dropping later findings.
  • Dispatch traces (.pipeline/T-*.{out,err,pid,brief}) are gitignored.
  • ShellCheck cleanups.

Verification

Run locally on this branch:

  • bash test/smoke.sh: all 38 checks pass
  • bash test/invariants.sh: all 135 (rule, file) pairs present
  • bash test/codex.sh: all behavioral checks pass (CLI doubles, no model calls)
  • python3 test/herdr.py: OK

Not done: no live end-to-end pipeline run against a real OpenCode server or a live Codex lead. docs/CODEX.md → Verification lists the manual scenarios.

Reviewer notes

  • Breaking state-file contract change. Downstream projects need migrations/04-per-role-sessions.md.
  • Known remaining Codex gaps (follow-up, not in this PR):
    • No Codex-native implementer or read-only reviewer agent.
    • Each sandboxed oc.sh / bg-dispatch.sh call needs runtime approval.
    • No automatic usage-limit retry under Codex.
    • The session hook only pins the id; it doesn't surface active tasks on resume.
    • tester.toml duplicates the tester rules inline and isn't covered by test/invariants.sh.
    • First-run customization skips .codex/agents/.
  • Supersedes the closed Codex lead parity #1 (Codex lead parity); its commits are included here.

🤖 Generated with Claude Code

abdoharb and others added 11 commits October 4, 2026 22:17
Make the generated Codex lead recover the correct team session, preserve
planner continuity and approvals, and detect runtime permission failures
before delegating work. Align the shared Claude/Codex pipeline contract
with Codex's protected configuration directories.

Runtime state and migration:
- Move generated task records, artifacts, provenance, server credentials,
  session pins and logs from .agents/ to .pipeline/. Keep discoverable
  skills under .agents/skills/ and Codex configuration under .codex/.
- Synchronize scripts, role instructions, flow references and ignore rules.
  Read legacy provenance for update triage, but refuse normal bootstrap
  while legacy task state remains to prevent parallel runtime directories.
- Document the breaking path change in migration 02 and the changelog.
  Existing projects require a task-boundary migration that preserves
  history, customizations and skills; no automatic migration is performed.

Exact lead and planner recovery:
- Replace latest-session fallback with a dedicated launcher and per-team
  session pin captured by SessionStart/UserPromptSubmit hooks. Run without
  the shared daemon so hooks receive the selected team's launch context.
- Validate hook inputs and project boundaries, ignore unrelated Codex
  chats, prevent pin replacement and concurrent leads, and stop on failed
  resume or missing session capture. Require explicit --fresh for a reset.
- Record the planner thread in task state; reuse it for same-task fixes,
  recover from task records and decision history, and release it on task
  completion. Preserve recorded workflow approvals across recovery.

Configuration and preflight:
- Add optional lead/planner model and reasoning flags, defaulting to
  inherit, with validation and provenance round-tripping.
- Install delegate, status-board and karpathy-guidelines supporting skills
  without overwriting local files. Expand update guards for permissions,
  hooks, agent tools, MCP and skills while allowing deliberate local drift.
- Check required CLIs, feature capabilities, generated files, actual
  .pipeline write access and authenticated OpenCode connectivity using the
  same endpoint/password precedence as oc.sh. Replace the raw flow curl
  check so custom endpoints work consistently.
- Keep workflow consent separate from runtime permissions. Preserve hook
  review/trust requirements and avoid automatic permission broadening.

Documentation and validation:
- Add the Codex setup/recovery guide, manual live-verification checklist,
  migration instructions and synchronized generator lessons/references.
- Add no-model behavioral coverage for launch/resume isolation, fresh and
  failure paths, hook validation, locks, preflight failures, settings,
  legacy migration guards and customization preservation; run it in CI.
- Add an opt-in real Codex OS sandbox check demonstrating writable
  .pipeline state and protected .agents/skills, .codex and .git paths.

Validation passed: smoke (25 checks), invariants (113 rule/file pairs),
Codex behavior (8 groups), real Codex 0.160.0 sandbox probe, Bash syntax
checks and staged diff whitespace checks. ShellCheck was unavailable
locally; CI retains its optional check. No live model-driven pipeline or
native planner/skill discovery run was performed. The planner's source
write boundary remains instructional under classic workspace-write.
Brings in OpenCode lead (leader/planner/commands, team.sh --lead opencode),
the standalone dashboard and the optional Herdr plugin, without changing the
fork's contract: task records stay in .pipeline/, skills in .agents/skills/,
OpenCode roles in .opencode/agents/, Codex launcher/hooks/preflight intact.

- Port upstream's new templates, dashboard and Herdr plugin from .agents/ to
  .pipeline/; dashboard falls back to an unmigrated .agents/ runtime.
- team.sh: keep codex-lead.sh for Codex, add upstream's OpenCode branch.
- init.sh: refuse bootstrap on legacy worker files, not on directory presence
  (upstream scaffolds already have .opencode/agents/ for leader/planner).
- Replace upstream's root AGENTS.md (a Claude->Codex find/replace copy of
  CLAUDE.md) with a pointer to CLAUDE.md.
- Fix v1 abort endpoint in feature.md; make verify-models.sh generic and
  fix its temp-file trap; warn when Codex is older than the tested baseline.
- Renumber upstream's lessons 29-31 to 33-35.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
CI's ShellCheck step failed (also on codex-lead-parity before the merge) and
stopped before the templates loop ran. Fix every finding:

- SC1087 in codex-preflight.sh.tmpl: brace the loop variable in the regex.
- SC2207 in team-completion.bash.tmpl: intentional word-splitting; mapfile is
  unavailable in macOS bash 3.2, so disable for the function with a reason.
- SC2015 in smoke.sh and codex.sh: split A && B || C into separate checks.
- SC2016 in init.sh and tests: literal backticks in single quotes are
  intentional; annotate each site.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Merge upstream v0.10.0 into the Codex/.pipeline line
Give a Codex lead the mechanics the Claude harness supplies natively, and
write down the lead lessons that only lived in a Claude session.

- scripts/bg-dispatch.sh (start/wait): detached dispatch plus a bounded,
  repeatable wait, replacing the Claude-only Monitor watch.
- scripts/claude-review.sh: headless `claude -p --agent reviewer` with a
  read-only tool list, so a non-Claude lead can dispatch a claude/* reviewer.
- scripts/oc.sh: --status (v2 /api/session/active) and --interrupt
  (v2 /api/session/<id>/interrupt).
- promote-findings.sh skips directory tags instead of aborting the run.
- codex-preflight.sh checks the new wrappers and the Claude reviewer deps.
- feature flow: status check, merge record, mid-task model switch,
  concurrent-writer claims, exact Pass heading, tester-cannot-be-spawned.
- Codex feature skill: matching adaptations.
- init.sh renders/updates the new scripts and ignores dispatch traces.
- smoke: 3 new checks (36 total).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- --tester-model codex/<model> scaffolds .codex/agents/tester.toml, a
  report-only Codex tester; verify-models.sh skips codex/* like claude/*;
  codex-preflight.sh requires the tester agent when the manifest names one.
- OpenCode lead: claude/* reviewer via scripts/claude-review.sh, waits via
  bg-dispatch.sh, stops roles with oc.sh --interrupt.
- Generated AGENTS.md asks the project to record whether sending review
  material to Anthropic is authorized.
- smoke: codex/* tester scaffold check (37 total).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
BREAKING CHANGE: the state file's single "OpenCode session id" is replaced
by per-role fields (builder, reviewer, tester) plus "Codex tester thread
id". Migration: migrations/04-per-role-sessions.md.

- Session policy: each role's first oc.sh call starts its own session and
  only that role's retry reuses it. A shared task session broke on opencode
  v2 (a session pins the opening agent's tool set, so the tester could not
  write results) and fed the reviewer the builder's reasoning. Review and
  test commands no longer pass the builder's session.
- SYSTEM.md, the invariant rule, dev-team-generator references (lesson 21
  rewritten), README, oc.sh header and the OpenCode lead follow.
- Canonical step 2 creates a T-<id>-<slug> branch (project prefix kept)
  before any implementer runs.
- init.sh --builder-auto ask|on stamps builder_auto; `on` is a standing
  user decision, `ask` (default) keeps the spec-time question. The flow
  names builder.md's deny list as the only thing --auto does not approve.
- smoke: builder_auto stamping and per-role state fields (38 total).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- claude-review.sh: SC2015, use an explicit if for the argument-count check.
- oc.sh --status: SC2086 disabled with a reason; the unquoted id list is
  the intentional one-argv-per-session split.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@abdoharb abdoharb closed this Oct 8, 2026
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