@agimon-ai/po-cache 0.0.0-alpha.120 → 0.0.0-alpha.121

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.
@@ -7,8 +7,8 @@ const require_promptCacheTelemetry = require("../promptCacheTelemetry-DeN4LdSo.c
7
7
  let node_crypto = require("node:crypto");
8
8
  let _agimon_ai_po_core_serverPlugin = require("@agimon-ai/po-core/serverPlugin");
9
9
  let _agimon_ai_po_core_extensionFile = require("@agimon-ai/po-core/extensionFile");
10
+ let _agimon_ai_po_config = require("@agimon-ai/po-config");
10
11
  let _agimon_ai_po_core_platform = require("@agimon-ai/po-core/platform");
11
- let _agimon_ai_po_config_harnessStore = require("@agimon-ai/po-config/harnessStore");
12
12
  let _agimon_ai_po_minor_mode = require("@agimon-ai/po-minor-mode");
13
13
  let node_path = require("node:path");
14
14
  let _earendil_works_pi_coding_agent = require("@earendil-works/pi-coding-agent");
@@ -152,9 +152,9 @@ function isErrorMessage(message) {
152
152
  const record = typeof message === "object" && message !== null ? message : void 0;
153
153
  return record?.stopReason === "error" || record?.stopReason === "aborted";
154
154
  }
155
- function createCacheRuntime(dependencies, environment) {
156
- const parentNamespaceEnvironment = new OwnedEnvironmentValue(require_environment.PO_PROMPT_CACHE_PARENT_NAMESPACE_ENV);
157
- const rootSessionEnvironment = new OwnedEnvironmentValue(require_environment.PO_PROMPT_CACHE_ROOT_SESSION_ENV);
155
+ function createCacheRuntime(dependencies, environment, readHarness, namespaceEnvironment) {
156
+ const parentNamespaceEnvironment = new OwnedEnvironmentValue(require_environment.PO_PROMPT_CACHE_PARENT_NAMESPACE_ENV, namespaceEnvironment);
157
+ const rootSessionEnvironment = new OwnedEnvironmentValue(require_environment.PO_PROMPT_CACHE_ROOT_SESSION_ENV, namespaceEnvironment);
158
158
  const projectedParentNamespace = stringValue(environment[require_environment.PO_PROMPT_CACHE_PARENT_NAMESPACE_ENV]);
159
159
  const childProjection = stringValue(environment[require_environment.PO_PROMPT_CACHE_CHILD_PROJECTION_ENV]);
160
160
  const isProjectedChild = Boolean(projectedParentNamespace && childProjection);
@@ -164,7 +164,7 @@ function createCacheRuntime(dependencies, environment) {
164
164
  const refreshParentNamespace = () => {
165
165
  if (isProjectedChild) return parentNamespace;
166
166
  if (!rootSessionId) return void 0;
167
- const harness = (0, _agimon_ai_po_config_harnessStore.getSessionHarnessState)(rootSessionId);
167
+ const harness = readHarness();
168
168
  parentNamespace = require_promptCacheTelemetry.createParentPromptCacheNamespace({
169
169
  rootSessionId,
170
170
  compositionFingerprint: harness.compositionFingerprint,
@@ -214,6 +214,12 @@ function createCacheRuntime(dependencies, environment) {
214
214
  };
215
215
  }
216
216
  //#endregion
217
+ //#region src/services/environment/sync.ts
218
+ /** Node's optimizer integrates with the process-level Pi provider environment. */
219
+ function cacheEnvironment(_environment) {
220
+ return process.env;
221
+ }
222
+ //#endregion
217
223
  //#region src/services/agentDirectory/index.ts
218
224
  /** Pi's agent directory, where the optimizer keeps its state; the edge build swaps in `index.edge.ts`. */
219
225
  function defaultAgentDirectory() {
@@ -3225,6 +3231,15 @@ function createOptimizerSupport(STATE_DIR, environment, fs) {
3225
3231
  };
3226
3232
  }
3227
3233
  //#endregion
3234
+ //#region src/services/nativeOptimizer/sync.ts
3235
+ /** Process metadata used by Node's persisted optimizer shards. */
3236
+ function cacheProcessIdentity() {
3237
+ return {
3238
+ pid: process.pid,
3239
+ ppid: process.ppid
3240
+ };
3241
+ }
3242
+ //#endregion
3228
3243
  //#region src/services/nativeOptimizer/index.ts
3229
3244
  const STATUS_KEY = "pi-cache-stats";
3230
3245
  const PERSIST_DEBOUNCE_MS = 2e3;
@@ -3289,8 +3304,7 @@ function createNativeOptimizer(initial, fs, stateDir = defaultAgentDirectory())
3289
3304
  instanceId,
3290
3305
  sessionHash,
3291
3306
  process: {
3292
- pid: process.pid,
3293
- ppid: process.ppid,
3307
+ ...cacheProcessIdentity(),
3294
3308
  instanceStartedAt
3295
3309
  },
3296
3310
  lifecycle: {
@@ -3522,7 +3536,7 @@ function createNativeOptimizer(initial, fs, stateDir = defaultAgentDirectory())
3522
3536
  handle: (_event, context) => serialized(async () => {
3523
3537
  if (started || closed) return;
3524
3538
  started = true;
3525
- releaseRetention = acquireEnvironmentValue("PI_CACHE_RETENTION", "long");
3539
+ releaseRetention = acquireEnvironmentValue("PI_CACHE_RETENTION", "long", cacheEnvironment(initial.environment));
3526
3540
  await support.refreshFileConfig();
3527
3541
  currentGlobalEpoch = await support.readGlobalStatsEpoch();
3528
3542
  await support.removeLegacyStatsFiles();
@@ -3593,10 +3607,14 @@ function createNativeOptimizer(initial, fs, stateDir = defaultAgentDirectory())
3593
3607
  var root_server_default = (0, _agimon_ai_po_core_extensionFile.defineRoot)(({ agent, context: root }) => {
3594
3608
  if (!agent) throw new Error("Cache statistics require the native session host.");
3595
3609
  const telemetry = new require_promptCacheTelemetry.PromptCacheTelemetry();
3610
+ let config;
3596
3611
  const runtime = createCacheRuntime({
3597
3612
  telemetry,
3598
3613
  now: Date.now
3599
- }, agent.context.environment);
3614
+ }, agent.context.environment, () => {
3615
+ if (!config) throw new Error("Cache requires the session configuration.");
3616
+ return config.getSnapshot().harness;
3617
+ }, cacheEnvironment(agent.context.environment));
3600
3618
  const optimizer = createNativeOptimizer(agent.context, (0, _agimon_ai_po_core_platform.requirePoFs)(root));
3601
3619
  return {
3602
3620
  value: { hooks: optimizer.hooks.map((hook) => {
@@ -3616,9 +3634,20 @@ var root_server_default = (0, _agimon_ai_po_core_extensionFile.defineRoot)(({ ag
3616
3634
  };
3617
3635
  return hook;
3618
3636
  }) },
3619
- services: [(context) => {
3620
- new require_promptCacheTelemetry.PromptCacheTelemetryService(context, telemetry);
3621
- }, runtime.plugin],
3637
+ services: [
3638
+ (context) => {
3639
+ context.inject([_agimon_ai_po_config.PO_CONFIG_SERVICE], (scoped) => {
3640
+ config = scoped.get(_agimon_ai_po_config.PO_CONFIG_SERVICE);
3641
+ return () => {
3642
+ config = void 0;
3643
+ };
3644
+ });
3645
+ },
3646
+ (context) => {
3647
+ new require_promptCacheTelemetry.PromptCacheTelemetryService(context, telemetry);
3648
+ },
3649
+ runtime.plugin
3650
+ ],
3622
3651
  async onDispose() {
3623
3652
  try {
3624
3653
  await optimizer.dispose();
@@ -3627,7 +3656,7 @@ var root_server_default = (0, _agimon_ai_po_core_extensionFile.defineRoot)(({ ag
3627
3656
  }
3628
3657
  }
3629
3658
  };
3630
- });
3659
+ }, { inject: [(0, _agimon_ai_po_core_extensionFile.defineServiceContract)(_agimon_ai_po_config.PO_CONFIG_SERVICE, { scope: "session" })] });
3631
3660
  //#endregion
3632
3661
  //#region src/extensions/workspaces/sessions/(backend)/hook/agent-settled.server.ts
3633
3662
  var agent_settled_server_default = (0, _agimon_ai_po_core_extensionFile.defineHook)((context) => context.root.hooks.find((hook) => hook.event === "agent_settled"));