@remnic/core 1.1.23 → 1.1.24

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.
@@ -2,6 +2,8 @@ declare const OFFLINE_SYNC_SNAPSHOT_FORMAT = "remnic.offline-sync.snapshot.v1";
2
2
  declare const OFFLINE_SYNC_CHANGESET_FORMAT = "remnic.offline-sync.changeset.v1";
3
3
  declare const OFFLINE_SYNC_STATE_VERSION = 1;
4
4
  declare const OFFLINE_SYNC_FILE_CONTENT_MAX_CHUNK_BYTES: number;
5
+ declare const OFFLINE_SYNC_FILE_CONTENT_TRANSFER_CHUNK_BYTES: number;
6
+ declare const OFFLINE_SYNC_APPLY_MAX_BODY_BYTES: number;
5
7
  interface OfflineSyncFileState {
6
8
  path: string;
7
9
  sha256: string;
@@ -200,4 +202,4 @@ declare function offlineSyncStateFromSnapshot(options: {
200
202
  declare function normalizeOfflineSyncState(input: unknown): OfflineSyncState;
201
203
  declare function fileStatesFromSnapshot(snapshot: OfflineSyncSnapshot): OfflineSyncFileState[];
202
204
 
203
- export { OFFLINE_SYNC_CHANGESET_FORMAT, OFFLINE_SYNC_FILE_CONTENT_MAX_CHUNK_BYTES, OFFLINE_SYNC_SNAPSHOT_FORMAT, OFFLINE_SYNC_STATE_VERSION, type OfflineSyncApplyChangesetResult, type OfflineSyncApplyFileContentChunkResult, type OfflineSyncApplySnapshotResult, type OfflineSyncChange, type OfflineSyncChangeset, type OfflineSyncChangesetSummary, type OfflineSyncConflict, type OfflineSyncFileContentChunk, type OfflineSyncFileRecord, type OfflineSyncFileStagingWriteTarget, type OfflineSyncFileState, type OfflineSyncFileTarget, type OfflineSyncFileWriteChunksTarget, type OfflineSyncFileWriteTarget, type OfflineSyncSnapshot, type OfflineSyncState, applyOfflineSyncChangeset, applyOfflineSyncFileContentChunk, applyOfflineSyncSnapshot, buildOfflineSyncChangeset, buildOfflineSyncSnapshot, buildOfflineSyncSnapshotForPaths, defaultOfflineSyncStatePath, fileStatesFromSnapshot, normalizeOfflineSyncChangeset, normalizeOfflineSyncSnapshot, normalizeOfflineSyncState, offlineSyncStateFromSnapshot, readOfflineSyncFileContentChunk, readOfflineSyncState, summarizeOfflineSyncChangeset, summarizeOfflineSyncPendingChanges, writeOfflineSyncState };
205
+ export { OFFLINE_SYNC_APPLY_MAX_BODY_BYTES, OFFLINE_SYNC_CHANGESET_FORMAT, OFFLINE_SYNC_FILE_CONTENT_MAX_CHUNK_BYTES, OFFLINE_SYNC_FILE_CONTENT_TRANSFER_CHUNK_BYTES, OFFLINE_SYNC_SNAPSHOT_FORMAT, OFFLINE_SYNC_STATE_VERSION, type OfflineSyncApplyChangesetResult, type OfflineSyncApplyFileContentChunkResult, type OfflineSyncApplySnapshotResult, type OfflineSyncChange, type OfflineSyncChangeset, type OfflineSyncChangesetSummary, type OfflineSyncConflict, type OfflineSyncFileContentChunk, type OfflineSyncFileRecord, type OfflineSyncFileStagingWriteTarget, type OfflineSyncFileState, type OfflineSyncFileTarget, type OfflineSyncFileWriteChunksTarget, type OfflineSyncFileWriteTarget, type OfflineSyncSnapshot, type OfflineSyncState, applyOfflineSyncChangeset, applyOfflineSyncFileContentChunk, applyOfflineSyncSnapshot, buildOfflineSyncChangeset, buildOfflineSyncSnapshot, buildOfflineSyncSnapshotForPaths, defaultOfflineSyncStatePath, fileStatesFromSnapshot, normalizeOfflineSyncChangeset, normalizeOfflineSyncSnapshot, normalizeOfflineSyncState, offlineSyncStateFromSnapshot, readOfflineSyncFileContentChunk, readOfflineSyncState, summarizeOfflineSyncChangeset, summarizeOfflineSyncPendingChanges, writeOfflineSyncState };
@@ -1,6 +1,8 @@
1
1
  import {
2
+ OFFLINE_SYNC_APPLY_MAX_BODY_BYTES,
2
3
  OFFLINE_SYNC_CHANGESET_FORMAT,
3
4
  OFFLINE_SYNC_FILE_CONTENT_MAX_CHUNK_BYTES,
5
+ OFFLINE_SYNC_FILE_CONTENT_TRANSFER_CHUNK_BYTES,
4
6
  OFFLINE_SYNC_SNAPSHOT_FORMAT,
5
7
  OFFLINE_SYNC_STATE_VERSION,
6
8
  applyOfflineSyncChangeset,
@@ -20,7 +22,7 @@ import {
20
22
  summarizeOfflineSyncChangeset,
21
23
  summarizeOfflineSyncPendingChanges,
22
24
  writeOfflineSyncState
23
- } from "./chunk-JKXFF3NT.js";
25
+ } from "./chunk-AMVN77EU.js";
24
26
  import "./chunk-I6K5FBRQ.js";
25
27
  import "./chunk-AGZQD76C.js";
26
28
  import "./chunk-MXFBBHJU.js";
@@ -28,8 +30,10 @@ import "./chunk-A6XUJE5D.js";
28
30
  import "./chunk-P7FMDTKL.js";
29
31
  import "./chunk-PZ5AY32C.js";
30
32
  export {
33
+ OFFLINE_SYNC_APPLY_MAX_BODY_BYTES,
31
34
  OFFLINE_SYNC_CHANGESET_FORMAT,
32
35
  OFFLINE_SYNC_FILE_CONTENT_MAX_CHUNK_BYTES,
36
+ OFFLINE_SYNC_FILE_CONTENT_TRANSFER_CHUNK_BYTES,
33
37
  OFFLINE_SYNC_SNAPSHOT_FORMAT,
34
38
  OFFLINE_SYNC_STATE_VERSION,
35
39
  applyOfflineSyncChangeset,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remnic/core",
3
- "version": "1.1.23",
3
+ "version": "1.1.24",
4
4
  "description": "Framework-agnostic Remnic memory engine — orchestrator, storage, extraction, search, trust zones",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -557,7 +557,7 @@ test("HTTP offline apply-file-content forwards binary chunks and metadata", asyn
557
557
  }
558
558
  });
559
559
 
560
- test("HTTP offline apply-file-content rate limits accepted chunks", async () => {
560
+ test("HTTP offline apply-file-content allows bulk sync chunks outside the generic write throttle", async () => {
561
561
  let calls = 0;
562
562
  const service = {
563
563
  offlineSyncApplyFileContent: async (options: {
@@ -618,8 +618,8 @@ test("HTTP offline apply-file-content rate limits accepted chunks", async () =>
618
618
  await response.arrayBuffer();
619
619
  }
620
620
 
621
- assert.equal(lastStatus, 429);
622
- assert.equal(calls, 30);
621
+ assert.equal(lastStatus, 200);
622
+ assert.equal(calls, 31);
623
623
  } finally {
624
624
  await server.stop();
625
625
  }
@@ -726,6 +726,69 @@ test("HTTP offline apply validates and forwards changesets", async () => {
726
726
  }
727
727
  });
728
728
 
729
+ test("HTTP offline apply accepts bulk changesets above the generic JSON body limit", async () => {
730
+ let calls = 0;
731
+ const largeContent = Buffer.alloc(256 * 1024, 7).toString("base64");
732
+ const changeset = {
733
+ format: "remnic.offline-sync.changeset.v1",
734
+ schemaVersion: 1,
735
+ createdAt: new Date("2026-05-21T00:00:00Z").toISOString(),
736
+ sourceId: "laptop:test",
737
+ includeTranscripts: true,
738
+ changes: [{
739
+ type: "upsert",
740
+ path: "facts/large.md",
741
+ file: {
742
+ path: "facts/large.md",
743
+ sha256: "b".repeat(64),
744
+ bytes: 256 * 1024,
745
+ mtimeMs: 1,
746
+ contentBase64: largeContent,
747
+ },
748
+ }],
749
+ };
750
+ const service = {
751
+ offlineSyncApply: async () => {
752
+ calls += 1;
753
+ return {
754
+ namespace: "team",
755
+ appliedUpserts: 1,
756
+ appliedDeletes: 0,
757
+ skipped: 0,
758
+ conflicts: [],
759
+ currentFiles: [],
760
+ };
761
+ },
762
+ } as unknown as EngramAccessService;
763
+ const server = new EngramAccessHttpServer({
764
+ service,
765
+ port: 0,
766
+ authToken: "test-token",
767
+ principal: "writer",
768
+ maxBodyBytes: 1024,
769
+ adminConsoleEnabled: false,
770
+ });
771
+
772
+ const status = await server.start();
773
+ try {
774
+ const response = await fetch(`http://127.0.0.1:${status.port}/remnic/v1/offline-sync/apply`, {
775
+ method: "POST",
776
+ headers: {
777
+ authorization: "Bearer test-token",
778
+ "content-type": "application/json",
779
+ },
780
+ body: JSON.stringify({ namespace: "team", changeset }),
781
+ });
782
+ const body = await response.json() as { appliedUpserts?: number };
783
+
784
+ assert.equal(response.status, 200);
785
+ assert.equal(body.appliedUpserts, 1);
786
+ assert.equal(calls, 1);
787
+ } finally {
788
+ await server.stop();
789
+ }
790
+ });
791
+
729
792
  test("HTTP offline apply requires a changeset", async () => {
730
793
  let calls = 0;
731
794
  const service = {
@@ -9,7 +9,10 @@ import { log } from "./logger.js";
9
9
  import { EngramAccessInputError, type EngramAccessService } from "./access-service.js";
10
10
  import { EngramMcpServer } from "./access-mcp.js";
11
11
  import { validateRequest, type SchemaName, type SchemaTypeFor } from "./access-schema.js";
12
- import { OFFLINE_SYNC_FILE_CONTENT_MAX_CHUNK_BYTES } from "./offline-sync.js";
12
+ import {
13
+ OFFLINE_SYNC_APPLY_MAX_BODY_BYTES,
14
+ OFFLINE_SYNC_FILE_CONTENT_MAX_CHUNK_BYTES,
15
+ } from "./offline-sync.js";
13
16
  import type { RecallDisclosure, RecallPlanMode } from "./types.js";
14
17
  import { isRecallDisclosure } from "./types.js";
15
18
  import { isTrustZoneName, type TrustZoneName, type TrustZoneRecordKind, type TrustZoneSourceClass } from "./trust-zones.js";
@@ -680,8 +683,6 @@ export class EngramAccessHttpServer {
680
683
  const namespaceParam = parsed.searchParams.get("namespace");
681
684
  const bytes = this.readRequiredIntegerHeader(req, "x-remnic-file-bytes");
682
685
  const offset = this.readOptionalIntegerHeader(req, "x-remnic-chunk-offset") ?? 0;
683
- const startsUpload = offset === 0;
684
- if (startsUpload) this.ensureWriteRateLimitAvailable();
685
686
  const content = await this.readBinaryBody(req, OFFLINE_SYNC_FILE_CONTENT_MAX_CHUNK_BYTES);
686
687
  const result = await this.service.offlineSyncApplyFileContent({
687
688
  namespace: this.resolveNamespace(
@@ -703,7 +704,6 @@ export class EngramAccessHttpServer {
703
704
  baseSha256: this.readOptionalHeader(req, "x-remnic-base-sha256"),
704
705
  content,
705
706
  });
706
- if (startsUpload) this.recordWriteRateLimitHit();
707
707
  this.respondJson(res, 200, result);
708
708
  return;
709
709
  }
@@ -712,14 +712,12 @@ export class EngramAccessHttpServer {
712
712
  req.method === "POST" &&
713
713
  (pathname === "/engram/v1/offline-sync/apply" || pathname === "/remnic/v1/offline-sync/apply")
714
714
  ) {
715
- const body = await this.readValidatedBody(req, "offlineSyncApply");
716
- this.ensureWriteRateLimitAvailable();
715
+ const body = await this.readValidatedBody(req, "offlineSyncApply", OFFLINE_SYNC_APPLY_MAX_BODY_BYTES);
717
716
  const result = await this.service.offlineSyncApply({
718
717
  namespace: this.resolveNamespace(req, body.namespace),
719
718
  principal: this.resolveRequestPrincipal(req),
720
719
  changeset: body.changeset,
721
720
  });
722
- this.recordWriteRateLimitHit();
723
721
  this.respondJson(res, 200, result);
724
722
  return;
725
723
  }
@@ -1924,13 +1922,16 @@ export class EngramAccessHttpServer {
1924
1922
  }
1925
1923
  }
1926
1924
 
1927
- private async readJsonBody(req: IncomingMessage): Promise<Record<string, unknown>> {
1925
+ private async readJsonBody(
1926
+ req: IncomingMessage,
1927
+ maxBodyBytes = this.maxBodyBytes,
1928
+ ): Promise<Record<string, unknown>> {
1928
1929
  const chunks: Buffer[] = [];
1929
1930
  let total = 0;
1930
1931
  for await (const chunk of req) {
1931
1932
  const buffer = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
1932
1933
  total += buffer.length;
1933
- if (total > this.maxBodyBytes) {
1934
+ if (total > maxBodyBytes) {
1934
1935
  throw new HttpError(413, "request_body_too_large", "request_body_too_large");
1935
1936
  }
1936
1937
  chunks.push(buffer);
@@ -2027,8 +2028,12 @@ export class EngramAccessHttpServer {
2027
2028
  throw new EngramAccessInputError(`${name} header must be one of: true, false`);
2028
2029
  }
2029
2030
 
2030
- private async readValidatedBody<S extends SchemaName>(req: IncomingMessage, schemaName: S): Promise<SchemaTypeFor<S>> {
2031
- const raw = await this.readJsonBody(req);
2031
+ private async readValidatedBody<S extends SchemaName>(
2032
+ req: IncomingMessage,
2033
+ schemaName: S,
2034
+ maxBodyBytes?: number,
2035
+ ): Promise<SchemaTypeFor<S>> {
2036
+ const raw = await this.readJsonBody(req, maxBodyBytes);
2032
2037
  const result = validateRequest(schemaName, raw);
2033
2038
  if (!result.success) {
2034
2039
  throw new HttpError(400, result.error.error, "validation_error", result.error.details);
package/src/index.ts CHANGED
@@ -679,8 +679,10 @@ export {
679
679
  // ---------------------------------------------------------------------------
680
680
 
681
681
  export {
682
+ OFFLINE_SYNC_APPLY_MAX_BODY_BYTES,
682
683
  OFFLINE_SYNC_CHANGESET_FORMAT,
683
684
  OFFLINE_SYNC_FILE_CONTENT_MAX_CHUNK_BYTES,
685
+ OFFLINE_SYNC_FILE_CONTENT_TRANSFER_CHUNK_BYTES,
684
686
  OFFLINE_SYNC_SNAPSHOT_FORMAT,
685
687
  OFFLINE_SYNC_STATE_VERSION,
686
688
  applyOfflineSyncFileContentChunk,
@@ -29,6 +29,8 @@ export const OFFLINE_SYNC_SNAPSHOT_FORMAT = "remnic.offline-sync.snapshot.v1";
29
29
  export const OFFLINE_SYNC_CHANGESET_FORMAT = "remnic.offline-sync.changeset.v1";
30
30
  export const OFFLINE_SYNC_STATE_VERSION = 1;
31
31
  export const OFFLINE_SYNC_FILE_CONTENT_MAX_CHUNK_BYTES = 64 * 1024 * 1024;
32
+ export const OFFLINE_SYNC_FILE_CONTENT_TRANSFER_CHUNK_BYTES = 8 * 1024 * 1024;
33
+ export const OFFLINE_SYNC_APPLY_MAX_BODY_BYTES = 16 * 1024 * 1024;
32
34
 
33
35
  export interface OfflineSyncFileState {
34
36
  path: string;
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/access-http.ts"],"sourcesContent":["import { createServer, type IncomingMessage, type Server, type ServerResponse } from \"node:http\";\nimport { randomUUID, timingSafeEqual } from \"node:crypto\";\nimport { AsyncLocalStorage } from \"node:async_hooks\";\nimport { existsSync } from \"node:fs\";\nimport { readFile } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { fileURLToPath, URL } from \"node:url\";\nimport { log } from \"./logger.js\";\nimport { EngramAccessInputError, type EngramAccessService } from \"./access-service.js\";\nimport { EngramMcpServer } from \"./access-mcp.js\";\nimport { validateRequest, type SchemaName, type SchemaTypeFor } from \"./access-schema.js\";\nimport { OFFLINE_SYNC_FILE_CONTENT_MAX_CHUNK_BYTES } from \"./offline-sync.js\";\nimport type { RecallDisclosure, RecallPlanMode } from \"./types.js\";\nimport { isRecallDisclosure } from \"./types.js\";\nimport { isTrustZoneName, type TrustZoneName, type TrustZoneRecordKind, type TrustZoneSourceClass } from \"./trust-zones.js\";\nimport { AdapterRegistry, type ResolvedIdentity } from \"./adapters/index.js\";\nimport type { CitationEntry } from \"./citations.js\";\nimport {\n subscribeGraphEvents,\n type GraphEvent,\n} from \"./graph-events.js\";\nimport { expandTildePath } from \"./utils/path.js\";\n\nexport interface EngramAccessHttpServerOptions {\n service: EngramAccessService;\n host?: string;\n port?: number;\n authToken?: string;\n /** Additional valid tokens (for multi-connector auth). Checked alongside authToken. */\n authTokens?: string[];\n /** Dynamic token loader — called on each auth check so new/revoked tokens take effect without restart. */\n authTokensGetter?: () => string[];\n principal?: string;\n maxBodyBytes?: number;\n adminConsoleEnabled?: boolean;\n adminConsolePublicDir?: string;\n trustPrincipalHeader?: boolean;\n /** Enable adapter-based identity resolution from request headers */\n enableAdapters?: boolean;\n /** Custom adapter registry (defaults to built-in adapters) */\n adapterRegistry?: AdapterRegistry;\n /** Enable oai-mem-citation blocks in recall responses (issue #379). */\n citationsEnabled?: boolean;\n /** Auto-enable citations for Codex adapter connections (issue #379). */\n citationsAutoDetect?: boolean;\n}\n\nexport interface EngramAccessHttpServerStatus {\n running: boolean;\n host: string;\n port: number;\n maxBodyBytes: number;\n}\n\nfunction resolveDefaultAdminConsolePublicDir(): string {\n const thisDir = path.dirname(fileURLToPath(import.meta.url));\n const candidates = [\n // Standard: admin-console sibling to src/ (development layout)\n path.resolve(thisDir, \"../admin-console/public\"),\n // Bundled: admin-console inside dist/ alongside the bundle\n path.resolve(thisDir, \"./admin-console/public\"),\n // Package root: walk up from dist/ to the package root\n path.resolve(thisDir, \"../../admin-console/public\"),\n ];\n return candidates.find((candidate) => existsSync(candidate)) ?? candidates[0];\n}\n\nconst defaultAdminConsolePublicDir = resolveDefaultAdminConsolePublicDir();\nconst correlationIdStore = new AsyncLocalStorage<string>();\n\nconst WRITE_RATE_LIMIT_WINDOW_MS = 60_000;\nconst WRITE_RATE_LIMIT_MAX_REQUESTS = 30;\nconst TRUST_ZONE_RECORD_KINDS = [\"memory\", \"artifact\", \"state\", \"trajectory\", \"external\"] as const;\nconst TRUST_ZONE_SOURCE_CLASSES = [\"tool_output\", \"web_content\", \"subagent_trace\", \"system_memory\", \"user_input\", \"manual\"] as const;\n\nclass HttpError extends Error {\n readonly code: string;\n readonly details?: unknown;\n constructor(readonly status: number, message: string, code?: string, details?: unknown) {\n super(message);\n this.code = code ?? `http_${status}`;\n this.details = details;\n }\n}\n\nfunction hostToUrlAuthority(host: string): string {\n if (host.includes(\":\") && !host.startsWith(\"[\") && !host.endsWith(\"]\")) {\n return `[${host}]`;\n }\n return host;\n}\n\nfunction parseHttpServerPort(port: number | undefined): number {\n if (port === undefined) return 0;\n if (!Number.isInteger(port) || port < 0 || port > 65535) {\n throw new Error(\"access HTTP port must be an integer from 0 to 65535\");\n }\n return port;\n}\n\nfunction parseTrustZoneKindFilter(raw: string | null): TrustZoneRecordKind | undefined {\n if (raw === null) return undefined;\n if ((TRUST_ZONE_RECORD_KINDS as readonly string[]).includes(raw)) {\n return raw as TrustZoneRecordKind;\n }\n throw new HttpError(400, `kind must be one of ${TRUST_ZONE_RECORD_KINDS.join(\"|\")}`, \"invalid_kind_filter\");\n}\n\nfunction parseTrustZoneSourceClassFilter(raw: string | null): TrustZoneSourceClass | undefined {\n if (raw === null) return undefined;\n if ((TRUST_ZONE_SOURCE_CLASSES as readonly string[]).includes(raw)) {\n return raw as TrustZoneSourceClass;\n }\n throw new HttpError(400, `sourceClass must be one of ${TRUST_ZONE_SOURCE_CLASSES.join(\"|\")}`, \"invalid_source_class_filter\");\n}\n\nfunction parseTrustZoneFilter(raw: string | null): TrustZoneName | undefined {\n if (raw === null) return undefined;\n if (isTrustZoneName(raw)) {\n return raw;\n }\n throw new HttpError(400, \"zone must be one of quarantine|working|trusted\", \"invalid_zone_filter\");\n}\n\n/**\n * Decode a `:peerId` URL path segment, converting malformed percent-encoded\n * input (e.g., `%E0%A4%A`) into a 400 client error rather than letting\n * `URIError` bubble up as a 500 `internal_error`.\n */\nfunction decodePeerIdSegment(raw: string): string {\n try {\n return decodeURIComponent(raw);\n } catch {\n throw new EngramAccessInputError(\"peerId path segment is not valid percent-encoded input\");\n }\n}\n\nexport class EngramAccessHttpServer {\n private readonly service: EngramAccessService;\n private readonly host: string;\n private readonly requestedPort: number;\n private readonly authToken?: string;\n private readonly authTokens: string[];\n private readonly authTokensGetter?: () => string[];\n private readonly authenticatedPrincipal?: string;\n private readonly maxBodyBytes: number;\n private readonly adminConsoleEnabled: boolean;\n private readonly adminConsolePublicDir: string;\n private readonly trustPrincipalHeader: boolean;\n private readonly adapterRegistry: AdapterRegistry | null;\n private readonly writeRequestTimestamps: number[] = [];\n private readonly mcpServer: EngramMcpServer;\n private server: Server | null = null;\n private boundPort = 0;\n /** Active SSE response objects for /engram/v1/graph/events. */\n private readonly sseClients = new Set<ServerResponse>();\n /** Throttle batch: pending SSE event batches per client. */\n private readonly sseBatchTimers = new Map<ServerResponse, ReturnType<typeof setTimeout>>();\n private readonly ssePendingBatches = new Map<ServerResponse, GraphEvent[]>();\n /**\n * Per-client cleanup callbacks: clear heartbeat interval, flush timer,\n * unsubscribe from bus, and end the response. Stored here so `stop()`\n * can invoke them even when the client hasn't disconnected yet\n * (Cursor review thread `access-http.ts:232`).\n */\n private readonly sseCleanupFns = new Set<() => void>();\n\n constructor(options: EngramAccessHttpServerOptions) {\n this.service = options.service;\n this.host = options.host?.trim() || \"127.0.0.1\";\n this.requestedPort = parseHttpServerPort(options.port);\n this.authToken = options.authToken?.trim() || undefined;\n this.authTokens = (options.authTokens ?? []).map((t) => t.trim()).filter(Boolean);\n this.authTokensGetter = options.authTokensGetter;\n this.authenticatedPrincipal = options.principal?.trim() || undefined;\n this.maxBodyBytes = Number.isFinite(options.maxBodyBytes)\n ? Math.max(1, Math.floor(options.maxBodyBytes ?? 131072))\n : 131072;\n this.adminConsoleEnabled = options.adminConsoleEnabled !== false;\n this.adminConsolePublicDir = options.adminConsolePublicDir ?? defaultAdminConsolePublicDir;\n this.trustPrincipalHeader = options.trustPrincipalHeader === true;\n this.adapterRegistry = options.enableAdapters !== false\n ? (options.adapterRegistry ?? new AdapterRegistry())\n : null;\n this.mcpServer = new EngramMcpServer(this.service, {\n principal: options.principal,\n citationsEnabled: options.citationsEnabled,\n citationsAutoDetect: options.citationsAutoDetect,\n });\n }\n\n async start(): Promise<EngramAccessHttpServerStatus> {\n if (!this.authToken && this.authTokens.length === 0 && !this.authTokensGetter) {\n throw new Error(\"engram access HTTP requires authToken or authTokens\");\n }\n if (this.server) return this.status();\n\n const server = createServer((req, res) => {\n const correlationId = randomUUID();\n correlationIdStore.run(correlationId, () => {\n void this.handle(req, res, correlationId).catch((err) => {\n log.debug(`engram access HTTP request failed [${correlationId}]: ${err}`);\n if (err instanceof HttpError) {\n const payload: Record<string, unknown> = { error: err.message, code: err.code };\n if (err.details) payload.details = err.details;\n this.respondJson(res, err.status, payload);\n return;\n }\n if (err instanceof EngramAccessInputError) {\n this.respondJson(res, 400, { error: err.message, code: \"input_error\" });\n return;\n }\n if (res.headersSent) {\n res.destroy(err as Error);\n return;\n }\n this.respondJson(res, 500, { error: \"internal_error\", code: \"internal_error\" });\n });\n });\n });\n\n try {\n await new Promise<void>((resolve, reject) => {\n const onError = (err: Error) => {\n server.off(\"listening\", onListening);\n reject(err);\n };\n const onListening = () => {\n server.off(\"error\", onError);\n resolve();\n };\n server.once(\"error\", onError);\n server.once(\"listening\", onListening);\n server.listen(this.requestedPort, this.host);\n });\n } catch (err) {\n server.close();\n throw err;\n }\n\n this.server = server;\n const address = server.address();\n this.boundPort = typeof address === \"object\" && address ? address.port : this.requestedPort;\n return this.status();\n }\n\n async stop(): Promise<void> {\n if (!this.server) return;\n const server = this.server;\n this.server = null;\n this.boundPort = 0;\n // Invoke each SSE client's cleanup callback so heartbeat intervals,\n // batch timers, and graph-bus subscriptions are all released before the\n // HTTP server closes. Without this, long-running SSE connections leak\n // setInterval handles and EventEmitter listeners (Cursor review thread\n // `access-http.ts:232`).\n for (const cleanup of this.sseCleanupFns) {\n try { cleanup(); } catch { /* ignore */ }\n }\n this.sseCleanupFns.clear();\n // Belt-and-suspenders: clear any state not yet reached by cleanup fns.\n for (const [res, timer] of this.sseBatchTimers.entries()) {\n clearTimeout(timer);\n this.sseBatchTimers.delete(res);\n }\n this.ssePendingBatches.clear();\n for (const res of this.sseClients) {\n try { res.end(); } catch { /* ignore */ }\n }\n this.sseClients.clear();\n await new Promise<void>((resolve, reject) => {\n server.close((err) => (err ? reject(err) : resolve()));\n });\n }\n\n status(): EngramAccessHttpServerStatus {\n return {\n running: this.server !== null,\n host: this.host,\n port: this.boundPort,\n maxBodyBytes: this.maxBodyBytes,\n };\n }\n\n /**\n * Resolve the adapter identity for the incoming request.\n * Includes MCP clientInfo from the last initialize handshake if available.\n * Returns null if no adapter matches or adapters are disabled.\n */\n resolveAdapterIdentity(req: IncomingMessage): ResolvedIdentity | null {\n if (!this.adapterRegistry) return null;\n // Look up clientInfo for this specific MCP session to avoid cross-session leaks.\n // Non-MCP requests (no mcp-session-id header) get undefined clientInfo and\n // rely on HTTP headers for adapter matching.\n const sessionId = (() => {\n const raw = req.headers[\"mcp-session-id\"];\n return typeof raw === \"string\" ? raw.trim() : undefined;\n })();\n return this.adapterRegistry.resolve({\n headers: req.headers as Record<string, string | string[] | undefined>,\n clientInfo: this.mcpServer.getClientInfo(sessionId),\n });\n }\n\n /** Cache for per-request identity resolution (avoids double adapter resolution) */\n private identityCache = new WeakMap<IncomingMessage, { principal?: string; namespace?: string }>();\n\n /** Resolve principal and namespace from request headers and adapter identity */\n private resolveRequestIdentity(req: IncomingMessage): { principal?: string; namespace?: string } {\n const cached = this.identityCache.get(req);\n if (cached) return cached;\n let principal: string | undefined;\n let namespace: string | undefined;\n\n // Explicit header override takes priority for principal\n if (this.trustPrincipalHeader) {\n const headerVal = req.headers[\"x-engram-principal\"];\n const raw = Array.isArray(headerVal) ? headerVal[0] : headerVal;\n if (typeof raw === \"string\") {\n const trimmed = raw.trim();\n if (trimmed.length > 0) {\n principal = trimmed;\n }\n }\n }\n\n // Try adapter-based identity resolution for both principal and namespace\n const adapterIdentity = this.resolveAdapterIdentity(req);\n if (adapterIdentity) {\n if (!principal) {\n principal = adapterIdentity.principal;\n }\n namespace = adapterIdentity.namespace;\n }\n\n if (!principal) {\n principal = this.authenticatedPrincipal;\n }\n\n const result = { principal, namespace };\n this.identityCache.set(req, result);\n return result;\n }\n\n private resolveRequestPrincipal(req: IncomingMessage): string | undefined {\n return this.resolveRequestIdentity(req).principal;\n }\n\n /** Resolve namespace: only use the explicit body value. Adapter-inferred namespace\n * is intentionally NOT used as a fallback for REST requests — omitting namespace\n * should default to the server's global namespace, not silently scope to an adapter. */\n private resolveNamespace(_req: IncomingMessage, bodyNamespace?: string): string | undefined {\n return bodyNamespace || undefined;\n }\n\n /**\n * Resolve the recall disclosure depth from the request (issue #677 PR\n * 2/4). Explicit body value wins; otherwise we accept a\n * `?disclosure=...` query parameter so curl/browser tooling can use the\n * three-tier surface without rewriting JSON. Invalid query values\n * throw `EngramAccessInputError` (CLAUDE.md rule 51 — no silent\n * fallback). An absent body field AND an absent query param yields\n * `undefined`, which the service maps to `DEFAULT_RECALL_DISCLOSURE`.\n */\n private resolveRecallDisclosure(\n bodyDisclosure: RecallDisclosure | undefined,\n parsed: URL,\n ): RecallDisclosure | undefined {\n if (bodyDisclosure !== undefined) {\n return bodyDisclosure;\n }\n const queryDisclosure = parsed.searchParams.get(\"disclosure\");\n if (queryDisclosure === null) {\n return undefined;\n }\n if (!isRecallDisclosure(queryDisclosure)) {\n throw new EngramAccessInputError(\n `disclosure must be one of: chunk, section, raw (got: ${queryDisclosure})`,\n );\n }\n return queryDisclosure;\n }\n\n private async handle(req: IncomingMessage, res: ServerResponse, correlationId: string): Promise<void> {\n const parsed = new URL(req.url ?? \"/\", `http://${hostToUrlAuthority(this.host)}`);\n const pathname = parsed.pathname;\n\n if (this.adminConsoleEnabled && await this.handleAdminConsole(req, res, pathname)) {\n return;\n }\n\n if (!this.isAuthorized(req, pathname)) {\n const body = JSON.stringify({ error: \"unauthorized\", code: \"unauthorized\" });\n res.writeHead(401, {\n \"content-type\": \"application/json; charset=utf-8\",\n \"www-authenticate\": \"Bearer\",\n \"x-request-id\": correlationId,\n });\n res.end(body);\n return;\n }\n\n if (req.method === \"POST\" && pathname === \"/mcp\") {\n await this.handleMcpRequest(req, res);\n return;\n }\n\n if (req.method === \"GET\" && pathname === \"/engram/v1/health\") {\n this.respondJson(res, 200, await this.service.health());\n return;\n }\n\n if (req.method === \"GET\" && pathname === \"/engram/v1/adapters\") {\n const identity = this.resolveAdapterIdentity(req);\n this.respondJson(res, 200, {\n adaptersEnabled: this.adapterRegistry !== null,\n registered: this.adapterRegistry?.list() ?? [],\n resolved: identity,\n });\n return;\n }\n\n if (req.method === \"POST\" && pathname === \"/engram/v1/recall\") {\n const body = await this.readValidatedBody(req, \"recall\");\n // Preserve the distinction between `codingContext: null` (explicit\n // clear) and `codingContext` missing from the JSON payload\n // (untouched). The previous `?? undefined` collapsed both into\n // undefined, so callers lost the ability to clear the session's\n // attached context through the recall endpoint.\n const codingContext =\n \"codingContext\" in body ? body.codingContext : undefined;\n // Disclosure resolution (issue #677 PR 2/4): accept the value from\n // the validated body OR the `?disclosure=` query parameter, with\n // the body taking precedence so an explicit JSON payload is never\n // silently overridden by a stale URL. CLAUDE.md rule 51: invalid\n // query-param values throw, never fall back silently.\n const disclosure = this.resolveRecallDisclosure(body.disclosure, parsed);\n // Issue #680 — historical recall pin (`asOf`). Body field wins\n // over `?as_of=` query param. Empty query is rejected only when\n // the body didn't supply a valid pin (codex P2 + cursor Medium).\n const asOfQueryRaw = parsed.searchParams.get(\"as_of\");\n const bodyHasAsOf =\n typeof body.asOf === \"string\" && body.asOf.length > 0;\n if (\n !bodyHasAsOf &&\n asOfQueryRaw !== null &&\n asOfQueryRaw.length === 0\n ) {\n throw new EngramAccessInputError(\n \"as_of must be a non-empty timestamp (got empty value)\",\n );\n }\n const asOf =\n body.asOf ??\n (asOfQueryRaw !== null && asOfQueryRaw.length > 0\n ? asOfQueryRaw\n : undefined);\n // Tag filter (issue #689). Body presence wins over query params\n // — explicit `tags: []` in body clears the filter even with\n // stale `?tag=` URLs.\n const bodyHasTagsField =\n body !== null &&\n typeof body === \"object\" &&\n \"tags\" in (body as Record<string, unknown>);\n const bodyTagsValue = bodyHasTagsField\n ? (body as { tags?: unknown }).tags\n : undefined;\n const bodyTags = Array.isArray(bodyTagsValue)\n ? (bodyTagsValue as string[])\n : undefined;\n const queryTags = parsed.searchParams.getAll(\"tag\");\n const tags = bodyHasTagsField\n ? bodyTags\n : queryTags.length > 0\n ? queryTags\n : undefined;\n const bodyTagMatch = (body as { tagMatch?: unknown }).tagMatch;\n let tagMatch: \"any\" | \"all\" | undefined;\n if (bodyTagMatch !== undefined) {\n if (bodyTagMatch === \"any\" || bodyTagMatch === \"all\") {\n tagMatch = bodyTagMatch;\n }\n } else {\n const queryTagMatch = parsed.searchParams.get(\"tag_match\");\n if (queryTagMatch !== null) {\n if (queryTagMatch !== \"any\" && queryTagMatch !== \"all\") {\n throw new EngramAccessInputError(\n `tag_match must be one of: any, all (got: ${queryTagMatch})`,\n );\n }\n tagMatch = queryTagMatch;\n }\n }\n // Issue #681 — `?include_low_confidence=true|false` mirrors the CLI\n // `--include-low-confidence` flag. Body field wins so a JSON payload can\n // explicitly clear a stale query parameter.\n const bodyIncludeLowConfidence =\n (body as { includeLowConfidence?: unknown }).includeLowConfidence;\n const queryIncludeLowConfidence = parsed.searchParams.get(\"include_low_confidence\");\n if (\n bodyIncludeLowConfidence === undefined &&\n queryIncludeLowConfidence !== null &&\n queryIncludeLowConfidence !== \"true\" &&\n queryIncludeLowConfidence !== \"false\"\n ) {\n throw new EngramAccessInputError(\n `include_low_confidence must be one of: true, false (got: ${queryIncludeLowConfidence})`,\n );\n }\n const includeLowConfidence =\n bodyIncludeLowConfidence === true ||\n (bodyIncludeLowConfidence === undefined &&\n queryIncludeLowConfidence === \"true\");\n const response = await this.service.recall({\n query: body.query ?? \"\",\n sessionKey: body.sessionKey,\n authenticatedPrincipal: this.resolveRequestPrincipal(req),\n idempotencyKey: body.idempotencyKey,\n namespace: this.resolveNamespace(req, body.namespace),\n topK: body.topK,\n mode: body.mode as RecallPlanMode | \"auto\" | undefined,\n includeDebug: body.includeDebug === true,\n // Forward the validated disclosure depth to the service layer\n // (issue #677). The zod schema accepts/rejects body values;\n // `resolveRecallDisclosure()` validates the query-param fallback.\n disclosure,\n codingContext,\n // Forward cwd/projectTag for auto git-context resolution (issue #569).\n cwd: body.cwd,\n projectTag: body.projectTag,\n ...(asOf !== undefined ? { asOf } : {}),\n ...(tags !== undefined ? { tags } : {}),\n ...(tagMatch !== undefined ? { tagMatch } : {}),\n ...(includeLowConfidence ? { includeLowConfidence: true } : {}),\n });\n this.respondJson(res, 200, response);\n return;\n }\n\n // Attach / clear coding-agent context for a session (issue #569 PR 5).\n // Mirrors `setCodingContext` on the access service. Connectors call this\n // at session start after resolving a git context for the cwd; `remnic\n // doctor` (PR 8) surfaces the attached context.\n if (req.method === \"POST\" && pathname === \"/engram/v1/coding-context\") {\n const body = await this.readValidatedBody(req, \"setCodingContext\");\n this.service.setCodingContext({\n sessionKey: body.sessionKey,\n codingContext: body.codingContext,\n });\n this.respondJson(res, 200, { ok: true });\n return;\n }\n\n if (\n req.method === \"POST\" &&\n (pathname === \"/engram/v1/capsules/export\" || pathname === \"/remnic/v1/capsules/export\")\n ) {\n const body = await this.readValidatedBody(req, \"capsuleExport\");\n this.ensureWriteRateLimitAvailable();\n const result = await this.service.capsuleExport({\n name: body.name,\n namespace: this.resolveNamespace(req, body.namespace),\n principal: this.resolveRequestPrincipal(req),\n since: body.since,\n includeKinds: body.includeKinds,\n peerIds: body.peerIds,\n includeTranscripts: body.includeTranscripts,\n encrypt: body.encrypt,\n });\n this.recordWriteRateLimitHit();\n this.respondJson(res, 200, result);\n return;\n }\n\n if (\n req.method === \"POST\" &&\n (pathname === \"/engram/v1/capsules/import\" || pathname === \"/remnic/v1/capsules/import\")\n ) {\n const body = await this.readValidatedBody(req, \"capsuleImport\");\n this.ensureWriteRateLimitAvailable();\n const result = await this.service.capsuleImport({\n archivePath: expandTildePath(body.archivePath),\n namespace: this.resolveNamespace(req, body.namespace),\n principal: this.resolveRequestPrincipal(req),\n mode: body.mode,\n });\n this.recordWriteRateLimitHit();\n this.respondJson(res, 200, result);\n return;\n }\n\n if (\n req.method === \"GET\" &&\n (pathname === \"/engram/v1/offline-sync/snapshot\" || pathname === \"/remnic/v1/offline-sync/snapshot\")\n ) {\n const includeTranscriptsRaw = parsed.searchParams.get(\"include_transcripts\");\n const includeContentRaw = parsed.searchParams.get(\"content\");\n if (\n includeTranscriptsRaw !== null &&\n includeTranscriptsRaw !== \"true\" &&\n includeTranscriptsRaw !== \"false\"\n ) {\n throw new EngramAccessInputError(\n `include_transcripts must be one of: true, false (got: ${includeTranscriptsRaw})`,\n );\n }\n if (\n includeContentRaw !== null &&\n includeContentRaw !== \"true\" &&\n includeContentRaw !== \"false\"\n ) {\n throw new EngramAccessInputError(\n `content must be one of: true, false (got: ${includeContentRaw})`,\n );\n }\n const namespaceParam = parsed.searchParams.get(\"namespace\");\n const result = await this.service.offlineSyncSnapshot({\n namespace: this.resolveNamespace(\n req,\n namespaceParam && namespaceParam.length > 0 ? namespaceParam : undefined,\n ),\n principal: this.resolveRequestPrincipal(req),\n includeTranscripts: includeTranscriptsRaw !== \"false\",\n includeContent: includeContentRaw !== \"false\",\n });\n this.respondJson(res, 200, result);\n return;\n }\n\n if (\n req.method === \"POST\" &&\n (pathname === \"/engram/v1/offline-sync/files\" || pathname === \"/remnic/v1/offline-sync/files\")\n ) {\n const body = await this.readValidatedBody(req, \"offlineSyncFiles\");\n const result = await this.service.offlineSyncFiles({\n namespace: this.resolveNamespace(req, body.namespace),\n principal: this.resolveRequestPrincipal(req),\n includeTranscripts: body.includeTranscripts,\n paths: body.paths,\n });\n this.respondJson(res, 200, result);\n return;\n }\n\n if (\n req.method === \"POST\" &&\n (\n pathname === \"/engram/v1/offline-sync/file-content\" ||\n pathname === \"/remnic/v1/offline-sync/file-content\"\n )\n ) {\n const body = await this.readValidatedBody(req, \"offlineSyncFileContent\");\n const result = await this.service.offlineSyncFileContent({\n namespace: this.resolveNamespace(req, body.namespace),\n principal: this.resolveRequestPrincipal(req),\n includeTranscripts: body.includeTranscripts,\n path: body.path,\n offset: body.offset,\n length: body.length,\n });\n this.respondBinary(res, 200, result.content, {\n \"x-remnic-namespace\": encodeURIComponent(result.namespace),\n \"x-remnic-file-path\": encodeURIComponent(result.path),\n \"x-remnic-file-bytes\": String(result.bytes),\n \"x-remnic-file-mtime-ms\": String(result.mtimeMs),\n \"x-remnic-chunk-offset\": String(result.offset),\n \"x-remnic-chunk-bytes\": String(result.chunkBytes),\n ...(result.sha256 ? { \"x-remnic-file-sha256\": result.sha256 } : {}),\n });\n return;\n }\n\n if (\n req.method === \"POST\" &&\n (\n pathname === \"/engram/v1/offline-sync/apply-file-content\" ||\n pathname === \"/remnic/v1/offline-sync/apply-file-content\"\n )\n ) {\n const namespaceParam = parsed.searchParams.get(\"namespace\");\n const bytes = this.readRequiredIntegerHeader(req, \"x-remnic-file-bytes\");\n const offset = this.readOptionalIntegerHeader(req, \"x-remnic-chunk-offset\") ?? 0;\n const startsUpload = offset === 0;\n if (startsUpload) this.ensureWriteRateLimitAvailable();\n const content = await this.readBinaryBody(req, OFFLINE_SYNC_FILE_CONTENT_MAX_CHUNK_BYTES);\n const result = await this.service.offlineSyncApplyFileContent({\n namespace: this.resolveNamespace(\n req,\n namespaceParam && namespaceParam.length > 0 ? namespaceParam : undefined,\n ),\n principal: this.resolveRequestPrincipal(req),\n includeTranscripts: this.parseOptionalBooleanHeader(\n req,\n \"x-remnic-include-transcripts\",\n true,\n ),\n sourceId: this.readRequiredDecodedHeader(req, \"x-remnic-source-id\"),\n path: this.readRequiredDecodedHeader(req, \"x-remnic-file-path\"),\n sha256: this.readRequiredHeader(req, \"x-remnic-file-sha256\"),\n bytes,\n mtimeMs: this.readRequiredNumberHeader(req, \"x-remnic-file-mtime-ms\"),\n offset,\n baseSha256: this.readOptionalHeader(req, \"x-remnic-base-sha256\"),\n content,\n });\n if (startsUpload) this.recordWriteRateLimitHit();\n this.respondJson(res, 200, result);\n return;\n }\n\n if (\n req.method === \"POST\" &&\n (pathname === \"/engram/v1/offline-sync/apply\" || pathname === \"/remnic/v1/offline-sync/apply\")\n ) {\n const body = await this.readValidatedBody(req, \"offlineSyncApply\");\n this.ensureWriteRateLimitAvailable();\n const result = await this.service.offlineSyncApply({\n namespace: this.resolveNamespace(req, body.namespace),\n principal: this.resolveRequestPrincipal(req),\n changeset: body.changeset,\n });\n this.recordWriteRateLimitHit();\n this.respondJson(res, 200, result);\n return;\n }\n\n if (req.method === \"POST\" && pathname === \"/engram/v1/recall/explain\") {\n const body = await this.readValidatedBody(req, \"recallExplain\");\n const response = await this.service.recallExplain({\n sessionKey: body.sessionKey,\n namespace: this.resolveNamespace(req, body.namespace),\n });\n this.respondJson(res, 200, response);\n return;\n }\n\n if (\n req.method === \"POST\" &&\n (pathname === \"/engram/v1/action-confidence\" || pathname === \"/remnic/v1/action-confidence\")\n ) {\n const body = await this.readValidatedBody(req, \"actionConfidence\");\n this.respondJson(res, 200, await this.service.actionConfidence(body));\n return;\n }\n\n // Tier-explain (issue #518): structured per-result annotation from\n // the direct-answer retrieval tier. Orthogonal to /recall/explain\n // above, which returns a graph-path explanation document.\n if (req.method === \"GET\" && pathname === \"/engram/v1/recall/tier-explain\") {\n const sessionParam = parsed.searchParams.get(\"session\");\n const sessionKey = sessionParam && sessionParam.length > 0 ? sessionParam : undefined;\n const namespaceParam = parsed.searchParams.get(\"namespace\");\n const namespace = this.resolveNamespace(\n req,\n namespaceParam && namespaceParam.length > 0 ? namespaceParam : undefined,\n );\n const payload = await this.service.recallTierExplain(\n sessionKey,\n namespace,\n this.resolveRequestPrincipal(req),\n );\n this.respondJson(res, 200, payload);\n return;\n }\n\n // Recall X-ray (issue #570 PR 4): unified per-result attribution\n // snapshot. Requires bearer auth (same as every other endpoint\n // here) and enforces namespace scope before the recall fires\n // (CLAUDE.md rule 42). Query comes from the `q` search param so\n // GET stays cacheable; `namespace` / `session` / `budget` are\n // optional.\n if (req.method === \"GET\" && pathname === \"/engram/v1/recall/xray\") {\n const queryParam = parsed.searchParams.get(\"q\");\n if (!queryParam || queryParam.trim().length === 0) {\n this.respondJson(res, 400, {\n error: \"missing_query\",\n code: \"missing_query\",\n message: \"q search parameter is required and must be non-empty\",\n });\n return;\n }\n const sessionParam = parsed.searchParams.get(\"session\");\n const sessionKey = sessionParam && sessionParam.length > 0\n ? sessionParam\n : undefined;\n const namespaceParam = parsed.searchParams.get(\"namespace\");\n const namespace = this.resolveNamespace(\n req,\n namespaceParam && namespaceParam.length > 0\n ? namespaceParam\n : undefined,\n );\n const budgetParam = parsed.searchParams.get(\"budget\");\n // Reject invalid `budget` with 400 rather than silently\n // defaulting (CLAUDE.md rules 14 + 51).\n let budget: number | undefined;\n if (budgetParam !== null && budgetParam !== \"\") {\n const parsedBudget = Number(budgetParam);\n if (\n !Number.isFinite(parsedBudget)\n || parsedBudget <= 0\n || !Number.isInteger(parsedBudget)\n ) {\n this.respondJson(res, 400, {\n error: \"invalid_budget\",\n code: \"invalid_budget\",\n message:\n \"budget expects a positive integer\",\n });\n return;\n }\n budget = parsedBudget;\n }\n // Disclosure depth (issue #677 PR 3/4 telemetry plumbing). When\n // present, must match the chunk|section|raw allow-list; invalid\n // values surface as a 400 (CLAUDE.md rule 51 — no silent\n // fallback) rather than silently disabling the per-disclosure\n // summary table.\n const disclosureParam = parsed.searchParams.get(\"disclosure\");\n let disclosure: RecallDisclosure | undefined;\n if (disclosureParam !== null && disclosureParam.length > 0) {\n if (!isRecallDisclosure(disclosureParam)) {\n this.respondJson(res, 400, {\n error: \"invalid_disclosure\",\n code: \"invalid_disclosure\",\n message:\n \"disclosure must be one of: chunk, section, raw\",\n });\n return;\n }\n disclosure = disclosureParam;\n }\n // Only translate validation errors (empty query, bad budget)\n // into 400s. Backend faults (timeouts, storage errors,\n // unexpected orchestrator failures) must bubble to the global\n // `handle()` error handler so they return 500 and get logged\n // properly. `service.recallXray` prefixes its validation\n // errors with \"recallXray:\" so we key off that prefix rather\n // than catching everything.\n let payload: Awaited<ReturnType<typeof this.service.recallXray>>;\n try {\n payload = await this.service.recallXray({\n query: queryParam,\n sessionKey,\n namespace,\n budget,\n authenticatedPrincipal: this.resolveRequestPrincipal(req),\n ...(disclosure !== undefined ? { disclosure } : {}),\n });\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n if (message.startsWith(\"recallXray:\")) {\n this.respondJson(res, 400, {\n error: \"invalid_request\",\n code: \"invalid_request\",\n message,\n });\n return;\n }\n // Anything else is a server-side fault; rethrow so the\n // outer `handle()` catch returns 500 + logs the error.\n throw err;\n }\n this.respondJson(res, 200, payload);\n return;\n }\n\n if (req.method === \"POST\" && pathname === \"/engram/v1/observe\") {\n const body = await this.readValidatedBody(req, \"observe\");\n this.ensureWriteRateLimitAvailable();\n const response = await this.service.observe({\n sessionKey: body.sessionKey,\n messages: body.messages.map((message) => ({\n role: message.role,\n content: message.content,\n sourceFormat: message.sourceFormat ?? undefined,\n rawContent: message.rawContent ?? undefined,\n parts: message.parts ?? undefined,\n })),\n namespace: this.resolveNamespace(req, body.namespace),\n authenticatedPrincipal: this.resolveRequestPrincipal(req),\n skipExtraction: body.skipExtraction === true,\n // Forward cwd/projectTag for auto git-context resolution (issue #569).\n cwd: body.cwd,\n projectTag: body.projectTag,\n });\n this.recordWriteRateLimitHit();\n this.respondJson(res, 202, response);\n return;\n }\n\n if (req.method === \"POST\" && pathname === \"/engram/v1/lcm/search\") {\n const body = await this.readValidatedBody(req, \"lcmSearch\");\n const response = await this.service.lcmSearch({\n query: body.query,\n sessionKey: body.sessionKey,\n namespace: this.resolveNamespace(req, body.namespace),\n authenticatedPrincipal: this.resolveRequestPrincipal(req),\n limit: body.limit,\n });\n this.respondJson(res, 200, response);\n return;\n }\n\n if (\n req.method === \"POST\" &&\n (pathname === \"/engram/v1/lcm/compaction/flush\" || pathname === \"/remnic/v1/lcm/compaction/flush\")\n ) {\n const body = await this.readValidatedBody(req, \"lcmCompactionFlush\");\n this.ensureWriteRateLimitAvailable();\n const response = await this.service.lcmCompactionFlush({\n sessionKey: body.sessionKey,\n namespace: this.resolveNamespace(req, body.namespace),\n authenticatedPrincipal: this.resolveRequestPrincipal(req),\n });\n this.recordWriteRateLimitHit();\n this.respondJson(res, 200, response);\n return;\n }\n\n if (\n req.method === \"POST\" &&\n (pathname === \"/engram/v1/lcm/compaction/record\" || pathname === \"/remnic/v1/lcm/compaction/record\")\n ) {\n const body = await this.readValidatedBody(req, \"lcmCompactionRecord\");\n this.ensureWriteRateLimitAvailable();\n const response = await this.service.lcmCompactionRecord({\n sessionKey: body.sessionKey,\n namespace: this.resolveNamespace(req, body.namespace),\n tokensBefore: body.tokensBefore,\n tokensAfter: body.tokensAfter,\n authenticatedPrincipal: this.resolveRequestPrincipal(req),\n });\n this.recordWriteRateLimitHit();\n this.respondJson(res, 200, response);\n return;\n }\n\n if (req.method === \"GET\" && pathname === \"/engram/v1/lcm/status\") {\n this.respondJson(res, 200, await this.service.lcmStatus());\n return;\n }\n\n if (req.method === \"POST\" && pathname === \"/engram/v1/memories\") {\n const body = await this.readValidatedBody(req, \"memoryStore\");\n const request = {\n schemaVersion: body.schemaVersion,\n idempotencyKey: body.idempotencyKey,\n dryRun: body.dryRun === true,\n sessionKey: body.sessionKey,\n authenticatedPrincipal: this.resolveRequestPrincipal(req),\n content: body.content,\n category: body.category,\n confidence: body.confidence,\n namespace: this.resolveNamespace(req, body.namespace),\n tags: body.tags,\n entityRef: body.entityRef,\n ttl: body.ttl,\n sourceReason: body.sourceReason,\n };\n const idempotencyStatus = await this.service.peekMemoryStoreIdempotency(request);\n if (idempotencyStatus === \"miss\" && request.dryRun !== true) {\n this.ensureWriteRateLimitAvailable();\n }\n const response = await this.service.memoryStore(request);\n if (this.shouldCountWriteRateLimit(response as { dryRun?: boolean; idempotencyReplay?: boolean })) {\n this.recordWriteRateLimitHit();\n }\n this.respondJson(res, this.writeResponseStatus(response), response);\n return;\n }\n\n if (req.method === \"POST\" && pathname === \"/engram/v1/suggestions\") {\n const body = await this.readValidatedBody(req, \"suggestionSubmit\");\n const request = {\n schemaVersion: body.schemaVersion,\n idempotencyKey: body.idempotencyKey,\n dryRun: body.dryRun === true,\n sessionKey: body.sessionKey,\n authenticatedPrincipal: this.resolveRequestPrincipal(req),\n content: body.content,\n category: body.category,\n confidence: body.confidence,\n namespace: this.resolveNamespace(req, body.namespace),\n tags: body.tags,\n entityRef: body.entityRef,\n ttl: body.ttl,\n sourceReason: body.sourceReason,\n };\n const idempotencyStatus = await this.service.peekSuggestionSubmitIdempotency(request);\n if (idempotencyStatus === \"miss\" && request.dryRun !== true) {\n this.ensureWriteRateLimitAvailable();\n }\n const response = await this.service.suggestionSubmit(request);\n if (this.shouldCountWriteRateLimit(response as { dryRun?: boolean; idempotencyReplay?: boolean })) {\n this.recordWriteRateLimitHit();\n }\n this.respondJson(res, this.writeResponseStatus(response), response);\n return;\n }\n\n if (req.method === \"GET\" && pathname === \"/engram/v1/memories\") {\n const limitRaw = parseInt(parsed.searchParams.get(\"limit\") ?? \"50\", 10);\n const offsetRaw = parseInt(parsed.searchParams.get(\"offset\") ?? \"0\", 10);\n const sortParam = parsed.searchParams.get(\"sort\") ?? undefined;\n const sort = sortParam === \"updated_desc\"\n || sortParam === \"updated_asc\"\n || sortParam === \"created_desc\"\n || sortParam === \"created_asc\"\n ? sortParam\n : undefined;\n const response = await this.service.memoryBrowse({\n query: parsed.searchParams.get(\"q\") ?? undefined,\n status: parsed.searchParams.get(\"status\") ?? undefined,\n category: parsed.searchParams.get(\"category\") ?? undefined,\n namespace: parsed.searchParams.get(\"namespace\") ?? undefined,\n authenticatedPrincipal: this.resolveRequestPrincipal(req),\n sort,\n limit: Number.isFinite(limitRaw) ? limitRaw : 50,\n offset: Number.isFinite(offsetRaw) ? offsetRaw : 0,\n });\n this.respondJson(res, 200, response);\n return;\n }\n\n const memoryMatch = pathname.match(/^\\/engram\\/v1\\/memories\\/([^/]+)$/);\n if (req.method === \"GET\" && memoryMatch) {\n const memoryId = decodeURIComponent(memoryMatch[1] ?? \"\");\n const namespace = parsed.searchParams.get(\"namespace\") ?? undefined;\n const response = await this.service.memoryGet(memoryId, namespace, this.resolveRequestPrincipal(req));\n this.respondJson(res, response.found ? 200 : 404, response);\n return;\n }\n\n const timelineMatch = pathname.match(/^\\/engram\\/v1\\/memories\\/([^/]+)\\/timeline$/);\n if (req.method === \"GET\" && timelineMatch) {\n const memoryId = decodeURIComponent(timelineMatch[1] ?? \"\");\n const namespace = parsed.searchParams.get(\"namespace\") ?? undefined;\n const limitRaw = parseInt(parsed.searchParams.get(\"limit\") ?? \"200\", 10);\n const limit = Number.isFinite(limitRaw) ? limitRaw : 200;\n const response = await this.service.memoryTimeline(memoryId, namespace, limit, this.resolveRequestPrincipal(req));\n this.respondJson(res, response.found ? 200 : 404, response);\n return;\n }\n\n if (req.method === \"GET\" && pathname === \"/engram/v1/entities\") {\n const limitRaw = parseInt(parsed.searchParams.get(\"limit\") ?? \"50\", 10);\n const offsetRaw = parseInt(parsed.searchParams.get(\"offset\") ?? \"0\", 10);\n const response = await this.service.entityList({\n namespace: parsed.searchParams.get(\"namespace\") ?? undefined,\n query: parsed.searchParams.get(\"q\") ?? undefined,\n limit: Number.isFinite(limitRaw) ? limitRaw : 50,\n offset: Number.isFinite(offsetRaw) ? offsetRaw : 0,\n });\n this.respondJson(res, 200, response);\n return;\n }\n\n const entityMatch = pathname.match(/^\\/engram\\/v1\\/entities\\/([^/]+)$/);\n if (req.method === \"GET\" && entityMatch) {\n const entityName = decodeURIComponent(entityMatch[1] ?? \"\");\n const namespace = parsed.searchParams.get(\"namespace\") ?? undefined;\n const response = await this.service.entityGet(entityName, namespace);\n this.respondJson(res, response.found ? 200 : 404, response);\n return;\n }\n\n if (req.method === \"GET\" && pathname === \"/engram/v1/review-queue\") {\n const response = await this.service.reviewQueue(\n parsed.searchParams.get(\"runId\") ?? undefined,\n parsed.searchParams.get(\"namespace\") ?? undefined,\n this.resolveRequestPrincipal(req),\n );\n this.respondJson(res, 200, response);\n return;\n }\n\n if (req.method === \"GET\" && pathname === \"/engram/v1/maintenance\") {\n this.respondJson(res, 200, await this.service.maintenance(parsed.searchParams.get(\"namespace\") ?? undefined, this.resolveRequestPrincipal(req)));\n return;\n }\n\n if (req.method === \"GET\" && pathname === \"/engram/v1/quality\") {\n this.respondJson(res, 200, await this.service.quality(parsed.searchParams.get(\"namespace\") ?? undefined, this.resolveRequestPrincipal(req)));\n return;\n }\n\n if (req.method === \"GET\" && pathname === \"/engram/v1/trust-zones/status\") {\n this.respondJson(\n res,\n 200,\n await this.service.trustZoneStatus(parsed.searchParams.get(\"namespace\") ?? undefined, this.resolveRequestPrincipal(req)),\n );\n return;\n }\n\n // Procedural memory stats (issue #567 PR 5/5). Read-only; namespace is\n // scoped via the same resolver used by recall/trust-zones so cross-\n // tenant reads aren't possible (CLAUDE.md rule 42).\n if (req.method === \"GET\" && pathname === \"/engram/v1/procedural/stats\") {\n const namespaceParam = parsed.searchParams.get(\"namespace\");\n this.respondJson(\n res,\n 200,\n await this.service.procedureStats(\n {\n namespace: this.resolveNamespace(\n req,\n namespaceParam && namespaceParam.length > 0\n ? namespaceParam\n : undefined,\n ),\n },\n this.resolveRequestPrincipal(req),\n ),\n );\n return;\n }\n\n if (req.method === \"GET\" && pathname === \"/engram/v1/trust-zones/records\") {\n const limitRaw = parseInt(parsed.searchParams.get(\"limit\") ?? \"25\", 10);\n const offsetRaw = parseInt(parsed.searchParams.get(\"offset\") ?? \"0\", 10);\n const response = await this.service.trustZoneBrowse({\n query: parsed.searchParams.get(\"q\") ?? undefined,\n zone: parseTrustZoneFilter(parsed.searchParams.get(\"zone\")),\n kind: parseTrustZoneKindFilter(parsed.searchParams.get(\"kind\")),\n sourceClass: parseTrustZoneSourceClassFilter(parsed.searchParams.get(\"sourceClass\")),\n namespace: parsed.searchParams.get(\"namespace\") ?? undefined,\n limit: Number.isFinite(limitRaw) ? limitRaw : 25,\n offset: Number.isFinite(offsetRaw) ? offsetRaw : 0,\n }, this.resolveRequestPrincipal(req));\n this.respondJson(res, 200, response);\n return;\n }\n\n if (req.method === \"POST\" && pathname === \"/engram/v1/review-disposition\") {\n const body = await this.readValidatedBody(req, \"reviewDisposition\");\n this.ensureWriteRateLimitAvailable();\n const response = await this.service.reviewDisposition({\n memoryId: body.memoryId,\n status: body.status,\n reasonCode: body.reasonCode,\n namespace: this.resolveNamespace(req, body.namespace),\n authenticatedPrincipal: this.resolveRequestPrincipal(req),\n });\n if (this.shouldCountWriteRateLimit(response as unknown as { dryRun?: boolean; idempotencyReplay?: boolean })) {\n this.recordWriteRateLimitHit();\n }\n this.respondJson(res, 200, response);\n return;\n }\n\n if (req.method === \"POST\" && pathname === \"/engram/v1/trust-zones/promote\") {\n const body = await this.readValidatedBody(req, \"trustZonePromote\");\n const dryRun = body.dryRun === true;\n if (!dryRun) {\n this.ensureWriteRateLimitAvailable();\n }\n const response = await this.service.trustZonePromote({\n recordId: body.recordId,\n targetZone: body.targetZone,\n promotionReason: body.promotionReason,\n recordedAt: body.recordedAt,\n summary: body.summary,\n dryRun,\n namespace: this.resolveNamespace(req, body.namespace),\n authenticatedPrincipal: this.resolveRequestPrincipal(req),\n });\n if (this.shouldCountWriteRateLimit(response as unknown as { dryRun?: boolean; idempotencyReplay?: boolean })) {\n this.recordWriteRateLimitHit();\n }\n this.respondJson(res, response.dryRun ? 200 : 201, response);\n return;\n }\n\n if (req.method === \"POST\" && pathname === \"/engram/v1/trust-zones/demo-seed\") {\n const body = await this.readValidatedBody(req, \"trustZoneDemoSeed\");\n const dryRun = body.dryRun === true;\n if (!dryRun) {\n this.ensureWriteRateLimitAvailable();\n }\n const response = await this.service.trustZoneDemoSeed({\n scenario: body.scenario,\n recordedAt: body.recordedAt,\n dryRun,\n namespace: this.resolveNamespace(req, body.namespace),\n authenticatedPrincipal: this.resolveRequestPrincipal(req),\n });\n if (this.shouldCountWriteRateLimit(response as unknown as { dryRun?: boolean; idempotencyReplay?: boolean })) {\n this.recordWriteRateLimitHit();\n }\n this.respondJson(res, response.dryRun ? 200 : 201, response);\n return;\n }\n\n // Citation usage tracking (issue #379)\n if (req.method === \"POST\" && pathname === \"/v1/citations/observed\") {\n const body = await this.readJsonBody(req);\n if (!body || typeof body !== \"object\" || Array.isArray(body)) {\n throw new HttpError(400, \"request body must be a JSON object\", \"invalid_body\");\n }\n const payload = body as Record<string, unknown>;\n const sessionId = typeof payload.sessionId === \"string\" ? payload.sessionId : undefined;\n const namespace = typeof payload.namespace === \"string\" ? payload.namespace : undefined;\n const citationsRaw = payload.citations;\n if (!citationsRaw || typeof citationsRaw !== \"object\" || Array.isArray(citationsRaw)) {\n throw new HttpError(400, \"citations must be a JSON object with entries and rolloutIds\", \"invalid_citations\");\n }\n const citObj = citationsRaw as Record<string, unknown>;\n const entries: CitationEntry[] = [];\n if (Array.isArray(citObj.entries)) {\n for (const raw of citObj.entries) {\n if (raw && typeof raw === \"object\" && !Array.isArray(raw)) {\n const e = raw as Record<string, unknown>;\n if (\n typeof e.path === \"string\" &&\n typeof e.lineStart === \"number\" &&\n typeof e.lineEnd === \"number\"\n ) {\n entries.push({\n path: e.path,\n lineStart: e.lineStart,\n lineEnd: e.lineEnd,\n note: typeof e.note === \"string\" ? e.note : \"\",\n });\n }\n }\n }\n }\n const rolloutIds: string[] = [];\n if (Array.isArray(citObj.rolloutIds)) {\n for (const id of citObj.rolloutIds) {\n if (typeof id === \"string\" && id.length > 0) {\n rolloutIds.push(id);\n }\n }\n }\n\n // Record usage: for each citation entry, try to increment usage on the\n // matching memory. The service exposes recordAccess for this purpose.\n // Pass authenticatedPrincipal so namespace ACL checks use the same\n // identity resolution as other write endpoints (Finding #1, issue #379).\n let matched = 0;\n let submitted = 0;\n if (typeof this.service.recordCitationUsage === \"function\") {\n const result = await this.service.recordCitationUsage({\n sessionId,\n namespace: this.resolveNamespace(req, namespace),\n authenticatedPrincipal: this.resolveRequestPrincipal(req),\n entries,\n rolloutIds,\n });\n submitted = result.submitted;\n matched = result.matched;\n }\n\n this.respondJson(res, 200, {\n ok: true,\n submitted,\n matched,\n entriesReceived: entries.length,\n rolloutIdsReceived: rolloutIds.length,\n });\n return;\n }\n\n // ── Contradiction Review (issue #520) ─────────────────────────────────────\n if (req.method === \"GET\" && pathname === \"/engram/v1/review/contradictions\") {\n const VALID_FILTERS = new Set([\"all\", \"unresolved\", \"contradicts\", \"independent\", \"duplicates\", \"needs-user\"]);\n const rawFilter = parsed.searchParams.get(\"filter\") ?? \"unresolved\";\n if (!VALID_FILTERS.has(rawFilter)) {\n this.respondJson(res, 400, { error: `Invalid filter '${rawFilter}'. Valid: ${[...VALID_FILTERS].join(\", \")}` });\n return;\n }\n const namespace = parsed.searchParams.get(\"namespace\") ?? undefined;\n const limitRaw = parseInt(parsed.searchParams.get(\"limit\") ?? \"50\", 10);\n const {\n isDefaultReviewNamespace,\n listPairs,\n } = await import(\"./contradiction/contradiction-review.js\");\n const principal = this.resolveRequestPrincipal(req);\n const resolved = await this.service.getReadableStorageForNamespace(namespace, principal);\n const reviewNamespace = this.service.configRef.namespacesEnabled ? resolved.namespace : undefined;\n const includeUnscopedForNamespace = Boolean(\n reviewNamespace && isDefaultReviewNamespace(this.service.configRef.defaultNamespace, namespace, reviewNamespace),\n );\n const result = listPairs(this.service.memoryDir, {\n filter: rawFilter as \"all\" | \"unresolved\" | \"contradicts\" | \"independent\" | \"duplicates\" | \"needs-user\",\n namespace: reviewNamespace,\n includeUnscopedForNamespace,\n limit: Number.isFinite(limitRaw) ? limitRaw : 50,\n });\n this.respondJson(res, 200, result);\n return;\n }\n\n if (req.method === \"GET\" && pathname.startsWith(\"/engram/v1/review/contradictions/\")) {\n const pairId = pathname.split(\"/\").pop() ?? \"\";\n const { readPair } = await import(\"./contradiction/contradiction-review.js\");\n const pair = readPair(this.service.memoryDir, pairId);\n if (!pair) {\n this.respondJson(res, 404, { error: \"pair_not_found\" });\n return;\n }\n try {\n await this.service.getReadableStorageForNamespace(pair.namespace, this.resolveRequestPrincipal(req));\n } catch {\n this.respondJson(res, 404, { error: \"pair_not_found\" });\n return;\n }\n this.respondJson(res, 200, pair);\n return;\n }\n\n if (req.method === \"POST\" && pathname === \"/engram/v1/review/resolve\") {\n const body = await this.readJsonBody(req) as Record<string, unknown>;\n const pairId = typeof body.pairId === \"string\" ? body.pairId : \"\";\n const verb = typeof body.verb === \"string\" ? body.verb : \"\";\n if (!pairId || !verb) {\n this.respondJson(res, 400, { error: \"pairId and verb are required\" });\n return;\n }\n const { isValidResolutionVerb, executeResolution } = await import(\"./contradiction/resolution.js\");\n if (!isValidResolutionVerb(verb)) {\n this.respondJson(res, 400, { error: `Invalid verb: ${verb}. Must be one of: keep-a, keep-b, merge, both-valid, needs-more-context` });\n return;\n }\n const principal = this.resolveRequestPrincipal(req);\n const result = await executeResolution(this.service.memoryDir, this.service.storageRef, pairId, verb, {\n mergedMemoryId: typeof body.mergedMemoryId === \"string\" ? body.mergedMemoryId : undefined,\n mergedContent: typeof body.mergedContent === \"string\" ? body.mergedContent : undefined,\n storageForNamespace: async (namespace) => {\n const resolved = await this.service.getWritableStorageForNamespace(namespace, principal);\n return resolved.storage;\n },\n });\n this.respondJson(res, 200, result);\n return;\n }\n\n // Graph snapshot (issue #691 PR 2/5) — read-only adjacency view used by\n // the admin-pane scaffold shipped in PR 1/5. All filters are query\n // params so the surface stays cacheable; invalid values yield 400 with\n // a descriptive body (CLAUDE.md rule 51 — never silently default).\n if (req.method === \"GET\" && pathname === \"/engram/v1/graph/snapshot\") {\n const limitRaw = parsed.searchParams.get(\"limit\");\n let limit: number | undefined;\n if (limitRaw !== null && limitRaw.length > 0) {\n const parsedLimit = Number(limitRaw);\n if (\n !Number.isFinite(parsedLimit)\n || !Number.isInteger(parsedLimit)\n || parsedLimit <= 0\n ) {\n this.respondJson(res, 400, {\n error: \"invalid_limit\",\n code: \"invalid_limit\",\n message: \"limit must be a positive integer\",\n });\n return;\n }\n limit = parsedLimit;\n }\n const sinceRaw = parsed.searchParams.get(\"since\");\n let since: string | undefined;\n if (sinceRaw !== null && sinceRaw.length > 0) {\n // Validate up-front so the access service can stay focused on the\n // pure snapshot logic (parser also runs there as a defense in\n // depth, but rejecting at the boundary preserves the\n // \"invalid_since\" error code instead of leaking a generic 500).\n if (!Number.isFinite(Date.parse(sinceRaw))) {\n this.respondJson(res, 400, {\n error: \"invalid_since\",\n code: \"invalid_since\",\n message: \"since must be a parseable ISO timestamp\",\n });\n return;\n }\n since = sinceRaw;\n }\n const focusNodeIdRaw = parsed.searchParams.get(\"focusNodeId\");\n const focusNodeId = focusNodeIdRaw && focusNodeIdRaw.length > 0\n ? focusNodeIdRaw\n : undefined;\n const categoriesRaw = parsed.searchParams.get(\"categories\");\n let categories: string[] | undefined;\n if (categoriesRaw !== null && categoriesRaw.length > 0) {\n categories = categoriesRaw\n .split(\",\")\n .map((value) => value.trim())\n .filter((value) => value.length > 0);\n if (categories.length === 0) {\n this.respondJson(res, 400, {\n error: \"invalid_categories\",\n code: \"invalid_categories\",\n message:\n \"categories must be a comma-separated list with at least one non-empty value\",\n });\n return;\n }\n }\n const namespaceParam = parsed.searchParams.get(\"namespace\");\n const namespace = this.resolveNamespace(\n req,\n namespaceParam && namespaceParam.length > 0 ? namespaceParam : undefined,\n );\n try {\n const snapshot = await this.service.graphSnapshot(\n {\n namespace,\n ...(limit !== undefined ? { limit } : {}),\n ...(since !== undefined ? { since } : {}),\n ...(focusNodeId !== undefined ? { focusNodeId } : {}),\n ...(categories !== undefined ? { categories } : {}),\n },\n this.resolveRequestPrincipal(req),\n );\n this.respondJson(res, 200, snapshot);\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n if (message.startsWith(\"graphSnapshot:\")) {\n this.respondJson(res, 400, {\n error: \"invalid_request\",\n code: \"invalid_request\",\n message,\n });\n return;\n }\n throw err;\n }\n return;\n }\n\n if (req.method === \"POST\" && pathname === \"/engram/v1/contradiction-scan\") {\n const body = await this.readJsonBody(req) as Record<string, unknown>;\n const { runContradictionScan } = await import(\"./contradiction/contradiction-scan.js\");\n const principal = this.resolveRequestPrincipal(req);\n const result = await runContradictionScan({\n storage: this.service.storageRef,\n config: this.service.configRef,\n memoryDir: this.service.memoryDir,\n embeddingLookupFactory: this.service.embeddingLookupFactoryRef,\n storageForNamespace: (namespace) =>\n this.service.getWritableStorageForNamespace(namespace, principal),\n localLlm: this.service.localLlmRef,\n fallbackLlm: this.service.fallbackLlmRef,\n namespace: typeof body.namespace === \"string\" ? body.namespace : undefined,\n });\n this.respondJson(res, 200, result);\n return;\n }\n\n // ── Graph mutation event stream (issue #691 PR 5/5) ──────────────────────\n //\n // GET /engram/v1/graph/events\n //\n // Server-Sent Events stream that emits graph mutation events in real time.\n // Event types: node-added, node-updated, edge-added, edge-updated, edge-removed.\n //\n // Auth: same Bearer token scheme as every other endpoint (checked above).\n //\n // The SSE handler subscribes to the in-process graph event bus for the\n // resolved memory dir. Events are batched within a 200 ms window so a\n // burst of writes (e.g. extraction of a large turn) doesn't overwhelm\n // the admin UI canvas with individual re-renders.\n //\n // The client receives a `data: <json>\\n\\n` line per batch. Each batch\n // payload is { events: GraphEvent[] }.\n //\n // The stream sends a heartbeat `data: {\"type\":\"heartbeat\"}\\n\\n` every\n // 25 s so load balancers and proxies don't time out idle connections.\n if (req.method === \"GET\" && pathname === \"/engram/v1/graph/events\") {\n await this.handleGraphEventsSSE(req, res);\n return;\n }\n\n // ── Peer Registry endpoints (issue #679) ─────────────────────────────────\n // GET /engram/v1/console/state — operator console engine-state snapshot (issue #688 PR 2/3).\n // Read-only; namespace-aware via resolveRequestPrincipal so cross-tenant\n // reads are not possible (CLAUDE.md rule 42).\n if (req.method === \"GET\" && pathname === \"/engram/v1/console/state\") {\n const namespace = parsed.searchParams.get(\"namespace\") ?? undefined;\n const snapshot = await this.service.consoleState(namespace, this.resolveRequestPrincipal(req));\n this.respondJson(res, 200, snapshot);\n return;\n }\n\n // GET /engram/v1/peers — list all peers\n // GET /engram/v1/peers/:id — get one peer\n // PUT /engram/v1/peers/:id — upsert (create/update)\n // DELETE /engram/v1/peers/:id — delete identity only (idempotent)\n // DELETE /engram/v1/peers/:id?forget=true — destructive full purge (issue #679 completion)\n // GET /engram/v1/peers/:id/profile — get peer profile\n if (req.method === \"GET\" && pathname === \"/engram/v1/peers\") {\n const result = await this.service.peerList();\n this.respondJson(res, 200, result);\n return;\n }\n\n const peerProfileMatch = /^\\/engram\\/v1\\/peers\\/([^/]+)\\/profile$/.exec(pathname);\n if (peerProfileMatch) {\n if (req.method !== \"GET\") {\n this.respondJson(res, 405, { error: \"method_not_allowed\", code: \"method_not_allowed\" });\n return;\n }\n const peerId = decodePeerIdSegment(peerProfileMatch[1] ?? \"\");\n const result = await this.service.peerProfileGet(peerId);\n if (!result.found) {\n this.respondJson(res, 404, { error: \"peer_profile_not_found\", code: \"peer_profile_not_found\" });\n return;\n }\n this.respondJson(res, 200, result);\n return;\n }\n\n const peerIdMatch = /^\\/engram\\/v1\\/peers\\/([^/]+)$/.exec(pathname);\n if (peerIdMatch) {\n const peerId = decodePeerIdSegment(peerIdMatch[1] ?? \"\");\n\n if (req.method === \"GET\") {\n const result = await this.service.peerGet(peerId);\n if (!result.found) {\n this.respondJson(res, 404, { error: \"peer_not_found\", code: \"peer_not_found\" });\n return;\n }\n this.respondJson(res, 200, result);\n return;\n }\n\n if (req.method === \"PUT\") {\n const body = await this.readJsonBody(req) as Record<string, unknown>;\n // Reject malformed types up front rather than silently dropping them\n // to undefined and letting peerSet fall back to defaults\n // (CLAUDE.md rule 51: no silent defaults on bad input).\n if (\"kind\" in body && body.kind !== undefined && typeof body.kind !== \"string\") {\n throw new EngramAccessInputError(\"kind must be a string when provided\");\n }\n if (\n \"displayName\" in body &&\n body.displayName !== undefined &&\n typeof body.displayName !== \"string\"\n ) {\n throw new EngramAccessInputError(\"displayName must be a string when provided\");\n }\n if (\"notes\" in body && body.notes !== undefined && typeof body.notes !== \"string\") {\n throw new EngramAccessInputError(\"notes must be a string when provided\");\n }\n const result = await this.service.peerSet({\n id: peerId,\n kind: typeof body.kind === \"string\" ? body.kind : undefined,\n displayName: typeof body.displayName === \"string\" ? body.displayName : undefined,\n notes: typeof body.notes === \"string\" ? body.notes : undefined,\n });\n this.respondJson(res, result.created ? 201 : 200, result);\n return;\n }\n\n if (req.method === \"DELETE\") {\n // `?forget=true` triggers the destructive full-purge path (issue #679\n // completion). The caller must also pass `confirm=yes` in the request\n // body; absent confirmation yields 400. Plain DELETE (no ?forget) keeps\n // the existing soft-delete behaviour (identity.md only).\n const forgetParam = parsed.searchParams.get(\"forget\");\n if (forgetParam === \"true\") {\n const body = await this.readJsonBody(req) as Record<string, unknown>;\n const confirm = typeof body.confirm === \"string\" ? body.confirm : \"\";\n if (confirm !== \"yes\") {\n this.respondJson(res, 400, {\n error: \"confirm_required\",\n code: \"confirm_required\",\n message: \"DELETE ?forget=true requires { confirm: 'yes' } in the request body\",\n });\n return;\n }\n const result = await this.service.peerForget(peerId, { confirm: \"yes\" });\n this.respondJson(res, 200, result);\n return;\n }\n const result = await this.service.peerDelete(peerId);\n this.respondJson(res, 200, result);\n return;\n }\n\n this.respondJson(res, 405, { error: \"method_not_allowed\", code: \"method_not_allowed\" });\n return;\n }\n\n // ── Dreams telemetry (issue #678 PR 3+4) ──────────────────────────────────\n\n if (req.method === \"GET\" && pathname === \"/engram/v1/dreams/status\") {\n const { normalizeDreamsStatusWindowHours } = await import(\"./maintenance/dreams-ledger.js\");\n const windowHoursRaw = parsed.searchParams.get(\"windowHours\");\n let windowHours: number;\n try {\n windowHours = normalizeDreamsStatusWindowHours(\n windowHoursRaw !== null ? Number(windowHoursRaw) : undefined,\n );\n } catch {\n this.respondJson(res, 400, { error: \"windowHours must be a positive integer\" });\n return;\n }\n const namespaceParam = parsed.searchParams.get(\"namespace\");\n const namespace = namespaceParam && namespaceParam.length > 0 ? namespaceParam : undefined;\n const result = await this.service.dreamsStatus({\n windowHours,\n namespace,\n principal: this.resolveRequestPrincipal(req),\n });\n this.respondJson(res, 200, result);\n return;\n }\n\n if (req.method === \"POST\" && pathname === \"/engram/v1/dreams/run\") {\n const body = await this.readJsonBody(req) as Record<string, unknown>;\n const VALID_PHASES = [\"lightSleep\", \"rem\", \"deepSleep\"] as const;\n const phase = typeof body.phase === \"string\" ? body.phase : undefined;\n if (!phase || !(VALID_PHASES as readonly string[]).includes(phase)) {\n this.respondJson(res, 400, {\n error: `phase is required and must be one of: ${VALID_PHASES.join(\", \")}`,\n });\n return;\n }\n if (\n \"dryRun\" in body &&\n body.dryRun !== undefined &&\n typeof body.dryRun !== \"boolean\"\n ) {\n this.respondJson(res, 400, {\n error: \"dryRun must be a boolean when provided\",\n });\n return;\n }\n if (\n \"namespace\" in body &&\n body.namespace !== undefined &&\n typeof body.namespace !== \"string\"\n ) {\n this.respondJson(res, 400, {\n error: \"namespace must be a string when provided\",\n });\n return;\n }\n const dryRun = body.dryRun === true;\n const namespace =\n typeof body.namespace === \"string\" ? body.namespace : undefined;\n if (!dryRun) {\n this.ensureWriteRateLimitAvailable();\n }\n const result = await this.service.dreamsRun({\n phase: phase as import(\"./types.js\").DreamsPhase,\n dryRun,\n namespace,\n authenticatedPrincipal: this.resolveRequestPrincipal(req),\n });\n if (this.shouldCountWriteRateLimit(result as { dryRun?: boolean; idempotencyReplay?: boolean })) {\n this.recordWriteRateLimitHit();\n }\n this.respondJson(res, 200, result);\n return;\n }\n\n this.respondJson(res, 404, { error: \"not_found\", code: \"not_found\" });\n }\n\n /**\n * SSE handler for /engram/v1/graph/events.\n *\n * Lifecycle:\n * 1. Write SSE headers (Content-Type: text/event-stream).\n * 2. Register this response in `sseClients`.\n * 3. Resolve the namespace from the request and subscribe to THAT\n * namespace's graph event bus (Codex P1: in multi-namespace\n * deployments each namespace has its own bus keyed by its storage\n * dir — subscribing to the global root leaks events across tenants).\n * 4. On each event, add to a 200 ms batch; flush batch as a single SSE frame.\n * 5. Send heartbeat every 25 s.\n * 6. On client disconnect (req \"close\"), clean up timers and unsubscribe.\n * 7. Register the cleanup callback in `sseCleanupFns` so `stop()` can\n * release the heartbeat interval and bus subscription even when the\n * client never disconnects (Cursor review thread `access-http.ts:232`).\n */\n private async handleGraphEventsSSE(req: IncomingMessage, res: ServerResponse): Promise<void> {\n // Resolve namespace from the ?namespace= query parameter (same pattern\n // as graphSnapshot and other read endpoints). Falls back to the\n // default namespace when absent.\n const parsed = new URL(req.url ?? \"/\", `http://${hostToUrlAuthority(this.host)}`);\n const namespaceParam = parsed.searchParams.get(\"namespace\");\n const namespace = namespaceParam && namespaceParam.length > 0 ? namespaceParam : undefined;\n // Resolve to the per-namespace storage directory so the bus subscription\n // is scoped to the correct tenant (CLAUDE.md rule 42).\n // Pass the request principal so namespace ACL is enforced — without it,\n // resolveReadableNamespace throws when namespacesEnabled=true (Cursor\n // thread PRRT_kwDORJXyws59snoR / Codex thread PRRT_kwDORJXyws59soGJ).\n const principal = this.resolveRequestPrincipal(req);\n const memoryDir = await this.service.getMemoryDirForNamespace(namespace, principal);\n\n res.writeHead(200, {\n \"content-type\": \"text/event-stream; charset=utf-8\",\n \"cache-control\": \"no-cache, no-store, must-revalidate\",\n \"connection\": \"keep-alive\",\n \"x-accel-buffering\": \"no\", // prevent nginx buffering\n \"transfer-encoding\": \"chunked\",\n });\n\n // Send initial \"connected\" frame so the client knows the stream is live.\n const writeSSE = (payload: unknown): void => {\n try {\n res.write(`data: ${JSON.stringify(payload)}\\n\\n`);\n } catch {\n // client already gone — cleanup will fire via \"close\"\n }\n };\n\n writeSSE({ type: \"connected\" });\n\n this.sseClients.add(res);\n\n // --- 200 ms batch throttle -----------------------------------------------\n const flushBatch = (): void => {\n const batch = this.ssePendingBatches.get(res);\n if (!batch || batch.length === 0) return;\n this.ssePendingBatches.delete(res);\n this.sseBatchTimers.delete(res);\n writeSSE({ type: \"batch\", events: batch });\n };\n\n const unsubscribe = subscribeGraphEvents(memoryDir, (event: GraphEvent) => {\n let batch = this.ssePendingBatches.get(res);\n if (!batch) {\n batch = [];\n this.ssePendingBatches.set(res, batch);\n }\n batch.push(event);\n if (!this.sseBatchTimers.has(res)) {\n this.sseBatchTimers.set(res, setTimeout(flushBatch, 200));\n }\n });\n\n // --- 25 s heartbeat -------------------------------------------------------\n const heartbeatInterval = setInterval(() => {\n writeSSE({ type: \"heartbeat\" });\n }, 25_000);\n\n // --- Cleanup on client disconnect -----------------------------------------\n const cleanup = (): void => {\n clearInterval(heartbeatInterval);\n const timer = this.sseBatchTimers.get(res);\n if (timer !== undefined) {\n clearTimeout(timer);\n this.sseBatchTimers.delete(res);\n }\n this.ssePendingBatches.delete(res);\n unsubscribe();\n this.sseClients.delete(res);\n this.sseCleanupFns.delete(cleanup);\n try { res.end(); } catch { /* ignore */ }\n };\n\n // Register so stop() can invoke cleanup even when the client is still\n // connected (releases the heartbeat interval and bus subscription\n // before the HTTP server is torn down).\n this.sseCleanupFns.add(cleanup);\n\n req.once(\"close\", cleanup);\n req.once(\"error\", cleanup);\n }\n\n private async handleMcpRequest(req: IncomingMessage, res: ServerResponse): Promise<void> {\n const body = await this.readJsonBody(req);\n const request = body as {\n jsonrpc?: string;\n id?: string | number | null;\n method?: string;\n params?: Record<string, unknown>;\n };\n\n // Enforce write rate limiting for MCP tool calls that mutate state,\n // matching the same protection applied to the REST write endpoints.\n // Pre-check ensures capacity; post-check skips counting dry runs and\n // idempotency replays, consistent with the REST handlers.\n const toolName = typeof request.params?.name === \"string\" ? request.params.name : \"\";\n const toolArgs = request.params?.arguments;\n const dreamsRunDryRun =\n (toolName === \"engram.dreams_run\" || toolName === \"remnic.dreams_run\") &&\n toolArgs !== null &&\n typeof toolArgs === \"object\" &&\n !Array.isArray(toolArgs) &&\n (toolArgs as { dryRun?: unknown }).dryRun === true;\n const memoryActionApplyDryRun =\n (toolName === \"engram.memory_action_apply\" || toolName === \"remnic.memory_action_apply\") &&\n toolArgs !== null &&\n typeof toolArgs === \"object\" &&\n !Array.isArray(toolArgs) &&\n (toolArgs as { dryRun?: unknown }).dryRun === true;\n const isMcpWrite =\n request.method === \"tools/call\" &&\n (\n toolName === \"engram.memory_store\" ||\n toolName === \"remnic.memory_store\" ||\n toolName === \"engram.suggestion_submit\" ||\n toolName === \"remnic.suggestion_submit\" ||\n toolName === \"engram.observe\" ||\n toolName === \"remnic.observe\" ||\n toolName === \"engram.lcm_compaction_flush\" ||\n toolName === \"remnic.lcm_compaction_flush\" ||\n toolName === \"engram.lcm_compaction_record\" ||\n toolName === \"remnic.lcm_compaction_record\" ||\n toolName === \"engram.capsule_export\" ||\n toolName === \"remnic.capsule_export\" ||\n toolName === \"engram.capsule_import\" ||\n toolName === \"remnic.capsule_import\" ||\n (\n !dreamsRunDryRun &&\n (toolName === \"engram.dreams_run\" || toolName === \"remnic.dreams_run\")\n ) ||\n (\n !memoryActionApplyDryRun &&\n (\n toolName === \"engram.memory_action_apply\" ||\n toolName === \"remnic.memory_action_apply\"\n )\n )\n );\n if (isMcpWrite) {\n this.ensureWriteRateLimitAvailable();\n }\n\n const sessionId = (() => {\n const raw = req.headers[\"mcp-session-id\"];\n return typeof raw === \"string\" ? raw.trim() : undefined;\n })();\n const mcpCorrelationId = correlationIdStore.getStore() ?? randomUUID();\n const response = await this.mcpServer.handleRequest(request, {\n principalOverride: this.resolveRequestPrincipal(req),\n sessionId,\n correlationId: mcpCorrelationId,\n });\n\n if (isMcpWrite && response !== null) {\n const result = (response as Record<string, unknown>).result as Record<string, unknown> | undefined;\n const isError = result?.isError === true;\n const structured = result?.structuredContent as { dryRun?: boolean; idempotencyReplay?: boolean } | undefined;\n if (!isError && structured && this.shouldCountWriteRateLimit(structured)) {\n this.recordWriteRateLimitHit();\n }\n }\n if (response === null) {\n res.statusCode = 202;\n res.end();\n return;\n }\n // If this was an initialize response, pop the session ID keyed by\n // correlation ID (unique per HTTP request, not client-chosen JSON-RPC id).\n const assignedSessionId = this.mcpServer.popInitSessionId(mcpCorrelationId);\n if (assignedSessionId) {\n res.setHeader(\"mcp-session-id\", assignedSessionId);\n }\n this.respondJson(res, 200, response);\n }\n\n private respondJson(res: ServerResponse, status: number, payload: unknown): void {\n const body = JSON.stringify(payload, null, 2);\n res.statusCode = status;\n res.setHeader(\"content-type\", \"application/json; charset=utf-8\");\n res.setHeader(\"content-length\", String(Buffer.byteLength(body)));\n const cid = correlationIdStore.getStore();\n if (cid) {\n res.setHeader(\"x-request-id\", cid);\n }\n res.end(body);\n }\n\n private respondBinary(\n res: ServerResponse,\n status: number,\n body: Buffer,\n headers: Record<string, string> = {},\n ): void {\n res.statusCode = status;\n res.setHeader(\"content-type\", \"application/octet-stream\");\n res.setHeader(\"content-length\", String(body.length));\n for (const [key, value] of Object.entries(headers)) {\n res.setHeader(key, value);\n }\n const cid = correlationIdStore.getStore();\n if (cid) {\n res.setHeader(\"x-request-id\", cid);\n }\n res.end(body);\n }\n\n private async handleAdminConsole(\n req: IncomingMessage,\n res: ServerResponse,\n pathname: string,\n ): Promise<boolean> {\n if (req.method !== \"GET\") return false;\n if (pathname === \"/remnic/ui\" || pathname === \"/engram/ui\") {\n res.statusCode = 301;\n res.setHeader(\"location\", pathname + \"/\");\n res.end();\n return true;\n }\n if (pathname === \"/remnic/ui/\" || pathname === \"/engram/ui/\") {\n await this.respondStatic(res, path.join(this.adminConsolePublicDir, \"index.html\"), \"text/html; charset=utf-8\");\n return true;\n }\n if (pathname === \"/remnic/ui/app.js\" || pathname === \"/engram/ui/app.js\") {\n await this.respondStatic(res, path.join(this.adminConsolePublicDir, \"app.js\"), \"application/javascript; charset=utf-8\");\n return true;\n }\n return false;\n }\n\n private async respondStatic(res: ServerResponse, filePath: string, contentType: string): Promise<void> {\n try {\n const body = await readFile(filePath, \"utf-8\");\n res.statusCode = 200;\n res.setHeader(\"content-type\", contentType);\n res.setHeader(\"content-length\", String(Buffer.byteLength(body)));\n res.end(body);\n } catch {\n this.respondJson(res, 404, { error: \"not_found\" });\n }\n }\n\n private async readJsonBody(req: IncomingMessage): Promise<Record<string, unknown>> {\n const chunks: Buffer[] = [];\n let total = 0;\n for await (const chunk of req) {\n const buffer = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);\n total += buffer.length;\n if (total > this.maxBodyBytes) {\n throw new HttpError(413, \"request_body_too_large\", \"request_body_too_large\");\n }\n chunks.push(buffer);\n }\n if (chunks.length === 0) return {};\n const raw = Buffer.concat(chunks).toString(\"utf-8\").trim();\n if (raw.length === 0) return {};\n let parsed: unknown;\n try {\n parsed = JSON.parse(raw);\n } catch {\n throw new HttpError(400, \"invalid_json\", \"invalid_json\");\n }\n if (!parsed || typeof parsed !== \"object\" || Array.isArray(parsed)) {\n throw new HttpError(400, \"invalid_json_object\", \"invalid_json_object\");\n }\n return parsed as Record<string, unknown>;\n }\n\n private async readBinaryBody(req: IncomingMessage, maxBytes: number): Promise<Buffer> {\n const chunks: Buffer[] = [];\n let total = 0;\n for await (const chunk of req) {\n const buffer = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);\n total += buffer.length;\n if (total > maxBytes) {\n throw new HttpError(413, \"request_body_too_large\", \"request_body_too_large\");\n }\n chunks.push(buffer);\n }\n return Buffer.concat(chunks, total);\n }\n\n private readRequiredHeader(req: IncomingMessage, name: string): string {\n const value = this.readOptionalHeader(req, name);\n if (value === undefined || value.length === 0) {\n throw new EngramAccessInputError(`${name} header is required`);\n }\n return value;\n }\n\n private readOptionalHeader(req: IncomingMessage, name: string): string | undefined {\n const raw = req.headers[name.toLowerCase()];\n if (Array.isArray(raw)) return raw[0]?.trim() || undefined;\n return raw?.trim() || undefined;\n }\n\n private readRequiredDecodedHeader(req: IncomingMessage, name: string): string {\n const raw = this.readRequiredHeader(req, name);\n try {\n return decodeURIComponent(raw);\n } catch {\n throw new EngramAccessInputError(`${name} header is not valid percent-encoded input`);\n }\n }\n\n private readRequiredIntegerHeader(req: IncomingMessage, name: string): number {\n const raw = this.readRequiredHeader(req, name);\n const parsed = Number(raw);\n if (!Number.isInteger(parsed) || parsed < 0) {\n throw new EngramAccessInputError(`${name} header must be a non-negative integer`);\n }\n return parsed;\n }\n\n private readOptionalIntegerHeader(req: IncomingMessage, name: string): number | undefined {\n const raw = this.readOptionalHeader(req, name);\n if (raw === undefined) return undefined;\n const parsed = Number(raw);\n if (!Number.isInteger(parsed) || parsed < 0) {\n throw new EngramAccessInputError(`${name} header must be a non-negative integer`);\n }\n return parsed;\n }\n\n private readRequiredNumberHeader(req: IncomingMessage, name: string): number {\n const raw = this.readRequiredHeader(req, name);\n const parsed = Number(raw);\n if (!Number.isFinite(parsed) || parsed < 0) {\n throw new EngramAccessInputError(`${name} header must be a non-negative finite number`);\n }\n return parsed;\n }\n\n private parseOptionalBooleanHeader(\n req: IncomingMessage,\n name: string,\n defaultValue: boolean,\n ): boolean {\n const raw = this.readOptionalHeader(req, name);\n if (raw === undefined) return defaultValue;\n if (raw === \"true\") return true;\n if (raw === \"false\") return false;\n throw new EngramAccessInputError(`${name} header must be one of: true, false`);\n }\n\n private async readValidatedBody<S extends SchemaName>(req: IncomingMessage, schemaName: S): Promise<SchemaTypeFor<S>> {\n const raw = await this.readJsonBody(req);\n const result = validateRequest(schemaName, raw);\n if (!result.success) {\n throw new HttpError(400, result.error.error, \"validation_error\", result.error.details);\n }\n return result.data as SchemaTypeFor<S>;\n }\n\n private isAuthorized(req: IncomingMessage, pathname?: string): boolean {\n if (!this.authToken && this.authTokens.length === 0 && !this.authTokensGetter) return false;\n // Primary path: Authorization: Bearer <token> header.\n const raw = req.headers.authorization;\n let candidate: string | null = null;\n if (raw) {\n const separator = raw.indexOf(\" \");\n if (separator > 0) {\n const scheme = raw.slice(0, separator).toLowerCase();\n if (scheme === \"bearer\") {\n candidate = raw.slice(separator + 1).trim();\n }\n }\n }\n // Fallback: ?token= query parameter — ONLY accepted for the SSE\n // endpoint (/engram/v1/graph/events). EventSource cannot set request\n // headers, so SSE clients must pass the token via the query string.\n // Allowing this fallback on every endpoint would let a CSRF attacker\n // embed a credentialed URL anywhere — restricting it to SSE limits the\n // attack surface (Codex P2 review thread `access-http.ts:1406`; Cursor\n // review thread `access-http.ts:1412`). Authorization header always\n // wins; timing-safe compare used below.\n if (!candidate && pathname === \"/engram/v1/graph/events\") {\n try {\n const parsed = new URL(req.url ?? \"/\", `http://${hostToUrlAuthority(this.host)}`);\n const queryToken = parsed.searchParams.get(\"token\");\n if (queryToken && queryToken.length > 0) {\n candidate = queryToken;\n }\n } catch {\n // Malformed URL — don't authenticate\n }\n }\n if (!candidate) return false;\n const token = candidate;\n // Check primary token\n if (this.authToken && this.timingSafeStringEqual(token, this.authToken)) return true;\n // Check static multi-connector tokens\n for (const valid of this.authTokens) {\n if (this.timingSafeStringEqual(token, valid)) return true;\n }\n // Check dynamic tokens (reloaded per request for generate/revoke without restart)\n if (this.authTokensGetter) {\n for (const valid of this.authTokensGetter()) {\n if (this.timingSafeStringEqual(token, valid)) return true;\n }\n }\n return false;\n }\n\n private timingSafeStringEqual(a: string, b: string): boolean {\n const left = this.encodeSecret(a);\n const right = this.encodeSecret(b);\n if (!left || !right) return false;\n return timingSafeEqual(left, right);\n }\n\n private encodeSecret(value: string): Buffer | null {\n const encoded = Buffer.from(value, \"utf-8\");\n if (encoded.length > 1024) return null;\n const out = Buffer.alloc(2 + 1024);\n out.writeUInt16BE(encoded.length, 0);\n encoded.copy(out, 2);\n return out;\n }\n\n private writeResponseStatus(response: { dryRun: boolean; status: string }): number {\n if (response.dryRun === true) return 200;\n if (response.status === \"stored\" || response.status === \"queued_for_review\") return 201;\n return 200;\n }\n\n private ensureWriteRateLimitAvailable(): void {\n const now = Date.now();\n while (\n this.writeRequestTimestamps.length > 0 &&\n now - (this.writeRequestTimestamps[0] ?? 0) > WRITE_RATE_LIMIT_WINDOW_MS\n ) {\n this.writeRequestTimestamps.shift();\n }\n if (this.writeRequestTimestamps.length >= WRITE_RATE_LIMIT_MAX_REQUESTS) {\n throw new HttpError(429, \"write_rate_limited\", \"write_rate_limited\");\n }\n }\n\n private recordWriteRateLimitHit(): void {\n this.writeRequestTimestamps.push(Date.now());\n }\n\n private shouldCountWriteRateLimit(response: { dryRun?: boolean; idempotencyReplay?: boolean }): boolean {\n return response.dryRun !== true && response.idempotencyReplay !== true;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,oBAA4E;AACrF,SAAS,YAAY,uBAAuB;AAC5C,SAAS,yBAAyB;AAClC,SAAS,kBAAkB;AAC3B,SAAS,gBAAgB;AACzB,OAAO,UAAU;AACjB,SAAS,eAAe,WAAW;AAgDnC,SAAS,sCAA8C;AACrD,QAAM,UAAU,KAAK,QAAQ,cAAc,YAAY,GAAG,CAAC;AAC3D,QAAM,aAAa;AAAA;AAAA,IAEjB,KAAK,QAAQ,SAAS,yBAAyB;AAAA;AAAA,IAE/C,KAAK,QAAQ,SAAS,wBAAwB;AAAA;AAAA,IAE9C,KAAK,QAAQ,SAAS,4BAA4B;AAAA,EACpD;AACA,SAAO,WAAW,KAAK,CAAC,cAAc,WAAW,SAAS,CAAC,KAAK,WAAW,CAAC;AAC9E;AAEA,IAAM,+BAA+B,oCAAoC;AACzE,IAAM,qBAAqB,IAAI,kBAA0B;AAEzD,IAAM,6BAA6B;AACnC,IAAM,gCAAgC;AACtC,IAAM,0BAA0B,CAAC,UAAU,YAAY,SAAS,cAAc,UAAU;AACxF,IAAM,4BAA4B,CAAC,eAAe,eAAe,kBAAkB,iBAAiB,cAAc,QAAQ;AAE1H,IAAM,YAAN,cAAwB,MAAM;AAA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