@humain/humain-code-contracts 0.4.10 → 0.4.11

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 CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.4.11] - 2026-10-14
4
+
5
+ ### Added
6
+
7
+ - Flow failure classes and RPC Flow reason classes accept `blocked` for generic precondition stops (additive). Older strict readers reject the new value; update consumers before exchanging records that use it.
8
+
3
9
  ## [0.4.10] - 2026-10-13
4
10
 
5
11
  ### Added
@@ -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"];
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"];
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">]>;
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<"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">]>;
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">]>;
65
65
  export type FlowReasonClass = Static<typeof FlowReasonClassSchema>;
66
66
  export declare const FlowProfileRefSchema: Type.TObject<{
67
67
  readonly id: Type.TString;
@@ -1 +1 @@
1
- {"version":3,"file":"flow-common.d.ts","sourceRoot":"","sources":["../src/flow-common.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAE,KAAK,Q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,CAIlE"}
@@ -108,6 +108,7 @@ export const FLOW_FAILURE_CLASSES = [
108
108
  "internal",
109
109
  "review_verdict_missing",
110
110
  "verification_unavailable",
111
+ "blocked",
111
112
  ];
112
113
  export const FlowFailureClassSchema = Type.Union([
113
114
  Type.Literal("provider_error"),
@@ -126,6 +127,7 @@ export const FlowFailureClassSchema = Type.Union([
126
127
  Type.Literal("internal"),
127
128
  Type.Literal("review_verdict_missing"),
128
129
  Type.Literal("verification_unavailable"),
130
+ Type.Literal("blocked"),
129
131
  ]);
130
132
  export const FlowReasonClassSchema = Type.Union([FlowFailureClassSchema, Type.Literal("size_underestimated")]);
131
133
  export const FlowProfileRefSchema = StrictObject({
@@ -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,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,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I,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] 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]);\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,MAA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ion, 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"]}
@@ -34,7 +34,7 @@ export declare const FlowControlReceiptV1Schema: Type.TObject<{
34
34
  readonly id: Type.TString;
35
35
  readonly command: Type.TUnion<[Type.TLiteral<"flow_status">, Type.TLiteral<"flow_pause">, Type.TLiteral<"flow_resume">, Type.TLiteral<"flow_cancel">]>;
36
36
  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<"size_underestimated">]>>;
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">]>>;
38
38
  readonly terminationConfirmed: Type.TOptional<Type.TBoolean>;
39
39
  }>;
40
40
  export type FlowControlReceiptV1 = Static<typeof FlowControlReceiptV1Schema>;
@@ -45,7 +45,7 @@ export declare const FlowMessageReceiptV1Schema: Type.TObject<{
45
45
  readonly command: Type.TLiteral<"flow_message">;
46
46
  readonly messageId: Type.TString;
47
47
  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<"size_underestimated">]>>;
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">]>>;
49
49
  readonly disposition: Type.TUnion<[Type.TLiteral<"live">, Type.TLiteral<"queued">, Type.TLiteral<"rejected">]>;
50
50
  readonly deliveredTo: Type.TOptional<Type.TObject<{
51
51
  readonly taskId: Type.TString;
@@ -69,7 +69,7 @@ export declare const FlowStatusV1Schema: Type.TObject<{
69
69
  readonly state: Type.TUnion<[Type.TLiteral<"pending">, Type.TLiteral<"running">, Type.TLiteral<"succeeded">, Type.TLiteral<"failed">, Type.TLiteral<"cancelled">]>;
70
70
  }>>;
71
71
  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<"size_underestimated">]>>;
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">]>>;
73
73
  }>;
74
74
  export type FlowStatusV1 = Static<typeof FlowStatusV1Schema>;
75
75
  /** Pushed frames (HC -> host). */
@@ -72,7 +72,7 @@ export declare const FlowEventV1Schema: Type.TUnion<[Type.TObject<{
72
72
  readonly payload: Type.TObject<{
73
73
  readonly from: Type.TUnion<[Type.TLiteral<"small">, Type.TLiteral<"medium">, Type.TLiteral<"large">]>;
74
74
  readonly to: Type.TUnion<[Type.TLiteral<"small">, Type.TLiteral<"medium">, Type.TLiteral<"large">]>;
75
- readonly reasonClass: 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<"size_underestimated">]>;
75
+ readonly reasonClass: 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">]>;
76
76
  }>;
77
77
  }>, Type.TObject<{
78
78
  readonly schema: Type.TLiteral<"humain-flow-event">;
@@ -124,7 +124,7 @@ export declare const FlowEventV1Schema: Type.TUnion<[Type.TObject<{
124
124
  readonly provider: Type.TString;
125
125
  readonly model: Type.TString;
126
126
  }>;
127
- readonly reasonClass: 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<"size_underestimated">]>;
127
+ readonly reasonClass: 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">]>;
128
128
  }>;
129
129
  }>, Type.TObject<{
130
130
  readonly schema: Type.TLiteral<"humain-flow-event">;
@@ -145,7 +145,7 @@ export declare const FlowEventV1Schema: Type.TUnion<[Type.TObject<{
145
145
  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">]>;
146
146
  readonly attempt: Type.TInteger;
147
147
  readonly state: Type.TUnion<[Type.TLiteral<"started">, Type.TLiteral<"succeeded">, Type.TLiteral<"failed">, Type.TLiteral<"retried">, Type.TLiteral<"cancelled">]>;
148
- readonly failureClass: Type.TOptional<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">]>>;
148
+ readonly failureClass: Type.TOptional<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">]>>;
149
149
  }>;
150
150
  }>, Type.TObject<{
151
151
  readonly schema: Type.TLiteral<"humain-flow-event">;
@@ -275,7 +275,7 @@ export declare const FlowEventV1Schema: Type.TUnion<[Type.TObject<{
275
275
  readonly kind: Type.TLiteral<"run_settled">;
276
276
  readonly payload: Type.TObject<{
277
277
  readonly outcome: Type.TUnion<[Type.TLiteral<"succeeded">, Type.TLiteral<"failed">, Type.TLiteral<"cancelled">, Type.TLiteral<"budget_stopped">, Type.TLiteral<"interrupted">]>;
278
- readonly failureClass: Type.TOptional<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">]>>;
278
+ readonly failureClass: Type.TOptional<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">]>>;
279
279
  readonly settledCleanly: Type.TBoolean;
280
280
  readonly retryOffer: Type.TArray<Type.TUnion<[Type.TLiteral<"flow">, Type.TLiteral<"direct">]>>;
281
281
  readonly totals: Type.TObject<{
package/dist/rpc.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"rpc.d.ts","sourceRoot":"","sources":["../src/rpc.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAC9D,OAAO,EAAiC,KAAK,wBAAwB,EAAE,MAAM,wBAAwB,CAAC;AAMtG,eAAO,MAAM,oBAAoB,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,MAAM,gCAAgC,GAAG,mBAAmB,GAAG;IACpE,IAAI,EAAE,oBAAoB,CAAC;CAC3B,GAAG,2BAA2B,CAAC;AAChC,MAAM,MAAM,uBAAuB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,2BAA2B,CAAC;AAC5F,MAAM,MAAM,YAAY,GACrB,aAAa,GACb,gBAAgB,GAChB,mBAAmB,GACnB,iBAAiB,GACjB,kBAAkB,GAClB,mBAAmB,CAAC;AAEvB,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,cAAc,GAAG,MAAM,CAmBpE;AAgID,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,GAAG,YAAY,CAwD9D;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,YAAY,GAAG,wBAAwB,GAAG,SAAS,CAMjG"}
package/dist/rpc.js CHANGED
@@ -32,6 +32,7 @@ const FLOW_REASON_CLASSES = [
32
32
  "internal",
33
33
  "review_verdict_missing",
34
34
  "verification_unavailable",
35
+ "blocked",
35
36
  "size_underestimated",
36
37
  ];
37
38
  const FLOW_ROLE_NAMES = [
package/dist/rpc.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"rpc.js","sourceRoot":"","sources":["../src/rpc.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,6BAA6B,EAAiC,MAAM,wBAAwB,CAAC;AAEtG,MAAM,qBAAqB,GAAG,GAAG,CAAC;AAClC,MAAM,kBAAkB,GAAG,OAAO,CAAC;AACnC,MAAM,gBAAgB,GAAG,MAAM,CAAC;AAChC,MAAM,uBAAuB,GAAG,KAAK,CAAC;AACtC,MAAM,CAAC,MAAM,oBAAoB,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC;AACrD,MAAM,CAAC,MAAM,iCAAiC,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC;AAClE,MAAM,CAAC,MAAM,iCAAiC,GAAG,EAAE,GAAG,IAAI,GAAG,IA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AAED,SAAS,eAAe,CAAC,KAAc,EAAE,SAAiB;IACzD,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,MAAM,IAAI,SAAS,CAAC;AAC/D,CAAC;AAED,SAAS,WAAW,CAAC,KAA8B,EAAE,OAA0B;IAC9E,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAChC,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,IAAI,OAAO,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,IAAI,KAAK,IAAI,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC;AACjH,CAAC;AAED,SAAS,aAAa,CAAC,GAAW;IACjC,OAAO,GAAG,KAAK,IAAI,IAAI,GAAG,KAAK,OAAO,IAAI,GAAG,KAAK,MAAM,CAAC;AAC1D,CAAC","sourcesContent":["import type { FlowControlCommandV1 } from \"./flow-control.ts\";\nimport { parseSubagentProgressSnapshot, type SubagentProgressSnapshot } from \"./subagent-progress.ts\";\n\nconst MAX_IDENTIFIER_LENGTH = 256;\nconst MAX_MESSAGE_LENGTH = 100_000;\nconst MAX_ERROR_LENGTH = 10_000;\nconst MAX_SESSION_PATH_LENGTH = 4_096;\nexport const MAX_RPC_FRAME_LENGTH = 16 * 1024 * 1024;\nexport const MAX_GET_STATE_RESPONSE_UTF8_BYTES = 16 * 1024 * 1024;\nexport const MAX_GET_STATE_RESPONSE_CODE_UNITS = 16 * 1024 * 1024;\nexport const SUBAGENT_PROGRESS_FIELD = \"subagentProgress\" as const;\n\nconst FLOW_COMMAND_TYPES = [\"flow_status\", \"flow_pause\", \"flow_resume\", \"flow_cancel\", \"flow_message\"] as const;\ntype FlowCommandType = (typeof FLOW_COMMAND_TYPES)[number];\nconst FLOW_ID_PATTERN = /^[a-z0-9][a-z0-9_.:-]{0,127}$/;\nconst FLOW_MESSAGE_MAX_LENGTH = 16_000;\nconst FLOW_RECEIPT_STATES = [\"accepted\", \"applied\", \"rejected\"];\nconst FLOW_CANCEL_REASONS = [\"user\", \"budget\", \"shutdown\", \"kill_switch\"];\nconst FLOW_DISPOSITIONS = [\"live\", \"queued\", \"rejected\"];\n// Mirrors FLOW_FAILURE_CLASSES + \"size_underestimated\" and FLOW_ROLES in ./flow-common (rpc.ts must stay import-free);\n// test/rpc.test.ts keeps the lists in sync.\nconst FLOW_REASON_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\"size_underestimated\",\n];\nconst FLOW_ROLE_NAMES = [\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];\nconst INVALID_FRAME_MESSAGE = \"Invalid HUMAIN Code CLI RPC frame\";\nconst INVALID_COMMAND_MESSAGE = \"Invalid HUMAIN Code CLI RPC command\";\nconst MAX_SNAPSHOT_DEPTH = 16;\nconst MAX_SNAPSHOT_NODES = 10_000;\n// The snapshot string cap must never be below any field limit; per-field limits are enforced after the snapshot.\nconst MAX_SNAPSHOT_STRING = Math.max(\n\tMAX_IDENTIFIER_LENGTH,\n\tMAX_MESSAGE_LENGTH,\n\tMAX_ERROR_LENGTH,\n\tMAX_SESSION_PATH_LENGTH,\n\tFLOW_MESSAGE_MAX_LENGTH,\n);\n\nexport type RpcWireCommand =\n\t| { id: string; type: \"prompt\"; message: string }\n\t| { id: string; type: \"abort\" }\n\t| { id: string; type: \"get_state\" }\n\t| { type: \"set_model\"; provider: string; modelId: string }\n\t| { id: string; type: \"switch_session\"; sessionPath: string }\n\t| FlowControlCommandV1;\n\nexport type RpcReadyFrame = {\n\ttype: \"ready\";\n\tprotocolVersion: 1;\n\tsessionId: string;\n\tpid: number;\n};\n\nexport type RpcResponseFrame = {\n\ttype: \"response\";\n\tid?: string;\n\tcommand: string;\n\tsuccess: boolean;\n\terror?: string;\n\tdata?: unknown;\n};\n\n/** Flow receipt: a `response` frame without `success`. Fully validated by `parseRpcWireFrame` (no TypeBox needed). */\nexport type RpcFlowReceiptFrame = {\n\ttype: \"response\";\n\tid: string;\n\tcommand: FlowCommandType;\n\tstate: \"accepted\" | \"applied\" | \"rejected\";\n\t[key: string]: unknown;\n};\n/**\n * Pushed flow frames: `parseRpcWireFrame` validates the ENVELOPE only (exactly `{type, event}` / `{type, status}`\n * with a plain-object payload) because rpc.ts must stay TypeBox-free. Consumers MUST pass `event` to\n * `parseFlowEventV1` (./flow-events) and `status` to `parseFlowStatusV1` (./flow-control) before using it.\n */\nexport type RpcFlowEventFrame = { type: \"flow_event\"; event: Record<string, unknown> };\nexport type RpcFlowStatusFrame = { type: \"flow_status\"; status: Record<string, unknown> };\n\nexport type RpcNativeEventFrame = { type: string; [key: string]: unknown };\nexport type RpcSubagentProgressMetadata = { subagentProgress?: SubagentProgressSnapshot };\nexport type RpcToolExecutionUpdateProgressFrame = RpcNativeEventFrame & {\n\ttype: \"tool_execution_update\";\n} & RpcSubagentProgressMetadata;\nexport type RpcToolExecutionEndProgressFrame = RpcNativeEventFrame & {\n\ttype: \"tool_execution_end\";\n} & RpcSubagentProgressMetadata;\nexport type RpcGetStateProgressData = Record<string, unknown> & RpcSubagentProgressMetadata;\nexport type RpcWireFrame =\n\t| RpcReadyFrame\n\t| RpcResponseFrame\n\t| RpcFlowReceiptFrame\n\t| RpcFlowEventFrame\n\t| RpcFlowStatusFrame\n\t| RpcNativeEventFrame;\n\nexport function encodeRpcWireCommand(command: RpcWireCommand): string {\n\tconst type = readOwnDiscriminant(command, \"type\", INVALID_COMMAND_MESSAGE);\n\tif (typeof type !== \"string\" || !type.startsWith(\"flow_\")) {\n\t\t// Legacy commands keep the contracts 0.3.3 validate-then-stringify behavior.\n\t\tif (!isRpcWireCommand(command)) throw new Error(INVALID_COMMAND_MESSAGE);\n\t\tconst encoded = JSON.stringify(command);\n\t\t// A proxy can answer differently per read; the serialized type must be the classified one.\n\t\tif ((JSON.parse(encoded) as { type?: unknown }).type !== type) throw new Error(INVALID_COMMAND_MESSAGE);\n\t\treturn `${encoded}\\n`;\n\t}\n\t// Flow commands: validate and serialize one plain-data snapshot so getters/proxies cannot change between check and write.\n\tlet snapshot: unknown;\n\ttry {\n\t\tsnapshot = snapshotPlainData(command, 0, { nodes: 0 });\n\t} catch {\n\t\tthrow new Error(INVALID_COMMAND_MESSAGE);\n\t}\n\tif (!isRpcWireCommand(snapshot)) throw new Error(INVALID_COMMAND_MESSAGE);\n\treturn `${JSON.stringify(snapshot)}\\n`;\n}\n\n/**\n * Reads a discriminant once as an OWN DATA property. Inherited or accessor discriminants throw: this is an\n * intentional, security-motivated exception to contracts 0.3.3 parity (a changing/inherited discriminant could\n * select the unvalidated path). Absent returns undefined. Non-records throw.\n */\nfunction readOwnDiscriminant(target: unknown, key: string, message: string): unknown {\n\tif (!isRecord(target)) throw new Error(message);\n\tlet descriptor: PropertyDescriptor | undefined;\n\tlet inherited = false;\n\ttry {\n\t\tdescriptor = Object.getOwnPropertyDescriptor(target, key);\n\t\tinherited = descriptor === undefined && key in target;\n\t} catch {\n\t\tthrow new Error(message);\n\t}\n\tif (inherited || (descriptor !== undefined && !(\"value\" in descriptor))) throw new Error(message);\n\treturn descriptor?.value;\n}\n\n/** Same rules as `snapshotFlowData` in ./flow-common (duplicated: this entry must not import anything). */\nfunction snapshotPlainData(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 (\n\t\t\t\ttypeof key !== \"string\" ||\n\t\t\t\t(key !== \"length\" &&\n\t\t\t\t\t!(\n\t\t\t\t\t\tNumber.isInteger(Number(key)) &&\n\t\t\t\t\t\tNumber(key) >= 0 &&\n\t\t\t\t\t\tNumber(key) < length &&\n\t\t\t\t\t\tString(Number(key)) === key\n\t\t\t\t\t))\n\t\t\t) {\n\t\t\t\tthrow new Error(\"array\");\n\t\t\t}\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(snapshotPlainData(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;\n\t\tObject.defineProperty(out, key, {\n\t\t\tvalue: snapshotPlainData(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 * One-level snapshot of a frame: own enumerable string-keyed DATA properties are copied (each read once); an\n * accessor, a throwing trap or a non-record is the constant invalid-frame error. Discriminants are read only from\n * the copy. Nested values are untouched here (native events pass through; flow frames are deep-snapshotted later).\n */\nfunction copyFrameData(frame: unknown): Record<string, unknown> {\n\ttry {\n\t\tif (!isRecord(frame)) throw new Error(\"record\");\n\t\tconst out: Record<string, unknown> = {};\n\t\tfor (const key of Reflect.ownKeys(frame)) {\n\t\t\tif (typeof key !== \"string\") continue;\n\t\t\tconst descriptor = Object.getOwnPropertyDescriptor(frame, key);\n\t\t\tif (descriptor === undefined || descriptor.enumerable !== true) continue;\n\t\t\tif (!(\"value\" in descriptor)) throw new Error(\"accessor\");\n\t\t\tObject.defineProperty(out, key, {\n\t\t\t\tvalue: descriptor.value,\n\t\t\t\tenumerable: true,\n\t\t\t\twritable: true,\n\t\t\t\tconfigurable: true,\n\t\t\t});\n\t\t}\n\t\treturn out;\n\t} catch {\n\t\tthrow new Error(INVALID_FRAME_MESSAGE);\n\t}\n}\n\n/** Deep plain snapshot of an (already copied) flow frame. */\nfunction snapshotFlowFrame(frame: Record<string, unknown>): Record<string, unknown> {\n\ttry {\n\t\treturn snapshotPlainData(frame, 0, { nodes: 0 }) as Record<string, unknown>;\n\t} catch {\n\t\tthrow new Error(INVALID_FRAME_MESSAGE);\n\t}\n}\n\nfunction validateFlowFrame(\n\tframe: Record<string, unknown>,\n): RpcFlowReceiptFrame | RpcFlowEventFrame | RpcFlowStatusFrame {\n\tif (frame.type === \"flow_event\" || frame.type === \"flow_status\") {\n\t\tconst payload = frame.type === \"flow_event\" ? \"event\" : \"status\";\n\t\tif (!hasExactKeys(frame, [\"type\", payload], []) || !isRecord(frame[payload]))\n\t\t\tthrow new Error(INVALID_FRAME_MESSAGE);\n\t\treturn frame as RpcFlowEventFrame | RpcFlowStatusFrame;\n\t}\n\tif (!isFlowReceiptFrame(frame)) throw new Error(INVALID_FRAME_MESSAGE);\n\treturn frame as RpcFlowReceiptFrame;\n}\n\nexport function parseRpcWireFrame(input: unknown): RpcWireFrame {\n\tif (typeof input === \"string\" && input.length > MAX_RPC_FRAME_LENGTH) {\n\t\tthrow new Error(`HUMAIN Code CLI RPC frame exceeds the ${MAX_RPC_FRAME_LENGTH}-character limit`);\n\t}\n\tlet frame: unknown = input;\n\tif (typeof input === \"string\") {\n\t\ttry {\n\t\t\tframe = JSON.parse(input);\n\t\t} catch {\n\t\t\tthrow new Error(\"Invalid HUMAIN Code CLI RPC frame\");\n\t\t}\n\t}\n\t// ponytail: proxy frames are not defended (limit: in-process code building a proxy already controls the process).\n\tconst type = readOwnDiscriminant(frame, \"type\", INVALID_FRAME_MESSAGE);\n\tconst record = frame as Record<string, unknown>;\n\tconst command = type === \"response\" ? readOwnDiscriminant(record, \"command\", INVALID_FRAME_MESSAGE) : undefined;\n\tconst success = type === \"response\" ? readOwnDiscriminant(record, \"success\", INVALID_FRAME_MESSAGE) : undefined;\n\t// HC emits `{success:false,error}` for invalid flow_* commands and Flow handler exceptions; keep the legacy path.\n\tconst isLegacyErrorResponse = () =>\n\t\tsuccess === false && typeof Object.getOwnPropertyDescriptor(record, \"error\")?.value === \"string\";\n\tif (\n\t\ttype === \"flow_event\" ||\n\t\ttype === \"flow_status\" ||\n\t\t(type === \"response\" && typeof command === \"string\" && command.startsWith(\"flow_\") && !isLegacyErrorResponse())\n\t) {\n\t\tconst flowFrame = snapshotFlowFrame(copyFrameData(record));\n\t\treturn validateFlowFrame(flowFrame);\n\t}\n\tif (typeof type !== \"string\" || type.length === 0) {\n\t\tthrow new Error(\"Invalid HUMAIN Code CLI RPC frame\");\n\t}\n\tif (type === \"ready\") {\n\t\tif (\n\t\t\t!hasOnlyKeys(record, [\"type\", \"protocolVersion\", \"sessionId\", \"pid\"]) ||\n\t\t\trecord.protocolVersion !== 1 ||\n\t\t\t!isNonemptyBoundedString(record.sessionId, MAX_IDENTIFIER_LENGTH) ||\n\t\t\t!Number.isSafeInteger(record.pid) ||\n\t\t\t(record.pid as number) <= 0\n\t\t) {\n\t\t\tthrow new Error(\"Invalid HUMAIN Code CLI RPC frame\");\n\t\t}\n\t\treturn record as RpcReadyFrame;\n\t}\n\tif (type === \"response\") {\n\t\tif (\n\t\t\t!hasOnlyKeys(record, [\"type\", \"id\", \"command\", \"success\", \"error\", \"data\"]) ||\n\t\t\t(record.id !== undefined && !isNonemptyBoundedString(record.id, MAX_IDENTIFIER_LENGTH)) ||\n\t\t\t!isNonemptyBoundedString(command, MAX_IDENTIFIER_LENGTH) ||\n\t\t\ttypeof success !== \"boolean\" ||\n\t\t\t(record.error !== undefined && !isBoundedString(record.error, MAX_ERROR_LENGTH))\n\t\t) {\n\t\t\tthrow new Error(\"Invalid HUMAIN Code CLI RPC frame\");\n\t\t}\n\t\treturn record as RpcResponseFrame;\n\t}\n\treturn frame as RpcNativeEventFrame;\n}\n\n/**\n * Reads optional subagent progress metadata. Absent field means unsupported/unavailable\n * (returns undefined); a present field is strictly parsed and throws when invalid.\n * Update/end piggyback envelopes must carry exactly one run (0 or 2+ throws); get_state accepts 0..64 runs.\n * No other frame fields are inspected or validated.\n */\nexport function readRpcSubagentProgress(frame: RpcWireFrame): SubagentProgressSnapshot | undefined {\n\ttry {\n\t\treturn extractRpcSubagentProgress(frame);\n\t} catch {\n\t\tthrow new Error(INVALID_PROGRESS_MESSAGE);\n\t}\n}\n\nconst INVALID_PROGRESS_MESSAGE = \"Invalid subagent progress snapshot\";\n\n/** Own data property lookup: never invokes getters; `inherited` is true when only a non-own property exists. */\nfunction readOwnData(target: object, key: string): { found: boolean; value?: unknown; inherited: boolean } {\n\tconst descriptor = Object.getOwnPropertyDescriptor(target, key);\n\tif (descriptor === undefined) return { found: false, inherited: key in target };\n\tif (!(\"value\" in descriptor)) throw new Error(INVALID_PROGRESS_MESSAGE);\n\treturn { found: true, value: descriptor.value, inherited: false };\n}\n\nfunction extractRpcSubagentProgress(frame: RpcWireFrame): SubagentProgressSnapshot | undefined {\n\tif (!isRecord(frame)) return undefined;\n\tconst type = readOwnData(frame, \"type\").value;\n\tlet carrier: unknown;\n\tlet singleRun = false;\n\tif (type === \"tool_execution_update\" || type === \"tool_execution_end\") {\n\t\tcarrier = frame;\n\t\tsingleRun = true;\n\t} else if (type === \"response\") {\n\t\tif (readOwnData(frame, \"command\").value !== \"get_state\" || readOwnData(frame, \"success\").value !== true) {\n\t\t\treturn undefined;\n\t\t}\n\t\tcarrier = readOwnData(frame, \"data\").value;\n\t} else {\n\t\treturn undefined;\n\t}\n\tif (!isRecord(carrier)) return undefined;\n\tconst field = readOwnData(carrier, SUBAGENT_PROGRESS_FIELD);\n\tif (field.inherited) throw new Error(INVALID_PROGRESS_MESSAGE);\n\tif (!field.found) return undefined;\n\tconst snapshot = parseSubagentProgressSnapshot(field.value);\n\tif (singleRun && snapshot.runs.length !== 1) throw new Error(INVALID_PROGRESS_MESSAGE);\n\treturn snapshot;\n}\n\nfunction isRpcWireCommand(value: unknown): value is RpcWireCommand {\n\tif (!isRecord(value)) return false;\n\tswitch (value.type) {\n\t\tcase \"prompt\":\n\t\t\treturn (\n\t\t\t\thasOnlyKeys(value, [\"id\", \"type\", \"message\"]) &&\n\t\t\t\tisNonemptyBoundedString(value.id, MAX_IDENTIFIER_LENGTH) &&\n\t\t\t\tisNonemptyBoundedString(value.message, MAX_MESSAGE_LENGTH)\n\t\t\t);\n\t\tcase \"abort\":\n\t\tcase \"get_state\":\n\t\t\treturn hasOnlyKeys(value, [\"id\", \"type\"]) && isNonemptyBoundedString(value.id, MAX_IDENTIFIER_LENGTH);\n\t\tcase \"set_model\":\n\t\t\treturn (\n\t\t\t\thasOnlyKeys(value, [\"type\", \"provider\", \"modelId\"]) &&\n\t\t\t\tisNonemptyBoundedString(value.provider, MAX_IDENTIFIER_LENGTH) &&\n\t\t\t\tisNonemptyBoundedString(value.modelId, MAX_IDENTIFIER_LENGTH)\n\t\t\t);\n\t\tcase \"switch_session\":\n\t\t\treturn (\n\t\t\t\thasOnlyKeys(value, [\"id\", \"type\", \"sessionPath\"]) &&\n\t\t\t\tisNonemptyBoundedString(value.id, MAX_IDENTIFIER_LENGTH) &&\n\t\t\t\tisNonemptyBoundedString(value.sessionPath, MAX_SESSION_PATH_LENGTH)\n\t\t\t);\n\t\tcase \"flow_status\":\n\t\t\treturn (\n\t\t\t\thasExactKeys(value, [\"id\", \"type\"], [\"runId\"]) &&\n\t\t\t\tisFlowId(value.id) &&\n\t\t\t\t(!(\"runId\" in value) || isFlowId(value.runId))\n\t\t\t);\n\t\tcase \"flow_pause\":\n\t\tcase \"flow_resume\":\n\t\t\treturn hasExactKeys(value, [\"id\", \"type\", \"runId\"], []) && isFlowId(value.id) && isFlowId(value.runId);\n\t\tcase \"flow_cancel\":\n\t\t\treturn (\n\t\t\t\thasExactKeys(value, [\"id\", \"type\", \"runId\", \"reason\"], []) &&\n\t\t\t\tisFlowId(value.id) &&\n\t\t\t\tisFlowId(value.runId) &&\n\t\t\t\tFLOW_CANCEL_REASONS.includes(value.reason as string)\n\t\t\t);\n\t\tcase \"flow_message\":\n\t\t\treturn (\n\t\t\t\thasExactKeys(value, [\"id\", \"type\", \"runId\", \"messageId\", \"text\"], [\"target\"]) &&\n\t\t\t\tisFlowId(value.id) &&\n\t\t\t\tisFlowId(value.runId) &&\n\t\t\t\tisFlowId(value.messageId) &&\n\t\t\t\tisNonemptyBoundedString(value.text, FLOW_MESSAGE_MAX_LENGTH) &&\n\t\t\t\t(value.target === undefined ||\n\t\t\t\t\tvalue.target === \"lead\" ||\n\t\t\t\t\t(isRecord(value.target) && hasExactKeys(value.target, [\"taskId\"], []) && isFlowId(value.target.taskId)))\n\t\t\t);\n\t\tdefault:\n\t\t\treturn false;\n\t}\n}\n\nfunction isFlowCommandType(value: unknown): value is FlowCommandType {\n\treturn FLOW_COMMAND_TYPES.includes(value as FlowCommandType);\n}\n\nfunction isFlowId(value: unknown): value is string {\n\treturn typeof value === \"string\" && FLOW_ID_PATTERN.test(value);\n}\n\nfunction hasExactKeys(\n\tvalue: Record<string, unknown>,\n\trequired: readonly string[],\n\toptional: readonly string[],\n): boolean {\n\treturn (\n\t\tObject.keys(value).every((key) => required.includes(key) || optional.includes(key)) &&\n\t\trequired.every((key) => key in value)\n\t);\n}\n\n/** Full receipt validation (state, reason, terminationConfirmed only for cancel, disposition/deliveredTo only for messages). */\nfunction isFlowReceiptFrame(frame: Record<string, unknown>): boolean {\n\tconst message = frame.command === \"flow_message\";\n\tconst cancel = frame.command === \"flow_cancel\";\n\tif (\n\t\t!hasExactKeys(\n\t\t\tframe,\n\t\t\t[\"type\", \"id\", \"command\", \"state\", ...(message ? [\"messageId\", \"disposition\"] : [])],\n\t\t\t[\"reason\", ...(message ? [\"deliveredTo\"] : cancel ? [\"terminationConfirmed\"] : [])],\n\t\t) ||\n\t\tframe.type !== \"response\" ||\n\t\t!isFlowCommandType(frame.command) ||\n\t\t!isFlowId(frame.id) ||\n\t\t!FLOW_RECEIPT_STATES.includes(frame.state as string) ||\n\t\t(frame.reason !== undefined && !FLOW_REASON_CLASSES.includes(frame.reason as string))\n\t) {\n\t\treturn false;\n\t}\n\tif (cancel) return frame.terminationConfirmed === undefined || typeof frame.terminationConfirmed === \"boolean\";\n\tif (!message) return true;\n\tconst delivered = frame.deliveredTo;\n\treturn (\n\t\tisFlowId(frame.messageId) &&\n\t\tFLOW_DISPOSITIONS.includes(frame.disposition as string) &&\n\t\t(delivered === undefined ||\n\t\t\t(isRecord(delivered) &&\n\t\t\t\thasExactKeys(delivered, [\"taskId\", \"role\"], []) &&\n\t\t\t\tisFlowId(delivered.taskId) &&\n\t\t\t\tFLOW_ROLE_NAMES.includes(delivered.role as string)))\n\t);\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction isNonemptyBoundedString(value: unknown, maxLength: number): value is string {\n\treturn typeof value === \"string\" && value.length > 0 && value.length <= maxLength;\n}\n\nfunction isBoundedString(value: unknown, maxLength: number): value is string {\n\treturn typeof value === \"string\" && value.length <= maxLength;\n}\n\nfunction hasOnlyKeys(value: Record<string, unknown>, allowed: readonly string[]): boolean {\n\tconst keys = Object.keys(value);\n\treturn keys.every((key) => allowed.includes(key)) && allowed.every((key) => key in value || isOptionalKey(key));\n}\n\nfunction isOptionalKey(key: string): boolean {\n\treturn key === \"id\" || key === \"error\" || key === \"data\";\n}\n"]}
1
+ {"version":3,"file":"rpc.js","sourceRoot":"","sources":["../src/rpc.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,6BAA6B,EAAiC,MAAM,wBAAwB,CAAC;AAEtG,MAAM,qBAAqB,GAAG,GAAG,CAAC;AAClC,MAAM,kBAAkB,GAAG,OAAO,CAAC;AACnC,MAAM,gBAAgB,GAAG,MAAM,CAAC;AAChC,MAAM,uBAAuB,GAAG,KAAK,CAAC;AACtC,MAAM,CAAC,MAAM,oBAAoB,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC;AACrD,MAAM,CAAC,MAAM,iCAAiC,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC;AAClE,MAAM,CAAC,MAAM,iCAAiC,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC;AAClE,MAAM,CAAC,MAAM,uBAAuB,GAAG,kBAA2B,CAAC;AAEnE,MAAM,kBAAkB,GAAG,CAAC,aAAa,EAAE,YAAY,EAAE,aAAa,EAAE,aAAa,EAAE,cAAc,CAAU,CAAC;AAEhH,MAAM,eAAe,GAAG,+BAA+B,CAAC;AACxD,MAAM,uBAAuB,GAAG,MAAM,CAAC;AACvC,MAAM,mBAAmB,GAAG,CAAC,UAAU,EAAE,SAAS,EAAE,UAAU,CAAC,CAAC;AAChE,MAAM,mBAAmB,GAAG,CAAC,MAAM,EAAE,QAAQ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,IAAI,OAAO,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,IAAI,KAAK,IAAI,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC;AACjH,CAAC;AAED,SAAS,aAAa,CAAC,GAAW;IACjC,OAAO,GAAG,KAAK,IAAI,IAAI,GAAG,KAAK,OAAO,IAAI,GAAG,KAAK,MAAM,CAAC;AAC1D,CAAC","sourcesContent":["import type { FlowControlCommandV1 } from \"./flow-control.ts\";\nimport { parseSubagentProgressSnapshot, type SubagentProgressSnapshot } from \"./subagent-progress.ts\";\n\nconst MAX_IDENTIFIER_LENGTH = 256;\nconst MAX_MESSAGE_LENGTH = 100_000;\nconst MAX_ERROR_LENGTH = 10_000;\nconst MAX_SESSION_PATH_LENGTH = 4_096;\nexport const MAX_RPC_FRAME_LENGTH = 16 * 1024 * 1024;\nexport const MAX_GET_STATE_RESPONSE_UTF8_BYTES = 16 * 1024 * 1024;\nexport const MAX_GET_STATE_RESPONSE_CODE_UNITS = 16 * 1024 * 1024;\nexport const SUBAGENT_PROGRESS_FIELD = \"subagentProgress\" as const;\n\nconst FLOW_COMMAND_TYPES = [\"flow_status\", \"flow_pause\", \"flow_resume\", \"flow_cancel\", \"flow_message\"] as const;\ntype FlowCommandType = (typeof FLOW_COMMAND_TYPES)[number];\nconst FLOW_ID_PATTERN = /^[a-z0-9][a-z0-9_.:-]{0,127}$/;\nconst FLOW_MESSAGE_MAX_LENGTH = 16_000;\nconst FLOW_RECEIPT_STATES = [\"accepted\", \"applied\", \"rejected\"];\nconst FLOW_CANCEL_REASONS = [\"user\", \"budget\", \"shutdown\", \"kill_switch\"];\nconst FLOW_DISPOSITIONS = [\"live\", \"queued\", \"rejected\"];\n// Mirrors FLOW_FAILURE_CLASSES + \"size_underestimated\" and FLOW_ROLES in ./flow-common (rpc.ts must stay import-free);\n// test/rpc.test.ts keeps the lists in sync.\nconst FLOW_REASON_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\"size_underestimated\",\n];\nconst FLOW_ROLE_NAMES = [\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];\nconst INVALID_FRAME_MESSAGE = \"Invalid HUMAIN Code CLI RPC frame\";\nconst INVALID_COMMAND_MESSAGE = \"Invalid HUMAIN Code CLI RPC command\";\nconst MAX_SNAPSHOT_DEPTH = 16;\nconst MAX_SNAPSHOT_NODES = 10_000;\n// The snapshot string cap must never be below any field limit; per-field limits are enforced after the snapshot.\nconst MAX_SNAPSHOT_STRING = Math.max(\n\tMAX_IDENTIFIER_LENGTH,\n\tMAX_MESSAGE_LENGTH,\n\tMAX_ERROR_LENGTH,\n\tMAX_SESSION_PATH_LENGTH,\n\tFLOW_MESSAGE_MAX_LENGTH,\n);\n\nexport type RpcWireCommand =\n\t| { id: string; type: \"prompt\"; message: string }\n\t| { id: string; type: \"abort\" }\n\t| { id: string; type: \"get_state\" }\n\t| { type: \"set_model\"; provider: string; modelId: string }\n\t| { id: string; type: \"switch_session\"; sessionPath: string }\n\t| FlowControlCommandV1;\n\nexport type RpcReadyFrame = {\n\ttype: \"ready\";\n\tprotocolVersion: 1;\n\tsessionId: string;\n\tpid: number;\n};\n\nexport type RpcResponseFrame = {\n\ttype: \"response\";\n\tid?: string;\n\tcommand: string;\n\tsuccess: boolean;\n\terror?: string;\n\tdata?: unknown;\n};\n\n/** Flow receipt: a `response` frame without `success`. Fully validated by `parseRpcWireFrame` (no TypeBox needed). */\nexport type RpcFlowReceiptFrame = {\n\ttype: \"response\";\n\tid: string;\n\tcommand: FlowCommandType;\n\tstate: \"accepted\" | \"applied\" | \"rejected\";\n\t[key: string]: unknown;\n};\n/**\n * Pushed flow frames: `parseRpcWireFrame` validates the ENVELOPE only (exactly `{type, event}` / `{type, status}`\n * with a plain-object payload) because rpc.ts must stay TypeBox-free. Consumers MUST pass `event` to\n * `parseFlowEventV1` (./flow-events) and `status` to `parseFlowStatusV1` (./flow-control) before using it.\n */\nexport type RpcFlowEventFrame = { type: \"flow_event\"; event: Record<string, unknown> };\nexport type RpcFlowStatusFrame = { type: \"flow_status\"; status: Record<string, unknown> };\n\nexport type RpcNativeEventFrame = { type: string; [key: string]: unknown };\nexport type RpcSubagentProgressMetadata = { subagentProgress?: SubagentProgressSnapshot };\nexport type RpcToolExecutionUpdateProgressFrame = RpcNativeEventFrame & {\n\ttype: \"tool_execution_update\";\n} & RpcSubagentProgressMetadata;\nexport type RpcToolExecutionEndProgressFrame = RpcNativeEventFrame & {\n\ttype: \"tool_execution_end\";\n} & RpcSubagentProgressMetadata;\nexport type RpcGetStateProgressData = Record<string, unknown> & RpcSubagentProgressMetadata;\nexport type RpcWireFrame =\n\t| RpcReadyFrame\n\t| RpcResponseFrame\n\t| RpcFlowReceiptFrame\n\t| RpcFlowEventFrame\n\t| RpcFlowStatusFrame\n\t| RpcNativeEventFrame;\n\nexport function encodeRpcWireCommand(command: RpcWireCommand): string {\n\tconst type = readOwnDiscriminant(command, \"type\", INVALID_COMMAND_MESSAGE);\n\tif (typeof type !== \"string\" || !type.startsWith(\"flow_\")) {\n\t\t// Legacy commands keep the contracts 0.3.3 validate-then-stringify behavior.\n\t\tif (!isRpcWireCommand(command)) throw new Error(INVALID_COMMAND_MESSAGE);\n\t\tconst encoded = JSON.stringify(command);\n\t\t// A proxy can answer differently per read; the serialized type must be the classified one.\n\t\tif ((JSON.parse(encoded) as { type?: unknown }).type !== type) throw new Error(INVALID_COMMAND_MESSAGE);\n\t\treturn `${encoded}\\n`;\n\t}\n\t// Flow commands: validate and serialize one plain-data snapshot so getters/proxies cannot change between check and write.\n\tlet snapshot: unknown;\n\ttry {\n\t\tsnapshot = snapshotPlainData(command, 0, { nodes: 0 });\n\t} catch {\n\t\tthrow new Error(INVALID_COMMAND_MESSAGE);\n\t}\n\tif (!isRpcWireCommand(snapshot)) throw new Error(INVALID_COMMAND_MESSAGE);\n\treturn `${JSON.stringify(snapshot)}\\n`;\n}\n\n/**\n * Reads a discriminant once as an OWN DATA property. Inherited or accessor discriminants throw: this is an\n * intentional, security-motivated exception to contracts 0.3.3 parity (a changing/inherited discriminant could\n * select the unvalidated path). Absent returns undefined. Non-records throw.\n */\nfunction readOwnDiscriminant(target: unknown, key: string, message: string): unknown {\n\tif (!isRecord(target)) throw new Error(message);\n\tlet descriptor: PropertyDescriptor | undefined;\n\tlet inherited = false;\n\ttry {\n\t\tdescriptor = Object.getOwnPropertyDescriptor(target, key);\n\t\tinherited = descriptor === undefined && key in target;\n\t} catch {\n\t\tthrow new Error(message);\n\t}\n\tif (inherited || (descriptor !== undefined && !(\"value\" in descriptor))) throw new Error(message);\n\treturn descriptor?.value;\n}\n\n/** Same rules as `snapshotFlowData` in ./flow-common (duplicated: this entry must not import anything). */\nfunction snapshotPlainData(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 (\n\t\t\t\ttypeof key !== \"string\" ||\n\t\t\t\t(key !== \"length\" &&\n\t\t\t\t\t!(\n\t\t\t\t\t\tNumber.isInteger(Number(key)) &&\n\t\t\t\t\t\tNumber(key) >= 0 &&\n\t\t\t\t\t\tNumber(key) < length &&\n\t\t\t\t\t\tString(Number(key)) === key\n\t\t\t\t\t))\n\t\t\t) {\n\t\t\t\tthrow new Error(\"array\");\n\t\t\t}\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(snapshotPlainData(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;\n\t\tObject.defineProperty(out, key, {\n\t\t\tvalue: snapshotPlainData(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 * One-level snapshot of a frame: own enumerable string-keyed DATA properties are copied (each read once); an\n * accessor, a throwing trap or a non-record is the constant invalid-frame error. Discriminants are read only from\n * the copy. Nested values are untouched here (native events pass through; flow frames are deep-snapshotted later).\n */\nfunction copyFrameData(frame: unknown): Record<string, unknown> {\n\ttry {\n\t\tif (!isRecord(frame)) throw new Error(\"record\");\n\t\tconst out: Record<string, unknown> = {};\n\t\tfor (const key of Reflect.ownKeys(frame)) {\n\t\t\tif (typeof key !== \"string\") continue;\n\t\t\tconst descriptor = Object.getOwnPropertyDescriptor(frame, key);\n\t\t\tif (descriptor === undefined || descriptor.enumerable !== true) continue;\n\t\t\tif (!(\"value\" in descriptor)) throw new Error(\"accessor\");\n\t\t\tObject.defineProperty(out, key, {\n\t\t\t\tvalue: descriptor.value,\n\t\t\t\tenumerable: true,\n\t\t\t\twritable: true,\n\t\t\t\tconfigurable: true,\n\t\t\t});\n\t\t}\n\t\treturn out;\n\t} catch {\n\t\tthrow new Error(INVALID_FRAME_MESSAGE);\n\t}\n}\n\n/** Deep plain snapshot of an (already copied) flow frame. */\nfunction snapshotFlowFrame(frame: Record<string, unknown>): Record<string, unknown> {\n\ttry {\n\t\treturn snapshotPlainData(frame, 0, { nodes: 0 }) as Record<string, unknown>;\n\t} catch {\n\t\tthrow new Error(INVALID_FRAME_MESSAGE);\n\t}\n}\n\nfunction validateFlowFrame(\n\tframe: Record<string, unknown>,\n): RpcFlowReceiptFrame | RpcFlowEventFrame | RpcFlowStatusFrame {\n\tif (frame.type === \"flow_event\" || frame.type === \"flow_status\") {\n\t\tconst payload = frame.type === \"flow_event\" ? \"event\" : \"status\";\n\t\tif (!hasExactKeys(frame, [\"type\", payload], []) || !isRecord(frame[payload]))\n\t\t\tthrow new Error(INVALID_FRAME_MESSAGE);\n\t\treturn frame as RpcFlowEventFrame | RpcFlowStatusFrame;\n\t}\n\tif (!isFlowReceiptFrame(frame)) throw new Error(INVALID_FRAME_MESSAGE);\n\treturn frame as RpcFlowReceiptFrame;\n}\n\nexport function parseRpcWireFrame(input: unknown): RpcWireFrame {\n\tif (typeof input === \"string\" && input.length > MAX_RPC_FRAME_LENGTH) {\n\t\tthrow new Error(`HUMAIN Code CLI RPC frame exceeds the ${MAX_RPC_FRAME_LENGTH}-character limit`);\n\t}\n\tlet frame: unknown = input;\n\tif (typeof input === \"string\") {\n\t\ttry {\n\t\t\tframe = JSON.parse(input);\n\t\t} catch {\n\t\t\tthrow new Error(\"Invalid HUMAIN Code CLI RPC frame\");\n\t\t}\n\t}\n\t// ponytail: proxy frames are not defended (limit: in-process code building a proxy already controls the process).\n\tconst type = readOwnDiscriminant(frame, \"type\", INVALID_FRAME_MESSAGE);\n\tconst record = frame as Record<string, unknown>;\n\tconst command = type === \"response\" ? readOwnDiscriminant(record, \"command\", INVALID_FRAME_MESSAGE) : undefined;\n\tconst success = type === \"response\" ? readOwnDiscriminant(record, \"success\", INVALID_FRAME_MESSAGE) : undefined;\n\t// HC emits `{success:false,error}` for invalid flow_* commands and Flow handler exceptions; keep the legacy path.\n\tconst isLegacyErrorResponse = () =>\n\t\tsuccess === false && typeof Object.getOwnPropertyDescriptor(record, \"error\")?.value === \"string\";\n\tif (\n\t\ttype === \"flow_event\" ||\n\t\ttype === \"flow_status\" ||\n\t\t(type === \"response\" && typeof command === \"string\" && command.startsWith(\"flow_\") && !isLegacyErrorResponse())\n\t) {\n\t\tconst flowFrame = snapshotFlowFrame(copyFrameData(record));\n\t\treturn validateFlowFrame(flowFrame);\n\t}\n\tif (typeof type !== \"string\" || type.length === 0) {\n\t\tthrow new Error(\"Invalid HUMAIN Code CLI RPC frame\");\n\t}\n\tif (type === \"ready\") {\n\t\tif (\n\t\t\t!hasOnlyKeys(record, [\"type\", \"protocolVersion\", \"sessionId\", \"pid\"]) ||\n\t\t\trecord.protocolVersion !== 1 ||\n\t\t\t!isNonemptyBoundedString(record.sessionId, MAX_IDENTIFIER_LENGTH) ||\n\t\t\t!Number.isSafeInteger(record.pid) ||\n\t\t\t(record.pid as number) <= 0\n\t\t) {\n\t\t\tthrow new Error(\"Invalid HUMAIN Code CLI RPC frame\");\n\t\t}\n\t\treturn record as RpcReadyFrame;\n\t}\n\tif (type === \"response\") {\n\t\tif (\n\t\t\t!hasOnlyKeys(record, [\"type\", \"id\", \"command\", \"success\", \"error\", \"data\"]) ||\n\t\t\t(record.id !== undefined && !isNonemptyBoundedString(record.id, MAX_IDENTIFIER_LENGTH)) ||\n\t\t\t!isNonemptyBoundedString(command, MAX_IDENTIFIER_LENGTH) ||\n\t\t\ttypeof success !== \"boolean\" ||\n\t\t\t(record.error !== undefined && !isBoundedString(record.error, MAX_ERROR_LENGTH))\n\t\t) {\n\t\t\tthrow new Error(\"Invalid HUMAIN Code CLI RPC frame\");\n\t\t}\n\t\treturn record as RpcResponseFrame;\n\t}\n\treturn frame as RpcNativeEventFrame;\n}\n\n/**\n * Reads optional subagent progress metadata. Absent field means unsupported/unavailable\n * (returns undefined); a present field is strictly parsed and throws when invalid.\n * Update/end piggyback envelopes must carry exactly one run (0 or 2+ throws); get_state accepts 0..64 runs.\n * No other frame fields are inspected or validated.\n */\nexport function readRpcSubagentProgress(frame: RpcWireFrame): SubagentProgressSnapshot | undefined {\n\ttry {\n\t\treturn extractRpcSubagentProgress(frame);\n\t} catch {\n\t\tthrow new Error(INVALID_PROGRESS_MESSAGE);\n\t}\n}\n\nconst INVALID_PROGRESS_MESSAGE = \"Invalid subagent progress snapshot\";\n\n/** Own data property lookup: never invokes getters; `inherited` is true when only a non-own property exists. */\nfunction readOwnData(target: object, key: string): { found: boolean; value?: unknown; inherited: boolean } {\n\tconst descriptor = Object.getOwnPropertyDescriptor(target, key);\n\tif (descriptor === undefined) return { found: false, inherited: key in target };\n\tif (!(\"value\" in descriptor)) throw new Error(INVALID_PROGRESS_MESSAGE);\n\treturn { found: true, value: descriptor.value, inherited: false };\n}\n\nfunction extractRpcSubagentProgress(frame: RpcWireFrame): SubagentProgressSnapshot | undefined {\n\tif (!isRecord(frame)) return undefined;\n\tconst type = readOwnData(frame, \"type\").value;\n\tlet carrier: unknown;\n\tlet singleRun = false;\n\tif (type === \"tool_execution_update\" || type === \"tool_execution_end\") {\n\t\tcarrier = frame;\n\t\tsingleRun = true;\n\t} else if (type === \"response\") {\n\t\tif (readOwnData(frame, \"command\").value !== \"get_state\" || readOwnData(frame, \"success\").value !== true) {\n\t\t\treturn undefined;\n\t\t}\n\t\tcarrier = readOwnData(frame, \"data\").value;\n\t} else {\n\t\treturn undefined;\n\t}\n\tif (!isRecord(carrier)) return undefined;\n\tconst field = readOwnData(carrier, SUBAGENT_PROGRESS_FIELD);\n\tif (field.inherited) throw new Error(INVALID_PROGRESS_MESSAGE);\n\tif (!field.found) return undefined;\n\tconst snapshot = parseSubagentProgressSnapshot(field.value);\n\tif (singleRun && snapshot.runs.length !== 1) throw new Error(INVALID_PROGRESS_MESSAGE);\n\treturn snapshot;\n}\n\nfunction isRpcWireCommand(value: unknown): value is RpcWireCommand {\n\tif (!isRecord(value)) return false;\n\tswitch (value.type) {\n\t\tcase \"prompt\":\n\t\t\treturn (\n\t\t\t\thasOnlyKeys(value, [\"id\", \"type\", \"message\"]) &&\n\t\t\t\tisNonemptyBoundedString(value.id, MAX_IDENTIFIER_LENGTH) &&\n\t\t\t\tisNonemptyBoundedString(value.message, MAX_MESSAGE_LENGTH)\n\t\t\t);\n\t\tcase \"abort\":\n\t\tcase \"get_state\":\n\t\t\treturn hasOnlyKeys(value, [\"id\", \"type\"]) && isNonemptyBoundedString(value.id, MAX_IDENTIFIER_LENGTH);\n\t\tcase \"set_model\":\n\t\t\treturn (\n\t\t\t\thasOnlyKeys(value, [\"type\", \"provider\", \"modelId\"]) &&\n\t\t\t\tisNonemptyBoundedString(value.provider, MAX_IDENTIFIER_LENGTH) &&\n\t\t\t\tisNonemptyBoundedString(value.modelId, MAX_IDENTIFIER_LENGTH)\n\t\t\t);\n\t\tcase \"switch_session\":\n\t\t\treturn (\n\t\t\t\thasOnlyKeys(value, [\"id\", \"type\", \"sessionPath\"]) &&\n\t\t\t\tisNonemptyBoundedString(value.id, MAX_IDENTIFIER_LENGTH) &&\n\t\t\t\tisNonemptyBoundedString(value.sessionPath, MAX_SESSION_PATH_LENGTH)\n\t\t\t);\n\t\tcase \"flow_status\":\n\t\t\treturn (\n\t\t\t\thasExactKeys(value, [\"id\", \"type\"], [\"runId\"]) &&\n\t\t\t\tisFlowId(value.id) &&\n\t\t\t\t(!(\"runId\" in value) || isFlowId(value.runId))\n\t\t\t);\n\t\tcase \"flow_pause\":\n\t\tcase \"flow_resume\":\n\t\t\treturn hasExactKeys(value, [\"id\", \"type\", \"runId\"], []) && isFlowId(value.id) && isFlowId(value.runId);\n\t\tcase \"flow_cancel\":\n\t\t\treturn (\n\t\t\t\thasExactKeys(value, [\"id\", \"type\", \"runId\", \"reason\"], []) &&\n\t\t\t\tisFlowId(value.id) &&\n\t\t\t\tisFlowId(value.runId) &&\n\t\t\t\tFLOW_CANCEL_REASONS.includes(value.reason as string)\n\t\t\t);\n\t\tcase \"flow_message\":\n\t\t\treturn (\n\t\t\t\thasExactKeys(value, [\"id\", \"type\", \"runId\", \"messageId\", \"text\"], [\"target\"]) &&\n\t\t\t\tisFlowId(value.id) &&\n\t\t\t\tisFlowId(value.runId) &&\n\t\t\t\tisFlowId(value.messageId) &&\n\t\t\t\tisNonemptyBoundedString(value.text, FLOW_MESSAGE_MAX_LENGTH) &&\n\t\t\t\t(value.target === undefined ||\n\t\t\t\t\tvalue.target === \"lead\" ||\n\t\t\t\t\t(isRecord(value.target) && hasExactKeys(value.target, [\"taskId\"], []) && isFlowId(value.target.taskId)))\n\t\t\t);\n\t\tdefault:\n\t\t\treturn false;\n\t}\n}\n\nfunction isFlowCommandType(value: unknown): value is FlowCommandType {\n\treturn FLOW_COMMAND_TYPES.includes(value as FlowCommandType);\n}\n\nfunction isFlowId(value: unknown): value is string {\n\treturn typeof value === \"string\" && FLOW_ID_PATTERN.test(value);\n}\n\nfunction hasExactKeys(\n\tvalue: Record<string, unknown>,\n\trequired: readonly string[],\n\toptional: readonly string[],\n): boolean {\n\treturn (\n\t\tObject.keys(value).every((key) => required.includes(key) || optional.includes(key)) &&\n\t\trequired.every((key) => key in value)\n\t);\n}\n\n/** Full receipt validation (state, reason, terminationConfirmed only for cancel, disposition/deliveredTo only for messages). */\nfunction isFlowReceiptFrame(frame: Record<string, unknown>): boolean {\n\tconst message = frame.command === \"flow_message\";\n\tconst cancel = frame.command === \"flow_cancel\";\n\tif (\n\t\t!hasExactKeys(\n\t\t\tframe,\n\t\t\t[\"type\", \"id\", \"command\", \"state\", ...(message ? [\"messageId\", \"disposition\"] : [])],\n\t\t\t[\"reason\", ...(message ? [\"deliveredTo\"] : cancel ? [\"terminationConfirmed\"] : [])],\n\t\t) ||\n\t\tframe.type !== \"response\" ||\n\t\t!isFlowCommandType(frame.command) ||\n\t\t!isFlowId(frame.id) ||\n\t\t!FLOW_RECEIPT_STATES.includes(frame.state as string) ||\n\t\t(frame.reason !== undefined && !FLOW_REASON_CLASSES.includes(frame.reason as string))\n\t) {\n\t\treturn false;\n\t}\n\tif (cancel) return frame.terminationConfirmed === undefined || typeof frame.terminationConfirmed === \"boolean\";\n\tif (!message) return true;\n\tconst delivered = frame.deliveredTo;\n\treturn (\n\t\tisFlowId(frame.messageId) &&\n\t\tFLOW_DISPOSITIONS.includes(frame.disposition as string) &&\n\t\t(delivered === undefined ||\n\t\t\t(isRecord(delivered) &&\n\t\t\t\thasExactKeys(delivered, [\"taskId\", \"role\"], []) &&\n\t\t\t\tisFlowId(delivered.taskId) &&\n\t\t\t\tFLOW_ROLE_NAMES.includes(delivered.role as string)))\n\t);\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction isNonemptyBoundedString(value: unknown, maxLength: number): value is string {\n\treturn typeof value === \"string\" && value.length > 0 && value.length <= maxLength;\n}\n\nfunction isBoundedString(value: unknown, maxLength: number): value is string {\n\treturn typeof value === \"string\" && value.length <= maxLength;\n}\n\nfunction hasOnlyKeys(value: Record<string, unknown>, allowed: readonly string[]): boolean {\n\tconst keys = Object.keys(value);\n\treturn keys.every((key) => allowed.includes(key)) && allowed.every((key) => key in value || isOptionalKey(key));\n}\n\nfunction isOptionalKey(key: string): boolean {\n\treturn key === \"id\" || key === \"error\" || key === \"data\";\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@humain/humain-code-contracts",
3
- "version": "0.4.10",
3
+ "version": "0.4.11",
4
4
  "private": false,
5
5
  "description": "Runtime-neutral HUMAIN Code CLI execution and RPC wire contracts",
6
6
  "type": "module",