@gamaze/hicortex 0.27.4 → 0.28.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 (92) hide show
  1. package/assets/dashboard.html +361 -100
  2. package/dist/backfill-privacy.d.ts +68 -45
  3. package/dist/backfill-privacy.js +236 -145
  4. package/dist/calibration.d.ts +67 -68
  5. package/dist/calibration.js +75 -78
  6. package/dist/capture-health.d.ts +2 -2
  7. package/dist/capture-health.js +2 -2
  8. package/dist/classification.d.ts +141 -12
  9. package/dist/classification.js +214 -27
  10. package/dist/classify-domains.d.ts +1 -1
  11. package/dist/classify-domains.js +2 -2
  12. package/dist/cli-args.d.ts +5 -3
  13. package/dist/cli-args.js +7 -3
  14. package/dist/cli.d.ts +2 -0
  15. package/dist/cli.js +64 -16
  16. package/dist/cluster.d.ts +12 -9
  17. package/dist/cluster.js +9 -6
  18. package/dist/consolidate.d.ts +93 -43
  19. package/dist/consolidate.js +255 -119
  20. package/dist/dashboard.d.ts +48 -5
  21. package/dist/dashboard.js +55 -3
  22. package/dist/db.js +27 -6
  23. package/dist/dedup.d.ts +2 -3
  24. package/dist/dedup.js +2 -3
  25. package/dist/distill-queue.d.ts +36 -4
  26. package/dist/distill-queue.js +80 -18
  27. package/dist/distiller.d.ts +1 -1
  28. package/dist/distiller.js +13 -12
  29. package/dist/domain-classify.d.ts +8 -9
  30. package/dist/domain-classify.js +6 -7
  31. package/dist/graph.d.ts +15 -5
  32. package/dist/graph.js +46 -13
  33. package/dist/hermes-transcript-reader.d.ts +1 -1
  34. package/dist/hermes-transcript-reader.js +1 -1
  35. package/dist/init.d.ts +2 -2
  36. package/dist/init.js +3 -3
  37. package/dist/llm.d.ts +1 -1
  38. package/dist/llm.js +5 -5
  39. package/dist/mcp-server.js +323 -59
  40. package/dist/memory-instructions.d.ts +2 -2
  41. package/dist/memory-instructions.js +2 -2
  42. package/dist/nightly.d.ts +1 -1
  43. package/dist/nightly.js +64 -5
  44. package/dist/nofit.d.ts +2 -2
  45. package/dist/nofit.js +2 -2
  46. package/dist/observed-agents.d.ts +54 -0
  47. package/dist/observed-agents.js +78 -0
  48. package/dist/project-canonicalize.d.ts +6 -5
  49. package/dist/project-canonicalize.js +6 -5
  50. package/dist/prompts.d.ts +29 -8
  51. package/dist/prompts.js +39 -16
  52. package/dist/quality-scoreboard.d.ts +1 -1
  53. package/dist/recall-hook-cli.d.ts +1 -1
  54. package/dist/recall-hook-cli.js +2 -2
  55. package/dist/recall-index.d.ts +28 -14
  56. package/dist/recall-index.js +22 -10
  57. package/dist/recall-precision.d.ts +3 -3
  58. package/dist/recall-precision.js +5 -4
  59. package/dist/reconcile-projects.d.ts +2 -2
  60. package/dist/reconcile-projects.js +2 -2
  61. package/dist/reconsolidation.d.ts +9 -2
  62. package/dist/reconsolidation.js +48 -31
  63. package/dist/relink.d.ts +2 -2
  64. package/dist/relink.js +4 -4
  65. package/dist/rescore-importance.d.ts +2 -2
  66. package/dist/rescore-importance.js +22 -3
  67. package/dist/retrieval.d.ts +14 -0
  68. package/dist/retrieval.js +11 -11
  69. package/dist/schema-prototypes.d.ts +1 -1
  70. package/dist/schema-prototypes.js +1 -1
  71. package/dist/seed-lesson.js +4 -2
  72. package/dist/spaces-api.d.ts +104 -0
  73. package/dist/spaces-api.js +193 -0
  74. package/dist/spaces-cli.d.ts +90 -0
  75. package/dist/spaces-cli.js +245 -0
  76. package/dist/spaces.d.ts +187 -0
  77. package/dist/spaces.js +360 -0
  78. package/dist/storage.d.ts +47 -10
  79. package/dist/storage.js +74 -17
  80. package/dist/sweep-volatile.d.ts +2 -2
  81. package/dist/sweep-volatile.js +2 -2
  82. package/dist/telemetry-cli.d.ts +1 -1
  83. package/dist/telemetry-cli.js +1 -1
  84. package/dist/type-classify.d.ts +1 -1
  85. package/dist/type-classify.js +1 -1
  86. package/dist/type-labels.d.ts +1 -1
  87. package/dist/type-labels.js +1 -1
  88. package/dist/types.d.ts +43 -20
  89. package/dist/wrapper-prompt.d.ts +2 -2
  90. package/dist/wrapper-prompt.js +2 -2
  91. package/package.json +1 -1
  92. package/server.json +2 -2
@@ -1,58 +1,73 @@
1
1
  /**
2
- * `hicortex backfill-privacy` (#332) — one-shot classification stamping for
3
- * EXISTING rows, by source agent, and (#609) by workspace path.
2
+ * `hicortex backfill-spaces` (#642 AC-14; the #332 `backfill-privacy` command
3
+ * generalized — the old name stays a hidden alias via resolveCommandAlias) —
4
+ * one-shot space stamping for EXISTING rows, by member roster and workspace
5
+ * path, PER SPACE.
4
6
  *
5
7
  * The intake derivation stamps every NEW delivery; this command heals history
6
- * when the roster or the path patterns change (an agent joins the circle, a
7
- * folder is listed, or the feature lands on a store that already has captures
8
- * from a now-covered birthplace). The plan is a pure function of the config ×
9
- * the rows' stored values:
10
- * - every memories/distill_queue row whose source_agent matches the roster
11
- * (isConfidentialSourceAgent — the same `<harness>/`-stripping matcher the
12
- * intake uses) AND whose privacy != 'confidential' → stamped confidential;
13
- * - #609: every row whose stored `workspace_path` matches a
14
- * `confidentialPaths` pattern (the same pure matcher the intake uses),
15
- * grouped per pattern. NULL-path rows are NEVER path-matched (pre-v28
16
- * rows have no path by construction; they are reported as unmatched, not
17
- * silently stamped). A row matching both a rostered agent and a pattern
18
- * flips once (agent groups claim it first; each remaining row joins its
19
- * first matching pattern so overlapping patterns never double-count);
20
- * - NOTHING is ever stamped BACK to standard (a roster/pattern removal is
21
- * not a demotion — memories stay confidential until the operator
8
+ * when a space's members or paths change (an agent joins a space, a folder
9
+ * tree is listed, or the feature lands on a store that already has captures
10
+ * from a now-covered birthplace). The plan is a pure function of the resolved
11
+ * spaces × the rows' stored values:
12
+ * - every memories/distill_queue row whose source_agent matches a space's
13
+ * members (isConfidentialSourceAgent — the same `<harness>/`-stripping
14
+ * matcher the intake uses) AND is still shared → stamped with that
15
+ * space's id, grouped per (space, stored source_agent);
16
+ * - every row whose stored `workspace_path` matches a space's path pattern
17
+ * (matchesConfidentialPath — the same pure matcher the intake uses),
18
+ * grouped per (space, pattern). NULL-path rows are NEVER path-matched
19
+ * (pre-v28 rows have no path by construction; they are reported as
20
+ * unmatched, not silently stamped);
21
+ * - CANDIDATES are ONLY rows with `privacy IS NULL OR privacy = 'standard'`
22
+ * — an already-stamped row NEVER moves (no demotion, no space→space);
23
+ * today's `!= 'confidential'` was the N=1 equivalent of this rule;
24
+ * - claim order: agent groups first (spaces in config order), then path
25
+ * groups (spaces in config order, patterns in entry order) — the FIRST
26
+ * matching space in config order claims a row (single flip, never
27
+ * double-counted);
28
+ * - NOTHING is ever stamped BACK to standard (a members/pattern removal is
29
+ * not a demotion — memories stay in their space until the operator
22
30
  * explicitly changes them; re-running with a smaller config is a no-op by
23
31
  * design).
24
32
  *
33
+ * A pure-legacy config (confidentialAgents/confidentialPaths, no `spaces`
34
+ * key) resolves to the MATERIALIZED confidential space — byte-identical
35
+ * legacy behavior: the same groups, the same 'confidential' stamps, the same
36
+ * report fields (roster/patterns stay the confidential space's).
37
+ *
25
38
  * Safety rails (the `hicortex dedup` / `reconcile-projects` pattern): dry run
26
39
  * by default (report only, zero writes); `--apply` takes a pre-apply DB
27
40
  * backup (abort all writes on failure), the single-flight capture lock
28
- * (waitMs 0 — busy aborts), and stamps in ONE transaction. The queue rows are
29
- * stamped too: a pre-upgrade queued segment from a covered birthplace would
30
- * otherwise distill as standard (migration v27 normalized it) — the backfill
31
- * closes that seam.
41
+ * (waitMs 0 — busy aborts), and stamps in ONE transaction, with the space id
42
+ * PARAMETERIZED (never interpolated into SQL). The queue rows are stamped
43
+ * too: a pre-upgrade queued segment from a covered birthplace would
44
+ * otherwise distill as standard — the backfill closes that seam.
32
45
  *
33
46
  * Idempotent by construction: a second run finds every covered row already
34
- * confidential and reports zero.
47
+ * stamped and reports zero.
35
48
  */
36
49
  import type Database from "better-sqlite3";
37
50
  import { acquireCaptureLock } from "./capture.js";
38
51
  import { type ConfidentialPathPattern } from "./classification.js";
39
- /** One planned stamp group: rows from one rostered source agent, or (#609)
40
- * from one confidentialPaths pattern. */
52
+ import { type SpaceDef } from "./spaces.js";
53
+ /** One planned stamp group: rows from one space's rostered source agent, or
54
+ * from one space's path pattern. */
41
55
  export interface BackfillGroup {
56
+ /** #642: the space whose birthplace claimed these rows (the stamp value). */
57
+ space: string;
42
58
  /**
43
59
  * The DISTINCT source_agent value as stored (not the roster entry) — or,
44
- * for a #609 path group, the pattern's raw config entry (display label).
60
+ * for a path group, the pattern's raw config entry (display label).
45
61
  */
46
62
  sourceAgent: string;
47
- /** Rows in `memories` that would flip to confidential. */
63
+ /** Rows in `memories` that would flip to the space. */
48
64
  memoryRows: number;
49
- /** Rows in `distill_queue` that would flip (distill as confidential). */
65
+ /** Rows in `distill_queue` that would flip (distill into the space). */
50
66
  queuedRows: number;
51
67
  /**
52
- * #609: the pattern this group matches — present on path groups only.
53
- * Path groups stamp by exact row ids (the matcher is JS-side; SQL cannot
54
- * express the three pattern forms); agent groups leave these unset and
55
- * stamp by the source_agent predicate.
68
+ * Present on path groups only. Path groups stamp by exact row ids (the
69
+ * matcher is JS-side; SQL cannot express the three pattern forms); agent
70
+ * groups leave these unset and stamp by the source_agent predicate.
56
71
  */
57
72
  pattern?: ConfidentialPathPattern;
58
73
  memoryIds?: string[];
@@ -60,9 +75,11 @@ export interface BackfillGroup {
60
75
  }
61
76
  export interface BackfillReport {
62
77
  dryRun: boolean;
63
- /** The roster entries the plan matched (subset of confidentialAgents). */
78
+ /** The LEGACY report fields: the (materialized or explicit) confidential
79
+ * space's roster — [] when no confidential space exists. Groups carry the
80
+ * per-space truth. */
64
81
  roster: string[];
65
- /** #609: the resolved confidentialPaths entries (raw strings). */
82
+ /** The confidential space's raw path patterns (legacy field, same rule). */
66
83
  patterns: string[];
67
84
  /** Planned/executed stamp groups, largest first. */
68
85
  groups: BackfillGroup[];
@@ -91,19 +108,25 @@ export interface BackfillOptions {
91
108
  acquireLock?: typeof acquireCaptureLock;
92
109
  }
93
110
  /**
94
- * The pure plan: which stored source_agent values match the roster, and how
95
- * many of their rows are not yet confidential. Roster matching uses the
111
+ * The pure plan. #642 AC-14: `planBackfill(db, resolveSpaces(config).spaces)`
112
+ * plans per-space groups; the legacy `planBackfill(db, roster, patterns)`
113
+ * form delegates with the confidential space. Roster matching uses the
96
114
  * INTAKE matcher (isConfidentialSourceAgent — `<harness>/`-stripping) so the
97
- * backfill and the intake can never disagree about who is rostered. #609 adds
98
- * the per-pattern groups (see planPathGroups) alongside the agent groups —
99
- * same rails, same never-demotes rule.
115
+ * backfill and the intake can never disagree about who is a member; path
116
+ * matching uses the intake's pure matcher over the stored workspace_path.
117
+ * Candidates are ONLY still-shared rows (privacy IS NULL OR 'standard') — an
118
+ * already-stamped row never moves.
100
119
  */
101
- export declare function planBackfill(db: Database.Database, roster: string[], patterns?: ConfidentialPathPattern[]): BackfillGroup[];
120
+ export declare function planBackfill(db: Database.Database, rosterOrSpaces: string[] | SpaceDef[], patterns?: ConfidentialPathPattern[]): BackfillGroup[];
102
121
  /**
103
- * Run `hicortex backfill-privacy`. Dry run by default (options.apply falsy) —
104
- * plan + report only, zero writes. `options.apply` executes: backup, capture
105
- * lock, ONE transaction stamping every planned row in BOTH tables. A busy
106
- * lock is an abort (reported as `lockBusy: true`, never a wait); a failed
107
- * backup aborts all writes (throw, like dedup/reconcile-projects).
122
+ * Run `hicortex backfill-spaces` (alias `backfill-privacy`). Dry run by
123
+ * default (options.apply falsy) — plan + report only, zero writes.
124
+ * `options.apply` executes: backup, capture lock, ONE transaction stamping
125
+ * every planned row in BOTH tables with its group's space id (parameterized
126
+ * SQL). A busy lock is an abort (reported as `lockBusy: true`, never a
127
+ * wait); a failed backup aborts all writes (throw, like
128
+ * dedup/reconcile-projects).
108
129
  */
109
130
  export declare function runBackfillPrivacy(options?: BackfillOptions): Promise<BackfillReport>;
131
+ /** #642: the canonical command name — same runner, clearer export. */
132
+ export declare const runBackfillSpaces: typeof runBackfillPrivacy;