@gamaze/hicortex 0.27.0 → 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 +14 -11
- 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/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/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/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
|
@@ -905,6 +905,29 @@ const MIGRATIONS = [
|
|
|
905
905
|
WHERE privacy IS NULL OR privacy NOT IN ('standard', 'confidential')`);
|
|
906
906
|
},
|
|
907
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
|
+
},
|
|
908
931
|
];
|
|
909
932
|
/**
|
|
910
933
|
* Run all pending migrations against the database.
|
package/dist/distill-queue.d.ts
CHANGED
|
@@ -44,6 +44,13 @@ export interface DistillQueueRow {
|
|
|
44
44
|
source_agent: string | null;
|
|
45
45
|
source_agent_id: string | null;
|
|
46
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;
|
|
47
54
|
source_machine: string | null;
|
|
48
55
|
project: string | null;
|
|
49
56
|
session_date: string | null;
|
|
@@ -70,6 +77,8 @@ export interface EnqueueDistillInput {
|
|
|
70
77
|
source_agent_id?: unknown;
|
|
71
78
|
source_domain?: unknown;
|
|
72
79
|
source_machine?: unknown;
|
|
80
|
+
/** #609: the delivery's workspace path (wire `workspace_path`). */
|
|
81
|
+
workspace_path?: unknown;
|
|
73
82
|
project?: unknown;
|
|
74
83
|
session_id?: unknown;
|
|
75
84
|
segment_id?: unknown;
|
package/dist/distill-queue.js
CHANGED
|
@@ -96,9 +96,12 @@ 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.
|
|
@@ -435,6 +438,10 @@ async function drainDistillQueue(db, opts) {
|
|
|
435
438
|
sourceAgent: item.source_agent ?? "unknown",
|
|
436
439
|
sourceAgentId: item.source_agent_id,
|
|
437
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,
|
|
438
445
|
sourceMachine: storage.sanitizeSourceMachine(item.source_machine),
|
|
439
446
|
sourceSession: sourcePrefix ? `${sourcePrefix}#${i}` : undefined,
|
|
440
447
|
project: canonProject ?? undefined,
|
|
@@ -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,
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure handlers for GET/PUT `/confidential/marker-key` (#616) — the narrow
|
|
3
|
+
* authenticated pair behind ONE-COMMAND marker-key provisioning.
|
|
4
|
+
*
|
|
5
|
+
* The problem (#616): `hicortex confidential` (#614) requires the server's
|
|
6
|
+
* `confidentialMarkerKey` on the machine it runs on, and distributing it by
|
|
7
|
+
* hand (mirror into each client's config.json, or export its env mirror) is
|
|
8
|
+
* ceremony an owner does once per machine. The fix keeps the client's ONE
|
|
9
|
+
* existing credential: the machine already holds the server URL + authToken,
|
|
10
|
+
* so the command can FETCH the key (second machine: no new key generated) or
|
|
11
|
+
* GENERATE one and REGISTER it with the server (first machine ever) — one
|
|
12
|
+
* command on the client, key on the server, done.
|
|
13
|
+
*
|
|
14
|
+
* Scope discipline (AC-4): this is NOT a general config-read/config-write
|
|
15
|
+
* API. GET answers the EFFECTIVE key and NOTHING else; PUT accepts the key
|
|
16
|
+
* and NOTHING else. Anything richer would turn the bearer token into a
|
|
17
|
+
* config exfiltration/write surface it deliberately is not today.
|
|
18
|
+
*
|
|
19
|
+
* Accepted trade-off (owner ruling on the issue — do not re-litigate): the
|
|
20
|
+
* key is fetchable by token, which collapses the marker key's barrier to
|
|
21
|
+
* token = owner. Fine: the marker key's real protection is against workspace
|
|
22
|
+
* processes WITHOUT the token/config access (a shell script or agent reading
|
|
23
|
+
* the marker file cannot forge one); a token holder can already POST
|
|
24
|
+
* arbitrary content (the #599 F5 ruling).
|
|
25
|
+
*
|
|
26
|
+
* Layout follows the identity-store.ts precedent: pure, side-effect-free
|
|
27
|
+
* handlers HERE (validation + response shaping), thin adapters in
|
|
28
|
+
* mcp-server.ts that own the I/O — fresh-config read, persistConfigUpdates,
|
|
29
|
+
* and the live-assign of the boot-resolved module-level key so a rotation
|
|
30
|
+
* bites at the NEXT /distill intake with NO restart (the PUT /identity/mode
|
|
31
|
+
* single-writer pattern: boot and this route are the only writers, never
|
|
32
|
+
* both at once).
|
|
33
|
+
*/
|
|
34
|
+
/**
|
|
35
|
+
* GET's result: the EFFECTIVE marker key — the value the daemon validates
|
|
36
|
+
* relays against (the boot-resolved module var in mcp-server.ts, i.e.
|
|
37
|
+
* env-resolved-first like resolveConfidentialMarkerKey, because that is the
|
|
38
|
+
* value markers must carry). null = no key configured = client markers are
|
|
39
|
+
* INERT (the #614 fail-closed default; a caller may then provision one).
|
|
40
|
+
* The body is exactly `{key}` — no other config ever rides along.
|
|
41
|
+
*/
|
|
42
|
+
export declare function handleMarkerKeyGet(effectiveKey: string | null): {
|
|
43
|
+
status: 200;
|
|
44
|
+
body: {
|
|
45
|
+
key: string | null;
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
export interface MarkerKeyPutResult {
|
|
49
|
+
status: number;
|
|
50
|
+
body: Record<string, unknown>;
|
|
51
|
+
/**
|
|
52
|
+
* Present ONLY on 200: the validated, trimmed key the adapter persists
|
|
53
|
+
* (config `confidentialMarkerKey`) and live-applies. Never echoed in
|
|
54
|
+
* `body` — the response is `{ok:true}` and nothing else.
|
|
55
|
+
*/
|
|
56
|
+
key?: string;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* PUT's validation, in order (each failure answers before any write):
|
|
60
|
+
*
|
|
61
|
+
* 400 — the body is not `{key: string}` with a non-blank, single-line value.
|
|
62
|
+
* The marker file is ONE line (readConfidentialMarker takes the trimmed
|
|
63
|
+
* first line), so a key containing `\n`/`\r` can never round-trip; a blank
|
|
64
|
+
* key would arm nothing (blank never validates — resolveConfidentialMarkerKey
|
|
65
|
+
* reads blank as unset, so the daemon would stay keyless = inert).
|
|
66
|
+
*
|
|
67
|
+
* 409 — the server runs under the `HICORTEX_CONFIDENTIAL_MARKER_KEY` env
|
|
68
|
+
* override. The env SHADOWS config on every boot, so a PUT here would
|
|
69
|
+
* persist a key that is never read — a no-op disguised as success. Blank
|
|
70
|
+
* env = unset (the same rule resolveConfidentialMarkerKey applies). The
|
|
71
|
+
* operator unsets the env and restarts to manage the key through this
|
|
72
|
+
* endpoint/config; hand-edited config still needs a restart either way.
|
|
73
|
+
*
|
|
74
|
+
* 200 — `{ok:true}` + the key for the adapter. The response never echoes
|
|
75
|
+
* the key value (log/response discipline shared with the CLI output).
|
|
76
|
+
*/
|
|
77
|
+
export declare function handleMarkerKeyPut(body: unknown,
|
|
78
|
+
/** The live env override (the adapter passes process.env…; set-and-non-blank ⇒ 409). */
|
|
79
|
+
envOverride: string | undefined): MarkerKeyPutResult;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Pure handlers for GET/PUT `/confidential/marker-key` (#616) — the narrow
|
|
4
|
+
* authenticated pair behind ONE-COMMAND marker-key provisioning.
|
|
5
|
+
*
|
|
6
|
+
* The problem (#616): `hicortex confidential` (#614) requires the server's
|
|
7
|
+
* `confidentialMarkerKey` on the machine it runs on, and distributing it by
|
|
8
|
+
* hand (mirror into each client's config.json, or export its env mirror) is
|
|
9
|
+
* ceremony an owner does once per machine. The fix keeps the client's ONE
|
|
10
|
+
* existing credential: the machine already holds the server URL + authToken,
|
|
11
|
+
* so the command can FETCH the key (second machine: no new key generated) or
|
|
12
|
+
* GENERATE one and REGISTER it with the server (first machine ever) — one
|
|
13
|
+
* command on the client, key on the server, done.
|
|
14
|
+
*
|
|
15
|
+
* Scope discipline (AC-4): this is NOT a general config-read/config-write
|
|
16
|
+
* API. GET answers the EFFECTIVE key and NOTHING else; PUT accepts the key
|
|
17
|
+
* and NOTHING else. Anything richer would turn the bearer token into a
|
|
18
|
+
* config exfiltration/write surface it deliberately is not today.
|
|
19
|
+
*
|
|
20
|
+
* Accepted trade-off (owner ruling on the issue — do not re-litigate): the
|
|
21
|
+
* key is fetchable by token, which collapses the marker key's barrier to
|
|
22
|
+
* token = owner. Fine: the marker key's real protection is against workspace
|
|
23
|
+
* processes WITHOUT the token/config access (a shell script or agent reading
|
|
24
|
+
* the marker file cannot forge one); a token holder can already POST
|
|
25
|
+
* arbitrary content (the #599 F5 ruling).
|
|
26
|
+
*
|
|
27
|
+
* Layout follows the identity-store.ts precedent: pure, side-effect-free
|
|
28
|
+
* handlers HERE (validation + response shaping), thin adapters in
|
|
29
|
+
* mcp-server.ts that own the I/O — fresh-config read, persistConfigUpdates,
|
|
30
|
+
* and the live-assign of the boot-resolved module-level key so a rotation
|
|
31
|
+
* bites at the NEXT /distill intake with NO restart (the PUT /identity/mode
|
|
32
|
+
* single-writer pattern: boot and this route are the only writers, never
|
|
33
|
+
* both at once).
|
|
34
|
+
*/
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.handleMarkerKeyGet = handleMarkerKeyGet;
|
|
37
|
+
exports.handleMarkerKeyPut = handleMarkerKeyPut;
|
|
38
|
+
/**
|
|
39
|
+
* GET's result: the EFFECTIVE marker key — the value the daemon validates
|
|
40
|
+
* relays against (the boot-resolved module var in mcp-server.ts, i.e.
|
|
41
|
+
* env-resolved-first like resolveConfidentialMarkerKey, because that is the
|
|
42
|
+
* value markers must carry). null = no key configured = client markers are
|
|
43
|
+
* INERT (the #614 fail-closed default; a caller may then provision one).
|
|
44
|
+
* The body is exactly `{key}` — no other config ever rides along.
|
|
45
|
+
*/
|
|
46
|
+
function handleMarkerKeyGet(effectiveKey) {
|
|
47
|
+
return { status: 200, body: { key: effectiveKey } };
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* PUT's validation, in order (each failure answers before any write):
|
|
51
|
+
*
|
|
52
|
+
* 400 — the body is not `{key: string}` with a non-blank, single-line value.
|
|
53
|
+
* The marker file is ONE line (readConfidentialMarker takes the trimmed
|
|
54
|
+
* first line), so a key containing `\n`/`\r` can never round-trip; a blank
|
|
55
|
+
* key would arm nothing (blank never validates — resolveConfidentialMarkerKey
|
|
56
|
+
* reads blank as unset, so the daemon would stay keyless = inert).
|
|
57
|
+
*
|
|
58
|
+
* 409 — the server runs under the `HICORTEX_CONFIDENTIAL_MARKER_KEY` env
|
|
59
|
+
* override. The env SHADOWS config on every boot, so a PUT here would
|
|
60
|
+
* persist a key that is never read — a no-op disguised as success. Blank
|
|
61
|
+
* env = unset (the same rule resolveConfidentialMarkerKey applies). The
|
|
62
|
+
* operator unsets the env and restarts to manage the key through this
|
|
63
|
+
* endpoint/config; hand-edited config still needs a restart either way.
|
|
64
|
+
*
|
|
65
|
+
* 200 — `{ok:true}` + the key for the adapter. The response never echoes
|
|
66
|
+
* the key value (log/response discipline shared with the CLI output).
|
|
67
|
+
*/
|
|
68
|
+
function handleMarkerKeyPut(body,
|
|
69
|
+
/** The live env override (the adapter passes process.env…; set-and-non-blank ⇒ 409). */
|
|
70
|
+
envOverride) {
|
|
71
|
+
if (body === null || typeof body !== "object" || Array.isArray(body)) {
|
|
72
|
+
return { status: 400, body: { error: 'Body must be a JSON object: {"key": "<single-line value>"}' } };
|
|
73
|
+
}
|
|
74
|
+
const raw = body.key;
|
|
75
|
+
if (typeof raw !== "string") {
|
|
76
|
+
return { status: 400, body: { error: "'key' must be a string" } };
|
|
77
|
+
}
|
|
78
|
+
if (/[\r\n]/.test(raw)) {
|
|
79
|
+
return { status: 400, body: { error: "'key' must be single-line — the marker file is one line" } };
|
|
80
|
+
}
|
|
81
|
+
const key = raw.trim();
|
|
82
|
+
if (!key) {
|
|
83
|
+
return { status: 400, body: { error: "'key' must not be blank — a blank key never validates" } };
|
|
84
|
+
}
|
|
85
|
+
if (typeof envOverride === "string" && envOverride.trim()) {
|
|
86
|
+
return {
|
|
87
|
+
status: 409,
|
|
88
|
+
body: {
|
|
89
|
+
error: "HICORTEX_CONFIDENTIAL_MARKER_KEY is set on this server and overrides config — " +
|
|
90
|
+
"a key written here would be shadowed on every boot. Unset the env (and restart) " +
|
|
91
|
+
"to manage the key through this endpoint or config.json.",
|
|
92
|
+
},
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
return { status: 200, body: { ok: true }, key };
|
|
96
|
+
}
|
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
|
*
|