@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
@@ -19,7 +19,7 @@
19
19
  * agent (posts / sessions / bytes / held / retried), bytes DESC.
20
20
  *
21
21
  * - readCaptureHealthWindow(db) — the same grouping over the ROLLING
22
- * capture window (#409 fix round 7, owner ruling 2026-09-14: the card
22
+ * capture window (#409 fix round 7: the card
23
23
  * shows the normal 30 days like the band's other cards). The newest
24
24
  * night's rows stay on the payload too (secondary info: the card's
25
25
  * "tonight" suffix); the window sums are the card's face.
@@ -45,7 +45,7 @@ const storage_js_1 = require("./storage.js");
45
45
  let lastPruneDay = null;
46
46
  /** The rolling capture window the console's card shows, in days — ALSO the
47
47
  * retention horizon for distill_activity (the recorder prunes past it).
48
- * Owner ruling 2026-09-14: the capture card shows the normal 30 day like
48
+ * #409 fix round 7: the capture card shows the normal 30 day like
49
49
  * the band's other cards, so the store must retain enough nights to sum
50
50
  * one. ONE constant feeds both the window aggregate and the prune: the card
51
51
  * can never claim a window the store no longer has rows for. */
@@ -28,6 +28,7 @@
28
28
  * and the pipeline stages consume them, and the tests exercise the decisions
29
29
  * directly.
30
30
  */
31
+ import { type SpaceDef } from "./spaces.js";
31
32
  import { LlmClient, type LlmConfig } from "./llm.js";
32
33
  import type { MemoryPrivacy } from "./types.js";
33
34
  /**
@@ -46,11 +47,11 @@ export declare function resolveConfidentialAgents(config: Record<string, unknown
46
47
  };
47
48
  /**
48
49
  * Normalize a capture-side `source_agent` for roster matching. Capture stamps
49
- * harness-qualified ids (`hermes/atlas`, `claude-code/myproject`), while the
50
+ * harness-qualified ids (`hermes/nova`, `claude-code/myproject`), while the
50
51
  * roster carries bare agent ids (the same ids the read side receives as
51
52
  * `agent`) — ONE config list, no read-ids/capture-ids sync hazard. The match
52
- * is exact, or exact after stripping the FIRST path segment (so `hermes/atlas`
53
- * matches roster `atlas`, and a future `anything/atlas` matches too — generic
53
+ * is exact, or exact after stripping the FIRST path segment (so `hermes/nova`
54
+ * matches roster `nova`, and a future `anything/nova` matches too — generic
54
55
  * prefix, not a per-harness table). Case-insensitive on the id half via the
55
56
  * roster's sanitized (lowercased) form.
56
57
  */
@@ -82,6 +83,20 @@ export interface ConfidentialPathPattern {
82
83
  /** Normalized segments of the literal part; `"*"` = exactly one segment. */
83
84
  segments: string[];
84
85
  }
86
+ /**
87
+ * Compile one raw config entry into a pattern, or null when the entry is not
88
+ * one of the three forms. Dropped kinds: relative entries (nothing to anchor
89
+ * a match on), a double-star anywhere but the end, a star that is not a whole
90
+ * segment (partial-segment wildcards), other metacharacters, blank, and
91
+ * ~user-style entries (whose home?). Dropped entries are reported by name at
92
+ * boot — a typo must surface, never silently match nothing.
93
+ *
94
+ * #642: exported as the SHARED per-space path compiler (spaces.ts compiles
95
+ * `spaces.<id>.paths` with the same three forms — one pattern language, not a
96
+ * copy). The `Confidential` in the surrounding names is the legacy N=1
97
+ * vocabulary; the forms themselves are space-neutral.
98
+ */
99
+ export declare function compilePathPattern(entry: string): ConfidentialPathPattern | null;
85
100
  /**
86
101
  * Resolve the `confidentialPaths` config value into validated patterns.
87
102
  * Entries that do not compile are dropped and their raw values returned in
@@ -129,6 +144,37 @@ export declare function safeMarkerKeyEqual(markerContent: string, key: string):
129
144
  * value into each client machine's config.json (or its env).
130
145
  */
131
146
  export declare function resolveConfidentialMarkerKey(config: Record<string, unknown> | null | undefined): string | null;
147
+ /**
148
+ * The intake-side derivation, generalized to N spaces (#642 AC-4): which ONE
149
+ * space a delivery from `sourceAgent` stamps. Fail-closed by construction —
150
+ * anything unattributed, unlisted, and unmatched is `standard` (the shared
151
+ * pool).
152
+ *
153
+ * Arm precedence (the more specific birthplace wins; on a pure-legacy install
154
+ * every arm yields the same value, so the order is invisible there):
155
+ * (a) PATHS — the FIRST space, in config order, whose compiled patterns
156
+ * match the delivery's workspace path (matchesConfidentialPath);
157
+ * (b) MEMBERS — the FIRST space, in config order, whose member list matches
158
+ * the source agent (isConfidentialSourceAgent, the `<harness>/`-stripping
159
+ * matcher);
160
+ * (c) MARKER — the confidential arm EXACTLY as shipped (#614): the relayed
161
+ * marker CONTENT must equal the boot-resolved `confidentialMarkerKey`
162
+ * (timing-safe, server-side — the client only relays). UNCONDITIONAL of
163
+ * the spaces list: 'confidential' is a reserved id the marker arm stamps
164
+ * even on installs where no confidential space materialized. Marker
165
+ * birthplace stays confidential-only by owner ruling (#642) — markers
166
+ * are never generalized to other spaces.
167
+ * (d) else 'standard'.
168
+ *
169
+ * `spaces` is the boot-resolved SpaceDef list (resolveSpaces in spaces.ts,
170
+ * config key order preserved). spaces.ts imports runtime values from THIS
171
+ * module (compilePathPattern, the confidential resolvers) and this module
172
+ * imports resolveSpaces back — a module cycle that is SAFE by construction:
173
+ * every cross-edge binding is a hoisted `function` declaration used only
174
+ * inside other function bodies, never at module-evaluation time, so neither
175
+ * evaluation order can observe an uninitialized binding.
176
+ */
177
+ export declare function deriveIntakeSpace(sourceAgent: string | null | undefined, spaces: SpaceDef[], signals?: IntakeWorkspaceSignals): MemoryPrivacy;
132
178
  /**
133
179
  * The intake-side derivation: which class a delivery from `sourceAgent`
134
180
  * stores as. Fail-closed by construction — anything unattributed or
@@ -145,6 +191,13 @@ export declare function resolveConfidentialMarkerKey(config: Record<string, unkn
145
191
  * content). The optional third argument
146
192
  * keeps every existing caller byte-identical (no signals = the #332
147
193
  * agent-only rule).
194
+ *
195
+ * #642: now a THIN WRAPPER over deriveIntakeSpace — the roster (+ optional
196
+ * signals paths) becomes one confidential space and the generalized
197
+ * derivation runs. At N=1 every arm yields the same value (paths, members,
198
+ * and the marker arm all answer 'confidential'), so the wrapper is
199
+ * value-identical to the pre-#642 direct implementation for every input
200
+ * combination; the pinned privacy-* / classification tests are the proof.
148
201
  */
149
202
  export declare function deriveIntakePrivacy(sourceAgent: string | null | undefined, roster: string[], signals?: IntakeWorkspaceSignals): MemoryPrivacy;
150
203
  /**
@@ -180,8 +233,8 @@ export interface IntakeWorkspaceSignals {
180
233
  * blank, or unknown `agent` → false (fail-closed: an unknown id can never
181
234
  * widen visibility, exactly like the identity layer's mode resolution). The
182
235
  * `agent` value is sanitized first so a wire id arrives in the roster's
183
- * namespace (`Atlas` → `atlas`); note sanitizeAgentId also collapses inner
184
- * separators, so `hermes/atlas` sent as a requester id reads as `hermes-atlas`
236
+ * namespace (`Nova` → `nova`); note sanitizeAgentId also collapses inner
237
+ * separators, so `hermes/nova` sent as a requester id reads as `hermes-nova`
185
238
  * — the read side intentionally matches BARE ids only (plugins send their
186
239
  * resolved profile name, not their capture-side qualified stamp).
187
240
  */
@@ -221,16 +274,58 @@ export declare function buildConfidentialLlm(savedConfig: Record<string, unknown
221
274
  config: LlmConfig;
222
275
  } | null;
223
276
  /**
224
- * The two clients a pipeline run needs. `standard` is the main model (always
277
+ * The clients a pipeline run needs. `standard` is the main model (always
225
278
  * present when the run does LLM work at all); `confidential` is null when the
226
279
  * circle is active but the second model is unconfigured — callers HOLD
227
280
  * confidential work in that case (clientForPool returns null), never fall
228
- * back.
281
+ * back. #642 adds `spaces`: one client (or null) per configured space EXCEPT
282
+ * 'confidential', whose client keeps flowing through the field above (one
283
+ * role, one field — buildSpaceLlms never stamps it into the map). Absent on
284
+ * a legacy pair (no spaces configured); clientForPool then answers null for
285
+ * every space id, which callers treat as HOLD — never fallback.
229
286
  */
230
287
  export interface LlmPair {
231
288
  standard: LlmClient;
232
289
  confidential: LlmClient | null;
290
+ /** #642: per-space clients (see above); 'confidential' is never a key. */
291
+ spaces?: Map<string, LlmClient | null>;
292
+ }
293
+ /**
294
+ * The per-space resolution bundle (#642 AC-9): the effective client + config
295
+ * for every CONFIGURED space except 'confidential'. A null entry is a HOLD,
296
+ * not a fallback — the main model is deliberately not representable here.
297
+ */
298
+ export interface SpaceLlmBundle {
299
+ clients: Map<string, LlmClient | null>;
300
+ configs: Map<string, LlmConfig | null>;
233
301
  }
302
+ /**
303
+ * Build the per-space clients (#642 AC-9). For each SpaceDef EXCEPT
304
+ * 'confidential' (the confidential space's client keeps its existing
305
+ * LlmPair.confidential role), the effective config is the inheritance
306
+ * ladder:
307
+ *
308
+ * 1. the space's EXPLICIT llm (spaces.<id>.llmBaseUrl + llmApiKey, the
309
+ * resolveConfidentialLlmConfig pair contract) — built exactly like
310
+ * buildConfidentialLlm builds the confidential one:
311
+ * resolveExplicitLlmConfig + applyTierTuningOverlay + new LlmClient, so
312
+ * a space model is never a second-class client (same maxTokens/timeouts/
313
+ * single-flight overlay);
314
+ * 2. else the `llmConfidential*` endpoint — the SAME client object the
315
+ * caller already built for the confidential pool when `inherited` is
316
+ * threaded (one breaker/single-flight state per endpoint; resolveLlmPair
317
+ * does), else resolved here;
318
+ * 3. else null — the space's deliveries and consolidation work HOLD
319
+ * (spaceHoldWarnings names it), never the main model.
320
+ */
321
+ export declare function buildSpaceLlms(savedConfig: Record<string, unknown> | null | undefined, spaces: SpaceDef[],
322
+ /** The already-built confidential pair — inheriting spaces share the SAME
323
+ * client object (one endpoint, one breaker). Pass null when the
324
+ * confidential model is absent; omit to resolve the endpoint here. */
325
+ inherited?: {
326
+ llm: LlmClient;
327
+ config: LlmConfig;
328
+ } | null): SpaceLlmBundle;
234
329
  /**
235
330
  * Resolve the full pair for a pipeline process (the nightly/CLI funnel —
236
331
  * resolveSavedLlmConfig for the standard client, buildConfidentialLlm for
@@ -238,20 +333,33 @@ export interface LlmPair {
238
333
  * the /distill sync path need the config for chunk-size detection/probing),
239
334
  * and passes through resolveSavedLlmConfig's `reason` so callers keep their
240
335
  * claude-binary-missing logging.
336
+ *
337
+ * #642: `spaces` (optional) is the boot-resolved SpaceDef list — omitted, it
338
+ * resolves internally (resolveSpaces). The returned `spaceClients`/
339
+ * `spaceConfigs` cover every configured space EXCEPT 'confidential'; on a
340
+ * legacy config the maps are EMPTY (the only space IS confidential), so
341
+ * pre-#642 callers and their tests see no change.
241
342
  */
242
- export declare function resolveLlmPair(savedConfig: Record<string, unknown> | null | undefined): {
343
+ export declare function resolveLlmPair(savedConfig: Record<string, unknown> | null | undefined, spaces?: SpaceDef[]): {
243
344
  pair: LlmPair | null;
244
345
  standardConfig: LlmConfig | null;
245
346
  confidentialConfig: LlmConfig | null;
246
347
  reason?: "claude_binary_missing";
348
+ /** #642: per-space clients (buildSpaceLlms) — empty on a legacy config. */
349
+ spaceClients: Map<string, LlmClient | null>;
350
+ /** #642: their configs (the drain's per-endpoint chunk-size cache). */
351
+ spaceConfigs: Map<string, LlmConfig | null>;
247
352
  };
248
353
  /**
249
354
  * The per-pool selection every stage call site goes through: the client that
250
- * MUST serve a memory class, or null when the confidential pool has no
251
- * client configured (the caller holds/skips that pool's work — the
252
- * structurally-hard guarantee that confidential text can never reach the
355
+ * MUST serve a memory's space, or null when that space has no client
356
+ * configured (the caller holds/skips that pool's work — the
357
+ * structurally-hard guarantee that non-shared text can never reach the
253
358
  * standard model: there is no code path that answers "give me SOME client
254
- * for confidential").
359
+ * for this pool"). 'confidential' keeps its dedicated field; NULL/''/
360
+ * 'standard' (the shared pool, spaceOf's normalization) is the main model;
361
+ * any other value is a space id answered from the #642 map — absent map,
362
+ * absent entry, or an explicit null entry all HOLD.
255
363
  */
256
364
  export declare function clientForPool(pair: LlmPair, privacy: MemoryPrivacy | null | undefined): LlmClient | null;
257
365
  /**
@@ -274,6 +382,27 @@ export declare function warnIfCircleUnconfigured(opts: {
274
382
  confidentialRows: number;
275
383
  queueConfidential: number;
276
384
  }): boolean;
385
+ /**
386
+ * #642 AC-9 — the per-space companion of warnIfCircleUnconfigured: one line
387
+ * per ACTIVE space whose effective client is null. "Active" = stored rows,
388
+ * queued drain items, a members list, or path patterns (the same
389
+ * anything-can-hold-work shape the confidential warning uses). The line
390
+ * names the space id and states the HOLD posture — deliveries and
391
+ * consolidation work for that space accumulate until a per-space llm
392
+ * (spaces.<id>.llmBaseUrl/llmApiKey) or the llmConfidential* endpoint is
393
+ * configured, and NEVER fall back to the main model.
394
+ *
395
+ * Pure — returns the lines; the caller prints them (nightly funnel + daemon
396
+ * boot, the warnIfCircleUnconfigured call sites) gated on non-empty, so a
397
+ * zero-space or fully-configured install prints nothing. The `confidential`
398
+ * space is deliberately NOT handled here (it flows through the confidential
399
+ * field and warnIfCircleUnconfigured owns its warning — one warning per
400
+ * exposure, never two).
401
+ */
402
+ export declare function spaceHoldWarnings(spaces: SpaceDef[], clients: ReadonlyMap<string, LlmClient | null>, opts: {
403
+ rowsBySpace: ReadonlyMap<string, number>;
404
+ queueBySpace: ReadonlyMap<string, number>;
405
+ }): string[];
277
406
  /**
278
407
  * The boot note when the circle is ACTIVE but the marker key is not (#614):
279
408
  * one line naming `confidentialMarkerKey` and that client workspace markers
@@ -32,22 +32,27 @@
32
32
  Object.defineProperty(exports, "__esModule", { value: true });
33
33
  exports.resolveConfidentialAgents = resolveConfidentialAgents;
34
34
  exports.isConfidentialSourceAgent = isConfidentialSourceAgent;
35
+ exports.compilePathPattern = compilePathPattern;
35
36
  exports.resolveConfidentialPaths = resolveConfidentialPaths;
36
37
  exports.matchesConfidentialPath = matchesConfidentialPath;
37
38
  exports.safeMarkerKeyEqual = safeMarkerKeyEqual;
38
39
  exports.resolveConfidentialMarkerKey = resolveConfidentialMarkerKey;
40
+ exports.deriveIntakeSpace = deriveIntakeSpace;
39
41
  exports.deriveIntakePrivacy = deriveIntakePrivacy;
40
42
  exports.isCircleMember = isCircleMember;
41
43
  exports.resolveConfidentialLlmConfig = resolveConfidentialLlmConfig;
42
44
  exports.buildConfidentialLlm = buildConfidentialLlm;
45
+ exports.buildSpaceLlms = buildSpaceLlms;
43
46
  exports.resolveLlmPair = resolveLlmPair;
44
47
  exports.clientForPool = clientForPool;
45
48
  exports.warnIfCircleUnconfigured = warnIfCircleUnconfigured;
49
+ exports.spaceHoldWarnings = spaceHoldWarnings;
46
50
  exports.confidentialMarkerKeyNote = confidentialMarkerKeyNote;
47
51
  exports.resetRefusedMarkerWarn = resetRefusedMarkerWarn;
48
52
  exports.warnRefusedMarker = warnRefusedMarker;
49
53
  const node_crypto_1 = require("node:crypto");
50
54
  const identity_store_js_1 = require("./identity-store.js");
55
+ const spaces_js_1 = require("./spaces.js");
51
56
  const llm_js_1 = require("./llm.js");
52
57
  const config_read_js_1 = require("./config-read.js");
53
58
  // ---------------------------------------------------------------------------
@@ -84,11 +89,11 @@ function resolveConfidentialAgents(config) {
84
89
  }
85
90
  /**
86
91
  * Normalize a capture-side `source_agent` for roster matching. Capture stamps
87
- * harness-qualified ids (`hermes/atlas`, `claude-code/myproject`), while the
92
+ * harness-qualified ids (`hermes/nova`, `claude-code/myproject`), while the
88
93
  * roster carries bare agent ids (the same ids the read side receives as
89
94
  * `agent`) — ONE config list, no read-ids/capture-ids sync hazard. The match
90
- * is exact, or exact after stripping the FIRST path segment (so `hermes/atlas`
91
- * matches roster `atlas`, and a future `anything/atlas` matches too — generic
95
+ * is exact, or exact after stripping the FIRST path segment (so `hermes/nova`
96
+ * matches roster `nova`, and a future `anything/nova` matches too — generic
92
97
  * prefix, not a per-harness table). Case-insensitive on the id half via the
93
98
  * roster's sanitized (lowercased) form.
94
99
  */
@@ -103,8 +108,8 @@ function isConfidentialSourceAgent(sourceAgent, roster) {
103
108
  return false;
104
109
  const bare = agent.slice(slash + 1);
105
110
  const rest = bare.indexOf("/");
106
- // Strip only the FIRST segment — `hermes/atlas` → `atlas`, but
107
- // `a/b/atlas` → `b/atlas` (never a deep-suffix match; capture ids are
111
+ // Strip only the FIRST segment — `hermes/nova` → `nova`, but
112
+ // `a/b/nova` → `b/nova` (never a deep-suffix match; capture ids are
108
113
  // single-qualified by construction).
109
114
  return rest < 0 && roster.includes(bare);
110
115
  }
@@ -125,8 +130,13 @@ const SEGMENT_METACHARS = /[*?[\]{}]/;
125
130
  * segment (partial-segment wildcards), other metacharacters, blank, and
126
131
  * ~user-style entries (whose home?). Dropped entries are reported by name at
127
132
  * boot — a typo must surface, never silently match nothing.
133
+ *
134
+ * #642: exported as the SHARED per-space path compiler (spaces.ts compiles
135
+ * `spaces.<id>.paths` with the same three forms — one pattern language, not a
136
+ * copy). The `Confidential` in the surrounding names is the legacy N=1
137
+ * vocabulary; the forms themselves are space-neutral.
128
138
  */
129
- function compileConfidentialPath(entry) {
139
+ function compilePathPattern(entry) {
130
140
  const trimmed = entry.trim();
131
141
  if (!trimmed)
132
142
  return null;
@@ -180,7 +190,7 @@ function resolveConfidentialPaths(config) {
180
190
  dropped.push(String(entry));
181
191
  continue;
182
192
  }
183
- const compiled = compileConfidentialPath(entry);
193
+ const compiled = compilePathPattern(entry);
184
194
  if (!compiled) {
185
195
  dropped.push(entry);
186
196
  }
@@ -266,6 +276,53 @@ function resolveConfidentialMarkerKey(config) {
266
276
  return env.trim();
267
277
  return (0, config_read_js_1.readStringConfig)(config ?? {}, "confidentialMarkerKey");
268
278
  }
279
+ /**
280
+ * The intake-side derivation, generalized to N spaces (#642 AC-4): which ONE
281
+ * space a delivery from `sourceAgent` stamps. Fail-closed by construction —
282
+ * anything unattributed, unlisted, and unmatched is `standard` (the shared
283
+ * pool).
284
+ *
285
+ * Arm precedence (the more specific birthplace wins; on a pure-legacy install
286
+ * every arm yields the same value, so the order is invisible there):
287
+ * (a) PATHS — the FIRST space, in config order, whose compiled patterns
288
+ * match the delivery's workspace path (matchesConfidentialPath);
289
+ * (b) MEMBERS — the FIRST space, in config order, whose member list matches
290
+ * the source agent (isConfidentialSourceAgent, the `<harness>/`-stripping
291
+ * matcher);
292
+ * (c) MARKER — the confidential arm EXACTLY as shipped (#614): the relayed
293
+ * marker CONTENT must equal the boot-resolved `confidentialMarkerKey`
294
+ * (timing-safe, server-side — the client only relays). UNCONDITIONAL of
295
+ * the spaces list: 'confidential' is a reserved id the marker arm stamps
296
+ * even on installs where no confidential space materialized. Marker
297
+ * birthplace stays confidential-only by owner ruling (#642) — markers
298
+ * are never generalized to other spaces.
299
+ * (d) else 'standard'.
300
+ *
301
+ * `spaces` is the boot-resolved SpaceDef list (resolveSpaces in spaces.ts,
302
+ * config key order preserved). spaces.ts imports runtime values from THIS
303
+ * module (compilePathPattern, the confidential resolvers) and this module
304
+ * imports resolveSpaces back — a module cycle that is SAFE by construction:
305
+ * every cross-edge binding is a hoisted `function` declaration used only
306
+ * inside other function bodies, never at module-evaluation time, so neither
307
+ * evaluation order can observe an uninitialized binding.
308
+ */
309
+ function deriveIntakeSpace(sourceAgent, spaces, signals) {
310
+ for (const space of spaces) {
311
+ if (matchesConfidentialPath(signals?.workspacePath, space.paths))
312
+ return space.id;
313
+ }
314
+ for (const space of spaces) {
315
+ if (isConfidentialSourceAgent(sourceAgent, space.members))
316
+ return space.id;
317
+ }
318
+ if (typeof signals?.markerKey === "string" &&
319
+ signals.markerKey.length > 0 &&
320
+ typeof signals?.markerContent === "string" &&
321
+ safeMarkerKeyEqual(signals.markerContent, signals.markerKey)) {
322
+ return "confidential";
323
+ }
324
+ return "standard";
325
+ }
269
326
  /**
270
327
  * The intake-side derivation: which class a delivery from `sourceAgent`
271
328
  * stores as. Fail-closed by construction — anything unattributed or
@@ -282,28 +339,32 @@ function resolveConfidentialMarkerKey(config) {
282
339
  * content). The optional third argument
283
340
  * keeps every existing caller byte-identical (no signals = the #332
284
341
  * agent-only rule).
342
+ *
343
+ * #642: now a THIN WRAPPER over deriveIntakeSpace — the roster (+ optional
344
+ * signals paths) becomes one confidential space and the generalized
345
+ * derivation runs. At N=1 every arm yields the same value (paths, members,
346
+ * and the marker arm all answer 'confidential'), so the wrapper is
347
+ * value-identical to the pre-#642 direct implementation for every input
348
+ * combination; the pinned privacy-* / classification tests are the proof.
285
349
  */
286
350
  function deriveIntakePrivacy(sourceAgent, roster, signals) {
287
- if (isConfidentialSourceAgent(sourceAgent, roster))
288
- return "confidential";
289
- if (typeof signals?.markerKey === "string" &&
290
- signals.markerKey.length > 0 &&
291
- typeof signals?.markerContent === "string" &&
292
- safeMarkerKeyEqual(signals.markerContent, signals.markerKey)) {
293
- return "confidential";
294
- }
295
- if (matchesConfidentialPath(signals?.workspacePath, signals?.paths ?? [])) {
296
- return "confidential";
297
- }
298
- return "standard";
351
+ return deriveIntakeSpace(sourceAgent, [
352
+ {
353
+ id: "confidential",
354
+ members: roster,
355
+ paths: signals?.paths ?? [],
356
+ llm: null,
357
+ privacyLine: "",
358
+ },
359
+ ], signals);
299
360
  }
300
361
  /**
301
362
  * The read-side membership check: is the requester a circle member? Absent,
302
363
  * blank, or unknown `agent` → false (fail-closed: an unknown id can never
303
364
  * widen visibility, exactly like the identity layer's mode resolution). The
304
365
  * `agent` value is sanitized first so a wire id arrives in the roster's
305
- * namespace (`Atlas` → `atlas`); note sanitizeAgentId also collapses inner
306
- * separators, so `hermes/atlas` sent as a requester id reads as `hermes-atlas`
366
+ * namespace (`Nova` → `nova`); note sanitizeAgentId also collapses inner
367
+ * separators, so `hermes/nova` sent as a requester id reads as `hermes-nova`
307
368
  * — the read side intentionally matches BARE ids only (plugins send their
308
369
  * resolved profile name, not their capture-side qualified stamp).
309
370
  */
@@ -381,6 +442,69 @@ function buildConfidentialLlm(savedConfig) {
381
442
  (0, llm_js_1.applyTierTuningOverlay)(config, savedConfig ?? null);
382
443
  return { llm: new llm_js_1.LlmClient(config), config };
383
444
  }
445
+ /**
446
+ * Build the per-space clients (#642 AC-9). For each SpaceDef EXCEPT
447
+ * 'confidential' (the confidential space's client keeps its existing
448
+ * LlmPair.confidential role), the effective config is the inheritance
449
+ * ladder:
450
+ *
451
+ * 1. the space's EXPLICIT llm (spaces.<id>.llmBaseUrl + llmApiKey, the
452
+ * resolveConfidentialLlmConfig pair contract) — built exactly like
453
+ * buildConfidentialLlm builds the confidential one:
454
+ * resolveExplicitLlmConfig + applyTierTuningOverlay + new LlmClient, so
455
+ * a space model is never a second-class client (same maxTokens/timeouts/
456
+ * single-flight overlay);
457
+ * 2. else the `llmConfidential*` endpoint — the SAME client object the
458
+ * caller already built for the confidential pool when `inherited` is
459
+ * threaded (one breaker/single-flight state per endpoint; resolveLlmPair
460
+ * does), else resolved here;
461
+ * 3. else null — the space's deliveries and consolidation work HOLD
462
+ * (spaceHoldWarnings names it), never the main model.
463
+ */
464
+ function buildSpaceLlms(savedConfig, spaces,
465
+ /** The already-built confidential pair — inheriting spaces share the SAME
466
+ * client object (one endpoint, one breaker). Pass null when the
467
+ * confidential model is absent; omit to resolve the endpoint here. */
468
+ inherited) {
469
+ const clients = new Map();
470
+ const configs = new Map();
471
+ for (const space of spaces) {
472
+ // The confidential space flows through LlmPair.confidential — stamping it
473
+ // here too would give one endpoint two breaker states.
474
+ if (space.id === "confidential")
475
+ continue;
476
+ if (space.llm) {
477
+ const config = (0, llm_js_1.resolveExplicitLlmConfig)({
478
+ llmBaseUrl: space.llm.baseUrl,
479
+ llmApiKey: space.llm.apiKey,
480
+ llmModel: space.llm.model,
481
+ llmProvider: space.llm.provider,
482
+ });
483
+ // resolveExplicitLlmConfig only answers null when the baseUrl/apiKey
484
+ // pair is absent — resolveSpaces already enforces the pair, so this is
485
+ // defensive; null means HOLD, same as an unconfigured space.
486
+ if (!config) {
487
+ clients.set(space.id, null);
488
+ configs.set(space.id, null);
489
+ continue;
490
+ }
491
+ (0, llm_js_1.applyTierTuningOverlay)(config, savedConfig ?? null);
492
+ clients.set(space.id, new llm_js_1.LlmClient(config));
493
+ configs.set(space.id, config);
494
+ continue;
495
+ }
496
+ const endpoint = inherited !== undefined ? inherited : buildConfidentialLlm(savedConfig);
497
+ if (endpoint) {
498
+ clients.set(space.id, endpoint.llm);
499
+ configs.set(space.id, endpoint.config);
500
+ }
501
+ else {
502
+ clients.set(space.id, null);
503
+ configs.set(space.id, null);
504
+ }
505
+ }
506
+ return { clients, configs };
507
+ }
384
508
  /**
385
509
  * Resolve the full pair for a pipeline process (the nightly/CLI funnel —
386
510
  * resolveSavedLlmConfig for the standard client, buildConfidentialLlm for
@@ -388,39 +512,63 @@ function buildConfidentialLlm(savedConfig) {
388
512
  * the /distill sync path need the config for chunk-size detection/probing),
389
513
  * and passes through resolveSavedLlmConfig's `reason` so callers keep their
390
514
  * claude-binary-missing logging.
515
+ *
516
+ * #642: `spaces` (optional) is the boot-resolved SpaceDef list — omitted, it
517
+ * resolves internally (resolveSpaces). The returned `spaceClients`/
518
+ * `spaceConfigs` cover every configured space EXCEPT 'confidential'; on a
519
+ * legacy config the maps are EMPTY (the only space IS confidential), so
520
+ * pre-#642 callers and their tests see no change.
391
521
  */
392
- function resolveLlmPair(savedConfig) {
522
+ function resolveLlmPair(savedConfig, spaces) {
523
+ const resolvedSpaces = spaces ?? (0, spaces_js_1.resolveSpaces)(savedConfig).spaces;
393
524
  const resolved = (0, llm_js_1.resolveSavedLlmConfig)(savedConfig ?? null);
394
525
  const confidential = buildConfidentialLlm(savedConfig);
526
+ // The confidential client object is REUSED for inheriting spaces (rung 2 of
527
+ // the ladder) — one endpoint, one breaker state.
528
+ const spaceBundle = buildSpaceLlms(savedConfig, resolvedSpaces, confidential);
395
529
  if (!resolved.config) {
396
530
  return {
397
531
  pair: null,
398
532
  standardConfig: null,
399
533
  confidentialConfig: confidential?.config ?? null,
400
534
  reason: resolved.reason,
535
+ spaceClients: spaceBundle.clients,
536
+ spaceConfigs: spaceBundle.configs,
401
537
  };
402
538
  }
403
539
  return {
404
540
  pair: {
405
541
  standard: new llm_js_1.LlmClient(resolved.config),
406
542
  confidential: confidential?.llm ?? null,
543
+ spaces: spaceBundle.clients,
407
544
  },
408
545
  standardConfig: resolved.config,
409
546
  confidentialConfig: confidential?.config ?? null,
547
+ spaceClients: spaceBundle.clients,
548
+ spaceConfigs: spaceBundle.configs,
410
549
  };
411
550
  }
412
551
  /**
413
552
  * The per-pool selection every stage call site goes through: the client that
414
- * MUST serve a memory class, or null when the confidential pool has no
415
- * client configured (the caller holds/skips that pool's work — the
416
- * structurally-hard guarantee that confidential text can never reach the
553
+ * MUST serve a memory's space, or null when that space has no client
554
+ * configured (the caller holds/skips that pool's work — the
555
+ * structurally-hard guarantee that non-shared text can never reach the
417
556
  * standard model: there is no code path that answers "give me SOME client
418
- * for confidential").
557
+ * for this pool"). 'confidential' keeps its dedicated field; NULL/''/
558
+ * 'standard' (the shared pool, spaceOf's normalization) is the main model;
559
+ * any other value is a space id answered from the #642 map — absent map,
560
+ * absent entry, or an explicit null entry all HOLD.
419
561
  */
420
562
  function clientForPool(pair, privacy) {
421
563
  if (privacy === "confidential")
422
564
  return pair.confidential;
423
- return pair.standard;
565
+ if (privacy === null ||
566
+ privacy === undefined ||
567
+ privacy === "" ||
568
+ privacy === "standard") {
569
+ return pair.standard;
570
+ }
571
+ return pair.spaces?.get(privacy) ?? null;
424
572
  }
425
573
  // ---------------------------------------------------------------------------
426
574
  // Boot warning
@@ -462,6 +610,45 @@ function warnIfCircleUnconfigured(opts) {
462
610
  console.warn("");
463
611
  return true;
464
612
  }
613
+ /**
614
+ * #642 AC-9 — the per-space companion of warnIfCircleUnconfigured: one line
615
+ * per ACTIVE space whose effective client is null. "Active" = stored rows,
616
+ * queued drain items, a members list, or path patterns (the same
617
+ * anything-can-hold-work shape the confidential warning uses). The line
618
+ * names the space id and states the HOLD posture — deliveries and
619
+ * consolidation work for that space accumulate until a per-space llm
620
+ * (spaces.<id>.llmBaseUrl/llmApiKey) or the llmConfidential* endpoint is
621
+ * configured, and NEVER fall back to the main model.
622
+ *
623
+ * Pure — returns the lines; the caller prints them (nightly funnel + daemon
624
+ * boot, the warnIfCircleUnconfigured call sites) gated on non-empty, so a
625
+ * zero-space or fully-configured install prints nothing. The `confidential`
626
+ * space is deliberately NOT handled here (it flows through the confidential
627
+ * field and warnIfCircleUnconfigured owns its warning — one warning per
628
+ * exposure, never two).
629
+ */
630
+ function spaceHoldWarnings(spaces, clients, opts) {
631
+ const out = [];
632
+ for (const space of spaces) {
633
+ if (space.id === "confidential")
634
+ continue;
635
+ if (clients.get(space.id))
636
+ continue;
637
+ const active = (opts.rowsBySpace.get(space.id) ?? 0) > 0 ||
638
+ (opts.queueBySpace.get(space.id) ?? 0) > 0 ||
639
+ space.members.length > 0 ||
640
+ space.paths.length > 0;
641
+ if (!active)
642
+ continue;
643
+ out.push(`[hicortex] space '${space.id}' has no model — its queued deliveries and ` +
644
+ `consolidation work (importance, reflection, classification, ` +
645
+ `reconsolidation) HOLD until a per-space llm ` +
646
+ `(spaces.${space.id}.llmBaseUrl + llmApiKey) or the llmConfidential* ` +
647
+ `endpoint is configured. They retry next run and never run on the ` +
648
+ `main model.`);
649
+ }
650
+ return out;
651
+ }
465
652
  /**
466
653
  * The boot note when the circle is ACTIVE but the marker key is not (#614):
467
654
  * one line naming `confidentialMarkerKey` and that client workspace markers
@@ -19,7 +19,7 @@
19
19
  * storage.setMemoryTags. After a completed (non-aborted) run the
20
20
  * prototypes, all weights, and all primaries are recomputed from the
21
21
  * final tag sets — same reconsolidation pass as the nightly.
22
- * - No-fit (owner amendment 07.07): an LLM reply of {"tags": []} means no
22
+ * - No-fit (spec 2026-07-07 amendment): an LLM reply of {"tags": []} means no
23
23
  * configured domain fits — there is NO fallback category. The memory gets
24
24
  * a WEAK primary (argmax prototype cosine, when >= weakPrimaryFloor) or,
25
25
  * below the floor, accelerated decay (base_strength halved, domain left
@@ -20,7 +20,7 @@
20
20
  * storage.setMemoryTags. After a completed (non-aborted) run the
21
21
  * prototypes, all weights, and all primaries are recomputed from the
22
22
  * final tag sets — same reconsolidation pass as the nightly.
23
- * - No-fit (owner amendment 07.07): an LLM reply of {"tags": []} means no
23
+ * - No-fit (spec 2026-07-07 amendment): an LLM reply of {"tags": []} means no
24
24
  * configured domain fits — there is NO fallback category. The memory gets
25
25
  * a WEAK primary (argmax prototype cosine, when >= weakPrimaryFloor) or,
26
26
  * below the floor, accelerated decay (base_strength halved, domain left
@@ -234,7 +234,7 @@ async function runClassifyDomains(options = {}) {
234
234
  }
235
235
  scannedInBatch++;
236
236
  if (result.tags.length === 0) {
237
- // Genuine no-fit (owner amendment 07.07): weak primary from the
237
+ // Genuine no-fit (spec 2026-07-07 amendment): weak primary from the
238
238
  // prototype argmax when it clears the floor, else accelerated
239
239
  // decay. Each rowid is visited at most once per run (cursor is
240
240
  // strictly increasing), so a run never double-halves.
@@ -18,8 +18,10 @@ export declare function readValueFlag(argv: string[], flag: string): string | un
18
18
  * Normalize a raw CLI command word. Hidden aliases resolve to their canonical
19
19
  * name so the cli.ts dispatch switch only spells the canonical form. Aliases
20
20
  * today (#264 rename): `context` → `identity` and `lessons-context` →
21
- * `learnings-identity`; kept so old scripts, installed hooks, and muscle memory
22
- * keep working. Pure + side-effect-free (unlike cli.ts, which dispatches on
23
- * import) so it can be unit-tested directly.
21
+ * `learnings-identity`; #642 rename: `backfill-privacy` → `backfill-spaces`
22
+ * (the confidential N=1 command generalized to per-space stamping). Kept so
23
+ * old scripts, installed hooks, and muscle memory keep working. Pure +
24
+ * side-effect-free (unlike cli.ts, which dispatches on import) so it can be
25
+ * unit-tested directly.
24
26
  */
25
27
  export declare function resolveCommandAlias(raw: string | undefined): string | undefined;