@tpsdev-ai/flair 0.56.0 → 0.58.0

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 (153) hide show
  1. package/README.md +19 -20
  2. package/SECURITY.md +4 -1
  3. package/dist/build-info.json +3 -3
  4. package/dist/cli.js +1800 -293
  5. package/dist/commands/agent.js +22 -15
  6. package/dist/commands/bridge.js +40 -3
  7. package/dist/commands/doctor.js +214 -4
  8. package/dist/commands/federation.js +265 -38
  9. package/dist/commands/hook.js +10 -2
  10. package/dist/commands/init.js +179 -48
  11. package/dist/commands/memory.js +24 -2
  12. package/dist/commands/quality.js +26 -18
  13. package/dist/commands/service.js +137 -22
  14. package/dist/commands/status.js +114 -3
  15. package/dist/commands/upgrade.js +204 -84
  16. package/dist/doctor-client.js +50 -4
  17. package/dist/federation/scheduler.js +253 -4
  18. package/dist/install/clients.js +89 -23
  19. package/dist/install/global-bin-path.js +26 -6
  20. package/dist/lib/atomic-write.js +256 -0
  21. package/dist/lib/auth-resolve.js +46 -0
  22. package/dist/lib/daemon-liveness.js +61 -0
  23. package/dist/lib/doctor-run.js +5 -0
  24. package/dist/lib/embed-gpu-doctor.js +49 -26
  25. package/dist/lib/federation-memory-attributes.js +15 -0
  26. package/dist/lib/init-admin-pass.js +4 -2
  27. package/dist/lib/init-listener-environ.js +38 -0
  28. package/dist/lib/init-occupied-listener.js +165 -0
  29. package/dist/lib/instance-identity-row.js +580 -0
  30. package/dist/lib/launchd-domain-preflight.js +448 -0
  31. package/dist/lib/launchd-management.js +176 -6
  32. package/dist/lib/launchd-repair.js +95 -0
  33. package/dist/lib/memory-attributes.js +77 -0
  34. package/dist/lib/node-alias-path.js +95 -0
  35. package/dist/lib/npm-registry.js +119 -6
  36. package/dist/lib/owned-pins.js +20 -6
  37. package/dist/lib/redact-token-id.js +197 -0
  38. package/dist/lib/service-repoint-apply.js +267 -0
  39. package/dist/lib/service-repoint.js +575 -0
  40. package/dist/lib/toml-string-array.js +104 -0
  41. package/dist/lib/tree-divergence.js +716 -0
  42. package/dist/lib/upgrade-plain-tree.js +18 -8
  43. package/dist/lib/upgrade-prior-liveness.js +69 -0
  44. package/dist/lib/upgrade-rollback.js +116 -0
  45. package/dist/rem/runner.js +11 -0
  46. package/dist/resources/Agent.js +27 -14
  47. package/dist/resources/AgentSeed.js +39 -2
  48. package/dist/resources/Asset.js +3 -11
  49. package/dist/resources/Credential.js +4 -10
  50. package/dist/resources/Federation.js +299 -127
  51. package/dist/resources/Integration.js +8 -32
  52. package/dist/resources/Memory.js +623 -86
  53. package/dist/resources/MemoryArchive.js +9 -0
  54. package/dist/resources/MemoryBootstrap.js +23 -12
  55. package/dist/resources/MemoryCandidate.js +3 -11
  56. package/dist/resources/MemoryDedupStats.js +1 -1
  57. package/dist/resources/MemoryFeed.js +214 -5
  58. package/dist/resources/MemoryGrant.js +19 -40
  59. package/dist/resources/MemoryHostSource.js +90 -0
  60. package/dist/resources/MemoryMaintenance.js +121 -32
  61. package/dist/resources/MemoryReflect.js +4 -1
  62. package/dist/resources/MemoryReindex.js +7 -4
  63. package/dist/resources/MemoryUsage.js +55 -18
  64. package/dist/resources/Presence.js +18 -10
  65. package/dist/resources/RecordUsage.js +30 -40
  66. package/dist/resources/Relationship.js +170 -89
  67. package/dist/resources/SemanticSearch.js +44 -19
  68. package/dist/resources/Soul.js +31 -19
  69. package/dist/resources/XAA.js +7 -3
  70. package/dist/resources/agent-auth.js +16 -10
  71. package/dist/resources/auth-middleware.js +164 -50
  72. package/dist/resources/auto-promote-lib.js +4 -4
  73. package/dist/resources/bm25-index-service.js +246 -32
  74. package/dist/resources/bm25-status.js +132 -0
  75. package/dist/resources/bm25.js +13 -14
  76. package/dist/resources/ed25519-auth.js +11 -54
  77. package/dist/resources/embed-gpu.js +262 -47
  78. package/dist/resources/embeddings-boot.js +52 -17
  79. package/dist/resources/federation-classify.js +12 -0
  80. package/dist/resources/federation-cleanup.js +289 -51
  81. package/dist/resources/federation-crypto.js +65 -19
  82. package/dist/resources/health.js +105 -22
  83. package/dist/resources/host-pointer/registry.js +35 -0
  84. package/dist/resources/host-pointer-adapter.js +15 -0
  85. package/dist/resources/host-source-visibility.js +167 -0
  86. package/dist/resources/host-source.js +151 -0
  87. package/dist/resources/in-process-api.js +2 -1
  88. package/dist/resources/instance-create-lock.js +363 -0
  89. package/dist/resources/instance-identity-rows.js +43 -0
  90. package/dist/resources/instance-identity.js +97 -12
  91. package/dist/resources/mcp-handler.js +155 -51
  92. package/dist/resources/mcp-tool-arguments.js +83 -0
  93. package/dist/resources/mcp-tools.js +28 -25
  94. package/dist/resources/memory-consolidate-lib.js +3 -1
  95. package/dist/resources/memory-declared-attributes.js +103 -0
  96. package/dist/resources/memory-feed-lib.js +5 -1
  97. package/dist/resources/memory-host-source.js +163 -0
  98. package/dist/resources/memory-visibility.js +10 -7
  99. package/dist/resources/migrations/synthetic-test-migration.js +4 -1
  100. package/dist/resources/migrations/visibility-backfill.js +4 -1
  101. package/dist/resources/originator-instance.js +235 -0
  102. package/dist/resources/promotion-stamp.js +2 -0
  103. package/dist/resources/provenance.js +111 -11
  104. package/dist/resources/rate-limit.js +6 -4
  105. package/dist/resources/record-owner-guard.js +19 -0
  106. package/dist/resources/record-type-kit.js +44 -23
  107. package/dist/resources/record-types.js +6 -6
  108. package/dist/resources/relay-ops.js +28 -3
  109. package/dist/resources/replay-store.js +289 -0
  110. package/dist/resources/request-transaction.js +78 -0
  111. package/dist/resources/search-readiness.js +26 -22
  112. package/dist/resources/semantic-retrieval-core.js +103 -4
  113. package/dist/resources/table-helpers.js +33 -0
  114. package/dist/resources/table-patch-policy.js +109 -0
  115. package/dist/resources/table-patches.js +17 -0
  116. package/dist/resources/table-post-policy.js +138 -0
  117. package/dist/resources/table-posts.js +22 -0
  118. package/dist/resources/table-subscription-policy.js +135 -0
  119. package/dist/resources/table-subscriptions.js +19 -0
  120. package/dist/resources/tool-descriptors/index.js +15 -15
  121. package/dist/resources/trust-block.js +10 -3
  122. package/dist/resources/usage-recording.js +169 -41
  123. package/dist/src/lib/instance-identity-row.js +580 -0
  124. package/dist/src/lib/memory-attributes.js +77 -0
  125. package/dist/src/lib/redact-token-id.js +197 -0
  126. package/docs/api-reference.md +80 -16
  127. package/docs/auth.md +5 -5
  128. package/docs/claude-code.md +137 -6
  129. package/docs/deploying-on-fabric.md +6 -3
  130. package/docs/deployment.md +1 -1
  131. package/docs/embedding-in-a-harper-app.md +3 -3
  132. package/docs/federation.md +17 -10
  133. package/docs/hosted-on-fabric.md +4 -3
  134. package/docs/integrations.md +28 -19
  135. package/docs/mcp-clients.md +26 -32
  136. package/docs/n8n.md +8 -8
  137. package/docs/notes/mcp-oauth-model2.md +27 -18
  138. package/docs/openclaw.md +29 -28
  139. package/docs/quickstart.md +5 -0
  140. package/docs/releasing.md +134 -2
  141. package/docs/spoke-bringup.md +14 -11
  142. package/docs/standalone-local.md +2 -2
  143. package/docs/supply-chain-policy.md +28 -10
  144. package/docs/system-requirements.md +1 -1
  145. package/docs/troubleshooting.md +11 -0
  146. package/docs/upgrade.md +189 -63
  147. package/package.json +9 -5
  148. package/schemas/agent.graphql +9 -6
  149. package/schemas/federation.graphql +2 -11
  150. package/schemas/memory.graphql +106 -17
  151. package/schemas/replay.graphql +18 -0
  152. package/templates/launchd/start-flair-with-admin-pass.sh +22 -0
  153. package/dist/resources/federation-nonce-store.js +0 -195
@@ -2,11 +2,107 @@ import { patchRecord } from "./table-helpers.js";
2
2
  import { server, databases } from "harper";
3
3
  import { getEmbedding } from "./embeddings-provider.js";
4
4
  import { isAdmin, isPrincipalDeactivated, FLAIR_AGENT_USERNAME } from "./agent-auth.js";
5
- import { WINDOW_MS, isNonceReplay, recordNonce, importEd25519Key, b64ToArrayBuffer, parseTpsEd25519Header } from "./ed25519-auth.js";
6
- import { resolveReadScope } from "./memory-read-scope.js";
7
- import { NOT_FOUND } from "./record-type-kit.js";
8
- import { isForbiddenOwnerMutation, resolveGuardedRecord } from "./record-owner-guard.js";
5
+ import { WINDOW_MS, importEd25519Key, b64ToArrayBuffer, parseTpsEd25519Header } from "./ed25519-auth.js";
6
+ import { isKnownAgentReplay, claimAgentNonce } from "./replay-store.js";
7
+ import { isForbiddenOwnerMutation, ownerMutationRefusal, resolveGuardedRecord } from "./record-owner-guard.js";
9
8
  import { checkHttpRateLimit } from "./rate-limit.js";
9
+ import { stripUndeclaredMemoryAttributes, DECLARED_MEMORY_ATTRIBUTES } from "./memory-declared-attributes.js";
10
+ // --- Non-admin Memory read: ignore the caller's selection --------------------
11
+ //
12
+ // flair#1940 round 17. A non-admin HTTP Memory read returns the authorized,
13
+ // pointer-projected row; a caller `select(...)` or `property` is dropped from the
14
+ // request URL before Harper parses it, while conditions, operator, sort, limit
15
+ // and offset are left exactly as sent. These helpers are the whole of that
16
+ // normalization.
17
+ const DECLARED_MEMORY_ATTRIBUTE_SET = new Set(DECLARED_MEMORY_ATTRIBUTES);
18
+ function isMemoryReadPath(pathname) {
19
+ return pathname === "/Memory" || pathname === "/Memory/" || pathname.startsWith("/Memory/");
20
+ }
21
+ // Drop a caller's `select(...)` and `property` from a Memory read URL, keeping
22
+ // conditions, operator, sort, limit and offset. Returns the input unchanged when
23
+ // the URL carries no selection.
24
+ function stripMemorySelection(rawUrl) {
25
+ const q = rawUrl.indexOf("?");
26
+ let pathPart = q === -1 ? rawUrl : rawUrl.slice(0, q);
27
+ let query = q === -1 ? "" : rawUrl.slice(q + 1);
28
+ // Path form: Harper reads a trailing `.<declared>` on the id as `property`.
29
+ // Harper decides on the DECODED path — RequestTarget decodes the path
30
+ // (`this.id = decodeURIComponent(path)`) and Resource.parsePath then splits at
31
+ // the first dot — so the middleware must decide on the decoded segment too, or
32
+ // it misses a percent-encoded dot: `%2E` (and `%2e`) IS a dot to Harper. Drop
33
+ // that suffix so the id addresses the full row; a suffix that is not a
34
+ // declared Memory attribute stays part of the id, exactly as Harper's own rule
35
+ // leaves it (a content-type extension such as `json` is not a declared
36
+ // attribute, so it is left for Harper to read as a content type).
37
+ const slash = pathPart.lastIndexOf("/");
38
+ const seg = pathPart.slice(slash + 1);
39
+ const decodedSeg = decodePathSegment(seg);
40
+ const dot = decodedSeg.indexOf(".");
41
+ if (dot > -1 && DECLARED_MEMORY_ATTRIBUTE_SET.has(decodedSeg.slice(dot + 1))) {
42
+ // Rebuild the id from its decoded form. Harper decodes the path it is handed,
43
+ // so this re-encoded segment addresses the SAME id, without the property.
44
+ pathPart = `${pathPart.slice(0, slash + 1)}${encodeURIComponent(decodedSeg.slice(0, dot))}`;
45
+ }
46
+ // Query form: drop every `select(...)` token and every `property` parameter.
47
+ for (const [start, end] of selectSpans(query).reverse()) {
48
+ query = query.slice(0, start) + query.slice(end);
49
+ }
50
+ query = query
51
+ .split("&")
52
+ .filter((p) => p !== "" && p !== "property" && !p.startsWith("property="))
53
+ .join("&");
54
+ // A run of separators left by removing `select(...)` tokens carries nothing.
55
+ if (/^[,;]*$/.test(query))
56
+ query = "";
57
+ if (q === -1)
58
+ return pathPart;
59
+ return query === "" ? pathPart : `${pathPart}?${query}`;
60
+ }
61
+ /** Decode a path segment the way Harper does before its property parse; fall
62
+ * back to the raw segment when it is not valid percent-encoding (Harper rejects
63
+ * the malformed request; the middleware must not crash on it). */
64
+ function decodePathSegment(raw) {
65
+ try {
66
+ return decodeURIComponent(raw);
67
+ }
68
+ catch {
69
+ return raw;
70
+ }
71
+ }
72
+ // [start, end) ranges of every `select(...)` call in a query string, accounting
73
+ // for Harper's nested-list form `select((a,b))`.
74
+ function selectSpans(query) {
75
+ const spans = [];
76
+ const marker = "select(";
77
+ let from = 0;
78
+ for (;;) {
79
+ const idx = query.indexOf(marker, from);
80
+ if (idx < 0)
81
+ break;
82
+ const before = idx > 0 ? query[idx - 1] : "";
83
+ if (before && /[A-Za-z0-9_$-]/.test(before)) {
84
+ from = idx + marker.length;
85
+ continue;
86
+ }
87
+ let depth = 1;
88
+ let i = idx + marker.length;
89
+ for (; i < query.length; i++) {
90
+ const ch = query[i];
91
+ if (ch === "(")
92
+ depth++;
93
+ else if (ch === ")") {
94
+ depth--;
95
+ if (depth === 0)
96
+ break;
97
+ }
98
+ }
99
+ if (i >= query.length)
100
+ break;
101
+ spans.push([idx, i + 1]);
102
+ from = i + 1;
103
+ }
104
+ return spans;
105
+ }
10
106
  // --- Admin credentials ---
11
107
  // Admin auth is sourced exclusively from Harper's own environment variables
12
108
  // (HDB_ADMIN_PASSWORD / FLAIR_ADMIN_PASSWORD). No filesystem token file.
@@ -40,11 +136,11 @@ function getAdminPass() {
40
136
  // auth reshape this gate and the per-resource allow* helpers must agree on who's
41
137
  // an admin — one implementation guarantees they can't diverge.
42
138
  // ─── Crypto + replay-guard helpers ────────────────────────────────────────────
43
- // WINDOW_MS, isNonceReplay/recordNonce (the ONE shared nonce store), and
44
- // importEd25519Key all live in ./ed25519-auth.ts — the single
45
- // shared implementation imported by auth-middleware.ts, agent-auth.ts, and
46
- // Presence.ts so a nonce recorded via any one of the three call sites is
47
- // visible to the other two, and the crypto/decoder logic can't drift.
139
+ // WINDOW_MS and importEd25519Key live in ./ed25519-auth.ts, and the replay
140
+ // guard (isKnownAgentReplay / claimAgentNonce) in ./replay-store.ts — shared by
141
+ // auth-middleware.ts, agent-auth.ts and Presence.ts, so a nonce recorded via
142
+ // any one of the three call sites, on any worker thread, is refused by all of
143
+ // them, and the crypto/decoder logic can't drift.
48
144
  async function backfillEmbedding(memoryId) {
49
145
  try {
50
146
  const record = await databases.flair.Memory.get(memoryId);
@@ -57,7 +153,9 @@ async function backfillEmbedding(memoryId) {
57
153
  const embedding = await getEmbedding(record.content, "document");
58
154
  if (!embedding)
59
155
  return;
60
- await patchRecord(databases.flair.Memory, memoryId, { embedding });
156
+ const embedPatch = { embedding };
157
+ stripUndeclaredMemoryAttributes(embedPatch);
158
+ await patchRecord(databases.flair.Memory, memoryId, embedPatch);
61
159
  console.log(`[auto-embed] ${memoryId}: ${embedding.length}d`);
62
160
  }
63
161
  catch (err) {
@@ -65,15 +163,41 @@ async function backfillEmbedding(memoryId) {
65
163
  }
66
164
  }
67
165
  // ─── HTTP middleware ──────────────────────────────────────────────────────────
166
+ // Flair's clients use exactly these HTTP methods. Harper routes other methods
167
+ // to resource handlers as well; refusing them here, before any other branch of
168
+ // the default REST middleware, keeps the tables it serves to the methods their
169
+ // handlers are written and tested for. (Separately mounted routes such as /mcp
170
+ // and OAuth discovery have their own dispatch chains and method handling.)
171
+ const ALLOWED_HTTP_METHODS = new Set([
172
+ "GET", "HEAD", "OPTIONS", "POST", "PUT", "PATCH", "DELETE",
173
+ ]);
68
174
  server.http(async (request, nextLayer) => {
175
+ // ── HTTP method allowlist, FIRST ───────────────────────────────────────────
176
+ // Before the public-path passthrough and before any auth branch, so no path
177
+ // and no caller (anonymous, agent or admin) can reach a handler through any
178
+ // other method.
179
+ // Exact match: HTTP methods are case-sensitive, and these are the spellings
180
+ // Flair's clients send.
181
+ const httpMethod = String(request.method ?? "");
182
+ if (!ALLOWED_HTTP_METHODS.has(httpMethod)) {
183
+ return new Response(JSON.stringify({
184
+ error: "method_not_allowed",
185
+ detail: `Flair accepts ${[...ALLOWED_HTTP_METHODS].join(", ")}.`,
186
+ }), {
187
+ status: 405,
188
+ headers: { "content-type": "application/json", allow: [...ALLOWED_HTTP_METHODS].join(", ") },
189
+ });
190
+ }
69
191
  const url = new URL(request.url, "http://" + (request.headers.get("host") || "localhost"));
70
- // ── Rate limiting, FIRST ───────────────────────────────────────────────────
192
+ // ── Rate limiting, right after the method check ────────────────────────────
71
193
  // Before the public-path passthrough below (the OAuth endpoints all sit on it,
72
194
  // so a hook placed after it would never run for them), and before anything
73
- // reads a credential.
195
+ // reads a credential. A request refused by the method check above never
196
+ // reaches the limiter, and consumes no budget.
74
197
  //
75
198
  // Ordering is a security property, not tidiness. The counter is consumed for
76
- // every request to a throttled endpoint whether or not the credential that
199
+ // every request to a throttled endpoint that passes the method check, whether
200
+ // or not the credential that
77
201
  // came with it was any good — if only failures were counted, "did this consume
78
202
  // budget" would answer "was that credential valid", which is a cleaner
79
203
  // enumeration oracle than the 400 the endpoint already returns. Because the
@@ -317,7 +441,9 @@ server.http(async (request, nextLayer) => {
317
441
  const now = Date.now();
318
442
  if (!Number.isFinite(ts) || Math.abs(now - ts) > WINDOW_MS)
319
443
  return new Response(JSON.stringify({ error: "timestamp_out_of_window" }), { status: 401 });
320
- if (isNonceReplay(agentId, nonce, now))
444
+ // A nonce this thread already saw recorded is refused before any lookup. A
445
+ // miss here proves nothing: claimAgentNonce below is the authoritative check.
446
+ if (isKnownAgentReplay(agentId, nonce, now))
321
447
  return new Response(JSON.stringify({ error: "nonce_replay_detected" }), { status: 401 });
322
448
  const agent = await databases.flair.Agent.get(agentId);
323
449
  if (!agent)
@@ -339,7 +465,12 @@ server.http(async (request, nextLayer) => {
339
465
  catch (e) {
340
466
  return new Response(JSON.stringify({ error: "signature_verification_failed", detail: e?.message }), { status: 401 });
341
467
  }
342
- recordNonce(agentId, nonce, ts);
468
+ // Record the nonce instance-wide now that the signature has verified, and
469
+ // before the request reaches anything else. A replay (401) or an unusable
470
+ // replay store (503, named in the server log) refuses.
471
+ const claim = await claimAgentNonce(agentId, nonce);
472
+ if (!claim.ok)
473
+ return new Response(JSON.stringify({ error: claim.error }), { status: claim.status });
343
474
  request.tpsAgent = agentId;
344
475
  request._tpsAuthVerified = true;
345
476
  request.tpsAgentIsAdmin = await isAdmin(agentId);
@@ -430,9 +561,7 @@ server.http(async (request, nextLayer) => {
430
561
  try {
431
562
  const record = await databases.flair[guarded.table]?.get(guarded.id);
432
563
  if (isForbiddenOwnerMutation(record, guarded.ownerField, agentId)) {
433
- return new Response(JSON.stringify({
434
- error: `forbidden: cannot modify ${guarded.table} owned by another principal`,
435
- }), { status: 403, headers: { "Content-Type": "application/json" } });
564
+ return ownerMutationRefusal(guarded.table);
436
565
  }
437
566
  }
438
567
  catch { /* unreadable row → fall through to the resource's own rules */ }
@@ -598,38 +727,23 @@ server.http(async (request, nextLayer) => {
598
727
  // Instead, the resource-level check (e.g. BootstrapMemories line 58) handles
599
728
  // body-level enforcement since it receives the parsed data from Harper's REST
600
729
  // layer. The middleware's job is identity verification (done above).
601
- // ── Memory GET: non-admin can only read own memories (by ID) ────────────────
602
- if (!request.tpsAgentIsAdmin && method === "GET") {
603
- if (url.pathname.startsWith("/Memory/")) {
604
- try {
605
- const pathParts = url.pathname.split("/").filter(Boolean);
606
- const memId = pathParts[1] ? decodeURIComponent(pathParts[1]) : null;
607
- if (memId) {
608
- const record = await databases.flair.Memory.get(memId);
609
- if (record && record.agentId && record.agentId !== agentId) {
610
- // Centralized read-scope (Layer 1): a grant only covers
611
- // the owner's SHARED memories, never their private ones. This
612
- // used to be a `visibility === "office"` bypass (any authenticated
613
- // agent, no grant needed) — that's gone; the private-exclusion is
614
- // now enforced the same way every other read path enforces it.
615
- //
616
- // Denial is the SAME 404 the resource layer returns (flair#1264):
617
- // Memory.get() deliberately answers NOT_FOUND for a cross-agent
618
- // private id so a denied caller can't distinguish "doesn't exist"
619
- // from "exists but not yours" — a 403 here, worse yet one naming
620
- // the owning agent, confirmed the id exists AND disclosed its
621
- // owner, defeating that anti-enumeration contract one layer up.
622
- // Reuses record-type-kit's NOT_FOUND so the two layers cannot
623
- // drift apart in shape.
624
- const scope = await resolveReadScope(agentId);
625
- if (!scope.isAllowed(record)) {
626
- return NOT_FOUND();
627
- }
628
- }
629
- }
630
- }
631
- catch { /* record not found or table error — let resource handle */ }
632
- }
730
+ // ── Memory read: a non-admin read ignores the caller's selection ─────────────
731
+ // flair#1940 round 17 (design ruling): a non-admin HTTP Memory read does NOT
732
+ // honour a caller `select(...)` or `property`. As soon as authentication has
733
+ // established that the caller is not an admin — and BEFORE anything reads a
734
+ // Memory row or hands the request to the next layer — the request URL is
735
+ // normalized to drop the caller's selection, keeping conditions, operator,
736
+ // sort, limit and offset exactly as sent. Harper builds its REST target from
737
+ // this URL AFTER this middleware, so the original selection cannot be
738
+ // reapplied. An admin read and a trusted internal read are unchanged, while a
739
+ // direct contextual non-admin read now ignores the selection too (the same
740
+ // contract, applied in `Memory.get`/`Memory.search`). The by-id
741
+ // read-scope denial is enforced by the resource layer (memoryByIdReadGate),
742
+ // which returns the same 404 this middleware used to return.
743
+ if (!request.tpsAgentIsAdmin && method === "GET" && isMemoryReadPath(url.pathname)) {
744
+ const stripped = stripMemorySelection(request.url);
745
+ if (stripped !== request.url)
746
+ request.url = stripped;
633
747
  }
634
748
  // ── Embedding backfill ─────────────────────────────────────────────────────
635
749
  const isMemoryWrite = isMutation && (url.pathname === "/Memory" || url.pathname.startsWith("/Memory/"));
@@ -107,10 +107,10 @@ export const DEFAULT_MAX_AUTO_PROMOTE_PER_CYCLE = 200;
107
107
  // describe it otherwise anywhere (comment, changelog, skip reason) — we amended
108
108
  // the 0.55.0 Metal entry for exactly this overclaim shape.
109
109
  //
110
- // The detection is ASCII-ONLY. It recognizes the ASCII backtick and the ASCII
111
- // pairs ( ) [ ] { }. Non-ASCII pairs — full-width ()/[]/{} and CJK lenticular
112
- // 【】/〔〕/〖〗 — are NOT covered, so a truncated claim written in those scripts
113
- // is judged balanced and is NOT refused. Do not assume Unicode coverage.
110
+ // Bracket coverage is the enumerated table in src/rem/promote-policy.ts,
111
+ // including its full-width/CJK pairs; unlisted bracket pairs are not checked.
112
+ // Backticks use parity, not Markdown span matching, so valid escape spans
113
+ // can be refused. This signal does not establish semantic completeness.
114
114
  //
115
115
  // The check counts delimiters WITHOUT interpreting context, so it is deliberately
116
116
  // over-broad: a COMPLETE claim that merely discusses an unmatched delimiter (an