@tpsdev-ai/flair 0.58.0 → 0.62.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 +7 -6
- package/SECURITY.md +36 -0
- package/config.yaml +15 -1
- package/dist/bridges/builtins/mem0.js +63 -28
- package/dist/bridges/runtime/import-runner.js +12 -0
- package/dist/bridges/runtime/load-plugin.js +42 -13
- package/dist/bridges/runtime/yaml-loader.js +4 -2
- package/dist/build-info.json +3 -3
- package/dist/cli.js +1030 -343
- package/dist/commands/agent.js +384 -45
- package/dist/commands/attention.js +4 -3
- package/dist/commands/backup.js +202 -34
- package/dist/commands/bridge.js +172 -119
- package/dist/commands/deploy.js +37 -4
- package/dist/commands/doctor.js +601 -163
- package/dist/commands/export.js +54 -19
- package/dist/commands/federation.js +141 -21
- package/dist/commands/hook.js +155 -2
- package/dist/commands/idp.js +14 -1
- package/dist/commands/import.js +7 -3
- package/dist/commands/init.js +462 -193
- package/dist/commands/integrity.js +388 -0
- package/dist/commands/keys.js +247 -58
- package/dist/commands/mcp.js +146 -53
- package/dist/commands/memory.js +171 -21
- package/dist/commands/migrate-harness-memory.js +3 -2
- package/dist/commands/orgevent.js +46 -37
- package/dist/commands/presence.js +4 -3
- package/dist/commands/principal.js +426 -48
- package/dist/commands/quality.js +10 -1
- package/dist/commands/reembed.js +141 -17
- package/dist/commands/relationship.js +2 -1
- package/dist/commands/rem.js +56 -18
- package/dist/commands/restore.js +101 -61
- package/dist/commands/search.js +6 -4
- package/dist/commands/service.js +151 -38
- package/dist/commands/soul.js +4 -3
- package/dist/commands/status.js +43 -5
- package/dist/commands/test.js +3 -2
- package/dist/commands/upgrade.js +24 -1
- package/dist/commands/workspace.js +6 -3
- package/dist/component-env.js +31 -41
- package/dist/deploy.js +77 -1
- package/dist/doctor-client.js +529 -92
- package/dist/engine-version-contract.js +1 -0
- package/dist/engine-version.js +23 -3
- package/dist/federation-verify.js +4 -3
- package/dist/hook-install.js +670 -6
- package/dist/keystore.js +72 -0
- package/dist/lib/action-recall-runtime.js +328 -0
- package/dist/lib/agent-home-fields.js +132 -0
- package/dist/lib/agent-home.js +427 -0
- package/dist/lib/agent-id-rule.js +46 -0
- package/dist/lib/agent-roster.js +33 -0
- package/dist/lib/auth-resolve.js +49 -16
- package/dist/lib/capture-runtime.js +124 -0
- package/dist/lib/credential-status-rule.js +78 -0
- package/dist/lib/daemon-liveness.js +81 -8
- package/dist/lib/doctor-run.js +140 -35
- package/dist/lib/durability-copy.js +10 -0
- package/dist/lib/embedding-space-doctor.js +75 -0
- package/dist/lib/flair-agent-role.js +120 -0
- package/dist/lib/hub-url.js +12 -0
- package/dist/lib/init-admin-pass.js +88 -12
- package/dist/lib/init-listener-environ.js +1 -2
- package/dist/lib/init-occupied-listener.js +15 -111
- package/dist/lib/init-spawn-attribution.js +73 -0
- package/dist/lib/init-tcp-probe.js +33 -0
- package/dist/lib/instance-identity-row.js +20 -0
- package/dist/lib/launchd-management.js +27 -2
- package/dist/lib/listener-table.js +268 -0
- package/dist/lib/local-delete-instance.js +27 -0
- package/dist/lib/local-instance-pair.js +256 -0
- package/dist/lib/mcp-enable.js +1775 -338
- package/dist/lib/mcp-oauth-env-core.js +133 -0
- package/dist/lib/mcp-oauth-env.js +125 -0
- package/dist/lib/mcp-spec.js +17 -1
- package/dist/lib/memory-attributes.js +2 -0
- package/dist/lib/memory-id-policy.js +46 -0
- package/dist/lib/memory-integrity.js +309 -0
- package/dist/lib/memory-purge-response.js +20 -0
- package/dist/lib/ops-table-count.js +25 -0
- package/dist/lib/owned-pins.js +67 -10
- package/dist/lib/peer-status.js +27 -0
- package/dist/lib/principal-status.js +29 -0
- package/dist/lib/process-start-time.js +103 -7
- package/dist/lib/proto-safe-record.js +42 -0
- package/dist/lib/record-id-path.js +25 -0
- package/dist/lib/reembed-server-support.js +66 -0
- package/dist/lib/restore-verify.js +104 -0
- package/dist/lib/scheduler-platform.js +10 -6
- package/dist/lib/secret-keys.js +25 -0
- package/dist/lib/secrets-push.js +50 -22
- package/dist/lib/skill-seed-pending.js +24 -0
- package/dist/lib/skill-seed.js +365 -0
- package/dist/lib/stop-start-recovery.js +54 -0
- package/dist/lib/using-flair-skill.js +87 -0
- package/dist/mcp-client-assertion.js +112 -4
- package/dist/memory-id-checkpoint.js +326 -0
- package/dist/memory-node-compare.js +207 -0
- package/dist/packages/flair-mcp/src/secret-redaction.js +113 -0
- package/dist/rem/restore.js +6 -5
- package/dist/rem/runner.js +103 -44
- package/dist/resources/Agent.js +348 -8
- package/dist/resources/AgentKeyRegister.js +214 -0
- package/dist/resources/AgentKeyRegistration.js +28 -0
- package/dist/resources/AgentSeed.js +19 -4
- package/dist/resources/AutoPromoteCandidates.js +7 -1
- package/dist/resources/Credential.js +177 -2
- package/dist/resources/Federation.js +752 -132
- package/dist/resources/FederationRetry.js +140 -0
- package/dist/resources/InstructionVersion.js +220 -0
- package/dist/resources/Integration.js +300 -25
- package/dist/resources/Memory.js +2113 -604
- package/dist/resources/MemoryArchive.js +75 -42
- package/dist/resources/MemoryBootstrap.js +227 -64
- package/dist/resources/MemoryCandidate.js +21 -1
- package/dist/resources/MemoryDedupStats.js +30 -1
- package/dist/resources/MemoryFeed.js +327 -45
- package/dist/resources/MemoryGrant.js +21 -1
- package/dist/resources/MemoryMaintenance.js +129 -25
- package/dist/resources/MemoryPurge.js +232 -0
- package/dist/resources/MemoryReflect.js +7 -2
- package/dist/resources/MemoryReindex.js +24 -8
- package/dist/resources/Message.js +5 -3
- package/dist/resources/OAuth.js +186 -9
- package/dist/resources/OrgEvent.js +126 -3
- package/dist/resources/OrgSkillAssignment.js +209 -0
- package/dist/resources/Presence.js +144 -49
- package/dist/resources/PromoteMemoryCandidate.js +18 -7
- package/dist/resources/Relationship.js +23 -0
- package/dist/resources/SemanticSearch.js +63 -32
- package/dist/resources/Soul.js +189 -76
- package/dist/resources/TeamDirectory.js +35 -0
- package/dist/resources/WorkspaceState.js +21 -1
- package/dist/resources/XAA.js +212 -65
- package/dist/resources/agent-auth.js +40 -15
- package/dist/resources/agent-status-guard.js +63 -0
- package/dist/resources/auth-middleware.js +402 -162
- package/dist/resources/ed25519-auth.js +1 -1
- package/dist/resources/embedding-space-guard.js +366 -72
- package/dist/resources/engine-version-stamp-boot.js +53 -0
- package/dist/resources/federation-classify.js +94 -0
- package/dist/resources/federation-crypto.js +5 -5
- package/dist/resources/federation-retry-lib.js +135 -0
- package/dist/resources/flair-agent-role-boot.js +26 -0
- package/dist/resources/grant-visibility.js +135 -0
- package/dist/resources/harper-routing.js +83 -0
- package/dist/resources/health.js +130 -20
- package/dist/resources/host-source-citation.js +49 -0
- package/dist/resources/host-source-visibility.js +7 -6
- package/dist/resources/instance-create-lock.js +17 -0
- package/dist/resources/instance-identity.js +23 -0
- package/dist/resources/instruction-version-record.js +343 -0
- package/dist/resources/key-lock.js +31 -0
- package/dist/resources/mcp-handler.js +36 -8
- package/dist/resources/mcp-oauth-env-guard.js +36 -0
- package/dist/resources/mcp-oauth.js +26 -12
- package/dist/resources/mcp-tool-arguments.js +4 -6
- package/dist/resources/mcp-tools.js +150 -23
- package/dist/resources/memory-bootstrap-lib.js +5 -15
- package/dist/resources/memory-declared-attributes.js +3 -1
- package/dist/resources/memory-deletion-history.js +55 -0
- package/dist/resources/memory-durability.js +54 -0
- package/dist/resources/memory-embed-hash.js +88 -0
- package/dist/resources/memory-embedding-value.js +8 -0
- package/dist/resources/memory-host-source.js +27 -5
- package/dist/resources/memory-id-guard.js +75 -0
- package/dist/resources/memory-redaction.js +236 -0
- package/dist/resources/memory-supplied-vector.js +72 -0
- package/dist/resources/memory-write-lock.js +310 -0
- package/dist/resources/memory-write-response.js +139 -0
- package/dist/resources/migrations/data-dir.js +74 -16
- package/dist/resources/migrations/dir-safety.js +1 -1
- package/dist/resources/migrations/embedding-stamp.js +193 -79
- package/dist/resources/migrations/export.js +1 -0
- package/dist/resources/migrations/graph-heal.js +18 -25
- package/dist/resources/migrations/lock.js +7 -1
- package/dist/resources/migrations/snapshot.js +1 -0
- package/dist/resources/migrations/source-fields.js +5 -5
- package/dist/resources/migrations/synthetic-test-migration.js +14 -11
- package/dist/resources/migrations/visibility-backfill.js +29 -29
- package/dist/resources/multi-worker-guard.js +121 -0
- package/dist/resources/oauth-discovery.js +1 -0
- package/dist/resources/oauth-wellknown.js +8 -4
- package/dist/resources/object-body-guard.js +33 -0
- package/dist/resources/org-event-created-at.js +133 -0
- package/dist/resources/originator-instance.js +39 -7
- package/dist/resources/owner-delete-recheck.js +78 -0
- package/dist/resources/owner-field-guard.js +39 -5
- package/dist/resources/owner-scoped-write-policy.js +212 -0
- package/dist/resources/owner-scoped-writes.js +58 -0
- package/dist/resources/presence-receipt.js +236 -0
- package/dist/resources/promotion-stamp.js +47 -12
- package/dist/resources/record-owner-guard.js +74 -26
- package/dist/resources/record-types.js +17 -1
- package/dist/resources/relay-ops.js +78 -6
- package/dist/resources/replay-store.js +145 -21
- package/dist/resources/request-target.js +136 -0
- package/dist/resources/request-transaction.js +35 -0
- package/dist/resources/search-readiness.js +4 -1
- package/dist/resources/seed-ids.js +9 -0
- package/dist/resources/seed-reservation.js +117 -0
- package/dist/resources/semantic-retrieval-core.js +20 -9
- package/dist/resources/skill-manifest.js +190 -0
- package/dist/resources/skill-provenance.js +15 -10
- package/dist/resources/skill-subject.js +53 -0
- package/dist/resources/skill-version-write.js +432 -0
- package/dist/resources/skill-write-fault.js +17 -0
- package/dist/resources/skill-write-policy.js +67 -0
- package/dist/resources/skill-write.js +67 -7
- package/dist/resources/table-helpers.js +10 -7
- package/dist/resources/team-directory.js +248 -0
- package/dist/resources/tool-descriptors/index.js +69 -8
- package/dist/resources/txn-pause-point.js +118 -0
- package/dist/resources/usage-recording.js +171 -63
- package/dist/resources/write-back.js +218 -0
- package/dist/src/engine-version-contract.js +1 -0
- package/dist/src/keystore.js +72 -0
- package/dist/src/lib/agent-home-fields.js +132 -0
- package/dist/src/lib/agent-id-rule.js +46 -0
- package/dist/src/lib/agent-key-register.js +80 -0
- package/dist/src/lib/atomic-write.js +256 -0
- package/dist/src/lib/credential-status-rule.js +78 -0
- package/dist/src/lib/expired-by-agent.js +37 -0
- package/dist/src/lib/flair-agent-role.js +120 -0
- package/dist/src/lib/idp-mapping-rule.js +81 -0
- package/dist/src/lib/instance-identity-row.js +20 -0
- package/dist/src/lib/mcp-oauth-env-core.js +133 -0
- package/dist/src/lib/memory-attributes.js +2 -0
- package/dist/src/lib/memory-id-policy.js +46 -0
- package/dist/src/lib/principal-status.js +29 -0
- package/dist/src/lib/proto-safe-record.js +42 -0
- package/dist/src/lib/reembed-server-support.js +66 -0
- package/dist/src/lib/scheduler-platform.js +10 -6
- package/dist/src/lib/systemd-agent-id.js +38 -0
- package/docs/access-control.md +768 -0
- package/docs/api-reference.md +52 -13
- package/docs/auth.md +10 -12
- package/docs/bridges.md +11 -0
- package/docs/claude-code.md +34 -4
- package/docs/deepseek-harness.md +1 -1
- package/docs/deploying-on-fabric.md +70 -0
- package/docs/deployment.md +2 -0
- package/docs/embedding-in-a-harper-app.md +1 -1
- package/docs/federation.md +33 -2
- package/docs/hosted-on-fabric.md +43 -36
- package/docs/integrations.md +6 -6
- package/docs/mcp-clients.md +10 -5
- package/docs/n8n.md +17 -11
- package/docs/notes/mcp-agent-auth-consumer.md +12 -4
- package/docs/notes/mcp-oauth-model2.md +34 -5
- package/docs/quickstart-fabric.md +2 -2
- package/docs/quickstart.md +9 -1
- package/docs/releasing.md +34 -28
- package/docs/rem.md +8 -0
- package/docs/secrets-and-keys.md +19 -2
- package/docs/standalone-local.md +1 -0
- package/docs/supply-chain-policy.md +13 -3
- package/docs/upgrade.md +32 -6
- package/package.json +12 -6
- package/schemas/agent-key-registration.graphql +22 -0
- package/schemas/agent.graphql +3 -0
- package/schemas/federation.graphql +38 -1
- package/schemas/memory.graphql +115 -5
- package/schemas/oauth.graphql +27 -4
- package/schemas/schema.graphql +2 -0
- package/templates/launchd/start-flair-with-admin-pass.sh +89 -16
|
@@ -94,8 +94,13 @@ export function isPointerEchoOf(input, storedPointer, writerAuthorId) {
|
|
|
94
94
|
/**
|
|
95
95
|
* Read the pointer rows for a WHOLE result set in ONE batched query (A1'
|
|
96
96
|
* item 4). Empty input issues no query. Returns memoryId -> row.
|
|
97
|
+
*
|
|
98
|
+
* `context` is optional: the reader join omits it. A caller that must observe
|
|
99
|
+
* a delete committed earlier in the SAME request passes its own transaction
|
|
100
|
+
* context, because a contextless read joins the request's ambient transaction
|
|
101
|
+
* and reads that transaction's pinned read snapshot (see storedPointerIds).
|
|
97
102
|
*/
|
|
98
|
-
export async function loadPointerRows(ids) {
|
|
103
|
+
export async function loadPointerRows(ids, context) {
|
|
99
104
|
const wanted = [...new Set(ids.filter((id) => typeof id === "string" && id.length > 0))];
|
|
100
105
|
const map = new Map();
|
|
101
106
|
if (wanted.length === 0)
|
|
@@ -108,18 +113,35 @@ export async function loadPointerRows(ids) {
|
|
|
108
113
|
const query = wanted.length === 1
|
|
109
114
|
? { conditions: [{ attribute: "memoryId", comparator: "equals", value: wanted[0] }] }
|
|
110
115
|
: { operator: "or", conditions: wanted.map((id) => ({ attribute: "memoryId", comparator: "equals", value: id })) };
|
|
111
|
-
const result = table.search(query);
|
|
116
|
+
const result = table.search(query, context);
|
|
112
117
|
for await (const row of result) {
|
|
113
118
|
if (row && typeof row.memoryId === "string")
|
|
114
119
|
map.set(row.memoryId, row);
|
|
115
120
|
}
|
|
116
121
|
return map;
|
|
117
122
|
}
|
|
123
|
+
/**
|
|
124
|
+
* The ids among `ids` that still have a stored pointer row: the check POST
|
|
125
|
+
* /MemoryPurge runs after its pointer deletes commit. Unlike loadPointerRows
|
|
126
|
+
* (the reader join, which reads a missing table as "no pointers"), it throws
|
|
127
|
+
* when the table cannot be searched, so a failed check never reads as "no
|
|
128
|
+
* pointer row left".
|
|
129
|
+
*
|
|
130
|
+
* The caller passes a transaction context it owns. A contextless read resolves
|
|
131
|
+
* the request's ambient operation transaction and reads that transaction's
|
|
132
|
+
* read snapshot, which was pinned before the purge's pointer delete committed,
|
|
133
|
+
* so it would report a deleted pointer row as still present.
|
|
134
|
+
*/
|
|
135
|
+
export async function storedPointerIds(ids, context) {
|
|
136
|
+
if (typeof pointerTable()?.search !== "function") {
|
|
137
|
+
throw new Error(`${MEMORY_HOST_SOURCE_TABLE} table unavailable`);
|
|
138
|
+
}
|
|
139
|
+
return new Set((await loadPointerRows(ids, context)).keys());
|
|
140
|
+
}
|
|
118
141
|
/**
|
|
119
142
|
* flair#1940 A1-iv item 2 — the ONE reader helper. `Memory.get()`,
|
|
120
|
-
* `Memory.search()
|
|
121
|
-
* helper.
|
|
122
|
-
* in this slice. It fetches the pointer rows for the WHOLE result set in ONE
|
|
143
|
+
* `Memory.search()`, `SemanticSearch` and bootstrap render pointers through the
|
|
144
|
+
* pointer helper. It fetches the pointer rows for the WHOLE result set in ONE
|
|
123
145
|
* batched query and applies the join, so no reader can forget the join and no
|
|
124
146
|
* module needs to touch the MemoryHostSource table itself. `readerAgentId` is
|
|
125
147
|
* the non-admin reader; an admin/operator read is the named exception (see
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* memory-id-guard.ts — the resource-layer refusal for a Memory id that ends in
|
|
3
|
+
* the `.content` property suffix (flair#2199).
|
|
4
|
+
*
|
|
5
|
+
*/
|
|
6
|
+
import { MEMORY_CONTENT_SELECTOR_SUFFIX, endsWithContentSelectorSuffix, decodeMemoryIdSegment } from "../src/lib/memory-id-policy.js";
|
|
7
|
+
import { DECLARED_MEMORY_ATTRIBUTES } from "./memory-declared-attributes.js";
|
|
8
|
+
const DECLARED = new Set(DECLARED_MEMORY_ATTRIBUTES);
|
|
9
|
+
/** The named error for a Memory write naming an id that ends in `.content`. */
|
|
10
|
+
export const CONTENT_SUFFIX_ID_ERROR = "memory_id_content_suffix";
|
|
11
|
+
/** The named 400 for one offending id. */
|
|
12
|
+
export function contentSuffixIdDenial(id) {
|
|
13
|
+
return new Response(JSON.stringify({
|
|
14
|
+
error: CONTENT_SUFFIX_ID_ERROR,
|
|
15
|
+
message: `Memory ids must not end in "${MEMORY_CONTENT_SELECTOR_SUFFIX}".`,
|
|
16
|
+
}), { status: 400, headers: { "content-type": "application/json" } });
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Refuse a write when any of its named ids (the URL-bound id and/or a body id)
|
|
20
|
+
* ends in the `.content` suffix.
|
|
21
|
+
*/
|
|
22
|
+
export function refuseContentSuffixId(ids, target) {
|
|
23
|
+
const rawId = typeof target?.pathname === "string"
|
|
24
|
+
? decodeMemoryIdSegment(target.pathname.split("/").at(-1) ?? "")
|
|
25
|
+
: undefined;
|
|
26
|
+
const bad = [...ids, rawId].find((id) => endsWithContentSelectorSuffix(id));
|
|
27
|
+
return bad === undefined ? null : contentSuffixIdDenial(String(bad));
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The record id a Memory reference resolves to, the way Harper resolves a
|
|
31
|
+
* by-id path: decode it, then drop a trailing `.<declared attribute>` selector
|
|
32
|
+
* (Harper splits at the FIRST dot and treats the remainder as a property ONLY
|
|
33
|
+
* when it names a declared attribute). A reference that carries no such
|
|
34
|
+
* selector resolves to its decoded form; a non-string resolves to undefined.
|
|
35
|
+
* Memory.ts resolves a `supersedes` reference with this once, before anything
|
|
36
|
+
* reads it, and uses the result for the reserved-id check, the authorization
|
|
37
|
+
* read (non-admin agents only), the stored reference and the close
|
|
38
|
+
* (flair#2307).
|
|
39
|
+
*/
|
|
40
|
+
export function resolveMemoryReferenceId(ref) {
|
|
41
|
+
if (typeof ref !== "string")
|
|
42
|
+
return undefined;
|
|
43
|
+
const decoded = decodeMemoryIdSegment(ref);
|
|
44
|
+
const dot = decoded.indexOf(".");
|
|
45
|
+
if (dot > -1 && DECLARED.has(decoded.slice(dot + 1)))
|
|
46
|
+
return decoded.slice(0, dot);
|
|
47
|
+
return decoded;
|
|
48
|
+
}
|
|
49
|
+
/** The named error for a `supersedes` target whose read failed (flair#2307). */
|
|
50
|
+
export const SUPERSEDES_TARGET_UNREADABLE_ERROR = "supersedes_target_unreadable";
|
|
51
|
+
/** The named error for a `supersedes` target that does not exist (flair#2307). */
|
|
52
|
+
export const SUPERSEDES_TARGET_MISSING_ERROR = "supersedes_target_missing";
|
|
53
|
+
/**
|
|
54
|
+
* Refuse a write whose `supersedes` target could not be read: the predecessor
|
|
55
|
+
* read every write with a `supersedes` makes (prepareSkillBody in
|
|
56
|
+
* resources/skill-version-write.ts), or, for a non-admin agent, the
|
|
57
|
+
* authorization read. A client error from the read (an id Harper cannot look
|
|
58
|
+
* up) answers 400; anything else 503, since a retry can succeed. Nothing has
|
|
59
|
+
* been written when this is returned.
|
|
60
|
+
*/
|
|
61
|
+
export function supersedesTargetUnreadable(err) {
|
|
62
|
+
const code = err?.statusCode;
|
|
63
|
+
const status = typeof code === "number" && code >= 400 && code < 500 ? 400 : 503;
|
|
64
|
+
return new Response(JSON.stringify({
|
|
65
|
+
error: SUPERSEDES_TARGET_UNREADABLE_ERROR,
|
|
66
|
+
message: "the record named by `supersedes` could not be read; nothing was written",
|
|
67
|
+
}), { status, headers: { "content-type": "application/json" } });
|
|
68
|
+
}
|
|
69
|
+
/** Refuse a write whose `supersedes` names a record that does not exist. */
|
|
70
|
+
export function supersedesTargetMissing() {
|
|
71
|
+
return new Response(JSON.stringify({
|
|
72
|
+
error: SUPERSEDES_TARGET_MISSING_ERROR,
|
|
73
|
+
message: "the record named by `supersedes` does not exist; nothing was written",
|
|
74
|
+
}), { status: 409, headers: { "content-type": "application/json" } });
|
|
75
|
+
}
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* memory-redaction.ts — server-side credential redaction for explicit Memory
|
|
3
|
+
* writes (flair#2407).
|
|
4
|
+
*
|
|
5
|
+
* ONE redactor. The automatic-capture path and the action-recall cache call
|
|
6
|
+
* `redactSecrets` (packages/flair-mcp/src/secret-redaction.ts), which delegates
|
|
7
|
+
* to `redactSecretsWithCount`; this module calls `redactSecretsWithCount`
|
|
8
|
+
* directly, so the server keeps no second pattern list.
|
|
9
|
+
*
|
|
10
|
+
* Memory text fields are redacted on write. Skill writes refuse metadata with
|
|
11
|
+
* duplicate top-level keys; otherwise name/description and string tags are
|
|
12
|
+
* redacted (flair#2575).
|
|
13
|
+
*
|
|
14
|
+
* Memory post/put/patch and the feed ingest (resources/MemoryFeed.ts) call
|
|
15
|
+
* redactMemoryWrite() on the write body before the row is persisted; post and
|
|
16
|
+
* put call it before the dedup gate and the stored embedding are computed.
|
|
17
|
+
* post, put and the feed ingest call redactSkillWrite() on the EFFECTIVE row
|
|
18
|
+
* after skill-tag inheritance (prepareSkillBody) and before persistence, so an
|
|
19
|
+
* omitted-tag PUT on a stored skill, a superseding POST and a feed ingest
|
|
20
|
+
* redact the skill fields of the row they write.
|
|
21
|
+
* When the count is above zero, a Memory post/put/patch response also carries
|
|
22
|
+
* `stored`: the stored (post-redaction) values of the fields that write's
|
|
23
|
+
* request supplied (flair#2561) — the REDACTED_MEMORY_FIELDS it supplied as
|
|
24
|
+
* strings (suppliedMemoryTextFields) and, for a skill-tagged row, the skill
|
|
25
|
+
* fields it supplied (suppliedSkillTextFields, flair#2575). The supplied
|
|
26
|
+
* fields are read from the body as the request sent it, before a stored row or
|
|
27
|
+
* a skill predecessor is merged into it (suppliedStoredTextFields,
|
|
28
|
+
* storedMemoryText). The feed ingest's response holds, of the row it stored or
|
|
29
|
+
* matched, only named primitive fields, plus `redactedValues` when present
|
|
30
|
+
* (resources/memory-write-response.ts).
|
|
31
|
+
* A skill PUT whose redaction replaced a value always writes its redacted
|
|
32
|
+
* effective row, so each field `stored` reports is what the row holds: the
|
|
33
|
+
* in-place (reserved seed) PUT's unchanged-row check never skips it.
|
|
34
|
+
* put() skips the call for the shipped-skill seed write (isOperatorSeedPut): a
|
|
35
|
+
* PUT of the reserved seed skill id by a verified Basic administrator
|
|
36
|
+
* (src/lib/skill-seed.ts). The seed compares the stored text to its source
|
|
37
|
+
* text, so it must round-trip unchanged. The call does not otherwise depend on
|
|
38
|
+
* the caller: an admin Ed25519 key or an OAuth principal is an agent
|
|
39
|
+
* (resources/skill-write-policy.ts) and is redacted. put()'s `_reindex` re-PUT
|
|
40
|
+
* returns before the call; it refuses a change to these fields.
|
|
41
|
+
*
|
|
42
|
+
* The FederationSync receive path does not call this module: the redactor
|
|
43
|
+
* leaves incoming federated content alone. Federation checks a record's
|
|
44
|
+
* signature, when it carries one, on the incoming record before it adds
|
|
45
|
+
* receiver bookkeeping to the row.
|
|
46
|
+
*/
|
|
47
|
+
import { redactSecretsWithCount } from "../packages/flair-mcp/src/secret-redaction.js";
|
|
48
|
+
import { isReservedSeedId } from "./seed-reservation.js";
|
|
49
|
+
import { isSkillWrite, MEMORY_EMBEDDING_INPUT_FIELDS } from "./skill-write.js";
|
|
50
|
+
import { parseSkillMetadata } from "./skill-provenance.js";
|
|
51
|
+
import { skillWriteSource } from "./skill-write-policy.js";
|
|
52
|
+
/** The Memory text fields redacted on a write. */
|
|
53
|
+
export const REDACTED_MEMORY_FIELDS = Object.freeze(["content", "summary", "trigger"]);
|
|
54
|
+
/** Metadata fields selected after duplicate-key validation. */
|
|
55
|
+
export const REDACTED_SKILL_FIELDS = Object.freeze(["name", "description"]);
|
|
56
|
+
/**
|
|
57
|
+
* flair#2561: the string-valued text fields a write request supplies: each of
|
|
58
|
+
* the REDACTED_MEMORY_FIELDS that holds a string in the request body. A field
|
|
59
|
+
* the body sends as null or as a non-string is not in the list. A write reads
|
|
60
|
+
* them from the body as the request sent it, before a stored row or a skill
|
|
61
|
+
* predecessor is merged into that body, so the list names only text fields the
|
|
62
|
+
* request itself carried.
|
|
63
|
+
*/
|
|
64
|
+
export function suppliedMemoryTextFields(body) {
|
|
65
|
+
if (!body || typeof body !== "object" || Array.isArray(body))
|
|
66
|
+
return [];
|
|
67
|
+
return REDACTED_MEMORY_FIELDS.filter((field) => typeof body[field] === "string");
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* flair#2561, flair#2575: the skill fields a write request supplies: `name` and
|
|
71
|
+
* `description` when the body's own `metadata` holds a string under that key,
|
|
72
|
+
* and `tags` when the body carries a `tags` array. Read, like
|
|
73
|
+
* suppliedMemoryTextFields, from the body as the request sent it, before a
|
|
74
|
+
* stored row or a skill predecessor is merged into it, so a field the row
|
|
75
|
+
* inherits (an omitted `tags` array, or a predecessor's `metadata`) is not in
|
|
76
|
+
* the list.
|
|
77
|
+
*/
|
|
78
|
+
export function suppliedSkillTextFields(body) {
|
|
79
|
+
if (!body || typeof body !== "object" || Array.isArray(body))
|
|
80
|
+
return [];
|
|
81
|
+
const record = body;
|
|
82
|
+
const meta = parseSkillMetadata(record.metadata);
|
|
83
|
+
const supplied = REDACTED_SKILL_FIELDS.filter((field) => typeof meta[field] === "string");
|
|
84
|
+
if (Array.isArray(record.tags))
|
|
85
|
+
supplied.push("tags");
|
|
86
|
+
return supplied;
|
|
87
|
+
}
|
|
88
|
+
/** The fields a Memory POST or PUT request supplies that its `stored` can
|
|
89
|
+
* report: suppliedMemoryTextFields plus suppliedSkillTextFields. */
|
|
90
|
+
export function suppliedStoredTextFields(body) {
|
|
91
|
+
return [...suppliedMemoryTextFields(body), ...suppliedSkillTextFields(body)];
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* flair#2467, flair#2561, flair#2575: the values on `row` of the `supplied`
|
|
95
|
+
* fields, copied; a supplied field that holds no value on `row` is left out. A
|
|
96
|
+
* write calls it on the row it stages, after redaction, with the fields its own
|
|
97
|
+
* request supplied (suppliedMemoryTextFields, suppliedStoredTextFields), so the
|
|
98
|
+
* copy holds the stored (post-redaction) value of each of those fields, changed
|
|
99
|
+
* or not, and no other field of the row: a field the row holds from a merged
|
|
100
|
+
* stored row or a skill predecessor is not in it. For a skill-tagged row the
|
|
101
|
+
* supplied skill fields are the `metadata` `name`/`description` (parsed out of
|
|
102
|
+
* the row) and the accepted `tags` entries. When the write replaced any value,
|
|
103
|
+
* its response carries the copy as `stored` next to `redactedValues`; the
|
|
104
|
+
* writer never has to read the row back, so a later write cannot change what
|
|
105
|
+
* this one reports.
|
|
106
|
+
*/
|
|
107
|
+
export function storedMemoryText(row, supplied) {
|
|
108
|
+
const stored = {};
|
|
109
|
+
if (!row || typeof row !== "object" || Array.isArray(row))
|
|
110
|
+
return stored;
|
|
111
|
+
const record = row;
|
|
112
|
+
for (const field of REDACTED_MEMORY_FIELDS) {
|
|
113
|
+
if (!supplied.includes(field))
|
|
114
|
+
continue;
|
|
115
|
+
const value = record[field];
|
|
116
|
+
if (typeof value === "string")
|
|
117
|
+
stored[field] = value;
|
|
118
|
+
}
|
|
119
|
+
if (isSkillWrite(record)) {
|
|
120
|
+
const meta = parseSkillMetadata(record.metadata);
|
|
121
|
+
for (const field of REDACTED_SKILL_FIELDS) {
|
|
122
|
+
if (supplied.includes(field) && typeof meta[field] === "string")
|
|
123
|
+
stored[field] = meta[field];
|
|
124
|
+
}
|
|
125
|
+
// Report the entries the schema accepts (`[String]`: a string or null), so
|
|
126
|
+
// `stored.tags` is what the row carries, not only its string entries.
|
|
127
|
+
if (supplied.includes("tags") && Array.isArray(record.tags)) {
|
|
128
|
+
stored.tags = record.tags.filter((tag) => typeof tag === "string" || tag === null);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return stored;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Whether a Memory PUT is the shipped-skill seed write: the caller is a
|
|
135
|
+
* verified Basic administrator (skillWriteSource "operator") and every id the
|
|
136
|
+
* write names (the URL id and any body id) is the reserved seed skill id.
|
|
137
|
+
*/
|
|
138
|
+
export function isOperatorSeedPut(context, auth, ids) {
|
|
139
|
+
const named = ids.filter((id) => id !== undefined && id !== null);
|
|
140
|
+
if (named.length === 0 || !named.every((id) => isReservedSeedId("Memory", id)))
|
|
141
|
+
return false;
|
|
142
|
+
return skillWriteSource(context, auth) === "operator";
|
|
143
|
+
}
|
|
144
|
+
/** The redacted fields an embedding can be computed from, across row kinds:
|
|
145
|
+
* `trigger` for a skill-tagged row with a non-empty trigger, `content` for every
|
|
146
|
+
* other row (MEMORY_EMBEDDING_INPUT_FIELDS, next to embedTextField/skillEmbedText
|
|
147
|
+
* in resources/skill-write.ts). Redaction sees the write body, not the stored
|
|
148
|
+
* row's kind, so it uses the whole set. */
|
|
149
|
+
const EMBEDDING_SOURCE_FIELDS = new Set(MEMORY_EMBEDDING_INPUT_FIELDS);
|
|
150
|
+
/**
|
|
151
|
+
* Redact REDACTED_MEMORY_FIELDS of a write body IN PLACE. When the redaction
|
|
152
|
+
* changes `content` or `trigger`, the fields an embedding is computed from, a
|
|
153
|
+
* caller-supplied `embedding` and `embeddingModel` are removed from the body,
|
|
154
|
+
* so the supplied vector is not stored. For a non-object input it changes
|
|
155
|
+
* nothing and returns `{ count: 0, embeddingDiscarded: false }`.
|
|
156
|
+
*/
|
|
157
|
+
export function redactMemoryWrite(content) {
|
|
158
|
+
const none = { count: 0, embeddingDiscarded: false };
|
|
159
|
+
if (!content || typeof content !== "object" || Array.isArray(content))
|
|
160
|
+
return none;
|
|
161
|
+
const row = content;
|
|
162
|
+
let count = 0;
|
|
163
|
+
let embedSourceChanged = false;
|
|
164
|
+
for (const field of REDACTED_MEMORY_FIELDS) {
|
|
165
|
+
const value = row[field];
|
|
166
|
+
if (typeof value !== "string")
|
|
167
|
+
continue;
|
|
168
|
+
const redacted = redactSecretsWithCount(value);
|
|
169
|
+
if (redacted.text !== value) {
|
|
170
|
+
row[field] = redacted.text;
|
|
171
|
+
count += redacted.count;
|
|
172
|
+
if (EMBEDDING_SOURCE_FIELDS.has(field))
|
|
173
|
+
embedSourceChanged = true;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
if (count === 0)
|
|
177
|
+
return none;
|
|
178
|
+
const supplied = row.embedding != null || row.embeddingModel != null;
|
|
179
|
+
if (!supplied || !embedSourceChanged)
|
|
180
|
+
return { count, embeddingDiscarded: false };
|
|
181
|
+
delete row.embedding;
|
|
182
|
+
delete row.embeddingModel;
|
|
183
|
+
return { count, embeddingDiscarded: true };
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Redact name/description and string tags after prepareSkillBody has refused
|
|
187
|
+
* metadata with duplicate top-level keys and resolved the effective skill tag.
|
|
188
|
+
* Returns the number of values replaced.
|
|
189
|
+
*/
|
|
190
|
+
export function redactSkillWrite(row) {
|
|
191
|
+
if (!row || typeof row !== "object" || Array.isArray(row))
|
|
192
|
+
return 0;
|
|
193
|
+
const record = row;
|
|
194
|
+
return isSkillWrite(record) ? redactSkillFields(record) : 0;
|
|
195
|
+
}
|
|
196
|
+
/** Redact validated skill fields in place. */
|
|
197
|
+
function redactSkillFields(row) {
|
|
198
|
+
let count = 0;
|
|
199
|
+
if (Array.isArray(row.tags)) {
|
|
200
|
+
row.tags = row.tags.map((entry) => {
|
|
201
|
+
if (typeof entry !== "string")
|
|
202
|
+
return entry;
|
|
203
|
+
const redacted = redactSecretsWithCount(entry);
|
|
204
|
+
if (redacted.text === entry)
|
|
205
|
+
return entry;
|
|
206
|
+
count += redacted.count;
|
|
207
|
+
return redacted.text;
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
count += redactSkillMetadata(row);
|
|
211
|
+
return count;
|
|
212
|
+
}
|
|
213
|
+
/** Serialize validated metadata only when name or description changes. */
|
|
214
|
+
function redactSkillMetadata(row) {
|
|
215
|
+
const original = row.metadata;
|
|
216
|
+
const asString = typeof original === "string";
|
|
217
|
+
const asObject = original !== null && typeof original === "object" && !Array.isArray(original);
|
|
218
|
+
if (!asString && !asObject)
|
|
219
|
+
return 0;
|
|
220
|
+
const parsed = parseSkillMetadata(original);
|
|
221
|
+
let count = 0;
|
|
222
|
+
for (const field of REDACTED_SKILL_FIELDS) {
|
|
223
|
+
const value = parsed[field];
|
|
224
|
+
if (typeof value !== "string")
|
|
225
|
+
continue;
|
|
226
|
+
const redacted = redactSecretsWithCount(value);
|
|
227
|
+
if (redacted.text !== value) {
|
|
228
|
+
parsed[field] = redacted.text;
|
|
229
|
+
count += redacted.count;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
if (count === 0)
|
|
233
|
+
return 0;
|
|
234
|
+
row.metadata = asString ? JSON.stringify(parsed) : parsed;
|
|
235
|
+
return count;
|
|
236
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Non-admin Memory writes discard caller-supplied vectors and model stamps.
|
|
3
|
+
* A vector or stamp counts as caller-supplied only when it differs from the
|
|
4
|
+
* stored row's value; one re-sent unchanged is carried and kept as stored.
|
|
5
|
+
* Embedding is computed when the resulting write needs one.
|
|
6
|
+
* Administrator and trusted in-process writes and federation-sync records are unchanged.
|
|
7
|
+
* Empty-vector normalization and the re-embed request protocol are unchanged;
|
|
8
|
+
* an ordinary non-admin write strips a supplied stamp even alongside a null or empty embedding.
|
|
9
|
+
*/
|
|
10
|
+
import { isDeepStrictEqual } from "node:util";
|
|
11
|
+
/** Presence check after empty-embedding normalization, not vector validation. */
|
|
12
|
+
export function hasSuppliedEmbedding(value) {
|
|
13
|
+
return value !== null && value !== undefined;
|
|
14
|
+
}
|
|
15
|
+
/** True when the caller's object body supplies an `embeddingModel` stamp (any
|
|
16
|
+
* value, `null` included). Captured before a stored row is merged in, so a
|
|
17
|
+
* stamp carried from a stored row is never mistaken for one the caller set. */
|
|
18
|
+
export function suppliesEmbeddingModel(content) {
|
|
19
|
+
return !!content && typeof content === "object" && !Array.isArray(content) &&
|
|
20
|
+
Object.prototype.hasOwnProperty.call(content, "embeddingModel");
|
|
21
|
+
}
|
|
22
|
+
function sameVector(a, b) {
|
|
23
|
+
const plain = (v) => (ArrayBuffer.isView(v) ? Array.from(v) : v);
|
|
24
|
+
return isDeepStrictEqual(plain(a), plain(b));
|
|
25
|
+
}
|
|
26
|
+
/** What the caller's own body supplies: a non-null `embedding` and/or an
|
|
27
|
+
* `embeddingModel` that DIFFERS from the stored row's. With no stored row
|
|
28
|
+
* (a create) everything present is supplied. Captured before a stored row is
|
|
29
|
+
* merged into the body. */
|
|
30
|
+
export function suppliedVectorFlags(content, stored) {
|
|
31
|
+
const body = content && typeof content === "object" && !Array.isArray(content) ? content : null;
|
|
32
|
+
const vector = hasSuppliedEmbedding(body?.embedding) && !(stored && sameVector(body.embedding, stored.embedding));
|
|
33
|
+
const stamp = suppliesEmbeddingModel(content) && !(stored && isDeepStrictEqual(body.embeddingModel, stored.embeddingModel));
|
|
34
|
+
return { vector, stamp };
|
|
35
|
+
}
|
|
36
|
+
/** True for actors exempt from discarding caller-supplied vectors:
|
|
37
|
+
* administrators and trusted in-process callers. A stored vector carried by
|
|
38
|
+
* a non-admin skill update can remain. */
|
|
39
|
+
export function keepsSuppliedVector(auth) {
|
|
40
|
+
return auth.kind === "internal" || (auth.kind === "agent" && auth.isAdmin);
|
|
41
|
+
}
|
|
42
|
+
/** Discard a non-admin write's caller-supplied vector and/or model stamp, in
|
|
43
|
+
* place. `supplied` comes from `suppliedVectorFlags`: what the CALLER's body
|
|
44
|
+
* held that differs from the stored row, before any stored row was merged in,
|
|
45
|
+
* so a vector prepareSkillBody carried from a stored row is left alone. A
|
|
46
|
+
* carried vector equal to `stored`'s keeps the stored stamp. A non-object or
|
|
47
|
+
* array body (no single record) is left untouched. Returns true when a field
|
|
48
|
+
* was removed. */
|
|
49
|
+
export function discardSuppliedVector(content, auth, supplied, stored) {
|
|
50
|
+
if (!content || typeof content !== "object" || Array.isArray(content))
|
|
51
|
+
return false;
|
|
52
|
+
if (keepsSuppliedVector(auth))
|
|
53
|
+
return false;
|
|
54
|
+
const carriedVector = !supplied.vector && hasSuppliedEmbedding(content.embedding);
|
|
55
|
+
let discarded = false;
|
|
56
|
+
if (supplied.vector && hasSuppliedEmbedding(content.embedding)) {
|
|
57
|
+
discarded = Object.prototype.hasOwnProperty.call(content, "embedding");
|
|
58
|
+
delete content.embedding;
|
|
59
|
+
}
|
|
60
|
+
if ((supplied.vector || supplied.stamp) && !carriedVector) {
|
|
61
|
+
discarded = Object.prototype.hasOwnProperty.call(content, "embeddingModel") || discarded;
|
|
62
|
+
delete content.embeddingModel;
|
|
63
|
+
}
|
|
64
|
+
else if (supplied.stamp && stored && sameVector(content.embedding, stored.embedding)) {
|
|
65
|
+
if (Object.prototype.hasOwnProperty.call(stored, "embeddingModel"))
|
|
66
|
+
content.embeddingModel = stored.embeddingModel;
|
|
67
|
+
else
|
|
68
|
+
delete content.embeddingModel;
|
|
69
|
+
discarded = true;
|
|
70
|
+
}
|
|
71
|
+
return discarded;
|
|
72
|
+
}
|