@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
package/dist/mcp-server.js
CHANGED
|
@@ -95,6 +95,7 @@ const capture_health_js_1 = require("./capture-health.js");
|
|
|
95
95
|
const recall_precision_js_1 = require("./recall-precision.js");
|
|
96
96
|
const capture_pause_js_1 = require("./capture-pause.js");
|
|
97
97
|
const project_canonicalize_js_1 = require("./project-canonicalize.js");
|
|
98
|
+
const classification_js_1 = require("./classification.js");
|
|
98
99
|
const init_js_1 = require("./init.js");
|
|
99
100
|
// ---------------------------------------------------------------------------
|
|
100
101
|
// Server state
|
|
@@ -104,6 +105,12 @@ let llm = null;
|
|
|
104
105
|
// llmConfig is module-level so the /distill handler can read numCtx without
|
|
105
106
|
// re-resolving on every request. null when no LLM is configured.
|
|
106
107
|
let llmConfig = null;
|
|
108
|
+
// #332: the CONFIDENTIAL model client (llmConfidential* config /
|
|
109
|
+
// HICORTEX_LLM_CONFIDENTIAL_* env). null when unconfigured — confidential
|
|
110
|
+
// work then refuses/holds, never falls back to the main client. Built at the
|
|
111
|
+
// same funnel as the main client (boot), with the same tuning overlay.
|
|
112
|
+
let confidentialLlm = null;
|
|
113
|
+
let confidentialLlmConfig = null;
|
|
107
114
|
// One-time-per-process deprecation warning for the `?privacy=` query param
|
|
108
115
|
// (0.16.x: the column is vestigial, never filtered). Old clients/plugins still
|
|
109
116
|
// send it; we accept it (backward compat) but warn ONCE so an operator relying
|
|
@@ -144,6 +151,11 @@ let recallIndexOptions = {};
|
|
|
144
151
|
let projectAliases = null;
|
|
145
152
|
// Product-owned memory instructions (#192): on unless config says false.
|
|
146
153
|
let memoryInstructionsEnabled = true;
|
|
154
|
+
// #332: the confidential-circle roster (config `confidentialAgents`),
|
|
155
|
+
// resolved once at boot like identityAgents (restart to apply). Empty = no
|
|
156
|
+
// circle: every delivery stamps standard, nothing is ever omitted from read
|
|
157
|
+
// paths — the zero-change default.
|
|
158
|
+
let confidentialRoster = [];
|
|
147
159
|
/**
|
|
148
160
|
* #567: fold ONE project string through the boot-resolved alias map — the
|
|
149
161
|
* shared normalization for every project-string entry point in this file
|
|
@@ -155,6 +167,16 @@ let memoryInstructionsEnabled = true;
|
|
|
155
167
|
* affinity, lesson selection, the dedup project rail) sees the same value.
|
|
156
168
|
*/
|
|
157
169
|
const canonProject = (v) => (0, project_canonicalize_js_1.canonicalizeProject)(typeof v === "string" ? v : null, projectAliases) ?? undefined;
|
|
170
|
+
/**
|
|
171
|
+
* #332: resolve the classification visibility for ONE request's `agent` param
|
|
172
|
+
* against the boot-resolved roster. Absent/blank/unknown agent → FALSE
|
|
173
|
+
* (fail-closed non-member — confidential rows are hard-omitted); a rostered
|
|
174
|
+
* agent id → TRUE (the additive circle: members see both pools). The `agent`
|
|
175
|
+
* self-asserts identity, exactly like the client-pushed project field — same
|
|
176
|
+
* trust level, documented in the spec (per-agent tokens are the known future
|
|
177
|
+
* fix). Shared by every agent-facing read route below.
|
|
178
|
+
*/
|
|
179
|
+
const requestSeesConfidential = (rawAgent) => (0, classification_js_1.isCircleMember)(typeof rawAgent === "string" && rawAgent ? rawAgent : null, confidentialRoster);
|
|
158
180
|
// Cache detectChunkSize results keyed by "<provider>/<model>@<baseUrl>" so we
|
|
159
181
|
// probe each endpoint once per server boot rather than once per /distill request.
|
|
160
182
|
const chunkSizeCache = new Map();
|
|
@@ -299,6 +321,11 @@ function createMcpServer() {
|
|
|
299
321
|
project: canonProject(project),
|
|
300
322
|
// Normalize legacy raw enum to the canonical term the DB stores.
|
|
301
323
|
memoryType: memory_type ? (0, type_labels_js_1.normalizeMemoryType)(memory_type) : "experience",
|
|
324
|
+
// #332: the MCP ingest path derives the stamp from its fixed
|
|
325
|
+
// source_agent like every write path (a roster entry
|
|
326
|
+
// "claude-code/manual" — or its bare "manual" — would stamp
|
|
327
|
+
// confidential; mechanical rule, no special case).
|
|
328
|
+
privacy: (0, classification_js_1.deriveIntakePrivacy)("claude-code/manual", confidentialRoster),
|
|
302
329
|
});
|
|
303
330
|
if (explicitMark)
|
|
304
331
|
(0, reconsolidation_js_1.applyExplicitMark)(db, id, explicitMark);
|
|
@@ -466,12 +493,21 @@ function createMcpServer() {
|
|
|
466
493
|
}, async ({ operation, id, target_id, limit: resultLimit, domain: filterDomain, relationship: filterRelationship }) => {
|
|
467
494
|
if (!db)
|
|
468
495
|
return { content: [{ type: "text", text: "Hicortex not initialized" }], isError: true };
|
|
496
|
+
// #332: MCP tools carry NO requester identity, so they are non-members
|
|
497
|
+
// by construction — confidential rows (incl. hub/neighbor content) are
|
|
498
|
+
// hard-omitted, and a confidential center/endpoint id reads as not
|
|
499
|
+
// found. Accepted in the spec: circle agents read through their
|
|
500
|
+
// plugin's agent-threaded REST calls, not through MCP tools.
|
|
501
|
+
const idVisible = (fullId) => {
|
|
502
|
+
const row = db.prepare("SELECT privacy FROM memories WHERE id = ?").get(fullId);
|
|
503
|
+
return row?.privacy !== "confidential";
|
|
504
|
+
};
|
|
469
505
|
try {
|
|
470
506
|
if (operation === "neighbors") {
|
|
471
507
|
if (!id)
|
|
472
508
|
return { content: [{ type: "text", text: "id is required for neighbors operation" }], isError: true };
|
|
473
509
|
const resolvedId = resolveMemoryId(db, id);
|
|
474
|
-
if (!resolvedId)
|
|
510
|
+
if (!resolvedId || !idVisible(resolvedId))
|
|
475
511
|
return { content: [{ type: "text", text: `Memory not found: ${id}` }], isError: true };
|
|
476
512
|
const neighbors = (0, graph_js_1.getNeighbors)(db, resolvedId, resultLimit ?? 10, filterRelationship);
|
|
477
513
|
if (neighbors.length === 0)
|
|
@@ -494,7 +530,7 @@ function createMcpServer() {
|
|
|
494
530
|
return { content: [{ type: "text", text: "id and target_id are required for path operation" }], isError: true };
|
|
495
531
|
const fromId = resolveMemoryId(db, id);
|
|
496
532
|
const toId = resolveMemoryId(db, target_id);
|
|
497
|
-
if (!fromId || !toId)
|
|
533
|
+
if (!fromId || !toId || !idVisible(fromId) || !idVisible(toId))
|
|
498
534
|
return { content: [{ type: "text", text: "One or both memory IDs not found" }], isError: true };
|
|
499
535
|
const path = (0, graph_js_1.shortestPath)(db, fromId, toId);
|
|
500
536
|
if (!path)
|
|
@@ -800,6 +836,17 @@ async function startServer(options = {}) {
|
|
|
800
836
|
console.warn("╚══════════════════════════════════════════════════════════════╝");
|
|
801
837
|
console.warn("");
|
|
802
838
|
}
|
|
839
|
+
// #332: the confidential model — built at the SAME funnel (boot) with the
|
|
840
|
+
// same tuning overlay (buildConfidentialLlm). Absent is legal (standard-only
|
|
841
|
+
// installs never need it); the loud warning below fires only when the
|
|
842
|
+
// circle is actually active.
|
|
843
|
+
const confidentialBuilt = (0, classification_js_1.buildConfidentialLlm)(savedConfig);
|
|
844
|
+
confidentialLlm = confidentialBuilt?.llm ?? null;
|
|
845
|
+
confidentialLlmConfig = confidentialBuilt?.config ?? null;
|
|
846
|
+
if (confidentialLlmConfig) {
|
|
847
|
+
console.log(`[hicortex] Confidential LLM: ${confidentialLlmConfig.provider}/${confidentialLlmConfig.model}` +
|
|
848
|
+
` — every touch of confidential text routes here`);
|
|
849
|
+
}
|
|
803
850
|
// One-time migration of legacy state files (no-op if state.json exists)
|
|
804
851
|
(0, state_js_1.migrateLegacyState)(stateDir);
|
|
805
852
|
// License: read from options, config file, or env var, init feature cache
|
|
@@ -897,6 +944,34 @@ async function startServer(options = {}) {
|
|
|
897
944
|
console.warn(`[hicortex] Ignoring invalid identityAgents entries: ${resolvedAgents.dropped.join(", ")} ` +
|
|
898
945
|
`(keys must match ^[a-z0-9][a-z0-9_-]*$; modes must be override|global|off)`);
|
|
899
946
|
}
|
|
947
|
+
// #332 confidential circle: resolve the roster (boot-time, like
|
|
948
|
+
// identityAgents — restart to apply). Every write path below derives the
|
|
949
|
+
// classification stamp from source_agent × this roster; the read paths
|
|
950
|
+
// membership-check the `agent` param against it. An empty roster is the
|
|
951
|
+
// zero-change default (deriveIntakePrivacy answers standard for everything).
|
|
952
|
+
const resolvedConfidential = (0, classification_js_1.resolveConfidentialAgents)(savedConfig);
|
|
953
|
+
confidentialRoster = resolvedConfidential.roster;
|
|
954
|
+
if (resolvedConfidential.dropped.length > 0) {
|
|
955
|
+
console.warn(`[hicortex] Ignoring invalid confidentialAgents entries: ${resolvedConfidential.dropped.join(", ")} ` +
|
|
956
|
+
`(ids must sanitize like ?agent= — a dropped id means that agent is NOT in the circle)`);
|
|
957
|
+
}
|
|
958
|
+
if (confidentialRoster.length > 0) {
|
|
959
|
+
console.log(`[hicortex] Confidential circle: ${confidentialRoster.length} agent(s) rostered`);
|
|
960
|
+
}
|
|
961
|
+
// #332: the ONE loud boot warning when the circle is active without the
|
|
962
|
+
// confidential model. "Active" = roster set OR confidential rows already
|
|
963
|
+
// stored OR confidential items already queued — on a zero-config install
|
|
964
|
+
// none of those hold and the warning stays silent (AC-2).
|
|
965
|
+
(0, classification_js_1.warnIfCircleUnconfigured)({
|
|
966
|
+
roster: confidentialRoster,
|
|
967
|
+
confidentialLlm,
|
|
968
|
+
confidentialRows: db
|
|
969
|
+
.prepare("SELECT COUNT(*) AS c FROM memories WHERE privacy = 'confidential'")
|
|
970
|
+
.get().c,
|
|
971
|
+
queueConfidential: db
|
|
972
|
+
.prepare("SELECT COUNT(*) AS c FROM distill_queue WHERE privacy = 'confidential'")
|
|
973
|
+
.get().c,
|
|
974
|
+
});
|
|
900
975
|
// #264 dir migration: rename <hicortex-home>/context/ → identity/ on boot
|
|
901
976
|
// when only the legacy dir exists. The fallback read in identity-store.ts
|
|
902
977
|
// (readSectionsWithFallback) is the safety net for a partial/no migration.
|
|
@@ -996,13 +1071,17 @@ async function startServer(options = {}) {
|
|
|
996
1071
|
// memory index for client CLAUDE.md injection. Both routes share ONE handler
|
|
997
1072
|
// so the alias can never drift from the canonical shape. The legacy name is
|
|
998
1073
|
// kept indefinitely (existing SessionStart hooks literally fetch /lessons).
|
|
999
|
-
|
|
1074
|
+
// #332: the optional `agent` query param is the circle-membership gate —
|
|
1075
|
+
// confidential lessons (born in the confidential reflection pool) serve to
|
|
1076
|
+
// members only; non-members get today's shape minus those rows.
|
|
1077
|
+
const learningsIndexHandler = (req, res) => {
|
|
1000
1078
|
if (!db) {
|
|
1001
1079
|
res.status(503).json({ error: "Server not initialized" });
|
|
1002
1080
|
return;
|
|
1003
1081
|
}
|
|
1004
1082
|
try {
|
|
1005
|
-
const
|
|
1083
|
+
const member = requestSeesConfidential(req.query.agent);
|
|
1084
|
+
const lessons = storage.getLessons(db, 30, null, { includeConfidential: member });
|
|
1006
1085
|
const totalCount = storage.countMemories(db);
|
|
1007
1086
|
// Project index
|
|
1008
1087
|
const projects = db
|
|
@@ -1039,7 +1118,11 @@ async function startServer(options = {}) {
|
|
|
1039
1118
|
res.status(503).json({ error: "Server not initialized" });
|
|
1040
1119
|
return;
|
|
1041
1120
|
}
|
|
1042
|
-
|
|
1121
|
+
// NOTE (#332): a client-declared `privacy` field is IGNORED here too —
|
|
1122
|
+
// /ingest is a write path, and the stamp is server-derived from
|
|
1123
|
+
// source_agent × the roster (a lying legacy client cannot smuggle itself
|
|
1124
|
+
// into — or out of — the confidential class).
|
|
1125
|
+
const { content, source_agent, source_agent_id, source_domain, source_machine, project, memory_type, source_session, session_date, corrects, supersedes } = req.body ?? {};
|
|
1043
1126
|
if (!content || typeof content !== "string") {
|
|
1044
1127
|
res.status(400).json({ error: "Missing or invalid 'content' field" });
|
|
1045
1128
|
return;
|
|
@@ -1096,9 +1179,9 @@ async function startServer(options = {}) {
|
|
|
1096
1179
|
// un-upgraded client folds here too.
|
|
1097
1180
|
project: canonProject(project),
|
|
1098
1181
|
memoryType: normalizedType ?? "experience",
|
|
1099
|
-
//
|
|
1100
|
-
//
|
|
1101
|
-
privacy: typeof
|
|
1182
|
+
// #332: server-derived stamp — same source_agent × roster rule as
|
|
1183
|
+
// /distill, so the legacy write path is not a stamping bypass.
|
|
1184
|
+
privacy: (0, classification_js_1.deriveIntakePrivacy)(typeof source_agent === "string" ? source_agent : null, confidentialRoster),
|
|
1102
1185
|
createdAt: session_date ? new Date(session_date).toISOString() : undefined,
|
|
1103
1186
|
});
|
|
1104
1187
|
if (explicitMark)
|
|
@@ -1144,9 +1227,12 @@ async function startServer(options = {}) {
|
|
|
1144
1227
|
// the #409 floor is unchanged in effect; the fence applies only when the
|
|
1145
1228
|
// request carries a project (applySearchRelevanceGate is identity
|
|
1146
1229
|
// otherwise).
|
|
1230
|
+
// #332: the optional `agent` param is the circle-membership gate —
|
|
1231
|
+
// absent/unknown = hard omit of confidential rows.
|
|
1232
|
+
const member = requestSeesConfidential(req.query.agent);
|
|
1147
1233
|
const minSimilarity = resolveSearchSimilarityFloor(req.query.minSimilarity);
|
|
1148
1234
|
try {
|
|
1149
|
-
let results = await retrieval.retrieve(db, embedder_js_1.embed, query, { limit, project });
|
|
1235
|
+
let results = await retrieval.retrieve(db, embedder_js_1.embed, query, { limit, project, includeConfidential: member });
|
|
1150
1236
|
results = applySearchRelevanceGate(results, { minSimilarity, project, crossProjectMinSimilarity: recallCrossProjectBar });
|
|
1151
1237
|
res.json({ results });
|
|
1152
1238
|
}
|
|
@@ -1191,10 +1277,15 @@ async function startServer(options = {}) {
|
|
|
1191
1277
|
// that searches unblended and touches no centroid state. Extracted so the
|
|
1192
1278
|
// exact behavior is unit-testable without HTTP (blendQueryVector
|
|
1193
1279
|
// precedent); this adapter stays thin.
|
|
1280
|
+
// #332: the optional body `agent` is the circle-membership gate — the
|
|
1281
|
+
// factory (built per request) carries it into retrieve() so the omit
|
|
1282
|
+
// happens at candidate-build time, not post-hoc. A client-declared
|
|
1283
|
+
// `privacy` body field remains ignored (0.16.x backcompat posture).
|
|
1194
1284
|
const factory = (0, recall_index_js_1.createRecallRetrieveFn)({
|
|
1195
1285
|
db,
|
|
1196
1286
|
registry: recallRegistry,
|
|
1197
1287
|
embedFn: embedder_js_1.embed,
|
|
1288
|
+
includeConfidential: requestSeesConfidential(req.body?.agent),
|
|
1198
1289
|
});
|
|
1199
1290
|
const r = await (0, recall_index_js_1.handleRecallIndex)({
|
|
1200
1291
|
db,
|
|
@@ -1221,8 +1312,11 @@ async function startServer(options = {}) {
|
|
|
1221
1312
|
return;
|
|
1222
1313
|
}
|
|
1223
1314
|
warnDeprecatedPrivacyParamIfPresent(req.query, "memory");
|
|
1315
|
+
// #332: the optional `agent` param is the circle-membership gate — a
|
|
1316
|
+
// confidential id fetched by a non-member answers 404 (before any
|
|
1317
|
+
// strengthening side effect, inside handleMemoryGet).
|
|
1224
1318
|
try {
|
|
1225
|
-
const r = (0, recall_index_js_1.handleMemoryGet)(db, { id: req.query.id }, { recordFetch: recall_precision_js_1.recordRecallFetch });
|
|
1319
|
+
const r = (0, recall_index_js_1.handleMemoryGet)(db, { id: req.query.id }, { recordFetch: recall_precision_js_1.recordRecallFetch }, { includeConfidential: requestSeesConfidential(req.query.agent) });
|
|
1226
1320
|
res.status(r.status).json(r.body);
|
|
1227
1321
|
}
|
|
1228
1322
|
catch (err) {
|
|
@@ -1241,10 +1335,12 @@ async function startServer(options = {}) {
|
|
|
1241
1335
|
// No hardcoded default: absent limit → the release-managed calibration
|
|
1242
1336
|
// default (#408 — was the recentLimit config key).
|
|
1243
1337
|
// 0.16.x: `privacy` query param accepted but ignored (vestigial column).
|
|
1338
|
+
// #332: the optional `agent` param is the circle-membership gate.
|
|
1244
1339
|
const limit = req.query.limit ? Number(req.query.limit) : undefined;
|
|
1245
1340
|
warnDeprecatedPrivacyParamIfPresent(req.query, "recent");
|
|
1341
|
+
const member = requestSeesConfidential(req.query.agent);
|
|
1246
1342
|
try {
|
|
1247
|
-
const results = retrieval.searchRecent(db, { project, limit });
|
|
1343
|
+
const results = retrieval.searchRecent(db, { project, limit, includeConfidential: member });
|
|
1248
1344
|
res.json({ results });
|
|
1249
1345
|
}
|
|
1250
1346
|
catch (err) {
|
|
@@ -1383,13 +1479,21 @@ async function startServer(options = {}) {
|
|
|
1383
1479
|
// attribution fields exist at EVERY exit incl. the 503 — capture-health
|
|
1384
1480
|
// accounting records held posts there too. Nothing else reads them before
|
|
1385
1481
|
// the guard, so semantics are unchanged.
|
|
1386
|
-
|
|
1482
|
+
// NOTE (#332): a client-declared `privacy` body field is IGNORED — the
|
|
1483
|
+
// classification stamp is server-derived below from source_agent × the
|
|
1484
|
+
// roster. The field is deliberately not even destructured.
|
|
1485
|
+
const { text, messages, source_agent, source_agent_id, source_domain, source_machine, project, session_id, segment_id, session_date } = req.body ?? {};
|
|
1387
1486
|
// #567: fold the wire project ONCE, right after the destructure — the
|
|
1388
1487
|
// queue enqueue, the sync distill prompt, and the insert opts below all
|
|
1389
1488
|
// carry the canonical value, so an un-upgraded client's raw label never
|
|
1390
1489
|
// lands as a stored variant (old npx clients, frozen plugin copies, and
|
|
1391
1490
|
// un-refreshed extensions all canonicalize for free at the server).
|
|
1392
1491
|
const canonProjectVal = canonProject(project);
|
|
1492
|
+
// #332: the classification stamp, derived ONCE per delivery from the
|
|
1493
|
+
// source agent × the boot-resolved roster (deterministic, by birthplace —
|
|
1494
|
+
// never a content judgment and never client-declared). Every downstream
|
|
1495
|
+
// landing (queue row, sync insert) carries THIS value.
|
|
1496
|
+
const derivedPrivacy = (0, classification_js_1.deriveIntakePrivacy)(typeof source_agent === "string" ? source_agent : null, confidentialRoster);
|
|
1393
1497
|
// #422 capture health: normalize the wire fields ONCE so every exit below
|
|
1394
1498
|
// records with a one-liner (recordDistillActivity re-sanitizes machine/
|
|
1395
1499
|
// agent — the builder only forwards + picks the byte count). bytes = the
|
|
@@ -1435,6 +1539,21 @@ async function startServer(options = {}) {
|
|
|
1435
1539
|
// the delivery without any LLM call and the nightly drain defers until
|
|
1436
1540
|
// an LLM is configured.
|
|
1437
1541
|
}
|
|
1542
|
+
// #332 sync-mode refusal: a CONFIDENTIAL delivery with no confidential
|
|
1543
|
+
// model answers 503 — the client holds its cursor and retries (the
|
|
1544
|
+
// strict-mode watermark precedent). It is NEVER distilled on the main
|
|
1545
|
+
// model. Queue mode stores it and the drain holds it instead (per-item
|
|
1546
|
+
// skip-and-continue); a fresh install's first delivery can never be
|
|
1547
|
+
// confidential (no roster configured ⇒ nothing derives confidential), so
|
|
1548
|
+
// the fresh-brain immediate-distill carve-out is untouched.
|
|
1549
|
+
if (derivedPrivacy === "confidential" && !queueMode && (!confidentialLlm || !confidentialLlmConfig)) {
|
|
1550
|
+
(0, capture_health_js_1.recordDistillActivity)(db, capEntry(0, "held"));
|
|
1551
|
+
res.status(503).json({
|
|
1552
|
+
error: "Confidential delivery held — no confidential model configured " +
|
|
1553
|
+
"(llmConfidentialBaseUrl/ApiKey). It will be retried; it is never distilled on the main model.",
|
|
1554
|
+
});
|
|
1555
|
+
return;
|
|
1556
|
+
}
|
|
1438
1557
|
// Resolve the conversation text from either the pre-denoised string or raw messages array.
|
|
1439
1558
|
// `fromTextBranch` is captured once so the redaction gate below uses the SAME
|
|
1440
1559
|
// discriminator as the resolution (avoids re-redacting the messages-derived
|
|
@@ -1447,8 +1566,12 @@ async function startServer(options = {}) {
|
|
|
1447
1566
|
}
|
|
1448
1567
|
else if (Array.isArray(messages) && messages.length > 0) {
|
|
1449
1568
|
// The messages branch already redacts via extractConversationText
|
|
1450
|
-
// (distiller.ts), which calls redact() as its final step.
|
|
1451
|
-
|
|
1569
|
+
// (distiller.ts), which calls redact() as its final step. #332: it
|
|
1570
|
+
// receives the SAME redaction config (the extended preset for
|
|
1571
|
+
// confidential deliveries) so both branches redact identically.
|
|
1572
|
+
conversationText = (0, distiller_js_1.extractConversationText)(messages, {
|
|
1573
|
+
extended: derivedPrivacy === "confidential",
|
|
1574
|
+
});
|
|
1452
1575
|
}
|
|
1453
1576
|
else {
|
|
1454
1577
|
res.status(400).json({ error: "Provide either 'text' (string) or 'messages' (array)" });
|
|
@@ -1464,8 +1587,14 @@ async function startServer(options = {}) {
|
|
|
1464
1587
|
// negative lookahead, and format-specific patterns don't match it). The
|
|
1465
1588
|
// messages branch is already covered above. Disable-resistance
|
|
1466
1589
|
// (hostedMode) is Phase 0b.
|
|
1590
|
+
// #332 redaction pilot: CONFIDENTIAL deliveries use the extended preset
|
|
1591
|
+
// (DEFAULT_PATTERNS + emails + phone numbers) — the material an
|
|
1592
|
+
// inner-circle agent captures is exactly the contact-identifier-rich
|
|
1593
|
+
// kind (#558). Standard deliveries keep today's set byte-identically.
|
|
1467
1594
|
if (fromTextBranch) {
|
|
1468
|
-
const { text: redacted, count } = (0, redact_js_1.redact)(conversationText
|
|
1595
|
+
const { text: redacted, count } = (0, redact_js_1.redact)(conversationText, {
|
|
1596
|
+
extended: derivedPrivacy === "confidential",
|
|
1597
|
+
});
|
|
1469
1598
|
if (count > 0) {
|
|
1470
1599
|
console.log(`[hicortex] Redacted ${count} secret(s) from /distill text`);
|
|
1471
1600
|
}
|
|
@@ -1531,7 +1660,9 @@ async function startServer(options = {}) {
|
|
|
1531
1660
|
session_id,
|
|
1532
1661
|
segment_id,
|
|
1533
1662
|
session_date,
|
|
1534
|
-
|
|
1663
|
+
// #332: the queue row carries the DERIVED stamp — the drain trusts it
|
|
1664
|
+
// (and routes the item to the matching model).
|
|
1665
|
+
privacy: derivedPrivacy,
|
|
1535
1666
|
});
|
|
1536
1667
|
(0, capture_health_js_1.recordDistillActivity)(db, capEntry(conversationText.length, duplicate ? "skipped" : "ok"));
|
|
1537
1668
|
if (duplicate) {
|
|
@@ -1549,20 +1680,27 @@ async function startServer(options = {}) {
|
|
|
1549
1680
|
});
|
|
1550
1681
|
return;
|
|
1551
1682
|
}
|
|
1552
|
-
// #529: from here on queueMode is false, so the no-LLM
|
|
1683
|
+
// #529: from here on queueMode is false, so the no-LLM guards above have
|
|
1553
1684
|
// already answered 503 in every path that reaches this line. Restated so
|
|
1554
1685
|
// the sync flow keeps its non-null llm/llmConfig typing unchanged.
|
|
1555
1686
|
if (!llm || !llmConfig) {
|
|
1556
1687
|
res.status(503).json({ error: "No LLM configured — run npx @gamaze/hicortex init. Session will be retried." });
|
|
1557
1688
|
return;
|
|
1558
1689
|
}
|
|
1690
|
+
// #332 per-pool client selection (the sync path's mirror of the drain's
|
|
1691
|
+
// selection): a confidential delivery distills on the CONFIDENTIAL client
|
|
1692
|
+
// — the refusal above guarantees it exists by here — and the probe gate +
|
|
1693
|
+
// chunk-size cache below use ITS endpoint. Standard deliveries are
|
|
1694
|
+
// byte-identical to today.
|
|
1695
|
+
const syncLlm = derivedPrivacy === "confidential" ? confidentialLlm : llm;
|
|
1696
|
+
const syncLlmConfig = derivedPrivacy === "confidential" ? confidentialLlmConfig : llmConfig;
|
|
1559
1697
|
// #337: readiness gate — cached minimal generation probe BEFORE
|
|
1560
1698
|
// detectChunkSize + distillSession, so a dead endpoint never even pays the
|
|
1561
1699
|
// chunk-size probe. Placed AFTER the dedup short-circuits (a duplicate
|
|
1562
1700
|
// costs nothing and must not trip the gate). On failure: 503 with the
|
|
1563
1701
|
// diagnosis — the capture client treats non-201/200 as transient and holds
|
|
1564
1702
|
// its cursor (capture.ts), so the segment is retried next run, never lost.
|
|
1565
|
-
if (!(await resolveDistillProbeGate(
|
|
1703
|
+
if (!(await resolveDistillProbeGate(syncLlm, syncLlmConfig))) {
|
|
1566
1704
|
(0, capture_health_js_1.recordDistillActivity)(db, capEntry(conversationText.length, "held"));
|
|
1567
1705
|
res.status(503).json({ error: "LLM endpoint not generating — session will be retried" });
|
|
1568
1706
|
return;
|
|
@@ -1570,9 +1708,9 @@ async function startServer(options = {}) {
|
|
|
1570
1708
|
// Cache detectChunkSize per endpoint so we probe at most once per server boot.
|
|
1571
1709
|
// numCtx is passed so chunk size derives from the request's ACTUAL context
|
|
1572
1710
|
// window (#231, #228) — the chunker and the request agree by construction.
|
|
1573
|
-
const cacheKey = `${
|
|
1711
|
+
const cacheKey = `${syncLlmConfig.provider}/${syncLlmConfig.model}@${syncLlmConfig.baseUrl}`;
|
|
1574
1712
|
if (!chunkSizeCache.has(cacheKey)) {
|
|
1575
|
-
chunkSizeCache.set(cacheKey, await (0, distiller_js_1.detectChunkSize)(
|
|
1713
|
+
chunkSizeCache.set(cacheKey, await (0, distiller_js_1.detectChunkSize)(syncLlmConfig.provider, syncLlmConfig.model, syncLlmConfig.baseUrl, syncLlmConfig.numCtx));
|
|
1576
1714
|
}
|
|
1577
1715
|
const chunkSize = chunkSizeCache.get(cacheKey);
|
|
1578
1716
|
const date = typeof session_date === "string" && session_date ? session_date : new Date().toISOString().slice(0, 10);
|
|
@@ -1597,7 +1735,10 @@ async function startServer(options = {}) {
|
|
|
1597
1735
|
// land in the caller's file-persisted nightly log (#156 audit trail); the
|
|
1598
1736
|
// server-side per-entry console.log in distillChunk stays as well.
|
|
1599
1737
|
const dropped = [];
|
|
1600
|
-
const entries = await (0, distiller_js_1.distillSession)(
|
|
1738
|
+
const entries = await (0, distiller_js_1.distillSession)(
|
|
1739
|
+
// #332: the per-pool selection — syncLlm is the confidential client
|
|
1740
|
+
// for confidential deliveries (guaranteed non-null by the refusal).
|
|
1741
|
+
syncLlm, conversationText, canonProjectVal ?? "unknown", date, chunkSize, dropped, (u) => {
|
|
1601
1742
|
distillUsage.prompt += u.prompt_tokens ?? 0;
|
|
1602
1743
|
distillUsage.completion += u.completion_tokens ?? 0;
|
|
1603
1744
|
distillUsage.total += u.total_tokens ?? 0;
|
|
@@ -1649,9 +1790,9 @@ async function startServer(options = {}) {
|
|
|
1649
1790
|
// distiller.ts. Pre-#216 distiller output (no tag) defaults to
|
|
1650
1791
|
// experience in the parser, so this is backward compatible.
|
|
1651
1792
|
memoryType,
|
|
1652
|
-
//
|
|
1653
|
-
//
|
|
1654
|
-
privacy:
|
|
1793
|
+
// #332: the DERIVED stamp — same value the queue branch would
|
|
1794
|
+
// have carried (client-declared privacy never reaches here).
|
|
1795
|
+
privacy: derivedPrivacy,
|
|
1655
1796
|
createdAt,
|
|
1656
1797
|
}));
|
|
1657
1798
|
}
|
|
@@ -1696,7 +1837,11 @@ async function startServer(options = {}) {
|
|
|
1696
1837
|
res.status(503).json({ error: "Server not initialized" });
|
|
1697
1838
|
return;
|
|
1698
1839
|
}
|
|
1699
|
-
|
|
1840
|
+
// NOTE (#332): `privacy` is no longer a writable field — classification is
|
|
1841
|
+
// server-derived at intake and changed only by the owner's
|
|
1842
|
+
// `hicortex backfill-privacy`. A body privacy field is ignored (kept out
|
|
1843
|
+
// of the destructure so the intent is structural).
|
|
1844
|
+
const { id, content, project, memory_type } = req.body ?? {};
|
|
1700
1845
|
if (!id || typeof id !== "string") {
|
|
1701
1846
|
res.status(400).json({ error: "Missing or invalid 'id' field" });
|
|
1702
1847
|
return;
|
|
@@ -1723,8 +1868,6 @@ async function startServer(options = {}) {
|
|
|
1723
1868
|
// label is junk), never a stored variant.
|
|
1724
1869
|
if (project !== undefined)
|
|
1725
1870
|
fields.project = (0, project_canonicalize_js_1.canonicalizeProject)(project, projectAliases);
|
|
1726
|
-
if (privacy !== undefined)
|
|
1727
|
-
fields.privacy = privacy;
|
|
1728
1871
|
// Validate + normalize memory_type BEFORE adding to `fields` so the
|
|
1729
1872
|
// empty-fields check below correctly counts a memory_type-only update.
|
|
1730
1873
|
const validTypes = type_labels_js_1.ACCEPTED_MEMORY_TYPES;
|
|
@@ -1901,6 +2044,17 @@ async function startServer(options = {}) {
|
|
|
1901
2044
|
const resultLimit = rawLimit && Number.isFinite(rawLimit) && rawLimit >= 1 ? Math.floor(rawLimit) : 10;
|
|
1902
2045
|
const filterDomain = typeof req.query.domain === "string" && req.query.domain ? req.query.domain : undefined;
|
|
1903
2046
|
const filterRelationship = typeof req.query.relationship === "string" && req.query.relationship ? req.query.relationship : undefined;
|
|
2047
|
+
// #332: the optional `agent` param gates neighbors/hubs/path (the
|
|
2048
|
+
// content-bearing ops). op=export stays UNGATED — it is the /viz owner
|
|
2049
|
+
// surface (owner ruling: dashboard/viz not gated in this build; a
|
|
2050
|
+
// show-confidential toggle is a separate later item).
|
|
2051
|
+
const member = requestSeesConfidential(req.query.agent);
|
|
2052
|
+
// A confidential endpoint/center id is invisible to non-members — same
|
|
2053
|
+
// 404 contract as GET /memory (existence is not revealed).
|
|
2054
|
+
const visibleId = (id) => {
|
|
2055
|
+
const row = db.prepare("SELECT privacy FROM memories WHERE id = ?").get(id);
|
|
2056
|
+
return member || row?.privacy !== "confidential";
|
|
2057
|
+
};
|
|
1904
2058
|
try {
|
|
1905
2059
|
if (op === "neighbors") {
|
|
1906
2060
|
const idParam = typeof req.query.id === "string" ? req.query.id : "";
|
|
@@ -1909,16 +2063,16 @@ async function startServer(options = {}) {
|
|
|
1909
2063
|
return;
|
|
1910
2064
|
}
|
|
1911
2065
|
const resolvedId = resolveMemoryId(db, idParam);
|
|
1912
|
-
if (!resolvedId) {
|
|
2066
|
+
if (!resolvedId || !visibleId(resolvedId)) {
|
|
1913
2067
|
res.status(404).json({ error: `Memory not found: ${idParam}` });
|
|
1914
2068
|
return;
|
|
1915
2069
|
}
|
|
1916
|
-
const neighbors = (0, graph_js_1.getNeighbors)(db, resolvedId, resultLimit, filterRelationship);
|
|
2070
|
+
const neighbors = (0, graph_js_1.getNeighbors)(db, resolvedId, resultLimit, filterRelationship, { includeConfidential: member });
|
|
1917
2071
|
res.json({ results: neighbors });
|
|
1918
2072
|
return;
|
|
1919
2073
|
}
|
|
1920
2074
|
if (op === "hubs") {
|
|
1921
|
-
let hubs = (0, graph_js_1.detectHubs)(db);
|
|
2075
|
+
let hubs = (0, graph_js_1.detectHubs)(db, 2, 3, { includeConfidential: member });
|
|
1922
2076
|
if (filterDomain) {
|
|
1923
2077
|
hubs = hubs.filter((h) => h.domain === filterDomain || h.project === filterDomain);
|
|
1924
2078
|
}
|
|
@@ -1934,11 +2088,11 @@ async function startServer(options = {}) {
|
|
|
1934
2088
|
}
|
|
1935
2089
|
const fromId = resolveMemoryId(db, fromParam);
|
|
1936
2090
|
const toId = resolveMemoryId(db, toParam);
|
|
1937
|
-
if (!fromId || !toId) {
|
|
2091
|
+
if (!fromId || !toId || !visibleId(fromId) || !visibleId(toId)) {
|
|
1938
2092
|
res.status(404).json({ error: "One or both memory IDs not found" });
|
|
1939
2093
|
return;
|
|
1940
2094
|
}
|
|
1941
|
-
const path = (0, graph_js_1.shortestPath)(db, fromId, toId);
|
|
2095
|
+
const path = (0, graph_js_1.shortestPath)(db, fromId, toId, 5, { includeConfidential: member });
|
|
1942
2096
|
res.json({ path: path ?? null });
|
|
1943
2097
|
return;
|
|
1944
2098
|
}
|
package/dist/nightly.js
CHANGED
|
@@ -61,7 +61,7 @@ catch { }
|
|
|
61
61
|
const db_js_1 = require("./db.js");
|
|
62
62
|
const config_read_js_1 = require("./config-read.js");
|
|
63
63
|
const calibration_js_1 = require("./calibration.js");
|
|
64
|
-
const
|
|
64
|
+
const classification_js_1 = require("./classification.js");
|
|
65
65
|
const embedder_js_1 = require("./embedder.js");
|
|
66
66
|
const storage = __importStar(require("./storage.js"));
|
|
67
67
|
const consolidate_js_1 = require("./consolidate.js");
|
|
@@ -573,12 +573,28 @@ async function runNightly(options = {}) {
|
|
|
573
573
|
// is handled by the running daemon over /distill — no local distill LLM needed.
|
|
574
574
|
// No LLM → capture loop still runs (sessions POST to /distill, which will 503
|
|
575
575
|
// transient-fail and hold the watermark), but consolidation is skipped.
|
|
576
|
-
|
|
577
|
-
|
|
576
|
+
// #332: resolveLlmPair resolves BOTH clients at this funnel — the main
|
|
577
|
+
// model plus the confidential one (llmConfidential* config /
|
|
578
|
+
// HICORTEX_LLM_CONFIDENTIAL_* env). The confidential client serves the
|
|
579
|
+
// drain's confidential items and (from the pool-aware stages) every
|
|
580
|
+
// consolidation touch of confidential text; absent = those hold/skip,
|
|
581
|
+
// never fall back.
|
|
582
|
+
const resolvedPair = (0, classification_js_1.resolveLlmPair)(savedConfig);
|
|
583
|
+
if (resolvedPair.reason === "claude_binary_missing") {
|
|
578
584
|
console.warn("[hicortex] claude-cli configured but binary not found — consolidation skipped");
|
|
579
585
|
}
|
|
580
|
-
const llmConfig =
|
|
581
|
-
const llm =
|
|
586
|
+
const llmConfig = resolvedPair.standardConfig;
|
|
587
|
+
const llm = resolvedPair.pair?.standard ?? null;
|
|
588
|
+
const confidentialLlm = resolvedPair.pair?.confidential ?? null;
|
|
589
|
+
const confidentialLlmConfig = resolvedPair.confidentialConfig;
|
|
590
|
+
// #332: the ONE loud warning when the circle is active without the
|
|
591
|
+
// confidential model (daemon boot mirrors this).
|
|
592
|
+
(0, classification_js_1.warnIfCircleUnconfigured)({
|
|
593
|
+
roster: (0, classification_js_1.resolveConfidentialAgents)(savedConfig).roster,
|
|
594
|
+
confidentialLlm: confidentialLlm ?? confidentialLlmConfig,
|
|
595
|
+
confidentialRows: db.prepare("SELECT COUNT(*) AS c FROM memories WHERE privacy = 'confidential'").get().c,
|
|
596
|
+
queueConfidential: db.prepare("SELECT COUNT(*) AS c FROM distill_queue WHERE privacy = 'confidential'").get().c,
|
|
597
|
+
});
|
|
582
598
|
// Steps 1+2: single-flight capture. The lock guards ONLY the capture phase
|
|
583
599
|
// (fix 10). We acquire it BEFORE reading the cursor store so a run that
|
|
584
600
|
// waited out another cannot act on a stale snapshot and clobber its cursor
|
|
@@ -725,6 +741,10 @@ async function runNightly(options = {}) {
|
|
|
725
741
|
const drainReport = await (0, distill_queue_js_1.drainDistillQueue)(db, {
|
|
726
742
|
llm,
|
|
727
743
|
llmConfig,
|
|
744
|
+
// #332: the confidential client — confidential queue items distill on
|
|
745
|
+
// it; without it they hold (per-item skip-and-continue).
|
|
746
|
+
confidentialLlm,
|
|
747
|
+
confidentialLlmConfig,
|
|
728
748
|
embed: embedder_js_1.embed,
|
|
729
749
|
budgetExceeded: () => (0, token_budget_js_1.isTokenBudgetExceeded)(stateDir),
|
|
730
750
|
deadline,
|
|
@@ -890,7 +910,11 @@ async function runNightly(options = {}) {
|
|
|
890
910
|
},
|
|
891
911
|
// #405: the ONE run-wide deadline — capture and every
|
|
892
912
|
// consolidation stage check this same handle.
|
|
893
|
-
deadline
|
|
913
|
+
deadline,
|
|
914
|
+
// #332: the confidential client — every pool-aware stage
|
|
915
|
+
// (importance batches, reflection, domain classification,
|
|
916
|
+
// reconsolidation) routes confidential text here; absent ⇒ hold.
|
|
917
|
+
confidentialLlm);
|
|
894
918
|
console.log(`[hicortex] Consolidation ${report.status} in ${report.elapsed_seconds}s` +
|
|
895
919
|
(report.stages.reflection ? ` (${report.stages.reflection.lessons_generated} lessons)` : ""));
|
|
896
920
|
consolidationStatus = report.status;
|
|
@@ -1230,7 +1254,9 @@ async function runNightly(options = {}) {
|
|
|
1230
1254
|
mode: "server",
|
|
1231
1255
|
agent: agentType,
|
|
1232
1256
|
mem: storage.countMemories(db),
|
|
1233
|
-
|
|
1257
|
+
// #332: telemetry counts the whole store (server-internal metric —
|
|
1258
|
+
// not an agent-facing surface, so no membership gate).
|
|
1259
|
+
lessons: storage.getLessons(db, 365, null, { includeConfidential: true }).length,
|
|
1234
1260
|
lessonsGenerated,
|
|
1235
1261
|
consolidation: consolidationStatus,
|
|
1236
1262
|
// #246: total tokens consumed by this run's consolidation (absent on
|
package/dist/recall-index.d.ts
CHANGED
|
@@ -184,11 +184,11 @@ export declare function passesRelevanceGate(r: MemorySearchResult, minSimilarity
|
|
|
184
184
|
* silently would leak out-of-scope memory titles into the injected index.
|
|
185
185
|
*
|
|
186
186
|
* #203: `project` and `mission_domains` are SOFT affinity signals in
|
|
187
|
-
* retrieval (zero-boost neutral, never a filter / penalty).
|
|
188
|
-
*
|
|
189
|
-
*
|
|
190
|
-
*
|
|
191
|
-
*
|
|
187
|
+
* retrieval (zero-boost neutral, never a filter / penalty). #332: the old
|
|
188
|
+
* `privacy` body field stays ACCEPTED-but-IGNORED (backward compat) — the
|
|
189
|
+
* classification gate rides the `agent` body field instead: the route
|
|
190
|
+
* adapter checks it against the boot roster and builds the retrieve closure
|
|
191
|
+
* with includeConfidential accordingly. */
|
|
192
192
|
export interface RecallFilters {
|
|
193
193
|
project?: string;
|
|
194
194
|
/** #203: Hermes mission domains (declared in plugin config). Soft domain
|
|
@@ -281,6 +281,13 @@ export declare function createRecallRetrieveFn(deps: {
|
|
|
281
281
|
embedFn: (text: string) => Promise<Float32Array>;
|
|
282
282
|
/** FTS resolution override (tests). Defaults to storage.searchFts. */
|
|
283
283
|
ftsFn?: typeof storage.searchFts;
|
|
284
|
+
/**
|
|
285
|
+
* #332 classification gate: TRUE only when the request's `agent` is a
|
|
286
|
+
* circle member (the route adapter computes membership per request — the
|
|
287
|
+
* factory is built per request). Default false = hard omit of confidential
|
|
288
|
+
* rows inside retrieve().
|
|
289
|
+
*/
|
|
290
|
+
includeConfidential?: boolean;
|
|
284
291
|
}): RecallRetrieveFactory;
|
|
285
292
|
/** Normalize a request-supplied string-list param: array of strings or a CSV
|
|
286
293
|
* string → string[] | undefined. Anything else (or an empty result) means
|
|
@@ -309,13 +316,16 @@ export interface MemoryGetDeps {
|
|
|
309
316
|
* citation ids agents are taught must work here like on /update, /delete.
|
|
310
317
|
* - A successful fetch is real use: access_count + 1 (strengthen).
|
|
311
318
|
*
|
|
312
|
-
*
|
|
313
|
-
*
|
|
314
|
-
*
|
|
319
|
+
* #332: `opts.includeConfidential` (default false) is the classification gate
|
|
320
|
+
* — a confidential memory fetched by a non-member answers 404 BEFORE any
|
|
321
|
+
* side effect (no strengthen, no precision event: existence is not revealed).
|
|
322
|
+
* Members (the adapter passes true) fetch both pools normally.
|
|
315
323
|
*/
|
|
316
324
|
export declare function handleMemoryGet(db: Database.Database, query: {
|
|
317
325
|
id?: unknown;
|
|
318
|
-
}, deps?: MemoryGetDeps
|
|
326
|
+
}, deps?: MemoryGetDeps, opts?: {
|
|
327
|
+
includeConfidential?: boolean;
|
|
328
|
+
}): RecallIndexResult;
|
|
319
329
|
/**
|
|
320
330
|
* MCP `hicortex_get` presentation: handleMemoryGet's result framed as the
|
|
321
331
|
* text block the MCP tool returns (provenance header + the SHARED citation +
|