@gamaze/hicortex 0.27.4 → 0.29.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.
Files changed (94) hide show
  1. package/assets/dashboard.html +1898 -3211
  2. package/assets/viz.html +229 -2
  3. package/dist/backfill-privacy.d.ts +68 -45
  4. package/dist/backfill-privacy.js +236 -145
  5. package/dist/calibration.d.ts +67 -68
  6. package/dist/calibration.js +75 -78
  7. package/dist/capture-health.d.ts +2 -2
  8. package/dist/capture-health.js +2 -2
  9. package/dist/classification.d.ts +141 -12
  10. package/dist/classification.js +214 -27
  11. package/dist/classify-domains.d.ts +1 -1
  12. package/dist/classify-domains.js +2 -2
  13. package/dist/cli-args.d.ts +5 -3
  14. package/dist/cli-args.js +7 -3
  15. package/dist/cli.d.ts +2 -0
  16. package/dist/cli.js +64 -16
  17. package/dist/cluster.d.ts +12 -9
  18. package/dist/cluster.js +9 -6
  19. package/dist/consolidate.d.ts +93 -43
  20. package/dist/consolidate.js +255 -119
  21. package/dist/dashboard.d.ts +48 -5
  22. package/dist/dashboard.js +55 -3
  23. package/dist/db.js +27 -6
  24. package/dist/dedup.d.ts +2 -3
  25. package/dist/dedup.js +2 -3
  26. package/dist/distill-queue.d.ts +36 -4
  27. package/dist/distill-queue.js +80 -18
  28. package/dist/distiller.d.ts +1 -1
  29. package/dist/distiller.js +13 -12
  30. package/dist/domain-classify.d.ts +8 -9
  31. package/dist/domain-classify.js +6 -7
  32. package/dist/graph.d.ts +15 -5
  33. package/dist/graph.js +46 -13
  34. package/dist/hermes-transcript-reader.d.ts +1 -1
  35. package/dist/hermes-transcript-reader.js +1 -1
  36. package/dist/init.d.ts +30 -2
  37. package/dist/init.js +48 -3
  38. package/dist/llm.d.ts +1 -1
  39. package/dist/llm.js +5 -5
  40. package/dist/mcp-server.js +323 -59
  41. package/dist/memory-instructions.d.ts +2 -2
  42. package/dist/memory-instructions.js +2 -2
  43. package/dist/nightly.d.ts +1 -1
  44. package/dist/nightly.js +64 -5
  45. package/dist/nofit.d.ts +2 -2
  46. package/dist/nofit.js +2 -2
  47. package/dist/observed-agents.d.ts +54 -0
  48. package/dist/observed-agents.js +78 -0
  49. package/dist/project-canonicalize.d.ts +6 -5
  50. package/dist/project-canonicalize.js +6 -5
  51. package/dist/prompts.d.ts +29 -8
  52. package/dist/prompts.js +39 -16
  53. package/dist/quality-scoreboard.d.ts +1 -1
  54. package/dist/recall-hook-cli.d.ts +1 -1
  55. package/dist/recall-hook-cli.js +2 -2
  56. package/dist/recall-index.d.ts +28 -14
  57. package/dist/recall-index.js +22 -10
  58. package/dist/recall-precision.d.ts +3 -3
  59. package/dist/recall-precision.js +5 -4
  60. package/dist/reconcile-projects.d.ts +2 -2
  61. package/dist/reconcile-projects.js +2 -2
  62. package/dist/reconsolidation.d.ts +9 -2
  63. package/dist/reconsolidation.js +48 -31
  64. package/dist/relink.d.ts +2 -2
  65. package/dist/relink.js +4 -4
  66. package/dist/rescore-importance.d.ts +2 -2
  67. package/dist/rescore-importance.js +22 -3
  68. package/dist/retrieval.d.ts +14 -0
  69. package/dist/retrieval.js +11 -11
  70. package/dist/schema-prototypes.d.ts +1 -1
  71. package/dist/schema-prototypes.js +1 -1
  72. package/dist/seed-lesson.js +4 -2
  73. package/dist/spaces-api.d.ts +104 -0
  74. package/dist/spaces-api.js +193 -0
  75. package/dist/spaces-cli.d.ts +90 -0
  76. package/dist/spaces-cli.js +245 -0
  77. package/dist/spaces.d.ts +187 -0
  78. package/dist/spaces.js +360 -0
  79. package/dist/storage.d.ts +47 -10
  80. package/dist/storage.js +74 -17
  81. package/dist/sweep-volatile.d.ts +2 -2
  82. package/dist/sweep-volatile.js +2 -2
  83. package/dist/telemetry-cli.d.ts +1 -1
  84. package/dist/telemetry-cli.js +1 -1
  85. package/dist/type-classify.d.ts +1 -1
  86. package/dist/type-classify.js +1 -1
  87. package/dist/type-labels.d.ts +1 -1
  88. package/dist/type-labels.js +1 -1
  89. package/dist/types.d.ts +43 -20
  90. package/dist/wrapper-prompt.d.ts +2 -2
  91. package/dist/wrapper-prompt.js +2 -2
  92. package/opencode-plugin/hicortex/index.ts +562 -364
  93. package/package.json +2 -2
  94. package/server.json +2 -2
package/dist/nightly.d.ts CHANGED
@@ -21,7 +21,7 @@
21
21
  * already-captured session yields an empty delta.
22
22
  *
23
23
  * First run (#436): with NO watermark yet, since = now − firstRunLookbackDays
24
- * (default 7 — owner ruling 2026-09-14: full-history first-run ingestion is
24
+ * (default 7 — #436 ruling: full-history first-run ingestion is
25
25
  * not feasible; a long-term AI user's entire session store must not be
26
26
  * discovered night one). The widening-only invariant composes unchanged:
27
27
  * min(now−7d, now−N) — a recapture window wider than the default widens, a
package/dist/nightly.js CHANGED
@@ -62,6 +62,7 @@ const db_js_1 = require("./db.js");
62
62
  const config_read_js_1 = require("./config-read.js");
63
63
  const calibration_js_1 = require("./calibration.js");
64
64
  const classification_js_1 = require("./classification.js");
65
+ const spaces_js_1 = require("./spaces.js");
65
66
  const embedder_js_1 = require("./embedder.js");
66
67
  const storage = __importStar(require("./storage.js"));
67
68
  const consolidate_js_1 = require("./consolidate.js");
@@ -162,7 +163,7 @@ function readLastRun(stateDir = HICORTEX_HOME) {
162
163
  * already-captured session yields an empty delta.
163
164
  *
164
165
  * First run (#436): with NO watermark yet, since = now − firstRunLookbackDays
165
- * (default 7 — owner ruling 2026-09-14: full-history first-run ingestion is
166
+ * (default 7 — #436 ruling: full-history first-run ingestion is
166
167
  * not feasible; a long-term AI user's entire session store must not be
167
168
  * discovered night one). The widening-only invariant composes unchanged:
168
169
  * min(now−7d, now−N) — a recapture window wider than the default widens, a
@@ -579,7 +580,12 @@ async function runNightly(options = {}) {
579
580
  // drain's confidential items and (from the pool-aware stages) every
580
581
  // consolidation touch of confidential text; absent = those hold/skip,
581
582
  // never fall back.
582
- const resolvedPair = (0, classification_js_1.resolveLlmPair)(savedConfig);
583
+ // #642: the spaces resolve ONCE here and feed the pair (per-space
584
+ // clients, AC-9's inheritance ladder), the unknown-id mirror below, the
585
+ // drain's known set, and the consolidation threading — one resolution,
586
+ // one definition (the confidential seam's discipline).
587
+ const spaceRes = (0, spaces_js_1.resolveSpaces)(savedConfig);
588
+ const resolvedPair = (0, classification_js_1.resolveLlmPair)(savedConfig, spaceRes.spaces);
583
589
  if (resolvedPair.reason === "claude_binary_missing") {
584
590
  console.warn("[hicortex] claude-cli configured but binary not found — consolidation skipped");
585
591
  }
@@ -587,6 +593,12 @@ async function runNightly(options = {}) {
587
593
  const llm = resolvedPair.pair?.standard ?? null;
588
594
  const confidentialLlm = resolvedPair.pair?.confidential ?? null;
589
595
  const confidentialLlmConfig = resolvedPair.confidentialConfig;
596
+ // #642 AC-9: per-space clients/configs — empty maps on a legacy config
597
+ // (the only space IS confidential), so every threading below is a no-op
598
+ // there and the run is byte-identical.
599
+ const spaceClients = resolvedPair.spaceClients;
600
+ const spaceConfigs = resolvedPair.spaceConfigs;
601
+ const knownSpaces = (0, spaces_js_1.knownSpaceIds)({ byId: spaceRes.byId });
590
602
  // #332: the ONE loud warning when the circle is active without the
591
603
  // confidential model (daemon boot mirrors this). "Active" includes
592
604
  // confidentialPaths patterns configured (#609) — a patterns-only circle
@@ -598,6 +610,42 @@ async function runNightly(options = {}) {
598
610
  confidentialRows: db.prepare("SELECT COUNT(*) AS c FROM memories WHERE privacy = 'confidential'").get().c,
599
611
  queueConfidential: db.prepare("SELECT COUNT(*) AS c FROM distill_queue WHERE privacy = 'confidential'").get().c,
600
612
  });
613
+ // #642 AC-7: mirror the daemon boot's unknown-space-id warning at the
614
+ // nightly funnel (same gate — only when non-empty) so the nightly log
615
+ // carries it too: stored ids no configured space claims are invisible to
616
+ // every requester until configured or re-stamped.
617
+ {
618
+ const unknownIds = (0, spaces_js_1.unknownStoredSpaceIds)(db, knownSpaces);
619
+ if (unknownIds.length > 0) {
620
+ console.warn(`[hicortex] Unknown space ids stored in the DB: ${unknownIds.join(", ")} — ` +
621
+ `no configured space claims them, so they are invisible to every requester ` +
622
+ `until configured or re-stamped (#642 AC-7)`);
623
+ }
624
+ }
625
+ // #642 AC-9: the per-space hold warnings (the warnIfCircleUnconfigured
626
+ // companion) — one line per ACTIVE space with no effective model. On a
627
+ // legacy or fully-configured install the list is empty and nothing
628
+ // prints (the zero-change default).
629
+ {
630
+ const rowsBySpace = new Map();
631
+ const queueBySpace = new Map();
632
+ for (const table of ["memories", "distill_queue"]) {
633
+ const target = table === "memories" ? rowsBySpace : queueBySpace;
634
+ for (const row of db
635
+ .prepare(`SELECT privacy, COUNT(*) AS c FROM ${table} ` +
636
+ `WHERE privacy IS NOT NULL AND privacy NOT IN ('standard', 'confidential') ` +
637
+ `GROUP BY privacy`)
638
+ .all()) {
639
+ target.set(row.privacy, row.c);
640
+ }
641
+ }
642
+ for (const warning of (0, classification_js_1.spaceHoldWarnings)(spaceRes.spaces, spaceClients, {
643
+ rowsBySpace,
644
+ queueBySpace,
645
+ })) {
646
+ console.warn(warning);
647
+ }
648
+ }
601
649
  // Steps 1+2: single-flight capture. The lock guards ONLY the capture phase
602
650
  // (fix 10). We acquire it BEFORE reading the cursor store so a run that
603
651
  // waited out another cannot act on a stale snapshot and clobber its cursor
@@ -757,6 +805,13 @@ async function runNightly(options = {}) {
757
805
  // boot-time alias map the daemon resolved (rows queued pre-deploy
758
806
  // still hold raw wire labels).
759
807
  projectAliases: (0, project_canonicalize_js_1.parseProjectAliases)(savedConfig),
808
+ // #642 AC-9/AC-7: per-space clients (a space item distills on ITS
809
+ // model, holds without one) + the known set for the insert-time
810
+ // normalize boundary (a retired stamp holds its row). Both empty on
811
+ // a legacy config.
812
+ spaceClients,
813
+ spaceConfigs,
814
+ knownSpaces,
760
815
  });
761
816
  // #5 metering, same as the daemon's sync path: record tokens against
762
817
  // the monthly budget (incl. a failed item's partial usage) and fold
@@ -917,7 +972,10 @@ async function runNightly(options = {}) {
917
972
  // #332: the confidential client — every pool-aware stage
918
973
  // (importance batches, reflection, domain classification,
919
974
  // reconsolidation) routes confidential text here; absent ⇒ hold.
920
- confidentialLlm);
975
+ confidentialLlm,
976
+ // #642: per-space clients + the resolved spaces (config order,
977
+ // privacy lines). Empty/[] on a legacy config — byte-identical.
978
+ spaceClients, spaceConfigs, spaceRes.spaces);
921
979
  console.log(`[hicortex] Consolidation ${report.status} in ${report.elapsed_seconds}s` +
922
980
  (report.stages.reflection ? ` (${report.stages.reflection.lessons_generated} lessons)` : ""));
923
981
  consolidationStatus = report.status;
@@ -1258,8 +1316,9 @@ async function runNightly(options = {}) {
1258
1316
  agent: agentType,
1259
1317
  mem: storage.countMemories(db),
1260
1318
  // #332: telemetry counts the whole store (server-internal metric —
1261
- // not an agent-facing surface, so no membership gate).
1262
- lessons: storage.getLessons(db, 365, null, { includeConfidential: true }).length,
1319
+ // not an agent-facing surface, so no membership gate). #642: allSpaces
1320
+ // is the explicit whole-store form (every pool).
1321
+ lessons: storage.getLessons(db, 365, null, { allSpaces: true }).length,
1263
1322
  lessonsGenerated,
1264
1323
  consolidation: consolidationStatus,
1265
1324
  // #246: total tokens consumed by this run's consolidation (absent on
package/dist/nofit.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * No-fit lifecycle — weak-primary floor + no-association decay
3
- * (owner amendment 07.07).
3
+ * (spec 2026-07-07 amendment).
4
4
  *
5
5
  * THE MODEL
6
6
  * ---------
@@ -16,7 +16,7 @@
16
16
  * humbly, with one weak association.
17
17
  *
18
18
  * 2. NO ASSOCIATION — best cosine below the floor means the memory
19
- * associates with nothing the owner cares about. It is NOT tagged;
19
+ * associates with nothing the user cares about. It is NOT tagged;
20
20
  * instead its base_strength is HALVED (floored at
21
21
  * NO_ASSOCIATION_MIN_STRENGTH) so the existing decay/prune stage
22
22
  * eventually removes it. domain stays NULL, which keeps the memory in
package/dist/nofit.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  /**
3
3
  * No-fit lifecycle — weak-primary floor + no-association decay
4
- * (owner amendment 07.07).
4
+ * (spec 2026-07-07 amendment).
5
5
  *
6
6
  * THE MODEL
7
7
  * ---------
@@ -17,7 +17,7 @@
17
17
  * humbly, with one weak association.
18
18
  *
19
19
  * 2. NO ASSOCIATION — best cosine below the floor means the memory
20
- * associates with nothing the owner cares about. It is NOT tagged;
20
+ * associates with nothing the user cares about. It is NOT tagged;
21
21
  * instead its base_strength is HALVED (floored at
22
22
  * NO_ASSOCIATION_MIN_STRENGTH) so the existing decay/prune stage
23
23
  * eventually removes it. domain stays NULL, which keeps the memory in
@@ -0,0 +1,54 @@
1
+ /**
2
+ * #642 AC-11 — the observed-agents store: read-side agent names, persisted
3
+ * for the first time.
4
+ *
5
+ * Before this store, the only agent names the server ever saw were
6
+ * capture-time `source_agent` stamps — a workspace that had PROMPTED but not
7
+ * yet been captured (its first nightly is hours away) was invisible to the
8
+ * dashboard, so the operator could not assign it to a space exactly when the
9
+ * "what is this new folder?" question first arises. First-prompt discovery
10
+ * closes that gap: the ONE seam every gated read already calls
11
+ * (requesterVisibleSpaces in mcp-server.ts) records the sanitized `agent`
12
+ * param, and the dashboard's spaces block (AC-10/AC-12) lists every observed
13
+ * agent that is in no space's members as UNASSIGNED.
14
+ *
15
+ * Storage-style module (the db.ts/storage.ts layout): recordObservedAgent is
16
+ * the raw upsert (throws on store errors like any storage fn);
17
+ * recordObservedAgentSighting is the fail-soft READ-seam wrapper — a store
18
+ * hiccup must never break the read itself (the sighting is advisory metadata,
19
+ * not a gate input), so it sanitizes, swallows store errors with ONE
20
+ * lifetime warn, and hands back the sanitized id so the caller resolves
21
+ * membership from the SAME value it recorded.
22
+ */
23
+ import type Database from "better-sqlite3";
24
+ /** One observed workspace/agent: firstSeen is its discovery time (never
25
+ * rewritten), lastSeen its most recent gated read (the dashboard's
26
+ * "newest first" ordering). */
27
+ export interface ObservedAgent {
28
+ agent: string;
29
+ first_seen: string;
30
+ last_seen: string;
31
+ }
32
+ /**
33
+ * Upsert one observed agent: first_seen is PRESERVED on conflict (discovery
34
+ * is a fact about the past), last_seen always advances to now. One
35
+ * INSERT ... ON CONFLICT statement — no read-modify-write race window between
36
+ * two concurrent reads of the same agent.
37
+ */
38
+ export declare function recordObservedAgent(db: Database.Database, agent: string): void;
39
+ /**
40
+ * Every observed agent, newest activity first (last_seen DESC, agent ASC as
41
+ * the deterministic tiebreak — ISO timestamps share ms, not everybody sleeps
42
+ * between prompts). The GET /spaces adapter feeds this straight into the
43
+ * unassigned computation.
44
+ */
45
+ export declare function listObservedAgents(db: Database.Database): ObservedAgent[];
46
+ /**
47
+ * The read-seam wrapper requesterVisibleSpaces calls on every gated read:
48
+ * sanitize the raw `agent` (the ?agent=/body agent namespace — invalid or
49
+ * absent records nothing), upsert it, and return the sanitized id for the
50
+ * caller's membership resolution. Fail-soft by design: the observed-agents
51
+ * store is advisory (first-prompt discovery), so a store hiccup logs ONE
52
+ * lifetime warn and never breaks the read that triggered it.
53
+ */
54
+ export declare function recordObservedAgentSighting(db: Database.Database, rawAgent: unknown): string | null;
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ /**
3
+ * #642 AC-11 — the observed-agents store: read-side agent names, persisted
4
+ * for the first time.
5
+ *
6
+ * Before this store, the only agent names the server ever saw were
7
+ * capture-time `source_agent` stamps — a workspace that had PROMPTED but not
8
+ * yet been captured (its first nightly is hours away) was invisible to the
9
+ * dashboard, so the operator could not assign it to a space exactly when the
10
+ * "what is this new folder?" question first arises. First-prompt discovery
11
+ * closes that gap: the ONE seam every gated read already calls
12
+ * (requesterVisibleSpaces in mcp-server.ts) records the sanitized `agent`
13
+ * param, and the dashboard's spaces block (AC-10/AC-12) lists every observed
14
+ * agent that is in no space's members as UNASSIGNED.
15
+ *
16
+ * Storage-style module (the db.ts/storage.ts layout): recordObservedAgent is
17
+ * the raw upsert (throws on store errors like any storage fn);
18
+ * recordObservedAgentSighting is the fail-soft READ-seam wrapper — a store
19
+ * hiccup must never break the read itself (the sighting is advisory metadata,
20
+ * not a gate input), so it sanitizes, swallows store errors with ONE
21
+ * lifetime warn, and hands back the sanitized id so the caller resolves
22
+ * membership from the SAME value it recorded.
23
+ */
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ exports.recordObservedAgent = recordObservedAgent;
26
+ exports.listObservedAgents = listObservedAgents;
27
+ exports.recordObservedAgentSighting = recordObservedAgentSighting;
28
+ const identity_store_js_1 = require("./identity-store.js");
29
+ /**
30
+ * Upsert one observed agent: first_seen is PRESERVED on conflict (discovery
31
+ * is a fact about the past), last_seen always advances to now. One
32
+ * INSERT ... ON CONFLICT statement — no read-modify-write race window between
33
+ * two concurrent reads of the same agent.
34
+ */
35
+ function recordObservedAgent(db, agent) {
36
+ const now = new Date().toISOString();
37
+ db.prepare(`INSERT INTO observed_agents (agent, first_seen, last_seen) VALUES (?, ?, ?)
38
+ ON CONFLICT(agent) DO UPDATE SET last_seen = excluded.last_seen`).run(agent, now, now);
39
+ }
40
+ /**
41
+ * Every observed agent, newest activity first (last_seen DESC, agent ASC as
42
+ * the deterministic tiebreak — ISO timestamps share ms, not everybody sleeps
43
+ * between prompts). The GET /spaces adapter feeds this straight into the
44
+ * unassigned computation.
45
+ */
46
+ function listObservedAgents(db) {
47
+ return db
48
+ .prepare(`SELECT agent, first_seen, last_seen FROM observed_agents
49
+ ORDER BY last_seen DESC, agent ASC`)
50
+ .all();
51
+ }
52
+ /** Once-per-process warn flag: a broken store errors on EVERY read, and the
53
+ * read must keep working — one warn line, then silence. */
54
+ let warnedStoreFailure = false;
55
+ /**
56
+ * The read-seam wrapper requesterVisibleSpaces calls on every gated read:
57
+ * sanitize the raw `agent` (the ?agent=/body agent namespace — invalid or
58
+ * absent records nothing), upsert it, and return the sanitized id for the
59
+ * caller's membership resolution. Fail-soft by design: the observed-agents
60
+ * store is advisory (first-prompt discovery), so a store hiccup logs ONE
61
+ * lifetime warn and never breaks the read that triggered it.
62
+ */
63
+ function recordObservedAgentSighting(db, rawAgent) {
64
+ const id = typeof rawAgent === "string" && rawAgent ? (0, identity_store_js_1.sanitizeAgentId)(rawAgent) : null;
65
+ if (!id)
66
+ return null;
67
+ try {
68
+ recordObservedAgent(db, id);
69
+ }
70
+ catch (err) {
71
+ if (!warnedStoreFailure) {
72
+ warnedStoreFailure = true;
73
+ console.warn(`[hicortex] observed-agents store unavailable — first-prompt discovery paused ` +
74
+ `(reads are unaffected). Cause: ${err instanceof Error ? err.message : String(err)}`);
75
+ }
76
+ }
77
+ return id;
78
+ }
@@ -4,10 +4,11 @@
4
4
  * The SAME project arrives under different labels: `hicortex` vs `Hicortex`
5
5
  * (case comes from the session-root dir name) split one project across two,
6
6
  * and junk labels (`default`, version-suffix numerics like `3`) carry no
7
- * project identity at all. Measured on the 22,691-memory corpus audit (#565
8
- * WS1): 5,544 rows split on case alone, 14% of the corpus under junk labels,
9
- * and project mismatch blocking 59 of 69 near-duplicate clusters in
10
- * `hicortex dedup` (423 excess rows). Every comparison that keys on project
7
+ * project identity at all. Measured on a production corpus audit (#565
8
+ * WS1): a meaningful share of rows split on case alone, a double-digit
9
+ * percent of the corpus under junk labels,
10
+ * and project mismatch blocking most near-duplicate clusters in
11
+ * `hicortex dedup`. Every comparison that keys on project
11
12
  * (recall affinity, lesson selection, the dedup project rail) is exact
12
13
  * `===` — so variants break affinity that should exist.
13
14
  *
@@ -28,7 +29,7 @@
28
29
  */
29
30
  /**
30
31
  * The mechanical fold: trim + lowercase. Labels are dir-name derived and
31
- * display-lowercase was accepted by the owner (no case-preservation
32
+ * display-lowercase was the accepted choice (no case-preservation
32
33
  * machinery — Option 3 stayed rejected), so this is the whole canonical
33
34
  * alphabet.
34
35
  */
@@ -5,10 +5,11 @@
5
5
  * The SAME project arrives under different labels: `hicortex` vs `Hicortex`
6
6
  * (case comes from the session-root dir name) split one project across two,
7
7
  * and junk labels (`default`, version-suffix numerics like `3`) carry no
8
- * project identity at all. Measured on the 22,691-memory corpus audit (#565
9
- * WS1): 5,544 rows split on case alone, 14% of the corpus under junk labels,
10
- * and project mismatch blocking 59 of 69 near-duplicate clusters in
11
- * `hicortex dedup` (423 excess rows). Every comparison that keys on project
8
+ * project identity at all. Measured on a production corpus audit (#565
9
+ * WS1): a meaningful share of rows split on case alone, a double-digit
10
+ * percent of the corpus under junk labels,
11
+ * and project mismatch blocking most near-duplicate clusters in
12
+ * `hicortex dedup`. Every comparison that keys on project
12
13
  * (recall affinity, lesson selection, the dedup project rail) is exact
13
14
  * `===` — so variants break affinity that should exist.
14
15
  *
@@ -33,7 +34,7 @@ exports.canonicalizeProject = canonicalizeProject;
33
34
  exports.parseProjectAliases = parseProjectAliases;
34
35
  /**
35
36
  * The mechanical fold: trim + lowercase. Labels are dir-name derived and
36
- * display-lowercase was accepted by the owner (no case-preservation
37
+ * display-lowercase was the accepted choice (no case-preservation
37
38
  * machinery — Option 3 stayed rejected), so this is the whole canonical
38
39
  * alphabet.
39
40
  */
package/dist/prompts.d.ts CHANGED
@@ -26,17 +26,29 @@ export declare const REFLECTION_PRIVACY_LINE_STANDARD = "Privacy: Never include
26
26
  * (c) credentials/passwords/API keys/secrets are STILL never included.
27
27
  */
28
28
  export declare const REFLECTION_PRIVACY_LINE_CONFIDENTIAL = "Privacy: this pool serves the confidential circle only (confidential memories). Lesson text may reference the user's personal domains (names, health, finances) at the process level where needed to make the lesson actionable. Credentials, passwords, API keys, and other secrets are still never included \u2014 abstract those away.";
29
+ /**
30
+ * The generic SPACE pool's reflection privacy line (#642) — the default for
31
+ * every configured space without an explicit `privacyLine`. Modeled on the
32
+ * confidential line (the pool serves its members only; personal domains at
33
+ * the process level where needed; secrets still never included), neutral
34
+ * private-pool wording: any space can carry it, confidential included. The
35
+ * `confidential` space itself is seeded the SHIPPED confidential line above
36
+ * (byte-identical prompts, #602 pin) — the seeding lives in spaces.ts
37
+ * resolution, never in prompt-building code.
38
+ */
39
+ export declare const REFLECTION_PRIVACY_LINE_SPACE = "Privacy: this pool serves its space's members only (space memories). Lesson text may reference the user's personal domains (names, health, finances) at the process level where needed to make the lesson actionable. Credentials, passwords, API keys, and other secrets are still never included \u2014 abstract those away.";
29
40
  /**
30
41
  * Importance scoring prompt. Takes a {memories_block} with indexed memories.
31
42
  *
32
43
  * RE-ANCHORED (#425): the pre-fix anchors put "useful context" at 0.3-0.5 —
33
44
  * but the distiller's ephemera gate already removes trivia before anything
34
45
  * reaches this scorer, so the model only ever saw curated material and the
35
- * distribution compressed upward (measured on the production snapshot via
36
- * eval:importance: median base 0.8, ~11% at exactly 1.0, which the decay
37
- * model never forgets). The anchors now place routine-but-curated content
38
- * LOW and add an explicit distribution instruction (owner decision D2,
39
- * 2026-09-13: target median 0.30-0.40, p90 <= 0.75; 1.0 is never a valid
46
+ * distribution compressed upward (measured on a production snapshot via
47
+ * eval:importance: most memories clustered high, a meaningful share at
48
+ * exactly 1.0, which the decay model never forgets). The anchors now place
49
+ * routine-but-curated content
50
+ * LOW and add an explicit distribution instruction (decision D2:
51
+ * target median 0.30-0.40, p90 <= 0.75; 1.0 is never a valid
40
52
  * score). The strict JSON-array response contract is unchanged.
41
53
  */
42
54
  export declare function importanceScoring(memoriesBlock: string): string;
@@ -54,12 +66,21 @@ export declare function importanceScoring(memoriesBlock: string): string;
54
66
  * API keys/secrets are never included. Everything else in the prompt
55
67
  * (generality bar, examples, output schema) is shared verbatim by both
56
68
  * pools — pinned by tests/reflection-prompt.test.ts.
69
+ *
70
+ * #642 SPACE-AWARE: the optional `privacyLine` argument is the RESOLVED
71
+ * per-space line (SpaceDef.privacyLine — concrete by the time a SpaceDef
72
+ * exists: explicit config, the confidential space's seeded #602 line, or
73
+ * REFLECTION_PRIVACY_LINE_SPACE). When given it REPLACES the two-constant
74
+ * selection entirely; absent, the #602 behavior is byte-identical. The
75
+ * caller (consolidate.ts reflectPool) threads `spaceById.get(pool)?.privacyLine`
76
+ * — undefined for 'standard', the seeded confidential text for 'confidential'
77
+ * (identical bytes to the constant, so both legacy pools are unchanged).
57
78
  */
58
- export declare function reflection(memoriesBlock: string, recentLessons?: string, pool?: MemoryPrivacy): string;
79
+ export declare function reflection(memoriesBlock: string, recentLessons?: string, pool?: MemoryPrivacy, privacyLine?: string): string;
59
80
  /**
60
81
  * Distillation prompt. Extracts knowledge from a session transcript.
61
82
  *
62
- * LAYOUT (REVERTED 2026-08-24): transcript BEFORE the static instruction
83
+ * LAYOUT (REVERTED): transcript BEFORE the static instruction
63
84
  * block — the pre-0.19.4 order. The #329 item-6 reorder (static-first, for
64
85
  * provider prefix caching) was REVERTED after a deterministic A/B on real
65
86
  * segments: with instructions first, the model over-fires NO_EXTRACT on
@@ -69,7 +90,7 @@ export declare function reflection(memoriesBlock: string, recentLessons?: string
69
90
  * loss beats any caching win. Re-attempting instructions-first requires a
70
91
  * gate fix that passes the A/B matrix harness first.
71
92
  *
72
- * #339 gate hardening (same day): the NO_EXTRACT rule now carries an explicit
93
+ * #339 gate hardening (same change): the NO_EXTRACT rule now carries an explicit
73
94
  * whole-transcript guard + counter-example (a summary-led session that
74
95
  * contains later decisions MUST be extracted) — the over-firing mechanism was
75
96
  * the model pattern-matching a bookkeeping-heavy OPENING to the ephemera gate
package/dist/prompts.js CHANGED
@@ -10,7 +10,7 @@
10
10
  * infra-name denylist cannot catch conceptual leaks, only known names.
11
11
  */
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
- exports.REFLECTION_PRIVACY_LINE_CONFIDENTIAL = exports.REFLECTION_PRIVACY_LINE_STANDARD = void 0;
13
+ exports.REFLECTION_PRIVACY_LINE_SPACE = exports.REFLECTION_PRIVACY_LINE_CONFIDENTIAL = exports.REFLECTION_PRIVACY_LINE_STANDARD = void 0;
14
14
  exports.importanceScoring = importanceScoring;
15
15
  exports.reflection = reflection;
16
16
  exports.distillation = distillation;
@@ -32,17 +32,29 @@ exports.REFLECTION_PRIVACY_LINE_STANDARD = "Privacy: Never include personal data
32
32
  * (c) credentials/passwords/API keys/secrets are STILL never included.
33
33
  */
34
34
  exports.REFLECTION_PRIVACY_LINE_CONFIDENTIAL = "Privacy: this pool serves the confidential circle only (confidential memories). Lesson text may reference the user's personal domains (names, health, finances) at the process level where needed to make the lesson actionable. Credentials, passwords, API keys, and other secrets are still never included — abstract those away.";
35
+ /**
36
+ * The generic SPACE pool's reflection privacy line (#642) — the default for
37
+ * every configured space without an explicit `privacyLine`. Modeled on the
38
+ * confidential line (the pool serves its members only; personal domains at
39
+ * the process level where needed; secrets still never included), neutral
40
+ * private-pool wording: any space can carry it, confidential included. The
41
+ * `confidential` space itself is seeded the SHIPPED confidential line above
42
+ * (byte-identical prompts, #602 pin) — the seeding lives in spaces.ts
43
+ * resolution, never in prompt-building code.
44
+ */
45
+ exports.REFLECTION_PRIVACY_LINE_SPACE = "Privacy: this pool serves its space's members only (space memories). Lesson text may reference the user's personal domains (names, health, finances) at the process level where needed to make the lesson actionable. Credentials, passwords, API keys, and other secrets are still never included — abstract those away.";
35
46
  /**
36
47
  * Importance scoring prompt. Takes a {memories_block} with indexed memories.
37
48
  *
38
49
  * RE-ANCHORED (#425): the pre-fix anchors put "useful context" at 0.3-0.5 —
39
50
  * but the distiller's ephemera gate already removes trivia before anything
40
51
  * reaches this scorer, so the model only ever saw curated material and the
41
- * distribution compressed upward (measured on the production snapshot via
42
- * eval:importance: median base 0.8, ~11% at exactly 1.0, which the decay
43
- * model never forgets). The anchors now place routine-but-curated content
44
- * LOW and add an explicit distribution instruction (owner decision D2,
45
- * 2026-09-13: target median 0.30-0.40, p90 <= 0.75; 1.0 is never a valid
52
+ * distribution compressed upward (measured on a production snapshot via
53
+ * eval:importance: most memories clustered high, a meaningful share at
54
+ * exactly 1.0, which the decay model never forgets). The anchors now place
55
+ * routine-but-curated content
56
+ * LOW and add an explicit distribution instruction (decision D2:
57
+ * target median 0.30-0.40, p90 <= 0.75; 1.0 is never a valid
46
58
  * score). The strict JSON-array response contract is unchanged.
47
59
  */
48
60
  function importanceScoring(memoriesBlock) {
@@ -91,14 +103,25 @@ No explanations. Just the JSON array.`;
91
103
  * API keys/secrets are never included. Everything else in the prompt
92
104
  * (generality bar, examples, output schema) is shared verbatim by both
93
105
  * pools — pinned by tests/reflection-prompt.test.ts.
106
+ *
107
+ * #642 SPACE-AWARE: the optional `privacyLine` argument is the RESOLVED
108
+ * per-space line (SpaceDef.privacyLine — concrete by the time a SpaceDef
109
+ * exists: explicit config, the confidential space's seeded #602 line, or
110
+ * REFLECTION_PRIVACY_LINE_SPACE). When given it REPLACES the two-constant
111
+ * selection entirely; absent, the #602 behavior is byte-identical. The
112
+ * caller (consolidate.ts reflectPool) threads `spaceById.get(pool)?.privacyLine`
113
+ * — undefined for 'standard', the seeded confidential text for 'confidential'
114
+ * (identical bytes to the constant, so both legacy pools are unchanged).
94
115
  */
95
- function reflection(memoriesBlock, recentLessons, pool) {
116
+ function reflection(memoriesBlock, recentLessons, pool, privacyLine) {
96
117
  const recentSection = recentLessons
97
118
  ? `\nRECENT LESSONS (already generated — do NOT duplicate, but DO escalate if patterns recur):\n${recentLessons}\n`
98
119
  : "";
99
- const privacyLine = pool === "confidential"
100
- ? exports.REFLECTION_PRIVACY_LINE_CONFIDENTIAL
101
- : exports.REFLECTION_PRIVACY_LINE_STANDARD;
120
+ const resolvedPrivacyLine = privacyLine !== undefined
121
+ ? privacyLine
122
+ : pool === "confidential"
123
+ ? exports.REFLECTION_PRIVACY_LINE_CONFIDENTIAL
124
+ : exports.REFLECTION_PRIVACY_LINE_STANDARD;
102
125
  return `You are a learning analyst for a multi-agent AI system. Review today's memories and extract actionable lessons from BOTH successes and failures.
103
126
 
104
127
  Like human learning: we grow fastest when we reinforce what works AND correct what doesn't. A system that only learns from mistakes becomes overly cautious. A system that only learns from successes never improves. The combination multiplies.
@@ -154,7 +177,7 @@ Focus on:
154
177
  - CROSS-AGENT PATTERNS: same issue or success across different agents — especially high-value
155
178
  - PROCESS FEEDBACK: user feedback about the agent's approach/behavior, not just its output
156
179
 
157
- ${privacyLine}
180
+ ${resolvedPrivacyLine}
158
181
 
159
182
  Skip: isolated trivial actions, already-documented rules, incident notes, changelog entries, and tool-specific recipes. However, if multiple small successes form a consistent pattern of quality, extract that pattern as a reinforcement.
160
183
 
@@ -163,7 +186,7 @@ Respond with a JSON array. Empty array [] is a valid response.`;
163
186
  /**
164
187
  * Distillation prompt. Extracts knowledge from a session transcript.
165
188
  *
166
- * LAYOUT (REVERTED 2026-08-24): transcript BEFORE the static instruction
189
+ * LAYOUT (REVERTED): transcript BEFORE the static instruction
167
190
  * block — the pre-0.19.4 order. The #329 item-6 reorder (static-first, for
168
191
  * provider prefix caching) was REVERTED after a deterministic A/B on real
169
192
  * segments: with instructions first, the model over-fires NO_EXTRACT on
@@ -173,7 +196,7 @@ Respond with a JSON array. Empty array [] is a valid response.`;
173
196
  * loss beats any caching win. Re-attempting instructions-first requires a
174
197
  * gate fix that passes the A/B matrix harness first.
175
198
  *
176
- * #339 gate hardening (same day): the NO_EXTRACT rule now carries an explicit
199
+ * #339 gate hardening (same change): the NO_EXTRACT rule now carries an explicit
177
200
  * whole-transcript guard + counter-example (a summary-led session that
178
201
  * contains later decisions MUST be extracted) — the over-firing mechanism was
179
202
  * the model pattern-matching a bookkeeping-heavy OPENING to the ephemera gate
@@ -335,8 +358,8 @@ Rules:
335
358
 
336
359
  Respond with ONLY a JSON array. No explanations.`;
337
360
  }
338
- // edgeClassification prompt REMOVED (2026-07). LLM edge classification is
339
- // retired: the 672-link audit found the LLM-classified UPPERCASE relationship
340
- // types near-useless (CONTRADICTS 4% acceptable). Linking is now heuristic-only
361
+ // edgeClassification prompt REMOVED. LLM edge classification is
362
+ // retired: a comprehensive link audit found the LLM-classified UPPERCASE relationship
363
+ // types near-useless (every one below half acceptable). Linking is now heuristic-only
341
364
  // (extends/relates_to) in consolidate.ts. A classification prompt may return
342
365
  // only when a future classifier passes the audit harness at >= 70% acceptable.
@@ -46,7 +46,7 @@ export interface QualityTier1 {
46
46
  * attributed lines; null when nothing attributed. */
47
47
  cross_share: number | null;
48
48
  /** Attributed lines ÷ all lines — the explicit attribution bound rendered
49
- * beside the share (the ~4% gap is visible, never silent); null when no
49
+ * beside the share (a small gap stays visible, never silent); null when no
50
50
  * lines. */
51
51
  attribution_coverage: number | null;
52
52
  /** Attributed cross lines with a measured similarity below the effective
@@ -13,7 +13,7 @@
13
13
  *
14
14
  * Fail-soft like learnings-identity: ANY failure (no config, timeout, non-2xx,
15
15
  * parse error) prints nothing and exits 0 — a broken hook must never block or
16
- * slow a CC session beyond the fetch timeout (1000 ms, owner-set).
16
+ * slow a CC session beyond the fetch timeout (1000 ms, a shipped constant).
17
17
  */
18
18
  interface HookPayload {
19
19
  session_id?: string;
@@ -14,7 +14,7 @@
14
14
  *
15
15
  * Fail-soft like learnings-identity: ANY failure (no config, timeout, non-2xx,
16
16
  * parse error) prints nothing and exits 0 — a broken hook must never block or
17
- * slow a CC session beyond the fetch timeout (1000 ms, owner-set).
17
+ * slow a CC session beyond the fetch timeout (1000 ms, a shipped constant).
18
18
  */
19
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
20
  exports.buildHookRequest = buildHookRequest;
@@ -53,7 +53,7 @@ function buildHookRequest(payload, cwd = process.cwd()) {
53
53
  // request at all — no HTTP call, so the 1000 ms hook budget is spent on
54
54
  // real prompts only. A wrapper CARRYING prose (agent-message hand-back,
55
55
  // report <result>, user text around the wrapper) recalls on the full text
56
- // (owner decision 4) — the shared classifier, same function the server
56
+ // (decision 4) — the shared classifier, same function the server
57
57
  // guards with (wrapper-prompt.ts).
58
58
  if ((0, wrapper_prompt_js_1.isPureWrapperPrompt)(prompt))
59
59
  return null;