@graphrefly/graphrefly 0.16.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 (47) hide show
  1. package/dist/{chunk-RLVFZDCE.js → chunk-2PORF4RP.js} +3 -3
  2. package/dist/{chunk-YX263TXI.js → chunk-646OG3PO.js} +2 -2
  3. package/dist/{chunk-VZY2B2LU.js → chunk-BV3TPSBK.js} +1 -2
  4. package/dist/chunk-BV3TPSBK.js.map +1 -0
  5. package/dist/chunk-EBNKJULL.js +231 -0
  6. package/dist/chunk-EBNKJULL.js.map +1 -0
  7. package/dist/{chunk-ITDVOCFO.js → chunk-F2ULI3Q3.js} +2 -2
  8. package/dist/{chunk-3BLRREFM.js → chunk-IHJHBADD.js} +3 -3
  9. package/dist/{chunk-LKP7IWRV.js → chunk-R6OHUUYB.js} +3 -3
  10. package/dist/{chunk-26A4E7J7.js → chunk-XJ6EMQ22.js} +4 -4
  11. package/dist/{chunk-RZSQ7P2C.js → chunk-YXROQFXZ.js} +3 -3
  12. package/dist/compat/nestjs/index.cjs +0 -1
  13. package/dist/compat/nestjs/index.cjs.map +1 -1
  14. package/dist/compat/nestjs/index.js +7 -7
  15. package/dist/core/index.cjs +0 -1
  16. package/dist/core/index.cjs.map +1 -1
  17. package/dist/core/index.js +3 -3
  18. package/dist/extra/index.cjs +0 -1
  19. package/dist/extra/index.cjs.map +1 -1
  20. package/dist/extra/index.js +3 -3
  21. package/dist/graph/index.cjs +125 -3
  22. package/dist/graph/index.cjs.map +1 -1
  23. package/dist/graph/index.d.cts +1 -1
  24. package/dist/graph/index.d.ts +1 -1
  25. package/dist/graph/index.js +10 -6
  26. package/dist/{index-Db27z6Ki.d.cts → index-4OIX-q0C.d.cts} +88 -3
  27. package/dist/{index-BR19vQME.d.ts → index-D7y9Q8W4.d.ts} +88 -3
  28. package/dist/index.cjs +193 -45
  29. package/dist/index.cjs.map +1 -1
  30. package/dist/index.d.cts +51 -8
  31. package/dist/index.d.ts +51 -8
  32. package/dist/index.js +85 -57
  33. package/dist/index.js.map +1 -1
  34. package/dist/patterns/reactive-layout/index.cjs +0 -1
  35. package/dist/patterns/reactive-layout/index.cjs.map +1 -1
  36. package/dist/patterns/reactive-layout/index.js +4 -4
  37. package/package.json +1 -1
  38. package/dist/chunk-SHRJH2DN.js +0 -107
  39. package/dist/chunk-SHRJH2DN.js.map +0 -1
  40. package/dist/chunk-VZY2B2LU.js.map +0 -1
  41. /package/dist/{chunk-RLVFZDCE.js.map → chunk-2PORF4RP.js.map} +0 -0
  42. /package/dist/{chunk-YX263TXI.js.map → chunk-646OG3PO.js.map} +0 -0
  43. /package/dist/{chunk-ITDVOCFO.js.map → chunk-F2ULI3Q3.js.map} +0 -0
  44. /package/dist/{chunk-3BLRREFM.js.map → chunk-IHJHBADD.js.map} +0 -0
  45. /package/dist/{chunk-LKP7IWRV.js.map → chunk-R6OHUUYB.js.map} +0 -0
  46. /package/dist/{chunk-26A4E7J7.js.map → chunk-XJ6EMQ22.js.map} +0 -0
  47. /package/dist/{chunk-RZSQ7P2C.js.map → chunk-YXROQFXZ.js.map} +0 -0
package/dist/index.cjs CHANGED
@@ -184,6 +184,7 @@ __export(index_exports, {
184
184
  fromWebhook: () => fromWebhook,
185
185
  globToRegExp: () => globToRegExp,
186
186
  graph: () => graph_exports,
187
+ graphProfile: () => graphProfile,
187
188
  graphspec: () => graphspec_exports,
188
189
  harness: () => harness_exports,
189
190
  interval: () => interval,
@@ -262,6 +263,7 @@ __export(index_exports, {
262
263
  shareReplay: () => shareReplay,
263
264
  signalToName: () => signalToName,
264
265
  signals: () => signals_exports,
266
+ sizeof: () => sizeof,
265
267
  skip: () => skip,
266
268
  solid: () => solid_exports,
267
269
  startWith: () => startWith,
@@ -1184,7 +1186,6 @@ var NodeImpl = class {
1184
1186
  this._downInternal(wasDirty ? [[RESOLVED]] : [[DIRTY], [RESOLVED]]);
1185
1187
  return;
1186
1188
  }
1187
- this._cached = value;
1188
1189
  this._downInternal(wasDirty ? [[DATA, value]] : [[DIRTY], [DATA, value]]);
1189
1190
  }
1190
1191
  _runFn() {
@@ -5797,9 +5798,11 @@ __export(graph_exports, {
5797
5798
  JsonCodec: () => JsonCodec,
5798
5799
  createDagCborCodec: () => createDagCborCodec,
5799
5800
  createDagCborZstdCodec: () => createDagCborZstdCodec,
5801
+ graphProfile: () => graphProfile,
5800
5802
  negotiateCodec: () => negotiateCodec,
5801
5803
  reachable: () => reachable,
5802
- replayWAL: () => replayWAL
5804
+ replayWAL: () => replayWAL,
5805
+ sizeof: () => sizeof
5803
5806
  });
5804
5807
 
5805
5808
  // src/graph/codec.ts
@@ -5878,6 +5881,125 @@ function replayWAL(entries) {
5878
5881
  return result;
5879
5882
  }
5880
5883
 
5884
+ // src/graph/sizeof.ts
5885
+ var OVERHEAD = {
5886
+ object: 56,
5887
+ array: 64,
5888
+ string: 40,
5889
+ // header; content added separately
5890
+ number: 8,
5891
+ boolean: 4,
5892
+ null: 0,
5893
+ undefined: 0,
5894
+ symbol: 40,
5895
+ bigint: 16,
5896
+ function: 120,
5897
+ map: 72,
5898
+ set: 72,
5899
+ mapEntry: 40,
5900
+ setEntry: 24
5901
+ };
5902
+ function sizeof(value) {
5903
+ const seen = /* @__PURE__ */ new WeakSet();
5904
+ return _sizeof(value, seen);
5905
+ }
5906
+ function _sizeof(value, seen) {
5907
+ if (value == null) return 0;
5908
+ const t = typeof value;
5909
+ switch (t) {
5910
+ case "number":
5911
+ return OVERHEAD.number;
5912
+ case "boolean":
5913
+ return OVERHEAD.boolean;
5914
+ case "string":
5915
+ return OVERHEAD.string + value.length * 2;
5916
+ // UTF-16
5917
+ case "bigint":
5918
+ return OVERHEAD.bigint;
5919
+ case "symbol":
5920
+ return OVERHEAD.symbol;
5921
+ case "function":
5922
+ if (seen.has(value)) return 0;
5923
+ seen.add(value);
5924
+ return OVERHEAD.function;
5925
+ case "undefined":
5926
+ return 0;
5927
+ }
5928
+ const obj = value;
5929
+ if (seen.has(obj)) return 0;
5930
+ seen.add(obj);
5931
+ if (obj instanceof Map) {
5932
+ let size2 = OVERHEAD.map;
5933
+ for (const [k, v] of obj) {
5934
+ size2 += OVERHEAD.mapEntry + _sizeof(k, seen) + _sizeof(v, seen);
5935
+ }
5936
+ return size2;
5937
+ }
5938
+ if (obj instanceof Set) {
5939
+ let size2 = OVERHEAD.set;
5940
+ for (const v of obj) {
5941
+ size2 += OVERHEAD.setEntry + _sizeof(v, seen);
5942
+ }
5943
+ return size2;
5944
+ }
5945
+ if (Array.isArray(obj)) {
5946
+ let size2 = OVERHEAD.array + obj.length * 8;
5947
+ for (const item of obj) {
5948
+ size2 += _sizeof(item, seen);
5949
+ }
5950
+ return size2;
5951
+ }
5952
+ if (obj instanceof ArrayBuffer) return obj.byteLength;
5953
+ if (ArrayBuffer.isView(obj)) return obj.byteLength;
5954
+ let size = OVERHEAD.object;
5955
+ const keys = Object.keys(obj);
5956
+ for (const key of keys) {
5957
+ size += OVERHEAD.string + key.length * 2;
5958
+ size += _sizeof(obj[key], seen);
5959
+ }
5960
+ return size;
5961
+ }
5962
+
5963
+ // src/graph/profile.ts
5964
+ function graphProfile(graph, opts) {
5965
+ const topN = opts?.topN ?? 10;
5966
+ const desc = graph.describe({ detail: "standard" });
5967
+ const targets = [];
5968
+ if (typeof graph._collectObserveTargets === "function") {
5969
+ graph._collectObserveTargets("", targets);
5970
+ }
5971
+ const pathToNode = /* @__PURE__ */ new Map();
5972
+ for (const [p, n] of targets) {
5973
+ pathToNode.set(p, n);
5974
+ }
5975
+ const profiles = [];
5976
+ for (const [path, nodeDesc] of Object.entries(desc.nodes)) {
5977
+ const nd = pathToNode.get(path);
5978
+ const impl = nd instanceof NodeImpl ? nd : null;
5979
+ const valueSizeBytes = impl ? sizeof(impl.get()) : 0;
5980
+ const subscriberCount = impl ? impl._sinkCount : 0;
5981
+ const depCount = nodeDesc.deps?.length ?? 0;
5982
+ profiles.push({
5983
+ path,
5984
+ type: nodeDesc.type,
5985
+ status: nodeDesc.status ?? "unknown",
5986
+ valueSizeBytes,
5987
+ subscriberCount,
5988
+ depCount
5989
+ });
5990
+ }
5991
+ const totalValueSizeBytes = profiles.reduce((sum, p) => sum + p.valueSizeBytes, 0);
5992
+ const hotspots = [...profiles].sort((a, b) => b.valueSizeBytes - a.valueSizeBytes).slice(0, topN);
5993
+ return {
5994
+ nodeCount: profiles.length,
5995
+ edgeCount: desc.edges.length,
5996
+ subgraphCount: desc.subgraphs.length,
5997
+ nodes: profiles,
5998
+ totalValueSizeBytes,
5999
+ hotspots
6000
+ };
6001
+ }
6002
+
5881
6003
  // src/patterns/cqrs.ts
5882
6004
  var COMMAND_GUARD = policy((allow, deny) => {
5883
6005
  allow("write");
@@ -13376,36 +13498,33 @@ function firstDataFromNode(resolved, opts) {
13376
13498
  }
13377
13499
  const timeoutMs = opts?.timeoutMs ?? DEFAULT_TIMEOUT_MS;
13378
13500
  return new Promise((resolve, reject) => {
13379
- let timer;
13380
- const cleanup = () => {
13381
- if (timer !== void 0) clearTimeout(timer);
13382
- };
13501
+ const timer = new ResettableTimer();
13383
13502
  const unsub = resolved.subscribe((messages) => {
13384
13503
  for (const msg of messages) {
13385
13504
  if (msg[0] === DATA) {
13386
- cleanup();
13505
+ timer.cancel();
13387
13506
  unsub();
13388
13507
  resolve(msg[1]);
13389
13508
  return;
13390
13509
  }
13391
13510
  if (msg[0] === ERROR) {
13392
- cleanup();
13511
+ timer.cancel();
13393
13512
  unsub();
13394
13513
  reject(msg[1]);
13395
13514
  return;
13396
13515
  }
13397
13516
  if (msg[0] === COMPLETE) {
13398
- cleanup();
13517
+ timer.cancel();
13399
13518
  unsub();
13400
13519
  reject(new Error("firstDataFromNode: completed without producing a value"));
13401
13520
  return;
13402
13521
  }
13403
13522
  }
13404
13523
  });
13405
- timer = setTimeout(() => {
13524
+ timer.start(timeoutMs, () => {
13406
13525
  unsub();
13407
13526
  reject(new Error(`firstDataFromNode: timed out after ${timeoutMs}ms`));
13408
- }, timeoutMs);
13527
+ });
13409
13528
  });
13410
13529
  }
13411
13530
  async function resolveToolHandlerResult(value) {
@@ -17347,9 +17466,11 @@ __export(harness_exports, {
17347
17466
  DEFAULT_QUEUE_CONFIGS: () => DEFAULT_QUEUE_CONFIGS,
17348
17467
  DEFAULT_SEVERITY_WEIGHTS: () => DEFAULT_SEVERITY_WEIGHTS,
17349
17468
  HarnessGraph: () => HarnessGraph,
17469
+ QUEUE_NAMES: () => QUEUE_NAMES,
17350
17470
  defaultErrorClassifier: () => defaultErrorClassifier,
17351
17471
  evalIntakeBridge: () => evalIntakeBridge,
17352
17472
  harnessLoop: () => harnessLoop,
17473
+ harnessProfile: () => harnessProfile,
17353
17474
  priorityScore: () => priorityScore,
17354
17475
  strategyKey: () => strategyKey,
17355
17476
  strategyModel: () => strategyModel
@@ -18250,6 +18371,12 @@ function onFailure(graph, name, source, recover, opts) {
18250
18371
  }
18251
18372
 
18252
18373
  // src/patterns/harness/types.ts
18374
+ var QUEUE_NAMES = [
18375
+ "auto-fix",
18376
+ "needs-decision",
18377
+ "investigation",
18378
+ "backlog"
18379
+ ];
18253
18380
  function strategyKey(rootCause, intervention) {
18254
18381
  return `${rootCause}\u2192${intervention}`;
18255
18382
  }
@@ -18350,8 +18477,8 @@ function priorityScore(item, strategy, lastInteractionNs, urgency, signals) {
18350
18477
  }
18351
18478
 
18352
18479
  // src/patterns/harness/loop.ts
18353
- function baseSummary(summary) {
18354
- return summary.replace(/^\[RETRY \d+\/\d+\]\s*/, "");
18480
+ function trackingKey(item) {
18481
+ return item.relatedTo?.[0] ?? item.summary;
18355
18482
  }
18356
18483
  var DEFAULT_TRIAGE_PROMPT = `You are a triage classifier for a reactive collaboration harness.
18357
18484
 
@@ -18397,12 +18524,6 @@ Output JSON:
18397
18524
  "findings": ["<finding1>", ...],
18398
18525
  "errorClass": "self-correctable" | "structural" // only if verified=false
18399
18526
  }`;
18400
- var QUEUE_NAMES = [
18401
- "auto-fix",
18402
- "needs-decision",
18403
- "investigation",
18404
- "backlog"
18405
- ];
18406
18527
  var HarnessGraph = class extends Graph {
18407
18528
  /** Intake topic — publish items here to enter the loop. */
18408
18529
  intake;
@@ -18414,19 +18535,19 @@ var HarnessGraph = class extends Graph {
18414
18535
  strategy;
18415
18536
  /** Verify results topic — subscribe to see verification outcomes. */
18416
18537
  verifyResults;
18417
- /** Per-item fast-retry counts (keyed by base summary). */
18418
- retryTracker;
18419
- /** Per-item reingestion counts (keyed by base summary). */
18420
- reingestionTracker;
18421
- constructor(name, intake, queues, gates, strategy, verifyResults, retryTracker, reingestionTracker) {
18538
+ /** Global retry count across all items (circuit breaker). Reactive — subscribable. */
18539
+ totalRetries;
18540
+ /** Global reingestion count across all items (circuit breaker). Reactive — subscribable. */
18541
+ totalReingestions;
18542
+ constructor(name, intake, queues, gates, strategy, verifyResults, totalRetries, totalReingestions) {
18422
18543
  super(name);
18423
18544
  this.intake = intake;
18424
18545
  this.queues = queues;
18425
18546
  this.gates = gates;
18426
18547
  this.strategy = strategy;
18427
18548
  this.verifyResults = verifyResults;
18428
- this.retryTracker = retryTracker;
18429
- this.reingestionTracker = reingestionTracker;
18549
+ this.totalRetries = totalRetries;
18550
+ this.totalReingestions = totalReingestions;
18430
18551
  }
18431
18552
  };
18432
18553
  function harnessLoop(name, opts) {
@@ -18468,11 +18589,14 @@ function harnessLoop(name, opts) {
18468
18589
  for (const route of QUEUE_NAMES) {
18469
18590
  queueTopics.set(route, new TopicGraph(`queue/${route}`, { retainedLimit }));
18470
18591
  }
18471
- const router = effect([triageNode], ([triaged]) => {
18472
- const item = triaged;
18473
- if (!item || !item.route) return;
18474
- const topic2 = queueTopics.get(item.route);
18475
- if (topic2) topic2.publish(item);
18592
+ const routerInput = withLatestFrom(triageNode, triageInput);
18593
+ const router = effect([routerInput], ([pair]) => {
18594
+ const [classification, triagePair] = pair;
18595
+ if (!classification || !classification.route) return;
18596
+ const intakeItem = triagePair?.[0];
18597
+ const merged = { ...intakeItem, ...classification };
18598
+ const topic2 = queueTopics.get(merged.route);
18599
+ if (topic2) topic2.publish(merged);
18476
18600
  });
18477
18601
  const routerUnsub = router.subscribe(() => {
18478
18602
  });
@@ -18532,8 +18656,10 @@ function harnessLoop(name, opts) {
18532
18656
  executeInput
18533
18657
  );
18534
18658
  const maxReingestions = opts.maxReingestions ?? 1;
18535
- const retryTracker = /* @__PURE__ */ new Map();
18536
- const reingestionTracker = /* @__PURE__ */ new Map();
18659
+ const maxTotalRetries = Math.min(opts.maxTotalRetries ?? maxRetries * 10, 100);
18660
+ const maxTotalReingestions = Math.min(opts.maxTotalReingestions ?? maxReingestions * 10, 100);
18661
+ const totalRetries = state(0);
18662
+ const totalReingestions = state(0);
18537
18663
  const fastRetry = effect([verifyContext], ([ctx]) => {
18538
18664
  const [[vo, execRaw], item] = ctx;
18539
18665
  if (!vo || !item) return;
@@ -18559,29 +18685,33 @@ function harnessLoop(name, opts) {
18559
18685
  outcome: "failure",
18560
18686
  detail: vr.findings.join("; ")
18561
18687
  });
18562
- const key = baseSummary(item.summary);
18563
- const retryCount = retryTracker.get(key) ?? 0;
18564
- if (errClass === "self-correctable" && retryCount < maxRetries) {
18565
- retryTracker.set(key, retryCount + 1);
18688
+ const itemRetries = item._retries ?? 0;
18689
+ if (errClass === "self-correctable" && itemRetries < maxRetries && (totalRetries.get() ?? 0) < maxTotalRetries) {
18690
+ totalRetries.down([[DATA, (totalRetries.get() ?? 0) + 1]]);
18691
+ const key = trackingKey(item);
18566
18692
  const retryItem = {
18567
18693
  ...item,
18568
- summary: `[RETRY ${retryCount + 1}/${maxRetries}] ${baseSummary(item.summary)} \u2014 Previous attempt failed: ${vr.findings.join("; ")}`
18694
+ _retries: itemRetries + 1,
18695
+ summary: `[RETRY ${itemRetries + 1}/${maxRetries}] ${key} \u2014 Previous attempt failed: ${vr.findings.join("; ")}`,
18696
+ relatedTo: [key]
18569
18697
  };
18570
18698
  retryTopic.publish(retryItem);
18571
18699
  } else {
18572
18700
  strategy.record(item.rootCause, item.intervention, false);
18573
18701
  verifyResults.publish(vr);
18574
- const itemReingestions = reingestionTracker.get(key) ?? 0;
18575
- if (itemReingestions < maxReingestions) {
18576
- reingestionTracker.set(key, itemReingestions + 1);
18702
+ const key = trackingKey(item);
18703
+ const itemReingestions = item._reingestions ?? 0;
18704
+ if (itemReingestions < maxReingestions && (totalReingestions.get() ?? 0) < maxTotalReingestions) {
18705
+ totalReingestions.down([[DATA, (totalReingestions.get() ?? 0) + 1]]);
18577
18706
  intake.publish({
18578
18707
  source: "eval",
18579
- summary: `Verification failed for: ${baseSummary(item.summary)}`,
18708
+ summary: `Verification failed for: ${key}`,
18580
18709
  evidence: vr.findings.join("\n"),
18581
18710
  affectsAreas: item.affectsAreas,
18582
18711
  affectsEvalTasks: item.affectsEvalTasks,
18583
18712
  severity: "high",
18584
- relatedTo: [baseSummary(item.summary)]
18713
+ relatedTo: [key],
18714
+ _reingestions: itemReingestions + 1
18585
18715
  });
18586
18716
  }
18587
18717
  }
@@ -18595,8 +18725,8 @@ function harnessLoop(name, opts) {
18595
18725
  gateControllers,
18596
18726
  strategy,
18597
18727
  verifyResults,
18598
- retryTracker,
18599
- reingestionTracker
18728
+ totalRetries,
18729
+ totalReingestions
18600
18730
  );
18601
18731
  harness.addDisposer(routerUnsub);
18602
18732
  harness.addDisposer(fastRetryUnsub);
@@ -18611,6 +18741,22 @@ function harnessLoop(name, opts) {
18611
18741
  return harness;
18612
18742
  }
18613
18743
 
18744
+ // src/patterns/harness/profile.ts
18745
+ function harnessProfile(harness, opts) {
18746
+ const base = graphProfile(harness, opts);
18747
+ const queueDepths = {};
18748
+ for (const [route, topic2] of harness.queues) {
18749
+ queueDepths[route] = topic2.retained().length;
18750
+ }
18751
+ return {
18752
+ ...base,
18753
+ queueDepths,
18754
+ strategyEntries: harness.strategy.node.get()?.size ?? 0,
18755
+ totalRetries: harness.totalRetries.get() ?? 0,
18756
+ totalReingestions: harness.totalReingestions.get() ?? 0
18757
+ };
18758
+ }
18759
+
18614
18760
  // src/patterns/reactive-layout/index.ts
18615
18761
  var reactive_layout_exports = {};
18616
18762
  __export(reactive_layout_exports, {
@@ -19224,6 +19370,7 @@ var version = "0.0.0";
19224
19370
  fromWebhook,
19225
19371
  globToRegExp,
19226
19372
  graph,
19373
+ graphProfile,
19227
19374
  graphspec,
19228
19375
  harness,
19229
19376
  interval,
@@ -19302,6 +19449,7 @@ var version = "0.0.0";
19302
19449
  shareReplay,
19303
19450
  signalToName,
19304
19451
  signals,
19452
+ sizeof,
19305
19453
  skip,
19306
19454
  solid,
19307
19455
  startWith,