@gtrabanco/agentic-workflow-schema 4.1.1 → 4.2.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 +20 -3
- package/dist/continuation-vectors.d.ts +22 -0
- package/dist/continuation-vectors.js +28 -0
- package/dist/continuation.d.ts +117 -0
- package/dist/continuation.js +260 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +29 -1
- package/envelope.schema.json +36 -0
- package/package.json +1 -2
- package/README.es.md +0 -781
package/README.md
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
# @gtrabanco/agentic-workflow-schema
|
|
2
2
|
|
|
3
|
-
> 🇪🇸 [Versión en español](README.es.md)
|
|
4
|
-
|
|
5
3
|
Zero-runtime-dependency machine contracts for
|
|
6
4
|
[agentic-workflow](https://github.com/gtrabanco/agentic-workflow). Version 3
|
|
7
5
|
keeps the established `workflow-status` envelope while giving headless drivers
|
|
@@ -197,6 +195,25 @@ It refuses a nonzero issue count without identities, an unmatched unit id, and
|
|
|
197
195
|
unstructured prose. The compatibility diagnostics make every repair visible to
|
|
198
196
|
the driver.
|
|
199
197
|
|
|
198
|
+
### Additive guarantee — `next.continuation` (feature 59, 4.2.0)
|
|
199
|
+
|
|
200
|
+
Envelope v2's `next` gains an **optional** `continuation` object:
|
|
201
|
+
`{ argv, rendering?, preconditions, evidence?, convergence }`. `argv` is the
|
|
202
|
+
command of record; `rendering` is display-only and derivable from `argv` per
|
|
203
|
+
platform family; `preconditions` carry the emitter's at-emit evaluation;
|
|
204
|
+
`evidence` is a receiver-verifiable `{ artifact, digest }` token; `convergence`
|
|
205
|
+
names the envelope/state field the command advances.
|
|
206
|
+
|
|
207
|
+
**Envelopes without `next.continuation` stay valid** — the field is additive,
|
|
208
|
+
so every 4.1.x consumer keeps validating and reading the same documents, and no
|
|
209
|
+
release here is a major bump. Omission is the absence semantics: the field is
|
|
210
|
+
never `null` and never defaulted. The public surface is `emitContinuation`
|
|
211
|
+
(pure, fail-closed), `CONTINUATION_REFUSALS` (the closed four-code refusal
|
|
212
|
+
vocabulary), `deriveContinuationRendering`, `parseContinuationArgv`,
|
|
213
|
+
`validateContinuation`, `canonicalizeContinuation`,
|
|
214
|
+
`verifyContinuationEvidence`, and the frozen `CONTINUATION_CANONICAL_VECTORS`.
|
|
215
|
+
Nothing is persisted by any of them.
|
|
216
|
+
|
|
200
217
|
## Workflow transition decider
|
|
201
218
|
|
|
202
219
|
Export `decideWorkflowAction(input)` — a pure, deterministic function that
|
|
@@ -602,7 +619,7 @@ installed-package consumer can run:
|
|
|
602
619
|
| `npm run check:verification-schemas` | rebuild and byte-check generated projections |
|
|
603
620
|
| `npm run check:verification-package` | inspect the package tarball contract |
|
|
604
621
|
| `npm run bench:verification -- --commands 128` | run the AC10 warm-process benchmark |
|
|
605
|
-
| `npm run test:verification-docs` | run the executable
|
|
622
|
+
| `npm run test:verification-docs` | run the executable documentation suite |
|
|
606
623
|
| `npm run gate:verification` | compose all verification release checks |
|
|
607
624
|
|
|
608
625
|
**Two-stage model:** requesting `fast` executes only fast commands; requesting
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Published canonical vectors for the continuation object.
|
|
3
|
+
*
|
|
4
|
+
* Each entry pins the EXACT lowercase SHA-256 digest of one fixture document
|
|
5
|
+
* (`test/fixtures/continuation-vectors.mjs`, kept in sync by name), canonicalized
|
|
6
|
+
* with `canonicalizeContinuation` (sorted keys, compact separators). The payloads
|
|
7
|
+
* are written as literal JSON documents — not produced by the emitter — so a change
|
|
8
|
+
* to the canonical serializer or the field projection shifts a digest here and the
|
|
9
|
+
* suite fails instead of silently re-blessing new bytes.
|
|
10
|
+
*
|
|
11
|
+
* A digest change is a contract change: it is reviewed, versioned, and recorded in
|
|
12
|
+
* `CHANGELOG.md`, never regenerated to make a test pass.
|
|
13
|
+
*/
|
|
14
|
+
/** Contract identifier for the continuation object (owned by `continuation.ts`). */
|
|
15
|
+
export declare const CONTINUATION_VECTOR_CONTRACT = "agentic-workflow/continuation@1";
|
|
16
|
+
export interface ContinuationCanonicalVector {
|
|
17
|
+
readonly contract: string;
|
|
18
|
+
readonly description: string;
|
|
19
|
+
readonly digest: string;
|
|
20
|
+
}
|
|
21
|
+
/** The two shipped vectors: minimal and full (with evidence). */
|
|
22
|
+
export declare const CONTINUATION_CANONICAL_VECTORS: readonly ContinuationCanonicalVector[];
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Published canonical vectors for the continuation object.
|
|
3
|
+
*
|
|
4
|
+
* Each entry pins the EXACT lowercase SHA-256 digest of one fixture document
|
|
5
|
+
* (`test/fixtures/continuation-vectors.mjs`, kept in sync by name), canonicalized
|
|
6
|
+
* with `canonicalizeContinuation` (sorted keys, compact separators). The payloads
|
|
7
|
+
* are written as literal JSON documents — not produced by the emitter — so a change
|
|
8
|
+
* to the canonical serializer or the field projection shifts a digest here and the
|
|
9
|
+
* suite fails instead of silently re-blessing new bytes.
|
|
10
|
+
*
|
|
11
|
+
* A digest change is a contract change: it is reviewed, versioned, and recorded in
|
|
12
|
+
* `CHANGELOG.md`, never regenerated to make a test pass.
|
|
13
|
+
*/
|
|
14
|
+
/** Contract identifier for the continuation object (owned by `continuation.ts`). */
|
|
15
|
+
export const CONTINUATION_VECTOR_CONTRACT = "agentic-workflow/continuation@1";
|
|
16
|
+
/** The two shipped vectors: minimal and full (with evidence). */
|
|
17
|
+
export const CONTINUATION_CANONICAL_VECTORS = Object.freeze([
|
|
18
|
+
Object.freeze({
|
|
19
|
+
contract: CONTINUATION_VECTOR_CONTRACT,
|
|
20
|
+
description: "minimal valid continuation (status-refresh class)",
|
|
21
|
+
digest: "2cfdfc3e95af4e277786b1b696017c5938fd666a7a4121c4c61011259409ecb2",
|
|
22
|
+
}),
|
|
23
|
+
Object.freeze({
|
|
24
|
+
contract: CONTINUATION_VECTOR_CONTRACT,
|
|
25
|
+
description: "full continuation with evidence (planning-gate class)",
|
|
26
|
+
digest: "08d10a797abf9d0dc7b8629aa82eca47b54409865a6591c18ccbbddf7699913c",
|
|
27
|
+
}),
|
|
28
|
+
]);
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Envelope v2 `next.continuation` — the executable hand-off object (feature 59).
|
|
3
|
+
*
|
|
4
|
+
* One deterministic emitter, many quoters. This module owns the frozen shape,
|
|
5
|
+
* the closed refusal vocabulary, the argv parser, the per-platform rendering
|
|
6
|
+
* derivation, the emitter, the validator, and the receiver-side evidence check.
|
|
7
|
+
* It fabricates nothing and persists nothing: every member it emits comes from
|
|
8
|
+
* an already-resolved command string plus the caller's unit context, and every
|
|
9
|
+
* failure path returns a typed refusal from `CONTINUATION_REFUSALS` instead of
|
|
10
|
+
* a guessed command (SPEC D-59-4/D-59-5/D-59-8, AC1, AC4, AC5).
|
|
11
|
+
*
|
|
12
|
+
* `argv` is the command of record; `rendering` is display-only and derivable
|
|
13
|
+
* from `argv` per platform family, so a caller may re-render for its own shell
|
|
14
|
+
* without ever changing the command. The whole field is optional: an Envelope
|
|
15
|
+
* without it stays valid (additive minor).
|
|
16
|
+
*/
|
|
17
|
+
/** Contract identifier for the continuation object. */
|
|
18
|
+
export declare const CONTINUATION_CONTRACT_ID = "agentic-workflow/continuation@1";
|
|
19
|
+
/**
|
|
20
|
+
* The closed refusal vocabulary (≤ 4 codes). A continuation that cannot be
|
|
21
|
+
* checked or rendered becomes one of these; extending the set is a SPEC change
|
|
22
|
+
* (D-59-5), never an emitter extension.
|
|
23
|
+
*/
|
|
24
|
+
export declare const CONTINUATION_REFUSALS: readonly ["precondition-uncheckable", "rendering-failed", "no-decision-available", "sensor-degraded"];
|
|
25
|
+
export type ContinuationRefusalCode = (typeof CONTINUATION_REFUSALS)[number];
|
|
26
|
+
/**
|
|
27
|
+
* Rendering families the derivation understands. v1 *emits* the POSIX-shell
|
|
28
|
+
* rendering (E-59-5); the Windows family is derivable by the same rule and is
|
|
29
|
+
* pinned by the rendering tests, but is not emitted until a SPEC change extends
|
|
30
|
+
* the family set (B-02).
|
|
31
|
+
*/
|
|
32
|
+
export declare const CONTINUATION_PLATFORM_FAMILIES: readonly ["posix", "windows"];
|
|
33
|
+
export type ContinuationPlatformFamily = (typeof CONTINUATION_PLATFORM_FAMILIES)[number];
|
|
34
|
+
/** One emit-time-checked precondition. `satisfied` is the emitter's evaluation. */
|
|
35
|
+
export interface ContinuationPrecondition {
|
|
36
|
+
id: string;
|
|
37
|
+
check: string;
|
|
38
|
+
satisfied: boolean;
|
|
39
|
+
}
|
|
40
|
+
/** Receiver-verifiable evidence token: `digest` is lowercase SHA-256 of `artifact`. */
|
|
41
|
+
export interface ContinuationEvidence {
|
|
42
|
+
artifact: string;
|
|
43
|
+
digest: string;
|
|
44
|
+
}
|
|
45
|
+
/** The frozen `next.continuation` shape (all members required unless marked `?`). */
|
|
46
|
+
export interface EnvelopeContinuation {
|
|
47
|
+
argv: string[];
|
|
48
|
+
/** Display-only, derived from `argv`; never alters the command of record. */
|
|
49
|
+
rendering?: string;
|
|
50
|
+
preconditions: ContinuationPrecondition[];
|
|
51
|
+
evidence?: ContinuationEvidence;
|
|
52
|
+
/** The envelope/state field that must measurably advance when the command runs. */
|
|
53
|
+
convergence: string;
|
|
54
|
+
}
|
|
55
|
+
/** Emitter input: the already-resolved command plus the unit context. */
|
|
56
|
+
export interface EmitContinuationInput {
|
|
57
|
+
/** Already-resolved command string (e.g. `next.recommended`). Never re-derived here. */
|
|
58
|
+
command: string;
|
|
59
|
+
/** The field the command advances (per-class, frozen in the SPEC's class table). */
|
|
60
|
+
convergence: string;
|
|
61
|
+
/** At-emit evaluation rows. Absent means "no preconditions declared". */
|
|
62
|
+
preconditions?: readonly ContinuationPrecondition[];
|
|
63
|
+
/** Optional evidence token; its digest is not recomputed here (see the verifier). */
|
|
64
|
+
evidence?: ContinuationEvidence;
|
|
65
|
+
/** Sensor input: `false` when no decision is available → `no-decision-available`. */
|
|
66
|
+
decisionAvailable?: boolean;
|
|
67
|
+
/** Sensor input: `true` when forge/git state is unavailable → `sensor-degraded`. */
|
|
68
|
+
sensorDegraded?: boolean;
|
|
69
|
+
/** Rendering family to emit. Defaults to `posix` (E-59-5). */
|
|
70
|
+
platform?: ContinuationPlatformFamily;
|
|
71
|
+
}
|
|
72
|
+
export type EmitContinuationResult = {
|
|
73
|
+
ok: true;
|
|
74
|
+
continuation: EnvelopeContinuation;
|
|
75
|
+
} | {
|
|
76
|
+
ok: false;
|
|
77
|
+
refusal: ContinuationRefusalCode;
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* Parse a resolved command string into argv by whitespace splitting, honoring
|
|
81
|
+
* single and double quotes so a quoted argument stays one token. Throws on an
|
|
82
|
+
* unterminated quote; the emitter maps that to `rendering-failed`.
|
|
83
|
+
*/
|
|
84
|
+
export declare function parseContinuationArgv(command: string): string[];
|
|
85
|
+
/**
|
|
86
|
+
* Derive the display rendering from `argv` for a platform family. Pure: it
|
|
87
|
+
* never mutates `argv`, so re-rendering cannot change the command of record.
|
|
88
|
+
*/
|
|
89
|
+
export declare function deriveContinuationRendering(argv: readonly string[], family?: ContinuationPlatformFamily): string;
|
|
90
|
+
/**
|
|
91
|
+
* The pure, deterministic, fail-closed emitter (AC1/AC2/AC5).
|
|
92
|
+
*
|
|
93
|
+
* Input is the already-resolved command string plus the unit context; this
|
|
94
|
+
* function does NOT re-derive the decision. It parses argv, validates and copies
|
|
95
|
+
* the preconditions, derives the rendering, and returns the continuation. Every
|
|
96
|
+
* failure path returns `{ ok: false, refusal }`:
|
|
97
|
+
*
|
|
98
|
+
* - `sensor-degraded` — the caller reports forge/git state unavailable;
|
|
99
|
+
* - `no-decision-available`— empty command, empty convergence, or no decision flag;
|
|
100
|
+
* - `rendering-failed` — the command cannot be parsed to argv or rendered;
|
|
101
|
+
* - `precondition-uncheckable` — a precondition/evidence row is not checkable.
|
|
102
|
+
*/
|
|
103
|
+
export declare function emitContinuation(input: EmitContinuationInput): EmitContinuationResult;
|
|
104
|
+
/**
|
|
105
|
+
* Validate a `next.continuation` value. Returns typed error strings (empty when
|
|
106
|
+
* valid); the envelope validator folds these into its own error list so an
|
|
107
|
+
* invalid shape fails closed instead of validating silently.
|
|
108
|
+
*/
|
|
109
|
+
export declare function validateContinuation(value: unknown): string[];
|
|
110
|
+
/** Canonical serialization of a continuation value (sorted keys, compact). */
|
|
111
|
+
export declare function canonicalizeContinuation(value: unknown): string;
|
|
112
|
+
/**
|
|
113
|
+
* Receiver-side evidence check (AC4). Re-derives the SHA-256 of `artifactText`
|
|
114
|
+
* and compares it with the token's digest. Nothing is persisted; a mismatch is a
|
|
115
|
+
* plain `false`, never a repair.
|
|
116
|
+
*/
|
|
117
|
+
export declare function verifyContinuationEvidence(continuation: EnvelopeContinuation | null | undefined, artifactText: string): boolean;
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Envelope v2 `next.continuation` — the executable hand-off object (feature 59).
|
|
3
|
+
*
|
|
4
|
+
* One deterministic emitter, many quoters. This module owns the frozen shape,
|
|
5
|
+
* the closed refusal vocabulary, the argv parser, the per-platform rendering
|
|
6
|
+
* derivation, the emitter, the validator, and the receiver-side evidence check.
|
|
7
|
+
* It fabricates nothing and persists nothing: every member it emits comes from
|
|
8
|
+
* an already-resolved command string plus the caller's unit context, and every
|
|
9
|
+
* failure path returns a typed refusal from `CONTINUATION_REFUSALS` instead of
|
|
10
|
+
* a guessed command (SPEC D-59-4/D-59-5/D-59-8, AC1, AC4, AC5).
|
|
11
|
+
*
|
|
12
|
+
* `argv` is the command of record; `rendering` is display-only and derivable
|
|
13
|
+
* from `argv` per platform family, so a caller may re-render for its own shell
|
|
14
|
+
* without ever changing the command. The whole field is optional: an Envelope
|
|
15
|
+
* without it stays valid (additive minor).
|
|
16
|
+
*/
|
|
17
|
+
import { canonicalJSONValue } from "./canonical-json.js";
|
|
18
|
+
import { sha256HexSync } from "./sha256.js";
|
|
19
|
+
/** Contract identifier for the continuation object. */
|
|
20
|
+
export const CONTINUATION_CONTRACT_ID = "agentic-workflow/continuation@1";
|
|
21
|
+
/**
|
|
22
|
+
* The closed refusal vocabulary (≤ 4 codes). A continuation that cannot be
|
|
23
|
+
* checked or rendered becomes one of these; extending the set is a SPEC change
|
|
24
|
+
* (D-59-5), never an emitter extension.
|
|
25
|
+
*/
|
|
26
|
+
export const CONTINUATION_REFUSALS = Object.freeze([
|
|
27
|
+
"precondition-uncheckable",
|
|
28
|
+
"rendering-failed",
|
|
29
|
+
"no-decision-available",
|
|
30
|
+
"sensor-degraded",
|
|
31
|
+
]);
|
|
32
|
+
/**
|
|
33
|
+
* Rendering families the derivation understands. v1 *emits* the POSIX-shell
|
|
34
|
+
* rendering (E-59-5); the Windows family is derivable by the same rule and is
|
|
35
|
+
* pinned by the rendering tests, but is not emitted until a SPEC change extends
|
|
36
|
+
* the family set (B-02).
|
|
37
|
+
*/
|
|
38
|
+
export const CONTINUATION_PLATFORM_FAMILIES = Object.freeze(["posix", "windows"]);
|
|
39
|
+
const DIGEST_RE = /^[0-9a-f]{64}$/;
|
|
40
|
+
function isPlainObject(value) {
|
|
41
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Parse a resolved command string into argv by whitespace splitting, honoring
|
|
45
|
+
* single and double quotes so a quoted argument stays one token. Throws on an
|
|
46
|
+
* unterminated quote; the emitter maps that to `rendering-failed`.
|
|
47
|
+
*/
|
|
48
|
+
export function parseContinuationArgv(command) {
|
|
49
|
+
if (typeof command !== "string") {
|
|
50
|
+
throw new TypeError("continuation command must be a string");
|
|
51
|
+
}
|
|
52
|
+
const tokens = [];
|
|
53
|
+
let current = "";
|
|
54
|
+
let quote = null;
|
|
55
|
+
let started = false;
|
|
56
|
+
for (const ch of command) {
|
|
57
|
+
if (quote !== null) {
|
|
58
|
+
if (ch === quote)
|
|
59
|
+
quote = null;
|
|
60
|
+
else
|
|
61
|
+
current += ch;
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
if (ch === "'" || ch === '"') {
|
|
65
|
+
quote = ch;
|
|
66
|
+
started = true;
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
if (/\s/.test(ch)) {
|
|
70
|
+
if (started) {
|
|
71
|
+
tokens.push(current);
|
|
72
|
+
current = "";
|
|
73
|
+
started = false;
|
|
74
|
+
}
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
current += ch;
|
|
78
|
+
started = true;
|
|
79
|
+
}
|
|
80
|
+
if (quote !== null) {
|
|
81
|
+
throw new TypeError("continuation command has an unterminated quote");
|
|
82
|
+
}
|
|
83
|
+
if (started)
|
|
84
|
+
tokens.push(current);
|
|
85
|
+
return tokens;
|
|
86
|
+
}
|
|
87
|
+
const POSIX_SAFE = /^[A-Za-z0-9_@%+=:,./-]+$/;
|
|
88
|
+
function posixQuote(token) {
|
|
89
|
+
if (token.length > 0 && POSIX_SAFE.test(token))
|
|
90
|
+
return token;
|
|
91
|
+
return `'${token.replace(/'/g, "'\\''")}'`;
|
|
92
|
+
}
|
|
93
|
+
function windowsQuote(token) {
|
|
94
|
+
if (token.length > 0 && !/[\s"]/.test(token))
|
|
95
|
+
return token;
|
|
96
|
+
return `"${token.replace(/"/g, '""')}"`;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Derive the display rendering from `argv` for a platform family. Pure: it
|
|
100
|
+
* never mutates `argv`, so re-rendering cannot change the command of record.
|
|
101
|
+
*/
|
|
102
|
+
export function deriveContinuationRendering(argv, family = "posix") {
|
|
103
|
+
if (!Array.isArray(argv) || argv.length === 0 || !argv.every((token) => typeof token === "string")) {
|
|
104
|
+
throw new TypeError("continuation argv must be a non-empty array of strings");
|
|
105
|
+
}
|
|
106
|
+
if (family === "posix")
|
|
107
|
+
return argv.map(posixQuote).join(" ");
|
|
108
|
+
if (family === "windows")
|
|
109
|
+
return argv.map(windowsQuote).join(" ");
|
|
110
|
+
throw new TypeError(`unknown continuation platform family: ${String(family)}`);
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* The pure, deterministic, fail-closed emitter (AC1/AC2/AC5).
|
|
114
|
+
*
|
|
115
|
+
* Input is the already-resolved command string plus the unit context; this
|
|
116
|
+
* function does NOT re-derive the decision. It parses argv, validates and copies
|
|
117
|
+
* the preconditions, derives the rendering, and returns the continuation. Every
|
|
118
|
+
* failure path returns `{ ok: false, refusal }`:
|
|
119
|
+
*
|
|
120
|
+
* - `sensor-degraded` — the caller reports forge/git state unavailable;
|
|
121
|
+
* - `no-decision-available`— empty command, empty convergence, or no decision flag;
|
|
122
|
+
* - `rendering-failed` — the command cannot be parsed to argv or rendered;
|
|
123
|
+
* - `precondition-uncheckable` — a precondition/evidence row is not checkable.
|
|
124
|
+
*/
|
|
125
|
+
export function emitContinuation(input) {
|
|
126
|
+
if (!isPlainObject(input))
|
|
127
|
+
return { ok: false, refusal: "no-decision-available" };
|
|
128
|
+
if (input.sensorDegraded === true)
|
|
129
|
+
return { ok: false, refusal: "sensor-degraded" };
|
|
130
|
+
if (input.decisionAvailable === false)
|
|
131
|
+
return { ok: false, refusal: "no-decision-available" };
|
|
132
|
+
const command = typeof input.command === "string" ? input.command.trim() : "";
|
|
133
|
+
if (command.length === 0)
|
|
134
|
+
return { ok: false, refusal: "no-decision-available" };
|
|
135
|
+
const convergence = typeof input.convergence === "string" ? input.convergence.trim() : "";
|
|
136
|
+
if (convergence.length === 0)
|
|
137
|
+
return { ok: false, refusal: "no-decision-available" };
|
|
138
|
+
let argv;
|
|
139
|
+
try {
|
|
140
|
+
argv = parseContinuationArgv(command);
|
|
141
|
+
}
|
|
142
|
+
catch {
|
|
143
|
+
return { ok: false, refusal: "rendering-failed" };
|
|
144
|
+
}
|
|
145
|
+
if (argv.length === 0 || argv.some((token) => token.length === 0)) {
|
|
146
|
+
return { ok: false, refusal: "no-decision-available" };
|
|
147
|
+
}
|
|
148
|
+
const preconditions = [];
|
|
149
|
+
const rawPreconditions = input.preconditions ?? [];
|
|
150
|
+
if (!Array.isArray(rawPreconditions))
|
|
151
|
+
return { ok: false, refusal: "precondition-uncheckable" };
|
|
152
|
+
for (const row of rawPreconditions) {
|
|
153
|
+
if (!isPlainObject(row)
|
|
154
|
+
|| typeof row.id !== "string" || row.id.length === 0
|
|
155
|
+
|| typeof row.check !== "string" || row.check.length === 0
|
|
156
|
+
|| typeof row.satisfied !== "boolean") {
|
|
157
|
+
return { ok: false, refusal: "precondition-uncheckable" };
|
|
158
|
+
}
|
|
159
|
+
preconditions.push({ id: row.id, check: row.check, satisfied: row.satisfied });
|
|
160
|
+
}
|
|
161
|
+
let evidence;
|
|
162
|
+
if (input.evidence !== undefined) {
|
|
163
|
+
if (!isPlainObject(input.evidence)
|
|
164
|
+
|| typeof input.evidence.artifact !== "string" || input.evidence.artifact.length === 0
|
|
165
|
+
|| typeof input.evidence.digest !== "string" || !DIGEST_RE.test(input.evidence.digest)) {
|
|
166
|
+
return { ok: false, refusal: "precondition-uncheckable" };
|
|
167
|
+
}
|
|
168
|
+
evidence = { artifact: input.evidence.artifact, digest: input.evidence.digest };
|
|
169
|
+
}
|
|
170
|
+
let rendering;
|
|
171
|
+
try {
|
|
172
|
+
rendering = deriveContinuationRendering(argv, input.platform ?? "posix");
|
|
173
|
+
}
|
|
174
|
+
catch {
|
|
175
|
+
return { ok: false, refusal: "rendering-failed" };
|
|
176
|
+
}
|
|
177
|
+
const continuation = { argv, rendering, preconditions, convergence };
|
|
178
|
+
if (evidence !== undefined)
|
|
179
|
+
continuation.evidence = evidence;
|
|
180
|
+
return { ok: true, continuation };
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Validate a `next.continuation` value. Returns typed error strings (empty when
|
|
184
|
+
* valid); the envelope validator folds these into its own error list so an
|
|
185
|
+
* invalid shape fails closed instead of validating silently.
|
|
186
|
+
*/
|
|
187
|
+
export function validateContinuation(value) {
|
|
188
|
+
if (!isPlainObject(value))
|
|
189
|
+
return ["next.continuation must be an object"];
|
|
190
|
+
const errors = [];
|
|
191
|
+
const allowed = new Set(["argv", "rendering", "preconditions", "evidence", "convergence"]);
|
|
192
|
+
for (const key of Object.keys(value)) {
|
|
193
|
+
if (!allowed.has(key))
|
|
194
|
+
errors.push(`next.continuation has an unexpected key: ${key}`);
|
|
195
|
+
}
|
|
196
|
+
if (!Array.isArray(value.argv)
|
|
197
|
+
|| value.argv.length === 0
|
|
198
|
+
|| !value.argv.every((token) => typeof token === "string" && token.length > 0)) {
|
|
199
|
+
errors.push("next.continuation.argv must be a non-empty array of non-empty strings");
|
|
200
|
+
}
|
|
201
|
+
if (typeof value.convergence !== "string" || value.convergence.trim().length === 0) {
|
|
202
|
+
errors.push("next.continuation.convergence must be a non-empty string");
|
|
203
|
+
}
|
|
204
|
+
if (!Array.isArray(value.preconditions)) {
|
|
205
|
+
errors.push("next.continuation.preconditions must be an array");
|
|
206
|
+
}
|
|
207
|
+
else {
|
|
208
|
+
value.preconditions.forEach((row, i) => {
|
|
209
|
+
if (!isPlainObject(row)) {
|
|
210
|
+
errors.push(`next.continuation.preconditions[${i}] must be an object`);
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
if (typeof row.id !== "string" || row.id.length === 0) {
|
|
214
|
+
errors.push(`next.continuation.preconditions[${i}].id must be a non-empty string`);
|
|
215
|
+
}
|
|
216
|
+
if (typeof row.check !== "string" || row.check.length === 0) {
|
|
217
|
+
errors.push(`next.continuation.preconditions[${i}].check must be a non-empty string`);
|
|
218
|
+
}
|
|
219
|
+
if (typeof row.satisfied !== "boolean") {
|
|
220
|
+
errors.push(`next.continuation.preconditions[${i}].satisfied must be a boolean`);
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
if (value.rendering !== undefined && (typeof value.rendering !== "string" || value.rendering.length === 0)) {
|
|
225
|
+
errors.push("next.continuation.rendering must be a non-empty string when present");
|
|
226
|
+
}
|
|
227
|
+
if (value.evidence !== undefined) {
|
|
228
|
+
if (!isPlainObject(value.evidence)) {
|
|
229
|
+
errors.push("next.continuation.evidence must be an object when present");
|
|
230
|
+
}
|
|
231
|
+
else {
|
|
232
|
+
if (typeof value.evidence.artifact !== "string" || value.evidence.artifact.length === 0) {
|
|
233
|
+
errors.push("next.continuation.evidence.artifact must be a non-empty string");
|
|
234
|
+
}
|
|
235
|
+
if (typeof value.evidence.digest !== "string" || !DIGEST_RE.test(value.evidence.digest)) {
|
|
236
|
+
errors.push("next.continuation.evidence.digest must be a lowercase 64-hex SHA-256 string");
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
return errors;
|
|
241
|
+
}
|
|
242
|
+
/** Canonical serialization of a continuation value (sorted keys, compact). */
|
|
243
|
+
export function canonicalizeContinuation(value) {
|
|
244
|
+
return canonicalJSONValue(value);
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Receiver-side evidence check (AC4). Re-derives the SHA-256 of `artifactText`
|
|
248
|
+
* and compares it with the token's digest. Nothing is persisted; a mismatch is a
|
|
249
|
+
* plain `false`, never a repair.
|
|
250
|
+
*/
|
|
251
|
+
export function verifyContinuationEvidence(continuation, artifactText) {
|
|
252
|
+
if (!continuation || !isPlainObject(continuation.evidence))
|
|
253
|
+
return false;
|
|
254
|
+
const { digest } = continuation.evidence;
|
|
255
|
+
if (typeof digest !== "string" || !DIGEST_RE.test(digest))
|
|
256
|
+
return false;
|
|
257
|
+
if (typeof artifactText !== "string")
|
|
258
|
+
return false;
|
|
259
|
+
return sha256HexSync(artifactText) === digest;
|
|
260
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
* take the LAST fenced ```json block of the assistant's final message;
|
|
9
9
|
* exactly one envelope per turn; all top-level keys always present.
|
|
10
10
|
*/
|
|
11
|
+
import { type EnvelopeContinuation } from "./continuation.js";
|
|
11
12
|
import { VERIFICATION_COMMAND_STATUSES, VERIFICATION_COST_CLASSES, VERIFICATION_DIAGNOSTIC_CODES, VERIFICATION_LIMITS, VERIFICATION_PLAN_CONTRACT_ID, VERIFICATION_RECEIPT_CONTRACT_ID, VERIFICATION_STAGES, VERIFICATION_VERDICTS, WORKING_DIRECTORY_POLICIES, type VerificationDiagnosticCodeV1, type VerificationDiagnosticV1 } from "./verification-contract.js";
|
|
12
13
|
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
14
|
export type EnvelopeState = (typeof ENVELOPE_STATES)[number];
|
|
@@ -91,6 +92,12 @@ export interface EnvelopeNext {
|
|
|
91
92
|
tier: Tier;
|
|
92
93
|
/** Optional trigger-attributed suggestions (workflow-status only). */
|
|
93
94
|
suggested?: EnvelopeSuggestion[];
|
|
95
|
+
/**
|
|
96
|
+
* Optional executable hand-off (feature 59). Present when the deterministic
|
|
97
|
+
* side could emit one; absent on every refusal path — omission IS the absence
|
|
98
|
+
* semantics, never `null` (D-59-8). Shape owned by `continuation.ts`.
|
|
99
|
+
*/
|
|
100
|
+
continuation?: EnvelopeContinuation;
|
|
94
101
|
}
|
|
95
102
|
export interface Envelope {
|
|
96
103
|
skill: string;
|
|
@@ -890,3 +897,14 @@ export declare const VERIFICATION_CANONICAL_VECTORS: ReadonlyArray<Readonly<Cano
|
|
|
890
897
|
export { buildPreExecutionArtifactSnapshot, canonicalizePreExecutionArtifactSnapshot, canonicalizePreExecutionReviewReceipt, comparePreExecutionReceiptToSnapshot, digestPreExecutionArtifactSnapshot, digestPreExecutionReviewReceipt, selectSpecProduct, validatePreExecutionArtifactSnapshotV1, validatePreExecutionReceiptAgainstSnapshot, validatePreExecutionReviewReceiptV1, PRE_EXECUTION_ARTIFACT_KINDS, PRE_EXECUTION_AUTHOR_EXCLUSIONS, PRE_EXECUTION_CANONICAL_VECTORS, PRE_EXECUTION_CONTEXT_KINDS, PRE_EXECUTION_CONTEXT_PRESENCE, PRE_EXECUTION_DIAGNOSTIC_CODES, PRE_EXECUTION_FINDING_CLASSES, PRE_EXECUTION_FINDING_RESOLUTIONS, PRE_EXECUTION_FINDING_SEVERITIES, PRE_EXECUTION_FINDING_VERIFICATION, PRE_EXECUTION_FRESHNESS_CODES, PRE_EXECUTION_LIMITS, PRE_EXECUTION_MODEL_DIVERSITY, PRE_EXECUTION_PARENT_ROLES, PRE_EXECUTION_POLICY_VERSION, PRE_EXECUTION_RECEIPT_CONTRACT_ID, PRE_EXECUTION_RECEIPT_TIMELINE_SKEW_MS, PRE_EXECUTION_REVIEW_ROLES, PRE_EXECUTION_RUNTIME_RULES, PRE_EXECUTION_SELECTORS, PRE_EXECUTION_SNAPSHOT_CONTRACT_ID, PRE_EXECUTION_SNAPSHOT_SELECTOR, PRE_EXECUTION_STAGES, PRE_EXECUTION_UNIT_KINDS, PRE_EXECUTION_VERDICTS, SPEC_PRODUCT_REQUIRED_HEADINGS, isImpossibleReceiptTimeline, } from "./pre-execution.js";
|
|
891
898
|
export { VERDICTS_BY_STAGE } from "./pre-execution-contract.js";
|
|
892
899
|
export type { PreExecutionArtifactInput, PreExecutionArtifactKind, PreExecutionArtifactRow, PreExecutionArtifactSnapshotV1, PreExecutionAuthorExclusion, PreExecutionCanonicalVector, PreExecutionContextBinding, PreExecutionContextInput, PreExecutionContextKind, PreExecutionContextPresence, PreExecutionDiagnostic, PreExecutionDiagnosticCode, PreExecutionFinding, PreExecutionFindingClass, PreExecutionFindingResolution, PreExecutionFindingSeverity, PreExecutionFindingVerification, PreExecutionFreshnessCode, PreExecutionFreshnessResult, PreExecutionModelDiversity, PreExecutionParentReceipt, PreExecutionParentRole, PreExecutionReceiptValidationResult, PreExecutionReviewReceiptV1, PreExecutionReviewerRole, PreExecutionSelector, PreExecutionSnapshotBuildInput, PreExecutionSnapshotValidationResult, PreExecutionStage, PreExecutionUnitKind, PreExecutionVerdict, SpecProductSelection, SpecProductSelectorError, } from "./pre-execution.js";
|
|
900
|
+
/**
|
|
901
|
+
* Re-exported so a consumer imports ONE package root for every contract family.
|
|
902
|
+
* The implementation lives in `continuation.ts`; the frozen shape stays a single
|
|
903
|
+
* definition that `EnvelopeNext.continuation` references.
|
|
904
|
+
*/
|
|
905
|
+
export { CONTINUATION_CONTRACT_ID, CONTINUATION_PLATFORM_FAMILIES, CONTINUATION_REFUSALS, canonicalizeContinuation, deriveContinuationRendering, emitContinuation, parseContinuationArgv, validateContinuation, verifyContinuationEvidence, } from "./continuation.js";
|
|
906
|
+
export { CONTINUATION_CANONICAL_VECTORS, CONTINUATION_VECTOR_CONTRACT } from "./continuation-vectors.js";
|
|
907
|
+
/** The digest surface the evidence token is bound through (feature 59, D-59-9). */
|
|
908
|
+
export { sha256Hex, sha256HexSync } from "./sha256.js";
|
|
909
|
+
export type { ContinuationEvidence, ContinuationPlatformFamily, ContinuationPrecondition, ContinuationRefusalCode, EmitContinuationInput, EmitContinuationResult, EnvelopeContinuation, } from "./continuation.js";
|
|
910
|
+
export type { ContinuationCanonicalVector } from "./continuation-vectors.js";
|
package/dist/index.js
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
*/
|
|
11
11
|
import { canonicalizeContractInput, canonicalJSONValue, utf8Bytes, utf8ByteCompare, } from "./canonical-json.js";
|
|
12
12
|
import { sha256Hex } from "./sha256.js";
|
|
13
|
+
import { validateContinuation } from "./continuation.js";
|
|
13
14
|
import { VERIFICATION_COMMAND_STATUSES, VERIFICATION_CONTRACT, VERIFICATION_COST_CLASSES, VERIFICATION_DIAGNOSTIC_CODES, VERIFICATION_LIMITS, VERIFICATION_PLAN_CONTRACT_ID, VERIFICATION_RECEIPT_CONTRACT_ID, VERIFICATION_STAGES, VERIFICATION_VERDICTS, createVerificationDiagnosticSink, captureVerificationInput, validateStructure, } from "./verification-contract.js";
|
|
14
15
|
// ---------------------------------------------------------------------------
|
|
15
16
|
// Types (source of truth: this package; the internal skill carries policy only)
|
|
@@ -293,6 +294,9 @@ export function validateEnvelope(value) {
|
|
|
293
294
|
});
|
|
294
295
|
}
|
|
295
296
|
}
|
|
297
|
+
if (value.next.continuation !== undefined) {
|
|
298
|
+
errors.push(...validateContinuation(value.next.continuation));
|
|
299
|
+
}
|
|
296
300
|
}
|
|
297
301
|
if (value.needs_input !== null && value.needs_input !== undefined) {
|
|
298
302
|
if (!isObj(value.needs_input) ||
|
|
@@ -390,12 +394,24 @@ function rejectUnexpectedEnvelopeKeys(value, errors) {
|
|
|
390
394
|
if (value.needs_input !== null) {
|
|
391
395
|
rejectUnexpectedKeys(value.needs_input, "needs_input", ["question", "options"], errors);
|
|
392
396
|
}
|
|
393
|
-
rejectUnexpectedKeys(value.next, "next", ["recommended", "alternatives", "tier", "suggested"], errors);
|
|
397
|
+
rejectUnexpectedKeys(value.next, "next", ["recommended", "alternatives", "tier", "suggested", "continuation"], errors);
|
|
394
398
|
if (isObj(value.next) && Array.isArray(value.next.suggested)) {
|
|
395
399
|
value.next.suggested.forEach((suggestion, index) => {
|
|
396
400
|
rejectUnexpectedKeys(suggestion, `next.suggested[${index}]`, ["command", "trigger", "source_skill"], errors);
|
|
397
401
|
});
|
|
398
402
|
}
|
|
403
|
+
if (isObj(value.next)) {
|
|
404
|
+
const continuation = value.next.continuation;
|
|
405
|
+
if (isObj(continuation)) {
|
|
406
|
+
rejectUnexpectedKeys(continuation, "next.continuation", ["argv", "rendering", "preconditions", "evidence", "convergence"], errors);
|
|
407
|
+
if (Array.isArray(continuation.preconditions)) {
|
|
408
|
+
continuation.preconditions.forEach((row, index) => {
|
|
409
|
+
rejectUnexpectedKeys(row, `next.continuation.preconditions[${index}]`, ["id", "check", "satisfied"], errors);
|
|
410
|
+
});
|
|
411
|
+
}
|
|
412
|
+
rejectUnexpectedKeys(continuation.evidence, "next.continuation.evidence", ["artifact", "digest"], errors);
|
|
413
|
+
}
|
|
414
|
+
}
|
|
399
415
|
}
|
|
400
416
|
/**
|
|
401
417
|
* Validates the documented v2 shape at a driver boundary.
|
|
@@ -2869,3 +2885,15 @@ export const VERIFICATION_CANONICAL_VECTORS = Object.freeze([
|
|
|
2869
2885
|
*/
|
|
2870
2886
|
export { buildPreExecutionArtifactSnapshot, canonicalizePreExecutionArtifactSnapshot, canonicalizePreExecutionReviewReceipt, comparePreExecutionReceiptToSnapshot, digestPreExecutionArtifactSnapshot, digestPreExecutionReviewReceipt, selectSpecProduct, validatePreExecutionArtifactSnapshotV1, validatePreExecutionReceiptAgainstSnapshot, validatePreExecutionReviewReceiptV1, PRE_EXECUTION_ARTIFACT_KINDS, PRE_EXECUTION_AUTHOR_EXCLUSIONS, PRE_EXECUTION_CANONICAL_VECTORS, PRE_EXECUTION_CONTEXT_KINDS, PRE_EXECUTION_CONTEXT_PRESENCE, PRE_EXECUTION_DIAGNOSTIC_CODES, PRE_EXECUTION_FINDING_CLASSES, PRE_EXECUTION_FINDING_RESOLUTIONS, PRE_EXECUTION_FINDING_SEVERITIES, PRE_EXECUTION_FINDING_VERIFICATION, PRE_EXECUTION_FRESHNESS_CODES, PRE_EXECUTION_LIMITS, PRE_EXECUTION_MODEL_DIVERSITY, PRE_EXECUTION_PARENT_ROLES, PRE_EXECUTION_POLICY_VERSION, PRE_EXECUTION_RECEIPT_CONTRACT_ID, PRE_EXECUTION_RECEIPT_TIMELINE_SKEW_MS, PRE_EXECUTION_REVIEW_ROLES, PRE_EXECUTION_RUNTIME_RULES, PRE_EXECUTION_SELECTORS, PRE_EXECUTION_SNAPSHOT_CONTRACT_ID, PRE_EXECUTION_SNAPSHOT_SELECTOR, PRE_EXECUTION_STAGES, PRE_EXECUTION_UNIT_KINDS, PRE_EXECUTION_VERDICTS, SPEC_PRODUCT_REQUIRED_HEADINGS, isImpossibleReceiptTimeline, } from "./pre-execution.js";
|
|
2871
2887
|
export { VERDICTS_BY_STAGE } from "./pre-execution-contract.js";
|
|
2888
|
+
// ---------------------------------------------------------------------------
|
|
2889
|
+
// next.continuation — the executable hand-off object (feature 59)
|
|
2890
|
+
// ---------------------------------------------------------------------------
|
|
2891
|
+
/**
|
|
2892
|
+
* Re-exported so a consumer imports ONE package root for every contract family.
|
|
2893
|
+
* The implementation lives in `continuation.ts`; the frozen shape stays a single
|
|
2894
|
+
* definition that `EnvelopeNext.continuation` references.
|
|
2895
|
+
*/
|
|
2896
|
+
export { CONTINUATION_CONTRACT_ID, CONTINUATION_PLATFORM_FAMILIES, CONTINUATION_REFUSALS, canonicalizeContinuation, deriveContinuationRendering, emitContinuation, parseContinuationArgv, validateContinuation, verifyContinuationEvidence, } from "./continuation.js";
|
|
2897
|
+
export { CONTINUATION_CANONICAL_VECTORS, CONTINUATION_VECTOR_CONTRACT } from "./continuation-vectors.js";
|
|
2898
|
+
/** The digest surface the evidence token is bound through (feature 59, D-59-9). */
|
|
2899
|
+
export { sha256Hex, sha256HexSync } from "./sha256.js";
|
package/envelope.schema.json
CHANGED
|
@@ -178,6 +178,42 @@
|
|
|
178
178
|
"source_skill": { "type": "string" }
|
|
179
179
|
}
|
|
180
180
|
}
|
|
181
|
+
},
|
|
182
|
+
"continuation": {
|
|
183
|
+
"type": "object",
|
|
184
|
+
"additionalProperties": false,
|
|
185
|
+
"required": ["argv", "preconditions", "convergence"],
|
|
186
|
+
"properties": {
|
|
187
|
+
"argv": {
|
|
188
|
+
"type": "array",
|
|
189
|
+
"minItems": 1,
|
|
190
|
+
"items": { "type": "string", "minLength": 1 }
|
|
191
|
+
},
|
|
192
|
+
"rendering": { "type": "string", "minLength": 1 },
|
|
193
|
+
"preconditions": {
|
|
194
|
+
"type": "array",
|
|
195
|
+
"items": {
|
|
196
|
+
"type": "object",
|
|
197
|
+
"additionalProperties": false,
|
|
198
|
+
"required": ["id", "check", "satisfied"],
|
|
199
|
+
"properties": {
|
|
200
|
+
"id": { "type": "string", "minLength": 1 },
|
|
201
|
+
"check": { "type": "string", "minLength": 1 },
|
|
202
|
+
"satisfied": { "type": "boolean" }
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
},
|
|
206
|
+
"evidence": {
|
|
207
|
+
"type": "object",
|
|
208
|
+
"additionalProperties": false,
|
|
209
|
+
"required": ["artifact", "digest"],
|
|
210
|
+
"properties": {
|
|
211
|
+
"artifact": { "type": "string", "minLength": 1 },
|
|
212
|
+
"digest": { "type": "string", "pattern": "^[0-9a-f]{64}$" }
|
|
213
|
+
}
|
|
214
|
+
},
|
|
215
|
+
"convergence": { "type": "string", "minLength": 1 }
|
|
216
|
+
}
|
|
181
217
|
}
|
|
182
218
|
}
|
|
183
219
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gtrabanco/agentic-workflow-schema",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.2.0",
|
|
4
4
|
"description": "Versioned machine contracts, JSON Schemas, parsers, and deterministic document snapshots for agentic-workflow orchestration.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"agentic-workflow",
|
|
@@ -48,7 +48,6 @@
|
|
|
48
48
|
"pre-execution-artifact-snapshot.schema.json",
|
|
49
49
|
"pre-execution-review-receipt.schema.json",
|
|
50
50
|
"README.md",
|
|
51
|
-
"README.es.md",
|
|
52
51
|
"LICENSE"
|
|
53
52
|
],
|
|
54
53
|
"engines": {
|