@graphrefly/graphrefly 0.15.0 → 0.17.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 (75) hide show
  1. package/dist/{chunk-4APC3AFN.js → chunk-2PORF4RP.js} +22 -49
  2. package/dist/chunk-2PORF4RP.js.map +1 -0
  3. package/dist/{chunk-QVYZD65U.js → chunk-646OG3PO.js} +10 -38
  4. package/dist/chunk-646OG3PO.js.map +1 -0
  5. package/dist/{chunk-H243FWYP.js → chunk-BV3TPSBK.js} +1 -2
  6. package/dist/chunk-BV3TPSBK.js.map +1 -0
  7. package/dist/chunk-EBNKJULL.js +231 -0
  8. package/dist/chunk-EBNKJULL.js.map +1 -0
  9. package/dist/{chunk-XQ4UMAU7.js → chunk-F2ULI3Q3.js} +2 -2
  10. package/dist/{chunk-CRACCCJY.js → chunk-IHJHBADD.js} +29 -5
  11. package/dist/chunk-IHJHBADD.js.map +1 -0
  12. package/dist/{chunk-YW6LFCFS.js → chunk-R6OHUUYB.js} +3 -3
  13. package/dist/{chunk-2ZICUAUJ.js → chunk-XJ6EMQ22.js} +10 -12
  14. package/dist/chunk-XJ6EMQ22.js.map +1 -0
  15. package/dist/{chunk-GKRKDYNT.js → chunk-YXROQFXZ.js} +3 -3
  16. package/dist/compat/nestjs/index.cjs +38 -42
  17. package/dist/compat/nestjs/index.cjs.map +1 -1
  18. package/dist/compat/nestjs/index.d.cts +4 -4
  19. package/dist/compat/nestjs/index.d.ts +4 -4
  20. package/dist/compat/nestjs/index.js +7 -7
  21. package/dist/core/index.cjs +0 -1
  22. package/dist/core/index.cjs.map +1 -1
  23. package/dist/core/index.d.cts +2 -2
  24. package/dist/core/index.d.ts +2 -2
  25. package/dist/core/index.js +3 -3
  26. package/dist/extra/index.cjs +27 -79
  27. package/dist/extra/index.cjs.map +1 -1
  28. package/dist/extra/index.d.cts +4 -4
  29. package/dist/extra/index.d.ts +4 -4
  30. package/dist/extra/index.js +3 -3
  31. package/dist/graph/index.cjs +151 -5
  32. package/dist/graph/index.cjs.map +1 -1
  33. package/dist/graph/index.d.cts +3 -3
  34. package/dist/graph/index.d.ts +3 -3
  35. package/dist/graph/index.js +10 -6
  36. package/dist/{graph-BXIK5Dq5.d.ts → graph-Dc-P9BVm.d.ts} +15 -3
  37. package/dist/{graph-BhADtuFU.d.cts → graph-fCsaaVIa.d.cts} +15 -3
  38. package/dist/{index-BkToATim.d.ts → index-4OIX-q0C.d.cts} +88 -3
  39. package/dist/{index-DSp5R3Xq.d.ts → index-BBVBYPxr.d.cts} +4 -4
  40. package/dist/{index-BNB0KjKe.d.ts → index-BmoUvOGN.d.ts} +1 -1
  41. package/dist/{index-DBhLjWSV.d.cts → index-ClaKZFPl.d.cts} +100 -31
  42. package/dist/{index-Wa8jXne6.d.cts → index-D7y9Q8W4.d.ts} +88 -3
  43. package/dist/{index-Dqemj9q0.d.cts → index-DWq0P9T6.d.ts} +4 -4
  44. package/dist/{index-fYObbpUw.d.ts → index-DhXznWyH.d.ts} +2 -2
  45. package/dist/{index-DANO9Gg7.d.cts → index-DlGMf_Qe.d.cts} +2 -2
  46. package/dist/{index-CKyYg4IP.d.ts → index-N704txAA.d.ts} +100 -31
  47. package/dist/{index-DKIyo4Bq.d.cts → index-YlOH1Gw6.d.cts} +1 -1
  48. package/dist/index.cjs +302 -231
  49. package/dist/index.cjs.map +1 -1
  50. package/dist/index.d.cts +71 -41
  51. package/dist/index.d.ts +71 -41
  52. package/dist/index.js +131 -151
  53. package/dist/index.js.map +1 -1
  54. package/dist/{meta-CrZUQAJ6.d.cts → meta-BV4pj9ML.d.cts} +6 -0
  55. package/dist/{meta-CrZUQAJ6.d.ts → meta-BV4pj9ML.d.ts} +6 -0
  56. package/dist/observable-Cz-AWhwR.d.cts +42 -0
  57. package/dist/observable-DCqlwGyl.d.ts +42 -0
  58. package/dist/patterns/reactive-layout/index.cjs +26 -3
  59. package/dist/patterns/reactive-layout/index.cjs.map +1 -1
  60. package/dist/patterns/reactive-layout/index.d.cts +3 -3
  61. package/dist/patterns/reactive-layout/index.d.ts +3 -3
  62. package/dist/patterns/reactive-layout/index.js +4 -4
  63. package/package.json +1 -1
  64. package/dist/chunk-2ZICUAUJ.js.map +0 -1
  65. package/dist/chunk-4APC3AFN.js.map +0 -1
  66. package/dist/chunk-CRACCCJY.js.map +0 -1
  67. package/dist/chunk-H243FWYP.js.map +0 -1
  68. package/dist/chunk-QVYZD65U.js.map +0 -1
  69. package/dist/chunk-ZHTHUX5D.js +0 -107
  70. package/dist/chunk-ZHTHUX5D.js.map +0 -1
  71. package/dist/reactive-log-ChbpUrY2.d.cts +0 -137
  72. package/dist/reactive-log-DV--7BWd.d.ts +0 -137
  73. /package/dist/{chunk-XQ4UMAU7.js.map → chunk-F2ULI3Q3.js.map} +0 -0
  74. /package/dist/{chunk-YW6LFCFS.js.map → chunk-R6OHUUYB.js.map} +0 -0
  75. /package/dist/{chunk-GKRKDYNT.js.map → chunk-YXROQFXZ.js.map} +0 -0
package/dist/index.js CHANGED
@@ -137,24 +137,26 @@ import {
137
137
  workerBridge,
138
138
  workerSelf,
139
139
  zip
140
- } from "./chunk-4APC3AFN.js";
140
+ } from "./chunk-2PORF4RP.js";
141
141
  import {
142
142
  cqrs_exports,
143
143
  nestjs_exports
144
- } from "./chunk-2ZICUAUJ.js";
144
+ } from "./chunk-XJ6EMQ22.js";
145
145
  import {
146
146
  JsonCodec,
147
147
  createDagCborCodec,
148
148
  createDagCborZstdCodec,
149
+ graphProfile,
149
150
  graph_exports,
150
151
  negotiateCodec,
151
- replayWAL
152
- } from "./chunk-ZHTHUX5D.js";
152
+ replayWAL,
153
+ sizeof
154
+ } from "./chunk-EBNKJULL.js";
153
155
  import {
154
156
  DEFAULT_DOWN,
155
157
  bridge,
156
158
  core_exports
157
- } from "./chunk-YW6LFCFS.js";
159
+ } from "./chunk-R6OHUUYB.js";
158
160
  import {
159
161
  cached,
160
162
  createWatermarkController,
@@ -187,7 +189,7 @@ import {
187
189
  toArray,
188
190
  toMessages$,
189
191
  toObservable
190
- } from "./chunk-QVYZD65U.js";
192
+ } from "./chunk-646OG3PO.js";
191
193
  import {
192
194
  ResettableTimer
193
195
  } from "./chunk-WZ2Z2CRV.js";
@@ -195,17 +197,17 @@ import {
195
197
  analyzeAndMeasure,
196
198
  computeLineBreaks,
197
199
  reactive_layout_exports
198
- } from "./chunk-GKRKDYNT.js";
200
+ } from "./chunk-YXROQFXZ.js";
199
201
  import {
200
202
  GRAPH_META_SEGMENT,
201
203
  Graph,
202
204
  reachable
203
- } from "./chunk-CRACCCJY.js";
205
+ } from "./chunk-IHJHBADD.js";
204
206
  import {
205
207
  describeNode,
206
208
  metaSnapshot,
207
209
  resolveDescribeFields
208
- } from "./chunk-XQ4UMAU7.js";
210
+ } from "./chunk-F2ULI3Q3.js";
209
211
  import {
210
212
  CLEANUP_RESULT,
211
213
  COMPLETE,
@@ -249,7 +251,7 @@ import {
249
251
  propagatesToMeta,
250
252
  state,
251
253
  wallClockNs
252
- } from "./chunk-H243FWYP.js";
254
+ } from "./chunk-BV3TPSBK.js";
253
255
 
254
256
  // src/compat/index.ts
255
257
  var compat_exports = {};
@@ -1489,36 +1491,33 @@ function firstDataFromNode(resolved, opts) {
1489
1491
  }
1490
1492
  const timeoutMs = opts?.timeoutMs ?? DEFAULT_TIMEOUT_MS;
1491
1493
  return new Promise((resolve, reject) => {
1492
- let timer;
1493
- const cleanup = () => {
1494
- if (timer !== void 0) clearTimeout(timer);
1495
- };
1494
+ const timer = new ResettableTimer();
1496
1495
  const unsub = resolved.subscribe((messages) => {
1497
1496
  for (const msg of messages) {
1498
1497
  if (msg[0] === DATA) {
1499
- cleanup();
1498
+ timer.cancel();
1500
1499
  unsub();
1501
1500
  resolve(msg[1]);
1502
1501
  return;
1503
1502
  }
1504
1503
  if (msg[0] === ERROR) {
1505
- cleanup();
1504
+ timer.cancel();
1506
1505
  unsub();
1507
1506
  reject(msg[1]);
1508
1507
  return;
1509
1508
  }
1510
1509
  if (msg[0] === COMPLETE) {
1511
- cleanup();
1510
+ timer.cancel();
1512
1511
  unsub();
1513
1512
  reject(new Error("firstDataFromNode: completed without producing a value"));
1514
1513
  return;
1515
1514
  }
1516
1515
  }
1517
1516
  });
1518
- timer = setTimeout(() => {
1517
+ timer.start(timeoutMs, () => {
1519
1518
  unsub();
1520
1519
  reject(new Error(`firstDataFromNode: timed out after ${timeoutMs}ms`));
1521
- }, timeoutMs);
1520
+ });
1522
1521
  });
1523
1522
  }
1524
1523
  async function resolveToolHandlerResult(value) {
@@ -1665,7 +1664,6 @@ function promptNode(adapter, deps, prompt, opts) {
1665
1664
  }
1666
1665
  var ChatStreamGraph = class extends Graph {
1667
1666
  _log;
1668
- _keepaliveSubs = [];
1669
1667
  messages;
1670
1668
  latest;
1671
1669
  messageCount;
@@ -1680,7 +1678,7 @@ var ChatStreamGraph = class extends Graph {
1680
1678
  this.latest = derived(
1681
1679
  [this.messages],
1682
1680
  ([snapshot]) => {
1683
- const entries = snapshot.value.entries;
1681
+ const entries = snapshot;
1684
1682
  return entries.length === 0 ? void 0 : entries[entries.length - 1];
1685
1683
  },
1686
1684
  {
@@ -1692,10 +1690,10 @@ var ChatStreamGraph = class extends Graph {
1692
1690
  );
1693
1691
  this.add("latest", this.latest);
1694
1692
  this.connect("messages", "latest");
1695
- this._keepaliveSubs.push(keepalive(this.latest));
1693
+ this.addDisposer(keepalive(this.latest));
1696
1694
  this.messageCount = derived(
1697
1695
  [this.messages],
1698
- ([snapshot]) => snapshot.value.entries.length,
1696
+ ([snapshot]) => snapshot.length,
1699
1697
  {
1700
1698
  name: "messageCount",
1701
1699
  describeKind: "derived",
@@ -1705,7 +1703,7 @@ var ChatStreamGraph = class extends Graph {
1705
1703
  );
1706
1704
  this.add("messageCount", this.messageCount);
1707
1705
  this.connect("messages", "messageCount");
1708
- this._keepaliveSubs.push(keepalive(this.messageCount));
1706
+ this.addDisposer(keepalive(this.messageCount));
1709
1707
  }
1710
1708
  append(role, content, extra) {
1711
1709
  this._log.append({ role, content, ...extra });
@@ -1717,12 +1715,7 @@ var ChatStreamGraph = class extends Graph {
1717
1715
  this._log.clear();
1718
1716
  }
1719
1717
  allMessages() {
1720
- return this.messages.get().value.entries;
1721
- }
1722
- destroy() {
1723
- for (const unsub of this._keepaliveSubs) unsub();
1724
- this._keepaliveSubs.length = 0;
1725
- super.destroy();
1718
+ return this.messages.get();
1726
1719
  }
1727
1720
  };
1728
1721
  function chatStream(name, opts) {
@@ -1731,7 +1724,6 @@ function chatStream(name, opts) {
1731
1724
  var ToolRegistryGraph = class extends Graph {
1732
1725
  definitions;
1733
1726
  schemas;
1734
- _keepaliveSubs = [];
1735
1727
  constructor(name, opts = {}) {
1736
1728
  super(name, opts.graph);
1737
1729
  this.definitions = state(/* @__PURE__ */ new Map(), {
@@ -1752,7 +1744,7 @@ var ToolRegistryGraph = class extends Graph {
1752
1744
  );
1753
1745
  this.add("schemas", this.schemas);
1754
1746
  this.connect("definitions", "schemas");
1755
- this._keepaliveSubs.push(keepalive(this.schemas));
1747
+ this.addDisposer(keepalive(this.schemas));
1756
1748
  }
1757
1749
  register(tool) {
1758
1750
  const current = this.definitions.get();
@@ -1777,11 +1769,6 @@ var ToolRegistryGraph = class extends Graph {
1777
1769
  getDefinition(name) {
1778
1770
  return this.definitions.get().get(name);
1779
1771
  }
1780
- destroy() {
1781
- for (const unsub of this._keepaliveSubs) unsub();
1782
- this._keepaliveSubs.length = 0;
1783
- super.destroy();
1784
- }
1785
1772
  };
1786
1773
  function toolRegistry(name, opts) {
1787
1774
  return new ToolRegistryGraph(name, opts);
@@ -1926,9 +1913,7 @@ function admissionFilter3D(opts = {}) {
1926
1913
  }
1927
1914
  var DEFAULT_DECAY_RATE = Math.LN2 / (7 * 86400);
1928
1915
  function extractStoreMap(snapshot) {
1929
- if (snapshot && typeof snapshot === "object" && "value" in snapshot && typeof snapshot.value === "object" && snapshot.value !== null && "map" in snapshot.value) {
1930
- return snapshot.value.map ?? /* @__PURE__ */ new Map();
1931
- }
1916
+ if (snapshot instanceof Map) return snapshot;
1932
1917
  return /* @__PURE__ */ new Map();
1933
1918
  }
1934
1919
  function agentMemory(name, source, opts) {
@@ -1979,7 +1964,7 @@ function agentMemory(name, source, opts) {
1979
1964
  consolidateTrigger
1980
1965
  };
1981
1966
  const distillBundle = distill(filteredSource, extractFn, distillOpts);
1982
- graph.add("store", distillBundle.store.node);
1967
+ graph.add("store", distillBundle.store.entries);
1983
1968
  graph.add("compact", distillBundle.compact);
1984
1969
  graph.add("size", distillBundle.size);
1985
1970
  graph.connect("store", "compact");
@@ -2006,7 +1991,7 @@ function agentMemory(name, source, opts) {
2006
1991
  const permanentKeys = /* @__PURE__ */ new Set();
2007
1992
  const tierOf = (key) => {
2008
1993
  if (permanentKeys.has(key)) return "permanent";
2009
- const storeMap = extractStoreMap(distillBundle.store.node.get());
1994
+ const storeMap = extractStoreMap(distillBundle.store.entries.get());
2010
1995
  if (storeMap.has(key)) return "active";
2011
1996
  return "archived";
2012
1997
  };
@@ -2015,7 +2000,7 @@ function agentMemory(name, source, opts) {
2015
2000
  permanent.upsert(key, value);
2016
2001
  };
2017
2002
  const entryCreatedAtNs = /* @__PURE__ */ new Map();
2018
- const storeNode = distillBundle.store.node;
2003
+ const storeNode = distillBundle.store.entries;
2019
2004
  const contextNode = opts.context ? fromAny(opts.context) : state(null);
2020
2005
  const tierClassifier = effect([storeNode, contextNode], ([snapshot, ctx]) => {
2021
2006
  const storeMap = extractStoreMap(snapshot);
@@ -2082,7 +2067,7 @@ function agentMemory(name, source, opts) {
2082
2067
  if (vectors || kg) {
2083
2068
  const embedFn = opts.embedFn;
2084
2069
  const entityFn = opts.entityFn;
2085
- const storeNode = distillBundle.store.node;
2070
+ const storeNode = distillBundle.store.entries;
2086
2071
  const indexer = effect([storeNode], ([snapshot]) => {
2087
2072
  const storeMap = extractStoreMap(snapshot);
2088
2073
  for (const [key, mem] of storeMap) {
@@ -2127,7 +2112,7 @@ function agentMemory(name, source, opts) {
2127
2112
  });
2128
2113
  graph.add("retrievalTrace", traceState);
2129
2114
  retrievalTraceNode = traceState;
2130
- const storeNode = distillBundle.store.node;
2115
+ const storeNode = distillBundle.store.entries;
2131
2116
  let lastTrace = null;
2132
2117
  const retrievalDerived = derived(
2133
2118
  [queryInput, storeNode, contextNode],
@@ -2220,12 +2205,10 @@ function agentMemory(name, source, opts) {
2220
2205
  return result;
2221
2206
  };
2222
2207
  }
2223
- const origDestroy = graph.destroy.bind(graph);
2224
- graph.destroy = () => {
2208
+ graph.addDisposer(() => {
2225
2209
  for (const unsub of keepaliveSubs) unsub();
2226
2210
  keepaliveSubs.length = 0;
2227
- origDestroy();
2228
- };
2211
+ });
2229
2212
  return Object.assign(graph, {
2230
2213
  distillBundle,
2231
2214
  compact: distillBundle.compact,
@@ -3268,7 +3251,7 @@ function funnel(name, sources, stages, opts) {
3268
3251
  });
3269
3252
  g.add(bridgeName, br);
3270
3253
  g.connect(prevOutputPath, bridgeName);
3271
- keepalive2(br);
3254
+ g.addDisposer(keepalive2(br));
3272
3255
  prevOutputPath = `${stage.name}::output`;
3273
3256
  }
3274
3257
  return g;
@@ -3320,7 +3303,7 @@ function feedback(graph, condition, reentry, opts) {
3320
3303
  });
3321
3304
  graph.add(feedbackEffectName, feedbackEffect);
3322
3305
  graph.connect(condition, feedbackEffectName);
3323
- keepalive2(feedbackEffect);
3306
+ graph.addDisposer(keepalive2(feedbackEffect));
3324
3307
  return graph;
3325
3308
  }
3326
3309
  function budgetGate(source, constraints, opts) {
@@ -3700,7 +3683,7 @@ function contentModerationGraph(name, opts) {
3700
3683
  }
3701
3684
  });
3702
3685
  g.add("__review_accumulator", reviewAccumulator);
3703
- keepalive3(reviewAccumulator);
3686
+ g.addDisposer(keepalive3(reviewAccumulator));
3704
3687
  try {
3705
3688
  g.connect("stratify::branch/review", "__review_accumulator");
3706
3689
  } catch {
@@ -3748,8 +3731,7 @@ function contentModerationGraph(name, opts) {
3748
3731
  const fbCondition = derived(
3749
3732
  [reviewLog.entries, policy2],
3750
3733
  (vals) => {
3751
- const snap = vals[0];
3752
- const entries = snap?.value?.entries;
3734
+ const entries = vals[0];
3753
3735
  if (entries && entries.length > 0) {
3754
3736
  const latest = entries[entries.length - 1];
3755
3737
  if (latest && latest.falsePositive) {
@@ -4901,9 +4883,11 @@ __export(harness_exports, {
4901
4883
  DEFAULT_QUEUE_CONFIGS: () => DEFAULT_QUEUE_CONFIGS,
4902
4884
  DEFAULT_SEVERITY_WEIGHTS: () => DEFAULT_SEVERITY_WEIGHTS,
4903
4885
  HarnessGraph: () => HarnessGraph,
4886
+ QUEUE_NAMES: () => QUEUE_NAMES,
4904
4887
  defaultErrorClassifier: () => defaultErrorClassifier,
4905
4888
  evalIntakeBridge: () => evalIntakeBridge,
4906
4889
  harnessLoop: () => harnessLoop,
4890
+ harnessProfile: () => harnessProfile,
4907
4891
  priorityScore: () => priorityScore,
4908
4892
  strategyKey: () => strategyKey,
4909
4893
  strategyModel: () => strategyModel
@@ -4981,7 +4965,6 @@ function messagingMeta(kind, extra) {
4981
4965
  }
4982
4966
  var TopicGraph = class extends Graph {
4983
4967
  _log;
4984
- _keepaliveDisposers = [];
4985
4968
  events;
4986
4969
  latest;
4987
4970
  constructor(name, opts = {}) {
@@ -4992,7 +4975,7 @@ var TopicGraph = class extends Graph {
4992
4975
  this.latest = derived(
4993
4976
  [this.events],
4994
4977
  ([snapshot]) => {
4995
- const entries = snapshot.value.entries;
4978
+ const entries = snapshot;
4996
4979
  return entries.length === 0 ? void 0 : entries[entries.length - 1];
4997
4980
  },
4998
4981
  {
@@ -5004,23 +4987,16 @@ var TopicGraph = class extends Graph {
5004
4987
  );
5005
4988
  this.add("latest", this.latest);
5006
4989
  this.connect("events", "latest");
5007
- this._keepaliveDisposers.push(keepalive4(this.latest));
5008
- }
5009
- destroy() {
5010
- for (const dispose of this._keepaliveDisposers) dispose();
5011
- this._keepaliveDisposers.length = 0;
5012
- super.destroy();
4990
+ this.addDisposer(keepalive4(this.latest));
5013
4991
  }
5014
4992
  publish(value) {
5015
4993
  this._log.append(value);
5016
4994
  }
5017
4995
  retained() {
5018
- const snapshot = this.events.get();
5019
- return snapshot.value.entries;
4996
+ return this.events.get();
5020
4997
  }
5021
4998
  };
5022
4999
  var SubscriptionGraph = class extends Graph {
5023
- _keepaliveDisposers = [];
5024
5000
  source;
5025
5001
  cursor;
5026
5002
  available;
@@ -5045,7 +5021,7 @@ var SubscriptionGraph = class extends Graph {
5045
5021
  this.available = derived(
5046
5022
  [this.source, this.cursor],
5047
5023
  ([sourceSnapshot, cursor]) => {
5048
- const entries = sourceSnapshot.value.entries;
5024
+ const entries = sourceSnapshot;
5049
5025
  const start = Math.max(0, Math.trunc(cursor ?? 0));
5050
5026
  return entries.slice(start);
5051
5027
  },
@@ -5060,13 +5036,8 @@ var SubscriptionGraph = class extends Graph {
5060
5036
  this.connect("topic::events", "source");
5061
5037
  this.connect("source", "available");
5062
5038
  this.connect("cursor", "available");
5063
- this._keepaliveDisposers.push(keepalive4(this.source));
5064
- this._keepaliveDisposers.push(keepalive4(this.available));
5065
- }
5066
- destroy() {
5067
- for (const dispose of this._keepaliveDisposers) dispose();
5068
- this._keepaliveDisposers.length = 0;
5069
- super.destroy();
5039
+ this.addDisposer(keepalive4(this.source));
5040
+ this.addDisposer(keepalive4(this.available));
5070
5041
  }
5071
5042
  ack(count) {
5072
5043
  const available = this.available.get();
@@ -5088,7 +5059,6 @@ var SubscriptionGraph = class extends Graph {
5088
5059
  var JobQueueGraph = class extends Graph {
5089
5060
  _pending;
5090
5061
  _jobs;
5091
- _keepaliveDisposers = [];
5092
5062
  _seq = 0;
5093
5063
  pending;
5094
5064
  jobs;
@@ -5098,27 +5068,18 @@ var JobQueueGraph = class extends Graph {
5098
5068
  this._pending = reactiveList([], { name: "pending" });
5099
5069
  this._jobs = reactiveMap({ name: "jobs" });
5100
5070
  this.pending = this._pending.items;
5101
- this.jobs = this._jobs.node;
5071
+ this.jobs = this._jobs.entries;
5102
5072
  this.add("pending", this.pending);
5103
5073
  this.add("jobs", this.jobs);
5104
- this.depth = derived(
5105
- [this.pending],
5106
- ([snapshot]) => snapshot.value.items.length,
5107
- {
5108
- name: "depth",
5109
- describeKind: "derived",
5110
- meta: messagingMeta("queue_depth"),
5111
- initial: 0
5112
- }
5113
- );
5074
+ this.depth = derived([this.pending], ([snapshot]) => snapshot.length, {
5075
+ name: "depth",
5076
+ describeKind: "derived",
5077
+ meta: messagingMeta("queue_depth"),
5078
+ initial: 0
5079
+ });
5114
5080
  this.add("depth", this.depth);
5115
5081
  this.connect("pending", "depth");
5116
- this._keepaliveDisposers.push(keepalive4(this.depth));
5117
- }
5118
- destroy() {
5119
- for (const dispose of this._keepaliveDisposers) dispose();
5120
- this._keepaliveDisposers.length = 0;
5121
- super.destroy();
5082
+ this.addDisposer(keepalive4(this.depth));
5122
5083
  }
5123
5084
  enqueue(payload, opts = {}) {
5124
5085
  const id = opts.id ?? `${this.name}-${++this._seq}`;
@@ -5141,8 +5102,7 @@ var JobQueueGraph = class extends Graph {
5141
5102
  if (max === 0) return [];
5142
5103
  const out = [];
5143
5104
  while (out.length < max) {
5144
- const snapshot = this.pending.get();
5145
- const ids = snapshot.value.items;
5105
+ const ids = this.pending.get();
5146
5106
  if (ids.length === 0) break;
5147
5107
  const id = this._pending.pop(0);
5148
5108
  const job = this._jobs.get(id);
@@ -5178,7 +5138,6 @@ var JobQueueGraph = class extends Graph {
5178
5138
  var JobFlowGraph = class extends Graph {
5179
5139
  _stageNames;
5180
5140
  _queues = /* @__PURE__ */ new Map();
5181
- _keepaliveDisposers = [];
5182
5141
  _completed;
5183
5142
  completed;
5184
5143
  completedCount;
@@ -5203,7 +5162,7 @@ var JobFlowGraph = class extends Graph {
5203
5162
  this.add("completed", this.completed);
5204
5163
  this.completedCount = derived(
5205
5164
  [this.completed],
5206
- ([snapshot]) => snapshot.value.entries.length,
5165
+ ([snapshot]) => snapshot.length,
5207
5166
  {
5208
5167
  name: "completedCount",
5209
5168
  describeKind: "derived",
@@ -5213,7 +5172,7 @@ var JobFlowGraph = class extends Graph {
5213
5172
  );
5214
5173
  this.add("completedCount", this.completedCount);
5215
5174
  this.connect("completed", "completedCount");
5216
- this._keepaliveDisposers.push(keepalive4(this.completedCount));
5175
+ this.addDisposer(keepalive4(this.completedCount));
5217
5176
  const maxPerPump = Math.max(
5218
5177
  1,
5219
5178
  requireNonNegativeInt(opts.maxPerPump ?? DEFAULT_MAX_PER_PUMP, "job flow maxPerPump")
@@ -5253,14 +5212,9 @@ var JobFlowGraph = class extends Graph {
5253
5212
  );
5254
5213
  this.add(`pump_${stage}`, pump);
5255
5214
  this.connect(`${stage}::pending`, `pump_${stage}`);
5256
- this._keepaliveDisposers.push(keepalive4(pump));
5215
+ this.addDisposer(keepalive4(pump));
5257
5216
  }
5258
5217
  }
5259
- destroy() {
5260
- for (const dispose of this._keepaliveDisposers) dispose();
5261
- this._keepaliveDisposers.length = 0;
5262
- super.destroy();
5263
- }
5264
5218
  stages() {
5265
5219
  return this._stageNames;
5266
5220
  }
@@ -5273,14 +5227,12 @@ var JobFlowGraph = class extends Graph {
5273
5227
  return this.queue(this._stageNames[0]).enqueue(payload, opts);
5274
5228
  }
5275
5229
  retainedCompleted() {
5276
- const snapshot = this.completed.get();
5277
- return snapshot.value.entries;
5230
+ return this.completed.get();
5278
5231
  }
5279
5232
  };
5280
5233
  var TopicBridgeGraph = class extends Graph {
5281
5234
  _sourceSub;
5282
5235
  _target;
5283
- _keepaliveDisposers = [];
5284
5236
  bridgedCount;
5285
5237
  constructor(name, sourceTopic, targetTopic, opts = {}) {
5286
5238
  super(name, opts.graph);
@@ -5325,12 +5277,7 @@ var TopicBridgeGraph = class extends Graph {
5325
5277
  );
5326
5278
  this.add("pump", pump);
5327
5279
  this.connect("subscription::available", "pump");
5328
- this._keepaliveDisposers.push(keepalive4(pump));
5329
- }
5330
- destroy() {
5331
- for (const dispose of this._keepaliveDisposers) dispose();
5332
- this._keepaliveDisposers.length = 0;
5333
- super.destroy();
5280
+ this.addDisposer(keepalive4(pump));
5334
5281
  }
5335
5282
  };
5336
5283
  function topic(name, opts) {
@@ -5622,7 +5569,7 @@ function gate(graph, name, source, opts) {
5622
5569
  isOpenNode.down([[DATA, false]]);
5623
5570
  }
5624
5571
  };
5625
- countNode.subscribe(() => void 0);
5572
+ graph.addDisposer(countNode.subscribe(() => void 0));
5626
5573
  registerStep(graph, name, output, src.path ? [src.path] : []);
5627
5574
  const internal = new Graph(`${name}_state`);
5628
5575
  internal.add("pending", pendingNode);
@@ -5841,6 +5788,12 @@ function onFailure(graph, name, source, recover, opts) {
5841
5788
  }
5842
5789
 
5843
5790
  // src/patterns/harness/types.ts
5791
+ var QUEUE_NAMES = [
5792
+ "auto-fix",
5793
+ "needs-decision",
5794
+ "investigation",
5795
+ "backlog"
5796
+ ];
5844
5797
  function strategyKey(rootCause, intervention) {
5845
5798
  return `${rootCause}\u2192${intervention}`;
5846
5799
  }
@@ -5869,9 +5822,9 @@ var DEFAULT_QUEUE_CONFIGS = {
5869
5822
  function strategyModel() {
5870
5823
  const _map = reactiveMap({ name: "strategy-entries" });
5871
5824
  const snapshot = derived(
5872
- [_map.node],
5825
+ [_map.entries],
5873
5826
  ([mapSnap]) => {
5874
- const raw = mapSnap.value.map;
5827
+ const raw = mapSnap;
5875
5828
  return new Map(raw);
5876
5829
  },
5877
5830
  {
@@ -5906,7 +5859,10 @@ function strategyModel() {
5906
5859
  }
5907
5860
  const _unsub = snapshot.subscribe(() => {
5908
5861
  });
5909
- return { node: snapshot, record, lookup };
5862
+ function dispose() {
5863
+ _unsub();
5864
+ }
5865
+ return { node: snapshot, record, lookup, dispose };
5910
5866
  }
5911
5867
  function priorityScore(item, strategy, lastInteractionNs, urgency, signals) {
5912
5868
  const severityWeights = { ...DEFAULT_SEVERITY_WEIGHTS, ...signals?.severityWeights };
@@ -5938,8 +5894,8 @@ function priorityScore(item, strategy, lastInteractionNs, urgency, signals) {
5938
5894
  }
5939
5895
 
5940
5896
  // src/patterns/harness/loop.ts
5941
- function baseSummary(summary) {
5942
- return summary.replace(/^\[RETRY \d+\/\d+\]\s*/, "");
5897
+ function trackingKey(item) {
5898
+ return item.relatedTo?.[0] ?? item.summary;
5943
5899
  }
5944
5900
  var DEFAULT_TRIAGE_PROMPT = `You are a triage classifier for a reactive collaboration harness.
5945
5901
 
@@ -5985,12 +5941,6 @@ Output JSON:
5985
5941
  "findings": ["<finding1>", ...],
5986
5942
  "errorClass": "self-correctable" | "structural" // only if verified=false
5987
5943
  }`;
5988
- var QUEUE_NAMES = [
5989
- "auto-fix",
5990
- "needs-decision",
5991
- "investigation",
5992
- "backlog"
5993
- ];
5994
5944
  var HarnessGraph = class extends Graph {
5995
5945
  /** Intake topic — publish items here to enter the loop. */
5996
5946
  intake;
@@ -6002,19 +5952,19 @@ var HarnessGraph = class extends Graph {
6002
5952
  strategy;
6003
5953
  /** Verify results topic — subscribe to see verification outcomes. */
6004
5954
  verifyResults;
6005
- /** Per-item fast-retry counts (keyed by base summary). */
6006
- retryTracker;
6007
- /** Per-item reingestion counts (keyed by base summary). */
6008
- reingestionTracker;
6009
- constructor(name, intake, queues, gates, strategy, verifyResults, retryTracker, reingestionTracker) {
5955
+ /** Global retry count across all items (circuit breaker). Reactive — subscribable. */
5956
+ totalRetries;
5957
+ /** Global reingestion count across all items (circuit breaker). Reactive — subscribable. */
5958
+ totalReingestions;
5959
+ constructor(name, intake, queues, gates, strategy, verifyResults, totalRetries, totalReingestions) {
6010
5960
  super(name);
6011
5961
  this.intake = intake;
6012
5962
  this.queues = queues;
6013
5963
  this.gates = gates;
6014
5964
  this.strategy = strategy;
6015
5965
  this.verifyResults = verifyResults;
6016
- this.retryTracker = retryTracker;
6017
- this.reingestionTracker = reingestionTracker;
5966
+ this.totalRetries = totalRetries;
5967
+ this.totalReingestions = totalReingestions;
6018
5968
  }
6019
5969
  };
6020
5970
  function harnessLoop(name, opts) {
@@ -6056,13 +6006,16 @@ function harnessLoop(name, opts) {
6056
6006
  for (const route of QUEUE_NAMES) {
6057
6007
  queueTopics.set(route, new TopicGraph(`queue/${route}`, { retainedLimit }));
6058
6008
  }
6059
- const router = effect([triageNode], ([triaged]) => {
6060
- const item = triaged;
6061
- if (!item || !item.route) return;
6062
- const topic2 = queueTopics.get(item.route);
6063
- if (topic2) topic2.publish(item);
6009
+ const routerInput = withLatestFrom(triageNode, triageInput);
6010
+ const router = effect([routerInput], ([pair]) => {
6011
+ const [classification, triagePair] = pair;
6012
+ if (!classification || !classification.route) return;
6013
+ const intakeItem = triagePair?.[0];
6014
+ const merged = { ...intakeItem, ...classification };
6015
+ const topic2 = queueTopics.get(merged.route);
6016
+ if (topic2) topic2.publish(merged);
6064
6017
  });
6065
- router.subscribe(() => {
6018
+ const routerUnsub = router.subscribe(() => {
6066
6019
  });
6067
6020
  const gateGraph = new Graph("gates");
6068
6021
  const gateControllers = /* @__PURE__ */ new Map();
@@ -6120,8 +6073,10 @@ function harnessLoop(name, opts) {
6120
6073
  executeInput
6121
6074
  );
6122
6075
  const maxReingestions = opts.maxReingestions ?? 1;
6123
- const retryTracker = /* @__PURE__ */ new Map();
6124
- const reingestionTracker = /* @__PURE__ */ new Map();
6076
+ const maxTotalRetries = Math.min(opts.maxTotalRetries ?? maxRetries * 10, 100);
6077
+ const maxTotalReingestions = Math.min(opts.maxTotalReingestions ?? maxReingestions * 10, 100);
6078
+ const totalRetries = state(0);
6079
+ const totalReingestions = state(0);
6125
6080
  const fastRetry = effect([verifyContext], ([ctx]) => {
6126
6081
  const [[vo, execRaw], item] = ctx;
6127
6082
  if (!vo || !item) return;
@@ -6147,34 +6102,38 @@ function harnessLoop(name, opts) {
6147
6102
  outcome: "failure",
6148
6103
  detail: vr.findings.join("; ")
6149
6104
  });
6150
- const key = baseSummary(item.summary);
6151
- const retryCount = retryTracker.get(key) ?? 0;
6152
- if (errClass === "self-correctable" && retryCount < maxRetries) {
6153
- retryTracker.set(key, retryCount + 1);
6105
+ const itemRetries = item._retries ?? 0;
6106
+ if (errClass === "self-correctable" && itemRetries < maxRetries && (totalRetries.get() ?? 0) < maxTotalRetries) {
6107
+ totalRetries.down([[DATA, (totalRetries.get() ?? 0) + 1]]);
6108
+ const key = trackingKey(item);
6154
6109
  const retryItem = {
6155
6110
  ...item,
6156
- summary: `[RETRY ${retryCount + 1}/${maxRetries}] ${baseSummary(item.summary)} \u2014 Previous attempt failed: ${vr.findings.join("; ")}`
6111
+ _retries: itemRetries + 1,
6112
+ summary: `[RETRY ${itemRetries + 1}/${maxRetries}] ${key} \u2014 Previous attempt failed: ${vr.findings.join("; ")}`,
6113
+ relatedTo: [key]
6157
6114
  };
6158
6115
  retryTopic.publish(retryItem);
6159
6116
  } else {
6160
6117
  strategy.record(item.rootCause, item.intervention, false);
6161
6118
  verifyResults.publish(vr);
6162
- const itemReingestions = reingestionTracker.get(key) ?? 0;
6163
- if (itemReingestions < maxReingestions) {
6164
- reingestionTracker.set(key, itemReingestions + 1);
6119
+ const key = trackingKey(item);
6120
+ const itemReingestions = item._reingestions ?? 0;
6121
+ if (itemReingestions < maxReingestions && (totalReingestions.get() ?? 0) < maxTotalReingestions) {
6122
+ totalReingestions.down([[DATA, (totalReingestions.get() ?? 0) + 1]]);
6165
6123
  intake.publish({
6166
6124
  source: "eval",
6167
- summary: `Verification failed for: ${baseSummary(item.summary)}`,
6125
+ summary: `Verification failed for: ${key}`,
6168
6126
  evidence: vr.findings.join("\n"),
6169
6127
  affectsAreas: item.affectsAreas,
6170
6128
  affectsEvalTasks: item.affectsEvalTasks,
6171
6129
  severity: "high",
6172
- relatedTo: [baseSummary(item.summary)]
6130
+ relatedTo: [key],
6131
+ _reingestions: itemReingestions + 1
6173
6132
  });
6174
6133
  }
6175
6134
  }
6176
6135
  });
6177
- fastRetry.subscribe(() => {
6136
+ const fastRetryUnsub = fastRetry.subscribe(() => {
6178
6137
  });
6179
6138
  const harness = new HarnessGraph(
6180
6139
  name,
@@ -6183,9 +6142,12 @@ function harnessLoop(name, opts) {
6183
6142
  gateControllers,
6184
6143
  strategy,
6185
6144
  verifyResults,
6186
- retryTracker,
6187
- reingestionTracker
6145
+ totalRetries,
6146
+ totalReingestions
6188
6147
  );
6148
+ harness.addDisposer(routerUnsub);
6149
+ harness.addDisposer(fastRetryUnsub);
6150
+ harness.addDisposer(strategy.dispose);
6189
6151
  harness.mount("intake", intake);
6190
6152
  for (const [route, topic2] of queueTopics) {
6191
6153
  harness.mount(`queue/${route}`, topic2);
@@ -6196,6 +6158,22 @@ function harnessLoop(name, opts) {
6196
6158
  return harness;
6197
6159
  }
6198
6160
 
6161
+ // src/patterns/harness/profile.ts
6162
+ function harnessProfile(harness, opts) {
6163
+ const base = graphProfile(harness, opts);
6164
+ const queueDepths = {};
6165
+ for (const [route, topic2] of harness.queues) {
6166
+ queueDepths[route] = topic2.retained().length;
6167
+ }
6168
+ return {
6169
+ ...base,
6170
+ queueDepths,
6171
+ strategyEntries: harness.strategy.node.get()?.size ?? 0,
6172
+ totalRetries: harness.totalRetries.get() ?? 0,
6173
+ totalReingestions: harness.totalReingestions.get() ?? 0
6174
+ };
6175
+ }
6176
+
6199
6177
  // src/index.ts
6200
6178
  var version = "0.0.0";
6201
6179
  export {
@@ -6318,6 +6296,7 @@ export {
6318
6296
  fromWebhook,
6319
6297
  globToRegExp,
6320
6298
  graph_exports as graph,
6299
+ graphProfile,
6321
6300
  graphspec_exports as graphspec,
6322
6301
  harness_exports as harness,
6323
6302
  interval,
@@ -6396,6 +6375,7 @@ export {
6396
6375
  shareReplay,
6397
6376
  signalToName,
6398
6377
  signals_exports as signals,
6378
+ sizeof,
6399
6379
  skip,
6400
6380
  solid_exports as solid,
6401
6381
  startWith,