@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.
@@ -1,28 +1,37 @@
1
1
  "use strict";
2
2
  /**
3
3
  * `hicortex backfill-privacy` (#332) — one-shot classification stamping for
4
- * EXISTING rows, by source agent.
4
+ * EXISTING rows, by source agent, and (#609) by workspace path.
5
5
  *
6
6
  * The intake derivation stamps every NEW delivery; this command heals history
7
- * when the roster changes (an agent joins the circle, or the feature lands on
8
- * a store that already has captures from a now-rostered agent). The plan is a
9
- * pure function of the roster × the rows' source_agent values:
7
+ * when the roster or the path patterns change (an agent joins the circle, a
8
+ * folder is listed, or the feature lands on a store that already has captures
9
+ * from a now-covered birthplace). The plan is a pure function of the config ×
10
+ * the rows' stored values:
10
11
  * - every memories/distill_queue row whose source_agent matches the roster
11
12
  * (isConfidentialSourceAgent — the same `<harness>/`-stripping matcher the
12
13
  * intake uses) AND whose privacy != 'confidential' → stamped confidential;
13
- * - NOTHING is ever stamped BACK to standard (a roster removal is not a
14
- * demotion — memories stay confidential until the operator explicitly
15
- * changes them; re-running with a smaller roster is a no-op by design).
14
+ * - #609: every row whose stored `workspace_path` matches a
15
+ * `confidentialPaths` pattern (the same pure matcher the intake uses),
16
+ * grouped per pattern. NULL-path rows are NEVER path-matched (pre-v28
17
+ * rows have no path by construction; they are reported as unmatched, not
18
+ * silently stamped). A row matching both a rostered agent and a pattern
19
+ * flips once (agent groups claim it first; each remaining row joins its
20
+ * first matching pattern so overlapping patterns never double-count);
21
+ * - NOTHING is ever stamped BACK to standard (a roster/pattern removal is
22
+ * not a demotion — memories stay confidential until the operator
23
+ * explicitly changes them; re-running with a smaller config is a no-op by
24
+ * design).
16
25
  *
17
26
  * Safety rails (the `hicortex dedup` / `reconcile-projects` pattern): dry run
18
27
  * by default (report only, zero writes); `--apply` takes a pre-apply DB
19
28
  * backup (abort all writes on failure), the single-flight capture lock
20
29
  * (waitMs 0 — busy aborts), and stamps in ONE transaction. The queue rows are
21
- * stamped too: a pre-upgrade queued segment from a rostered agent would
30
+ * stamped too: a pre-upgrade queued segment from a covered birthplace would
22
31
  * otherwise distill as standard (migration v27 normalized it) — the backfill
23
32
  * closes that seam.
24
33
  *
25
- * Idempotent by construction: a second run finds every rostered row already
34
+ * Idempotent by construction: a second run finds every covered row already
26
35
  * confidential and reports zero.
27
36
  */
28
37
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -57,11 +66,18 @@ function readSourceAgents(db, table) {
57
66
  * The pure plan: which stored source_agent values match the roster, and how
58
67
  * many of their rows are not yet confidential. Roster matching uses the
59
68
  * INTAKE matcher (isConfidentialSourceAgent — `<harness>/`-stripping) so the
60
- * backfill and the intake can never disagree about who is rostered.
69
+ * backfill and the intake can never disagree about who is rostered. #609 adds
70
+ * the per-pattern groups (see planPathGroups) alongside the agent groups —
71
+ * same rails, same never-demotes rule.
61
72
  */
62
- function planBackfill(db, roster) {
73
+ function planBackfill(db, roster, patterns = []) {
63
74
  const memoryAgents = readSourceAgents(db, "memories");
64
75
  const queuedAgents = readSourceAgents(db, "distill_queue");
76
+ // Row ids the agent groups below claim — the path groups skip them so a row
77
+ // covered by BOTH a rostered agent and a pattern flips (and is counted)
78
+ // exactly once.
79
+ const agentClaimedMem = new Set();
80
+ const agentClaimedQueue = new Set();
65
81
  const groups = [];
66
82
  for (const [agent, memoryRows] of memoryAgents) {
67
83
  if (!(0, classification_js_1.isConfidentialSourceAgent)(agent, roster))
@@ -76,6 +92,20 @@ function planBackfill(db, roster) {
76
92
  : 0;
77
93
  if (pending === 0 && queued === 0)
78
94
  continue;
95
+ if (pending > 0) {
96
+ for (const r of db
97
+ .prepare("SELECT id FROM memories WHERE source_agent = ? AND privacy != 'confidential'")
98
+ .all(agent)) {
99
+ agentClaimedMem.add(r.id);
100
+ }
101
+ }
102
+ if (queued > 0) {
103
+ for (const r of db
104
+ .prepare("SELECT id FROM distill_queue WHERE source_agent = ? AND privacy != 'confidential'")
105
+ .all(agent)) {
106
+ agentClaimedQueue.add(r.id);
107
+ }
108
+ }
79
109
  groups.push({ sourceAgent: agent, memoryRows: pending, queuedRows: queued });
80
110
  }
81
111
  // Queue-only groups (memories already stamped, inbox holds old rows).
@@ -87,12 +117,76 @@ function planBackfill(db, roster) {
87
117
  const queued = db
88
118
  .prepare("SELECT COUNT(*) AS c FROM distill_queue WHERE source_agent = ? AND privacy != 'confidential'")
89
119
  .get(agent).c;
90
- if (queued > 0)
120
+ if (queued > 0) {
91
121
  groups.push({ sourceAgent: agent, memoryRows: 0, queuedRows: queued });
122
+ for (const r of db
123
+ .prepare("SELECT id FROM distill_queue WHERE source_agent = ? AND privacy != 'confidential'")
124
+ .all(agent)) {
125
+ agentClaimedQueue.add(r.id);
126
+ }
127
+ }
92
128
  }
129
+ groups.push(...planPathGroups(db, patterns, agentClaimedMem, agentClaimedQueue));
93
130
  groups.sort((a, b) => b.memoryRows - a.memoryRows || a.sourceAgent.localeCompare(b.sourceAgent));
94
131
  return groups;
95
132
  }
133
+ /**
134
+ * #609: the per-PATTERN stamp groups. Rows whose STORED `workspace_path`
135
+ * matches a configured pattern flip to confidential — matched in JS with the
136
+ * same pure matcher the intake uses (SQL cannot express the three forms),
137
+ * over the not-yet-confidential rows that carry a path. NULL-path rows are
138
+ * never matched (they have no path to match — reported as unmatched, never
139
+ * silently stamped). Rows already claimed by an agent group are skipped
140
+ * (single flip); each remaining row joins its FIRST matching pattern (config
141
+ * order) so overlapping patterns never double-count.
142
+ */
143
+ function planPathGroups(db, patterns, agentClaimedMem, agentClaimedQueue) {
144
+ if (patterns.length === 0)
145
+ return [];
146
+ const claims = patterns.map(() => ({ memIds: [], queueIds: [] }));
147
+ const memRows = db
148
+ .prepare("SELECT id, workspace_path FROM memories WHERE privacy != 'confidential' AND workspace_path IS NOT NULL")
149
+ .all();
150
+ for (const row of memRows) {
151
+ if (agentClaimedMem.has(row.id))
152
+ continue;
153
+ for (let p = 0; p < patterns.length; p++) {
154
+ if ((0, classification_js_1.matchesConfidentialPath)(row.workspace_path, [patterns[p]])) {
155
+ claims[p].memIds.push(row.id);
156
+ break;
157
+ }
158
+ }
159
+ }
160
+ const queueRows = db
161
+ .prepare("SELECT id, workspace_path FROM distill_queue WHERE privacy != 'confidential' AND workspace_path IS NOT NULL")
162
+ .all();
163
+ for (const row of queueRows) {
164
+ if (agentClaimedQueue.has(row.id))
165
+ continue;
166
+ for (let p = 0; p < patterns.length; p++) {
167
+ if ((0, classification_js_1.matchesConfidentialPath)(row.workspace_path, [patterns[p]])) {
168
+ claims[p].queueIds.push(row.id);
169
+ break;
170
+ }
171
+ }
172
+ }
173
+ const groups = [];
174
+ for (let p = 0; p < patterns.length; p++) {
175
+ const { memIds, queueIds } = claims[p];
176
+ if (memIds.length === 0 && queueIds.length === 0)
177
+ continue;
178
+ groups.push({
179
+ // Display label: the pattern's raw config entry.
180
+ sourceAgent: patterns[p].raw,
181
+ pattern: patterns[p],
182
+ memoryRows: memIds.length,
183
+ queuedRows: queueIds.length,
184
+ memoryIds: memIds,
185
+ queuedIds: queueIds,
186
+ });
187
+ }
188
+ return groups;
189
+ }
96
190
  /**
97
191
  * Run `hicortex backfill-privacy`. Dry run by default (options.apply falsy) —
98
192
  * plan + report only, zero writes. `options.apply` executes: backup, capture
@@ -103,10 +197,12 @@ function planBackfill(db, roster) {
103
197
  async function runBackfillPrivacy(options = {}) {
104
198
  const stateDir = options.stateDir ?? HICORTEX_HOME;
105
199
  const config = options.config !== undefined ? options.config : readConfig(stateDir);
106
- // The roster comes from the SAME resolution the server uses at boot
107
- // (resolveConfidentialAgents) — one config shape, one id namespace.
108
- const { resolveConfidentialAgents } = await import("./classification.js");
109
- const roster = resolveConfidentialAgents(config).roster;
200
+ // The roster AND the path patterns come from the SAME resolutions the
201
+ // server uses at boot (resolveConfidentialAgents / resolveConfidentialPaths)
202
+ // — one config shape, one matcher, so the backfill can never disagree with
203
+ // the intake about what is covered.
204
+ const roster = (0, classification_js_1.resolveConfidentialAgents)(config).roster;
205
+ const patterns = (0, classification_js_1.resolveConfidentialPaths)(config).patterns;
110
206
  // Server-mode only — client installs have no local DB.
111
207
  if (config?.mode === "client") {
112
208
  throw new Error("[hicortex] backfill-privacy is server-mode only (it needs the local DB). " +
@@ -117,27 +213,30 @@ async function runBackfillPrivacy(options = {}) {
117
213
  const db = (0, db_js_1.initDb)(dbPath);
118
214
  try {
119
215
  console.log(`[hicortex] backfill-privacy starting (${apply ? "APPLY" : "dry-run"}): db ${dbPath}, ` +
120
- `${roster.length} rostered agent(s)${roster.length > 0 ? ` (${roster.join(", ")})` : ""}`);
121
- if (roster.length === 0) {
122
- console.log("[hicortex] backfill-privacy: no confidentialAgents configured — nothing to stamp. " +
123
- "Add agent ids to config.json confidentialAgents first.");
124
- return { dryRun: !apply, roster, groups: [], totalMemories: 0, totalQueued: 0 };
216
+ `${roster.length} rostered agent(s)${roster.length > 0 ? ` (${roster.join(", ")})` : ""}` +
217
+ `, ${patterns.length} path pattern(s)${patterns.length > 0 ? ` (${patterns.map((p) => p.raw).join(", ")})` : ""}`);
218
+ if (roster.length === 0 && patterns.length === 0) {
219
+ console.log("[hicortex] backfill-privacy: no confidentialAgents or confidentialPaths configured — nothing to stamp. " +
220
+ "Add agent ids to config.json confidentialAgents and/or path patterns to confidentialPaths first.");
221
+ return { dryRun: !apply, roster, patterns: [], groups: [], totalMemories: 0, totalQueued: 0 };
125
222
  }
126
- const groups = planBackfill(db, roster);
223
+ const groups = planBackfill(db, roster, patterns);
127
224
  const totalMemories = groups.reduce((s, g) => s + g.memoryRows, 0);
128
225
  const totalQueued = groups.reduce((s, g) => s + g.queuedRows, 0);
129
226
  const report = {
130
227
  dryRun: !apply,
131
228
  roster,
229
+ patterns: patterns.map((p) => p.raw),
132
230
  groups,
133
231
  totalMemories,
134
232
  totalQueued,
135
233
  };
136
- console.log(`[hicortex] backfill-privacy: ${groups.length} source agent(s) match the roster, ` +
234
+ console.log(`[hicortex] backfill-privacy: ${groups.length} group(s) match the config, ` +
137
235
  `${totalMemories} memory row(s)${totalQueued > 0 ? `, ${totalQueued} queued row(s)` : ""} ` +
138
236
  `→ confidential (${apply ? "applying" : "dry run — zero writes"})`);
139
237
  for (const g of groups) {
140
- console.log(`[hicortex] ${g.sourceAgent}: ${g.memoryRows} memory row(s)${g.queuedRows > 0 ? `, ${g.queuedRows} queued` : ""}`);
238
+ const label = g.pattern ? `pattern ${g.pattern.raw}` : g.sourceAgent;
239
+ console.log(`[hicortex] ${label}: ${g.memoryRows} memory row(s)${g.queuedRows > 0 ? `, ${g.queuedRows} queued` : ""}`);
141
240
  }
142
241
  if (!apply)
143
242
  return report;
@@ -164,15 +263,27 @@ async function runBackfillPrivacy(options = {}) {
164
263
  console.log(`[hicortex] Backup written: ${backupPath}`);
165
264
  report.backupPath = backupPath;
166
265
  // ONE transaction: every group's memory + queue stamps commit together
167
- // (the plan is order-independent — pure source_agent predicates).
266
+ // (the plan is order-independent — pure predicates). Agent groups stamp
267
+ // by source_agent; #609 path groups stamp by exact row id (the JS-side
268
+ // matcher planned them — SQL cannot express the pattern forms).
168
269
  const stampMem = db.prepare("UPDATE memories SET privacy = 'confidential' WHERE source_agent = ? AND privacy != 'confidential'");
169
270
  const stampQueue = db.prepare("UPDATE distill_queue SET privacy = 'confidential' WHERE source_agent = ? AND privacy != 'confidential'");
271
+ const stampMemById = db.prepare("UPDATE memories SET privacy = 'confidential' WHERE id = ? AND privacy != 'confidential'");
272
+ const stampQueueById = db.prepare("UPDATE distill_queue SET privacy = 'confidential' WHERE id = ? AND privacy != 'confidential'");
170
273
  const applied = db.transaction(() => {
171
274
  let memories = 0;
172
275
  let queued = 0;
173
276
  for (const g of groups) {
174
- memories += stampMem.run(g.sourceAgent).changes;
175
- queued += stampQueue.run(g.sourceAgent).changes;
277
+ if (g.pattern) {
278
+ for (const id of g.memoryIds ?? [])
279
+ memories += stampMemById.run(id).changes;
280
+ for (const id of g.queuedIds ?? [])
281
+ queued += stampQueueById.run(id).changes;
282
+ }
283
+ else {
284
+ memories += stampMem.run(g.sourceAgent).changes;
285
+ queued += stampQueue.run(g.sourceAgent).changes;
286
+ }
176
287
  }
177
288
  return { memories, queued };
178
289
  })();
@@ -180,7 +291,7 @@ async function runBackfillPrivacy(options = {}) {
180
291
  report.appliedQueued = applied.queued;
181
292
  console.log(`[hicortex] backfill-privacy complete: ${applied.memories} memory row(s) stamped confidential` +
182
293
  (applied.queued > 0 ? `, ${applied.queued} queued row(s)` : "") +
183
- " (nothing is ever stamped back to standard — a roster removal is not a demotion)");
294
+ " (nothing is ever stamped back to standard — a roster/pattern removal is not a demotion)");
184
295
  return report;
185
296
  }
186
297
  finally {
package/dist/capture.d.ts CHANGED
@@ -64,10 +64,70 @@ export interface DistillBody {
64
64
  session_id: string;
65
65
  segment_id: string;
66
66
  session_date: string;
67
+ /**
68
+ * #609: the session's workspace path (batch.workspacePath) — the directory
69
+ * the capturing agent worked in. Always sent when known (the server cannot
70
+ * match confidentialPaths or backfill by path without it); null/omitted
71
+ * when the harness has no workspace (Hermes) or the reader predates #609.
72
+ * Old servers ignore unknown body fields by construction.
73
+ */
74
+ workspace_path?: string | null;
75
+ /**
76
+ * #614: the marker file's relayed CONTENT — readConfidentialMarker's walk
77
+ * result (the trimmed first line of `.hicortex-confidential` at the
78
+ * workspace or an ancestor). "" when the marker exists but is empty (the
79
+ * pre-#614 shape — the server warns on it, never validates it); null when
80
+ * no marker was found. Content = the server's confidentialMarkerKey today,
81
+ * a space-id + key pair later (#613) — the wire field never changes shape.
82
+ * Sent on every segment of the batch; the SERVER validates it against its
83
+ * own key at intake (a client-side match alone is never trusted).
84
+ */
85
+ client_marker?: string | null;
86
+ /**
87
+ * LEGACY (pre-#614): the marker-walk boolean. Capture STOPPED sending it
88
+ * in #614 — the boolean was the client-writable classification channel the
89
+ * server-side key validation closes; a #614 server accepts-and-ignores it
90
+ * (not even destructured, the #332 client `privacy` precedent). Kept on
91
+ * the interface for the version-skew window exactly like `privacy` below:
92
+ * a #609-era client's `true` against a #614 server reads standard, and a
93
+ * #614 client against a #609-era server reads standard too — fail-closed
94
+ * in both directions (intended; both ends must upgrade for marker-derived
95
+ * confidentiality).
96
+ */
97
+ client_confidential?: boolean;
67
98
  /** 0.16.x: optional/vestigial. The distiller no longer sets it; a legacy
68
99
  * client may. Honored if present, else the memory stores NULL. */
69
100
  privacy?: string;
70
101
  }
102
+ /**
103
+ * #614 read cap for the relayed marker content, in BYTES. A marker is ONE
104
+ * short line (the key); anything larger is junk someone planted in the file,
105
+ * not a marker — the walk relays at most this many bytes so a multi-KB blob
106
+ * can never ride the capture body. (Judgment constant — a key comfortably
107
+ * fits; matches the common single-read page intuition.)
108
+ */
109
+ export declare const MARKER_READ_CAP_BYTES = 4096;
110
+ /**
111
+ * #614 marker walk: does `.hicortex-confidential` (the constant lives in
112
+ * confidential-marker.ts — the command writes it, this walk reads it) exist
113
+ * at `workspacePath` or any ancestor directory up to `/`, and WHAT does it
114
+ * carry? Returns the marker file's trimmed FIRST line — the content the
115
+ * server validates against its `confidentialMarkerKey` (was a boolean walk
116
+ * in #609; #614 made the marker carry a key, so the client relays content
117
+ * and the SERVER decides). "" = a marker exists but is empty (the pre-#614
118
+ * shape — present, never valid); null = no marker found.
119
+ *
120
+ * Same walk semantics as the #609 boolean: a marked parent covers child
121
+ * workspaces, the marker rides folder renames/moves, one bounded read per
122
+ * ancestor, FIRST hit wins, a PLAIN STRING walk with NO symlink resolution
123
+ * (a symlinked workspace must not silently change which directory chain is
124
+ * inspected), null/empty path → null (Hermes, unknown workspace — a signal
125
+ * is never invented), any stat error reads as absent and the walk continues.
126
+ * A stat-successful but UNREADABLE marker relays "" — the marker is present,
127
+ * its content cannot be validated, so the server refuses it (fail-closed:
128
+ * never confidential off a file we could not read).
129
+ */
130
+ export declare function readConfidentialMarker(workspacePath: string | null | undefined): string | null;
71
131
  /** Normalized POST result the caller's transport returns. */
72
132
  export interface PostResult {
73
133
  status: number;
package/dist/capture.js CHANGED
@@ -14,7 +14,8 @@
14
14
  * multi-night simulation can run as a pure unit test with no HTTP listener.
15
15
  */
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.RATE_LIMIT_RETRIES = exports.MIN_SEGMENT_CHARS = exports.SEGMENT_MAX_CHARS = void 0;
17
+ exports.RATE_LIMIT_RETRIES = exports.MARKER_READ_CAP_BYTES = exports.MIN_SEGMENT_CHARS = exports.SEGMENT_MAX_CHARS = void 0;
18
+ exports.readConfidentialMarker = readConfidentialMarker;
18
19
  exports.hardSplitText = hardSplitText;
19
20
  exports.packSegments = packSegments;
20
21
  exports.isTokenBudget429 = isTokenBudget429;
@@ -22,6 +23,7 @@ exports.captureBatches = captureBatches;
22
23
  exports.acquireCaptureLock = acquireCaptureLock;
23
24
  const node_fs_1 = require("node:fs");
24
25
  const node_path_1 = require("node:path");
26
+ const confidential_marker_js_1 = require("./confidential-marker.js");
25
27
  const distiller_js_1 = require("./distiller.js");
26
28
  /**
27
29
  * Max denoised chars per segment. Kept below the server's 80K distill cap
@@ -43,6 +45,74 @@ exports.SEGMENT_MAX_CHARS = 60_000;
43
45
  exports.MIN_SEGMENT_CHARS = 200;
44
46
  /** Chars added by the "\n\n" joiner extractConversationText places between entries. */
45
47
  const JOINER_CHARS = 2;
48
+ /**
49
+ * #614 read cap for the relayed marker content, in BYTES. A marker is ONE
50
+ * short line (the key); anything larger is junk someone planted in the file,
51
+ * not a marker — the walk relays at most this many bytes so a multi-KB blob
52
+ * can never ride the capture body. (Judgment constant — a key comfortably
53
+ * fits; matches the common single-read page intuition.)
54
+ */
55
+ exports.MARKER_READ_CAP_BYTES = 4096;
56
+ /**
57
+ * #614 marker walk: does `.hicortex-confidential` (the constant lives in
58
+ * confidential-marker.ts — the command writes it, this walk reads it) exist
59
+ * at `workspacePath` or any ancestor directory up to `/`, and WHAT does it
60
+ * carry? Returns the marker file's trimmed FIRST line — the content the
61
+ * server validates against its `confidentialMarkerKey` (was a boolean walk
62
+ * in #609; #614 made the marker carry a key, so the client relays content
63
+ * and the SERVER decides). "" = a marker exists but is empty (the pre-#614
64
+ * shape — present, never valid); null = no marker found.
65
+ *
66
+ * Same walk semantics as the #609 boolean: a marked parent covers child
67
+ * workspaces, the marker rides folder renames/moves, one bounded read per
68
+ * ancestor, FIRST hit wins, a PLAIN STRING walk with NO symlink resolution
69
+ * (a symlinked workspace must not silently change which directory chain is
70
+ * inspected), null/empty path → null (Hermes, unknown workspace — a signal
71
+ * is never invented), any stat error reads as absent and the walk continues.
72
+ * A stat-successful but UNREADABLE marker relays "" — the marker is present,
73
+ * its content cannot be validated, so the server refuses it (fail-closed:
74
+ * never confidential off a file we could not read).
75
+ */
76
+ function readConfidentialMarker(workspacePath) {
77
+ if (!workspacePath)
78
+ return null;
79
+ let dir = workspacePath;
80
+ for (;;) {
81
+ const markerPath = (0, node_path_1.join)(dir, confidential_marker_js_1.CONFIDENTIAL_MARKER_FILENAME);
82
+ try {
83
+ if ((0, node_fs_1.statSync)(markerPath).isFile()) {
84
+ try {
85
+ // Bounded read: open + readSync at the cap, never readFileSync (a
86
+ // planted "marker" of arbitrary size must not be buffered whole).
87
+ const fd = (0, node_fs_1.openSync)(markerPath, "r");
88
+ try {
89
+ const buf = Buffer.alloc(exports.MARKER_READ_CAP_BYTES);
90
+ const n = (0, node_fs_1.readSync)(fd, buf, 0, exports.MARKER_READ_CAP_BYTES, 0);
91
+ // First line only, trimmed: "key\n…" → "key" (CRLF folds through
92
+ // the trim); an empty file → "".
93
+ return buf.subarray(0, n).toString("utf-8").split("\n")[0].trim();
94
+ }
95
+ finally {
96
+ (0, node_fs_1.closeSync)(fd);
97
+ }
98
+ }
99
+ catch {
100
+ // Present but unreadable — see the doc comment: "" (refused), not
101
+ // absent (the marker IS there; pretending otherwise would let a
102
+ // chmod decide confidentiality).
103
+ return "";
104
+ }
105
+ }
106
+ }
107
+ catch {
108
+ /* absent — walk on */
109
+ }
110
+ const parent = (0, node_path_1.dirname)(dir);
111
+ if (parent === dir)
112
+ return null; // reached "/"
113
+ dir = parent;
114
+ }
115
+ }
46
116
  /**
47
117
  * Split an already-denoised string into ≤maxChars pieces (A2 hard-split).
48
118
  * Prefers paragraph, then line, then hard boundaries — mirrors the distiller's
@@ -243,6 +313,16 @@ async function captureBatches(batches, opts) {
243
313
  // has no prefix — keeps ids byte-identical to first-cut and to any already
244
314
  // stored on an older server.
245
315
  const genPrefix = batch.generation > 0 ? `g${batch.generation}.` : "";
316
+ // #609/#614: the workspace birthplace signals, computed ONCE per batch
317
+ // before the segment loop — the marker walk reads the workspace and each
318
+ // ancestor (first hit wins), and both values ride EVERY segment POST so
319
+ // the server can compose its confidentialPaths rule and validate the
320
+ // marker key. null workspace (Hermes / unknown) sends a null path and a
321
+ // null marker — never invented. #614: the client RELAYS marker content
322
+ // (client_marker); it no longer asserts a confidentiality boolean —
323
+ // validation is server-side.
324
+ const workspacePath = batch.workspacePath ?? null;
325
+ const markerContent = readConfidentialMarker(workspacePath);
246
326
  // Cursor value the last confirmed boundary reached — advanced once, at
247
327
  // session end (A4), so per-session file writes stay bounded.
248
328
  let lastConfirmedEnd = batch.startCursor;
@@ -281,6 +361,15 @@ async function captureBatches(batches, opts) {
281
361
  session_id: batch.sessionId,
282
362
  segment_id: `${genPrefix}${seg.segStart}-${seg.segEnd}${seg.idSuffix}`,
283
363
  session_date: batch.date,
364
+ // #609/#614: both workspace signals on every segment (see the
365
+ // per-batch computation above) — the path verbatim, the marker's
366
+ // relayed CONTENT. Old servers never read unknown fields; the
367
+ // pre-#614 client_confidential boolean is deliberately NOT sent
368
+ // (DistillBody keeps the field documented as legacy for the skew
369
+ // window — a #609 server reading only the boolean sees standard,
370
+ // fail-closed, intended).
371
+ workspace_path: workspacePath,
372
+ client_marker: markerContent,
284
373
  };
285
374
  let result;
286
375
  try {