@humain/humain-code-contracts 0.4.14 → 0.4.15
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/CHANGELOG.md +6 -0
- package/dist/flow-admission.d.ts +9 -0
- package/dist/flow-admission.d.ts.map +1 -1
- package/dist/flow-admission.js +2 -0
- package/dist/flow-admission.js.map +1 -1
- package/dist/flow-common.d.ts +3 -3
- package/dist/flow-common.d.ts.map +1 -1
- package/dist/flow-common.js +2 -0
- package/dist/flow-common.js.map +1 -1
- package/dist/flow-control.d.ts +13 -6
- package/dist/flow-control.d.ts.map +1 -1
- package/dist/flow-control.js +12 -3
- package/dist/flow-control.js.map +1 -1
- package/dist/flow-events.d.ts +167 -6
- package/dist/flow-events.d.ts.map +1 -1
- package/dist/flow-events.js +90 -1
- package/dist/flow-events.js.map +1 -1
- package/dist/flow-profile.d.ts +12 -0
- package/dist/flow-profile.d.ts.map +1 -1
- package/dist/flow-profile.js +10 -0
- package/dist/flow-profile.js.map +1 -1
- package/dist/rpc.d.ts +1 -1
- package/dist/rpc.d.ts.map +1 -1
- package/dist/rpc.js +21 -2
- package/dist/rpc.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.4.15] - 2026-10-15
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- verify-after Flow contracts: event kinds `implementation_ready`, `verification_started`, `repair_proposed`, `repair_started`, `repair_finished`, `repair_skipped` and `verification_settled`; optional `verdict.round` and `verdict.attribution`; the `flow_repair` control command and receipt; `flow_cancel.reason` `superseded`; `FlowStatusV1.stage` `verifying_after`; optional `FlowRunAdmissionV1.verification`, `FlowProfileV1.verification.mode` and `FlowProfileV1.limits.verifyBudgetMs`. All additive and content-free. HUMAIN Code emits them only for runs that request `verification: "after"`; strict readers must upgrade before a host requests verify-after.
|
|
8
|
+
|
|
3
9
|
## [0.4.14] - 2026-10-15
|
|
4
10
|
|
|
5
11
|
### Changed
|
package/dist/flow-admission.d.ts
CHANGED
|
@@ -146,6 +146,7 @@ export declare const FlowRunAdmissionV1Schema: Type.TObject<{
|
|
|
146
146
|
readonly largeAt: Type.TNumber;
|
|
147
147
|
}>;
|
|
148
148
|
readonly triageRole: Type.TLiteral<"triage">;
|
|
149
|
+
readonly triage: Type.TOptional<Type.TBoolean>;
|
|
149
150
|
readonly maxEscalations: Type.TUnion<[Type.TLiteral<0>, Type.TLiteral<1>]>;
|
|
150
151
|
}>>;
|
|
151
152
|
readonly limits: Type.TObject<{
|
|
@@ -155,7 +156,13 @@ export declare const FlowRunAdmissionV1Schema: Type.TObject<{
|
|
|
155
156
|
readonly maxRetries: Type.TInteger;
|
|
156
157
|
readonly inactivityMs: Type.TInteger;
|
|
157
158
|
readonly ciWaitMs: Type.TInteger;
|
|
159
|
+
readonly runDeadlineMs: Type.TOptional<Type.TInteger>;
|
|
160
|
+
readonly repairRounds: Type.TOptional<Type.TInteger>;
|
|
161
|
+
readonly verifyBudgetMs: Type.TOptional<Type.TInteger>;
|
|
158
162
|
}>;
|
|
163
|
+
readonly verification: Type.TOptional<Type.TObject<{
|
|
164
|
+
readonly mode: Type.TUnion<[Type.TLiteral<"inline">, Type.TLiteral<"after">]>;
|
|
165
|
+
}>>;
|
|
159
166
|
readonly spend: Type.TObject<{
|
|
160
167
|
readonly runCapMicrousd: Type.TInteger;
|
|
161
168
|
readonly warnAtPct: Type.TInteger;
|
|
@@ -217,6 +224,8 @@ export declare const FlowRunAdmissionV1Schema: Type.TObject<{
|
|
|
217
224
|
readonly path: Type.TString;
|
|
218
225
|
}>>;
|
|
219
226
|
readonly issuedAt: Type.TRefine<Type.TString>;
|
|
227
|
+
/** Host opt-in to verify-after (result first, verdict streamed after). Missing means `inline`. */
|
|
228
|
+
readonly verification: Type.TOptional<Type.TUnion<[Type.TLiteral<"inline">, Type.TLiteral<"after">]>>;
|
|
220
229
|
readonly admissionDigest: Type.TString;
|
|
221
230
|
}>;
|
|
222
231
|
export type FlowRunAdmissionV1 = Static<typeof FlowRunAdmissionV1Schema>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flow-admission.d.ts","sourceRoot":"","sources":["../src/flow-admission.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAIN,KAAK,gBAAgB,EAUrB,MAAM,kBAAkB,CAAC;AAG1B,eAAO,MAAM,wBAAwB
|
|
1
|
+
{"version":3,"file":"flow-admission.d.ts","sourceRoot":"","sources":["../src/flow-admission.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAIN,KAAK,gBAAgB,EAUrB,MAAM,kBAAkB,CAAC;AAG1B,eAAO,MAAM,wBAAwB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAsBpC,kGAAkG;;;EAGjG,CAAC;AACH,MAAM,MAAM,kBAAkB,GAAG,MAAM,CAAC,OAAO,wBAAwB,CAAC,CAAC;AAIzE,+GAA+G;AAC/G,wBAAgB,wBAAwB,CAAC,GAAG,EAAE,kBAAkB,GAAG,MAAM,CAExE;AAYD;;;GAGG;AACH,wBAAgB,4BAA4B,CAAC,KAAK,EAAE,OAAO,GAAG,kBAAkB,CAE/E;AAED,+HAA+H;AAC/H,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,gBAAgB,GAAG,kBAAkB,CASpG"}
|
package/dist/flow-admission.js
CHANGED
|
@@ -20,6 +20,8 @@ export const FlowRunAdmissionV1Schema = StrictObject({
|
|
|
20
20
|
path: Type.String({ minLength: 1, maxLength: 1024 }),
|
|
21
21
|
}), { maxItems: 64 }),
|
|
22
22
|
issuedAt: FlowTimestampSchema,
|
|
23
|
+
/** Host opt-in to verify-after (result first, verdict streamed after). Missing means `inline`. */
|
|
24
|
+
verification: Type.Optional(Type.Union([Type.Literal("inline"), Type.Literal("after")])),
|
|
23
25
|
admissionDigest: FlowDigestSchema,
|
|
24
26
|
});
|
|
25
27
|
const Validator = compileFlow(FlowRunAdmissionV1Schema);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flow-admission.js","sourceRoot":"","sources":["../src/flow-admission.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,IAAI,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EACN,gBAAgB,EAChB,WAAW,EACX,iBAAiB,EAEjB,gBAAgB,EAChB,YAAY,EACZ,kBAAkB,EAClB,kBAAkB,EAClB,cAAc,EACd,mBAAmB,EACnB,aAAa,EACb,YAAY,EACZ,gBAAgB,GAChB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAEzG,MAAM,CAAC,MAAM,wBAAwB,GAAG,YAAY,CAAC;IACpD,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,uBAAuB,CAAC;IAC7C,aAAa,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;IAC9B,KAAK,EAAE,YAAY;IACnB,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;IAC/D,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC;IAC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AC;IAAC,MAAM,CAAC;QACR,OAAO,KAAK,CAAC;IACd,CAAC;AACF,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,4BAA4B,CAAC,KAAc;IAC1D,OAAO,aAAa,CAAC,mBAAmB,EAAE,KAAK,EAAE,gBAAgB,CAAC,CAAC;AACpE,CAAC;AAED,+HAA+H;AAC/H,MAAM,UAAU,uBAAuB,CAAC,KAAc,EAAE,MAAwB;IAC/E,MAAM,SAAS,GAAG,4BAA4B,CAAC,KAAK,CAAC,CAAC;IACtD,IAAI,CAAC,gBAAgB,CAAC,MAAM,EAAE,sBAAsB,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QACpG,MAAM,IAAI,iBAAiB,CAAC,iBAAiB,CAAC,CAAC;IAChD,CAAC;IACD,IAAI,CAAC,gBAAgB,CAAC,MAAM,EAAE,wBAAwB,CAAC,SAAS,CAAC,EAAE,SAAS,CAAC,eAAe,CAAC,EAAE,CAAC;QAC/F,MAAM,IAAI,iBAAiB,CAAC,iBAAiB,CAAC,CAAC;IAChD,CAAC;IACD,OAAO,SAAS,CAAC;AAClB,CAAC","sourcesContent":["import { type Static, Type } from \"typebox\";\nimport {\n\tcanonicalWithout,\n\tcompileFlow,\n\tFlowContractError,\n\ttype FlowDigestHasher,\n\tFlowDigestSchema,\n\tFlowIdSchema,\n\tFlowMicrousdSchema,\n\tFlowModelRefSchema,\n\tFlowSizeSchema,\n\tFlowTimestampSchema,\n\tparseFlowData,\n\tStrictObject,\n\tverifyFlowDigest,\n} from \"./flow-common.ts\";\nimport { FlowProfileV1Schema, flowProfileDigestInput, parseFlowProfileV1Shape } from \"./flow-profile.ts\";\n\nexport const FlowRunAdmissionV1Schema = StrictObject({\n\tschema: Type.Literal(\"humain-flow-admission\"),\n\tschemaVersion: Type.Literal(1),\n\trunId: FlowIdSchema,\n\tsurface: Type.Union([Type.Literal(\"cli\"), Type.Literal(\"web\")]),\n\ttenantId: Type.Optional(FlowIdSchema),\n\tprojectId: Type.Optional(FlowIdSchema),\n\tmode: Type.Union([Type.Literal(\"auto\"), Type.Literal(\"direct\")]),\n\tprofile: FlowProfileV1Schema,\n\tsizeOverride: Type.Optional(FlowSizeSchema),\n\tdirectModel: Type.Optional(FlowModelRefSchema),\n\tspendCapMicrousd: FlowMicrousdSchema,\n\tinputs: Type.Array(\n\t\tStrictObject({\n\t\t\tkind: Type.Union([Type.Literal(\"plan\"), Type.Literal(\"sketch\")]),\n\t\t\tref: FlowIdSchema,\n\t\t\tsha256: FlowDigestSchema,\n\t\t\tpath: Type.String({ minLength: 1, maxLength: 1024 }),\n\t\t}),\n\t\t{ maxItems: 64 },\n\t),\n\tissuedAt: FlowTimestampSchema,\n\tadmissionDigest: FlowDigestSchema,\n});\nexport type FlowRunAdmissionV1 = Static<typeof FlowRunAdmissionV1Schema>;\n\nconst Validator = compileFlow(FlowRunAdmissionV1Schema);\n\n/** Canonical text hashed (sha256 hex) to produce `admissionDigest`: the document without `admissionDigest`. */\nexport function flowAdmissionDigestInput(doc: FlowRunAdmissionV1): string {\n\treturn canonicalWithout(doc, \"admissionDigest\");\n}\n\nfunction isAdmissionShape(value: unknown): value is FlowRunAdmissionV1 {\n\tif (!Validator.Check(value)) return false;\n\ttry {\n\t\tparseFlowProfileV1Shape(value.profile);\n\t\treturn true;\n\t} catch {\n\t\treturn false;\n\t}\n}\n\n/**\n * SHAPE ONLY: validates structure and the embedded profile's cross-field rules but does NOT verify\n * `admissionDigest` or the embedded profile digest. Prefer {@link parseFlowRunAdmissionV1}.\n */\nexport function parseFlowRunAdmissionV1Shape(input: unknown): FlowRunAdmissionV1 {\n\treturn parseFlowData(\"admission_invalid\", input, isAdmissionShape);\n}\n\n/** Shape validation plus verification of the embedded profile digest and `admissionDigest` (integrity, not authentication). */\nexport function parseFlowRunAdmissionV1(input: unknown, hasher: FlowDigestHasher): FlowRunAdmissionV1 {\n\tconst admission = parseFlowRunAdmissionV1Shape(input);\n\tif (!verifyFlowDigest(hasher, flowProfileDigestInput(admission.profile), admission.profile.digest)) {\n\t\tthrow new FlowContractError(\"digest_mismatch\");\n\t}\n\tif (!verifyFlowDigest(hasher, flowAdmissionDigestInput(admission), admission.admissionDigest)) {\n\t\tthrow new FlowContractError(\"digest_mismatch\");\n\t}\n\treturn admission;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"flow-admission.js","sourceRoot":"","sources":["../src/flow-admission.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,IAAI,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EACN,gBAAgB,EAChB,WAAW,EACX,iBAAiB,EAEjB,gBAAgB,EAChB,YAAY,EACZ,kBAAkB,EAClB,kBAAkB,EAClB,cAAc,EACd,mBAAmB,EACnB,aAAa,EACb,YAAY,EACZ,gBAAgB,GAChB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAEzG,MAAM,CAAC,MAAM,wBAAwB,GAAG,YAAY,CAAC;IACpD,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,uBAAuB,CAAC;IAC7C,aAAa,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;IAC9B,KAAK,EAAE,YAAY;IACnB,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;IAC/D,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC;IACrC,SAAS,EAAE,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC;IACtC,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;IAChE,OAAO,EAAE,m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OAAO,KAAK,CAAC;IACd,CAAC;AACF,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,4BAA4B,CAAC,KAAc;IAC1D,OAAO,aAAa,CAAC,mBAAmB,EAAE,KAAK,EAAE,gBAAgB,CAAC,CAAC;AACpE,CAAC;AAED,+HAA+H;AAC/H,MAAM,UAAU,uBAAuB,CAAC,KAAc,EAAE,MAAwB;IAC/E,MAAM,SAAS,GAAG,4BAA4B,CAAC,KAAK,CAAC,CAAC;IACtD,IAAI,CAAC,gBAAgB,CAAC,MAAM,EAAE,sBAAsB,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QACpG,MAAM,IAAI,iBAAiB,CAAC,iBAAiB,CAAC,CAAC;IAChD,CAAC;IACD,IAAI,CAAC,gBAAgB,CAAC,MAAM,EAAE,wBAAwB,CAAC,SAAS,CAAC,EAAE,SAAS,CAAC,eAAe,CAAC,EAAE,CAAC;QAC/F,MAAM,IAAI,iBAAiB,CAAC,iBAAiB,CAAC,CAAC;IAChD,CAAC;IACD,OAAO,SAAS,CAAC;AAClB,CAAC","sourcesContent":["import { type Static, Type } from \"typebox\";\nimport {\n\tcanonicalWithout,\n\tcompileFlow,\n\tFlowContractError,\n\ttype FlowDigestHasher,\n\tFlowDigestSchema,\n\tFlowIdSchema,\n\tFlowMicrousdSchema,\n\tFlowModelRefSchema,\n\tFlowSizeSchema,\n\tFlowTimestampSchema,\n\tparseFlowData,\n\tStrictObject,\n\tverifyFlowDigest,\n} from \"./flow-common.ts\";\nimport { FlowProfileV1Schema, flowProfileDigestInput, parseFlowProfileV1Shape } from \"./flow-profile.ts\";\n\nexport const FlowRunAdmissionV1Schema = StrictObject({\n\tschema: Type.Literal(\"humain-flow-admission\"),\n\tschemaVersion: Type.Literal(1),\n\trunId: FlowIdSchema,\n\tsurface: Type.Union([Type.Literal(\"cli\"), Type.Literal(\"web\")]),\n\ttenantId: Type.Optional(FlowIdSchema),\n\tprojectId: Type.Optional(FlowIdSchema),\n\tmode: Type.Union([Type.Literal(\"auto\"), Type.Literal(\"direct\")]),\n\tprofile: FlowProfileV1Schema,\n\tsizeOverride: Type.Optional(FlowSizeSchema),\n\tdirectModel: Type.Optional(FlowModelRefSchema),\n\tspendCapMicrousd: FlowMicrousdSchema,\n\tinputs: Type.Array(\n\t\tStrictObject({\n\t\t\tkind: Type.Union([Type.Literal(\"plan\"), Type.Literal(\"sketch\")]),\n\t\t\tref: FlowIdSchema,\n\t\t\tsha256: FlowDigestSchema,\n\t\t\tpath: Type.String({ minLength: 1, maxLength: 1024 }),\n\t\t}),\n\t\t{ maxItems: 64 },\n\t),\n\tissuedAt: FlowTimestampSchema,\n\t/** Host opt-in to verify-after (result first, verdict streamed after). Missing means `inline`. */\n\tverification: Type.Optional(Type.Union([Type.Literal(\"inline\"), Type.Literal(\"after\")])),\n\tadmissionDigest: FlowDigestSchema,\n});\nexport type FlowRunAdmissionV1 = Static<typeof FlowRunAdmissionV1Schema>;\n\nconst Validator = compileFlow(FlowRunAdmissionV1Schema);\n\n/** Canonical text hashed (sha256 hex) to produce `admissionDigest`: the document without `admissionDigest`. */\nexport function flowAdmissionDigestInput(doc: FlowRunAdmissionV1): string {\n\treturn canonicalWithout(doc, \"admissionDigest\");\n}\n\nfunction isAdmissionShape(value: unknown): value is FlowRunAdmissionV1 {\n\tif (!Validator.Check(value)) return false;\n\ttry {\n\t\tparseFlowProfileV1Shape(value.profile);\n\t\treturn true;\n\t} catch {\n\t\treturn false;\n\t}\n}\n\n/**\n * SHAPE ONLY: validates structure and the embedded profile's cross-field rules but does NOT verify\n * `admissionDigest` or the embedded profile digest. Prefer {@link parseFlowRunAdmissionV1}.\n */\nexport function parseFlowRunAdmissionV1Shape(input: unknown): FlowRunAdmissionV1 {\n\treturn parseFlowData(\"admission_invalid\", input, isAdmissionShape);\n}\n\n/** Shape validation plus verification of the embedded profile digest and `admissionDigest` (integrity, not authentication). */\nexport function parseFlowRunAdmissionV1(input: unknown, hasher: FlowDigestHasher): FlowRunAdmissionV1 {\n\tconst admission = parseFlowRunAdmissionV1Shape(input);\n\tif (!verifyFlowDigest(hasher, flowProfileDigestInput(admission.profile), admission.profile.digest)) {\n\t\tthrow new FlowContractError(\"digest_mismatch\");\n\t}\n\tif (!verifyFlowDigest(hasher, flowAdmissionDigestInput(admission), admission.admissionDigest)) {\n\t\tthrow new FlowContractError(\"digest_mismatch\");\n\t}\n\treturn admission;\n}\n"]}
|
package/dist/flow-common.d.ts
CHANGED
|
@@ -58,10 +58,10 @@ export declare const partialByRole: <T extends TSchema>(schema: T) => Type.TObje
|
|
|
58
58
|
export declare const FLOW_SIZES: readonly ["small", "medium", "large"];
|
|
59
59
|
export type FlowSize = (typeof FLOW_SIZES)[number];
|
|
60
60
|
export declare const FlowSizeSchema: TUnion<[TLiteral<"small">, TLiteral<"medium">, TLiteral<"large">]>;
|
|
61
|
-
export declare const FLOW_FAILURE_CLASSES: readonly ["provider_error", "provider_unreachable", "rate_limit", "timeout", "check_failed", "review_rejected", "qa_failed", "budget_stop", "cancelled", "crash", "unsafe_scope", "stalled", "config_invalid", "internal", "review_verdict_missing", "verification_unavailable", "blocked"];
|
|
61
|
+
export declare const FLOW_FAILURE_CLASSES: readonly ["provider_error", "provider_unreachable", "rate_limit", "timeout", "check_failed", "review_rejected", "qa_failed", "budget_stop", "cancelled", "crash", "unsafe_scope", "stalled", "config_invalid", "internal", "review_verdict_missing", "verification_unavailable", "blocked", "review_findings"];
|
|
62
62
|
export type FlowFailureClass = (typeof FLOW_FAILURE_CLASSES)[number];
|
|
63
|
-
export declare const FlowFailureClassSchema: TUnion<[TLiteral<"provider_error">, TLiteral<"provider_unreachable">, TLiteral<"rate_limit">, TLiteral<"timeout">, TLiteral<"check_failed">, TLiteral<"review_rejected">, TLiteral<"qa_failed">, TLiteral<"budget_stop">, TLiteral<"cancelled">, TLiteral<"crash">, TLiteral<"unsafe_scope">, TLiteral<"stalled">, TLiteral<"config_invalid">, TLiteral<"internal">, TLiteral<"review_verdict_missing">, TLiteral<"verification_unavailable">, TLiteral<"blocked">]>;
|
|
64
|
-
export declare const FlowReasonClassSchema: TUnion<[TUnion<[TLiteral<"provider_error">, TLiteral<"provider_unreachable">, TLiteral<"rate_limit">, TLiteral<"timeout">, TLiteral<"check_failed">, TLiteral<"review_rejected">, TLiteral<"qa_failed">, TLiteral<"budget_stop">, TLiteral<"cancelled">, TLiteral<"crash">, TLiteral<"unsafe_scope">, TLiteral<"stalled">, TLiteral<"config_invalid">, TLiteral<"internal">, TLiteral<"review_verdict_missing">, TLiteral<"verification_unavailable">, TLiteral<"blocked">]>, TLiteral<"size_underestimated">]>;
|
|
63
|
+
export declare const FlowFailureClassSchema: TUnion<[TLiteral<"provider_error">, TLiteral<"provider_unreachable">, TLiteral<"rate_limit">, TLiteral<"timeout">, TLiteral<"check_failed">, TLiteral<"review_rejected">, TLiteral<"qa_failed">, TLiteral<"budget_stop">, TLiteral<"cancelled">, TLiteral<"crash">, TLiteral<"unsafe_scope">, TLiteral<"stalled">, TLiteral<"config_invalid">, TLiteral<"internal">, TLiteral<"review_verdict_missing">, TLiteral<"verification_unavailable">, TLiteral<"blocked">, TLiteral<"review_findings">]>;
|
|
64
|
+
export declare const FlowReasonClassSchema: TUnion<[TUnion<[TLiteral<"provider_error">, TLiteral<"provider_unreachable">, TLiteral<"rate_limit">, TLiteral<"timeout">, TLiteral<"check_failed">, TLiteral<"review_rejected">, TLiteral<"qa_failed">, TLiteral<"budget_stop">, TLiteral<"cancelled">, TLiteral<"crash">, TLiteral<"unsafe_scope">, TLiteral<"stalled">, TLiteral<"config_invalid">, TLiteral<"internal">, TLiteral<"review_verdict_missing">, TLiteral<"verification_unavailable">, TLiteral<"blocked">, TLiteral<"review_findings">]>, TLiteral<"size_underestimated">]>;
|
|
65
65
|
export type FlowReasonClass = Static<typeof FlowReasonClassSchema>;
|
|
66
66
|
export declare const FlowProfileRefSchema: Type.TObject<{
|
|
67
67
|
read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,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAIlE"}
|
package/dist/flow-common.js
CHANGED
|
@@ -109,6 +109,7 @@ export const FLOW_FAILURE_CLASSES = [
|
|
|
109
109
|
"review_verdict_missing",
|
|
110
110
|
"verification_unavailable",
|
|
111
111
|
"blocked",
|
|
112
|
+
"review_findings",
|
|
112
113
|
];
|
|
113
114
|
export const FlowFailureClassSchema = Type.Union([
|
|
114
115
|
Type.Literal("provider_error"),
|
|
@@ -128,6 +129,7 @@ export const FlowFailureClassSchema = Type.Union([
|
|
|
128
129
|
Type.Literal("review_verdict_missing"),
|
|
129
130
|
Type.Literal("verification_unavailable"),
|
|
130
131
|
Type.Literal("blocked"),
|
|
132
|
+
Type.Literal("review_findings"),
|
|
131
133
|
]);
|
|
132
134
|
export const FlowReasonClassSchema = Type.Union([FlowFailureClassSchema, Type.Literal("size_underestimated")]);
|
|
133
135
|
export const FlowProfileRefSchema = StrictObject({
|
package/dist/flow-common.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flow-common.js","sourceRoot":"","sources":["../src/flow-common.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyD,IAAI,EAAE,MAAM,SAAS,CAAC;AACtF,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAE1C;;;GAGG;AAEH,MAAM,CAAC,MAAM,eAAe,GAAG,+BAA+B,CAAC;AAC/D,gHAAgH;AAChH,MAAM,CAAC,MAAM,qBAAqB,GAAG,iEAAiE,CAAC;AACvG,MAAM,CAAC,MAAM,mBAAmB,GAAG,gBAAgB,CAAC;AACpD,MAAM,eAAe,GACpB,+IAA+I,CAAC;AAEjJ,MAAM,CAAC,MAAM,yBAAyB,GAAG;IACxC,eAAe,EAAE,sBAAsB;IACvC,iBAAiB,EAAE,4BAA4B;IAC/C,aAAa,EAAE,oBAAoB;IACnC,eAAe,EAAE,8BAA8B;IAC/C,eAAe,EAAE,8BAA8B;IAC/C,cAAc,EAAE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,KAAgC,CAAC;IAChD,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC;QAC9C,IAAI,CAAC,GAAG,CAAC,YAAY,EAAE;YAAE,MAAM,IAAI,iBAAiB,CAAC,mBAAmB,CAAC,CAAC;QAC1E,IAAI,MAAM,CAAC,GAAG,CAAC,KAAK,SAAS;YAAE,SAAS;QACxC,KAAK,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,iBAAiB,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC;IACxE,CAAC;IACD,OAAO,IAAI,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;AAC/B,CAAC;AAED,2DAA2D;AAC3D,MAAM,UAAU,gBAAgB,CAAC,GAAW,EAAE,IAAY;IACzD,MAAM,IAAI,GAA4B,EAAE,GAAG,GAAG,EAAE,CAAC;IACjD,OAAO,IAAI,CAAC,IAAI,CAAC,CAAC;IAClB,OAAO,iBAAiB,CAAC,IAAI,CAAC,CAAC;AAChC,CAAC","sourcesContent":["import { type Static, type TLiteral, type TSchema, type TUnion, Type } from \"typebox\";\nimport { Compile } from \"typebox/compile\";\n\n/**\n * Shared primitives for the `./flow-*` contract subpaths. TypeBox-only and browser-safe: no node:* imports,\n * no hashing (callers inject `sha256Hex`), no free-text string types.\n */\n\nexport const FLOW_ID_PATTERN = \"^[a-z0-9][a-z0-9_.:-]{0,127}$\";\n/** Model ids may be provider-qualified: lowercase, at most one `/`, no empty segment, <= 128 chars in total. */\nexport const FLOW_MODEL_ID_PATTERN = \"^(?=.{1,128}$)[a-z0-9][a-z0-9_.:-]*(?:/[a-z0-9][a-z0-9_.:-]*)?$\";\nexport const FLOW_DIGEST_PATTERN = \"^[a-f0-9]{64}$\";\nconst FLOW_TS_PATTERN =\n\t\"^\\\\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\\\\d|3[01])T(?:[01]\\\\d|2[0-3]):[0-5]\\\\d:[0-5]\\\\d(?:\\\\.\\\\d{1,9})?(?:Z|[+-](?:[01]\\\\d|2[0-3]):[0-5]\\\\d)$\";\n\nexport const FLOW_CONTRACT_ERROR_CODES = {\n\tprofile_invalid: \"Invalid flow profile\",\n\tadmission_invalid: \"Invalid flow run admission\",\n\tevent_invalid: \"Invalid flow event\",\n\tcommand_invalid: \"Invalid flow control command\",\n\treceipt_invalid: \"Invalid flow control receipt\",\n\tstatus_invalid: \"Invalid flow status\",\n\tdigest_mismatch: \"Flow digest mismatch\",\n\tdigest_unverifiable: \"Flow digest cannot be verified\",\n\tcanonical_invalid: \"Flow data cannot be canonicalized\",\n\treceipt_conflict: \"Flow receipt conflicts with the first receipt\",\n} as const;\nexport type FlowContractErrorCode = keyof typeof FLOW_CONTRACT_ERROR_CODES;\n\n/** Messages are constants chosen by contract code from `code`; rejected input is never echoed. */\nexport class FlowContractError extends Error {\n\treadonly code: FlowContractErrorCode;\n\tconstructor(code: FlowContractErrorCode) {\n\t\tsuper(FLOW_CONTRACT_ERROR_CODES[code]);\n\t\tthis.name = \"FlowContractError\";\n\t\tthis.code = code;\n\t}\n}\n\n/** Union of string literals with a precise Static type (a mapped array would infer `never`). */\nexport const lit = <const T extends readonly string[]>(...values: T) =>\n\tType.Union(values.map((value) => Type.Literal(value))) as unknown as TUnion<{\n\t\t-readonly [K in keyof T]: TLiteral<T[K]>;\n\t}>;\n\nexport const StrictObject = <const T extends Parameters<typeof Type.Object>[0]>(properties: T) =>\n\tType.Object(properties, { additionalProperties: false });\n\nexport const FlowIdSchema = Type.String({ pattern: FLOW_ID_PATTERN });\nexport const FlowDigestSchema = Type.String({ pattern: FLOW_DIGEST_PATTERN });\nconst DAYS_IN_MONTH = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] as const;\n\n/** Pattern-valid timestamps only: rejects impossible calendar dates such as 2026-02-31 or a non-leap Feb 29. */\nfunction isRealCalendarDate(timestamp: string): boolean {\n\tconst year = Number(timestamp.slice(0, 4));\n\tconst month = Number(timestamp.slice(5, 7));\n\tconst day = Number(timestamp.slice(8, 10));\n\tconst leap = (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;\n\treturn day <= (month === 2 && leap ? 29 : (DAYS_IN_MONTH[month - 1] ?? 0));\n}\n\nexport const FlowTimestampSchema = Type.Refine(Type.String({ pattern: FLOW_TS_PATTERN }), isRealCalendarDate);\nexport const FlowMicrousdSchema = Type.Integer({ minimum: 0, maximum: Number.MAX_SAFE_INTEGER });\nexport const FlowCountSchema = Type.Integer({ minimum: 0, maximum: Number.MAX_SAFE_INTEGER });\nexport const FlowPositiveIntSchema = Type.Integer({ minimum: 1, maximum: Number.MAX_SAFE_INTEGER });\n\nexport const FlowModelRefSchema = StrictObject({\n\tprovider: FlowIdSchema,\n\tmodel: Type.String({ pattern: FLOW_MODEL_ID_PATTERN }),\n});\nexport type FlowModelRef = Static<typeof FlowModelRefSchema>;\n\nexport const FLOW_ROLES = [\n\t\"scout\",\n\t\"worker\",\n\t\"implementer\",\n\t\"lead\",\n\t\"lead_large\",\n\t\"architect\",\n\t\"reviewer\",\n\t\"security_reviewer\",\n\t\"qa\",\n\t\"triage\",\n] as const;\nexport type FlowRole = (typeof FLOW_ROLES)[number];\nexport const FlowRoleSchema = Type.Union([\n\tType.Literal(\"scout\"),\n\tType.Literal(\"worker\"),\n\tType.Literal(\"implementer\"),\n\tType.Literal(\"lead\"),\n\tType.Literal(\"lead_large\"),\n\tType.Literal(\"architect\"),\n\tType.Literal(\"reviewer\"),\n\tType.Literal(\"security_reviewer\"),\n\tType.Literal(\"qa\"),\n\tType.Literal(\"triage\"),\n]);\n\n/** `Partial<Record<FlowRole, T>>` as a strict object. */\nexport const partialByRole = <T extends TSchema>(schema: T) =>\n\tStrictObject({\n\t\tscout: Type.Optional(schema),\n\t\tworker: Type.Optional(schema),\n\t\timplementer: Type.Optional(schema),\n\t\tlead: Type.Optional(schema),\n\t\tlead_large: Type.Optional(schema),\n\t\tarchitect: Type.Optional(schema),\n\t\treviewer: Type.Optional(schema),\n\t\tsecurity_reviewer: Type.Optional(schema),\n\t\tqa: Type.Optional(schema),\n\t\ttriage: Type.Optional(schema),\n\t});\n\nexport const FLOW_SIZES = [\"small\", \"medium\", \"large\"] as const;\nexport type FlowSize = (typeof FLOW_SIZES)[number];\nexport const FlowSizeSchema = Type.Union([Type.Literal(\"small\"), Type.Literal(\"medium\"), Type.Literal(\"large\")]);\n\nexport const FLOW_FAILURE_CLASSES = [\n\t\"provider_error\",\n\t\"provider_unreachable\",\n\t\"rate_limit\",\n\t\"timeout\",\n\t\"check_failed\",\n\t\"review_rejected\",\n\t\"qa_failed\",\n\t\"budget_stop\",\n\t\"cancelled\",\n\t\"crash\",\n\t\"unsafe_scope\",\n\t\"stalled\",\n\t\"config_invalid\",\n\t\"internal\",\n\t\"review_verdict_missing\",\n\t\"verification_unavailable\",\n\t\"blocked\",\n] as const;\nexport type FlowFailureClass = (typeof FLOW_FAILURE_CLASSES)[number];\nexport const FlowFailureClassSchema = Type.Union([\n\tType.Literal(\"provider_error\"),\n\tType.Literal(\"provider_unreachable\"),\n\tType.Literal(\"rate_limit\"),\n\tType.Literal(\"timeout\"),\n\tType.Literal(\"check_failed\"),\n\tType.Literal(\"review_rejected\"),\n\tType.Literal(\"qa_failed\"),\n\tType.Literal(\"budget_stop\"),\n\tType.Literal(\"cancelled\"),\n\tType.Literal(\"crash\"),\n\tType.Literal(\"unsafe_scope\"),\n\tType.Literal(\"stalled\"),\n\tType.Literal(\"config_invalid\"),\n\tType.Literal(\"internal\"),\n\tType.Literal(\"review_verdict_missing\"),\n\tType.Literal(\"verification_unavailable\"),\n\tType.Literal(\"blocked\"),\n]);\n\nexport const FlowReasonClassSchema = Type.Union([FlowFailureClassSchema, Type.Literal(\"size_underestimated\")]);\nexport type FlowReasonClass = Static<typeof FlowReasonClassSchema>;\n\nexport const FlowProfileRefSchema = StrictObject({\n\tid: FlowIdSchema,\n\tversion: FlowPositiveIntSchema,\n\tdigest: FlowDigestSchema,\n});\nexport type FlowProfileRefV1 = Static<typeof FlowProfileRefSchema>;\n\n/** Hasher injected by the host; keeps contracts free of node:crypto. Required by every digest-verifying parser. */\nexport type FlowDigestHasher = { sha256Hex: (text: string) => string };\n\n/** True when `sha256Hex(text)` equals `expected`. A missing, throwing or non-string hasher is a constant error. */\nexport function verifyFlowDigest(hasher: FlowDigestHasher, text: string, expected: string): boolean {\n\tlet actual: unknown;\n\ttry {\n\t\tactual = hasher.sha256Hex(text);\n\t} catch {\n\t\tthrow new FlowContractError(\"digest_unverifiable\");\n\t}\n\tif (typeof actual !== \"string\") throw new FlowContractError(\"digest_unverifiable\");\n\treturn actual === expected;\n}\n\nconst MAX_SNAPSHOT_DEPTH = 16;\nconst MAX_SNAPSHOT_NODES = 10_000;\nconst MAX_SNAPSHOT_STRING = 65_536;\n\nfunction isIndexKey(key: string, length: number): boolean {\n\tconst index = Number(key);\n\treturn Number.isInteger(index) && index >= 0 && index < length && String(index) === key;\n}\n\nfunction snapshotValue(value: unknown, depth: number, budget: { nodes: number }): unknown {\n\tbudget.nodes += 1;\n\tif (depth > MAX_SNAPSHOT_DEPTH || budget.nodes > MAX_SNAPSHOT_NODES) throw new Error(\"bounds\");\n\tif (value === null || typeof value === \"boolean\") return value;\n\tif (typeof value === \"string\") {\n\t\tif (value.length > MAX_SNAPSHOT_STRING || !value.isWellFormed()) throw new Error(\"string\");\n\t\treturn value;\n\t}\n\tif (typeof value === \"number\") {\n\t\tif (!Number.isFinite(value)) throw new Error(\"number\");\n\t\treturn value;\n\t}\n\tif (typeof value !== \"object\") throw new Error(\"type\");\n\tif (Array.isArray(value)) {\n\t\tconst length = value.length;\n\t\tif (length > MAX_SNAPSHOT_NODES) throw new Error(\"bounds\");\n\t\tfor (const key of Reflect.ownKeys(value)) {\n\t\t\tif (typeof key !== \"string\" || (key !== \"length\" && !isIndexKey(key, length))) throw new Error(\"array\");\n\t\t}\n\t\tconst out: unknown[] = [];\n\t\tfor (let index = 0; index < length; index += 1) {\n\t\t\tconst descriptor = Object.getOwnPropertyDescriptor(value, String(index));\n\t\t\tif (descriptor === undefined || !(\"value\" in descriptor)) throw new Error(\"array\");\n\t\t\tout.push(snapshotValue(descriptor.value, depth + 1, budget));\n\t\t}\n\t\treturn out;\n\t}\n\tconst proto = Object.getPrototypeOf(value);\n\tif (proto !== null && Object.getPrototypeOf(proto) !== null) throw new Error(\"prototype\");\n\tconst out: Record<string, unknown> = {};\n\tfor (const key of Reflect.ownKeys(value)) {\n\t\tif (typeof key !== \"string\" || !key.isWellFormed()) throw new Error(\"key\");\n\t\tconst descriptor = Object.getOwnPropertyDescriptor(value, key);\n\t\tif (descriptor === undefined || !(\"value\" in descriptor) || descriptor.enumerable !== true)\n\t\t\tthrow new Error(\"property\");\n\t\tif (descriptor.value === undefined) continue; // JSON semantics: an undefined property is absent\n\t\tObject.defineProperty(out, key, {\n\t\t\tvalue: snapshotValue(descriptor.value, depth + 1, budget),\n\t\t\tenumerable: true,\n\t\t\twritable: true,\n\t\t\tconfigurable: true,\n\t\t});\n\t}\n\treturn out;\n}\n\n/**\n * Plain-data snapshot of untrusted input: own enumerable data properties only (accessors, symbols, exotic and\n * non-plain objects are rejected), bounded depth/size, finite numbers, well-formed strings. Each property is read\n * exactly once, so the snapshot cannot change after it has been validated.\n */\nexport function snapshotFlowData(input: unknown): unknown {\n\treturn snapshotValue(input, 0, { nodes: 0 });\n}\n\n/**\n * Snapshot `input`, validate the snapshot, return the snapshot. Anything thrown while inspecting hostile input\n * (getters, proxy traps, forged FlowContractError objects) is discarded and replaced by a NEW constant `code` error;\n * the thrown value is never read, compared or rethrown. Only our own validation, after the snapshot exists, may throw.\n */\nexport function parseFlowData<T>(\n\tcode: FlowContractErrorCode,\n\tinput: unknown,\n\tvalidate: (snapshot: unknown) => snapshot is T,\n): T {\n\tconst snapshot = trySnapshotFlowData(code, input);\n\tif (!validate(snapshot)) throw new FlowContractError(code);\n\treturn snapshot;\n}\n\n/** `snapshotFlowData` whose every failure is a new `FlowContractError(code)`; the thrown value is not inspected. */\nexport function trySnapshotFlowData(code: FlowContractErrorCode, input: unknown): unknown {\n\ttry {\n\t\treturn snapshotFlowData(input);\n\t} catch {\n\t\tthrow new FlowContractError(code);\n\t}\n}\n\nexport function compileFlow<T extends TSchema>(schema: T) {\n\treturn Compile(schema);\n}\n\nexport function modelKey(ref: FlowModelRef): string {\n\treturn `${ref.provider}\\u0000${ref.model}`;\n}\n\nexport function hasDuplicateModels(refs: readonly FlowModelRef[]): boolean {\n\treturn new Set(refs.map(modelKey)).size !== refs.length;\n}\n\n/**\n * Canonical JSON text (RFC 8785 JCS subset): object keys sorted by UTF-16 code unit, no whitespace, `undefined`\n * properties omitted, numbers as ECMAScript Number toString (`JSON.stringify`; -0 prints 0, 1e21 prints 1e+21).\n * Lone surrogates (keys or strings), non-finite numbers and non-JSON values are rejected with a constant error.\n */\nexport function canonicalFlowJson(value: unknown): string {\n\tif (value === null || typeof value === \"boolean\") return JSON.stringify(value);\n\tif (typeof value === \"string\") {\n\t\tif (!value.isWellFormed()) throw new FlowContractError(\"canonical_invalid\");\n\t\treturn JSON.stringify(value);\n\t}\n\tif (typeof value === \"number\") {\n\t\tif (!Number.isFinite(value)) throw new FlowContractError(\"canonical_invalid\");\n\t\treturn JSON.stringify(value);\n\t}\n\tif (Array.isArray(value)) return `[${value.map(canonicalFlowJson).join(\",\")}]`;\n\tif (typeof value !== \"object\") throw new FlowContractError(\"canonical_invalid\");\n\tconst record = value as Record<string, unknown>;\n\tconst parts: string[] = [];\n\tfor (const key of Object.keys(record).sort()) {\n\t\tif (!key.isWellFormed()) throw new FlowContractError(\"canonical_invalid\");\n\t\tif (record[key] === undefined) continue;\n\t\tparts.push(`${JSON.stringify(key)}:${canonicalFlowJson(record[key])}`);\n\t}\n\treturn `{${parts.join(\",\")}}`;\n}\n\n/** Canonical text of `doc` without the property `omit`. */\nexport function canonicalWithout(doc: object, omit: string): string {\n\tconst copy: Record<string, unknown> = { ...doc };\n\tdelete copy[omit];\n\treturn canonicalFlowJson(copy);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"flow-common.js","sourceRoot":"","sources":["../src/flow-common.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyD,IAAI,EAAE,MAAM,SAAS,CAAC;AACtF,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAE1C;;;GAGG;AAEH,MAAM,CAAC,MAAM,eAAe,GAAG,+BAA+B,CAAC;AAC/D,gHAAgH;AAChH,MAAM,CAAC,MAAM,qBAAqB,GAAG,iEAAiE,CAAC;AACvG,MAAM,CAAC,MAAM,mBAAmB,GAAG,gBAAgB,CAAC;AACpD,MAAM,eAAe,GACpB,+IAA+I,CAAC;AAEjJ,MAAM,CAAC,MAAM,yBAAyB,GAAG;IACxC,eAAe,EAAE,sBAAsB;IACvC,iBAAiB,EAAE,4BAA4B;IAC/C,aAAa,EAAE,oBAAoB;IACnC,eAAe,EAAE,8BAA8B;IAC/C,eAAe,EAAE,8BAA8B;IAC/C,cAAc,EAAE,qBAAqB;IACrC,eAAe,EAAE,sBAAsB;IACvC,mBAAmB,EAAE,gCAAgC;IACrD,iBAAiB,EAAE,mCAAmC;IACtD,gBAAgB,EAAE,+CAA+C;CACxD,CAAC;AAGX,kGAAkG;AAClG,MAAM,OAAO,iBAAkB,SAAQ,KAAK;IAClC,IAAI,CAAwB;IACrC,YAAY,IAA2B;QACtC,KAAK,CAAC,yBAAyB,CAAC,IAAI,CAAC,CAAC,CAAC;QACvC,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC;QAChC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IAClB,CAAC;CACD;AAED,gGAAgG;AAChG,MAAM,CAAC,MAAM,GAAG,GAAG,CAAoC,GAAG,MAAS,EAAE,EAAE,CACtE,IAAI,CAAC,KAAK,CAA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AC,CAAC;IACxE,CAAC;IACD,OAAO,IAAI,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;AAC/B,CAAC;AAED,2DAA2D;AAC3D,MAAM,UAAU,gBAAgB,CAAC,GAAW,EAAE,IAAY;IACzD,MAAM,IAAI,GAA4B,EAAE,GAAG,GAAG,EAAE,CAAC;IACjD,OAAO,IAAI,CAAC,IAAI,CAAC,CAAC;IAClB,OAAO,iBAAiB,CAAC,IAAI,CAAC,CAAC;AAChC,CAAC","sourcesContent":["import { type Static, type TLiteral, type TSchema, type TUnion, Type } from \"typebox\";\nimport { Compile } from \"typebox/compile\";\n\n/**\n * Shared primitives for the `./flow-*` contract subpaths. TypeBox-only and browser-safe: no node:* imports,\n * no hashing (callers inject `sha256Hex`), no free-text string types.\n */\n\nexport const FLOW_ID_PATTERN = \"^[a-z0-9][a-z0-9_.:-]{0,127}$\";\n/** Model ids may be provider-qualified: lowercase, at most one `/`, no empty segment, <= 128 chars in total. */\nexport const FLOW_MODEL_ID_PATTERN = \"^(?=.{1,128}$)[a-z0-9][a-z0-9_.:-]*(?:/[a-z0-9][a-z0-9_.:-]*)?$\";\nexport const FLOW_DIGEST_PATTERN = \"^[a-f0-9]{64}$\";\nconst FLOW_TS_PATTERN =\n\t\"^\\\\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\\\\d|3[01])T(?:[01]\\\\d|2[0-3]):[0-5]\\\\d:[0-5]\\\\d(?:\\\\.\\\\d{1,9})?(?:Z|[+-](?:[01]\\\\d|2[0-3]):[0-5]\\\\d)$\";\n\nexport const FLOW_CONTRACT_ERROR_CODES = {\n\tprofile_invalid: \"Invalid flow profile\",\n\tadmission_invalid: \"Invalid flow run admission\",\n\tevent_invalid: \"Invalid flow event\",\n\tcommand_invalid: \"Invalid flow control command\",\n\treceipt_invalid: \"Invalid flow control receipt\",\n\tstatus_invalid: \"Invalid flow status\",\n\tdigest_mismatch: \"Flow digest mismatch\",\n\tdigest_unverifiable: \"Flow digest cannot be verified\",\n\tcanonical_invalid: \"Flow data cannot be canonicalized\",\n\treceipt_conflict: \"Flow receipt conflicts with the first receipt\",\n} as const;\nexport type FlowContractErrorCode = keyof typeof FLOW_CONTRACT_ERROR_CODES;\n\n/** Messages are constants chosen by contract code from `code`; rejected input is never echoed. */\nexport class FlowContractError extends Error {\n\treadonly code: FlowContractErrorCode;\n\tconstructor(code: FlowContractErrorCode) {\n\t\tsuper(FLOW_CONTRACT_ERROR_CODES[code]);\n\t\tthis.name = \"FlowContractError\";\n\t\tthis.code = code;\n\t}\n}\n\n/** Union of string literals with a precise Static type (a mapped array would infer `never`). */\nexport const lit = <const T extends readonly string[]>(...values: T) =>\n\tType.Union(values.map((value) => Type.Literal(value))) as unknown as TUnion<{\n\t\t-readonly [K in keyof T]: TLiteral<T[K]>;\n\t}>;\n\nexport const StrictObject = <const T extends Parameters<typeof Type.Object>[0]>(properties: T) =>\n\tType.Object(properties, { additionalProperties: false });\n\nexport const FlowIdSchema = Type.String({ pattern: FLOW_ID_PATTERN });\nexport const FlowDigestSchema = Type.String({ pattern: FLOW_DIGEST_PATTERN });\nconst DAYS_IN_MONTH = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] as const;\n\n/** Pattern-valid timestamps only: rejects impossible calendar dates such as 2026-02-31 or a non-leap Feb 29. */\nfunction isRealCalendarDate(timestamp: string): boolean {\n\tconst year = Number(timestamp.slice(0, 4));\n\tconst month = Number(timestamp.slice(5, 7));\n\tconst day = Number(timestamp.slice(8, 10));\n\tconst leap = (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;\n\treturn day <= (month === 2 && leap ? 29 : (DAYS_IN_MONTH[month - 1] ?? 0));\n}\n\nexport const FlowTimestampSchema = Type.Refine(Type.String({ pattern: FLOW_TS_PATTERN }), isRealCalendarDate);\nexport const FlowMicrousdSchema = Type.Integer({ minimum: 0, maximum: Number.MAX_SAFE_INTEGER });\nexport const FlowCountSchema = Type.Integer({ minimum: 0, maximum: Number.MAX_SAFE_INTEGER });\nexport const FlowPositiveIntSchema = Type.Integer({ minimum: 1, maximum: Number.MAX_SAFE_INTEGER });\n\nexport const FlowModelRefSchema = StrictObject({\n\tprovider: FlowIdSchema,\n\tmodel: Type.String({ pattern: FLOW_MODEL_ID_PATTERN }),\n});\nexport type FlowModelRef = Static<typeof FlowModelRefSchema>;\n\nexport const FLOW_ROLES = [\n\t\"scout\",\n\t\"worker\",\n\t\"implementer\",\n\t\"lead\",\n\t\"lead_large\",\n\t\"architect\",\n\t\"reviewer\",\n\t\"security_reviewer\",\n\t\"qa\",\n\t\"triage\",\n] as const;\nexport type FlowRole = (typeof FLOW_ROLES)[number];\nexport const FlowRoleSchema = Type.Union([\n\tType.Literal(\"scout\"),\n\tType.Literal(\"worker\"),\n\tType.Literal(\"implementer\"),\n\tType.Literal(\"lead\"),\n\tType.Literal(\"lead_large\"),\n\tType.Literal(\"architect\"),\n\tType.Literal(\"reviewer\"),\n\tType.Literal(\"security_reviewer\"),\n\tType.Literal(\"qa\"),\n\tType.Literal(\"triage\"),\n]);\n\n/** `Partial<Record<FlowRole, T>>` as a strict object. */\nexport const partialByRole = <T extends TSchema>(schema: T) =>\n\tStrictObject({\n\t\tscout: Type.Optional(schema),\n\t\tworker: Type.Optional(schema),\n\t\timplementer: Type.Optional(schema),\n\t\tlead: Type.Optional(schema),\n\t\tlead_large: Type.Optional(schema),\n\t\tarchitect: Type.Optional(schema),\n\t\treviewer: Type.Optional(schema),\n\t\tsecurity_reviewer: Type.Optional(schema),\n\t\tqa: Type.Optional(schema),\n\t\ttriage: Type.Optional(schema),\n\t});\n\nexport const FLOW_SIZES = [\"small\", \"medium\", \"large\"] as const;\nexport type FlowSize = (typeof FLOW_SIZES)[number];\nexport const FlowSizeSchema = Type.Union([Type.Literal(\"small\"), Type.Literal(\"medium\"), Type.Literal(\"large\")]);\n\nexport const FLOW_FAILURE_CLASSES = [\n\t\"provider_error\",\n\t\"provider_unreachable\",\n\t\"rate_limit\",\n\t\"timeout\",\n\t\"check_failed\",\n\t\"review_rejected\",\n\t\"qa_failed\",\n\t\"budget_stop\",\n\t\"cancelled\",\n\t\"crash\",\n\t\"unsafe_scope\",\n\t\"stalled\",\n\t\"config_invalid\",\n\t\"internal\",\n\t\"review_verdict_missing\",\n\t\"verification_unavailable\",\n\t\"blocked\",\n\t\"review_findings\",\n] as const;\nexport type FlowFailureClass = (typeof FLOW_FAILURE_CLASSES)[number];\nexport const FlowFailureClassSchema = Type.Union([\n\tType.Literal(\"provider_error\"),\n\tType.Literal(\"provider_unreachable\"),\n\tType.Literal(\"rate_limit\"),\n\tType.Literal(\"timeout\"),\n\tType.Literal(\"check_failed\"),\n\tType.Literal(\"review_rejected\"),\n\tType.Literal(\"qa_failed\"),\n\tType.Literal(\"budget_stop\"),\n\tType.Literal(\"cancelled\"),\n\tType.Literal(\"crash\"),\n\tType.Literal(\"unsafe_scope\"),\n\tType.Literal(\"stalled\"),\n\tType.Literal(\"config_invalid\"),\n\tType.Literal(\"internal\"),\n\tType.Literal(\"review_verdict_missing\"),\n\tType.Literal(\"verification_unavailable\"),\n\tType.Literal(\"blocked\"),\n\tType.Literal(\"review_findings\"),\n]);\n\nexport const FlowReasonClassSchema = Type.Union([FlowFailureClassSchema, Type.Literal(\"size_underestimated\")]);\nexport type FlowReasonClass = Static<typeof FlowReasonClassSchema>;\n\nexport const FlowProfileRefSchema = StrictObject({\n\tid: FlowIdSchema,\n\tversion: FlowPositiveIntSchema,\n\tdigest: FlowDigestSchema,\n});\nexport type FlowProfileRefV1 = Static<typeof FlowProfileRefSchema>;\n\n/** Hasher injected by the host; keeps contracts free of node:crypto. Required by every digest-verifying parser. */\nexport type FlowDigestHasher = { sha256Hex: (text: string) => string };\n\n/** True when `sha256Hex(text)` equals `expected`. A missing, throwing or non-string hasher is a constant error. */\nexport function verifyFlowDigest(hasher: FlowDigestHasher, text: string, expected: string): boolean {\n\tlet actual: unknown;\n\ttry {\n\t\tactual = hasher.sha256Hex(text);\n\t} catch {\n\t\tthrow new FlowContractError(\"digest_unverifiable\");\n\t}\n\tif (typeof actual !== \"string\") throw new FlowContractError(\"digest_unverifiable\");\n\treturn actual === expected;\n}\n\nconst MAX_SNAPSHOT_DEPTH = 16;\nconst MAX_SNAPSHOT_NODES = 10_000;\nconst MAX_SNAPSHOT_STRING = 65_536;\n\nfunction isIndexKey(key: string, length: number): boolean {\n\tconst index = Number(key);\n\treturn Number.isInteger(index) && index >= 0 && index < length && String(index) === key;\n}\n\nfunction snapshotValue(value: unknown, depth: number, budget: { nodes: number }): unknown {\n\tbudget.nodes += 1;\n\tif (depth > MAX_SNAPSHOT_DEPTH || budget.nodes > MAX_SNAPSHOT_NODES) throw new Error(\"bounds\");\n\tif (value === null || typeof value === \"boolean\") return value;\n\tif (typeof value === \"string\") {\n\t\tif (value.length > MAX_SNAPSHOT_STRING || !value.isWellFormed()) throw new Error(\"string\");\n\t\treturn value;\n\t}\n\tif (typeof value === \"number\") {\n\t\tif (!Number.isFinite(value)) throw new Error(\"number\");\n\t\treturn value;\n\t}\n\tif (typeof value !== \"object\") throw new Error(\"type\");\n\tif (Array.isArray(value)) {\n\t\tconst length = value.length;\n\t\tif (length > MAX_SNAPSHOT_NODES) throw new Error(\"bounds\");\n\t\tfor (const key of Reflect.ownKeys(value)) {\n\t\t\tif (typeof key !== \"string\" || (key !== \"length\" && !isIndexKey(key, length))) throw new Error(\"array\");\n\t\t}\n\t\tconst out: unknown[] = [];\n\t\tfor (let index = 0; index < length; index += 1) {\n\t\t\tconst descriptor = Object.getOwnPropertyDescriptor(value, String(index));\n\t\t\tif (descriptor === undefined || !(\"value\" in descriptor)) throw new Error(\"array\");\n\t\t\tout.push(snapshotValue(descriptor.value, depth + 1, budget));\n\t\t}\n\t\treturn out;\n\t}\n\tconst proto = Object.getPrototypeOf(value);\n\tif (proto !== null && Object.getPrototypeOf(proto) !== null) throw new Error(\"prototype\");\n\tconst out: Record<string, unknown> = {};\n\tfor (const key of Reflect.ownKeys(value)) {\n\t\tif (typeof key !== \"string\" || !key.isWellFormed()) throw new Error(\"key\");\n\t\tconst descriptor = Object.getOwnPropertyDescriptor(value, key);\n\t\tif (descriptor === undefined || !(\"value\" in descriptor) || descriptor.enumerable !== true)\n\t\t\tthrow new Error(\"property\");\n\t\tif (descriptor.value === undefined) continue; // JSON semantics: an undefined property is absent\n\t\tObject.defineProperty(out, key, {\n\t\t\tvalue: snapshotValue(descriptor.value, depth + 1, budget),\n\t\t\tenumerable: true,\n\t\t\twritable: true,\n\t\t\tconfigurable: true,\n\t\t});\n\t}\n\treturn out;\n}\n\n/**\n * Plain-data snapshot of untrusted input: own enumerable data properties only (accessors, symbols, exotic and\n * non-plain objects are rejected), bounded depth/size, finite numbers, well-formed strings. Each property is read\n * exactly once, so the snapshot cannot change after it has been validated.\n */\nexport function snapshotFlowData(input: unknown): unknown {\n\treturn snapshotValue(input, 0, { nodes: 0 });\n}\n\n/**\n * Snapshot `input`, validate the snapshot, return the snapshot. Anything thrown while inspecting hostile input\n * (getters, proxy traps, forged FlowContractError objects) is discarded and replaced by a NEW constant `code` error;\n * the thrown value is never read, compared or rethrown. Only our own validation, after the snapshot exists, may throw.\n */\nexport function parseFlowData<T>(\n\tcode: FlowContractErrorCode,\n\tinput: unknown,\n\tvalidate: (snapshot: unknown) => snapshot is T,\n): T {\n\tconst snapshot = trySnapshotFlowData(code, input);\n\tif (!validate(snapshot)) throw new FlowContractError(code);\n\treturn snapshot;\n}\n\n/** `snapshotFlowData` whose every failure is a new `FlowContractError(code)`; the thrown value is not inspected. */\nexport function trySnapshotFlowData(code: FlowContractErrorCode, input: unknown): unknown {\n\ttry {\n\t\treturn snapshotFlowData(input);\n\t} catch {\n\t\tthrow new FlowContractError(code);\n\t}\n}\n\nexport function compileFlow<T extends TSchema>(schema: T) {\n\treturn Compile(schema);\n}\n\nexport function modelKey(ref: FlowModelRef): string {\n\treturn `${ref.provider}\\u0000${ref.model}`;\n}\n\nexport function hasDuplicateModels(refs: readonly FlowModelRef[]): boolean {\n\treturn new Set(refs.map(modelKey)).size !== refs.length;\n}\n\n/**\n * Canonical JSON text (RFC 8785 JCS subset): object keys sorted by UTF-16 code unit, no whitespace, `undefined`\n * properties omitted, numbers as ECMAScript Number toString (`JSON.stringify`; -0 prints 0, 1e21 prints 1e+21).\n * Lone surrogates (keys or strings), non-finite numbers and non-JSON values are rejected with a constant error.\n */\nexport function canonicalFlowJson(value: unknown): string {\n\tif (value === null || typeof value === \"boolean\") return JSON.stringify(value);\n\tif (typeof value === \"string\") {\n\t\tif (!value.isWellFormed()) throw new FlowContractError(\"canonical_invalid\");\n\t\treturn JSON.stringify(value);\n\t}\n\tif (typeof value === \"number\") {\n\t\tif (!Number.isFinite(value)) throw new FlowContractError(\"canonical_invalid\");\n\t\treturn JSON.stringify(value);\n\t}\n\tif (Array.isArray(value)) return `[${value.map(canonicalFlowJson).join(\",\")}]`;\n\tif (typeof value !== \"object\") throw new FlowContractError(\"canonical_invalid\");\n\tconst record = value as Record<string, unknown>;\n\tconst parts: string[] = [];\n\tfor (const key of Object.keys(record).sort()) {\n\t\tif (!key.isWellFormed()) throw new FlowContractError(\"canonical_invalid\");\n\t\tif (record[key] === undefined) continue;\n\t\tparts.push(`${JSON.stringify(key)}:${canonicalFlowJson(record[key])}`);\n\t}\n\treturn `{${parts.join(\",\")}}`;\n}\n\n/** Canonical text of `doc` without the property `omit`. */\nexport function canonicalWithout(doc: object, omit: string): string {\n\tconst copy: Record<string, unknown> = { ...doc };\n\tdelete copy[omit];\n\treturn canonicalFlowJson(copy);\n}\n"]}
|
package/dist/flow-control.d.ts
CHANGED
|
@@ -17,7 +17,14 @@ export declare const FlowControlCommandV1Schema: Type.TUnion<[Type.TObject<{
|
|
|
17
17
|
readonly id: Type.TString;
|
|
18
18
|
readonly type: Type.TLiteral<"flow_cancel">;
|
|
19
19
|
readonly runId: Type.TString;
|
|
20
|
-
readonly reason: Type.TUnion<[Type.TLiteral<"user">, Type.TLiteral<"budget">, Type.TLiteral<"shutdown">, Type.TLiteral<"kill_switch">]>;
|
|
20
|
+
readonly reason: Type.TUnion<[Type.TLiteral<"user">, Type.TLiteral<"budget">, Type.TLiteral<"shutdown">, Type.TLiteral<"kill_switch">, Type.TLiteral<"superseded">]>;
|
|
21
|
+
}>, Type.TObject<{
|
|
22
|
+
readonly id: Type.TString;
|
|
23
|
+
readonly type: Type.TLiteral<"flow_repair">;
|
|
24
|
+
readonly runId: Type.TString;
|
|
25
|
+
readonly round: Type.TInteger;
|
|
26
|
+
readonly decision: Type.TUnion<[Type.TLiteral<"grant">, Type.TLiteral<"deny">]>;
|
|
27
|
+
readonly reason: Type.TOptional<Type.TUnion<[Type.TLiteral<"user_edited">, Type.TLiteral<"busy">, Type.TLiteral<"policy">]>>;
|
|
21
28
|
}>, Type.TObject<{
|
|
22
29
|
readonly id: Type.TString;
|
|
23
30
|
readonly type: Type.TLiteral<"flow_message">;
|
|
@@ -32,9 +39,9 @@ export type FlowControlCommandV1 = Static<typeof FlowControlCommandV1Schema>;
|
|
|
32
39
|
export declare const FlowControlReceiptV1Schema: Type.TObject<{
|
|
33
40
|
readonly type: Type.TLiteral<"response">;
|
|
34
41
|
readonly id: Type.TString;
|
|
35
|
-
readonly command: Type.TUnion<[Type.TLiteral<"flow_status">, Type.TLiteral<"flow_pause">, Type.TLiteral<"flow_resume">, Type.TLiteral<"flow_cancel">]>;
|
|
42
|
+
readonly command: Type.TUnion<[Type.TLiteral<"flow_status">, Type.TLiteral<"flow_pause">, Type.TLiteral<"flow_resume">, Type.TLiteral<"flow_cancel">, Type.TLiteral<"flow_repair">]>;
|
|
36
43
|
readonly state: Type.TUnion<[Type.TLiteral<"accepted">, Type.TLiteral<"applied">, Type.TLiteral<"rejected">]>;
|
|
37
|
-
readonly reason: Type.TOptional<Type.TUnion<[Type.TUnion<[Type.TLiteral<"provider_error">, Type.TLiteral<"provider_unreachable">, Type.TLiteral<"rate_limit">, Type.TLiteral<"timeout">, Type.TLiteral<"check_failed">, Type.TLiteral<"review_rejected">, Type.TLiteral<"qa_failed">, Type.TLiteral<"budget_stop">, Type.TLiteral<"cancelled">, Type.TLiteral<"crash">, Type.TLiteral<"unsafe_scope">, Type.TLiteral<"stalled">, Type.TLiteral<"config_invalid">, Type.TLiteral<"internal">, Type.TLiteral<"review_verdict_missing">, Type.TLiteral<"verification_unavailable">, Type.TLiteral<"blocked">]>, Type.TLiteral<"size_underestimated">]>>;
|
|
44
|
+
readonly reason: Type.TOptional<Type.TUnion<[Type.TUnion<[Type.TLiteral<"provider_error">, Type.TLiteral<"provider_unreachable">, Type.TLiteral<"rate_limit">, Type.TLiteral<"timeout">, Type.TLiteral<"check_failed">, Type.TLiteral<"review_rejected">, Type.TLiteral<"qa_failed">, Type.TLiteral<"budget_stop">, Type.TLiteral<"cancelled">, Type.TLiteral<"crash">, Type.TLiteral<"unsafe_scope">, Type.TLiteral<"stalled">, Type.TLiteral<"config_invalid">, Type.TLiteral<"internal">, Type.TLiteral<"review_verdict_missing">, Type.TLiteral<"verification_unavailable">, Type.TLiteral<"blocked">, Type.TLiteral<"review_findings">]>, Type.TLiteral<"size_underestimated">]>>;
|
|
38
45
|
readonly terminationConfirmed: Type.TOptional<Type.TBoolean>;
|
|
39
46
|
}>;
|
|
40
47
|
export type FlowControlReceiptV1 = Static<typeof FlowControlReceiptV1Schema>;
|
|
@@ -45,7 +52,7 @@ export declare const FlowMessageReceiptV1Schema: Type.TObject<{
|
|
|
45
52
|
readonly command: Type.TLiteral<"flow_message">;
|
|
46
53
|
readonly messageId: Type.TString;
|
|
47
54
|
readonly state: Type.TUnion<[Type.TLiteral<"accepted">, Type.TLiteral<"applied">, Type.TLiteral<"rejected">]>;
|
|
48
|
-
readonly reason: Type.TOptional<Type.TUnion<[Type.TUnion<[Type.TLiteral<"provider_error">, Type.TLiteral<"provider_unreachable">, Type.TLiteral<"rate_limit">, Type.TLiteral<"timeout">, Type.TLiteral<"check_failed">, Type.TLiteral<"review_rejected">, Type.TLiteral<"qa_failed">, Type.TLiteral<"budget_stop">, Type.TLiteral<"cancelled">, Type.TLiteral<"crash">, Type.TLiteral<"unsafe_scope">, Type.TLiteral<"stalled">, Type.TLiteral<"config_invalid">, Type.TLiteral<"internal">, Type.TLiteral<"review_verdict_missing">, Type.TLiteral<"verification_unavailable">, Type.TLiteral<"blocked">]>, Type.TLiteral<"size_underestimated">]>>;
|
|
55
|
+
readonly reason: Type.TOptional<Type.TUnion<[Type.TUnion<[Type.TLiteral<"provider_error">, Type.TLiteral<"provider_unreachable">, Type.TLiteral<"rate_limit">, Type.TLiteral<"timeout">, Type.TLiteral<"check_failed">, Type.TLiteral<"review_rejected">, Type.TLiteral<"qa_failed">, Type.TLiteral<"budget_stop">, Type.TLiteral<"cancelled">, Type.TLiteral<"crash">, Type.TLiteral<"unsafe_scope">, Type.TLiteral<"stalled">, Type.TLiteral<"config_invalid">, Type.TLiteral<"internal">, Type.TLiteral<"review_verdict_missing">, Type.TLiteral<"verification_unavailable">, Type.TLiteral<"blocked">, Type.TLiteral<"review_findings">]>, Type.TLiteral<"size_underestimated">]>>;
|
|
49
56
|
readonly disposition: Type.TUnion<[Type.TLiteral<"live">, Type.TLiteral<"queued">, Type.TLiteral<"rejected">]>;
|
|
50
57
|
readonly deliveredTo: Type.TOptional<Type.TObject<{
|
|
51
58
|
readonly taskId: Type.TString;
|
|
@@ -58,7 +65,7 @@ export declare const FlowStatusV1Schema: Type.TObject<{
|
|
|
58
65
|
readonly mode: Type.TUnion<[Type.TLiteral<"auto">, Type.TLiteral<"direct">]>;
|
|
59
66
|
readonly size: Type.TUnion<[Type.TLiteral<"small">, Type.TLiteral<"medium">, Type.TLiteral<"large">]>;
|
|
60
67
|
readonly state: Type.TUnion<[Type.TLiteral<"starting">, Type.TLiteral<"running">, Type.TLiteral<"paused">, Type.TLiteral<"cancelling">, Type.TLiteral<"settled">]>;
|
|
61
|
-
readonly stage: Type.TUnion<[Type.TLiteral<"sizing">, Type.TLiteral<"planning">, Type.TLiteral<"implementing">, Type.TLiteral<"reviewing">, Type.TLiteral<"qa">, Type.TLiteral<"settling">]>;
|
|
68
|
+
readonly stage: Type.TUnion<[Type.TLiteral<"sizing">, Type.TLiteral<"planning">, Type.TLiteral<"implementing">, Type.TLiteral<"reviewing">, Type.TLiteral<"qa">, Type.TLiteral<"settling">, Type.TLiteral<"verifying_after">]>;
|
|
62
69
|
readonly agents: Type.TArray<Type.TObject<{
|
|
63
70
|
readonly taskId: Type.TString;
|
|
64
71
|
readonly role: Type.TUnion<[Type.TLiteral<"scout">, Type.TLiteral<"worker">, Type.TLiteral<"implementer">, Type.TLiteral<"lead">, Type.TLiteral<"lead_large">, Type.TLiteral<"architect">, Type.TLiteral<"reviewer">, Type.TLiteral<"security_reviewer">, Type.TLiteral<"qa">, Type.TLiteral<"triage">]>;
|
|
@@ -69,7 +76,7 @@ export declare const FlowStatusV1Schema: Type.TObject<{
|
|
|
69
76
|
readonly state: Type.TUnion<[Type.TLiteral<"pending">, Type.TLiteral<"running">, Type.TLiteral<"succeeded">, Type.TLiteral<"failed">, Type.TLiteral<"cancelled">]>;
|
|
70
77
|
}>>;
|
|
71
78
|
readonly budgetPct: Type.TNumber;
|
|
72
|
-
readonly warnings: Type.TArray<Type.TUnion<[Type.TUnion<[Type.TLiteral<"provider_error">, Type.TLiteral<"provider_unreachable">, Type.TLiteral<"rate_limit">, Type.TLiteral<"timeout">, Type.TLiteral<"check_failed">, Type.TLiteral<"review_rejected">, Type.TLiteral<"qa_failed">, Type.TLiteral<"budget_stop">, Type.TLiteral<"cancelled">, Type.TLiteral<"crash">, Type.TLiteral<"unsafe_scope">, Type.TLiteral<"stalled">, Type.TLiteral<"config_invalid">, Type.TLiteral<"internal">, Type.TLiteral<"review_verdict_missing">, Type.TLiteral<"verification_unavailable">, Type.TLiteral<"blocked">]>, Type.TLiteral<"size_underestimated">]>>;
|
|
79
|
+
readonly warnings: Type.TArray<Type.TUnion<[Type.TUnion<[Type.TLiteral<"provider_error">, Type.TLiteral<"provider_unreachable">, Type.TLiteral<"rate_limit">, Type.TLiteral<"timeout">, Type.TLiteral<"check_failed">, Type.TLiteral<"review_rejected">, Type.TLiteral<"qa_failed">, Type.TLiteral<"budget_stop">, Type.TLiteral<"cancelled">, Type.TLiteral<"crash">, Type.TLiteral<"unsafe_scope">, Type.TLiteral<"stalled">, Type.TLiteral<"config_invalid">, Type.TLiteral<"internal">, Type.TLiteral<"review_verdict_missing">, Type.TLiteral<"verification_unavailable">, Type.TLiteral<"blocked">, Type.TLiteral<"review_findings">]>, Type.TLiteral<"size_underestimated">]>>;
|
|
73
80
|
}>;
|
|
74
81
|
export type FlowStatusV1 = Static<typeof FlowStatusV1Schema>;
|
|
75
82
|
/** Pushed frames (HC -> host). */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flow-control.d.ts","sourceRoot":"","sources":["../src/flow-control.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAe5C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAEpD,eAAO,MAAM,uBAAuB,QAAS,CAAC;AAE9C,eAAO,MAAM,0BAA0B
|
|
1
|
+
{"version":3,"file":"flow-control.d.ts","sourceRoot":"","sources":["../src/flow-control.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAe5C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAEpD,eAAO,MAAM,uBAAuB,QAAS,CAAC;AAE9C,eAAO,MAAM,0BAA0B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IA2BrC,CAAC;AACH,MAAM,MAAM,oBAAoB,GAAG,MAAM,CAAC,OAAO,0BAA0B,CAAC,CAAC;AAI7E,eAAO,MAAM,0BAA0B;;;;;;;EAOrC,CAAC;AACH,MAAM,MAAM,oBAAoB,GAAG,MAAM,CAAC,OAA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 export const FlowControlCommandV1Schema = Type.Union([
|
|
|
9
9
|
id: FlowIdSchema,
|
|
10
10
|
type: Type.Literal("flow_cancel"),
|
|
11
11
|
runId: FlowIdSchema,
|
|
12
|
-
reason: lit("user", "budget", "shutdown", "kill_switch"),
|
|
12
|
+
reason: lit("user", "budget", "shutdown", "kill_switch", "superseded"),
|
|
13
|
+
}),
|
|
14
|
+
// Host answer to a verify-after `repair_proposed` event (RepairGate host adapter).
|
|
15
|
+
StrictObject({
|
|
16
|
+
id: FlowIdSchema,
|
|
17
|
+
type: Type.Literal("flow_repair"),
|
|
18
|
+
runId: FlowIdSchema,
|
|
19
|
+
round: Type.Integer({ minimum: 1, maximum: 4 }),
|
|
20
|
+
decision: lit("grant", "deny"),
|
|
21
|
+
reason: Type.Optional(lit("user_edited", "busy", "policy")),
|
|
13
22
|
}),
|
|
14
23
|
StrictObject({
|
|
15
24
|
id: FlowIdSchema,
|
|
@@ -24,7 +33,7 @@ const State = lit("accepted", "applied", "rejected");
|
|
|
24
33
|
export const FlowControlReceiptV1Schema = StrictObject({
|
|
25
34
|
type: Type.Literal("response"),
|
|
26
35
|
id: FlowIdSchema,
|
|
27
|
-
command: lit("flow_status", "flow_pause", "flow_resume", "flow_cancel"),
|
|
36
|
+
command: lit("flow_status", "flow_pause", "flow_resume", "flow_cancel", "flow_repair"),
|
|
28
37
|
state: State,
|
|
29
38
|
reason: Type.Optional(FlowReasonClassSchema),
|
|
30
39
|
terminationConfirmed: Type.Optional(Type.Boolean()),
|
|
@@ -45,7 +54,7 @@ export const FlowStatusV1Schema = StrictObject({
|
|
|
45
54
|
mode: lit("auto", "direct"),
|
|
46
55
|
size: FlowSizeSchema,
|
|
47
56
|
state: lit("starting", "running", "paused", "cancelling", "settled"),
|
|
48
|
-
stage: lit("sizing", "planning", "implementing", "reviewing", "qa", "settling"),
|
|
57
|
+
stage: lit("sizing", "planning", "implementing", "reviewing", "qa", "settling", "verifying_after"),
|
|
49
58
|
agents: Type.Array(StrictObject({
|
|
50
59
|
taskId: FlowIdSchema,
|
|
51
60
|
role: FlowRoleSchema,
|
package/dist/flow-control.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flow-control.js","sourceRoot":"","sources":["../src/flow-control.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,IAAI,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EACN,iBAAiB,EACjB,WAAW,EACX,iBAAiB,EACjB,YAAY,EACZ,kBAAkB,EAClB,qBAAqB,EACrB,cAAc,EACd,cAAc,EACd,GAAG,EACH,aAAa,EACb,YAAY,EACZ,mBAAmB,GACnB,MAAM,kBAAkB,CAAC;AAG1B,MAAM,CAAC,MAAM,uBAAuB,GAAG,MAAM,CAAC;AAE9C,MAAM,CAAC,MAAM,0BAA0B,GAAG,IAAI,CAAC,KAAK,CAAC;IACpD,YAAY,CAAC,EAAE,EAAE,EAAE,YAAY,EAAE,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC,EAAE,CAAC;IACzG,YAAY,CAAC,EAAE,EAAE,EAAE,YAAY,EAAE,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE,KAAK,EAAE,YAAY,EAAE,CAAC;IACzF,YAAY,CAAC,EAAE,EAAE,EAAE,YAAY,EAAE,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,EAAE,KAAK,EAAE,YAAY,EAAE,CAAC;IAC1F,YAAY,CAAC;QACZ,EAAE,EAAE,YAAY;QAChB,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC;QACjC,KAAK,EAAE,YAAY;QACnB,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,QAAQ,EAAE,UAAU,EAAE,aAAa,CAAC;KACxD,CAAC;IACF,YAAY,CAAC;QACZ,EAAE,EAAE,YAAY;QAChB,IAAI,EAAE,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O,EAAE,eAAe,CAAC,MAAM,CAAC,EAAE,CAAC;QAC9D,CAAC;KACD,CAAC;AACH,CAAC","sourcesContent":["import { type Static, Type } from \"typebox\";\nimport {\n\tcanonicalFlowJson,\n\tcompileFlow,\n\tFlowContractError,\n\tFlowIdSchema,\n\tFlowModelRefSchema,\n\tFlowReasonClassSchema,\n\tFlowRoleSchema,\n\tFlowSizeSchema,\n\tlit,\n\tparseFlowData,\n\tStrictObject,\n\ttrySnapshotFlowData,\n} from \"./flow-common.ts\";\nimport type { FlowEventV1 } from \"./flow-events.ts\";\n\nexport const FLOW_MESSAGE_MAX_LENGTH = 16_000;\n\nexport const FlowControlCommandV1Schema = Type.Union([\n\tStrictObject({ id: FlowIdSchema, type: Type.Literal(\"flow_status\"), runId: Type.Optional(FlowIdSchema) }),\n\tStrictObject({ id: FlowIdSchema, type: Type.Literal(\"flow_pause\"), runId: FlowIdSchema }),\n\tStrictObject({ id: FlowIdSchema, type: Type.Literal(\"flow_resume\"), runId: FlowIdSchema }),\n\tStrictObject({\n\t\tid: FlowIdSchema,\n\t\ttype: Type.Literal(\"flow_cancel\"),\n\t\trunId: FlowIdSchema,\n\t\treason: lit(\"user\", \"budget\", \"shutdown\", \"kill_switch\"),\n\t}),\n\tStrictObject({\n\t\tid: FlowIdSchema,\n\t\ttype: Type.Literal(\"flow_message\"),\n\t\trunId: FlowIdSchema,\n\t\tmessageId: FlowIdSchema,\n\t\ttext: Type.String({ minLength: 1, maxLength: FLOW_MESSAGE_MAX_LENGTH }),\n\t\ttarget: Type.Optional(Type.Union([StrictObject({ taskId: FlowIdSchema }), Type.Literal(\"lead\")])),\n\t}),\n]);\nexport type FlowControlCommandV1 = Static<typeof FlowControlCommandV1Schema>;\n\nconst State = lit(\"accepted\", \"applied\", \"rejected\");\n\nexport const FlowControlReceiptV1Schema = StrictObject({\n\ttype: Type.Literal(\"response\"),\n\tid: FlowIdSchema,\n\tcommand: lit(\"flow_status\", \"flow_pause\", \"flow_resume\", \"flow_cancel\"),\n\tstate: State,\n\treason: Type.Optional(FlowReasonClassSchema),\n\tterminationConfirmed: Type.Optional(Type.Boolean()),\n});\nexport type FlowControlReceiptV1 = Static<typeof FlowControlReceiptV1Schema>;\n\n/** `messageId` is carried so message receipts can be de-duplicated by it. */\nexport const FlowMessageReceiptV1Schema = StrictObject({\n\ttype: Type.Literal(\"response\"),\n\tid: FlowIdSchema,\n\tcommand: Type.Literal(\"flow_message\"),\n\tmessageId: FlowIdSchema,\n\tstate: State,\n\treason: Type.Optional(FlowReasonClassSchema),\n\tdisposition: lit(\"live\", \"queued\", \"rejected\"),\n\tdeliveredTo: Type.Optional(StrictObject({ taskId: FlowIdSchema, role: FlowRoleSchema })),\n});\nexport type FlowMessageReceiptV1 = Static<typeof FlowMessageReceiptV1Schema>;\n\nexport const FlowStatusV1Schema = StrictObject({\n\trunId: FlowIdSchema,\n\tmode: lit(\"auto\", \"direct\"),\n\tsize: FlowSizeSchema,\n\tstate: lit(\"starting\", \"running\", \"paused\", \"cancelling\", \"settled\"),\n\tstage: lit(\"sizing\", \"planning\", \"implementing\", \"reviewing\", \"qa\", \"settling\"),\n\tagents: Type.Array(\n\t\tStrictObject({\n\t\t\ttaskId: FlowIdSchema,\n\t\t\trole: FlowRoleSchema,\n\t\t\tmodel: FlowModelRefSchema,\n\t\t\tstate: lit(\"pending\", \"running\", \"succeeded\", \"failed\", \"cancelled\"),\n\t\t}),\n\t\t{ maxItems: 64 },\n\t),\n\tbudgetPct: Type.Number({ minimum: 0, maximum: 100 }),\n\twarnings: Type.Array(FlowReasonClassSchema, { maxItems: 16 }),\n});\nexport type FlowStatusV1 = Static<typeof FlowStatusV1Schema>;\n\n/** Pushed frames (HC -> host). */\nexport type FlowEventFrameV1 = { type: \"flow_event\"; event: FlowEventV1 };\nexport type FlowStatusFrameV1 = { type: \"flow_status\"; status: FlowStatusV1 };\n\nconst CommandValidator = compileFlow(FlowControlCommandV1Schema);\nconst ControlReceiptValidator = compileFlow(FlowControlReceiptV1Schema);\nconst MessageReceiptValidator = compileFlow(FlowMessageReceiptV1Schema);\nconst StatusValidator = compileFlow(FlowStatusV1Schema);\n\n/** Each parser validates a plain-data snapshot of `input` and returns the snapshot (never the caller's object). */\nexport function parseFlowControlCommandV1(input: unknown): FlowControlCommandV1 {\n\t// TypeBox may count maxLength in code points; the contract is UTF-16 code units (String.length), like rpc.ts.\n\treturn parseFlowData(\n\t\t\"command_invalid\",\n\t\tinput,\n\t\t(value): value is FlowControlCommandV1 =>\n\t\t\tCommandValidator.Check(value) &&\n\t\t\t(value.type !== \"flow_message\" || value.text.length <= FLOW_MESSAGE_MAX_LENGTH),\n\t);\n}\n\nfunction isControlReceipt(value: unknown): value is FlowControlReceiptV1 {\n\t// terminationConfirmed is meaningful for cancel only.\n\treturn (\n\t\tControlReceiptValidator.Check(value) &&\n\t\t(value.terminationConfirmed === undefined || value.command === \"flow_cancel\")\n\t);\n}\n\nexport function parseFlowControlReceiptV1(input: unknown): FlowControlReceiptV1 {\n\treturn parseFlowData(\"receipt_invalid\", input, isControlReceipt);\n}\n\nexport function parseFlowMessageReceiptV1(input: unknown): FlowMessageReceiptV1 {\n\treturn parseFlowData(\"receipt_invalid\", input, (value): value is FlowMessageReceiptV1 =>\n\t\tMessageReceiptValidator.Check(value),\n\t);\n}\n\nexport function parseFlowStatusV1(input: unknown): FlowStatusV1 {\n\treturn parseFlowData(\"status_invalid\", input, (value): value is FlowStatusV1 => StatusValidator.Check(value));\n}\n\nexport type FlowReceiptV1 = FlowControlReceiptV1 | FlowMessageReceiptV1;\n\nfunction withId(receipt: FlowReceiptV1, id: string): FlowReceiptV1 {\n\treturn { ...receipt, id };\n}\n\nfunction withoutId(receipt: FlowReceiptV1): string {\n\tconst { id: _id, ...rest } = receipt;\n\treturn canonicalFlowJson(rest);\n}\n\n/**\n * True when `next` is an allowed repeat of `prev`. Same command id => identical receipt. Same messageId\n * (message receipts) => identical receipt apart from `id`. Unrelated receipts return false. Conflicts throw.\n */\nexport function checkFlowReceiptIdempotency(prev: FlowReceiptV1, next: FlowReceiptV1): boolean {\n\tconst sameId = prev.id === next.id;\n\tconst sameMessage = \"messageId\" in prev && \"messageId\" in next && prev.messageId === next.messageId;\n\tif (!sameId && !sameMessage) return false;\n\tconst identical = sameId ? canonicalFlowJson(prev) === canonicalFlowJson(next) : withoutId(prev) === withoutId(next);\n\tif (!identical) throw new FlowContractError(\"receipt_conflict\");\n\treturn true;\n}\n\nexport type FlowReceiptLedger = {\n\t/**\n\t * First receipt wins. A repeat (same command id, or same messageId under a new command id) returns a copy of the\n\t * first receipt and binds the new command id to it; a conflicting repeat throws. Receipts are validated, stored\n\t * frozen, and returned as deep copies.\n\t */\n\trecord(receipt: FlowReceiptV1): { replayed: boolean; receipt: FlowReceiptV1 };\n};\n\nfunction deepFreeze<T>(value: T): T {\n\tif (typeof value === \"object\" && value !== null) {\n\t\tfor (const child of Object.values(value)) deepFreeze(child);\n\t\tObject.freeze(value);\n\t}\n\treturn value;\n}\n\nexport function createFlowReceiptLedger(): FlowReceiptLedger {\n\t// Every command id seen (including replay aliases) maps to the first receipt it was bound to.\n\tconst byCommand = new Map<string, FlowReceiptV1>();\n\tconst byMessage = new Map<string, FlowReceiptV1>();\n\treturn {\n\t\trecord(input) {\n\t\t\t// Snapshot first: the discriminant is read from the snapshot, never from the caller's object.\n\t\t\tconst snapshot = trySnapshotFlowData(\"receipt_invalid\", input);\n\t\t\tconst next =\n\t\t\t\t(snapshot as { command?: unknown } | null)?.command === \"flow_message\"\n\t\t\t\t\t? parseFlowMessageReceiptV1(snapshot)\n\t\t\t\t\t: parseFlowControlReceiptV1(snapshot);\n\t\t\tconst priors = [\n\t\t\t\tbyCommand.get(next.id),\n\t\t\t\t\"messageId\" in next ? byMessage.get(next.messageId) : undefined,\n\t\t\t].filter((prior): prior is FlowReceiptV1 => prior !== undefined);\n\t\t\tfor (const prior of priors) {\n\t\t\t\tif (canonicalFlowJson(withId(prior, next.id)) !== canonicalFlowJson(next)) {\n\t\t\t\t\tthrow new FlowContractError(\"receipt_conflict\");\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst first = priors[0];\n\t\t\tif (first !== undefined) {\n\t\t\t\tbyCommand.set(next.id, first);\n\t\t\t\treturn { replayed: true, receipt: structuredClone(first) };\n\t\t\t}\n\t\t\tconst stored = deepFreeze(next);\n\t\t\tbyCommand.set(stored.id, stored);\n\t\t\tif (\"messageId\" in stored) byMessage.set(stored.messageId, stored);\n\t\t\treturn { replayed: false, receipt: structuredClone(stored) };\n\t\t},\n\t};\n}\n"]}
|
|
1
|
+
{"version":3,"file":"flow-control.js","sourceRoot":"","sources":["../src/flow-control.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,IAAI,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EACN,iBAAiB,EACjB,WAAW,EACX,iBAAiB,EACjB,YAAY,EACZ,kBAAkB,EAClB,qBAAqB,EACrB,cAAc,EACd,cAAc,EACd,GAAG,EACH,aAAa,EACb,YAAY,EACZ,mBAAmB,GACnB,MAAM,kBAAkB,CAAC;AAG1B,MAAM,CAAC,MAAM,uBAAuB,GAAG,MAAM,CAAC;AAE9C,MAAM,CAAC,MAAM,0BAA0B,GAAG,IAAI,CAAC,KAAK,CAAC;IACpD,YAAY,CAAC,EAAE,EAAE,EAAE,YAAY,EAAE,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC,EAAE,CAAC;IACzG,YAAY,CAAC,EAAE,EAAE,EAAE,YAAY,EAAE,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE,KAAK,EAAE,YAAY,EAAE,CAAC;IACzF,YAAY,CAAC,EAAE,EAAE,EAAE,YAAY,EAAE,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,EAAE,KAAK,EAAE,YAAY,EAAE,CAAC;IAC1F,YAAY,CAAC;QACZ,EAAE,E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,CAAC,KAAK,iBAAiB,CAAC,IAAI,CAAC,EAAE,CAAC;oBAC3E,MAAM,IAAI,iBAAiB,CAAC,kBAAkB,CAAC,CAAC;gBACjD,CAAC;YACF,CAAC;YACD,MAAM,KAAK,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;YACxB,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;gBACzB,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;gBAC9B,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,OAAO,EAAE,eAAe,CAAC,KAAK,CAAC,EAAE,CAAC;YAC5D,CAAC;YACD,MAAM,MAAM,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC;YAChC,SAAS,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC;YACjC,IAAI,WAAW,IAAI,MAAM;gBAAE,SAAS,CAAC,GAAG,CAAC,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;YACnE,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,OAAO,EAAE,eAAe,CAAC,MAAM,CAAC,EAAE,CAAC;QAC9D,CAAC;KACD,CAAC;AACH,CAAC","sourcesContent":["import { type Static, Type } from \"typebox\";\nimport {\n\tcanonicalFlowJson,\n\tcompileFlow,\n\tFlowContractError,\n\tFlowIdSchema,\n\tFlowModelRefSchema,\n\tFlowReasonClassSchema,\n\tFlowRoleSchema,\n\tFlowSizeSchema,\n\tlit,\n\tparseFlowData,\n\tStrictObject,\n\ttrySnapshotFlowData,\n} from \"./flow-common.ts\";\nimport type { FlowEventV1 } from \"./flow-events.ts\";\n\nexport const FLOW_MESSAGE_MAX_LENGTH = 16_000;\n\nexport const FlowControlCommandV1Schema = Type.Union([\n\tStrictObject({ id: FlowIdSchema, type: Type.Literal(\"flow_status\"), runId: Type.Optional(FlowIdSchema) }),\n\tStrictObject({ id: FlowIdSchema, type: Type.Literal(\"flow_pause\"), runId: FlowIdSchema }),\n\tStrictObject({ id: FlowIdSchema, type: Type.Literal(\"flow_resume\"), runId: FlowIdSchema }),\n\tStrictObject({\n\t\tid: FlowIdSchema,\n\t\ttype: Type.Literal(\"flow_cancel\"),\n\t\trunId: FlowIdSchema,\n\t\treason: lit(\"user\", \"budget\", \"shutdown\", \"kill_switch\", \"superseded\"),\n\t}),\n\t// Host answer to a verify-after `repair_proposed` event (RepairGate host adapter).\n\tStrictObject({\n\t\tid: FlowIdSchema,\n\t\ttype: Type.Literal(\"flow_repair\"),\n\t\trunId: FlowIdSchema,\n\t\tround: Type.Integer({ minimum: 1, maximum: 4 }),\n\t\tdecision: lit(\"grant\", \"deny\"),\n\t\treason: Type.Optional(lit(\"user_edited\", \"busy\", \"policy\")),\n\t}),\n\tStrictObject({\n\t\tid: FlowIdSchema,\n\t\ttype: Type.Literal(\"flow_message\"),\n\t\trunId: FlowIdSchema,\n\t\tmessageId: FlowIdSchema,\n\t\ttext: Type.String({ minLength: 1, maxLength: FLOW_MESSAGE_MAX_LENGTH }),\n\t\ttarget: Type.Optional(Type.Union([StrictObject({ taskId: FlowIdSchema }), Type.Literal(\"lead\")])),\n\t}),\n]);\nexport type FlowControlCommandV1 = Static<typeof FlowControlCommandV1Schema>;\n\nconst State = lit(\"accepted\", \"applied\", \"rejected\");\n\nexport const FlowControlReceiptV1Schema = StrictObject({\n\ttype: Type.Literal(\"response\"),\n\tid: FlowIdSchema,\n\tcommand: lit(\"flow_status\", \"flow_pause\", \"flow_resume\", \"flow_cancel\", \"flow_repair\"),\n\tstate: State,\n\treason: Type.Optional(FlowReasonClassSchema),\n\tterminationConfirmed: Type.Optional(Type.Boolean()),\n});\nexport type FlowControlReceiptV1 = Static<typeof FlowControlReceiptV1Schema>;\n\n/** `messageId` is carried so message receipts can be de-duplicated by it. */\nexport const FlowMessageReceiptV1Schema = StrictObject({\n\ttype: Type.Literal(\"response\"),\n\tid: FlowIdSchema,\n\tcommand: Type.Literal(\"flow_message\"),\n\tmessageId: FlowIdSchema,\n\tstate: State,\n\treason: Type.Optional(FlowReasonClassSchema),\n\tdisposition: lit(\"live\", \"queued\", \"rejected\"),\n\tdeliveredTo: Type.Optional(StrictObject({ taskId: FlowIdSchema, role: FlowRoleSchema })),\n});\nexport type FlowMessageReceiptV1 = Static<typeof FlowMessageReceiptV1Schema>;\n\nexport const FlowStatusV1Schema = StrictObject({\n\trunId: FlowIdSchema,\n\tmode: lit(\"auto\", \"direct\"),\n\tsize: FlowSizeSchema,\n\tstate: lit(\"starting\", \"running\", \"paused\", \"cancelling\", \"settled\"),\n\tstage: lit(\"sizing\", \"planning\", \"implementing\", \"reviewing\", \"qa\", \"settling\", \"verifying_after\"),\n\tagents: Type.Array(\n\t\tStrictObject({\n\t\t\ttaskId: FlowIdSchema,\n\t\t\trole: FlowRoleSchema,\n\t\t\tmodel: FlowModelRefSchema,\n\t\t\tstate: lit(\"pending\", \"running\", \"succeeded\", \"failed\", \"cancelled\"),\n\t\t}),\n\t\t{ maxItems: 64 },\n\t),\n\tbudgetPct: Type.Number({ minimum: 0, maximum: 100 }),\n\twarnings: Type.Array(FlowReasonClassSchema, { maxItems: 16 }),\n});\nexport type FlowStatusV1 = Static<typeof FlowStatusV1Schema>;\n\n/** Pushed frames (HC -> host). */\nexport type FlowEventFrameV1 = { type: \"flow_event\"; event: FlowEventV1 };\nexport type FlowStatusFrameV1 = { type: \"flow_status\"; status: FlowStatusV1 };\n\nconst CommandValidator = compileFlow(FlowControlCommandV1Schema);\nconst ControlReceiptValidator = compileFlow(FlowControlReceiptV1Schema);\nconst MessageReceiptValidator = compileFlow(FlowMessageReceiptV1Schema);\nconst StatusValidator = compileFlow(FlowStatusV1Schema);\n\n/** Each parser validates a plain-data snapshot of `input` and returns the snapshot (never the caller's object). */\nexport function parseFlowControlCommandV1(input: unknown): FlowControlCommandV1 {\n\t// TypeBox may count maxLength in code points; the contract is UTF-16 code units (String.length), like rpc.ts.\n\treturn parseFlowData(\n\t\t\"command_invalid\",\n\t\tinput,\n\t\t(value): value is FlowControlCommandV1 =>\n\t\t\tCommandValidator.Check(value) &&\n\t\t\t(value.type !== \"flow_message\" || value.text.length <= FLOW_MESSAGE_MAX_LENGTH),\n\t);\n}\n\nfunction isControlReceipt(value: unknown): value is FlowControlReceiptV1 {\n\t// terminationConfirmed is meaningful for cancel only.\n\treturn (\n\t\tControlReceiptValidator.Check(value) &&\n\t\t(value.terminationConfirmed === undefined || value.command === \"flow_cancel\")\n\t);\n}\n\nexport function parseFlowControlReceiptV1(input: unknown): FlowControlReceiptV1 {\n\treturn parseFlowData(\"receipt_invalid\", input, isControlReceipt);\n}\n\nexport function parseFlowMessageReceiptV1(input: unknown): FlowMessageReceiptV1 {\n\treturn parseFlowData(\"receipt_invalid\", input, (value): value is FlowMessageReceiptV1 =>\n\t\tMessageReceiptValidator.Check(value),\n\t);\n}\n\nexport function parseFlowStatusV1(input: unknown): FlowStatusV1 {\n\treturn parseFlowData(\"status_invalid\", input, (value): value is FlowStatusV1 => StatusValidator.Check(value));\n}\n\nexport type FlowReceiptV1 = FlowControlReceiptV1 | FlowMessageReceiptV1;\n\nfunction withId(receipt: FlowReceiptV1, id: string): FlowReceiptV1 {\n\treturn { ...receipt, id };\n}\n\nfunction withoutId(receipt: FlowReceiptV1): string {\n\tconst { id: _id, ...rest } = receipt;\n\treturn canonicalFlowJson(rest);\n}\n\n/**\n * True when `next` is an allowed repeat of `prev`. Same command id => identical receipt. Same messageId\n * (message receipts) => identical receipt apart from `id`. Unrelated receipts return false. Conflicts throw.\n */\nexport function checkFlowReceiptIdempotency(prev: FlowReceiptV1, next: FlowReceiptV1): boolean {\n\tconst sameId = prev.id === next.id;\n\tconst sameMessage = \"messageId\" in prev && \"messageId\" in next && prev.messageId === next.messageId;\n\tif (!sameId && !sameMessage) return false;\n\tconst identical = sameId ? canonicalFlowJson(prev) === canonicalFlowJson(next) : withoutId(prev) === withoutId(next);\n\tif (!identical) throw new FlowContractError(\"receipt_conflict\");\n\treturn true;\n}\n\nexport type FlowReceiptLedger = {\n\t/**\n\t * First receipt wins. A repeat (same command id, or same messageId under a new command id) returns a copy of the\n\t * first receipt and binds the new command id to it; a conflicting repeat throws. Receipts are validated, stored\n\t * frozen, and returned as deep copies.\n\t */\n\trecord(receipt: FlowReceiptV1): { replayed: boolean; receipt: FlowReceiptV1 };\n};\n\nfunction deepFreeze<T>(value: T): T {\n\tif (typeof value === \"object\" && value !== null) {\n\t\tfor (const child of Object.values(value)) deepFreeze(child);\n\t\tObject.freeze(value);\n\t}\n\treturn value;\n}\n\nexport function createFlowReceiptLedger(): FlowReceiptLedger {\n\t// Every command id seen (including replay aliases) maps to the first receipt it was bound to.\n\tconst byCommand = new Map<string, FlowReceiptV1>();\n\tconst byMessage = new Map<string, FlowReceiptV1>();\n\treturn {\n\t\trecord(input) {\n\t\t\t// Snapshot first: the discriminant is read from the snapshot, never from the caller's object.\n\t\t\tconst snapshot = trySnapshotFlowData(\"receipt_invalid\", input);\n\t\t\tconst next =\n\t\t\t\t(snapshot as { command?: unknown } | null)?.command === \"flow_message\"\n\t\t\t\t\t? parseFlowMessageReceiptV1(snapshot)\n\t\t\t\t\t: parseFlowControlReceiptV1(snapshot);\n\t\t\tconst priors = [\n\t\t\t\tbyCommand.get(next.id),\n\t\t\t\t\"messageId\" in next ? byMessage.get(next.messageId) : undefined,\n\t\t\t].filter((prior): prior is FlowReceiptV1 => prior !== undefined);\n\t\t\tfor (const prior of priors) {\n\t\t\t\tif (canonicalFlowJson(withId(prior, next.id)) !== canonicalFlowJson(next)) {\n\t\t\t\t\tthrow new FlowContractError(\"receipt_conflict\");\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst first = priors[0];\n\t\t\tif (first !== undefined) {\n\t\t\t\tbyCommand.set(next.id, first);\n\t\t\t\treturn { replayed: true, receipt: structuredClone(first) };\n\t\t\t}\n\t\t\tconst stored = deepFreeze(next);\n\t\t\tbyCommand.set(stored.id, stored);\n\t\t\tif (\"messageId\" in stored) byMessage.set(stored.messageId, stored);\n\t\t\treturn { replayed: false, receipt: structuredClone(stored) };\n\t\t},\n\t};\n}\n"]}
|