<!-- filepath: sp-docs/sp-plan-workflow-contract.md -->
<!-- Version: 1.0.1 -->
# SP Plan Workflow Contract

This document is the toolkit-owned workflow contract shipped to repos that use the SP workflow.
Use it together with `sp-plan/PLAN.md`.

`sp-plan/PLAN.md` remains the repo-root active workflow plan and claim surface for kit-level and cross-cutting work.
`sp-plan/PLAN.md` keeps repo-local current work, plan items, claims, and archive state.
Subproject plans follow the convention `<subproject-root>/sp-plan/PLAN.md` and are scoped to their directory tree (see § "Multi-plan scope" below).
This contract holds the reusable Golden Path, claim rules, and lifecycle semantics that should not be duplicated into every repo-local plan body.

## Authority split
- `sp-docs/sp-plan-workflow-contract.md` is authoritative for reusable Golden Path, claim rules, task marker semantics, and plan lifecycle expectations.
- `sp-plan/PLAN.md` is authoritative for repo-local current work, repo-local phases/items, active claims, and archive state.
- README files, `AGENTS.md`, and instruction surfaces should summarize the split briefly and point back to this document instead of re-defining the shared workflow contract in full.

## Golden Path (how to use the SP workflow)
1) `/sp-analyze` -> PICARD analysis + HANDOFF
2) `/sp-pro-plan` -> proposal + HANDOFF
3) `/sp-new-plan` (or `/sp-new-plan-item`) -> apply HANDOFF to create plan content, including upfront `D#` verification intent from the PICARD Response phase
4) Claim the active `T#` or `D#` on the canonical coordination branch using the selected task marker option in this file
5) Push the coordination-branch plan claim before substantial implementation work starts
6) `/sp-get-task-explanation` (alias `/sp-explain-task`) -> explain implementation and test approach from existing sources only
7) `/sp-set-task-testing` (alias `/sp-ensure-testing`) -> turn the planned verification intent into exact automation-first task-level commands and evidence before coding
8) `/sp-implement` -> implement against plan items (`T#`)
9) `/sp-test-task-implementation` (alias `/sp-test-implementation`) -> execute and document automated tests for work ready to close
10) `/sp-doc` -> sync docs after executed test evidence exists or the work is explicitly blocked
11) Use Complete/Reopen/Archive for plan item lifecycle and clear or refresh claims as needed

Cross-cutting workflow note:
- Reflect status changes back into the coordination-branch plan state as work progresses instead of treating status sync as one late linear step.

## Next-command recommendation contract
- `sp-*` command responses should end by recommending the next likely command derived from the Golden Path or the nearest valid workflow branch.
- Prefer one `Recommended Next Command:` line with one full copy/pasteable command invocation.
- When the next step is genuinely ambiguous, emit `Recommended Next Commands:` with up to three full command invocations ordered best-first.
- Use concrete selectors or inputs from the current context when they are knowable; do not stop at bare selectors or vague "use X next" wording when a full command can be inferred.
- Proposal, inventory, and diagnosis prompts may still explain alternate branches, but they should pair that explanation with the concrete next command line or lines.
- Exception: handoff-driven co-authoring turns may treat one durable HANDOFF block as the authoritative next-step carrier when that handoff already names the next role and one repo-root-relative file path; in that case do not duplicate the same move with a separate `Recommended Next Command:` line unless the user explicitly asks for it.
- If the workflow is already at a terminal or explicitly blocked state with no defensible next command, say so explicitly instead of inventing one.

## Plan shell contract
- `sp-plan/PLAN.md` is the shared coordination surface for payload workflow truth.
- `sp-plan/PLAN.md` is the repo-root active workflow plan; subproject plans follow the convention `<subproject-root>/sp-plan/PLAN.md` (see § "Multi-plan scope").
- `sp-plan/PLAN.md` tracks repo/toolkit work and privacy-safe synthetic sample coordination only.
- `sp-plan/PLAN.md` must NEVER carry private or real person/company/job/application coordination.
- Real person/job-specific work must be planned and verified in ignored local person/package surfaces, not in tracked `sp-plan/PLAN.md`.
- This prohibition includes real identifiers, employer or role names, dossier/workbench file paths, co-authoring topic state, round-by-round review notes, and commands targeting ignored person folders.
- Do not mirror ignored local work into `sp-plan/PLAN.md` as real identifiers, placeholder stand-ins, or commands targeting ignored person folders.
- Keep `sp-plan/PLAN.md` at the level of goals, scope, affected surface families, and verification intent.
- Exact local script invocations, transient grep commands, and file-by-file inspection steps belong in `/sp-set-task-testing` output or local session notes, not in long-lived plan entries.
- Keep these sections in `sp-plan/PLAN.md`:
  - `## Current Work (keep up to date)`
  - `## Plan entries (phases + items)`
  - `## Archive`
- Keep repo-local active claims, branch ownership, and task lifecycle in `sp-plan/PLAN.md`.
- Keep reusable workflow explanation, Golden Path, and lifecycle rules in shared workflow docs instead of duplicating them into repo-local plan state.
- Historical or deprecated plan snapshots are reference-only and must not become active claim surfaces.

## Shared execution rules
- Default coordination branch: `main`
- Repositories may explicitly choose another shared integration branch, but only one branch may be authoritative for task claims.
- If implementation happens on a feature branch, claim/create/update task markers on the coordination-branch `sp-plan/PLAN.md` (default `main`), not only on the feature branch.
- Before substantial implementation starts, push the active task claim on the coordination branch so others can see it.
- `D#` items are documentation and verification checkpoints.
- Decisions do not belong in `D#` plan items; route them to README files, HLDs, or `00-Development-Rules.md` through PICARD findings routing.
- Task marker format options:
  - `Option LONG`:
    - Use these fields on active tasks:
      - `Status:` `Ready | InProgress | Blocked | Done`
      - `Owner:` `<person or agent id>`
      - `Branch:` `<working branch>`
      - `Updated:` `YYYY-MM-DD`
    - When a task is truly finished, collapse the item to a done marker such as `T#: (DONE) ...` and remove stale active-claim metadata instead of leaving it looking active forever.
  - `Option SHORT`:
    - Use this notation on active or completed tasks:
      - `T#: ( [InProgress | Blocked | Done] | Owner: <person or agent id> | YYYY-MM-DD )`
  - `CURRENT_OPTION = LONG`
- Owner uniqueness for multi-agent runs:
  - Prefer `Owner: <agent-app>/<agent-instance-id>`.
  - Recommended `<agent-instance-id>` format: `<branch-or-main>@<YYYYMMDDTHHMMSSZ>-<short-rand>`.
- Plan changes made only on a feature branch are branch-local notes until they are merged or copied to the coordination branch.
- The same claim protocol applies to GitHub-based collaboration and multiple local agents working in parallel.
- If work pauses, is abandoned, or is handed off, refresh or clear the claim instead of leaving it stale.
- Completed work should be marked done instead of keeping stale active-claim metadata on finished items.
- Tool approval loss, unavailable tools, or Restricted Mode behavior are blocking environment states and must be reported explicitly.
- If a required tool call is rejected or unavailable, stop the write path immediately and provide the exact pending patch or command sequence instead of continuing silently.

## Existing repo migration
- Fresh installs generate a `sp-plan/PLAN.md` shell that already points here.
- Updates preserve an existing `sp-plan/PLAN.md` by default because it is a mixed-role repo-local state file.
- If an older `sp-plan/PLAN.md` does not yet reference this contract, install/update may add the standard pointer with `-MigratePlanContractReference`.
- Without that opt-in migration, install/update should leave the plan untouched and write guidance under `.sp-kit/plan-migration/`.

## Multi-plan scope (scoped subproject plans)

### Convention

A repository may contain multiple independent plan surfaces:

| Surface | Scope | Path |
|---|---|---|
| Repo-root plan | Kit-level / cross-cutting work | `sp-plan/PLAN.md` |
| Subproject plan | Work scoped to a subproject directory tree | `<subproject-root>/sp-plan/PLAN.md` |

Example: `examples/sp-application-wizard/sp-plan/PLAN.md`

### Rules

1. **Scope isolation** — A subproject plan is authoritative only for work whose target files live within that subproject's directory tree. Claims in one plan do not conflict with claims in any other plan.
2. **Plan resolution** — Agents determine which plan to use by the target work path. If the target lives under a subproject root that contains its own `sp-plan/PLAN.md`, that plan governs. Otherwise the repo-root plan governs.
3. **ID namespace isolation** — Each plan has its own `P#/T#/D#` namespace. IDs are plan-local; no cross-plan deduplication is needed.
4. **Contract reuse** — All plans (root and subproject) follow this same workflow contract: Golden Path, claim gates, lifecycle markers, and plan-item semantics all apply identically.
5. **Coordination branch** — Each plan is authoritative on the repo's canonical coordination branch (`main` by default) unless the subproject explicitly declares otherwise in its own plan header.
6. **Backward compatibility** — A repo with zero subproject plans behaves identically to the previous single-plan model. The multi-plan convention is purely additive.

### Cross-cutting work

If a task spans both the root and a subproject (e.g., updating kit infrastructure that a subproject consumes), claim the task in the **root plan** and note the subproject dependency there. Do not duplicate the claim across plans.
