stitchkit 0.88.0 → 0.90.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 (184) hide show
  1. package/CHANGELOG.md +182 -0
  2. package/dist/agent-runtime/child-blocking.d.ts +17 -0
  3. package/dist/agent-runtime/child-blocking.d.ts.map +1 -0
  4. package/dist/agent-runtime/child-budget-policy.d.ts +23 -0
  5. package/dist/agent-runtime/child-budget-policy.d.ts.map +1 -0
  6. package/dist/agent-runtime/children-contract.d.ts +155 -0
  7. package/dist/agent-runtime/children-contract.d.ts.map +1 -0
  8. package/dist/agent-runtime/children.d.ts +4 -99
  9. package/dist/agent-runtime/children.d.ts.map +1 -1
  10. package/dist/agent-runtime/coding-shell-process.d.ts +33 -0
  11. package/dist/agent-runtime/coding-shell-process.d.ts.map +1 -0
  12. package/dist/agent-runtime/coding-tool-contract.d.ts +18 -0
  13. package/dist/agent-runtime/coding-tool-contract.d.ts.map +1 -1
  14. package/dist/agent-runtime/coding-tool-files.d.ts.map +1 -1
  15. package/dist/agent-runtime/coding-tool-listing.d.ts.map +1 -1
  16. package/dist/agent-runtime/coding-tool-search-patch.d.ts.map +1 -1
  17. package/dist/agent-runtime/coding-tool-shell.d.ts.map +1 -1
  18. package/dist/agent-runtime/coding-tool-utf8.d.ts +28 -0
  19. package/dist/agent-runtime/coding-tool-utf8.d.ts.map +1 -0
  20. package/dist/agent-runtime/contained-files.d.ts +20 -0
  21. package/dist/agent-runtime/contained-files.d.ts.map +1 -1
  22. package/dist/agent-runtime/durability-contract.d.ts +176 -0
  23. package/dist/agent-runtime/durability-contract.d.ts.map +1 -0
  24. package/dist/agent-runtime/durability-json.d.ts +3 -0
  25. package/dist/agent-runtime/durability-json.d.ts.map +1 -0
  26. package/dist/agent-runtime/durability-ledger.d.ts +16 -0
  27. package/dist/agent-runtime/durability-ledger.d.ts.map +1 -0
  28. package/dist/agent-runtime/durability-scheduler.d.ts +29 -0
  29. package/dist/agent-runtime/durability-scheduler.d.ts.map +1 -0
  30. package/dist/agent-runtime/durability.d.ts +14 -0
  31. package/dist/agent-runtime/durability.d.ts.map +1 -0
  32. package/dist/agent-runtime/event-search.d.ts.map +1 -1
  33. package/dist/agent-runtime/harness-contract.d.ts +37 -0
  34. package/dist/agent-runtime/harness-contract.d.ts.map +1 -1
  35. package/dist/agent-runtime/harness.d.ts +8 -0
  36. package/dist/agent-runtime/harness.d.ts.map +1 -1
  37. package/dist/agent-runtime/prompt.d.ts +23 -0
  38. package/dist/agent-runtime/prompt.d.ts.map +1 -1
  39. package/dist/agent-runtime/run-execution.d.ts.map +1 -1
  40. package/dist/agent-runtime/runtime-internals.d.ts +4 -0
  41. package/dist/agent-runtime/runtime-internals.d.ts.map +1 -1
  42. package/dist/agent-runtime/runtime.d.ts +13 -0
  43. package/dist/agent-runtime/runtime.d.ts.map +1 -1
  44. package/dist/agent-runtime/sandbox-broker.d.ts +7 -0
  45. package/dist/agent-runtime/sandbox-broker.d.ts.map +1 -0
  46. package/dist/agent-runtime/sandbox-bubblewrap-args.d.ts +9 -0
  47. package/dist/agent-runtime/sandbox-bubblewrap-args.d.ts.map +1 -0
  48. package/dist/agent-runtime/sandbox-bubblewrap-storage.d.ts +22 -0
  49. package/dist/agent-runtime/sandbox-bubblewrap-storage.d.ts.map +1 -0
  50. package/dist/agent-runtime/sandbox-bubblewrap.d.ts +14 -0
  51. package/dist/agent-runtime/sandbox-bubblewrap.d.ts.map +1 -0
  52. package/dist/agent-runtime/sandbox-coding-adapter.d.ts +15 -0
  53. package/dist/agent-runtime/sandbox-coding-adapter.d.ts.map +1 -0
  54. package/dist/agent-runtime/sandbox-coding.d.ts +15 -0
  55. package/dist/agent-runtime/sandbox-coding.d.ts.map +1 -0
  56. package/dist/agent-runtime/sandbox-contract.d.ts +93 -0
  57. package/dist/agent-runtime/sandbox-contract.d.ts.map +1 -0
  58. package/dist/agent-runtime/sandbox-process-owner.d.ts +11 -0
  59. package/dist/agent-runtime/sandbox-process-owner.d.ts.map +1 -0
  60. package/dist/agent-runtime/sandbox-process.d.ts +8 -0
  61. package/dist/agent-runtime/sandbox-process.d.ts.map +1 -0
  62. package/dist/agent-runtime/sandbox-session.d.ts +5 -0
  63. package/dist/agent-runtime/sandbox-session.d.ts.map +1 -0
  64. package/dist/agent-runtime/sandbox.d.ts +19 -0
  65. package/dist/agent-runtime/sandbox.d.ts.map +1 -1
  66. package/dist/agent-runtime/sqlite-purge.d.ts.map +1 -1
  67. package/dist/agent-runtime/sqlite.d.ts.map +1 -1
  68. package/dist/agent-runtime/store-driver.d.ts +127 -0
  69. package/dist/agent-runtime/store-driver.d.ts.map +1 -1
  70. package/dist/agent-runtime/store-events.d.ts +104 -0
  71. package/dist/agent-runtime/store-events.d.ts.map +1 -1
  72. package/dist/agent-runtime/store-migrations/v2-to-v3.d.ts +14 -0
  73. package/dist/agent-runtime/store-migrations/v2-to-v3.d.ts.map +1 -0
  74. package/dist/agent-runtime/store.d.ts +115 -0
  75. package/dist/agent-runtime/store.d.ts.map +1 -1
  76. package/dist/agent-runtime-coding-tools.js +11 -1247
  77. package/dist/agent-runtime-harness.d.ts +1 -1
  78. package/dist/agent-runtime-harness.d.ts.map +1 -1
  79. package/dist/agent-runtime-harness.js +65 -15
  80. package/dist/agent-runtime-openrouter.d.ts +3 -12
  81. package/dist/agent-runtime-openrouter.d.ts.map +1 -1
  82. package/dist/agent-runtime-openrouter.js +10 -7
  83. package/dist/agent-runtime-sandbox.d.ts +5 -0
  84. package/dist/agent-runtime-sandbox.d.ts.map +1 -0
  85. package/dist/agent-runtime-sandbox.js +797 -0
  86. package/dist/agent-runtime-sqlite-bun.js +3 -3
  87. package/dist/agent-runtime-sqlite-node.js +3 -3
  88. package/dist/agent-runtime.d.ts +5 -4
  89. package/dist/agent-runtime.d.ts.map +1 -1
  90. package/dist/agent-runtime.js +259 -65
  91. package/dist/application/watch-hub.d.ts +24 -2
  92. package/dist/application/watch-hub.d.ts.map +1 -1
  93. package/dist/application.js +127 -37
  94. package/dist/cli.js +8 -8
  95. package/dist/index-2na0qrfn.js +214 -0
  96. package/dist/{index-rcgsnrr6.js → index-31jw8fjq.js} +3 -3
  97. package/dist/{index-9hw9eq48.js → index-7601qfg1.js} +14 -14
  98. package/dist/{index-3xnq72rz.js → index-7rkhw9ec.js} +14 -1
  99. package/dist/{index-0vfdh685.js → index-8c3a7m4g.js} +1 -1
  100. package/dist/{index-t7gh5w3v.js → index-bn2cjajt.js} +27 -6
  101. package/dist/index-cp20z0n6.js +1351 -0
  102. package/dist/{index-qp3vshvc.js → index-fadnxwna.js} +87 -5
  103. package/dist/{index-v1qk37y9.js → index-hrbajay7.js} +106 -4
  104. package/dist/{index-p86mxmpp.js → index-hw2chdvy.js} +646 -43
  105. package/dist/{index-0ydchz76.js → index-mnm4qp0p.js} +5 -5
  106. package/dist/{index-1szetq6f.js → index-q3ve2d1k.js} +30 -8
  107. package/dist/{index-6krwcdcf.js → index-zwkgfq1s.js} +95 -85
  108. package/dist/{index-wn9cb82y.js → index-zyvby92n.js} +12 -9
  109. package/dist/index.js +13 -13
  110. package/dist/live/watch-client.d.ts +2 -1
  111. package/dist/live/watch-client.d.ts.map +1 -1
  112. package/dist/live/watch-contract.d.ts +70 -4
  113. package/dist/live/watch-contract.d.ts.map +1 -1
  114. package/dist/live/watch-delta.d.ts +110 -0
  115. package/dist/live/watch-delta.d.ts.map +1 -0
  116. package/dist/live.d.ts +2 -1
  117. package/dist/live.d.ts.map +1 -1
  118. package/dist/live.js +56 -4
  119. package/dist/observability/changes.d.ts +55 -0
  120. package/dist/observability/changes.d.ts.map +1 -0
  121. package/dist/observability/index.d.ts +2 -0
  122. package/dist/observability/index.d.ts.map +1 -1
  123. package/dist/observability/index.js +127 -0
  124. package/dist/observability/spool.d.ts +53 -0
  125. package/dist/observability/spool.d.ts.map +1 -0
  126. package/dist/server/index.js +9 -9
  127. package/dist/testing/agent-store-conformance.d.ts.map +1 -1
  128. package/dist/testing.js +57 -23
  129. package/dist/tool-invoker.js +6 -6
  130. package/dist/tools/agent.d.ts +6 -0
  131. package/dist/tools/agent.d.ts.map +1 -1
  132. package/dist/tools/connections/define.d.ts +6 -0
  133. package/dist/tools/connections/define.d.ts.map +1 -0
  134. package/dist/tools/connections/errors.d.ts +50 -0
  135. package/dist/tools/connections/errors.d.ts.map +1 -0
  136. package/dist/tools/connections/http.d.ts +3 -0
  137. package/dist/tools/connections/http.d.ts.map +1 -0
  138. package/dist/tools/connections/index.d.ts +19 -0
  139. package/dist/tools/connections/index.d.ts.map +1 -0
  140. package/dist/tools/connections/index.js +1047 -0
  141. package/dist/tools/connections/instance.d.ts +3 -0
  142. package/dist/tools/connections/instance.d.ts.map +1 -0
  143. package/dist/tools/connections/json-rpc.d.ts +8 -0
  144. package/dist/tools/connections/json-rpc.d.ts.map +1 -0
  145. package/dist/tools/connections/limits.d.ts +36 -0
  146. package/dist/tools/connections/limits.d.ts.map +1 -0
  147. package/dist/tools/connections/mcp-client.d.ts +44 -0
  148. package/dist/tools/connections/mcp-client.d.ts.map +1 -0
  149. package/dist/tools/connections/mcp.d.ts +5 -0
  150. package/dist/tools/connections/mcp.d.ts.map +1 -0
  151. package/dist/tools/connections/mount.d.ts +12 -0
  152. package/dist/tools/connections/mount.d.ts.map +1 -0
  153. package/dist/tools/connections/openapi-document.d.ts +4 -0
  154. package/dist/tools/connections/openapi-document.d.ts.map +1 -0
  155. package/dist/tools/connections/openapi.d.ts +5 -0
  156. package/dist/tools/connections/openapi.d.ts.map +1 -0
  157. package/dist/tools/connections/runtime.d.ts +29 -0
  158. package/dist/tools/connections/runtime.d.ts.map +1 -0
  159. package/dist/tools/connections/schema-budget.d.ts +8 -0
  160. package/dist/tools/connections/schema-budget.d.ts.map +1 -0
  161. package/dist/tools/connections/sse-frames.d.ts +7 -0
  162. package/dist/tools/connections/sse-frames.d.ts.map +1 -0
  163. package/dist/tools/connections/sse-session.d.ts +26 -0
  164. package/dist/tools/connections/sse-session.d.ts.map +1 -0
  165. package/dist/tools/connections/ssrf.d.ts +15 -0
  166. package/dist/tools/connections/ssrf.d.ts.map +1 -0
  167. package/dist/tools/connections/types.d.ts +60 -0
  168. package/dist/tools/connections/types.d.ts.map +1 -0
  169. package/dist/tools/durability-context.d.ts +7 -0
  170. package/dist/tools/durability-context.d.ts.map +1 -0
  171. package/dist/tools/execute.d.ts +2 -0
  172. package/dist/tools/execute.d.ts.map +1 -1
  173. package/dist/tools/registry.d.ts +38 -0
  174. package/dist/tools/registry.d.ts.map +1 -0
  175. package/dist/tools/runtime-tool.d.ts +4 -0
  176. package/dist/tools/runtime-tool.d.ts.map +1 -1
  177. package/dist/tools.d.ts +1 -0
  178. package/dist/tools.d.ts.map +1 -1
  179. package/dist/tools.js +83 -26
  180. package/llms-full.txt +386 -16
  181. package/llms.txt +1 -0
  182. package/package.json +9 -1
  183. package/dist/index-dre2ywck.js +0 -48
  184. package/dist/{index-evcnmsc3.js → index-t7fkyxcr.js} +3 -3
@@ -1,17 +1,3 @@
1
- import"./index-pq95qkbf.js";
2
- import {
3
- ApplicationAdmissionError,
4
- ApplicationRestartInputSchema,
5
- ApplicationRestartOutcomeSchema,
6
- ApplicationRestartResultSchema,
7
- ApplicationShutdownBudgetSchema,
8
- ApplicationShutdownOptionsSchema,
9
- createApplication
10
- } from "./index-evcnmsc3.js";
11
- import {
12
- defineManagedResource,
13
- managedResourceDependencyId
14
- } from "./index-2k4yrqkc.js";
15
1
  import {
16
2
  ActivityIdSchema,
17
3
  ActivityLiveStateSchema,
@@ -28,6 +14,29 @@ import {
28
14
  createApplicationSnapshotSink,
29
15
  createManagedSchedule
30
16
  } from "./index-9f8ztey6.js";
17
+ import {
18
+ DiagnosticJournalCloseResultSchema,
19
+ DiagnosticJournalFailurePhaseSchema,
20
+ DiagnosticJournalFrameSchema,
21
+ DiagnosticJournalLimitsSchema,
22
+ DiagnosticJournalLockPolicySchema,
23
+ DiagnosticJournalRefusalReasonSchema,
24
+ DiagnosticJournalStateSchema,
25
+ DiagnosticJournalStatusSchema,
26
+ DiagnosticJournalSubmitResultSchema,
27
+ DiagnosticJournalWaitResultSchema,
28
+ readDiagnosticJournalLockDiagnosis
29
+ } from "./index-wc4x00bn.js";
30
+ import"./index-pq95qkbf.js";
31
+ import {
32
+ ApplicationAdmissionError,
33
+ ApplicationRestartInputSchema,
34
+ ApplicationRestartOutcomeSchema,
35
+ ApplicationRestartResultSchema,
36
+ ApplicationShutdownBudgetSchema,
37
+ ApplicationShutdownOptionsSchema,
38
+ createApplication
39
+ } from "./index-t7fkyxcr.js";
31
40
  import {
32
41
  ApplicationAdmissionSnapshotSchema,
33
42
  ApplicationHealthSchema,
@@ -42,18 +51,9 @@ import {
42
51
  projectApplicationStatus
43
52
  } from "./index-3gye9wzb.js";
44
53
  import {
45
- DiagnosticJournalCloseResultSchema,
46
- DiagnosticJournalFailurePhaseSchema,
47
- DiagnosticJournalFrameSchema,
48
- DiagnosticJournalLimitsSchema,
49
- DiagnosticJournalLockPolicySchema,
50
- DiagnosticJournalRefusalReasonSchema,
51
- DiagnosticJournalStateSchema,
52
- DiagnosticJournalStatusSchema,
53
- DiagnosticJournalSubmitResultSchema,
54
- DiagnosticJournalWaitResultSchema,
55
- readDiagnosticJournalLockDiagnosis
56
- } from "./index-wc4x00bn.js";
54
+ defineManagedResource,
55
+ managedResourceDependencyId
56
+ } from "./index-2k4yrqkc.js";
57
57
  import {
58
58
  withDeadline
59
59
  } from "./index-b9aefrqd.js";
@@ -66,8 +66,10 @@ import {
66
66
  createBackoff
67
67
  } from "./index-s8cnx02s.js";
68
68
  import {
69
+ deltaWins,
70
+ diff,
69
71
  watchKeyString
70
- } from "./index-dre2ywck.js";
72
+ } from "./index-2na0qrfn.js";
71
73
  import"./index-ywd0y6m1.js";
72
74
  import {
73
75
  BoundedChannelPolicySchema,
@@ -1563,17 +1565,20 @@ function createWatchHub(config) {
1563
1565
  const held = new Map;
1564
1566
  const maxWatches = config.maxWatchesPerSubscriber ?? 64;
1565
1567
  const holdMs = config.holdMs ?? 0;
1568
+ const deltaMemoryBytes = config.deltaMemoryBytes ?? 262144;
1566
1569
  const same = config.same ?? ((previous, next) => JSON.stringify(stableValue(previous)) === JSON.stringify(stableValue(next)));
1567
1570
  let reads = 0;
1568
1571
  let closed = false;
1569
- function tell(key, deliver) {
1572
+ function tell(key, deliver2) {
1570
1573
  try {
1571
- deliver();
1574
+ deliver2();
1575
+ return true;
1572
1576
  } catch (error) {
1573
1577
  config.logger?.warn?.("[stitchkit] watch subscriber threw", {
1574
1578
  key: watchKeyString(key),
1575
1579
  error: error instanceof Error ? error.message : String(error)
1576
1580
  });
1581
+ return false;
1577
1582
  }
1578
1583
  }
1579
1584
  function announceState(source, state) {
@@ -1582,13 +1587,85 @@ function createWatchHub(config) {
1582
1587
  tell(source.key, () => subscriber.state(state));
1583
1588
  }
1584
1589
  }
1585
- function publish(source, value) {
1590
+ function remember(source, revision, value, fingerprint) {
1591
+ if (deltaMemoryBytes === 0)
1592
+ return;
1593
+ const bytes = (JSON.stringify(value) ?? "null").length;
1594
+ if (bytes > deltaMemoryBytes)
1595
+ return;
1596
+ source.history.set(revision, { value, fingerprint, bytes });
1597
+ source.historyBytes += bytes;
1598
+ for (const [oldest, entry] of source.history) {
1599
+ if (source.historyBytes <= deltaMemoryBytes)
1600
+ break;
1601
+ source.history.delete(oldest);
1602
+ source.historyBytes -= entry.bytes;
1603
+ }
1604
+ }
1605
+ function frameFor(source, subscriber) {
1606
+ const value = source.value;
1607
+ const fingerprint = source.fingerprint ?? valueFingerprint(value);
1608
+ const full = {
1609
+ kind: "full",
1610
+ key: source.key,
1611
+ revision: source.revision,
1612
+ fingerprint,
1613
+ value
1614
+ };
1615
+ const base = source.baselines.get(subscriber);
1616
+ if (base === undefined)
1617
+ return full;
1618
+ if (base === source.revision) {
1619
+ return { kind: "unchanged", key: source.key, revision: source.revision, fingerprint };
1620
+ }
1621
+ const held2 = source.history.get(base);
1622
+ if (!held2)
1623
+ return full;
1624
+ const delta = diff(held2.value, value);
1625
+ if (delta === undefined || !deltaWins(delta, value))
1626
+ return full;
1627
+ return {
1628
+ kind: "delta",
1629
+ key: source.key,
1630
+ revision: source.revision,
1631
+ fingerprint,
1632
+ base,
1633
+ delta
1634
+ };
1635
+ }
1636
+ function adoptBaseline(source, subscriber, have) {
1637
+ if (source.fingerprint === have.fingerprint) {
1638
+ source.baselines.set(subscriber, source.revision);
1639
+ return;
1640
+ }
1641
+ const named = source.history.get(have.revision);
1642
+ if (named?.fingerprint === have.fingerprint) {
1643
+ source.baselines.set(subscriber, have.revision);
1644
+ return;
1645
+ }
1646
+ for (const [revision, entry] of source.history) {
1647
+ if (entry.fingerprint !== have.fingerprint)
1648
+ continue;
1649
+ source.baselines.set(subscriber, revision);
1650
+ return;
1651
+ }
1652
+ }
1653
+ function deliver(source, subscriber) {
1654
+ const frame = frameFor(source, subscriber);
1655
+ const delivered = tell(source.key, () => subscriber.value(frame));
1656
+ if (delivered)
1657
+ source.baselines.set(subscriber, source.revision);
1658
+ return delivered;
1659
+ }
1660
+ function publish(source, value, fingerprint) {
1661
+ if (source.fingerprint !== undefined) {
1662
+ remember(source, source.revision, source.value, source.fingerprint);
1663
+ }
1586
1664
  source.revision += 1;
1587
1665
  source.value = value;
1588
- const frame = { key: source.key, revision: source.revision, value };
1589
- for (const subscriber of source.subscribers) {
1590
- tell(source.key, () => subscriber.value(frame));
1591
- }
1666
+ source.fingerprint = fingerprint;
1667
+ for (const subscriber of source.subscribers)
1668
+ deliver(source, subscriber);
1592
1669
  }
1593
1670
  async function pump(source) {
1594
1671
  if (source.reading || closed)
@@ -1605,7 +1682,7 @@ function createWatchHub(config) {
1605
1682
  const unchanged = source.signature !== undefined && same(source.value, value);
1606
1683
  source.signature = signature;
1607
1684
  if (!unchanged)
1608
- publish(source, value);
1685
+ publish(source, value, valueFingerprint(value));
1609
1686
  if (source.state.phase !== "live") {
1610
1687
  announceState(source, { key: source.key, phase: "live" });
1611
1688
  }
@@ -1655,6 +1732,9 @@ function createWatchHub(config) {
1655
1732
  subscribers: new Set,
1656
1733
  unsubscribes: [],
1657
1734
  revision: 0,
1735
+ history: new Map,
1736
+ historyBytes: 0,
1737
+ baselines: new Map,
1658
1738
  reading: false,
1659
1739
  dirty: true,
1660
1740
  state: { key, phase: "opening" },
@@ -1696,7 +1776,7 @@ function createWatchHub(config) {
1696
1776
  const keys = new Set;
1697
1777
  held.set(subscriber, keys);
1698
1778
  return {
1699
- open(key, args) {
1779
+ open(key, args, have) {
1700
1780
  if (closed)
1701
1781
  return { accepted: false, reason: "the watch hub is closed" };
1702
1782
  const operation = { service: key.service, action: key.action };
@@ -1718,13 +1798,18 @@ function createWatchHub(config) {
1718
1798
  const source = acquire(operation, key, args);
1719
1799
  source.subscribers.add(subscriber);
1720
1800
  keys.add(id);
1801
+ if (have)
1802
+ adoptBaseline(source, subscriber, have);
1721
1803
  try {
1722
1804
  if (source.signature !== undefined) {
1723
- subscriber.value({ key, revision: source.revision, value: source.value });
1805
+ const frame = frameFor(source, subscriber);
1806
+ subscriber.value(frame);
1807
+ source.baselines.set(subscriber, source.revision);
1724
1808
  }
1725
1809
  subscriber.state(source.state);
1726
1810
  } catch (error) {
1727
1811
  source.subscribers.delete(subscriber);
1812
+ source.baselines.delete(subscriber);
1728
1813
  keys.delete(id);
1729
1814
  release(source);
1730
1815
  return {
@@ -1743,6 +1828,7 @@ function createWatchHub(config) {
1743
1828
  if (!source)
1744
1829
  return;
1745
1830
  source.subscribers.delete(subscriber);
1831
+ source.baselines.delete(subscriber);
1746
1832
  release(source);
1747
1833
  },
1748
1834
  detach() {
@@ -1751,6 +1837,7 @@ function createWatchHub(config) {
1751
1837
  if (!source)
1752
1838
  continue;
1753
1839
  source.subscribers.delete(subscriber);
1840
+ source.baselines.delete(subscriber);
1754
1841
  release(source);
1755
1842
  }
1756
1843
  keys.clear();
@@ -1779,6 +1866,9 @@ function createWatchHub(config) {
1779
1866
  }
1780
1867
  };
1781
1868
  }
1869
+ function valueFingerprint(value) {
1870
+ return argumentsDigest({ value });
1871
+ }
1782
1872
  function readErrorCode(error) {
1783
1873
  if (typeof error !== "object" || error === null)
1784
1874
  return;
package/dist/cli.js CHANGED
@@ -5,23 +5,23 @@ import {
5
5
  emitResult,
6
6
  parseCliArgs,
7
7
  pollUntilDone
8
- } from "./index-9hw9eq48.js";
8
+ } from "./index-7601qfg1.js";
9
9
  import"./index-sbdmyz75.js";
10
- import"./index-rcgsnrr6.js";
11
- import"./index-kc6h6hg0.js";
12
- import"./index-0vfdh685.js";
13
- import"./index-wn9cb82y.js";
10
+ import"./index-31jw8fjq.js";
11
+ import"./index-8c3a7m4g.js";
12
+ import"./index-zyvby92n.js";
14
13
  import"./index-vsbzgd7b.js";
15
14
  import"./index-f9mb610r.js";
16
- import"./index-r159gjwy.js";
17
- import"./index-cby4ar3v.js";
18
- import"./index-7zbps32p.js";
19
15
  import"./index-7evdsyez.js";
20
16
  import"./index-2bxcmqkb.js";
21
17
  import"./index-6k1937bx.js";
22
18
  import"./index-0w9abg87.js";
23
19
  import"./index-zcgf3gqf.js";
20
+ import"./index-7zbps32p.js";
24
21
  import"./index-kzfs85xp.js";
22
+ import"./index-kc6h6hg0.js";
23
+ import"./index-r159gjwy.js";
24
+ import"./index-cby4ar3v.js";
25
25
  import"./index-77fekveh.js";
26
26
  export {
27
27
  pollUntilDone,
@@ -0,0 +1,214 @@
1
+ import {
2
+ LiveStatePhaseSchema,
3
+ LiveStateStopReasonSchema
4
+ } from "./index-ywd0y6m1.js";
5
+ import {
6
+ stableValue
7
+ } from "./index-a916km3r.js";
8
+
9
+ // src/live/watch-delta.ts
10
+ import { z } from "zod";
11
+ var WatchDeltaSchema = z.lazy(() => z.union([
12
+ z.object({ t: z.literal("set"), v: z.unknown() }),
13
+ z.object({
14
+ t: z.literal("obj"),
15
+ set: z.record(z.string(), WatchDeltaSchema).optional(),
16
+ drop: z.array(z.string()).optional()
17
+ }),
18
+ z.object({ t: z.literal("arr"), ops: z.array(WatchArrayOpSchema) })
19
+ ]));
20
+ var WatchArrayOpSchema = z.lazy(() => z.union([
21
+ z.object({
22
+ o: z.literal("copy"),
23
+ from: z.number().int().nonnegative(),
24
+ count: z.number().int().positive()
25
+ }),
26
+ z.object({
27
+ o: z.literal("patch"),
28
+ from: z.number().int().nonnegative(),
29
+ d: WatchDeltaSchema
30
+ }),
31
+ z.object({ o: z.literal("put"), v: z.unknown() })
32
+ ]));
33
+ function isRecord(value) {
34
+ return typeof value === "object" && value !== null && !Array.isArray(value);
35
+ }
36
+ function signature(value) {
37
+ return JSON.stringify(stableValue(value)) ?? "undefined";
38
+ }
39
+ function diff(previous, next) {
40
+ if (signature(previous) === signature(next))
41
+ return;
42
+ if (isRecord(previous) && isRecord(next))
43
+ return objectDiff(previous, next);
44
+ if (Array.isArray(previous) && Array.isArray(next))
45
+ return arrayDiff(previous, next);
46
+ return { t: "set", v: next };
47
+ }
48
+ function objectDiff(previous, next) {
49
+ const set = {};
50
+ const drop = [];
51
+ for (const key of Object.keys(next)) {
52
+ if (!Object.hasOwn(previous, key)) {
53
+ set[key] = { t: "set", v: next[key] };
54
+ continue;
55
+ }
56
+ const nested = diff(previous[key], next[key]);
57
+ if (nested !== undefined)
58
+ set[key] = nested;
59
+ }
60
+ for (const key of Object.keys(previous)) {
61
+ if (!Object.hasOwn(next, key))
62
+ drop.push(key);
63
+ }
64
+ return {
65
+ t: "obj",
66
+ ...Object.keys(set).length > 0 && { set },
67
+ ...drop.length > 0 && { drop }
68
+ };
69
+ }
70
+ function arrayDiff(previous, next) {
71
+ const previousSignatures = previous.map(signature);
72
+ const positions = new Map;
73
+ previousSignatures.forEach((value, index) => {
74
+ const bucket = positions.get(value);
75
+ if (bucket)
76
+ bucket.push(index);
77
+ else
78
+ positions.set(value, [index]);
79
+ });
80
+ const taken = new Set;
81
+ const ops = [];
82
+ let cursor = 0;
83
+ const extend = (from) => {
84
+ const last = ops.at(-1);
85
+ if (last?.o !== "copy" || last.from + last.count !== from)
86
+ return false;
87
+ ops[ops.length - 1] = { o: "copy", from: last.from, count: last.count + 1 };
88
+ return true;
89
+ };
90
+ for (const element of next) {
91
+ const wanted = signature(element);
92
+ const last = ops.at(-1);
93
+ const continuation = last?.o === "copy" ? last.from + last.count : undefined;
94
+ if (continuation !== undefined && continuation < previous.length && previousSignatures[continuation] === wanted && !taken.has(continuation)) {
95
+ taken.add(continuation);
96
+ extend(continuation);
97
+ cursor = continuation + 1;
98
+ continue;
99
+ }
100
+ const bucket = positions.get(wanted);
101
+ const found = bucket?.find((index) => !taken.has(index));
102
+ if (found !== undefined) {
103
+ taken.add(found);
104
+ if (!extend(found))
105
+ ops.push({ o: "copy", from: found, count: 1 });
106
+ cursor = found + 1;
107
+ continue;
108
+ }
109
+ const counterpart = cursor < previous.length && !taken.has(cursor) ? cursor : undefined;
110
+ const nested = counterpart === undefined ? undefined : diff(previous[counterpart], element);
111
+ if (counterpart !== undefined && nested !== undefined) {
112
+ taken.add(counterpart);
113
+ ops.push({ o: "patch", from: counterpart, d: nested });
114
+ cursor = counterpart + 1;
115
+ continue;
116
+ }
117
+ ops.push({ o: "put", v: element });
118
+ }
119
+ return { t: "arr", ops };
120
+ }
121
+ function apply(previous, delta) {
122
+ if (delta.t === "set")
123
+ return delta.v;
124
+ if (delta.t === "obj") {
125
+ if (!isRecord(previous))
126
+ throw new Error("an object difference needs an object to apply to");
127
+ const result2 = { ...previous };
128
+ for (const key of delta.drop ?? [])
129
+ delete result2[key];
130
+ for (const [key, nested] of Object.entries(delta.set ?? {})) {
131
+ result2[key] = apply(Object.hasOwn(result2, key) ? result2[key] : undefined, nested);
132
+ }
133
+ return result2;
134
+ }
135
+ if (!Array.isArray(previous))
136
+ throw new Error("an array difference needs an array to apply to");
137
+ const result = [];
138
+ for (const op of delta.ops) {
139
+ if (op.o === "put") {
140
+ result.push(op.v);
141
+ continue;
142
+ }
143
+ if (op.from >= previous.length) {
144
+ throw new Error(`the difference reads element ${op.from} of an array of ${previous.length}`);
145
+ }
146
+ if (op.o === "patch") {
147
+ result.push(apply(previous[op.from], op.d));
148
+ continue;
149
+ }
150
+ if (op.from + op.count > previous.length) {
151
+ throw new Error(`the difference copies ${op.count} from ${op.from} of an array of ${previous.length}`);
152
+ }
153
+ result.push(...previous.slice(op.from, op.from + op.count));
154
+ }
155
+ return result;
156
+ }
157
+ function deltaWins(delta, value) {
158
+ return JSON.stringify(delta).length < (JSON.stringify(value) ?? "null").length;
159
+ }
160
+
161
+ // src/live/watch-contract.ts
162
+ import { z as z2 } from "zod";
163
+ var WatchKeySchema = z2.object({
164
+ service: z2.string().min(1),
165
+ action: z2.string().min(1),
166
+ digest: z2.string().min(1)
167
+ }).strict().readonly();
168
+ var WatchHaveSchema = z2.object({ revision: z2.number().int().nonnegative(), fingerprint: z2.string().min(1) }).strict().readonly();
169
+ var WatchOpenSchema = z2.object({ key: WatchKeySchema, args: z2.unknown(), have: WatchHaveSchema.optional() }).readonly();
170
+ var WatchAcceptedSchema = z2.object({
171
+ accepted: z2.boolean(),
172
+ reason: z2.string().optional()
173
+ }).strict().readonly();
174
+ var watchValueParts = {
175
+ key: WatchKeySchema,
176
+ revision: z2.number().int().nonnegative(),
177
+ fingerprint: z2.string().min(1)
178
+ };
179
+ var WatchValueSchema = z2.discriminatedUnion("kind", [
180
+ z2.object({ kind: z2.literal("full"), ...watchValueParts, value: z2.unknown() }).readonly(),
181
+ z2.object({
182
+ kind: z2.literal("delta"),
183
+ ...watchValueParts,
184
+ base: z2.number().int().nonnegative(),
185
+ delta: WatchDeltaSchema
186
+ }).readonly(),
187
+ z2.object({ kind: z2.literal("unchanged"), ...watchValueParts }).readonly()
188
+ ]);
189
+ var WatchStateSchema = z2.object({
190
+ key: WatchKeySchema,
191
+ phase: LiveStatePhaseSchema,
192
+ reason: LiveStateStopReasonSchema.optional(),
193
+ code: z2.string().optional(),
194
+ message: z2.string().optional()
195
+ }).readonly();
196
+ var WATCH_OPEN = "stitchkit.watch.open";
197
+ var WATCH_CLOSE = "stitchkit.watch.close";
198
+ var WATCH_VALUE = "stitchkit.watch.value";
199
+ var WATCH_STATE = "stitchkit.watch.state";
200
+ var watchContract = {
201
+ serverToClient: {
202
+ [WATCH_VALUE]: { args: z2.tuple([WatchValueSchema]) },
203
+ [WATCH_STATE]: { args: z2.tuple([WatchStateSchema]) }
204
+ },
205
+ clientToServer: {
206
+ [WATCH_OPEN]: { args: z2.tuple([WatchOpenSchema]), ack: WatchAcceptedSchema },
207
+ [WATCH_CLOSE]: { args: z2.tuple([z2.object({ key: WatchKeySchema }).readonly()]) }
208
+ }
209
+ };
210
+ function watchKeyString(key) {
211
+ return `${key.service}/${key.action}/${key.digest}`;
212
+ }
213
+
214
+ export { WatchDeltaSchema, WatchArrayOpSchema, diff, apply, deltaWins, WatchKeySchema, WatchHaveSchema, WatchValueSchema, WatchStateSchema, WATCH_OPEN, WATCH_CLOSE, WATCH_VALUE, WATCH_STATE, watchContract, watchKeyString };
@@ -1,9 +1,9 @@
1
+ import {
2
+ contractToolMountable
3
+ } from "./index-8c3a7m4g.js";
1
4
  import {
2
5
  runtimeToolMountable
3
6
  } from "./index-kc6h6hg0.js";
4
- import {
5
- contractToolMountable
6
- } from "./index-0vfdh685.js";
7
7
  import {
8
8
  projectToolSurface
9
9
  } from "./index-r159gjwy.js";
@@ -3,33 +3,33 @@ import {
3
3
  } from "./index-sbdmyz75.js";
4
4
  import {
5
5
  collectToolSurface
6
- } from "./index-rcgsnrr6.js";
6
+ } from "./index-31jw8fjq.js";
7
7
  import {
8
8
  createToolRunner,
9
9
  formatToolError
10
- } from "./index-0vfdh685.js";
10
+ } from "./index-8c3a7m4g.js";
11
11
  import {
12
12
  toolResultFromError
13
- } from "./index-wn9cb82y.js";
14
- import {
15
- assertUniqueToolName,
16
- buildToolPresentationSchema,
17
- objectShapeKeys
18
- } from "./index-r159gjwy.js";
19
- import {
20
- jsonSchemaFields
21
- } from "./index-cby4ar3v.js";
22
- import {
23
- coerceJsonArgs
24
- } from "./index-7zbps32p.js";
13
+ } from "./index-zyvby92n.js";
25
14
  import {
26
15
  formatZodError,
27
16
  validateDeclaredOutput
28
17
  } from "./index-7evdsyez.js";
18
+ import {
19
+ coerceJsonArgs
20
+ } from "./index-7zbps32p.js";
29
21
  import {
30
22
  isUnsafeKey,
31
23
  safeJsonParse
32
24
  } from "./index-kzfs85xp.js";
25
+ import {
26
+ assertUniqueToolName,
27
+ buildToolPresentationSchema,
28
+ objectShapeKeys
29
+ } from "./index-r159gjwy.js";
30
+ import {
31
+ jsonSchemaFields
32
+ } from "./index-cby4ar3v.js";
33
33
  import {
34
34
  isRecord
35
35
  } from "./index-77fekveh.js";
@@ -18,4 +18,17 @@ function isAgentToolError(value) {
18
18
  return typeof value === "object" && value !== null && AGENT_TOOL_ERROR_BRAND in value;
19
19
  }
20
20
 
21
- export { AgentToolError, isAgentToolError };
21
+ // src/tools/durability-context.ts
22
+ var contexts = new WeakMap;
23
+ function createToolDurabilityContext(factory) {
24
+ const context = {};
25
+ contexts.set(context, factory);
26
+ return context;
27
+ }
28
+ function resolveToolDurability(context, callId, signal) {
29
+ if (typeof context !== "object" || context === null)
30
+ return;
31
+ return contexts.get(context)?.(callId, signal);
32
+ }
33
+
34
+ export { AgentToolError, isAgentToolError, createToolDurabilityContext, resolveToolDurability };
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  executeToolMethod
3
- } from "./index-wn9cb82y.js";
3
+ } from "./index-zyvby92n.js";
4
4
  import {
5
5
  assertToolExtensionCompatible,
6
6
  mergeSchemas,
@@ -21,6 +21,9 @@ import {
21
21
  import { createRequire } from "node:module";
22
22
  import path from "node:path";
23
23
  import { fileURLToPath } from "node:url";
24
+ function containedEntryKind(entry) {
25
+ return entry.isDirectory() ? "directory" : entry.isSymbolicLink() ? "symlink" : entry.isFile() ? "file" : "other";
26
+ }
24
27
  var FILE_TYPE_MASK = 61440;
25
28
  var FILE_TYPE_DIRECTORY = 16384;
26
29
  var FILE_TYPE_REGULAR = 32768;
@@ -174,14 +177,18 @@ async function listContainedDirectory(root, relative, maxEntries, authorizePath)
174
177
  const raw = [...await listAt(current)];
175
178
  raw.sort((left, right) => left.name.localeCompare(right.name));
176
179
  const admitted = [];
180
+ const denied = [];
177
181
  for (const entry of raw) {
178
182
  const entryPath = relative === "." ? entry.name : path.join(relative, entry.name);
179
- if (!authorizePath || await authorizePath(entryPath))
180
- admitted.push(entry);
183
+ if (authorizePath && !await authorizePath(entryPath)) {
184
+ denied.push({ name: entry.name, kind: containedEntryKind(entry) });
185
+ continue;
186
+ }
187
+ admitted.push(entry);
181
188
  }
182
189
  const entries = [];
183
190
  for (const entry of admitted.slice(0, maxEntries)) {
184
- const kind = entry.isDirectory() ? "directory" : entry.isSymbolicLink() ? "symlink" : entry.isFile() ? "file" : "other";
191
+ const kind = containedEntryKind(entry);
185
192
  if (kind !== "file") {
186
193
  entries.push({ name: entry.name, kind });
187
194
  continue;
@@ -198,7 +205,12 @@ async function listContainedDirectory(root, relative, maxEntries, authorizePath)
198
205
  return left.name.localeCompare(right.name);
199
206
  return left.kind === "directory" ? -1 : right.kind === "directory" ? 1 : 0;
200
207
  });
201
- return { entries, truncated: admitted.length > maxEntries };
208
+ return {
209
+ entries,
210
+ truncated: admitted.length > maxEntries,
211
+ denied: denied.slice(0, maxEntries),
212
+ deniedTruncated: denied.length > maxEntries
213
+ };
202
214
  } finally {
203
215
  await current.close();
204
216
  }
@@ -424,6 +436,8 @@ async function scanContainedFiles(input) {
424
436
  let truncated = false;
425
437
  let skippedDirectories = 0;
426
438
  let skippedSymlinks = 0;
439
+ const denied = [];
440
+ let deniedTruncated = false;
427
441
  const root = await openPinnedDirectory(input.root);
428
442
  const visit = async (directory, relativeDirectory, depth) => {
429
443
  if (truncated)
@@ -437,8 +451,15 @@ async function scanContainedFiles(input) {
437
451
  for (const entry of entries) {
438
452
  const relative = relativeDirectory ? path.join(relativeDirectory, entry.name) : entry.name;
439
453
  const kind = entry.isDirectory() ? "directory" : entry.isSymbolicLink() ? "symlink" : entry.isFile() ? "file" : "other";
440
- if (input.authorizePath && !await input.authorizePath(relative, kind))
454
+ if (kind === "file" && input.includeFile && !input.includeFile(relative))
455
+ continue;
456
+ if (input.authorizePath && !await input.authorizePath(relative, kind)) {
457
+ if (denied.length < input.maxFiles)
458
+ denied.push({ relative, kind });
459
+ else
460
+ deniedTruncated = true;
441
461
  continue;
462
+ }
442
463
  if (entry.isSymbolicLink()) {
443
464
  if (input.symlinks === "refuse") {
444
465
  throw new Error(`Contained file traversal refuses symlink: ${relative}`);
@@ -497,7 +518,7 @@ async function scanContainedFiles(input) {
497
518
  } finally {
498
519
  await root.close();
499
520
  }
500
- return { files, truncated, skippedDirectories, skippedSymlinks };
521
+ return { files, truncated, skippedDirectories, skippedSymlinks, denied, deniedTruncated };
501
522
  }
502
523
 
503
524
  export { listContainedDirectory, missingContainedDirectories, openContainedParent, openContainedFile, assertContainedFileCurrent, assertContainedParentCurrent, writeContainedFile, containedEntryMetadata, openContainedParentFile, readContainedUtf8Handle, walkContainedFiles, scanContainedFiles };