@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
@@ -0,0 +1,245 @@
1
+ "use strict";
2
+ /**
3
+ * spaces-cli — `hicortex space …` (#642 AC-13): the CLI consumer of the AC-10
4
+ * admin API (GET /spaces, PUT /spaces/assign + /spaces/unassign). The
5
+ * dashboard's space management card is the other consumer — one API, two
6
+ * interfaces (the owner's ruling); this module speaks to the SAME endpoints
7
+ * the page does.
8
+ *
9
+ * hicortex space list every configured space (members,
10
+ * counts, llm posture) + the unassigned
11
+ * observed agents
12
+ * hicortex space assign <agent> <space> add an agent to a space
13
+ * hicortex space unassign <agent> <space> remove an agent (it drops to shared-only)
14
+ * hicortex space <name> the ONE-COMMAND form, run INSIDE a
15
+ * workspace: derives the local agent id
16
+ * (workspaceAgentId — the #600 sanitized
17
+ * basename grammar) and assigns it to <name>
18
+ *
19
+ * There is no `space create` / `space remove`: a space EXISTS BY CONFIG
20
+ * PRESENCE (the `domains` precedent — config-owned vocabulary, never a
21
+ * command). Add a spaces.<id> entry to config.json on the server, restart,
22
+ * then assign. Unassign never deletes the entry (an empty members list is a
23
+ * valid state).
24
+ *
25
+ * identity-cli.ts layout: pure URL/token resolution + formatters (unit-tested
26
+ * without a server), authed fetch with a 5 s timeout, SpacesCliError for every
27
+ * expected user-facing failure (cli.ts prints .message + exits 1), and a
28
+ * describeSpacesFailure that distinguishes a down server from an HTTP error —
29
+ * 404 names the "server predates spaces" case, 401 points at the config token
30
+ * (`hicortex status`), unreachable points at the daemon. The server's own
31
+ * 400/404 error text (e.g. the config-presence law) surfaces VERBATIM.
32
+ */
33
+ Object.defineProperty(exports, "__esModule", { value: true });
34
+ exports.SPACES_USAGE = exports.SpacesCliError = void 0;
35
+ exports.resolveSpacesTarget = resolveSpacesTarget;
36
+ exports.getSpaces = getSpaces;
37
+ exports.putSpacesMutation = putSpacesMutation;
38
+ exports.formatSpacesList = formatSpacesList;
39
+ exports.runSpacesCommand = runSpacesCommand;
40
+ const learnings_identity_js_1 = require("./learnings-identity.js");
41
+ const identity_cli_js_1 = require("./identity-cli.js");
42
+ const node_path_1 = require("node:path");
43
+ const DEFAULT_PORT = 8787;
44
+ const REQUEST_TIMEOUT_MS = 5000;
45
+ /** Thrown for any expected, user-facing failure. cli.ts prints .message + exits 1. */
46
+ class SpacesCliError extends Error {
47
+ }
48
+ exports.SpacesCliError = SpacesCliError;
49
+ /**
50
+ * Resolve the server URL + token from a parsed config object. Pure + exported
51
+ * so it is unit-testable without a live config. Mirrors identity-cli.ts
52
+ * resolveIdentityTarget (client mode → serverUrl; server mode →
53
+ * http://127.0.0.1:<port>; token from authToken) — the same rules every CLI
54
+ * consumer of the daemon follows.
55
+ */
56
+ function resolveSpacesTarget(config) {
57
+ const baseUrl = config.mode === "client" && typeof config.serverUrl === "string"
58
+ ? config.serverUrl.replace(/\/+$/, "")
59
+ : `http://127.0.0.1:${config.port ?? DEFAULT_PORT}`;
60
+ const authToken = typeof config.authToken === "string" ? config.authToken : undefined;
61
+ return { baseUrl, authToken };
62
+ }
63
+ function authHeaders(token) {
64
+ return token ? { Authorization: `Bearer ${token}` } : {};
65
+ }
66
+ /**
67
+ * Human-readable failure. status === null ⇒ the fetch itself threw (server
68
+ * unreachable — actionable: config, status, daemon). 404 = the server
69
+ * predates the /spaces API; 401 = token trouble. Mirrors identity-cli
70
+ * describeFailure's discipline.
71
+ */
72
+ function describeSpacesFailure(status, bodyError) {
73
+ const suffix = bodyError ? `: ${bodyError}` : "";
74
+ if (status === null) {
75
+ return ("server unreachable (connection refused or timed out) — check the config " +
76
+ "(hicortex status shows the server URL), is the daemon running?" + suffix);
77
+ }
78
+ if (status === 404) {
79
+ return `HTTP 404 — /spaces not found; the server predates spaces (needs the #642 release)${suffix}`;
80
+ }
81
+ if (status === 401) {
82
+ return `HTTP 401 — unauthorized; check authToken in the config (hicortex status shows the current token)${suffix}`;
83
+ }
84
+ return `server returned HTTP ${status}${suffix}`;
85
+ }
86
+ async function readBodyError(resp) {
87
+ try {
88
+ const j = (await resp.json());
89
+ return typeof j?.error === "string" ? j.error : undefined;
90
+ }
91
+ catch {
92
+ return undefined;
93
+ }
94
+ }
95
+ /** GET /spaces. Throws SpacesCliError with a clear message on any failure. */
96
+ async function getSpaces(target) {
97
+ let resp;
98
+ try {
99
+ resp = await fetch(`${target.baseUrl}/spaces`, {
100
+ headers: authHeaders(target.authToken),
101
+ signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS),
102
+ });
103
+ }
104
+ catch {
105
+ throw new SpacesCliError(`GET /spaces failed — ${describeSpacesFailure(null)}`);
106
+ }
107
+ if (!resp.ok) {
108
+ throw new SpacesCliError(`GET /spaces failed — ${describeSpacesFailure(resp.status, await readBodyError(resp))}`);
109
+ }
110
+ const data = (await resp.json());
111
+ if (!data || typeof data !== "object" || !Array.isArray(data.spaces)) {
112
+ throw new SpacesCliError("GET /spaces returned an unexpected body (no spaces array) — server version mismatch?");
113
+ }
114
+ return data;
115
+ }
116
+ /**
117
+ * PUT /spaces/assign or /spaces/unassign. Returns the parsed body
118
+ * ({ok:true} or {ok:true, idempotent:true}); throws SpacesCliError carrying
119
+ * the SERVER's error text verbatim (the 404 config-presence law, the 400
120
+ * validation rules) so the operator reads exactly what the server rejected.
121
+ */
122
+ async function putSpacesMutation(target, verb, agent, space) {
123
+ let resp;
124
+ try {
125
+ resp = await fetch(`${target.baseUrl}/spaces/${verb}`, {
126
+ method: "PUT",
127
+ headers: { "Content-Type": "application/json", ...authHeaders(target.authToken) },
128
+ body: JSON.stringify({ agent, space }),
129
+ signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS),
130
+ });
131
+ }
132
+ catch {
133
+ throw new SpacesCliError(`PUT /spaces/${verb} failed — ${describeSpacesFailure(null)}`);
134
+ }
135
+ if (!resp.ok) {
136
+ throw new SpacesCliError(`PUT /spaces/${verb} failed — ${describeSpacesFailure(resp.status, await readBodyError(resp))}`);
137
+ }
138
+ return (await resp.json().catch(() => ({})));
139
+ }
140
+ // ---------------------------------------------------------------------------
141
+ // Pure formatters (tested directly; no I/O)
142
+ // ---------------------------------------------------------------------------
143
+ /** Render GET /spaces for the terminal: one block per space + the unassigned
144
+ * list. Pure — the exact bytes `space list` prints. */
145
+ function formatSpacesList(body) {
146
+ const parts = [];
147
+ if (body.spaces.length === 0) {
148
+ parts.push("no spaces configured — a space exists by config presence: add a spaces.<id> entry", "(members, paths, optional llm) to config.json on the server, restart, then assign");
149
+ }
150
+ else {
151
+ parts.push(`spaces (${body.spaces.length}):`);
152
+ for (const s of body.spaces) {
153
+ const members = s.members.length > 0 ? s.members.join(", ") : "no members";
154
+ const counts = `${s.memoryCount} memor${s.memoryCount === 1 ? "y" : "ies"}` +
155
+ (s.queuedCount > 0 ? `, ${s.queuedCount} queued` : "");
156
+ const llm = s.llmConfigured ? "llm ready" : "llm NOT configured (work holds — never the main model)";
157
+ parts.push(` ${s.id} — ${s.members.length} member(s): ${members} · ${counts} · ${llm}`);
158
+ if (s.paths.length > 0)
159
+ parts.push(` paths: ${s.paths.join(", ")}`);
160
+ }
161
+ }
162
+ if (body.unassigned.length > 0) {
163
+ parts.push(`unassigned observed agents (${body.unassigned.length}): ${body.unassigned.join(", ")}`);
164
+ }
165
+ else {
166
+ parts.push("unassigned observed agents: none (a workspace appears here within seconds of its first prompt)");
167
+ }
168
+ return parts.join("\n");
169
+ }
170
+ /** `hicortex space` with no subcommand: the usage block listing all four
171
+ * forms + the config-presence law. Pure — printed verbatim. */
172
+ exports.SPACES_USAGE = `Usage: hicortex space <list | assign <agent> <space> | unassign <agent> <space> | <space>>
173
+
174
+ space list every configured space (members, counts) + the unassigned agents
175
+ space assign <agent> <space> add an agent to a space (writes the server's config, applies live)
176
+ space unassign <agent> <space> remove an agent from a space (it drops to shared-only)
177
+ space <name> run INSIDE a workspace: assigns THIS workspace — its folder name,
178
+ the #600 sanitized-basename agent grammar — to space <name>
179
+
180
+ There is no space create/remove: a space EXISTS BY CONFIG PRESENCE (the domains
181
+ precedent) — add a spaces.<id> entry (members, paths, optional llm) to
182
+ config.json on the server and restart, then assign. 'list', 'assign' and
183
+ 'unassign' are reserved words — a space named so is only addressable via
184
+ 'hicortex space assign <agent> <space>'.`;
185
+ /** `hicortex space assign <agent> <space>` — prints the outcome incl. the
186
+ * idempotent no-op case. Throws SpacesCliError on any failure. */
187
+ async function runAssign(target, agent, space) {
188
+ const body = await putSpacesMutation(target, "assign", agent, space);
189
+ process.stdout.write(body.idempotent
190
+ ? `'${agent}' is already a member of '${space}' — nothing to do.\n`
191
+ : `Assigned '${agent}' to space '${space}' — applies live (the agent sees the space from its next read).\n`);
192
+ }
193
+ /** `hicortex space unassign <agent> <space>` — same shape as runAssign. */
194
+ async function runUnassign(target, agent, space) {
195
+ const body = await putSpacesMutation(target, "unassign", agent, space);
196
+ process.stdout.write(body.idempotent
197
+ ? `'${agent}' is not a member of '${space}' — nothing to do.\n`
198
+ : `Removed '${agent}' from space '${space}' — it sees shared-only from its next read (already-captured memories stay stamped).\n`);
199
+ }
200
+ /**
201
+ * Dispatch for `hicortex space <sub>` (cli.ts's `space` case). argv[3] ∈
202
+ * {list, assign, unassign} routes to those; ANY OTHER VALUE is a SPACE NAME —
203
+ * the one-command form (argv[3] required: bare `space` is usage help). Throws
204
+ * SpacesCliError on bad usage/failure; cli.ts prints .message + exits 1.
205
+ */
206
+ async function runSpacesCommand(args, opts = {}) {
207
+ const sub = args[0];
208
+ if (sub === undefined || sub === "")
209
+ throw new SpacesCliError(exports.SPACES_USAGE);
210
+ // opts.config null/undefined both mean "read the real config" — the
211
+ // identity-cli loadConfig seam.
212
+ const target = resolveSpacesTarget(opts.config ?? (0, identity_cli_js_1.loadConfig)());
213
+ if (sub === "list") {
214
+ const body = await getSpaces(target);
215
+ process.stdout.write(formatSpacesList(body) + "\n");
216
+ return;
217
+ }
218
+ if (sub === "assign" || sub === "unassign") {
219
+ const agent = args[1];
220
+ const space = args[2];
221
+ if (!agent || !space) {
222
+ throw new SpacesCliError(`Usage: hicortex space ${sub} <agent> <space>`);
223
+ }
224
+ if (sub === "assign")
225
+ await runAssign(target, agent, space);
226
+ else
227
+ await runUnassign(target, agent, space);
228
+ return;
229
+ }
230
+ // The ONE-COMMAND form: argv[3] is a space name, run from the workspace to
231
+ // assign. The local agent id is the #600 sanitized basename grammar — the
232
+ // same id the workspace's reads carry as ?agent=.
233
+ const name = sub;
234
+ const cwd = opts.cwd ?? process.cwd();
235
+ const agent = (0, learnings_identity_js_1.workspaceAgentId)(cwd);
236
+ if (!agent) {
237
+ throw new SpacesCliError(`This folder's name cannot be an agent id: '${(0, node_path_1.basename)(cwd)}' sanitizes to nothing ` +
238
+ `(ids are lowercase alphanumerics with - or _ separators — the #600 workspace grammar). ` +
239
+ `Run from the workspace folder, or assign explicitly: hicortex space assign <agent> ${name}`);
240
+ }
241
+ const body = await putSpacesMutation(target, "assign", agent, name);
242
+ process.stdout.write(body.idempotent
243
+ ? `'${agent}' (this workspace) is already a member of '${name}' — nothing to do.\n`
244
+ : `Assigned '${agent}' (this workspace) to space '${name}' — this workspace sees the space from its next read.\n`);
245
+ }
@@ -0,0 +1,187 @@
1
+ /**
2
+ * Spaces (#642) — the confidential circle (#332) generalized to N private
3
+ * pools, on the groups model (owner ruling 2026-11-22): a workspace (agent)
4
+ * joins zero or more spaces; a memory ROW belongs to exactly ONE space,
5
+ * carried by the widened `memories.privacy` vocabulary
6
+ * ('standard' | <configured space id> — see MemoryPrivacy in types.ts; no
7
+ * migration, values are data).
8
+ *
9
+ * The model in one paragraph: an operator configures a `spaces` map (space id
10
+ * → { members, paths, optional per-space llm, optional privacyLine }). Space
11
+ * ids run through the SAME allowlist as agent ids (isValidAgentId — one
12
+ * namespace, the identityAgents precedent). The legacy confidential keys
13
+ * (`confidentialAgents` + `confidentialPaths`) MATERIALIZE a pre-configured
14
+ * space named `confidential` when no explicit `spaces.confidential` entry
15
+ * exists — an existing confidential-only install is the N=1 case of the same
16
+ * machinery, byte-for-byte. 'standard' (and NULL) is the FIXED shared pool —
17
+ * never a space id, never configurable. The marker key (#614) stays
18
+ * confidential-only (owner ruling: no keys in the MVP; the reserved
19
+ * 'confidential' id is always known so the marker arm can stamp it even on
20
+ * installs where no confidential space materialized). Assignment = a name in
21
+ * a list; the shared bearer token is the trust boundary (self-asserted names
22
+ * accepted for MVP, #631 accepted risk; keys are v2).
23
+ *
24
+ * This module is the pure resolution core (no HTTP, no fs — the
25
+ * identity-store.ts / marker-key-api.ts layout; the ONE db-taking function
26
+ * is unknownStoredSpaceIds, the AC-7 boot-report helper, which takes a handle
27
+ * like the storage fns): resolveSpaces parses config ONCE at the boot seam in
28
+ * mcp-server.ts (restart to apply, like the confidential roster), and the
29
+ * small predicates below are the shared vocabulary every later stage (read
30
+ * gates, consolidation, dashboard, CLI) consumes. Intake precedence lives in
31
+ * classification.ts deriveIntakeSpace (#642 AC-4: per-space paths first,
32
+ * then member lists, then the confidential marker arm — the more specific
33
+ * birthplace wins).
34
+ *
35
+ * Zero-change default (AC-1): an install that configures nothing resolves to
36
+ * an empty result with NO warnings — stamps, gates, prompts, and boot output
37
+ * are byte-identical to the #332 release.
38
+ */
39
+ import type Database from "better-sqlite3";
40
+ import { type ConfidentialPathPattern } from "./classification.js";
41
+ /**
42
+ * One RESOLVED space — everything the intake stamp, the read gate, and the
43
+ * consolidation split need. `privacyLine` is always CONCRETE by the time a
44
+ * SpaceDef exists (explicit config wins; the `confidential` space seeds the
45
+ * SHIPPED confidential line byte-identically so its prompts never change;
46
+ * every other space defaults to REFLECTION_PRIVACY_LINE_SPACE) — prompt
47
+ * building never branches on `id === "confidential"`.
48
+ */
49
+ export interface SpaceDef {
50
+ /** The config key, validated by isValidAgentId (never 'standard'). */
51
+ id: string;
52
+ /** Sanitized agent ids (the ?agent= / roster namespace), deduped. */
53
+ members: string[];
54
+ /** Compiled path patterns (the compilePathPattern forms), deduped on raw. */
55
+ paths: ConfidentialPathPattern[];
56
+ /**
57
+ * Per-space LLM endpoint (llmBaseUrl + llmApiKey required as a pair, the
58
+ * resolveConfidentialLlmConfig contract; llmModel/llmProvider optional).
59
+ * null = not configured — the space inherits the `llmConfidential*`
60
+ * endpoint at consolidation and HOLDS without one (never the main model).
61
+ */
62
+ llm: {
63
+ baseUrl: string;
64
+ apiKey: string;
65
+ model?: string;
66
+ provider?: string;
67
+ } | null;
68
+ /** The reflection privacy line for this pool (always concrete — see above). */
69
+ privacyLine: string;
70
+ }
71
+ /**
72
+ * Resolve the `spaces` config map (plus the legacy confidential
73
+ * materialization, AC-2) into the ordered SpaceDef list. Pure — parse once at
74
+ * boot (mcp-server.ts, the confidential seam); restart to apply.
75
+ *
76
+ * Entry fields (all optional): `members?: string[]` (sanitized like ?agent=,
77
+ * invalid entries dropped and named, deduped), `paths?: string[]` (compiled
78
+ * with compilePathPattern, dropped entries named, deduped on raw),
79
+ * `llmBaseUrl`/`llmApiKey`/`llmModel`/`llmProvider?: string` (baseUrl+apiKey
80
+ * required as a PAIR — a half-pair drops the llm field with a warning while
81
+ * the space survives), `privacyLine?: string` (trimmed non-empty, else the
82
+ * field drops with a warning and the pool default applies).
83
+ *
84
+ * Drop/warning discipline (the resolveIdentityAgents pattern): an invalid id
85
+ * key or a non-object entry drops the WHOLE space, named in `dropped`; a
86
+ * wrong-typed or half-configured FIELD drops just the field, named in
87
+ * `warnings` — a typo must surface at boot, never silently match nothing.
88
+ * `dropped` also carries invalid member entries and non-compiling path
89
+ * patterns by raw value. The legacy resolvers' own dropped arrays are NOT
90
+ * re-reported here — mcp-server.ts already prints them at its confidential
91
+ * seam (one boot warning per problem, never two).
92
+ *
93
+ * `spaces` preserves CONFIG KEY ORDER — deriveIntakeSpace's
94
+ * first-matching-space precedence depends on it. The legacy-materialized
95
+ * `confidential` space appends LAST (explicit spaces outrank it in the
96
+ * paths/members arms; on a pure-legacy install there is nothing to outrank).
97
+ *
98
+ * 'standard' is a RESERVED non-id (the fixed shared pool): an explicit entry
99
+ * under it drops with the rule named. 'confidential' IS a valid space id —
100
+ * an explicit entry wins entirely over the legacy keys, with ONE conflict
101
+ * warning ("explicit wins; legacy ignored"); an explicit-but-DROPPED entry
102
+ * (broken shape) falls back to legacy materialization so a typo can never
103
+ * silently disable the circle (the drop is already named in `dropped`).
104
+ *
105
+ * Zero-config (no `spaces` key, no active legacy keys): empty everything —
106
+ * the AC-1 byte-identical boot.
107
+ */
108
+ export declare function resolveSpaces(config: Record<string, unknown> | null | undefined): {
109
+ spaces: SpaceDef[];
110
+ byId: Map<string, SpaceDef>;
111
+ dropped: string[];
112
+ warnings: string[];
113
+ };
114
+ /**
115
+ * Every id a delivery may legally stamp: the CONFIGURED ids plus the reserved
116
+ * 'confidential' ALWAYS — the marker arm stamps 'confidential' even on
117
+ * marker-key-only installs where no confidential space materialized, so the
118
+ * write boundary's known set must include it unconditionally. Callers:
119
+ * normalizeStoredPrivacy's known argument at the enqueue site (AC-7) and the
120
+ * read gate's visible-set resolution.
121
+ */
122
+ export declare function knownSpaceIds(res: {
123
+ byId: Map<string, SpaceDef>;
124
+ }): Set<string>;
125
+ /**
126
+ * The `privacy`/`spaceOf` column normalizer every predicate will use:
127
+ * NULL/undefined/''/'standard' → 'standard' (the fixed shared pool — NULL-safe
128
+ * predicates everywhere already treat pre-v27 NULLs as shared); anything else
129
+ * passes through as-is (lowercase-trust: the column is server-written, and
130
+ * server-written space ids are validated ids by construction). This is a READ
131
+ * predicate, not a write gate — writes go through normalizeStoredPrivacy,
132
+ * which REFUSES unknown ids (#642 AC-7).
133
+ */
134
+ export declare function spaceOf(privacy: string | null | undefined): string;
135
+ /**
136
+ * The read-side membership resolution: the ids of every space whose members
137
+ * list contains the sanitized `agent`. Null/blank/unknown agent → EMPTY set
138
+ * (fail-closed — an unknown id can never widen visibility, exactly like
139
+ * isCircleMember). Note the read side matches BARE ids only: sanitizeAgentId
140
+ * collapses separators, so a harness-qualified `hermes/nova` reads as
141
+ * `hermes-nova` and matches nothing (plugins send their resolved profile
142
+ * name, not their capture-side qualified stamp).
143
+ */
144
+ export declare function spacesForMember(agent: string | null | undefined, spaces: SpaceDef[]): Set<string>;
145
+ /**
146
+ * Compose ONE visible-space set from the two option forms every read gate
147
+ * accepts (#642 AC-5): the legacy boolean (`includeConfidential` — TRUE adds
148
+ * the reserved 'confidential' id, the exact pre-#642 member behavior) and the
149
+ * generalized `visibleSpaces` (the requester's resolved membership set).
150
+ * Union: `(includeConfidential ? {'confidential'} : ∅) ∪ (visibleSpaces ?? ∅)`.
151
+ *
152
+ * A caller that passes NEITHER gets the EMPTY set = shared-only — the
153
+ * fail-closed default every un-gated surface (MCP tools, internal passes that
154
+ * want the whole store must say so explicitly) already had as boolean-false.
155
+ * Byte-identical to the old predicate on standard/confidential data for every
156
+ * boolean-only call: false → ∅ (confidential hidden), true → {'confidential'}
157
+ * (confidential visible).
158
+ */
159
+ export declare function resolveVisibleSet(includeConfidential?: boolean, visibleSpaces?: ReadonlySet<string>): Set<string>;
160
+ /**
161
+ * THE visibility predicate — one rule every read gate consults (#642 AC-5):
162
+ * shared rows ('standard', i.e. spaceOf of NULL/''/'standard') are visible to
163
+ * EVERYONE; every other row is visible iff its space id is in the viewer's
164
+ * set. A stored id outside {'standard'} ∪ visible is INVISIBLE to that viewer
165
+ * — which makes an unknown or retired space id (no configured space claims
166
+ * it, so no membership list can ever contain it) invisible to EVERY
167
+ * requester, the AC-7 fail-closed direction: unknown ids are never
168
+ * normalized to shared, they are dropped from view until configured or
169
+ * re-stamped.
170
+ */
171
+ export declare function isVisiblePrivacy(privacy: string | null | undefined, visible: ReadonlySet<string>): boolean;
172
+ /**
173
+ * #642 AC-7: stored space ids NO configured space claims — the boot-warning
174
+ * input. Scans `memories.privacy` AND `distill_queue.privacy` (both carry
175
+ * stamps; a retired space can sit queued as well as stored) for DISTINCT
176
+ * values outside the fixed vocabulary ('standard' — NULL never reaches here —
177
+ * and 'confidential', which is RESERVED: always known, never unknown, even on
178
+ * installs where no confidential space materialized) and drops every id the
179
+ * `known` set (knownSpaceIds at the calling seam) contains. Sorted for a
180
+ * deterministic one-line-per-boot warning; empty = nothing to report.
181
+ *
182
+ * Such rows are stored-but-invisible: no members list can contain an
183
+ * unconfigured id, so isVisiblePrivacy excludes them for EVERY requester —
184
+ * the fail-closed direction (never normalized to shared). The operator
185
+ * resolves them by configuring the space or re-stamping (backfill).
186
+ */
187
+ export declare function unknownStoredSpaceIds(db: Database.Database, known: ReadonlySet<string>): string[];