@agentplat/mesh 0.3.0-alpha.1 → 0.3.0-alpha.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 (102) hide show
  1. package/README.md +247 -2
  2. package/dist/coordination-allocation-contracts.d.ts +598 -0
  3. package/dist/coordination-allocation-contracts.d.ts.map +1 -0
  4. package/dist/coordination-allocation-contracts.js +2 -0
  5. package/dist/coordination-allocation-contracts.js.map +1 -0
  6. package/dist/coordination-allocation-state.d.ts +19 -0
  7. package/dist/coordination-allocation-state.d.ts.map +1 -0
  8. package/dist/coordination-allocation-state.js +5496 -0
  9. package/dist/coordination-allocation-state.js.map +1 -0
  10. package/dist/coordination-allocation.d.ts +10 -0
  11. package/dist/coordination-allocation.d.ts.map +1 -0
  12. package/dist/coordination-allocation.js +2743 -0
  13. package/dist/coordination-allocation.js.map +1 -0
  14. package/dist/coordination-contracts.d.ts +78 -0
  15. package/dist/coordination-contracts.d.ts.map +1 -0
  16. package/dist/coordination-contracts.js +2 -0
  17. package/dist/coordination-contracts.js.map +1 -0
  18. package/dist/coordination-discovery-contracts.d.ts +150 -0
  19. package/dist/coordination-discovery-contracts.d.ts.map +1 -0
  20. package/dist/coordination-discovery-contracts.js +2 -0
  21. package/dist/coordination-discovery-contracts.js.map +1 -0
  22. package/dist/coordination-discovery-state.d.ts +12 -0
  23. package/dist/coordination-discovery-state.d.ts.map +1 -0
  24. package/dist/coordination-discovery-state.js +542 -0
  25. package/dist/coordination-discovery-state.js.map +1 -0
  26. package/dist/coordination-discovery.d.ts +19 -0
  27. package/dist/coordination-discovery.d.ts.map +1 -0
  28. package/dist/coordination-discovery.js +850 -0
  29. package/dist/coordination-discovery.js.map +1 -0
  30. package/dist/coordination-execution.d.ts +6 -0
  31. package/dist/coordination-execution.d.ts.map +1 -0
  32. package/dist/coordination-execution.js +854 -0
  33. package/dist/coordination-execution.js.map +1 -0
  34. package/dist/coordination-inbound-contracts.d.ts +150 -0
  35. package/dist/coordination-inbound-contracts.d.ts.map +1 -0
  36. package/dist/coordination-inbound-contracts.js +2 -0
  37. package/dist/coordination-inbound-contracts.js.map +1 -0
  38. package/dist/coordination-inbound-state.d.ts +26 -0
  39. package/dist/coordination-inbound-state.d.ts.map +1 -0
  40. package/dist/coordination-inbound-state.js +331 -0
  41. package/dist/coordination-inbound-state.js.map +1 -0
  42. package/dist/coordination-inbound.d.ts +16 -0
  43. package/dist/coordination-inbound.d.ts.map +1 -0
  44. package/dist/coordination-inbound.js +944 -0
  45. package/dist/coordination-inbound.js.map +1 -0
  46. package/dist/coordination-lease-renewal.d.ts +8 -0
  47. package/dist/coordination-lease-renewal.d.ts.map +1 -0
  48. package/dist/coordination-lease-renewal.js +518 -0
  49. package/dist/coordination-lease-renewal.js.map +1 -0
  50. package/dist/coordination-objective-topic-contracts.d.ts +70 -0
  51. package/dist/coordination-objective-topic-contracts.d.ts.map +1 -0
  52. package/dist/coordination-objective-topic-contracts.js +2 -0
  53. package/dist/coordination-objective-topic-contracts.js.map +1 -0
  54. package/dist/coordination-objective-topic.d.ts +6 -0
  55. package/dist/coordination-objective-topic.d.ts.map +1 -0
  56. package/dist/coordination-objective-topic.js +561 -0
  57. package/dist/coordination-objective-topic.js.map +1 -0
  58. package/dist/coordination-objective-work-contracts.d.ts +212 -0
  59. package/dist/coordination-objective-work-contracts.d.ts.map +1 -0
  60. package/dist/coordination-objective-work-contracts.js +2 -0
  61. package/dist/coordination-objective-work-contracts.js.map +1 -0
  62. package/dist/coordination-objective-work-state.d.ts +10 -0
  63. package/dist/coordination-objective-work-state.d.ts.map +1 -0
  64. package/dist/coordination-objective-work-state.js +1075 -0
  65. package/dist/coordination-objective-work-state.js.map +1 -0
  66. package/dist/coordination-objective-work-time.d.ts +9 -0
  67. package/dist/coordination-objective-work-time.d.ts.map +1 -0
  68. package/dist/coordination-objective-work-time.js +48 -0
  69. package/dist/coordination-objective-work-time.js.map +1 -0
  70. package/dist/coordination-objective-work.d.ts +11 -0
  71. package/dist/coordination-objective-work.d.ts.map +1 -0
  72. package/dist/coordination-objective-work.js +1090 -0
  73. package/dist/coordination-objective-work.js.map +1 -0
  74. package/dist/coordination-recovery.d.ts +13 -0
  75. package/dist/coordination-recovery.d.ts.map +1 -0
  76. package/dist/coordination-recovery.js +951 -0
  77. package/dist/coordination-recovery.js.map +1 -0
  78. package/dist/coordination-reducer.d.ts +8 -0
  79. package/dist/coordination-reducer.d.ts.map +1 -0
  80. package/dist/coordination-reducer.js +81 -0
  81. package/dist/coordination-reducer.js.map +1 -0
  82. package/dist/coordination-state.d.ts +13 -0
  83. package/dist/coordination-state.d.ts.map +1 -0
  84. package/dist/coordination-state.js +335 -0
  85. package/dist/coordination-state.js.map +1 -0
  86. package/dist/coordination-topic-contracts.d.ts +82 -0
  87. package/dist/coordination-topic-contracts.d.ts.map +1 -0
  88. package/dist/coordination-topic-contracts.js +2 -0
  89. package/dist/coordination-topic-contracts.js.map +1 -0
  90. package/dist/coordination-topic.d.ts +6 -0
  91. package/dist/coordination-topic.d.ts.map +1 -0
  92. package/dist/coordination-topic.js +561 -0
  93. package/dist/coordination-topic.js.map +1 -0
  94. package/dist/coordination.d.ts +21 -0
  95. package/dist/coordination.d.ts.map +1 -0
  96. package/dist/coordination.js +21 -0
  97. package/dist/coordination.js.map +1 -0
  98. package/dist/sha256.d.ts +3 -0
  99. package/dist/sha256.d.ts.map +1 -0
  100. package/dist/sha256.js +117 -0
  101. package/dist/sha256.js.map +1 -0
  102. package/package.json +7 -3
package/README.md CHANGED
@@ -42,8 +42,253 @@ The coordinator validates canonical, bounded identity, admission, peer, replay,
42
42
  message-ID, preparation and causal state before cryptographic work. Logical time
43
43
  is monotonic across reducer and inbound transitions.
44
44
 
45
- Alpha 1 accepts direct peer audiences only. Mesh-topic intake, work allocation,
46
- leases and recovery are introduced in later preview releases.
45
+ The additive `@agentplat/mesh/coordination` subpath provides the Alpha 2 runtime
46
+ foundation without changing the Alpha 1 state, limits, input or effect
47
+ contracts. It defines a strict schema-versioned snapshot with bounded redacted
48
+ domain-record metadata, generation-fenced trusted timers and a bounded decision
49
+ journal. Its pure timer evaluator uses only injected logical time; an early,
50
+ stale or duplicate generation cannot mutate state, and journal exhaustion
51
+ fails closed before a due timer is consumed.
52
+
53
+ The generic coordination timer evaluator refuses workflow-owned
54
+ `objective.expiry`, `work.deadline` and `lease.expiry` timers. Those timers are
55
+ evaluated only by their Objective/Work or Allocation workflow evaluator, so
56
+ the generic path cannot consume or reinterpret them.
57
+
58
+ The foundation does not schedule host timers. Driver integration is added only
59
+ with the workflow increment that first creates each timer, so a public effect
60
+ cannot be emitted before loopback and simulation drivers know how to interpret
61
+ it.
62
+
63
+ The same subpath now exposes an independently versioned discovery projection.
64
+ Local admission is explicit and separate from Peer Cards; a card can refresh
65
+ only an admitted identity and cannot extend admission validity. Verified Peer
66
+ Card and capability records update causal high-water projections with hard
67
+ entry and encoded-byte ceilings. Expiry and passive-view eviction use injected
68
+ logical time and canonical ordering. Runtime composition also checks that every
69
+ routable projection is backed by the corresponding accepted domain record and
70
+ that sibling instances cannot mutate each other's discovery heads.
71
+
72
+ `matchMeshDiscoveryCapabilities` returns deterministic local matches and reason
73
+ codes from unexpired self-claims. `selectMeshDiscoveryTopicRecipients` resolves
74
+ a bounded recipient set only from the caller's local Peer View. Neither API
75
+ returns assignment authority, epochs, leases or fencing tokens. The evaluator
76
+ accepts only `VerifiedMeshEnvelope` values.
77
+
78
+ `createMeshDiscoveryInboundProcessor` constructs the authenticated coordination
79
+ boundary. It snapshots trusted local key resolution, cryptographic policy, Web
80
+ Crypto and protocol options outside the remote-message path. Each request then
81
+ contains only the envelope and trusted receiver times. The processor revalidates
82
+ scope, audience, freshness and critical extensions before the reference
83
+ verifier, then applies configured admission, instance ownership and an
84
+ independently restorable replay snapshot before the discovery projection.
85
+ Resolver lookup is synchronous by contract and cannot hide network I/O.
86
+ Rejections before replay return the original composite state; an authenticated
87
+ message that reaches replay but fails a domain transition retains replay
88
+ accounting without changing discovery or domain state. Rejection codes are
89
+ local diagnostics, not transport response payloads; adapters must rate-limit
90
+ ingress and avoid exposing cryptographic distinctions. Topic receipt never
91
+ relays or emits effects.
92
+
93
+ `createMeshCoordinationTopicDriver` is the final Increment 1 coordination-only
94
+ driver. It is an additive, bounded in-memory reference driver, not a production
95
+ transport or durability mechanism. Its process-local registry is a route table,
96
+ not membership: it selects recipients only from the publisher's local active
97
+ Peer View, joined to endpoints registered for those exact current instances.
98
+ It never consults a global recipient oracle, supplies a complete membership
99
+ view, fans out beyond that snapshot, or forwards a received envelope.
100
+
101
+ The driver copies the exact signed envelope for every selected recipient into
102
+ one atomically accepted bounded FIFO queue and serializes delivery. Each
103
+ receiver is invoked only through its construction-bound trusted clock and
104
+ inbound processor. Public receipts deliberately coarsen rejection details to
105
+ `accepted`, `rejected` or `unavailable`; detailed codes remain local diagnostics
106
+ and cannot be used as a remote validation oracle.
107
+
108
+ The first Increment 2 slice adds a separate Objective and Work Item projection.
109
+ `createMeshObjectiveWorkState` provisions bounded issuer peer/key authority;
110
+ `createMeshObjectiveWorkRuntimeState` composes it with aligned coordination and
111
+ discovery snapshots. Strict restoration binds each Objective's coordination
112
+ domain record to its `objectiveId`, retains the complete signed envelope and
113
+ derived policy for every accepted Objective revision under a hard non-evicting
114
+ limit, and canonicalizes each Work Item to that exact immutable policy head.
115
+ Restore validates the closed envelope, recomputes the canonical SHA-256 payload
116
+ digest, checks derived wall/logical expiry metadata and binds the result to the
117
+ accepted domain record. A cancelled head also retains its signed cancellation
118
+ envelope and binds its payload, digest, message, cause and trusted validation
119
+ time to the terminal record. It rejects missing, forged, orphaned or
120
+ cross-revision bindings. Objective revision `1`, exact next revisions,
121
+ cancellation and expiry are causal and terminal. An issuer may rotate among its
122
+ currently provisioned keys, but another issuer peer cannot take over an
123
+ Objective.
124
+
125
+ Local `work.create`, `work.revise` and `work.cancel` commands derive local
126
+ ownership and the exact next Work Item revision. They use only caller-injected
127
+ trusted wall and logical time, enforce the current Objective's capability,
128
+ Work Item-count, per-Work budget and deadline ceilings, and reject without
129
+ mutation when journal, timer or projection capacity is unavailable. Stable
130
+ length-prefixed timer IDs avoid ambiguous composite identifiers; exact
131
+ generations fence both Objective expiry and Work deadlines. RFC 3339
132
+ sub-millisecond differences use exact nanosecond arithmetic and round a
133
+ positive remainder up to one logical millisecond. A later Objective revision
134
+ governs later Work revisions but does not rewrite an existing Work Item or its
135
+ timer binding. Any attempt to create a timer whose stable ID collides with a
136
+ different existing timer fails closed.
137
+
138
+ `evaluateVerifiedMeshObjectiveEnvelope` is a pure already-verified boundary. It
139
+ revalidates closed protocol structure, context, admission instance and
140
+ provisioned issuer authority, but it does not perform signature verification or
141
+ replay accounting. Network adapters must not invoke it with merely parsed or
142
+ self-asserted values. Snapshot restore verifies the retained canonical payload
143
+ digest but does not resolve keys or reverify the proof, so persisted snapshots
144
+ must be integrity protected by the driver.
145
+
146
+ `createMeshObjectiveInboundProcessor` is the authenticated ingress boundary for
147
+ Objective messages. It shares the discovery replay and retained-message-ID
148
+ security snapshot, and applies checks in this order: context, cryptographic
149
+ verification, exact admission and issuer authority, replay accounting, then the
150
+ Objective domain transition. An authenticated message that reaches replay but
151
+ is rejected by the Objective domain retains normal security accounting while
152
+ leaving the domain projection unchanged. The runtime state contains immutable,
153
+ identity-aligned coordination, discovery, Objective and inbound-security
154
+ snapshots. If discovery alone advanced logical time, Objective evaluation uses
155
+ an ephemeral clock-aligned view without rewriting the Objective projection.
156
+
157
+ `createMeshCoordinationObjectiveTopicDriver` is the corresponding bounded,
158
+ in-memory Objective delivery driver. It selects recipients only from the
159
+ publisher's local active view, then captures registered routes for those exact
160
+ peer instances. It atomically admits copied signed envelopes to a bounded FIFO
161
+ queue and invokes the registered Objective inbound processor with a
162
+ construction-bound clock. Receipts expose only `accepted`, `rejected` or
163
+ `unavailable`; detailed rejection information is local diagnostic data. The
164
+ driver is sender-local: it provides no forwarding, global membership view,
165
+ durability or delivery guarantee.
166
+
167
+ An exact historical Objective record is idempotent only after this evaluator
168
+ has applied the current structure, context, admission, issuer-authority and
169
+ freshness checks; it cannot use duplicate handling to bypass them or restore an
170
+ older Objective head.
171
+
172
+ The Alpha 1 root runtime continues to accept direct peer audiences and its
173
+ `peer.hello`, `peer.ping` and `peer.ping_ack` workflows only. The explicit
174
+ coordination subpath now projects already-verified discovery and Objective
175
+ records plus local ready Work Items.
176
+
177
+ The first Allocation sub-slice adds a separately versioned, immutable
178
+ projection for a local owner's first offer attempt. The owner supplies one
179
+ recipient-specific, already-signed direct `work.offer` envelope for every
180
+ candidate selected from its bounded local capability view. The reducer validates
181
+ the exact envelopes and retains each recipient's `messageId`; a verified direct
182
+ `work.bid` must causally name that exact message ID. Bid replacements are
183
+ causal and revision-monotonic, retained signed evidence is bounded, and
184
+ deterministic selection is read-only: lowest budget units, earliest expected
185
+ completion, peer ID, then bid ID.
186
+
187
+ Opening that first offer reserves the Work Item's budget immediately and
188
+ creates a generation-fenced bid-deadline timer. When due, the timer closes the
189
+ offer and releases its reservation exactly once. The local signer that prepares
190
+ offer envelopes is a trusted driver boundary; this reducer does not verify a
191
+ signature itself.
192
+
193
+ The owner-side award increment extends that projection with one prepared,
194
+ signed direct `work.award` envelope for the current deterministic bid. Awarding
195
+ atomically closes the bid window, replaces its timer with a generation-fenced
196
+ acceptance timer and keeps the reservation reserved. Already-verified direct
197
+ `work.accept` and `work.decline` responses are accepted only from the awarded
198
+ assignee with exact award-envelope causation, current Objective/Work bindings,
199
+ initial epoch and matching authority/token. The acceptance deadline is
200
+ exclusive: acceptance moves budget reserved-to-committed and activates the
201
+ owner's Work projection; decline or timeout releases it exactly once.
202
+ Rejected award and assignment-response inputs expose phase-specific stable
203
+ codes (`award_*`, `assignment_*` and `assignment_response_*`) so telemetry does
204
+ not misclassify them as offer or bid failures. Replaying the exact same signed
205
+ response is idempotent; reusing its ID or message ID with any different signed
206
+ envelope is a conflict.
207
+
208
+ After a reservation is released, a later offer uses exactly the next attempt
209
+ number and names the preceding offer. It opens a fresh bounded bid window and
210
+ reserves the same Work Item budget anew; it cannot rewrite the Work revision or
211
+ reuse the original attempt.
212
+
213
+ The owner-side state machine establishes allocation, and the execution
214
+ lifecycle consumes only its accepted assignment authority. A valid signature or
215
+ admission entry alone never grants execution authority.
216
+
217
+ The paired assignee-side allocation slice accepts an already-verified direct
218
+ `work.award` only for the local peer and only when it proves the peer's retained
219
+ prepared bid and recipient-specific offer-envelope causation. Offer and award
220
+ intake independently enforce the current accepted Objective document and its
221
+ budget, capability and timing limits. Later offers preserve immutable Work
222
+ terms and require the exact predecessor offer and envelope causation after
223
+ predecessor closure. Its separately restorable bounded
224
+ projection retains the signed award, epoch, authority, fencing token, lease and
225
+ exclusive response deadline. Before that deadline, the local peer can commit
226
+ one prepared signed `work.accept` or `work.decline` and emit its dispatch
227
+ effect; exact retries are idempotent and conflicting reuse is rejected without
228
+ mutation. A successful local acceptance retains the initial assignment
229
+ authority. A due generation-fenced local response deadline closes the local
230
+ award without sending a response, and dispatch is not evidence that the owner
231
+ received a response.
232
+
233
+ The execution-lifecycle slice accepts locally prepared or authenticated inbound
234
+ `work.progress`, `work.checkpoint`, `work.result`, `work.release` and
235
+ `work.cancel` records. It retains bounded signed records and an assignment-scope
236
+ head, enforces direct audience and role authority, exact Objective/Work and
237
+ assignment bindings, current epoch and fencing token, causation and sequence
238
+ rules, and trusted Work/current-lease deadlines. Progress and checkpoints are
239
+ append-only; a result, release or cancellation is terminal and later ordinary
240
+ records are rejected. Exact replay is idempotent while identifier or canonical
241
+ content reuse conflicts fail closed. Owner cancellation of a pending award
242
+ releases its reservation; terminal active execution does not reverse committed
243
+ Objective budget accounting.
244
+
245
+ Accepted assignments immediately materialize a sequence-zero lease head and a
246
+ generation-fenced expiry timer. A locally prepared or authenticated direct
247
+ `lease.renew` record may extend only the current active lease while preserving
248
+ its assignee, epoch, authority and fencing token. Renewals form one exact
249
+ bounded predecessor chain, obey Objective duration/count and Work deadlines,
250
+ and replace the active timer generation atomically. Expiry is terminal for that
251
+ authority but retains all original assignment and renewal evidence. Terminal
252
+ execution retires the active lease timer and head without rewriting historical
253
+ records. Release and active cancellation causally name the latest accepted
254
+ renewal when one exists. Assignee execution and release remain lease-bound; the
255
+ owner may still close or cancel an expired assignment before the Work deadline.
256
+
257
+ Certified recovery retains direct assignment evidence at the configured
258
+ witnesses. After lease expiry plus the Objective recovery grace, a candidate or
259
+ witness can fan out a recipient-specific proposal for exactly the next epoch.
260
+ Each fixed witness contributes at most one vote for that stable assignment
261
+ scope and proposed epoch. A certificate requires the configured majority of
262
+ distinct votes and advances the stable fence before any replacement can become
263
+ active. The unchanged owner must then issue a recovery award for the certified
264
+ candidate, epoch and `certificateId` token; acceptance reuses the existing
265
+ budget commitment and resumes the checkpoint named by that award. A proposal,
266
+ vote or certificate alone never grants execution authority, and an unavailable
267
+ owner leaves the newer epoch fenced but inactive. The first replacement
268
+ checkpoint must name the award's checkpoint as its parent and use its sequence
269
+ plus one. A local recovery command verifies the complete exact direct fanout;
270
+ an authenticated received copy verifies only its own audience, role and causal
271
+ evidence, and never asserts delivery to other recipients.
272
+
273
+ Allocation snapshots now use schema version 6. Restore migrates versions 1–5
274
+ deterministically, derives sequence-zero lease heads and missing initial expiry
275
+ timers for legacy accepted assignments, and derives conservative bounded
276
+ limits. Strict restore revalidates retained envelopes, causal/domain bindings,
277
+ each signed renewal's complete authority and derived logical deadline, stable
278
+ fence heads, witness copies, proposal/vote/certificate graphs, checkpoint
279
+ resume metadata, current lease heads, historical execution deadlines, timer
280
+ generations, terminal heads and accounting before exposing the immutable
281
+ snapshot.
282
+
283
+ `createMeshAllocationInboundProcessor` authenticates Allocation traffic before
284
+ domain evaluation. It construction-binds key resolution and cryptographic
285
+ policy, then orders context, signature verification, exact admission and
286
+ instance authority, replay accounting and the allocation transition. A signed
287
+ execution record rejected by the domain still consumes normal replay security
288
+ accounting; diagnostics remain local. The same boundary accepts authenticated
289
+ `lease.renew`, `lease.takeover_proposal`, `lease.vote` and `lease.certificate`
290
+ records only after replay and admission checks. This alpha does not implement
291
+ durable execution storage, owner transfer or external-action authority.
47
292
 
48
293
  `@agentplat/mesh/loopback` provides the explicit in-memory signed transport used
49
294
  by the local vertical slice. `createMeshLoopbackTransport` owns composite