@massu/core 2.5.4 → 2.5.5

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.
@@ -951,7 +951,8 @@ var init_config = __esm({
951
951
  input_per_million: z2.number(),
952
952
  output_per_million: z2.number(),
953
953
  cache_read_per_million: z2.number().optional(),
954
- cache_write_per_million: z2.number().optional()
954
+ cache_write_per_million: z2.number().optional(),
955
+ cache_write_1h_per_million: z2.number().optional()
955
956
  });
956
957
  AnalyticsConfigSchema = z2.object({
957
958
  quality: z2.object({
@@ -2208,6 +2209,7 @@ __export(memory_db_exports, {
2208
2209
  pruneToolCostEvents: () => pruneToolCostEvents,
2209
2210
  recordRecallHits: () => recordRecallHits,
2210
2211
  recordTelemetry: () => recordTelemetry,
2212
+ releaseMetaLease: () => releaseMetaLease,
2211
2213
  removePendingSync: () => removePendingSync,
2212
2214
  sanitizeFts5Query: () => sanitizeFts5Query,
2213
2215
  sanitizeFts5QueryOr: () => sanitizeFts5QueryOr,
@@ -2216,6 +2218,7 @@ __export(memory_db_exports, {
2216
2218
  searchObservations: () => searchObservations,
2217
2219
  setLastProcessedLine: () => setLastProcessedLine,
2218
2220
  setMemoryMeta: () => setMemoryMeta,
2221
+ tryAcquireMetaLease: () => tryAcquireMetaLease,
2219
2222
  upsertObservationEmbedding: () => upsertObservationEmbedding,
2220
2223
  usageWarmupElapsed: () => usageWarmupElapsed
2221
2224
  });
@@ -2721,6 +2724,15 @@ function initMemorySchema(db) {
2721
2724
  );
2722
2725
  CREATE INDEX IF NOT EXISTS idx_sc_session ON session_costs(session_id);
2723
2726
  `);
2727
+ const costCols = db.prepare(`PRAGMA table_info(session_costs)`).all();
2728
+ const addCostCol = (name, ddl) => {
2729
+ if (!costCols.some((c) => c.name === name)) db.exec(`ALTER TABLE session_costs ADD COLUMN ${ddl}`);
2730
+ };
2731
+ addCostCol("cost_status", `cost_status TEXT NOT NULL DEFAULT 'unknown'`);
2732
+ addCostCol("unpriced_models", `unpriced_models TEXT NOT NULL DEFAULT ''`);
2733
+ addCostCol("priced_responses", `priced_responses INTEGER NOT NULL DEFAULT 0`);
2734
+ addCostCol("unpriced_responses", `unpriced_responses INTEGER NOT NULL DEFAULT 0`);
2735
+ addCostCol("pricing_version", `pricing_version INTEGER NOT NULL DEFAULT 0`);
2724
2736
  db.exec(`
2725
2737
  CREATE TABLE IF NOT EXISTS feature_costs (
2726
2738
  id INTEGER PRIMARY KEY AUTOINCREMENT,
@@ -3150,6 +3162,18 @@ function getMemoryMeta(db, key) {
3150
3162
  function setMemoryMeta(db, key, value) {
3151
3163
  db.prepare("INSERT OR REPLACE INTO memory_meta (key, value) VALUES (?, ?)").run(key, value);
3152
3164
  }
3165
+ function tryAcquireMetaLease(db, key, ttlSec, nowSec = Math.floor(Date.now() / 1e3)) {
3166
+ const r = db.prepare(
3167
+ `INSERT INTO memory_meta (key, value) VALUES (?, ?)
3168
+ ON CONFLICT(key) DO UPDATE SET value = excluded.value
3169
+ WHERE memory_meta.value = ''
3170
+ OR CAST(substr(memory_meta.value, instr(memory_meta.value, ':') + 1) AS INTEGER) <= ?`
3171
+ ).run(key, `${process.pid}:${nowSec + ttlSec}`, nowSec);
3172
+ return Number(r.changes) === 1;
3173
+ }
3174
+ function releaseMetaLease(db, key) {
3175
+ db.prepare(`UPDATE memory_meta SET value = '' WHERE key = ? AND value LIKE ?`).run(key, `${process.pid}:%`);
3176
+ }
3153
3177
  function upsertObservationEmbedding(db, observationId, vec, modelId, dim) {
3154
3178
  db.prepare(
3155
3179
  `INSERT OR REPLACE INTO observation_embeddings (observation_id, model_id, dim, vec, created_at)
@@ -4018,7 +4042,7 @@ var init_memory_db = __esm({
4018
4042
  init_rule_candidate_store();
4019
4043
  init_hook_failure_signal();
4020
4044
  init_memory_embed_sweep();
4021
- MEMORY_SCHEMA_VERSION = 1;
4045
+ MEMORY_SCHEMA_VERSION = 2;
4022
4046
  TOOL_COST_EVENTS_RETENTION_DAYS = 90;
4023
4047
  MAX_DRAFT_TEXT_LEN = 16384;
4024
4048
  FUNNEL_EVENT_OUTBOX_CAP = 2e4;
@@ -951,7 +951,8 @@ var init_config = __esm({
951
951
  input_per_million: z2.number(),
952
952
  output_per_million: z2.number(),
953
953
  cache_read_per_million: z2.number().optional(),
954
- cache_write_per_million: z2.number().optional()
954
+ cache_write_per_million: z2.number().optional(),
955
+ cache_write_1h_per_million: z2.number().optional()
955
956
  });
956
957
  AnalyticsConfigSchema = z2.object({
957
958
  quality: z2.object({
@@ -2208,6 +2209,7 @@ __export(memory_db_exports, {
2208
2209
  pruneToolCostEvents: () => pruneToolCostEvents,
2209
2210
  recordRecallHits: () => recordRecallHits,
2210
2211
  recordTelemetry: () => recordTelemetry,
2212
+ releaseMetaLease: () => releaseMetaLease,
2211
2213
  removePendingSync: () => removePendingSync,
2212
2214
  sanitizeFts5Query: () => sanitizeFts5Query,
2213
2215
  sanitizeFts5QueryOr: () => sanitizeFts5QueryOr,
@@ -2216,6 +2218,7 @@ __export(memory_db_exports, {
2216
2218
  searchObservations: () => searchObservations,
2217
2219
  setLastProcessedLine: () => setLastProcessedLine,
2218
2220
  setMemoryMeta: () => setMemoryMeta,
2221
+ tryAcquireMetaLease: () => tryAcquireMetaLease,
2219
2222
  upsertObservationEmbedding: () => upsertObservationEmbedding,
2220
2223
  usageWarmupElapsed: () => usageWarmupElapsed
2221
2224
  });
@@ -2721,6 +2724,15 @@ function initMemorySchema(db) {
2721
2724
  );
2722
2725
  CREATE INDEX IF NOT EXISTS idx_sc_session ON session_costs(session_id);
2723
2726
  `);
2727
+ const costCols = db.prepare(`PRAGMA table_info(session_costs)`).all();
2728
+ const addCostCol = (name, ddl) => {
2729
+ if (!costCols.some((c) => c.name === name)) db.exec(`ALTER TABLE session_costs ADD COLUMN ${ddl}`);
2730
+ };
2731
+ addCostCol("cost_status", `cost_status TEXT NOT NULL DEFAULT 'unknown'`);
2732
+ addCostCol("unpriced_models", `unpriced_models TEXT NOT NULL DEFAULT ''`);
2733
+ addCostCol("priced_responses", `priced_responses INTEGER NOT NULL DEFAULT 0`);
2734
+ addCostCol("unpriced_responses", `unpriced_responses INTEGER NOT NULL DEFAULT 0`);
2735
+ addCostCol("pricing_version", `pricing_version INTEGER NOT NULL DEFAULT 0`);
2724
2736
  db.exec(`
2725
2737
  CREATE TABLE IF NOT EXISTS feature_costs (
2726
2738
  id INTEGER PRIMARY KEY AUTOINCREMENT,
@@ -3150,6 +3162,18 @@ function getMemoryMeta(db, key) {
3150
3162
  function setMemoryMeta(db, key, value) {
3151
3163
  db.prepare("INSERT OR REPLACE INTO memory_meta (key, value) VALUES (?, ?)").run(key, value);
3152
3164
  }
3165
+ function tryAcquireMetaLease(db, key, ttlSec, nowSec = Math.floor(Date.now() / 1e3)) {
3166
+ const r = db.prepare(
3167
+ `INSERT INTO memory_meta (key, value) VALUES (?, ?)
3168
+ ON CONFLICT(key) DO UPDATE SET value = excluded.value
3169
+ WHERE memory_meta.value = ''
3170
+ OR CAST(substr(memory_meta.value, instr(memory_meta.value, ':') + 1) AS INTEGER) <= ?`
3171
+ ).run(key, `${process.pid}:${nowSec + ttlSec}`, nowSec);
3172
+ return Number(r.changes) === 1;
3173
+ }
3174
+ function releaseMetaLease(db, key) {
3175
+ db.prepare(`UPDATE memory_meta SET value = '' WHERE key = ? AND value LIKE ?`).run(key, `${process.pid}:%`);
3176
+ }
3153
3177
  function upsertObservationEmbedding(db, observationId, vec, modelId, dim) {
3154
3178
  db.prepare(
3155
3179
  `INSERT OR REPLACE INTO observation_embeddings (observation_id, model_id, dim, vec, created_at)
@@ -4018,7 +4042,7 @@ var init_memory_db = __esm({
4018
4042
  init_rule_candidate_store();
4019
4043
  init_hook_failure_signal();
4020
4044
  init_memory_embed_sweep();
4021
- MEMORY_SCHEMA_VERSION = 1;
4045
+ MEMORY_SCHEMA_VERSION = 2;
4022
4046
  TOOL_COST_EVENTS_RETENTION_DAYS = 90;
4023
4047
  MAX_DRAFT_TEXT_LEN = 16384;
4024
4048
  FUNNEL_EVENT_OUTBOX_CAP = 2e4;
@@ -951,7 +951,8 @@ var init_config = __esm({
951
951
  input_per_million: z2.number(),
952
952
  output_per_million: z2.number(),
953
953
  cache_read_per_million: z2.number().optional(),
954
- cache_write_per_million: z2.number().optional()
954
+ cache_write_per_million: z2.number().optional(),
955
+ cache_write_1h_per_million: z2.number().optional()
955
956
  });
956
957
  AnalyticsConfigSchema = z2.object({
957
958
  quality: z2.object({
@@ -2137,6 +2138,7 @@ __export(memory_db_exports, {
2137
2138
  pruneToolCostEvents: () => pruneToolCostEvents,
2138
2139
  recordRecallHits: () => recordRecallHits,
2139
2140
  recordTelemetry: () => recordTelemetry,
2141
+ releaseMetaLease: () => releaseMetaLease,
2140
2142
  removePendingSync: () => removePendingSync,
2141
2143
  sanitizeFts5Query: () => sanitizeFts5Query,
2142
2144
  sanitizeFts5QueryOr: () => sanitizeFts5QueryOr,
@@ -2145,6 +2147,7 @@ __export(memory_db_exports, {
2145
2147
  searchObservations: () => searchObservations,
2146
2148
  setLastProcessedLine: () => setLastProcessedLine,
2147
2149
  setMemoryMeta: () => setMemoryMeta,
2150
+ tryAcquireMetaLease: () => tryAcquireMetaLease,
2148
2151
  upsertObservationEmbedding: () => upsertObservationEmbedding,
2149
2152
  usageWarmupElapsed: () => usageWarmupElapsed
2150
2153
  });
@@ -2650,6 +2653,15 @@ function initMemorySchema(db) {
2650
2653
  );
2651
2654
  CREATE INDEX IF NOT EXISTS idx_sc_session ON session_costs(session_id);
2652
2655
  `);
2656
+ const costCols = db.prepare(`PRAGMA table_info(session_costs)`).all();
2657
+ const addCostCol = (name, ddl) => {
2658
+ if (!costCols.some((c) => c.name === name)) db.exec(`ALTER TABLE session_costs ADD COLUMN ${ddl}`);
2659
+ };
2660
+ addCostCol("cost_status", `cost_status TEXT NOT NULL DEFAULT 'unknown'`);
2661
+ addCostCol("unpriced_models", `unpriced_models TEXT NOT NULL DEFAULT ''`);
2662
+ addCostCol("priced_responses", `priced_responses INTEGER NOT NULL DEFAULT 0`);
2663
+ addCostCol("unpriced_responses", `unpriced_responses INTEGER NOT NULL DEFAULT 0`);
2664
+ addCostCol("pricing_version", `pricing_version INTEGER NOT NULL DEFAULT 0`);
2653
2665
  db.exec(`
2654
2666
  CREATE TABLE IF NOT EXISTS feature_costs (
2655
2667
  id INTEGER PRIMARY KEY AUTOINCREMENT,
@@ -3079,6 +3091,18 @@ function getMemoryMeta(db, key) {
3079
3091
  function setMemoryMeta(db, key, value) {
3080
3092
  db.prepare("INSERT OR REPLACE INTO memory_meta (key, value) VALUES (?, ?)").run(key, value);
3081
3093
  }
3094
+ function tryAcquireMetaLease(db, key, ttlSec, nowSec = Math.floor(Date.now() / 1e3)) {
3095
+ const r = db.prepare(
3096
+ `INSERT INTO memory_meta (key, value) VALUES (?, ?)
3097
+ ON CONFLICT(key) DO UPDATE SET value = excluded.value
3098
+ WHERE memory_meta.value = ''
3099
+ OR CAST(substr(memory_meta.value, instr(memory_meta.value, ':') + 1) AS INTEGER) <= ?`
3100
+ ).run(key, `${process.pid}:${nowSec + ttlSec}`, nowSec);
3101
+ return Number(r.changes) === 1;
3102
+ }
3103
+ function releaseMetaLease(db, key) {
3104
+ db.prepare(`UPDATE memory_meta SET value = '' WHERE key = ? AND value LIKE ?`).run(key, `${process.pid}:%`);
3105
+ }
3082
3106
  function upsertObservationEmbedding(db, observationId, vec, modelId, dim) {
3083
3107
  db.prepare(
3084
3108
  `INSERT OR REPLACE INTO observation_embeddings (observation_id, model_id, dim, vec, created_at)
@@ -3947,7 +3971,7 @@ var init_memory_db = __esm({
3947
3971
  init_rule_candidate_store();
3948
3972
  init_hook_failure_signal();
3949
3973
  init_memory_embed_sweep();
3950
- MEMORY_SCHEMA_VERSION = 1;
3974
+ MEMORY_SCHEMA_VERSION = 2;
3951
3975
  TOOL_COST_EVENTS_RETENTION_DAYS = 90;
3952
3976
  MAX_DRAFT_TEXT_LEN = 16384;
3953
3977
  FUNNEL_EVENT_OUTBOX_CAP = 2e4;
@@ -951,7 +951,8 @@ var init_config = __esm({
951
951
  input_per_million: z2.number(),
952
952
  output_per_million: z2.number(),
953
953
  cache_read_per_million: z2.number().optional(),
954
- cache_write_per_million: z2.number().optional()
954
+ cache_write_per_million: z2.number().optional(),
955
+ cache_write_1h_per_million: z2.number().optional()
955
956
  });
956
957
  AnalyticsConfigSchema = z2.object({
957
958
  quality: z2.object({
@@ -2208,6 +2209,7 @@ __export(memory_db_exports, {
2208
2209
  pruneToolCostEvents: () => pruneToolCostEvents,
2209
2210
  recordRecallHits: () => recordRecallHits,
2210
2211
  recordTelemetry: () => recordTelemetry,
2212
+ releaseMetaLease: () => releaseMetaLease,
2211
2213
  removePendingSync: () => removePendingSync,
2212
2214
  sanitizeFts5Query: () => sanitizeFts5Query,
2213
2215
  sanitizeFts5QueryOr: () => sanitizeFts5QueryOr,
@@ -2216,6 +2218,7 @@ __export(memory_db_exports, {
2216
2218
  searchObservations: () => searchObservations,
2217
2219
  setLastProcessedLine: () => setLastProcessedLine,
2218
2220
  setMemoryMeta: () => setMemoryMeta,
2221
+ tryAcquireMetaLease: () => tryAcquireMetaLease,
2219
2222
  upsertObservationEmbedding: () => upsertObservationEmbedding,
2220
2223
  usageWarmupElapsed: () => usageWarmupElapsed
2221
2224
  });
@@ -2721,6 +2724,15 @@ function initMemorySchema(db) {
2721
2724
  );
2722
2725
  CREATE INDEX IF NOT EXISTS idx_sc_session ON session_costs(session_id);
2723
2726
  `);
2727
+ const costCols = db.prepare(`PRAGMA table_info(session_costs)`).all();
2728
+ const addCostCol = (name, ddl) => {
2729
+ if (!costCols.some((c) => c.name === name)) db.exec(`ALTER TABLE session_costs ADD COLUMN ${ddl}`);
2730
+ };
2731
+ addCostCol("cost_status", `cost_status TEXT NOT NULL DEFAULT 'unknown'`);
2732
+ addCostCol("unpriced_models", `unpriced_models TEXT NOT NULL DEFAULT ''`);
2733
+ addCostCol("priced_responses", `priced_responses INTEGER NOT NULL DEFAULT 0`);
2734
+ addCostCol("unpriced_responses", `unpriced_responses INTEGER NOT NULL DEFAULT 0`);
2735
+ addCostCol("pricing_version", `pricing_version INTEGER NOT NULL DEFAULT 0`);
2724
2736
  db.exec(`
2725
2737
  CREATE TABLE IF NOT EXISTS feature_costs (
2726
2738
  id INTEGER PRIMARY KEY AUTOINCREMENT,
@@ -3150,6 +3162,18 @@ function getMemoryMeta(db, key) {
3150
3162
  function setMemoryMeta(db, key, value) {
3151
3163
  db.prepare("INSERT OR REPLACE INTO memory_meta (key, value) VALUES (?, ?)").run(key, value);
3152
3164
  }
3165
+ function tryAcquireMetaLease(db, key, ttlSec, nowSec = Math.floor(Date.now() / 1e3)) {
3166
+ const r = db.prepare(
3167
+ `INSERT INTO memory_meta (key, value) VALUES (?, ?)
3168
+ ON CONFLICT(key) DO UPDATE SET value = excluded.value
3169
+ WHERE memory_meta.value = ''
3170
+ OR CAST(substr(memory_meta.value, instr(memory_meta.value, ':') + 1) AS INTEGER) <= ?`
3171
+ ).run(key, `${process.pid}:${nowSec + ttlSec}`, nowSec);
3172
+ return Number(r.changes) === 1;
3173
+ }
3174
+ function releaseMetaLease(db, key) {
3175
+ db.prepare(`UPDATE memory_meta SET value = '' WHERE key = ? AND value LIKE ?`).run(key, `${process.pid}:%`);
3176
+ }
3153
3177
  function upsertObservationEmbedding(db, observationId, vec, modelId, dim) {
3154
3178
  db.prepare(
3155
3179
  `INSERT OR REPLACE INTO observation_embeddings (observation_id, model_id, dim, vec, created_at)
@@ -4018,7 +4042,7 @@ var init_memory_db = __esm({
4018
4042
  init_rule_candidate_store();
4019
4043
  init_hook_failure_signal();
4020
4044
  init_memory_embed_sweep();
4021
- MEMORY_SCHEMA_VERSION = 1;
4045
+ MEMORY_SCHEMA_VERSION = 2;
4022
4046
  TOOL_COST_EVENTS_RETENTION_DAYS = 90;
4023
4047
  MAX_DRAFT_TEXT_LEN = 16384;
4024
4048
  FUNNEL_EVENT_OUTBOX_CAP = 2e4;
@@ -481,7 +481,8 @@ var init_config = __esm({
481
481
  input_per_million: z2.number(),
482
482
  output_per_million: z2.number(),
483
483
  cache_read_per_million: z2.number().optional(),
484
- cache_write_per_million: z2.number().optional()
484
+ cache_write_per_million: z2.number().optional(),
485
+ cache_write_1h_per_million: z2.number().optional()
485
486
  });
486
487
  AnalyticsConfigSchema = z2.object({
487
488
  quality: z2.object({
@@ -2137,6 +2138,7 @@ __export(memory_db_exports, {
2137
2138
  pruneToolCostEvents: () => pruneToolCostEvents,
2138
2139
  recordRecallHits: () => recordRecallHits,
2139
2140
  recordTelemetry: () => recordTelemetry,
2141
+ releaseMetaLease: () => releaseMetaLease,
2140
2142
  removePendingSync: () => removePendingSync,
2141
2143
  sanitizeFts5Query: () => sanitizeFts5Query,
2142
2144
  sanitizeFts5QueryOr: () => sanitizeFts5QueryOr,
@@ -2145,6 +2147,7 @@ __export(memory_db_exports, {
2145
2147
  searchObservations: () => searchObservations,
2146
2148
  setLastProcessedLine: () => setLastProcessedLine,
2147
2149
  setMemoryMeta: () => setMemoryMeta,
2150
+ tryAcquireMetaLease: () => tryAcquireMetaLease,
2148
2151
  upsertObservationEmbedding: () => upsertObservationEmbedding,
2149
2152
  usageWarmupElapsed: () => usageWarmupElapsed
2150
2153
  });
@@ -2650,6 +2653,15 @@ function initMemorySchema(db) {
2650
2653
  );
2651
2654
  CREATE INDEX IF NOT EXISTS idx_sc_session ON session_costs(session_id);
2652
2655
  `);
2656
+ const costCols = db.prepare(`PRAGMA table_info(session_costs)`).all();
2657
+ const addCostCol = (name, ddl) => {
2658
+ if (!costCols.some((c) => c.name === name)) db.exec(`ALTER TABLE session_costs ADD COLUMN ${ddl}`);
2659
+ };
2660
+ addCostCol("cost_status", `cost_status TEXT NOT NULL DEFAULT 'unknown'`);
2661
+ addCostCol("unpriced_models", `unpriced_models TEXT NOT NULL DEFAULT ''`);
2662
+ addCostCol("priced_responses", `priced_responses INTEGER NOT NULL DEFAULT 0`);
2663
+ addCostCol("unpriced_responses", `unpriced_responses INTEGER NOT NULL DEFAULT 0`);
2664
+ addCostCol("pricing_version", `pricing_version INTEGER NOT NULL DEFAULT 0`);
2653
2665
  db.exec(`
2654
2666
  CREATE TABLE IF NOT EXISTS feature_costs (
2655
2667
  id INTEGER PRIMARY KEY AUTOINCREMENT,
@@ -3079,6 +3091,18 @@ function getMemoryMeta(db, key) {
3079
3091
  function setMemoryMeta(db, key, value) {
3080
3092
  db.prepare("INSERT OR REPLACE INTO memory_meta (key, value) VALUES (?, ?)").run(key, value);
3081
3093
  }
3094
+ function tryAcquireMetaLease(db, key, ttlSec, nowSec = Math.floor(Date.now() / 1e3)) {
3095
+ const r = db.prepare(
3096
+ `INSERT INTO memory_meta (key, value) VALUES (?, ?)
3097
+ ON CONFLICT(key) DO UPDATE SET value = excluded.value
3098
+ WHERE memory_meta.value = ''
3099
+ OR CAST(substr(memory_meta.value, instr(memory_meta.value, ':') + 1) AS INTEGER) <= ?`
3100
+ ).run(key, `${process.pid}:${nowSec + ttlSec}`, nowSec);
3101
+ return Number(r.changes) === 1;
3102
+ }
3103
+ function releaseMetaLease(db, key) {
3104
+ db.prepare(`UPDATE memory_meta SET value = '' WHERE key = ? AND value LIKE ?`).run(key, `${process.pid}:%`);
3105
+ }
3082
3106
  function upsertObservationEmbedding(db, observationId, vec, modelId, dim) {
3083
3107
  db.prepare(
3084
3108
  `INSERT OR REPLACE INTO observation_embeddings (observation_id, model_id, dim, vec, created_at)
@@ -3947,7 +3971,7 @@ var init_memory_db = __esm({
3947
3971
  init_rule_candidate_store();
3948
3972
  init_hook_failure_signal();
3949
3973
  init_memory_embed_sweep();
3950
- MEMORY_SCHEMA_VERSION = 1;
3974
+ MEMORY_SCHEMA_VERSION = 2;
3951
3975
  TOOL_COST_EVENTS_RETENTION_DAYS = 90;
3952
3976
  MAX_DRAFT_TEXT_LEN = 16384;
3953
3977
  FUNNEL_EVENT_OUTBOX_CAP = 2e4;
@@ -951,7 +951,8 @@ var init_config = __esm({
951
951
  input_per_million: z2.number(),
952
952
  output_per_million: z2.number(),
953
953
  cache_read_per_million: z2.number().optional(),
954
- cache_write_per_million: z2.number().optional()
954
+ cache_write_per_million: z2.number().optional(),
955
+ cache_write_1h_per_million: z2.number().optional()
955
956
  });
956
957
  AnalyticsConfigSchema = z2.object({
957
958
  quality: z2.object({
@@ -2137,6 +2138,7 @@ __export(memory_db_exports, {
2137
2138
  pruneToolCostEvents: () => pruneToolCostEvents,
2138
2139
  recordRecallHits: () => recordRecallHits,
2139
2140
  recordTelemetry: () => recordTelemetry,
2141
+ releaseMetaLease: () => releaseMetaLease,
2140
2142
  removePendingSync: () => removePendingSync,
2141
2143
  sanitizeFts5Query: () => sanitizeFts5Query,
2142
2144
  sanitizeFts5QueryOr: () => sanitizeFts5QueryOr,
@@ -2145,6 +2147,7 @@ __export(memory_db_exports, {
2145
2147
  searchObservations: () => searchObservations,
2146
2148
  setLastProcessedLine: () => setLastProcessedLine,
2147
2149
  setMemoryMeta: () => setMemoryMeta,
2150
+ tryAcquireMetaLease: () => tryAcquireMetaLease,
2148
2151
  upsertObservationEmbedding: () => upsertObservationEmbedding,
2149
2152
  usageWarmupElapsed: () => usageWarmupElapsed
2150
2153
  });
@@ -2650,6 +2653,15 @@ function initMemorySchema(db) {
2650
2653
  );
2651
2654
  CREATE INDEX IF NOT EXISTS idx_sc_session ON session_costs(session_id);
2652
2655
  `);
2656
+ const costCols = db.prepare(`PRAGMA table_info(session_costs)`).all();
2657
+ const addCostCol = (name, ddl) => {
2658
+ if (!costCols.some((c) => c.name === name)) db.exec(`ALTER TABLE session_costs ADD COLUMN ${ddl}`);
2659
+ };
2660
+ addCostCol("cost_status", `cost_status TEXT NOT NULL DEFAULT 'unknown'`);
2661
+ addCostCol("unpriced_models", `unpriced_models TEXT NOT NULL DEFAULT ''`);
2662
+ addCostCol("priced_responses", `priced_responses INTEGER NOT NULL DEFAULT 0`);
2663
+ addCostCol("unpriced_responses", `unpriced_responses INTEGER NOT NULL DEFAULT 0`);
2664
+ addCostCol("pricing_version", `pricing_version INTEGER NOT NULL DEFAULT 0`);
2653
2665
  db.exec(`
2654
2666
  CREATE TABLE IF NOT EXISTS feature_costs (
2655
2667
  id INTEGER PRIMARY KEY AUTOINCREMENT,
@@ -3079,6 +3091,18 @@ function getMemoryMeta(db, key) {
3079
3091
  function setMemoryMeta(db, key, value) {
3080
3092
  db.prepare("INSERT OR REPLACE INTO memory_meta (key, value) VALUES (?, ?)").run(key, value);
3081
3093
  }
3094
+ function tryAcquireMetaLease(db, key, ttlSec, nowSec = Math.floor(Date.now() / 1e3)) {
3095
+ const r = db.prepare(
3096
+ `INSERT INTO memory_meta (key, value) VALUES (?, ?)
3097
+ ON CONFLICT(key) DO UPDATE SET value = excluded.value
3098
+ WHERE memory_meta.value = ''
3099
+ OR CAST(substr(memory_meta.value, instr(memory_meta.value, ':') + 1) AS INTEGER) <= ?`
3100
+ ).run(key, `${process.pid}:${nowSec + ttlSec}`, nowSec);
3101
+ return Number(r.changes) === 1;
3102
+ }
3103
+ function releaseMetaLease(db, key) {
3104
+ db.prepare(`UPDATE memory_meta SET value = '' WHERE key = ? AND value LIKE ?`).run(key, `${process.pid}:%`);
3105
+ }
3082
3106
  function upsertObservationEmbedding(db, observationId, vec, modelId, dim) {
3083
3107
  db.prepare(
3084
3108
  `INSERT OR REPLACE INTO observation_embeddings (observation_id, model_id, dim, vec, created_at)
@@ -3947,7 +3971,7 @@ var init_memory_db = __esm({
3947
3971
  init_rule_candidate_store();
3948
3972
  init_hook_failure_signal();
3949
3973
  init_memory_embed_sweep();
3950
- MEMORY_SCHEMA_VERSION = 1;
3974
+ MEMORY_SCHEMA_VERSION = 2;
3951
3975
  TOOL_COST_EVENTS_RETENTION_DAYS = 90;
3952
3976
  MAX_DRAFT_TEXT_LEN = 16384;
3953
3977
  FUNNEL_EVENT_OUTBOX_CAP = 2e4;