@gtrabanco/agentic-workflow-schema 1.0.0

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.
package/README.md ADDED
@@ -0,0 +1,57 @@
1
+ # @gtrabanco/agentic-workflow-schema
2
+
3
+ Types, JSON Schema, and parser/validator for the
4
+ [agentic-workflow](https://github.com/gtrabanco/agentic-workflow) **machine
5
+ envelope** — the fixed JSON block every user-facing skill prints as the
6
+ absolute last output of its turn, so external orchestrators can route the
7
+ workflow programmatically (which command next, on which model tier).
8
+
9
+ Zero runtime dependencies. Source of truth for the contract:
10
+ [`skills/orchestration-envelope/SKILL.md`](https://github.com/gtrabanco/agentic-workflow/blob/main/skills/orchestration-envelope/SKILL.md);
11
+ driver protocol:
12
+ [`docs/workflow/ORCHESTRATION.md`](https://github.com/gtrabanco/agentic-workflow/blob/main/docs/workflow/ORCHESTRATION.md).
13
+
14
+ ## Install
15
+
16
+ ```sh
17
+ npm install @gtrabanco/agentic-workflow-schema
18
+ ```
19
+
20
+ ## Use
21
+
22
+ ```ts
23
+ import {
24
+ parseEnvelope,
25
+ isTerminal,
26
+ isRunHalt,
27
+ } from "@gtrabanco/agentic-workflow-schema";
28
+
29
+ const output = await runAgentHeadless("Follow the installed SKILL.md for: /workflow-status --json-only");
30
+
31
+ const result = parseEnvelope(output); // extracts the LAST fenced ```json block
32
+ if (!result.ok) throw new Error(result.errors.join("; "));
33
+
34
+ const env = result.envelope; // fully typed
35
+ if (isRunHalt(env)) stopEverythingAndPage(env.blockers);
36
+ else if (isTerminal(env.state)) askHuman(env);
37
+ else invokeNext(env.next.recommended, env.next.tier); // "strong" | "cheap"
38
+ ```
39
+
40
+ The parse contract is exactly what the skills promise: **the last fenced
41
+ ```` ```json ````…```` ``` ```` block of the final message is the envelope**,
42
+ one per turn, all top-level keys always present.
43
+
44
+ Also exported: `extractLastJsonBlock(text)`, `validateEnvelope(value)`,
45
+ `ENVELOPE_STATES` (the 11-state enum), `TERMINAL_STATES`, and every field
46
+ type. A language-agnostic **JSON Schema** ships too:
47
+
48
+ ```ts
49
+ import schema from "@gtrabanco/agentic-workflow-schema/envelope.schema.json" with { type: "json" };
50
+ ```
51
+
52
+ ## Versioning
53
+
54
+ This package's semver tracks the **envelope contract**, not the repo:
55
+ breaking schema change (key removed/renamed, state removed) → major;
56
+ additive (new optional key, new state) → minor; fixes/docs → patch. When the
57
+ `orchestration-envelope` skill changes, this package changes in the same PR.
@@ -0,0 +1,135 @@
1
+ /**
2
+ * @gtrabanco/agentic-workflow-schema
3
+ *
4
+ * Types, extraction, and validation for the agentic-workflow **machine
5
+ * envelope** — the fixed JSON block every user-facing skill prints as the
6
+ * absolute last output of its turn.
7
+ *
8
+ * Parse contract (mirrors skills/orchestration-envelope/SKILL.md):
9
+ * take the LAST fenced ```json block of the assistant's final message;
10
+ * exactly one envelope per turn; all top-level keys always present.
11
+ */
12
+ export declare const ENVELOPE_STATES: readonly ["OK", "CONTINUE", "READY_FOR_REVIEW", "READY_FOR_AUDIT", "MERGE_READY", "MERGED", "NEEDS_FIXES", "BLOCKED", "NEEDS_INPUT", "FAILED", "HALT"];
13
+ export type EnvelopeState = (typeof ENVELOPE_STATES)[number];
14
+ /** States after which an orchestrator must stop and involve a human. */
15
+ export declare const TERMINAL_STATES: readonly EnvelopeState[];
16
+ export type UnitType = "feature" | "fix" | "docs" | "none";
17
+ export type PrState = "open" | "merged" | "none";
18
+ export type CiState = "green" | "red" | "pending" | "none";
19
+ export type VerificationState = "green" | "red" | "not-run";
20
+ export type BlockerKind = "dependency" | "issue" | "gate" | "merge-conflict" | "substrate" | "input";
21
+ export type BlockerScope = "unit" | "run";
22
+ export type Tier = "strong" | "cheap";
23
+ export interface EnvelopeUnit {
24
+ type: UnitType;
25
+ id: string | null;
26
+ issue: number | null;
27
+ branch: string | null;
28
+ }
29
+ export interface EnvelopePhase {
30
+ current: string | null;
31
+ total: number | null;
32
+ completed: number | null;
33
+ }
34
+ export interface EnvelopePr {
35
+ number: number | null;
36
+ url: string | null;
37
+ state: PrState;
38
+ head_sha: string | null;
39
+ merge_ready: boolean | null;
40
+ ci: CiState | null;
41
+ }
42
+ export interface EnvelopeGates {
43
+ verification: VerificationState | null;
44
+ review_pending: boolean | null;
45
+ audit_pending: boolean | null;
46
+ }
47
+ export interface EnvelopeFixNowFinding {
48
+ ref: string;
49
+ title: string;
50
+ file?: string | null;
51
+ }
52
+ export interface EnvelopeFindings {
53
+ fix_now: EnvelopeFixNowFinding[];
54
+ /** Issue numbers created/updated this turn. */
55
+ issues_filed: number[];
56
+ untriaged: number;
57
+ decisions_recorded: number;
58
+ }
59
+ export interface EnvelopeBlocker {
60
+ kind: BlockerKind;
61
+ id: string;
62
+ scope: BlockerScope;
63
+ detail: string;
64
+ }
65
+ export interface EnvelopeDependencies {
66
+ unmet: string[];
67
+ /** Deepest-first order to unblock. */
68
+ build_order: string[];
69
+ }
70
+ export interface EnvelopeRecommendations {
71
+ product_audit: boolean;
72
+ reason: string | null;
73
+ }
74
+ export interface EnvelopeNeedsInput {
75
+ question: string;
76
+ options: string[];
77
+ }
78
+ export interface EnvelopeNext {
79
+ recommended: string;
80
+ alternatives: string[];
81
+ tier: Tier;
82
+ }
83
+ export interface Envelope {
84
+ skill: string;
85
+ state: EnvelopeState;
86
+ summary: string;
87
+ unit: EnvelopeUnit;
88
+ phase: EnvelopePhase;
89
+ pr: EnvelopePr;
90
+ gates: EnvelopeGates;
91
+ findings: EnvelopeFindings;
92
+ blockers: EnvelopeBlocker[];
93
+ dependencies: EnvelopeDependencies;
94
+ recommendations: EnvelopeRecommendations;
95
+ needs_input: EnvelopeNeedsInput | null;
96
+ next: EnvelopeNext;
97
+ /** Skill-specific payload; documented per skill. */
98
+ detail: unknown;
99
+ }
100
+ /**
101
+ * Returns the raw content of the LAST fenced ```json block in `text`,
102
+ * or null when none exists. This is the envelope parse contract.
103
+ */
104
+ export declare function extractLastJsonBlock(text: string): string | null;
105
+ export type ValidationResult = {
106
+ ok: true;
107
+ envelope: Envelope;
108
+ } | {
109
+ ok: false;
110
+ errors: string[];
111
+ };
112
+ /**
113
+ * Structural validation of a parsed value against the envelope contract.
114
+ * Checks required keys, the state enum, and the shape of the routing-critical
115
+ * fields (an orchestrator routes on these; `detail` is intentionally opaque).
116
+ */
117
+ export declare function validateEnvelope(value: unknown): ValidationResult;
118
+ export type ParseResult = {
119
+ ok: true;
120
+ envelope: Envelope;
121
+ raw: string;
122
+ } | {
123
+ ok: false;
124
+ errors: string[];
125
+ raw: string | null;
126
+ };
127
+ /**
128
+ * Extract the last fenced ```json block from a skill's turn output, parse it,
129
+ * and validate it against the envelope contract.
130
+ */
131
+ export declare function parseEnvelope(text: string): ParseResult;
132
+ /** True when the orchestrator must stop and involve a human. */
133
+ export declare function isTerminal(state: EnvelopeState): boolean;
134
+ /** True when every blocker (or any) demands stopping the whole run. */
135
+ export declare function isRunHalt(envelope: Envelope): boolean;
package/dist/index.js ADDED
@@ -0,0 +1,184 @@
1
+ /**
2
+ * @gtrabanco/agentic-workflow-schema
3
+ *
4
+ * Types, extraction, and validation for the agentic-workflow **machine
5
+ * envelope** — the fixed JSON block every user-facing skill prints as the
6
+ * absolute last output of its turn.
7
+ *
8
+ * Parse contract (mirrors skills/orchestration-envelope/SKILL.md):
9
+ * take the LAST fenced ```json block of the assistant's final message;
10
+ * exactly one envelope per turn; all top-level keys always present.
11
+ */
12
+ // ---------------------------------------------------------------------------
13
+ // Types (source of truth: skills/orchestration-envelope/SKILL.md)
14
+ // ---------------------------------------------------------------------------
15
+ export const ENVELOPE_STATES = [
16
+ "OK",
17
+ "CONTINUE",
18
+ "READY_FOR_REVIEW",
19
+ "READY_FOR_AUDIT",
20
+ "MERGE_READY",
21
+ "MERGED",
22
+ "NEEDS_FIXES",
23
+ "BLOCKED",
24
+ "NEEDS_INPUT",
25
+ "FAILED",
26
+ "HALT",
27
+ ];
28
+ /** States after which an orchestrator must stop and involve a human. */
29
+ export const TERMINAL_STATES = [
30
+ "NEEDS_INPUT",
31
+ "FAILED",
32
+ "HALT",
33
+ ];
34
+ // ---------------------------------------------------------------------------
35
+ // Extraction — last fenced ```json block
36
+ // ---------------------------------------------------------------------------
37
+ const FENCE_RE = /```json[ \t]*\r?\n([\s\S]*?)\r?\n[ \t]*```/g;
38
+ /**
39
+ * Returns the raw content of the LAST fenced ```json block in `text`,
40
+ * or null when none exists. This is the envelope parse contract.
41
+ */
42
+ export function extractLastJsonBlock(text) {
43
+ let last = null;
44
+ for (const match of text.matchAll(FENCE_RE)) {
45
+ last = match[1];
46
+ }
47
+ return last;
48
+ }
49
+ function isObj(v) {
50
+ return typeof v === "object" && v !== null && !Array.isArray(v);
51
+ }
52
+ const REQUIRED_KEYS = [
53
+ "skill",
54
+ "state",
55
+ "summary",
56
+ "unit",
57
+ "phase",
58
+ "pr",
59
+ "gates",
60
+ "findings",
61
+ "blockers",
62
+ "dependencies",
63
+ "recommendations",
64
+ "needs_input",
65
+ "next",
66
+ ];
67
+ /**
68
+ * Structural validation of a parsed value against the envelope contract.
69
+ * Checks required keys, the state enum, and the shape of the routing-critical
70
+ * fields (an orchestrator routes on these; `detail` is intentionally opaque).
71
+ */
72
+ export function validateEnvelope(value) {
73
+ const errors = [];
74
+ if (!isObj(value)) {
75
+ return { ok: false, errors: ["envelope is not a JSON object"] };
76
+ }
77
+ for (const key of REQUIRED_KEYS) {
78
+ if (!(key in value))
79
+ errors.push(`missing required key: ${key}`);
80
+ }
81
+ if (typeof value.skill !== "string" || value.skill.length === 0) {
82
+ errors.push("skill must be a non-empty string");
83
+ }
84
+ if (!ENVELOPE_STATES.includes(value.state)) {
85
+ errors.push(`state must be one of ${ENVELOPE_STATES.join("|")} (got: ${String(value.state)})`);
86
+ }
87
+ if (typeof value.summary !== "string") {
88
+ errors.push("summary must be a string");
89
+ }
90
+ if (!isObj(value.unit))
91
+ errors.push("unit must be an object");
92
+ if (!isObj(value.phase))
93
+ errors.push("phase must be an object");
94
+ if (!isObj(value.pr))
95
+ errors.push("pr must be an object");
96
+ if (!isObj(value.gates))
97
+ errors.push("gates must be an object");
98
+ if (!Array.isArray(value.blockers)) {
99
+ errors.push("blockers must be an array");
100
+ }
101
+ else {
102
+ value.blockers.forEach((b, i) => {
103
+ if (!isObj(b) || typeof b.kind !== "string" || typeof b.id !== "string") {
104
+ errors.push(`blockers[${i}] must be {kind, id, scope, detail}`);
105
+ }
106
+ });
107
+ }
108
+ if (!isObj(value.dependencies)) {
109
+ errors.push("dependencies must be an object");
110
+ }
111
+ else {
112
+ if (!Array.isArray(value.dependencies.unmet)) {
113
+ errors.push("dependencies.unmet must be an array");
114
+ }
115
+ if (!Array.isArray(value.dependencies.build_order)) {
116
+ errors.push("dependencies.build_order must be an array");
117
+ }
118
+ }
119
+ if (!isObj(value.findings)) {
120
+ errors.push("findings must be an object");
121
+ }
122
+ else {
123
+ if (!Array.isArray(value.findings.fix_now)) {
124
+ errors.push("findings.fix_now must be an array");
125
+ }
126
+ if (!Array.isArray(value.findings.issues_filed) ||
127
+ !value.findings.issues_filed.every((n) => typeof n === "number" && Number.isInteger(n))) {
128
+ errors.push("findings.issues_filed must be an array of integers");
129
+ }
130
+ }
131
+ if (!isObj(value.next)) {
132
+ errors.push("next must be an object");
133
+ }
134
+ else {
135
+ if (typeof value.next.recommended !== "string") {
136
+ errors.push("next.recommended must be a string");
137
+ }
138
+ if (value.next.tier !== "strong" && value.next.tier !== "cheap") {
139
+ errors.push(`next.tier must be strong|cheap (got: ${String(value.next.tier)})`);
140
+ }
141
+ }
142
+ if (value.needs_input !== null && value.needs_input !== undefined) {
143
+ if (!isObj(value.needs_input) || typeof value.needs_input.question !== "string") {
144
+ errors.push("needs_input must be null or {question, options}");
145
+ }
146
+ }
147
+ if (errors.length > 0)
148
+ return { ok: false, errors };
149
+ return { ok: true, envelope: value };
150
+ }
151
+ /**
152
+ * Extract the last fenced ```json block from a skill's turn output, parse it,
153
+ * and validate it against the envelope contract.
154
+ */
155
+ export function parseEnvelope(text) {
156
+ const raw = extractLastJsonBlock(text);
157
+ if (raw === null) {
158
+ return { ok: false, errors: ["no fenced ```json block found"], raw: null };
159
+ }
160
+ let parsed;
161
+ try {
162
+ parsed = JSON.parse(raw);
163
+ }
164
+ catch (e) {
165
+ return {
166
+ ok: false,
167
+ errors: [`invalid JSON in last fenced block: ${e.message}`],
168
+ raw,
169
+ };
170
+ }
171
+ const result = validateEnvelope(parsed);
172
+ if (!result.ok)
173
+ return { ok: false, errors: result.errors, raw };
174
+ return { ok: true, envelope: result.envelope, raw };
175
+ }
176
+ /** True when the orchestrator must stop and involve a human. */
177
+ export function isTerminal(state) {
178
+ return TERMINAL_STATES.includes(state);
179
+ }
180
+ /** True when every blocker (or any) demands stopping the whole run. */
181
+ export function isRunHalt(envelope) {
182
+ return (envelope.state === "HALT" ||
183
+ envelope.blockers.some((b) => b.scope === "run"));
184
+ }
@@ -0,0 +1,156 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "$id": "https://github.com/gtrabanco/agentic-workflow/packages/agentic-workflow-schema/envelope.schema.json",
4
+ "title": "agentic-workflow machine envelope",
5
+ "description": "The fixed JSON block every user-facing agentic-workflow skill prints as the absolute last output of its turn. Source of truth: skills/orchestration-envelope/SKILL.md.",
6
+ "type": "object",
7
+ "required": [
8
+ "skill",
9
+ "state",
10
+ "summary",
11
+ "unit",
12
+ "phase",
13
+ "pr",
14
+ "gates",
15
+ "findings",
16
+ "blockers",
17
+ "dependencies",
18
+ "recommendations",
19
+ "needs_input",
20
+ "next"
21
+ ],
22
+ "properties": {
23
+ "skill": { "type": "string", "minLength": 1 },
24
+ "state": {
25
+ "enum": [
26
+ "OK",
27
+ "CONTINUE",
28
+ "READY_FOR_REVIEW",
29
+ "READY_FOR_AUDIT",
30
+ "MERGE_READY",
31
+ "MERGED",
32
+ "NEEDS_FIXES",
33
+ "BLOCKED",
34
+ "NEEDS_INPUT",
35
+ "FAILED",
36
+ "HALT"
37
+ ]
38
+ },
39
+ "summary": { "type": "string" },
40
+ "unit": {
41
+ "type": "object",
42
+ "required": ["type", "id", "issue", "branch"],
43
+ "properties": {
44
+ "type": { "enum": ["feature", "fix", "docs", "none"] },
45
+ "id": { "type": ["string", "null"] },
46
+ "issue": { "type": ["integer", "null"] },
47
+ "branch": { "type": ["string", "null"] }
48
+ }
49
+ },
50
+ "phase": {
51
+ "type": "object",
52
+ "required": ["current", "total", "completed"],
53
+ "properties": {
54
+ "current": { "type": ["string", "null"] },
55
+ "total": { "type": ["integer", "null"] },
56
+ "completed": { "type": ["integer", "null"] }
57
+ }
58
+ },
59
+ "pr": {
60
+ "type": "object",
61
+ "required": ["number", "url", "state", "head_sha", "merge_ready", "ci"],
62
+ "properties": {
63
+ "number": { "type": ["integer", "null"] },
64
+ "url": { "type": ["string", "null"] },
65
+ "state": { "enum": ["open", "merged", "none"] },
66
+ "head_sha": { "type": ["string", "null"] },
67
+ "merge_ready": { "type": ["boolean", "null"] },
68
+ "ci": { "enum": ["green", "red", "pending", "none", null] }
69
+ }
70
+ },
71
+ "gates": {
72
+ "type": "object",
73
+ "required": ["verification", "review_pending", "audit_pending"],
74
+ "properties": {
75
+ "verification": { "enum": ["green", "red", "not-run", null] },
76
+ "review_pending": { "type": ["boolean", "null"] },
77
+ "audit_pending": { "type": ["boolean", "null"] }
78
+ }
79
+ },
80
+ "findings": {
81
+ "type": "object",
82
+ "required": ["fix_now", "issues_filed", "untriaged", "decisions_recorded"],
83
+ "properties": {
84
+ "fix_now": {
85
+ "type": "array",
86
+ "items": {
87
+ "type": "object",
88
+ "required": ["ref", "title"],
89
+ "properties": {
90
+ "ref": { "type": "string" },
91
+ "title": { "type": "string" },
92
+ "file": { "type": ["string", "null"] }
93
+ }
94
+ }
95
+ },
96
+ "issues_filed": { "type": "array", "items": { "type": "integer" } },
97
+ "untriaged": { "type": "integer", "minimum": 0 },
98
+ "decisions_recorded": { "type": "integer", "minimum": 0 }
99
+ }
100
+ },
101
+ "blockers": {
102
+ "type": "array",
103
+ "items": {
104
+ "type": "object",
105
+ "required": ["kind", "id", "scope", "detail"],
106
+ "properties": {
107
+ "kind": {
108
+ "enum": ["dependency", "issue", "gate", "merge-conflict", "substrate", "input"]
109
+ },
110
+ "id": { "type": "string" },
111
+ "scope": { "enum": ["unit", "run"] },
112
+ "detail": { "type": "string" }
113
+ }
114
+ }
115
+ },
116
+ "dependencies": {
117
+ "type": "object",
118
+ "required": ["unmet", "build_order"],
119
+ "properties": {
120
+ "unmet": { "type": "array", "items": { "type": "string" } },
121
+ "build_order": { "type": "array", "items": { "type": "string" } }
122
+ }
123
+ },
124
+ "recommendations": {
125
+ "type": "object",
126
+ "required": ["product_audit", "reason"],
127
+ "properties": {
128
+ "product_audit": { "type": "boolean" },
129
+ "reason": { "type": ["string", "null"] }
130
+ }
131
+ },
132
+ "needs_input": {
133
+ "oneOf": [
134
+ { "type": "null" },
135
+ {
136
+ "type": "object",
137
+ "required": ["question", "options"],
138
+ "properties": {
139
+ "question": { "type": "string" },
140
+ "options": { "type": "array", "items": { "type": "string" } }
141
+ }
142
+ }
143
+ ]
144
+ },
145
+ "next": {
146
+ "type": "object",
147
+ "required": ["recommended", "alternatives", "tier"],
148
+ "properties": {
149
+ "recommended": { "type": "string" },
150
+ "alternatives": { "type": "array", "items": { "type": "string" } },
151
+ "tier": { "enum": ["strong", "cheap"] }
152
+ }
153
+ },
154
+ "detail": {}
155
+ }
156
+ }
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "@gtrabanco/agentic-workflow-schema",
3
+ "version": "1.0.0",
4
+ "description": "Types, JSON Schema, and parser/validator for the agentic-workflow machine envelope — the fixed JSON block every user-facing skill prints as its last output, for programmatic orchestration.",
5
+ "keywords": [
6
+ "agentic-workflow",
7
+ "agent",
8
+ "orchestration",
9
+ "skills",
10
+ "schema",
11
+ "envelope"
12
+ ],
13
+ "license": "MIT",
14
+ "author": "Gabriel Trabanco <gtrabanco@users.noreply.github.com>",
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/gtrabanco/agentic-workflow.git",
18
+ "directory": "packages/agentic-workflow-schema"
19
+ },
20
+ "homepage": "https://github.com/gtrabanco/agentic-workflow/blob/main/docs/workflow/ORCHESTRATION.md",
21
+ "type": "module",
22
+ "main": "./dist/index.js",
23
+ "types": "./dist/index.d.ts",
24
+ "exports": {
25
+ ".": {
26
+ "types": "./dist/index.d.ts",
27
+ "import": "./dist/index.js"
28
+ },
29
+ "./envelope.schema.json": "./envelope.schema.json"
30
+ },
31
+ "files": [
32
+ "dist",
33
+ "envelope.schema.json",
34
+ "README.md"
35
+ ],
36
+ "engines": {
37
+ "node": ">=18"
38
+ },
39
+ "publishConfig": {
40
+ "access": "public"
41
+ },
42
+ "scripts": {
43
+ "build": "tsc",
44
+ "test": "npm run build && node --test test/index.test.mjs",
45
+ "prepublishOnly": "npm test"
46
+ },
47
+ "devDependencies": {
48
+ "typescript": "6"
49
+ }
50
+ }