@gamaze/hicortex 0.26.3 → 0.27.1
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 +21 -13
- package/assets/dashboard.html +95 -3
- package/dist/backfill-privacy.d.ts +109 -0
- package/dist/backfill-privacy.js +304 -0
- package/dist/capture.d.ts +60 -0
- package/dist/capture.js +90 -1
- package/dist/classification.d.ts +315 -0
- package/dist/classification.js +525 -0
- package/dist/classify-domains.js +24 -7
- package/dist/cli.js +80 -0
- package/dist/cluster.d.ts +15 -8
- package/dist/cluster.js +10 -3
- package/dist/confidential-marker.d.ts +103 -0
- package/dist/confidential-marker.js +285 -0
- package/dist/consolidate.d.ts +65 -5
- package/dist/consolidate.js +275 -48
- package/dist/dashboard.d.ts +32 -0
- package/dist/dashboard.js +33 -0
- package/dist/db.js +49 -1
- package/dist/dedup.d.ts +5 -3
- package/dist/dedup.js +26 -12
- package/dist/distill-queue.d.ts +34 -1
- package/dist/distill-queue.js +57 -10
- package/dist/graph.d.ts +28 -3
- package/dist/graph.js +46 -4
- package/dist/hermes-transcript-reader.js +5 -0
- package/dist/init.d.ts +18 -9
- package/dist/init.js +111 -81
- package/dist/marker-key-api.d.ts +79 -0
- package/dist/marker-key-api.js +96 -0
- package/dist/mcp-server.js +317 -32
- package/dist/nightly.js +36 -7
- package/dist/opencode-transcript-reader.js +3 -0
- package/dist/pi-transcript-reader.js +3 -0
- package/dist/prompts.d.ts +33 -1
- package/dist/prompts.js +37 -2
- 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 +43 -11
- package/dist/transcript-reader.d.ts +10 -0
- package/dist/transcript-reader.js +13 -0
- package/dist/type-classify.js +22 -7
- package/dist/types.d.ts +117 -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/dashboard.js
CHANGED
|
@@ -28,6 +28,7 @@ exports.computeDashboardMetrics = computeDashboardMetrics;
|
|
|
28
28
|
exports.computeStageCounts = computeStageCounts;
|
|
29
29
|
exports.writeSnapshot = writeSnapshot;
|
|
30
30
|
exports.backfillSnapshots = backfillSnapshots;
|
|
31
|
+
exports.readAgentCircle = readAgentCircle;
|
|
31
32
|
exports.handleDashboardData = handleDashboardData;
|
|
32
33
|
exports.dashboardDataHandler = dashboardDataHandler;
|
|
33
34
|
exports.accountHandler = accountHandler;
|
|
@@ -53,6 +54,7 @@ const recall_precision_js_1 = require("./recall-precision.js");
|
|
|
53
54
|
const quality_scoreboard_js_1 = require("./quality-scoreboard.js");
|
|
54
55
|
const distill_queue_js_1 = require("./distill-queue.js");
|
|
55
56
|
const capture_pause_js_1 = require("./capture-pause.js");
|
|
57
|
+
const classification_js_1 = require("./classification.js");
|
|
56
58
|
const state_js_1 = require("./state.js");
|
|
57
59
|
const retrieval_js_1 = require("./retrieval.js");
|
|
58
60
|
const stages_js_1 = require("./stages.js");
|
|
@@ -433,6 +435,34 @@ function renderIndexLine(row, maxLen) {
|
|
|
433
435
|
}, maxLen);
|
|
434
436
|
return { id: row.id, line, created_at: row.created_at };
|
|
435
437
|
}
|
|
438
|
+
/**
|
|
439
|
+
* #601 — compute fleet.circle: the sanitized roster plus the OBSERVED
|
|
440
|
+
* source_agent values that match it, each with its confidential memory count.
|
|
441
|
+
* Reuses the intake path's own decision core (resolveConfidentialAgents +
|
|
442
|
+
* isConfidentialSourceAgent from classification.ts — one id namespace, one
|
|
443
|
+
* match rule; no second matcher to drift). One GROUP BY over memories:
|
|
444
|
+
* membership is observed-and-rostered (a rostered agent seen with only
|
|
445
|
+
* standard rows is a member at 0), the value is the confidential row count.
|
|
446
|
+
* Pure: takes a db + config, returns the block; no side effects.
|
|
447
|
+
*/
|
|
448
|
+
function readAgentCircle(db, config) {
|
|
449
|
+
const { roster } = (0, classification_js_1.resolveConfidentialAgents)(config);
|
|
450
|
+
if (roster.length === 0)
|
|
451
|
+
return { roster: [], members: {} };
|
|
452
|
+
const rows = db
|
|
453
|
+
.prepare(`SELECT source_agent AS agent,
|
|
454
|
+
COUNT(CASE WHEN privacy = 'confidential' THEN 1 END) AS conf
|
|
455
|
+
FROM memories
|
|
456
|
+
WHERE source_agent IS NOT NULL
|
|
457
|
+
GROUP BY source_agent`)
|
|
458
|
+
.all();
|
|
459
|
+
const members = {};
|
|
460
|
+
for (const r of rows) {
|
|
461
|
+
if ((0, classification_js_1.isConfidentialSourceAgent)(r.agent, roster))
|
|
462
|
+
members[r.agent] = r.conf;
|
|
463
|
+
}
|
|
464
|
+
return { roster, members };
|
|
465
|
+
}
|
|
436
466
|
/**
|
|
437
467
|
* The pure data handler for GET /dashboard/data. Reads query params
|
|
438
468
|
* (`range`, `date`, `digestLimit`) off the request, returns the DashboardData
|
|
@@ -622,9 +652,12 @@ function handleDashboardData(db, query, config) {
|
|
|
622
652
|
},
|
|
623
653
|
// #423 phase 3: pauses + presence in one block — one source of truth
|
|
624
654
|
// for the rail's dots, toggles and the capture card's PAUSED badges.
|
|
655
|
+
// #601: circle rides the same block — visibility only (roster +
|
|
656
|
+
// observed members + counts), never a gate.
|
|
625
657
|
fleet: {
|
|
626
658
|
pauses: (0, capture_pause_js_1.listCapturePauses)(db),
|
|
627
659
|
last_seen: (0, capture_pause_js_1.readFleetLastSeen)(db),
|
|
660
|
+
circle: readAgentCircle(db, config),
|
|
628
661
|
},
|
|
629
662
|
digest,
|
|
630
663
|
},
|
package/dist/db.js
CHANGED
|
@@ -104,7 +104,11 @@ CREATE TABLE IF NOT EXISTS memories (
|
|
|
104
104
|
source_agent TEXT DEFAULT 'default',
|
|
105
105
|
source_session TEXT,
|
|
106
106
|
project TEXT,
|
|
107
|
-
|
|
107
|
+
-- #332: the two-level memory classification ('standard' | 'confidential').
|
|
108
|
+
-- Server-derived at intake from source_agent × the confidentialAgents
|
|
109
|
+
-- roster — never client-declared. The fresh-schema default flipped from the
|
|
110
|
+
-- pre-0.16 'WORK' (migration v27 maps every legacy value/NULL → standard).
|
|
111
|
+
privacy TEXT DEFAULT 'standard',
|
|
108
112
|
memory_type TEXT DEFAULT 'experience',
|
|
109
113
|
updated_at TIMESTAMP
|
|
110
114
|
);
|
|
@@ -880,6 +884,50 @@ const MIGRATIONS = [
|
|
|
880
884
|
db.exec("CREATE INDEX IF NOT EXISTS idx_recall_verdicts_push_memory ON recall_verdicts(push_id, memory_id)");
|
|
881
885
|
},
|
|
882
886
|
},
|
|
887
|
+
{
|
|
888
|
+
version: 27,
|
|
889
|
+
name: "privacy_standard",
|
|
890
|
+
up: (db) => {
|
|
891
|
+
// #332 — the privacy column becomes the two-level classification carrier
|
|
892
|
+
// ('standard' | 'confidential'). Production rows carry BOTH legacy
|
|
893
|
+
// populations: 'WORK' (the pre-0.16 schema default) and NULL (modern
|
|
894
|
+
// inserts, which passed `privacy ?? null`). Both map to 'standard' — the
|
|
895
|
+
// fail-closed default class; 'confidential' only ever exists once the
|
|
896
|
+
// server derives it at intake (source_agent × the confidentialAgents
|
|
897
|
+
// roster) or the operator backfills it. Any other legacy value ('',
|
|
898
|
+
// 'PERSONAL', …) maps the same way. The distill_queue rows are normalized
|
|
899
|
+
// with the SAME predicate so a pre-upgrade queued segment distills with
|
|
900
|
+
// the same stamp the migration just gave its already-stored siblings.
|
|
901
|
+
// Idempotent: re-running rewrites the same 'standard' onto the same rows.
|
|
902
|
+
db.exec(`UPDATE memories SET privacy = 'standard'
|
|
903
|
+
WHERE privacy IS NULL OR privacy NOT IN ('standard', 'confidential')`);
|
|
904
|
+
db.exec(`UPDATE distill_queue SET privacy = 'standard'
|
|
905
|
+
WHERE privacy IS NULL OR privacy NOT IN ('standard', 'confidential')`);
|
|
906
|
+
},
|
|
907
|
+
},
|
|
908
|
+
{
|
|
909
|
+
version: 28,
|
|
910
|
+
name: "workspace_path",
|
|
911
|
+
up: (db) => {
|
|
912
|
+
// #609 — confidential birthplace by workspace. Both tables gain the
|
|
913
|
+
// delivery's workspace path (the wire `workspace_path` field): the
|
|
914
|
+
// intake matcher stamps confidential when it matches a
|
|
915
|
+
// `confidentialPaths` pattern, and `hicortex backfill-privacy` re-plans
|
|
916
|
+
// retroactively from the stored value — impossible without persisting
|
|
917
|
+
// it. Metadata in the same class as the already-stored `project`
|
|
918
|
+
// (matched/attributed, never distilled into prompt text). Pre-v28 rows
|
|
919
|
+
// have no path by construction and stay NULL — there is deliberately no
|
|
920
|
+
// client re-scan to recover them (the spec's non-goal); their routes to
|
|
921
|
+
// confidential remain the agent-roster backfill or explicit acceptance.
|
|
922
|
+
// Idempotent: hasColumn-guarded ALTER (the v15/v26 pattern).
|
|
923
|
+
if (!hasColumn(db, "memories", "workspace_path")) {
|
|
924
|
+
db.exec("ALTER TABLE memories ADD COLUMN workspace_path TEXT");
|
|
925
|
+
}
|
|
926
|
+
if (!hasColumn(db, "distill_queue", "workspace_path")) {
|
|
927
|
+
db.exec("ALTER TABLE distill_queue ADD COLUMN workspace_path TEXT");
|
|
928
|
+
}
|
|
929
|
+
},
|
|
930
|
+
},
|
|
883
931
|
];
|
|
884
932
|
/**
|
|
885
933
|
* Run all pending migrations against the database.
|
package/dist/dedup.d.ts
CHANGED
|
@@ -223,7 +223,7 @@ export type MergeMemoryIdsResult = {
|
|
|
223
223
|
linksRepointed: number;
|
|
224
224
|
} | {
|
|
225
225
|
ok: false;
|
|
226
|
-
reason: "project_mismatch" | "conflict_linked" | "no_members";
|
|
226
|
+
reason: "project_mismatch" | "classification_mismatch" | "conflict_linked" | "no_members";
|
|
227
227
|
};
|
|
228
228
|
/**
|
|
229
229
|
* Merge an explicit set of memories (the judged-pair phase of #392: the
|
|
@@ -231,8 +231,10 @@ export type MergeMemoryIdsResult = {
|
|
|
231
231
|
* through THIS function so the merge math stays single-definition). Loads the
|
|
232
232
|
* LIVE rows at apply time — members that vanished or were absorbed between
|
|
233
233
|
* verdict and apply are dropped defensively; a project disagreement refuses
|
|
234
|
-
* the merge (both memories stay live — the
|
|
235
|
-
*
|
|
234
|
+
* the merge (both memories stay live — the #206 metadata rail); a
|
|
235
|
+
* CLASSIFICATION disagreement refuses it the same way (#332: the pools never
|
|
236
|
+
* cross — a confidential row never blends into a standard canonical or vice
|
|
237
|
+
* versa); a conflicts-linked pair refuses it exactly the same way
|
|
236
238
|
* (#393 guard-C). One transaction for the whole set.
|
|
237
239
|
*/
|
|
238
240
|
export declare function mergeMemoryIds(db: Database.Database, ids: string[]): MergeMemoryIdsResult;
|
package/dist/dedup.js
CHANGED
|
@@ -287,9 +287,12 @@ function planDedup(db, threshold) {
|
|
|
287
287
|
continue;
|
|
288
288
|
}
|
|
289
289
|
const mismatch = (0, cluster_js_1.clusterMetadataMismatch)(members);
|
|
290
|
-
// #206 decision 2:
|
|
291
|
-
//
|
|
292
|
-
|
|
290
|
+
// #206 decision 2: the source_agent rail was removed (cross-agent
|
|
291
|
+
// clusters merge). Project stayed the only METADATA rail until #332 added
|
|
292
|
+
// the classification rail — a cluster mixing standard and confidential
|
|
293
|
+
// rows is skipped, never blended (either skip reason keeps every member
|
|
294
|
+
// live; the pair re-detects structurally).
|
|
295
|
+
if (mismatch.projectMismatch || mismatch.classificationMismatch) {
|
|
293
296
|
mismatchSkipped.push({ size: members.length, memberIds: members.map((m) => m.id), mismatch });
|
|
294
297
|
continue;
|
|
295
298
|
}
|
|
@@ -392,8 +395,10 @@ function mergeCluster(db, canonical, losers, injectFailure) {
|
|
|
392
395
|
* through THIS function so the merge math stays single-definition). Loads the
|
|
393
396
|
* LIVE rows at apply time — members that vanished or were absorbed between
|
|
394
397
|
* verdict and apply are dropped defensively; a project disagreement refuses
|
|
395
|
-
* the merge (both memories stay live — the
|
|
396
|
-
*
|
|
398
|
+
* the merge (both memories stay live — the #206 metadata rail); a
|
|
399
|
+
* CLASSIFICATION disagreement refuses it the same way (#332: the pools never
|
|
400
|
+
* cross — a confidential row never blends into a standard canonical or vice
|
|
401
|
+
* versa); a conflicts-linked pair refuses it exactly the same way
|
|
397
402
|
* (#393 guard-C). One transaction for the whole set.
|
|
398
403
|
*/
|
|
399
404
|
function mergeMemoryIds(db, ids) {
|
|
@@ -411,6 +416,9 @@ function mergeMemoryIds(db, ids) {
|
|
|
411
416
|
if (mismatch.projectMismatch) {
|
|
412
417
|
return { ok: false, reason: "project_mismatch" };
|
|
413
418
|
}
|
|
419
|
+
if (mismatch.classificationMismatch) {
|
|
420
|
+
return { ok: false, reason: "classification_mismatch" };
|
|
421
|
+
}
|
|
414
422
|
const { canonical, losers } = pickCanonical(members);
|
|
415
423
|
const tx = db.transaction(() => mergeCluster(db, canonical, losers));
|
|
416
424
|
const plan = tx();
|
|
@@ -471,7 +479,10 @@ async function runDeterministicMergeZone(db, opts = {}) {
|
|
|
471
479
|
merged_clusters: 0,
|
|
472
480
|
losers_merged: 0,
|
|
473
481
|
links_repointed: 0,
|
|
474
|
-
|
|
482
|
+
// #332: mismatch skips split by rail — project vs classification (a
|
|
483
|
+
// cluster can only trip one: either skip keeps every member live).
|
|
484
|
+
skipped_project_mismatch: plan.mismatchSkipped.filter((c) => c.mismatch.projectMismatch).length,
|
|
485
|
+
skipped_classification_mismatch: plan.mismatchSkipped.filter((c) => c.mismatch.classificationMismatch).length,
|
|
475
486
|
skipped_conflict: plan.conflictSkipped.length,
|
|
476
487
|
capped: 0,
|
|
477
488
|
failed: 0,
|
|
@@ -576,6 +587,7 @@ async function runDeterministicMergeZone(db, opts = {}) {
|
|
|
576
587
|
console.log(`[hicortex] deterministic-merge zone (>= ${threshold}): ${report.merged_clusters}/${plan.mergePlans.length} ` +
|
|
577
588
|
`cluster(s) merged, ${report.losers_merged} loser(s) absorbed, ` +
|
|
578
589
|
`${report.skipped_project_mismatch} skipped (project mismatch), ` +
|
|
590
|
+
`${report.skipped_classification_mismatch ?? 0} skipped (classification mismatch, #332), ` +
|
|
579
591
|
`${report.skipped_conflict} skipped (conflict-flagged)` +
|
|
580
592
|
(report.capped > 0 ? `, ${report.capped} deferred (run deadline)` : "") +
|
|
581
593
|
(report.failed > 0 ? `, ${report.failed} FAILED` : ""));
|
|
@@ -594,7 +606,8 @@ async function runDeterministicMergeZone(db, opts = {}) {
|
|
|
594
606
|
return {
|
|
595
607
|
threshold, clusters_found: 0, mergeable_clusters: 0,
|
|
596
608
|
merged_clusters: 0, losers_merged: 0, links_repointed: 0,
|
|
597
|
-
skipped_project_mismatch: 0,
|
|
609
|
+
skipped_project_mismatch: 0, skipped_classification_mismatch: 0,
|
|
610
|
+
skipped_conflict: 0, capped: 0, failed: 0,
|
|
598
611
|
};
|
|
599
612
|
}
|
|
600
613
|
}
|
|
@@ -658,7 +671,7 @@ async function runDedup(options = {}) {
|
|
|
658
671
|
linksSkippedExisting: linksSkippedExistingPreview,
|
|
659
672
|
};
|
|
660
673
|
console.log(`[hicortex] dedup: ${plan.clusterCount} cluster(s) found, ${mergeable.length} mergeable ` +
|
|
661
|
-
`(${plannedMerges} row(s) would be absorbed), ${plan.mismatchSkipped.length} skipped (project mismatch), ` +
|
|
674
|
+
`(${plannedMerges} row(s) would be absorbed), ${plan.mismatchSkipped.length} skipped (project/classification mismatch), ` +
|
|
662
675
|
`${plan.conflictSkipped.length} skipped (conflict-flagged), ` +
|
|
663
676
|
`${linksSkippedExistingPreview} link(s) would be skipped (existing edge on the canonical)`);
|
|
664
677
|
if (!apply) {
|
|
@@ -669,10 +682,11 @@ async function runDedup(options = {}) {
|
|
|
669
682
|
`${c.linksSkippedSelfLink} skipped (self-link)`);
|
|
670
683
|
}
|
|
671
684
|
for (const c of plan.mismatchSkipped) {
|
|
672
|
-
// #206 decision 2
|
|
673
|
-
//
|
|
674
|
-
// run sizes
|
|
675
|
-
|
|
685
|
+
// The skip rail: project (#206 decision 2 — the source_agent rail was
|
|
686
|
+
// removed) or classification (#332 — the pools never cross). The dry
|
|
687
|
+
// run sizes each rail off these lines.
|
|
688
|
+
const reason = c.mismatch.classificationMismatch ? "classification_mismatch" : "project_mismatch";
|
|
689
|
+
console.log(`[hicortex] SKIPPED (${reason}): ${c.memberIds.map((id) => id.slice(0, 8)).join(", ")}`);
|
|
676
690
|
}
|
|
677
691
|
// #393 guard-C: listed for review like the mismatch clusters — a
|
|
678
692
|
// conflicts-linked near-duplicate pair is deliberate, not an error.
|
package/dist/distill-queue.d.ts
CHANGED
|
@@ -34,6 +34,7 @@
|
|
|
34
34
|
import type Database from "better-sqlite3";
|
|
35
35
|
import { detectChunkSize } from "./distiller.js";
|
|
36
36
|
import type { LlmUsage, LlmConfig } from "./llm.js";
|
|
37
|
+
import type { MemoryPrivacy } from "./types.js";
|
|
37
38
|
import type { RunDeadline } from "./run-deadline.js";
|
|
38
39
|
/** One queued delivery, as stored in `distill_queue`. */
|
|
39
40
|
export interface DistillQueueRow {
|
|
@@ -43,10 +44,23 @@ export interface DistillQueueRow {
|
|
|
43
44
|
source_agent: string | null;
|
|
44
45
|
source_agent_id: string | null;
|
|
45
46
|
source_domain: string | null;
|
|
47
|
+
/**
|
|
48
|
+
* The delivery's workspace path (#609, migration v28) — carried through the
|
|
49
|
+
* inbox so the drain's inserts keep it and `hicortex backfill-privacy` can
|
|
50
|
+
* path-match queued rows. NULL when the delivery had none (Hermes,
|
|
51
|
+
* pre-#609 clients).
|
|
52
|
+
*/
|
|
53
|
+
workspace_path: string | null;
|
|
46
54
|
source_machine: string | null;
|
|
47
55
|
project: string | null;
|
|
48
56
|
session_date: string | null;
|
|
49
|
-
|
|
57
|
+
/**
|
|
58
|
+
* #332 classification stamp. 'standard' | 'confidential' on every row
|
|
59
|
+
* written after v27 (enqueue normalizes; the intake handler derives);
|
|
60
|
+
* nullable defensively because the column is loose TEXT and pre-v27 rows
|
|
61
|
+
* existed — readers treat NULL as standard (the fail-closed default).
|
|
62
|
+
*/
|
|
63
|
+
privacy: MemoryPrivacy | null;
|
|
50
64
|
text: string;
|
|
51
65
|
arrived_at: string;
|
|
52
66
|
}
|
|
@@ -63,6 +77,8 @@ export interface EnqueueDistillInput {
|
|
|
63
77
|
source_agent_id?: unknown;
|
|
64
78
|
source_domain?: unknown;
|
|
65
79
|
source_machine?: unknown;
|
|
80
|
+
/** #609: the delivery's workspace path (wire `workspace_path`). */
|
|
81
|
+
workspace_path?: unknown;
|
|
66
82
|
project?: unknown;
|
|
67
83
|
session_id?: unknown;
|
|
68
84
|
segment_id?: unknown;
|
|
@@ -176,6 +192,16 @@ export interface DrainOptions {
|
|
|
176
192
|
* mechanical fold only. The nightly passes the boot-resolved config value.
|
|
177
193
|
*/
|
|
178
194
|
projectAliases?: Readonly<Record<string, string>> | null;
|
|
195
|
+
/**
|
|
196
|
+
* #332: the CONFIDENTIAL model client. Items stamped 'confidential' distill
|
|
197
|
+
* on THIS client; when it is absent they are HELD — the row stays queued
|
|
198
|
+
* (skip-and-continue, the no_llm precedent but per-item) and standard items
|
|
199
|
+
* keep draining. There is NO fallback to `llm`: confidential text never
|
|
200
|
+
* reaches the standard model, held beats exposed.
|
|
201
|
+
*/
|
|
202
|
+
confidentialLlm?: DrainLlm | null;
|
|
203
|
+
/** Its config — drives the confidential endpoint's own chunk-size cache. */
|
|
204
|
+
confidentialLlmConfig?: LlmConfig | null;
|
|
179
205
|
}
|
|
180
206
|
export interface DrainReport {
|
|
181
207
|
/**
|
|
@@ -196,6 +222,13 @@ export interface DrainReport {
|
|
|
196
222
|
memories: number;
|
|
197
223
|
/** Items still queued after this run. */
|
|
198
224
|
remaining: number;
|
|
225
|
+
/**
|
|
226
|
+
* #332: items HELD this run — stamped confidential with no confidential
|
|
227
|
+
* client configured. They stay queued (skip-and-continue); standard items
|
|
228
|
+
* drained normally. The boot warning names the exposure; this count is the
|
|
229
|
+
* per-run queue-growth signal.
|
|
230
|
+
*/
|
|
231
|
+
held_confidential?: number;
|
|
199
232
|
/** Tokens metered this drain (incl. a failed item's partial usage). */
|
|
200
233
|
usage: {
|
|
201
234
|
prompt: number;
|
package/dist/distill-queue.js
CHANGED
|
@@ -96,13 +96,23 @@ function enqueueDistill(db, input) {
|
|
|
96
96
|
const result = db
|
|
97
97
|
.prepare(`INSERT OR IGNORE INTO distill_queue
|
|
98
98
|
(session_id, segment_id, source_agent, source_agent_id, source_domain,
|
|
99
|
-
source_machine, project, session_date, privacy, text, arrived_at)
|
|
100
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`)
|
|
101
|
-
.run(str(input.session_id), typeof input.segment_id === "string" ? input.segment_id : "", str(input.source_agent), str(input.source_agent_id), str(input.source_domain),
|
|
99
|
+
workspace_path, source_machine, project, session_date, privacy, text, arrived_at)
|
|
100
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`)
|
|
101
|
+
.run(str(input.session_id), typeof input.segment_id === "string" ? input.segment_id : "", str(input.source_agent), str(input.source_agent_id), str(input.source_domain),
|
|
102
|
+
// #609: the workspace path rides the queue row (the drain's inserts and
|
|
103
|
+
// the path backfill read it back); NULL when the delivery had none.
|
|
104
|
+
str(input.workspace_path), str(input.source_machine), str(input.project),
|
|
102
105
|
// Resolve the date ONCE at delivery (mirrors the sync handler): absent
|
|
103
106
|
// or non-string becomes today, and the drain reuses the stored value so
|
|
104
107
|
// a queued segment keeps its session date.
|
|
105
|
-
str(input.session_date) ?? new Date().toISOString().slice(0, 10),
|
|
108
|
+
str(input.session_date) ?? new Date().toISOString().slice(0, 10),
|
|
109
|
+
// #332: the classification stamp, normalized at the insert boundary —
|
|
110
|
+
// a legacy client's 'WORK'/blank/absent value lands as 'standard'
|
|
111
|
+
// (migration v27 normalized pre-existing rows the same way). The intake
|
|
112
|
+
// handler derives the stamp from source_agent × roster before it gets
|
|
113
|
+
// here, so a rostered agent's delivery is queued 'confidential' even
|
|
114
|
+
// when the client declares nothing.
|
|
115
|
+
storage.normalizeStoredPrivacy(input.privacy), input.text, new Date().toISOString());
|
|
106
116
|
return { duplicate: result.changes === 0 };
|
|
107
117
|
}
|
|
108
118
|
/**
|
|
@@ -189,8 +199,7 @@ function resolveQueueMode(db, distillQueueEnabled) {
|
|
|
189
199
|
}
|
|
190
200
|
/** Chunk-size cache, keyed per endpoint exactly like the handler's. */
|
|
191
201
|
const chunkSizeCache = new Map();
|
|
192
|
-
async function
|
|
193
|
-
const cfg = opts.llmConfig;
|
|
202
|
+
async function resolveDrainChunkSizeFor(opts, cfg) {
|
|
194
203
|
const detect = opts.detectChunkSize ?? distiller_js_1.detectChunkSize;
|
|
195
204
|
const cacheKey = `${cfg.provider}/${cfg.model}@${cfg.baseUrl}`;
|
|
196
205
|
if (!chunkSizeCache.has(cacheKey)) {
|
|
@@ -276,6 +285,7 @@ async function drainDistillQueue(db, opts) {
|
|
|
276
285
|
duplicates: 0,
|
|
277
286
|
memories: 0,
|
|
278
287
|
remaining: 0,
|
|
288
|
+
held_confidential: 0,
|
|
279
289
|
usage: { prompt: 0, completion: 0, total: 0 },
|
|
280
290
|
};
|
|
281
291
|
const rows = db
|
|
@@ -283,6 +293,16 @@ async function drainDistillQueue(db, opts) {
|
|
|
283
293
|
.all();
|
|
284
294
|
if (rows.length === 0)
|
|
285
295
|
return report; // the healthy steady state: depth 0
|
|
296
|
+
// #332: confidential items with no confidential client HOLD (skip-and-
|
|
297
|
+
// continue) — one warn per run, then the drain proceeds over the standard
|
|
298
|
+
// items. The rows stay queued; the report carries the held count.
|
|
299
|
+
const confidentialCount = rows.filter((r) => r.privacy === "confidential").length;
|
|
300
|
+
const hasConfidentialClient = !!(opts.confidentialLlm && opts.confidentialLlmConfig);
|
|
301
|
+
if (confidentialCount > 0 && !hasConfidentialClient) {
|
|
302
|
+
console.warn(`[hicortex] drain: ${confidentialCount} confidential item(s) HELD — no confidential model configured ` +
|
|
303
|
+
`(llmConfidentialBaseUrl/ApiKey). They stay queued; standard items drain normally. ` +
|
|
304
|
+
`Confidential text never touches the standard model.`);
|
|
305
|
+
}
|
|
286
306
|
// No LLM configured: delivery still queued (queue mode needs no LLM), but
|
|
287
307
|
// distillation cannot run. Report + defer — items stay queued; the
|
|
288
308
|
// consolidation block reports its own no_llm right after.
|
|
@@ -307,7 +327,6 @@ async function drainDistillQueue(db, opts) {
|
|
|
307
327
|
}
|
|
308
328
|
const queues = [...byClient.values()];
|
|
309
329
|
console.log(`[hicortex] Distill inbox: ${rows.length} item(s) from ${queues.length} client(s) — draining`);
|
|
310
|
-
const chunkSize = await resolveDrainChunkSize(opts);
|
|
311
330
|
const warned = { unreachable: false };
|
|
312
331
|
let stopped;
|
|
313
332
|
outer: while (queues.some((q) => q.length > 0)) {
|
|
@@ -354,6 +373,24 @@ async function drainDistillQueue(db, opts) {
|
|
|
354
373
|
// usage accrues even on throw (some chunks' LLM calls already happened)
|
|
355
374
|
// — the caller records it against the monthly meter, same as the sync
|
|
356
375
|
// path's finally.
|
|
376
|
+
//
|
|
377
|
+
// #332 per-pool client selection: a confidential item distills on the
|
|
378
|
+
// CONFIDENTIAL client; without one it HOLDS here (skip-and-continue —
|
|
379
|
+
// the row stays queued, standard items drain on, held count reported).
|
|
380
|
+
// Standard items use the main client as before.
|
|
381
|
+
if (item.privacy === "confidential") {
|
|
382
|
+
if (!opts.confidentialLlm || !opts.confidentialLlmConfig) {
|
|
383
|
+
report.held_confidential = (report.held_confidential ?? 0) + 1;
|
|
384
|
+
continue;
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
const itemLlm = (item.privacy === "confidential"
|
|
388
|
+
? opts.confidentialLlm
|
|
389
|
+
: opts.llm);
|
|
390
|
+
const itemLlmConfig = item.privacy === "confidential"
|
|
391
|
+
? opts.confidentialLlmConfig
|
|
392
|
+
: opts.llmConfig;
|
|
393
|
+
const chunkSize = await resolveDrainChunkSizeFor(opts, itemLlmConfig);
|
|
357
394
|
const usage = { prompt: 0, completion: 0, total: 0 };
|
|
358
395
|
const label = item.segment_id !== ""
|
|
359
396
|
? item.segment_id
|
|
@@ -367,7 +404,7 @@ async function drainDistillQueue(db, opts) {
|
|
|
367
404
|
const canonProject = (0, project_canonicalize_js_1.canonicalizeProject)(item.project, opts.projectAliases);
|
|
368
405
|
try {
|
|
369
406
|
// Cast: DrainLlm is the structural surface distillSession uses.
|
|
370
|
-
const llm =
|
|
407
|
+
const llm = itemLlm;
|
|
371
408
|
const entries = await (0, distiller_js_1.distillSession)(llm, item.text, canonProject ?? "unknown", item.session_date ?? new Date().toISOString().slice(0, 10), chunkSize, [], (u) => {
|
|
372
409
|
usage.prompt += u.prompt_tokens ?? 0;
|
|
373
410
|
usage.completion += u.completion_tokens ?? 0;
|
|
@@ -401,11 +438,18 @@ async function drainDistillQueue(db, opts) {
|
|
|
401
438
|
sourceAgent: item.source_agent ?? "unknown",
|
|
402
439
|
sourceAgentId: item.source_agent_id,
|
|
403
440
|
sourceDomain: item.source_domain,
|
|
441
|
+
// #609: the queue row's workspace path flows onto the stored
|
|
442
|
+
// memories (the drain SELECT is `SELECT *`, so the column
|
|
443
|
+
// arrives for free — this opt is what lands it).
|
|
444
|
+
workspacePath: item.workspace_path ?? null,
|
|
404
445
|
sourceMachine: storage.sanitizeSourceMachine(item.source_machine),
|
|
405
446
|
sourceSession: sourcePrefix ? `${sourcePrefix}#${i}` : undefined,
|
|
406
447
|
project: canonProject ?? undefined,
|
|
407
448
|
memoryType,
|
|
408
|
-
|
|
449
|
+
// #332: the row's class stamp rides into the stored memories —
|
|
450
|
+
// normalized defensively (a NULL from a pre-v27 row reads
|
|
451
|
+
// standard, same as the read gates).
|
|
452
|
+
privacy: storage.normalizeStoredPrivacy(item.privacy),
|
|
409
453
|
createdAt,
|
|
410
454
|
});
|
|
411
455
|
}
|
|
@@ -439,7 +483,10 @@ async function drainDistillQueue(db, opts) {
|
|
|
439
483
|
report.remaining = queueDepth(db);
|
|
440
484
|
if (report.outcome === "completed") {
|
|
441
485
|
console.log(`[hicortex] Distill inbox drained: ${report.processed} item(s), ` +
|
|
442
|
-
`${report.memories} memories, ${report.duplicates} duplicate skip(s)`
|
|
486
|
+
`${report.memories} memories, ${report.duplicates} duplicate skip(s)` +
|
|
487
|
+
(report.held_confidential
|
|
488
|
+
? `, ${report.held_confidential} confidential item(s) HELD (no confidential model)`
|
|
489
|
+
: ""));
|
|
443
490
|
}
|
|
444
491
|
return report;
|
|
445
492
|
}
|
package/dist/graph.d.ts
CHANGED
|
@@ -37,11 +37,26 @@ export declare function louvainCommunities(db: Database.Database): {
|
|
|
37
37
|
nodeCount: number;
|
|
38
38
|
edgeCount: number;
|
|
39
39
|
};
|
|
40
|
+
/**
|
|
41
|
+
* #332: the confidential id set — the hard-omit set for the gated graph
|
|
42
|
+
* surfaces. Computed once per call (the graph ops are single-query + small
|
|
43
|
+
* loops; a corpus-wide id set is cheap). NULL-safe: only
|
|
44
|
+
* privacy = 'confidential' rows enter.
|
|
45
|
+
*/
|
|
46
|
+
export declare function confidentialNodeIds(db: Database.Database): Set<string>;
|
|
40
47
|
/**
|
|
41
48
|
* Find hub nodes — memories with link count significantly above median.
|
|
42
49
|
* Returns nodes with links > threshold (default: 2x median, minimum 3 links).
|
|
50
|
+
*
|
|
51
|
+
* #332: `includeConfidential` defaults to FALSE — the agent-facing surfaces
|
|
52
|
+
* (REST /graph?op=hubs without a member agent, the MCP graph tool) hard-omit
|
|
53
|
+
* confidential hubs (their content snippets ARE content-bearing). The /viz
|
|
54
|
+
* export (the owner surface — deliberately ungated per the #332 owner ruling)
|
|
55
|
+
* passes true.
|
|
43
56
|
*/
|
|
44
|
-
export declare function detectHubs(db: Database.Database, thresholdMultiplier?: number, minLinks?: number
|
|
57
|
+
export declare function detectHubs(db: Database.Database, thresholdMultiplier?: number, minLinks?: number, opts?: {
|
|
58
|
+
includeConfidential?: boolean;
|
|
59
|
+
}): HubNode[];
|
|
45
60
|
export interface GraphNeighbor {
|
|
46
61
|
id: string;
|
|
47
62
|
relationship: string;
|
|
@@ -50,7 +65,9 @@ export interface GraphNeighbor {
|
|
|
50
65
|
content: string;
|
|
51
66
|
project: string | null;
|
|
52
67
|
}
|
|
53
|
-
export declare function getNeighbors(db: Database.Database, memoryId: string, limit?: number, relationship?: string
|
|
68
|
+
export declare function getNeighbors(db: Database.Database, memoryId: string, limit?: number, relationship?: string, opts?: {
|
|
69
|
+
includeConfidential?: boolean;
|
|
70
|
+
}): GraphNeighbor[];
|
|
54
71
|
export declare const EXPORT_DEFAULT_LIMIT = 5000;
|
|
55
72
|
export declare const EXPORT_MAX_LIMIT = 10000;
|
|
56
73
|
export interface VizNode {
|
|
@@ -106,4 +123,12 @@ export interface ExportGraphOptions {
|
|
|
106
123
|
* queries) and feed the per-node linkCount field.
|
|
107
124
|
*/
|
|
108
125
|
export declare function exportGraph(db: Database.Database, options?: ExportGraphOptions): VizGraph;
|
|
109
|
-
|
|
126
|
+
/**
|
|
127
|
+
* BFS shortest path. #332: `includeConfidential` defaults to FALSE —
|
|
128
|
+
* confidential nodes are excluded from TRAVERSAL entirely (a confidential id
|
|
129
|
+
* must not appear even as an intermediate hop; the endpoints' own classes are
|
|
130
|
+
* the caller's gate, same contract as getNeighbors' center).
|
|
131
|
+
*/
|
|
132
|
+
export declare function shortestPath(db: Database.Database, fromId: string, toId: string, maxDepth?: number, opts?: {
|
|
133
|
+
includeConfidential?: boolean;
|
|
134
|
+
}): string[] | null;
|
package/dist/graph.js
CHANGED
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
13
|
exports.EXPORT_MAX_LIMIT = exports.EXPORT_DEFAULT_LIMIT = void 0;
|
|
14
14
|
exports.louvainCommunities = louvainCommunities;
|
|
15
|
+
exports.confidentialNodeIds = confidentialNodeIds;
|
|
15
16
|
exports.detectHubs = detectHubs;
|
|
16
17
|
exports.getNeighbors = getNeighbors;
|
|
17
18
|
exports.exportGraph = exportGraph;
|
|
@@ -139,11 +140,30 @@ function louvainCommunities(db) {
|
|
|
139
140
|
// ---------------------------------------------------------------------------
|
|
140
141
|
// Hub node detection
|
|
141
142
|
// ---------------------------------------------------------------------------
|
|
143
|
+
/**
|
|
144
|
+
* #332: the confidential id set — the hard-omit set for the gated graph
|
|
145
|
+
* surfaces. Computed once per call (the graph ops are single-query + small
|
|
146
|
+
* loops; a corpus-wide id set is cheap). NULL-safe: only
|
|
147
|
+
* privacy = 'confidential' rows enter.
|
|
148
|
+
*/
|
|
149
|
+
function confidentialNodeIds(db) {
|
|
150
|
+
const rows = db
|
|
151
|
+
.prepare("SELECT id FROM memories WHERE privacy = 'confidential'")
|
|
152
|
+
.all();
|
|
153
|
+
return new Set(rows.map((r) => r.id));
|
|
154
|
+
}
|
|
142
155
|
/**
|
|
143
156
|
* Find hub nodes — memories with link count significantly above median.
|
|
144
157
|
* Returns nodes with links > threshold (default: 2x median, minimum 3 links).
|
|
158
|
+
*
|
|
159
|
+
* #332: `includeConfidential` defaults to FALSE — the agent-facing surfaces
|
|
160
|
+
* (REST /graph?op=hubs without a member agent, the MCP graph tool) hard-omit
|
|
161
|
+
* confidential hubs (their content snippets ARE content-bearing). The /viz
|
|
162
|
+
* export (the owner surface — deliberately ungated per the #332 owner ruling)
|
|
163
|
+
* passes true.
|
|
145
164
|
*/
|
|
146
|
-
function detectHubs(db, thresholdMultiplier = 2, minLinks = 3) {
|
|
165
|
+
function detectHubs(db, thresholdMultiplier = 2, minLinks = 3, opts) {
|
|
166
|
+
const hidden = opts?.includeConfidential === true ? null : confidentialNodeIds(db);
|
|
147
167
|
const rows = db
|
|
148
168
|
.prepare(`SELECT id, cnt FROM (
|
|
149
169
|
SELECT id, COUNT(*) as cnt FROM (
|
|
@@ -163,6 +183,8 @@ function detectHubs(db, thresholdMultiplier = 2, minLinks = 3) {
|
|
|
163
183
|
for (const { id, cnt } of rows) {
|
|
164
184
|
if (cnt < threshold)
|
|
165
185
|
break; // sorted desc, no more hubs
|
|
186
|
+
if (hidden?.has(id))
|
|
187
|
+
continue;
|
|
166
188
|
const mem = db
|
|
167
189
|
.prepare("SELECT content, project, domain FROM memories WHERE id = ?")
|
|
168
190
|
.get(id);
|
|
@@ -178,7 +200,13 @@ function detectHubs(db, thresholdMultiplier = 2, minLinks = 3) {
|
|
|
178
200
|
}
|
|
179
201
|
return hubs;
|
|
180
202
|
}
|
|
181
|
-
function getNeighbors(db, memoryId, limit = 10, relationship) {
|
|
203
|
+
function getNeighbors(db, memoryId, limit = 10, relationship, opts) {
|
|
204
|
+
// #332: hard-omit set for confidential NEIGHBORS (their content rides the
|
|
205
|
+
// row). The CENTER memory's own class is the CALLER's gate — an
|
|
206
|
+
// agent-facing adapter must refuse a confidential center id before calling
|
|
207
|
+
// (REST /graph and the MCP tool 404 it for non-members, same contract as
|
|
208
|
+
// GET /memory). Default false = omit; the owner surfaces pass true.
|
|
209
|
+
const hidden = opts?.includeConfidential === true ? null : confidentialNodeIds(db);
|
|
182
210
|
let sql = `SELECT source_id, target_id, relationship, strength
|
|
183
211
|
FROM memory_links
|
|
184
212
|
WHERE (source_id = ? OR target_id = ?)`;
|
|
@@ -196,6 +224,8 @@ function getNeighbors(db, memoryId, limit = 10, relationship) {
|
|
|
196
224
|
for (const row of rows) {
|
|
197
225
|
const isOutgoing = row.source_id === memoryId;
|
|
198
226
|
const neighborId = isOutgoing ? row.target_id : row.source_id;
|
|
227
|
+
if (hidden?.has(neighborId))
|
|
228
|
+
continue;
|
|
199
229
|
const mem = db
|
|
200
230
|
.prepare("SELECT content, project FROM memories WHERE id = ?")
|
|
201
231
|
.get(neighborId);
|
|
@@ -270,7 +300,10 @@ function exportGraph(db, options = {}) {
|
|
|
270
300
|
if (where.length > 0)
|
|
271
301
|
sql += ` WHERE ${where.join(" AND ")}`;
|
|
272
302
|
const rows = db.prepare(sql).all(...params);
|
|
273
|
-
|
|
303
|
+
// #332: the /viz export is the OWNER surface — deliberately ungated per the
|
|
304
|
+
// issue-332 owner ruling ("dashboard/viz NOT gated in this build"; a
|
|
305
|
+
// show-confidential graph toggle is a separate later item). Explicit true.
|
|
306
|
+
const hubIds = new Set(detectHubs(db, 2, 3, { includeConfidential: true }).map((h) => h.id));
|
|
274
307
|
// Score, filter on effective strength, rank, cap
|
|
275
308
|
const scored = rows.map((row) => {
|
|
276
309
|
const linkCount = linkCounts.get(row.id) ?? 0;
|
|
@@ -356,13 +389,22 @@ function exportGraph(db, options = {}) {
|
|
|
356
389
|
// ---------------------------------------------------------------------------
|
|
357
390
|
// Shortest path (for MCP tool)
|
|
358
391
|
// ---------------------------------------------------------------------------
|
|
359
|
-
|
|
392
|
+
/**
|
|
393
|
+
* BFS shortest path. #332: `includeConfidential` defaults to FALSE —
|
|
394
|
+
* confidential nodes are excluded from TRAVERSAL entirely (a confidential id
|
|
395
|
+
* must not appear even as an intermediate hop; the endpoints' own classes are
|
|
396
|
+
* the caller's gate, same contract as getNeighbors' center).
|
|
397
|
+
*/
|
|
398
|
+
function shortestPath(db, fromId, toId, maxDepth = 5, opts) {
|
|
360
399
|
// BFS on the memory_links graph
|
|
361
400
|
const links = db
|
|
362
401
|
.prepare("SELECT source_id, target_id FROM memory_links")
|
|
363
402
|
.all();
|
|
403
|
+
const hidden = opts?.includeConfidential === true ? null : confidentialNodeIds(db);
|
|
364
404
|
const adj = new Map();
|
|
365
405
|
for (const { source_id, target_id } of links) {
|
|
406
|
+
if (hidden?.has(source_id) || hidden?.has(target_id))
|
|
407
|
+
continue;
|
|
366
408
|
if (!adj.has(source_id))
|
|
367
409
|
adj.set(source_id, new Set());
|
|
368
410
|
adj.get(source_id).add(target_id);
|
|
@@ -146,6 +146,11 @@ function readHermesSessions(since, hermesHome = HERMES_HOME, cursors = {}) {
|
|
|
146
146
|
batches.push({
|
|
147
147
|
sessionId: s.id,
|
|
148
148
|
projectName: profile,
|
|
149
|
+
// #609: Hermes has NO workspace — sessions are per-profile
|
|
150
|
+
// conversations and the message query selects no path field — so
|
|
151
|
+
// path/marker birthplace signals deliberately never fire for Hermes
|
|
152
|
+
// deliveries (roster-only coverage). Never invent a path here.
|
|
153
|
+
workspacePath: null,
|
|
149
154
|
sourceAgent: `hermes/${profile}`,
|
|
150
155
|
date: new Date(endTs * 1000).toISOString().slice(0, 10),
|
|
151
156
|
entries,
|