@e4779/pi-fabric 0.96.4-fork.9 → 0.97.0-fork.13

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 (91) hide show
  1. package/README.md +1 -0
  2. package/dist/cache/leases.d.ts +24 -0
  3. package/dist/cache/leases.d.ts.map +1 -0
  4. package/dist/cache/observations.d.ts +8 -0
  5. package/dist/cache/observations.d.ts.map +1 -0
  6. package/dist/cache/types.d.ts +68 -0
  7. package/dist/cache/types.d.ts.map +1 -0
  8. package/dist/chunks/{chunk-3CJETB4S.js → chunk-2LBC6TTP.js} +2 -2
  9. package/dist/chunks/{chunk-ZRI433JP.js → chunk-4F27LJTS.js} +2 -2
  10. package/dist/chunks/{chunk-GGETIGM5.js → chunk-5WUW727L.js} +2 -1
  11. package/dist/chunks/{chunk-GGETIGM5.js.map → chunk-5WUW727L.js.map} +2 -2
  12. package/dist/chunks/{chunk-QFKHAAZA.js → chunk-6K5SRGW6.js} +1 -1
  13. package/dist/chunks/{chunk-EBWMC3OO.js → chunk-A4XPJESK.js} +2 -2
  14. package/dist/chunks/{chunk-B2IVWASP.js → chunk-CZSX6UG6.js} +2 -2
  15. package/dist/chunks/{chunk-ZTXZ6JDO.js → chunk-D5GNTBV6.js} +2 -2
  16. package/dist/chunks/{chunk-ULQFHZJE.js → chunk-EPAFGT2M.js} +35 -1
  17. package/dist/chunks/{chunk-ULQFHZJE.js.map → chunk-EPAFGT2M.js.map} +2 -2
  18. package/dist/chunks/{chunk-F72MAIQY.js → chunk-EQIGYLVB.js} +34 -1
  19. package/dist/chunks/chunk-EQIGYLVB.js.map +7 -0
  20. package/dist/chunks/{chunk-OUAC6O5C.js → chunk-F676L43O.js} +2 -2
  21. package/dist/chunks/{chunk-YC3QQDZ3.js → chunk-IPHEM6RY.js} +2 -2
  22. package/dist/chunks/{chunk-PMSIZLV6.js → chunk-IUCEIYLV.js} +2 -1
  23. package/dist/chunks/chunk-IUCEIYLV.js.map +7 -0
  24. package/dist/chunks/{chunk-Y57UHPIK.js → chunk-KBHITFTO.js} +1 -1
  25. package/dist/chunks/chunk-KBHITFTO.js.map +7 -0
  26. package/dist/chunks/chunk-QNMMQAZ7.js +162 -0
  27. package/dist/chunks/chunk-QNMMQAZ7.js.map +7 -0
  28. package/dist/chunks/{chunk-2A2NWQ36.js → chunk-WGGUZMQ4.js} +2 -2
  29. package/dist/components/configuration.js +2 -2
  30. package/dist/components/provider-component.d.ts +1 -1
  31. package/dist/components/provider-component.d.ts.map +1 -1
  32. package/dist/config.d.ts +11 -0
  33. package/dist/config.d.ts.map +1 -1
  34. package/dist/core/action-registry.js +2 -2
  35. package/dist/fabric-runtime-state.d.ts.map +1 -1
  36. package/dist/fabric-runtime-state.js +533 -167
  37. package/dist/fabric-runtime-state.js.map +4 -4
  38. package/dist/index.js +5 -5
  39. package/dist/index.js.map +2 -2
  40. package/dist/jev.js +1 -1
  41. package/dist/memory/file-worker.js +1 -1
  42. package/dist/memory/fs-source.d.ts +12 -0
  43. package/dist/memory/fs-source.d.ts.map +1 -0
  44. package/dist/memory/worker-provider.js +2 -2
  45. package/dist/memory.d.ts +2 -0
  46. package/dist/memory.d.ts.map +1 -1
  47. package/dist/memory.js +7 -1
  48. package/dist/memory.js.map +1 -1
  49. package/dist/protocol.d.ts +1 -0
  50. package/dist/protocol.d.ts.map +1 -1
  51. package/dist/protocol.js +1 -1
  52. package/dist/providers/cache-provider.d.ts +16 -0
  53. package/dist/providers/cache-provider.d.ts.map +1 -0
  54. package/dist/providers/jev-provider.js +1 -1
  55. package/dist/providers/memory-provider.js +1 -1
  56. package/dist/residency/host.js +3 -3
  57. package/dist/residency/pi-entry.js +3 -3
  58. package/dist/runtime/core-override-guest-types.js +2 -2
  59. package/dist/runtime/cpython-runtime.js +1 -1
  60. package/dist/runtime/cpython-runtime.js.map +1 -1
  61. package/dist/runtime/guest-types.d.ts +1 -1
  62. package/dist/runtime/guest-types.d.ts.map +1 -1
  63. package/dist/runtime/guest-types.js +1 -1
  64. package/dist/runtime/monty-runtime.js +2 -2
  65. package/dist/runtime/monty-runtime.js.map +2 -2
  66. package/dist/runtime/node-process-runtime.js +2 -2
  67. package/dist/runtime/quickjs-runtime.d.ts.map +1 -1
  68. package/dist/runtime/quickjs-runtime.js +1 -1
  69. package/dist/runtime/typescript-kernel.js +4 -4
  70. package/dist/runtime-state-builtins.d.ts.map +1 -1
  71. package/dist/schema/policy.d.ts.map +1 -1
  72. package/dist/ui/settings.js +1 -1
  73. package/docs/architecture.md +1 -0
  74. package/docs/components.md +3 -0
  75. package/docs/configuration.md +18 -0
  76. package/docs/memory-recall.md +21 -0
  77. package/docs/prompt-cache.md +91 -0
  78. package/package.json +1 -1
  79. package/skillsets/typescript/fabric-exec/SKILL.md +5 -0
  80. package/dist/chunks/chunk-F72MAIQY.js.map +0 -7
  81. package/dist/chunks/chunk-PMSIZLV6.js.map +0 -7
  82. package/dist/chunks/chunk-Y57UHPIK.js.map +0 -7
  83. /package/dist/chunks/{chunk-3CJETB4S.js.map → chunk-2LBC6TTP.js.map} +0 -0
  84. /package/dist/chunks/{chunk-ZRI433JP.js.map → chunk-4F27LJTS.js.map} +0 -0
  85. /package/dist/chunks/{chunk-QFKHAAZA.js.map → chunk-6K5SRGW6.js.map} +0 -0
  86. /package/dist/chunks/{chunk-EBWMC3OO.js.map → chunk-A4XPJESK.js.map} +0 -0
  87. /package/dist/chunks/{chunk-B2IVWASP.js.map → chunk-CZSX6UG6.js.map} +0 -0
  88. /package/dist/chunks/{chunk-ZTXZ6JDO.js.map → chunk-D5GNTBV6.js.map} +0 -0
  89. /package/dist/chunks/{chunk-OUAC6O5C.js.map → chunk-F676L43O.js.map} +0 -0
  90. /package/dist/chunks/{chunk-YC3QQDZ3.js.map → chunk-IPHEM6RY.js.map} +0 -0
  91. /package/dist/chunks/{chunk-2A2NWQ36.js.map → chunk-WGGUZMQ4.js.map} +0 -0
@@ -12,10 +12,10 @@ import {
12
12
  componentEntries,
13
13
  validateComponentConfig,
14
14
  watchComponentConfiguration
15
- } from "./chunks/chunk-YC3QQDZ3.js";
15
+ } from "./chunks/chunk-IPHEM6RY.js";
16
16
  import {
17
17
  WorkerMemoryProvider
18
- } from "./chunks/chunk-EBWMC3OO.js";
18
+ } from "./chunks/chunk-A4XPJESK.js";
19
19
  import {
20
20
  ResidentActorClient
21
21
  } from "./chunks/chunk-NHMICIEU.js";
@@ -31,7 +31,7 @@ import {
31
31
  scoreActionSearch,
32
32
  summarizeEffects,
33
33
  trackedRegistration
34
- } from "./chunks/chunk-3CJETB4S.js";
34
+ } from "./chunks/chunk-2LBC6TTP.js";
35
35
  import {
36
36
  formatFabricEffectConflict
37
37
  } from "./chunks/chunk-LMAVZN7J.js";
@@ -52,7 +52,7 @@ import {
52
52
  resolveFabricIdentity,
53
53
  runtimeIdentityStatus,
54
54
  setModelSafely
55
- } from "./chunks/chunk-GGETIGM5.js";
55
+ } from "./chunks/chunk-5WUW727L.js";
56
56
  import {
57
57
  AgentTranscriptReader,
58
58
  MAX_WRITE_DIFF_BYTES,
@@ -65,7 +65,10 @@ import {
65
65
  loadCompiledSurface,
66
66
  withExclusiveFileLockAsync
67
67
  } from "./chunks/chunk-JCV54SSP.js";
68
- import "./chunks/chunk-OUAC6O5C.js";
68
+ import {
69
+ createConfiguredMemorySourceRegistry
70
+ } from "./chunks/chunk-QNMMQAZ7.js";
71
+ import "./chunks/chunk-F676L43O.js";
69
72
  import "./chunks/chunk-FJSHRHOR.js";
70
73
  import "./chunks/chunk-UBPFGMDQ.js";
71
74
  import "./chunks/chunk-VQGO4P7C.js";
@@ -119,7 +122,7 @@ import {
119
122
  FABRIC_PROVIDER_DISCOVER_EVENT,
120
123
  FABRIC_TOOL_RESULT_PROXY_KIND,
121
124
  readFabricToolResultProxyDetailsV1
122
- } from "./chunks/chunk-Y57UHPIK.js";
125
+ } from "./chunks/chunk-KBHITFTO.js";
123
126
  import {
124
127
  ActorDirectory,
125
128
  ActorRegistryOwnershipError,
@@ -145,7 +148,7 @@ import {
145
148
  snapshotHandoffSession,
146
149
  thinkingTransferPolicy,
147
150
  withInheritedSessionPins
148
- } from "./chunks/chunk-ZRI433JP.js";
151
+ } from "./chunks/chunk-4F27LJTS.js";
149
152
  import {
150
153
  executeFile,
151
154
  processIsAlive,
@@ -178,7 +181,7 @@ import {
178
181
  MAX_AGENT_TIMEOUT_MS,
179
182
  MIN_AGENT_TIMEOUT_MS,
180
183
  loadFabricConfig
181
- } from "./chunks/chunk-F72MAIQY.js";
184
+ } from "./chunks/chunk-EQIGYLVB.js";
182
185
  import "./chunks/chunk-OKOHRXGF.js";
183
186
  import {
184
187
  fabricExecTitleHintCached
@@ -2678,8 +2681,8 @@ var FabricComponentSupervisor = class {
2678
2681
  }
2679
2682
  #assertEffectCapacity(component, additional = 0) {
2680
2683
  if (component.guarantee !== "revertible") return;
2681
- const count = (component.scope?.footprint(MAX_COMPONENT_EFFECTS + 1).length ?? 0) + component.actionEffects.length + additional;
2682
- if (count > MAX_COMPONENT_EFFECTS) {
2684
+ const count2 = (component.scope?.footprint(MAX_COMPONENT_EFFECTS + 1).length ?? 0) + component.actionEffects.length + additional;
2685
+ if (count2 > MAX_COMPONENT_EFFECTS) {
2683
2686
  throw new Error(
2684
2687
  `Revertible Fabric component ${component.entry.id} exceeds ${MAX_COMPONENT_EFFECTS} tracked effects`
2685
2688
  );
@@ -2753,8 +2756,8 @@ var FabricComponentSupervisor = class {
2753
2756
  }
2754
2757
  if (path15.length > this.#components.size) return;
2755
2758
  const nextPositions = new Map(positions).set(node, path15.length);
2756
- for (const target of adjacent.get(node) ?? []) {
2757
- visit(target, [...path15, node], nextPositions);
2759
+ for (const target2 of adjacent.get(node) ?? []) {
2760
+ visit(target2, [...path15, node], nextPositions);
2758
2761
  }
2759
2762
  };
2760
2763
  for (const id of this.#components.keys()) visit(id, [], /* @__PURE__ */ new Map());
@@ -3029,12 +3032,12 @@ var FabricComponentLoader = class {
3029
3032
  const changed = [];
3030
3033
  const removed = [];
3031
3034
  try {
3032
- for (const [id, target] of targets) {
3035
+ for (const [id, target2] of targets) {
3033
3036
  const current = this.#loaded.get(id);
3034
3037
  if (!current) {
3035
3038
  try {
3036
- await this.supervisor.start(target.entry, target.definition);
3037
- this.#loaded.set(id, target);
3039
+ await this.supervisor.start(target2.entry, target2.definition);
3040
+ this.#loaded.set(id, target2);
3038
3041
  added.push(id);
3039
3042
  } catch (error) {
3040
3043
  try {
@@ -3045,12 +3048,12 @@ var FabricComponentLoader = class {
3045
3048
  }
3046
3049
  continue;
3047
3050
  }
3048
- if (current.entryHash === target.entryHash && current.definitionRevision === target.definitionRevision) {
3051
+ if (current.entryHash === target2.entryHash && current.definitionRevision === target2.definitionRevision) {
3049
3052
  continue;
3050
3053
  }
3051
- await this.supervisor.replace(id, target.entry, target.definition);
3054
+ await this.supervisor.replace(id, target2.entry, target2.definition);
3052
3055
  changed.push({ id, previous: current });
3053
- this.#loaded.set(id, target);
3056
+ this.#loaded.set(id, target2);
3054
3057
  }
3055
3058
  for (const [id, current] of [...this.#loaded]) {
3056
3059
  if (targets.has(id)) continue;
@@ -3829,7 +3832,7 @@ var FabricExecutionService = class {
3829
3832
  this.#runtimeKind = runtimeKind;
3830
3833
  }
3831
3834
  let code = options.code;
3832
- let checked = { errors: [] };
3835
+ let checked2 = { errors: [] };
3833
3836
  const unavailable = new Map(
3834
3837
  this.registry.unavailableProviders().map((entry) => [entry.name, entry.reason])
3835
3838
  );
@@ -3849,7 +3852,7 @@ var FabricExecutionService = class {
3849
3852
  },
3850
3853
  ...this.#capabilityView ? { capabilityView: this.#capabilityView } : {}
3851
3854
  });
3852
- ({ code, checked } = runtime.prepare(
3855
+ ({ code, checked: checked2 } = runtime.prepare(
3853
3856
  options.code,
3854
3857
  effectiveFullCodeMode,
3855
3858
  [...unavailable.keys()],
@@ -3857,8 +3860,8 @@ var FabricExecutionService = class {
3857
3860
  coreOverrides
3858
3861
  ));
3859
3862
  }
3860
- if (checked.errors.length > 0) {
3861
- for (const error of checked.errors) {
3863
+ if (checked2.errors.length > 0) {
3864
+ for (const error of checked2.errors) {
3862
3865
  const missing = /^Cannot find name '([^']+)'/.exec(error.message);
3863
3866
  const reason = missing?.[1] ? unavailable.get(missing[1]) : void 0;
3864
3867
  if (missing && reason) {
@@ -3876,10 +3879,10 @@ var FabricExecutionService = class {
3876
3879
  trace: traceRecorder.seal(
3877
3880
  "failed",
3878
3881
  [],
3879
- `Type checking failed (${checked.errors.length} ${checked.errors.length === 1 ? "error" : "errors"})`
3882
+ `Type checking failed (${checked2.errors.length} ${checked2.errors.length === 1 ? "error" : "errors"})`
3880
3883
  ),
3881
3884
  elapsedMs: performance.now() - startedAt,
3882
- typeErrors: checked.errors
3885
+ typeErrors: checked2.errors
3883
3886
  };
3884
3887
  }
3885
3888
  const classifierUsages = [];
@@ -4399,8 +4402,8 @@ var FabricExecutionService = class {
4399
4402
  maxLogChars: this.config.executor.maxOutputChars,
4400
4403
  minimumTimeoutMsForHostCall,
4401
4404
  ...!python ? { piToolCanonicalFields } : {},
4402
- ...checked.javascript ? { transpiledCode: checked.javascript } : {},
4403
- ...checked.sourceMap ? { transpiledSourceMap: checked.sourceMap } : {},
4405
+ ...checked2.javascript ? { transpiledCode: checked2.javascript } : {},
4406
+ ...checked2.sourceMap ? { transpiledSourceMap: checked2.sourceMap } : {},
4404
4407
  ...options.strings ? { strings: options.strings } : {},
4405
4408
  ...options.tokenBudget !== void 0 ? { tokenBudget: options.tokenBudget } : {},
4406
4409
  ...options.signal ? { signal: options.signal } : {}
@@ -4469,9 +4472,9 @@ var applyKeyAliasRepairs = (ref, args, repairs, schema) => {
4469
4472
  }
4470
4473
  if (applicable.length === 0) return { args, changed: false };
4471
4474
  const out = { ...args };
4472
- for (const [target, sources] of sourcesByTarget) {
4475
+ for (const [target2, sources] of sourcesByTarget) {
4473
4476
  const source = [...sources][0];
4474
- Object.defineProperty(out, target, {
4477
+ Object.defineProperty(out, target2, {
4475
4478
  value: args[source],
4476
4479
  enumerable: true,
4477
4480
  writable: true,
@@ -4906,9 +4909,9 @@ var statSignature = (filePath) => {
4906
4909
  };
4907
4910
  var signatureEquals = (left, right) => left === "missing" || right === "missing" ? left === right : left.mtimeMs === right.mtimeMs && left.size === right.size;
4908
4911
  var readFreshness = (args, cwd) => {
4909
- const target = args.path;
4910
- if (typeof target !== "string" || target.length === 0) return void 0;
4911
- const resolved = path4.resolve(cwd, target);
4912
+ const target2 = args.path;
4913
+ if (typeof target2 !== "string" || target2.length === 0) return void 0;
4914
+ const resolved = path4.resolve(cwd, target2);
4912
4915
  const snapshot = statSignature(resolved);
4913
4916
  if (snapshot === "error") return void 0;
4914
4917
  return () => {
@@ -5073,11 +5076,11 @@ ${bindingToken}`;
5073
5076
  this.#endedInvocations.clear();
5074
5077
  }
5075
5078
  #inFlightCount() {
5076
- let count = 0;
5079
+ let count2 = 0;
5077
5080
  for (const entry of this.#entries.values()) {
5078
- if (!entry.failed) count += 1;
5081
+ if (!entry.failed) count2 += 1;
5079
5082
  }
5080
- return count;
5083
+ return count2;
5081
5084
  }
5082
5085
  #sweepExpired(now) {
5083
5086
  for (const [key, entry] of this.#entries) {
@@ -5403,6 +5406,7 @@ var allowedEnforceRefs = /* @__PURE__ */ new Set([
5403
5406
  "mesh.get",
5404
5407
  "mesh.list",
5405
5408
  "compact.status",
5409
+ "cache.status",
5406
5410
  "components.list",
5407
5411
  "components.describe",
5408
5412
  "components.status",
@@ -5845,36 +5849,36 @@ var LifecycleDeliveryScheduler = class {
5845
5849
  #timers = /* @__PURE__ */ new Map();
5846
5850
  #inFlight = /* @__PURE__ */ new Map();
5847
5851
  #closed = false;
5848
- schedule(target, delivery) {
5852
+ schedule(target2, delivery) {
5849
5853
  if (this.#closed) return;
5850
5854
  if (delivery.subscription.delivery === "steer") {
5851
- void this.#dispatch(target, [delivery]);
5855
+ void this.#dispatch(target2, [delivery]);
5852
5856
  return;
5853
5857
  }
5854
- const buffer = this.#buffers.get(target);
5858
+ const buffer = this.#buffers.get(target2);
5855
5859
  if (buffer) buffer.push(delivery);
5856
- else this.#buffers.set(target, [delivery]);
5857
- if (this.#timers.has(target)) return;
5858
- const timer = setTimeout(() => void this.flush(target), this.#coalesceMs);
5860
+ else this.#buffers.set(target2, [delivery]);
5861
+ if (this.#timers.has(target2)) return;
5862
+ const timer = setTimeout(() => void this.flush(target2), this.#coalesceMs);
5859
5863
  timer.unref();
5860
- this.#timers.set(target, timer);
5864
+ this.#timers.set(target2, timer);
5861
5865
  }
5862
- async flush(target) {
5863
- const timer = this.#timers.get(target);
5866
+ async flush(target2) {
5867
+ const timer = this.#timers.get(target2);
5864
5868
  if (timer) {
5865
5869
  clearTimeout(timer);
5866
- this.#timers.delete(target);
5870
+ this.#timers.delete(target2);
5867
5871
  }
5868
- const batch = this.#buffers.get(target);
5872
+ const batch = this.#buffers.get(target2);
5869
5873
  if (!batch || batch.length === 0) return;
5870
- this.#buffers.delete(target);
5871
- await this.#dispatch(target, batch);
5874
+ this.#buffers.delete(target2);
5875
+ await this.#dispatch(target2, batch);
5872
5876
  }
5873
5877
  async flushAll() {
5874
5878
  for (const timer of this.#timers.values()) clearTimeout(timer);
5875
5879
  this.#timers.clear();
5876
5880
  const targets = [...this.#buffers.keys()];
5877
- await Promise.all(targets.map((target) => this.flush(target)));
5881
+ await Promise.all(targets.map((target2) => this.flush(target2)));
5878
5882
  await Promise.all(this.#inFlight.values());
5879
5883
  }
5880
5884
  async dispose() {
@@ -5884,20 +5888,20 @@ var LifecycleDeliveryScheduler = class {
5884
5888
  this.#buffers.clear();
5885
5889
  await Promise.all(this.#inFlight.values());
5886
5890
  }
5887
- async #dispatch(target, batch) {
5888
- const previous = this.#inFlight.get(target);
5891
+ async #dispatch(target2, batch) {
5892
+ const previous = this.#inFlight.get(target2);
5889
5893
  const operation = (async () => {
5890
5894
  await previous?.catch(() => void 0);
5891
5895
  try {
5892
- await this.deliver(target, batch);
5896
+ await this.deliver(target2, batch);
5893
5897
  } catch (error) {
5894
- this.onError(target, batch, error);
5898
+ this.onError(target2, batch, error);
5895
5899
  }
5896
5900
  })();
5897
5901
  this.#inFlight.set(
5898
- target,
5902
+ target2,
5899
5903
  operation.finally(() => {
5900
- if (this.#inFlight.get(target) === operation) this.#inFlight.delete(target);
5904
+ if (this.#inFlight.get(target2) === operation) this.#inFlight.delete(target2);
5901
5905
  })
5902
5906
  );
5903
5907
  await operation;
@@ -6556,16 +6560,16 @@ var AgentMessageRouter = class {
6556
6560
  if (!(error instanceof Error && /Unknown Fabric agent/.test(error.message))) throw error;
6557
6561
  }
6558
6562
  this.actorManager.validateDirectMessage(message2, data);
6559
- let target;
6563
+ let target2;
6560
6564
  try {
6561
- target = this.resolveActorTarget(id);
6565
+ target2 = this.resolveActorTarget(id);
6562
6566
  } catch (error) {
6563
6567
  if (error instanceof Error && /Unknown Fabric actor/.test(error.message)) {
6564
6568
  throw new Error(`Unknown Fabric participant: ${id}`);
6565
6569
  }
6566
6570
  throw error;
6567
6571
  }
6568
- const { actor, participant } = target;
6572
+ const { actor, participant } = target2;
6569
6573
  const localActor = Boolean(actor && (!participant || participant.local));
6570
6574
  const binding = options.binding && context && localActor ? this.resolvePiRunBinding(options.binding, actor.runner, context) : options.binding;
6571
6575
  if (actor && localActor) {
@@ -6737,8 +6741,8 @@ var resolveThinkingTransfer = (extensionContext, targetKey2, sourceModel) => {
6737
6741
  if (separator <= 0 || separator === targetKey2.length - 1) return void 0;
6738
6742
  const registry = extensionContext?.modelRegistry;
6739
6743
  if (!registry) return void 0;
6740
- const target = registry.find(targetKey2.slice(0, separator), targetKey2.slice(separator + 1));
6741
- if (!target) return void 0;
6744
+ const target2 = registry.find(targetKey2.slice(0, separator), targetKey2.slice(separator + 1));
6745
+ if (!target2) return void 0;
6742
6746
  const source = sourceModel ? {
6743
6747
  provider: sourceModel.provider,
6744
6748
  modelId: sourceModel.modelId,
@@ -6747,12 +6751,12 @@ var resolveThinkingTransfer = (extensionContext, targetKey2, sourceModel) => {
6747
6751
  return {
6748
6752
  ...source ? { source } : {},
6749
6753
  target: {
6750
- provider: target.provider,
6751
- modelId: target.id,
6752
- api: target.api,
6753
- reasoning: target.reasoning,
6754
- ...target.compat?.requiresThinkingAsText !== void 0 ? {
6755
- requiresThinkingAsText: target.compat.requiresThinkingAsText
6754
+ provider: target2.provider,
6755
+ modelId: target2.id,
6756
+ api: target2.api,
6757
+ reasoning: target2.reasoning,
6758
+ ...target2.compat?.requiresThinkingAsText !== void 0 ? {
6759
+ requiresThinkingAsText: target2.compat.requiresThinkingAsText
6756
6760
  } : {}
6757
6761
  }
6758
6762
  };
@@ -6886,10 +6890,10 @@ var AgentsProvider = class {
6886
6890
  );
6887
6891
  this.#lifecycleScheduler = new LifecycleDeliveryScheduler(
6888
6892
  DEFAULT_LIFECYCLE_COALESCE_MS,
6889
- (target, batch) => this.#routeLifecycleBatch(target, batch),
6890
- (target, batch, error) => {
6893
+ (target2, batch) => this.#routeLifecycleBatch(target2, batch),
6894
+ (target2, batch, error) => {
6891
6895
  console.warn(
6892
- `[pi-fabric] lifecycle delivery to ${target} failed for ${batch.length} event(s): ` + (error instanceof Error ? error.message : String(error))
6896
+ `[pi-fabric] lifecycle delivery to ${target2} failed for ${batch.length} event(s): ` + (error instanceof Error ? error.message : String(error))
6893
6897
  );
6894
6898
  }
6895
6899
  );
@@ -6904,7 +6908,7 @@ var AgentsProvider = class {
6904
6908
  const run = event.runId ? ` (run ${event.runId.slice(0, 8)})` : "";
6905
6909
  return `Fabric lifecycle ${event.event} from ${event.source.name} (${event.source.id})${run}${status}.`;
6906
6910
  }
6907
- async #routeLifecycleBatch(target, batch) {
6911
+ async #routeLifecycleBatch(target2, batch) {
6908
6912
  const first = batch[0];
6909
6913
  const single = batch.length === 1;
6910
6914
  const message2 = single ? this.#lifecycleMessage(first.event) : `Fabric lifecycle events (${batch.length}):
@@ -6912,7 +6916,7 @@ var AgentsProvider = class {
6912
6916
  const data = single ? first.event : batch.map((delivery) => delivery.event);
6913
6917
  const last = batch[batch.length - 1];
6914
6918
  await this.routeMessage(
6915
- target,
6919
+ target2,
6916
6920
  message2,
6917
6921
  data,
6918
6922
  first.subscription.delivery,
@@ -7416,9 +7420,9 @@ var AgentsProvider = class {
7416
7420
  case "setModel": {
7417
7421
  const id = String(args.id);
7418
7422
  const model = typeof args.model === "string" ? args.model.trim() : "";
7419
- const target = this.#resolveActorTarget(id);
7420
- const ownsActor = target.actor ? this.actorManager.owns(target.actor.id) : false;
7421
- const runner = target.actor?.runner ?? target.participant.runner;
7423
+ const target2 = this.#resolveActorTarget(id);
7424
+ const ownsActor = target2.actor ? this.actorManager.owns(target2.actor.id) : false;
7425
+ const runner = target2.actor?.runner ?? target2.participant.runner;
7422
7426
  const resolvedModel = model && ownsActor ? this.#resolvePiModelArgs({ model }, context, runner).model : model || void 0;
7423
7427
  return this.actorManager.setModel(
7424
7428
  id,
@@ -7803,9 +7807,362 @@ var CompactProvider = class {
7803
7807
  }
7804
7808
  };
7805
7809
 
7810
+ // src/cache/leases.ts
7811
+ import { createHash as createHash2, randomUUID as randomUUID5 } from "node:crypto";
7812
+ var MAX_CACHE_LEASE_MS = 30 * 6e4;
7813
+ var MAX_CACHE_LEASES = 128;
7814
+ var CacheLeases = class {
7815
+ constructor(pi, sessionId) {
7816
+ this.pi = pi;
7817
+ this.sessionId = sessionId;
7818
+ }
7819
+ #leases = /* @__PURE__ */ new Map();
7820
+ #unsubscribe = [];
7821
+ #releaseNative;
7822
+ #binding;
7823
+ #failedBinding;
7824
+ #cleanupError = null;
7825
+ #closed = false;
7826
+ supported(context) {
7827
+ return typeof context.acquireCacheWarming === "function";
7828
+ }
7829
+ get cleanupError() {
7830
+ return this.#cleanupError;
7831
+ }
7832
+ values() {
7833
+ return [...this.#leases.values()].map((lease) => ({ ...lease.value }));
7834
+ }
7835
+ #key(context) {
7836
+ return createHash2("sha256").update(JSON.stringify([
7837
+ context.sessionManager.getSessionId(),
7838
+ context.model?.provider,
7839
+ context.model?.id,
7840
+ context.thinkingLevel ?? this.pi.getThinkingLevel(),
7841
+ context.getSystemPrompt(),
7842
+ [...this.pi.getActiveTools()].sort()
7843
+ ])).digest("hex");
7844
+ }
7845
+ reconcile(context) {
7846
+ if (!this.#binding && !this.#failedBinding) return;
7847
+ const key = this.#key(context);
7848
+ if (this.#binding && (this.#binding !== key || !this.supported(context))) this.invalidate();
7849
+ if (this.#failedBinding !== key) this.#failedBinding = void 0;
7850
+ }
7851
+ #listen() {
7852
+ if (this.#unsubscribe.length) return;
7853
+ const invalidate = () => {
7854
+ this.invalidate();
7855
+ };
7856
+ this.#unsubscribe.push(
7857
+ this.pi.on("session_start", invalidate),
7858
+ this.pi.on("session_before_switch", invalidate),
7859
+ this.pi.on("session_before_fork", invalidate),
7860
+ this.pi.on("session_tree", invalidate),
7861
+ this.pi.on("session_before_compact", invalidate),
7862
+ this.pi.on("session_compact", invalidate),
7863
+ this.pi.on("model_select", invalidate),
7864
+ this.pi.on("session_shutdown", invalidate)
7865
+ );
7866
+ this.#unsubscribe.push(this.pi.on("cache_warming_decision", (_event, context) => {
7867
+ this.reconcile(context);
7868
+ }));
7869
+ this.#unsubscribe.push(this.pi.on("before_agent_start", (_event, context) => {
7870
+ this.reconcile(context);
7871
+ }));
7872
+ }
7873
+ hold(options, context, scope, invocationId, signal) {
7874
+ signal?.throwIfAborted();
7875
+ if (this.#closed || context.sessionManager.getSessionId() !== this.sessionId) {
7876
+ return { status: "unavailable", reason: "Session or provider generation has ended" };
7877
+ }
7878
+ this.reconcile(context);
7879
+ if (!this.supported(context)) return { status: "unsupported", reason: "Native scoped cache warming is unavailable; no fallback requests are made" };
7880
+ if (options.maxCostUsd !== void 0 || options.maxRefreshes !== void 0) {
7881
+ return { status: "unsupported", reason: "Native cost and refresh-count admission is unavailable; requested bounds cannot be enforced" };
7882
+ }
7883
+ if (!context.model) return { status: "unavailable", reason: "No current model" };
7884
+ if (this.#cleanupError) return { status: "unavailable", reason: this.#cleanupError };
7885
+ if (this.#leases.size >= MAX_CACHE_LEASES) return { status: "unavailable", reason: "Cache lease capacity reached" };
7886
+ const key = this.#key(context);
7887
+ if (this.#failedBinding === key) return { status: "unavailable", reason: "Native acquisition failed for this binding; no automatic retry" };
7888
+ this.#listen();
7889
+ if (!this.#releaseNative) {
7890
+ try {
7891
+ const release = context.acquireCacheWarming("idle");
7892
+ if (typeof release !== "function") throw new Error("Invalid native lease");
7893
+ this.#releaseNative = release;
7894
+ this.#binding = key;
7895
+ } catch {
7896
+ this.#failedBinding = key;
7897
+ return { status: "unavailable", reason: "Native acquisition failed for this binding; no automatic retry" };
7898
+ }
7899
+ }
7900
+ const value = {
7901
+ id: randomUUID5(),
7902
+ scope,
7903
+ sessionId: this.sessionId,
7904
+ model: `${context.model.provider}/${context.model.id}`,
7905
+ expiresAt: Date.now() + options.durationMs
7906
+ };
7907
+ const timer = setTimeout(() => this.#drop(value.id), options.durationMs);
7908
+ timer.unref();
7909
+ const abort = () => {
7910
+ this.#drop(value.id);
7911
+ };
7912
+ const detach = () => signal?.removeEventListener("abort", abort);
7913
+ this.#leases.set(value.id, { value, timer, detach, invocationId });
7914
+ signal?.addEventListener("abort", abort, { once: true });
7915
+ if (signal?.aborted) {
7916
+ this.#drop(value.id);
7917
+ signal.throwIfAborted();
7918
+ }
7919
+ return { status: "held", ...value };
7920
+ }
7921
+ release(id) {
7922
+ const lease = this.#leases.get(id);
7923
+ if (lease?.value.scope === "component") throw new Error("A component cache lease can only be released by its owning scope");
7924
+ return { released: this.#drop(id), cleanupError: this.#cleanupError };
7925
+ }
7926
+ dispose(id) {
7927
+ this.#drop(id);
7928
+ if (this.#cleanupError) throw new Error(this.#cleanupError);
7929
+ }
7930
+ invocationEnded(id) {
7931
+ for (const lease of this.#leases.values()) {
7932
+ if (lease.value.scope === "session" && lease.invocationId === id) lease.detach();
7933
+ }
7934
+ }
7935
+ #drop(id) {
7936
+ const lease = this.#leases.get(id);
7937
+ if (!lease) return false;
7938
+ this.#leases.delete(id);
7939
+ clearTimeout(lease.timer);
7940
+ lease.detach();
7941
+ if (this.#leases.size === 0) this.#release();
7942
+ return true;
7943
+ }
7944
+ #release() {
7945
+ try {
7946
+ this.#releaseNative?.();
7947
+ this.#releaseNative = void 0;
7948
+ this.#binding = void 0;
7949
+ this.#cleanupError = null;
7950
+ } catch {
7951
+ this.#cleanupError = "Native cache lease cleanup failed";
7952
+ }
7953
+ }
7954
+ invalidate() {
7955
+ for (const id of this.#leases.keys()) this.#drop(id);
7956
+ this.#failedBinding = void 0;
7957
+ }
7958
+ close() {
7959
+ this.#closed = true;
7960
+ this.invalidate();
7961
+ this.#release();
7962
+ for (const unsubscribe of this.#unsubscribe.splice(0)) unsubscribe();
7963
+ if (this.#cleanupError) throw new Error(this.#cleanupError);
7964
+ }
7965
+ };
7966
+
7967
+ // src/cache/observations.ts
7968
+ var CACHE_OBSERVATION_LIMIT = 256;
7969
+ var count = (value) => typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
7970
+ var price = (value) => typeof value === "number" && Number.isFinite(value) && value >= 0;
7971
+ function cacheSample(usage, entryId, timestamp) {
7972
+ if (!usage || typeof usage !== "object") return null;
7973
+ const value = usage;
7974
+ const { input, cacheRead, cacheWrite, output } = value;
7975
+ if (!count(input) || !count(cacheRead) || !count(cacheWrite) || !count(output)) return null;
7976
+ const totalInput = input + cacheRead + cacheWrite;
7977
+ const observedAt = Date.parse(timestamp);
7978
+ if (!Number.isSafeInteger(totalInput + output) || totalInput === 0 || !Number.isFinite(observedAt)) return null;
7979
+ const cost = value.cost && typeof value.cost === "object" ? value.cost.total : void 0;
7980
+ return {
7981
+ entryId,
7982
+ observedAt,
7983
+ input,
7984
+ cacheRead,
7985
+ cacheWrite,
7986
+ output,
7987
+ totalInput,
7988
+ cacheReadShare: cacheRead / totalInput,
7989
+ reportedCostUsd: price(cost) ? cost : null
7990
+ };
7991
+ }
7992
+ function observePromptCache(context) {
7993
+ const result = {
7994
+ lastRequest: null,
7995
+ lastRefresh: null,
7996
+ maintenance: { requests: 0, tokens: 0, reportedCostUsd: 0, unknownCostRequests: 0, unknownTokenRequests: 0 },
7997
+ window: { entries: 0, limit: CACHE_OBSERVATION_LIMIT, truncated: false, stoppedAt: null }
7998
+ };
7999
+ const manager = context.sessionManager;
8000
+ if (typeof manager.getLeafEntry !== "function" || typeof manager.getEntry !== "function") {
8001
+ result.window.stoppedAt = "history-unavailable";
8002
+ return result;
8003
+ }
8004
+ const seen = /* @__PURE__ */ new Set();
8005
+ let entry = manager.getLeafEntry();
8006
+ while (entry && result.window.entries < CACHE_OBSERVATION_LIMIT) {
8007
+ if (seen.has(entry.id)) {
8008
+ result.window.stoppedAt = "invalid-history";
8009
+ break;
8010
+ }
8011
+ seen.add(entry.id);
8012
+ result.window.entries++;
8013
+ if (["compaction", "branch_summary", "model_change", "thinking_level_change", "context_edit"].includes(entry.type) || entry.type === "message" && entry.message.role === "system") {
8014
+ result.window.stoppedAt = entry.type;
8015
+ break;
8016
+ }
8017
+ if (entry.type === "message" && entry.message.role === "assistant") {
8018
+ const message2 = entry.message;
8019
+ if (message2.provider === context.model?.provider && message2.model === context.model.id) {
8020
+ result.lastRequest ??= cacheSample(message2.usage, entry.id, entry.timestamp);
8021
+ }
8022
+ } else if (entry.type === "usage" && entry.kind === "cache_warm" && entry.provider === context.model?.provider && entry.model === context.model.id) {
8023
+ const sample = cacheSample(entry.usage, entry.id, entry.timestamp);
8024
+ result.lastRefresh ??= sample;
8025
+ result.maintenance.requests++;
8026
+ const counters = [entry.usage.input, entry.usage.output, entry.usage.cacheRead, entry.usage.cacheWrite];
8027
+ const tokens = counters.reduce((sum, value) => sum + value, 0);
8028
+ if (counters.every(count) && count(tokens) && count(result.maintenance.tokens + tokens)) result.maintenance.tokens += tokens;
8029
+ else result.maintenance.unknownTokenRequests++;
8030
+ const cost = entry.usage.cost?.total;
8031
+ if (price(cost) && price(result.maintenance.reportedCostUsd + cost)) result.maintenance.reportedCostUsd += cost;
8032
+ else result.maintenance.unknownCostRequests++;
8033
+ }
8034
+ const parentId = entry.parentId;
8035
+ entry = parentId ? manager.getEntry(parentId) : void 0;
8036
+ if (parentId && !entry) result.window.stoppedAt = "missing-parent";
8037
+ }
8038
+ result.window.truncated = Boolean(entry) && result.window.stoppedAt === null;
8039
+ return result;
8040
+ }
8041
+
8042
+ // src/providers/cache-provider.ts
8043
+ var target = { type: "string", enum: ["self", "main"], description: "Local session only. main is accepted only in the root Pi runtime; never routes to another process." };
8044
+ var statusSchema = { type: "object", properties: { target }, additionalProperties: false };
8045
+ var holdSchema = {
8046
+ type: "object",
8047
+ required: ["durationMs"],
8048
+ additionalProperties: false,
8049
+ properties: {
8050
+ target,
8051
+ durationMs: { type: "integer", minimum: 1e3, maximum: MAX_CACHE_LEASE_MS },
8052
+ maxRefreshes: { type: "integer", minimum: 1, maximum: 1e3, description: "Currently unsupported: specifying this bound rejects acquisition, never silently ignores it." },
8053
+ maxCostUsd: { type: "number", exclusiveMinimum: 0, maximum: 1e3, description: "Currently unsupported: specifying this bound rejects acquisition, never silently ignores it." }
8054
+ }
8055
+ };
8056
+ var descriptors2 = [
8057
+ {
8058
+ name: "status",
8059
+ description: "Observe local prompt-cache usage from a bounded active-branch window and inspect Fabric leases. Past cache reads and held leases never prove cache residency. No warming requests or settings changes.",
8060
+ inputSchema: statusSchema,
8061
+ risk: "read",
8062
+ effect: { kind: "none", resources: ["pi:prompt-cache"], ordering: "commutative" }
8063
+ },
8064
+ {
8065
+ name: "hold",
8066
+ description: "Opt into a time-bounded local idle-warming lease. May incur paid native requests; Pi retains eligibility and economic policy. Unsupported SDKs or requested cost/count caps return unsupported without fallback. Survives successful fabric_exec until release, expiry, or invalidation; not restart-durable.",
8067
+ inputSchema: holdSchema,
8068
+ risk: "agent",
8069
+ effect: { kind: "emission", resources: ["pi:prompt-cache"], ordering: "ordered" }
8070
+ },
8071
+ {
8072
+ name: "release",
8073
+ description: "Idempotently release a session-owned cache hold. Does not disable native settings or another owner's interest, or undo already-billed refreshes. Component leases are scope-owned.",
8074
+ inputSchema: { type: "object", properties: { id: { type: "string", minLength: 1, maxLength: 128 } }, required: ["id"], additionalProperties: false },
8075
+ risk: "write",
8076
+ effect: { kind: "emission", resources: ["pi:prompt-cache"], ordering: "ordered" }
8077
+ },
8078
+ {
8079
+ name: "lease",
8080
+ description: "Host-component scoped cache hold; use context.acquire, not tools.call. Disposal releases only this interest; paid usage is irreversible. Same native capability and bounds as cache.hold.",
8081
+ inputSchema: holdSchema,
8082
+ risk: "agent",
8083
+ effect: { kind: "scoped", resources: ["pi:prompt-cache"], ordering: "ordered" }
8084
+ }
8085
+ ];
8086
+ function checked(action, args) {
8087
+ const descriptor = descriptors2.find((candidate) => candidate.name === action);
8088
+ if (!descriptor) throw new Error(`Unknown cache action: ${action}`);
8089
+ const error = validationMessage(descriptor.inputSchema, args);
8090
+ if (error) throw new Error(`Invalid cache.${action} arguments: ${error}`);
8091
+ }
8092
+ var CacheProvider = class {
8093
+ constructor(pi, context, isMain) {
8094
+ this.isMain = isMain;
8095
+ this.#sessionId = context.sessionManager.getSessionId();
8096
+ this.#leases = new CacheLeases(pi, this.#sessionId);
8097
+ }
8098
+ name = "cache";
8099
+ description = "Observed prompt-cache usage and optional native scoped warming; not a key/value or tool-result cache";
8100
+ #leases;
8101
+ #sessionId;
8102
+ async list(request) {
8103
+ const query = request.query?.toLowerCase();
8104
+ return descriptors2.filter((action) => !query || `${action.name} ${action.description}`.toLowerCase().includes(query));
8105
+ }
8106
+ async describe(name) {
8107
+ return descriptors2.find((action) => action.name === name);
8108
+ }
8109
+ #checkContext(args, context) {
8110
+ if (context.extensionContext.sessionManager.getSessionId() !== this.#sessionId) throw new Error("Cache provider belongs to a different session");
8111
+ if (args.target === "main" && !this.isMain) throw new Error("Main cache is not local to this runtime; use self for this child session");
8112
+ }
8113
+ async invoke(name, args, context) {
8114
+ if (!["status", "hold", "release"].includes(name)) throw new Error(name === "lease" ? "cache.lease requires component context.acquire" : `Unknown cache action: ${name}`);
8115
+ checked(name, args);
8116
+ this.#checkContext(args, context);
8117
+ const host = context.extensionContext;
8118
+ if (name === "release") return this.#leases.release(args.id);
8119
+ if (name === "hold") return this.#hold(args, context, "session");
8120
+ const supported = this.#leases.supported(host);
8121
+ const result = {
8122
+ target: "self",
8123
+ sessionId: this.#sessionId,
8124
+ model: host.model ? `${host.model.provider}/${host.model.id}` : null,
8125
+ supported,
8126
+ reason: supported ? null : "Native scoped cache warming is unavailable; observations remain available",
8127
+ limits: { durationMs: true, maxRefreshes: false, maxCostUsd: false },
8128
+ leases: this.#leases.values(),
8129
+ scheduled: null,
8130
+ cleanupError: this.#leases.cleanupError,
8131
+ observation: observePromptCache(host)
8132
+ };
8133
+ return result;
8134
+ }
8135
+ #hold(args, context, scope) {
8136
+ const result = this.#leases.hold(
8137
+ args,
8138
+ context.extensionContext,
8139
+ scope,
8140
+ context.parentToolCallId,
8141
+ context.signal
8142
+ );
8143
+ context.activity?.({ type: "progress", message: result.status === "held" ? "Native cache-warming interest held; not proof of refresh or cache residency" : result.reason });
8144
+ return result;
8145
+ }
8146
+ async acquire(name, args, context) {
8147
+ if (name !== "lease") throw new Error(`Not a scoped cache action: ${name}`);
8148
+ checked(name, args);
8149
+ this.#checkContext(args, context);
8150
+ const result = this.#hold(args, context, "component");
8151
+ return { value: result, dispose: () => {
8152
+ if (result.status === "held") this.#leases.dispose(result.id);
8153
+ } };
8154
+ }
8155
+ async invocationEnded(id) {
8156
+ this.#leases.invocationEnded(id);
8157
+ }
8158
+ async close() {
8159
+ this.#leases.close();
8160
+ }
8161
+ };
8162
+
7806
8163
  // src/providers/prewalk-provider.ts
7807
8164
  var emptySchema2 = { type: "object", properties: {}, additionalProperties: false };
7808
- var descriptors2 = [
8165
+ var descriptors3 = [
7809
8166
  {
7810
8167
  name: "plan",
7811
8168
  description: "Record the approach the executor will follow: the outcome, the ordered steps with the exact files and checks, how each step is verified, and the risks. An armed session owes this before its mutation boundary hands off; Fabric delivers the recorded plan directly in the executor continuation or task, even if this action's return is discarded.",
@@ -7819,7 +8176,7 @@ var descriptors2 = [
7819
8176
  risk: "read"
7820
8177
  }
7821
8178
  ];
7822
- var normalizePrewalkArgs = actionArgNormalizer(() => descriptors2);
8179
+ var normalizePrewalkArgs = actionArgNormalizer(() => descriptors3);
7823
8180
  var PrewalkProvider = class {
7824
8181
  constructor(controller, options = {}) {
7825
8182
  this.controller = controller;
@@ -7829,12 +8186,12 @@ var PrewalkProvider = class {
7829
8186
  description = "Frontier-first handoff readiness: record the plan an executor inherits";
7830
8187
  async list(request, _context) {
7831
8188
  const query = request.query?.toLowerCase();
7832
- return query ? descriptors2.filter(
8189
+ return query ? descriptors3.filter(
7833
8190
  (descriptor) => `${descriptor.name} ${descriptor.description}`.toLowerCase().includes(query)
7834
- ) : descriptors2;
8191
+ ) : descriptors3;
7835
8192
  }
7836
8193
  async describe(actionName, _context) {
7837
- return descriptors2.find((descriptor) => descriptor.name === actionName);
8194
+ return descriptors3.find((descriptor) => descriptor.name === actionName);
7838
8195
  }
7839
8196
  prepareArguments(actionName, args) {
7840
8197
  return normalizePrewalkArgs(actionName, args);
@@ -7898,7 +8255,7 @@ var changeProperties = {
7898
8255
  remove: { type: "array", items: { type: "string" }, maxItems: 256 },
7899
8256
  reset: { type: "array", items: { type: "string" }, maxItems: 256, description: "Session only: remove overlays and use trusted file configuration for these IDs." }
7900
8257
  };
7901
- var descriptors3 = [
8258
+ var descriptors4 = [
7902
8259
  {
7903
8260
  name: "list",
7904
8261
  description: "List registered component definitions and configured component instances.",
@@ -7974,16 +8331,16 @@ var ComponentsProvider = class {
7974
8331
  description = "Supervised component lifecycle, exact capability dependencies, effect cleanup, and reload diagnostics.";
7975
8332
  async list(request, _context) {
7976
8333
  const query = request.query?.normalize("NFKC").trim().toLowerCase();
7977
- const filtered = query ? descriptors3.filter(
8334
+ const filtered = query ? descriptors4.filter(
7978
8335
  (descriptor) => `${descriptor.name} ${descriptor.description}`.toLowerCase().includes(query)
7979
- ) : descriptors3;
8336
+ ) : descriptors4;
7980
8337
  return filtered.slice(0, Math.max(1, Math.min(request.limit ?? 100, 100)));
7981
8338
  }
7982
8339
  async describe(actionName, _context) {
7983
- return descriptors3.find((descriptor) => descriptor.name === actionName);
8340
+ return descriptors4.find((descriptor) => descriptor.name === actionName);
7984
8341
  }
7985
8342
  async invoke(actionName, args, context) {
7986
- const descriptor = descriptors3.find((action) => action.name === actionName);
8343
+ const descriptor = descriptors4.find((action) => action.name === actionName);
7987
8344
  if (descriptor) {
7988
8345
  const invalid = validationMessage(descriptor.inputSchema, args);
7989
8346
  if (invalid) throw new Error(`Invalid components.${actionName} arguments: ${invalid}`);
@@ -8087,9 +8444,9 @@ var CapturedToolsProvider = class {
8087
8444
  #allowedTools = readChildToolAllowlist();
8088
8445
  async list(request, _context) {
8089
8446
  const query = request.query?.trim().toLowerCase();
8090
- const descriptors8 = this.catalog.list().filter((entry) => !this.#allowedTools || this.#allowedTools.has(entry.name)).map(descriptorFrom);
8091
- if (!query) return descriptors8;
8092
- return descriptors8.filter(
8447
+ const descriptors9 = this.catalog.list().filter((entry) => !this.#allowedTools || this.#allowedTools.has(entry.name)).map(descriptorFrom);
8448
+ if (!query) return descriptors9;
8449
+ return descriptors9.filter(
8093
8450
  (descriptor) => `${descriptor.name} ${descriptor.description} ${descriptor.namespace ?? ""}`.toLowerCase().includes(query)
8094
8451
  );
8095
8452
  }
@@ -8235,7 +8592,7 @@ var assertReadableStateKey = (key) => {
8235
8592
  throw new Error(`Fabric mesh key is private host state: ${key}`);
8236
8593
  }
8237
8594
  };
8238
- var descriptors4 = [
8595
+ var descriptors5 = [
8239
8596
  {
8240
8597
  name: "self",
8241
8598
  description: "Return this Fabric participant's mesh identity",
@@ -8354,7 +8711,7 @@ var descriptors4 = [
8354
8711
  namespace: "coordination"
8355
8712
  }
8356
8713
  ];
8357
- var normalizeMeshArgs = actionArgNormalizer(() => descriptors4);
8714
+ var normalizeMeshArgs = actionArgNormalizer(() => descriptors5);
8358
8715
  var MeshProvider = class {
8359
8716
  constructor(store, identity, participants) {
8360
8717
  this.store = store;
@@ -8365,12 +8722,12 @@ var MeshProvider = class {
8365
8722
  description = "Durable topics and compare-and-swap shared state for emergent agent coordination";
8366
8723
  async list(request, _context) {
8367
8724
  const query = request.query?.toLowerCase();
8368
- return query ? descriptors4.filter(
8725
+ return query ? descriptors5.filter(
8369
8726
  (descriptor) => `${descriptor.name} ${descriptor.description}`.toLowerCase().includes(query)
8370
- ) : descriptors4;
8727
+ ) : descriptors5;
8371
8728
  }
8372
8729
  async describe(actionName, _context) {
8373
- return descriptors4.find((descriptor) => descriptor.name === actionName);
8730
+ return descriptors5.find((descriptor) => descriptor.name === actionName);
8374
8731
  }
8375
8732
  prepareArguments(actionName, args) {
8376
8733
  return normalizeMeshArgs(actionName, args);
@@ -8929,10 +9286,10 @@ var PiToolsProvider = class {
8929
9286
  }
8930
9287
  async list(request, _context) {
8931
9288
  const query = request.query?.toLowerCase();
8932
- const descriptors8 = await Promise.all(
9289
+ const descriptors9 = await Promise.all(
8933
9290
  PI_CORE_TOOL_NAMES.map((name) => this.describe(name, _context))
8934
9291
  );
8935
- return descriptors8.filter((descriptor) => descriptor !== void 0).filter(
9292
+ return descriptors9.filter((descriptor) => descriptor !== void 0).filter(
8936
9293
  (descriptor) => query ? `${descriptor.name} ${descriptor.description}`.toLowerCase().includes(query) : true
8937
9294
  );
8938
9295
  }
@@ -9390,7 +9747,7 @@ var watchSchema = { ...waitSchema, properties: {
9390
9747
  ...waitSchema.properties,
9391
9748
  after: { type: "integer", minimum: 0, maximum: Number.MAX_SAFE_INTEGER, description: "Previously returned nextCursor; default 0. Missing retained events are disclosed as omitted." }
9392
9749
  } };
9393
- var descriptors5 = [
9750
+ var descriptors6 = [
9394
9751
  { name: "list", description: "List this session's tracked shell tasks and monitors, with IDs, command, cwd, state, timestamps, and bounded monitor events. No output polling is needed: detached completions notify the owning agent.", inputSchema: { type: "object", properties: {}, additionalProperties: false }, risk: "read", effect: { kind: "none", ordering: "commutative" } },
9395
9752
  { name: "get", description: "Inspect one shell task by ID, returning metadata and a bounded output tail. Acknowledges its pending notification after a successful read. Full retained output is at logPath (bounded, not an archive).", inputSchema: idSchema, risk: "read", effect: { kind: "emission", ordering: "ordered" } },
9396
9753
  { name: "wait", description: "Wait without polling for a session-owned shell task to finish, default 30 seconds. Returns task metadata, a bounded output tail and timedOut. Inspect status and exitCode; an exited task is not goal verification. Timeout or cancellation stops only this wait.", inputSchema: waitSchema, risk: "read", effect: { kind: "emission", ordering: "ordered" } },
@@ -9405,10 +9762,10 @@ var TasksProvider = class {
9405
9762
  description = "Session-owned shell orchestration with bounded wait/watch and explicit stop";
9406
9763
  async list(request) {
9407
9764
  const query = request.query?.toLowerCase();
9408
- return query ? descriptors5.filter((d) => `${d.name} ${d.description}`.toLowerCase().includes(query)) : descriptors5;
9765
+ return query ? descriptors6.filter((d) => `${d.name} ${d.description}`.toLowerCase().includes(query)) : descriptors6;
9409
9766
  }
9410
9767
  async describe(name) {
9411
- return descriptors5.find((d) => d.name === name);
9768
+ return descriptors6.find((d) => d.name === name);
9412
9769
  }
9413
9770
  async invoke(name, args, context) {
9414
9771
  const descriptor = await this.describe(name);
@@ -9424,14 +9781,14 @@ var TasksProvider = class {
9424
9781
  if (!job.options.monitor) throw new Error("tasks.watch requires a task started with monitor; use tasks.wait for ordinary tasks");
9425
9782
  const after2 = args.after ?? 0;
9426
9783
  const { task, timedOut } = await this.jobs.waitFor(id, { after: after2, timeoutMs: args.timeoutMs ?? 5e3, signal: context.signal });
9427
- const count = task.eventCount - after2;
9784
+ const count2 = task.eventCount - after2;
9428
9785
  const retained = task.lastEvent?.lines ?? [];
9429
- const lines = count > 0 ? retained.slice(-Math.min(count, retained.length)) : [];
9786
+ const lines = count2 > 0 ? retained.slice(-Math.min(count2, retained.length)) : [];
9430
9787
  return {
9431
9788
  task,
9432
- reason: count > 0 ? "event" : timedOut ? "timeout" : "finished",
9789
+ reason: count2 > 0 ? "event" : timedOut ? "timeout" : "finished",
9433
9790
  lines,
9434
- omitted: Math.max(0, count - lines.length),
9791
+ omitted: Math.max(0, count2 - lines.length),
9435
9792
  nextCursor: task.eventCount
9436
9793
  };
9437
9794
  }
@@ -9445,7 +9802,7 @@ var TasksProvider = class {
9445
9802
  };
9446
9803
 
9447
9804
  // src/state/store.ts
9448
- import { createHash as createHash3 } from "node:crypto";
9805
+ import { createHash as createHash4 } from "node:crypto";
9449
9806
  import path11 from "node:path";
9450
9807
 
9451
9808
  // src/state/complexity.ts
@@ -9642,7 +9999,7 @@ var countTypeScriptJavaScript = (source) => {
9642
9999
  const tokens = tokenize(source);
9643
10000
  const switchBodies = [];
9644
10001
  let waitingForSwitchBody = false;
9645
- let count = 0;
10002
+ let count2 = 0;
9646
10003
  for (let index = 0; index < tokens.length; index++) {
9647
10004
  const token = tokens[index]?.value;
9648
10005
  if (token === "switch") waitingForSwitchBody = true;
@@ -9656,22 +10013,22 @@ var countTypeScriptJavaScript = (source) => {
9656
10013
  continue;
9657
10014
  }
9658
10015
  if ((token === "if" || token === "for" || token === "while") && followedBy(tokens, index, "(")) {
9659
- count++;
10016
+ count2++;
9660
10017
  continue;
9661
10018
  }
9662
10019
  if (token === "catch" && (followedBy(tokens, index, "(") || followedBy(tokens, index, "{"))) {
9663
- count++;
10020
+ count2++;
9664
10021
  continue;
9665
10022
  }
9666
10023
  if (switchBodies[switchBodies.length - 1] === true) {
9667
10024
  if (token === "default" && followedBy(tokens, index, ":")) {
9668
- count++;
10025
+ count2++;
9669
10026
  } else if (token === "case") {
9670
- count++;
10027
+ count2++;
9671
10028
  }
9672
10029
  }
9673
10030
  }
9674
- return count;
10031
+ return count2;
9675
10032
  };
9676
10033
  var typeScriptJavaScriptComplexity = {
9677
10034
  language: "typescript/javascript",
@@ -9697,7 +10054,7 @@ var countFileComplexity = (file) => {
9697
10054
 
9698
10055
  // src/state/evidence-runner.ts
9699
10056
  import { spawn } from "node:child_process";
9700
- import { createHash as createHash2 } from "node:crypto";
10057
+ import { createHash as createHash3 } from "node:crypto";
9701
10058
  var COMMAND_OUTPUT_MAX_BYTES = 32 * 1024;
9702
10059
  var errorMessage4 = (error) => error instanceof Error ? error.message : String(error);
9703
10060
  var truncateUtf82 = (value, maxBytes) => {
@@ -9764,7 +10121,7 @@ var runCommand = (command, options) => new Promise((resolve2) => {
9764
10121
  let outputBytes = 0;
9765
10122
  const outputChunks = [];
9766
10123
  let retainedBytes = 0;
9767
- const outputHash = createHash2("sha256");
10124
+ const outputHash = createHash3("sha256");
9768
10125
  let timer;
9769
10126
  let terminationReason;
9770
10127
  let termination;
@@ -9884,7 +10241,7 @@ var toStringArray = (value) => {
9884
10241
  }
9885
10242
  return items.length > 0 ? items : void 0;
9886
10243
  };
9887
- var digest = (value) => `sha256:${createHash3("sha256").update(JSON.stringify(value)).digest("hex")}`;
10244
+ var digest = (value) => `sha256:${createHash4("sha256").update(JSON.stringify(value)).digest("hex")}`;
9888
10245
  var truncateUtf83 = (value, maxBytes) => {
9889
10246
  const bytes = Buffer.from(value, "utf8");
9890
10247
  if (bytes.length <= maxBytes) return { value, omittedBytes: 0 };
@@ -9994,14 +10351,14 @@ var toHeadRecord = (head) => {
9994
10351
  };
9995
10352
  var toCertificationTarget = (value) => {
9996
10353
  if (!value || typeof value !== "object") return void 0;
9997
- const target = value;
9998
- if (typeof target.transitionId !== "string" || typeof target.label !== "string" || typeof target.to !== "string") {
10354
+ const target2 = value;
10355
+ if (typeof target2.transitionId !== "string" || typeof target2.label !== "string" || typeof target2.to !== "string") {
9999
10356
  return void 0;
10000
10357
  }
10001
10358
  return {
10002
- transitionId: target.transitionId,
10003
- label: target.label,
10004
- to: target.to
10359
+ transitionId: target2.transitionId,
10360
+ label: target2.label,
10361
+ to: target2.to
10005
10362
  };
10006
10363
  };
10007
10364
  var toCertificationHead = (value) => {
@@ -10026,14 +10383,14 @@ var verificationTargets = (event) => {
10026
10383
  if (event.kind !== "state.certified" && event.kind !== "state.violated") return [];
10027
10384
  const data = event.data;
10028
10385
  if (!data || !Array.isArray(data.targets)) return [];
10029
- return data.targets.map(toCertificationTarget).filter((target) => target !== void 0);
10386
+ return data.targets.map(toCertificationTarget).filter((target2) => target2 !== void 0);
10030
10387
  };
10031
10388
  var latestTransitionOutcomes = (events) => {
10032
10389
  const latest = /* @__PURE__ */ new Map();
10033
10390
  for (const event of events) {
10034
10391
  if (event.kind !== "state.certified" && event.kind !== "state.violated") continue;
10035
- for (const target of verificationTargets(event)) {
10036
- latest.set(target.transitionId, {
10392
+ for (const target2 of verificationTargets(event)) {
10393
+ latest.set(target2.transitionId, {
10037
10394
  event,
10038
10395
  phase: event.kind === "state.certified" ? "certified" : "violated"
10039
10396
  });
@@ -10047,10 +10404,10 @@ var toCertificate = (event, currentHead, latestOutcomes) => {
10047
10404
  if (!data || !Array.isArray(data.targets) || typeof data.evidenceDigest !== "string" || typeof data.resultDigest !== "string") {
10048
10405
  return void 0;
10049
10406
  }
10050
- const targets = data.targets.map(toCertificationTarget).filter((target) => target !== void 0);
10407
+ const targets = data.targets.map(toCertificationTarget).filter((target2) => target2 !== void 0);
10051
10408
  if (targets.length === 0) return void 0;
10052
10409
  const head = toCertificationHead(data.head);
10053
- const currentTarget = currentHead === null ? void 0 : targets.find((target) => target.transitionId === currentHead.transitionId);
10410
+ const currentTarget = currentHead === null ? void 0 : targets.find((target2) => target2.transitionId === currentHead.transitionId);
10054
10411
  const latestCurrentOutcome = currentTarget ? latestOutcomes?.get(currentTarget.transitionId) : void 0;
10055
10412
  const current = head !== null && currentHead !== null && currentTarget !== void 0 && head.transitionId === currentHead.transitionId && (head.labelDigest ? head.labelDigest === digest(currentHead.label) : head.label === currentHead.label) && (head.toDigest ? head.toDigest === digest(currentHead.to) : head.to === currentHead.to) && head.version === currentHead.version && (latestCurrentOutcome === void 0 || latestCurrentOutcome.phase === "certified" && latestCurrentOutcome.event.sequence === event.sequence);
10056
10413
  return {
@@ -10071,12 +10428,12 @@ var durableCurrentCertificate = (head, latestOutcomes) => {
10071
10428
  return void 0;
10072
10429
  }
10073
10430
  const certificateHead = toCertificationHead(certificate.head);
10074
- const targets = certificate.targets.map(toCertificationTarget).filter((target2) => target2 !== void 0);
10075
- const target = targets.find(
10431
+ const targets = certificate.targets.map(toCertificationTarget).filter((target3) => target3 !== void 0);
10432
+ const target2 = targets.find(
10076
10433
  (item) => item.transitionId === head.transitionId && item.label === head.label && item.to === head.to
10077
10434
  );
10078
10435
  const latestOutcome = latestOutcomes?.get(head.transitionId);
10079
- if (!target || certificateHead === null || certificateHead.transitionId !== head.transitionId || (certificateHead.labelDigest ? certificateHead.labelDigest !== digest(head.label) : certificateHead.label !== head.label) || (certificateHead.toDigest ? certificateHead.toDigest !== digest(head.to) : certificateHead.to !== head.to) || certificateHead.version !== head.version || latestOutcome !== void 0 && (latestOutcome.phase !== "certified" || latestOutcome.event.sequence !== certificate.sequence)) {
10436
+ if (!target2 || certificateHead === null || certificateHead.transitionId !== head.transitionId || (certificateHead.labelDigest ? certificateHead.labelDigest !== digest(head.label) : certificateHead.label !== head.label) || (certificateHead.toDigest ? certificateHead.toDigest !== digest(head.to) : certificateHead.to !== head.to) || certificateHead.version !== head.version || latestOutcome !== void 0 && (latestOutcome.phase !== "certified" || latestOutcome.event.sequence !== certificate.sequence)) {
10080
10437
  return void 0;
10081
10438
  }
10082
10439
  return {
@@ -10518,7 +10875,7 @@ var StateStore = class {
10518
10875
  const visibleIds = new Set(visibleRecords.map((record) => record.transitionId));
10519
10876
  const latestOutcomes = latestTransitionOutcomes(events);
10520
10877
  const eventCertifications = events.map((event) => toCertificate(event, currentHead, latestOutcomes)).filter((certificate) => certificate !== void 0).filter(
10521
- (certificate) => certificate.targets.every((target) => visibleIds.has(target.transitionId))
10878
+ (certificate) => certificate.targets.every((target2) => visibleIds.has(target2.transitionId))
10522
10879
  ).reverse();
10523
10880
  const durableCertificate = currentHead ? durableCurrentCertificate(currentHead, latestOutcomes) : void 0;
10524
10881
  const certifications = durableCertificate ? [
@@ -10562,7 +10919,7 @@ var StateStore = class {
10562
10919
  transitions: limited,
10563
10920
  labels: [...labelSet],
10564
10921
  certifications: certifications.filter(
10565
- (certificate) => certificate.targets.some((target) => limitedIds.has(target.transitionId))
10922
+ (certificate) => certificate.targets.some((target2) => limitedIds.has(target2.transitionId))
10566
10923
  )
10567
10924
  };
10568
10925
  }
@@ -10792,17 +11149,17 @@ var StateStore = class {
10792
11149
  } else {
10793
11150
  targets = [];
10794
11151
  }
10795
- const certificationTargets = targets.map((target) => ({
10796
- transitionId: target.transitionId,
10797
- label: target.label,
10798
- to: target.to
11152
+ const certificationTargets = targets.map((target2) => ({
11153
+ transitionId: target2.transitionId,
11154
+ label: target2.label,
11155
+ to: target2.to
10799
11156
  }));
10800
11157
  const evidenceDigest = digest(
10801
- targets.map((target) => ({
10802
- transitionId: target.transitionId,
10803
- label: target.label,
10804
- to: target.to,
10805
- evidence: target.evidence ?? []
11158
+ targets.map((target2) => ({
11159
+ transitionId: target2.transitionId,
11160
+ label: target2.label,
11161
+ to: target2.to,
11162
+ evidence: target2.evidence ?? []
10806
11163
  }))
10807
11164
  );
10808
11165
  const results = [];
@@ -10813,14 +11170,14 @@ var StateStore = class {
10813
11170
  message: input.labels === void 0 ? "No current state transition is available to verify" : "No active state transitions matched the requested labels"
10814
11171
  });
10815
11172
  }
10816
- for (const target of targets) {
10817
- const evidence = target.evidence ?? [];
11173
+ for (const target2 of targets) {
11174
+ const evidence = target2.evidence ?? [];
10818
11175
  if (evidence.length === 0) {
10819
11176
  failures.push({
10820
11177
  reason: "missing-evidence",
10821
- message: `Transition "${target.label}" has no executable evidence`,
10822
- transitionId: target.transitionId,
10823
- label: target.label
11178
+ message: `Transition "${target2.label}" has no executable evidence`,
11179
+ transitionId: target2.transitionId,
11180
+ label: target2.label
10824
11181
  });
10825
11182
  }
10826
11183
  for (const command of evidence) {
@@ -10837,7 +11194,7 @@ var StateStore = class {
10837
11194
  timeoutMs: input.timeoutMs ?? 3e4,
10838
11195
  ...input.signal ? { signal: input.signal } : {}
10839
11196
  });
10840
- results.push(toVerifyResult(target.summary, command, result));
11197
+ results.push(toVerifyResult(target2.summary, command, result));
10841
11198
  }
10842
11199
  }
10843
11200
  for (const result of results) {
@@ -10853,10 +11210,10 @@ var StateStore = class {
10853
11210
  }
10854
11211
  let certified = results.length > 0 && failures.length === 0 && results.every((result) => result.status === "confirmed");
10855
11212
  let resultDigest = digest({ results, failures });
10856
- const boundedTargets = certificationTargets.map((target) => ({
10857
- transitionId: truncateUtf83(target.transitionId, EVENT_TEXT_MAX_BYTES).value,
10858
- label: truncateUtf83(target.label, EVENT_TEXT_MAX_BYTES).value,
10859
- to: truncateUtf83(target.to, EVENT_TEXT_MAX_BYTES).value
11213
+ const boundedTargets = certificationTargets.map((target2) => ({
11214
+ transitionId: truncateUtf83(target2.transitionId, EVENT_TEXT_MAX_BYTES).value,
11215
+ label: truncateUtf83(target2.label, EVENT_TEXT_MAX_BYTES).value,
11216
+ to: truncateUtf83(target2.to, EVENT_TEXT_MAX_BYTES).value
10860
11217
  }));
10861
11218
  const targetChunks = [];
10862
11219
  for (let index = 0; index < boundedTargets.length; index += EVENT_TARGET_LIMIT) {
@@ -10864,7 +11221,7 @@ var StateStore = class {
10864
11221
  }
10865
11222
  if (targetChunks.length === 0) targetChunks.push([]);
10866
11223
  const targetsCurrentHead = verificationHead !== null && certificationTargets.some(
10867
- (target) => target.transitionId === verificationHead.transitionId
11224
+ (target2) => target2.transitionId === verificationHead.transitionId
10868
11225
  );
10869
11226
  const publishViolation = async () => {
10870
11227
  const nonConfirmed = results.filter((result) => result.status !== "confirmed");
@@ -10940,7 +11297,7 @@ var StateStore = class {
10940
11297
  }
10941
11298
  });
10942
11299
  if (certificateEvent === void 0 || targetChunks[index]?.some(
10943
- (target) => target.transitionId === headIdentity?.transitionId
11300
+ (target2) => target2.transitionId === headIdentity?.transitionId
10944
11301
  )) {
10945
11302
  certificateEvent = event;
10946
11303
  }
@@ -11094,7 +11451,7 @@ var checkGoalSchema = {
11094
11451
  additionalProperties: false
11095
11452
  };
11096
11453
  var emptySchema4 = { type: "object", properties: {}, additionalProperties: false };
11097
- var descriptors6 = [
11454
+ var descriptors7 = [
11098
11455
  {
11099
11456
  name: "transition",
11100
11457
  description: "Append a labeled, validated state transition and compare-and-swap advance the head",
@@ -11145,7 +11502,7 @@ var descriptors6 = [
11145
11502
  namespace: "state"
11146
11503
  }
11147
11504
  ];
11148
- var normalizeStateArgs = actionArgNormalizer(() => descriptors6);
11505
+ var normalizeStateArgs = actionArgNormalizer(() => descriptors7);
11149
11506
  var StateProvider = class {
11150
11507
  name = "state";
11151
11508
  description = "Schema-style labeled transition layer: an append-only timeline of validated transitions with a compare-and-swap head and evidence-based certification over mesh storage";
@@ -11160,12 +11517,12 @@ var StateProvider = class {
11160
11517
  }
11161
11518
  async list(request, _context) {
11162
11519
  const query = request.query?.toLowerCase();
11163
- return query ? descriptors6.filter(
11520
+ return query ? descriptors7.filter(
11164
11521
  (descriptor) => `${descriptor.name} ${descriptor.description}`.toLowerCase().includes(query)
11165
- ) : descriptors6;
11522
+ ) : descriptors7;
11166
11523
  }
11167
11524
  async describe(actionName, _context) {
11168
- return descriptors6.find((descriptor) => descriptor.name === actionName);
11525
+ return descriptors7.find((descriptor) => descriptor.name === actionName);
11169
11526
  }
11170
11527
  prepareArguments(actionName, args) {
11171
11528
  return normalizeStateArgs(actionName, args);
@@ -11387,12 +11744,14 @@ var RuntimeStateBuiltins = class {
11387
11744
  await this.install(createProviderComponent({ provider: "memory", description: "Managed current-session recall", create: () => this.managedHost.provider("memory") }));
11388
11745
  } else if (config.memory.enabled) {
11389
11746
  const sessionFile = context.sessionManager.getSessionFile();
11747
+ const sources = config.memory.sources && config.memory.sources.length > 0 ? createConfiguredMemorySourceRegistry(config.memory.sources) : void 0;
11390
11748
  const memoryContext = {
11391
11749
  agentDir: resolveAgentDir(),
11392
11750
  cwd: context.cwd,
11393
11751
  config: config.memory,
11394
11752
  sessionId,
11395
11753
  ...sessionFile ? { sessionFile } : {},
11754
+ ...sources ? { sources } : {},
11396
11755
  getLiveBranch: () => ({
11397
11756
  entries: context.sessionManager.getBranch(),
11398
11757
  leafId: context.sessionManager.getLeafId()
@@ -11418,6 +11777,7 @@ var RuntimeStateBuiltins = class {
11418
11777
  ...config.mesh.enabled ? ["mesh", "state"] : ["mesh", "state"].filter((name) => this.managedHost?.has(name)),
11419
11778
  "schema",
11420
11779
  "compact",
11780
+ ...!this.managedHost ? ["cache"] : [],
11421
11781
  "prewalk",
11422
11782
  "agents",
11423
11783
  ...!this.managedHost && config.jev.enabled && config.schema.mode !== "enforce" ? ["jev"] : [],
@@ -11429,7 +11789,7 @@ var RuntimeStateBuiltins = class {
11429
11789
 
11430
11790
  // src/schema/controller.ts
11431
11791
  import { spawn as spawn2 } from "node:child_process";
11432
- import { createHash as createHash5, randomBytes, randomUUID as randomUUID5 } from "node:crypto";
11792
+ import { createHash as createHash6, randomBytes, randomUUID as randomUUID6 } from "node:crypto";
11433
11793
  import fs9 from "node:fs";
11434
11794
  import path13 from "node:path";
11435
11795
 
@@ -11438,7 +11798,7 @@ var stateBinding = (head) => head ? { transitionId: head.transitionId, version:
11438
11798
 
11439
11799
  // src/schema/workspace.ts
11440
11800
  import { execFileSync } from "node:child_process";
11441
- import { createHash as createHash4 } from "node:crypto";
11801
+ import { createHash as createHash5 } from "node:crypto";
11442
11802
  import fs8 from "node:fs";
11443
11803
  import path12 from "node:path";
11444
11804
  var SNAPSHOT_MAX_FILES = 2e4;
@@ -11451,7 +11811,7 @@ var FALLBACK_SKIPPED_DIRECTORIES = /* @__PURE__ */ new Set([
11451
11811
  "coverage",
11452
11812
  ".cache"
11453
11813
  ]);
11454
- var digest2 = (value) => createHash4("sha256").update(value).digest("hex");
11814
+ var digest2 = (value) => createHash5("sha256").update(value).digest("hex");
11455
11815
  var git = (cwd, args) => execFileSync("git", ["-C", cwd, ...args], {
11456
11816
  encoding: "buffer",
11457
11817
  maxBuffer: 128 * 1024 * 1024,
@@ -11619,7 +11979,7 @@ var WORKSPACE_KEY = "schema/workspace";
11619
11979
  var HYPOTHESIS_PREFIX = "schema/hypothesis/";
11620
11980
  var CERTIFICATE_PREFIX = "schema/certificate/";
11621
11981
  var OUTPUT_LIMIT = 64 * 1024;
11622
- var hashToken = (token) => createHash5("sha256").update(token).digest("hex");
11982
+ var hashToken = (token) => createHash6("sha256").update(token).digest("hex");
11623
11983
  var sameBinding = (left, right) => JSON.stringify(left) === JSON.stringify(right);
11624
11984
  var errorMessage6 = (error) => error instanceof Error ? error.message : String(error);
11625
11985
  var atomicJsonWrite = (filePath, value) => {
@@ -11691,7 +12051,7 @@ var SchemaController = class {
11691
12051
  const generation = this.#generation();
11692
12052
  const now = Date.now();
11693
12053
  const record = {
11694
- id: randomUUID5(),
12054
+ id: randomUUID6(),
11695
12055
  label: input.label,
11696
12056
  summary: input.summary,
11697
12057
  evidence: input.evidence,
@@ -11833,7 +12193,7 @@ var SchemaController = class {
11833
12193
  }
11834
12194
  this.#assertPayloadBound(input);
11835
12195
  const release = this.#acquireCommitLock();
11836
- const transactionId = randomUUID5();
12196
+ const transactionId = randomUUID6();
11837
12197
  const journalPath = path13.join(this.#journalRoot, `${transactionId}.json`);
11838
12198
  let journal;
11839
12199
  let consumed = false;
@@ -12436,7 +12796,7 @@ var operationSchema = {
12436
12796
  }
12437
12797
  ]
12438
12798
  };
12439
- var descriptors7 = [
12799
+ var descriptors8 = [
12440
12800
  {
12441
12801
  name: "status",
12442
12802
  description: "Read the fixed session Schema mode, transaction bounds, generation, and invocation hypotheses",
@@ -12506,7 +12866,7 @@ var descriptors7 = [
12506
12866
  namespace: "schema"
12507
12867
  }
12508
12868
  ];
12509
- var normalizeSchemaArgs = actionArgNormalizer(() => descriptors7);
12869
+ var normalizeSchemaArgs = actionArgNormalizer(() => descriptors8);
12510
12870
  var SchemaProvider = class {
12511
12871
  constructor(controller) {
12512
12872
  this.controller = controller;
@@ -12515,12 +12875,12 @@ var SchemaProvider = class {
12515
12875
  description = "Host-owned, opt-in Schema verification and bounded local-file transaction control plane";
12516
12876
  async list(request, _context) {
12517
12877
  const query = request.query?.toLowerCase();
12518
- return query ? descriptors7.filter(
12878
+ return query ? descriptors8.filter(
12519
12879
  (descriptor) => `${descriptor.name} ${descriptor.description}`.toLowerCase().includes(query)
12520
- ) : descriptors7;
12880
+ ) : descriptors8;
12521
12881
  }
12522
12882
  async describe(actionName, _context) {
12523
- return descriptors7.find((descriptor) => descriptor.name === actionName);
12883
+ return descriptors8.find((descriptor) => descriptor.name === actionName);
12524
12884
  }
12525
12885
  prepareArguments(actionName, args) {
12526
12886
  return normalizeSchemaArgs(actionName, args);
@@ -13150,6 +13510,7 @@ var FabricRuntimeState = class {
13150
13510
  }));
13151
13511
  if (this.#managedHost) {
13152
13512
  this.#registry.markUnavailable("jev", "Jev programs are unavailable in managed hosts");
13513
+ this.#registry.markUnavailable("cache", "Native prompt-cache access is unavailable in managed hosts");
13153
13514
  for (const name of ["agents", "schema", "compact", "memory", "mesh", "state"]) {
13154
13515
  if (["agents", "schema", "compact"].includes(name) || this.#managedHost.has(name)) {
13155
13516
  await builtins.install(createProviderComponent({
@@ -13165,6 +13526,11 @@ var FabricRuntimeState = class {
13165
13526
  }
13166
13527
  const sessionId = context.sessionManager.getSessionId();
13167
13528
  const { identity, mainAgentId } = resolveFabricIdentity(sessionId);
13529
+ await builtins.install(createProviderComponent({
13530
+ provider: "cache",
13531
+ description: "Local prompt-cache observations and scoped native warming",
13532
+ create: () => new CacheProvider(this.pi, context, identity.kind === "main")
13533
+ }));
13168
13534
  const fabricSessionId = process.env.PI_FABRIC_SESSION_ID?.trim() || sessionId;
13169
13535
  const ownsPersistentActorRegistry = identity.kind === "main" && !enforceSchema && projectTrusted && this.#config.mesh.enabled;
13170
13536
  const mainAgent = new MainAgentController(
@@ -14072,16 +14438,16 @@ var lifecycleObservedAt = (payload) => {
14072
14438
  return typeof timestamp === "number" && Number.isFinite(timestamp) ? timestamp : Date.now();
14073
14439
  };
14074
14440
  var isPlainObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
14075
- var deepAssign = (target, source) => {
14076
- for (const key of Object.keys(target)) {
14077
- if (!(key in source)) delete target[key];
14441
+ var deepAssign = (target2, source) => {
14442
+ for (const key of Object.keys(target2)) {
14443
+ if (!(key in source)) delete target2[key];
14078
14444
  }
14079
14445
  for (const [key, value] of Object.entries(source)) {
14080
- const targetValue = target[key];
14446
+ const targetValue = target2[key];
14081
14447
  if (isPlainObject(value) && isPlainObject(targetValue)) {
14082
14448
  deepAssign(targetValue, value);
14083
14449
  } else {
14084
- target[key] = value;
14450
+ target2[key] = value;
14085
14451
  }
14086
14452
  }
14087
14453
  };