@gamaze/hicortex 0.27.0 → 0.27.2
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 +16 -13
- package/assets/dashboard.html +95 -3
- package/dist/backfill-privacy.d.ts +40 -13
- package/dist/backfill-privacy.js +139 -28
- package/dist/capture.d.ts +60 -0
- package/dist/capture.js +90 -1
- package/dist/classification.d.ts +172 -10
- package/dist/classification.js +273 -13
- package/dist/cli.js +49 -0
- package/dist/confidential-marker.d.ts +103 -0
- package/dist/confidential-marker.js +285 -0
- package/dist/consolidate.d.ts +34 -3
- package/dist/consolidate.js +84 -10
- package/dist/dashboard.d.ts +32 -0
- package/dist/dashboard.js +33 -0
- package/dist/db.js +23 -0
- package/dist/distill-queue.d.ts +9 -0
- package/dist/distill-queue.js +10 -3
- package/dist/hermes-transcript-reader.js +5 -0
- package/dist/learnings-identity.d.ts +26 -3
- package/dist/learnings-identity.js +54 -17
- package/dist/marker-key-api.d.ts +79 -0
- package/dist/marker-key-api.js +96 -0
- package/dist/mcp-server.js +144 -13
- package/dist/nightly.js +4 -1
- 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-hook-cli.d.ts +3 -0
- package/dist/recall-hook-cli.js +14 -1
- package/dist/storage.js +6 -3
- package/dist/transcript-reader.d.ts +10 -0
- package/dist/transcript-reader.js +13 -0
- package/dist/types.d.ts +41 -5
- package/opencode-plugin/hicortex/index.ts +146 -11
- package/package.json +1 -1
- package/pi-extension/hicortex/index.ts +114 -11
- package/server.json +2 -2
package/dist/mcp-server.js
CHANGED
|
@@ -97,6 +97,7 @@ const capture_pause_js_1 = require("./capture-pause.js");
|
|
|
97
97
|
const project_canonicalize_js_1 = require("./project-canonicalize.js");
|
|
98
98
|
const classification_js_1 = require("./classification.js");
|
|
99
99
|
const init_js_1 = require("./init.js");
|
|
100
|
+
const marker_key_api_js_1 = require("./marker-key-api.js");
|
|
100
101
|
// ---------------------------------------------------------------------------
|
|
101
102
|
// Server state
|
|
102
103
|
// ---------------------------------------------------------------------------
|
|
@@ -156,6 +157,16 @@ let memoryInstructionsEnabled = true;
|
|
|
156
157
|
// circle: every delivery stamps standard, nothing is ever omitted from read
|
|
157
158
|
// paths — the zero-change default.
|
|
158
159
|
let confidentialRoster = [];
|
|
160
|
+
// #609: the workspace-path patterns (config `confidentialPaths`), resolved at
|
|
161
|
+
// the same boot seam as the roster (restart to apply). Empty = the path
|
|
162
|
+
// birthplace signal never fires; the matcher itself lives in classification.ts.
|
|
163
|
+
let confidentialPathPatterns = [];
|
|
164
|
+
// #614: the marker key (config `confidentialMarkerKey` / env
|
|
165
|
+
// HICORTEX_CONFIDENTIAL_MARKER_KEY), resolved at the same boot seam. Null =
|
|
166
|
+
// client workspace markers are INERT (ignored with a boot note when the
|
|
167
|
+
// circle is otherwise active) — the attack surface ships disabled by
|
|
168
|
+
// default. The compare itself lives in classification.ts (timing-safe).
|
|
169
|
+
let confidentialMarkerKey = null;
|
|
159
170
|
/**
|
|
160
171
|
* #567: fold ONE project string through the boot-resolved alias map — the
|
|
161
172
|
* shared normalization for every project-string entry point in this file
|
|
@@ -955,22 +966,60 @@ async function startServer(options = {}) {
|
|
|
955
966
|
console.warn(`[hicortex] Ignoring invalid confidentialAgents entries: ${resolvedConfidential.dropped.join(", ")} ` +
|
|
956
967
|
`(ids must sanitize like ?agent= — a dropped id means that agent is NOT in the circle)`);
|
|
957
968
|
}
|
|
958
|
-
|
|
959
|
-
|
|
969
|
+
// #609: workspace-path patterns resolve at the SAME boot seam (restart to
|
|
970
|
+
// apply, like the roster). Dropped entries are named once — a dropped
|
|
971
|
+
// pattern matches nothing, so a typo must surface in the log, never as a
|
|
972
|
+
// folder silently staying standard.
|
|
973
|
+
const resolvedConfidentialPaths = (0, classification_js_1.resolveConfidentialPaths)(savedConfig);
|
|
974
|
+
confidentialPathPatterns = resolvedConfidentialPaths.patterns;
|
|
975
|
+
if (resolvedConfidentialPaths.dropped.length > 0) {
|
|
976
|
+
console.warn(`[hicortex] Ignoring invalid confidentialPaths entries: ${resolvedConfidentialPaths.dropped.join(", ")} ` +
|
|
977
|
+
`(entries must be absolute paths or ~/…, with * only as a full segment and ** only as a trailing /** — ` +
|
|
978
|
+
`a dropped pattern matches nothing)`);
|
|
960
979
|
}
|
|
980
|
+
// #614: resolve the marker key at the SAME boot seam (restart to apply).
|
|
981
|
+
// Null = client workspace markers are INERT — see the note below.
|
|
982
|
+
confidentialMarkerKey = (0, classification_js_1.resolveConfidentialMarkerKey)(savedConfig);
|
|
983
|
+
if (confidentialRoster.length > 0 || confidentialPathPatterns.length > 0) {
|
|
984
|
+
console.log(`[hicortex] Confidential circle: ${confidentialRoster.length} agent(s) rostered` +
|
|
985
|
+
`${confidentialPathPatterns.length > 0 ? `, ${confidentialPathPatterns.length} path pattern(s)` : ""}` +
|
|
986
|
+
// #614: name the marker arm's state on the same status line — a keyed
|
|
987
|
+
// marker is the third birthplace signal, and its being armed (or not)
|
|
988
|
+
// is exactly what an operator scanning the boot log needs to see.
|
|
989
|
+
(confidentialMarkerKey !== null ? ", workspace markers keyed" : ""));
|
|
990
|
+
}
|
|
991
|
+
// The two "is the circle active" counts, computed ONCE for the marker-key
|
|
992
|
+
// boot note below and the unconfigured-circle warning after it (the same
|
|
993
|
+
// active predicate, warnIfCircleUnconfigured's).
|
|
994
|
+
const confidentialRowsCount = db
|
|
995
|
+
.prepare("SELECT COUNT(*) AS c FROM memories WHERE privacy = 'confidential'")
|
|
996
|
+
.get().c;
|
|
997
|
+
const queueConfidentialCount = db
|
|
998
|
+
.prepare("SELECT COUNT(*) AS c FROM distill_queue WHERE privacy = 'confidential'")
|
|
999
|
+
.get().c;
|
|
1000
|
+
// #614: absent key + otherwise-active circle → the one-line inert note, so
|
|
1001
|
+
// a marked folder's standard stamps are explained in the log, never silent.
|
|
1002
|
+
// Zero-config installs stay silent (the classification zero-change rule).
|
|
1003
|
+
const markerKeyNote = (0, classification_js_1.confidentialMarkerKeyNote)({
|
|
1004
|
+
markerKey: confidentialMarkerKey,
|
|
1005
|
+
roster: confidentialRoster,
|
|
1006
|
+
patterns: confidentialPathPatterns,
|
|
1007
|
+
confidentialRows: confidentialRowsCount,
|
|
1008
|
+
queueConfidential: queueConfidentialCount,
|
|
1009
|
+
});
|
|
1010
|
+
if (markerKeyNote)
|
|
1011
|
+
console.warn(markerKeyNote);
|
|
961
1012
|
// #332: the ONE loud boot warning when the circle is active without the
|
|
962
|
-
// confidential model. "Active" = roster set OR
|
|
963
|
-
// stored OR confidential items already queued —
|
|
964
|
-
// none of those hold and the warning stays silent
|
|
1013
|
+
// confidential model. "Active" = roster set OR path patterns set (#609) OR
|
|
1014
|
+
// confidential rows already stored OR confidential items already queued —
|
|
1015
|
+
// on a zero-config install none of those hold and the warning stays silent
|
|
1016
|
+
// (AC-2).
|
|
965
1017
|
(0, classification_js_1.warnIfCircleUnconfigured)({
|
|
966
1018
|
roster: confidentialRoster,
|
|
1019
|
+
patterns: confidentialPathPatterns,
|
|
967
1020
|
confidentialLlm,
|
|
968
|
-
confidentialRows:
|
|
969
|
-
|
|
970
|
-
.get().c,
|
|
971
|
-
queueConfidential: db
|
|
972
|
-
.prepare("SELECT COUNT(*) AS c FROM distill_queue WHERE privacy = 'confidential'")
|
|
973
|
-
.get().c,
|
|
1021
|
+
confidentialRows: confidentialRowsCount,
|
|
1022
|
+
queueConfidential: queueConfidentialCount,
|
|
974
1023
|
});
|
|
975
1024
|
// #264 dir migration: rename <hicortex-home>/context/ → identity/ on boot
|
|
976
1025
|
// when only the legacy dir exists. The fallback read in identity-store.ts
|
|
@@ -1462,6 +1511,46 @@ async function startServer(options = {}) {
|
|
|
1462
1511
|
(0, health_js_1.logAndSendInternalError)(res, "identity/mode", err);
|
|
1463
1512
|
}
|
|
1464
1513
|
});
|
|
1514
|
+
// GET/PUT /confidential/marker-key — ONE-COMMAND marker-key provisioning
|
|
1515
|
+
// (#616). The pair behind `hicortex confidential`'s fetch-or-generate flow:
|
|
1516
|
+
// GET answers the EFFECTIVE key (the boot-resolved module var — the value
|
|
1517
|
+
// markers must carry) so a second machine reuses it instead of minting a
|
|
1518
|
+
// second key; PUT registers a generated/chosen key (first machine, or
|
|
1519
|
+
// rotation). Scoped to THIS key only — not a general config API (AC-4).
|
|
1520
|
+
//
|
|
1521
|
+
// Single-writer discipline, the PUT /identity/mode pattern: the key is
|
|
1522
|
+
// normally resolved once at boot, and THIS route is the one live writer.
|
|
1523
|
+
// On a successful PUT the adapter (1) persists through persistConfigUpdates
|
|
1524
|
+
// (survives restarts, unrelated keys untouched) and (2) assigns the
|
|
1525
|
+
// module-level confidentialMarkerKey to the SAME value — a rotation bites
|
|
1526
|
+
// at the NEXT /distill intake with no restart, where an old-marker relay
|
|
1527
|
+
// flips to standard + the #615 refusal warn. A PUT under the
|
|
1528
|
+
// HICORTEX_CONFIDENTIAL_MARKER_KEY env override 409s (the env would shadow
|
|
1529
|
+
// the write — no no-op success; the rule lives in the pure handler).
|
|
1530
|
+
// Bearer-only: the standard auth middleware above, no exemption — the key
|
|
1531
|
+
// is the confidential circle's secret, fetchable by token = owner (the
|
|
1532
|
+
// #616 accepted trade-off). Pure handlers in marker-key-api.ts.
|
|
1533
|
+
app.get("/confidential/marker-key", (_req, res) => {
|
|
1534
|
+
const r = (0, marker_key_api_js_1.handleMarkerKeyGet)(confidentialMarkerKey);
|
|
1535
|
+
res.status(r.status).json(r.body);
|
|
1536
|
+
});
|
|
1537
|
+
app.put("/confidential/marker-key", (req, res) => {
|
|
1538
|
+
try {
|
|
1539
|
+
const r = (0, marker_key_api_js_1.handleMarkerKeyPut)(req.body ?? null, process.env.HICORTEX_CONFIDENTIAL_MARKER_KEY);
|
|
1540
|
+
if (r.status === 200 && r.key !== undefined) {
|
|
1541
|
+
(0, init_js_1.persistConfigUpdates)((0, node_path_1.join)(stateDir, "config.json"), { confidentialMarkerKey: r.key });
|
|
1542
|
+
confidentialMarkerKey = r.key;
|
|
1543
|
+
// One line, never the key value — the operator sees THAT the key
|
|
1544
|
+
// rotated, not WHAT it is (same discipline as the CLI output).
|
|
1545
|
+
console.log("[hicortex] confidentialMarkerKey set — the next delivery with a matching marker stamps confidential; " +
|
|
1546
|
+
"markers carrying a previous key now stamp standard");
|
|
1547
|
+
}
|
|
1548
|
+
res.status(r.status).json(r.body);
|
|
1549
|
+
}
|
|
1550
|
+
catch (err) {
|
|
1551
|
+
(0, health_js_1.logAndSendInternalError)(res, "confidential/marker-key", err);
|
|
1552
|
+
}
|
|
1553
|
+
});
|
|
1465
1554
|
// REST /distill — canonical capture endpoint (0.9.0+).
|
|
1466
1555
|
// Every machine (including the server itself) POSTs denoised session text here.
|
|
1467
1556
|
// The server distills, embeds, stores. Body limit: see `distillBodyLimitMb`
|
|
@@ -1482,7 +1571,23 @@ async function startServer(options = {}) {
|
|
|
1482
1571
|
// NOTE (#332): a client-declared `privacy` body field is IGNORED — the
|
|
1483
1572
|
// classification stamp is server-derived below from source_agent × the
|
|
1484
1573
|
// roster. The field is deliberately not even destructured.
|
|
1485
|
-
|
|
1574
|
+
// NOTE (#614): the pre-#614 `client_confidential` BOOLEAN is ignored the
|
|
1575
|
+
// same way (accepted-and-ignored, deliberately not destructured) — it was
|
|
1576
|
+
// the client-writable classification channel the marker key closes; only
|
|
1577
|
+
// the relayed marker CONTENT (`client_marker`), validated server-side
|
|
1578
|
+
// below, can stamp a delivery confidential from the client end.
|
|
1579
|
+
// #609/#614: `workspace_path` (the session's workspace) and `client_marker`
|
|
1580
|
+
// (the marker file's relayed content) join the destructure — the two
|
|
1581
|
+
// client-carried birthplace signals, composed below. An old client sends
|
|
1582
|
+
// neither; a new client against an old server is a no-op (unknown fields
|
|
1583
|
+
// are never read).
|
|
1584
|
+
const { text, messages, source_agent, source_agent_id, source_domain, source_machine, workspace_path, client_marker, project, session_id, segment_id, session_date } = req.body ?? {};
|
|
1585
|
+
// typeof guards at the one boundary — anything malformed reads as absent.
|
|
1586
|
+
const workspacePath = typeof workspace_path === "string" && workspace_path ? workspace_path : null;
|
|
1587
|
+
// #614: unlike workspace_path, an EMPTY string stays PRESENT — an empty
|
|
1588
|
+
// pre-#614 marker file relays as "" and is refused (warned) below, never
|
|
1589
|
+
// silently treated as "no marker".
|
|
1590
|
+
const clientMarker = typeof client_marker === "string" ? client_marker : null;
|
|
1486
1591
|
// #567: fold the wire project ONCE, right after the destructure — the
|
|
1487
1592
|
// queue enqueue, the sync distill prompt, and the insert opts below all
|
|
1488
1593
|
// carry the canonical value, so an un-upgraded client's raw label never
|
|
@@ -1493,7 +1598,27 @@ async function startServer(options = {}) {
|
|
|
1493
1598
|
// source agent × the boot-resolved roster (deterministic, by birthplace —
|
|
1494
1599
|
// never a content judgment and never client-declared). Every downstream
|
|
1495
1600
|
// landing (queue row, sync insert) carries THIS value.
|
|
1496
|
-
|
|
1601
|
+
// #609: the derivation composes the birthplace signals — roster agent OR
|
|
1602
|
+
// confidentialPaths pattern OR the marker arm.
|
|
1603
|
+
// #614: the marker arm is now KEY-VALIDATED server-side — the boot-resolved
|
|
1604
|
+
// confidentialMarkerKey compared timing-safe against the relayed content
|
|
1605
|
+
// (an absent key makes every marker inert; a refused marker never reduces
|
|
1606
|
+
// a server rule).
|
|
1607
|
+
const derivedPrivacy = (0, classification_js_1.deriveIntakePrivacy)(typeof source_agent === "string" ? source_agent : null, confidentialRoster, {
|
|
1608
|
+
workspacePath,
|
|
1609
|
+
markerContent: clientMarker,
|
|
1610
|
+
markerKey: confidentialMarkerKey,
|
|
1611
|
+
paths: confidentialPathPatterns,
|
|
1612
|
+
});
|
|
1613
|
+
// #614: the rate-limited refusal warn at the intake seam. Marker content
|
|
1614
|
+
// arrived and did NOT validate — no key configured (the arm is inert), or
|
|
1615
|
+
// a mismatch (stale pre-key marker / rotated key / forgery). One guard
|
|
1616
|
+
// covers both cases; warnRefusedMarker itself is once-per-process and
|
|
1617
|
+
// never echoes the content or the key. A matching marker never warns; an
|
|
1618
|
+
// absent marker (null) never warns.
|
|
1619
|
+
if (clientMarker !== null && clientMarker !== confidentialMarkerKey) {
|
|
1620
|
+
(0, classification_js_1.warnRefusedMarker)({ markerKey: confidentialMarkerKey, workspacePath });
|
|
1621
|
+
}
|
|
1497
1622
|
// #422 capture health: normalize the wire fields ONCE so every exit below
|
|
1498
1623
|
// records with a one-liner (recordDistillActivity re-sanitizes machine/
|
|
1499
1624
|
// agent — the builder only forwards + picks the byte count). bytes = the
|
|
@@ -1656,6 +1781,9 @@ async function startServer(options = {}) {
|
|
|
1656
1781
|
source_agent_id,
|
|
1657
1782
|
source_domain,
|
|
1658
1783
|
source_machine,
|
|
1784
|
+
// #609: the workspace path rides the queue row so the drain's inserts
|
|
1785
|
+
// keep it and backfill-privacy can path-match queued rows.
|
|
1786
|
+
workspace_path: workspacePath,
|
|
1659
1787
|
project: canonProjectVal,
|
|
1660
1788
|
session_id,
|
|
1661
1789
|
segment_id,
|
|
@@ -1779,6 +1907,9 @@ async function startServer(options = {}) {
|
|
|
1779
1907
|
// filtered. Default null for older clients that don't send them.
|
|
1780
1908
|
sourceAgentId: typeof source_agent_id === "string" ? source_agent_id : null,
|
|
1781
1909
|
sourceDomain: typeof source_domain === "string" ? source_domain : null,
|
|
1910
|
+
// #609: the workspace path (metadata for the path backfill +
|
|
1911
|
+
// attribution); null for deliveries that carried none.
|
|
1912
|
+
workspacePath,
|
|
1782
1913
|
sourceMachine: storage.sanitizeSourceMachine(source_machine),
|
|
1783
1914
|
// Per-chunk key: "<session_id>[#<segment_id>]#<i>". The prefix
|
|
1784
1915
|
// matches the dedup checks above, so a re-run is idempotent.
|
package/dist/nightly.js
CHANGED
|
@@ -588,9 +588,12 @@ async function runNightly(options = {}) {
|
|
|
588
588
|
const confidentialLlm = resolvedPair.pair?.confidential ?? null;
|
|
589
589
|
const confidentialLlmConfig = resolvedPair.confidentialConfig;
|
|
590
590
|
// #332: the ONE loud warning when the circle is active without the
|
|
591
|
-
// confidential model (daemon boot mirrors this).
|
|
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).
|
|
592
594
|
(0, classification_js_1.warnIfCircleUnconfigured)({
|
|
593
595
|
roster: (0, classification_js_1.resolveConfidentialAgents)(savedConfig).roster,
|
|
596
|
+
patterns: (0, classification_js_1.resolveConfidentialPaths)(savedConfig).patterns,
|
|
594
597
|
confidentialLlm: confidentialLlm ?? confidentialLlmConfig,
|
|
595
598
|
confidentialRows: db.prepare("SELECT COUNT(*) AS c FROM memories WHERE privacy = 'confidential'").get().c,
|
|
596
599
|
queueConfidential: db.prepare("SELECT COUNT(*) AS c FROM distill_queue WHERE privacy = 'confidential'").get().c,
|
|
@@ -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
|
|
|
@@ -5,6 +5,9 @@
|
|
|
5
5
|
* dispatches on the payload):
|
|
6
6
|
* - UserPromptSubmit: POST the prompt to the server's /recall-index; print
|
|
7
7
|
* the returned index block to stdout (CC injects hook stdout as context).
|
|
8
|
+
* #600: the body carries `agent` = the sanitized basename of the session
|
|
9
|
+
* cwd (the workspace folder name IS the agent name) so the server's
|
|
10
|
+
* confidential-circle gate can recognize the session.
|
|
8
11
|
* - SessionStart (startup/resume/clear/compact): POST a reset so the
|
|
9
12
|
* server's per-session shown-set matches the fresh context window.
|
|
10
13
|
*
|
package/dist/recall-hook-cli.js
CHANGED
|
@@ -6,6 +6,9 @@
|
|
|
6
6
|
* dispatches on the payload):
|
|
7
7
|
* - UserPromptSubmit: POST the prompt to the server's /recall-index; print
|
|
8
8
|
* the returned index block to stdout (CC injects hook stdout as context).
|
|
9
|
+
* #600: the body carries `agent` = the sanitized basename of the session
|
|
10
|
+
* cwd (the workspace folder name IS the agent name) so the server's
|
|
11
|
+
* confidential-circle gate can recognize the session.
|
|
9
12
|
* - SessionStart (startup/resume/clear/compact): POST a reset so the
|
|
10
13
|
* server's per-session shown-set matches the fresh context window.
|
|
11
14
|
*
|
|
@@ -58,7 +61,17 @@ function buildHookRequest(payload, cwd = process.cwd()) {
|
|
|
58
61
|
// soft project-affinity boost. basename(cwd) matches capture's
|
|
59
62
|
// decodeProjectDirName for non-hyphenated dirs (the common case); a hyphen
|
|
60
63
|
// edge case is a pre-existing capture bug, filed separately.
|
|
61
|
-
|
|
64
|
+
// #600: the same basename IS the agent id — sent SANITIZED so the server's
|
|
65
|
+
// confidential-circle gate can recognize the session (a rostered workspace
|
|
66
|
+
// reads as a member). A basename that sanitizes to null omits the field
|
|
67
|
+
// entirely (non-member, fail-closed — never an id the server would 400 on).
|
|
68
|
+
// The SessionStart reset above deliberately carries NO agent: a reset
|
|
69
|
+
// returns no rows, so there is nothing to gate.
|
|
70
|
+
const body = { session_id: sessionId, prompt, project: (0, node_path_1.basename)(cwd) };
|
|
71
|
+
const agent = (0, learnings_identity_js_1.workspaceAgentId)(cwd);
|
|
72
|
+
if (agent)
|
|
73
|
+
body.agent = agent;
|
|
74
|
+
return body;
|
|
62
75
|
}
|
|
63
76
|
async function runRecallHook() {
|
|
64
77
|
const cfg = (0, learnings_identity_js_1.resolveConfig)();
|
package/dist/storage.js
CHANGED
|
@@ -134,9 +134,12 @@ function insertMemory(db, content, embedding, opts = {}) {
|
|
|
134
134
|
.prepare(`INSERT OR IGNORE INTO memories
|
|
135
135
|
(id, content, base_strength, last_accessed, access_count,
|
|
136
136
|
created_at, ingested_at, source_agent, source_agent_id, source_session,
|
|
137
|
-
source_domain, project, privacy, memory_type, source_machine)
|
|
138
|
-
VALUES (?, ?, ?, ?, 0, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`)
|
|
139
|
-
.run(id, content, opts.baseStrength ?? 0.5, ts, ts, ingestedTs, opts.sourceAgent ?? "default", opts.sourceAgentId ?? null, sourceSession, opts.sourceDomain ?? null,
|
|
137
|
+
source_domain, workspace_path, project, privacy, memory_type, source_machine)
|
|
138
|
+
VALUES (?, ?, ?, ?, 0, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`)
|
|
139
|
+
.run(id, content, opts.baseStrength ?? 0.5, ts, ts, ingestedTs, opts.sourceAgent ?? "default", opts.sourceAgentId ?? null, sourceSession, opts.sourceDomain ?? null,
|
|
140
|
+
// #609: the workspace path rides the row (metadata for the
|
|
141
|
+
// confidentialPaths match + backfill); null when the delivery had none.
|
|
142
|
+
opts.workspacePath ?? null, opts.project ?? null,
|
|
140
143
|
// #332: 'standard' is the fail-closed default class — a NULL here would
|
|
141
144
|
// pre-date migration v27's normalization and force every read gate to
|
|
142
145
|
// keep a NULL arm forever. Confidential rows always carry an explicit
|
|
@@ -20,6 +20,16 @@ export interface TranscriptBatch {
|
|
|
20
20
|
* `claude-code/<project>`. Lets per-harness readers stamp their own origin.
|
|
21
21
|
*/
|
|
22
22
|
sourceAgent?: string;
|
|
23
|
+
/**
|
|
24
|
+
* The session's workspace path (#609) — the directory the capturing agent
|
|
25
|
+
* worked in (CC: the delta entries' `cwd`; Pi/OC: the session header `cwd`;
|
|
26
|
+
* opencode: `session.directory`). The nightly sends it on every segment
|
|
27
|
+
* POST (`workspace_path`) and walks the confidential marker from it.
|
|
28
|
+
* AUTHORITATIVE over `projectName`, which stays the lossy last-segment
|
|
29
|
+
* label. Null when the harness has no workspace (Hermes — per-profile
|
|
30
|
+
* conversations, no cwd in its store; never invented).
|
|
31
|
+
*/
|
|
32
|
+
workspacePath?: string | null;
|
|
23
33
|
/**
|
|
24
34
|
* Per-session cursor key (`<prefix>:<sessionId>`) — the capture-cursors.json
|
|
25
35
|
* key whose value gates and advances this session's incremental capture (#189).
|
|
@@ -144,6 +144,18 @@ function parseTranscriptFile(filePath, projectName, cursorKey, startCursor, gene
|
|
|
144
144
|
if (timestamps[i])
|
|
145
145
|
lastTimestamp = timestamps[i];
|
|
146
146
|
}
|
|
147
|
+
// #609: the workspace path — the first non-empty `cwd` among the DELTA's
|
|
148
|
+
// entries (CC writes the session's cwd on every entry; the delta slice keeps
|
|
149
|
+
// the value authoritative for what THIS capture covers). projectName stays
|
|
150
|
+
// the lossy directory-name decode — it keeps serving only the label.
|
|
151
|
+
let workspacePath = null;
|
|
152
|
+
for (const entry of delta) {
|
|
153
|
+
const cwd = entry?.cwd;
|
|
154
|
+
if (typeof cwd === "string" && cwd) {
|
|
155
|
+
workspacePath = cwd;
|
|
156
|
+
break;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
147
159
|
return {
|
|
148
160
|
sessionId: (0, node_path_1.basename)(filePath, ".jsonl"),
|
|
149
161
|
projectName,
|
|
@@ -151,6 +163,7 @@ function parseTranscriptFile(filePath, projectName, cursorKey, startCursor, gene
|
|
|
151
163
|
? lastTimestamp.slice(0, 10)
|
|
152
164
|
: new Date().toISOString().slice(0, 10),
|
|
153
165
|
entries: delta,
|
|
166
|
+
workspacePath,
|
|
154
167
|
cursorKey,
|
|
155
168
|
startCursor: start,
|
|
156
169
|
generation: gen,
|
package/dist/types.d.ts
CHANGED
|
@@ -8,11 +8,13 @@
|
|
|
8
8
|
* PERSONAL/SENSITIVE vocabulary is dead; migration v27 maps every legacy
|
|
9
9
|
* value and NULL to 'standard'). 'confidential' is ONLY ever set by the
|
|
10
10
|
* server: derived at intake from `source_agent` × the `confidentialAgents`
|
|
11
|
-
* config roster,
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
11
|
+
* config roster, a `confidentialPaths` workspace match (#609), or marker
|
|
12
|
+
* content validated against the server's `confidentialMarkerKey` (#614) — or
|
|
13
|
+
* stamped by the `backfill-privacy` owner command; the client only RELAYS
|
|
14
|
+
* raw inputs, it never declares the class. The class is a hard gate on every
|
|
15
|
+
* agent-facing read path (absent/unknown requester = non-member =
|
|
16
|
+
* confidential rows omitted, single fetch 404) and routes every LLM touch of
|
|
17
|
+
* confidential text to the separately configured confidential model.
|
|
16
18
|
*/
|
|
17
19
|
export type MemoryPrivacy = "standard" | "confidential";
|
|
18
20
|
/** A stored memory record. */
|
|
@@ -42,6 +44,13 @@ export interface Memory {
|
|
|
42
44
|
* above). NULL when the client declares none. Echoed back on /memory GET.
|
|
43
45
|
*/
|
|
44
46
|
source_domain: string | null;
|
|
47
|
+
/**
|
|
48
|
+
* The workspace path the capture ran in (#609, migration v28) — metadata
|
|
49
|
+
* for the confidentialPaths intake match and the path backfill. Optional
|
|
50
|
+
* because rowToMemory is a cast over SELECT * rows; NULL on every pre-v28
|
|
51
|
+
* row and on deliveries that carried no path (Hermes, pre-#609 clients).
|
|
52
|
+
*/
|
|
53
|
+
workspace_path?: string | null;
|
|
45
54
|
/**
|
|
46
55
|
* The #332 two-level classification ('standard' | 'confidential'; see
|
|
47
56
|
* MemoryPrivacy). NULL only on rows written before migration v27 — the
|
|
@@ -852,6 +861,25 @@ export interface HicortexConfig {
|
|
|
852
861
|
* Boot-time (restart to apply).
|
|
853
862
|
*/
|
|
854
863
|
confidentialAgents?: string[];
|
|
864
|
+
/**
|
|
865
|
+
* #614 — the confidential marker key: the owner-set secret the workspace
|
|
866
|
+
* marker `.hicortex-confidential` must carry (as its single-line content)
|
|
867
|
+
* for a client-marked folder to stamp `confidential` at intake. The client
|
|
868
|
+
* RELAYS the marker's content (`client_marker` on /distill); the server
|
|
869
|
+
* compares it timing-safe against this key — the pre-#614 empty marker (and
|
|
870
|
+
* the `client_confidential` boolean) were a client-writable classification
|
|
871
|
+
* channel any token holder could set, and the key closes it: forgery
|
|
872
|
+
* requires a secret token possession alone does not grant. Distributed
|
|
873
|
+
* like `authToken` — mirror the server's value into each client machine's
|
|
874
|
+
* config.json (the `hicortex confidential` command reads it there) or its
|
|
875
|
+
* env mirror HICORTEX_CONFIDENTIAL_MARKER_KEY (which overrides config on
|
|
876
|
+
* both ends). Absent/blank (the default) = markers INERT, fail-closed both
|
|
877
|
+
* directions: marker-carrying deliveries stamp standard and a boot note
|
|
878
|
+
* names the key when the circle is otherwise active. Boot-time (restart to
|
|
879
|
+
* apply). This is the N=1 form of the per-space key (#613); the marker
|
|
880
|
+
* content evolves to space-id + key without a wire change.
|
|
881
|
+
*/
|
|
882
|
+
confidentialMarkerKey?: string;
|
|
855
883
|
/**
|
|
856
884
|
* #332 — the confidential model's endpoint. With `llmConfidentialApiKey`
|
|
857
885
|
* (both required; `llmConfidentialModel` optional, `llmConfidentialProvider`
|
|
@@ -939,6 +967,14 @@ export interface InsertMemoryOptions {
|
|
|
939
967
|
* only — stamped by the nightly (config `machineName` ?? os.hostname()),
|
|
940
968
|
* accepted optionally from /distill + /ingest. Null on pre-v15 rows. */
|
|
941
969
|
sourceMachine?: string | null;
|
|
970
|
+
/**
|
|
971
|
+
* The delivery's workspace path (#609) — the directory the capturing agent
|
|
972
|
+
* worked in. Metadata only: matched at intake against `confidentialPaths`
|
|
973
|
+
* and stored so `hicortex backfill-privacy` can re-plan by path; never
|
|
974
|
+
* distilled into prompt text. Null on pre-v28 rows, Hermes deliveries (no
|
|
975
|
+
* workspace), and clients that predate the wire field.
|
|
976
|
+
*/
|
|
977
|
+
workspacePath?: string | null;
|
|
942
978
|
project?: string | null;
|
|
943
979
|
/**
|
|
944
980
|
* #332 classification stamp. Absent → 'standard' (the fail-closed default;
|