stitchkit 0.107.0 → 0.108.0

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 (85) hide show
  1. package/CHANGELOG.md +99 -0
  2. package/README.md +2 -0
  3. package/darwin-native.cjs +1 -0
  4. package/dist/browser/stream.d.ts +38 -12
  5. package/dist/browser/stream.d.ts.map +1 -1
  6. package/dist/entrypoints/application/diagnostic-journal.js +2 -2
  7. package/dist/entrypoints/application/directory-inbox.js +4 -4
  8. package/dist/entrypoints/bin/upgrade-cli.d.ts +32 -0
  9. package/dist/entrypoints/bin/upgrade-cli.d.ts.map +1 -1
  10. package/dist/entrypoints/bin/upgrade-cli.js +451 -8
  11. package/dist/entrypoints/cli/publish.js +3 -3
  12. package/dist/entrypoints/files/packaging.d.ts +3 -1
  13. package/dist/entrypoints/files/packaging.d.ts.map +1 -1
  14. package/dist/entrypoints/files/packaging.js +105 -41
  15. package/dist/entrypoints/files.js +3 -3
  16. package/dist/entrypoints/index.d.ts +1 -1
  17. package/dist/entrypoints/index.d.ts.map +1 -1
  18. package/dist/entrypoints/index.js +7 -1
  19. package/dist/entrypoints/process.js +1 -1
  20. package/dist/entrypoints/remote.js +1 -1
  21. package/dist/entrypoints/server.js +4 -4
  22. package/dist/entrypoints/telegram/screens.js +1 -1
  23. package/dist/entrypoints/telegram.d.ts +2 -0
  24. package/dist/entrypoints/telegram.d.ts.map +1 -1
  25. package/dist/entrypoints/telegram.js +337 -3
  26. package/dist/entrypoints/testing.d.ts +1 -0
  27. package/dist/entrypoints/testing.d.ts.map +1 -1
  28. package/dist/entrypoints/testing.js +131 -1
  29. package/dist/files/native-artifact.d.ts +14 -0
  30. package/dist/files/native-artifact.d.ts.map +1 -0
  31. package/dist/files/native-packaging-layout.d.ts +5 -0
  32. package/dist/files/native-packaging-layout.d.ts.map +1 -1
  33. package/dist/files/native-packaging-plugin.d.ts +53 -0
  34. package/dist/files/native-packaging-plugin.d.ts.map +1 -0
  35. package/dist/files/native-packaging.d.ts +1 -35
  36. package/dist/files/native-packaging.d.ts.map +1 -1
  37. package/dist/index-a5qr2rj6.js +26 -0
  38. package/dist/{index-7r74re56.js → index-bh2ht9y5.js} +12 -6
  39. package/dist/{index-mbf4h8kp.js → index-nx49x0tw.js} +1 -1
  40. package/dist/{index-zsqt5q98.js → index-p5kx5vqd.js} +209 -54
  41. package/dist/{index-bnf8s6v3.js → index-t2bsd0hm.js} +1 -1
  42. package/dist/{index-4f37d3bg.js → index-w9mqgnz9.js} +1 -1
  43. package/dist/{index-e05cjgtf.js → index-xvj9h8yh.js} +28 -1
  44. package/dist/internal/bounded-lines.d.ts +46 -2
  45. package/dist/internal/bounded-lines.d.ts.map +1 -1
  46. package/dist/internal/process-identity.d.ts.map +1 -1
  47. package/dist/internal/until-aborted.d.ts +9 -0
  48. package/dist/internal/until-aborted.d.ts.map +1 -0
  49. package/dist/internal/upgrade-affects.d.ts +58 -0
  50. package/dist/internal/upgrade-affects.d.ts.map +1 -0
  51. package/dist/internal/upgrade-plan.d.ts +20 -0
  52. package/dist/internal/upgrade-plan.d.ts.map +1 -1
  53. package/dist/internal/upgrade-usage.d.ts +61 -0
  54. package/dist/internal/upgrade-usage.d.ts.map +1 -0
  55. package/dist/telegram/bot-api.d.ts +10 -4
  56. package/dist/telegram/bot-api.d.ts.map +1 -1
  57. package/dist/telegram/broadcast.d.ts +2 -1
  58. package/dist/telegram/broadcast.d.ts.map +1 -1
  59. package/dist/telegram/not-dispatched.d.ts +26 -0
  60. package/dist/telegram/not-dispatched.d.ts.map +1 -0
  61. package/dist/telegram/operator-channel.d.ts +2 -1
  62. package/dist/telegram/operator-channel.d.ts.map +1 -1
  63. package/dist/telegram/send-failure.d.ts +4 -3
  64. package/dist/telegram/send-failure.d.ts.map +1 -1
  65. package/dist/telegram/transport-connect.d.ts +38 -0
  66. package/dist/telegram/transport-connect.d.ts.map +1 -0
  67. package/dist/telegram/transport.d.ts +43 -0
  68. package/dist/telegram/transport.d.ts.map +1 -0
  69. package/dist/telegram/webhook.d.ts +2 -1
  70. package/dist/telegram/webhook.d.ts.map +1 -1
  71. package/dist/testing/manual-clock.d.ts +82 -0
  72. package/dist/testing/manual-clock.d.ts.map +1 -0
  73. package/llms/files-packaging.txt +4 -1
  74. package/llms/process.txt +19 -5
  75. package/llms/stitchkit.2.txt +211 -628
  76. package/llms/stitchkit.txt +635 -10
  77. package/llms/telegram.txt +36 -3
  78. package/llms/testing.txt +47 -0
  79. package/llms/{upgrading-0.98.0-0.107.0.txt → upgrading-0.100.0-0.108.0.txt} +59 -64
  80. package/llms/{upgrading-0.72.0-0.97.0.txt → upgrading-0.72.0-0.99.0.txt} +64 -3
  81. package/llms/upgrading.txt +34 -2
  82. package/llms-full.txt +246 -17
  83. package/llms.txt +8 -8
  84. package/package.json +1 -1
  85. package/llms/stitchkit.3.txt +0 -177
package/CHANGELOG.md CHANGED
@@ -15,6 +15,78 @@ additive**; the first breaking change landed in 0.10.0. Grep the file for
15
15
 
16
16
  ## [Unreleased]
17
17
 
18
+ ## [0.108.0] - 2026-10-06
19
+
20
+ ### ⚠️ Breaking changes
21
+
22
+ **Who must act:** code with an exhaustive `switch` or `Record` over `TelegramSendFailureReason` or
23
+ `TelegramSendFailure['evidence']`; builds whose entry imports a `stitchkit` installation other
24
+ than the one their native packaging plugin came from.
25
+
26
+ - `stitchkit/telegram` — **a request that never left is its own send outcome.**
27
+ `TelegramSendFailureReason` gains `not-dispatched` (retryable, recipient reachable) and
28
+ `TelegramSendFailure.evidence` gains `transport`: `classifyTelegramSendFailure` returns them for a
29
+ `TelegramNotDispatchedError` anywhere in the cause chain, so a broadcast retries such a send as
30
+ `transient` and the operator channel sends it again, where both used to give it up as unknown.
31
+ `// before: const code: Record<TelegramSendFailureReason, string> = { …, unknown: 'E_UNKNOWN' }`
32
+ → `// after: const code: Record<TelegramSendFailureReason, string> = { …, 'not-dispatched': 'E_NOT_SENT', unknown: 'E_UNKNOWN' }`
33
+ **Who must act:** exhaustive code over the reasons or the evidence. See
34
+ [migration](docs/guide/upgrading.md#a-request-that-never-left-is-its-own-send-outcome). → ADR 0253
35
+ **Affects:** `stitchkit/telegram` TelegramSendFailureReason, TelegramSendFailure(evidence), TELEGRAM_SEND_FAILURE_REASONS, classifyTelegramSendFailure(reason)
36
+ - `stitchkit/files/packaging` — **a packaging plugin fails a build that carries another
37
+ installation's loader.** The plugin packages only the default Darwin loader of the `stitchkit` it
38
+ was created from; an entry that imports another installation (another version, or the same
39
+ version under another path, as when a build tool brings its own copy) used to build, ship that
40
+ installation's default loader and refuse the addon on macOS at run time. The build now fails with
41
+ an error naming both versions and roots.
42
+ `// before: Bun.build({ plugins: [toolCopy.createNativePackaging(…).plugin] }) // entry imports another stitchkit`
43
+ → `// after: Bun.build({ plugins: [entryCopy.createNativePackaging(…).plugin] })`
44
+ **Who must act:** builds that take the plugin from a `stitchkit` the entry does not import. See
45
+ [migration](docs/guide/upgrading.md#a-packaging-plugin-packages-only-its-own-installation). → ADR 0254
46
+ **Affects:** `stitchkit/files/packaging` createNativePackaging(plugin)
47
+
48
+ ### Added
49
+
50
+ - `stitchkit/telegram` — `createTelegramBotTransport()`, a `fetch` for the Bot API senders that
51
+ connects before it writes: a failure before the first byte is `TelegramNotDispatchedError`
52
+ (`stage`: `lookup`, `connect`, `request`), any later one stays unknown. Addresses race in the
53
+ resolver's order (Happy Eyeballs); the lookup, the connection rounds, the answer's time and its size are bounded.
54
+ The senders' `fetch` option is now typed `TelegramFetch` (`(url, init) => Promise<Response>`), which
55
+ the global `fetch` still satisfies. → ADR 0253
56
+ - `stitchkit` — `parseNDJSON` and `parseSSE` read any byte source: a `Response`, a
57
+ `ReadableStream<Uint8Array>` (a Bun child's `stdout`) or an `AsyncIterable<Uint8Array>` (a Node
58
+ child's `stdout`), with `signal` cancelling the source. `createNDJSONDecoder` drives the same
59
+ bounded reader by `push(chunk)` / `end()` for a socket's `data` callback. A line past
60
+ `maxLineBytes` throws `StreamLineLimitError` (`limitBytes`, `lineBytes`) at the chunk that crossed
61
+ the limit, so memory stays bounded; a source ended inside a line under `finalLine:
62
+ 'require-newline'` throws `StreamTruncatedLineError`. They extend the `RangeError` and `SyntaxError`
63
+ thrown before, so `instanceof` still holds; their `name` is now the class name and their message
64
+ ends with the bytes seen. A decoder stops at
65
+ its first error, and an abort rejects with the signal's reason even when `onParseError` is set.
66
+ - `stitchkit/files/packaging` — `inspectNativeArtifact(bytes)` classifies a built artifact as
67
+ `packaged`, `unpackaged` or `no-loader` by a marker every generated loader now carries
68
+ (`module.exports.stitchkitNativeLoader`), in latin1 and UTF-16LE. It replaces the documented search
69
+ for `STITCHKIT_NATIVE_NOT_PACKAGED`, which every bundle with a lock carries as an error code and so
70
+ refused correct builds. → ADR 0254
71
+ - `stitchkit upgrade` — every breaking item from 0.104.0 carries an `**Affects:**` line naming its
72
+ entrypoints and exports (or `behaviour`), and `release:check` refuses a breaking item without it.
73
+ The CLI reads the project's imports (`--cwd`, default `.`) and gives each item a verdict:
74
+ `affects this project` with `path:line`, `not used here`, `behavioural — check by hand` with the
75
+ importing files, or `not declared — check by hand` for older items; `--json` prints the verdicts.
76
+ - `stitchkit/testing` — `createManualClock()`: manual time for schedules, retries and deadlines. Due
77
+ timers fire in deadline order with real event-loop yields between them, so `advance(10_000)` does
78
+ not skip a retry armed at the fifth second; `hold` keeps time still while real work of unknown
79
+ length runs and fails naming it past `holdLimitMs`; `until` moves deadline to deadline; one move
80
+ runs at a time. It is the
81
+ clock of `createManagedSchedule`, a durable sleep, a revision signal and bounded admission.
82
+
83
+ ### Fixed
84
+
85
+ - `stitchkit/server`, `stitchkit/process`, `stitchkit/files` — loading these leaves no longer calls
86
+ a Node API: process identity built its command runner with `promisify(execFile)` at module scope,
87
+ so a browser bundle that reached the server leaf for an error class (where `node:util` is an empty
88
+ module) threw `promisify is not a function` while loading, although nothing called it.
89
+
18
90
  ## [0.107.0] - 2026-10-06
19
91
 
20
92
  ### ⚠️ Breaking changes
@@ -33,6 +105,7 @@ any artifact made without the packaging plugin by 0.105.0–0.106.1.
33
105
  → `// after: createNativePackaging({ platform: 'darwin', architecture: 'arm64', delivery: 'embedded' })`
34
106
  **Who must act:** builds with `delivery: 'embedded'`. See
35
107
  [migration](docs/guide/upgrading.md#embedded-native-packaging-names-no-paths). → ADR 0252
108
+ **Affects:** `stitchkit/files/packaging` createNativePackaging(delivery: 'embedded'), NativePackagingOptions, NativePackagingResult, NativePackagingAsset
36
109
 
37
110
  ### Fixed
38
111
 
@@ -99,6 +172,7 @@ or a failing sink).
99
172
  `// after: onLeaderSettled: (e) => { if (e.kind === 'stopped') stopped(e.cause, e.signal) }`
100
173
  **Who must act:** code that handles a stop in `kind === 'error'`. See
101
174
  [migration](docs/guide/upgrading.md#a-stopped-leader-settles-as-stopped). → ADR 0248
175
+ **Affects:** `stitchkit/process` runNativeCommand(onLeaderSettled), NativeCommandOptions(onLeaderSettled), NativeCommandSettlement
102
176
 
103
177
  ### Added
104
178
 
@@ -183,6 +257,7 @@ and code that imports `publishCli` or its types from `stitchkit/cli`.
183
257
  **Who must act:** code that imports `publishCli` or a `CliPublication*` type from
184
258
  `stitchkit/cli`. See [migration](docs/guide/upgrading.md#cli-publication-has-its-own-entrypoint).
185
259
  → ADR 0245
260
+ **Affects:** `stitchkit/cli` publishCli, CliPublicationOptions, CliPublicationPhase, CliPublicationResult
186
261
 
187
262
  - `stitchkit/process` — **`killGraceMs` becomes the `stop` policy.** How a cancelled command
188
263
  stops is one named object: `target` `'group'` (the signal goes to every member, as before) or
@@ -195,6 +270,7 @@ and code that imports `publishCli` or its types from `stitchkit/cli`.
195
270
  `// before: runNativeCommand({ …, killGraceMs: 500 })` →
196
271
  `// after: runNativeCommand({ …, stop: { target: 'group', graceMs: 500 } })`
197
272
  **Who must act:** callers that pass `killGraceMs`. → ADR 0243
273
+ **Affects:** `stitchkit/process` runNativeCommand(killGraceMs), NativeCommandOptions(killGraceMs)
198
274
 
199
275
  - `stitchkit/process` — **a command's leftover group members are stopped after its leader
200
276
  exits.** `runNativeCommand` takes `descendants: 'terminate-after-leader' | 'leave'`, and
@@ -209,6 +285,7 @@ and code that imports `publishCli` or its types from `stitchkit/cli`.
209
285
  keep running after the command returns. See
210
286
  [migration](docs/guide/upgrading.md#a-command-stops-what-its-leader-left).
211
287
  → ADR 0246
288
+ **Affects:** `stitchkit/process` runNativeCommand(descendants), NativeCommandOptions(descendants)
212
289
 
213
290
  - `stitchkit/server`, `stitchkit/files`, `stitchkit/process` — **bundles no longer emit Darwin
214
291
  addons.** The packaged Darwin loader names its addon by a computed path, so a Bun bundle of
@@ -222,6 +299,7 @@ and code that imports `publishCli` or its types from `stitchkit/cli`.
222
299
  **Who must act:** Darwin packagers of bundled or compiled artifacts using these entrypoints.
223
300
  Linux and portable bundles need no change. See [migration](docs/guide/upgrading.md#released-migration-010313).
224
301
  → ADR 0235
302
+ **Affects:** `stitchkit/server`, `stitchkit/files`, `stitchkit/process` behaviour
225
303
  - `stitchkit/files/packaging` — **`createNativePackaging` checks each addon against a digest the
226
304
  package published, and returns the verified bytes.** `native-assets.json` is now written when
227
305
  Stitchkit is built, at `formatVersion: 2`, with the `path`, `size` and `sha256` of every Darwin
@@ -247,6 +325,7 @@ and code that imports `publishCli` or its types from `stitchkit/cli`.
247
325
  than the literal `'darwin'`.
248
326
  See [migration](docs/guide/upgrading.md#native-packaging-verifies-published-digests).
249
327
  → ADR 0241
328
+ **Affects:** `stitchkit/files/packaging` createNativePackaging(platform), NativePackagingAsset(sourcePath), NativePackagingResult(code)
250
329
  - `stitchkit/files` — **`withExclusiveLock` publishes its lock with the owner already recorded,
251
330
  and `ownerlessGraceMs` defaults to `null`.** The owner record is written to a temporary file
252
331
  and hard-linked to the lock name, so the name never exists without an owner and a stalled
@@ -260,6 +339,7 @@ and code that imports `publishCli` or its types from `stitchkit/cli`.
260
339
  file, and locks on a filesystem without hard links; every other caller is unaffected.
261
340
  See [migration](docs/guide/upgrading.md#exclusive-locks-publish-their-owner-first).
262
341
  → ADR 0238
342
+ **Affects:** `stitchkit/files` withExclusiveLock(ownerlessGraceMs), ExclusiveLockOptions(ownerlessGraceMs)
263
343
  - `stitchkit/tools/connections` — **a `timeoutMs` or `maxResponseBytes` that is not a positive
264
344
  integer within range throws a `RangeError`** instead of falling back to the default. This
265
345
  shipped in 0.104.0 without a breaking entry.
@@ -267,6 +347,7 @@ and code that imports `publishCli` or its types from `stitchkit/cli`.
267
347
  `// after: timeoutMs: 0 (RangeError; omit the option to take the default)`
268
348
  **Who must act:** callers that passed 0, a negative, a fractional or an oversized limit.
269
349
  See [migration](docs/guide/upgrading.md#connection-limits-are-validated).
350
+ **Affects:** `stitchkit/tools/connections` defineMcpClientConnection(timeoutMs), defineOpenApiConnection(timeoutMs), McpConnectionLimits, ConnectionOperationLimits
270
351
  - `stitchkit/testing` — **`serializeSurfaceValue` is removed.** It was a second name for the
271
352
  package's one canonical serializer. `canonicalJson` from `stitchkit/primitives` is that
272
353
  serializer, bounded and with a typed refusal:
@@ -275,6 +356,7 @@ and code that imports `publishCli` or its types from `stitchkit/cli`.
275
356
  **Who must act:** tests that call `serializeSurfaceValue`.
276
357
  See [migration](docs/guide/upgrading.md#one-canonical-json-serializer).
277
358
  → ADR 0199, ADR 0238
359
+ **Affects:** `stitchkit/testing` serializeSurfaceValue
278
360
  - `stitchkit/agent-runtime` — **`canonicalAgentJson` follows the one admissibility table of
279
361
  `canonicalJson`.** A value nested deeper than 100 levels is refused with a
280
362
  `CanonicalJsonError`, and an `undefined` object member is omitted instead of failing. It still
@@ -286,6 +368,7 @@ and code that imports `publishCli` or its types from `stitchkit/cli`.
286
368
  **Who must act:** code that puts a value nested deeper than 100 levels into agent store events,
287
369
  archives or projections. See
288
370
  [migration](docs/guide/upgrading.md#one-canonical-json-serializer).
371
+ **Affects:** `stitchkit/agent-runtime` canonicalAgentJson
289
372
  - `stitchkit/application` — **`DirectoryInbox` sets a hard-linked entry file aside as
290
373
  `invalid`, and `accept` takes the schema's input type.** A dropped file with more than one
291
374
  link is never trusted, because another name can still rewrite it (since 0.104.0, without a
@@ -298,6 +381,7 @@ and code that imports `publishCli` or its types from `stitchkit/cli`.
298
381
  **Who must act:** producers that drop hard links into an inbox directory, and callers that pass
299
382
  `accept` the output of a transforming schema.
300
383
  See [migration](docs/guide/upgrading.md#directory-inbox-entries).
384
+ **Affects:** `stitchkit/application` DirectoryInbox, DirectoryInboxConfig, DirectoryInboxResource; `stitchkit/application/directory-inbox` createDirectoryInbox
301
385
  - `stitchkit/application` — **`createDiagnosticJournal` checks only the last line of each file
302
386
  when it opens** (`startupScan: 'tails'`, the default), so opening no longer parses and
303
387
  validates every line of every retained generation. The scan still reads each file once in
@@ -308,6 +392,7 @@ and code that imports `publishCli` or its types from `stitchkit/cli`.
308
392
  `// after: createDiagnosticJournal({ path, eventSchema, limits, startupScan: 'full' }) (the same full scan)`
309
393
  **Who must act:** operators that read `recovery` at startup to find damaged rows in the middle
310
394
  of a file. See [migration](docs/guide/upgrading.md#journal-startup-scan).
395
+ **Affects:** `stitchkit/application/diagnostic-journal` createDiagnosticJournal(startupScan)
311
396
  - `stitchkit/application/diagnostic-journal`, `stitchkit/application` — **opening a diagnostic
312
397
  journal moves a file it cannot keep in place aside and starts, instead of refusing to start.**
313
398
  A torn active file with `maxFiles: 1`, a generation name that is not a regular file and a
@@ -330,6 +415,7 @@ and code that imports `publishCli` or its types from `stitchkit/cli`.
330
415
  `recovery`; protocols that embed `DiagnosticJournalRecoveryStatusSchema` and their readers.
331
416
  See [migration](docs/guide/upgrading.md#journal-startup-quarantine).
332
417
  → ADR 0240
418
+ **Affects:** `stitchkit/application/diagnostic-journal` createDiagnosticJournal(onStartupRefusal); `stitchkit/application` DiagnosticJournalRecoveryError, DiagnosticJournalRecoveryStatusSchema
333
419
 
334
420
  - `stitchkit/cli`, `stitchkit/tools`, `stitchkit/tools/mcp` — **one runtime-tool declaration.**
335
421
  `RuntimeToolExecution`, `RuntimeToolExecutionWithOutput` (cli), `RuntimeMcpToolDefinition`,
@@ -351,6 +437,7 @@ and code that imports `publishCli` or its types from `stitchkit/cli`.
351
437
  `createRuntimeToolFactory` need no change.
352
438
  See [migration](docs/guide/upgrading.md#one-runtime-tool-declaration).
353
439
  → ADR 0236, ADR 0238
440
+ **Affects:** `stitchkit/cli` RuntimeToolExecution, RuntimeToolExecutionWithOutput; `stitchkit/tools/mcp` RuntimeMcpToolDefinition, RuntimeMcpToolDefinitionWithOutput; `stitchkit/tools` ToolSurfaceDefinition, RuntimeToolDefinitionWithOutput
354
441
  - `stitchkit/tools`, `stitchkit/tools/mcp` — **a flattened union keeps declaration order.**
355
442
  With `flattenUnionInput: true`, properties, enum values and branch labels are advertised in the
356
443
  order of their first appearance across the variants instead of alphabetically, so the bytes of
@@ -362,6 +449,7 @@ and code that imports `publishCli` or its types from `stitchkit/cli`.
362
449
  anyone using `flattenUnionInput: true`: regenerate the snapshots.
363
450
  See [migration](docs/guide/upgrading.md#flattened-unions-keep-declaration-order).
364
451
  → ADR 0238
452
+ **Affects:** `stitchkit/tools`, `stitchkit/tools/mcp` behaviour
365
453
  - `stitchkit/tools`, `stitchkit/cli` — **a list written as text is refused in every
366
454
  string-or-array field.** `coerceJsonArgs`, and so every tool surface, throws a validation error
367
455
  naming the field when a union that keeps a string member receives a string that parses to an
@@ -373,12 +461,14 @@ and code that imports `publishCli` or its types from `stitchkit/cli`.
373
461
  **Who must act:** callers that send a JSON array as text to a string-or-array field; a plain
374
462
  string, including one that is not a list the array member accepts, is unchanged.
375
463
  → ADR 0218, ADR 0239, ADR 0238
464
+ **Affects:** `stitchkit/tools`, `stitchkit/cli` behaviour
376
465
  - `stitchkit/agent-runtime` — **the `stitchkit/agent-runtime/harness-tools` leaf is removed.** It
377
466
  was one `mountAgent` call with the run's fence composed in; no consumer imported it.
378
467
  `// before: tools: createAgentHarnessTools(({ context }) => ({ services: [svc], context }))` →
379
468
  `// after: tools: ({ context, toolFenceLifecycle }) => mountAgent([svc], { context, lifecycle: composeToolLifecycle(undefined, toolFenceLifecycle) })`
380
469
  **Who must act:** imports of `stitchkit/agent-runtime/harness-tools`. See
381
470
  [migration](docs/guide/upgrading.md#one-runtime-tool-declaration).
471
+ **Affects:** `stitchkit/agent-runtime/harness-tools` *
382
472
  - `stitchkit/agent-runtime/realtime`, `stitchkit/agent-runtime/browser` — **control errors use one
383
473
  vocabulary, and the binding authorizes requests, not events.** `ACCESS_DENIED` is `FORBIDDEN`, and
384
474
  a closed connection answers `CONNECTION_CLOSED` instead of a denial. `AgentControlErrorCode`
@@ -393,6 +483,7 @@ and code that imports `publishCli` or its types from `stitchkit/cli`.
393
483
  `// after: if (state.error?.code === 'FORBIDDEN') …`
394
484
  **Who must act:** code that compares control error codes, and applications that revoke access while
395
485
  a stream is open (call `binding.revoke`; before, every event re-asked `authorize`).
486
+ **Affects:** `stitchkit/agent-runtime/browser` AgentControlErrorCode, AgentControlErrorCodeSchema, AgentControllerState(error); `stitchkit/agent-runtime/realtime` bindAgentHarnessRealtime(authorize), AgentHarnessRealtimeBinding(revoke)
396
487
  - `stitchkit/contract`, `stitchkit/server`, `stitchkit/node` — **`AppError` takes its fields by
397
488
  name.** The constructor had seven positions, so a call that set only `retryable` read
398
489
  `new AppError(code, message, 409, undefined, undefined, undefined, true)`. The code stays first;
@@ -405,6 +496,7 @@ and code that imports `publishCli` or its types from `stitchkit/cli`.
405
496
  The `notFound`, `badRequest`, `unauthorized`, `forbidden`, `conflict` and `rateLimited` helpers
406
497
  are unchanged. See [migration](docs/guide/upgrading.md#error-constructors-take-named-options).
407
498
  → ADR 0238
499
+ **Affects:** `stitchkit/contract`, `stitchkit/server`, `stitchkit/node` AppError
408
500
  - `stitchkit` — **`ApiError` takes its fields by name.** The constructor had eight positions
409
501
  and call sites ended in `undefined, undefined, retryable`. The code stays first and the rest
410
502
  is one options object; `new ApiError(code)` still works:
@@ -416,6 +508,7 @@ and code that imports `publishCli` or its types from `stitchkit/cli`.
416
508
  `retryable` or `cause` is unaffected. See
417
509
  [migration](docs/guide/upgrading.md#error-constructors-take-named-options).
418
510
  → ADR 0238
511
+ **Affects:** `stitchkit` ApiError
419
512
 
420
513
  ### Added
421
514
 
@@ -559,16 +652,19 @@ native CLI commands and ordinary one-argument state transitions remain valid.
559
652
  in `CliConfig.runtimeTools` / `CliInvokerConfig.runtimeTools`. Existing typed definitions and
560
653
  native `commands` need no change. See [migration](docs/guide/upgrading.md#released-migration-01040).
561
654
  → ADR 0227
655
+ **Affects:** `stitchkit/cli` CliConfig(runtimeTools), CliInvokerConfig(runtimeTools)
562
656
  - `stitchkit/application` — custom state adapters must supply an active, fenced
563
657
  `StateStoreUpdateContext`: `transition(current)` → `transition(current, context)` inside
564
658
  their protected transaction. Remove file-store `staleLockMs` / `retryMs`:
565
659
  `{ staleLockMs, retryMs, lockTimeoutMs }` → `{ lockTimeoutMs }`. Live and unknown owners
566
660
  cannot be reclaimed by age; legacy lock recovery requires proof that the owner stopped.
567
661
  Ordinary one-argument transition callbacks still work. → ADR 0228
662
+ **Affects:** `stitchkit/application` StateStore, StateStoreUpdate, StateStoreUpdateContext; `stitchkit/server` createFileStateStore(staleLockMs), FileStateStoreOptions(retryMs)
568
663
  - `stitchkit/telegram` — broadcast halt uses `TelegramBroadcastFailure`:
569
664
  `report.halt.reason` → `report.halt.kind`. An unknown send outcome becomes durable
570
665
  `uncertain` and halts without replay; explicit retry classifiers certify that the failed
571
666
  attempt did not apply its effect. → ADR 0228
667
+ **Affects:** `stitchkit/telegram` runTelegramBroadcast(halt), TelegramBroadcastReport(halt)
572
668
  - `stitchkit/tools`, `stitchkit/tools/mcp` — construct schema-dependent MCP tools before
573
669
  heterogeneous registration: `runtimeTools: [{ input, output, handler, present }]` →
574
670
  `const tool = { … } satisfies RuntimeMcpToolDefinitionWithOutput<typeof input, typeof output>; runtimeTools: [tool]`.
@@ -576,16 +672,19 @@ native CLI commands and ordinary one-argument state transitions remain valid.
576
672
  official SDK's required content and metadata types: `present: { mcp: () => ({}) }` →
577
673
  `present: { mcp: () => ({ content: [] }) }`. **Who must act:** inline MCP constructors
578
674
  and presenters returning malformed content or metadata. → ADR 0231
675
+ **Affects:** `stitchkit/tools` createMcpHandler(runtimeTools), mountMcp(runtimeTools); `stitchkit/tools/mcp` buildMcpServer(runtimeTools), RuntimeMcpToolPresenters
579
676
  - `stitchkit/contract`, `stitchkit/remote` — error envelopes and framed errors admit an
580
677
  optional boolean `retryable`. A closed error schema must add
581
678
  `retryable: z.boolean().optional()` before upgrading producers that declare it; envelopes
582
679
  without a declaration remain unchanged. See [migrations](docs/guide/upgrading.md).
583
680
  These migrations require a minor release. → ADR 0232
681
+ **Affects:** `stitchkit/contract`, `stitchkit/remote` behaviour
584
682
  - `stitchkit/tools`, `stitchkit/cli` — raw unexpected tool errors are observed through
585
683
  `hooks.onToolError` / `hooks.afterToolCall` instead of being printed on protocol stderr.
586
684
  **Who must act:** applications collecting raw tool causes from `console.error`; configure
587
685
  an internal hook sink instead. MCP resolver failures reach the same observing hooks without
588
686
  rerunning the handler or its lifecycle. → ADR 0229
687
+ **Affects:** `stitchkit/tools`, `stitchkit/cli` behaviour
589
688
 
590
689
  ### Fixed
591
690
 
package/README.md CHANGED
@@ -359,11 +359,13 @@ import { parseSSE } from 'stitchkit' // client: Response → AsyncGene
359
359
  | **Cache Bridge** | `createCacheBridge()` — socket events → TanStack Query cache |
360
360
  | **Auth** | `createAuthHook()` / `createBearerResolver()` — scope-aware auth from `contract.scope` |
361
361
  | **SSE Streaming** | `streamSSE()` / `parseSSE()` — async generator ↔ SSE |
362
+ | **NDJSON** | `ndjsonRoute()` / `parseNDJSON()` / `createNDJSONDecoder()` — bounded lines from a response, a child's stdout or a socket |
362
363
  | **Events** | `createEventBus<EventMap>()` — typed in-process pub/sub |
363
364
  | **Multipart** | typed buffered or streaming single/multi-file uploads with limits and MIME policy |
364
365
  | **Rate Limiting** | `createRateLimiter()` — token bucket, per-key |
365
366
  | **Cache** | `createCache()` — in-memory with TTL + `cacheHeaders()` |
366
367
  | **Errors** | `AppError`, `notFound()`, `badRequest()`, `unauthorized()` |
368
+ | **Manual time** | `createManualClock()` (`stitchkit/testing`) — schedules, retries and deadlines advanced by the test, in order |
367
369
 
368
370
  ## How it compares
369
371
 
package/darwin-native.cjs CHANGED
@@ -22,3 +22,4 @@ module.exports = function loadDarwinAddon() {
22
22
  throw new Error('Darwin addon loading failed', { cause });
23
23
  }
24
24
  };
25
+ module.exports.stitchkitNativeLoader = 'stitchkit-native-loader:unpackaged';
@@ -1,17 +1,25 @@
1
1
  import type { StreamFinalLinePolicy } from '../contract/define.js';
2
- export { DEFAULT_STREAM_LINE_BYTES } from '../internal/bounded-lines.js';
3
- /** Options for `parseNDJSON`. */
2
+ import { type StreamByteSource } from '../internal/bounded-lines.js';
3
+ export { DEFAULT_STREAM_LINE_BYTES, type StreamByteSource, StreamLineLimitError, StreamTruncatedLineError, } from '../internal/bounded-lines.js';
4
+ /** Options for `parseNDJSON` and `createNDJSONDecoder`. */
4
5
  export interface ParseNDJSONOptions {
5
- /** Maximum bytes retained for one line. Default 1 MiB. */
6
+ /** Maximum bytes retained for one line; past it, `StreamLineLimitError`. Default 1 MiB. */
6
7
  maxLineBytes?: number;
7
8
  /** Called for invalid UTF-8/JSON; without it parsing fails closed. */
8
9
  onParseError?: (raw: string, error: Error) => void;
9
- /** Default `allow`; use `require-newline` when a missing delimiter means truncation. */
10
+ /**
11
+ * Default `allow`; use `require-newline` when a missing delimiter means truncation (a socket or
12
+ * a child's stdout that ends mid-line), so the fragment is `StreamTruncatedLineError`, not a value.
13
+ */
10
14
  finalLine?: StreamFinalLinePolicy;
15
+ /** Stops reading and cancels the source; the iteration rejects with the signal's reason. */
16
+ signal?: AbortSignal;
11
17
  }
12
18
  /**
13
- * Parse a newline-delimited JSON response body — the client half of
14
- * `ndjsonRoute`.
19
+ * Parse newline-delimited JSON — the client half of `ndjsonRoute`, and the reader for any other
20
+ * byte source: a `Response`, a `ReadableStream<Uint8Array>` (a fetch body, a Bun child's
21
+ * `stdout`) or an `AsyncIterable<Uint8Array>` (a Node child's `stdout`). A source that delivers
22
+ * bytes through a callback, such as a `Bun.listen` socket, uses `createNDJSONDecoder`.
15
23
  *
16
24
  * **Blank lines are skipped**, and that is the contract rather than a
17
25
  * convenience. A long-lived NDJSON stream has to send something while it is
@@ -26,18 +34,36 @@ export interface ParseNDJSONOptions {
26
34
  * the other end stayed alive for seconds afterwards. An aborted request reaches
27
35
  * the route's `context.signal` at once.
28
36
  */
29
- export declare function parseNDJSON<T>(response: Response, options?: ParseNDJSONOptions): AsyncGenerator<T>;
37
+ export declare function parseNDJSON<T>(source: StreamByteSource, options?: ParseNDJSONOptions): AsyncGenerator<T>;
38
+ /**
39
+ * Push-driven NDJSON for a source that hands over bytes through a callback. `push` returns the
40
+ * values its chunk completed; `end` returns the value of an unterminated final line, or throws
41
+ * `StreamTruncatedLineError` under `finalLine: 'require-newline'`.
42
+ */
43
+ export interface NDJSONDecoder<T> {
44
+ push(chunk: Uint8Array): T[];
45
+ end(): T[];
46
+ }
47
+ /**
48
+ * The same bounded, fatal-UTF-8 NDJSON reading as `parseNDJSON`, for a `Bun.listen` /
49
+ * `Bun.connect` socket's `data` handler or any other callback source. A line past
50
+ * `maxLineBytes` throws `StreamLineLimitError` as soon as it crosses the limit; invalid JSON
51
+ * goes to `onParseError` or throws. (`signal` does not apply: the caller owns the source.)
52
+ */
53
+ export declare function createNDJSONDecoder<T>(options?: Omit<ParseNDJSONOptions, 'signal'>): NDJSONDecoder<T>;
30
54
  /** Options for `parseSSE`. */
31
55
  export interface ParseSSEOptions {
32
- /** Maximum bytes retained for one SSE line. Default 1 MiB. */
56
+ /** Maximum bytes retained for one SSE line; past it, `StreamLineLimitError`. Default 1 MiB. */
33
57
  maxLineBytes?: number;
34
58
  /** Called for invalid UTF-8/JSON; without it parsing fails closed. */
35
59
  onParseError?: (raw: string, error: Error) => void;
60
+ /** Stops reading and cancels the source; the iteration rejects with the signal's reason. */
61
+ signal?: AbortSignal;
36
62
  }
37
63
  /**
38
- * Parse a Server-Sent Events `Response` body into an async generator of JSON
39
- * values — the client counterpart of `streamSSE`. Stops at the `[DONE]`
40
- * sentinel; the stream lock is released on every exit path.
64
+ * Parse Server-Sent Events into an async generator of JSON values — the client counterpart of
65
+ * `streamSSE`. Reads the same byte sources as `parseNDJSON`. Stops at the `[DONE]` sentinel;
66
+ * the source is cancelled on every exit path.
41
67
  */
42
- export declare function parseSSE<T>(response: Response, options?: ParseSSEOptions): AsyncGenerator<T>;
68
+ export declare function parseSSE<T>(source: StreamByteSource, options?: ParseSSEOptions): AsyncGenerator<T>;
43
69
  //# sourceMappingURL=stream.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../../src/browser/stream.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAGhE,OAAO,EAAE,yBAAyB,EAAE,MAAM,2BAA2B,CAAC;AAEtE,iCAAiC;AACjC,MAAM,WAAW,kBAAkB;IACjC,0DAA0D;IAC1D,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,sEAAsE;IACtE,YAAY,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IACnD,wFAAwF;IACxF,SAAS,CAAC,EAAE,qBAAqB,CAAC;CACnC;AAYD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAuB,WAAW,CAAC,CAAC,EAClC,QAAQ,EAAE,QAAQ,EAClB,OAAO,CAAC,EAAE,kBAAkB,GAC3B,cAAc,CAAC,CAAC,CAAC,CAkBnB;AAED,8BAA8B;AAC9B,MAAM,WAAW,eAAe;IAC9B,8DAA8D;IAC9D,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,sEAAsE;IACtE,YAAY,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;CACpD;AAED;;;;GAIG;AACH,wBAAuB,QAAQ,CAAC,CAAC,EAC/B,QAAQ,EAAE,QAAQ,EAClB,OAAO,CAAC,EAAE,eAAe,GACxB,cAAc,CAAC,CAAC,CAAC,CAuBnB"}
1
+ {"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../../src/browser/stream.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAChE,OAAO,EAIL,KAAK,gBAAgB,EACtB,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EACL,yBAAyB,EACzB,KAAK,gBAAgB,EACrB,oBAAoB,EACpB,wBAAwB,GACzB,MAAM,2BAA2B,CAAC;AAEnC,2DAA2D;AAC3D,MAAM,WAAW,kBAAkB;IACjC,2FAA2F;IAC3F,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,sEAAsE;IACtE,YAAY,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IACnD;;;OAGG;IACH,SAAS,CAAC,EAAE,qBAAqB,CAAC;IAClC,4FAA4F;IAC5F,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAiBD;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAuB,WAAW,CAAC,CAAC,EAClC,MAAM,EAAE,gBAAgB,EACxB,OAAO,CAAC,EAAE,kBAAkB,GAC3B,cAAc,CAAC,CAAC,CAAC,CA4BnB;AAED;;;;GAIG;AACH,MAAM,WAAW,aAAa,CAAC,CAAC;IAC9B,IAAI,CAAC,KAAK,EAAE,UAAU,GAAG,CAAC,EAAE,CAAC;IAC7B,GAAG,IAAI,CAAC,EAAE,CAAC;CACZ;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,EACnC,OAAO,CAAC,EAAE,IAAI,CAAC,kBAAkB,EAAE,QAAQ,CAAC,GAC3C,aAAa,CAAC,CAAC,CAAC,CAkClB;AAED,8BAA8B;AAC9B,MAAM,WAAW,eAAe;IAC9B,+FAA+F;IAC/F,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,sEAAsE;IACtE,YAAY,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IACnD,4FAA4F;IAC5F,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED;;;;GAIG;AACH,wBAAuB,QAAQ,CAAC,CAAC,EAC/B,MAAM,EAAE,gBAAgB,EACxB,OAAO,CAAC,EAAE,eAAe,GACxB,cAAc,CAAC,CAAC,CAAC,CA6BnB"}
@@ -18,10 +18,10 @@ import {
18
18
  createBoundedChannel2
19
19
  } from "../../index-w0eqdhyd.js";
20
20
  import"../../index-2kbysk9s.js";
21
- import"../../index-7r74re56.js";
21
+ import"../../index-bh2ht9y5.js";
22
22
  import {
23
23
  attemptExclusiveLock
24
- } from "../../index-bnf8s6v3.js";
24
+ } from "../../index-t2bsd0hm.js";
25
25
  import {
26
26
  BoundedFileReadError,
27
27
  openRegularFile
@@ -14,15 +14,15 @@ import {
14
14
  backoffDelay
15
15
  } from "../../index-g6a3na27.js";
16
16
  import"../../index-2kbysk9s.js";
17
- import"../../index-7r74re56.js";
18
- import"../../index-bnf8s6v3.js";
17
+ import"../../index-bh2ht9y5.js";
18
+ import"../../index-t2bsd0hm.js";
19
19
  import {
20
20
  defineManagedResource2
21
21
  } from "../../index-50ejfz75.js";
22
22
  import {
23
23
  createFileStateStore2
24
- } from "../../index-mbf4h8kp.js";
25
- import"../../index-4f37d3bg.js";
24
+ } from "../../index-nx49x0tw.js";
25
+ import"../../index-w9mqgnz9.js";
26
26
  import {
27
27
  raceAbort
28
28
  } from "../../index-b0kddvzw.js";
@@ -1,4 +1,36 @@
1
1
  #!/usr/bin/env node
2
+ /**
3
+ * `stitchkit upgrade` — the migration plan, from the package itself.
4
+ *
5
+ * A consumer used to recover its plan by cloning this repository and running a
6
+ * script that lives only here, or by being handed the version range in a letter.
7
+ * Both make upgrading depend on us. The changelog ships inside the package and
8
+ * this binary reads it, so `bunx stitchkit@latest upgrade` answers "what do I
9
+ * have to change" in one command, in the consumer's own project, with nobody
10
+ * told anything.
11
+ *
12
+ * Node built-ins only, and a `node` shebang: `npx` must work as well as `bunx`.
13
+ */
14
+ import { type Dirent } from 'node:fs';
15
+ import { type ProjectSource } from '../../internal/upgrade-usage.js';
16
+ /** How the scan reads the project; a test substitutes a refusal no file mode produces for root. */
17
+ export interface ProjectSourceIo {
18
+ readdir(path: string): readonly Dirent[];
19
+ readFile(path: string): string;
20
+ }
21
+ /** A directory or file the scan could not read, by path relative to the project root. */
22
+ export interface Unscanned {
23
+ readonly path: string;
24
+ readonly code: string;
25
+ }
26
+ /**
27
+ * Every source file of the project, by path relative to its root; links are not followed. A
28
+ * directory or file the process may not read is listed as unscanned rather than ending the plan.
29
+ */
30
+ export declare function projectSources(root: string, io?: ProjectSourceIo): {
31
+ sources: ProjectSource[];
32
+ unscanned: Unscanned[];
33
+ };
2
34
  export interface UpgradeCliResult {
3
35
  /** What to write to stdout. */
4
36
  readonly output: string;
@@ -1 +1 @@
1
- {"version":3,"file":"upgrade-cli.d.ts","sourceRoot":"","sources":["../../../src/entrypoints/bin/upgrade-cli.ts"],"names":[],"mappings":";AAgEA,MAAM,WAAW,gBAAgB;IAC/B,+BAA+B;IAC/B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,6EAA6E;IAC7E,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,GAAG,gBAAgB,CAqCvE;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CASrF"}
1
+ {"version":3,"file":"upgrade-cli.d.ts","sourceRoot":"","sources":["../../../src/entrypoints/bin/upgrade-cli.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,KAAK,MAAM,EAA2C,MAAM,SAAS,CAAC;AAI/E,OAAO,EACL,KAAK,aAAa,EAKnB,MAAM,8BAA8B,CAAC;AA4BtC,mGAAmG;AACnG,MAAM,WAAW,eAAe;IAC9B,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,CAAC;IACzC,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;CAChC;AAED,yFAAyF;AACzF,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAWD;;;GAGG;AACH,wBAAgB,cAAc,CAC5B,IAAI,EAAE,MAAM,EACZ,EAAE,GAAE,eAGH,GACA;IAAE,OAAO,EAAE,aAAa,EAAE,CAAC;IAAC,SAAS,EAAE,SAAS,EAAE,CAAA;CAAE,CAiCtD;AAoCD,MAAM,WAAW,gBAAgB;IAC/B,+BAA+B;IAC/B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,6EAA6E;IAC7E,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,GAAG,gBAAgB,CA+DvE;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CASrF"}