turnfile-codex-collaboration
Execute the Turnfile protocol workflow in Codex for mailbox lifecycle, payload-first review exchange, lock-safe shared-file updates, session close/resume, and Turnfile task/lock coordination. Use when the maintainer explicitly asks Codex to run a protocol module or produce an auditable protocol-conforming change.
Turnfile Codex Collaboration
Run modules only on explicit maintainer instruction.
Execution Contract
- Start in propose-only mode.
- Treat invocation as write permission only when maintainer explicitly includes apply intent (for example, "run and apply").
- Require explicit maintainer confirmation before any file write if apply intent is absent.
- Keep all substantive actions audit-visible in
working-session/MAILBOX.md,working-session/WORKLOG.md, orworking-session/TURNFILE.yaml.
Active-Turn Boundary Discipline
- Read
working-session/MAILBOX.mdfirst for active-turn boundary checks. - Re-check
working-session/MAILBOX.mdbefore declaring completion. - Do not declare turn complete if Codex unread count is non-zero.
- Escalate with explicit blocker context when unread cannot be cleared in-turn.
- Close or explicitly defer Codex-owned actionable threads before turn completion.
- Ensure
Open Queuedoes not retain stale entries for threads Codex just resolved.
Startup Orientation Read Order
- Read
working-session/TURNFILE.yaml. - Read
working-session/WORKLOG.mdstatus block. - Read
working-session/MAILBOX.mdinbox snapshot + assigned unread cards. - Read scope-specific protocol docs and PRDs.
- Read
working-session/OPEN_QUESTIONS.mdwhen work affects unresolved or deferred items.
State Freshness Hooks
- After milestone/task completion, refresh coordination artifacts in the same turn:
working-session/WORKLOG.mdstatus blockworking-session/TURNFILE.yamltask metadata / signalworking-session/MAILBOX.mdlifecycle status when a thread changed
- After mailbox edits, regenerate
working-session/MAILBOX.json. - Keep skill metadata accurate when protocol state changes materially (module behavior, validation status, tooling dependencies).
Module Catalog
M-01 Mailbox Lifecycle + SLA
Trigger examples:
- "Run mailbox lifecycle for MSG-20260208-040."
- "Process unread Codex messages and apply."
Expected inputs:
- Target message IDs or inbox scope.
- Desired action (
acknowledged,actioned,closed).
Deterministic outputs:
- Updated message status and Ack/Reply lines in
working-session/MAILBOX.md. - Updated inbox/open-queue snapshot.
- Regenerated
working-session/MAILBOX.jsonwhen mailbox changed.
Stop/escalate:
- Stop if closure owner/decision authority is unclear.
- Escalate if status transition violates PRD-003 lifecycle.
M-02 Maintainer Decision Request/Reply
Trigger examples:
- "Prepare decision-required message for maintainer on PRD-012 scope."
- "Apply maintainer decision from MSG-####."
Expected inputs:
- Decision context and requested outcome.
- Priority and due cycle.
Deterministic outputs:
- Decision-required mailbox card with explicit ask and evidence references.
- WORKLOG decision index entry when decision is final/substantive.
Stop/escalate:
- Stop if decision scope is ambiguous or contradictory.
- Escalate if prior maintainer decisions conflict.
M-03 Payload-First Review Envelope
Trigger examples:
- "Prepare apply-or-counter payload for PRD-013."
- "Validate revision token and payload envelope."
Expected inputs:
- Target files and review scope (
full,critical-only,interface-only). - Ask type (
apply,apply-or-counter,ack-or-counter).
Deterministic outputs:
- Revision-tagged payload envelope with explicit file list.
- Mailbox update referencing payload and expected response mode.
Stop/escalate:
- Stop if payload cannot be tied to deterministic revision lineage.
- Escalate if envelope conflicts with PRD-008/009 requirements.
M-04 Cross-PRD Reconciliation
Trigger examples:
- "Run reconciliation for PRD-006/007/010 interfaces."
- "Reconcile interface deltas and propose cross-doc fixes."
Expected inputs:
- File set and interface boundaries.
- Decision evidence and delta acceptance criteria.
Deterministic outputs:
- Delta summary with required/recommended classifications.
- Mailbox evidence trail for review outcomes.
Stop/escalate:
- Stop if source docs conflict and no authoritative tie-break is available.
- Escalate unresolved contradictions with explicit options.
M-05 Shared-File Transaction Discipline
Trigger examples:
- "Apply shared-file-safe update to MAILBOX and WORKLOG."
- "Run lock-safe control-plane mutation."
Expected inputs:
- Target shared files.
- Intended mutation and invariant checks.
Deterministic outputs:
- Transactional update sequence aligned with PRD-010/013.
- No partial writes across related control-plane artifacts.
- Projection regeneration when required.
- Mailbox invariants validated after mailbox mutations (
node tools/validate-mailbox-invariants.mjs).
Stop/escalate:
- Stop if lock ownership or revision check fails.
- Escalate after bounded retry on unchanged coordination revision.
M-06 Session Close/Resume Snapshot
Trigger examples:
- "Prepare closeout handoff for session end."
- "Run startup resumption checklist."
Expected inputs:
- Session scope and carry-over anchors.
- Required compaction/cleanup expectations.
Deterministic outputs:
- Updated boot/worklog handoff sections.
- Clear carry-over + next-owner designation.
- Explicit unresolved blocker list if present.
Stop/escalate:
- Stop if closeout would hide unresolved high-priority items.
- Escalate when compaction or archival decisions require maintainer call.
M-07 Turnfile Coordination Read/Write
Trigger examples:
- "Claim P2-D task and signal readiness."
- "Update task status and release lock in Turnfile."
Expected inputs:
- Task ID, status transition, and signal intent.
- Coordination revision expectations.
Deterministic outputs:
- Turnfile updates respecting section ownership and revision progression.
- Task claim/completion metadata (
claim_rev,completed_rev, notes). - Coordination signal entry under
messages.
Stop/escalate:
- Stop if update would modify non-owned Turnfile sections.
- Escalate on repeated revision contention.
M-08 OQ Registry Operations (OQ-only lane)
Trigger examples:
- "Register OQ for PRD-016 threshold wording."
- "Resolve OQ-050 and sync references."
Expected inputs:
- OQ IDs or new-question prompt.
- Resolution evidence (maintainer decision, accepted payload, or cross-review outcome).
Deterministic outputs:
- Updated
working-session/OPEN_QUESTIONS.mdlifecycle state (active,deferred,resolved). - Referenced PRD OQ section updated with matching resolution text when authorized.
- Mailbox/WORKLOG linkage to the governing decision evidence.
Stop/escalate:
- Stop if resolution authority is ambiguous.
- Escalate when OQ resolution would alter required protocol semantics without maintainer decision.
Fallback Rules
- If helper tooling is unavailable, run manual equivalent steps and log the fallback.
- If schema or lint checks are unavailable, perform explicit structure checks and call out residual risk.
- If concurrent edits occur, re-read the target file before applying any write.
Output Format Requirements
- State module executed.
- State whether run mode was propose-only or apply-authorized.
- List changed files with exact paths.
- List verification commands and outcomes.
- List blockers and next owner.