stitchkit 0.123.6 → 0.123.7

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 (47) hide show
  1. package/CHANGELOG.md +51 -0
  2. package/dist/entrypoints/application/diagnostic-journal.js +1 -1
  3. package/dist/entrypoints/application/directory-inbox.js +3 -3
  4. package/dist/entrypoints/cli/publish.js +2 -2
  5. package/dist/entrypoints/cli.js +2 -1
  6. package/dist/entrypoints/files.js +2 -2
  7. package/dist/entrypoints/node.js +2 -2
  8. package/dist/entrypoints/server.js +5 -5
  9. package/dist/entrypoints/telegram.js +1 -1
  10. package/dist/entrypoints/tools/contract.js +4 -2
  11. package/dist/entrypoints/tools/toolkit.js +2 -1
  12. package/dist/entrypoints/tools.js +33 -27
  13. package/dist/{index-xjb131sc.js → index-1a741dpf.js} +188 -51
  14. package/dist/{index-yfpt7sxr.js → index-6qrspvxp.js} +5 -3
  15. package/dist/index-81t0bf0f.js +18 -0
  16. package/dist/{index-d9cg0gen.js → index-8yky60kq.js} +1 -1
  17. package/dist/{index-bph35vpy.js → index-9cxxfkhb.js} +21 -1
  18. package/dist/index-bknzva6n.js +39 -0
  19. package/dist/{index-73dappvg.js → index-ezwvsqx9.js} +1 -1
  20. package/dist/{index-chz7c830.js → index-mqttte96.js} +39 -6
  21. package/dist/{index-eabx6qjh.js → index-tnnmekgb.js} +1 -6
  22. package/dist/index-zs8cze4j.js +6 -0
  23. package/dist/internal/exclusive-lock.d.ts.map +1 -1
  24. package/dist/internal/media-extension.d.ts +3 -0
  25. package/dist/internal/media-extension.d.ts.map +1 -0
  26. package/dist/tools/cli/args.d.ts +1 -1
  27. package/dist/tools/cli/args.d.ts.map +1 -1
  28. package/dist/tools/cli/command.d.ts +7 -1
  29. package/dist/tools/cli/command.d.ts.map +1 -1
  30. package/dist/tools/cli/config.d.ts +5 -2
  31. package/dist/tools/cli/config.d.ts.map +1 -1
  32. package/dist/tools/cli/download.d.ts +25 -4
  33. package/dist/tools/cli/download.d.ts.map +1 -1
  34. package/dist/tools/cli/inline-files.d.ts +70 -0
  35. package/dist/tools/cli/inline-files.d.ts.map +1 -0
  36. package/dist/tools/cli/session.d.ts.map +1 -1
  37. package/dist/tools/transfer/download-core.d.ts +2 -0
  38. package/dist/tools/transfer/download-core.d.ts.map +1 -1
  39. package/dist/tools/transfer/view-file-contract.d.ts +34 -4
  40. package/dist/tools/transfer/view-file-contract.d.ts.map +1 -1
  41. package/dist/tools/transfer/view-file.d.ts.map +1 -1
  42. package/llms/cli.txt +63 -3
  43. package/llms/tools.2.txt +5 -0
  44. package/llms-full.txt +68 -3
  45. package/llms.txt +2 -2
  46. package/package.json +1 -1
  47. package/dist/index-sba3e6m4.js +0 -52
package/CHANGELOG.md CHANGED
@@ -15,6 +15,57 @@ additive**; the first breaking change landed in 0.10.0. Grep the file for
15
15
 
16
16
  ## [Unreleased]
17
17
 
18
+ ## [0.123.7] - 2026-11-17
19
+
20
+ ### Added
21
+
22
+ - `stitchkit/cli` — **`--output-dir` saves the files a result carries inline and prints links
23
+ to them.** The blocks of a successful result's top-level `content` that hold a file — `image`
24
+ and `audio` of `McpMediaContentSchema`, and an embedded `resource` of any type with `blob` or
25
+ `text` (a PDF, a spreadsheet, a CSV) — are saved without a `download` callback, in the same
26
+ batch, pinned directory and atomic contained writer as URL downloads. This covers a
27
+ `defineViewFileTool` result and a tool mounted through MCP. A part of any other shape is left
28
+ alone. A media block's `name`, or the last path segment of a resource's `uri`, supplies the
29
+ file's basename; a block that names no file is `<type>-<sha256 of its bytes><extension>`.
30
+ Canonical base64 is validated and `maxDownloadBytes` is checked before the bytes are
31
+ allocated, one file at a time. On stdout each saved block becomes
32
+ `{ type: 'resource_link', uri: 'file://…', name, mimeType, size }`, so the bytes are not
33
+ printed again; a block that could not be saved keeps its bytes and the exit is `1`. A result
34
+ policy still receives the operation's own result. A result with no media prints and exits as
35
+ it does without the flag, and stderr says that nothing was saved — so `--output-dir` on a CLI
36
+ without a `download` callback runs the command instead of refusing it with exit `2`.
37
+ [guide](docs/guide/cli.md#saving-result-media). → ADR 0291
38
+
39
+ - `stitchkit/tools`, `stitchkit/tools/contract` — **An image or audio block carries the file
40
+ name of its source.** `McpMediaContentSchema` gains an optional `name` on its `image` and
41
+ `audio` blocks. `defineViewFileTool`, `mountViewFile` and `resolveMedia` set it: a managed
42
+ file keeps its own name, a URL takes its download name — the path's base name with the body's
43
+ extension. The name travels inside the block, over MCP as well. A download whose body is
44
+ `audio/mp4` is named `.m4a`.
45
+
46
+ ### Fixed
47
+
48
+ - `stitchkit/cli` — **Two `--output-dir` files with one name do not replace each other.** A
49
+ `download` callback that named two different files alike left the last one on disk while both
50
+ printed `saved`. A name is written once per batch: the same bytes again are one file,
51
+ different bytes fail that file with `another file of this batch is already saved as "<name>"`
52
+ and exit `1`, and the first file stays.
53
+ **Affects:** `stitchkit/cli` behaviour
54
+
55
+ - `stitchkit/cli` — **A `maxDownloadBytes` that is not a positive safe integer is refused when
56
+ the CLI is created**, with the shared limit message that ends in the value received. A
57
+ fractional, zero, negative or non-finite cap used to reach the first download.
58
+ **Affects:** `stitchkit/cli` createCli(maxDownloadBytes)
59
+
60
+ - `stitchkit/files` — **Reclaiming a dead owner's lock never removes a live one.** A reclaimer
61
+ judged the lock's record, then removed the file by its inode number. If the judged owner
62
+ released in between and a new holder created the lock on the freed inode, the live lock was
63
+ removed and two processes held it at once — seen under load when several processes recovered
64
+ a lock and its reclaim guard together. The reclaimer now keeps a descriptor open on the judged
65
+ file, so its inode cannot be reused, and removes it only while the name still holds that file
66
+ with the judged record; a lock replaced meanwhile refuses the reclaim and is waited for.
67
+ **Affects:** `stitchkit/files` withExclusiveLock(behaviour)
68
+
18
69
  ## [0.123.6] - 2026-11-16
19
70
 
20
71
  ### Added
@@ -21,7 +21,7 @@ import"../../index-sqc6ezrb.js";
21
21
  import"../../index-bqzgaj57.js";
22
22
  import {
23
23
  attemptExclusiveLock
24
- } from "../../index-chz7c830.js";
24
+ } from "../../index-mqttte96.js";
25
25
  import {
26
26
  BoundedFileReadError,
27
27
  openRegularFile
@@ -15,14 +15,14 @@ import {
15
15
  } from "../../index-g6a3na27.js";
16
16
  import"../../index-sqc6ezrb.js";
17
17
  import"../../index-bqzgaj57.js";
18
- import"../../index-chz7c830.js";
18
+ import"../../index-mqttte96.js";
19
19
  import {
20
20
  defineManagedResource2
21
21
  } from "../../index-50ejfz75.js";
22
22
  import {
23
23
  createFileStateStore2
24
- } from "../../index-d9cg0gen.js";
25
- import"../../index-73dappvg.js";
24
+ } from "../../index-8yky60kq.js";
25
+ import"../../index-ezwvsqx9.js";
26
26
  import {
27
27
  isJsonData
28
28
  } from "../../index-m6w6jtda.js";
@@ -1,7 +1,7 @@
1
1
  import"../../index-xqhede6x.js";
2
2
  import"../../index-sqc6ezrb.js";
3
3
  import"../../index-bqzgaj57.js";
4
- import"../../index-chz7c830.js";
4
+ import"../../index-mqttte96.js";
5
5
  import {
6
6
  signCliManifest2,
7
7
  verifyCliManifest2,
@@ -18,7 +18,7 @@ import {
18
18
  } from "../../index-tt3ej8r3.js";
19
19
  import {
20
20
  withExclusiveLock2
21
- } from "../../index-73dappvg.js";
21
+ } from "../../index-ezwvsqx9.js";
22
22
  import {
23
23
  ManagedFileError2,
24
24
  createManagedFileBoundary2
@@ -17,7 +17,7 @@ import {
17
17
  renderCliView2,
18
18
  pollUntilDone2,
19
19
  createCli2
20
- } from "../index-xjb131sc.js";
20
+ } from "../index-1a741dpf.js";
21
21
  import"../index-ndjzbt2v.js";
22
22
  import"../index-ct75c3at.js";
23
23
  import"../index-tynna0n4.js";
@@ -26,6 +26,7 @@ import"../index-yt1gg11x.js";
26
26
  import"../index-qc7tq0za.js";
27
27
  import"../index-332d0m9g.js";
28
28
  import"../index-sqc6ezrb.js";
29
+ import"../index-bknzva6n.js";
29
30
  import"../index-0v9xb8pz.js";
30
31
  import {
31
32
  CliBuildSignatureSchema2,
@@ -4,14 +4,14 @@ import {
4
4
  } from "../index-xqhede6x.js";
5
5
  import"../index-sqc6ezrb.js";
6
6
  import"../index-bqzgaj57.js";
7
- import"../index-chz7c830.js";
7
+ import"../index-mqttte96.js";
8
8
  import {
9
9
  bindUnixSocket2
10
10
  } from "../index-drcjjhy1.js";
11
11
  import {
12
12
  ExclusiveLockError2,
13
13
  withExclusiveLock2
14
- } from "../index-73dappvg.js";
14
+ } from "../index-ezwvsqx9.js";
15
15
  import {
16
16
  ManagedFileError2,
17
17
  createManagedFileBoundary2
@@ -24,7 +24,7 @@ import {
24
24
  createSocketIOServer2,
25
25
  UnixClientTransportError2,
26
26
  createUnixClientTransport2
27
- } from "../index-yfpt7sxr.js";
27
+ } from "../index-6qrspvxp.js";
28
28
  import {
29
29
  bindRealtimeServer2
30
30
  } from "../index-sqkttz7z.js";
@@ -33,7 +33,7 @@ import {
33
33
  implement2,
34
34
  createImplement2,
35
35
  createScopedImplement2
36
- } from "../index-eabx6qjh.js";
36
+ } from "../index-tnnmekgb.js";
37
37
  import"../index-9ypczvpj.js";
38
38
  import {
39
39
  AppError2,
@@ -1,6 +1,6 @@
1
1
  import"../index-sqc6ezrb.js";
2
2
  import"../index-bqzgaj57.js";
3
- import"../index-chz7c830.js";
3
+ import"../index-mqttte96.js";
4
4
  import {
5
5
  errorCode2,
6
6
  normalizeError2
@@ -53,17 +53,17 @@ import {
53
53
  socketIoLane2,
54
54
  UnixClientTransportError2,
55
55
  createUnixClientTransport2
56
- } from "../index-yfpt7sxr.js";
56
+ } from "../index-6qrspvxp.js";
57
57
  import {
58
58
  createFileStateStore2
59
- } from "../index-d9cg0gen.js";
59
+ } from "../index-8yky60kq.js";
60
60
  import {
61
61
  bindRealtimeServer2
62
62
  } from "../index-sqkttz7z.js";
63
63
  import {
64
64
  bindUnixSocket2
65
65
  } from "../index-drcjjhy1.js";
66
- import"../index-73dappvg.js";
66
+ import"../index-ezwvsqx9.js";
67
67
  import {
68
68
  withDeadline
69
69
  } from "../index-9tqbxv5p.js";
@@ -84,7 +84,7 @@ import {
84
84
  implement2,
85
85
  createImplement2,
86
86
  createScopedImplement2
87
- } from "../index-eabx6qjh.js";
87
+ } from "../index-tnnmekgb.js";
88
88
  import"../index-9ypczvpj.js";
89
89
  import {
90
90
  DEFAULT_CORS_ALLOW_HEADERS2,
@@ -5,7 +5,7 @@ import"../index-sqc6ezrb.js";
5
5
  import"../index-bqzgaj57.js";
6
6
  import {
7
7
  attemptExclusiveLock
8
- } from "../index-chz7c830.js";
8
+ } from "../index-mqttte96.js";
9
9
  import {
10
10
  TELEGRAM_WIDGET_LIMITS2,
11
11
  TelegramWidgetHtmlSchema2,
@@ -1,12 +1,14 @@
1
1
  import {
2
2
  AsyncOperationCancelResultSchema2,
3
- createAsyncOperationSnapshotSchema2,
3
+ createAsyncOperationSnapshotSchema2
4
+ } from "../../index-81t0bf0f.js";
5
+ import {
4
6
  McpAnnotationsSchema2,
5
7
  McpMediaContentSchema2,
6
8
  ViewFileErrorSchema2,
7
9
  ViewFileOutputSchema2,
8
10
  ViewFileInputSchema2
9
- } from "../../index-sba3e6m4.js";
11
+ } from "../../index-bknzva6n.js";
10
12
  import {
11
13
  coerceJsonArgs2
12
14
  } from "../../index-t8jz0e20.js";
@@ -11,9 +11,10 @@ import {
11
11
  } from "../../index-yebkpytc.js";
12
12
  import {
13
13
  createCli2
14
- } from "../../index-xjb131sc.js";
14
+ } from "../../index-1a741dpf.js";
15
15
  import"../../index-332d0m9g.js";
16
16
  import"../../index-sqc6ezrb.js";
17
+ import"../../index-bknzva6n.js";
17
18
  import"../../index-0v9xb8pz.js";
18
19
  import {
19
20
  mountMcp2,
@@ -37,25 +37,26 @@ import {
37
37
  } from "../index-99nnsz39.js";
38
38
  import {
39
39
  AsyncOperationCancelResultSchema2,
40
- createAsyncOperationSnapshotSchema2,
40
+ createAsyncOperationSnapshotSchema2
41
+ } from "../index-81t0bf0f.js";
42
+ import {
43
+ ManagedFilePathSchema2,
44
+ ManagedFileRefSchema2
45
+ } from "../index-xqhede6x.js";
46
+ import {
41
47
  McpAnnotationsSchema2,
42
48
  McpMediaContentSchema2,
43
49
  ViewFileErrorSchema2,
44
50
  ViewFileOutputSchema2,
45
51
  ViewFileInputSchema2
46
- } from "../index-sba3e6m4.js";
47
- import {
48
- ManagedFilePathSchema2,
49
- ManagedFileRefSchema2
50
- } from "../index-xqhede6x.js";
52
+ } from "../index-bknzva6n.js";
51
53
  import {
52
54
  signJwt2,
53
55
  verifyPkce2
54
56
  } from "../index-hkw233vx.js";
55
57
  import {
56
- contractOnlyService,
57
- mediaTypeEssence
58
- } from "../index-eabx6qjh.js";
58
+ contractOnlyService
59
+ } from "../index-tnnmekgb.js";
59
60
  import"../index-9ypczvpj.js";
60
61
  import {
61
62
  describeToolCatalog2,
@@ -80,8 +81,12 @@ import {
80
81
  } from "../index-96yjwwgf.js";
81
82
  import {
82
83
  WaitTimeoutError,
83
- runWaitOperation
84
- } from "../index-bph35vpy.js";
84
+ runWaitOperation,
85
+ mediaExtension
86
+ } from "../index-9cxxfkhb.js";
87
+ import {
88
+ mediaTypeEssence
89
+ } from "../index-zs8cze4j.js";
85
90
  import {
86
91
  collectToolSurface
87
92
  } from "../index-993vtv1w.js";
@@ -1410,17 +1415,6 @@ function createToolLogger(config = {}) {
1410
1415
  // src/tools/transfer/download-core.ts
1411
1416
  import { basename, extname } from "node:path";
1412
1417
  var DEFAULT_MAX_BYTES = 100 * 1024 * 1024;
1413
- var MIME_EXT = {
1414
- "image/png": ".png",
1415
- "image/jpeg": ".jpg",
1416
- "image/webp": ".webp",
1417
- "image/gif": ".gif",
1418
- "video/mp4": ".mp4",
1419
- "video/webm": ".webm",
1420
- "audio/mpeg": ".mp3",
1421
- "audio/wav": ".wav",
1422
- "audio/ogg": ".ogg"
1423
- };
1424
1418
 
1425
1419
  class DownloadOperationError extends Error {
1426
1420
  code;
@@ -1433,8 +1427,9 @@ class DownloadOperationError extends Error {
1433
1427
  }
1434
1428
  }
1435
1429
  function extensionFor(url, mime) {
1436
- if (MIME_EXT[mime])
1437
- return MIME_EXT[mime];
1430
+ const known = mediaExtension(mime);
1431
+ if (known)
1432
+ return known;
1438
1433
  try {
1439
1434
  const ext = extname(new URL(url).pathname).toLowerCase();
1440
1435
  if (ext)
@@ -1450,6 +1445,9 @@ function baseNameFor(url) {
1450
1445
  return "download";
1451
1446
  }
1452
1447
  }
1448
+ function downloadFileName(url, mime) {
1449
+ return `${baseNameFor(url)}${extensionFor(url, mime)}`;
1450
+ }
1453
1451
  async function runDownloadOperation(config) {
1454
1452
  const res = await fetchGuarded(new URL(config.url), config.allowPrivateHosts ?? false, {
1455
1453
  timeoutMs: config.timeoutMs,
@@ -1465,7 +1463,7 @@ async function runDownloadOperation(config) {
1465
1463
  await res.body?.cancel();
1466
1464
  throw new DownloadOperationError("DOWNLOAD_TOO_LARGE", `file exceeds the ${max}-byte cap`, 413);
1467
1465
  }
1468
- const path = config.path ?? `${baseNameFor(config.url)}${extensionFor(config.url, mimeType)}`;
1466
+ const path = config.path ?? downloadFileName(config.url, mimeType);
1469
1467
  return config.files.write(path, res.body ?? new Uint8Array, {
1470
1468
  maxBytes: max,
1471
1469
  mediaType: mimeType,
@@ -1604,7 +1602,7 @@ function defineUploadTool(config) {
1604
1602
  });
1605
1603
  }
1606
1604
  // src/tools/transfer/view-file.ts
1607
- import { extname as extname2 } from "node:path";
1605
+ import { basename as basename2, extname as extname2 } from "node:path";
1608
1606
  import { z as z5 } from "zod";
1609
1607
  var MAX_INLINE_BYTES = 20 * 1024 * 1024;
1610
1608
  var EXT_MIME = {
@@ -1621,10 +1619,16 @@ var EXT_MIME = {
1621
1619
  ".webm": "video/webm",
1622
1620
  ".mov": "video/quicktime"
1623
1621
  };
1622
+ function isHttpUrl(pathOrUrl) {
1623
+ return pathOrUrl.startsWith("http://") || pathOrUrl.startsWith("https://");
1624
+ }
1625
+ function sourceName(pathOrUrl, mimeType) {
1626
+ return isHttpUrl(pathOrUrl) ? downloadFileName(pathOrUrl, mimeType) : basename2(pathOrUrl);
1627
+ }
1624
1628
  async function fetchSource(pathOrUrl, options, maxBytes) {
1625
1629
  const extension = extname2(pathOrUrl);
1626
1630
  const extMime = EXT_MIME[extension.toLowerCase()];
1627
- if (pathOrUrl.startsWith("http://") || pathOrUrl.startsWith("https://")) {
1631
+ if (isHttpUrl(pathOrUrl)) {
1628
1632
  const url = new URL(pathOrUrl);
1629
1633
  const res = await fetchGuarded(url, options.allowPrivateHosts ?? false, {
1630
1634
  timeoutMs: options.timeoutMs,
@@ -1717,6 +1721,7 @@ async function resolveMediaWithinBudget(pathOrUrl, options, maxBytes) {
1717
1721
  type: "image",
1718
1722
  data: buffer.toString("base64"),
1719
1723
  mimeType,
1724
+ name: sourceName(pathOrUrl, mimeType),
1720
1725
  annotations: { audience: ["user", "assistant"], priority: 0.9 }
1721
1726
  },
1722
1727
  { type: "text", text: `[image] ${mimeType}, ${sizeKb}KB` }
@@ -1731,6 +1736,7 @@ async function resolveMediaWithinBudget(pathOrUrl, options, maxBytes) {
1731
1736
  type: "audio",
1732
1737
  data: buffer.toString("base64"),
1733
1738
  mimeType,
1739
+ name: sourceName(pathOrUrl, mimeType),
1734
1740
  annotations: { audience: ["user", "assistant"], priority: 0.9 }
1735
1741
  },
1736
1742
  { type: "text", text: `[audio] ${mimeType}, ${sizeKb}KB` }