@cleocode/contracts 2026.6.11 → 2026.6.13

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 (136) hide show
  1. package/dist/__tests__/operation-def.test.js +2 -1
  2. package/dist/__tests__/operation-def.test.js.map +1 -1
  3. package/dist/__tests__/sealed-credential.test.d.ts +19 -0
  4. package/dist/__tests__/sealed-credential.test.d.ts.map +1 -0
  5. package/dist/__tests__/sealed-credential.test.js +74 -0
  6. package/dist/__tests__/sealed-credential.test.js.map +1 -0
  7. package/dist/__tests__/skill-executor-contract.test.js +3 -0
  8. package/dist/__tests__/skill-executor-contract.test.js.map +1 -1
  9. package/dist/acceptance-gate.d.ts +2 -3
  10. package/dist/acceptance-gate.d.ts.map +1 -1
  11. package/dist/boundary.d.ts.map +1 -1
  12. package/dist/boundary.js +1 -19
  13. package/dist/boundary.js.map +1 -1
  14. package/dist/config.d.ts +102 -0
  15. package/dist/config.d.ts.map +1 -1
  16. package/dist/data-accessor.d.ts +21 -1
  17. package/dist/data-accessor.d.ts.map +1 -1
  18. package/dist/data-accessor.js.map +1 -1
  19. package/dist/dispatch/identity.d.ts +1 -1
  20. package/dist/dispatch/identity.d.ts.map +1 -1
  21. package/dist/dispatch/identity.js +5 -0
  22. package/dist/dispatch/identity.js.map +1 -1
  23. package/dist/dispatch/operations-registry.d.ts.map +1 -1
  24. package/dist/dispatch/operations-registry.js +46 -168
  25. package/dist/dispatch/operations-registry.js.map +1 -1
  26. package/dist/docs/read.d.ts +2 -2
  27. package/dist/index.d.ts +12 -7
  28. package/dist/index.d.ts.map +1 -1
  29. package/dist/index.js +3 -0
  30. package/dist/index.js.map +1 -1
  31. package/dist/lease-ipc/__tests__/freeze.test.d.ts +15 -0
  32. package/dist/lease-ipc/__tests__/freeze.test.d.ts.map +1 -0
  33. package/dist/lease-ipc/__tests__/freeze.test.js +221 -0
  34. package/dist/lease-ipc/__tests__/freeze.test.js.map +1 -0
  35. package/dist/lease-ipc/index.d.ts +17 -0
  36. package/dist/lease-ipc/index.d.ts.map +1 -0
  37. package/dist/lease-ipc/index.js +16 -0
  38. package/dist/lease-ipc/index.js.map +1 -0
  39. package/dist/lease-ipc/messages.d.ts +754 -0
  40. package/dist/lease-ipc/messages.d.ts.map +1 -0
  41. package/dist/lease-ipc/messages.js +383 -0
  42. package/dist/lease-ipc/messages.js.map +1 -0
  43. package/dist/lease-ipc/version.d.ts +41 -0
  44. package/dist/lease-ipc/version.d.ts.map +1 -0
  45. package/dist/lease-ipc/version.js +43 -0
  46. package/dist/lease-ipc/version.js.map +1 -0
  47. package/dist/llm/interfaces.d.ts +23 -0
  48. package/dist/llm/interfaces.d.ts.map +1 -1
  49. package/dist/llm/sealed-credential.d.ts +164 -0
  50. package/dist/llm/sealed-credential.d.ts.map +1 -0
  51. package/dist/llm/sealed-credential.js +43 -0
  52. package/dist/llm/sealed-credential.js.map +1 -0
  53. package/dist/llm/system-of-use.d.ts +383 -0
  54. package/dist/llm/system-of-use.d.ts.map +1 -0
  55. package/dist/llm/system-of-use.js +238 -0
  56. package/dist/llm/system-of-use.js.map +1 -0
  57. package/dist/llm/system-resolver.d.ts +45 -11
  58. package/dist/llm/system-resolver.d.ts.map +1 -1
  59. package/dist/llm/system-resolver.js +14 -7
  60. package/dist/llm/system-resolver.js.map +1 -1
  61. package/dist/operations/__tests__/ensures-schema-registry.test.d.ts +17 -0
  62. package/dist/operations/__tests__/ensures-schema-registry.test.d.ts.map +1 -0
  63. package/dist/operations/__tests__/ensures-schema-registry.test.js +113 -0
  64. package/dist/operations/__tests__/ensures-schema-registry.test.js.map +1 -0
  65. package/dist/operations/ensures-schema-registry.d.ts +172 -0
  66. package/dist/operations/ensures-schema-registry.d.ts.map +1 -0
  67. package/dist/operations/ensures-schema-registry.js +226 -0
  68. package/dist/operations/ensures-schema-registry.js.map +1 -0
  69. package/dist/operations/llm.d.ts +101 -9
  70. package/dist/operations/llm.d.ts.map +1 -1
  71. package/dist/operations/validate.d.ts +1 -12
  72. package/dist/operations/validate.d.ts.map +1 -1
  73. package/dist/operations/validate.js +1 -1
  74. package/dist/playbook.d.ts +60 -0
  75. package/dist/playbook.d.ts.map +1 -1
  76. package/dist/session.d.ts +11 -0
  77. package/dist/session.d.ts.map +1 -1
  78. package/dist/session.js.map +1 -1
  79. package/dist/templates/manifest.d.ts +1 -1
  80. package/dist/tools/agent-tools.d.ts +231 -0
  81. package/dist/tools/agent-tools.d.ts.map +1 -0
  82. package/dist/tools/agent-tools.js +25 -0
  83. package/dist/tools/agent-tools.js.map +1 -0
  84. package/dist/tools/atomic.d.ts +19 -0
  85. package/dist/tools/atomic.d.ts.map +1 -1
  86. package/dist/tools/atomic.js +17 -0
  87. package/dist/tools/atomic.js.map +1 -1
  88. package/dist/tools/index.d.ts +2 -0
  89. package/dist/tools/index.d.ts.map +1 -1
  90. package/dist/tools/skill-executor.d.ts +7 -0
  91. package/dist/tools/skill-executor.d.ts.map +1 -1
  92. package/dist/tools/web-tools.d.ts +217 -0
  93. package/dist/tools/web-tools.d.ts.map +1 -0
  94. package/dist/tools/web-tools.js +31 -0
  95. package/dist/tools/web-tools.js.map +1 -0
  96. package/package.json +6 -2
  97. package/src/__tests__/__snapshots__/operations-registry.test.ts.snap +1 -1
  98. package/src/__tests__/operation-def.test.ts +2 -1
  99. package/src/__tests__/sealed-credential.test.ts +100 -0
  100. package/src/__tests__/skill-executor-contract.test.ts +3 -0
  101. package/src/acceptance-gate.ts +2 -3
  102. package/src/boundary.ts +1 -20
  103. package/src/config.ts +104 -0
  104. package/src/data-accessor.ts +22 -1
  105. package/src/dispatch/identity.ts +5 -0
  106. package/src/dispatch/operations-registry.ts +51 -170
  107. package/src/index.ts +103 -24
  108. package/src/lease-ipc/__tests__/freeze.test.ts +246 -0
  109. package/src/lease-ipc/index.ts +63 -0
  110. package/src/lease-ipc/messages.ts +471 -0
  111. package/src/lease-ipc/version.ts +46 -0
  112. package/src/llm/interfaces.ts +23 -0
  113. package/src/llm/sealed-credential.ts +166 -0
  114. package/src/llm/system-of-use.ts +503 -0
  115. package/src/llm/system-resolver.ts +46 -11
  116. package/src/operations/__tests__/ensures-schema-registry.test.ts +169 -0
  117. package/src/operations/ensures-schema-registry.ts +260 -0
  118. package/src/operations/llm.ts +105 -8
  119. package/src/operations/validate.ts +1 -14
  120. package/src/playbook.ts +61 -0
  121. package/src/session.ts +11 -0
  122. package/src/tools/agent-tools.ts +270 -0
  123. package/src/tools/atomic.ts +21 -0
  124. package/src/tools/index.ts +46 -0
  125. package/src/tools/skill-executor.ts +7 -0
  126. package/src/tools/web-tools.ts +247 -0
  127. package/dist/tessera.d.ts +0 -32
  128. package/dist/tessera.d.ts.map +0 -1
  129. package/dist/tessera.js +0 -11
  130. package/dist/tessera.js.map +0 -1
  131. package/dist/warp-chain.d.ts +0 -129
  132. package/dist/warp-chain.d.ts.map +0 -1
  133. package/dist/warp-chain.js +0 -13
  134. package/dist/warp-chain.js.map +0 -1
  135. package/src/tessera.ts +0 -35
  136. package/src/warp-chain.ts +0 -185
package/src/index.ts CHANGED
@@ -264,6 +264,7 @@ export type {
264
264
  LlmConfig,
265
265
  LlmDefaultConfig,
266
266
  LlmProfileConfig,
267
+ LlmProfileTier,
267
268
  LlmProfileTuning,
268
269
  LlmProviderEntry,
269
270
  LlmProviderTransport,
@@ -282,6 +283,7 @@ export type {
282
283
  SharingMode,
283
284
  SignalDockConfig,
284
285
  SignalDockMode,
286
+ SystemBinding,
285
287
  } from './config.js';
286
288
  export type { AdapterContextMonitorProvider } from './context-monitor.js';
287
289
  // === Claude Code credential parsing (T9307 — pure helper, no core imports) ===
@@ -739,6 +741,56 @@ export {
739
741
  isLafsError,
740
742
  isLafsSuccess,
741
743
  } from './lafs.js';
744
+ // === Lease-IPC v1.1 (PARALLEL DbWriterLease contract — T11627 · SG-RUNTIME-UNIFICATION) ===
745
+ export type {
746
+ ChildKilledUnresponsiveResponse,
747
+ LeaseAcquireRequest,
748
+ LeaseDeniedResponse,
749
+ LeaseErrorResponse,
750
+ LeaseGrantedResponse,
751
+ LeaseIpcEnvelope,
752
+ LeaseIpcRequest,
753
+ LeaseIpcRequestEnvelope,
754
+ LeaseIpcResponse,
755
+ LeaseIpcResponseEnvelope,
756
+ LeaseLane,
757
+ LeaseQueuedResponse,
758
+ LeaseReleaseRequest,
759
+ LeaseRenewRequest,
760
+ LeaseRevokedResponse,
761
+ LeaseScope,
762
+ RateCheckRequest,
763
+ RateResultResponse,
764
+ ToolGrantedResponse,
765
+ ToolGrantRequest,
766
+ } from './lease-ipc/index.js';
767
+ export {
768
+ ChildKilledUnresponsiveResponseSchema,
769
+ isFrozenLeaseIpcVersion,
770
+ LEASE_IPC_MESSAGE_KINDS,
771
+ LEASE_IPC_PROTOCOL_VERSION,
772
+ LEASE_IPC_REQUEST_KINDS,
773
+ LEASE_IPC_RESPONSE_KINDS,
774
+ LeaseAcquireRequestSchema,
775
+ LeaseDeniedResponseSchema,
776
+ LeaseErrorResponseSchema,
777
+ LeaseGrantedResponseSchema,
778
+ LeaseIpcEnvelopeSchema,
779
+ LeaseIpcRequestEnvelopeSchema,
780
+ LeaseIpcRequestSchema,
781
+ LeaseIpcResponseEnvelopeSchema,
782
+ LeaseIpcResponseSchema,
783
+ LeaseLaneSchema,
784
+ LeaseQueuedResponseSchema,
785
+ LeaseReleaseRequestSchema,
786
+ LeaseRenewRequestSchema,
787
+ LeaseRevokedResponseSchema,
788
+ LeaseScopeSchema,
789
+ RateCheckRequestSchema,
790
+ RateResultResponseSchema,
791
+ ToolGrantedResponseSchema,
792
+ ToolGrantRequestSchema,
793
+ } from './lease-ipc/index.js';
742
794
  // === LLM Error Taxonomy (T9270 — Hermes FailoverReason port) ===
743
795
  export type { ClassifiedError, FailoverReason } from './llm/failover-reason.js';
744
796
  // === Phase 4 Unified Architecture (T9281 / ADR-072) — Session + Executor interfaces ===
@@ -794,10 +846,42 @@ export type {
794
846
  export type { ResolvedCredential } from './llm/resolved-credential.js';
795
847
  // === E9 SSoT resolution descriptor (T11745 / T11761) ===
796
848
  export type { ModelCaps, ResolvedLLMDescriptor } from './llm/resolved-descriptor.js';
849
+ // === E10 Sealed credential handle (T11752 / T11746) — on-demand decrypt at the wire ===
850
+ export type { DecryptedToken, SealedCredential } from './llm/sealed-credential.js';
851
+ // === E9 System-of-Use taxonomy + registry (T11747 · hermes _AUX_TASKS analog) ===
852
+ export type {
853
+ AuxSystem,
854
+ AuxSystemId,
855
+ CantbookNodeSystem,
856
+ OpenSystemKind,
857
+ OrchestrationSystem,
858
+ RegisteredSystemOfUse,
859
+ RoleSystem,
860
+ SkillSystem,
861
+ SpawnUnitSystem,
862
+ SystemOfUse,
863
+ SystemOfUseDefaults,
864
+ SystemOfUseKind,
865
+ SystemOfUsePickerEntry,
866
+ ToolSystem,
867
+ WhoamiRoleId,
868
+ } from './llm/system-of-use.js';
869
+ export {
870
+ AUX_SYSTEM_IDS,
871
+ BUILTIN_SYSTEMS_OF_USE,
872
+ isBuiltinSystemOfUse,
873
+ isOpenSystemKind,
874
+ isSystemOfUse,
875
+ OPEN_SYSTEM_KEY_PREFIXES,
876
+ ORCHESTRATION_TIER_IDS,
877
+ ROLE_SYSTEM_IDS,
878
+ WHOAMI_ROLE_IDS,
879
+ } from './llm/system-of-use.js';
797
880
  // === E9 System-of-Use chokepoint contract (T11749) ===
798
881
  export type {
799
882
  ResolveLLMForSystemOptions,
800
- SystemOfUse,
883
+ SystemOfUseLabel,
884
+ SystemResolverInput,
801
885
  } from './llm/system-resolver.js';
802
886
  export { SYSTEM_ROLE_MAP } from './llm/system-resolver.js';
803
887
  // === Logger contract (T9766 — centralized from @cleocode/core) ===
@@ -1045,6 +1129,20 @@ export {
1045
1129
  type DocsLifecycleStatus,
1046
1130
  type DocsUpdateParams,
1047
1131
  } from './operations/docs.js';
1132
+ // === Ensures-schema Zod registry (T11762 ST-1 / T11900 — cantbook ensures.schema SSoT) ===
1133
+ // Named Zod validators for cantbook `ensures.schema` shapes (task_tree, evidence)
1134
+ // + the registry DATA. Bodied accessors live in @cleocode/core (ST-1b) to keep
1135
+ // contracts Gate-10-pure. The runtime resolves a schema name → validator here
1136
+ // instead of hardcoding `if (schema === 'task_tree') … else if (=== 'evidence')`.
1137
+ export type { EnsuresSchemaSpec } from './operations/ensures-schema-registry.js';
1138
+ export {
1139
+ ENSURES_SCHEMA_REGISTRY,
1140
+ evidenceSchema,
1141
+ LEGACY_PASSTHROUGH_SCHEMA_NAMES,
1142
+ passthroughSchema,
1143
+ taskTreeEntrySchema,
1144
+ taskTreeSchema,
1145
+ } from './operations/ensures-schema-registry.js';
1048
1146
  // === Operations Types (API wire format, namespaced to avoid collision with domain types) ===
1049
1147
  export * as ops from './operations/index.js';
1050
1148
  // === Operation Input Contracts (T9914 / Saga T9855 / E7) ===
@@ -1091,6 +1189,7 @@ export type {
1091
1189
  // === LLM Credential + Role-Resolver Wire Types (T-LLM-CRED Phase 1/2 — T9255) ===
1092
1190
  export type {
1093
1191
  AuthTypeWire,
1192
+ CredentialMetadataWire,
1094
1193
  CredentialResultWire,
1095
1194
  CredentialSourceWire,
1096
1195
  CredentialsStoreStrategyWire,
@@ -1110,6 +1209,8 @@ export type {
1110
1209
  LlmRemoveResult,
1111
1210
  LlmStatusResult,
1112
1211
  LlmStoredCredentialView,
1212
+ LlmSystemsOfUseParams,
1213
+ LlmSystemsOfUseResult,
1113
1214
  LlmTestParams,
1114
1215
  LlmTestResult,
1115
1216
  LlmUseParams,
@@ -1550,8 +1651,6 @@ export type {
1550
1651
  ValidateCanonDocsResult,
1551
1652
  ValidateCanonParams,
1552
1653
  ValidateCanonResult,
1553
- ValidateChainParams,
1554
- ValidateChainResult,
1555
1654
  ValidateCoherenceParams,
1556
1655
  ValidateCoherenceResult,
1557
1656
  ValidateComplianceRecordParams,
@@ -1658,6 +1757,7 @@ export type {
1658
1757
  PlaybookDefinition,
1659
1758
  PlaybookDeterministicNode,
1660
1759
  PlaybookEdge,
1760
+ PlaybookEdgeCondition,
1661
1761
  PlaybookEnsures,
1662
1762
  PlaybookErrorHandler,
1663
1763
  PlaybookInput,
@@ -2220,12 +2320,6 @@ export {
2220
2320
  TEMPLATE_UPDATE_STRATEGIES,
2221
2321
  TemplateManifestEntrySchema,
2222
2322
  } from './templates/manifest.js';
2223
- // === Tessera Types ===
2224
- export type {
2225
- TesseraInstantiationInput,
2226
- TesseraTemplate,
2227
- TesseraVariable,
2228
- } from './tessera.js';
2229
2323
  export type { FetchBrainEntriesInput, FetchBrainEntriesOutput } from './tools/brain-fetch.js';
2230
2324
  export type { ObserveBrainInput, ObserveBrainOutput } from './tools/brain-observe.js';
2231
2325
  // === SDK Tool Contracts (T10068 / T10070 / T9835) ===
@@ -2291,21 +2385,6 @@ export {
2291
2385
  validatorRejectionSchema,
2292
2386
  validatorVerdictSchema,
2293
2387
  } from './validator/index.js';
2294
- // === WarpChain Types ===
2295
- export type {
2296
- ChainShape,
2297
- ChainValidation,
2298
- GateCheck,
2299
- GateContract,
2300
- GateName,
2301
- GateResult,
2302
- ProtocolType,
2303
- WarpChain,
2304
- WarpChainExecution,
2305
- WarpChainInstance,
2306
- WarpLink,
2307
- WarpStage,
2308
- } from './warp-chain.js';
2309
2388
  export type {
2310
2389
  TasksFrontierParamsInput,
2311
2390
  TasksRollupParamsInput,
@@ -0,0 +1,246 @@
1
+ /**
2
+ * Schema-drift guard for the `lease-ipc` v1.1 PARALLEL contract (T11627 ST-1).
3
+ *
4
+ * Pins the v1.1 protocol version and the exact request/response message-kind
5
+ * set. If a future change adds, removes, or renames a message kind without a
6
+ * coordinated dual (Rust + TS) edit, these assertions fail — forcing an
7
+ * explicit, reviewed decision rather than silent drift across the Rust/TS wire.
8
+ *
9
+ * Also asserts the Rust wire shape (snake_case keys, `direction` + `kind`
10
+ * discriminators, snake_case enum payloads) round-trips through the Zod schemas,
11
+ * proving the TypeScript and Rust sides agree on the same bytes — the exact JSON
12
+ * produced by `cleo_supervisor::lease_ipc::LeaseEnvelope::*::to_ndjson()`.
13
+ */
14
+
15
+ import { describe, expect, it } from 'vitest';
16
+ import {
17
+ isFrozenLeaseIpcVersion,
18
+ LEASE_IPC_MESSAGE_KINDS,
19
+ LEASE_IPC_PROTOCOL_VERSION,
20
+ LEASE_IPC_REQUEST_KINDS,
21
+ LEASE_IPC_RESPONSE_KINDS,
22
+ LeaseIpcEnvelopeSchema,
23
+ LeaseIpcRequestSchema,
24
+ LeaseIpcResponseSchema,
25
+ } from '../index.js';
26
+
27
+ describe('lease-ipc v1.1 freeze guard (T11627)', () => {
28
+ it('pins the parallel protocol version', () => {
29
+ expect(LEASE_IPC_PROTOCOL_VERSION).toBe('1.1.0');
30
+ });
31
+
32
+ it('the version differs from the frozen supervisor-ipc v1.0 wire version', () => {
33
+ // The two contracts are distinguished on the wire purely by this string;
34
+ // it MUST NOT collide with '1.0.0'.
35
+ expect(LEASE_IPC_PROTOCOL_VERSION).not.toBe('1.0.0');
36
+ expect(isFrozenLeaseIpcVersion('1.1.0')).toBe(true);
37
+ expect(isFrozenLeaseIpcVersion('1.0.0')).toBe(false);
38
+ });
39
+
40
+ it('pins the exact request kind set', () => {
41
+ expect([...LEASE_IPC_REQUEST_KINDS]).toEqual([
42
+ 'lease_acquire',
43
+ 'lease_release',
44
+ 'lease_renew',
45
+ 'rate_check',
46
+ 'tool_grant',
47
+ ]);
48
+ });
49
+
50
+ it('pins the exact response kind set', () => {
51
+ expect([...LEASE_IPC_RESPONSE_KINDS]).toEqual([
52
+ 'lease_granted',
53
+ 'lease_queued',
54
+ 'lease_denied',
55
+ 'rate_result',
56
+ 'tool_granted',
57
+ 'lease_revoked',
58
+ 'child_killed_unresponsive',
59
+ 'error',
60
+ ]);
61
+ });
62
+
63
+ it('the union schemas cover exactly the v1.1 kinds', () => {
64
+ for (const kind of LEASE_IPC_REQUEST_KINDS) {
65
+ const sample = sampleRequestFor(kind);
66
+ expect(LeaseIpcRequestSchema.safeParse(sample).success).toBe(true);
67
+ }
68
+ for (const kind of LEASE_IPC_RESPONSE_KINDS) {
69
+ const sample = sampleResponseFor(kind);
70
+ expect(LeaseIpcResponseSchema.safeParse(sample).success).toBe(true);
71
+ }
72
+ expect(LEASE_IPC_MESSAGE_KINDS).toHaveLength(
73
+ LEASE_IPC_REQUEST_KINDS.length + LEASE_IPC_RESPONSE_KINDS.length,
74
+ );
75
+ });
76
+
77
+ it('pins the EXACT complete v1.1 message-kind set', () => {
78
+ expect([...LEASE_IPC_MESSAGE_KINDS]).toEqual([
79
+ 'lease_acquire',
80
+ 'lease_release',
81
+ 'lease_renew',
82
+ 'rate_check',
83
+ 'tool_grant',
84
+ 'lease_granted',
85
+ 'lease_queued',
86
+ 'lease_denied',
87
+ 'rate_result',
88
+ 'tool_granted',
89
+ 'lease_revoked',
90
+ 'child_killed_unresponsive',
91
+ 'error',
92
+ ]);
93
+ });
94
+ });
95
+
96
+ describe('lease-ipc v1.1 wire-shape parity with Rust serde (T11627)', () => {
97
+ it('parses the exact JSON a Rust lease_acquire request envelope serializes', () => {
98
+ // Literal JSON shape produced by
99
+ // cleo_supervisor::lease_ipc::LeaseEnvelope::request(...).to_ndjson().
100
+ const wire = {
101
+ protocol_version: '1.1.0',
102
+ id: 'abc',
103
+ direction: 'request',
104
+ request: {
105
+ kind: 'lease_acquire',
106
+ scope: 'project',
107
+ lane: 'tasks',
108
+ holder_id: 'pid-42:tasks',
109
+ priority: 0,
110
+ ttl_ms: 30000,
111
+ reentrant: true,
112
+ },
113
+ };
114
+ const parsed = LeaseIpcEnvelopeSchema.safeParse(wire);
115
+ expect(parsed.success).toBe(true);
116
+ if (parsed.success && parsed.data.direction === 'request') {
117
+ expect(parsed.data.request.kind).toBe('lease_acquire');
118
+ }
119
+ });
120
+
121
+ it('parses the exact JSON a Rust lease_granted response envelope serializes', () => {
122
+ const wire = {
123
+ protocol_version: '1.1.0',
124
+ id: 'abc',
125
+ direction: 'response',
126
+ response: {
127
+ kind: 'lease_granted',
128
+ scope: 'global',
129
+ lane: 'brain',
130
+ holder_id: 'pid-42:brain',
131
+ epoch: 7,
132
+ ttl_ms: 30000,
133
+ expires_at_ms: 1000030000,
134
+ },
135
+ };
136
+ expect(LeaseIpcEnvelopeSchema.safeParse(wire).success).toBe(true);
137
+ });
138
+
139
+ it('parses a Rust child_killed_unresponsive event envelope', () => {
140
+ const wire = {
141
+ protocol_version: '1.1.0',
142
+ id: 'evt-1',
143
+ direction: 'response',
144
+ response: {
145
+ kind: 'child_killed_unresponsive',
146
+ child_id: 'worker-1',
147
+ holder_id: 'pid-42:tasks',
148
+ scope: 'project',
149
+ reason: 'unresponsive past ttl',
150
+ },
151
+ };
152
+ expect(LeaseIpcEnvelopeSchema.safeParse(wire).success).toBe(true);
153
+ });
154
+
155
+ it('parses a reused v1.0 error response shape ({ kind, code, message })', () => {
156
+ const wire = {
157
+ protocol_version: '1.1.0',
158
+ id: 'e',
159
+ direction: 'response',
160
+ response: { kind: 'error', code: 'E_LEASE_UNIMPLEMENTED', message: 'deferred handler' },
161
+ };
162
+ expect(LeaseIpcEnvelopeSchema.safeParse(wire).success).toBe(true);
163
+ });
164
+
165
+ it('rejects an unknown message kind (proves the union is closed)', () => {
166
+ const wire = {
167
+ protocol_version: '1.1.0',
168
+ id: 'abc',
169
+ direction: 'request',
170
+ request: { kind: 'lease_teleport', scope: 'project', lane: 'tasks' },
171
+ };
172
+ expect(LeaseIpcEnvelopeSchema.safeParse(wire).success).toBe(false);
173
+ });
174
+
175
+ it('rejects an unknown scope/lane enum value (snake_case enums are closed)', () => {
176
+ const wire = {
177
+ protocol_version: '1.1.0',
178
+ id: 'abc',
179
+ direction: 'request',
180
+ request: {
181
+ kind: 'lease_acquire',
182
+ scope: 'session',
183
+ lane: 'tasks',
184
+ holder_id: 'h',
185
+ priority: 0,
186
+ ttl_ms: 1,
187
+ reentrant: false,
188
+ },
189
+ };
190
+ expect(LeaseIpcEnvelopeSchema.safeParse(wire).success).toBe(false);
191
+ });
192
+ });
193
+
194
+ /** Build a minimal valid request payload for the given kind. */
195
+ function sampleRequestFor(kind: (typeof LEASE_IPC_REQUEST_KINDS)[number]): unknown {
196
+ switch (kind) {
197
+ case 'lease_acquire':
198
+ return {
199
+ kind,
200
+ scope: 'project',
201
+ lane: 'tasks',
202
+ holder_id: 'h',
203
+ priority: 0,
204
+ ttl_ms: 30000,
205
+ reentrant: true,
206
+ };
207
+ case 'lease_release':
208
+ return { kind, scope: 'project', lane: 'tasks', holder_id: 'h', epoch: 1 };
209
+ case 'lease_renew':
210
+ return { kind, scope: 'project', lane: 'tasks', holder_id: 'h', epoch: 1 };
211
+ case 'rate_check':
212
+ return { kind, scope: 'global', lane: 'bulk', est_bytes: 4096 };
213
+ case 'tool_grant':
214
+ return { kind, tool: 'browser', holder_id: 'h' };
215
+ }
216
+ }
217
+
218
+ /** Build a minimal valid response payload for the given kind. */
219
+ function sampleResponseFor(kind: (typeof LEASE_IPC_RESPONSE_KINDS)[number]): unknown {
220
+ switch (kind) {
221
+ case 'lease_granted':
222
+ return {
223
+ kind,
224
+ scope: 'project',
225
+ lane: 'tasks',
226
+ holder_id: 'h',
227
+ epoch: 1,
228
+ ttl_ms: 30000,
229
+ expires_at_ms: 1000030000,
230
+ };
231
+ case 'lease_queued':
232
+ return { kind, scope: 'project', lane: 'tasks', ticket: 1, ahead: 0 };
233
+ case 'lease_denied':
234
+ return { kind, scope: 'global', code: 'E_LEASE_UNAVAILABLE', message: 'no arbiter' };
235
+ case 'rate_result':
236
+ return { kind, scope: 'global', ok: true, retry_after_ms: 0, tokens_remaining: 10 };
237
+ case 'tool_granted':
238
+ return { kind, tool: 'browser', holder_id: 'h' };
239
+ case 'lease_revoked':
240
+ return { kind, scope: 'project', lane: 'tasks', holder_id: 'h', reason: 'ttl expired' };
241
+ case 'child_killed_unresponsive':
242
+ return { kind, child_id: 'w1', holder_id: 'h', scope: 'project', reason: 'unresponsive' };
243
+ case 'error':
244
+ return { kind, code: 'E_X', message: 'x' };
245
+ }
246
+ }
@@ -0,0 +1,63 @@
1
+ /**
2
+ * `lease-ipc` v1.1 — PARALLEL DbWriterLease IPC contract barrel (T11627 ST-1).
3
+ *
4
+ * Re-exports the version constants and Zod message schemas + inferred types for
5
+ * the CLEO DbWriterLease arbitration surface. Runs **in parallel** to the
6
+ * byte-frozen `supervisor-ipc` v1.0 contract — see
7
+ * {@link LEASE_IPC_PROTOCOL_VERSION}. ST-1 ships the protocol surface with no
8
+ * consumer (zero behavior change); the local-mode arbiter (ST-2+) and the
9
+ * supervisor fast path (ST-5) consume it later.
10
+ *
11
+ * @task T11627
12
+ * @packageDocumentation
13
+ */
14
+
15
+ export type {
16
+ ChildKilledUnresponsiveResponse,
17
+ LeaseAcquireRequest,
18
+ LeaseDeniedResponse,
19
+ LeaseErrorResponse,
20
+ LeaseGrantedResponse,
21
+ LeaseIpcEnvelope,
22
+ LeaseIpcRequest,
23
+ LeaseIpcRequestEnvelope,
24
+ LeaseIpcResponse,
25
+ LeaseIpcResponseEnvelope,
26
+ LeaseLane,
27
+ LeaseQueuedResponse,
28
+ LeaseReleaseRequest,
29
+ LeaseRenewRequest,
30
+ LeaseRevokedResponse,
31
+ LeaseScope,
32
+ RateCheckRequest,
33
+ RateResultResponse,
34
+ ToolGrantedResponse,
35
+ ToolGrantRequest,
36
+ } from './messages.js';
37
+
38
+ export {
39
+ ChildKilledUnresponsiveResponseSchema,
40
+ LEASE_IPC_MESSAGE_KINDS,
41
+ LEASE_IPC_REQUEST_KINDS,
42
+ LEASE_IPC_RESPONSE_KINDS,
43
+ LeaseAcquireRequestSchema,
44
+ LeaseDeniedResponseSchema,
45
+ LeaseErrorResponseSchema,
46
+ LeaseGrantedResponseSchema,
47
+ LeaseIpcEnvelopeSchema,
48
+ LeaseIpcRequestEnvelopeSchema,
49
+ LeaseIpcRequestSchema,
50
+ LeaseIpcResponseEnvelopeSchema,
51
+ LeaseIpcResponseSchema,
52
+ LeaseLaneSchema,
53
+ LeaseQueuedResponseSchema,
54
+ LeaseReleaseRequestSchema,
55
+ LeaseRenewRequestSchema,
56
+ LeaseRevokedResponseSchema,
57
+ LeaseScopeSchema,
58
+ RateCheckRequestSchema,
59
+ RateResultResponseSchema,
60
+ ToolGrantedResponseSchema,
61
+ ToolGrantRequestSchema,
62
+ } from './messages.js';
63
+ export { isFrozenLeaseIpcVersion, LEASE_IPC_PROTOCOL_VERSION } from './version.js';