@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.
- package/README.md +19 -20
- package/SECURITY.md +4 -1
- package/dist/build-info.json +3 -3
- package/dist/cli.js +1800 -293
- package/dist/commands/agent.js +22 -15
- package/dist/commands/bridge.js +40 -3
- package/dist/commands/doctor.js +214 -4
- package/dist/commands/federation.js +265 -38
- package/dist/commands/hook.js +10 -2
- package/dist/commands/init.js +179 -48
- package/dist/commands/memory.js +24 -2
- package/dist/commands/quality.js +26 -18
- package/dist/commands/service.js +137 -22
- package/dist/commands/status.js +114 -3
- package/dist/commands/upgrade.js +204 -84
- package/dist/doctor-client.js +50 -4
- package/dist/federation/scheduler.js +253 -4
- package/dist/install/clients.js +89 -23
- package/dist/install/global-bin-path.js +26 -6
- package/dist/lib/atomic-write.js +256 -0
- package/dist/lib/auth-resolve.js +46 -0
- package/dist/lib/daemon-liveness.js +61 -0
- package/dist/lib/doctor-run.js +5 -0
- package/dist/lib/embed-gpu-doctor.js +49 -26
- package/dist/lib/federation-memory-attributes.js +15 -0
- package/dist/lib/init-admin-pass.js +4 -2
- package/dist/lib/init-listener-environ.js +38 -0
- package/dist/lib/init-occupied-listener.js +165 -0
- package/dist/lib/instance-identity-row.js +580 -0
- package/dist/lib/launchd-domain-preflight.js +448 -0
- package/dist/lib/launchd-management.js +176 -6
- package/dist/lib/launchd-repair.js +95 -0
- package/dist/lib/memory-attributes.js +77 -0
- package/dist/lib/node-alias-path.js +95 -0
- package/dist/lib/npm-registry.js +119 -6
- package/dist/lib/owned-pins.js +20 -6
- package/dist/lib/redact-token-id.js +197 -0
- package/dist/lib/service-repoint-apply.js +267 -0
- package/dist/lib/service-repoint.js +575 -0
- package/dist/lib/toml-string-array.js +104 -0
- package/dist/lib/tree-divergence.js +716 -0
- package/dist/lib/upgrade-plain-tree.js +18 -8
- package/dist/lib/upgrade-prior-liveness.js +69 -0
- package/dist/lib/upgrade-rollback.js +116 -0
- package/dist/rem/runner.js +11 -0
- package/dist/resources/Agent.js +27 -14
- package/dist/resources/AgentSeed.js +39 -2
- package/dist/resources/Asset.js +3 -11
- package/dist/resources/Credential.js +4 -10
- package/dist/resources/Federation.js +299 -127
- package/dist/resources/Integration.js +8 -32
- package/dist/resources/Memory.js +623 -86
- package/dist/resources/MemoryArchive.js +9 -0
- package/dist/resources/MemoryBootstrap.js +23 -12
- package/dist/resources/MemoryCandidate.js +3 -11
- package/dist/resources/MemoryDedupStats.js +1 -1
- package/dist/resources/MemoryFeed.js +214 -5
- package/dist/resources/MemoryGrant.js +19 -40
- package/dist/resources/MemoryHostSource.js +90 -0
- package/dist/resources/MemoryMaintenance.js +121 -32
- package/dist/resources/MemoryReflect.js +4 -1
- package/dist/resources/MemoryReindex.js +7 -4
- package/dist/resources/MemoryUsage.js +55 -18
- package/dist/resources/Presence.js +18 -10
- package/dist/resources/RecordUsage.js +30 -40
- package/dist/resources/Relationship.js +170 -89
- package/dist/resources/SemanticSearch.js +44 -19
- package/dist/resources/Soul.js +31 -19
- package/dist/resources/XAA.js +7 -3
- package/dist/resources/agent-auth.js +16 -10
- package/dist/resources/auth-middleware.js +164 -50
- package/dist/resources/auto-promote-lib.js +4 -4
- package/dist/resources/bm25-index-service.js +246 -32
- package/dist/resources/bm25-status.js +132 -0
- package/dist/resources/bm25.js +13 -14
- package/dist/resources/ed25519-auth.js +11 -54
- package/dist/resources/embed-gpu.js +262 -47
- package/dist/resources/embeddings-boot.js +52 -17
- package/dist/resources/federation-classify.js +12 -0
- package/dist/resources/federation-cleanup.js +289 -51
- package/dist/resources/federation-crypto.js +65 -19
- package/dist/resources/health.js +105 -22
- package/dist/resources/host-pointer/registry.js +35 -0
- package/dist/resources/host-pointer-adapter.js +15 -0
- package/dist/resources/host-source-visibility.js +167 -0
- package/dist/resources/host-source.js +151 -0
- package/dist/resources/in-process-api.js +2 -1
- package/dist/resources/instance-create-lock.js +363 -0
- package/dist/resources/instance-identity-rows.js +43 -0
- package/dist/resources/instance-identity.js +97 -12
- package/dist/resources/mcp-handler.js +155 -51
- package/dist/resources/mcp-tool-arguments.js +83 -0
- package/dist/resources/mcp-tools.js +28 -25
- package/dist/resources/memory-consolidate-lib.js +3 -1
- package/dist/resources/memory-declared-attributes.js +103 -0
- package/dist/resources/memory-feed-lib.js +5 -1
- package/dist/resources/memory-host-source.js +163 -0
- package/dist/resources/memory-visibility.js +10 -7
- package/dist/resources/migrations/synthetic-test-migration.js +4 -1
- package/dist/resources/migrations/visibility-backfill.js +4 -1
- package/dist/resources/originator-instance.js +235 -0
- package/dist/resources/promotion-stamp.js +2 -0
- package/dist/resources/provenance.js +111 -11
- package/dist/resources/rate-limit.js +6 -4
- package/dist/resources/record-owner-guard.js +19 -0
- package/dist/resources/record-type-kit.js +44 -23
- package/dist/resources/record-types.js +6 -6
- package/dist/resources/relay-ops.js +28 -3
- package/dist/resources/replay-store.js +289 -0
- package/dist/resources/request-transaction.js +78 -0
- package/dist/resources/search-readiness.js +26 -22
- package/dist/resources/semantic-retrieval-core.js +103 -4
- package/dist/resources/table-helpers.js +33 -0
- package/dist/resources/table-patch-policy.js +109 -0
- package/dist/resources/table-patches.js +17 -0
- package/dist/resources/table-post-policy.js +138 -0
- package/dist/resources/table-posts.js +22 -0
- package/dist/resources/table-subscription-policy.js +135 -0
- package/dist/resources/table-subscriptions.js +19 -0
- package/dist/resources/tool-descriptors/index.js +15 -15
- package/dist/resources/trust-block.js +10 -3
- package/dist/resources/usage-recording.js +169 -41
- package/dist/src/lib/instance-identity-row.js +580 -0
- package/dist/src/lib/memory-attributes.js +77 -0
- package/dist/src/lib/redact-token-id.js +197 -0
- package/docs/api-reference.md +80 -16
- package/docs/auth.md +5 -5
- package/docs/claude-code.md +137 -6
- package/docs/deploying-on-fabric.md +6 -3
- package/docs/deployment.md +1 -1
- package/docs/embedding-in-a-harper-app.md +3 -3
- package/docs/federation.md +17 -10
- package/docs/hosted-on-fabric.md +4 -3
- package/docs/integrations.md +28 -19
- package/docs/mcp-clients.md +26 -32
- package/docs/n8n.md +8 -8
- package/docs/notes/mcp-oauth-model2.md +27 -18
- package/docs/openclaw.md +29 -28
- package/docs/quickstart.md +5 -0
- package/docs/releasing.md +134 -2
- package/docs/spoke-bringup.md +14 -11
- package/docs/standalone-local.md +2 -2
- package/docs/supply-chain-policy.md +28 -10
- package/docs/system-requirements.md +1 -1
- package/docs/troubleshooting.md +11 -0
- package/docs/upgrade.md +189 -63
- package/package.json +9 -5
- package/schemas/agent.graphql +9 -6
- package/schemas/federation.graphql +2 -11
- package/schemas/memory.graphql +106 -17
- package/schemas/replay.graphql +18 -0
- package/templates/launchd/start-flair-with-admin-pass.sh +22 -0
- 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,
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
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
|
|
44
|
-
//
|
|
45
|
-
//
|
|
46
|
-
//
|
|
47
|
-
//
|
|
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
|
-
|
|
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,
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
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
|
-
//
|
|
111
|
-
//
|
|
112
|
-
//
|
|
113
|
-
//
|
|
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
|