@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/classification.d.ts
CHANGED
|
@@ -8,7 +8,12 @@
|
|
|
8
8
|
* `identityAgents` / `?agent=`). Captures whose `source_agent` is rostered
|
|
9
9
|
* are stamped `confidential` at intake — server-derived, deterministic, by
|
|
10
10
|
* birthplace; never a content judgment (content classification was rejected,
|
|
11
|
-
* #197) and never client-declared.
|
|
11
|
+
* #197) and never client-declared. The workspace marker (#609/#614) is
|
|
12
|
+
* client-RELAYED but server-VALIDATED: the marker file carries the owner-set
|
|
13
|
+
* `confidentialMarkerKey` as its content, compared timing-safe at intake —
|
|
14
|
+
* marker content without the key never stamps (the client-writable
|
|
15
|
+
* classification channel #614 closes; an unkeyed install ignores markers
|
|
16
|
+
* entirely, fail-closed both directions). Every agent-facing read path accepts an
|
|
12
17
|
* optional `agent` requester id: absent or unknown = non-member = HARD OMIT
|
|
13
18
|
* of confidential rows (fail-closed both ends — unrostered sources are
|
|
14
19
|
* standard, unknown requesters are non-members). The circle is ADDITIVE:
|
|
@@ -50,12 +55,126 @@ export declare function resolveConfidentialAgents(config: Record<string, unknown
|
|
|
50
55
|
* roster's sanitized (lowercased) form.
|
|
51
56
|
*/
|
|
52
57
|
export declare function isConfidentialSourceAgent(sourceAgent: string | null | undefined, roster: string[]): boolean;
|
|
58
|
+
/**
|
|
59
|
+
* One validated `confidentialPaths` entry, compiled once at boot (the
|
|
60
|
+
* resolveConfidentialAgents pattern). The three match forms are deliberately
|
|
61
|
+
* tiny — no glob library, no character classes, no brace expansion — so the
|
|
62
|
+
* auditable surface is exactly what the spec rules:
|
|
63
|
+
* - absolute exact path (`/home/alice/finance`);
|
|
64
|
+
* - `*` as a FULL path segment — matches exactly ONE segment (a lone-star
|
|
65
|
+
* segment between /home/ and /finance matches any single middle segment);
|
|
66
|
+
* - trailing `/**` — the whole subtree INCLUDING the prefix itself
|
|
67
|
+
* (`/home/alice/**` matches `/home/alice`);
|
|
68
|
+
* - a leading `~/` matches any single home prefix STRUCTURALLY
|
|
69
|
+
* (`/home/<user>/…` or `/Users/<user>/…`) so one entry covers a
|
|
70
|
+
* multi-OS fleet.
|
|
71
|
+
* Comparison normalizes separators to `/` + Unicode NFC and is
|
|
72
|
+
* case-insensitive — over-match is the fail-closed direction (more
|
|
73
|
+
* confidential, never less).
|
|
74
|
+
*/
|
|
75
|
+
export interface ConfidentialPathPattern {
|
|
76
|
+
/** The raw config entry as written (boot warnings, backfill reports). */
|
|
77
|
+
raw: string;
|
|
78
|
+
/** Leading `~/` — match any user's home directory as the prefix. */
|
|
79
|
+
home: boolean;
|
|
80
|
+
/** Trailing `/**` — prefix match including the prefix path itself. */
|
|
81
|
+
subtree: boolean;
|
|
82
|
+
/** Normalized segments of the literal part; `"*"` = exactly one segment. */
|
|
83
|
+
segments: string[];
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Resolve the `confidentialPaths` config value into validated patterns.
|
|
87
|
+
* Entries that do not compile are dropped and their raw values returned in
|
|
88
|
+
* `dropped` for a one-time boot warning (a dropped pattern matches nothing —
|
|
89
|
+
* the operator learns from the log, not from a folder silently staying
|
|
90
|
+
* standard). Duplicates (same raw entry) collapse. Absent/non-array/empty →
|
|
91
|
+
* no patterns, nothing dropped — the zero-change default.
|
|
92
|
+
*/
|
|
93
|
+
export declare function resolveConfidentialPaths(config: Record<string, unknown> | null | undefined): {
|
|
94
|
+
patterns: ConfidentialPathPattern[];
|
|
95
|
+
dropped: string[];
|
|
96
|
+
};
|
|
97
|
+
/**
|
|
98
|
+
* The pure matcher: does `workspacePath` fall under any resolved pattern?
|
|
99
|
+
* Empty pattern list matches nothing (and the zero-change default is exactly
|
|
100
|
+
* that); a null/empty path matches nothing (Hermes has no workspace — path
|
|
101
|
+
* signals never fire there). No fs access — callers pass the delivery's
|
|
102
|
+
* declared workspace path; the server decides (the client never knows the
|
|
103
|
+
* patterns).
|
|
104
|
+
*/
|
|
105
|
+
export declare function matchesConfidentialPath(workspacePath: string | null | undefined, patterns: ConfidentialPathPattern[]): boolean;
|
|
106
|
+
/**
|
|
107
|
+
* Constant-time marker-content × key comparison (#614) — the safeBearerMatch
|
|
108
|
+
* pattern (viz.ts auth). `crypto.timingSafeEqual` THROWS RangeError on
|
|
109
|
+
* mismatched buffer lengths, so the length check MUST gate the call; the
|
|
110
|
+
* short-circuit leaks only the CONTENT length, which is already visible on
|
|
111
|
+
* the wire (the delivery body carries the content verbatim) — the key bytes
|
|
112
|
+
* are never compared byte-by-byte through a timing side channel. Empty
|
|
113
|
+
* content never matches: an empty (pre-#614) marker file is inert by DESIGN,
|
|
114
|
+
* not by luck of the length gate.
|
|
115
|
+
*/
|
|
116
|
+
export declare function safeMarkerKeyEqual(markerContent: string, key: string): boolean;
|
|
117
|
+
/**
|
|
118
|
+
* Resolve the `confidentialMarkerKey` (#614) — the owner-set secret a
|
|
119
|
+
* workspace marker must carry for its folder to stamp confidential at
|
|
120
|
+
* intake. Precedence: env `HICORTEX_CONFIDENTIAL_MARKER_KEY` OVERRIDES the
|
|
121
|
+
* config value (the env-last-word ops override, so a restart-free rotation
|
|
122
|
+
* or override path exists beside the file), then the config value through
|
|
123
|
+
* the readStringConfig boundary (wrong type warns + null — never coerced;
|
|
124
|
+
* a JSON slip like a number cannot silently arm the arm). Blank/absent →
|
|
125
|
+
* null = the marker arm is INERT: no key configured means client markers
|
|
126
|
+
* are ignored entirely (fail-closed both directions — the empty-marker
|
|
127
|
+
* attack surface ships disabled by default, AC-1). Boot-time like the
|
|
128
|
+
* roster; restart to apply. Distributed like authToken: mirror the server's
|
|
129
|
+
* value into each client machine's config.json (or its env).
|
|
130
|
+
*/
|
|
131
|
+
export declare function resolveConfidentialMarkerKey(config: Record<string, unknown> | null | undefined): string | null;
|
|
53
132
|
/**
|
|
54
133
|
* The intake-side derivation: which class a delivery from `sourceAgent`
|
|
55
134
|
* stores as. Fail-closed by construction — anything unattributed or
|
|
56
135
|
* unrostered is `standard` (the global pool).
|
|
136
|
+
*
|
|
137
|
+
* #609/#614 composition invariant: confidential iff roster agent OR server
|
|
138
|
+
* path pattern OR VALIDATED marker content. The marker arm is key-gated
|
|
139
|
+
* (#614): the delivery's relayed marker CONTENT must equal the boot-resolved
|
|
140
|
+
* `confidentialMarkerKey` (timing-safe, server-side — a client-side match is
|
|
141
|
+
* never trusted, the client only relays). An absent key makes every marker
|
|
142
|
+
* inert (the empty-marker client-writable channel is closed), and a
|
|
143
|
+
* present-but-refused marker never reduces a server rule (markers only add,
|
|
144
|
+
* never subtract — safe because a token holder can already POST arbitrary
|
|
145
|
+
* content, the #599 F5 ruling, token = owner). The optional third argument
|
|
146
|
+
* keeps every existing caller byte-identical (no signals = the #332
|
|
147
|
+
* agent-only rule).
|
|
148
|
+
*/
|
|
149
|
+
export declare function deriveIntakePrivacy(sourceAgent: string | null | undefined, roster: string[], signals?: IntakeWorkspaceSignals): MemoryPrivacy;
|
|
150
|
+
/**
|
|
151
|
+
* The #609/#614 workspace birthplace signals `deriveIntakePrivacy` composes
|
|
152
|
+
* with the roster. Every field optional/nullable — a delivery from a harness
|
|
153
|
+
* with no workspace (Hermes) or a pre-#609 client carries none of them.
|
|
57
154
|
*/
|
|
58
|
-
export
|
|
155
|
+
export interface IntakeWorkspaceSignals {
|
|
156
|
+
/** The delivery's workspace path (wire `workspace_path`). Null/absent when
|
|
157
|
+
* unknown — never invented client-side. */
|
|
158
|
+
workspacePath?: string | null;
|
|
159
|
+
/**
|
|
160
|
+
* #614: the relayed marker content (wire `client_marker`) — the trimmed
|
|
161
|
+
* first line of `.hicortex-confidential` at the workspace or an ancestor
|
|
162
|
+
* (readConfidentialMarker in capture.ts). Null/absent = no marker found;
|
|
163
|
+
* "" = a marker file exists but is empty (the pre-#614 shape — present,
|
|
164
|
+
* never valid). The field's MEANING is "what the marker carried" (a key
|
|
165
|
+
* today, a space-id + key pair later, #613) — validity is decided HERE,
|
|
166
|
+
* against `markerKey`, never client-side.
|
|
167
|
+
*/
|
|
168
|
+
markerContent?: string | null;
|
|
169
|
+
/**
|
|
170
|
+
* #614: the boot-resolved `confidentialMarkerKey`
|
|
171
|
+
* (resolveConfidentialMarkerKey). Null = markers INERT — no key, no
|
|
172
|
+
* marker-derived stamp (fail-closed both directions).
|
|
173
|
+
*/
|
|
174
|
+
markerKey?: string | null;
|
|
175
|
+
/** Boot-resolved confidentialPaths patterns (resolveConfidentialPaths). */
|
|
176
|
+
paths?: ConfidentialPathPattern[];
|
|
177
|
+
}
|
|
59
178
|
/**
|
|
60
179
|
* The read-side membership check: is the requester a circle member? Absent,
|
|
61
180
|
* blank, or unknown `agent` → false (fail-closed: an unknown id can never
|
|
@@ -136,18 +255,61 @@ export declare function resolveLlmPair(savedConfig: Record<string, unknown> | nu
|
|
|
136
255
|
*/
|
|
137
256
|
export declare function clientForPool(pair: LlmPair, privacy: MemoryPrivacy | null | undefined): LlmClient | null;
|
|
138
257
|
/**
|
|
139
|
-
* The ONE loud boot warning when the circle is ACTIVE (a roster
|
|
140
|
-
* configured, OR confidential rows exist, OR
|
|
141
|
-
* but the confidential model is not. Called at
|
|
142
|
-
* prints once per call site (the callers are
|
|
143
|
-
* names the exposure and the HOLD behavior —
|
|
144
|
-
* logs that deliveries are piling up, not
|
|
145
|
-
* model. Returns whether the warning fired
|
|
146
|
-
* their own log lines).
|
|
258
|
+
* The ONE loud boot warning when the circle is ACTIVE (a roster OR
|
|
259
|
+
* confidentialPaths patterns are configured, OR confidential rows exist, OR
|
|
260
|
+
* confidential items sit queued) but the confidential model is not. Called at
|
|
261
|
+
* daemon boot and nightly start; prints once per call site (the callers are
|
|
262
|
+
* once-per-process). The wording names the exposure and the HOLD behavior —
|
|
263
|
+
* the operator learns from the logs that deliveries are piling up, not
|
|
264
|
+
* silently distilling on the main model. Returns whether the warning fired
|
|
265
|
+
* (tests + callers that compose their own log lines).
|
|
147
266
|
*/
|
|
148
267
|
export declare function warnIfCircleUnconfigured(opts: {
|
|
149
268
|
roster: string[];
|
|
269
|
+
/** #609: boot-resolved confidentialPaths patterns — configured patterns
|
|
270
|
+
* activate the circle exactly like a roster (deliveries can derive
|
|
271
|
+
* confidential with no rostered agent involved). Absent = none. */
|
|
272
|
+
patterns?: ConfidentialPathPattern[];
|
|
150
273
|
confidentialLlm: LlmClient | LlmConfig | null;
|
|
151
274
|
confidentialRows: number;
|
|
152
275
|
queueConfidential: number;
|
|
153
276
|
}): boolean;
|
|
277
|
+
/**
|
|
278
|
+
* The boot note when the circle is ACTIVE but the marker key is not (#614):
|
|
279
|
+
* one line naming `confidentialMarkerKey` and that client workspace markers
|
|
280
|
+
* are IGNORED (inert) until it is set — an operator running a marked folder
|
|
281
|
+
* learns from the log why it stamps standard, not from silently
|
|
282
|
+
* unclassified captures. Fires ONLY when the key is absent AND the circle is
|
|
283
|
+
* otherwise active (the SAME active predicate as warnIfCircleUnconfigured:
|
|
284
|
+
* roster, confidentialPaths patterns, stored confidential rows, or queued
|
|
285
|
+
* confidential items); a zero-config install stays silent (the header's
|
|
286
|
+
* zero-change-default discipline). Pure — returns the note string, the
|
|
287
|
+
* caller prints it (testable without console spies). Null = say nothing.
|
|
288
|
+
*/
|
|
289
|
+
export declare function confidentialMarkerKeyNote(opts: {
|
|
290
|
+
markerKey: string | null;
|
|
291
|
+
roster: string[];
|
|
292
|
+
/** Boot-resolved confidentialPaths patterns — configured patterns
|
|
293
|
+
* activate the circle exactly like a roster (#609). Absent = none. */
|
|
294
|
+
patterns?: unknown[];
|
|
295
|
+
confidentialRows: number;
|
|
296
|
+
queueConfidential: number;
|
|
297
|
+
}): string | null;
|
|
298
|
+
/** Test seam: re-arm the warnRefusedMarker once-latch. */
|
|
299
|
+
export declare function resetRefusedMarkerWarn(): void;
|
|
300
|
+
/**
|
|
301
|
+
* The refused-marker warn (#614): a delivery carried marker content that did
|
|
302
|
+
* NOT validate at intake — present with NO key configured (the marker arm is
|
|
303
|
+
* inert) or present but NOT equal to the key (a stale pre-key marker, a
|
|
304
|
+
* rotated key, or a forgery attempt). The CALLER guards the call
|
|
305
|
+
* (`clientMarker !== null && clientMarker !== key` — one guard covers both
|
|
306
|
+
* reasons); the reason wording here distinguishes them for the operator.
|
|
307
|
+
* NEVER echoes the marker content or the key (log discipline — the secret
|
|
308
|
+
* and the guess both stay out of the logs); naming the workspace path is
|
|
309
|
+
* fine (it is the operator's own path, and it is what they need to fix).
|
|
310
|
+
* Returns whether the line printed (the once-latch ate it → false).
|
|
311
|
+
*/
|
|
312
|
+
export declare function warnRefusedMarker(opts: {
|
|
313
|
+
markerKey: string | null;
|
|
314
|
+
workspacePath: string | null;
|
|
315
|
+
}): boolean;
|
package/dist/classification.js
CHANGED
|
@@ -9,7 +9,12 @@
|
|
|
9
9
|
* `identityAgents` / `?agent=`). Captures whose `source_agent` is rostered
|
|
10
10
|
* are stamped `confidential` at intake — server-derived, deterministic, by
|
|
11
11
|
* birthplace; never a content judgment (content classification was rejected,
|
|
12
|
-
* #197) and never client-declared.
|
|
12
|
+
* #197) and never client-declared. The workspace marker (#609/#614) is
|
|
13
|
+
* client-RELAYED but server-VALIDATED: the marker file carries the owner-set
|
|
14
|
+
* `confidentialMarkerKey` as its content, compared timing-safe at intake —
|
|
15
|
+
* marker content without the key never stamps (the client-writable
|
|
16
|
+
* classification channel #614 closes; an unkeyed install ignores markers
|
|
17
|
+
* entirely, fail-closed both directions). Every agent-facing read path accepts an
|
|
13
18
|
* optional `agent` requester id: absent or unknown = non-member = HARD OMIT
|
|
14
19
|
* of confidential rows (fail-closed both ends — unrostered sources are
|
|
15
20
|
* standard, unknown requesters are non-members). The circle is ADDITIVE:
|
|
@@ -27,6 +32,10 @@
|
|
|
27
32
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
33
|
exports.resolveConfidentialAgents = resolveConfidentialAgents;
|
|
29
34
|
exports.isConfidentialSourceAgent = isConfidentialSourceAgent;
|
|
35
|
+
exports.resolveConfidentialPaths = resolveConfidentialPaths;
|
|
36
|
+
exports.matchesConfidentialPath = matchesConfidentialPath;
|
|
37
|
+
exports.safeMarkerKeyEqual = safeMarkerKeyEqual;
|
|
38
|
+
exports.resolveConfidentialMarkerKey = resolveConfidentialMarkerKey;
|
|
30
39
|
exports.deriveIntakePrivacy = deriveIntakePrivacy;
|
|
31
40
|
exports.isCircleMember = isCircleMember;
|
|
32
41
|
exports.resolveConfidentialLlmConfig = resolveConfidentialLlmConfig;
|
|
@@ -34,8 +43,13 @@ exports.buildConfidentialLlm = buildConfidentialLlm;
|
|
|
34
43
|
exports.resolveLlmPair = resolveLlmPair;
|
|
35
44
|
exports.clientForPool = clientForPool;
|
|
36
45
|
exports.warnIfCircleUnconfigured = warnIfCircleUnconfigured;
|
|
46
|
+
exports.confidentialMarkerKeyNote = confidentialMarkerKeyNote;
|
|
47
|
+
exports.resetRefusedMarkerWarn = resetRefusedMarkerWarn;
|
|
48
|
+
exports.warnRefusedMarker = warnRefusedMarker;
|
|
49
|
+
const node_crypto_1 = require("node:crypto");
|
|
37
50
|
const identity_store_js_1 = require("./identity-store.js");
|
|
38
51
|
const llm_js_1 = require("./llm.js");
|
|
52
|
+
const config_read_js_1 = require("./config-read.js");
|
|
39
53
|
// ---------------------------------------------------------------------------
|
|
40
54
|
// Roster
|
|
41
55
|
// ---------------------------------------------------------------------------
|
|
@@ -94,13 +108,194 @@ function isConfidentialSourceAgent(sourceAgent, roster) {
|
|
|
94
108
|
// single-qualified by construction).
|
|
95
109
|
return rest < 0 && roster.includes(bare);
|
|
96
110
|
}
|
|
111
|
+
/**
|
|
112
|
+
* Shared normalization for pattern and path sides: NFC, `\` → `/`, lowercase
|
|
113
|
+
* (the case-insensitive compare). Pure string prep — no fs, no symlinks.
|
|
114
|
+
*/
|
|
115
|
+
function normalizePathForMatch(p) {
|
|
116
|
+
return p.normalize("NFC").replace(/\\/g, "/").toLowerCase();
|
|
117
|
+
}
|
|
118
|
+
/** Glob metacharacters a LITERAL segment must not contain (`*` alone is the
|
|
119
|
+
* one-segment wildcard; anything else is a typo, not a form). */
|
|
120
|
+
const SEGMENT_METACHARS = /[*?[\]{}]/;
|
|
121
|
+
/**
|
|
122
|
+
* Compile one raw config entry into a pattern, or null when the entry is not
|
|
123
|
+
* one of the three forms. Dropped kinds: relative entries (nothing to anchor
|
|
124
|
+
* a match on), a double-star anywhere but the end, a star that is not a whole
|
|
125
|
+
* segment (partial-segment wildcards), other metacharacters, blank, and
|
|
126
|
+
* ~user-style entries (whose home?). Dropped entries are reported by name at
|
|
127
|
+
* boot — a typo must surface, never silently match nothing.
|
|
128
|
+
*/
|
|
129
|
+
function compileConfidentialPath(entry) {
|
|
130
|
+
const trimmed = entry.trim();
|
|
131
|
+
if (!trimmed)
|
|
132
|
+
return null;
|
|
133
|
+
let s = trimmed;
|
|
134
|
+
let home = false;
|
|
135
|
+
if (s.startsWith("~")) {
|
|
136
|
+
if (s === "~" || s.startsWith("~/")) {
|
|
137
|
+
home = true;
|
|
138
|
+
s = s === "~" ? "" : s.slice(2);
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
return null; // "~user/…" — whose home? Not one of the forms.
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
if (!home && !s.startsWith("/"))
|
|
145
|
+
return null; // relative — no anchor
|
|
146
|
+
let subtree = false;
|
|
147
|
+
if (s.endsWith("/**")) {
|
|
148
|
+
subtree = true;
|
|
149
|
+
s = s.slice(0, -3);
|
|
150
|
+
}
|
|
151
|
+
if (s.includes("**"))
|
|
152
|
+
return null; // ** mid-path (incl. a second trailing one)
|
|
153
|
+
const segments = normalizePathForMatch(s)
|
|
154
|
+
.split("/")
|
|
155
|
+
.filter((seg) => seg !== "");
|
|
156
|
+
for (const seg of segments) {
|
|
157
|
+
if (seg === "*")
|
|
158
|
+
continue; // the one-segment wildcard
|
|
159
|
+
if (SEGMENT_METACHARS.test(seg))
|
|
160
|
+
return null;
|
|
161
|
+
}
|
|
162
|
+
return { raw: entry, home, subtree, segments };
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Resolve the `confidentialPaths` config value into validated patterns.
|
|
166
|
+
* Entries that do not compile are dropped and their raw values returned in
|
|
167
|
+
* `dropped` for a one-time boot warning (a dropped pattern matches nothing —
|
|
168
|
+
* the operator learns from the log, not from a folder silently staying
|
|
169
|
+
* standard). Duplicates (same raw entry) collapse. Absent/non-array/empty →
|
|
170
|
+
* no patterns, nothing dropped — the zero-change default.
|
|
171
|
+
*/
|
|
172
|
+
function resolveConfidentialPaths(config) {
|
|
173
|
+
const raw = config?.confidentialPaths;
|
|
174
|
+
if (!Array.isArray(raw))
|
|
175
|
+
return { patterns: [], dropped: [] };
|
|
176
|
+
const patterns = [];
|
|
177
|
+
const dropped = [];
|
|
178
|
+
for (const entry of raw) {
|
|
179
|
+
if (typeof entry !== "string") {
|
|
180
|
+
dropped.push(String(entry));
|
|
181
|
+
continue;
|
|
182
|
+
}
|
|
183
|
+
const compiled = compileConfidentialPath(entry);
|
|
184
|
+
if (!compiled) {
|
|
185
|
+
dropped.push(entry);
|
|
186
|
+
}
|
|
187
|
+
else if (!patterns.some((p) => p.raw === compiled.raw)) {
|
|
188
|
+
patterns.push(compiled);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
return { patterns, dropped };
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* The pure matcher: does `workspacePath` fall under any resolved pattern?
|
|
195
|
+
* Empty pattern list matches nothing (and the zero-change default is exactly
|
|
196
|
+
* that); a null/empty path matches nothing (Hermes has no workspace — path
|
|
197
|
+
* signals never fire there). No fs access — callers pass the delivery's
|
|
198
|
+
* declared workspace path; the server decides (the client never knows the
|
|
199
|
+
* patterns).
|
|
200
|
+
*/
|
|
201
|
+
function matchesConfidentialPath(workspacePath, patterns) {
|
|
202
|
+
if (!workspacePath || patterns.length === 0)
|
|
203
|
+
return false;
|
|
204
|
+
const pathSegs = normalizePathForMatch(workspacePath)
|
|
205
|
+
.split("/")
|
|
206
|
+
.filter((seg) => seg !== "");
|
|
207
|
+
return patterns.some((p) => patternMatchesSegments(p, pathSegs));
|
|
208
|
+
}
|
|
209
|
+
/** Segment-level match of one compiled pattern against a normalized path. */
|
|
210
|
+
function patternMatchesSegments(p, pathSegs) {
|
|
211
|
+
let rest = pathSegs;
|
|
212
|
+
if (p.home) {
|
|
213
|
+
// Any single home prefix: /home/<user>/… or /Users/<user>/… — structural,
|
|
214
|
+
// so `~/finance` covers the same folder on Linux and macOS fleets.
|
|
215
|
+
if (pathSegs.length < 2)
|
|
216
|
+
return false;
|
|
217
|
+
if (pathSegs[0] !== "home" && pathSegs[0] !== "users")
|
|
218
|
+
return false;
|
|
219
|
+
rest = pathSegs.slice(2);
|
|
220
|
+
}
|
|
221
|
+
// Subtree: the path equals the prefix OR extends it. Exact: lengths equal.
|
|
222
|
+
if (rest.length < p.segments.length)
|
|
223
|
+
return false;
|
|
224
|
+
if (!p.subtree && rest.length !== p.segments.length)
|
|
225
|
+
return false;
|
|
226
|
+
// "*" matches exactly ONE segment — never zero, never two.
|
|
227
|
+
return p.segments.every((seg, i) => seg === "*" || seg === rest[i]);
|
|
228
|
+
}
|
|
229
|
+
// ---------------------------------------------------------------------------
|
|
230
|
+
// The marker key (#614) — server-validated marker content
|
|
231
|
+
// ---------------------------------------------------------------------------
|
|
232
|
+
/**
|
|
233
|
+
* Constant-time marker-content × key comparison (#614) — the safeBearerMatch
|
|
234
|
+
* pattern (viz.ts auth). `crypto.timingSafeEqual` THROWS RangeError on
|
|
235
|
+
* mismatched buffer lengths, so the length check MUST gate the call; the
|
|
236
|
+
* short-circuit leaks only the CONTENT length, which is already visible on
|
|
237
|
+
* the wire (the delivery body carries the content verbatim) — the key bytes
|
|
238
|
+
* are never compared byte-by-byte through a timing side channel. Empty
|
|
239
|
+
* content never matches: an empty (pre-#614) marker file is inert by DESIGN,
|
|
240
|
+
* not by luck of the length gate.
|
|
241
|
+
*/
|
|
242
|
+
function safeMarkerKeyEqual(markerContent, key) {
|
|
243
|
+
if (markerContent.length === 0)
|
|
244
|
+
return false;
|
|
245
|
+
const a = Buffer.from(markerContent);
|
|
246
|
+
const b = Buffer.from(key);
|
|
247
|
+
return a.length === b.length && (0, node_crypto_1.timingSafeEqual)(a, b);
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Resolve the `confidentialMarkerKey` (#614) — the owner-set secret a
|
|
251
|
+
* workspace marker must carry for its folder to stamp confidential at
|
|
252
|
+
* intake. Precedence: env `HICORTEX_CONFIDENTIAL_MARKER_KEY` OVERRIDES the
|
|
253
|
+
* config value (the env-last-word ops override, so a restart-free rotation
|
|
254
|
+
* or override path exists beside the file), then the config value through
|
|
255
|
+
* the readStringConfig boundary (wrong type warns + null — never coerced;
|
|
256
|
+
* a JSON slip like a number cannot silently arm the arm). Blank/absent →
|
|
257
|
+
* null = the marker arm is INERT: no key configured means client markers
|
|
258
|
+
* are ignored entirely (fail-closed both directions — the empty-marker
|
|
259
|
+
* attack surface ships disabled by default, AC-1). Boot-time like the
|
|
260
|
+
* roster; restart to apply. Distributed like authToken: mirror the server's
|
|
261
|
+
* value into each client machine's config.json (or its env).
|
|
262
|
+
*/
|
|
263
|
+
function resolveConfidentialMarkerKey(config) {
|
|
264
|
+
const env = process.env.HICORTEX_CONFIDENTIAL_MARKER_KEY;
|
|
265
|
+
if (typeof env === "string" && env.trim())
|
|
266
|
+
return env.trim();
|
|
267
|
+
return (0, config_read_js_1.readStringConfig)(config ?? {}, "confidentialMarkerKey");
|
|
268
|
+
}
|
|
97
269
|
/**
|
|
98
270
|
* The intake-side derivation: which class a delivery from `sourceAgent`
|
|
99
271
|
* stores as. Fail-closed by construction — anything unattributed or
|
|
100
272
|
* unrostered is `standard` (the global pool).
|
|
273
|
+
*
|
|
274
|
+
* #609/#614 composition invariant: confidential iff roster agent OR server
|
|
275
|
+
* path pattern OR VALIDATED marker content. The marker arm is key-gated
|
|
276
|
+
* (#614): the delivery's relayed marker CONTENT must equal the boot-resolved
|
|
277
|
+
* `confidentialMarkerKey` (timing-safe, server-side — a client-side match is
|
|
278
|
+
* never trusted, the client only relays). An absent key makes every marker
|
|
279
|
+
* inert (the empty-marker client-writable channel is closed), and a
|
|
280
|
+
* present-but-refused marker never reduces a server rule (markers only add,
|
|
281
|
+
* never subtract — safe because a token holder can already POST arbitrary
|
|
282
|
+
* content, the #599 F5 ruling, token = owner). The optional third argument
|
|
283
|
+
* keeps every existing caller byte-identical (no signals = the #332
|
|
284
|
+
* agent-only rule).
|
|
101
285
|
*/
|
|
102
|
-
function deriveIntakePrivacy(sourceAgent, roster) {
|
|
103
|
-
|
|
286
|
+
function deriveIntakePrivacy(sourceAgent, roster, signals) {
|
|
287
|
+
if (isConfidentialSourceAgent(sourceAgent, roster))
|
|
288
|
+
return "confidential";
|
|
289
|
+
if (typeof signals?.markerKey === "string" &&
|
|
290
|
+
signals.markerKey.length > 0 &&
|
|
291
|
+
typeof signals?.markerContent === "string" &&
|
|
292
|
+
safeMarkerKeyEqual(signals.markerContent, signals.markerKey)) {
|
|
293
|
+
return "confidential";
|
|
294
|
+
}
|
|
295
|
+
if (matchesConfidentialPath(signals?.workspacePath, signals?.paths ?? [])) {
|
|
296
|
+
return "confidential";
|
|
297
|
+
}
|
|
298
|
+
return "standard";
|
|
104
299
|
}
|
|
105
300
|
/**
|
|
106
301
|
* The read-side membership check: is the requester a circle member? Absent,
|
|
@@ -231,19 +426,22 @@ function clientForPool(pair, privacy) {
|
|
|
231
426
|
// Boot warning
|
|
232
427
|
// ---------------------------------------------------------------------------
|
|
233
428
|
/**
|
|
234
|
-
* The ONE loud boot warning when the circle is ACTIVE (a roster
|
|
235
|
-
* configured, OR confidential rows exist, OR
|
|
236
|
-
* but the confidential model is not. Called at
|
|
237
|
-
* prints once per call site (the callers are
|
|
238
|
-
* names the exposure and the HOLD behavior —
|
|
239
|
-
* logs that deliveries are piling up, not
|
|
240
|
-
* model. Returns whether the warning fired
|
|
241
|
-
* their own log lines).
|
|
429
|
+
* The ONE loud boot warning when the circle is ACTIVE (a roster OR
|
|
430
|
+
* confidentialPaths patterns are configured, OR confidential rows exist, OR
|
|
431
|
+
* confidential items sit queued) but the confidential model is not. Called at
|
|
432
|
+
* daemon boot and nightly start; prints once per call site (the callers are
|
|
433
|
+
* once-per-process). The wording names the exposure and the HOLD behavior —
|
|
434
|
+
* the operator learns from the logs that deliveries are piling up, not
|
|
435
|
+
* silently distilling on the main model. Returns whether the warning fired
|
|
436
|
+
* (tests + callers that compose their own log lines).
|
|
242
437
|
*/
|
|
243
438
|
function warnIfCircleUnconfigured(opts) {
|
|
244
439
|
if (opts.confidentialLlm)
|
|
245
440
|
return false;
|
|
246
|
-
const active = opts.roster.length > 0 ||
|
|
441
|
+
const active = opts.roster.length > 0 ||
|
|
442
|
+
(opts.patterns?.length ?? 0) > 0 ||
|
|
443
|
+
opts.confidentialRows > 0 ||
|
|
444
|
+
opts.queueConfidential > 0;
|
|
247
445
|
if (!active)
|
|
248
446
|
return false;
|
|
249
447
|
console.warn("");
|
|
@@ -251,7 +449,8 @@ function warnIfCircleUnconfigured(opts) {
|
|
|
251
449
|
console.warn("║ CONFIDENTIAL CIRCLE ACTIVE WITHOUT A CONFIDENTIAL MODEL ║");
|
|
252
450
|
console.warn("║ ║");
|
|
253
451
|
console.warn("║ Confidential memories exist (or a confidentialAgents ║");
|
|
254
|
-
console.warn("║ roster
|
|
452
|
+
console.warn("║ roster / confidentialPaths patterns are set) but ║");
|
|
453
|
+
console.warn("║ llmConfidentialBaseUrl/ApiKey are not. ║");
|
|
255
454
|
console.warn("║ Confidential deliveries are HELD, not distilled — they ║");
|
|
256
455
|
console.warn("║ accumulate until a confidential model is configured ║");
|
|
257
456
|
console.warn("║ (they never fall back to the main model). Standard ║");
|
|
@@ -263,3 +462,64 @@ function warnIfCircleUnconfigured(opts) {
|
|
|
263
462
|
console.warn("");
|
|
264
463
|
return true;
|
|
265
464
|
}
|
|
465
|
+
/**
|
|
466
|
+
* The boot note when the circle is ACTIVE but the marker key is not (#614):
|
|
467
|
+
* one line naming `confidentialMarkerKey` and that client workspace markers
|
|
468
|
+
* are IGNORED (inert) until it is set — an operator running a marked folder
|
|
469
|
+
* learns from the log why it stamps standard, not from silently
|
|
470
|
+
* unclassified captures. Fires ONLY when the key is absent AND the circle is
|
|
471
|
+
* otherwise active (the SAME active predicate as warnIfCircleUnconfigured:
|
|
472
|
+
* roster, confidentialPaths patterns, stored confidential rows, or queued
|
|
473
|
+
* confidential items); a zero-config install stays silent (the header's
|
|
474
|
+
* zero-change-default discipline). Pure — returns the note string, the
|
|
475
|
+
* caller prints it (testable without console spies). Null = say nothing.
|
|
476
|
+
*/
|
|
477
|
+
function confidentialMarkerKeyNote(opts) {
|
|
478
|
+
if (opts.markerKey)
|
|
479
|
+
return null;
|
|
480
|
+
const active = opts.roster.length > 0 ||
|
|
481
|
+
(opts.patterns?.length ?? 0) > 0 ||
|
|
482
|
+
opts.confidentialRows > 0 ||
|
|
483
|
+
opts.queueConfidential > 0;
|
|
484
|
+
if (!active)
|
|
485
|
+
return null;
|
|
486
|
+
return ("[hicortex] confidentialMarkerKey is not set — client workspace markers are IGNORED " +
|
|
487
|
+
"(deliveries from marked folders stamp standard). Set confidentialMarkerKey in " +
|
|
488
|
+
"config.json (or the HICORTEX_CONFIDENTIAL_MARKER_KEY env var) and mirror it to the " +
|
|
489
|
+
"machines that mark folders, then restart.");
|
|
490
|
+
}
|
|
491
|
+
/**
|
|
492
|
+
* Module-level once-latch for the refused-marker warn — ONE line per process
|
|
493
|
+
* (that IS the rate limit: a fleet of nightly segments from a mis-keyed
|
|
494
|
+
* folder must not flood the daemon log). resetRefusedMarkerWarn re-arms it
|
|
495
|
+
* for tests.
|
|
496
|
+
*/
|
|
497
|
+
let refusedMarkerWarned = false;
|
|
498
|
+
/** Test seam: re-arm the warnRefusedMarker once-latch. */
|
|
499
|
+
function resetRefusedMarkerWarn() {
|
|
500
|
+
refusedMarkerWarned = false;
|
|
501
|
+
}
|
|
502
|
+
/**
|
|
503
|
+
* The refused-marker warn (#614): a delivery carried marker content that did
|
|
504
|
+
* NOT validate at intake — present with NO key configured (the marker arm is
|
|
505
|
+
* inert) or present but NOT equal to the key (a stale pre-key marker, a
|
|
506
|
+
* rotated key, or a forgery attempt). The CALLER guards the call
|
|
507
|
+
* (`clientMarker !== null && clientMarker !== key` — one guard covers both
|
|
508
|
+
* reasons); the reason wording here distinguishes them for the operator.
|
|
509
|
+
* NEVER echoes the marker content or the key (log discipline — the secret
|
|
510
|
+
* and the guess both stay out of the logs); naming the workspace path is
|
|
511
|
+
* fine (it is the operator's own path, and it is what they need to fix).
|
|
512
|
+
* Returns whether the line printed (the once-latch ate it → false).
|
|
513
|
+
*/
|
|
514
|
+
function warnRefusedMarker(opts) {
|
|
515
|
+
if (refusedMarkerWarned)
|
|
516
|
+
return false;
|
|
517
|
+
refusedMarkerWarned = true;
|
|
518
|
+
const reason = opts.markerKey
|
|
519
|
+
? "does not match this server's confidentialMarkerKey"
|
|
520
|
+
: "arrived but no confidentialMarkerKey is configured (markers are inert)";
|
|
521
|
+
const where = opts.workspacePath ? ` (workspace ${opts.workspacePath})` : "";
|
|
522
|
+
console.warn(`[hicortex] Confidential marker refused${where}: marker content ${reason} — the delivery stamps standard. ` +
|
|
523
|
+
`Re-run \`hicortex confidential\` in that folder to rewrite the marker, or align the key.`);
|
|
524
|
+
return true;
|
|
525
|
+
}
|
package/dist/cli.js
CHANGED
|
@@ -362,6 +362,33 @@ switch (command) {
|
|
|
362
362
|
});
|
|
363
363
|
break;
|
|
364
364
|
}
|
|
365
|
+
case "confidential": {
|
|
366
|
+
// #609: mark/unmark a workspace folder confidential via the local
|
|
367
|
+
// .hicortex-confidential marker file; the nightly's marker walk reads the
|
|
368
|
+
// file at the next capture. #616: the marker key is provisioned in ONE
|
|
369
|
+
// command — no local key → fetch it from the server (or generate +
|
|
370
|
+
// register one there); --key <value> rotates (PUTs the new value).
|
|
371
|
+
// Precedent: backfill-privacy (thin switch, runner in its own module).
|
|
372
|
+
const args = process.argv.slice(3);
|
|
373
|
+
const off = args.includes("--off");
|
|
374
|
+
let key;
|
|
375
|
+
try {
|
|
376
|
+
key = (0, cli_args_js_1.readValueFlag)(args, "--key");
|
|
377
|
+
}
|
|
378
|
+
catch {
|
|
379
|
+
console.error("[hicortex] confidential: --key requires a value");
|
|
380
|
+
process.exit(1);
|
|
381
|
+
}
|
|
382
|
+
// Positional path: the first bare arg that is not a --key value pair.
|
|
383
|
+
const pathArg = args.find((a, i) => !a.startsWith("-") && args[i - 1] !== "--key");
|
|
384
|
+
import("./confidential-marker.js").then(({ runConfidentialCommand }) => {
|
|
385
|
+
runConfidentialCommand({ path: pathArg, off, key }).catch((err) => {
|
|
386
|
+
console.error(err instanceof Error ? err.message : `[hicortex] confidential failed: ${err}`);
|
|
387
|
+
process.exit(1);
|
|
388
|
+
});
|
|
389
|
+
});
|
|
390
|
+
break;
|
|
391
|
+
}
|
|
365
392
|
case "sweep-volatile": {
|
|
366
393
|
// One-shot store sweep of volatile GH-status/version rows (#489,
|
|
367
394
|
// deliverable iii): reuses the distill path's deterministic gate over the
|
|
@@ -527,6 +554,11 @@ Commands:
|
|
|
527
554
|
reconcile-projects Canonicalize existing project labels (server mode; dry run by default)
|
|
528
555
|
backfill-privacy Stamp history confidential by source agent (#332; server mode;
|
|
529
556
|
dry run by default — --apply executes: backup + capture lock + stamp)
|
|
557
|
+
confidential Mark a workspace folder confidential via a local marker file
|
|
558
|
+
(#616: the marker carries the server's confidentialMarkerKey,
|
|
559
|
+
provisioned by this very command — fetched from the server,
|
|
560
|
+
or generated + registered there on first use; --key <value>
|
|
561
|
+
rotates); confidential [path] writes, --off [path] removes
|
|
530
562
|
history Show a memory's rewrite history, or roll one back (server mode)
|
|
531
563
|
history <id> List rewrite events (read-only)
|
|
532
564
|
history --rollback <row> Undo one rewrite + un-absorb its triggers
|
|
@@ -568,7 +600,24 @@ Options:
|
|
|
568
600
|
backfill-privacy --apply Execute the stamps (default: dry run, report only)
|
|
569
601
|
Backup + capture lock first; stamps memories + distill_queue;
|
|
570
602
|
never stamps back to standard (a roster removal is not a demotion)
|
|
603
|
+
#609: also plans/stamps per confidentialPaths pattern (rows' stored
|
|
604
|
+
workspace_path); NULL-path rows are never matched
|
|
571
605
|
backfill-privacy --db <path> DB path override (defaults to the configured DB)
|
|
606
|
+
confidential [path] Mark a folder confidential — writes .hicortex-confidential carrying
|
|
607
|
+
the server's confidentialMarkerKey at its root (default path: cwd).
|
|
608
|
+
ONE command, no manual key mirroring (#616): no local key → fetch
|
|
609
|
+
the server's, or generate + register one there on first use; the
|
|
610
|
+
fetched/generated key is saved into ~/.hicortex/config.json for
|
|
611
|
+
offline reuse. An env (HICORTEX_CONFIDENTIAL_MARKER_KEY) or config
|
|
612
|
+
key already on this machine is used as-is, no server contact.
|
|
613
|
+
Refuses when no key exists AND no server is reachable (an
|
|
614
|
+
unvalidated marker would be inert). A marked parent covers child
|
|
615
|
+
workspaces; unmarking never demotes already-captured memories
|
|
616
|
+
confidential --key <v> [path] ROTATION: register <v> as the server's confidentialMarkerKey
|
|
617
|
+
(PUT), save it locally, write the marker — markers carrying a
|
|
618
|
+
previous key then stamp standard. The server refuses (409) while
|
|
619
|
+
its HICORTEX_CONFIDENTIAL_MARKER_KEY env override is set
|
|
620
|
+
confidential --off [path] Remove the marker (succeeds when absent; no key needed, no network)
|
|
572
621
|
history --rollback <row> Roll back history row <row>: restores prior content/status, un-absorbs triggers
|
|
573
622
|
history --db <path> DB path override (defaults to the configured DB)
|
|
574
623
|
backup --out <dir> Write the artifact into <dir> as hicortex-<ISO>.tar.gz (default: <home>/backups)
|