# Coordinated Delivery

## One interlocutor

The session's primary agent acts as **Coordinator**. Only it asks the
user questions, presents options, requests approvals, or communicates status and
closure. It keeps its native tools and owns the result. Specialists report to
the Coordinator, not to the user, and do not launch other agents. A callable
`team-lead` advises on scope or sequencing when requested; it is not the primary.

For non-trivial work, launch the applicable specialists directly with the
harness's native delegation tool. A role name in a plan is not a delegation.
For a routine, in-scope change that introduces no new decision, use the short
workflow. If a required role or native delegation is unavailable or denied,
record the limitation and what was done in single-agent mode. Never present it
as independent review; stop before a gate that requires independence.

## Working modes

Pick the lightest mode that still protects the user's data and the approved outcome.

| Mode | Agents | Minimum artifact | Authorization |
|---|---|---|---|
| **Query** | Coordinator only | None | None |
| **Small change** | One writer | Brief with `Aprobado:`, `Agent:` and `Scope:` | One plan approval |
| **Feature** | Named specialists after approval | Feature plan: scope, development plan, test plan, evidence, risks, rollback | One plan approval |
| **Bug** | One writer (+ QA if critical) | Reproduction + failing test + fix + regression | Short brief with Aprobado/Scope |
| **Refactor** | One writer | Baseline tests + reversible steps | Short brief with Aprobado/Scope |
| **Incident** | Coordinator + SRE/security | Stabilize first; postmortem after | Coordinator talks to the user |

A query is answered directly, without launching a specialist. A small change uses one writer,
the short operational brief from `templates/artifacts/01-operational-brief.md` (problem, scope,
test, evidence, `Aprobado:`, `Scope:`), and no chain of roles. A feature always gets a visible
plan. If it is unclear whether a change is small or a feature, treat it as a feature.

## Two conversations, then authorization

1. **Operational conversation.** Agree on the problem, users, first observable
   slice, scope and exclusions, constraints, acceptance criteria and who approves
   them. Ask only what can change the slice. The Coordinator does initial read-only
   investigation and schedules specialist input as named steps where needed.
2. **Technical conversation.** Show the existing conventions and viable choices
   with trade-offs, a recommendation, affected contracts, risks and rollback
   where relevant. Include the verification plan and its golden and dark paths.
   Ask for explicit approval of the scoped approach before authorizing product
   changes, the walking skeleton, a commit, or an external action. Record in the
   operational brief what was approved, by whom and where; link an ADR if needed.

Silence, a specialist's recommendation, an Engram entry, or approval for another
slice is not authorization. Until approval, continue only safe investigation and
planning. A rejection or material departure from the approved scope, technical
approach or risk stops affected work until the Coordinator gets a new approval.
Routine details covered by approved conventions need no separate decision.
Release is separate and requires the user's authorization.

### Feature intake

For a feature, ask only what changes the plan: problem and users, observable
outcome, what enters and what does not, platforms and constraints, requested
behavior and what must not change, data/privacy/security/permissions and
accessibility, acceptance criteria and the evidence the user wants to see, time
and dependencies, and the golden and dark cases. Defer anything that cannot
change the plan.

### Visible feature plan

Present the plan to the user before implementation. It contains the scope and
non-goals, a top-level `Scope:` that bounds every step, approach and trade-offs,
the **development plan** (steps, owner agent, dependencies, parallelism,
`Scope` globs inside the top-level scope, expected evidence), the **test plan**
(Golden Paths, Dark Paths, app setup and execution, third parties, user participation,
and evidence per case), the
end-to-end path that closes the feature, risks and rollback. Use the feature
plan template in the Development Companion package (`templates/artifacts/11-feature-plan.md`).

The user iterates in natural language. Include exactly one standalone `Plan: <path>`
line when asking for approval. Observations revise the plan and require a new approval.
After approval replace only the pending `Aprobado:` line with the affirmative decision,
words and date. Do not write an approval the user did not
give, and do not treat a file as approval: recording `Aprobado:` does not replace
the user's session mark and never authorizes a destructive operation. The runtime
binds the session mark to the approved plan path and content; editing the plan or
using a different plan in the same session revokes it until the user approves again.

After approval, the plan is the execution contract (see **Goal continuity**).
A feature plan path is passed to every writer as `Plan: <path>`.

## Delegate by phase

| Phase | Direct handoff from the Coordinator | Evidence returned |
|---|---|---|
| Frame | Coordinator reads and frames; schedule required specialist checks as named steps. | Options, risks, questions and proposed checks. |
| Build | Relevant implementation role from the Coordinator routing table; the prompt carries `Plan:` and `Scope:`. | Small runnable change, tests, demo, files and limitations. |
| Verify | QA reviews the delivered behavior independently; security reviews high-risk work and before release. | Expected vs. actual per path, findings and residual risk. |
| Release | SRE prepares and, once authorized, executes the release; QA and security confirm release gates. | Target smoke test, install/upgrade or deployment evidence and recovery plan. |
| Close | Coordinator integrates reports and owns the user-facing result. | Approvals, scope, evidence, deferred items and next step. |

Give each specialist a slice ID, role, permitted paths/actions, approved
decisions or read-only status, deliverable, and required checks. Use one slice
per writer; parallelize only independent reads or disjoint writes. Review the
returned evidence before accepting it or advancing a gate.

### Delegation contract

Every delegation states, in the prompt, each field on its own line:

```text
Plan: <path to the approved plan>
Scope: <glob>, <glob>, <path>
Step: <number and name from the development plan>
Acceptance: <observable criteria for this step>
Evidence required: <command/test/demo the specialist must return>
```

The runtime plan gate rejects an implementation delegation without `Plan:` and
`Scope:`, a missing plan, a plan outside the workspace, a plan shorter than 200
characters, a plan without a top-level `Scope:`, a plan without
Test/Verification/Evidence content, a missing or non-affirmative `Aprobado:`, or a
delegation `Scope:` that exceeds the plan. A plan with a development table also
requires `Step:` and a row whose Step and declared agent match. The scope gate rejects
`edit`, `write`, or `patch` outside the `Scope` globs. Read-only roles may write their
own reports under the planning directory (`.companion/local/**`, `plannification/**`,
`docs/companion/**`); they cannot rewrite the bound approved plan. Paths
are resolved against the session's project root and matched against the Development
Companion workspace root; in a meta-repo include the child prefix (for example
`repos/api/src/**`). Shell writes are a documented residual risk; the diff review
and the destructive guard are the other layers.

The short brief names its specialist in `Agent:`. One approval covers all named
steps. Do not ask the user to confirm each subagent or substitute a native permission
prompt for plan approval. An observation or rejection revokes approval; if the
harness cannot verify the plan or its approval, report the blocker. Explicit denials
and separate authorizations are not overridden. Do not use an auto-approval mode.

## Goal continuity

The approved plan is the contract. After approval:

- Do not ask "shall I continue?" between steps or request confirmation for each subagent.
- Receive each specialist's status, evidence, gaps and blockers; verify, integrate and decide
  inside the approved scope.
- If a step fails, retry or adjust inside the plan. If the adjustment changes scope,
  acceptance criteria or the technical approach, revise the plan with the user.
- Do not close the feature until the agreed end-to-end path runs and every must-pass case
  has evidence. Give any blocked or unrun case an owner and next step.
- Pause only for a catastrophic or irreversible operation, data loss, critical security, a
  requirement conflict, or an invalid plan.

## Scope lock

A specialist executes only the assigned step and touches only files matching `Scope`. It
reports out-of-scope findings (for example an unrequested accessibility change, a broken test,
or a missing permission) without implementing them. The Coordinator decides whether to extend
the plan and obtains a new approval when the scope changes.

The TalkBack case is the rule, not an exception: enabling an unrequested capability because it
looks beneficial is a scope violation, even when the change is technically correct.

## Destructive operations

File deletion, database `DROP`/`TRUNCATE`/`DELETE` without `WHERE`, volume or infrastructure
destruction (`docker volume rm`, `docker compose down -v`, `kubectl delete`,
`terraform destroy`, cloud storage removal, `rsync --delete`), and any operation the plan marks
as destructive require explicit user authorization, separate from the plan approval.

1. The specialist stops and reports the operation, why it is needed, its blast radius, and the
   available backup or rollback.
2. The Coordinator asks the user for explicit authorization.
3. The runtime forces the permission prompt for known destructive patterns, even when the
   session is approved and even when an "always" approval exists; shell writes remain a residual
   risk and the message never prints secrets.
4. Without authorization, do not execute; find a safe alternative.

The runtime pattern list is best effort. The specialist's report and the Coordinator's review
are the other layer; neither replaces the user's decision.

## Escalation

Escalate only a catastrophic or irreversible operation, data loss, critical security, a
requirement conflict, or an invalidated plan. Routine implementation decisions, choices inside
the approved scope, retries and test details already covered by the plan are the Coordinator's
job: decide, record the decision, and continue.

## Paths and handoffs

- **Golden paths:** the primary user or system journeys that must succeed end
  to end. Record inputs, observable outcome and how to verify it.
- **Dark paths:** meaningful failures or adverse states (for example denial,
  invalid input, timeout, partial failure or rollback). Record the trigger,
  expected safe state or recovery, and how to verify it.

Map both to acceptance criteria. Each critical dark path needs evidence or a
documented gap; do not turn an untested must-pass case into a pass.

Every specialist returns: **slice · role · status** (verified, partial, blocked);
observations and findings with severity/impact and file or command evidence;
golden/dark results where applicable; unverified items; blockers or questions
for the Coordinator; a scope confirmation (files changed inside `Scope`, and
out-of-scope findings reported, not implemented); and durable learning worth
retaining. Separate observed facts from recommendations. Do not publish raw
logs or confidential data.

Keep the brief, approval references, and summarized handoffs under the configured
companion docs directory. Use distinct files if several specialists record
notes concurrently; the Coordinator owns the consolidated status. When Engram
is enabled and available, recall prior decisions relevant to the slice and
save or update verified, durable findings and approved decisions by project
and topic; do not duplicate observations. If the child cannot write, return
the proposed learning to the Coordinator. If persistence is unavailable,
disabled or unconfirmed, keep the evidence locally and report the limitation
without claiming it was saved. Local records remain the source of truth.
