stitchkit 0.71.0 → 0.72.1

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 (57) hide show
  1. package/README.md +1 -1
  2. package/dist/application/admission.d.ts +22 -2
  3. package/dist/application/admission.d.ts.map +1 -1
  4. package/dist/application/channel.d.ts +28 -0
  5. package/dist/application/channel.d.ts.map +1 -1
  6. package/dist/application/diagnostic-journal-contract.d.ts +20 -0
  7. package/dist/application/diagnostic-journal-contract.d.ts.map +1 -1
  8. package/dist/application/diagnostic-journal-lock.d.ts +17 -0
  9. package/dist/application/diagnostic-journal-lock.d.ts.map +1 -0
  10. package/dist/application/diagnostic-journal-manager.d.ts +2 -1
  11. package/dist/application/diagnostic-journal-manager.d.ts.map +1 -1
  12. package/dist/application/diagnostic-journal-storage.d.ts +4 -1
  13. package/dist/application/diagnostic-journal-storage.d.ts.map +1 -1
  14. package/dist/application/diagnostic-journal.d.ts +4 -2
  15. package/dist/application/diagnostic-journal.d.ts.map +1 -1
  16. package/dist/application-opentelemetry.js +1 -1
  17. package/dist/application.d.ts +3 -3
  18. package/dist/application.d.ts.map +1 -1
  19. package/dist/application.js +134 -21
  20. package/dist/browser/resumable.d.ts +56 -0
  21. package/dist/browser/resumable.d.ts.map +1 -0
  22. package/dist/{index-zpyj7hsv.js → index-3cwck0rm.js} +98 -33
  23. package/dist/index.d.ts +1 -0
  24. package/dist/index.d.ts.map +1 -1
  25. package/dist/index.js +103 -14
  26. package/dist/primitives/audit.d.ts +52 -0
  27. package/dist/primitives/audit.d.ts.map +1 -0
  28. package/dist/primitives/deadline.d.ts +39 -0
  29. package/dist/primitives/deadline.d.ts.map +1 -0
  30. package/dist/primitives/decimal.d.ts +10 -0
  31. package/dist/primitives/decimal.d.ts.map +1 -0
  32. package/dist/primitives/delivery.d.ts +96 -0
  33. package/dist/primitives/delivery.d.ts.map +1 -0
  34. package/dist/primitives/event.d.ts +42 -0
  35. package/dist/primitives/event.d.ts.map +1 -0
  36. package/dist/primitives/export-operation.d.ts +89 -0
  37. package/dist/primitives/export-operation.d.ts.map +1 -0
  38. package/dist/primitives/index.d.ts +12 -0
  39. package/dist/primitives/index.d.ts.map +1 -0
  40. package/dist/primitives/lifecycle.d.ts +90 -0
  41. package/dist/primitives/lifecycle.d.ts.map +1 -0
  42. package/dist/primitives/migration-checks.d.ts +15 -0
  43. package/dist/primitives/migration-checks.d.ts.map +1 -0
  44. package/dist/primitives/money.d.ts +43 -0
  45. package/dist/primitives/money.d.ts.map +1 -0
  46. package/dist/primitives/owner-scope.d.ts +30 -0
  47. package/dist/primitives/owner-scope.d.ts.map +1 -0
  48. package/dist/primitives/permission.d.ts +28 -0
  49. package/dist/primitives/permission.d.ts.map +1 -0
  50. package/dist/primitives/quantity.d.ts +57 -0
  51. package/dist/primitives/quantity.d.ts.map +1 -0
  52. package/dist/primitives.d.ts +3 -0
  53. package/dist/primitives.d.ts.map +1 -0
  54. package/dist/primitives.js +750 -0
  55. package/llms-full.txt +270 -3
  56. package/llms.txt +1 -0
  57. package/package.json +6 -2
package/llms-full.txt CHANGED
@@ -48,6 +48,7 @@ own, recorded as an ADR.
48
48
  |--------|--------|----------|-------|
49
49
  | `stitchkit` | browser **and** server | stable | `defineContract`, `createClient`, `createHttpClient`, `createSocketIOClient`, `parseSSE`, the error model |
50
50
  | `stitchkit/contract` | browser **and** server | stable | the contract layer alone — `defineContract`, errors, pagination |
51
+ | `stitchkit/primitives` | browser **and** server | evolving | generic values and declarations for lifecycle, access, audit, delivery and exports |
51
52
  | `stitchkit/server` | server (Bun) | stable | `createServer`, `implement`, hooks, auth, Socket.IO server, server primitives |
52
53
  | `stitchkit/node` | server (Node ≥ 22) | stable | `serveNode` + the runtime-agnostic core — the Node mirror of `/server` |
53
54
  | `stitchkit/tools` | server | stable | `createMcpHandler`, `mountMcp`, `mountAgent`, the OAuth provider, native tools |
@@ -60,7 +61,7 @@ own, recorded as an ADR.
60
61
  | `stitchkit/testing` | tests on Bun or Node | stable | in-process generated clients over a real Fetch handler, plus the store and managed-resource conformance kits |
61
62
  | `stitchkit/declaration` | build and deployment tooling (Bun or Node) | evolving | `ProjectDeclarationSchema` — the one machine-readable statement a repository makes about itself |
62
63
  | `stitchkit/react` | browser | stable | `createCursorQuery`, `createCacheBridge` |
63
- | `stitchkit/agent-runtime` | server | evolving<br>_redefined in 10 of the 16 minors since 0.56.2, most recently 0.69.0_ | optional durable conversation/run loop, history, models, prompts, fencing and events |
64
+ | `stitchkit/agent-runtime` | server | evolving<br>_redefined in 10 of the 17 minors since 0.56.2, most recently 0.69.0_ | optional durable conversation/run loop, history, models, prompts, fencing and events |
64
65
  | `stitchkit/agent-runtime/harness` | server | evolving | resource-aware process-local facade over the canonical Agent runtime; supervision stays outside |
65
66
  | `stitchkit/agent-runtime/coding-tools` | server (Bun or Node) | evolving | bounded host-authorized direct file and shell tools; a root boundary, not an OS sandbox |
66
67
  | `stitchkit/agent-runtime/openrouter` | server | evolving | isolated OpenRouter language-model adapter |
@@ -68,7 +69,7 @@ own, recorded as an ADR.
68
69
  | `stitchkit/agent-runtime/sqlite/bun` | server (Bun) | evolving | durable built-in SQLite store for the agent runtime |
69
70
  | `stitchkit/agent-runtime/sqlite/node` | server (Node ≥ 22.5) | evolving | durable built-in SQLite store for the agent runtime |
70
71
  | `stitchkit-tui` | terminal (Bun) | evolving | optional official OpenTUI host over a caller-composed headless runtime |
71
- | `stitchkit/application` | server | evolving<br>_redefined in 3 of the 16 minors since 0.56.2, most recently 0.67.0_ | managed resource graph, readiness, admission, schedules and bounded shutdown |
72
+ | `stitchkit/application` | server | evolving<br>_redefined in 4 of the 17 minors since 0.56.2, most recently 0.72.0_ | managed resource graph, readiness, admission, schedules and bounded shutdown |
72
73
  | `stitchkit/application/grammy` | server | evolving | isolated grammY polling and webhook lifecycle adapters |
73
74
  | `stitchkit/application/opentelemetry` | server | evolving | maps application snapshots onto an injected OpenTelemetry `Meter` |
74
75
 
@@ -2565,6 +2566,49 @@ Set `finalLine: 'require-newline'` when the final newline is part of the
2565
2566
  protocol's truncation proof. The default `allow` continues to accept one valid
2566
2567
  final JSON document without a newline.
2567
2568
 
2569
+ ## Resumable streams
2570
+
2571
+ A stream that survives a dropped connection needs four things beyond opening it:
2572
+ re-open, back off before retrying, resume from where it stopped rather than
2573
+ restart, and stop for good on a terminal item. `resumableIterator` owns those
2574
+ four; your code keeps every decision that is about your data.
2575
+
2576
+ ```ts
2577
+ import { resumableIterator } from 'stitchkit'
2578
+
2579
+ for await (const event of resumableIterator<Event, string>({
2580
+ async open(cursor) {
2581
+ const url = cursor ? `/api/events?after=${cursor}` : '/api/events'
2582
+ return parseNDJSON(await fetch(url, { signal }))
2583
+ },
2584
+ advance: (event) => event.id, // what "where it stopped" means
2585
+ isTerminal: (event) => event.done, // which item ends the stream
2586
+ retry: { minDelayMs: 500, maxDelayMs: 30_000, jitter: 0.5 },
2587
+ signal,
2588
+ onAttempt: ({ number, delayMs, error }) => log.warn({ number, delayMs, error }),
2589
+ })) {
2590
+ render(event)
2591
+ }
2592
+ ```
2593
+
2594
+ `open` receives the cursor produced by the last **delivered** item, so a source
2595
+ that fails after three items re-opens after the third, not from the beginning.
2596
+ A source that simply ends without a terminal item is treated as a dropped
2597
+ connection — that is the case a hand-written loop usually mistakes for
2598
+ completion, and it is why the stream stops resuming.
2599
+
2600
+ **Jitter is not a detail.** Without it every consumer that lost the same server
2601
+ retries at the same instant and the fleet arrives together on a server that has
2602
+ just come back. The randomisation only ever *shortens* a delay, so `maxDelayMs`
2603
+ stays a real ceiling. `createBackoff({ minDelayMs, maxDelayMs, jitter })` is the
2604
+ same policy as a standalone value — `next()` and `reset()` — when you need the
2605
+ delays without the iterator.
2606
+
2607
+ A delivered item resets the backoff, so a stream that reconnects, works for an
2608
+ hour and drops again starts its next retry at `minDelayMs` rather than the
2609
+ ceiling it reached last time. Aborting the signal ends the iteration promptly,
2610
+ including in the middle of a wait.
2611
+
2568
2612
 
2569
2613
  ==============================================================================
2570
2614
  # Guide: MCP & agents (docs/guide/mcp-and-agents.md)
@@ -5609,6 +5653,110 @@ retry rules do **not** disappear. They were never process-local glue and remain
5609
5653
  application-owned.
5610
5654
 
5611
5655
 
5656
+ ==============================================================================
5657
+ # Guide: Generic application primitives (docs/guide/primitives.md)
5658
+ ==============================================================================
5659
+
5660
+ ---
5661
+ title: Generic application primitives
5662
+ description: Declare lifecycle, access, exact values, audit, delivery and exports without moving application infrastructure into Stitchkit.
5663
+ type: guide
5664
+ status: active
5665
+ created: 2026-09-01
5666
+ updated: 2026-09-01
5667
+ ---
5668
+
5669
+ # Generic application primitives
5670
+
5671
+ `stitchkit/primitives` is an optional browser-safe leaf. It declares values and policies; it does
5672
+ not own a database, transaction, scheduler, durable queue, transport or document generator.
5673
+
5674
+ ## Lifecycle and access
5675
+
5676
+ ```ts
5677
+ import { defineLifecycle, defineOwnerScope, definePermissionMatrix } from 'stitchkit/primitives';
5678
+ import { z } from 'zod';
5679
+
5680
+ const lifecycle = defineLifecycle({
5681
+ name: 'document',
5682
+ states: ['draft', 'published'],
5683
+ roles: ['author'],
5684
+ transitions: {
5685
+ publish: {
5686
+ from: 'draft',
5687
+ to: 'published',
5688
+ by: ['author'],
5689
+ payload: z.object({ note: z.string() }),
5690
+ },
5691
+ },
5692
+ });
5693
+
5694
+ const permissions = definePermissionMatrix({
5695
+ roles: ['reader', 'author'],
5696
+ operations: ['read', 'publish'],
5697
+ grants: {
5698
+ reader: { read: true, publish: false },
5699
+ author: { read: true, publish: true },
5700
+ },
5701
+ });
5702
+ ```
5703
+
5704
+ Persist `transition(...).event` in the same application transaction as the next state. A state is
5705
+ an immutable branded value; `transition()` produces the next one. `availableTransitions()` and
5706
+ `transition()` read the same declaration.
5707
+
5708
+ `defineOwnerScope` resolves one owner from authenticated identity. Reading across owners is a
5709
+ separate `acrossAllOwners(identity)` call and permission. Pass the resulting branded `OwnerScope`
5710
+ to the data adapter. This proves the scope was explicit; Stitchkit cannot prove what SQL an
5711
+ arbitrary adapter emits. `scanOwnerFilterRisks` maps existing caller-named manual filters before a
5712
+ migration.
5713
+
5714
+ ## Exact values and deadlines
5715
+
5716
+ `defineMoney(currency)` stores integer minor units as a JSON string. Arithmetic keeps the currency
5717
+ literal in the type; division and rational shares return an explicit remainder. It does not own
5718
+ exchange rates.
5719
+
5720
+ `defineUnitSystem` stores exact canonical decimal strings. Every conversion is an application
5721
+ rational with an id. A converted `QuantityProjection` is `derived` and carries both its source and
5722
+ conversion id; a form/database value can be marked `recorded`. Whether a derived projection is
5723
+ persisted or recomputed is an application decision.
5724
+
5725
+ `defineDeadlinePolicy` requires an explicit `now`, IANA timezone and elapsed/calendar-day boundary.
5726
+ It returns the due instant, signed remaining days, overdue days and caller-owned category key.
5727
+ `queryBoundary(now)` returns instants suitable for a data-adapter predicate; reminders and
5728
+ escalations are not included.
5729
+
5730
+ ## Audit and delivery
5731
+
5732
+ Put an audit decision beside each operation:
5733
+
5734
+ ```ts
5735
+ meta: { audit: audit.record(z.object({ changed: z.array(z.string()) })) }
5736
+ // or
5737
+ meta: { audit: audit.omit('read-only projection') }
5738
+ ```
5739
+
5740
+ `assertAuditDeclared(contract)` refuses silence. `createAuditRecord()` validates the change and
5741
+ returns a `DomainEvent`; the same id/value can feed both the journal and delivery.
5742
+
5743
+ `defineDomainEventDelivery().plan(event)` is pure. Save that event and its destinations in the
5744
+ application's transaction. After commit, call `dispatch(event.id)`: the dispatcher accepts only an
5745
+ id and obtains actual work from `DomainEventOutbox.claim`. A transport returns `delivered`,
5746
+ `retryable`, `terminal` or `unknown`; the dispatcher calls the matching outbox transition. Only
5747
+ `retry` may schedule another claim, while `unknown` is held for inspection instead of guessed into
5748
+ a retry. The application owns retention and scheduling. There is deliberately no scheduler or
5749
+ distributed lease.
5750
+
5751
+ ## Exports
5752
+
5753
+ `defineExportOperation` supplies one input and one result schema to an ordinary contract endpoint.
5754
+ A small result can be `ready` with a `ManagedFileRef`; a larger result can be `pending` with the id
5755
+ of the application's existing async operation. The input, scope, metadata and tool identity do not
5756
+ change. The application creates bytes and owns operation persistence; the managed-file boundary
5757
+ streams them.
5758
+
5759
+
5612
5760
  ==============================================================================
5613
5761
  # Guide: Application migration recipes (docs/guide/application-migration-recipes.md)
5614
5762
  ==============================================================================
@@ -9293,6 +9441,69 @@ additive** — adopting it changes nothing in your code. (See
9293
9441
  So upgrading is: read the `### ⚠️ Breaking changes` of every version *above* your
9294
9442
  current one *up to* your target, and apply each snippet.
9295
9443
 
9444
+ ## What your range does, and does not, do for you
9445
+
9446
+ A caret range (`"stitchkit": "^0.71.0"`) is a real gate: it resolves `< 0.72.0`,
9447
+ so a plain `install` picks up every patch — fixes, new API, no code changes —
9448
+ and **never** crosses a minor. Crossing one is always something you chose.
9449
+
9450
+ **An exact pin (`"stitchkit": "0.71.0"`) is a different arrangement, and it is
9451
+ easy to mistake for a safer version of the same one.** It does not opt you out
9452
+ of breaking changes; it opts you out of *every* change, patches included. No
9453
+ install will move you, nothing will warn you, and the gap grows quietly — a
9454
+ project pinned exactly for a few months is typically several minors behind and
9455
+ has had no signal at all that this is so. That is a legitimate choice, but it
9456
+ makes one thing your job rather than the resolver's:
9457
+
9458
+ - **Check deliberately.** `npm view stitchkit version` against your pin, on
9459
+ whatever cadence suits the project. Nothing else will raise it.
9460
+ - **Then upgrade across the whole gap at once**, exactly as below: apply the
9461
+ `### ⚠️ Breaking changes` of every version above your pin up to your target,
9462
+ in order. A pin held across four minors is four migrations, not one, and
9463
+ three of them may be a single snippet each.
9464
+
9465
+ The mechanical part is identical either way. Only the *noticing* differs, and an
9466
+ exact pin moves it onto you.
9467
+
9468
+ ## Released migration: 0.72.0
9469
+
9470
+ Nothing you *pass* changed. Both items are about types you read or build, and
9471
+ both stop the compiler rather than surprising you at runtime.
9472
+
9473
+ ### If you read `perKey` off `BoundedAdmissionPolicy`
9474
+
9475
+ `perKey` is now a union: the flat ceiling it always was, or `{ maxKeys, limits }`
9476
+ where the ceiling is resolved from the key. Declaring one is unchanged; reading
9477
+ one needs a narrowing.
9478
+
9479
+ ```ts
9480
+ // before
9481
+ const ceiling = policy.perKey?.maxConcurrent
9482
+
9483
+ // after
9484
+ const ceiling =
9485
+ policy.perKey && !('limits' in policy.perKey) ? policy.perKey.maxConcurrent : undefined
9486
+ ```
9487
+
9488
+ A shape carrying members of both branches — `{ maxKeys, maxConcurrent, limits }` —
9489
+ is refused at construction. It does *not* fail to typecheck: an excess-property
9490
+ check against a union admits any property some member declares, so this one is
9491
+ caught by `createBoundedAdmission`, not by `tsc`.
9492
+
9493
+ ### If you build a snapshot or a status by hand
9494
+
9495
+ `CreditWindowSnapshot` gained `waiting` (producers parked in the new waiting
9496
+ `acquire`) and `DiagnosticJournalStatus` gained `lock`. Both are produced by the
9497
+ framework, so reading them is unaffected — but a test double stops compiling:
9498
+
9499
+ ```ts
9500
+ // before
9501
+ const snapshot: CreditWindowSnapshot = { state: 'open', capacityBytes: 100, /* … */ }
9502
+
9503
+ // after
9504
+ const snapshot: CreditWindowSnapshot = { state: 'open', capacityBytes: 100, /* … */ waiting: 0 }
9505
+ ```
9506
+
9296
9507
  ## Released migration: 0.71.0
9297
9508
 
9298
9509
  The Agent coding tools. Two of the three changes are visible to the compiler;
@@ -12020,6 +12231,8 @@ The browser-and-server entrypoint. Re-exports everything from
12020
12231
  | `createRetainedTopics` | function | retained last-value store for sticky events — [guide](../guide/realtime.md#sticky-events) |
12021
12232
  | `parseSSE` | function | parse an SSE `Response` into an async generator — [guide](../guide/client.md#sse) |
12022
12233
  | `parseNDJSON` | function | parse bounded fatal-UTF-8 NDJSON; blank keep-alives are skipped and `finalLine: 'require-newline'` can make the delimiter mandatory — [guide](../guide/client.md#ndjson) |
12234
+ | `resumableIterator` | function | re-open a long-lived stream from the last delivered cursor, with jittered backoff, a caller-owned terminal item and prompt abort — [guide](../guide/client.md#resumable-streams) |
12235
+ | `createBackoff` | function | exponential backoff with subtractive jitter as a value: `next()` / `reset()` |
12023
12236
  | `ContractStreamFrameSchema` / `ContractStreamFrame` | schema / _type_ | default on-the-wire `data` / safe `error` / `end` envelope of a contract-first stream |
12024
12237
  | `ContractStreamFraming` / `ContractStreamCompletion` | _types_ | opt-in item-vs-envelope framing and terminal-vs-stream-end completion policies |
12025
12238
  | `StreamFinalLinePolicy` | _type_ | permissive or newline-required final NDJSON line policy |
@@ -12063,6 +12276,10 @@ The browser-and-server entrypoint. Re-exports everything from
12063
12276
  | `RetainedTopics` | _type_ | the `createRetainedTopics` handle |
12064
12277
  | `ParseSSEOptions` | _type_ | options for `parseSSE` |
12065
12278
  | `ParseNDJSONOptions` | _type_ | options for `parseNDJSON` |
12279
+ | `BackoffPolicySchema` / `BackoffPolicy` | schema / _type_ | `minDelayMs`, `maxDelayMs` and a `0`–`1` jitter fraction; a ceiling below the floor is refused |
12280
+ | `Backoff` | _type_ | the backoff handle returned by `createBackoff` |
12281
+ | `ResumableIteratorConfig` | _type_ | caller-owned `open` / `advance` / `isTerminal`, retry policy, abort signal and `onAttempt` observer |
12282
+ | `ResumableAttempt` | _type_ | attempt number, the delay about to be waited and the error that caused it |
12066
12283
 
12067
12284
  ### Trace (client)
12068
12285
 
@@ -12174,6 +12391,51 @@ from the root `stitchkit`.
12174
12391
 
12175
12392
  ---
12176
12393
 
12394
+ ## `stitchkit/primitives`
12395
+
12396
+ Browser-and-server-safe declarations for facts an application wants to define once. See the
12397
+ [primitives guide](../guide/primitives.md). Storage, transactions, data-adapter predicates,
12398
+ schedules, transports and file generation remain application-owned.
12399
+
12400
+ | Export | Kind | Summary |
12401
+ |--------|------|---------|
12402
+ | `defineLifecycle` | function | immutable finite-state transition declaration, role/payload validation, available-action projection and transition event |
12403
+ | `LifecycleState` / `LifecycleTransitionDefinition` / `LifecycleDefinition` | _types_ | branded state value and the declaration inferred from application strings |
12404
+ | `LifecycleTransitionInput` / `LifecycleTransitionResult` / `LifecycleTransitionSuccess` / `LifecycleTransitionFailure` | _types_ | typed execution input and distinct transition/state, role and payload outcomes |
12405
+ | `LifecycleTransitionEventSchema` / `LifecycleTransitionEvent` | schema / _type_ | canonical event returned for application-atomic persistence |
12406
+ | `defineOwnerScope` | function | resolve one owner from identity or require the explicit `acrossAllOwners` capability |
12407
+ | `OwnerScope` / `OwnerScopeDefinition` / `OwnerScopeResolution` | _types_ | branded adapter input and its resolved/refused outcomes |
12408
+ | `definePermissionMatrix` | function | exhaustive role × operation decisions with server check and client capability projection |
12409
+ | `PermissionGrantMatrix` / `PermissionCheckResult` | _types_ | compile-time complete matrix and unknown/allowed/denied runtime result |
12410
+ | `defineMoney` / `createMoneySchema` | functions | fixed-currency JSON-safe minor-unit value and Zod schema |
12411
+ | `addMoney` / `subtractMoney` / `multiplyMoney` / `shareMoney` / `splitMoney` | functions | exact same-currency arithmetic with explicit indivisible remainder |
12412
+ | `Money` / `MoneyShare` / `MoneySplit` | _types_ | currency-literal value and remainder-bearing operation results |
12413
+ | `defineUnitSystem` / `createQuantitySchema` / `addQuantity` | functions | exact decimal quantities and caller-declared finite conversions |
12414
+ | `Quantity` / `UnitConversion` / `QuantityProjection` | _types_ | unit-literal value, rational conversion and recorded/derived provenance |
12415
+ | `QuantityProjectionSchema` | schema | transport-safe recorded/derived quantity union |
12416
+ | `defineDeadlinePolicy` | function | elapsed- or calendar-day projection with explicit timezone, threshold, current time and caller category keys |
12417
+ | `DeadlineResultSchema` / `DeadlineResult` | schema / _type_ | due instant, remaining/overdue days and projected category |
12418
+ | `audit` | constant | constructors for explicit `record(changeSchema)` or `omit(reason)` endpoint metadata |
12419
+ | `assertAuditDeclared` | function | refuse a contract operation with no audit decision |
12420
+ | `createAuditRecord` | function | validate one declared change and return the canonical event value |
12421
+ | `AuditPolicy` / `AuditRecordPolicy` / `AuditOmitPolicy` / `CreateAuditRecordInput` | _types_ | audit declaration and record input contracts |
12422
+ | `AuditRecordSchema` / `AuditRecord` | schema / _type_ | domain-event-shaped audit record |
12423
+ | `createDomainEventSchema` | function | wrap a typed payload in the canonical event envelope |
12424
+ | `DomainEventSchema` / `DomainEvent` | schema / _type_ | generic event with stable id, time, subject and optional actor |
12425
+ | `DomainEventActorSchema` / `DomainEventActor` | schema / _type_ | structured actor identity and application role |
12426
+ | `DomainEventSubjectSchema` / `DomainEventSubject` | schema / _type_ | generic subject type/id pair |
12427
+ | `defineDomainEventDelivery` | function | plan routes and dispatch only application-outbox claims by committed event id |
12428
+ | `DomainEventDestinationSchema` / `DomainEventDestination` | schema / _type_ | transport-neutral destination identity |
12429
+ | `DomainEventDeliveryOutcomeSchema` / `DomainEventDeliveryOutcome` | schema / _type_ | delivered, retryable, terminal or unknown transport result |
12430
+ | `DomainEventDeliveryClaimSchema` / `DomainEventDeliveryClaim` | schema / _type_ | application-owned atomic outbox claim |
12431
+ | `DomainEventOutbox` / `DomainEventRoute` / `DomainEventTransport` | _types_ | host capabilities composed by process-local delivery |
12432
+ | `DomainEventDeliveryPlan` / `DomainEventDispatchResult` | _types_ | transaction input and bounded dispatch summary |
12433
+ | `defineExportOperation` / `createExportResultSchema` | functions | one typed contract operation returning a ready managed file or pending operation id |
12434
+ | `scanMoneyNumberRisks` / `scanOwnerFilterRisks` | functions | source-text migration diagnostics with caller-owned identifiers |
12435
+ | `SourceText` / `SourceRisk` | _types_ | migration scanner input and exact path/line evidence |
12436
+
12437
+ ---
12438
+
12177
12439
  ## `stitchkit/server`
12178
12440
 
12179
12441
  Server-only. Builds and runs the HTTP server, and carries the server primitives.
@@ -12423,7 +12685,9 @@ cutovers are covered by the executable
12423
12685
  | Export | Kind | Summary |
12424
12686
  |--------|------|---------|
12425
12687
  | `createBoundedAdmission` | function | process-local no-queue global/per-key concurrency and rate leases, optionally composed with application admission |
12426
- | `BoundedAdmissionPolicySchema` / `BoundedAdmissionPolicy` | schema / _type_ | finite global budget and optional finite per-key budget with `maxKeys` |
12688
+ | `BoundedAdmissionPolicySchema` / `BoundedAdmissionPolicy` | schema / _type_ | finite global budget and optional finite per-key budget with `maxKeys`, declared either as one flat ceiling or as a resolver — never both |
12689
+ | `BoundedAdmissionPerKeyLimitsSchema` / `BoundedAdmissionPerKeyLimits` | schema / _type_ | one key's resolved ceiling: `maxConcurrent` and optional `rate` |
12690
+ | `BoundedAdmissionPerKeyLimitResolver` | _type_ | `(key) => limits`, resolved on a key's first admission and cached until the key is evicted |
12427
12691
  | `BoundedRateBudgetSchema` / `BoundedRateBudget` | schema / _type_ | `{ limit, intervalMs }` monotonic sliding-window budget |
12428
12692
  | `BoundedAdmissionStateSchema` / `BoundedAdmissionState` | schema / _type_ | `accepting \| draining \| closed` |
12429
12693
  | `BoundedAdmissionRefusalReasonSchema` / `BoundedAdmissionRefusalReason` | schema / _type_ | exact local/upstream refusal vocabulary |
@@ -12450,6 +12714,8 @@ cutovers are covered by the executable
12450
12714
  | `createCreditWindow` | function | finite byte-credit lease window with exact once-only replenishment |
12451
12715
  | `CreditWindow` / `CreditWindowSnapshot` / `CreditWindowSnapshotSchema` | _type_ / schema | byte-credit handle and absolute accounting record |
12452
12716
  | `CreditAcquireResult` / `CreditLease` | _type_ | reasoned refusal or idempotently releasable byte-credit lease |
12717
+ | `CreditAcquireWaitOptions` | _type_ | `signal` / `timeoutMs` for the waiting `acquire` overload; absent budget waits until credit, close or abort |
12718
+ | `CreditWaitResult` / `CreditWaitRefusalReason` | _type_ | waiting-acquire outcome; `insufficient-credit` is absent by construction, `timed-out` and `aborted` replace it |
12453
12719
 
12454
12720
  ### Bounded diagnostic journal
12455
12721
 
@@ -12458,6 +12724,7 @@ cutovers are covered by the executable
12458
12724
  | `createDiagnosticJournal` | function | create one schema-owned FIFO JSONL writer with bounded retained memory, exclusive local path ownership and finite rotation |
12459
12725
  | `DiagnosticJournalConfig` / `DiagnosticJournal` | _type_ | owner schema/path/limits/failure observer and the synchronous `submit`, bounded-wait `flush`/`close`, status handle |
12460
12726
  | `DiagnosticJournalLimitsSchema` / `DiagnosticJournalLimits` | schema / _type_ | positive event, pending-item, pending-byte, file-byte and retained-file limits |
12727
+ | `DiagnosticJournalLockPolicySchema` / `DiagnosticJournalLockPolicy` | schema / _type_ | `refuse` (default) or `reclaim-stale`, which reclaims only a lock whose recorded owner is provably gone |
12461
12728
  | `DiagnosticJournalSubmitResultSchema` / `DiagnosticJournalSubmitResult` | schema / _type_ | accepted epoch/sequence or explicit invalid, oversized, capacity, closed or failed refusal |
12462
12729
  | `DiagnosticJournalStatusSchema` / `DiagnosticJournalStatus` | schema / _type_ | state, limits, exact admission/write/failure counters, pending ownership, rotations, partial tails and last safe sequences |
12463
12730
  | `DiagnosticJournalFrameSchema` / `DiagnosticJournalFrame` | schema / _type_ | version-1 JSONL frame carrying process epoch, contiguous accepted sequence and schema-validated JSON event |
package/llms.txt CHANGED
@@ -12,6 +12,7 @@ Build with stitchkit: define a contract once, then `implement` it and serve it (
12
12
  - [MCP & agents](https://github.com/max-listov/stitchkit/blob/master/docs/guide/mcp-and-agents.md): contracts as MCP tools (createMcpHandler) and AI-agent tools (mountAgent); tool lifecycle, extend, identity
13
13
  - [Agent application runtime](https://github.com/max-listov/stitchkit/blob/master/docs/guide/agent-runtime.md): optional durable history, prompt/model composition, stream loop, coordination, fencing and events
14
14
  - [Managed application kernel](https://github.com/max-listov/stitchkit/blob/master/docs/guide/application-kernel.md): process-local resources, readiness, admission, schedules, projections and optional provider adapters
15
+ - [Generic application primitives](https://github.com/max-listov/stitchkit/blob/master/docs/guide/primitives.md): lifecycle transitions, owner scope, permissions, exact money and quantities, deadlines, audit, delivery and exports — declared, not persisted
15
16
  - [Application migration recipes](https://github.com/max-listov/stitchkit/blob/master/docs/guide/application-migration-recipes.md): executable database, poller, queue-consumer and operational publishing cutovers
16
17
  - [CLI](https://github.com/max-listov/stitchkit/blob/master/docs/guide/cli.md): contracts as a command-line program
17
18
  - [Realtime](https://github.com/max-listov/stitchkit/blob/master/docs/guide/realtime.md): Socket.IO server/client wrappers, handshake auth, the cache bridge, a raw WebSocket lane
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "stitchkit",
3
- "version": "0.71.0",
3
+ "version": "0.72.1",
4
4
  "description": "Contract-first backend framework — one defineContract() into an HTTP API, MCP tools, AI-agent tools and a typed client. Bun and Node.",
5
5
  "keywords": [
6
6
  "bun",
@@ -73,6 +73,10 @@
73
73
  "types": "./dist/contract/index.d.ts",
74
74
  "import": "./dist/contract/index.js"
75
75
  },
76
+ "./primitives": {
77
+ "types": "./dist/primitives.d.ts",
78
+ "import": "./dist/primitives.js"
79
+ },
76
80
  "./server": {
77
81
  "types": "./dist/server/index.d.ts",
78
82
  "import": "./dist/server/index.js"
@@ -148,7 +152,7 @@
148
152
  "scripts": {
149
153
  "build:native-contained-files": "node scripts/build-contained-files-native.mjs",
150
154
  "check": "bun x tsc --noEmit",
151
- "build:browser": "bun build src/index.ts src/react.ts src/contract/index.ts src/declaration.ts src/agent-runtime-browser.ts --outdir dist --target node --packages external --splitting --root src",
155
+ "build:browser": "bun build src/index.ts src/react.ts src/contract/index.ts src/primitives.ts src/declaration.ts src/agent-runtime-browser.ts --outdir dist --target node --packages external --splitting --root src",
152
156
  "build:server": "bun build src/server/index.ts src/node.ts src/tools.ts src/tool-invoker.ts src/cli.ts src/remote.ts src/files.ts src/testing.ts src/observability/index.ts src/agent-runtime.ts src/agent-runtime-harness.ts src/agent-runtime-coding-tools.ts src/agent-runtime-openrouter.ts src/agent-runtime-sqlite-bun.ts src/agent-runtime-sqlite-node.ts src/application.ts src/application-grammy.ts src/application-opentelemetry.ts src/telegram.ts --outdir dist --target node --packages external --splitting --root src",
153
157
  "build:js": "bun run build:browser && bun run build:server && bun scripts/preserve-webpack-ignore.mjs",
154
158
  "build:types": "bun x tsc -p tsconfig.build.json --emitDeclarationOnly && bun scripts/rewrite-declaration-specifiers.mjs",