@humain/humain-code-contracts 0.4.8 → 0.4.10

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,21 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.4.10] - 2026-10-13
4
+
5
+ ### Added
6
+
7
+ - Added optional `FlowProfileV1.modelSelection` for Flow-only tier and capability primaries, ordered backups and capability effort, with exported schemas, types and supported tier and capability constants. Backup lists allow at most eight models and reject duplicate references; omitted backups inherit while `[]` explicitly disables fallbacks.
8
+
9
+ ### Changed
10
+
11
+ - Profiles and admissions containing `modelSelection` include it in their digest input. Existing documents without it retain their original digests. Older strict readers reject the new field; update profile and admission consumers before exchanging new-format documents.
12
+
13
+ ## [0.4.9] - 2026-10-13
14
+
15
+ ### Added
16
+
17
+ - Flow failure classes and RPC Flow reason classes accept `provider_unreachable` for provider transport failures (additive).
18
+
3
19
  ## [0.4.8] - 2026-10-13
4
20
 
5
21
  ### Added
@@ -172,6 +172,29 @@ export declare const FlowRunAdmissionV1Schema: Type.TObject<{
172
172
  readonly triage: Type.TOptional<Type.TInteger>;
173
173
  }>>;
174
174
  }>;
175
+ readonly modelSelection: Type.TOptional<Type.TObject<{
176
+ readonly tiers: Type.TOptional<Type.TObject<Record<"cheap" | "frontier" | "mid" | "premium", Type.TOptional<Type.TObject<{
177
+ readonly primary: Type.TOptional<Type.TObject<{
178
+ readonly provider: Type.TString;
179
+ readonly model: Type.TString;
180
+ }>>;
181
+ readonly backups: Type.TOptional<Type.TArray<Type.TObject<{
182
+ readonly provider: Type.TString;
183
+ readonly model: Type.TString;
184
+ }>>>;
185
+ }>>>>>;
186
+ readonly capabilities: Type.TOptional<Type.TObject<Record<"analysis_mid" | "analysis_strong" | "api_contract_review" | "architect" | "implementation_fast" | "implementation_strong" | "integration_review" | "lead" | "lead_large" | "lead_small" | "migration_review" | "performance_review" | "qa_agent" | "scope_scout" | "scout" | "security_review" | "technical_lead" | "technical_review" | "triage" | "worker", Type.TOptional<Type.TObject<{
187
+ readonly primary: Type.TOptional<Type.TObject<{
188
+ readonly provider: Type.TString;
189
+ readonly model: Type.TString;
190
+ }>>;
191
+ readonly backups: Type.TOptional<Type.TArray<Type.TObject<{
192
+ readonly provider: Type.TString;
193
+ readonly model: Type.TString;
194
+ }>>>;
195
+ readonly effort: Type.TOptional<Type.TUnion<[Type.TLiteral<"off">, Type.TLiteral<"minimal">, Type.TLiteral<"low">, Type.TLiteral<"medium">, Type.TLiteral<"high">, Type.TLiteral<"xhigh">, Type.TLiteral<"max">]>>;
196
+ }>>>>>;
197
+ }>>;
175
198
  readonly providers: Type.TOptional<Type.TObject<{
176
199
  readonly preference: Type.TArray<Type.TString>;
177
200
  }>>;
@@ -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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAuBnC,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"}
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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAuBnC,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"}
@@ -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", "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"];
62
62
  export type FlowFailureClass = (typeof FLOW_FAILURE_CLASSES)[number];
63
- export declare const FlowFailureClassSchema: TUnion<[TLiteral<"provider_error">, 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<"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">]>;
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">]>;
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,QAAQ,EAAE,KAAK,OAAO,EAAE,KAAK,MAAM,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAGtF;;;GAGG;AAEH,eAAO,MAAM,eAAe,kCAAkC,CAAC;AAC/D,gHAAgH;AAChH,eAAO,MAAM,qBAAqB,oEAAoE,CAAC;AACvG,eAAO,MAAM,mBAAmB,mBAAmB,CAAC;AAIpD,eAAO,MAAM,yBAAyB;aACrC,eAAe,EAAE,sBAAsB;aACvC,iBAAiB,EAAE,4BAA4B;aAC/C,aAAa,EAAE,oBAAoB;aACnC,eAAe,EAAE,8BAA8B;aAC/C,eAAe,EAAE,8BAA8B;aAC/C,cAAc,EAAE,qBAAqB;aACrC,eAAe,EAAE,sBAAsB;aACvC,mBAAmB,EAAE,gCAAgC;aACrD,iBAAiB,EAAE,mCAAmC;aACtD,gBAAgB,EAAE,+CAA+C;CACxD,CAAC;AACX,MAAM,MAAM,qBAAqB,GAAG,MAAM,OAAO,yBAAyB,CAAC;AAE3E,kGAAkG;AAClG,qBAAa,iBAAkB,SAAQ,KAAK;IAC3C,QAAQ,CAAC,IAAI,EAAE,qBAAqB,CAAC;IACrC,YAAY,IAAI,EAAE,qBAAqB,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,mBAAmB,CAAC,IAAI,EAAE,qBAAqB,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAMxF;AAED,wBAAgB,WAAW,CAAC,CAAC,SAAS,OAAO,EAAE,MAAM,EAAE,CAAC,4JAEvD;AAED,wBAAgB,QAAQ,CAAC,GAAG,EAAE,YAAY,GAAG,MAAM,CAElD;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,SAAS,YAAY,EAAE,GAAG,OAAO,CAEzE;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAoBxD;AAED,2DAA2D;AAC3D,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAIlE"}
@@ -93,6 +93,7 @@ export const FLOW_SIZES = ["small", "medium", "large"];
93
93
  export const FlowSizeSchema = Type.Union([Type.Literal("small"), Type.Literal("medium"), Type.Literal("large")]);
94
94
  export const FLOW_FAILURE_CLASSES = [
95
95
  "provider_error",
96
+ "provider_unreachable",
96
97
  "rate_limit",
97
98
  "timeout",
98
99
  "check_failed",
@@ -110,6 +111,7 @@ export const FLOW_FAILURE_CLASSES = [
110
111
  ];
111
112
  export const FlowFailureClassSchema = Type.Union([
112
113
  Type.Literal("provider_error"),
114
+ Type.Literal("provider_unreachable"),
113
115
  Type.Literal("rate_limit"),
114
116
  Type.Literal("timeout"),
115
117
  Type.Literal("check_failed"),
@@ -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,MA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iB,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;IAC/E,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,MAAM,IAAI,iBAAiB,CAAC,mBAAmB,CAAC,CAAC;IAChF,MAAM,MAAM,GAAG,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\"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(\"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,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,CAA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AAI,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"]}
@@ -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<"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<"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<"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<"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<"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<"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<"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<"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<"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<"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<"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">]>>;
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<"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">]>>;
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<{
@@ -1,20 +1,75 @@
1
- import { type Static, Type } from "typebox";
1
+ import { type Static, type TObject, type TOptional, Type } from "typebox";
2
2
  import { type FlowDigestHasher } from "./flow-common.ts";
3
3
  export { FlowProfileRefSchema, type FlowProfileRefV1 } from "./flow-common.ts";
4
4
  export declare const FlowEffortSchema: Type.TUnion<[Type.TLiteral<"low">, Type.TLiteral<"medium">, Type.TLiteral<"high">]>;
5
- export declare const FlowRoleBindingSchema: Type.TObject<{
6
- readonly primary: Type.TObject<{
5
+ export declare const FlowRoleBindingSchema: TObject<{
6
+ readonly primary: TObject<{
7
7
  readonly provider: Type.TString;
8
8
  readonly model: Type.TString;
9
9
  }>;
10
- readonly backups: Type.TArray<Type.TObject<{
10
+ readonly backups: Type.TArray<TObject<{
11
11
  readonly provider: Type.TString;
12
12
  readonly model: Type.TString;
13
13
  }>>;
14
14
  readonly effort: Type.TUnion<[Type.TLiteral<"low">, Type.TLiteral<"medium">, Type.TLiteral<"high">]>;
15
15
  }>;
16
16
  export type FlowRoleBindingV1 = Static<typeof FlowRoleBindingSchema>;
17
- export declare const FlowProfileV1Schema: Type.TObject<{
17
+ /** Cost tiers a selection may declare (matches Flow's `Tier`). */
18
+ export declare const FLOW_MODEL_SELECTION_TIERS: readonly ["cheap", "mid", "premium", "frontier"];
19
+ export type FlowSelectionTier = (typeof FLOW_MODEL_SELECTION_TIERS)[number];
20
+ /** Flow's `ALL_CAPABILITIES` (method.json) plus the runtime `triage` capability; parity is pinned in the flow tests. */
21
+ export declare const FLOW_MODEL_SELECTION_CAPABILITIES: readonly ["scout", "scope_scout", "worker", "implementation_fast", "analysis_mid", "technical_lead", "lead_small", "lead", "lead_large", "implementation_strong", "technical_review", "integration_review", "migration_review", "performance_review", "api_contract_review", "qa_agent", "analysis_strong", "architect", "security_review", "triage"];
22
+ export type FlowSelectionCapability = (typeof FLOW_MODEL_SELECTION_CAPABILITIES)[number];
23
+ export declare const FlowSelectionEffortSchema: Type.TUnion<[Type.TLiteral<"off">, Type.TLiteral<"minimal">, Type.TLiteral<"low">, Type.TLiteral<"medium">, Type.TLiteral<"high">, Type.TLiteral<"xhigh">, Type.TLiteral<"max">]>;
24
+ /** Omitted `backups` inherits; an explicit `[]` means no fallbacks. Both must survive round-trips. */
25
+ export declare const FlowTierSelectionSchema: TObject<{
26
+ readonly primary: TOptional<TObject<{
27
+ readonly provider: Type.TString;
28
+ readonly model: Type.TString;
29
+ }>>;
30
+ readonly backups: TOptional<Type.TArray<TObject<{
31
+ readonly provider: Type.TString;
32
+ readonly model: Type.TString;
33
+ }>>>;
34
+ }>;
35
+ export type FlowTierSelectionV1 = Static<typeof FlowTierSelectionSchema>;
36
+ export declare const FlowCapabilitySelectionSchema: TObject<{
37
+ readonly primary: TOptional<TObject<{
38
+ readonly provider: Type.TString;
39
+ readonly model: Type.TString;
40
+ }>>;
41
+ readonly backups: TOptional<Type.TArray<TObject<{
42
+ readonly provider: Type.TString;
43
+ readonly model: Type.TString;
44
+ }>>>;
45
+ readonly effort: TOptional<Type.TUnion<[Type.TLiteral<"off">, Type.TLiteral<"minimal">, Type.TLiteral<"low">, Type.TLiteral<"medium">, Type.TLiteral<"high">, Type.TLiteral<"xhigh">, Type.TLiteral<"max">]>>;
46
+ }>;
47
+ export type FlowCapabilitySelectionV1 = Static<typeof FlowCapabilitySelectionSchema>;
48
+ export declare const FlowModelSelectionSchema: TObject<{
49
+ readonly tiers: TOptional<TObject<Record<"cheap" | "frontier" | "mid" | "premium", TOptional<TObject<{
50
+ readonly primary: TOptional<TObject<{
51
+ readonly provider: Type.TString;
52
+ readonly model: Type.TString;
53
+ }>>;
54
+ readonly backups: TOptional<Type.TArray<TObject<{
55
+ readonly provider: Type.TString;
56
+ readonly model: Type.TString;
57
+ }>>>;
58
+ }>>>>>;
59
+ readonly capabilities: TOptional<TObject<Record<"analysis_mid" | "analysis_strong" | "api_contract_review" | "architect" | "implementation_fast" | "implementation_strong" | "integration_review" | "lead" | "lead_large" | "lead_small" | "migration_review" | "performance_review" | "qa_agent" | "scope_scout" | "scout" | "security_review" | "technical_lead" | "technical_review" | "triage" | "worker", TOptional<TObject<{
60
+ readonly primary: TOptional<TObject<{
61
+ readonly provider: Type.TString;
62
+ readonly model: Type.TString;
63
+ }>>;
64
+ readonly backups: TOptional<Type.TArray<TObject<{
65
+ readonly provider: Type.TString;
66
+ readonly model: Type.TString;
67
+ }>>>;
68
+ readonly effort: TOptional<Type.TUnion<[Type.TLiteral<"off">, Type.TLiteral<"minimal">, Type.TLiteral<"low">, Type.TLiteral<"medium">, Type.TLiteral<"high">, Type.TLiteral<"xhigh">, Type.TLiteral<"max">]>>;
69
+ }>>>>>;
70
+ }>;
71
+ export type FlowModelSelectionV1 = Static<typeof FlowModelSelectionSchema>;
72
+ export declare const FlowProfileV1Schema: TObject<{
18
73
  readonly schema: Type.TLiteral<"humain-flow-profile">;
19
74
  readonly schemaVersion: Type.TLiteral<1>;
20
75
  readonly id: Type.TString;
@@ -22,139 +77,139 @@ export declare const FlowProfileV1Schema: Type.TObject<{
22
77
  readonly digest: Type.TString;
23
78
  readonly kind: Type.TUnion<[Type.TLiteral<"direct">, Type.TLiteral<"flow">]>;
24
79
  readonly label: Type.TString;
25
- readonly description: Type.TOptional<Type.TString>;
26
- readonly direct: Type.TOptional<Type.TObject<{
27
- readonly model: Type.TObject<{
80
+ readonly description: TOptional<Type.TString>;
81
+ readonly direct: TOptional<TObject<{
82
+ readonly model: TObject<{
28
83
  readonly provider: Type.TString;
29
84
  readonly model: Type.TString;
30
85
  }>;
31
- readonly fallbacks: Type.TArray<Type.TObject<{
86
+ readonly fallbacks: Type.TArray<TObject<{
32
87
  readonly provider: Type.TString;
33
88
  readonly model: Type.TString;
34
89
  }>>;
35
90
  }>>;
36
- readonly roles: Type.TOptional<Type.TObject<{
37
- readonly scout: Type.TOptional<Type.TObject<{
38
- readonly primary: Type.TObject<{
91
+ readonly roles: TOptional<TObject<{
92
+ readonly scout: TOptional<TObject<{
93
+ readonly primary: TObject<{
39
94
  readonly provider: Type.TString;
40
95
  readonly model: Type.TString;
41
96
  }>;
42
- readonly backups: Type.TArray<Type.TObject<{
97
+ readonly backups: Type.TArray<TObject<{
43
98
  readonly provider: Type.TString;
44
99
  readonly model: Type.TString;
45
100
  }>>;
46
101
  readonly effort: Type.TUnion<[Type.TLiteral<"low">, Type.TLiteral<"medium">, Type.TLiteral<"high">]>;
47
102
  }>>;
48
- readonly worker: Type.TOptional<Type.TObject<{
49
- readonly primary: Type.TObject<{
103
+ readonly worker: TOptional<TObject<{
104
+ readonly primary: TObject<{
50
105
  readonly provider: Type.TString;
51
106
  readonly model: Type.TString;
52
107
  }>;
53
- readonly backups: Type.TArray<Type.TObject<{
108
+ readonly backups: Type.TArray<TObject<{
54
109
  readonly provider: Type.TString;
55
110
  readonly model: Type.TString;
56
111
  }>>;
57
112
  readonly effort: Type.TUnion<[Type.TLiteral<"low">, Type.TLiteral<"medium">, Type.TLiteral<"high">]>;
58
113
  }>>;
59
- readonly implementer: Type.TOptional<Type.TObject<{
60
- readonly primary: Type.TObject<{
114
+ readonly implementer: TOptional<TObject<{
115
+ readonly primary: TObject<{
61
116
  readonly provider: Type.TString;
62
117
  readonly model: Type.TString;
63
118
  }>;
64
- readonly backups: Type.TArray<Type.TObject<{
119
+ readonly backups: Type.TArray<TObject<{
65
120
  readonly provider: Type.TString;
66
121
  readonly model: Type.TString;
67
122
  }>>;
68
123
  readonly effort: Type.TUnion<[Type.TLiteral<"low">, Type.TLiteral<"medium">, Type.TLiteral<"high">]>;
69
124
  }>>;
70
- readonly lead: Type.TOptional<Type.TObject<{
71
- readonly primary: Type.TObject<{
125
+ readonly lead: TOptional<TObject<{
126
+ readonly primary: TObject<{
72
127
  readonly provider: Type.TString;
73
128
  readonly model: Type.TString;
74
129
  }>;
75
- readonly backups: Type.TArray<Type.TObject<{
130
+ readonly backups: Type.TArray<TObject<{
76
131
  readonly provider: Type.TString;
77
132
  readonly model: Type.TString;
78
133
  }>>;
79
134
  readonly effort: Type.TUnion<[Type.TLiteral<"low">, Type.TLiteral<"medium">, Type.TLiteral<"high">]>;
80
135
  }>>;
81
- readonly lead_large: Type.TOptional<Type.TObject<{
82
- readonly primary: Type.TObject<{
136
+ readonly lead_large: TOptional<TObject<{
137
+ readonly primary: TObject<{
83
138
  readonly provider: Type.TString;
84
139
  readonly model: Type.TString;
85
140
  }>;
86
- readonly backups: Type.TArray<Type.TObject<{
141
+ readonly backups: Type.TArray<TObject<{
87
142
  readonly provider: Type.TString;
88
143
  readonly model: Type.TString;
89
144
  }>>;
90
145
  readonly effort: Type.TUnion<[Type.TLiteral<"low">, Type.TLiteral<"medium">, Type.TLiteral<"high">]>;
91
146
  }>>;
92
- readonly architect: Type.TOptional<Type.TObject<{
93
- readonly primary: Type.TObject<{
147
+ readonly architect: TOptional<TObject<{
148
+ readonly primary: TObject<{
94
149
  readonly provider: Type.TString;
95
150
  readonly model: Type.TString;
96
151
  }>;
97
- readonly backups: Type.TArray<Type.TObject<{
152
+ readonly backups: Type.TArray<TObject<{
98
153
  readonly provider: Type.TString;
99
154
  readonly model: Type.TString;
100
155
  }>>;
101
156
  readonly effort: Type.TUnion<[Type.TLiteral<"low">, Type.TLiteral<"medium">, Type.TLiteral<"high">]>;
102
157
  }>>;
103
- readonly reviewer: Type.TOptional<Type.TObject<{
104
- readonly primary: Type.TObject<{
158
+ readonly reviewer: TOptional<TObject<{
159
+ readonly primary: TObject<{
105
160
  readonly provider: Type.TString;
106
161
  readonly model: Type.TString;
107
162
  }>;
108
- readonly backups: Type.TArray<Type.TObject<{
163
+ readonly backups: Type.TArray<TObject<{
109
164
  readonly provider: Type.TString;
110
165
  readonly model: Type.TString;
111
166
  }>>;
112
167
  readonly effort: Type.TUnion<[Type.TLiteral<"low">, Type.TLiteral<"medium">, Type.TLiteral<"high">]>;
113
168
  }>>;
114
- readonly security_reviewer: Type.TOptional<Type.TObject<{
115
- readonly primary: Type.TObject<{
169
+ readonly security_reviewer: TOptional<TObject<{
170
+ readonly primary: TObject<{
116
171
  readonly provider: Type.TString;
117
172
  readonly model: Type.TString;
118
173
  }>;
119
- readonly backups: Type.TArray<Type.TObject<{
174
+ readonly backups: Type.TArray<TObject<{
120
175
  readonly provider: Type.TString;
121
176
  readonly model: Type.TString;
122
177
  }>>;
123
178
  readonly effort: Type.TUnion<[Type.TLiteral<"low">, Type.TLiteral<"medium">, Type.TLiteral<"high">]>;
124
179
  }>>;
125
- readonly qa: Type.TOptional<Type.TObject<{
126
- readonly primary: Type.TObject<{
180
+ readonly qa: TOptional<TObject<{
181
+ readonly primary: TObject<{
127
182
  readonly provider: Type.TString;
128
183
  readonly model: Type.TString;
129
184
  }>;
130
- readonly backups: Type.TArray<Type.TObject<{
185
+ readonly backups: Type.TArray<TObject<{
131
186
  readonly provider: Type.TString;
132
187
  readonly model: Type.TString;
133
188
  }>>;
134
189
  readonly effort: Type.TUnion<[Type.TLiteral<"low">, Type.TLiteral<"medium">, Type.TLiteral<"high">]>;
135
190
  }>>;
136
- readonly triage: Type.TOptional<Type.TObject<{
137
- readonly primary: Type.TObject<{
191
+ readonly triage: TOptional<TObject<{
192
+ readonly primary: TObject<{
138
193
  readonly provider: Type.TString;
139
194
  readonly model: Type.TString;
140
195
  }>;
141
- readonly backups: Type.TArray<Type.TObject<{
196
+ readonly backups: Type.TArray<TObject<{
142
197
  readonly provider: Type.TString;
143
198
  readonly model: Type.TString;
144
199
  }>>;
145
200
  readonly effort: Type.TUnion<[Type.TLiteral<"low">, Type.TLiteral<"medium">, Type.TLiteral<"high">]>;
146
201
  }>>;
147
202
  }>>;
148
- readonly sizing: Type.TOptional<Type.TObject<{
203
+ readonly sizing: TOptional<TObject<{
149
204
  readonly classifierPolicyId: Type.TString;
150
- readonly thresholds: Type.TObject<{
205
+ readonly thresholds: TObject<{
151
206
  readonly mediumAt: Type.TNumber;
152
207
  readonly largeAt: Type.TNumber;
153
208
  }>;
154
209
  readonly triageRole: Type.TLiteral<"triage">;
155
210
  readonly maxEscalations: Type.TUnion<[Type.TLiteral<0>, Type.TLiteral<1>]>;
156
211
  }>>;
157
- readonly limits: Type.TObject<{
212
+ readonly limits: TObject<{
158
213
  readonly maxAgents: Type.TInteger;
159
214
  readonly maxConcurrent: Type.TInteger;
160
215
  readonly maxDepth: Type.TInteger;
@@ -162,30 +217,53 @@ export declare const FlowProfileV1Schema: Type.TObject<{
162
217
  readonly inactivityMs: Type.TInteger;
163
218
  readonly ciWaitMs: Type.TInteger;
164
219
  }>;
165
- readonly spend: Type.TObject<{
220
+ readonly spend: TObject<{
166
221
  readonly runCapMicrousd: Type.TInteger;
167
222
  readonly warnAtPct: Type.TInteger;
168
- readonly perRoleCapMicrousd: Type.TOptional<Type.TObject<{
169
- readonly scout: Type.TOptional<Type.TInteger>;
170
- readonly worker: Type.TOptional<Type.TInteger>;
171
- readonly implementer: Type.TOptional<Type.TInteger>;
172
- readonly lead: Type.TOptional<Type.TInteger>;
173
- readonly lead_large: Type.TOptional<Type.TInteger>;
174
- readonly architect: Type.TOptional<Type.TInteger>;
175
- readonly reviewer: Type.TOptional<Type.TInteger>;
176
- readonly security_reviewer: Type.TOptional<Type.TInteger>;
177
- readonly qa: Type.TOptional<Type.TInteger>;
178
- readonly triage: Type.TOptional<Type.TInteger>;
223
+ readonly perRoleCapMicrousd: TOptional<TObject<{
224
+ readonly scout: TOptional<Type.TInteger>;
225
+ readonly worker: TOptional<Type.TInteger>;
226
+ readonly implementer: TOptional<Type.TInteger>;
227
+ readonly lead: TOptional<Type.TInteger>;
228
+ readonly lead_large: TOptional<Type.TInteger>;
229
+ readonly architect: TOptional<Type.TInteger>;
230
+ readonly reviewer: TOptional<Type.TInteger>;
231
+ readonly security_reviewer: TOptional<Type.TInteger>;
232
+ readonly qa: TOptional<Type.TInteger>;
233
+ readonly triage: TOptional<Type.TInteger>;
179
234
  }>>;
180
235
  }>;
181
- readonly providers: Type.TOptional<Type.TObject<{
236
+ readonly modelSelection: TOptional<TObject<{
237
+ readonly tiers: TOptional<TObject<Record<"cheap" | "frontier" | "mid" | "premium", TOptional<TObject<{
238
+ readonly primary: TOptional<TObject<{
239
+ readonly provider: Type.TString;
240
+ readonly model: Type.TString;
241
+ }>>;
242
+ readonly backups: TOptional<Type.TArray<TObject<{
243
+ readonly provider: Type.TString;
244
+ readonly model: Type.TString;
245
+ }>>>;
246
+ }>>>>>;
247
+ readonly capabilities: TOptional<TObject<Record<"analysis_mid" | "analysis_strong" | "api_contract_review" | "architect" | "implementation_fast" | "implementation_strong" | "integration_review" | "lead" | "lead_large" | "lead_small" | "migration_review" | "performance_review" | "qa_agent" | "scope_scout" | "scout" | "security_review" | "technical_lead" | "technical_review" | "triage" | "worker", TOptional<TObject<{
248
+ readonly primary: TOptional<TObject<{
249
+ readonly provider: Type.TString;
250
+ readonly model: Type.TString;
251
+ }>>;
252
+ readonly backups: TOptional<Type.TArray<TObject<{
253
+ readonly provider: Type.TString;
254
+ readonly model: Type.TString;
255
+ }>>>;
256
+ readonly effort: TOptional<Type.TUnion<[Type.TLiteral<"off">, Type.TLiteral<"minimal">, Type.TLiteral<"low">, Type.TLiteral<"medium">, Type.TLiteral<"high">, Type.TLiteral<"xhigh">, Type.TLiteral<"max">]>>;
257
+ }>>>>>;
258
+ }>>;
259
+ readonly providers: TOptional<TObject<{
182
260
  readonly preference: Type.TArray<Type.TString>;
183
261
  }>>;
184
- readonly approval: Type.TOptional<Type.TObject<{
262
+ readonly approval: TOptional<TObject<{
185
263
  readonly approvedBy: Type.TString;
186
264
  readonly approvedAt: Type.TRefine<Type.TString>;
187
265
  }>>;
188
- readonly builtIn: Type.TOptional<Type.TLiteral<true>>;
266
+ readonly builtIn: TOptional<Type.TLiteral<true>>;
189
267
  }>;
190
268
  export type FlowProfileV1 = Static<typeof FlowProfileV1Schema>;
191
269
  /** Canonical text hashed (sha256 hex) to produce `digest`: the document without `digest`. */
@@ -1 +1 @@
1
- {"version":3,"file":"flow-profile.d.ts","sourceRoot":"","sources":["../src/flow-profile.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAIN,KAAK,gBAAgB,EAarB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,oBAAoB,EAAE,KAAK,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAE/E,eAAO,MAAM,gBAAgB,qFAAkF,CAAC;AAEhH,eAAO,MAAM,qBA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,aAAa,GAAG,MAAM,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAK/D,6FAA6F;AAC7F,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,aAAa,GAAG,MAAM,CAEjE;AAiCD;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,OAAO,GAAG,aAAa,CAErE;AAED,sHAAsH;AACtH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,gBAAgB,GAAG,aAAa,CAM1F"}
@@ -1,5 +1,5 @@
1
1
  import { Type } from "typebox";
2
- import { canonicalWithout, compileFlow, FlowContractError, FlowDigestSchema, FlowIdSchema, FlowMicrousdSchema, FlowModelRefSchema, FlowPositiveIntSchema, FlowTimestampSchema, hasDuplicateModels, parseFlowData, partialByRole, StrictObject, verifyFlowDigest, } from "./flow-common.js";
2
+ import { canonicalWithout, compileFlow, FlowContractError, FlowDigestSchema, FlowIdSchema, FlowMicrousdSchema, FlowModelRefSchema, FlowPositiveIntSchema, FlowTimestampSchema, hasDuplicateModels, lit, parseFlowData, partialByRole, StrictObject, verifyFlowDigest, } from "./flow-common.js";
3
3
  export { FlowProfileRefSchema } from "./flow-common.js";
4
4
  export const FlowEffortSchema = Type.Union([Type.Literal("low"), Type.Literal("medium"), Type.Literal("high")]);
5
5
  export const FlowRoleBindingSchema = StrictObject({
@@ -7,6 +7,47 @@ export const FlowRoleBindingSchema = StrictObject({
7
7
  backups: Type.Array(FlowModelRefSchema, { maxItems: 8 }),
8
8
  effort: FlowEffortSchema,
9
9
  });
10
+ /** Cost tiers a selection may declare (matches Flow's `Tier`). */
11
+ export const FLOW_MODEL_SELECTION_TIERS = ["cheap", "mid", "premium", "frontier"];
12
+ /** Flow's `ALL_CAPABILITIES` (method.json) plus the runtime `triage` capability; parity is pinned in the flow tests. */
13
+ export const FLOW_MODEL_SELECTION_CAPABILITIES = [
14
+ "scout",
15
+ "scope_scout",
16
+ "worker",
17
+ "implementation_fast",
18
+ "analysis_mid",
19
+ "technical_lead",
20
+ "lead_small",
21
+ "lead",
22
+ "lead_large",
23
+ "implementation_strong",
24
+ "technical_review",
25
+ "integration_review",
26
+ "migration_review",
27
+ "performance_review",
28
+ "api_contract_review",
29
+ "qa_agent",
30
+ "analysis_strong",
31
+ "architect",
32
+ "security_review",
33
+ "triage",
34
+ ];
35
+ export const FlowSelectionEffortSchema = lit("off", "minimal", "low", "medium", "high", "xhigh", "max");
36
+ /** Omitted `backups` inherits; an explicit `[]` means no fallbacks. Both must survive round-trips. */
37
+ export const FlowTierSelectionSchema = StrictObject({
38
+ primary: Type.Optional(FlowModelRefSchema),
39
+ backups: Type.Optional(Type.Array(FlowModelRefSchema, { maxItems: 8 })),
40
+ });
41
+ export const FlowCapabilitySelectionSchema = StrictObject({
42
+ primary: Type.Optional(FlowModelRefSchema),
43
+ backups: Type.Optional(Type.Array(FlowModelRefSchema, { maxItems: 8 })),
44
+ effort: Type.Optional(FlowSelectionEffortSchema),
45
+ });
46
+ const optionalEach = (keys, schema) => StrictObject(Object.fromEntries(keys.map((key) => [key, Type.Optional(schema)])));
47
+ export const FlowModelSelectionSchema = StrictObject({
48
+ tiers: Type.Optional(optionalEach(FLOW_MODEL_SELECTION_TIERS, FlowTierSelectionSchema)),
49
+ capabilities: Type.Optional(optionalEach(FLOW_MODEL_SELECTION_CAPABILITIES, FlowCapabilitySelectionSchema)),
50
+ });
10
51
  export const FlowProfileV1Schema = StrictObject({
11
52
  schema: Type.Literal("humain-flow-profile"),
12
53
  schemaVersion: Type.Literal(1),
@@ -40,6 +81,7 @@ export const FlowProfileV1Schema = StrictObject({
40
81
  warnAtPct: Type.Integer({ minimum: 1, maximum: 99 }),
41
82
  perRoleCapMicrousd: Type.Optional(partialByRole(FlowMicrousdSchema)),
42
83
  }),
84
+ modelSelection: Type.Optional(FlowModelSelectionSchema),
43
85
  providers: Type.Optional(StrictObject({ preference: Type.Array(FlowIdSchema, { maxItems: 16 }) })),
44
86
  approval: Type.Optional(StrictObject({ approvedBy: FlowIdSchema, approvedAt: FlowTimestampSchema })),
45
87
  builtIn: Type.Optional(Type.Literal(true)),
@@ -50,7 +92,18 @@ const REQUIRED_FLOW_ROLES = ["lead", "worker", "reviewer", "qa"];
50
92
  export function flowProfileDigestInput(doc) {
51
93
  return canonicalWithout(doc, "digest");
52
94
  }
95
+ function selectionLayerValid(layer) {
96
+ const refs = [...(layer.primary === undefined ? [] : [layer.primary]), ...(layer.backups ?? [])];
97
+ return !hasDuplicateModels(refs);
98
+ }
99
+ function modelSelectionValid(selection) {
100
+ const layers = [...Object.values(selection.tiers ?? {}), ...Object.values(selection.capabilities ?? {})];
101
+ return layers.every(selectionLayerValid);
102
+ }
53
103
  function crossFieldsValid(doc) {
104
+ if (doc.modelSelection !== undefined && (doc.kind === "direct" || !modelSelectionValid(doc.modelSelection))) {
105
+ return false;
106
+ }
54
107
  if (doc.kind === "direct") {
55
108
  if (doc.direct === undefined || doc.roles !== undefined || doc.sizing !== undefined)
56
109
  return false;
@@ -1 +1 @@
1
- {"version":3,"file":"flow-profile.js","sourceRoot":"","sources":["../src/flow-profile.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,EAElB,kBAAkB,EAClB,qBAAqB,EACrB,mBAAmB,EACnB,kBAAkB,EAClB,aAAa,EACb,aAAa,EACb,YAAY,EACZ,gBAAgB,GAChB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,oBAAoB,EAAyB,MAAM,kBAAkB,CAAC;AAE/E,MAAM,CAAC,MAAM,gBAAgB,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAA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\n\tFlowIdSchema,\n\tFlowMicrousdSchema,\n\ttype FlowModelRef,\n\tFlowModelRefSchema,\n\tFlowPositiveIntSchema,\n\tFlowTimestampSchema,\n\thasDuplicateModels,\n\tparseFlowData,\n\tpartialByRole,\n\tStrictObject,\n\tverifyFlowDigest,\n} from \"./flow-common.ts\";\n\nexport { FlowProfileRefSchema, type FlowProfileRefV1 } from \"./flow-common.ts\";\n\nexport const FlowEffortSchema = Type.Union([Type.Literal(\"low\"), Type.Literal(\"medium\"), Type.Literal(\"high\")]);\n\nexport const FlowRoleBindingSchema = StrictObject({\n\tprimary: FlowModelRefSchema,\n\tbackups: Type.Array(FlowModelRefSchema, { maxItems: 8 }),\n\teffort: FlowEffortSchema,\n});\nexport type FlowRoleBindingV1 = Static<typeof FlowRoleBindingSchema>;\n\nexport const FlowProfileV1Schema = StrictObject({\n\tschema: Type.Literal(\"humain-flow-profile\"),\n\tschemaVersion: Type.Literal(1),\n\tid: FlowIdSchema,\n\tversion: FlowPositiveIntSchema,\n\tdigest: FlowDigestSchema,\n\tkind: Type.Union([Type.Literal(\"direct\"), Type.Literal(\"flow\")]),\n\tlabel: Type.String({ minLength: 1, maxLength: 80 }),\n\tdescription: Type.Optional(Type.String({ maxLength: 500 })),\n\tdirect: Type.Optional(\n\t\tStrictObject({ model: FlowModelRefSchema, fallbacks: Type.Array(FlowModelRefSchema, { maxItems: 8 }) }),\n\t),\n\troles: Type.Optional(partialByRole(FlowRoleBindingSchema)),\n\tsizing: Type.Optional(\n\t\tStrictObject({\n\t\t\tclassifierPolicyId: FlowIdSchema,\n\t\t\tthresholds: StrictObject({\n\t\t\t\tmediumAt: Type.Number({ minimum: 0, maximum: 1_000_000 }),\n\t\t\t\tlargeAt: Type.Number({ minimum: 0, maximum: 1_000_000 }),\n\t\t\t}),\n\t\t\ttriageRole: Type.Literal(\"triage\"),\n\t\t\tmaxEscalations: Type.Union([Type.Literal(0), Type.Literal(1)]),\n\t\t}),\n\t),\n\tlimits: StrictObject({\n\t\tmaxAgents: Type.Integer({ minimum: 1, maximum: 256 }),\n\t\tmaxConcurrent: Type.Integer({ minimum: 1, maximum: 64 }),\n\t\tmaxDepth: Type.Integer({ minimum: 0, maximum: 3 }),\n\t\tmaxRetries: Type.Integer({ minimum: 0, maximum: 16 }),\n\t\tinactivityMs: Type.Integer({ minimum: 1, maximum: 86_400_000 }),\n\t\tciWaitMs: Type.Integer({ minimum: 0, maximum: 86_400_000 }),\n\t}),\n\tspend: StrictObject({\n\t\trunCapMicrousd: FlowMicrousdSchema,\n\t\twarnAtPct: Type.Integer({ minimum: 1, maximum: 99 }),\n\t\tperRoleCapMicrousd: Type.Optional(partialByRole(FlowMicrousdSchema)),\n\t}),\n\tproviders: Type.Optional(StrictObject({ preference: Type.Array(FlowIdSchema, { maxItems: 16 }) })),\n\tapproval: Type.Optional(StrictObject({ approvedBy: FlowIdSchema, approvedAt: FlowTimestampSchema })),\n\tbuiltIn: Type.Optional(Type.Literal(true)),\n});\nexport type FlowProfileV1 = Static<typeof FlowProfileV1Schema>;\n\nconst Validator = compileFlow(FlowProfileV1Schema);\nconst REQUIRED_FLOW_ROLES = [\"lead\", \"worker\", \"reviewer\", \"qa\"] as const;\n\n/** Canonical text hashed (sha256 hex) to produce `digest`: the document without `digest`. */\nexport function flowProfileDigestInput(doc: FlowProfileV1): string {\n\treturn canonicalWithout(doc, \"digest\");\n}\n\nfunction crossFieldsValid(doc: FlowProfileV1): boolean {\n\tif (doc.kind === \"direct\") {\n\t\tif (doc.direct === undefined || doc.roles !== undefined || doc.sizing !== undefined) return false;\n\t\treturn !hasDuplicateModels([doc.direct.model, ...doc.direct.fallbacks]);\n\t}\n\tif (doc.direct !== undefined || doc.roles === undefined) return false;\n\tfor (const role of REQUIRED_FLOW_ROLES) if (doc.roles[role] === undefined) return false;\n\tfor (const binding of Object.values(doc.roles)) {\n\t\tconst refs: FlowModelRef[] = [binding.primary, ...binding.backups];\n\t\tif (hasDuplicateModels(refs)) return false;\n\t}\n\treturn doc.sizing === undefined || doc.sizing.thresholds.mediumAt <= doc.sizing.thresholds.largeAt;\n}\n\nfunction isProfile(value: unknown): value is FlowProfileV1 {\n\treturn Validator.Check(value) && crossFieldsValid(value);\n}\n\n/**\n * SHAPE ONLY: validates structure and cross-field rules but does NOT verify `digest`. Use only for documents whose\n * integrity is established elsewhere (e.g. authored drafts); prefer {@link parseFlowProfileV1}.\n */\nexport function parseFlowProfileV1Shape(input: unknown): FlowProfileV1 {\n\treturn parseFlowData(\"profile_invalid\", input, isProfile);\n}\n\n/** Shape validation plus digest verification with the injected hasher (digests are integrity, not authentication). */\nexport function parseFlowProfileV1(input: unknown, hasher: FlowDigestHasher): FlowProfileV1 {\n\tconst profile = parseFlowProfileV1Shape(input);\n\tif (!verifyFlowDigest(hasher, flowProfileDigestInput(profile), profile.digest)) {\n\t\tthrow new FlowContractError(\"digest_mismatch\");\n\t}\n\treturn profile;\n}\n"]}
1
+ {"version":3,"file":"flow-profile.js","sourceRoot":"","sources":["../src/flow-profile.ts"],"names":[],"mappings":"AAAA,OAAO,EAA2D,IAAI,EAAE,MAAM,SAAS,CAAC;AACxF,OAAO,EACN,gBAAgB,EAChB,WAAW,EACX,iBAAiB,EAEjB,gBAAgB,EAChB,YAAY,EACZ,kBAAkB,EAElB,kBAAkB,EAClB,qBAAqB,EACrB,mBAAmB,EACnB,kBAAkB,EAClB,GAAG,EACH,aAAa,EACb,aAAa,EACb,YAAY,EACZ,gBAAgB,GAChB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,oBAAoB,EAAyB,MAAM,kBAAkB,CAAC;AAE/E,MAAM,CAAC,MAAM,gBAAgB,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;AAEhH,MAAM,CAAC,MAAM,qBAAqB,GAA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AAE,IAAI,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,SAAS;YAAE,OAAO,KAAK,CAAC;IACxF,KAAK,MAAM,OAAO,IAAI,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;QAChD,MAAM,IAAI,GAAmB,CAAC,OAAO,CAAC,OAAO,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;QACnE,IAAI,kBAAkB,CAAC,IAAI,CAAC;YAAE,OAAO,KAAK,CAAC;IAC5C,CAAC;IACD,OAAO,GAAG,CAAC,MAAM,KAAK,SAAS,IAAI,GAAG,CAAC,MAAM,CAAC,UAAU,CAAC,QAAQ,IAAI,GAAG,CAAC,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC;AACpG,CAAC;AAED,SAAS,SAAS,CAAC,KAAc;IAChC,OAAO,SAAS,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,gBAAgB,CAAC,KAAK,CAAC,CAAC;AAC1D,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,uBAAuB,CAAC,KAAc;IACrD,OAAO,aAAa,CAAC,iBAAiB,EAAE,KAAK,EAAE,SAAS,CAAC,CAAC;AAC3D,CAAC;AAED,sHAAsH;AACtH,MAAM,UAAU,kBAAkB,CAAC,KAAc,EAAE,MAAwB;IAC1E,MAAM,OAAO,GAAG,uBAAuB,CAAC,KAAK,CAAC,CAAC;IAC/C,IAAI,CAAC,gBAAgB,CAAC,MAAM,EAAE,sBAAsB,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QAChF,MAAM,IAAI,iBAAiB,CAAC,iBAAiB,CAAC,CAAC;IAChD,CAAC;IACD,OAAO,OAAO,CAAC;AAChB,CAAC","sourcesContent":["import { type Static, type TObject, type TOptional, type TSchema, Type } from \"typebox\";\nimport {\n\tcanonicalWithout,\n\tcompileFlow,\n\tFlowContractError,\n\ttype FlowDigestHasher,\n\tFlowDigestSchema,\n\tFlowIdSchema,\n\tFlowMicrousdSchema,\n\ttype FlowModelRef,\n\tFlowModelRefSchema,\n\tFlowPositiveIntSchema,\n\tFlowTimestampSchema,\n\thasDuplicateModels,\n\tlit,\n\tparseFlowData,\n\tpartialByRole,\n\tStrictObject,\n\tverifyFlowDigest,\n} from \"./flow-common.ts\";\n\nexport { FlowProfileRefSchema, type FlowProfileRefV1 } from \"./flow-common.ts\";\n\nexport const FlowEffortSchema = Type.Union([Type.Literal(\"low\"), Type.Literal(\"medium\"), Type.Literal(\"high\")]);\n\nexport const FlowRoleBindingSchema = StrictObject({\n\tprimary: FlowModelRefSchema,\n\tbackups: Type.Array(FlowModelRefSchema, { maxItems: 8 }),\n\teffort: FlowEffortSchema,\n});\nexport type FlowRoleBindingV1 = Static<typeof FlowRoleBindingSchema>;\n\n/** Cost tiers a selection may declare (matches Flow's `Tier`). */\nexport const FLOW_MODEL_SELECTION_TIERS = [\"cheap\", \"mid\", \"premium\", \"frontier\"] as const;\nexport type FlowSelectionTier = (typeof FLOW_MODEL_SELECTION_TIERS)[number];\n\n/** Flow's `ALL_CAPABILITIES` (method.json) plus the runtime `triage` capability; parity is pinned in the flow tests. */\nexport const FLOW_MODEL_SELECTION_CAPABILITIES = [\n\t\"scout\",\n\t\"scope_scout\",\n\t\"worker\",\n\t\"implementation_fast\",\n\t\"analysis_mid\",\n\t\"technical_lead\",\n\t\"lead_small\",\n\t\"lead\",\n\t\"lead_large\",\n\t\"implementation_strong\",\n\t\"technical_review\",\n\t\"integration_review\",\n\t\"migration_review\",\n\t\"performance_review\",\n\t\"api_contract_review\",\n\t\"qa_agent\",\n\t\"analysis_strong\",\n\t\"architect\",\n\t\"security_review\",\n\t\"triage\",\n] as const;\nexport type FlowSelectionCapability = (typeof FLOW_MODEL_SELECTION_CAPABILITIES)[number];\n\nexport const FlowSelectionEffortSchema = lit(\"off\", \"minimal\", \"low\", \"medium\", \"high\", \"xhigh\", \"max\");\n\n/** Omitted `backups` inherits; an explicit `[]` means no fallbacks. Both must survive round-trips. */\nexport const FlowTierSelectionSchema = StrictObject({\n\tprimary: Type.Optional(FlowModelRefSchema),\n\tbackups: Type.Optional(Type.Array(FlowModelRefSchema, { maxItems: 8 })),\n});\nexport type FlowTierSelectionV1 = Static<typeof FlowTierSelectionSchema>;\n\nexport const FlowCapabilitySelectionSchema = StrictObject({\n\tprimary: Type.Optional(FlowModelRefSchema),\n\tbackups: Type.Optional(Type.Array(FlowModelRefSchema, { maxItems: 8 })),\n\teffort: Type.Optional(FlowSelectionEffortSchema),\n});\nexport type FlowCapabilitySelectionV1 = Static<typeof FlowCapabilitySelectionSchema>;\n\nconst optionalEach = <T extends TSchema>(keys: readonly string[], schema: T) =>\n\tStrictObject(Object.fromEntries(keys.map((key) => [key, Type.Optional(schema)])));\n\nexport const FlowModelSelectionSchema = StrictObject({\n\ttiers: Type.Optional(\n\t\toptionalEach(FLOW_MODEL_SELECTION_TIERS, FlowTierSelectionSchema) as TObject<\n\t\t\tRecord<FlowSelectionTier, TOptional<typeof FlowTierSelectionSchema>>\n\t\t>,\n\t),\n\tcapabilities: Type.Optional(\n\t\toptionalEach(FLOW_MODEL_SELECTION_CAPABILITIES, FlowCapabilitySelectionSchema) as TObject<\n\t\t\tRecord<FlowSelectionCapability, TOptional<typeof FlowCapabilitySelectionSchema>>\n\t\t>,\n\t),\n});\nexport type FlowModelSelectionV1 = Static<typeof FlowModelSelectionSchema>;\n\nexport const FlowProfileV1Schema = StrictObject({\n\tschema: Type.Literal(\"humain-flow-profile\"),\n\tschemaVersion: Type.Literal(1),\n\tid: FlowIdSchema,\n\tversion: FlowPositiveIntSchema,\n\tdigest: FlowDigestSchema,\n\tkind: Type.Union([Type.Literal(\"direct\"), Type.Literal(\"flow\")]),\n\tlabel: Type.String({ minLength: 1, maxLength: 80 }),\n\tdescription: Type.Optional(Type.String({ maxLength: 500 })),\n\tdirect: Type.Optional(\n\t\tStrictObject({ model: FlowModelRefSchema, fallbacks: Type.Array(FlowModelRefSchema, { maxItems: 8 }) }),\n\t),\n\troles: Type.Optional(partialByRole(FlowRoleBindingSchema)),\n\tsizing: Type.Optional(\n\t\tStrictObject({\n\t\t\tclassifierPolicyId: FlowIdSchema,\n\t\t\tthresholds: StrictObject({\n\t\t\t\tmediumAt: Type.Number({ minimum: 0, maximum: 1_000_000 }),\n\t\t\t\tlargeAt: Type.Number({ minimum: 0, maximum: 1_000_000 }),\n\t\t\t}),\n\t\t\ttriageRole: Type.Literal(\"triage\"),\n\t\t\tmaxEscalations: Type.Union([Type.Literal(0), Type.Literal(1)]),\n\t\t}),\n\t),\n\tlimits: StrictObject({\n\t\tmaxAgents: Type.Integer({ minimum: 1, maximum: 256 }),\n\t\tmaxConcurrent: Type.Integer({ minimum: 1, maximum: 64 }),\n\t\tmaxDepth: Type.Integer({ minimum: 0, maximum: 3 }),\n\t\tmaxRetries: Type.Integer({ minimum: 0, maximum: 16 }),\n\t\tinactivityMs: Type.Integer({ minimum: 1, maximum: 86_400_000 }),\n\t\tciWaitMs: Type.Integer({ minimum: 0, maximum: 86_400_000 }),\n\t}),\n\tspend: StrictObject({\n\t\trunCapMicrousd: FlowMicrousdSchema,\n\t\twarnAtPct: Type.Integer({ minimum: 1, maximum: 99 }),\n\t\tperRoleCapMicrousd: Type.Optional(partialByRole(FlowMicrousdSchema)),\n\t}),\n\tmodelSelection: Type.Optional(FlowModelSelectionSchema),\n\tproviders: Type.Optional(StrictObject({ preference: Type.Array(FlowIdSchema, { maxItems: 16 }) })),\n\tapproval: Type.Optional(StrictObject({ approvedBy: FlowIdSchema, approvedAt: FlowTimestampSchema })),\n\tbuiltIn: Type.Optional(Type.Literal(true)),\n});\nexport type FlowProfileV1 = Static<typeof FlowProfileV1Schema>;\n\nconst Validator = compileFlow(FlowProfileV1Schema);\nconst REQUIRED_FLOW_ROLES = [\"lead\", \"worker\", \"reviewer\", \"qa\"] as const;\n\n/** Canonical text hashed (sha256 hex) to produce `digest`: the document without `digest`. */\nexport function flowProfileDigestInput(doc: FlowProfileV1): string {\n\treturn canonicalWithout(doc, \"digest\");\n}\n\nfunction selectionLayerValid(layer: FlowTierSelectionV1 | FlowCapabilitySelectionV1): boolean {\n\tconst refs = [...(layer.primary === undefined ? [] : [layer.primary]), ...(layer.backups ?? [])];\n\treturn !hasDuplicateModels(refs);\n}\n\nfunction modelSelectionValid(selection: FlowModelSelectionV1): boolean {\n\tconst layers = [...Object.values(selection.tiers ?? {}), ...Object.values(selection.capabilities ?? {})];\n\treturn layers.every(selectionLayerValid);\n}\n\nfunction crossFieldsValid(doc: FlowProfileV1): boolean {\n\tif (doc.modelSelection !== undefined && (doc.kind === \"direct\" || !modelSelectionValid(doc.modelSelection))) {\n\t\treturn false;\n\t}\n\tif (doc.kind === \"direct\") {\n\t\tif (doc.direct === undefined || doc.roles !== undefined || doc.sizing !== undefined) return false;\n\t\treturn !hasDuplicateModels([doc.direct.model, ...doc.direct.fallbacks]);\n\t}\n\tif (doc.direct !== undefined || doc.roles === undefined) return false;\n\tfor (const role of REQUIRED_FLOW_ROLES) if (doc.roles[role] === undefined) return false;\n\tfor (const binding of Object.values(doc.roles)) {\n\t\tconst refs: FlowModelRef[] = [binding.primary, ...binding.backups];\n\t\tif (hasDuplicateModels(refs)) return false;\n\t}\n\treturn doc.sizing === undefined || doc.sizing.thresholds.mediumAt <= doc.sizing.thresholds.largeAt;\n}\n\nfunction isProfile(value: unknown): value is FlowProfileV1 {\n\treturn Validator.Check(value) && crossFieldsValid(value);\n}\n\n/**\n * SHAPE ONLY: validates structure and cross-field rules but does NOT verify `digest`. Use only for documents whose\n * integrity is established elsewhere (e.g. authored drafts); prefer {@link parseFlowProfileV1}.\n */\nexport function parseFlowProfileV1Shape(input: unknown): FlowProfileV1 {\n\treturn parseFlowData(\"profile_invalid\", input, isProfile);\n}\n\n/** Shape validation plus digest verification with the injected hasher (digests are integrity, not authentication). */\nexport function parseFlowProfileV1(input: unknown, hasher: FlowDigestHasher): FlowProfileV1 {\n\tconst profile = parseFlowProfileV1Shape(input);\n\tif (!verifyFlowDigest(hasher, flowProfileDigestInput(profile), profile.digest)) {\n\t\tthrow new FlowContractError(\"digest_mismatch\");\n\t}\n\treturn profile;\n}\n"]}
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,QAAmB,CAAC;AACrD,eAAO,MAAM,iCAAiC,QAAmB,CAAC;AAClE,eAAO,MAAM,iCAAiC,QAAmB,CAAC;AAClE,eAAO,MAAM,uBAAuB,EAAG,kBAA2B,CAAC;AAEnE,QAAA,MAAM,kBAAkB,YAAI,aAAa,EAAE,YAAY,EAAE,aAAa,EAAE,aAAa,EAAE,cAAc,CAAU,CAAC;AAChH,KAAK,eAAe,GAAG,CAAC,OAAO,kBAAkB,CAAC,CAAC,MAAM,CAAC,CAAC;AAmD3D,MAAM,MAAM,cAAc,GACvB;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,QAAQ,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GAC/C;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,OAAO,CAAA;CAAE,GAC7B;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,WAAW,CAAA;CAAE,GACjC;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GACxD;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,gBAAgB,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,GAC3D,oBAAoB,CAAC;AAExB,MAAM,MAAM,aAAa,GAAG;IAC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CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAAE,CAAC;AAE1F,MAAM,MAAM,mBAAmB,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CAAE,CAAC;AAC3E,MAAM,MAAM,2BAA2B,GAAG;IAAE,gBAAgB,CAAC,EAAE,wBAAwB,CAAA;CAAE,CAAC;AAC1F,MAAM,MAAM,mCAAmC,GAAG,mBAAmB,GAAG;IACvE,IAAI,EAAE,uBAAuB,CAAC;CAC9B,GAAG,2BAA2B,CAAC;AAChC,MAAM,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
@@ -17,6 +17,7 @@ const FLOW_DISPOSITIONS = ["live", "queued", "rejected"];
17
17
  // test/rpc.test.ts keeps the lists in sync.
18
18
  const FLOW_REASON_CLASSES = [
19
19
  "provider_error",
20
+ "provider_unreachable",
20
21
  "rate_limit",
21
22
  "timeout",
22
23
  "check_failed",
package/dist/rpc.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"rpc.js","sourceRoot":"","sources":["../src/rpc.ts"],"names":[],"mappings":"AACA,OAAO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,CAAC,SAAS,CAAC,IAAc,CAAC,CAAC,CAAC,CACtD,CAAC;AACH,CAAC;AAED,SAAS,QAAQ,CAAC,KAAc;IAC/B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC7E,CAAC;AAED,SAAS,uBAAuB,CAAC,KAAc,EAAE,SAAiB;IACjE,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,IAAI,KAAK,CAAC,MAAM,IAAI,SAAS,CAAC;AACnF,CAAC;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\"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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AC;AACnF,CAAC;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"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@humain/humain-code-contracts",
3
- "version": "0.4.8",
3
+ "version": "0.4.10",
4
4
  "private": false,
5
5
  "description": "Runtime-neutral HUMAIN Code CLI execution and RPC wire contracts",
6
6
  "type": "module",