@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/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,31 @@ 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). "Active" includes
|
|
592
|
+
// confidentialPaths patterns configured (#609) — a patterns-only circle
|
|
593
|
+
// warns here too, not just at daemon boot (one clock, one definition).
|
|
594
|
+
(0, classification_js_1.warnIfCircleUnconfigured)({
|
|
595
|
+
roster: (0, classification_js_1.resolveConfidentialAgents)(savedConfig).roster,
|
|
596
|
+
patterns: (0, classification_js_1.resolveConfidentialPaths)(savedConfig).patterns,
|
|
597
|
+
confidentialLlm: confidentialLlm ?? confidentialLlmConfig,
|
|
598
|
+
confidentialRows: db.prepare("SELECT COUNT(*) AS c FROM memories WHERE privacy = 'confidential'").get().c,
|
|
599
|
+
queueConfidential: db.prepare("SELECT COUNT(*) AS c FROM distill_queue WHERE privacy = 'confidential'").get().c,
|
|
600
|
+
});
|
|
582
601
|
// Steps 1+2: single-flight capture. The lock guards ONLY the capture phase
|
|
583
602
|
// (fix 10). We acquire it BEFORE reading the cursor store so a run that
|
|
584
603
|
// waited out another cannot act on a stale snapshot and clobber its cursor
|
|
@@ -725,6 +744,10 @@ async function runNightly(options = {}) {
|
|
|
725
744
|
const drainReport = await (0, distill_queue_js_1.drainDistillQueue)(db, {
|
|
726
745
|
llm,
|
|
727
746
|
llmConfig,
|
|
747
|
+
// #332: the confidential client — confidential queue items distill on
|
|
748
|
+
// it; without it they hold (per-item skip-and-continue).
|
|
749
|
+
confidentialLlm,
|
|
750
|
+
confidentialLlmConfig,
|
|
728
751
|
embed: embedder_js_1.embed,
|
|
729
752
|
budgetExceeded: () => (0, token_budget_js_1.isTokenBudgetExceeded)(stateDir),
|
|
730
753
|
deadline,
|
|
@@ -890,7 +913,11 @@ async function runNightly(options = {}) {
|
|
|
890
913
|
},
|
|
891
914
|
// #405: the ONE run-wide deadline — capture and every
|
|
892
915
|
// consolidation stage check this same handle.
|
|
893
|
-
deadline
|
|
916
|
+
deadline,
|
|
917
|
+
// #332: the confidential client — every pool-aware stage
|
|
918
|
+
// (importance batches, reflection, domain classification,
|
|
919
|
+
// reconsolidation) routes confidential text here; absent ⇒ hold.
|
|
920
|
+
confidentialLlm);
|
|
894
921
|
console.log(`[hicortex] Consolidation ${report.status} in ${report.elapsed_seconds}s` +
|
|
895
922
|
(report.stages.reflection ? ` (${report.stages.reflection.lessons_generated} lessons)` : ""));
|
|
896
923
|
consolidationStatus = report.status;
|
|
@@ -1230,7 +1257,9 @@ async function runNightly(options = {}) {
|
|
|
1230
1257
|
mode: "server",
|
|
1231
1258
|
agent: agentType,
|
|
1232
1259
|
mem: storage.countMemories(db),
|
|
1233
|
-
|
|
1260
|
+
// #332: telemetry counts the whole store (server-internal metric —
|
|
1261
|
+
// not an agent-facing surface, so no membership gate).
|
|
1262
|
+
lessons: storage.getLessons(db, 365, null, { includeConfidential: true }).length,
|
|
1234
1263
|
lessonsGenerated,
|
|
1235
1264
|
consolidation: consolidationStatus,
|
|
1236
1265
|
// #246: total tokens consumed by this run's consolidation (absent on
|
|
@@ -160,6 +160,9 @@ function readOpencodeSessions(since, opencodeHome = OPENCODE_DATA_HOME, cursors
|
|
|
160
160
|
batches.push({
|
|
161
161
|
sessionId: s.id,
|
|
162
162
|
projectName: (0, node_path_1.basename)(s.directory ?? "") || "opencode",
|
|
163
|
+
// #609: session.directory IS the workspace path (the basename above
|
|
164
|
+
// keeps serving only the project label).
|
|
165
|
+
workspacePath: typeof s.directory === "string" && s.directory ? s.directory : null,
|
|
163
166
|
sourceAgent: "opencode",
|
|
164
167
|
date: new Date(rows[rows.length - 1].time_created).toISOString().slice(0, 10),
|
|
165
168
|
entries,
|
|
@@ -142,6 +142,9 @@ function readPiTranscripts(since, sessionsDir = DEFAULT_PI_SESSIONS_DIR, cursors
|
|
|
142
142
|
projectName,
|
|
143
143
|
date: deltaDate || sessionDate || new Date().toISOString().slice(0, 10),
|
|
144
144
|
entries: delta,
|
|
145
|
+
// #609: the session header's `cwd` is the canonical workspace path
|
|
146
|
+
// (the encoded directory name is only a filesystem-safe form).
|
|
147
|
+
workspacePath: sessionCwd || null,
|
|
145
148
|
cursorKey,
|
|
146
149
|
startCursor: start,
|
|
147
150
|
generation: gen,
|
package/dist/prompts.d.ts
CHANGED
|
@@ -8,6 +8,24 @@
|
|
|
8
8
|
* real internal project/tool/host names or real incident specifics. The
|
|
9
9
|
* infra-name denylist cannot catch conceptual leaks, only known names.
|
|
10
10
|
*/
|
|
11
|
+
import type { MemoryPrivacy } from "./types.js";
|
|
12
|
+
/**
|
|
13
|
+
* The STANDARD pool's reflection privacy line — pinned verbatim since #602
|
|
14
|
+
* (it was a literal inside the template before). The standard pool's prompt
|
|
15
|
+
* must stay byte-identical to the pre-#602 prompt; tests pin this exact string
|
|
16
|
+
* so nobody edits it silently.
|
|
17
|
+
*/
|
|
18
|
+
export declare const REFLECTION_PRIVACY_LINE_STANDARD = "Privacy: Never include personal data (names, health, finances, credentials) in lesson text. Abstract to the process level.";
|
|
19
|
+
/**
|
|
20
|
+
* The CONFIDENTIAL pool's reflection privacy line (#602). Three elements:
|
|
21
|
+
* (a) the pool serves the owner's inner circle only (confidential circle,
|
|
22
|
+
* #598 — its lessons stay inside the pool via the inherited stamp);
|
|
23
|
+
* (b) lesson text MAY reference the user's personal domains at the process
|
|
24
|
+
* level where needed to make the lesson actionable — the standard line
|
|
25
|
+
* suppressed all confidential lessons by construction (#602 finding);
|
|
26
|
+
* (c) credentials/passwords/API keys/secrets are STILL never included.
|
|
27
|
+
*/
|
|
28
|
+
export declare const REFLECTION_PRIVACY_LINE_CONFIDENTIAL = "Privacy: this pool serves the owner's inner circle only (confidential memories). Lesson text may reference the user's personal domains (names, health, finances) at the process level where needed to make the lesson actionable. Credentials, passwords, API keys, and other secrets are still never included \u2014 abstract those away.";
|
|
11
29
|
/**
|
|
12
30
|
* Importance scoring prompt. Takes a {memories_block} with indexed memories.
|
|
13
31
|
*
|
|
@@ -24,8 +42,22 @@
|
|
|
24
42
|
export declare function importanceScoring(memoriesBlock: string): string;
|
|
25
43
|
/**
|
|
26
44
|
* Reflection prompt. Takes a {memories_block} with today's memories.
|
|
45
|
+
*
|
|
46
|
+
* POOL-AWARE (#602): the optional `pool` argument swaps ONLY the privacy line.
|
|
47
|
+
* Absent/undefined = "standard" = the pre-#602 prompt BYTE-IDENTICAL — the
|
|
48
|
+
* standard pool's prompt must never change. The confidential variant exists
|
|
49
|
+
* because the confidential pool is BY DEFINITION personal-domain content
|
|
50
|
+
* (health, finances, the people in the owner's inner circle), so the standard
|
|
51
|
+
* line ("Never include personal data (names, health, finances, credentials)")
|
|
52
|
+
* suppressed every confidential lesson by construction — #602's measured
|
|
53
|
+
* finding: 0 confidential lessons from a real cohort. Owner ruling
|
|
54
|
+
* 2026-11-12: the confidential pool SHOULD generate lessons for the inner
|
|
55
|
+
* circle; only the PROMPT suppressed them. The confidential line keeps one
|
|
56
|
+
* absolute: credentials/passwords/API keys/secrets are never included.
|
|
57
|
+
* Everything else in the prompt (generality bar, examples, output schema) is
|
|
58
|
+
* shared verbatim by both pools — pinned by tests/reflection-prompt.test.ts.
|
|
27
59
|
*/
|
|
28
|
-
export declare function reflection(memoriesBlock: string, recentLessons?: string): string;
|
|
60
|
+
export declare function reflection(memoriesBlock: string, recentLessons?: string, pool?: MemoryPrivacy): string;
|
|
29
61
|
/**
|
|
30
62
|
* Distillation prompt. Extracts knowledge from a session transcript.
|
|
31
63
|
*
|
package/dist/prompts.js
CHANGED
|
@@ -10,10 +10,28 @@
|
|
|
10
10
|
* infra-name denylist cannot catch conceptual leaks, only known names.
|
|
11
11
|
*/
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.REFLECTION_PRIVACY_LINE_CONFIDENTIAL = exports.REFLECTION_PRIVACY_LINE_STANDARD = void 0;
|
|
13
14
|
exports.importanceScoring = importanceScoring;
|
|
14
15
|
exports.reflection = reflection;
|
|
15
16
|
exports.distillation = distillation;
|
|
16
17
|
exports.domainCuration = domainCuration;
|
|
18
|
+
/**
|
|
19
|
+
* The STANDARD pool's reflection privacy line — pinned verbatim since #602
|
|
20
|
+
* (it was a literal inside the template before). The standard pool's prompt
|
|
21
|
+
* must stay byte-identical to the pre-#602 prompt; tests pin this exact string
|
|
22
|
+
* so nobody edits it silently.
|
|
23
|
+
*/
|
|
24
|
+
exports.REFLECTION_PRIVACY_LINE_STANDARD = "Privacy: Never include personal data (names, health, finances, credentials) in lesson text. Abstract to the process level.";
|
|
25
|
+
/**
|
|
26
|
+
* The CONFIDENTIAL pool's reflection privacy line (#602). Three elements:
|
|
27
|
+
* (a) the pool serves the owner's inner circle only (confidential circle,
|
|
28
|
+
* #598 — its lessons stay inside the pool via the inherited stamp);
|
|
29
|
+
* (b) lesson text MAY reference the user's personal domains at the process
|
|
30
|
+
* level where needed to make the lesson actionable — the standard line
|
|
31
|
+
* suppressed all confidential lessons by construction (#602 finding);
|
|
32
|
+
* (c) credentials/passwords/API keys/secrets are STILL never included.
|
|
33
|
+
*/
|
|
34
|
+
exports.REFLECTION_PRIVACY_LINE_CONFIDENTIAL = "Privacy: this pool serves the owner's inner circle only (confidential memories). Lesson text may reference the user's personal domains (names, health, finances) at the process level where needed to make the lesson actionable. Credentials, passwords, API keys, and other secrets are still never included — abstract those away.";
|
|
17
35
|
/**
|
|
18
36
|
* Importance scoring prompt. Takes a {memories_block} with indexed memories.
|
|
19
37
|
*
|
|
@@ -61,11 +79,28 @@ No explanations. Just the JSON array.`;
|
|
|
61
79
|
}
|
|
62
80
|
/**
|
|
63
81
|
* Reflection prompt. Takes a {memories_block} with today's memories.
|
|
82
|
+
*
|
|
83
|
+
* POOL-AWARE (#602): the optional `pool` argument swaps ONLY the privacy line.
|
|
84
|
+
* Absent/undefined = "standard" = the pre-#602 prompt BYTE-IDENTICAL — the
|
|
85
|
+
* standard pool's prompt must never change. The confidential variant exists
|
|
86
|
+
* because the confidential pool is BY DEFINITION personal-domain content
|
|
87
|
+
* (health, finances, the people in the owner's inner circle), so the standard
|
|
88
|
+
* line ("Never include personal data (names, health, finances, credentials)")
|
|
89
|
+
* suppressed every confidential lesson by construction — #602's measured
|
|
90
|
+
* finding: 0 confidential lessons from a real cohort. Owner ruling
|
|
91
|
+
* 2026-11-12: the confidential pool SHOULD generate lessons for the inner
|
|
92
|
+
* circle; only the PROMPT suppressed them. The confidential line keeps one
|
|
93
|
+
* absolute: credentials/passwords/API keys/secrets are never included.
|
|
94
|
+
* Everything else in the prompt (generality bar, examples, output schema) is
|
|
95
|
+
* shared verbatim by both pools — pinned by tests/reflection-prompt.test.ts.
|
|
64
96
|
*/
|
|
65
|
-
function reflection(memoriesBlock, recentLessons) {
|
|
97
|
+
function reflection(memoriesBlock, recentLessons, pool) {
|
|
66
98
|
const recentSection = recentLessons
|
|
67
99
|
? `\nRECENT LESSONS (already generated — do NOT duplicate, but DO escalate if patterns recur):\n${recentLessons}\n`
|
|
68
100
|
: "";
|
|
101
|
+
const privacyLine = pool === "confidential"
|
|
102
|
+
? exports.REFLECTION_PRIVACY_LINE_CONFIDENTIAL
|
|
103
|
+
: exports.REFLECTION_PRIVACY_LINE_STANDARD;
|
|
69
104
|
return `You are a learning analyst for a multi-agent AI system. Review today's memories and extract actionable lessons from BOTH successes and failures.
|
|
70
105
|
|
|
71
106
|
Like human learning: we grow fastest when we reinforce what works AND correct what doesn't. A system that only learns from mistakes becomes overly cautious. A system that only learns from successes never improves. The combination multiplies.
|
|
@@ -121,7 +156,7 @@ Focus on:
|
|
|
121
156
|
- CROSS-AGENT PATTERNS: same issue or success across different agents — especially high-value
|
|
122
157
|
- PROCESS FEEDBACK: user feedback about the agent's approach/behavior, not just its output
|
|
123
158
|
|
|
124
|
-
|
|
159
|
+
${privacyLine}
|
|
125
160
|
|
|
126
161
|
Skip: isolated trivial actions, already-documented rules, incident notes, changelog entries, and tool-specific recipes. However, if multiple small successes form a consistent pattern of quality, extract that pattern as a reinforcement.
|
|
127
162
|
|
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 +
|
package/dist/recall-index.js
CHANGED
|
@@ -301,6 +301,9 @@ function createRecallRetrieveFn(deps) {
|
|
|
301
301
|
project: filters?.project,
|
|
302
302
|
missionDomains: filters?.mission_domains,
|
|
303
303
|
queryEmbedding: queryVec,
|
|
304
|
+
// #332: the classification gate — hard omit unless the requesting
|
|
305
|
+
// agent is a circle member (the factory was built with membership).
|
|
306
|
+
includeConfidential: deps.includeConfidential === true,
|
|
304
307
|
// #329: shared per-request FTS list. The recall path never passes
|
|
305
308
|
// sourceAgent, so the memo is keyed on (query, fetchLimit) only —
|
|
306
309
|
// exactly the two things retrieve() would pass to searchFts.
|
|
@@ -563,11 +566,12 @@ async function handleRecallIndex(deps, body) {
|
|
|
563
566
|
* citation ids agents are taught must work here like on /update, /delete.
|
|
564
567
|
* - A successful fetch is real use: access_count + 1 (strengthen).
|
|
565
568
|
*
|
|
566
|
-
*
|
|
567
|
-
*
|
|
568
|
-
*
|
|
569
|
+
* #332: `opts.includeConfidential` (default false) is the classification gate
|
|
570
|
+
* — a confidential memory fetched by a non-member answers 404 BEFORE any
|
|
571
|
+
* side effect (no strengthen, no precision event: existence is not revealed).
|
|
572
|
+
* Members (the adapter passes true) fetch both pools normally.
|
|
569
573
|
*/
|
|
570
|
-
function handleMemoryGet(db, query, deps) {
|
|
574
|
+
function handleMemoryGet(db, query, deps, opts) {
|
|
571
575
|
const id = typeof query.id === "string" ? query.id : "";
|
|
572
576
|
if (!id)
|
|
573
577
|
return { status: 400, body: { error: "Missing 'id'" } };
|
|
@@ -581,6 +585,12 @@ function handleMemoryGet(db, query, deps) {
|
|
|
581
585
|
const mem = storage.getMemory(db, fullId);
|
|
582
586
|
if (!mem)
|
|
583
587
|
return notFound;
|
|
588
|
+
// #332: the gate fires BEFORE strengthenMemory + the fetch recorder — a
|
|
589
|
+
// refused fetch must leave no trace on the row and record no event (the
|
|
590
|
+
// same 404 shape an unknown id produces).
|
|
591
|
+
if (mem.privacy === "confidential" && opts?.includeConfidential !== true) {
|
|
592
|
+
return notFound;
|
|
593
|
+
}
|
|
584
594
|
storage.strengthenMemory(db, fullId, new Date().toISOString());
|
|
585
595
|
// #476: one kind='fetch' precision event per successful fetch (the use
|
|
586
596
|
// signal for Level 2 / divergence). Fail-soft — the fetch result is never
|
package/dist/recall-precision.js
CHANGED
|
@@ -216,7 +216,9 @@ function createStandingContextBasis(config) {
|
|
|
216
216
|
// Read errors degrade to an empty lesson half — the basis is a reference,
|
|
217
217
|
// not a ledger.
|
|
218
218
|
try {
|
|
219
|
-
|
|
219
|
+
// #332: the basis is a server-internal redundancy reference over the
|
|
220
|
+
// whole lesson store (no agent sees it) — ungated by design.
|
|
221
|
+
for (const lesson of storage.getLessons(db, 30, null, { includeConfidential: true }))
|
|
220
222
|
texts.push(lesson.content);
|
|
221
223
|
}
|
|
222
224
|
catch (err) {
|
|
@@ -158,6 +158,16 @@ export interface ReconsolidationOptions {
|
|
|
158
158
|
* the real capture.ts lock. DedupOptions.acquireLock pattern.
|
|
159
159
|
*/
|
|
160
160
|
acquireLock?: typeof acquireCaptureLock;
|
|
161
|
+
/**
|
|
162
|
+
* #332: the CONFIDENTIAL model client. Every LLM call in this stage carries
|
|
163
|
+
* memory content (scout shape, pair verdicts, rewrite prompts) — each call
|
|
164
|
+
* selects the client matching the memories it reads; when the confidential
|
|
165
|
+
* side is needed and absent, that pair/group holds (skipped_infra counts,
|
|
166
|
+
* retried next run), never judged on the main model. The deterministic
|
|
167
|
+
* merge zone needs no client but is class-pure via the classification rail
|
|
168
|
+
* (clusterMetadataMismatch).
|
|
169
|
+
*/
|
|
170
|
+
confidentialLlm?: LlmClient | null;
|
|
161
171
|
}
|
|
162
172
|
/** The stage report (typed once, in ConsolidationReport — field list there). */
|
|
163
173
|
export type ReconsolidationStageResult = NonNullable<ConsolidationReport["stages"]["reconsolidation"]>;
|
package/dist/reconsolidation.js
CHANGED
|
@@ -139,6 +139,7 @@ exports.bandForCosine = bandForCosine;
|
|
|
139
139
|
exports.stageReconsolidation = stageReconsolidation;
|
|
140
140
|
exports.rollbackHistoryRow = rollbackHistoryRow;
|
|
141
141
|
exports.runHistoryCommand = runHistoryCommand;
|
|
142
|
+
const classification_js_1 = require("./classification.js");
|
|
142
143
|
const retrieval_js_1 = require("./retrieval.js");
|
|
143
144
|
const storage = __importStar(require("./storage.js"));
|
|
144
145
|
const state_js_1 = require("./state.js");
|
|
@@ -577,9 +578,15 @@ function accumulateBandStat(cumulative, run) {
|
|
|
577
578
|
*/
|
|
578
579
|
async function findOlderCorrectionNeighbors(db, candidate, embedFn, minSimilarity) {
|
|
579
580
|
const embedding = storage.getStoredEmbedding(db, candidate.id) ?? (await embedFn(candidate.content));
|
|
581
|
+
// #332: pairing is class-pure — the KNN pool is unscoped, the filter
|
|
582
|
+
// narrows it to the candidate's own class (no reconsolidation pair ever
|
|
583
|
+
// mixes classes; NULL privacy reads standard).
|
|
584
|
+
const candidateConfidential = candidate.privacy === "confidential";
|
|
580
585
|
return storage
|
|
581
586
|
.vectorSearch(db, embedding, CORRECTION_NEIGHBOR_POOL, [candidate.id])
|
|
582
|
-
.filter((n) => n.
|
|
587
|
+
.filter((n) => (n.privacy === "confidential") === candidateConfidential &&
|
|
588
|
+
n.created_at < candidate.created_at &&
|
|
589
|
+
(0, retrieval_js_1.l2ToCosine)(n.distance) >= minSimilarity)
|
|
583
590
|
.sort((a, b) => (0, retrieval_js_1.l2ToCosine)(b.distance) - (0, retrieval_js_1.l2ToCosine)(a.distance))
|
|
584
591
|
.slice(0, CORRECTION_NEIGHBOR_TOP_K);
|
|
585
592
|
}
|
|
@@ -600,8 +607,12 @@ function findScoutNeighbors(db, candidate, references, candidateEmbedding) {
|
|
|
600
607
|
return [];
|
|
601
608
|
try {
|
|
602
609
|
const hits = storage.searchFts(db, references, CORRECTION_NEIGHBOR_POOL);
|
|
610
|
+
// #332: the scout source is class-pure too — same filter as the KNN
|
|
611
|
+
// source (the FTS pool is unscoped; the filter narrows it).
|
|
612
|
+
const candidateConfidential = candidate.privacy === "confidential";
|
|
603
613
|
return hits
|
|
604
|
-
.filter((m) => m.
|
|
614
|
+
.filter((m) => (m.privacy === "confidential") === candidateConfidential &&
|
|
615
|
+
m.id !== candidate.id &&
|
|
605
616
|
m.created_at < candidate.created_at &&
|
|
606
617
|
m.status !== "absorbed")
|
|
607
618
|
.slice(0, CORRECTION_NEIGHBOR_TOP_K)
|
|
@@ -699,6 +710,16 @@ async function stageReconsolidation(db, llm, budget, embedFn, dryRun, stateDir,
|
|
|
699
710
|
// hit() logs event=deadline_deferred once per stage name.
|
|
700
711
|
const deadline = options.deadline;
|
|
701
712
|
const deadlineHit = (stageLabel = exports.RECONSOLIDATION_STAGE_LABEL) => deadline?.hit(stageLabel) ?? false;
|
|
713
|
+
// ---- #332 per-pool client selection. Every LLM call below goes through
|
|
714
|
+
// clientFor(...); a null answer means "confidential text, no confidential
|
|
715
|
+
// model" — the pair/group HOLDS (skippedInfra, retried next run), never
|
|
716
|
+
// judged on the standard client. (Named llmPair — the merge-batch loop
|
|
717
|
+
// below has its own local `pair` per queued merge.)
|
|
718
|
+
const llmPair = { standard: llm, confidential: options.confidentialLlm ?? null };
|
|
719
|
+
const clientFor = (...mems) => {
|
|
720
|
+
const confidential = mems.some((m) => m.privacy === "confidential");
|
|
721
|
+
return (0, classification_js_1.clientForPool)(llmPair, confidential ? "confidential" : "standard");
|
|
722
|
+
};
|
|
702
723
|
// Per-run verdict statistics by cosine band (#392) — report snapshot here,
|
|
703
724
|
// cumulative series in state.json at stage end (never on dry-run).
|
|
704
725
|
const bands = buildResolutionBands(minSimilarity, autoMergeThreshold);
|
|
@@ -933,7 +954,14 @@ async function stageReconsolidation(db, llm, budget, embedFn, dryRun, stateDir,
|
|
|
933
954
|
explicitDivergent++; // mark's target is gone/invisible — retain link, nothing to upgrade
|
|
934
955
|
continue;
|
|
935
956
|
}
|
|
936
|
-
|
|
957
|
+
// #332: an explicit mark may legally cross classes (an agent marked
|
|
958
|
+
// across pools) — the verdict call selects its client by BOTH sides.
|
|
959
|
+
const markClient = clientFor(target, candidate);
|
|
960
|
+
if (!markClient) {
|
|
961
|
+
skippedInfra++; // held — no confidential model for a confidential side
|
|
962
|
+
continue;
|
|
963
|
+
}
|
|
964
|
+
const { verdict, usage } = await classifyPair(markClient, target.content, candidate.content);
|
|
937
965
|
budget.recordUsage(exports.RECONSOLIDATION_STAGE_LABEL, usage);
|
|
938
966
|
pairsEvaluated++;
|
|
939
967
|
if (candidate.__rowid <= prevScannedRowid)
|
|
@@ -984,21 +1012,30 @@ async function stageReconsolidation(db, llm, budget, embedFn, dryRun, stateDir,
|
|
|
984
1012
|
}
|
|
985
1013
|
else {
|
|
986
1014
|
scoutScanned++;
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
1015
|
+
// #332: the shape call reads the candidate's content — pool-matched
|
|
1016
|
+
// client; held (skip the scout source for this memory, fail-soft like
|
|
1017
|
+
// a parse failure) when the confidential side is unconfigured.
|
|
1018
|
+
const scoutClient = clientFor(candidate);
|
|
1019
|
+
if (!scoutClient) {
|
|
1020
|
+
skippedInfra++;
|
|
1021
|
+
}
|
|
1022
|
+
else {
|
|
1023
|
+
try {
|
|
1024
|
+
const r = await scoutClient.complete(buildScoutShapePrompt(candidate.content));
|
|
1025
|
+
budget.recordUsage(exports.RECONSOLIDATION_STAGE_LABEL, r.usage);
|
|
1026
|
+
const shape = parseScoutShape(r.text);
|
|
1027
|
+
if (!shape) {
|
|
1028
|
+
skippedInfra++;
|
|
1029
|
+
}
|
|
1030
|
+
else if (shape.correction) {
|
|
1031
|
+
scoutCorrectionShaped++;
|
|
1032
|
+
scoutReferences = shape.references;
|
|
1033
|
+
}
|
|
993
1034
|
}
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
scoutReferences = shape.references;
|
|
1035
|
+
catch {
|
|
1036
|
+
skippedInfra++;
|
|
997
1037
|
}
|
|
998
1038
|
}
|
|
999
|
-
catch {
|
|
1000
|
-
skippedInfra++;
|
|
1001
|
-
}
|
|
1002
1039
|
}
|
|
1003
1040
|
}
|
|
1004
1041
|
// ---- AC2: detection pairs against older neighbors — TWO sources (#393 B):
|
|
@@ -1077,7 +1114,15 @@ async function stageReconsolidation(db, llm, budget, embedFn, dryRun, stateDir,
|
|
|
1077
1114
|
stopScan = true; // the boundary below still applies what this candidate already confirmed
|
|
1078
1115
|
break;
|
|
1079
1116
|
}
|
|
1080
|
-
|
|
1117
|
+
// #332: the verdict call reads BOTH memories — pool-matched client
|
|
1118
|
+
// (detection pairs are class-pure by construction, so the pool is one
|
|
1119
|
+
// value; a held pair counts skippedInfra and re-detects next run).
|
|
1120
|
+
const verdictClient = clientFor(entry.mem, candidate);
|
|
1121
|
+
if (!verdictClient) {
|
|
1122
|
+
skippedInfra++;
|
|
1123
|
+
continue;
|
|
1124
|
+
}
|
|
1125
|
+
const { verdict, usage } = await classifyPair(verdictClient, entry.mem.content, candidate.content);
|
|
1081
1126
|
budget.recordUsage(exports.RECONSOLIDATION_STAGE_LABEL, usage);
|
|
1082
1127
|
pairsEvaluated++;
|
|
1083
1128
|
if (candidate.__rowid <= prevScannedRowid)
|
|
@@ -1242,6 +1287,13 @@ async function stageReconsolidation(db, llm, budget, embedFn, dryRun, stateDir,
|
|
|
1242
1287
|
console.log(`[hicortex] Reconsolidation: merge of ${pair.oldId.slice(0, 8)} + ${pair.newId.slice(0, 8)} ` +
|
|
1243
1288
|
`skipped (project mismatch) — both kept`);
|
|
1244
1289
|
}
|
|
1290
|
+
else if (result.reason === "classification_mismatch") {
|
|
1291
|
+
// #332: the pools never cross — a cross-class pair (only
|
|
1292
|
+
// reachable via a legacy cross-class link) stays live on
|
|
1293
|
+
// both sides; the verdict was rendered, the cursor advances.
|
|
1294
|
+
console.log(`[hicortex] Reconsolidation: merge of ${pair.oldId.slice(0, 8)} + ${pair.newId.slice(0, 8)} ` +
|
|
1295
|
+
`skipped (classification mismatch) — both kept`);
|
|
1296
|
+
}
|
|
1245
1297
|
else if (result.reason === "conflict_linked") {
|
|
1246
1298
|
// #393 guard-C: the pair is conflicts-linked (operator-planted
|
|
1247
1299
|
// or a prior verdict) — never blended; the cursor advances,
|
|
@@ -1285,8 +1337,19 @@ async function stageReconsolidation(db, llm, budget, embedFn, dryRun, stateDir,
|
|
|
1285
1337
|
const triggersArg = group.triggers.map((t) => ({ id: t.id, content: t.memory.content }));
|
|
1286
1338
|
let contract = null;
|
|
1287
1339
|
let infraError = false;
|
|
1340
|
+
// #332: the rewrite prompt reads the target AND every trigger —
|
|
1341
|
+
// pool-matched client (groups are class-pure by construction: their
|
|
1342
|
+
// pairs came from the class-pure detection sources). Held when the
|
|
1343
|
+
// confidential side is unconfigured: the group defers untouched.
|
|
1344
|
+
const rewriteClient = clientFor(group.target, ...group.triggers.map((t) => t.memory));
|
|
1345
|
+
if (!rewriteClient) {
|
|
1346
|
+
skippedInfra++;
|
|
1347
|
+
rewritesDeferred = true;
|
|
1348
|
+
stopScan = true;
|
|
1349
|
+
break;
|
|
1350
|
+
}
|
|
1288
1351
|
try {
|
|
1289
|
-
const r = await
|
|
1352
|
+
const r = await rewriteClient.complete(buildRewritePrompt(group.target.content, triggersArg));
|
|
1290
1353
|
contract = parseRewriteReply(r.text, group.triggers.map((t) => t.id), group.target.content);
|
|
1291
1354
|
budget.recordUsage(exports.RECONSOLIDATION_STAGE_LABEL, r.usage);
|
|
1292
1355
|
}
|
package/dist/redact.d.ts
CHANGED
|
@@ -34,12 +34,20 @@ export interface RedactionConfig {
|
|
|
34
34
|
extraPatterns?: string[];
|
|
35
35
|
/** Replacement string. Default: "[REDACTED]". */
|
|
36
36
|
replacement?: string;
|
|
37
|
+
/**
|
|
38
|
+
* #332: the confidential preset — DEFAULT_PATTERNS PLUS emails and phone
|
|
39
|
+
* numbers. Set by the /distill intake for confidential deliveries only;
|
|
40
|
+
* standard deliveries keep today's pattern set byte-identically.
|
|
41
|
+
*/
|
|
42
|
+
extended?: boolean;
|
|
37
43
|
}
|
|
38
44
|
/**
|
|
39
45
|
* Redact secrets and PII from text.
|
|
40
46
|
*
|
|
41
47
|
* @param text The raw transcript text to redact
|
|
42
|
-
* @param config Optional configuration (extra patterns, replacement string
|
|
48
|
+
* @param config Optional configuration (extra patterns, replacement string,
|
|
49
|
+
* and `extended: true` for the confidential preset — #332: DEFAULT_PATTERNS
|
|
50
|
+
* plus emails and phone numbers)
|
|
43
51
|
* @returns The redacted text and count of redactions applied
|
|
44
52
|
*/
|
|
45
53
|
export declare function redact(text: string, config?: RedactionConfig): RedactionResult;
|
package/dist/redact.js
CHANGED
|
@@ -60,11 +60,31 @@ const DEFAULT_PATTERNS = [
|
|
|
60
60
|
// Same lookbehind to avoid URL false positives
|
|
61
61
|
{ name: "linux_path", pattern: /(?<![:/])\/home\/[a-zA-Z0-9._-]+/g },
|
|
62
62
|
];
|
|
63
|
+
/**
|
|
64
|
+
* The CONFIDENTIAL preset (#332 redaction pilot, the #558 gap): everything in
|
|
65
|
+
* DEFAULT_PATTERNS plus emails and phone numbers. Confidential-pool content
|
|
66
|
+
* is the material an inner-circle agent captures (finance, medical, personal
|
|
67
|
+
* correspondence), so its intake redacts contact identifiers BEFORE queueing
|
|
68
|
+
* — standard deliveries keep today's set unchanged (the general email/phone
|
|
69
|
+
* fix for standard rows is deliberately out of scope, #332 non-goals).
|
|
70
|
+
*/
|
|
71
|
+
const CONFIDENTIAL_PATTERNS = [
|
|
72
|
+
// Email addresses — local@domain with a TLD. The negative lookbehind keeps
|
|
73
|
+
// already-redacted [REDACTED] markers (no @) from re-matching; surrounding
|
|
74
|
+
// angle brackets (markdown autolinks) are not captured.
|
|
75
|
+
{ name: "email", pattern: /[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/g },
|
|
76
|
+
// Phone numbers — international E.164 (+4670...) and common dashed/dotted/
|
|
77
|
+
// spaced national forms, 7-15 digits total. Word-ish boundaries avoid
|
|
78
|
+
// matching inside longer digit runs (order ids, timestamps).
|
|
79
|
+
{ name: "phone", pattern: /(?:\+\d{1,3}[\s.-]?)?(?:\(\d{1,4}\)[\s.-]?)?\d{2,4}(?:[\s.-]\d{2,4}){1,4}(?!\d)/g },
|
|
80
|
+
];
|
|
63
81
|
/**
|
|
64
82
|
* Redact secrets and PII from text.
|
|
65
83
|
*
|
|
66
84
|
* @param text The raw transcript text to redact
|
|
67
|
-
* @param config Optional configuration (extra patterns, replacement string
|
|
85
|
+
* @param config Optional configuration (extra patterns, replacement string,
|
|
86
|
+
* and `extended: true` for the confidential preset — #332: DEFAULT_PATTERNS
|
|
87
|
+
* plus emails and phone numbers)
|
|
68
88
|
* @returns The redacted text and count of redactions applied
|
|
69
89
|
*/
|
|
70
90
|
function redact(text, config) {
|
|
@@ -82,6 +102,17 @@ function redact(text, config) {
|
|
|
82
102
|
return replacement;
|
|
83
103
|
});
|
|
84
104
|
}
|
|
105
|
+
// #332: the confidential preset's extra patterns (emails + phones) — only
|
|
106
|
+
// when `extended` is set (confidential deliveries at /distill intake).
|
|
107
|
+
if (config?.extended) {
|
|
108
|
+
for (const { pattern } of CONFIDENTIAL_PATTERNS) {
|
|
109
|
+
pattern.lastIndex = 0;
|
|
110
|
+
result = result.replace(pattern, () => {
|
|
111
|
+
count++;
|
|
112
|
+
return replacement;
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
}
|
|
85
116
|
// Apply user-configured extra patterns
|
|
86
117
|
if (config?.extraPatterns) {
|
|
87
118
|
for (const patternStr of config.extraPatterns) {
|
|
@@ -31,7 +31,7 @@ const paths_js_1 = require("./paths.js");
|
|
|
31
31
|
const db_js_1 = require("./db.js");
|
|
32
32
|
const state_js_1 = require("./state.js");
|
|
33
33
|
const consolidate_js_1 = require("./consolidate.js");
|
|
34
|
-
const
|
|
34
|
+
const classification_js_1 = require("./classification.js");
|
|
35
35
|
const backup_js_1 = require("./backup.js");
|
|
36
36
|
const config_read_js_1 = require("./config-read.js");
|
|
37
37
|
const calibration_js_1 = require("./calibration.js");
|
|
@@ -121,15 +121,20 @@ async function runRescoreImportance(options = {}) {
|
|
|
121
121
|
`This machine is a client of ${config.serverUrl ?? "a remote server"} — run it on the server.`);
|
|
122
122
|
}
|
|
123
123
|
let llm;
|
|
124
|
+
// #332: the confidential client — confidential rows in a slice score on it;
|
|
125
|
+
// without one they hold (the slice's cursor holds below them, retried when
|
|
126
|
+
// the model is configured).
|
|
127
|
+
let confidentialLlm = null;
|
|
124
128
|
if (options.llm) {
|
|
125
129
|
llm = options.llm;
|
|
126
130
|
}
|
|
127
131
|
else {
|
|
128
|
-
const resolved = (0,
|
|
129
|
-
if (!resolved.
|
|
132
|
+
const resolved = (0, classification_js_1.resolveLlmPair)(config);
|
|
133
|
+
if (!resolved.pair) {
|
|
130
134
|
throw new Error("[hicortex] rescore-importance: no LLM configured — run `npx @gamaze/hicortex init`.");
|
|
131
135
|
}
|
|
132
|
-
llm =
|
|
136
|
+
llm = resolved.pair.standard;
|
|
137
|
+
confidentialLlm = resolved.pair.confidential;
|
|
133
138
|
}
|
|
134
139
|
const dbPath = (0, db_js_1.resolveDbPath)(options.dbPath);
|
|
135
140
|
const db = (0, db_js_1.initDb)(dbPath);
|
|
@@ -178,10 +183,22 @@ async function runRescoreImportance(options = {}) {
|
|
|
178
183
|
const sliceRows = chunk.slice(i, i + LLM_SLICE);
|
|
179
184
|
const memories = memoriesForIds(db, sliceRows);
|
|
180
185
|
const r = await (0, consolidate_js_1.scoreMemoriesImportance)(db, memories, llm, {
|
|
186
|
+
confidentialLlm,
|
|
181
187
|
onBatch: (written, batchFailed) => {
|
|
182
188
|
calls++;
|
|
183
189
|
},
|
|
184
190
|
});
|
|
191
|
+
if ((r.skipped_confidential ?? 0) > 0) {
|
|
192
|
+
// #332: confidential rows in this slice are held (no confidential
|
|
193
|
+
// model). Hold the cursor BELOW the slice — never advance past unscored
|
|
194
|
+
// rows; they retry once llmConfidential* is configured (the nightly's
|
|
195
|
+
// watermark pool also re-finds them).
|
|
196
|
+
aborted = true;
|
|
197
|
+
console.warn(`[hicortex] rescore-importance ABORTED: ${r.skipped_confidential} confidential row(s) ` +
|
|
198
|
+
`in the slice at rowid ${sliceRows[0].__rowid} need a confidential model ` +
|
|
199
|
+
`(llmConfidentialBaseUrl/ApiKey). Cursor held — re-run after configuring.`);
|
|
200
|
+
break;
|
|
201
|
+
}
|
|
185
202
|
if (r.failed > 0) {
|
|
186
203
|
// The slice's call threw (endpoint down) or a write failed — nothing
|
|
187
204
|
// usable came out of it. Stop; the cursor stays at the last
|