@remnic/core 10.0.134 → 10.0.136

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.
Files changed (176) hide show
  1. package/dist/access-admin-ops-surface.js +39 -39
  2. package/dist/access-cli.js +39 -39
  3. package/dist/access-extraction-force-flush.js +39 -39
  4. package/dist/access-http-briefing.js +39 -39
  5. package/dist/access-http-query.js +39 -39
  6. package/dist/access-http.d.ts.map +1 -1
  7. package/dist/access-http.js +39 -39
  8. package/dist/access-identity-continuity-surface.js +39 -39
  9. package/dist/access-lcm-surface.js +39 -39
  10. package/dist/access-mcp.js +39 -39
  11. package/dist/access-observe-write-surface.js +39 -39
  12. package/dist/access-operations-batch.js +39 -39
  13. package/dist/access-operations.js +39 -39
  14. package/dist/access-recall-concurrency.js +39 -39
  15. package/dist/access-recall-diagnostics.js +2 -2
  16. package/dist/access-recall-response.d.ts.map +1 -1
  17. package/dist/access-recall-response.js +39 -39
  18. package/dist/access-recall-surface.d.ts.map +1 -1
  19. package/dist/access-recall-surface.js +39 -39
  20. package/dist/access-service.d.ts +2 -0
  21. package/dist/access-service.d.ts.map +1 -1
  22. package/dist/access-service.js +39 -39
  23. package/dist/active-recall.js +3 -3
  24. package/dist/briefing.js +3 -3
  25. package/dist/causal-consolidation.js +4 -4
  26. package/dist/{chunk-AGDPIO6J.js → chunk-2OIQHXN4.js} +2 -2
  27. package/dist/{chunk-MKXKED3B.js → chunk-37T5ZO5P.js} +2 -2
  28. package/dist/{chunk-7DWLU7GU.js → chunk-3F6COEHZ.js} +1 -1
  29. package/dist/chunk-3F6COEHZ.js.map +1 -0
  30. package/dist/{chunk-PVCGXXQB.js → chunk-3TU6OBI7.js} +2 -2
  31. package/dist/{chunk-6IPTMGLJ.js → chunk-4H7TUVWQ.js} +2 -2
  32. package/dist/{chunk-SS7CPYWD.js → chunk-4VL2H5Q3.js} +2 -2
  33. package/dist/{chunk-XMT27576.js → chunk-5RCXMLI5.js} +2 -2
  34. package/dist/{chunk-MFPPRA4F.js → chunk-5RZ4DAP6.js} +3 -3
  35. package/dist/{chunk-PWTXXSJ5.js → chunk-5ZS73P3U.js} +2 -2
  36. package/dist/{chunk-ZKYWI3N5.js → chunk-6LNWA6IT.js} +3 -3
  37. package/dist/{chunk-KRMAIJMP.js → chunk-6Z7BRM7C.js} +2 -2
  38. package/dist/{chunk-G2LJ6KVK.js → chunk-BL545EH7.js} +2 -2
  39. package/dist/chunk-BL545EH7.js.map +1 -0
  40. package/dist/{chunk-D4LXRZVD.js → chunk-CGEOIR4F.js} +59 -36
  41. package/dist/{chunk-D4LXRZVD.js.map → chunk-CGEOIR4F.js.map} +1 -1
  42. package/dist/{chunk-L7V55O3P.js → chunk-EFMAYZOB.js} +2 -2
  43. package/dist/{chunk-VTL2NQED.js → chunk-FEWOSD33.js} +2 -2
  44. package/dist/{chunk-CEN6DW6X.js → chunk-G4NKURT4.js} +7 -2
  45. package/dist/{chunk-CEN6DW6X.js.map → chunk-G4NKURT4.js.map} +1 -1
  46. package/dist/{chunk-7OX7U2XB.js → chunk-GUI7MLKC.js} +2 -2
  47. package/dist/{chunk-LAUZ3EQU.js → chunk-GW23JXGJ.js} +2 -2
  48. package/dist/{chunk-5A6HGHTU.js → chunk-HKQ3LH34.js} +3 -3
  49. package/dist/{chunk-EVM7JM3U.js → chunk-IXX4SKF5.js} +2 -2
  50. package/dist/{chunk-G5RFNMJ2.js → chunk-KIICCGSV.js} +2 -2
  51. package/dist/{chunk-L2NXX7B7.js → chunk-KN44QS5F.js} +3 -3
  52. package/dist/{chunk-SEQ3PEJ4.js → chunk-LK3LXSJQ.js} +2 -2
  53. package/dist/{chunk-K4BSIADH.js → chunk-LR6QP72R.js} +2 -2
  54. package/dist/{chunk-IE3KZVCC.js → chunk-NEXJ3OOZ.js} +3 -3
  55. package/dist/{chunk-ETDVI7JS.js → chunk-OE35LFBF.js} +2 -2
  56. package/dist/{chunk-FASAQQF7.js → chunk-PA5FI6A5.js} +2 -2
  57. package/dist/{chunk-H37DI6HW.js → chunk-QOI4PNVG.js} +2 -2
  58. package/dist/{chunk-P76WH5JD.js → chunk-S3LWB6K3.js} +2 -2
  59. package/dist/{chunk-P4G6C7XS.js → chunk-SCQO7JOF.js} +2 -2
  60. package/dist/{chunk-PK7IEAQB.js → chunk-STKNZY7A.js} +2 -2
  61. package/dist/{chunk-FEAIHXCI.js → chunk-U5OVNYJX.js} +2 -2
  62. package/dist/{chunk-MUHGYV2V.js → chunk-VT75USBD.js} +2 -1
  63. package/dist/chunk-VT75USBD.js.map +1 -0
  64. package/dist/{chunk-GQ6MZ43R.js → chunk-WYSCN5TA.js} +2 -2
  65. package/dist/{chunk-5RPRVPZU.js → chunk-XBNGH2FV.js} +2 -2
  66. package/dist/{chunk-45GDXYAW.js → chunk-XCZQ7MID.js} +7 -7
  67. package/dist/{chunk-Z4EIJ6CR.js → chunk-Y3TA66MZ.js} +2 -2
  68. package/dist/{chunk-IP25A6HJ.js → chunk-YNTVQWLX.js} +8 -8
  69. package/dist/{chunk-45BPRD6P.js → chunk-ZGGFGUUF.js} +2 -2
  70. package/dist/{chunk-MWDMUMQ6.js → chunk-ZKHDDEPF.js} +2 -2
  71. package/dist/cli.js +39 -39
  72. package/dist/coding/export-okf-codegraph.js +2 -2
  73. package/dist/compounding/engine.js +4 -4
  74. package/dist/config.d.ts.map +1 -1
  75. package/dist/config.js +3 -3
  76. package/dist/connectors/codex-materialize-runner.js +3 -3
  77. package/dist/connectors/index.js +3 -3
  78. package/dist/convergence-refresh.js +5 -5
  79. package/dist/corpus-watermark.js +5 -5
  80. package/dist/entity-retrieval.js +3 -3
  81. package/dist/explicit-capture.js +39 -39
  82. package/dist/extraction.js +3 -3
  83. package/dist/harmonic-retrieval.js +3 -3
  84. package/dist/index.js +39 -39
  85. package/dist/location/index.js +4 -4
  86. package/dist/maintenance/memory-governance.js +3 -3
  87. package/dist/maintenance/rebuild-memory-lifecycle-ledger.js +3 -3
  88. package/dist/maintenance/rebuild-memory-projection-runner.js +5 -5
  89. package/dist/maintenance/rebuild-memory-projection.js +4 -4
  90. package/dist/namespaces/migrate.js +4 -4
  91. package/dist/namespaces/storage.js +3 -3
  92. package/dist/operator-doctor-corpus.js +6 -6
  93. package/dist/operator-toolkit.js +10 -10
  94. package/dist/orchestration/backlog-scheduler.js +40 -40
  95. package/dist/orchestration/buffer-drain-runner.js +40 -40
  96. package/dist/orchestration/maintenance.js +11 -11
  97. package/dist/orchestration/recall-internal.d.ts.map +1 -1
  98. package/dist/orchestrator.js +39 -39
  99. package/dist/recall-explain-renderer.js +3 -3
  100. package/dist/recall-navigate-access.js +2 -2
  101. package/dist/recall-navigate-disclosure.js +2 -2
  102. package/dist/recall-navigate.js +2 -2
  103. package/dist/recall-navigation.js +39 -39
  104. package/dist/recall-state.d.ts +10 -0
  105. package/dist/recall-state.d.ts.map +1 -1
  106. package/dist/recall-state.js +1 -1
  107. package/dist/recall-timings.d.ts +15 -0
  108. package/dist/recall-timings.d.ts.map +1 -1
  109. package/dist/recall-timings.js +3 -1
  110. package/dist/recall-xray-cli.js +4 -4
  111. package/dist/recall-xray-renderer.js +3 -3
  112. package/dist/recall-xray.js +2 -2
  113. package/dist/resume-bundles.js +4 -4
  114. package/dist/semantic-consolidation.js +4 -4
  115. package/dist/semantic-rule-promotion.js +3 -3
  116. package/dist/semantic-rule-verifier.js +3 -3
  117. package/dist/source-agent-qualifier.js +3 -3
  118. package/dist/standup/build.js +3 -3
  119. package/dist/storage.js +2 -2
  120. package/dist/transfer/export-okf.js +3 -3
  121. package/dist/types.d.ts +4 -7
  122. package/dist/types.d.ts.map +1 -1
  123. package/dist/types.js +1 -1
  124. package/dist/verified-recall.js +3 -3
  125. package/dist/who-knows-cli.js +4 -4
  126. package/dist/who-knows.js +3 -3
  127. package/package.json +2 -2
  128. package/src/access-http.ts +28 -0
  129. package/src/access-recall-response.ts +1 -0
  130. package/src/access-recall-surface.ts +5 -4
  131. package/src/access-serve-trust-principal-config.test.ts +270 -0
  132. package/src/access-service.ts +2 -0
  133. package/src/access-trust-principal-header.test.ts +6 -4
  134. package/src/config.ts +6 -8
  135. package/src/orchestration/recall-internal.ts +2 -0
  136. package/src/recall-state.ts +11 -0
  137. package/src/recall-timings.ts +15 -0
  138. package/src/types.ts +11 -8
  139. package/dist/chunk-7DWLU7GU.js.map +0 -1
  140. package/dist/chunk-G2LJ6KVK.js.map +0 -1
  141. package/dist/chunk-MUHGYV2V.js.map +0 -1
  142. /package/dist/{chunk-AGDPIO6J.js.map → chunk-2OIQHXN4.js.map} +0 -0
  143. /package/dist/{chunk-MKXKED3B.js.map → chunk-37T5ZO5P.js.map} +0 -0
  144. /package/dist/{chunk-PVCGXXQB.js.map → chunk-3TU6OBI7.js.map} +0 -0
  145. /package/dist/{chunk-6IPTMGLJ.js.map → chunk-4H7TUVWQ.js.map} +0 -0
  146. /package/dist/{chunk-SS7CPYWD.js.map → chunk-4VL2H5Q3.js.map} +0 -0
  147. /package/dist/{chunk-XMT27576.js.map → chunk-5RCXMLI5.js.map} +0 -0
  148. /package/dist/{chunk-MFPPRA4F.js.map → chunk-5RZ4DAP6.js.map} +0 -0
  149. /package/dist/{chunk-PWTXXSJ5.js.map → chunk-5ZS73P3U.js.map} +0 -0
  150. /package/dist/{chunk-ZKYWI3N5.js.map → chunk-6LNWA6IT.js.map} +0 -0
  151. /package/dist/{chunk-KRMAIJMP.js.map → chunk-6Z7BRM7C.js.map} +0 -0
  152. /package/dist/{chunk-L7V55O3P.js.map → chunk-EFMAYZOB.js.map} +0 -0
  153. /package/dist/{chunk-VTL2NQED.js.map → chunk-FEWOSD33.js.map} +0 -0
  154. /package/dist/{chunk-7OX7U2XB.js.map → chunk-GUI7MLKC.js.map} +0 -0
  155. /package/dist/{chunk-LAUZ3EQU.js.map → chunk-GW23JXGJ.js.map} +0 -0
  156. /package/dist/{chunk-5A6HGHTU.js.map → chunk-HKQ3LH34.js.map} +0 -0
  157. /package/dist/{chunk-EVM7JM3U.js.map → chunk-IXX4SKF5.js.map} +0 -0
  158. /package/dist/{chunk-G5RFNMJ2.js.map → chunk-KIICCGSV.js.map} +0 -0
  159. /package/dist/{chunk-L2NXX7B7.js.map → chunk-KN44QS5F.js.map} +0 -0
  160. /package/dist/{chunk-SEQ3PEJ4.js.map → chunk-LK3LXSJQ.js.map} +0 -0
  161. /package/dist/{chunk-K4BSIADH.js.map → chunk-LR6QP72R.js.map} +0 -0
  162. /package/dist/{chunk-IE3KZVCC.js.map → chunk-NEXJ3OOZ.js.map} +0 -0
  163. /package/dist/{chunk-ETDVI7JS.js.map → chunk-OE35LFBF.js.map} +0 -0
  164. /package/dist/{chunk-FASAQQF7.js.map → chunk-PA5FI6A5.js.map} +0 -0
  165. /package/dist/{chunk-H37DI6HW.js.map → chunk-QOI4PNVG.js.map} +0 -0
  166. /package/dist/{chunk-P76WH5JD.js.map → chunk-S3LWB6K3.js.map} +0 -0
  167. /package/dist/{chunk-P4G6C7XS.js.map → chunk-SCQO7JOF.js.map} +0 -0
  168. /package/dist/{chunk-PK7IEAQB.js.map → chunk-STKNZY7A.js.map} +0 -0
  169. /package/dist/{chunk-FEAIHXCI.js.map → chunk-U5OVNYJX.js.map} +0 -0
  170. /package/dist/{chunk-GQ6MZ43R.js.map → chunk-WYSCN5TA.js.map} +0 -0
  171. /package/dist/{chunk-5RPRVPZU.js.map → chunk-XBNGH2FV.js.map} +0 -0
  172. /package/dist/{chunk-45GDXYAW.js.map → chunk-XCZQ7MID.js.map} +0 -0
  173. /package/dist/{chunk-Z4EIJ6CR.js.map → chunk-Y3TA66MZ.js.map} +0 -0
  174. /package/dist/{chunk-IP25A6HJ.js.map → chunk-YNTVQWLX.js.map} +0 -0
  175. /package/dist/{chunk-45BPRD6P.js.map → chunk-ZGGFGUUF.js.map} +0 -0
  176. /package/dist/{chunk-MWDMUMQ6.js.map → chunk-ZKHDDEPF.js.map} +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remnic/core",
3
- "version": "10.0.134",
3
+ "version": "10.0.136",
4
4
  "description": "Framework-agnostic Remnic memory engine — orchestrator, storage, extraction, search, trust zones",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -3396,7 +3396,7 @@
3396
3396
  "core"
3397
3397
  ],
3398
3398
  "peerDependencies": {
3399
- "@remnic/coding-graph": "^10.0.134"
3399
+ "@remnic/coding-graph": "^10.0.136"
3400
3400
  },
3401
3401
  "peerDependenciesMeta": {
3402
3402
  "@remnic/coding-graph": {
@@ -263,6 +263,26 @@ function rejectBlankRelayNamespace(value: string | null | undefined): void {
263
263
  }
264
264
  }
265
265
 
266
+ const PRINCIPAL_HEADER_MAX_CHARS = 128;
267
+ // Principals are durable identity strings (sessionOwnerPrincipal, scope-group
268
+ // keys, derived namespaces): no whitespace, control characters, or path
269
+ // separators; `..` is refused so a value can never collide with traversal
270
+ // shapes anywhere downstream.
271
+ const INVALID_PRINCIPAL_HEADER_CHARS = /[\s\/\\]|\.{2}/;
272
+
273
+ function isValidPrincipalHeaderValue(value: string): boolean {
274
+ if (value.length === 0 || Array.from(value).length > PRINCIPAL_HEADER_MAX_CHARS) return false;
275
+ if (INVALID_PRINCIPAL_HEADER_CHARS.test(value)) return false;
276
+ // Control characters are refused: C0 (<0x20) plus DEL and the C1 range
277
+ // (0x7f-0x9f, which \s does not cover — e.g. U+0085 NEL). Printable/unicode
278
+ // otherwise fine.
279
+ for (const ch of value) {
280
+ const code = ch.codePointAt(0) ?? 0;
281
+ if (code < 0x20 || (code >= 0x7f && code <= 0x9f)) return false;
282
+ }
283
+ return true;
284
+ }
285
+
266
286
  function codingContextFromProjectTag(projectTag: string): {
267
287
  projectId: string;
268
288
  branch: string | null;
@@ -610,6 +630,14 @@ export class EngramAccessHttpServer extends ReviewDeckAccessHttpBase {
610
630
  if (typeof raw === "string") {
611
631
  const trimmed = raw.trim();
612
632
  if (trimmed.length > 0) {
633
+ // Trust boundary (issue #3460): once the header is honored, a client
634
+ // could stamp any value as sessionOwnerPrincipal on durable records.
635
+ // Reject malformed identities instead of storing them verbatim.
636
+ if (!isValidPrincipalHeaderValue(trimmed)) {
637
+ throw new EngramAccessInputError(
638
+ `invalid x-engram-principal header value: must be 1-128 chars with no whitespace, control chars, or path separators`,
639
+ );
640
+ }
613
641
  principal = trimmed;
614
642
  }
615
643
  }
@@ -342,6 +342,7 @@ export async function assembleRecallResponse(
342
342
  auditAnomalies,
343
343
  budgetWarning: toBudgetWarning(budgetDecision),
344
344
  latencyMs: snapshot?.latencyMs ?? (Date.now() - startedAt),
345
+ timings: snapshot?.timings,
345
346
  debug: safeDebug,
346
347
  },
347
348
  // Non-null when this recall reserved a cross-namespace budget event at
@@ -32,6 +32,7 @@ import { coerceIncludedMemories, type LastRecallSnapshot } from "./recall-state.
32
32
  import type { RecallContextComposition } from "./recall-context-composition.js";
33
33
  import { type TagMatchMode, applyTagFilter, normalizeTags, parseTagMatch } from "./recall-tag-filter.js";
34
34
  import { type RecallXraySnapshot, estimateRecallTokens } from "./recall-xray.js";
35
+ import { lastRecallTimingsFor } from "./recall-timings.js";
35
36
  import { SecureStoreLockedError } from "./secure-store/index.js";
36
37
  import { StorageManager } from "./index.js";
37
38
  import { DEFAULT_RECALL_DISCLOSURE, type MemoryFile, type RecallDisclosure, type RecallPlanMode, isRecallDisclosure } from "./types.js";
@@ -237,10 +238,7 @@ export class AccessRecallSurface {
237
238
  recallNamespaces: [namespace],
238
239
  traceId: options.snapshot.traceId,
239
240
  plannerMode: options.normalizedMode,
240
- requestedMode:
241
- options.requestedMode && options.requestedMode !== "auto"
242
- ? options.requestedMode
243
- : undefined,
241
+ requestedMode: options.requestedMode !== "auto" ? options.requestedMode : undefined,
244
242
  sourcesUsed,
245
243
  budgetsApplied: {
246
244
  appliedTopK: memoryIds.length,
@@ -249,6 +247,8 @@ export class AccessRecallSurface {
249
247
  finalContextChars: options.snapshot.budget.used,
250
248
  },
251
249
  latencyMs: Date.now() - options.startedAt,
250
+ // The record the capture's own recall wrote carries the section timings (traceId-pinned).
251
+ timings: lastRecallTimingsFor(this.deps.orchestrator.lastRecall, options.sessionKey, options.snapshot.traceId),
252
252
  includedMemories,
253
253
  };
254
254
  const results = await this.deps.serializeRecallResults(
@@ -296,6 +296,7 @@ export class AccessRecallSurface {
296
296
  budgetsApplied: snapshotForSerialization.budgetsApplied,
297
297
  storageCorpusVersionsAtRecallStart: options.storageCorpusVersionsAtRecallStart,
298
298
  latencyMs: snapshotForSerialization.latencyMs,
299
+ timings: snapshotForSerialization.timings,
299
300
  };
300
301
  }
301
302
 
@@ -0,0 +1,270 @@
1
+ /**
2
+ * `agentAccessHttp.trustPrincipalHeader` config path (issue #3462).
3
+ *
4
+ * The per-request principal header (`x-engram-principal`) was only reachable
5
+ * through the `--trust-principal-header` CLI flag; a fleet daemon started
6
+ * without the flag silently ignored pane-sent principals. This drives the
7
+ * registered `engram access http-serve` action (registerCli + recording
8
+ * program mock, as in cli-wearables-fuse.test.ts) against real namespace
9
+ * storage and asserts the precedence contract:
10
+ *
11
+ * - explicit `--trust-principal-header` flag wins,
12
+ * - absent flag falls back to `agentAccessHttp.trustPrincipalHeader` config,
13
+ * - both unset: header ignored (unchanged behavior),
14
+ * - parseConfig coerces bool-like strings and defaults to false.
15
+ */
16
+
17
+ import assert from "node:assert/strict";
18
+ import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises";
19
+ import os from "node:os";
20
+ import path from "node:path";
21
+ import test from "node:test";
22
+
23
+ import {
24
+ registerCli,
25
+ type CliApi,
26
+ type CliCommand,
27
+ type CliProgram,
28
+ } from "./cli.js";
29
+ import { parseConfig } from "./config.js";
30
+ import { NamespaceStorageRouter } from "./namespaces/storage.js";
31
+ import type { Orchestrator } from "./orchestrator.js";
32
+
33
+ /** Recording commander stand-in (same shape as cli-wearables-fuse.test.ts). */
34
+ class RecCmd implements CliCommand {
35
+ readonly children = new Map<string, RecCmd>();
36
+ readonly options: string[] = [];
37
+ readonly args: string[] = [];
38
+ actionFn?: (...args: unknown[]) => Promise<void> | void;
39
+ constructor(readonly rawName: string) {}
40
+ description(): CliCommand {
41
+ return this;
42
+ }
43
+ option(flags: string): CliCommand {
44
+ this.options.push(flags);
45
+ return this;
46
+ }
47
+ requiredOption(flags: string): CliCommand {
48
+ this.options.push(flags);
49
+ return this;
50
+ }
51
+ argument(name: string): CliCommand {
52
+ this.args.push(name);
53
+ return this;
54
+ }
55
+ action(fn: (...args: unknown[]) => Promise<void> | void): CliCommand {
56
+ this.actionFn = fn;
57
+ return this;
58
+ }
59
+ command(name: string): CliCommand {
60
+ const key = name.split(/\s+/)[0]!;
61
+ const child = new RecCmd(name);
62
+ this.children.set(key, child);
63
+ return child;
64
+ }
65
+ }
66
+
67
+ class RecProgram implements CliProgram {
68
+ readonly root = new RecCmd("__program__");
69
+ command(name: string): CliCommand {
70
+ return this.root.command(name);
71
+ }
72
+ }
73
+
74
+ const SERVE_TOKEN = "synthetic-serve-token";
75
+
76
+ /** CLI options shape commander hands the `engram access http-serve` action (flag values stay strings). */
77
+ interface ServeCliOptions {
78
+ host?: string;
79
+ port?: string;
80
+ token?: string;
81
+ trustPrincipalHeader?: boolean;
82
+ }
83
+
84
+ interface ServeFixture {
85
+ serve: (options: ServeCliOptions) => Promise<{ host: string; port: number }>;
86
+ stop: () => Promise<void>;
87
+ cleanup: () => Promise<void>;
88
+ }
89
+
90
+ interface EntityListBody {
91
+ entities?: Array<{ name?: string }>;
92
+ }
93
+
94
+ /** Config input for the fixture's access server; parseConfig accepts bool-like strings for the flag. */
95
+ interface FixtureAccessHttp {
96
+ principal: string;
97
+ trustPrincipalHeader?: boolean | string;
98
+ }
99
+
100
+ /**
101
+ * Entity reads need only config + real storage routing from the orchestrator
102
+ * (same Pick pattern as access-entity-principal.test.ts). The configured
103
+ * access principal is "reader", who may read `restricted` but NOT `default`;
104
+ * the header-supplied principal "owner" may read both — so a 200 on
105
+ * `namespace=default` proves the header principal was trusted.
106
+ */
107
+ async function createServeFixture(options: { trustPrincipalHeader?: boolean | string } = {}): Promise<ServeFixture> {
108
+ const memoryDir = await mkdtemp(path.join(os.tmpdir(), "remnic-serve-trust-"));
109
+ const agentAccessHttp: FixtureAccessHttp = {
110
+ principal: "reader",
111
+ };
112
+ if (options.trustPrincipalHeader !== undefined) {
113
+ agentAccessHttp.trustPrincipalHeader = options.trustPrincipalHeader;
114
+ }
115
+ const config = parseConfig({
116
+ memoryDir,
117
+ namespacesEnabled: true,
118
+ defaultNamespace: "default",
119
+ namespacePolicies: [
120
+ { name: "default", readPrincipals: ["owner"], writePrincipals: ["owner"] },
121
+ { name: "restricted", readPrincipals: ["owner", "reader"], writePrincipals: ["owner"] },
122
+ ],
123
+ agentAccessHttp,
124
+ });
125
+ const router = new NamespaceStorageRouter(config);
126
+ for (const namespace of ["default", "restricted"]) {
127
+ const storage = await router.storageFor(namespace);
128
+ const entitiesDir = path.join(storage.dir, "entities");
129
+ await mkdir(entitiesDir, { recursive: true });
130
+ await writeFile(path.join(entitiesDir, "project-widget.md"), [
131
+ `# Widget-${namespace}`,
132
+ "",
133
+ "**Type:** project",
134
+ "",
135
+ "## Summary",
136
+ "",
137
+ `Synthetic entity in ${namespace}.`,
138
+ "",
139
+ ].join("\n"));
140
+ }
141
+
142
+ const dependencies: Pick<Orchestrator, "config" | "getStorage" | "initialize"> = {
143
+ config,
144
+ getStorage: (namespace?: string) => router.storageFor(namespace ?? config.defaultNamespace),
145
+ initialize: async () => {},
146
+ };
147
+
148
+ const program = new RecProgram();
149
+ const api: CliApi = {
150
+ registerCli: (handler) => handler({ program }),
151
+ };
152
+ // SAFETY: registerCli and the http-serve action touch only config, getStorage, and
153
+ // initialize on the orchestrator; each member is provided with its real shape.
154
+ registerCli(api, dependencies as Parameters<typeof registerCli>[1]);
155
+ const engram = program.root.children.get("engram");
156
+ const access = engram?.children.get("access");
157
+ const serveCmd = access?.children.get("http-serve");
158
+ const stopCmd = access?.children.get("http-stop");
159
+ assert.ok(serveCmd?.actionFn, "engram access http-serve registered an action");
160
+ assert.ok(stopCmd?.actionFn, "engram access http-stop registered an action");
161
+
162
+ const stop = async () => {
163
+ await stopCmd!.actionFn!({});
164
+ };
165
+
166
+ const serve = async (options: ServeCliOptions) => {
167
+ const logs: string[] = [];
168
+ const originalLog = console.log;
169
+ console.log = (...args: unknown[]) => {
170
+ logs.push(args.map(String).join(" "));
171
+ };
172
+ try {
173
+ await serveCmd!.actionFn!(options);
174
+ } finally {
175
+ console.log = originalLog;
176
+ }
177
+ const statusLine = logs.map((line) => line.trim()).find((line) => line.startsWith("{"));
178
+ assert.ok(statusLine, "http-serve printed its status JSON");
179
+ // SAFETY: http-serve prints the server.start() status JSON ({ running, host, port, ... });
180
+ // only running/host/port are read and each is asserted below.
181
+ const status = JSON.parse(statusLine) as { running?: boolean; host?: string; port?: number };
182
+ assert.equal(status.running, true);
183
+ assert.ok(Number.isInteger(status.port), "http-serve status carries an integer port");
184
+ return { host: status.host ?? "127.0.0.1", port: status.port! };
185
+ };
186
+
187
+ return { serve, stop, cleanup: () => rm(memoryDir, { recursive: true, force: true }) };
188
+ }
189
+
190
+ async function readDefaultNamespaceAsOwner(
191
+ fixture: ServeFixture,
192
+ serveOptions: ServeCliOptions,
193
+ ): Promise<Response> {
194
+ const { host, port } = await fixture.serve(serveOptions);
195
+ try {
196
+ return await fetch(`http://${host}:${port}/engram/v1/entities?namespace=default`, {
197
+ headers: {
198
+ authorization: "Bearer " + SERVE_TOKEN,
199
+ "x-engram-principal": "owner",
200
+ },
201
+ });
202
+ } finally {
203
+ await fixture.stop();
204
+ }
205
+ }
206
+
207
+ test("parseConfig defaults agentAccessHttp.trustPrincipalHeader to false and coerces bool-like strings", () => {
208
+ assert.equal(parseConfig({}).agentAccessHttp.trustPrincipalHeader, false);
209
+ assert.equal(parseConfig({ agentAccessHttp: {} }).agentAccessHttp.trustPrincipalHeader, false);
210
+ assert.equal(parseConfig({ agentAccessHttp: { trustPrincipalHeader: true } }).agentAccessHttp.trustPrincipalHeader, true);
211
+ assert.equal(parseConfig({ agentAccessHttp: { trustPrincipalHeader: false } }).agentAccessHttp.trustPrincipalHeader, false);
212
+ assert.equal(parseConfig({ agentAccessHttp: { trustPrincipalHeader: "true" } }).agentAccessHttp.trustPrincipalHeader, true);
213
+ assert.equal(parseConfig({ agentAccessHttp: { trustPrincipalHeader: "1" } }).agentAccessHttp.trustPrincipalHeader, true);
214
+ assert.equal(parseConfig({ agentAccessHttp: { trustPrincipalHeader: "false" } }).agentAccessHttp.trustPrincipalHeader, false);
215
+ assert.equal(parseConfig({ agentAccessHttp: { trustPrincipalHeader: "0" } }).agentAccessHttp.trustPrincipalHeader, false);
216
+ });
217
+
218
+ test("absent flag falls back to agentAccessHttp.trustPrincipalHeader config (issue #3462)", async () => {
219
+ const fixture = await createServeFixture({ trustPrincipalHeader: true });
220
+ try {
221
+ // NO --trust-principal-header flag: config alone must trust the header.
222
+ // reader cannot read `default`; the header principal "owner" can.
223
+ const response = await readDefaultNamespaceAsOwner(fixture, {
224
+ host: "127.0.0.1",
225
+ port: "0",
226
+ token: "synthetic-serve-token",
227
+ });
228
+ assert.equal(response.status, 200);
229
+ // SAFETY: a 200 from /engram/v1/entities carries the entity-list envelope; only entity names are read.
230
+ const body = (await response.json()) as EntityListBody;
231
+ assert.equal(body.entities?.[0]?.name, "Widget-default");
232
+ } finally {
233
+ await fixture.cleanup();
234
+ }
235
+ });
236
+
237
+ test("explicit --trust-principal-header flag wins over config", async () => {
238
+ const fixture = await createServeFixture();
239
+ try {
240
+ const response = await readDefaultNamespaceAsOwner(fixture, {
241
+ host: "127.0.0.1",
242
+ port: "0",
243
+ token: "synthetic-serve-token",
244
+ trustPrincipalHeader: true,
245
+ });
246
+ assert.equal(response.status, 200);
247
+ // SAFETY: a 200 from /engram/v1/entities carries the entity-list envelope; only entity names are read.
248
+ const body = (await response.json()) as EntityListBody;
249
+ assert.equal(body.entities?.[0]?.name, "Widget-default");
250
+ } finally {
251
+ await fixture.cleanup();
252
+ }
253
+ });
254
+
255
+ test("both unset: x-engram-principal header stays ignored", async () => {
256
+ const fixture = await createServeFixture();
257
+ try {
258
+ const response = await readDefaultNamespaceAsOwner(fixture, {
259
+ host: "127.0.0.1",
260
+ port: "0",
261
+ token: "synthetic-serve-token",
262
+ });
263
+ assert.equal(response.status, 400);
264
+ // SAFETY: an ACL refusal from the access server answers { error }; only the message is read.
265
+ const body = (await response.json()) as { error?: string };
266
+ assert.match(body.error ?? "", /not readable/);
267
+ } finally {
268
+ await fixture.cleanup();
269
+ }
270
+ });
@@ -469,6 +469,8 @@ export interface EngramAccessRecallResponse {
469
469
  auditAnomalies?: AnomalyDetectorResult;
470
470
  budgetWarning?: BudgetWarning;
471
471
  latencyMs?: number;
472
+ /** Per-section timings from the recall snapshot (see `LastRecallSnapshot.timings`). */
473
+ timings?: Record<string, string>;
472
474
  debug?: {
473
475
  snapshot?: LastRecallSnapshot;
474
476
  intent?: IntentDebugSnapshot | null;
@@ -33,16 +33,18 @@ function makeConfig(memoryDir: string, agentAccessHttp?: AgentAccessHttpRawOverr
33
33
  });
34
34
  }
35
35
 
36
- test("agentAccessHttp.trustPrincipalHeader defaults off and takes only explicit true", () => {
37
- for (const input of [undefined, false, "yes", 1, { trust: true }]) {
36
+ test("agentAccessHttp.trustPrincipalHeader defaults off and accepts bool-like strings", () => {
37
+ for (const input of [undefined, false, 1, { trust: true }, "garbage"]) {
38
38
  const parsed = makeConfig(
39
39
  "/tmp/remnic-tph-default",
40
40
  input === undefined ? {} : { trustPrincipalHeader: input },
41
41
  );
42
42
  assert.equal(parsed.agentAccessHttp.trustPrincipalHeader, false, `input ${String(input)}`);
43
43
  }
44
- const trusted = makeConfig("/tmp/remnic-tph-on", { trustPrincipalHeader: true });
45
- assert.equal(trusted.agentAccessHttp.trustPrincipalHeader, true);
44
+ for (const input of [true, "yes", "1", "on"]) {
45
+ const parsed = makeConfig("/tmp/remnic-tph-on", { trustPrincipalHeader: input });
46
+ assert.equal(parsed.agentAccessHttp.trustPrincipalHeader, true, `input ${String(input)}`);
47
+ }
46
48
  });
47
49
 
48
50
  /** One timings-probe server per flag value; the route 200s for the operator principal and 403s otherwise. */
package/src/config.ts CHANGED
@@ -435,13 +435,11 @@ function isSecretRefShape(value: unknown): value is import("./types.js").SecretR
435
435
  }
436
436
 
437
437
  /**
438
- * Parse the `agentAccessHttp.authToken` field. Accepts:
439
- * - `string` → env-expanded immediately (current behavior preserved)
440
- * - `SecretRef` object (`{source, ...}`) → preserved verbatim for runtime
441
- * resolution by OpenClaw's gateway secret resolver
442
- * - `undefined` / empty string → fall back to env var, then `undefined`
443
- * - Any other shape → throw with a clear, actionable error so operators can
444
- * debug rather than chasing a generic startup failure (issue #757).
438
+ * Parse `agentAccessHttp.authToken`: string → env-expanded immediately (current behavior
439
+ * preserved); SecretRef object (`{source, ...}`) → preserved verbatim for runtime resolution
440
+ * by OpenClaw's gateway secret resolver; undefined/empty string → env var fallback then
441
+ * undefined; any other shape → throw with an actionable error, never a generic startup
442
+ * failure operators must chase down (issue #757).
445
443
  */
446
444
  function parseAgentAccessAuthToken(raw: unknown): import("./types.js").AgentAccessAuthToken | undefined {
447
445
  if (raw === undefined || raw === null) {
@@ -1487,7 +1485,7 @@ export function parseConfig(
1487
1485
  60_000,
1488
1486
  "agentAccessHttp.writeRateLimitWindowMs",
1489
1487
  ),
1490
- trustPrincipalHeader: rawAgentAccessHttp?.trustPrincipalHeader === true,
1488
+ trustPrincipalHeader: coerceBool(rawAgentAccessHttp?.trustPrincipalHeader, "agentAccessHttp.trustPrincipalHeader") ?? false,
1491
1489
  };
1492
1490
 
1493
1491
  let baseUrl: string | undefined;
@@ -619,6 +619,7 @@ export class RecallInternalCoordinator {
619
619
  qmdHybridFetchLimit,
620
620
  }),
621
621
  latencyMs: Date.now() - recallStart,
622
+ timings: { ...timings },
622
623
  includedMemories: [],
623
624
  policyVersion,
624
625
  appendImpression: this.deps.config.recordEmptyRecallImpressions,
@@ -5240,6 +5241,7 @@ export class RecallInternalCoordinator {
5240
5241
  sourcesUsed,
5241
5242
  budgetsApplied,
5242
5243
  latencyMs: Date.now() - recallStart,
5244
+ timings: { ...timings },
5243
5245
  includedMemories: assembledRecall.includedMemories,
5244
5246
  policyVersion,
5245
5247
  appendImpression:
@@ -63,6 +63,15 @@ export interface LastRecallSnapshot {
63
63
  sourcesUsed?: string[];
64
64
  budgetsApplied?: LastRecallBudgetSummary;
65
65
  latencyMs?: number;
66
+ /**
67
+ * Per-section wall-clock timings recorded during the recall pipeline
68
+ * (same map as the `recall timings:` log line and the timings ring
69
+ * buffer). Values are formatted strings — e.g. "4746ms", "skip",
70
+ * "12ms-cache" — so callers render them verbatim. Added so recall
71
+ * responses can name the slow section instead of exposing only
72
+ * `latencyMs`.
73
+ */
74
+ timings?: Record<string, string>;
66
75
  resultPaths?: string[];
67
76
  resultNamespaces?: Array<string | undefined>;
68
77
  policyVersion?: string;
@@ -411,6 +420,7 @@ export class LastRecallStore {
411
420
  sourcesUsed?: string[];
412
421
  budgetsApplied?: LastRecallBudgetSummary;
413
422
  latencyMs?: number;
423
+ timings?: Record<string, string>;
414
424
  resultPaths?: string[];
415
425
  resultNamespaces?: Array<string | undefined>;
416
426
  policyVersion?: string;
@@ -464,6 +474,7 @@ export class LastRecallStore {
464
474
  sourcesUsed: opts.sourcesUsed,
465
475
  budgetsApplied: opts.budgetsApplied,
466
476
  latencyMs: opts.latencyMs,
477
+ timings: opts.timings ? { ...opts.timings } : undefined,
467
478
  policyVersion: opts.policyVersion,
468
479
  identityInjectionMode: opts.identityInjection?.mode,
469
480
  identityInjectedChars: opts.identityInjection?.injectedChars,
@@ -155,3 +155,18 @@ export function getRecallTimingStatus(config: PluginConfig): RecallTimingStatus
155
155
  records,
156
156
  };
157
157
  }
158
+
159
+ /**
160
+ * Read the section-timing map the last-recall store kept for the recall that
161
+ * produced `traceId`. The traceId match pins the record to that run so an
162
+ * interleaved same-session recall cannot lend its timings to the wrong reply.
163
+ */
164
+ export function lastRecallTimingsFor(
165
+ store: { get(sessionKey: string): { traceId?: string; timings?: Record<string, string> } | null;
166
+ getMostRecent(): { traceId?: string; timings?: Record<string, string> } | null },
167
+ sessionKey: string | undefined,
168
+ traceId: string | undefined,
169
+ ): Record<string, string> | undefined {
170
+ const record = sessionKey ? store.get(sessionKey) : store.getMostRecent();
171
+ return record != null && record.traceId === traceId ? record.timings : undefined;
172
+ }
package/src/types.ts CHANGED
@@ -92,7 +92,13 @@ export type CodexCompactionFlushMode = "signal" | "heuristic" | "auto";
92
92
  export type DreamingNarrativePromptStyle = "reflective" | "diary" | "analytical";
93
93
  export type HeartbeatDetectionMode = "runtime-signal" | "heuristic" | "auto";
94
94
  export type ActiveRecallQueryMode = "message" | "recent" | "full";
95
- export type ActiveRecallPromptStyle = "balanced" | "strict" | "contextual" | "recall-heavy" | "precision-heavy" | "preference-only";
95
+ export type ActiveRecallPromptStyle =
96
+ | "balanced"
97
+ | "strict"
98
+ | "contextual"
99
+ | "recall-heavy"
100
+ | "precision-heavy"
101
+ | "preference-only";
96
102
  export type ActiveRecallThinking = "off" | "minimal" | "low" | "medium" | "high" | "xhigh" | "adaptive";
97
103
  export type ActiveRecallChatType = "direct" | "group" | "channel";
98
104
  export type ActiveRecallModelFallbackPolicy = "default-remote" | "resolved-only";
@@ -285,11 +291,8 @@ export interface AgentAccessHttpConfig {
285
291
  enabled: boolean;
286
292
  host: string;
287
293
  port: number;
288
- /**
289
- * Bearer token. Either a literal string (env-expanded) or an unresolved
290
- * SecretRef object preserved verbatim from openclaw.json — resolved at
291
- * service-start time via {@link resolveAgentAccessAuthToken}.
292
- */
294
+ /** Literal string (env-expanded) or unresolved SecretRef object, preserved verbatim and
295
+ * resolved at service-start time via {@link resolveAgentAccessAuthToken}. */
293
296
  authToken?: AgentAccessAuthToken;
294
297
  principal?: string;
295
298
  maxBodyBytes: number;
@@ -297,8 +300,8 @@ export interface AgentAccessHttpConfig {
297
300
  writeRateLimitMaxRequests: number;
298
301
  /** Rolling window for the write rate limit, in ms (issue #1937). */
299
302
  writeRateLimitWindowMs: number;
300
- /** Trust the `x-engram-principal` header for per-request principal resolution (default off; trusted proxies only). */
301
- trustPrincipalHeader?: boolean;
303
+ /** Trust the per-request `X-Engram-Principal` header; only behind the bearer-token trust boundary; `--trust-principal-header` overrides (issue #3462). */
304
+ trustPrincipalHeader: boolean;
302
305
  }
303
306
 
304
307
  export interface DreamingConfig {