@gamaze/hicortex 0.26.2 → 0.27.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.
- package/README.md +7 -2
- package/assets/dashboard.html +1 -1
- package/dist/backfill-privacy.d.ts +82 -0
- package/dist/backfill-privacy.js +193 -0
- package/dist/classification.d.ts +153 -0
- package/dist/classification.js +265 -0
- package/dist/classify-domains.js +24 -7
- package/dist/cli.js +31 -0
- package/dist/cluster.d.ts +15 -8
- package/dist/cluster.js +10 -3
- package/dist/consolidate.d.ts +31 -2
- package/dist/consolidate.js +193 -40
- package/dist/db.js +26 -1
- package/dist/dedup.d.ts +5 -3
- package/dist/dedup.js +26 -12
- package/dist/distill-queue.d.ts +25 -1
- package/dist/distill-queue.js +47 -7
- package/dist/graph.d.ts +28 -3
- package/dist/graph.js +46 -4
- package/dist/init.d.ts +18 -9
- package/dist/init.js +111 -81
- package/dist/mcp-server.js +186 -32
- package/dist/nightly.js +33 -7
- package/dist/recall-index.d.ts +19 -9
- package/dist/recall-index.js +14 -4
- package/dist/recall-precision.js +3 -1
- package/dist/reconsolidation.d.ts +10 -0
- package/dist/reconsolidation.js +80 -17
- package/dist/redact.d.ts +9 -1
- package/dist/redact.js +32 -1
- package/dist/rescore-importance.js +21 -4
- package/dist/retrieval.d.ts +23 -6
- package/dist/retrieval.js +41 -15
- package/dist/seed-lesson.js +3 -1
- package/dist/storage.d.ts +23 -4
- package/dist/storage.js +38 -9
- package/dist/type-classify.js +22 -7
- package/dist/types.d.ts +81 -15
- package/dist/uninstall.js +6 -5
- package/hermes-plugin/hicortex/README.md +4 -0
- package/hermes-plugin/hicortex/client.py +36 -9
- package/hermes-plugin/hicortex/plugin.yaml +1 -1
- package/hermes-plugin/hicortex/provider.py +28 -6
- package/package.json +1 -1
- package/server.json +2 -2
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* The confidential circle (#332) — the pure decision core for the two-level
|
|
4
|
+
* memory classification (`standard` | `confidential`, carried by
|
|
5
|
+
* `memories.privacy`; see MemoryPrivacy in types.ts).
|
|
6
|
+
*
|
|
7
|
+
* The model, in one paragraph: an operator lists inner-circle agents in
|
|
8
|
+
* config (`confidentialAgents`, the same agent-id namespace as
|
|
9
|
+
* `identityAgents` / `?agent=`). Captures whose `source_agent` is rostered
|
|
10
|
+
* are stamped `confidential` at intake — server-derived, deterministic, by
|
|
11
|
+
* birthplace; never a content judgment (content classification was rejected,
|
|
12
|
+
* #197) and never client-declared. Every agent-facing read path accepts an
|
|
13
|
+
* optional `agent` requester id: absent or unknown = non-member = HARD OMIT
|
|
14
|
+
* of confidential rows (fail-closed both ends — unrostered sources are
|
|
15
|
+
* standard, unknown requesters are non-members). The circle is ADDITIVE:
|
|
16
|
+
* members see both pools. Every LLM touch of confidential text routes to a
|
|
17
|
+
* separately configured second model (`llmConfidential*` config keys /
|
|
18
|
+
* `HICORTEX_LLM_CONFIDENTIAL_*` env) — when that model is absent, the work
|
|
19
|
+
* HOLDS (queue stays, deliveries refuse), never falls back to the main
|
|
20
|
+
* model. An install that configures nothing sees zero change: no roster, no
|
|
21
|
+
* confidential rows, no warning, no second client.
|
|
22
|
+
*
|
|
23
|
+
* All functions here are pure (no DB, no HTTP): the handlers in mcp-server.ts
|
|
24
|
+
* and the pipeline stages consume them, and the tests exercise the decisions
|
|
25
|
+
* directly.
|
|
26
|
+
*/
|
|
27
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
|
+
exports.resolveConfidentialAgents = resolveConfidentialAgents;
|
|
29
|
+
exports.isConfidentialSourceAgent = isConfidentialSourceAgent;
|
|
30
|
+
exports.deriveIntakePrivacy = deriveIntakePrivacy;
|
|
31
|
+
exports.isCircleMember = isCircleMember;
|
|
32
|
+
exports.resolveConfidentialLlmConfig = resolveConfidentialLlmConfig;
|
|
33
|
+
exports.buildConfidentialLlm = buildConfidentialLlm;
|
|
34
|
+
exports.resolveLlmPair = resolveLlmPair;
|
|
35
|
+
exports.clientForPool = clientForPool;
|
|
36
|
+
exports.warnIfCircleUnconfigured = warnIfCircleUnconfigured;
|
|
37
|
+
const identity_store_js_1 = require("./identity-store.js");
|
|
38
|
+
const llm_js_1 = require("./llm.js");
|
|
39
|
+
// ---------------------------------------------------------------------------
|
|
40
|
+
// Roster
|
|
41
|
+
// ---------------------------------------------------------------------------
|
|
42
|
+
/**
|
|
43
|
+
* Resolve the `confidentialAgents` config value into a clean roster of agent
|
|
44
|
+
* ids. Each entry is sanitized EXACTLY like `?agent=` (sanitizeAgentId —
|
|
45
|
+
* lowercase, collapse invalid runs to `-`, allowlist-validated) so the roster,
|
|
46
|
+
* the wire `agent` param, and capture's `<harness>/<id>` stamps live in one
|
|
47
|
+
* id namespace. Entries that sanitize to null are dropped and their raw
|
|
48
|
+
* values returned in `dropped` for a one-time boot warning (the
|
|
49
|
+
* resolveIdentityAgents pattern — a typo must surface, not silently drop an
|
|
50
|
+
* agent out of the circle).
|
|
51
|
+
*/
|
|
52
|
+
function resolveConfidentialAgents(config) {
|
|
53
|
+
const raw = config?.confidentialAgents;
|
|
54
|
+
if (!Array.isArray(raw))
|
|
55
|
+
return { roster: [], dropped: [] };
|
|
56
|
+
const roster = [];
|
|
57
|
+
const dropped = [];
|
|
58
|
+
for (const entry of raw) {
|
|
59
|
+
if (typeof entry !== "string") {
|
|
60
|
+
dropped.push(String(entry));
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
const id = (0, identity_store_js_1.sanitizeAgentId)(entry);
|
|
64
|
+
if (id && !roster.includes(id))
|
|
65
|
+
roster.push(id);
|
|
66
|
+
else if (!id)
|
|
67
|
+
dropped.push(entry);
|
|
68
|
+
}
|
|
69
|
+
return { roster, dropped };
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Normalize a capture-side `source_agent` for roster matching. Capture stamps
|
|
73
|
+
* harness-qualified ids (`hermes/nano`, `claude-code/myproject`), while the
|
|
74
|
+
* roster carries bare agent ids (the same ids the read side receives as
|
|
75
|
+
* `agent`) — ONE config list, no read-ids/capture-ids sync hazard. The match
|
|
76
|
+
* is exact, or exact after stripping the FIRST path segment (so `hermes/nano`
|
|
77
|
+
* matches roster `nano`, and a future `anything/nano` matches too — generic
|
|
78
|
+
* prefix, not a per-harness table). Case-insensitive on the id half via the
|
|
79
|
+
* roster's sanitized (lowercased) form.
|
|
80
|
+
*/
|
|
81
|
+
function isConfidentialSourceAgent(sourceAgent, roster) {
|
|
82
|
+
if (!sourceAgent || roster.length === 0)
|
|
83
|
+
return false;
|
|
84
|
+
const agent = sourceAgent.toLowerCase();
|
|
85
|
+
if (roster.includes(agent))
|
|
86
|
+
return true;
|
|
87
|
+
const slash = agent.indexOf("/");
|
|
88
|
+
if (slash < 0)
|
|
89
|
+
return false;
|
|
90
|
+
const bare = agent.slice(slash + 1);
|
|
91
|
+
const rest = bare.indexOf("/");
|
|
92
|
+
// Strip only the FIRST segment — `hermes/nano` → `nano`, but
|
|
93
|
+
// `a/b/nano` → `b/nano` (never a deep-suffix match; capture ids are
|
|
94
|
+
// single-qualified by construction).
|
|
95
|
+
return rest < 0 && roster.includes(bare);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* The intake-side derivation: which class a delivery from `sourceAgent`
|
|
99
|
+
* stores as. Fail-closed by construction — anything unattributed or
|
|
100
|
+
* unrostered is `standard` (the global pool).
|
|
101
|
+
*/
|
|
102
|
+
function deriveIntakePrivacy(sourceAgent, roster) {
|
|
103
|
+
return isConfidentialSourceAgent(sourceAgent, roster) ? "confidential" : "standard";
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* The read-side membership check: is the requester a circle member? Absent,
|
|
107
|
+
* blank, or unknown `agent` → false (fail-closed: an unknown id can never
|
|
108
|
+
* widen visibility, exactly like the identity layer's mode resolution). The
|
|
109
|
+
* `agent` value is sanitized first so a wire id arrives in the roster's
|
|
110
|
+
* namespace (`Nano` → `nano`); note sanitizeAgentId also collapses inner
|
|
111
|
+
* separators, so `hermes/nano` sent as a requester id reads as `hermes-nano`
|
|
112
|
+
* — the read side intentionally matches BARE ids only (plugins send their
|
|
113
|
+
* resolved profile name, not their capture-side qualified stamp).
|
|
114
|
+
*/
|
|
115
|
+
function isCircleMember(agent, roster) {
|
|
116
|
+
if (!agent || roster.length === 0)
|
|
117
|
+
return false;
|
|
118
|
+
const id = (0, identity_store_js_1.sanitizeAgentId)(agent);
|
|
119
|
+
return id !== null && roster.includes(id);
|
|
120
|
+
}
|
|
121
|
+
// ---------------------------------------------------------------------------
|
|
122
|
+
// The confidential LLM client
|
|
123
|
+
// ---------------------------------------------------------------------------
|
|
124
|
+
/**
|
|
125
|
+
* Resolve the confidential model's CONFIG from explicit config keys or env —
|
|
126
|
+
* the same shape and precedence as the main model
|
|
127
|
+
* (resolveExplicitLlmConfig):
|
|
128
|
+
*
|
|
129
|
+
* 1. config `llmConfidentialBaseUrl` + `llmConfidentialApiKey` (both
|
|
130
|
+
* required; `llmConfidentialModel` optional; `llmConfidentialProvider`
|
|
131
|
+
* selects the request dialect, else URL detection — the llmProvider
|
|
132
|
+
* precedent);
|
|
133
|
+
* 2. env `HICORTEX_LLM_CONFIDENTIAL_BASE_URL` +
|
|
134
|
+
* `HICORTEX_LLM_CONFIDENTIAL_API_KEY` (both required;
|
|
135
|
+
* `HICORTEX_LLM_CONFIDENTIAL_MODEL` optional) — mirroring the main
|
|
136
|
+
* model's HICORTEX_LLM_* env pattern.
|
|
137
|
+
*
|
|
138
|
+
* null when nothing explicit is set — the caller holds/skips confidential
|
|
139
|
+
* work and warns (never falls back to the main model).
|
|
140
|
+
*
|
|
141
|
+
* Deliberately NOT routed through the named backends (claude-cli / ollama):
|
|
142
|
+
* the confidential model is a full explicit-config surface by spec — a
|
|
143
|
+
* second claude-cli subprocess or a local ollama alias would silently be the
|
|
144
|
+
* SAME trust domain as the main model.
|
|
145
|
+
*/
|
|
146
|
+
function resolveConfidentialLlmConfig(savedConfig) {
|
|
147
|
+
const s = savedConfig ?? {};
|
|
148
|
+
const str = (v) => typeof v === "string" && v ? v : undefined;
|
|
149
|
+
const cfgBase = str(s.llmConfidentialBaseUrl);
|
|
150
|
+
const cfgKey = str(s.llmConfidentialApiKey);
|
|
151
|
+
// Both config keys required (the main model's contract). Called with BOTH
|
|
152
|
+
// set, resolveExplicitLlmConfig answers from them alone — it only falls to
|
|
153
|
+
// the MAIN HICORTEX_LLM_* env vars when its overrides are absent, which
|
|
154
|
+
// would silently configure the confidential client as the main model. The
|
|
155
|
+
// explicit guard keeps that branch unreachable here.
|
|
156
|
+
if (cfgBase && cfgKey) {
|
|
157
|
+
return (0, llm_js_1.resolveExplicitLlmConfig)({
|
|
158
|
+
llmBaseUrl: cfgBase,
|
|
159
|
+
llmApiKey: cfgKey,
|
|
160
|
+
llmModel: str(s.llmConfidentialModel),
|
|
161
|
+
llmProvider: str(s.llmConfidentialProvider),
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
const envBase = str(process.env.HICORTEX_LLM_CONFIDENTIAL_BASE_URL);
|
|
165
|
+
const envKey = str(process.env.HICORTEX_LLM_CONFIDENTIAL_API_KEY);
|
|
166
|
+
if (envBase && envKey) {
|
|
167
|
+
return (0, llm_js_1.resolveExplicitLlmConfig)({
|
|
168
|
+
llmBaseUrl: envBase,
|
|
169
|
+
llmApiKey: envKey,
|
|
170
|
+
llmModel: str(process.env.HICORTEX_LLM_CONFIDENTIAL_MODEL),
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
return null;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Build the confidential LlmClient for a resolved config — the daemon
|
|
177
|
+
* funnel's construction half. Applies the SAME tuning overlay as the main
|
|
178
|
+
* client (applyTierTuningOverlay, the both-sites discipline: maxTokens,
|
|
179
|
+
* timeouts, single-flight apply per-process at construction) so the second
|
|
180
|
+
* model is not a second-class client.
|
|
181
|
+
*/
|
|
182
|
+
function buildConfidentialLlm(savedConfig) {
|
|
183
|
+
const config = resolveConfidentialLlmConfig(savedConfig);
|
|
184
|
+
if (!config)
|
|
185
|
+
return null;
|
|
186
|
+
(0, llm_js_1.applyTierTuningOverlay)(config, savedConfig ?? null);
|
|
187
|
+
return { llm: new llm_js_1.LlmClient(config), config };
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Resolve the full pair for a pipeline process (the nightly/CLI funnel —
|
|
191
|
+
* resolveSavedLlmConfig for the standard client, buildConfidentialLlm for
|
|
192
|
+
* the confidential one). Returns the pair plus both configs (the drain and
|
|
193
|
+
* the /distill sync path need the config for chunk-size detection/probing),
|
|
194
|
+
* and passes through resolveSavedLlmConfig's `reason` so callers keep their
|
|
195
|
+
* claude-binary-missing logging.
|
|
196
|
+
*/
|
|
197
|
+
function resolveLlmPair(savedConfig) {
|
|
198
|
+
const resolved = (0, llm_js_1.resolveSavedLlmConfig)(savedConfig ?? null);
|
|
199
|
+
const confidential = buildConfidentialLlm(savedConfig);
|
|
200
|
+
if (!resolved.config) {
|
|
201
|
+
return {
|
|
202
|
+
pair: null,
|
|
203
|
+
standardConfig: null,
|
|
204
|
+
confidentialConfig: confidential?.config ?? null,
|
|
205
|
+
reason: resolved.reason,
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
return {
|
|
209
|
+
pair: {
|
|
210
|
+
standard: new llm_js_1.LlmClient(resolved.config),
|
|
211
|
+
confidential: confidential?.llm ?? null,
|
|
212
|
+
},
|
|
213
|
+
standardConfig: resolved.config,
|
|
214
|
+
confidentialConfig: confidential?.config ?? null,
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* The per-pool selection every stage call site goes through: the client that
|
|
219
|
+
* MUST serve a memory class, or null when the confidential pool has no
|
|
220
|
+
* client configured (the caller holds/skips that pool's work — the
|
|
221
|
+
* structurally-hard guarantee that confidential text can never reach the
|
|
222
|
+
* standard model: there is no code path that answers "give me SOME client
|
|
223
|
+
* for confidential").
|
|
224
|
+
*/
|
|
225
|
+
function clientForPool(pair, privacy) {
|
|
226
|
+
if (privacy === "confidential")
|
|
227
|
+
return pair.confidential;
|
|
228
|
+
return pair.standard;
|
|
229
|
+
}
|
|
230
|
+
// ---------------------------------------------------------------------------
|
|
231
|
+
// Boot warning
|
|
232
|
+
// ---------------------------------------------------------------------------
|
|
233
|
+
/**
|
|
234
|
+
* The ONE loud boot warning when the circle is ACTIVE (a roster is
|
|
235
|
+
* configured, OR confidential rows exist, OR confidential items sit queued)
|
|
236
|
+
* but the confidential model is not. Called at daemon boot and nightly start;
|
|
237
|
+
* prints once per call site (the callers are once-per-process). The wording
|
|
238
|
+
* names the exposure and the HOLD behavior — the operator learns from the
|
|
239
|
+
* logs that deliveries are piling up, not silently distilling on the main
|
|
240
|
+
* model. Returns whether the warning fired (tests + callers that compose
|
|
241
|
+
* their own log lines).
|
|
242
|
+
*/
|
|
243
|
+
function warnIfCircleUnconfigured(opts) {
|
|
244
|
+
if (opts.confidentialLlm)
|
|
245
|
+
return false;
|
|
246
|
+
const active = opts.roster.length > 0 || opts.confidentialRows > 0 || opts.queueConfidential > 0;
|
|
247
|
+
if (!active)
|
|
248
|
+
return false;
|
|
249
|
+
console.warn("");
|
|
250
|
+
console.warn("╔══════════════════════════════════════════════════════════════╗");
|
|
251
|
+
console.warn("║ CONFIDENTIAL CIRCLE ACTIVE WITHOUT A CONFIDENTIAL MODEL ║");
|
|
252
|
+
console.warn("║ ║");
|
|
253
|
+
console.warn("║ Confidential memories exist (or a confidentialAgents ║");
|
|
254
|
+
console.warn("║ roster is set) but llmConfidentialBaseUrl/ApiKey are not. ║");
|
|
255
|
+
console.warn("║ Confidential deliveries are HELD, not distilled — they ║");
|
|
256
|
+
console.warn("║ accumulate until a confidential model is configured ║");
|
|
257
|
+
console.warn("║ (they never fall back to the main model). Standard ║");
|
|
258
|
+
console.warn("║ capture and consolidation continue normally. ║");
|
|
259
|
+
console.warn("║ ║");
|
|
260
|
+
console.warn("║ Set llmConfidentialBaseUrl + llmConfidentialApiKey ║");
|
|
261
|
+
console.warn("║ (+ llmConfidentialModel) in config.json and restart. ║");
|
|
262
|
+
console.warn("╚══════════════════════════════════════════════════════════════╝");
|
|
263
|
+
console.warn("");
|
|
264
|
+
return true;
|
|
265
|
+
}
|
package/dist/classify-domains.js
CHANGED
|
@@ -75,7 +75,7 @@ const node_path_1 = require("node:path");
|
|
|
75
75
|
const db_js_1 = require("./db.js");
|
|
76
76
|
const state_js_1 = require("./state.js");
|
|
77
77
|
const storage = __importStar(require("./storage.js"));
|
|
78
|
-
const
|
|
78
|
+
const classification_js_1 = require("./classification.js");
|
|
79
79
|
const domain_classify_js_1 = require("./domain-classify.js");
|
|
80
80
|
const consolidate_js_1 = require("./consolidate.js");
|
|
81
81
|
const schema_prototypes_js_1 = require("./schema-prototypes.js");
|
|
@@ -125,17 +125,22 @@ async function runClassifyDomains(options = {}) {
|
|
|
125
125
|
const weakPrimaryFloor = Number.isFinite(floorRaw) && floorRaw > 0 && floorRaw < 1
|
|
126
126
|
? floorRaw
|
|
127
127
|
: nofit_js_1.DEFAULT_WEAK_PRIMARY_FLOOR;
|
|
128
|
-
// Resolve the LLM (one model serves all phases — #231).
|
|
128
|
+
// Resolve the LLM (one model serves all phases — #231). #332: plus the
|
|
129
|
+
// confidential client — each row's classify call picks the client matching
|
|
130
|
+
// its stamp; a confidential row without a client holds (treated like the
|
|
131
|
+
// infra abort: untouched, retried).
|
|
129
132
|
let llm;
|
|
133
|
+
let confidentialLlm = null;
|
|
130
134
|
if (options.llm) {
|
|
131
135
|
llm = options.llm;
|
|
132
136
|
}
|
|
133
137
|
else {
|
|
134
|
-
const resolved = (0,
|
|
135
|
-
if (!resolved.
|
|
138
|
+
const resolved = (0, classification_js_1.resolveLlmPair)(config);
|
|
139
|
+
if (!resolved.pair) {
|
|
136
140
|
throw new Error("[hicortex] classify-domains: no LLM configured — run `npx @gamaze/hicortex init`.");
|
|
137
141
|
}
|
|
138
|
-
llm =
|
|
142
|
+
llm = resolved.pair.standard;
|
|
143
|
+
confidentialLlm = resolved.pair.confidential;
|
|
139
144
|
}
|
|
140
145
|
const dbPath = (0, db_js_1.resolveDbPath)(options.dbPath);
|
|
141
146
|
const db = (0, db_js_1.initDb)(dbPath);
|
|
@@ -185,7 +190,7 @@ async function runClassifyDomains(options = {}) {
|
|
|
185
190
|
: `rowid > ? AND COALESCE(status, '') != 'absorbed' ` +
|
|
186
191
|
`AND (domain IS NULL OR domain NOT IN (${placeholders}) ` +
|
|
187
192
|
`OR id NOT IN (SELECT DISTINCT memory_id FROM memory_tags))`;
|
|
188
|
-
const batchStmt = db.prepare(`SELECT rowid AS __rowid, id, content, project, domain FROM memories
|
|
193
|
+
const batchStmt = db.prepare(`SELECT rowid AS __rowid, id, content, project, domain, privacy FROM memories
|
|
189
194
|
WHERE ${scopeSql} ORDER BY rowid ASC LIMIT ?`);
|
|
190
195
|
// Set true when the classifier returns null (infra error): finish the
|
|
191
196
|
// current batch's already-classified writes, commit, advance cursor to the
|
|
@@ -209,7 +214,19 @@ async function runClassifyDomains(options = {}) {
|
|
|
209
214
|
// the scan phase; only the writes are deferred to the transaction.
|
|
210
215
|
const writes = [];
|
|
211
216
|
for (const row of rows) {
|
|
212
|
-
|
|
217
|
+
// #332: per-row client selection — a confidential row classifies on
|
|
218
|
+
// the confidential client; without one it HOLDS (the infra-abort
|
|
219
|
+
// posture: untouched, retried next run).
|
|
220
|
+
const rowLlm = row.privacy === "confidential"
|
|
221
|
+
? confidentialLlm
|
|
222
|
+
: llm;
|
|
223
|
+
if (!rowLlm) {
|
|
224
|
+
console.warn(`[hicortex] classify-domains: confidential row ${row.id.slice(0, 8)} held — ` +
|
|
225
|
+
`no confidential model configured (llmConfidentialBaseUrl/ApiKey)`);
|
|
226
|
+
infraAbort = true;
|
|
227
|
+
break;
|
|
228
|
+
}
|
|
229
|
+
const result = await (0, domain_classify_js_1.classifyMemoryTags)(row.content, row.project, domains, rowLlm);
|
|
213
230
|
if (result === null) {
|
|
214
231
|
// Infra error — stop scanning; leave this row untouched for retry.
|
|
215
232
|
infraAbort = true;
|
package/dist/cli.js
CHANGED
|
@@ -337,6 +337,31 @@ switch (command) {
|
|
|
337
337
|
});
|
|
338
338
|
break;
|
|
339
339
|
}
|
|
340
|
+
case "backfill-privacy": {
|
|
341
|
+
// One-shot classification stamping for EXISTING rows, by source agent
|
|
342
|
+
// (#332): every row whose source_agent matches the confidentialAgents
|
|
343
|
+
// roster flips to confidential. Mirrors `dedup`/`reconcile-projects`:
|
|
344
|
+
// dry-run default, --apply explicit (backup + capture lock + ONE
|
|
345
|
+
// transaction); flags parsed here, the runner lives in
|
|
346
|
+
// backfill-privacy.ts so this switch stays thin.
|
|
347
|
+
const args = process.argv.slice(3);
|
|
348
|
+
let dbPath;
|
|
349
|
+
try {
|
|
350
|
+
dbPath = (0, cli_args_js_1.readValueFlag)(args, "--db");
|
|
351
|
+
}
|
|
352
|
+
catch {
|
|
353
|
+
console.error("[hicortex] backfill-privacy: --db requires a path value");
|
|
354
|
+
process.exit(1);
|
|
355
|
+
}
|
|
356
|
+
const backfillOptions = { apply: args.includes("--apply"), dbPath };
|
|
357
|
+
import("./backfill-privacy.js").then(({ runBackfillPrivacy }) => {
|
|
358
|
+
runBackfillPrivacy(backfillOptions).catch((err) => {
|
|
359
|
+
console.error(err instanceof Error ? err.message : `[hicortex] backfill-privacy failed: ${err}`);
|
|
360
|
+
process.exit(1);
|
|
361
|
+
});
|
|
362
|
+
});
|
|
363
|
+
break;
|
|
364
|
+
}
|
|
340
365
|
case "sweep-volatile": {
|
|
341
366
|
// One-shot store sweep of volatile GH-status/version rows (#489,
|
|
342
367
|
// deliverable iii): reuses the distill path's deterministic gate over the
|
|
@@ -500,6 +525,8 @@ Commands:
|
|
|
500
525
|
relink Resumable link-discovery pass over the ENTIRE corpus (server mode)
|
|
501
526
|
dedup Cluster + merge near-duplicate memories (server mode; dry run by default)
|
|
502
527
|
reconcile-projects Canonicalize existing project labels (server mode; dry run by default)
|
|
528
|
+
backfill-privacy Stamp history confidential by source agent (#332; server mode;
|
|
529
|
+
dry run by default — --apply executes: backup + capture lock + stamp)
|
|
503
530
|
history Show a memory's rewrite history, or roll one back (server mode)
|
|
504
531
|
history <id> List rewrite events (read-only)
|
|
505
532
|
history --rollback <row> Undo one rewrite + un-absorb its triggers
|
|
@@ -538,6 +565,10 @@ Options:
|
|
|
538
565
|
reconcile-projects --apply Execute the project renames (default: dry run, report only)
|
|
539
566
|
Backup first; renames memories + distill_queue only
|
|
540
567
|
reconcile-projects --db <path> DB path override (defaults to the configured DB)
|
|
568
|
+
backfill-privacy --apply Execute the stamps (default: dry run, report only)
|
|
569
|
+
Backup + capture lock first; stamps memories + distill_queue;
|
|
570
|
+
never stamps back to standard (a roster removal is not a demotion)
|
|
571
|
+
backfill-privacy --db <path> DB path override (defaults to the configured DB)
|
|
541
572
|
history --rollback <row> Roll back history row <row>: restores prior content/status, un-absorbs triggers
|
|
542
573
|
history --db <path> DB path override (defaults to the configured DB)
|
|
543
574
|
backup --out <dir> Write the artifact into <dir> as hicortex-<ISO>.tar.gz (default: <home>/backups)
|
package/dist/cluster.d.ts
CHANGED
|
@@ -25,12 +25,16 @@ export declare class UnionFind {
|
|
|
25
25
|
export declare function clusterEdges(edges: Edge[], threshold: number): string[][];
|
|
26
26
|
/** Excess = sum(cluster size − 1) — rows that would disappear if every cluster merged to one. */
|
|
27
27
|
export declare function clusterExcess(clusters: string[][]): number;
|
|
28
|
-
/** Metadata row shape for the merge-safety check. `
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
28
|
+
/** Metadata row shape for the merge-safety check. `source_agent` is on the
|
|
29
|
+
* row (the column still exists) but is NOT a merge-safety field: the agent
|
|
30
|
+
* rail was REMOVED by owner decision (#206 decision 2, 2026-09-21) —
|
|
31
|
+
* cross-agent clusters merge, because attribution survives on the retained
|
|
32
|
+
* absorbed-loser row and no recall path filters by source_agent. Project is
|
|
33
|
+
* one rail; `privacy` (the #332 classification, standard | confidential) is
|
|
34
|
+
* the other — a cluster mixing classes is NEVER blended (the confidential
|
|
35
|
+
* pool must not absorb standard rows into hidden view, nor leak
|
|
36
|
+
* confidential content onto a standard canonical). This re-adds a
|
|
37
|
+
* classification-shaped rail #206 removed when the column was vestigial. */
|
|
34
38
|
export interface ClusterMetaRow {
|
|
35
39
|
project: string | null;
|
|
36
40
|
privacy: string | null;
|
|
@@ -38,9 +42,12 @@ export interface ClusterMetaRow {
|
|
|
38
42
|
}
|
|
39
43
|
export interface ClusterMetadataMismatch {
|
|
40
44
|
projectMismatch: boolean;
|
|
45
|
+
/** #332: members disagree on the standard|confidential classification. */
|
|
46
|
+
classificationMismatch: boolean;
|
|
41
47
|
}
|
|
42
|
-
/** Do cluster members disagree on project? (merge-safety
|
|
43
|
-
*
|
|
48
|
+
/** Do cluster members disagree on project or classification? (merge-safety
|
|
49
|
+
* input for #100/#206 + #332.) source_agent is intentionally NOT checked —
|
|
50
|
+
* see ClusterMetaRow. */
|
|
44
51
|
export declare function clusterMetadataMismatch(members: ClusterMetaRow[]): ClusterMetadataMismatch;
|
|
45
52
|
/**
|
|
46
53
|
* Build the max-cosine edge set via top-K KNN on `memory_vectors`, keeping
|
package/dist/cluster.js
CHANGED
|
@@ -69,11 +69,18 @@ function clusterEdges(edges, threshold) {
|
|
|
69
69
|
function clusterExcess(clusters) {
|
|
70
70
|
return clusters.reduce((sum, c) => sum + (c.length - 1), 0);
|
|
71
71
|
}
|
|
72
|
-
/** Do cluster members disagree on project? (merge-safety
|
|
73
|
-
*
|
|
72
|
+
/** Do cluster members disagree on project or classification? (merge-safety
|
|
73
|
+
* input for #100/#206 + #332.) source_agent is intentionally NOT checked —
|
|
74
|
+
* see ClusterMetaRow. */
|
|
74
75
|
function clusterMetadataMismatch(members) {
|
|
75
76
|
const projects = new Set(members.map((m) => m.project ?? "\u0000null"));
|
|
76
|
-
|
|
77
|
+
// The classification comparison treats NULL (pre-v27 rows) as 'standard' —
|
|
78
|
+
// the same normalization every read gate applies.
|
|
79
|
+
const classes = new Set(members.map((m) => (m.privacy === "confidential" ? "confidential" : "standard")));
|
|
80
|
+
return {
|
|
81
|
+
projectMismatch: projects.size > 1,
|
|
82
|
+
classificationMismatch: classes.size > 1,
|
|
83
|
+
};
|
|
77
84
|
}
|
|
78
85
|
// ---------------------------------------------------------------------------
|
|
79
86
|
// KNN edge building
|
package/dist/consolidate.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Ported from hicortex/consolidate/ (stages.py, __init__.py, budget.py).
|
|
5
5
|
*/
|
|
6
6
|
import type Database from "better-sqlite3";
|
|
7
|
-
import type { Memory, ConsolidationReport } from "./types.js";
|
|
7
|
+
import type { Memory, ConsolidationReport, MemoryPrivacy } from "./types.js";
|
|
8
8
|
import type { LlmClient } from "./llm.js";
|
|
9
9
|
import type { EmbedFn } from "./retrieval.js";
|
|
10
10
|
import { type DomainDef } from "./domain-classify.js";
|
|
@@ -185,10 +185,30 @@ export declare function scoreMemoriesImportance(db: Database.Database, memories:
|
|
|
185
185
|
deadline?: RunDeadline;
|
|
186
186
|
dryRun?: boolean;
|
|
187
187
|
onBatch?: (written: number, failed: number) => void;
|
|
188
|
+
/**
|
|
189
|
+
* #332: the confidential-pool client. The batch builder partitions the
|
|
190
|
+
* pool by class FIRST (buildImportanceBatches — batches are single-class
|
|
191
|
+
* by construction), so every LLM call carries one class of text to one
|
|
192
|
+
* client. Confidential batches without a client are SKIPPED (their rows
|
|
193
|
+
* keep importance_scored_at NULL — the watermark pool re-finds them next
|
|
194
|
+
* run; counted in skipped_confidential), never scored on the main model.
|
|
195
|
+
*/
|
|
196
|
+
confidentialLlm?: LlmClient | null;
|
|
188
197
|
}): Promise<{
|
|
189
198
|
scored: number;
|
|
190
199
|
failed: number;
|
|
191
200
|
skipped_budget: number;
|
|
201
|
+
skipped_confidential?: number;
|
|
202
|
+
}>;
|
|
203
|
+
/**
|
|
204
|
+
* #332 — the importance batch builder: partition by classification, then
|
|
205
|
+
* slice into batches. Every batch is SINGLE-CLASS by construction (AC-10),
|
|
206
|
+
* so the scoring call site can route each batch to the client matching its
|
|
207
|
+
* pool with no per-item checks. Exported for the unit test.
|
|
208
|
+
*/
|
|
209
|
+
export declare function buildImportanceBatches(memories: Memory[], batchSize?: number): Array<{
|
|
210
|
+
pool: MemoryPrivacy;
|
|
211
|
+
memories: Memory[];
|
|
192
212
|
}>;
|
|
193
213
|
/**
|
|
194
214
|
* Rebuild moduleIndex from the configured domain set + live DB counts, and
|
|
@@ -369,4 +389,13 @@ reconsolidationOptions?: ReconsolidationOptions,
|
|
|
369
389
|
* the report status becomes "deferred" — which keeps lastConsolidated
|
|
370
390
|
* un-advanced so the next run re-finds the pending work.
|
|
371
391
|
*/
|
|
372
|
-
deadline?: RunDeadline
|
|
392
|
+
deadline?: RunDeadline,
|
|
393
|
+
/**
|
|
394
|
+
* #332: the CONFIDENTIAL model client. Every stage that can touch
|
|
395
|
+
* confidential text (importance batches, reflection, domain classification,
|
|
396
|
+
* reconsolidation verdicts/rewrites) selects per-pool — confidential work
|
|
397
|
+
* goes here; when null, that work HOLDS/skips, never falls back to `llm`.
|
|
398
|
+
* Optional so every pre-#332 caller (and corpora with no confidential
|
|
399
|
+
* rows) is byte-identical.
|
|
400
|
+
*/
|
|
401
|
+
confidentialLlm?: LlmClient | null): Promise<ConsolidationReport>;
|