@gamaze/hicortex 0.20.10 → 0.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1548,7 +1548,7 @@ async function startServer(options = {}) {
1548
1548
  //
1549
1549
  // An enrich is EVIDENCE ABOUT IMPORTANCE: it bumps corroboration_count and
1550
1550
  // base_strength (+the calibration delta, capped at 1.0) — the same anchor
1551
- // the nightly's LLM scoring and hub-boost write. It must NOT touch
1551
+ // the nightly's LLM scoring writes. It must NOT touch
1552
1552
  // access_count (reserved for real recall use) or shown_count (index
1553
1553
  // exposure) — faking either corrupts the uses-per-showing adoption metric.
1554
1554
  // Never a stage write: stages are derived presentation (the E-reframe).
package/dist/nofit.d.ts CHANGED
@@ -38,7 +38,8 @@
38
38
  * memory from pruning. Halving does not touch last_accessed/access_count.
39
39
  * - Re-classification: a later run whose LLM tags it, or whose evolved
40
40
  * prototypes clear the floor, gives it a (weak) primary — halving stops.
41
- * Its strength is NOT restored; only access does that job.
41
+ * Its strength is restored only by the nightly promotion stage (#448),
42
+ * which converts each new access_count delta into a base_strength bump.
42
43
  *
43
44
  * PRUNE INTERACTION (verified against stageDecayPrune + effectiveStrength):
44
45
  * prune fires when effectiveStrength < 0.01 for a >90-day-old, never-accessed
package/dist/nofit.js CHANGED
@@ -39,7 +39,8 @@
39
39
  * memory from pruning. Halving does not touch last_accessed/access_count.
40
40
  * - Re-classification: a later run whose LLM tags it, or whose evolved
41
41
  * prototypes clear the floor, gives it a (weak) primary — halving stops.
42
- * Its strength is NOT restored; only access does that job.
42
+ * Its strength is restored only by the nightly promotion stage (#448),
43
+ * which converts each new access_count delta into a base_strength bump.
43
44
  *
44
45
  * PRUNE INTERACTION (verified against stageDecayPrune + effectiveStrength):
45
46
  * prune fires when effectiveStrength < 0.01 for a >90-day-old, never-accessed
@@ -10,8 +10,9 @@
10
10
  * Strengthening semantics (the recall/decay alignment):
11
11
  * - Appearing in the index = exposure: shown_count + last_accessed refresh
12
12
  * (mild, temporary strengthen — the decay clock resets) via
13
- * storage.touchMemoriesShown. NO access_count bump: hardening, the prune
14
- * shield, and the adoption metric stay driven by real use.
13
+ * storage.touchMemoriesShown. NO access_count bump: the promotion signal
14
+ * (#448), the prune shield, and the adoption metric stay driven by real
15
+ * use.
15
16
  * - hicortex_get = use: full strengthen (access_count + 1).
16
17
  *
17
18
  * Anti-bloat gates: relevance floor (measured cosine, or a real BM25 match),
@@ -11,8 +11,9 @@
11
11
  * Strengthening semantics (the recall/decay alignment):
12
12
  * - Appearing in the index = exposure: shown_count + last_accessed refresh
13
13
  * (mild, temporary strengthen — the decay clock resets) via
14
- * storage.touchMemoriesShown. NO access_count bump: hardening, the prune
15
- * shield, and the adoption metric stay driven by real use.
14
+ * storage.touchMemoriesShown. NO access_count bump: the promotion signal
15
+ * (#448), the prune shield, and the adoption metric stay driven by real
16
+ * use.
16
17
  * - hicortex_get = use: full strengthen (access_count + 1).
17
18
  *
18
19
  * Anti-bloat gates: relevance floor (measured cosine, or a real BM25 match),
@@ -208,7 +208,7 @@ export declare function l2ToCosine(distance: number): number;
208
208
  */
209
209
  export declare function cosineBetweenVectors(a: Float32Array, b: Float32Array): number;
210
210
  /**
211
- * Compute decayed strength with adaptive decay (B+E+D model).
211
+ * Compute decayed strength with adaptive decay (B+D model).
212
212
  * Exported for use by consolidation decay/prune stage.
213
213
  *
214
214
  * #425 read-side law: the decay-relevant importance is CLAMPED at the
@@ -216,11 +216,17 @@ export declare function cosineBetweenVectors(a: Float32Array, b: Float32Array):
216
216
  * exactly 1.0 the decay rate is exactly 1.0 and the row never decays, so
217
217
  * legacy base-1.0 rows (and any write site that predates the cap) decay
218
218
  * again. The clamp applies to explicit importance passes too.
219
+ *
220
+ * #448: the access/connectivity HARDENING terms are REMOVED — the fade rate
221
+ * no longer depends on access or link history (a briefly-used memory was
222
+ * near-immortal: 10 accesses cut the decay rate to 3% of normal). Real use
223
+ * now raises the STORED score via the nightly promotion stage
224
+ * (consolidate.ts stagePromotion) instead of slowing future decay, so a
225
+ * promoted-then-abandoned memory fades on the same 365-day clock as any
226
+ * other, from a higher anchor.
219
227
  */
220
228
  export declare function effectiveStrength(baseStrength: number, lastAccessed: string | null, now: Date, options?: {
221
229
  importance?: number;
222
- accessCount?: number;
223
- linkCount?: number;
224
230
  }): number;
225
231
  /**
226
232
  * Return a composite relevance score in [0, 1] for a candidate memory.
package/dist/retrieval.js CHANGED
@@ -486,7 +486,7 @@ function parseTimestamp(ts) {
486
486
  // Scoring helpers
487
487
  // ---------------------------------------------------------------------------
488
488
  /**
489
- * Compute decayed strength with adaptive decay (B+E+D model).
489
+ * Compute decayed strength with adaptive decay (B+D model).
490
490
  * Exported for use by consolidation decay/prune stage.
491
491
  *
492
492
  * #425 read-side law: the decay-relevant importance is CLAMPED at the
@@ -494,20 +494,21 @@ function parseTimestamp(ts) {
494
494
  * exactly 1.0 the decay rate is exactly 1.0 and the row never decays, so
495
495
  * legacy base-1.0 rows (and any write site that predates the cap) decay
496
496
  * again. The clamp applies to explicit importance passes too.
497
+ *
498
+ * #448: the access/connectivity HARDENING terms are REMOVED — the fade rate
499
+ * no longer depends on access or link history (a briefly-used memory was
500
+ * near-immortal: 10 accesses cut the decay rate to 3% of normal). Real use
501
+ * now raises the STORED score via the nightly promotion stage
502
+ * (consolidate.ts stagePromotion) instead of slowing future decay, so a
503
+ * promoted-then-abandoned memory fades on the same 365-day clock as any
504
+ * other, from a higher anchor.
497
505
  */
498
506
  function effectiveStrength(baseStrength, lastAccessed, now, options) {
499
507
  const rawImportance = options?.importance ?? baseStrength;
500
508
  const importance = Math.min(rawImportance, CALIBRATION.IMPORTANCE_CEILING);
501
- const accessCount = options?.accessCount ?? 0;
502
- const linkCount = options?.linkCount ?? 0;
503
509
  const hours = Math.max((now.getTime() - parseTimestamp(lastAccessed).getTime()) / 3_600_000, 0);
504
510
  // B: Importance slows decay
505
- let decayRate = 1.0 - BASE_DECAY * (1.0 - importance);
506
- // E: Access hardening
507
- const hardening = 0.7;
508
- decayRate = 1.0 - (1.0 - decayRate) * Math.pow(hardening, accessCount);
509
- // E: Connectivity hardening
510
- decayRate = 1.0 - (1.0 - decayRate) * Math.pow(hardening, linkCount);
511
+ const decayRate = 1.0 - BASE_DECAY * (1.0 - importance);
511
512
  // D: Asymptotic floor
512
513
  const floor = baseStrength * importance * 0.1;
513
514
  return floor + (baseStrength - floor) * Math.pow(decayRate, hours);
@@ -529,8 +530,6 @@ function computeScore(memory, distance, connectionCount, maxConnections, now, op
529
530
  // time — now stated at the call site so the triple-win coupling
530
531
  // (score share, decay rate, floor) is visible and single-sourced).
531
532
  importance: memory.base_strength ?? 0.5,
532
- accessCount: memory.access_count ?? 0,
533
- linkCount: connectionCount,
534
533
  });
535
534
  const connScore = maxConnections > 0 ? connectionCount / maxConnections : 0;
536
535
  const hoursSinceCreated = Math.max((now.getTime() - parseTimestamp(memory.created_at).getTime()) / 3_600_000, 0);
@@ -546,10 +545,11 @@ function computeScore(memory, distance, connectionCount, maxConnections, now, op
546
545
  // session captured last night ranks as ~1 day old (not 0), and backfilled
547
546
  // older content correctly gets no boost. The slow
548
547
  // `recency` term above (≈58-day half-life at weight 0.15) could never lift a
549
- // day-old memory past a hardened old one — measured case: an exact-match
550
- // 1-day-old memory (strength 0.50) lost to an unrelated memory at strength
551
- // 0.80. This is an ADDITIVE bonus that decays linearly to zero at the window
552
- // edge, so it cannot distort ranking among memories that are all old.
548
+ // day-old memory past an old high-strength one — measured case: an
549
+ // exact-match 1-day-old memory (strength 0.50) lost to an unrelated memory
550
+ // at strength 0.80. This is an ADDITIVE bonus that decays linearly to zero
551
+ // at the window edge, so it cannot distort ranking among memories that are
552
+ // all old.
553
553
  const ageDays = hoursSinceCreated / 24;
554
554
  if (memory.created_at && ageDays < scoringWeights.freshnessBoostDays) {
555
555
  const freshness = 1 - ageDays / scoringWeights.freshnessBoostDays;
@@ -832,10 +832,7 @@ async function retrieve(db, embedFn, query, options) {
832
832
  // signature — graph-only and single-channel candidates add nothing.
833
833
  bothChannel: source === "both",
834
834
  });
835
- const effStr = effectiveStrength(mem.base_strength ?? 0.5, mem.last_accessed, now, {
836
- accessCount: mem.access_count ?? 0,
837
- linkCount: connectionCounts.get(mem.id) ?? 0,
838
- });
835
+ const effStr = effectiveStrength(mem.base_strength ?? 0.5, mem.last_accessed, now);
839
836
  const rrf = rrfScores.get(mid) ?? 0;
840
837
  const normalizedRrf = maxRrf > 0 ? rrf / maxRrf : 0;
841
838
  // #205: composite/RRF blend is now config-driven (rrfCompositeWeight, 0.8
@@ -851,7 +848,8 @@ async function retrieve(db, embedFn, query, options) {
851
848
  scored.push({ mem, finalScore, effStr, connCount, similarity, source });
852
849
  }
853
850
  // 6. Sort and take top N — with cold-exposure slots (#192).
854
- // Access hardening + effective strength make past winners self-reinforcing:
851
+ // Effective strength + the promotion stage (#448) make past winners
852
+ // self-reinforcing:
855
853
  // 88% of the production corpus had never been returned by any query. Reserve
856
854
  // up to 2 of k for the best-scoring never-accessed candidates so the long
857
855
  // tail gets nonzero exposure whenever it is semantically in range. Slots are
@@ -899,10 +897,7 @@ async function retrieve(db, embedFn, query, options) {
899
897
  const connCount = storage.getLinks(db, terminalId, "both").length;
900
898
  const composite = computeScore(mem, DEFAULT_GRAPH_DISTANCE, connCount, maxConnections, now, { superseded: supersededIds.has(terminalId) });
901
899
  const finalScore = composite * scoringWeights.rrfCompositeWeight;
902
- const effStr = effectiveStrength(mem.base_strength ?? 0.5, mem.last_accessed, now, {
903
- accessCount: mem.access_count ?? 0,
904
- linkCount: connCount,
905
- });
900
+ const effStr = effectiveStrength(mem.base_strength ?? 0.5, mem.last_accessed, now);
906
901
  return { mem, finalScore, effStr, connCount, similarity: null, source: "graph" };
907
902
  });
908
903
  const results = top.map((t) => formatResult(t.mem, t.finalScore, t.effStr, t.connCount, {
@@ -948,10 +943,7 @@ function searchRecent(db, options) {
948
943
  const score = computeScore(mem, DEFAULT_GRAPH_DISTANCE, connCount, maxConnections, now, {
949
944
  superseded: supersededRecent.has(mem.id),
950
945
  });
951
- const effStr = effectiveStrength(mem.base_strength ?? 0.5, mem.last_accessed, now, {
952
- accessCount: mem.access_count ?? 0,
953
- linkCount: connectionCounts.get(mem.id) ?? 0,
954
- });
946
+ const effStr = effectiveStrength(mem.base_strength ?? 0.5, mem.last_accessed, now);
955
947
  scored.push({ mem, score, effStr, connCount });
956
948
  }
957
949
  scored.sort((a, b) => b.score - a.score);
@@ -977,10 +969,7 @@ function searchRecent(db, options) {
977
969
  return null;
978
970
  const connCount = storage.getLinks(db, terminalId, "both").length;
979
971
  const score = computeScore(mem, DEFAULT_GRAPH_DISTANCE, connCount, maxConnections, now, { superseded: supersededRecent.has(terminalId) });
980
- const effStr = effectiveStrength(mem.base_strength ?? 0.5, mem.last_accessed, now, {
981
- accessCount: mem.access_count ?? 0,
982
- linkCount: connCount,
983
- });
972
+ const effStr = effectiveStrength(mem.base_strength ?? 0.5, mem.last_accessed, now);
984
973
  return { mem, score, effStr, connCount };
985
974
  });
986
975
  const results = top.map((t) => formatResult(t.mem, t.score, t.effStr, t.connCount));
package/dist/status.js CHANGED
@@ -66,6 +66,24 @@ async function runStatus() {
66
66
  console.log(`Memories: ${stats.memories} (${typeStr || "none"})`);
67
67
  console.log(`Links: ${stats.links}`);
68
68
  console.log(`DB size: ${(stats.db_size_bytes / 1024).toFixed(1)} KB`);
69
+ // 0.21 migration detection (#425): pre-0.21 stores have inflated importance
70
+ // scores (median ~0.80 vs the honest ~0.40). If the live median is high,
71
+ // recommend the one-shot rescore.
72
+ if (stats.memories > 0) {
73
+ try {
74
+ const live = db.prepare("SELECT base_strength FROM memories WHERE base_strength IS NOT NULL AND (status IS NULL OR status NOT IN ('absorbed','superseded','retracted')) ORDER BY base_strength").all();
75
+ if (live.length >= 10) {
76
+ const median = live[Math.floor(live.length / 2)].base_strength;
77
+ if (median >= 0.6) {
78
+ console.log(``);
79
+ console.log(`⚠ Pre-0.21 importance scores detected (median ${median.toFixed(2)}).`);
80
+ console.log(` Run: npx @gamaze/hicortex rescore-importance --apply`);
81
+ console.log(` to re-score your store under the honest rubric.`);
82
+ }
83
+ }
84
+ }
85
+ catch { /* non-fatal */ }
86
+ }
69
87
  db.close();
70
88
  }
71
89
  catch (err) {
package/dist/storage.d.ts CHANGED
@@ -68,7 +68,8 @@ export declare function enrichMemory(db: Database.Database, memoryId: string, no
68
68
  * Record that memories appeared in a pushed recall index (#192): bump
69
69
  * shown_count and refresh last_accessed (a mild strengthen — the decay clock
70
70
  * resets so topically-live memories stop sinking) WITHOUT touching
71
- * access_count, which stays reserved for real use (hardening + prune shield).
71
+ * access_count, which stays reserved for real use (the promotion signal
72
+ * #448 + the prune shield).
72
73
  */
73
74
  export declare function touchMemoriesShown(db: Database.Database, memoryIds: string[], nowIsoStr: string): void;
74
75
  /**
package/dist/storage.js CHANGED
@@ -190,6 +190,10 @@ const ALLOWED_UPDATE_FIELDS = new Set([
190
190
  // stageImportance, the enrich path, and the rescore-importance backfill —
191
191
  // the moment a row's base_strength is settled under some rubric.
192
192
  "importance_scored_at",
193
+ // Promotion baseline (#448, migration v20): written by the nightly
194
+ // promotion stage and dedup merges (which sum a cluster's counters onto
195
+ // the canonical — the baseline must move with the summed access_count).
196
+ "promotion_last_count",
193
197
  ]);
194
198
  /**
195
199
  * Update specific fields on a memory.
@@ -256,7 +260,8 @@ function enrichMemory(db, memoryId, nowIsoStr) {
256
260
  * Record that memories appeared in a pushed recall index (#192): bump
257
261
  * shown_count and refresh last_accessed (a mild strengthen — the decay clock
258
262
  * resets so topically-live memories stop sinking) WITHOUT touching
259
- * access_count, which stays reserved for real use (hardening + prune shield).
263
+ * access_count, which stays reserved for real use (the promotion signal
264
+ * #448 + the prune shield).
260
265
  */
261
266
  function touchMemoriesShown(db, memoryIds, nowIsoStr) {
262
267
  if (memoryIds.length === 0)
package/dist/types.d.ts CHANGED
@@ -62,6 +62,16 @@ export interface Memory {
62
62
  * rows, which stay NULL for exactly one scoring under the new rubric).
63
63
  */
64
64
  importance_scored_at?: string | null;
65
+ /**
66
+ * Promotion baseline (#448, migration v20): the access_count the nightly
67
+ * promotion stage (stagePromotion) last consumed — the delta
68
+ * access_count − promotion_last_count drives the per-use strength bump.
69
+ * Written by the stage, the migration backfill, and dedup merges (the
70
+ * baseline moves with the summed counter so a merge never replays the
71
+ * losers' lifetime accesses as fresh promotions). Optional because
72
+ * rowToMemory is a cast over SELECT * rows.
73
+ */
74
+ promotion_last_count?: number | null;
65
75
  }
66
76
  /** A link between two memories. */
67
77
  export interface MemoryLink {
@@ -228,10 +238,6 @@ export interface ConsolidationReport {
228
238
  no_association_decayed?: number;
229
239
  reason?: string;
230
240
  };
231
- hub_boost?: {
232
- hubs_found: number;
233
- boosted: number;
234
- };
235
241
  links?: {
236
242
  auto_linked: number;
237
243
  llm_classified?: number;
@@ -391,6 +397,21 @@ export interface ConsolidationReport {
391
397
  pruned: number;
392
398
  failed: number;
393
399
  };
400
+ /**
401
+ * Strength promotion (#448) — runs PRE-SKIP (quiet nights still promote
402
+ * the day's uses), BEFORE memory_cap eviction (a promoted row survives a
403
+ * cap it would otherwise lose). Zero LLM: it sits in the deterministic
404
+ * zone, before the BudgetTracker exists.
405
+ */
406
+ promotion?: {
407
+ /** Memories whose base_strength was bumped this run (delta iterations). */
408
+ promoted: number;
409
+ /**
410
+ * Demotion-set rows (superseded/retracted/absorbed + superseded_by-link
411
+ * sources) with a use delta — no bump, baseline advanced only.
412
+ */
413
+ demoted_skipped: number;
414
+ };
394
415
  /** Capacity eviction (#245) — runs after decay_prune. When the corpus
395
416
  * exceeds `memorySoftCap`, the lowest-effectiveStrength memories are
396
417
  * evicted until under the cap. `cap = 0` (disabled) → evicted = 0. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gamaze/hicortex",
3
- "version": "0.20.10",
3
+ "version": "0.22.0",
4
4
  "description": "Persistent agent identity for AI agents \u2014 a hand-edited identity layer, nightly-distilled experience, and lessons injected every session, shared across your whole fleet. Works with Hermes, OpenClaw, Claude Code, Pi, and opencode.",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
package/server.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "$schema": "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json",
3
3
  "name": "io.github.gamaze-labs/hicortex",
4
- "title": "Hicortex",
4
+ "title": "Hicortex \u2014 AI Fleet Memory",
5
5
  "description": "Shared fleet memory for AI agents: nightly self-correction, recall every prompt (supported agents).",
6
- "version": "0.20.9",
6
+ "version": "0.22.0",
7
7
  "packages": [
8
8
  {
9
9
  "registryType": "npm",
10
10
  "identifier": "@gamaze/hicortex",
11
- "version": "0.20.9",
11
+ "version": "0.22.0",
12
12
  "transport": {
13
13
  "type": "stdio",
14
14
  "command": "npx",
@@ -41,4 +41,4 @@
41
41
  "source": "github"
42
42
  },
43
43
  "websiteUrl": "https://hicortex.gamaze.com"
44
- }
44
+ }