orchestration-envelope · diff
v1.5.1 to v2.0.1
60 added, 102 removed. Audit A to A.
---
name: orchestration-envelope
user-invocable: false
- version: 1.5.1
+ version: 2.0.1
+ metadata:
+ internal: true
author: "Gabriel Trabanco <gtrabanco@users.noreply.github.com>"
license: MIT
description: >
- Internal contract of the agentic-workflow pack: the machine envelope — the
- fixed JSON block an external orchestrator parses to route the next step
- (which command, which model tier) without a human reading the chat. Skills
- do NOT emit it on their own (except workflow-status, the sensor): a driver
- that wants it injects the canonical system-prompt snippet defined here and
- runs the repair loop on parse failure. Not a menu entry; this skill owns the
- schema, and docs/workflow/ORCHESTRATION.md documents the driver loop that
- consumes it.
+ Internal machine-result contract for headless agentic-workflow drivers. The
+ executable source is @gtrabanco/agentic-workflow-schema: strict Envelope v2
+ for workflow-status, compact SkillOutcome v1 for driven work, compatibility
+ parsing, and deterministic document snapshots. Not a menu entry.
---
- # Machine envelope (internal contract)
-
- The **envelope** is one fenced `json` block, the **absolute last output** of a
- turn, used by an external orchestrator to route the outcome. This skill also
- owns the canonical [Turn contract](references/TURN_CONTRACT.md) (11 boxes;
- other skills load it plus their additions). **Emission** (feature 10):
-
- - **`workflow-status` always** (emitting it is the sensor's function).
- - **Other user-facing skills only on driver request**, via the canonical
- injected snippet below; interactive sessions emit none.
- - Internal skills never emit one; they return their fixed reports. At most one
- envelope exists per turn.
-
- **Parse contract for orchestrators:** take the **last fenced ```json block**
- of the final assistant message. Exactly one envelope per turn; parse failure
- → the repair loop below.
-
- ## Schema (all top-level keys ALWAYS present — use null / [] / 0 when n/a)
-
- ```json
- {
- "skill": "<emitting skill name>",
- "state": "OK | CONTINUE | READY_FOR_REVIEW | READY_FOR_AUDIT | MERGE_READY | MERGED | NEEDS_FIXES | BLOCKED | NEEDS_INPUT | FAILED | HALT",
- "summary": "<one plain-text sentence: what happened this turn>",
- "unit": {"type": "feature | fix | docs | none", "id": "<NN-slug | N-topic | null>", "issue": null, "branch": "<branch | null>"},
- "phase": {"current": "<P2 | null>", "total": null, "completed": null},
- "pr": {"number": null, "url": null, "state": "open | merged | none", "head_sha": null, "merge_ready": null, "ci": "green | red | pending | none | null"},
- "gates": {"verification": "green | red | not-run | null", "review_pending": null, "audit_pending": null},
- "findings": {"fix_now": [], "issues_filed": [], "untriaged": 0, "decisions_recorded": 0},
- "blockers": [],
- "dependencies": {"unmet": [], "build_order": []},
- "recommendations": {"product_audit": false, "reason": null},
- "needs_input": null,
- "next": {"recommended": "<the → Next: block's recommended command>", "alternatives": [], "tier": "strong | cheap", "suggested": []},
- "detail": null
- }
- ```
+ # Machine result contract (internal)
- Field rules (checkable):
+ Interactive skills remain text-first. A headless driver obtains a compact,
+ validated result at the boundary; it does not add a repeated JSON section to
+ every user-facing skill.
- - **`state`** is exactly one of the 11 schema values. Route semantics: `OK`
- finished; `CONTINUE` has more same-unit work; `READY_FOR_REVIEW` requires
- `review-change` and `gates.review_pending: true`; `READY_FOR_AUDIT` requires
- `audit-pr`; `MERGE_READY` permits documented human/auto merge and sets
- `pr.merge_ready: true`; `MERGED` means authorized auto-merge ran;
- `NEEDS_FIXES` has current-branch `findings.fix_now`; `BLOCKED` cannot proceed;
- `NEEDS_INPUT` fills `needs_input.question` and `.options`; `FAILED` exhausted
- in-skill retries; `HALT` stops the whole run and every blocker has `scope: run`.
- - **`findings`**: `fix_now` objects are `{ref,title,file}`; `issues_filed` is
- integer issue numbers; `untriaged` counts findings without a destination.
- - **`blockers[]`** objects are `{kind,id,scope,detail}` where `kind` is
- `dependency|issue|gate|merge-conflict|substrate|input` and `scope` is
- `unit|run`.
- `dependencies.unmet` lists prerequisite ids; `build_order` is deepest-first.
- - **`next.tier`** is `strong` for plan/review/audit/triage judgment and `cheap`
- for mechanical work. `next.suggested[]` is optional and workflow-status-only;
- each `{command,trigger,source_skill}` quotes the owning condition and is
- advisory beside `next.recommended`/`next.tier` (mirrored in schema package 2.1.0).
- - **`detail`** is an optional emitter-defined object, otherwise `null`.
- Truthfulness: use verified command output; unverified values are `null`.
- Placement: one fenced ```json object, absolutely last, with nothing after it.
+ The canonical [Turn contract](references/TURN_CONTRACT.md) remains here for
+ the executor and review skills that load it.
- ## Driver system-prompt snippet + repair loop
+ The executable source of truth is
+ [`@gtrabanco/agentic-workflow-schema`](../../packages/agentic-workflow-schema/):
+ types, JSON Schemas, `renderOutputInstruction(skill)`, `parseTurn(input)`, and
+ `compileWorkflowSnapshot(input)`. This document states the policy only; do not
+ copy a second schema here.
- User-facing skills (except `workflow-status`) do not print an envelope inline.
- A driver that wants one injects this **canonical system-prompt snippet**
- verbatim into every headless invocation:
+ ## Output profiles
- ```text
- Every turn you produce MUST end with exactly one fenced ```json block matching
- the orchestration envelope schema (all top-level keys present; values only
- from verified command output). Emit nothing after it.
- ```
+ `WORKFLOW_SKILL_PROFILES` is the authoritative inventory.
- **Repair loop:** if `parseEnvelope(lastTurn)` fails, re-invoke the **same
- session** once with `Emit only the machine envelope for the turn above.` and
- parse that reply. A second failure is driver-level `FAILED`; never retry
- indefinitely.
+ - `workflow-status` always returns the strict **Envelope v2** sensor result.
+ Its envelope includes the detailed project view under `detail`.
+ - The other driver-invoked skills return **SkillOutcome v1** only when the
+ driver appends `renderOutputInstruction(skill)` to that invocation. It has
+ the small model-owned fields: outcome, next intent/targets, blockers,
+ questions, discoveries, and evidence references.
+ - `ship-roadmap` is the conductor, not a worker profile: it keeps its native
+ terminal `SHIP:` banner and is parsed by its own fixed turn contract.
+ - Interactive invocations emit their normal human-readable reports; no driver
+ result is required.
- **Structured-output shortcut (optional):** when supported, send only the
- envelope/repair turn with `response_format: {type: "json_schema", strict: true}`
- and the package schema. Keep working turns unrestricted; otherwise prose/tool
- use is suppressed. The repair loop remains the fallback.
+ Both results are one final fenced `json` block. The package rejects unknown
+ keys at the routing boundary. Repository facts are never reconstructed from
+ model prose: the driver compiles `WorkflowSnapshot v1` from its selected,
+ versioned documents and caller-supplied repository facts.
- `workflow-status` still emits inline (`--json-only` depends on it), so polling
- it needs no repair loop; the snippet applies only to other user-facing skills.
+ ## Driver protocol
- ## Companion npm package (keep it in sync)
+ 1. Read the profile and append `renderOutputInstruction(skill)` only for a
+ driven invocation.
+ 2. Pass the final response to `parseTurn({skill, text, context})`. Keep the
+ returned source and diagnostics with the run journal.
+ 3. On an absent, malformed, or invalid machine result, re-invoke the same
+ session once with: `Emit only the machine result for the turn above.`
+ 4. Parse the repair reply. A second failure is driver-level `FAILED`; never
+ retry indefinitely and never turn arbitrary prose into workflow facts.
- The schema ships as **`@gtrabanco/agentic-workflow-schema`** in
- `packages/agentic-workflow-schema/` (types, JSON Schema, `parseEnvelope()`).
- Any schema change must update `src/index.ts`, `envelope.schema.json`, tests and
- the package semver in the same PR (removed/renamed key or state = major,
- additive = minor, fix = patch). CI publishes new versions on merge; skipping
- the package makes the change incomplete.
+ Compatibility is deliberately narrow: it can repair documented legacy v2
+ shapes only when the missing value is mechanically knowable. A nonzero issue
+ count without issue identities, an unmatched numeric unit id, or unrelated
+ prose remains invalid and is surfaced to the driver.
- ## Relationship to other skills
+ ## Contract evolution
- Every user-facing skill carries a `## Machine envelope` section for its states
- and `detail`; this file owns the shared schema. `workflow-status` is the
- read-only sensor with the richest `detail`. `docs/workflow/ORCHESTRATION.md`
- documents the external state → command → tier loop.
+ - Envelope v2 is strict for new drivers. `detail` is required (usually `null`)
+ and skill-specific extensions live inside it; `design_candidates`, for
+ example, is `detail.design_candidates`, never a root key.
+ - `workflow-status` retains Envelope v2 for existing sensor consumers.
+ `parseEnvelope()` remains the legacy-compatible package API; new consumers
+ use `parseEnvelopeV2Strict()` or `parseTurn()`.
+ - `SkillOutcome v1` and `WorkflowSnapshot v1` are separate, versioned JSON
+ Schemas. A breaking change to any published contract is a package major.
## Normalized Repository State
- Drivers call `discover-repository-state` before planning and pass the frozen
- `docs/workflow/REPOSITORY_STATE.md` reference forward. Contradictions route to
- `resolve-repository-state`; never silently replace the snapshot.
+ Drivers call `discover-repository-state` before planning and retain the frozen
+ `docs/workflow/REPOSITORY_STATE.md` reference. `WorkflowSnapshot v1` preserves
+ unknowns, provenance, and declared contradictions; a driver routes a
+ contradiction to `resolve-repository-state` rather than silently replacing it.