@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/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,
|
|
@@ -17,6 +17,10 @@
|
|
|
17
17
|
* GET /lessons → episodic memory lessons + memory index, rendered as the
|
|
18
18
|
* existing `## Hicortex Memory` block.
|
|
19
19
|
*
|
|
20
|
+
* #600: both fetches carry `?agent=<sanitized basename of the session cwd>` —
|
|
21
|
+
* the workspace folder name IS the agent name, so a rostered workspace reads
|
|
22
|
+
* as a confidential-circle member server-side (fail-closed otherwise).
|
|
23
|
+
*
|
|
20
24
|
* The two fetches run in Promise.all, each with its OWN 3 s timeout and
|
|
21
25
|
* INDEPENDENT fail-soft: an /identity failure must never cost the lessons
|
|
22
26
|
* block, and vice versa. Sequential fetches would double worst-case
|
|
@@ -43,7 +47,10 @@ export interface ResolvedConfig {
|
|
|
43
47
|
serverUrl: string;
|
|
44
48
|
authToken: string | undefined;
|
|
45
49
|
home: string;
|
|
46
|
-
/**
|
|
50
|
+
/** The resolved config `agentName` (0.13). #600: CONFIG/STATUS-REPORTED
|
|
51
|
+
* ONLY — the hooks no longer send it (the workspace basename is the agent
|
|
52
|
+
* identity on the wire now); `hicortex status` reports it via its own
|
|
53
|
+
* resolveAgentIdentity call. null → unset/invalid config value. */
|
|
47
54
|
agentName: string | null;
|
|
48
55
|
/** Max lessons to inject (config.lessonsLimit, default 10). */
|
|
49
56
|
lessonsLimit?: number;
|
|
@@ -71,6 +78,19 @@ export declare function resolveConfig(): ResolvedConfig | null;
|
|
|
71
78
|
* plus this function are the whole client-side seam).
|
|
72
79
|
*/
|
|
73
80
|
export declare function deriveHookProject(cwd: string, aliases?: Readonly<Record<string, string>> | null): string | null;
|
|
81
|
+
/**
|
|
82
|
+
* #600: the workspace-scoped agent id a CC client sends on its read calls —
|
|
83
|
+
* the SANITIZED basename of the session's working directory (owner ruling
|
|
84
|
+
* 2026-11-17: the workspace folder name IS the agent name, the same basename
|
|
85
|
+
* `project` is derived from; no precedence chain, no configured-name
|
|
86
|
+
* override). The server's confidential-circle gate matches rostered BARE ids
|
|
87
|
+
* here. null when the basename sanitizes to nothing (e.g. "!!!" or "/") → the
|
|
88
|
+
* caller omits the `agent` param entirely, never sending an id the server
|
|
89
|
+
* would 400 on (the fail-soft hook would silently swallow that and drop the
|
|
90
|
+
* whole block). Reuses the package's sanitizeAgentId so client and server
|
|
91
|
+
* agree on the id grammar by construction.
|
|
92
|
+
*/
|
|
93
|
+
export declare function workspaceAgentId(cwd: string): string | null;
|
|
74
94
|
/**
|
|
75
95
|
* Title-case a section name for its heading: split on `-`/`_`, capitalize each
|
|
76
96
|
* word ("user" → "User", "my_notes" → "My Notes").
|
|
@@ -163,9 +183,12 @@ export declare function gateAndRenderIdentity(data: IdentityResponse, harness: s
|
|
|
163
183
|
* Fetch identity + lessons concurrently and return the combined Markdown block,
|
|
164
184
|
* or null when neither yields anything (nothing to inject; caller prints
|
|
165
185
|
* nothing and exits 0). The `## Identity` block is prepended before the existing
|
|
166
|
-
* `## Hicortex Memory` block.
|
|
186
|
+
* `## Hicortex Memory` block. #600: `cwd` is the session's working directory
|
|
187
|
+
* (default process.cwd()) — its sanitized basename is the workspace-scoped
|
|
188
|
+
* agent id both fetches send; the optional parameter is the test seam,
|
|
189
|
+
* mirroring buildHookRequest.
|
|
167
190
|
*/
|
|
168
|
-
export declare function fetchLessonsIdentity(): Promise<string | null>;
|
|
191
|
+
export declare function fetchLessonsIdentity(cwd?: string): Promise<string | null>;
|
|
169
192
|
/** Backcompat alias (#264). */
|
|
170
193
|
export declare const fetchLessonsContext: typeof fetchLessonsIdentity;
|
|
171
194
|
/** Backcompat aliases (#264) for the renamed symbols. */
|
|
@@ -18,6 +18,10 @@
|
|
|
18
18
|
* GET /lessons → episodic memory lessons + memory index, rendered as the
|
|
19
19
|
* existing `## Hicortex Memory` block.
|
|
20
20
|
*
|
|
21
|
+
* #600: both fetches carry `?agent=<sanitized basename of the session cwd>` —
|
|
22
|
+
* the workspace folder name IS the agent name, so a rostered workspace reads
|
|
23
|
+
* as a confidential-circle member server-side (fail-closed otherwise).
|
|
24
|
+
*
|
|
21
25
|
* The two fetches run in Promise.all, each with its OWN 3 s timeout and
|
|
22
26
|
* INDEPENDENT fail-soft: an /identity failure must never cost the lessons
|
|
23
27
|
* block, and vice versa. Sequential fetches would double worst-case
|
|
@@ -31,6 +35,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
31
35
|
exports.gateAndRenderContext = exports.renderContextBlock = exports.fetchLessonsContext = void 0;
|
|
32
36
|
exports.resolveConfig = resolveConfig;
|
|
33
37
|
exports.deriveHookProject = deriveHookProject;
|
|
38
|
+
exports.workspaceAgentId = workspaceAgentId;
|
|
34
39
|
exports.titleCaseSection = titleCaseSection;
|
|
35
40
|
exports.orderSectionNames = orderSectionNames;
|
|
36
41
|
exports.renderIdentityBlock = renderIdentityBlock;
|
|
@@ -67,11 +72,11 @@ function resolveConfig() {
|
|
|
67
72
|
const serverUrl = config.mode === "client" && typeof config.serverUrl === "string"
|
|
68
73
|
? config.serverUrl.replace(/\/+$/, "")
|
|
69
74
|
: `http://127.0.0.1:${config.port ?? DEFAULT_PORT}`;
|
|
70
|
-
// Per-agent identity id (0.13) via the shared resolver, so
|
|
71
|
-
// always matches what `hicortex status` reports.
|
|
72
|
-
//
|
|
73
|
-
// identity
|
|
74
|
-
//
|
|
75
|
+
// Per-agent identity id (0.13) via the shared resolver, so what an install
|
|
76
|
+
// has CONFIGURED always matches what `hicortex status` reports. #600: the
|
|
77
|
+
// hooks no longer send this id — the workspace basename is the agent
|
|
78
|
+
// identity on the wire (see workspaceAgentId); agentName stays
|
|
79
|
+
// config/status-reported only.
|
|
75
80
|
const agentName = (0, identity_store_js_1.resolveAgentIdentity)(config).agentId;
|
|
76
81
|
return {
|
|
77
82
|
serverUrl,
|
|
@@ -98,6 +103,21 @@ function authHeaders(authToken) {
|
|
|
98
103
|
function deriveHookProject(cwd, aliases) {
|
|
99
104
|
return (0, project_canonicalize_js_1.canonicalizeProject)((0, node_path_1.basename)(cwd), aliases);
|
|
100
105
|
}
|
|
106
|
+
/**
|
|
107
|
+
* #600: the workspace-scoped agent id a CC client sends on its read calls —
|
|
108
|
+
* the SANITIZED basename of the session's working directory (owner ruling
|
|
109
|
+
* 2026-11-17: the workspace folder name IS the agent name, the same basename
|
|
110
|
+
* `project` is derived from; no precedence chain, no configured-name
|
|
111
|
+
* override). The server's confidential-circle gate matches rostered BARE ids
|
|
112
|
+
* here. null when the basename sanitizes to nothing (e.g. "!!!" or "/") → the
|
|
113
|
+
* caller omits the `agent` param entirely, never sending an id the server
|
|
114
|
+
* would 400 on (the fail-soft hook would silently swallow that and drop the
|
|
115
|
+
* whole block). Reuses the package's sanitizeAgentId so client and server
|
|
116
|
+
* agree on the id grammar by construction.
|
|
117
|
+
*/
|
|
118
|
+
function workspaceAgentId(cwd) {
|
|
119
|
+
return (0, identity_store_js_1.sanitizeAgentId)((0, node_path_1.basename)(cwd));
|
|
120
|
+
}
|
|
101
121
|
/**
|
|
102
122
|
* Trust framing + provenance for the injected lessons block (#516). The
|
|
103
123
|
* fence + two lines are byte-identical on every client surface (CC hook,
|
|
@@ -112,9 +132,17 @@ const MEMORY_PROVENANCE = "Provenance: auto-distilled by Hicortex from this memo
|
|
|
112
132
|
/**
|
|
113
133
|
* Fetch /lessons and build the `## Hicortex Memory` block, or null on any
|
|
114
134
|
* failure (missing/non-2xx/parse). Preserves the pre-0.12 behavior exactly.
|
|
135
|
+
* #600: `cwd` is the session's working directory (default process.cwd()) —
|
|
136
|
+
* the sanitized basename rides the request as `?agent=` (confidential lessons
|
|
137
|
+
* are member-gated server-side) and feeds the project fold. A null-sanitizing
|
|
138
|
+
* basename → bare /lessons (non-member, fail-closed).
|
|
115
139
|
*/
|
|
116
|
-
async function fetchLessonsBlock(cfg) {
|
|
117
|
-
const
|
|
140
|
+
async function fetchLessonsBlock(cfg, cwd = process.cwd()) {
|
|
141
|
+
const agent = workspaceAgentId(cwd);
|
|
142
|
+
const url = agent
|
|
143
|
+
? `${cfg.serverUrl}/lessons?agent=${encodeURIComponent(agent)}`
|
|
144
|
+
: `${cfg.serverUrl}/lessons`;
|
|
145
|
+
const resp = await fetch(url, {
|
|
118
146
|
headers: authHeaders(cfg.authToken),
|
|
119
147
|
signal: AbortSignal.timeout(3000),
|
|
120
148
|
});
|
|
@@ -129,7 +157,7 @@ async function fetchLessonsBlock(cfg) {
|
|
|
129
157
|
// This enables in-project + same-domain lesson boosting on the CC path.
|
|
130
158
|
// #567: folded through the shared canonicalizer so the local label
|
|
131
159
|
// compares equal to the canonical server corpus (see deriveHookProject).
|
|
132
|
-
const project = deriveHookProject(
|
|
160
|
+
const project = deriveHookProject(cwd, cfg.projectAliases);
|
|
133
161
|
const selected = await (0, extensions_js_1.getLessonSelector)().select(data.lessons, { maxLessons, moduleIndex, project });
|
|
134
162
|
const lessonLines = selected.map((l) => {
|
|
135
163
|
const typeMatch = l.content.match(/\*\*Type:\*\* (\w+)/);
|
|
@@ -296,14 +324,20 @@ function gateAndRenderIdentity(data, harness, opts) {
|
|
|
296
324
|
* Fetch /identity and build the `## Identity` block, or null when nothing should
|
|
297
325
|
* be injected: non-2xx, this harness not in `clients`, no sections, or all
|
|
298
326
|
* sections empty. Throws propagate to the caller's fail-soft catch.
|
|
327
|
+
* #600: `cwd` is the session's working directory (default process.cwd()) —
|
|
328
|
+
* its sanitized basename is the workspace-scoped identity sent as `?agent=`.
|
|
299
329
|
*/
|
|
300
|
-
async function fetchIdentityBlock(cfg) {
|
|
330
|
+
async function fetchIdentityBlock(cfg, cwd = process.cwd()) {
|
|
301
331
|
// Send ?agent= only when we have a valid id; the server does the merge and
|
|
302
332
|
// returns the resolved sections, so the hook stays dumb (no client-side mode
|
|
303
|
-
// logic).
|
|
304
|
-
//
|
|
305
|
-
|
|
306
|
-
|
|
333
|
+
// logic). #600: the id is the SANITIZED WORKSPACE BASENAME (owner ruling
|
|
334
|
+
// 2026-11-17: the folder name IS the agent name — it replaces the configured
|
|
335
|
+
// agentName on the hook path, which stays config/status-reported only). A
|
|
336
|
+
// null id (a basename that sanitizes to nothing) → bare /identity → the
|
|
337
|
+
// shared global set.
|
|
338
|
+
const id = workspaceAgentId(cwd);
|
|
339
|
+
const url = id
|
|
340
|
+
? `${cfg.serverUrl}/identity?agent=${encodeURIComponent(id)}`
|
|
307
341
|
: `${cfg.serverUrl}/identity`;
|
|
308
342
|
const resp = await fetch(url, {
|
|
309
343
|
headers: authHeaders(cfg.authToken),
|
|
@@ -323,9 +357,12 @@ async function fetchIdentityBlock(cfg) {
|
|
|
323
357
|
* Fetch identity + lessons concurrently and return the combined Markdown block,
|
|
324
358
|
* or null when neither yields anything (nothing to inject; caller prints
|
|
325
359
|
* nothing and exits 0). The `## Identity` block is prepended before the existing
|
|
326
|
-
* `## Hicortex Memory` block.
|
|
360
|
+
* `## Hicortex Memory` block. #600: `cwd` is the session's working directory
|
|
361
|
+
* (default process.cwd()) — its sanitized basename is the workspace-scoped
|
|
362
|
+
* agent id both fetches send; the optional parameter is the test seam,
|
|
363
|
+
* mirroring buildHookRequest.
|
|
327
364
|
*/
|
|
328
|
-
async function fetchLessonsIdentity() {
|
|
365
|
+
async function fetchLessonsIdentity(cwd = process.cwd()) {
|
|
329
366
|
const cfg = resolveConfig();
|
|
330
367
|
if (!cfg)
|
|
331
368
|
return null;
|
|
@@ -333,8 +370,8 @@ async function fetchLessonsIdentity() {
|
|
|
333
370
|
// other. Promise.all runs them concurrently — each carries its own 3 s
|
|
334
371
|
// timeout, so worst-case latency stays ~3 s, not ~6 s (spec §7).
|
|
335
372
|
const [identityBlock, lessonsBlock] = await Promise.all([
|
|
336
|
-
fetchIdentityBlock(cfg).catch(() => null),
|
|
337
|
-
fetchLessonsBlock(cfg).catch(() => null),
|
|
373
|
+
fetchIdentityBlock(cfg, cwd).catch(() => null),
|
|
374
|
+
fetchLessonsBlock(cfg, cwd).catch(() => null),
|
|
338
375
|
]);
|
|
339
376
|
const blocks = [identityBlock, lessonsBlock].filter((b) => b !== null && b !== "");
|
|
340
377
|
if (blocks.length === 0)
|
|
@@ -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
|
+
}
|