@gtrabanco/agentic-workflow-schema 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +122 -0
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -59,6 +59,128 @@ On Node 20.10+/22, the newer import-attributes form also works:
59
59
  import schema from "@gtrabanco/agentic-workflow-schema/envelope.schema.json" with { type: "json" };
60
60
  ```
61
61
 
62
+ ## The envelope, field by field
63
+
64
+ Every top-level key is **always present** (`required` in the JSON Schema) —
65
+ a skill that has nothing to report for a key uses `null` / `[]` / `0`, never
66
+ omits it. **Closed** = the exact enum below is exhaustive (the validator
67
+ rejects anything else); **open** = free-form, any value of the stated type.
68
+
69
+ | Field | Type | Values | Meaning |
70
+ |---|---|---|---|
71
+ | `skill` | string | open (non-empty) | Which skill produced this envelope. |
72
+ | `state` | enum | **closed** — the 11 states below | The routing key. Everything an orchestrator decides starts here. |
73
+ | `summary` | string | open | One plain-text sentence: what happened this turn. |
74
+ | `unit.type` | enum | **closed** — `feature` · `fix` · `docs` · `none` | What kind of unit the turn worked on. |
75
+ | `unit.id` | string\|null | open | The unit's identifier (`NN-slug` for features, `n-topic` for fixes). |
76
+ | `unit.issue` | integer\|null | open | The tracking issue number, when the unit is issue-born. |
77
+ | `unit.branch` | string\|null | open | The working branch. |
78
+ | `phase.current` | string\|null | open (by convention `P1`, `P2`, …) | Phase just worked, for phased (M/L) features. |
79
+ | `phase.total` / `phase.completed` | integer\|null | open | Phase counts; `null` for single-pass units. |
80
+ | `pr.number` / `pr.url` / `pr.head_sha` | int/str\|null | open | The unit's PR, once it exists. |
81
+ | `pr.state` | enum | **closed** — `open` · `merged` · `none` | Merge state lives in the forge, not the roadmap. |
82
+ | `pr.merge_ready` | boolean\|null | open | `true` only after an `audit-pr` MERGE-READY verdict on the current head. |
83
+ | `pr.ci` | enum | **closed** — `green` · `red` · `pending` · `none` · `null` | `none` = the project has no CI; `null` = not checked this turn. |
84
+ | `gates.verification` | enum | **closed** — `green` · `red` · `not-run` · `null` | The project's own gate (type-check + tests + build) as last RUN. |
85
+ | `gates.review_pending` / `gates.audit_pending` | boolean\|null | open | Whether the mandatory review / merge audit still has to happen. |
86
+ | `findings.fix_now[]` | object array | items: `ref` (open), `title` (open), `file` (open, nullable) | Findings that must fold into the CURRENT branch before it advances. |
87
+ | `findings.issues_filed[]` | integer array | open | Issue numbers created/updated this turn. |
88
+ | `findings.untriaged` | integer ≥ 0 | open | Findings still without a destination — skills whose contract routes everything must report `0`. |
89
+ | `findings.decisions_recorded` | integer ≥ 0 | open | Decisions written to `decisions.md`-class records this turn. |
90
+ | `blockers[].kind` | enum | **closed** — `dependency` · `issue` · `gate` · `merge-conflict` · `substrate` · `input` | Why the unit (or run) cannot proceed. |
91
+ | `blockers[].scope` | enum | **closed** — `unit` · `run` | `run` means stop-the-world: nothing else proceeds either. |
92
+ | `blockers[].id` / `blockers[].detail` | string | open | What exactly (a slug, `#N`, a check name) + one line of context. |
93
+ | `dependencies.unmet[]` / `dependencies.build_order[]` | string arrays | open | Unmet roadmap/issue refs, and the deepest-first order to build them. |
94
+ | `recommendations.product_audit` | boolean | open | `true` when recurring drift suggests the founding assumptions are stale. |
95
+ | `recommendations.reason` | string\|null | open | Why (required in practice when the flag is `true`). |
96
+ | `needs_input` | object\|null | `question` (open) + `options[]` (open) | Non-null only on `state: NEEDS_INPUT` — the human decision to surface, with concrete options. Nothing was guessed. |
97
+ | `next.recommended` | string | open (a skill invocation) | The single best next command. |
98
+ | `next.alternatives[]` | string array | open | The other defensible choices. |
99
+ | `next.tier` | enum | **closed** — `strong` · `cheap` | Which model class the next step deserves — judgment vs mechanical. |
100
+ | `detail` | any | open (skill-specific) | Per-skill payload — e.g. `workflow-status` carries the full project tree (`features`, `fixes`, `startable_now`, `blocked_units`, `crash_recovery`, …) here. |
101
+
102
+ ### The `state` routing table (closed — exactly these 11)
103
+
104
+ | `state` | Meaning | Orchestrator action |
105
+ |---|---|---|
106
+ | `OK` | Skill finished its job | Invoke `next.recommended` on `next.tier` |
107
+ | `CONTINUE` | Same unit, more of the same work | Re-invoke `next.recommended` (advisory checkpoints also land here — the alternative is listed) |
108
+ | `READY_FOR_REVIEW` | Unit finished; mandatory review next | `/review-change` on a strong model, fresh context |
109
+ | `READY_FOR_AUDIT` | Review clean | `/audit-pr` (strong) |
110
+ | `MERGE_READY` | Audit passed on the current head SHA | Human merges — or your written auto-merge policy does |
111
+ | `MERGED` | An authorized auto-merge ran this turn | Next unit: poll `workflow-status` |
112
+ | `NEEDS_FIXES` | `findings.fix_now` is non-empty | Fold on-branch (commit AND push), then re-run the gate that emitted them |
113
+ | `BLOCKED` | Unmet dependency / external cause | Follow `dependencies.build_order`, or resolve `blockers[]` |
114
+ | `NEEDS_INPUT` | A human must decide | Surface `needs_input.question` + `options`; resume with the answer |
115
+ | `FAILED` | Retries exhausted | Stop this unit; a human looks |
116
+ | `HALT` | Stop-the-world discovery (`blockers[].scope: "run"`) | Stop the whole run; nothing proceeds until a human clears it |
117
+
118
+ `isTerminal(state)` covers `NEEDS_INPUT` / `FAILED` / `HALT` (+ human-gated
119
+ `MERGE_READY`); `isRunHalt(envelope)` is the `HALT` / run-scoped-blocker check.
120
+
121
+ ## Orchestrating with this schema
122
+
123
+ Two patterns, both consuming the same envelope. In both, **inject the
124
+ canonical system-prompt snippet** into every headless invocation (skills do
125
+ not emit the envelope on their own — `workflow-status` is the one exception):
126
+
127
+ ```text
128
+ Every turn you produce MUST end with exactly one fenced ```json block matching
129
+ the orchestration envelope schema (all top-level keys present; values only
130
+ from verified command output). Emit nothing after it.
131
+ ```
132
+
133
+ …and run the **repair loop** on parse failure — one retry, then fail the step:
134
+
135
+ ```ts
136
+ async function turn(prompt: string) {
137
+ let out = await invokeAgent(prompt, { system: SNIPPET });
138
+ let r = parseEnvelope(out);
139
+ if (!r.ok) {
140
+ out = await invokeAgent("Emit only the machine envelope for the turn above.", { resume: true });
141
+ r = parseEnvelope(out);
142
+ if (!r.ok) throw new Error(`step failed: no valid envelope (${r.errors.join("; ")})`);
143
+ }
144
+ return r.envelope;
145
+ }
146
+ ```
147
+
148
+ **Pattern 1 — fixed driver loop** (start here): poll the sensor, route on
149
+ `state`, repeat. Full skeleton in
150
+ [`docs/workflow/ORCHESTRATION.md`](https://github.com/gtrabanco/agentic-workflow/blob/main/docs/workflow/ORCHESTRATION.md),
151
+ including the crash-recovery restart protocol (`--last-envelope` hint +
152
+ append-only envelope journal).
153
+
154
+ **Pattern 2 — dynamic workflows** (the conductor pattern): one long-running
155
+ conductor context *writes and monitors* the work plan; every worker runs in a
156
+ **clean context** and only its envelope flows back up — the conductor never
157
+ ingests raw transcripts, which is what lets it stay long-running without
158
+ degrading. The envelope is precisely the "structured result" this pattern
159
+ needs:
160
+
161
+ ```ts
162
+ // Conductor: fan out independent units (workflow-status said they're startable
163
+ // in parallel and the project declares `worktrees`), read back only envelopes.
164
+ const status = await turn("Follow the installed SKILL.md for: /workflow-status --json-only");
165
+ const units = status.detail.startable_now as string[];
166
+
167
+ const results = await Promise.all(
168
+ units.map((u) => turn(`Follow the installed SKILL.md for: /execute-phase ${u}`))
169
+ );
170
+
171
+ for (const env of results) {
172
+ if (isRunHalt(env)) throw new Error(`HALT: ${JSON.stringify(env.blockers)}`);
173
+ if (env.state === "NEEDS_FIXES")
174
+ await turn(`Fold the fix-now findings on ${env.unit.branch}: ${JSON.stringify(env.findings.fix_now)}`);
175
+ }
176
+ // The conductor's own context grew by a few KB of envelopes — not by N transcripts.
177
+ ```
178
+
179
+ Safety floor for any driver, fixed loop or dynamic: never skip a
180
+ `review_pending`/`audit_pending` gate, never merge on anything but a fresh
181
+ `MERGE_READY` bound to the current head SHA, and treat `HALT` as terminal
182
+ until a human clears it.
183
+
62
184
  ## Versioning
63
185
 
64
186
  This package's semver tracks the **envelope contract**, not the repo:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gtrabanco/agentic-workflow-schema",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "Types, JSON Schema, and parser/validator for the agentic-workflow machine envelope — the fixed JSON block a driven agent turn ends with (workflow-status always; other skills under the driver-injected snippet), for programmatic orchestration.",
5
5
  "keywords": [
6
6
  "agentic-workflow",