@massu/core 2.5.3 → 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.
@@ -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;
@@ -487,7 +487,8 @@ var init_config = __esm({
487
487
  input_per_million: z2.number(),
488
488
  output_per_million: z2.number(),
489
489
  cache_read_per_million: z2.number().optional(),
490
- cache_write_per_million: z2.number().optional()
490
+ cache_write_per_million: z2.number().optional(),
491
+ cache_write_1h_per_million: z2.number().optional()
491
492
  });
492
493
  AnalyticsConfigSchema = z2.object({
493
494
  quality: z2.object({
@@ -2214,6 +2215,7 @@ __export(memory_db_exports, {
2214
2215
  pruneToolCostEvents: () => pruneToolCostEvents,
2215
2216
  recordRecallHits: () => recordRecallHits,
2216
2217
  recordTelemetry: () => recordTelemetry,
2218
+ releaseMetaLease: () => releaseMetaLease,
2217
2219
  removePendingSync: () => removePendingSync,
2218
2220
  sanitizeFts5Query: () => sanitizeFts5Query,
2219
2221
  sanitizeFts5QueryOr: () => sanitizeFts5QueryOr,
@@ -2222,6 +2224,7 @@ __export(memory_db_exports, {
2222
2224
  searchObservations: () => searchObservations,
2223
2225
  setLastProcessedLine: () => setLastProcessedLine,
2224
2226
  setMemoryMeta: () => setMemoryMeta,
2227
+ tryAcquireMetaLease: () => tryAcquireMetaLease,
2225
2228
  upsertObservationEmbedding: () => upsertObservationEmbedding,
2226
2229
  usageWarmupElapsed: () => usageWarmupElapsed
2227
2230
  });
@@ -2727,6 +2730,15 @@ function initMemorySchema(db) {
2727
2730
  );
2728
2731
  CREATE INDEX IF NOT EXISTS idx_sc_session ON session_costs(session_id);
2729
2732
  `);
2733
+ const costCols = db.prepare(`PRAGMA table_info(session_costs)`).all();
2734
+ const addCostCol = (name, ddl) => {
2735
+ if (!costCols.some((c) => c.name === name)) db.exec(`ALTER TABLE session_costs ADD COLUMN ${ddl}`);
2736
+ };
2737
+ addCostCol("cost_status", `cost_status TEXT NOT NULL DEFAULT 'unknown'`);
2738
+ addCostCol("unpriced_models", `unpriced_models TEXT NOT NULL DEFAULT ''`);
2739
+ addCostCol("priced_responses", `priced_responses INTEGER NOT NULL DEFAULT 0`);
2740
+ addCostCol("unpriced_responses", `unpriced_responses INTEGER NOT NULL DEFAULT 0`);
2741
+ addCostCol("pricing_version", `pricing_version INTEGER NOT NULL DEFAULT 0`);
2730
2742
  db.exec(`
2731
2743
  CREATE TABLE IF NOT EXISTS feature_costs (
2732
2744
  id INTEGER PRIMARY KEY AUTOINCREMENT,
@@ -3156,6 +3168,18 @@ function getMemoryMeta(db, key) {
3156
3168
  function setMemoryMeta(db, key, value) {
3157
3169
  db.prepare("INSERT OR REPLACE INTO memory_meta (key, value) VALUES (?, ?)").run(key, value);
3158
3170
  }
3171
+ function tryAcquireMetaLease(db, key, ttlSec, nowSec = Math.floor(Date.now() / 1e3)) {
3172
+ const r = db.prepare(
3173
+ `INSERT INTO memory_meta (key, value) VALUES (?, ?)
3174
+ ON CONFLICT(key) DO UPDATE SET value = excluded.value
3175
+ WHERE memory_meta.value = ''
3176
+ OR CAST(substr(memory_meta.value, instr(memory_meta.value, ':') + 1) AS INTEGER) <= ?`
3177
+ ).run(key, `${process.pid}:${nowSec + ttlSec}`, nowSec);
3178
+ return Number(r.changes) === 1;
3179
+ }
3180
+ function releaseMetaLease(db, key) {
3181
+ db.prepare(`UPDATE memory_meta SET value = '' WHERE key = ? AND value LIKE ?`).run(key, `${process.pid}:%`);
3182
+ }
3159
3183
  function upsertObservationEmbedding(db, observationId, vec, modelId, dim) {
3160
3184
  db.prepare(
3161
3185
  `INSERT OR REPLACE INTO observation_embeddings (observation_id, model_id, dim, vec, created_at)
@@ -4024,7 +4048,7 @@ var init_memory_db = __esm({
4024
4048
  init_rule_candidate_store();
4025
4049
  init_hook_failure_signal();
4026
4050
  init_memory_embed_sweep();
4027
- MEMORY_SCHEMA_VERSION = 1;
4051
+ MEMORY_SCHEMA_VERSION = 2;
4028
4052
  TOOL_COST_EVENTS_RETENTION_DAYS = 90;
4029
4053
  MAX_DRAFT_TEXT_LEN = 16384;
4030
4054
  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;
@@ -487,7 +487,8 @@ var init_config = __esm({
487
487
  input_per_million: z2.number(),
488
488
  output_per_million: z2.number(),
489
489
  cache_read_per_million: z2.number().optional(),
490
- cache_write_per_million: z2.number().optional()
490
+ cache_write_per_million: z2.number().optional(),
491
+ cache_write_1h_per_million: z2.number().optional()
491
492
  });
492
493
  AnalyticsConfigSchema = z2.object({
493
494
  quality: z2.object({
@@ -2143,6 +2144,7 @@ __export(memory_db_exports, {
2143
2144
  pruneToolCostEvents: () => pruneToolCostEvents,
2144
2145
  recordRecallHits: () => recordRecallHits,
2145
2146
  recordTelemetry: () => recordTelemetry,
2147
+ releaseMetaLease: () => releaseMetaLease,
2146
2148
  removePendingSync: () => removePendingSync,
2147
2149
  sanitizeFts5Query: () => sanitizeFts5Query,
2148
2150
  sanitizeFts5QueryOr: () => sanitizeFts5QueryOr,
@@ -2151,6 +2153,7 @@ __export(memory_db_exports, {
2151
2153
  searchObservations: () => searchObservations,
2152
2154
  setLastProcessedLine: () => setLastProcessedLine,
2153
2155
  setMemoryMeta: () => setMemoryMeta,
2156
+ tryAcquireMetaLease: () => tryAcquireMetaLease,
2154
2157
  upsertObservationEmbedding: () => upsertObservationEmbedding,
2155
2158
  usageWarmupElapsed: () => usageWarmupElapsed
2156
2159
  });
@@ -2656,6 +2659,15 @@ function initMemorySchema(db) {
2656
2659
  );
2657
2660
  CREATE INDEX IF NOT EXISTS idx_sc_session ON session_costs(session_id);
2658
2661
  `);
2662
+ const costCols = db.prepare(`PRAGMA table_info(session_costs)`).all();
2663
+ const addCostCol = (name, ddl) => {
2664
+ if (!costCols.some((c) => c.name === name)) db.exec(`ALTER TABLE session_costs ADD COLUMN ${ddl}`);
2665
+ };
2666
+ addCostCol("cost_status", `cost_status TEXT NOT NULL DEFAULT 'unknown'`);
2667
+ addCostCol("unpriced_models", `unpriced_models TEXT NOT NULL DEFAULT ''`);
2668
+ addCostCol("priced_responses", `priced_responses INTEGER NOT NULL DEFAULT 0`);
2669
+ addCostCol("unpriced_responses", `unpriced_responses INTEGER NOT NULL DEFAULT 0`);
2670
+ addCostCol("pricing_version", `pricing_version INTEGER NOT NULL DEFAULT 0`);
2659
2671
  db.exec(`
2660
2672
  CREATE TABLE IF NOT EXISTS feature_costs (
2661
2673
  id INTEGER PRIMARY KEY AUTOINCREMENT,
@@ -3085,6 +3097,18 @@ function getMemoryMeta(db, key) {
3085
3097
  function setMemoryMeta(db, key, value) {
3086
3098
  db.prepare("INSERT OR REPLACE INTO memory_meta (key, value) VALUES (?, ?)").run(key, value);
3087
3099
  }
3100
+ function tryAcquireMetaLease(db, key, ttlSec, nowSec = Math.floor(Date.now() / 1e3)) {
3101
+ const r = db.prepare(
3102
+ `INSERT INTO memory_meta (key, value) VALUES (?, ?)
3103
+ ON CONFLICT(key) DO UPDATE SET value = excluded.value
3104
+ WHERE memory_meta.value = ''
3105
+ OR CAST(substr(memory_meta.value, instr(memory_meta.value, ':') + 1) AS INTEGER) <= ?`
3106
+ ).run(key, `${process.pid}:${nowSec + ttlSec}`, nowSec);
3107
+ return Number(r.changes) === 1;
3108
+ }
3109
+ function releaseMetaLease(db, key) {
3110
+ db.prepare(`UPDATE memory_meta SET value = '' WHERE key = ? AND value LIKE ?`).run(key, `${process.pid}:%`);
3111
+ }
3088
3112
  function upsertObservationEmbedding(db, observationId, vec, modelId, dim) {
3089
3113
  db.prepare(
3090
3114
  `INSERT OR REPLACE INTO observation_embeddings (observation_id, model_id, dim, vec, created_at)
@@ -3953,7 +3977,7 @@ var init_memory_db = __esm({
3953
3977
  init_rule_candidate_store();
3954
3978
  init_hook_failure_signal();
3955
3979
  init_memory_embed_sweep();
3956
- MEMORY_SCHEMA_VERSION = 1;
3980
+ MEMORY_SCHEMA_VERSION = 2;
3957
3981
  TOOL_COST_EVENTS_RETENTION_DAYS = 90;
3958
3982
  MAX_DRAFT_TEXT_LEN = 16384;
3959
3983
  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({
@@ -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({
@@ -2244,6 +2245,7 @@ __export(memory_db_exports, {
2244
2245
  pruneToolCostEvents: () => pruneToolCostEvents,
2245
2246
  recordRecallHits: () => recordRecallHits,
2246
2247
  recordTelemetry: () => recordTelemetry,
2248
+ releaseMetaLease: () => releaseMetaLease,
2247
2249
  removePendingSync: () => removePendingSync,
2248
2250
  sanitizeFts5Query: () => sanitizeFts5Query,
2249
2251
  sanitizeFts5QueryOr: () => sanitizeFts5QueryOr,
@@ -2252,6 +2254,7 @@ __export(memory_db_exports, {
2252
2254
  searchObservations: () => searchObservations,
2253
2255
  setLastProcessedLine: () => setLastProcessedLine,
2254
2256
  setMemoryMeta: () => setMemoryMeta,
2257
+ tryAcquireMetaLease: () => tryAcquireMetaLease,
2255
2258
  upsertObservationEmbedding: () => upsertObservationEmbedding,
2256
2259
  usageWarmupElapsed: () => usageWarmupElapsed
2257
2260
  });
@@ -2757,6 +2760,15 @@ function initMemorySchema(db) {
2757
2760
  );
2758
2761
  CREATE INDEX IF NOT EXISTS idx_sc_session ON session_costs(session_id);
2759
2762
  `);
2763
+ const costCols = db.prepare(`PRAGMA table_info(session_costs)`).all();
2764
+ const addCostCol = (name, ddl) => {
2765
+ if (!costCols.some((c) => c.name === name)) db.exec(`ALTER TABLE session_costs ADD COLUMN ${ddl}`);
2766
+ };
2767
+ addCostCol("cost_status", `cost_status TEXT NOT NULL DEFAULT 'unknown'`);
2768
+ addCostCol("unpriced_models", `unpriced_models TEXT NOT NULL DEFAULT ''`);
2769
+ addCostCol("priced_responses", `priced_responses INTEGER NOT NULL DEFAULT 0`);
2770
+ addCostCol("unpriced_responses", `unpriced_responses INTEGER NOT NULL DEFAULT 0`);
2771
+ addCostCol("pricing_version", `pricing_version INTEGER NOT NULL DEFAULT 0`);
2760
2772
  db.exec(`
2761
2773
  CREATE TABLE IF NOT EXISTS feature_costs (
2762
2774
  id INTEGER PRIMARY KEY AUTOINCREMENT,
@@ -3186,6 +3198,18 @@ function getMemoryMeta(db, key) {
3186
3198
  function setMemoryMeta(db, key, value) {
3187
3199
  db.prepare("INSERT OR REPLACE INTO memory_meta (key, value) VALUES (?, ?)").run(key, value);
3188
3200
  }
3201
+ function tryAcquireMetaLease(db, key, ttlSec, nowSec = Math.floor(Date.now() / 1e3)) {
3202
+ const r = db.prepare(
3203
+ `INSERT INTO memory_meta (key, value) VALUES (?, ?)
3204
+ ON CONFLICT(key) DO UPDATE SET value = excluded.value
3205
+ WHERE memory_meta.value = ''
3206
+ OR CAST(substr(memory_meta.value, instr(memory_meta.value, ':') + 1) AS INTEGER) <= ?`
3207
+ ).run(key, `${process.pid}:${nowSec + ttlSec}`, nowSec);
3208
+ return Number(r.changes) === 1;
3209
+ }
3210
+ function releaseMetaLease(db, key) {
3211
+ db.prepare(`UPDATE memory_meta SET value = '' WHERE key = ? AND value LIKE ?`).run(key, `${process.pid}:%`);
3212
+ }
3189
3213
  function upsertObservationEmbedding(db, observationId, vec, modelId, dim) {
3190
3214
  db.prepare(
3191
3215
  `INSERT OR REPLACE INTO observation_embeddings (observation_id, model_id, dim, vec, created_at)
@@ -4054,7 +4078,7 @@ var init_memory_db = __esm({
4054
4078
  init_rule_candidate_store();
4055
4079
  init_hook_failure_signal();
4056
4080
  init_memory_embed_sweep();
4057
- MEMORY_SCHEMA_VERSION = 1;
4081
+ MEMORY_SCHEMA_VERSION = 2;
4058
4082
  TOOL_COST_EVENTS_RETENTION_DAYS = 90;
4059
4083
  MAX_DRAFT_TEXT_LEN = 16384;
4060
4084
  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;
@@ -957,7 +957,8 @@ var init_config = __esm({
957
957
  input_per_million: z2.number(),
958
958
  output_per_million: z2.number(),
959
959
  cache_read_per_million: z2.number().optional(),
960
- cache_write_per_million: z2.number().optional()
960
+ cache_write_per_million: z2.number().optional(),
961
+ cache_write_1h_per_million: z2.number().optional()
961
962
  });
962
963
  AnalyticsConfigSchema = z2.object({
963
964
  quality: z2.object({
@@ -2214,6 +2215,7 @@ __export(memory_db_exports, {
2214
2215
  pruneToolCostEvents: () => pruneToolCostEvents,
2215
2216
  recordRecallHits: () => recordRecallHits,
2216
2217
  recordTelemetry: () => recordTelemetry,
2218
+ releaseMetaLease: () => releaseMetaLease,
2217
2219
  removePendingSync: () => removePendingSync,
2218
2220
  sanitizeFts5Query: () => sanitizeFts5Query,
2219
2221
  sanitizeFts5QueryOr: () => sanitizeFts5QueryOr,
@@ -2222,6 +2224,7 @@ __export(memory_db_exports, {
2222
2224
  searchObservations: () => searchObservations,
2223
2225
  setLastProcessedLine: () => setLastProcessedLine,
2224
2226
  setMemoryMeta: () => setMemoryMeta,
2227
+ tryAcquireMetaLease: () => tryAcquireMetaLease,
2225
2228
  upsertObservationEmbedding: () => upsertObservationEmbedding,
2226
2229
  usageWarmupElapsed: () => usageWarmupElapsed
2227
2230
  });
@@ -2727,6 +2730,15 @@ function initMemorySchema(db) {
2727
2730
  );
2728
2731
  CREATE INDEX IF NOT EXISTS idx_sc_session ON session_costs(session_id);
2729
2732
  `);
2733
+ const costCols = db.prepare(`PRAGMA table_info(session_costs)`).all();
2734
+ const addCostCol = (name, ddl) => {
2735
+ if (!costCols.some((c) => c.name === name)) db.exec(`ALTER TABLE session_costs ADD COLUMN ${ddl}`);
2736
+ };
2737
+ addCostCol("cost_status", `cost_status TEXT NOT NULL DEFAULT 'unknown'`);
2738
+ addCostCol("unpriced_models", `unpriced_models TEXT NOT NULL DEFAULT ''`);
2739
+ addCostCol("priced_responses", `priced_responses INTEGER NOT NULL DEFAULT 0`);
2740
+ addCostCol("unpriced_responses", `unpriced_responses INTEGER NOT NULL DEFAULT 0`);
2741
+ addCostCol("pricing_version", `pricing_version INTEGER NOT NULL DEFAULT 0`);
2730
2742
  db.exec(`
2731
2743
  CREATE TABLE IF NOT EXISTS feature_costs (
2732
2744
  id INTEGER PRIMARY KEY AUTOINCREMENT,
@@ -3156,6 +3168,18 @@ function getMemoryMeta(db, key) {
3156
3168
  function setMemoryMeta(db, key, value) {
3157
3169
  db.prepare("INSERT OR REPLACE INTO memory_meta (key, value) VALUES (?, ?)").run(key, value);
3158
3170
  }
3171
+ function tryAcquireMetaLease(db, key, ttlSec, nowSec = Math.floor(Date.now() / 1e3)) {
3172
+ const r = db.prepare(
3173
+ `INSERT INTO memory_meta (key, value) VALUES (?, ?)
3174
+ ON CONFLICT(key) DO UPDATE SET value = excluded.value
3175
+ WHERE memory_meta.value = ''
3176
+ OR CAST(substr(memory_meta.value, instr(memory_meta.value, ':') + 1) AS INTEGER) <= ?`
3177
+ ).run(key, `${process.pid}:${nowSec + ttlSec}`, nowSec);
3178
+ return Number(r.changes) === 1;
3179
+ }
3180
+ function releaseMetaLease(db, key) {
3181
+ db.prepare(`UPDATE memory_meta SET value = '' WHERE key = ? AND value LIKE ?`).run(key, `${process.pid}:%`);
3182
+ }
3159
3183
  function upsertObservationEmbedding(db, observationId, vec, modelId, dim) {
3160
3184
  db.prepare(
3161
3185
  `INSERT OR REPLACE INTO observation_embeddings (observation_id, model_id, dim, vec, created_at)
@@ -4024,7 +4048,7 @@ var init_memory_db = __esm({
4024
4048
  init_rule_candidate_store();
4025
4049
  init_hook_failure_signal();
4026
4050
  init_memory_embed_sweep();
4027
- MEMORY_SCHEMA_VERSION = 1;
4051
+ MEMORY_SCHEMA_VERSION = 2;
4028
4052
  TOOL_COST_EVENTS_RETENTION_DAYS = 90;
4029
4053
  MAX_DRAFT_TEXT_LEN = 16384;
4030
4054
  FUNNEL_EVENT_OUTBOX_CAP = 2e4;