Development Workflow Context Injection
Opt-in unified-hook releases use the numbered vYYYY.MM.N-canary.N channel
through cleo release cut and the OIDC workflow. The version suffix picks the npm
dist-tag, so publication stays on canary and does not advance to latest. Preserve registry retries and installed-package soak
checks. Stable promotion needs the separately retained, source-bound live harness
and hosted VidaPeps pilot evidence; missing or unavailable verification holds it.
The stable target may follow the canary base when npm has already advanced, but
every receipt must still bind to the exact canary and implementation digest.
Reject backward targets and prerelease targets; use the normal stable pipeline.
Before editing, inspect focus/briefing authority and coverage. Missing evidence
means UNKNOWN impact; current static coverage does not prove every runtime caller.
Task start, verification, completion, and handoff expose assessed coverage. Preserve
these limitations in PR and handoff claims, and recheck after source changes.
Use the repair matrix and sourced foreground resolutions; verify postconditions
and retain receipt recovery. Record actionable learning rather than empty traces.
Protocol: @src/protocols/contribution.md
Type: Context Injection (cleo-subagent)
Version: 3.0.0
Purpose
Context injection for development workflow tasks spawned via cleo-subagent. Provides domain expertise for atomic commits with task traceability, conventional commit messages, and systematic release processes.
Core Principle: Task-Driven Development
CRITICAL: NO code changes or commits without a tracked task.
Every commit MUST be traceable to a CLEO task. This ensures:
- Work is planned and tracked
- Changes are reviewable and reversible
- Progress is measurable
- Context is preserved for future agents
Immutable Constraints (WORKFLOW)
| ID | Rule | Enforcement |
|----|------|-------------|
| WF-001 | Task required | NO commits without CLEO task reference |
| WF-002 | Branch discipline | NO commits to main/master |
| WF-003 | Atomic commits | ONE logical change per commit |
| WF-004 | Conventional format | <type>(<scope>): <description> |
| WF-005 | Tests before push | Relevant tests MUST pass |
Git hook compatibility (T13349)
Init, upgrade and explicit Git hook installation share the ownership-aware installer.
Resolve the effective hook directory through Git, including core.hooksPath and
linked worktrees. Preserve foreign hooks and customized managed hooks; a CLEO
marker alone never authorizes replacement. Refresh only exact shipped legacy
bodies or receipt-owned content, using locked atomic writes and hash-guarded
rollback. Report conflicts with the suggested integration snippet.
Receipts and locks stay in Git-private common metadata, including when
core.hooksPath selects tracked files. Default installation preserves hook
paths inside the checkout. Use cleo init --git-hooks-only --allow-tracked-hooks-path only after
reviewing the tracked destination; this opt-in still preserves foreign and
customized hooks. Init warnings carry the exact opt-in command.
The pre-push wrapper spools Git stdin once for task IDs and shared project checks.
Besides Merge/Revert/fixup!/squash!/amend!, commit-msg and pre-push accept the exact
subject initial: cleo init (the empty commit cleo init makes so HEAD resolves; T13577),
only on a parentless first commit (T13582); a later commit with that subject, or any
longer or different subject, still needs a task ID. A template change adds the
previously shipped hash to legacy-hashes.json so installed copies refresh.
The managed pre-commit refuses CLEO runtime state staged at ANY path (T14189):
cleo.db/brain.db/tasks.db and their WAL sidecars by name, a project-info.json
naming a "projectId", and .cleo/config.json or a byte-identical copy. It lists the
paths and git reset -q -- <paths>; cleo doctor runs the same rule (staged_cleo_state).
This repository's .githooks/pre-commit calls the template rather than copying it.
It also refuses any added or modified .cleo/ path the shipped .cleo/.gitignore EXPLICIT
DENY rules name (backups, quarantine, logs, caches; T14549). The rules are embedded in the
hook as git pathspecs (runtimePathspecs(), test-enforced), so a user-edited
.cleo/.gitignore cannot disable it, and git matches them, so no quote, space or newline in
a name slips past. It prints an exact untrack command and cleo doctor --fix; every staged
change but a deletion (the repair) is checked, including renames and type changes. A FOREIGN pre-commit (no CLEO marker) is chained, not
skipped: it moves to pre-commit.cleo-chained and runs FIRST, so every check sees the
index it leaves; its failure stops the commit. A customized CLEO copy is still preserved.
cleo doctor reports git-tracked .cleo runtime files (tracked_cleo_runtime: error for
SQLite store files and sidecars, warning for the rest; --fix runs git rm --cached only and prints
the commit) and cleo init, cleo upgrade and cleo session start warn about them.
cleo init and cleo upgrade no longer seed the CleoOS hub (Pi extensions, CANT
workflows, justfile) into the global CLEO home (T13994, ADR-098); only the deprecated
cleo admin scaffold-hub still does.
cleo init and cleo upgrade write the canonical cleo-lead and cleo-worker agent files
(@cleocode/agents definitions/) for every detected provider whose CAAMP registry entry
declares agentDefinitions (Claude Code .claude/agents/, OpenCode .opencode/agents/); other
providers are reported as unsupported. Re-runs change nothing, and a file without CLEO's
generated marker is never overwritten (T14378). The lead is written only where the format can
restrict it: Claude Code gets Agent(cleo-worker), the cleo_run runner and its MCP server
(cleo orchestrate lead-runner), with Bash, Edit and Write denied; OpenCode files cannot hold a
tool allow-list, so its lead is reported as not installed (T14374).
On a project with no tasks, cleo init's next steps start with the root saga
(cleo saga create --title ... --acceptance ...), the only node allowed without a parent; the
first cleo add refusal names the same command (T14186).
With orchestrate.leadWorker.v1 on and agentmbx installed, cleo init records
orchestrate.leadMailbox as <project>-<id-hash>-lead (cleo upgrade records it too — on an
already-initialized project init refuses and --force resets config, so upgrade is the
non-destructive verb, T14448); spawn and fanout name it in worker
prompts when --lead-mbx is not given. Without agentmbx, both warn and write nothing;
with the flag off they neither probe nor name one (T14379, T14448).
It probes CLEO_PROJECT_HOOK_V1 before invoking the implemented CLI adapter;
missing or incompatible runners warn and allow. cleo hook run --probe -- execution
answers EXEC or INERT (older builds answer V1; stable builds before 2026.10.17 are
inert). Every ungated push, including a hooks-inert cleo first on PATH, prints one
pre-push stderr line WARNING: push NOT gated by project hooks: <reason>, flagging a
checkout whose activation is on (T13774). Verify nested checkout paths, linked
worktrees, custom hook paths, historical release bodies and corrupt receipts
with focused Git fixtures before changing this delivery path.
The four post-* managed hooks (post-merge, post-commit, post-checkout,
post-rewrite; T12349) keep the NEXUS index current and never block. In shell they
start cleo nexus auto-reindex detached, except in a linked worktree, when git config
cleo.nexusAutoReindex is false, or when CLEO_NEXUS_AUTO_REINDEX=off (vitest.setup.ts
sets this for every test fork). post-checkout skips file checkouts. Git ignores a
post-* exit status, so a foreign hook at one of these names is chained, not skipped:
it moves to <name>.cleo-chained, and the CLEO hook execs it last with the same
arguments and stdin. A refresh of a receipt-owned hook keeps its first pre-CLEO image.
cleo nexus hooks install turns the refresh on (idempotent). `cleo nexus hooks
uninstall sets the marker to false, which init, upgrade and checkGitHooks` respect,
and restores the three refresh hooks exactly: it renames each chained hook back and
removes any hook CLEO created. A hook edited since install is kept and reported in skipped.
cleo run admits a git command whose only hooks are these unmodified refresh hooks, with no
executable .cleo-chained sibling, as a light job (isDetachedCleoHook, T14384); the refresh
itself is admitted as cleo run --class scan. A customized or chained hook keeps the class plan.
The refresh runs one at a time per project (.cleo/nexus-reindex.lock). A request
that finds the lock held leaves .cleo/nexus-reindex.pending, so a burst coalesces
into one follow-up pass by the holder. nexus analyze is incremental by default and
is admitted through cleo run --class scan at the lowest priority: it never joins the
queue, tries only when nothing is waiting, and records deferred after
nexus.reindexOnMerge.timeoutSeconds (300). When the refresh is off, post-merge
still runs the opt-in cleo nexus reindex-on-merge (T14010; cleo.nexusReindexOnMerge
marker, base branch only, --enable / --disable), which uses the same lock.
Task Tracking Integration
Before Any Work
# 1. Verify you have a task
cleo current
# 2. If no task, find or create one
cleo find "relevant query"
cleo add "Task title" --description "What you're doing" --parent T001
cleo start T123
# 3. If 'cleo start' fails with E_SESSION_UNBOUND (spawned workers and
# subagents are already bound), bind first, then retry:
# cleo session start --scope global --name "<what you are doing>"
# (or: cleo session resume <id>)
Commit Message Format
MUST include task reference:
<type>(<scope>): <description>
<body explaining why>
Task: T123
Co-Authored-By: Claude <noreply@anthropic.com>
Example:
fix(auth): prevent token expiry race condition
The refresh token was being invalidated before the new access
token was validated, causing intermittent auth failures.
Task: T1456
Co-Authored-By: Claude <noreply@anthropic.com>
Branch & Subagent Awareness
Single Branch Reality
Subagents share the parent session's branch. This means:
- All work happens on the same branch
- No parallel feature branches from subagents
- Commits are sequential, not parallel
- Worktrees needed for true branch isolation
Branch Strategy
# Check current branch
git branch --show-current
# Feature work (typical pattern)
main → feature/T123-description → PR → main
# Branch naming
feature/T123-auth-improvements # Task-prefixed
fix/T456-token-validation # Bug fix
Gate System (Simplified)
Not all gates apply to all changes. Follow the decision matrix. Required gates also follow the task's evidence kind (verification.requiredGatesByKind): research and documentation tasks owe the required gates without testsPassed/qaPassed until their work touches any non-document path, which restores the full code gates.
G0: Pre-Flight Check
Always required.
# 1. Verify task context
cleo current
# MUST have a current task
# 2. Check branch
git branch --show-current
# MUST NOT be main/master
# 3. Check for uncommitted work
git status --porcelain
# Review staged/unstaged changes
G1: Classify Change
| Type | Description | Tests Needed | Version Bump |
|------|-------------|--------------|--------------|
| feat | New feature | Related tests | MINOR |
| fix | Bug fix | Regression test | PATCH |
| docs | Documentation | None | None |
| refactor | Code restructure | Affected tests | PATCH |
| test | Test additions | The new tests | None |
| chore | Maintenance | None | None |
| perf | Performance | Perf tests | PATCH |
| security | Security fix | Security tests | PATCH |
G2: Testing (Smart Scope)
NOT always full test suite. CI runs full tests on push.
| Change Type | Test Scope | Command |
|-------------|------------|---------|
| feat | Related module tests | bats tests/unit/feature.bats |
| fix | Regression + affected | bats tests/unit/affected.bats |
| docs | None (CI validates) | Skip |
| refactor | Affected modules | bats tests/unit/module*.bats |
| test | The new tests only | bats tests/unit/new.bats |
| chore | Syntax check only | bash -n scripts/*.sh |
When to run full suite locally:
- Before release (version bump)
- Major refactoring
- Cross-cutting changes
- User explicitly requests
# Full suite (when needed)
./tests/run-all-tests.sh
# Targeted tests (typical)
bats tests/unit/specific-feature.bats
bats tests/integration/workflow.bats
# Quick syntax check
bash -n scripts/*.sh lib/*.sh
G3: Commit
# 1. Get task info
task_id=$(cleo current --quiet)
# 2. Stage changes (be specific for atomic commits)
git add scripts/specific-file.sh lib/related.sh
# 3. Create commit with task reference
git commit -m "$(cat <<'EOF'
fix(auth): prevent token expiry race condition
The refresh token was being invalidated before validation.
Task: T1456
Co-Authored-By: Claude <noreply@anthropic.com>
EOF
)"
G4: Push (Triggers CI)
# Push branch (CI runs full tests)
git push origin HEAD
# CI will run:
# - Full test suite
# - ShellCheck linting
# - JSON validation
# - Documentation drift check
# - Installation test
G5: Pull request
Every change reaches main through a PR. The body names each task and the ACs the
PR delivers, one line per task (ADR-099):
Closes: T1456 AC1,AC2
Refs: T1400 AC3
Closes: completes the task once its ACs are covered; Refs: binds ACs for
partial delivery. The PR text never waives an AC. Check the lines against the
store before merge:
cleo done --from-merge <pr> --dry-run
A reviewer that is not the author records a verdict per AC on the PR head
(cleo review packet <pr> --task T1456, then cleo review verdict). Merge on
green CI; the merge sweep closes the task and records its evidence. No step
follows the merge.
cleo merge train does the merging (dry run by default; --execute acts). It
merges an open PR only on the exact head that was reviewed (pinned with
--match-head-commit), when the required checks are green on that sha in each
run's latest attempt, the review check passes and done --from-merge --dry-run
says nothing waits or is refused. An infra-only red (runner shutdown, cancel)
gets its failed jobs rerun, at most 3 times per head; a real red is reported
once and never rerun. The review is judged first: a head whose review check
has gaps gets at most one infra rerun, and each decision states the review
state (review: ready or gaps: ...) before the rerun decision. Nothing merges while main's latest push run is red except
a PR labelled main-fix; Merge-After: #<n> holds a PR until PR n merged.
Once the merge commit has a completed push run, the train runs the merge sweep
for the PR. One train runs per repository, and a train that stops says so.
G6: Release
Commits never bump versions or tag. Each user-facing change carries a
.changeset/ entry, and a release is one command run by the lead:
cleo release cut v2026.MM.N --dry-run # green sha, notes, packages, task report
cleo release cut v2026.MM.N # tags; release.yml builds and publishes
Quick Decision Matrix
What Tests to Run?
| Change | Local Tests | Rely on CI |
|--------|-------------|------------|
| Single file fix | Related unit test | Yes |
| New feature | Feature tests | Yes |
| Docs only | None | Yes |
| Schema change | Schema tests | Yes |
| Cross-cutting refactor | Full suite | Yes |
| Release prep | Full suite | Yes |
Do I Need a Version Bump?
No. Add a .changeset/ entry for user-facing changes; versions and tags come
from cleo release cut.
PR Cadence (D11212)
Many small PRs, each tied to a task group, so every change is traceable from
task to PR to release (spec: cleo docs fetch pr-cadence):
- One PR per task group. A PR delivers one task, or a few tasks that cannot
land apart. Never bundle unrelated tasks to save a CI run.
- Small. Reviewable in one sitting. Split a large task into PRs that each
keep main green: Refs: on each, Closes: on the last.
- Name the tasks. One body line per task:
Closes: T#### AC1,AC2or
Refs: T#### AC3. The PR Task Lines check flags a PR with none or with a
malformed line. A change no task owns takes the no-task label.
- Changeset with the same
tasks:for user-facing changes; release notes
are built from them.
- Durability ledger (SG-CLEO-DURABILITY PRs, T14247). The body carries a
Ledger: line pairing every exception it adds with the rule it deletes.
Items follow on the line (;-separated) or as bullets below it:
adds <kind> <name> -> deletes <rule>, adds model <name>,
adds part <name>, deletes <rule>, or adds nothing. Exception kinds
(verdict, code, key, flag, registry, gate) need the
-> deletes pairing; model (a receipt, a census, measured charges) and
part (a helper, predicate, job, report, verb or field that adds no rule)
do not. The PR Task Lines workflow flags a PR with a Ledger: or
Durability: line whose ledger is missing, malformed or unpaired
(scripts/lint-pr-ledger.mjs).
- Batch at release time, not in PRs. PRs merge one at a time on green
CI; cleo release cut ships everything merged since the last tag.
Task System Integration
@skills/_shared/task-system-integration.md
CLEO Integration Commands
# Task lifecycle
cleo current # Current task
cleo start T123 # Start task (on E_SESSION_UNBOUND: bind a session, see above)
cleo complete T123 # Mark done (no-PR work; PR work closes on merge)
# Find existing work
cleo find "query" # Search tasks
cleo list --status pending # Pending work
# Create new work
cleo add "Title" --parent T001 --description "..."
# Session management
cleo session status # Current session
cleo session end --note "Completed X, Y, Z"
Subagent Protocol
@skills/_shared/subagent-protocol-base.md
Output Requirements
- MUST record workflow summary with
cleo docs add {{TASK_ID}} --content - --type note --slug {{TOPIC_SLUG}}(never a raw file under.cleo/agent-outputs/) - MUST record ONE manifest entry:
cleo manifest append --entry '<entry JSON>'(the flat manifest file is retired, ADR-027) - MUST return ONLY: "Workflow complete. Manifest appended to pipeline_manifest."
- MUST NOT return full commit/release details in response
Complete Workflow Examples
Example 1: Bug Fix (Typical)
# 1. Verify task
cleo current
# Output: T1456 - Fix token validation
# 2. Make changes
# ... edit files ...
# 3. Run relevant test
bats tests/unit/auth.bats
# 4. Stage specific files
git add lib/auth.sh scripts/login.sh
# 5. Commit with task
git commit -m "$(cat <<'EOF'
fix(auth): prevent token expiry race condition
Task: T1456
Co-Authored-By: Claude <noreply@anthropic.com>
EOF
)"
# 6. Push and open a PR whose body says `Closes: T1456 AC1,AC2`
git push origin HEAD
gh pr create --fill
cleo done --from-merge <pr> --dry-run
# 7. Merge on green CI after the per-AC review; the merge sweep closes T1456
Example 2: Documentation Only
# 1. Verify task
cleo current # T1550 - Update README
# 2. Make doc changes
# ... edit docs ...
# 3. No tests needed (CI validates)
# 4. Commit
git add docs/ README.md
git commit -m "$(cat <<'EOF'
docs: update installation instructions
Task: T1550
Co-Authored-By: Claude <noreply@anthropic.com>
EOF
)"
# 5. Push and open a PR whose body says `Closes: T1550 AC1`
git push origin HEAD
gh pr create --fill
# 6. Merge on green CI after the per-AC review; the merge sweep closes T1550
Anti-Patterns
| Pattern | Problem | Solution |
|---------|---------|----------|
| No task reference | Untracked work | Create/find task first |
| Committing to main | Bypass review | Use feature branches |
| Running full tests always | Slow iteration | Use smart test scope |
| Skipping CI | Missing validations | Always push, let CI run |
| Manual release creation | Inconsistent releases | Use tag, GH Actions |
| Giant commits | Hard to review/revert | Atomic commits |
| Vague commit messages | Lost context | Conventional + task ref |
Critical Rules Summary
- Always have a task before making changes
- Always include task reference in commit message
- Never commit to main/master directly
- Run relevant tests locally, not always full suite
- Let CI validate with full test suite on push
- Use tags for releases - GitHub Actions handles the rest
- One logical change per commit (atomic)
- Conventional commit format with task reference
Shared project hooks and managed Git delivery
Provider delivery receives canonical SDK file reads and Git discovery through a contracts port.
Adapters do not acquire a runtime dependency on core for these utilities.
CLEO's own harness hooks are separate from project hooks: cleo hook heavy-command
(PreToolUse), cleo hook stop (Stop; it runs ask-enforce) and, for Claude Code, cleo hook session-end
(SessionEnd) and cleo hook subagent-start (SubagentStart, the ct-lean rules for Agent-tool subagents) are installed together by
cleo init/cleo upgrade or cleo doctor heavy-command-hook --fix, and fail open.
Project business rules live in tracked .cleo/hooks.json; generated provider entries
are delivery outputs. hooks-v1 was promoted in v2026.10.17 and is released in source
(T13776), so every build activates and runs project hooks. The release gate
(core/src/hooks/release-gate.ts, T13557) stays for a future hook feature: while one is
unreleased, cleo hook sync --activate refuses with E_HOOKS_V1_UNRELEASED and existing
receipts report unreleased and never run. Preview with cleo hook sync --dry-run; explicit local activation
uses cleo hook sync --activate and binds definitions, handlers and dependencies to
current hashes. Source drift requires reactivation and runs no handler: Git, worktree, direct
and CI refuse (naming cleo hook sync --activate) every event bound by the approved bindings
recorded at activation, the current manifest or a linked checkout's, so a deleted, rebound or
unparseable definition, or a deleted handler or dependency, stays enforced; unbound events
run no hooks (a pre-bindings activation refuses them too), and agents only warn (T13742). Agent project checks are advisory; Git applies project verdicts. Native harness trust remains separately unverified.
Inspect with cleo doctor hooks; --fix never activates definitions or grants trust.
cleo hook sync --disable disables execution and removes only verified managed entries:
it skips providers with no delivery receipt, creates nothing, prunes only containers
activation created, deletes a provider config (and its directory) that activation created
once it is empty, and deletes the receipt (T13743).
CI uses cleo hook check <id> --ci --candidate <sha> or an explicit JSON --input file;
CLEO infrastructure failure is an unavailable check, never successful CI evidence.
Launcher faults allow locally regardless of checker error policy. File inputs and
provider records use bounded regular-file reads; FIFOs are rejected. Unsupported
provider bindings remain unsupported in delivery summaries, including mixed bindings.
The Stop event has ONE CLEO entry per provider, cleo hook stop --provider claude-code|codex
(T13796), in order goal tick → ask-enforce. Stop fires at every turn end, so it NEVER ends the CLEO
session (T13913): ending there deleted the terminal binding every turn. Claude Code's SessionEnd
hook (cleo hook session-end, always installed) runs cleo session end --quiet detached, waited for
at most 20 s; Codex has no session-end event, so its sessions end explicitly. The goal runtime goes first, only when
.opencode/goals/ exists (CLEO_GOAL_TICK_COMMAND, default ocg tick, Stop JSON on stdin,
JSON-only stdout, at most 60 s, its process group SIGKILLed at the deadline): a block is
re-serialised as exactly {decision, reason} (reason capped) and skips the rest. Otherwise
ask-enforce (T13420) answers. Every step fails open (missing, failing or timed-out tick;
ask-enforce error); CLEO_GOAL_TICK=off skips the tick; CLEO_ASK_ENFORCE=off or heavy-command
mode off (CLEO_HEAVY_COMMAND_HOOK / resources.heavyCommandHook, read at run time) skips the
ask check, as they removed its separate hook before.
Sync folds the separate ask-enforce and old session-end Stop entries into it in place; Codex's
rides the heavy-command mode, Claude Code's always stays. cleo doctor heavy-command-hook
reports the hook outdated when the Stop, SessionEnd or SubagentStart entry is missing or was
written by another build (a binary updated without a re-sync, T13960); --fix re-syncs them.
cleo self-update re-syncs only the project it runs in.
Init, upgrade and inspection share the commit-msg, pre-commit and pre-push installer.
Git determines effective hooksPath and the common directory, including linked worktrees.
Exact known template hashes or local receipts authorize refresh; a marker alone does
not. Customized and foreign hooks are preserved even on forced refresh and report an
integration snippet. Rollback is guarded by the installed-content hash.