10 KiB
E2E Delivery Procedure (MANDATORY)
This guide is REQUIRED for all agent sessions.
0. Mode Handshake (Before Any Action)
First response MUST declare mode before tool calls or implementation steps:
- Orchestration mission:
Now initiating Orchestrator mode... - Implementation mission:
Now initiating Delivery mode... - Review-only mission:
Now initiating Review mode...
1. PRD Gate (Before Coding)
- Ensure
docs/PRD.mdordocs/PRD.jsonexists before coding. - Load
~/.config/mosaic/guides/PRD.md. - Prepare/update PRD from user input and available project context.
- If requirements are missing:
- proceed with best-guess assumptions by default,
- mark each assumption with
ASSUMPTION:and rationale, - escalate only when uncertainty is high-impact and cannot be bounded safely.
- Treat PRD as the requirement source for implementation, testing, and review.
1a. Tracking Gate (Before Coding)
- For non-trivial work,
docs/TASKS.mdMUST exist before coding. - If
docs/TASKS.mdis missing, create it from~/.config/mosaic/templates/docs/TASKS.md.template. - Detect provider first via
~/.config/mosaic/rails/git/detect-platform.sh. - For issue/PR/milestone operations, use Mosaic wrappers first (
~/.config/mosaic/rails/git/*.sh). - If external git provider is available (Gitea/GitHub/GitLab), create or update issue(s) before coding.
- Record provider issue reference(s) in
docs/TASKS.md(example:#123). - If no external provider is available, use internal task refs in
docs/TASKS.md(example:TASKS:T1). - Scratchpad MUST reference both task ID and issue/internal ref.
2. Intake and Scope
- Define scope, constraints, and acceptance criteria.
- Identify affected surfaces (API, DB, UI, infra, auth, CI/CD, docs).
- Identify required guides and load them before implementation.
- For code/API/auth/infra changes, load
~/.config/mosaic/guides/DOCUMENTATION.md. - Determine budget constraints:
- if the user provided a plan limit or token budget, treat it as a HARD cap,
- if budget is unknown, derive a working budget from estimates and runtime limits, then continue autonomously.
- Record budget assumptions and caps in the scratchpad before implementation starts.
- Track estimated vs used tokens per logical unit and adapt strategy to remain inside budget.
- If projected usage exceeds budget, auto-reduce scope/parallelism first; escalate only if cap still cannot be met.
2a. Steered Autonomy (Lights-Out)
- Agent owns delivery end-to-end: planning, coding, testing, review, PR/repo operations, release/tag, and deployment (when in scope).
- Human intervention is escalation-only; do not pause for routine approvals or handoffs.
- Continue execution until completion criteria are met or an escalation trigger is hit.
3. Scratchpad Requirement
- Create a task-specific scratchpad before implementation.
- Record:
- objective
- plan
- progress checkpoints
- tests run
- risks/blockers
- final verification evidence
4. Embedded Execution Cycle (MANDATORY)
For implementation work, you MUST run this cycle in order:
plan- map PRD requirements to concrete implementation steps.code- implement one logical unit.test- run required baseline and situational checks for that unit.review- perform independent code review on the current delta.remediate- fix all findings and any test failures.review- re-review remediated changes until blockers are cleared.commit- commit only when the logical unit passes tests and review.pre-push queue guard- before pushing, wait for running/queued project pipelines to clear:~/.config/mosaic/rails/git/ci-queue-wait.sh --purpose push.push- push immediately after queue guard passes.PR integration- if external git provider is available, create/update PR tomainand merge with required strategy via Mosaic wrappers.pre-merge queue guard- before merging PR, wait for running/queued project pipelines to clear:~/.config/mosaic/rails/git/ci-queue-wait.sh --purpose merge.CI/pipeline verification- wait for terminal CI status and require green before completion (~/.config/mosaic/rails/git/pr-ci-wait.shfor PR-based workflow).issue closure- close linked external issue (or close internaldocs/TASKS.mdtask ref when provider is unavailable).greenfield situational test- validate required user flows in a clean environment/startup path (post-merge for trunk workflow changes).deploy + post-deploy validation- when deployment is in scope, deploy to configured target and run post-deploy health/smoke checks.repeat- continue until all acceptance criteria are complete.
Post-PR Hard Gate (Execute Sequentially, No Exceptions)
~/.config/mosaic/rails/git/ci-queue-wait.sh --purpose merge -B main~/.config/mosaic/rails/git/pr-merge.sh -n <PR_NUMBER> -m squash~/.config/mosaic/rails/git/pr-ci-wait.sh -n <PR_NUMBER>~/.config/mosaic/rails/git/issue-close.sh -i <ISSUE_NUMBER>(or close internaldocs/TASKS.mdref when no provider exists)- If any step fails: set status
blocked, report the exact failed wrapper command, and stop. - Do not ask the human to perform routine merge/close operations.
- Do not claim completion before step 4 succeeds.
Forbidden Anti-Patterns
- Do NOT stop at "PR created" or "PR updated".
- Do NOT ask "should I merge?" for routine delivery PRs.
- Do NOT ask "should I close the issue?" after merge + green CI.
If any step fails, you MUST remediate and re-run from the relevant step before proceeding.
If push-queue/merge-queue/PR merge/CI/issue closure fails, status is blocked (not complete) and you MUST report the exact failed wrapper command.
5. Testing Priority Model
Use this order of priority:
- Situational tests are the PRIMARY gate and MUST prove changed behavior meets requirements.
- Baseline tests are REQUIRED safety checks and MUST run for all software changes.
- TDD is risk-based and REQUIRED only for specific high-risk change types.
6. Mandatory Test Baseline
For all software changes, you MUST run baseline checks applicable to the repo/toolchain:
- lint (or equivalent static checks)
- type checks (if language/tooling supports it)
- unit tests for changed logic
- integration tests for changed boundaries
7. Situational Testing Matrix (PRIMARY GATE)
Run additional tests based on what changed:
| Change Surface | Required Situational Tests |
|---|---|
| Authentication/authorization | auth failure-path tests, permission boundary tests, token/session validation |
| Database schema/migrations | migration up/down validation, rollback safety, data integrity checks |
| API contract changes | backward compatibility checks, consumer-impact tests, contract tests |
| Frontend/UI workflow changes | end-to-end flow tests, accessibility sanity checks, state transition checks |
| CI/CD or deployment changes | pipeline execution validation, artifact integrity checks, rollback path check |
| Security-sensitive logic | abuse-case tests, input validation fuzzing/sanitization checks |
| Performance-critical path | baseline comparison, regression threshold checks |
8. Risk-Based TDD Requirement
TDD is REQUIRED for:
- bug fixes (write a reproducer test first)
- security/auth/permission logic changes
- critical business logic and data-mutation rules
TDD is RECOMMENDED (not mandatory) for low-risk UI, copy, styling, and mechanical refactors. If TDD is skipped for a non-required case, record the rationale in the scratchpad.
9. Mandatory Code Review Gate
If you modify source code, you MUST run an independent code review before completion.
- Use automated review tooling when available.
- If automated tooling is unavailable, run manual review using
~/.config/mosaic/guides/CODE-REVIEW.md. - Any blocker or critical finding MUST be fixed or tracked as an explicit remediation task before closure.
10. Mandatory Documentation Gate
For code/API/auth/infra changes, documentation updates are REQUIRED before completion.
- Apply the standard in
~/.config/mosaic/guides/DOCUMENTATION.md. - Update required docs in the same logical change set as implementation.
- Complete
~/.config/mosaic/templates/docs/DOCUMENTATION-CHECKLIST.md. - If publish platform is unspecified, ask the user to choose in-app or external platform before publishing.
- Missing required documentation is a BLOCKER.
11. Completion Gate (All Required)
You MUST satisfy all items before completion:
- Acceptance criteria met.
- Baseline tests passed.
- Situational tests passed (primary gate), including required greenfield situational validation.
- PRD is current and implementation is aligned with PRD.
- Acceptance criteria mapped to verification evidence.
- Code review completed for source code changes.
- Required documentation updates completed and reviewed.
- Scratchpad updated with evidence.
- Known risks documented.
- No unresolved blocker hidden.
- If deployment is in scope, deployment target, release version, and post-deploy verification evidence are documented.
docs/TASKS.mdstatus and issue/internal references are updated to match delivered work.- If source code changed and external provider is available: PR merged to
main(squash), with merge evidence recorded. - CI/pipeline status is terminal green for the merged PR/head commit.
- Linked external issue is closed (or internal task ref is closed when no provider exists).
- If any of items 13-15 fail due access/tooling, report
blockedwith exact failed wrapper command and do not claim completion.
12. Review and Reporting
Completion report MUST include:
- what changed
- PRD alignment summary
- acceptance criteria to evidence mapping
- what was tested (baseline + situational)
- what was reviewed (code review scope)
- what documentation was updated
- command-level evidence summary
- residual risks
- deployment and post-deploy verification summary (if in scope)
- explicit pass/fail status
- tracking summary (
docs/TASKS.mdupdates and issue/internal refs) - PR lifecycle summary (PR number, merge commit, merge method)
- CI/pipeline summary (run/check URL, terminal status)
- issue closure summary (issue number/ref and close evidence)