@tpsdev-ai/flair 0.56.0 → 0.57.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 +16 -17
- package/dist/build-info.json +3 -3
- package/dist/cli.js +115 -14
- package/dist/commands/agent.js +22 -15
- package/dist/commands/bridge.js +40 -3
- package/dist/commands/doctor.js +52 -0
- package/dist/commands/federation.js +263 -37
- package/dist/commands/init.js +29 -4
- package/dist/lib/auth-resolve.js +46 -0
- package/dist/lib/instance-identity-row.js +580 -0
- package/dist/lib/redact-token-id.js +197 -0
- package/dist/resources/AgentSeed.js +4 -1
- package/dist/resources/Asset.js +3 -11
- package/dist/resources/Credential.js +4 -10
- package/dist/resources/Federation.js +232 -78
- package/dist/resources/Integration.js +8 -32
- package/dist/resources/Memory.js +58 -16
- package/dist/resources/MemoryBootstrap.js +19 -12
- package/dist/resources/MemoryCandidate.js +3 -11
- package/dist/resources/MemoryDedupStats.js +1 -1
- package/dist/resources/MemoryFeed.js +10 -2
- package/dist/resources/MemoryGrant.js +19 -40
- package/dist/resources/MemoryUsage.js +7 -20
- package/dist/resources/Relationship.js +3 -11
- package/dist/resources/SemanticSearch.js +25 -13
- package/dist/resources/auth-middleware.js +32 -5
- package/dist/resources/bm25.js +13 -14
- package/dist/resources/federation-cleanup.js +289 -51
- package/dist/resources/health.js +48 -8
- 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 +94 -10
- package/dist/resources/mcp-handler.js +9 -1
- package/dist/resources/mcp-tool-arguments.js +83 -0
- package/dist/resources/mcp-tools.js +4 -5
- package/dist/resources/memory-visibility.js +10 -7
- package/dist/resources/rate-limit.js +6 -4
- package/dist/resources/record-type-kit.js +47 -23
- package/dist/resources/search-readiness.js +7 -1
- package/dist/resources/semantic-retrieval-core.js +98 -3
- package/dist/resources/table-helpers.js +33 -0
- package/dist/resources/tool-descriptors/index.js +2 -2
- package/dist/src/lib/instance-identity-row.js +580 -0
- package/dist/src/lib/redact-token-id.js +197 -0
- package/docs/api-reference.md +1 -1
- package/docs/auth.md +5 -5
- package/docs/claude-code.md +5 -6
- package/docs/deploying-on-fabric.md +6 -3
- package/docs/embedding-in-a-harper-app.md +3 -3
- package/docs/federation.md +16 -9
- package/docs/hosted-on-fabric.md +4 -3
- package/docs/integrations.md +24 -15
- package/docs/mcp-clients.md +16 -12
- package/docs/n8n.md +8 -8
- package/docs/notes/mcp-oauth-model2.md +12 -17
- package/docs/openclaw.md +29 -28
- package/docs/spoke-bringup.md +14 -11
- package/docs/standalone-local.md +2 -2
- package/docs/supply-chain-policy.md +21 -8
- package/docs/system-requirements.md +1 -1
- package/docs/upgrade.md +2 -2
- package/package.json +1 -1
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* redact-token-id.ts — the ONE pairing-token-id redactor (flair#1902).
|
|
3
|
+
*
|
|
4
|
+
* A pairing-token id IS the credential a spoke redeems, so only its 8-character
|
|
5
|
+
* prefix may ever reach a log line. Three sites grew their own copy of this rule
|
|
6
|
+
* in one day (the cleanup sweep's per-token lines, its table-level lines, and the
|
|
7
|
+
* rollback reporter), so the class is fixed here rather than at each site: one
|
|
8
|
+
* deep redactor every line that can carry a token id passes through.
|
|
9
|
+
*
|
|
10
|
+
* This is HYGIENE, not a security boundary — an operator holds admin credentials
|
|
11
|
+
* and can read the table directly. But a token id printed in full in a log is a
|
|
12
|
+
* credential handed to whoever reads the log, and the same gap reappearing at a
|
|
13
|
+
* new site is the failure this module exists to end.
|
|
14
|
+
*
|
|
15
|
+
* What "deep" means: a string (a message OR a string field at any depth, an array
|
|
16
|
+
* element, or an object KEY) has each secret replaced; numbers, booleans and null
|
|
17
|
+
* pass through untouched; a PLAIN object is rebuilt with redacted keys and values.
|
|
18
|
+
* Object keys are redacted too — a `{ "<token-id>": ... }` map is exactly as much
|
|
19
|
+
* a leak as one in a value. A NON-plain object — a Date, Error, Map, Set or class
|
|
20
|
+
* instance — passes through unchanged: rebuilding it through `Object.entries`
|
|
21
|
+
* would lose its message or entries, and its String form is what a caller should
|
|
22
|
+
* log. A cyclic value terminates: a container already on the path is returned
|
|
23
|
+
* as-is rather than recursed into (a log helper must never crash the sweep).
|
|
24
|
+
*
|
|
25
|
+
* Two properties the naive `split(secret).join(prefix)` gets wrong, and this
|
|
26
|
+
* module gets right:
|
|
27
|
+
*
|
|
28
|
+
* - LENGTH GUARD: a secret shorter than MIN_SECRET_LENGTH characters is
|
|
29
|
+
* replaced by "[redacted]" in full. Cutting an 11-character id to its
|
|
30
|
+
* 8-character prefix leaves most of the id visible, which is not a redaction.
|
|
31
|
+
* Empty secrets are ignored (never a replacement of "" that would splice the
|
|
32
|
+
* replacement between every character).
|
|
33
|
+
* - ONE PASS, LONGEST FIRST: the secrets are matched in a SINGLE pass over the
|
|
34
|
+
* original text, longest secret first. Sequential replaces let a short secret
|
|
35
|
+
* that is a prefix of a longer one match first and strand the longer id's
|
|
36
|
+
* suffix — and let a later secret match inside text a previous replacement
|
|
37
|
+
* just inserted. A single left-to-right scan avoids both, and it deliberately
|
|
38
|
+
* does NOT build a RegExp: a pattern assembled from the secrets would run on
|
|
39
|
+
* caller-supplied text, and a ReDoS there is a worse failure than the leak.
|
|
40
|
+
*
|
|
41
|
+
* `createTokenRedactor(secrets)` compiles the matcher once; the sweep reuses one
|
|
42
|
+
* per tick rather than rebuilding the replacement rules (or copying the id list)
|
|
43
|
+
* for every line it logs.
|
|
44
|
+
*/
|
|
45
|
+
/** How many leading characters of a long secret are kept. */
|
|
46
|
+
export const TOKEN_ID_PREFIX_LENGTH = 8;
|
|
47
|
+
/**
|
|
48
|
+
* Below this length, a secret is replaced in full: its "prefix" would be most of
|
|
49
|
+
* it. Pairing-token ids are 32 characters (`randomBytes(24).toString("base64url")`),
|
|
50
|
+
* so this bound is an untested assumption made explicit, not a live path — the
|
|
51
|
+
* guard exists so a short id can never be printed whole by a prefix rule.
|
|
52
|
+
*/
|
|
53
|
+
export const MIN_SECRET_LENGTH = 12;
|
|
54
|
+
/** What a secret too short to prefix-cut becomes. */
|
|
55
|
+
export const FULLY_REDACTED = "[redacted]";
|
|
56
|
+
/** The replacement text for one secret. */
|
|
57
|
+
function replacementFor(secret) {
|
|
58
|
+
return secret.length < MIN_SECRET_LENGTH
|
|
59
|
+
? FULLY_REDACTED
|
|
60
|
+
: `${secret.slice(0, TOKEN_ID_PREFIX_LENGTH)}…`;
|
|
61
|
+
}
|
|
62
|
+
/** Non-empty, de-duplicated secrets paired with their replacement, longest first. */
|
|
63
|
+
function secretReplacements(secrets) {
|
|
64
|
+
const seen = new Set();
|
|
65
|
+
const out = [];
|
|
66
|
+
for (const secret of secrets) {
|
|
67
|
+
if (typeof secret !== "string" || secret.length === 0)
|
|
68
|
+
continue;
|
|
69
|
+
if (seen.has(secret))
|
|
70
|
+
continue;
|
|
71
|
+
seen.add(secret);
|
|
72
|
+
out.push([secret, replacementFor(secret)]);
|
|
73
|
+
}
|
|
74
|
+
// Longest-first: the scan takes the LONGEST secret that starts at a position,
|
|
75
|
+
// so where two secrets overlap the longer one wins and no suffix of it is left
|
|
76
|
+
// stranded by a shorter secret matching first.
|
|
77
|
+
out.sort((a, b) => b[0].length - a[0].length);
|
|
78
|
+
return out;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Compile `secrets` into a redactor. Build it ONCE for a batch of lines and reuse
|
|
82
|
+
* it — the sweep logs many lines per tick, and recompiling per line is the
|
|
83
|
+
* quadratic cost this avoids.
|
|
84
|
+
*
|
|
85
|
+
* The scan walks the ORIGINAL text once: at each position it takes the longest
|
|
86
|
+
* secret that starts there (the list is longest-first), emits that secret's
|
|
87
|
+
* replacement, and advances past it; otherwise it copies one character. Text a
|
|
88
|
+
* replacement inserts is never re-scanned, and no RegExp is built from the
|
|
89
|
+
* secrets (so a token id can never become a pattern).
|
|
90
|
+
*/
|
|
91
|
+
export function createTokenRedactor(secrets) {
|
|
92
|
+
const replacements = secretReplacements(secrets);
|
|
93
|
+
const redactMessage = (message) => {
|
|
94
|
+
if (replacements.length === 0 || message.length === 0)
|
|
95
|
+
return message;
|
|
96
|
+
let out = "";
|
|
97
|
+
let i = 0;
|
|
98
|
+
while (i < message.length) {
|
|
99
|
+
let matched;
|
|
100
|
+
for (const pair of replacements) {
|
|
101
|
+
if (message.startsWith(pair[0], i)) {
|
|
102
|
+
matched = pair;
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
if (matched) {
|
|
107
|
+
out += matched[1];
|
|
108
|
+
i += matched[0].length;
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
out += message[i];
|
|
112
|
+
i += 1;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return out;
|
|
116
|
+
};
|
|
117
|
+
return {
|
|
118
|
+
redactMessage,
|
|
119
|
+
redactValue: (value) => (replacements.length === 0 ? value : walk(value, redactMessage)),
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
function walk(value, redact) {
|
|
123
|
+
return walkDeep(value, redact, new Map());
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* A plain object: its prototype is `Object.prototype` or null. A Date, Error,
|
|
127
|
+
* Map, Set or class instance is NOT a plain object, so it is not rebuilt — it
|
|
128
|
+
* passes through UNREDACTED, and its String form is what a caller should log
|
|
129
|
+
* (every call site stringifies an error before it reaches the redactor).
|
|
130
|
+
*/
|
|
131
|
+
function isPlainObject(value) {
|
|
132
|
+
const proto = Object.getPrototypeOf(value);
|
|
133
|
+
return proto === Object.prototype || proto === null;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Rebuild `value` with every string redacted. `copies` maps each container
|
|
137
|
+
* already rebuilt to its REDACTED copy, and the copy is registered before its
|
|
138
|
+
* children are walked: a sub-object reached twice (an alias) is the same
|
|
139
|
+
* redacted copy both times, and a cyclic value terminates by pointing at its own
|
|
140
|
+
* redacted copy. Returning the original for a repeated reference would hand back
|
|
141
|
+
* the unredacted container — the leak flair#1905's review found.
|
|
142
|
+
*/
|
|
143
|
+
function walkDeep(value, redact, copies) {
|
|
144
|
+
if (typeof value === "string")
|
|
145
|
+
return redact(value);
|
|
146
|
+
if (Array.isArray(value)) {
|
|
147
|
+
const known = copies.get(value);
|
|
148
|
+
if (known !== undefined)
|
|
149
|
+
return known;
|
|
150
|
+
const out = [];
|
|
151
|
+
copies.set(value, out);
|
|
152
|
+
for (const v of value)
|
|
153
|
+
out.push(walkDeep(v, redact, copies));
|
|
154
|
+
return out;
|
|
155
|
+
}
|
|
156
|
+
if (value && typeof value === "object") {
|
|
157
|
+
if (!isPlainObject(value))
|
|
158
|
+
return value;
|
|
159
|
+
const known = copies.get(value);
|
|
160
|
+
if (known !== undefined)
|
|
161
|
+
return known;
|
|
162
|
+
const out = {};
|
|
163
|
+
copies.set(value, out);
|
|
164
|
+
for (const [key, v] of Object.entries(value)) {
|
|
165
|
+
// Define each rebuilt key as an OWN property. A bracket assignment
|
|
166
|
+
// (`out[redact(key)] = …`) for the key `__proto__` would set the COPY's
|
|
167
|
+
// prototype instead of defining a key, dropping it and giving the copy an
|
|
168
|
+
// attacker-chosen prototype — reachable whenever the input came from
|
|
169
|
+
// JSON.parse or Object.defineProperty (flair#1907).
|
|
170
|
+
Object.defineProperty(out, redact(key), {
|
|
171
|
+
value: walkDeep(v, redact, copies),
|
|
172
|
+
enumerable: true,
|
|
173
|
+
writable: true,
|
|
174
|
+
configurable: true,
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
return out;
|
|
178
|
+
}
|
|
179
|
+
// Numbers, booleans, null, undefined, functions, symbols: untouched.
|
|
180
|
+
return value;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* A string with every secret replaced by its prefix (or `[redacted]` when the
|
|
184
|
+
* secret is too short to cut). The string-only convenience over the same
|
|
185
|
+
* implementation the deep redactor uses.
|
|
186
|
+
*/
|
|
187
|
+
export function redactTokenMessage(message, secrets) {
|
|
188
|
+
return createTokenRedactor(secrets).redactMessage(message);
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* `value` with every secret replaced in every string at any depth — a message, a
|
|
192
|
+
* string field, an array element, and an object KEY — rebuilt so keys and values
|
|
193
|
+
* are both redacted. Non-string scalars pass through untouched.
|
|
194
|
+
*/
|
|
195
|
+
export function redactTokenIds(value, secrets) {
|
|
196
|
+
return createTokenRedactor(secrets).redactValue(value);
|
|
197
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
1
2
|
/**
|
|
2
3
|
* POST /AgentSeed
|
|
3
4
|
*
|
|
@@ -128,7 +129,9 @@ export class AgentSeed extends Resource {
|
|
|
128
129
|
const skillDenial = rejectSkillWritePath(def);
|
|
129
130
|
if (skillDenial)
|
|
130
131
|
return skillDenial;
|
|
131
|
-
|
|
132
|
+
// A full random UUID in the id: this raw-table write is meant to create,
|
|
133
|
+
// never to replace an existing record.
|
|
134
|
+
const id = `seed-${agentId}-${i}-${Date.now()}-${randomUUID()}`;
|
|
132
135
|
const record = {
|
|
133
136
|
id,
|
|
134
137
|
agentId,
|
package/dist/resources/Asset.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { createBlob, databases } from "harper";
|
|
2
2
|
import { resolveAgentAuth } from "./agent-auth.js";
|
|
3
3
|
import { guardOwnerFieldImmutable } from "./owner-field-guard.js";
|
|
4
|
-
import { FORBIDDEN, UNAUTH, makeAuthGate, makeByIdReadGate, makeReadScope, resolveAuthGate, stampAttribution, } from "./record-type-kit.js";
|
|
4
|
+
import { FORBIDDEN, UNAUTH, makeAuthGate, makeByIdReadGate, makeReadScope, makeScopedSearch, resolveAuthGate, stampAttribution, } from "./record-type-kit.js";
|
|
5
5
|
import { RECORD_TYPES } from "./record-types.js";
|
|
6
6
|
// Kit parameters read FROM RECORD_TYPES.Asset (single source of truth), same
|
|
7
7
|
// composition MemoryCandidate.ts uses.
|
|
8
8
|
const assetReadScope = makeReadScope(RECORD_TYPES.Asset.readScope, RECORD_TYPES.Asset.ownerField);
|
|
9
|
+
const assetScopedSearch = makeScopedSearch(assetReadScope);
|
|
9
10
|
const assetByIdReadGate = makeByIdReadGate(assetReadScope);
|
|
10
11
|
const assetAuthGate = makeAuthGate();
|
|
11
12
|
/**
|
|
@@ -58,16 +59,7 @@ export class Asset extends databases.flair.Asset {
|
|
|
58
59
|
return gate.response;
|
|
59
60
|
if (gate.kind === "unfiltered")
|
|
60
61
|
return super.search(query);
|
|
61
|
-
|
|
62
|
-
const agentCondition = scope.condition;
|
|
63
|
-
if (!query?.conditions) {
|
|
64
|
-
return super.search({ conditions: [agentCondition], ...(query || {}) });
|
|
65
|
-
}
|
|
66
|
-
return super.search({
|
|
67
|
-
...query,
|
|
68
|
-
conditions: [agentCondition, { conditions: query.conditions, operator: query.operator || "and" }],
|
|
69
|
-
operator: "and",
|
|
70
|
-
});
|
|
62
|
+
return assetScopedSearch(gate.agentId, query, (q) => super.search(q));
|
|
71
63
|
}
|
|
72
64
|
async post(content) {
|
|
73
65
|
const ctx = this.getContext?.();
|
|
@@ -2,7 +2,9 @@ import { databases } from "harper";
|
|
|
2
2
|
import { resolveAgentAuth, allowVerified } from "./agent-auth.js";
|
|
3
3
|
import { guardOwnerFieldImmutable } from "./owner-field-guard.js";
|
|
4
4
|
import { checkRateLimit, rateLimitResponse } from "./rate-limiter.js";
|
|
5
|
-
import { stampAttribution, UNAUTH } from "./record-type-kit.js";
|
|
5
|
+
import { makeReadScope, makeScopedSearch, stampAttribution, UNAUTH } from "./record-type-kit.js";
|
|
6
|
+
const credentialReadScope = makeReadScope("owner-only", "principalId");
|
|
7
|
+
const credentialScopedSearch = makeScopedSearch(credentialReadScope);
|
|
6
8
|
/**
|
|
7
9
|
* Credential resource — authentication surfaces for Principals.
|
|
8
10
|
*
|
|
@@ -84,15 +86,7 @@ export class Credential extends databases.flair.Credential {
|
|
|
84
86
|
return super.search(query);
|
|
85
87
|
}
|
|
86
88
|
// Non-admin agent: scope to own credentials.
|
|
87
|
-
|
|
88
|
-
if (!query?.conditions) {
|
|
89
|
-
return super.search({ conditions: [condition], ...(query || {}) });
|
|
90
|
-
}
|
|
91
|
-
return super.search({
|
|
92
|
-
...query,
|
|
93
|
-
conditions: [condition, { conditions: query.conditions, operator: query.operator || "and" }],
|
|
94
|
-
operator: "and",
|
|
95
|
-
});
|
|
89
|
+
return credentialScopedSearch(auth.agentId, query, (q) => super.search(q));
|
|
96
90
|
}
|
|
97
91
|
async get() {
|
|
98
92
|
const result = await super.get();
|