@humain/humain-code-contracts 0.3.2

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.
Files changed (51) hide show
  1. package/CHANGELOG.md +51 -0
  2. package/README.md +92 -0
  3. package/dist/index.d.ts +224 -0
  4. package/dist/index.d.ts.map +1 -0
  5. package/dist/index.js +218 -0
  6. package/dist/index.js.map +1 -0
  7. package/dist/orchestration.d.ts +327 -0
  8. package/dist/orchestration.d.ts.map +1 -0
  9. package/dist/orchestration.js +307 -0
  10. package/dist/orchestration.js.map +1 -0
  11. package/dist/rpc.d.ts +63 -0
  12. package/dist/rpc.d.ts.map +1 -0
  13. package/dist/rpc.js +147 -0
  14. package/dist/rpc.js.map +1 -0
  15. package/dist/subagent-progress.d.ts +106 -0
  16. package/dist/subagent-progress.d.ts.map +1 -0
  17. package/dist/subagent-progress.js +440 -0
  18. package/dist/subagent-progress.js.map +1 -0
  19. package/dist/testing.d.ts +390 -0
  20. package/dist/testing.d.ts.map +1 -0
  21. package/dist/testing.js +431 -0
  22. package/dist/testing.js.map +1 -0
  23. package/dist/trace-api.d.ts +293 -0
  24. package/dist/trace-api.d.ts.map +1 -0
  25. package/dist/trace-api.js +202 -0
  26. package/dist/trace-api.js.map +1 -0
  27. package/dist/trace-artifact.d.ts +94 -0
  28. package/dist/trace-artifact.d.ts.map +1 -0
  29. package/dist/trace-artifact.js +168 -0
  30. package/dist/trace-artifact.js.map +1 -0
  31. package/dist/trace-canonical.d.ts +23 -0
  32. package/dist/trace-canonical.d.ts.map +1 -0
  33. package/dist/trace-canonical.js +240 -0
  34. package/dist/trace-canonical.js.map +1 -0
  35. package/dist/trace-export.d.ts +94 -0
  36. package/dist/trace-export.d.ts.map +1 -0
  37. package/dist/trace-export.js +374 -0
  38. package/dist/trace-export.js.map +1 -0
  39. package/dist/trace-http.d.ts +1294 -0
  40. package/dist/trace-http.d.ts.map +1 -0
  41. package/dist/trace-http.js +1481 -0
  42. package/dist/trace-http.js.map +1 -0
  43. package/dist/trace-payload.d.ts +425 -0
  44. package/dist/trace-payload.d.ts.map +1 -0
  45. package/dist/trace-payload.js +1519 -0
  46. package/dist/trace-payload.js.map +1 -0
  47. package/dist/trace.d.ts +257 -0
  48. package/dist/trace.d.ts.map +1 -0
  49. package/dist/trace.js +1014 -0
  50. package/dist/trace.js.map +1 -0
  51. package/package.json +64 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"trace.js","sourceRoot":"","sources":["../src/trace.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,IAAI,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC3G,OAAO,EAAE,oBAAoB,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAElF,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AAEnC;;;;;;GAMG;AAEH,MAAM,YAAY,GAAG,CAAoD,UAAa,EAAE,EAAE,CACzF,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,EAAE,oBAAoB,EAAE,KAAK,EAAE,CAAC,CAAC;AAC1D,MAAM,eAAe,GAAG,IAAI,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,gBAAgB,EAAE,CAAC,CAAC;AACvF,MAAM,kBAAkB,GAAG,IAAI,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,gBAAgB,EAAE,CAAC,CAAC;AAC1F,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,gBAA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AK,SAAS;YACjC,UAAU,CAAC,aAAa,KAAK,SAAS;YACtC,KAAK,CAAC,aAAa,KAAK,UAAU,CAAC,aAAa,GAAG,CAAC,EACnD,CAAC;YACF,MAAM,CAAC,IAAI,CAAC,uDAAuD,CAAC,CAAC;QACtE,CAAC;IACF,CAAC;AACF,CAAC","sourcesContent":["import { type Static, Type } from \"typebox\";\nimport { Compile } from \"typebox/compile\";\nimport { assertDhPlainData, DhContractError, dhCanonicalText, parseDhRawJson } from \"./trace-canonical.ts\";\nimport { assertDhEventPayload, validateDhPayloadGraph } from \"./trace-payload.ts\";\n\nexport * from \"./trace-api.ts\";\nexport * from \"./trace-artifact.ts\";\nexport * from \"./trace-canonical.ts\";\nexport * from \"./trace-export.ts\";\nexport * from \"./trace-http.ts\";\nexport * from \"./trace-payload.ts\";\n\n/**\n * HUMAIN Code agent-activity trace wire contract (v1), shared by Code, CLI and Flow producers.\n *\n * Three independent axes are never conflated: execution outcome (`outcome`), capture coverage\n * (`DhCoverage`) and transfer state (`DhAck`). Producers redact before upload; the server\n * re-checks `tenantScope`, which is producer-declared only and never trusted on its own.\n */\n\nconst StrictObject = <const T extends Parameters<typeof Type.Object>[0]>(properties: T) =>\n\tType.Object(properties, { additionalProperties: false });\nconst PositiveInteger = Type.Integer({ minimum: 1, maximum: Number.MAX_SAFE_INTEGER });\nconst NonnegativeInteger = Type.Integer({ minimum: 0, maximum: Number.MAX_SAFE_INTEGER });\nconst Digest = Type.String({ pattern: \"^[a-f0-9]{64}$\" });\nconst SafeArtifactReference = Type.String({\n\tminLength: 1,\n\tmaxLength: 512,\n\tpattern: \"^(?!/)(?!.*(?:^|/)\\\\.\\\\.(?:/|$))[A-Za-z0-9._-]+(?:/[A-Za-z0-9._-]+)*$\",\n});\nconst BoundedString = (maxLength: number) => Type.String({ minLength: 1, maxLength });\nconst ShortString = BoundedString(256);\nconst DetailString = Type.String({ minLength: 1, maxLength: 1024 });\nconst IsoUtcTimestamp = Type.String({\n\tminLength: 20,\n\tmaxLength: 30,\n\tpattern: \"^\\\\d{4}-\\\\d{2}-\\\\d{2}T\\\\d{2}:\\\\d{2}:\\\\d{2}(?:\\\\.\\\\d{1,9})?Z$\",\n});\n\nexport const DH_TRACE_CONTRACT_VERSION = 1 as const;\nexport const DH_EVENT_SCHEMA_ID = \"dh.event/1\" as const;\nexport const DH_ARTIFACT_SCHEMA_ID = \"dh.artifact/1\" as const;\nexport const DH_ACK_SCHEMA_ID = \"dh.ack/1\" as const;\n\nexport const DH_EVENT_MAX_UTF8_BYTES = 65536;\nexport const DH_ARTIFACT_MAX_BYTES = 64 * 1024 * 1024;\nexport const DH_MAX_EXTERNAL_IDS = 16;\nexport const DH_MAX_PAYLOAD_PROPERTIES = 128;\nexport const DH_MAX_FIELD_COVERAGE_ENTRIES = 64;\nexport const DH_MAX_ARTIFACT_REFS = 32;\nexport const DH_MAX_REMOVED_FIELD_PATHS = 256;\nexport const DH_MAX_ACK_IDS = 1000;\n/** Maximum container nesting of `payload` (the payload object itself is depth 1). */\nexport const DH_PAYLOAD_MAX_DEPTH = 16;\n/** Maximum number of JSON values (containers and scalars, root included) in one `payload`. */\nexport const DH_PAYLOAD_MAX_NODES = 4096;\n/** Maximum length of any object key inside `payload`, at any depth. */\nexport const DH_PAYLOAD_MAX_KEY_LENGTH = 128;\n/** Maximum length of a `fields` key (field path). */\nexport const DH_FIELD_PATH_MAX_LENGTH = 256;\n\n// ---------------------------------------------------------------------------\n// External ids and canonical trace ids\n// ---------------------------------------------------------------------------\n\nexport const DH_ISSUERS = [\"code\", \"cli\", \"flow\"] as const;\nexport type DhIssuer = (typeof DH_ISSUERS)[number];\nexport const DhIssuerSchema = Type.Enum(DH_ISSUERS);\n\n/** Producer-native id mapped onto the canonical trace id space (e.g. code.run, cli.session, flow.launch). */\nexport const DhExternalIdSchema = StrictObject({\n\tissuer: DhIssuerSchema,\n\tnamespace: Type.String({ pattern: \"^[a-z][a-z0-9_.-]{0,63}$\", maxLength: 64 }),\n\tvalue: ShortString,\n\tmappingVersion: PositiveInteger,\n});\nexport type DhExternalId = Static<typeof DhExternalIdSchema>;\n\nconst prefixedId = (prefix: string) =>\n\tType.String({\n\t\tpattern: `^${prefix}_[A-Za-z0-9_-]{8,128}$`,\n\t\tminLength: prefix.length + 9,\n\t\tmaxLength: prefix.length + 129,\n\t});\n\nexport const DhGenerationIdSchema = prefixedId(\"gen\");\nexport const DhAgentIdSchema = prefixedId(\"agt\");\nexport const DhAttemptIdSchema = prefixedId(\"att\");\nexport const DhEventIdSchema = prefixedId(\"evt\");\nexport const DhArtifactIdSchema = prefixedId(\"art\");\n\n// ---------------------------------------------------------------------------\n// Coverage\n// ---------------------------------------------------------------------------\n\nexport const DH_COVERAGE_STATES = [\n\t\"captured\",\n\t\"redacted\",\n\t\"truncated\",\n\t\"unavailable\",\n\t\"not-applicable\",\n\t\"inferred\",\n] as const;\nexport type DhCoverageState = (typeof DH_COVERAGE_STATES)[number];\n\nexport const DH_COVERAGE_REASONS = [\n\t\"secret_redacted\",\n\t\"policy_redacted\",\n\t\"size_limit\",\n\t\"producer_lost\",\n\t\"worker_exited_before_flush\",\n\t\"legacy_producer\",\n\t\"not_captured_by_version\",\n\t\"provider_hidden\",\n\t\"not_applicable\",\n\t\"derived_from_summary\",\n] as const;\nexport type DhCoverageReason = (typeof DH_COVERAGE_REASONS)[number];\n\n/**\n * Per-field or per-artifact capture coverage. A `reason` is REQUIRED for every state except\n * `captured` (enforced by the parse functions, not by the schema alone).\n *\n * `inferred` means the value was derived (e.g. from a summary) rather than recorded. Consumers\n * MUST NOT present an `inferred` value as a recorded fact.\n */\nexport const DhCoverageSchema = StrictObject({\n\tstate: Type.Enum(DH_COVERAGE_STATES),\n\treason: Type.Optional(Type.Enum(DH_COVERAGE_REASONS)),\n\tdetail: Type.Optional(DetailString),\n});\nexport type DhCoverage = Static<typeof DhCoverageSchema>;\n\n// ---------------------------------------------------------------------------\n// Shared sub-schemas\n// ---------------------------------------------------------------------------\n\nexport const DhRedactionSchema = StrictObject({\n\tpolicyId: ShortString,\n\tpolicyVersion: ShortString,\n\tremovedFieldPaths: Type.Array(BoundedString(512), { maxItems: DH_MAX_REMOVED_FIELD_PATHS }),\n});\nexport type DhRedaction = Static<typeof DhRedactionSchema>;\n\n/** Producer-declared scope. The server re-checks it against the authenticated producer binding. */\nexport const DH_SCOPE_ID_PATTERN = \"^[A-Za-z0-9][A-Za-z0-9_.-]{0,255}$\";\nexport const DhScopeIdSchema = Type.String({ minLength: 1, maxLength: 256, pattern: DH_SCOPE_ID_PATTERN });\nexport const DhStreamIdSchema = Type.String({ minLength: 1, maxLength: 128, pattern: \"^[A-Za-z0-9_-]{1,128}$\" });\nexport const DhTenantScopeSchema = StrictObject({\n\tenvironmentId: DhScopeIdSchema,\n\tprojectId: DhScopeIdSchema,\n});\nexport type DhTenantScope = Static<typeof DhTenantScopeSchema>;\n\nexport const DH_EVENT_KINDS = [\n\t\"generation.started\",\n\t\"generation.finished\",\n\t\"agent.spawned\",\n\t\"attempt.started\",\n\t\"attempt.finished\",\n\t\"attempt.retry_scheduled\",\n\t\"model.request\",\n\t\"model.response\",\n\t\"tool.call\",\n\t\"tool.result\",\n\t\"file.change\",\n\t\"orchestration.decision\",\n\t\"cancellation.requested\",\n\t\"cancellation.outcome\",\n\t\"usage.reported\",\n\t// Added with typed payloads (dh.payload.*/1): no legacy freeform shape, `payload.schema` is required.\n\t// Amended into dh.event/1 before any deployment (C0 freeze doc, section 1.15). The exact list is pinned by\n\t// test/trace-payload-conformance.test.ts and the freeze digest: a further kind is a deliberate, reviewed change.\n\t\"capture.health\",\n\t\"control.correlation\",\n\t\"event.amendment\",\n] as const;\nexport type DhEventKind = (typeof DH_EVENT_KINDS)[number];\n\nexport const DH_OUTCOMES = [\"succeeded\", \"failed\", \"cancelled\", \"unknown\"] as const;\nexport type DhOutcome = (typeof DH_OUTCOMES)[number];\n\nexport const DhFailureSchema = StrictObject({\n\tcode: Type.String({ pattern: \"^[a-z][a-z0-9_.-]{0,63}$\", maxLength: 64 }),\n\tmessage: Type.Optional(DetailString),\n});\nexport type DhFailure = Static<typeof DhFailureSchema>;\n\n// ---------------------------------------------------------------------------\n// Event\n// ---------------------------------------------------------------------------\n\nexport const DhEventV1Schema = StrictObject({\n\tschema: Type.Literal(DH_EVENT_SCHEMA_ID),\n\teventId: DhEventIdSchema,\n\tgenerationId: DhGenerationIdSchema,\n\tagentId: DhAgentIdSchema,\n\tattemptId: Type.Optional(DhAttemptIdSchema),\n\tparentAgentId: Type.Optional(DhAgentIdSchema),\n\tproducer: StrictObject({\n\t\tissuer: DhIssuerSchema,\n\t\tversion: ShortString,\n\t\tmode: ShortString,\n\t}),\n\texternalIds: Type.Array(DhExternalIdSchema, { maxItems: DH_MAX_EXTERNAL_IDS }),\n\t/** Monotonic per producer stream. */\n\tsequence: NonnegativeInteger,\n\tstreamId: DhStreamIdSchema,\n\toccurredAt: IsoUtcTimestamp,\n\trecordedAt: IsoUtcTimestamp,\n\tkind: Type.Enum(DH_EVENT_KINDS),\n\toutcome: Type.Optional(Type.Enum(DH_OUTCOMES)),\n\tfailure: Type.Optional(DhFailureSchema),\n\tretryOfAttemptId: Type.Optional(DhAttemptIdSchema),\n\tattemptNumber: Type.Optional(PositiveInteger),\n\t/**\n\t * JSON-safe values only. TypeBox cannot express the depth, node, key-length or forbidden-key\n\t * limits (and drops `maxLength` on Record key schemas), so `parseDhEvent` enforces them with\n\t * `assertJsonPayload` before cloning.\n\t */\n\tpayload: Type.Record(Type.String(), Type.Unknown(), {\n\t\tmaxProperties: DH_MAX_PAYLOAD_PROPERTIES,\n\t}),\n\t/**\n\t * Field path (e.g. `payload.messages`) -> coverage for that field. Key length and pattern are\n\t * enforced by `parseDhEvent` (`assertFieldPaths`), not by the schema.\n\t */\n\tfields: Type.Record(Type.String(), DhCoverageSchema, {\n\t\tmaxProperties: DH_MAX_FIELD_COVERAGE_ENTRIES,\n\t}),\n\tartifacts: Type.Optional(Type.Array(DhArtifactIdSchema, { maxItems: DH_MAX_ARTIFACT_REFS })),\n\tredaction: DhRedactionSchema,\n\ttenantScope: DhTenantScopeSchema,\n});\nexport type DhJsonValue =\n\t| null\n\t| boolean\n\t| number\n\t| string\n\t| readonly DhJsonValue[]\n\t| { readonly [key: string]: DhJsonValue };\nexport type DhEventV1 = Omit<Static<typeof DhEventV1Schema>, \"payload\"> & {\n\tpayload: { readonly [key: string]: DhJsonValue };\n};\n\n// ---------------------------------------------------------------------------\n// Artifact\n// ---------------------------------------------------------------------------\n\nexport const DH_ARTIFACT_KINDS = [\n\t\"file-diff\",\n\t\"file-snapshot\",\n\t\"tool-output\",\n\t\"model-context\",\n\t\"log\",\n\t\"bundle\",\n] as const;\nexport type DhArtifactKind = (typeof DH_ARTIFACT_KINDS)[number];\n\nexport const DH_ARTIFACT_MEDIA_TYPES = [\n\t\"text/plain\",\n\t\"text/x-diff\",\n\t\"application/json\",\n\t\"application/octet-stream\",\n] as const;\nexport type DhArtifactMediaType = (typeof DH_ARTIFACT_MEDIA_TYPES)[number];\n\nexport const DhArtifactV1Schema = StrictObject({\n\tschema: Type.Literal(DH_ARTIFACT_SCHEMA_ID),\n\tartifactId: DhArtifactIdSchema,\n\tgenerationId: DhGenerationIdSchema,\n\tagentId: DhAgentIdSchema,\n\tattemptId: Type.Optional(DhAttemptIdSchema),\n\teventId: DhEventIdSchema,\n\tkind: Type.Enum(DH_ARTIFACT_KINDS),\n\tmediaType: Type.Enum(DH_ARTIFACT_MEDIA_TYPES),\n\tsizeBytes: Type.Integer({ minimum: 0, maximum: DH_ARTIFACT_MAX_BYTES }),\n\tsha256: Digest,\n\tlogicalPath: Type.Optional(SafeArtifactReference),\n\tcoverage: DhCoverageSchema,\n\tredaction: DhRedactionSchema,\n\ttenantScope: DhTenantScopeSchema,\n});\nexport type DhArtifactV1 = Static<typeof DhArtifactV1Schema>;\n\n// ---------------------------------------------------------------------------\n// Ack\n// ---------------------------------------------------------------------------\n\nexport const DH_REJECTION_CODES = [\n\t\"duplicate_conflict\",\n\t\"schema_invalid\",\n\t\"scope_denied\",\n\t\"tombstoned\",\n\t\"too_large\",\n\t\"rate_limited\",\n] as const;\nexport type DhRejectionCode = (typeof DH_REJECTION_CODES)[number];\n\n/**\n * Server acknowledgement for a producer stream. Delivering an identical record again is accepted\n * idempotently (it appears in `accepted`); delivering the same id with different content is\n * rejected as `duplicate_conflict` and never overwrites the stored record.\n */\nexport const DhAckV1Schema = StrictObject({\n\tschema: Type.Literal(DH_ACK_SCHEMA_ID),\n\tstreamId: DhStreamIdSchema,\n\tackedThroughSequence: NonnegativeInteger,\n\taccepted: StrictObject({\n\t\teventIds: Type.Array(DhEventIdSchema, { maxItems: DH_MAX_ACK_IDS }),\n\t\tartifactIds: Type.Array(DhArtifactIdSchema, { maxItems: DH_MAX_ACK_IDS }),\n\t}),\n\trejected: Type.Array(\n\t\tStrictObject({\n\t\t\tid: Type.String({ pattern: \"^(?:evt|art)_[A-Za-z0-9_-]{8,128}$\", maxLength: 136 }),\n\t\t\tcode: Type.Enum(DH_REJECTION_CODES),\n\t\t\tretryable: Type.Boolean(),\n\t\t}),\n\t\t{ maxItems: DH_MAX_ACK_IDS },\n\t),\n\treceivedAt: IsoUtcTimestamp,\n});\nexport type DhAckV1 = Static<typeof DhAckV1Schema>;\n\n// ---------------------------------------------------------------------------\n// Parsing\n// ---------------------------------------------------------------------------\n\nconst EventValidator = Compile(DhEventV1Schema);\nconst ArtifactValidator = Compile(DhArtifactV1Schema);\nconst AckValidator = Compile(DhAckV1Schema);\nconst textEncoder = new TextEncoder();\n\nfunction schemaError(label: string, errors: readonly { instancePath: string }[]): Error {\n\tconst field = errors[0]?.instancePath.split(\"/\")[1];\n\tconst properties =\n\t\tlabel === \"dh.event/1\"\n\t\t\t? DhEventV1Schema.properties\n\t\t\t: label === \"dh.artifact/1\"\n\t\t\t\t? DhArtifactV1Schema.properties\n\t\t\t\t: DhAckV1Schema.properties;\n\tconst where = field !== undefined && Object.hasOwn(properties, field) ? ` at /${field}` : \"\";\n\treturn new DhContractError(\"schema_invalid\", `Invalid ${label}${where}`);\n}\n\nfunction assertCoverage(label: string, coverage: DhCoverage): void {\n\tif (coverage.state !== \"captured\" && coverage.reason === undefined) {\n\t\tthrow new DhContractError(\"schema_invalid\", `Invalid ${label}: coverage has state but no reason`);\n\t}\n}\n\nconst FORBIDDEN_KEYS: ReadonlySet<string> = new Set([\"__proto__\", \"constructor\", \"prototype\"]);\nconst FIELD_PATH_PATTERN = /^[A-Za-z][A-Za-z0-9_-]*(?:\\.[A-Za-z0-9_-]+)*$/;\nconst TIMESTAMP_PARTS = /^(\\d{4})-(\\d{2})-(\\d{2})T(\\d{2}):(\\d{2}):(\\d{2})(?:\\.(\\d{1,9}))?Z$/;\n\n/**\n * Returns the UTC instant (epoch milliseconds, sub-millisecond digits ignored) of a calendar-valid\n * timestamp, or undefined. `Date.parse` rolls impossible dates over (2025-02-30 becomes 03-02), so\n * the parsed instant must round-trip to the same calendar fields.\n */\nfunction parseInstant(timestamp: string): number | undefined {\n\tconst parts = TIMESTAMP_PARTS.exec(timestamp);\n\tif (parts === null) return undefined;\n\tconst [, year, month, day, hour, minute, second, fraction] = parts;\n\tconst base = `${year}-${month}-${day}T${hour}:${minute}:${second}`;\n\tconst whole = Date.parse(`${base}.000Z`);\n\tif (Number.isNaN(whole)) return undefined;\n\tif (new Date(whole).toISOString().slice(0, 19) !== base) return undefined;\n\treturn whole + (fraction === undefined ? 0 : Number(fraction.slice(0, 3).padEnd(3, \"0\")));\n}\n\nfunction assertTimestamp(label: string, path: string, timestamp: string): void {\n\tif (parseInstant(timestamp) === undefined) {\n\t\tthrow new DhContractError(\"schema_invalid\", `Invalid ${label}: ${path} is not a calendar-valid UTC instant`);\n\t}\n}\n\nfunction assertFieldPaths(fields: Record<string, DhCoverage>): void {\n\tfor (const path of Object.keys(fields)) {\n\t\tif (path.length > DH_FIELD_PATH_MAX_LENGTH) {\n\t\t\tthrow new DhContractError(\n\t\t\t\t\"schema_invalid\",\n\t\t\t\t`Invalid dh.event/1: fields key exceeds ${DH_FIELD_PATH_MAX_LENGTH} characters`,\n\t\t\t);\n\t\t}\n\t\tif (!FIELD_PATH_PATTERN.test(path) || path.split(\".\").some((segment) => FORBIDDEN_KEYS.has(segment))) {\n\t\t\tthrow new DhContractError(\"schema_invalid\", \"Invalid dh.event/1: fields key is not a valid field path\");\n\t\t}\n\t}\n}\n\nfunction fail(_path: string, reason: string): never {\n\tthrow new DhContractError(\n\t\treason.startsWith(\"exceeds\") ? \"too_large\" : \"schema_invalid\",\n\t\t`Invalid dh.event/1: payload ${reason}`,\n\t);\n}\n\n/**\n * Iterative (non-recursive) walk that admits only JSON-safe values: null, boolean, finite number,\n * string, array and plain object. Enforces depth, total node count and key limits, and rejects the\n * keys `__proto__`, `constructor` and `prototype` at any depth, plus accessor properties on both\n * objects and arrays. Counting happens when a value is queued, so the work stack never exceeds\n * `DH_PAYLOAD_MAX_NODES` entries. Keys come from `Object.keys`, which includes own `__proto__`\n * properties created by `JSON.parse`, so the same walk is safe to run on a parsed result.\n */\nfunction assertJsonPayload(payload: object): void {\n\tconst stack: { value: unknown; depth: number; path: string }[] = [{ value: payload, depth: 1, path: \"payload\" }];\n\tlet nodes = 1;\n\twhile (stack.length > 0) {\n\t\tconst item = stack.pop();\n\t\tif (item === undefined) break;\n\t\tconst { value, depth, path } = item;\n\t\tif (value === null || typeof value === \"boolean\" || typeof value === \"string\") continue;\n\t\tif (typeof value === \"number\") {\n\t\t\tif (!Number.isFinite(value)) fail(path, \"is not a finite number\");\n\t\t\tcontinue;\n\t\t}\n\t\tif (typeof value !== \"object\") fail(path, `has non-JSON type ${typeof value}`);\n\t\tif (depth > DH_PAYLOAD_MAX_DEPTH) fail(path, `exceeds maximum nesting depth ${DH_PAYLOAD_MAX_DEPTH}`);\n\t\tconst container = value as object;\n\t\tconst children: [string, unknown][] = [];\n\t\tif (Array.isArray(container)) {\n\t\t\tif (nodes + container.length > DH_PAYLOAD_MAX_NODES) {\n\t\t\t\tfail(path, `exceeds maximum of ${DH_PAYLOAD_MAX_NODES} payload nodes`);\n\t\t\t}\n\t\t\tfor (let index = 0; index < container.length; index++) {\n\t\t\t\tconst descriptor = Object.getOwnPropertyDescriptor(container, String(index));\n\t\t\t\tif (descriptor === undefined) fail(path, \"is a sparse array\");\n\t\t\t\tif (!(\"value\" in descriptor)) fail(`${path}[${index}]`, \"is an accessor property\");\n\t\t\t\tchildren.push([`${path}[${index}]`, descriptor.value]);\n\t\t\t}\n\t\t} else {\n\t\t\tconst proto = Object.getPrototypeOf(container);\n\t\t\tif (proto !== Object.prototype && proto !== null) fail(path, \"is not a plain object\");\n\t\t\tconst keys = Object.keys(container);\n\t\t\tif (keys.length > DH_MAX_PAYLOAD_PROPERTIES)\n\t\t\t\tfail(path, `exceeds maximum of ${DH_MAX_PAYLOAD_PROPERTIES} payload properties`);\n\t\t\tif (nodes + keys.length > DH_PAYLOAD_MAX_NODES) {\n\t\t\t\tfail(path, `exceeds maximum of ${DH_PAYLOAD_MAX_NODES} payload nodes`);\n\t\t\t}\n\t\t\tfor (const key of keys) {\n\t\t\t\tif (key.length > DH_PAYLOAD_MAX_KEY_LENGTH) {\n\t\t\t\t\tfail(path, `has a key longer than ${DH_PAYLOAD_MAX_KEY_LENGTH} characters`);\n\t\t\t\t}\n\t\t\t\tif (FORBIDDEN_KEYS.has(key)) fail(path, `has forbidden key \"${key}\"`);\n\t\t\t\tconst descriptor = Object.getOwnPropertyDescriptor(container, key);\n\t\t\t\tif (descriptor === undefined || !(\"value\" in descriptor)) fail(`${path}.${key}`, \"is an accessor property\");\n\t\t\t\tchildren.push([`${path}.${key}`, descriptor?.value]);\n\t\t\t}\n\t\t}\n\t\tnodes += children.length;\n\t\tfor (const [childPath, child] of children) stack.push({ value: child, depth: depth + 1, path: childPath });\n\t}\n}\n\n/**\n * Attempt-linked fields need an `attemptId`: attempt lifecycle kinds, retry links and attempt\n * numbers are meaningless (and would skip attempt validation) without one. Returns the violated\n * rule, or undefined.\n */\nfunction attemptIdViolation(event: {\n\tkind: DhEventKind;\n\tattemptId?: string;\n\tretryOfAttemptId?: string;\n\tattemptNumber?: number;\n}): string | undefined {\n\tif (event.attemptId !== undefined) return undefined;\n\tif (\n\t\tevent.kind === \"attempt.started\" ||\n\t\tevent.kind === \"attempt.finished\" ||\n\t\tevent.kind === \"attempt.retry_scheduled\"\n\t) {\n\t\treturn \"attemptId is required on attempt lifecycle events\";\n\t}\n\tif (event.retryOfAttemptId !== undefined) return \"attemptId is required when retryOfAttemptId is present\";\n\tif (event.attemptNumber !== undefined) return \"attemptId is required when attemptNumber is present\";\n\treturn undefined;\n}\n\nfunction deepFreeze<T>(root: T): T {\n\tconst stack: unknown[] = [root];\n\twhile (stack.length > 0) {\n\t\tconst value = stack.pop();\n\t\tif (value === null || typeof value !== \"object\" || Object.isFrozen(value)) continue;\n\t\tObject.freeze(value);\n\t\tfor (const child of Object.values(value)) stack.push(child);\n\t}\n\treturn root;\n}\n\n/** Content checks the schema cannot express. Run on the input and again on the serialized clone. */\nfunction assertEventContent(event: DhEventV1): void {\n\tassertJsonPayload(event.payload);\n\tassertFieldPaths(event.fields);\n\tassertTimestamp(\"dh.event/1\", \"occurredAt\", event.occurredAt);\n\tassertTimestamp(\"dh.event/1\", \"recordedAt\", event.recordedAt);\n\tfor (const coverage of Object.values(event.fields)) {\n\t\tassertCoverage(\"dh.event/1\", coverage);\n\t}\n\tconst violation = attemptIdViolation(event);\n\tif (violation !== undefined) throw new DhContractError(\"schema_invalid\", `Invalid dh.event/1: ${violation}`);\n}\n\n/**\n * The input is validated, serialized exactly once, and the serialized string is parsed and fully\n * re-validated. The shared descriptor gate rejects getters and toJSON before invocation.\n * The byte limit is measured on the same canonical string returned by serialization.\n */\nexport function parseDhEvent(value: unknown): DhEventV1 {\n\tif (value instanceof Uint8Array) value = parseDhRawJson(value, { maxBytes: DH_EVENT_MAX_UTF8_BYTES });\n\tassertDhPlainData(value);\n\tif (!EventValidator.Check(value)) throw schemaError(\"dh.event/1\", EventValidator.Errors(value));\n\tassertEventContent(value as DhEventV1);\n\tconst text = dhCanonicalText(value);\n\tif (textEncoder.encode(text).length > DH_EVENT_MAX_UTF8_BYTES) {\n\t\tthrow new DhContractError(\"too_large\", \"Invalid dh.event/1: exceeds UTF-8 bytes limit\");\n\t}\n\tconst parsed: unknown = JSON.parse(text);\n\tif (!EventValidator.Check(parsed)) throw schemaError(\"dh.event/1\", EventValidator.Errors(parsed));\n\tassertEventContent(parsed as DhEventV1);\n\tassertDhEventPayload(parsed as DhEventV1);\n\treturn deepFreeze(parsed as DhEventV1);\n}\n\nexport function parseDhArtifact(value: unknown): DhArtifactV1 {\n\tassertDhPlainData(value);\n\tif (!ArtifactValidator.Check(value)) throw schemaError(\"dh.artifact/1\", ArtifactValidator.Errors(value));\n\tassertCoverage(\"dh.artifact/1\", value.coverage);\n\tconst parsed: unknown = JSON.parse(dhCanonicalText(value));\n\tif (!ArtifactValidator.Check(parsed)) throw schemaError(\"dh.artifact/1\", ArtifactValidator.Errors(parsed));\n\tassertCoverage(\"dh.artifact/1\", parsed.coverage);\n\treturn deepFreeze(parsed);\n}\n\nexport function parseDhAck(value: unknown): DhAckV1 {\n\tassertDhPlainData(value);\n\tif (!AckValidator.Check(value)) throw schemaError(\"dh.ack/1\", AckValidator.Errors(value));\n\tassertTimestamp(\"dh.ack/1\", \"receivedAt\", value.receivedAt);\n\tconst parsed: unknown = JSON.parse(dhCanonicalText(value));\n\tif (!AckValidator.Check(parsed)) throw schemaError(\"dh.ack/1\", AckValidator.Errors(parsed));\n\tassertTimestamp(\"dh.ack/1\", \"receivedAt\", parsed.receivedAt);\n\treturn deepFreeze(parsed);\n}\n\n// ---------------------------------------------------------------------------\n// Managed lifecycle and durable contextual retry admission\n// ---------------------------------------------------------------------------\n\nexport interface DhReceiptOwner {\n\treadonly bindingId: string;\n\treadonly originProducerInstanceId: string;\n\treadonly originStreamId: string;\n\treadonly originIssuer: DhIssuer;\n}\nexport interface DhTerminalOwnership {\n\treadonly authorizedAmendmentEventIds: ReadonlySet<string>;\n\treadonly receiptOwners: ReadonlyMap<string, DhReceiptOwner>;\n}\nexport interface DhRetryAdmissionContext extends DhTerminalOwnership {\n\treadonly starts: readonly DhEventV1[];\n\treadonly terminals: readonly DhEventV1[];\n\treadonly amendments: readonly DhEventV1[];\n\treadonly retryClaims: ReadonlyMap<string, string>;\n}\nexport interface DhEffectiveTerminal {\n\treadonly event: DhEventV1;\n\treadonly outcome: DhOutcome | undefined;\n\treadonly resolutionEventId?: string;\n\treadonly conflict: boolean;\n\treadonly authorityUnresolved: boolean;\n}\n\n/** Single-record shape only. It never treats a retry link as proof that its source failed. */\nexport function assertDhManagedLifecycle(input: DhEventV1): void {\n\tconst event = parseDhEvent(input);\n\tconst payload = event.payload;\n\tif (\n\t\t![\"attempt.started\", \"attempt.finished\", \"attempt.retry_scheduled\"].includes(event.kind) ||\n\t\tpayload.schema !== \"dh.payload.attempt-lifecycle/1\"\n\t)\n\t\tthrow new DhContractError(\"schema_invalid\");\n\tif (event.retryOfAttemptId !== undefined && event.kind !== \"attempt.started\")\n\t\tthrow new DhContractError(\"schema_invalid\");\n\tif (\n\t\tevent.attemptNumber !== undefined &&\n\t\t(!Number.isSafeInteger(event.attemptNumber) || event.attemptNumber < 1 || event.attemptNumber > 10000)\n\t)\n\t\tthrow new DhContractError(\"schema_invalid\");\n\tif (\n\t\tevent.kind === \"attempt.started\" &&\n\t\t(event.attemptNumber === undefined ||\n\t\t\tpayload.attemptNumber !== event.attemptNumber ||\n\t\t\tevent.outcome !== undefined ||\n\t\t\tevent.failure !== undefined)\n\t)\n\t\tthrow new DhContractError(\"schema_invalid\");\n\tif (\n\t\tevent.kind === \"attempt.retry_scheduled\" &&\n\t\t(typeof payload.nextAttemptNumber !== \"number\" ||\n\t\t\tpayload.nextAttemptNumber < 2 ||\n\t\t\tpayload.nextAttemptNumber > 10000)\n\t)\n\t\tthrow new DhContractError(\"schema_invalid\");\n}\n\n/** Original terminals remain immutable. Only committed, explicitly authorized same-owner resolutions apply. */\nexport function resolveDhEffectiveTerminals(\n\tevents: readonly DhEventV1[],\n\townership?: DhTerminalOwnership,\n): ReadonlyMap<string, DhEffectiveTerminal> {\n\tconst terminals = new Map<string, DhEffectiveTerminal>();\n\tconst byId = new Map<string, DhEventV1>();\n\tfor (const event of events) {\n\t\tbyId.set(event.eventId, event);\n\t\tif (event.kind !== \"attempt.finished\" || event.attemptId === undefined) continue;\n\t\tconst prior = terminals.get(event.attemptId);\n\t\tterminals.set(event.attemptId, {\n\t\t\tevent: prior?.event ?? event,\n\t\t\toutcome: prior?.outcome ?? event.outcome,\n\t\t\tconflict: prior !== undefined,\n\t\t\tauthorityUnresolved: prior?.authorityUnresolved ?? false,\n\t\t});\n\t}\n\tconst resolutions = new Set<string>();\n\tfor (const amendment of events) {\n\t\tif (\n\t\t\tamendment.kind !== \"event.amendment\" ||\n\t\t\tamendment.payload.schema !== \"dh.payload.amendment/1\" ||\n\t\t\tamendment.payload.relation !== \"resolves-unknown\"\n\t\t)\n\t\t\tcontinue;\n\t\tconst target = byId.get(String(amendment.payload.amendsEventId));\n\t\tif (target?.kind !== \"attempt.finished\" || target.attemptId === undefined) continue;\n\t\tconst terminal = terminals.get(target.attemptId);\n\t\tif (!terminal) continue;\n\t\tconst replacement = amendment.payload.replacement;\n\t\tconst outcome =\n\t\t\treplacement !== null && typeof replacement === \"object\" && !Array.isArray(replacement)\n\t\t\t\t? (replacement as { outcome?: DhOutcome }).outcome\n\t\t\t\t: undefined;\n\t\tconst a = ownership?.receiptOwners.get(target.eventId);\n\t\tconst b = ownership?.receiptOwners.get(amendment.eventId);\n\t\tconst sameOwner =\n\t\t\ta !== undefined &&\n\t\t\tb !== undefined &&\n\t\t\ta.bindingId === b.bindingId &&\n\t\t\ta.originProducerInstanceId === b.originProducerInstanceId &&\n\t\t\ta.originStreamId === b.originStreamId &&\n\t\t\ta.originIssuer === b.originIssuer &&\n\t\t\ta.originStreamId === target.streamId &&\n\t\t\tb.originStreamId === amendment.streamId &&\n\t\t\ta.originIssuer === target.producer.issuer &&\n\t\t\tb.originIssuer === amendment.producer.issuer;\n\t\tconst conflict =\n\t\t\tterminal.conflict ||\n\t\t\tresolutions.has(target.eventId) ||\n\t\t\ttarget.outcome !== \"unknown\" ||\n\t\t\ttarget.agentId !== amendment.agentId ||\n\t\t\ttarget.attemptId !== amendment.attemptId ||\n\t\t\ttarget.generationId !== amendment.generationId ||\n\t\t\tscopeKey(target.tenantScope) !== scopeKey(amendment.tenantScope) ||\n\t\t\ttarget.streamId !== amendment.streamId ||\n\t\t\ttarget.sequence >= amendment.sequence ||\n\t\t\tamendment.payload.amendsKind !== target.kind ||\n\t\t\t!outcome ||\n\t\t\toutcome === \"unknown\";\n\t\tconst authorized = ownership?.authorizedAmendmentEventIds.has(amendment.eventId) === true && sameOwner;\n\t\tresolutions.add(target.eventId);\n\t\tterminals.set(target.attemptId, {\n\t\t\tevent: terminal.event,\n\t\t\toutcome: !conflict && authorized ? outcome : terminal.outcome,\n\t\t\t...(authorized && !conflict ? { resolutionEventId: amendment.eventId } : {}),\n\t\t\tconflict,\n\t\t\tauthorityUnresolved: terminal.authorityUnresolved || !authorized,\n\t\t});\n\t}\n\treturn terminals;\n}\n\n/** Eligibility uses durable authenticated context, not source absence or producer timestamps. */\nexport function assertDhRetryAdmission(start: DhEventV1, context: DhRetryAdmissionContext): void {\n\tassertDhManagedLifecycle(start);\n\tif (start.kind !== \"attempt.started\") throw new DhContractError(\"schema_invalid\");\n\tfunction deny(): never {\n\t\tthrow new DhContractError(\"not_eligible\");\n\t}\n\tconst target = context.starts.find((event) => event.attemptId === start.attemptId);\n\tif (target) {\n\t\tif (\n\t\t\tstart.retryOfAttemptId !== undefined &&\n\t\t\tcontext.retryClaims.get(start.retryOfAttemptId) === start.attemptId &&\n\t\t\tdhCanonicalText(target) === dhCanonicalText(start)\n\t\t)\n\t\t\treturn;\n\t\tdeny();\n\t}\n\tconst priorId = start.retryOfAttemptId;\n\tconst starts = context.starts.filter((event) => event.kind === \"attempt.started\" && event.agentId === start.agentId);\n\tif (priorId === undefined) {\n\t\tif (starts.length !== 0 || start.attemptNumber !== 1) deny();\n\t\treturn;\n\t}\n\tconst source = context.starts.find((event) => event.attemptId === priorId);\n\tif (\n\t\tsource?.kind !== \"attempt.started\" ||\n\t\tsource.agentId !== start.agentId ||\n\t\tsource.generationId !== start.generationId ||\n\t\tscopeKey(source.tenantScope) !== scopeKey(start.tenantScope)\n\t)\n\t\tdeny();\n\ttry {\n\t\tassertDhManagedLifecycle(source);\n\t} catch {\n\t\tdeny();\n\t}\n\tif (\n\t\tsource.attemptNumber === undefined ||\n\t\tstart.attemptNumber !== source.attemptNumber + 1 ||\n\t\tstarts.some((event) => event.attemptNumber === undefined || event.attemptNumber > source.attemptNumber!)\n\t)\n\t\tdeny();\n\tif (new Set(starts.map((event) => event.attemptNumber)).size !== starts.length) deny();\n\tconst terminal = resolveDhEffectiveTerminals([...context.terminals, ...context.amendments], context).get(priorId);\n\tif (\n\t\tterminal?.outcome !== \"failed\" ||\n\t\tterminal.conflict ||\n\t\tterminal.authorityUnresolved ||\n\t\tterminal.event.agentId !== start.agentId ||\n\t\tterminal.event.generationId !== start.generationId ||\n\t\tscopeKey(terminal.event.tenantScope) !== scopeKey(start.tenantScope)\n\t)\n\t\tdeny();\n\tconst claim = context.retryClaims.get(priorId);\n\tif (claim !== undefined && claim !== start.attemptId) deny();\n}\n\n// ---------------------------------------------------------------------------\n// Bundle referential integrity\n// ---------------------------------------------------------------------------\n\nexport interface DhTraceBundle {\n\tevents: readonly DhEventV1[];\n\tartifacts: readonly DhArtifactV1[];\n}\n\nexport type DhTraceBundleValidation = { ok: true } | { ok: false; errors: string[] };\n\nfunction scopeKey(scope: DhTenantScope): string {\n\treturn JSON.stringify([scope.environmentId, scope.projectId]);\n}\n\n/**\n * Validates cross-record integrity of already-parsed records. Does not re-run schema checks, but\n * reports (rather than compares) timestamps that are not calendar-valid UTC instants.\n */\nexport function validateDhTraceBundle(bundle: DhTraceBundle, ownership?: DhTerminalOwnership): DhTraceBundleValidation {\n\tconst errors: string[] = [];\n\tconst { events, artifacts } = bundle;\n\n\tconst generationIds = new Set<string>();\n\tconst scopes = new Set<string>();\n\tfor (const record of [...events, ...artifacts]) {\n\t\tgenerationIds.add(record.generationId);\n\t\tscopes.add(scopeKey(record.tenantScope));\n\t}\n\tif (generationIds.size > 1) errors.push(\"records span multiple generationIds; expected one\");\n\tif (scopes.size > 1) errors.push(\"records span multiple tenantScopes; expected one\");\n\n\t// Timestamps are compared only when calendar-valid; invalid ones are reported once.\n\tconst occurredAt = new Map<DhEventV1, number>();\n\tfor (const event of events) {\n\t\tconst occurred = parseInstant(event.occurredAt);\n\t\tif (occurred === undefined) errors.push(\"occurredAt is not a calendar-valid UTC instant\");\n\t\telse occurredAt.set(event, occurred);\n\t\tif (parseInstant(event.recordedAt) === undefined) {\n\t\t\terrors.push(\"recordedAt is not a calendar-valid UTC instant\");\n\t\t}\n\t}\n\n\tconst eventsById = new Map<string, DhEventV1>();\n\tconst streamSequences = new Set<string>();\n\tfor (const event of events) {\n\t\tif (eventsById.has(event.eventId)) errors.push(\"duplicate eventId\");\n\t\telse eventsById.set(event.eventId, event);\n\t\tconst key = JSON.stringify([event.streamId, event.sequence]);\n\t\tif (streamSequences.has(key)) errors.push(\"duplicate (streamId, sequence)\");\n\t\tstreamSequences.add(key);\n\t}\n\n\t// Artifact links are reciprocal: artifact.eventId <-> event.artifacts, with matching owner.\n\tconst artifactsById = new Map<string, DhArtifactV1>();\n\tfor (const artifact of artifacts) {\n\t\tif (artifactsById.has(artifact.artifactId)) errors.push(\"duplicate artifactId\");\n\t\telse artifactsById.set(artifact.artifactId, artifact);\n\t\tconst event = eventsById.get(artifact.eventId);\n\t\tif (event === undefined) {\n\t\t\terrors.push(\"artifact references unknown eventId\");\n\t\t\tcontinue;\n\t\t}\n\t\tif (!(event.artifacts ?? []).includes(artifact.artifactId)) {\n\t\t\terrors.push(\"artifact is not listed in artifacts of event\");\n\t\t}\n\t\tif (artifact.agentId !== event.agentId) {\n\t\t\terrors.push(\"artifact agentId does not match event\");\n\t\t}\n\t\tif (artifact.attemptId !== event.attemptId) {\n\t\t\terrors.push(\"artifact attemptId does not match event\");\n\t\t}\n\t}\n\tfor (const event of events) {\n\t\tfor (const ref of event.artifacts ?? []) {\n\t\t\tconst artifact = artifactsById.get(ref);\n\t\t\tif (artifact === undefined) errors.push(\"event references unknown artifact\");\n\t\t\telse if (artifact.eventId !== event.eventId) {\n\t\t\t\terrors.push(\"event lists artifact which names a different event\");\n\t\t\t}\n\t\t}\n\t}\n\n\tvalidateAgentHierarchy(events, errors);\n\tvalidateAttempts(events, occurredAt, errors, ownership);\n\tvalidateDelegations(events, eventsById, errors);\n\terrors.push(...validateDhPayloadGraph(events, artifacts, ownership));\n\n\treturn errors.length === 0 ? { ok: true } : { ok: false, errors };\n}\n\n/** Validate declared subagent provenance without requiring a result from unfinished work. */\nfunction validateDelegations(\n\tevents: readonly DhEventV1[],\n\teventsById: ReadonlyMap<string, DhEventV1>,\n\terrors: string[],\n): void {\n\tconst calls = new Map<string, DhEventV1>();\n\tconst spawns = new Map<string, DhEventV1>();\n\tconst childrenByCall = new Map<string, Set<string>>();\n\tfor (const event of events) {\n\t\tif (event.kind === \"tool.call\" && typeof event.payload.callId === \"string\") {\n\t\t\tconst key = JSON.stringify([event.agentId, event.attemptId ?? null, event.payload.callId]);\n\t\t\tif (calls.has(key)) errors.push(\"duplicate tool call identity\");\n\t\t\telse calls.set(key, event);\n\t\t}\n\t\tif (event.kind !== \"agent.spawned\") continue;\n\t\tif (spawns.has(event.agentId)) errors.push(\"duplicate agent.spawned\");\n\t\telse spawns.set(event.agentId, event);\n\t\tif (event.payload.via !== \"subagent\" && event.payload.spawnedByEventId === undefined) continue;\n\t\tconst sourceId = event.payload.spawnedByEventId;\n\t\tif (typeof sourceId !== \"string\" || sourceId.length === 0) {\n\t\t\tconst coverage = event.fields[\"payload.spawnedByEventId\"] ?? event.fields.payload;\n\t\t\tif (!coverage || ![\"unavailable\", \"redacted\", \"truncated\"].includes(coverage.state) || !coverage.reason) {\n\t\t\t\terrors.push(\"subagent spawn has no call provenance or loss coverage\");\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\t\tconst call = eventsById.get(sourceId);\n\t\tif (call?.kind !== \"tool.call\" || call.payload.toolName !== \"subagent\") {\n\t\t\terrors.push(\"spawn references no subagent tool.call\");\n\t\t} else if (call.agentId !== event.parentAgentId || typeof call.payload.callId !== \"string\") {\n\t\t\terrors.push(\"spawn does not belong to the parent call\");\n\t\t} else {\n\t\t\tif (call.streamId === event.streamId && call.sequence >= event.sequence) {\n\t\t\t\terrors.push(\"spawn precedes its parent call in the producer stream\");\n\t\t\t}\n\t\t\tconst children = childrenByCall.get(call.eventId) ?? new Set<string>();\n\t\t\tchildren.add(event.agentId);\n\t\t\tchildrenByCall.set(call.eventId, children);\n\t\t}\n\t}\n\tfor (const event of events) {\n\t\tif (event.kind !== \"tool.result\" || event.payload.toolName !== \"subagent\") continue;\n\t\tconst callId = event.payload.callId;\n\t\tconst key = JSON.stringify([event.agentId, event.attemptId ?? null, callId]);\n\t\tconst call = typeof callId === \"string\" ? calls.get(key) : undefined;\n\t\tif (call?.payload.toolName !== \"subagent\") {\n\t\t\terrors.push(\"subagent result has no matching parent call\");\n\t\t\tcontinue;\n\t\t}\n\t\tif (call.streamId === event.streamId && call.sequence >= event.sequence) {\n\t\t\terrors.push(\"result precedes its parent call in the producer stream\");\n\t\t}\n\t\tconst one = event.payload.childAgentId;\n\t\tconst many = event.payload.childAgentIds;\n\t\tif (one !== undefined && many !== undefined) {\n\t\t\terrors.push(\"use childAgentId or childAgentIds, not both\");\n\t\t\tcontinue;\n\t\t}\n\t\tif (one !== undefined && typeof one !== \"string\") {\n\t\t\terrors.push(\"childAgentId must be a string\");\n\t\t\tcontinue;\n\t\t}\n\t\tif (many !== undefined && (!Array.isArray(many) || many.some((id) => typeof id !== \"string\"))) {\n\t\t\terrors.push(\"childAgentIds must be an array of strings\");\n\t\t\tcontinue;\n\t\t}\n\t\tconst children = typeof one === \"string\" ? [one] : Array.isArray(many) ? many : [];\n\t\tconst seen = new Set<string>();\n\t\tfor (const child of children) {\n\t\t\tif (typeof child !== \"string\") continue;\n\t\t\tif (seen.has(child)) errors.push(\"duplicate child\");\n\t\t\tseen.add(child);\n\t\t\tconst spawn = spawns.get(child);\n\t\t\tif (!spawn || spawn.parentAgentId !== event.agentId || spawn.payload.spawnedByEventId !== call.eventId) {\n\t\t\t\terrors.push(\"child was not spawned by this call\");\n\t\t\t} else if (spawn.streamId === event.streamId && spawn.sequence >= event.sequence) {\n\t\t\t\terrors.push(\"result precedes child in the producer stream\");\n\t\t\t}\n\t\t}\n\t\tconst coverage =\n\t\t\tevent.fields[\"payload.childAgentIds\"] ?? event.fields[\"payload.childAgentId\"] ?? event.fields.payload;\n\t\tconst missingCovered =\n\t\t\tcoverage && [\"unavailable\", \"redacted\", \"truncated\"].includes(coverage.state) && coverage.reason;\n\t\tif (!missingCovered) {\n\t\t\tfor (const child of childrenByCall.get(call.eventId) ?? []) {\n\t\t\t\tif (!seen.has(child)) errors.push(\"result omits observed child\");\n\t\t\t}\n\t\t}\n\t}\n}\n\n/** One parent per agent, no ancestry cycles, exactly one root agent per generation. */\nfunction validateAgentHierarchy(events: readonly DhEventV1[], errors: string[]): void {\n\tconst parentOf = new Map<string, string>();\n\tconst agentsWithoutParentEvent = new Set<string>();\n\tconst spawnedAgents = new Set<string>();\n\tconst generationOf = new Map<string, string>();\n\tfor (const event of events) {\n\t\tgenerationOf.set(event.agentId, event.generationId);\n\t\tif (event.kind === \"agent.spawned\") spawnedAgents.add(event.agentId);\n\t\tif (event.parentAgentId === undefined) {\n\t\t\tagentsWithoutParentEvent.add(event.agentId);\n\t\t\tcontinue;\n\t\t}\n\t\tconst known = parentOf.get(event.agentId);\n\t\tif (known === undefined) parentOf.set(event.agentId, event.parentAgentId);\n\t\telse if (known !== event.parentAgentId) {\n\t\t\terrors.push(\"agent has conflicting parentAgentId values\");\n\t\t}\n\t}\n\tfor (const agentId of agentsWithoutParentEvent) {\n\t\tif (parentOf.has(agentId)) errors.push(\"agent has events both with and without parentAgentId\");\n\t}\n\n\tfor (const [agentId, parent] of parentOf) {\n\t\tif (parent === agentId) errors.push(\"agent is its own parent\");\n\t\telse if (!generationOf.has(parent)) errors.push(\"unknown parentAgentId\");\n\t\telse if (parentOf.has(parent) && !spawnedAgents.has(parent)) {\n\t\t\terrors.push(\"parentAgentId was never spawned in this generation\");\n\t\t}\n\t}\n\n\t// Cycle detection: walk each ancestry chain once; revisiting a node on the current walk is a cycle.\n\tconst settled = new Set<string>();\n\tfor (const start of parentOf.keys()) {\n\t\tconst walk = new Set<string>();\n\t\tlet current: string | undefined = start;\n\t\twhile (current !== undefined && !settled.has(current)) {\n\t\t\tif (walk.has(current)) {\n\t\t\t\terrors.push(\"agent ancestry cycle\");\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\twalk.add(current);\n\t\t\tcurrent = parentOf.get(current);\n\t\t}\n\t\tfor (const visited of walk) settled.add(visited);\n\t}\n\n\tconst rootsByGeneration = new Map<string, string[]>();\n\tfor (const [agentId, generationId] of generationOf) {\n\t\tif (parentOf.has(agentId)) continue;\n\t\tconst roots = rootsByGeneration.get(generationId) ?? [];\n\t\troots.push(agentId);\n\t\trootsByGeneration.set(generationId, roots);\n\t}\n\tfor (const generationId of new Set(generationOf.values())) {\n\t\tconst roots = rootsByGeneration.get(generationId) ?? [];\n\t\tif (roots.length !== 1) {\n\t\t\terrors.push(\"generation must have exactly one root agent\");\n\t\t}\n\t}\n}\n\n/** Attempt ownership, uniqueness, chronology and retry linkage. */\nfunction validateAttempts(\n\tevents: readonly DhEventV1[],\n\toccurredAt: ReadonlyMap<DhEventV1, number>,\n\terrors: string[],\n\townership?: DhTerminalOwnership,\n): void {\n\tconst effective = resolveDhEffectiveTerminals(events, ownership);\n\tconst retryClaims = new Map<string, string>();\n\tconst started = new Map<string, DhEventV1>();\n\tconst finished = new Map<string, DhEventV1>();\n\tfor (const event of events) {\n\t\tif (event.attemptId === undefined) continue;\n\t\tif (event.kind === \"attempt.started\") {\n\t\t\tif (started.has(event.attemptId)) errors.push(\"duplicate attempt.started for attempt\");\n\t\t\telse started.set(event.attemptId, event);\n\t\t} else if (event.kind === \"attempt.finished\") {\n\t\t\tif (finished.has(event.attemptId)) errors.push(\"duplicate attempt.finished for attempt\");\n\t\t\telse finished.set(event.attemptId, event);\n\t\t}\n\t}\n\n\tfor (const event of events) {\n\t\tconst violation = attemptIdViolation(event);\n\t\tif (violation !== undefined) errors.push(violation);\n\t\tif (event.retryOfAttemptId !== undefined && event.kind !== \"attempt.started\") {\n\t\t\terrors.push(\"retryOfAttemptId is only allowed on attempt.started\");\n\t\t}\n\t\tif (event.attemptId === undefined) continue;\n\t\tconst start = started.get(event.attemptId);\n\t\tif (start === undefined) {\n\t\t\terrors.push(\n\t\t\t\tevent.kind === \"attempt.finished\"\n\t\t\t\t\t? \"attempt.finished for attempt has no matching attempt.started\"\n\t\t\t\t\t: \"attempt has no attempt.started\",\n\t\t\t);\n\t\t\tcontinue;\n\t\t}\n\t\tif (start.agentId !== event.agentId) {\n\t\t\terrors.push(\"attempt belongs to a different agent\");\n\t\t}\n\t\tif (event.kind === \"attempt.finished\" && finished.get(event.attemptId) === event) {\n\t\t\tconst startedAt = occurredAt.get(start);\n\t\t\tconst finishedAt = occurredAt.get(event);\n\t\t\tif (\n\t\t\t\tstart.streamId === event.streamId &&\n\t\t\t\tstartedAt !== undefined &&\n\t\t\t\tfinishedAt !== undefined &&\n\t\t\t\tfinishedAt < startedAt\n\t\t\t) {\n\t\t\t\terrors.push(\"attempt finished before it started\");\n\t\t\t}\n\t\t}\n\t}\n\n\tconst previousByAttempt = new Map<string, DhEventV1>();\n\tconst startedByAgent = new Map<string, DhEventV1[]>();\n\tfor (const event of started.values()) {\n\t\tconst list = startedByAgent.get(event.agentId) ?? [];\n\t\tlist.push(event);\n\t\tstartedByAgent.set(event.agentId, list);\n\t}\n\tfor (const list of startedByAgent.values()) {\n\t\tlist.sort((a, b) => (a.attemptNumber ?? a.sequence + 1) - (b.attemptNumber ?? b.sequence + 1));\n\t\tlist.forEach((event, index) => {\n\t\t\tconst previous = list[index - 1];\n\t\t\tif (previous && event.attemptId) previousByAttempt.set(event.attemptId, previous);\n\t\t\tif (event.payload.schema === \"dh.payload.attempt-lifecycle/1\") {\n\t\t\t\ttry {\n\t\t\t\t\tassertDhManagedLifecycle(event);\n\t\t\t\t} catch {\n\t\t\t\t\terrors.push(\"schema_invalid: invalid managed lifecycle\");\n\t\t\t\t}\n\t\t\t\tif (\n\t\t\t\t\t(index === 0 && event.retryOfAttemptId !== undefined) ||\n\t\t\t\t\t(index > 0 && event.retryOfAttemptId !== previous?.attemptId)\n\t\t\t\t)\n\t\t\t\t\terrors.push(\"not_eligible: attempt start must link its latest recorded predecessor\");\n\t\t\t}\n\t\t\tif (event.attemptNumber !== undefined && event.attemptNumber !== index + 1) {\n\t\t\t\terrors.push(\"attemptNumber does not match the attempt order\");\n\t\t\t}\n\t\t});\n\t}\n\n\tconst scheduled = new Map<string, DhEventV1[]>();\n\tfor (const event of events) {\n\t\tif (event.kind !== \"attempt.retry_scheduled\" || !event.attemptId) continue;\n\t\tconst list = scheduled.get(event.attemptId) ?? [];\n\t\tlist.push(event);\n\t\tscheduled.set(event.attemptId, list);\n\t}\n\tfor (const event of started.values()) {\n\t\tconst prior = event.retryOfAttemptId;\n\t\tif (prior === undefined) continue;\n\t\tif (prior === event.attemptId) {\n\t\t\terrors.push(\"attempt cannot retry itself\");\n\t\t\tcontinue;\n\t\t}\n\t\tfor (const schedule of scheduled.get(prior) ?? []) {\n\t\t\tif (\n\t\t\t\tschedule.agentId !== event.agentId ||\n\t\t\t\tschedule.generationId !== event.generationId ||\n\t\t\t\tscopeKey(schedule.tenantScope) !== scopeKey(event.tenantScope) ||\n\t\t\t\tschedule.payload.nextAttemptNumber !== event.attemptNumber\n\t\t\t)\n\t\t\t\terrors.push(\"not_eligible: retry schedule does not match source and next attempt number\");\n\t\t}\n\t\tconst priorStart = started.get(prior);\n\t\tconst priorFinish = finished.get(prior);\n\t\tif (priorFinish === undefined || priorStart === undefined) {\n\t\t\terrors.push(\"retryOfAttemptId is not a known finished attempt\");\n\t\t\tcontinue;\n\t\t}\n\t\tif (priorStart.agentId !== event.agentId) {\n\t\t\terrors.push(\"retryOfAttemptId belongs to a different agent\");\n\t\t}\n\t\tconst terminal = effective.get(prior);\n\t\tif (terminal?.outcome !== \"failed\" || terminal.conflict || terminal.authorityUnresolved) {\n\t\t\terrors.push(\"retryOfAttemptId did not finish with outcome failed\");\n\t\t}\n\t\tif (\n\t\t\tpriorStart.generationId !== event.generationId ||\n\t\t\tscopeKey(priorStart.tenantScope) !== scopeKey(event.tenantScope)\n\t\t)\n\t\t\terrors.push(\"not_eligible: retry source has a foreign generation or scope\");\n\t\tif (retryClaims.has(prior) && retryClaims.get(prior) !== event.attemptId)\n\t\t\terrors.push(\"not_eligible: retry source already claimed\");\n\t\tretryClaims.set(prior, event.attemptId!);\n\t\tif (event.attemptId && previousByAttempt.get(event.attemptId)?.attemptId !== prior)\n\t\t\terrors.push(\"not_eligible: retry source is not the latest attempt\");\n\t\tconst priorFinishedAt = occurredAt.get(priorFinish);\n\t\tconst retryStartedAt = occurredAt.get(event);\n\t\tif (\n\t\t\tpriorFinish.streamId === event.streamId &&\n\t\t\tpriorFinishedAt !== undefined &&\n\t\t\tretryStartedAt !== undefined &&\n\t\t\tpriorFinishedAt > retryStartedAt\n\t\t) {\n\t\t\terrors.push(\"retryOfAttemptId finished after the retry\");\n\t\t}\n\t\tif (\n\t\t\tevent.attemptNumber !== undefined &&\n\t\t\tpriorStart.attemptNumber !== undefined &&\n\t\t\tevent.attemptNumber !== priorStart.attemptNumber + 1\n\t\t) {\n\t\t\terrors.push(\"attemptNumber does not follow the prior attemptNumber\");\n\t\t}\n\t}\n}\n"]}
package/package.json ADDED
@@ -0,0 +1,64 @@
1
+ {
2
+ "name": "@humain/humain-code-contracts",
3
+ "version": "0.3.2",
4
+ "private": false,
5
+ "description": "Runtime-neutral HUMAIN Terminal execution and RPC wire contracts",
6
+ "type": "module",
7
+ "main": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js"
13
+ },
14
+ "./orchestration": {
15
+ "types": "./dist/orchestration.d.ts",
16
+ "import": "./dist/orchestration.js"
17
+ },
18
+ "./rpc": {
19
+ "types": "./dist/rpc.d.ts",
20
+ "import": "./dist/rpc.js"
21
+ },
22
+ "./trace": {
23
+ "types": "./dist/trace.d.ts",
24
+ "import": "./dist/trace.js"
25
+ },
26
+ "./testing": {
27
+ "types": "./dist/testing.d.ts",
28
+ "import": "./dist/testing.js"
29
+ }
30
+ },
31
+ "files": [
32
+ "dist",
33
+ "README.md",
34
+ "CHANGELOG.md"
35
+ ],
36
+ "scripts": {
37
+ "clean": "shx rm -rf dist",
38
+ "build": "tsc -p tsconfig.build.json",
39
+ "test": "vitest --run",
40
+ "prepublishOnly": "npm run clean && npm run build"
41
+ },
42
+ "dependencies": {
43
+ "typebox": "1.3.34"
44
+ },
45
+ "devDependencies": {
46
+ "shx": "0.4.0",
47
+ "vitest": "5.0.2"
48
+ },
49
+ "keywords": [
50
+ "humain-terminal",
51
+ "protocol",
52
+ "contracts"
53
+ ],
54
+ "author": "HUMAIN",
55
+ "license": "MIT",
56
+ "repository": {
57
+ "type": "git",
58
+ "url": "git+https://gitlab.humain.com/humain/data-and-ai-modeling/standard/agentic/humain-terminal.git",
59
+ "directory": "packages/humain-code-contracts"
60
+ },
61
+ "engines": {
62
+ "node": ">=22.22.2"
63
+ }
64
+ }