@tpsdev-ai/flair 0.54.2 → 0.55.1
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/dist/build-info.json +3 -3
- package/dist/cli.js +774 -176
- package/dist/commands/doctor.js +86 -1
- package/dist/commands/federation.js +131 -36
- package/dist/commands/hook.js +20 -10
- package/dist/commands/init.js +193 -67
- package/dist/commands/service.js +16 -12
- package/dist/commands/soul.js +10 -5
- package/dist/commands/status.js +62 -7
- package/dist/commands/upgrade.js +6 -0
- package/dist/doctor-client.js +118 -32
- package/dist/hook-install.js +170 -16
- package/dist/lib/doctor-run.js +49 -3
- package/dist/lib/embed-gpu-doctor.js +63 -0
- package/dist/lib/federation-pair-access.js +118 -0
- package/dist/lib/harper-port-value.js +43 -0
- package/dist/lib/http-bind.js +227 -0
- package/dist/lib/init-admin-pass.js +316 -0
- package/dist/lib/launchd-management.js +16 -0
- package/dist/lib/launchd-repair.js +122 -1
- package/dist/lib/owned-pins.js +54 -1
- package/dist/lib/process-start-time.js +82 -0
- package/dist/lib/scratch-owner.js +124 -10
- package/dist/lib/stale-client-pin.js +26 -0
- package/dist/lib/upgrade-plain-tree.js +293 -48
- package/dist/rem/runner.js +10 -1
- package/dist/resources/AdminInstance.js +8 -2
- package/dist/resources/Memory.js +36 -1
- package/dist/resources/MemoryBootstrap.js +23 -32
- package/dist/resources/MemoryFeed.js +4 -1
- package/dist/resources/MemoryReflect.js +121 -93
- package/dist/resources/SkillScan.js +13 -11
- package/dist/resources/Soul.js +15 -1
- package/dist/resources/XAA.js +16 -1
- package/dist/resources/a2a-url.js +5 -2
- package/dist/resources/client-version-gate.js +144 -0
- package/dist/resources/embed-gpu.js +241 -0
- package/dist/resources/embeddings-boot.js +34 -42
- package/dist/resources/federation-peer-liveness.js +7 -1
- package/dist/resources/health.js +12 -3
- package/dist/resources/memory-reflect-lib.js +66 -0
- package/dist/resources/memory-reflect-models.js +9 -0
- package/dist/resources/migrations/embedding-stamp.js +32 -4
- package/dist/resources/oauth-discovery.js +3 -1
- package/dist/resources/record-type-kit.js +59 -0
- package/dist/resources/scan/skill-markdown.js +166 -0
- package/dist/resources/scan/skill-scanner.js +89 -68
- package/dist/resources/skill-provenance.js +273 -0
- package/dist/resources/skill-write.js +26 -7
- package/dist/src/lib/harper-port-value.js +43 -0
- package/docs/api-reference.md +35 -2
- package/docs/deployment.md +39 -6
- package/docs/federation.md +18 -7
- package/docs/mcp-clients.md +19 -6
- package/docs/releasing.md +79 -13
- package/docs/rem.md +1 -1
- package/docs/secrets-and-keys.md +1 -0
- package/docs/standalone-local.md +8 -5
- package/docs/troubleshooting.md +17 -0
- package/package.json +1 -1
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* skill-provenance.ts — durable source + stated conflict outcome (flair#1433).
|
|
3
|
+
*
|
|
4
|
+
* Two defects, two functions, no Harper imports:
|
|
5
|
+
*
|
|
6
|
+
* 1. Registration: a skill-assignment (Soul key `skill-assignment`) whose
|
|
7
|
+
* `metadata.source` is a filesystem path under a temp directory is not
|
|
8
|
+
* provenance. `registerSkillAssignment` / `refuseSkillAssignmentWrite`
|
|
9
|
+
* fail and name the path. Scratch/inspect paths (`/tmp/...-inspect/...`)
|
|
10
|
+
* are the known-answer case from the 2026-08-26 flint bootstrap payload.
|
|
11
|
+
*
|
|
12
|
+
* 2. Load: `SKILL_CONFLICT` must decide something. Skills are identified by
|
|
13
|
+
* `value` (name). Priority is stated precedence (critical > high >
|
|
14
|
+
* standard > low). A unique highest priority loads; an equal-priority
|
|
15
|
+
* tie refuses the whole name-set. Map iteration order never picks a
|
|
16
|
+
* winner. The payload line states the decision and why.
|
|
17
|
+
*
|
|
18
|
+
* Trust/signature is out of scope (epic #1434, later). This module does not
|
|
19
|
+
* invent a signing model.
|
|
20
|
+
*
|
|
21
|
+
* A normally-installed, non-conflicting skill with a durable (or absent)
|
|
22
|
+
* source still loads silently — no marker.
|
|
23
|
+
*/
|
|
24
|
+
import { tmpdir } from "node:os";
|
|
25
|
+
import { isAbsolute, resolve, sep } from "node:path";
|
|
26
|
+
import { fileURLToPath } from "node:url";
|
|
27
|
+
export const SKILL_ASSIGNMENT_KEY = "skill-assignment";
|
|
28
|
+
export const PRIORITY_RANK = {
|
|
29
|
+
critical: 0,
|
|
30
|
+
high: 1,
|
|
31
|
+
standard: 2,
|
|
32
|
+
low: 3,
|
|
33
|
+
};
|
|
34
|
+
export function parseSkillMetadata(metadata) {
|
|
35
|
+
if (metadata && typeof metadata === "object" && !Array.isArray(metadata)) {
|
|
36
|
+
return metadata;
|
|
37
|
+
}
|
|
38
|
+
if (typeof metadata === "string" && metadata.length > 0) {
|
|
39
|
+
try {
|
|
40
|
+
const parsed = JSON.parse(metadata);
|
|
41
|
+
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
42
|
+
return parsed;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
/* opaque / corrupt blob — no source */
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return {};
|
|
50
|
+
}
|
|
51
|
+
export function skillSourceOf(record) {
|
|
52
|
+
const src = parseSkillMetadata(record.metadata).source;
|
|
53
|
+
return typeof src === "string" && src.trim().length > 0 ? src.trim() : undefined;
|
|
54
|
+
}
|
|
55
|
+
const SCHEME = /^([a-zA-Z][a-zA-Z0-9+.-]*):/;
|
|
56
|
+
function isWindowsDrivePath(source) {
|
|
57
|
+
return /^[a-zA-Z]:[\\/]/.test(source);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* If `source` names a filesystem path (absolute, relative, or `file:` URL),
|
|
61
|
+
* return that path. Scheme-bearing identifiers (`npm:`, `https:`, …) are
|
|
62
|
+
* not filesystem paths. A bare name is not a path.
|
|
63
|
+
*/
|
|
64
|
+
export function filesystemPathFromSkillSource(source) {
|
|
65
|
+
const trimmed = source.trim();
|
|
66
|
+
if (!trimmed)
|
|
67
|
+
return null;
|
|
68
|
+
if (trimmed.startsWith("file:")) {
|
|
69
|
+
try {
|
|
70
|
+
return fileURLToPath(trimmed);
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
const rest = trimmed.replace(/^file:\/\//, "").replace(/^file:/, "");
|
|
74
|
+
return rest.length > 0 ? rest : null;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (SCHEME.test(trimmed) && !isWindowsDrivePath(trimmed))
|
|
78
|
+
return null;
|
|
79
|
+
if (isAbsolute(trimmed) || trimmed.startsWith(".") || /[\\/]/.test(trimmed)) {
|
|
80
|
+
return trimmed;
|
|
81
|
+
}
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
function tempRoots() {
|
|
85
|
+
const roots = new Set();
|
|
86
|
+
const add = (p) => {
|
|
87
|
+
if (!p || typeof p !== "string" || p.length === 0)
|
|
88
|
+
return;
|
|
89
|
+
try {
|
|
90
|
+
roots.add(resolve(p));
|
|
91
|
+
}
|
|
92
|
+
catch {
|
|
93
|
+
/* ignore unresolvable */
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
add(tmpdir());
|
|
97
|
+
add("/tmp");
|
|
98
|
+
add("/private/tmp");
|
|
99
|
+
add("/var/tmp");
|
|
100
|
+
add(process.env.TMPDIR);
|
|
101
|
+
add(process.env.TMP);
|
|
102
|
+
add(process.env.TEMP);
|
|
103
|
+
return [...roots];
|
|
104
|
+
}
|
|
105
|
+
export function isNonDurableFilesystemPath(fsPath) {
|
|
106
|
+
let resolved;
|
|
107
|
+
try {
|
|
108
|
+
resolved = resolve(fsPath);
|
|
109
|
+
}
|
|
110
|
+
catch {
|
|
111
|
+
return true;
|
|
112
|
+
}
|
|
113
|
+
for (const root of tempRoots()) {
|
|
114
|
+
if (resolved === root || resolved.startsWith(root + sep))
|
|
115
|
+
return true;
|
|
116
|
+
}
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
export function isDurableSkillSource(source) {
|
|
120
|
+
const fsPath = filesystemPathFromSkillSource(source);
|
|
121
|
+
if (fsPath == null)
|
|
122
|
+
return true;
|
|
123
|
+
return !isNonDurableFilesystemPath(fsPath);
|
|
124
|
+
}
|
|
125
|
+
export function registerSkillAssignment(input) {
|
|
126
|
+
const key = typeof input.key === "string" ? input.key : SKILL_ASSIGNMENT_KEY;
|
|
127
|
+
if (key !== SKILL_ASSIGNMENT_KEY)
|
|
128
|
+
return { ok: true };
|
|
129
|
+
const source = skillSourceOf(input);
|
|
130
|
+
if (!source)
|
|
131
|
+
return { ok: true };
|
|
132
|
+
if (isDurableSkillSource(source))
|
|
133
|
+
return { ok: true };
|
|
134
|
+
return {
|
|
135
|
+
ok: false,
|
|
136
|
+
error: "skill_source_not_durable",
|
|
137
|
+
path: source,
|
|
138
|
+
message: `skill source is not durable: ${source}`,
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
export function refuseNonDurableSourceResponse(source) {
|
|
142
|
+
if (!source)
|
|
143
|
+
return null;
|
|
144
|
+
if (isDurableSkillSource(source))
|
|
145
|
+
return null;
|
|
146
|
+
return new Response(JSON.stringify({
|
|
147
|
+
error: "skill_source_not_durable",
|
|
148
|
+
path: source,
|
|
149
|
+
message: `skill source is not durable: ${source}`,
|
|
150
|
+
}), { status: 400, headers: { "content-type": "application/json" } });
|
|
151
|
+
}
|
|
152
|
+
function assignmentKey(content, existing) {
|
|
153
|
+
const key = content?.key ?? existing?.key;
|
|
154
|
+
return typeof key === "string" ? key : undefined;
|
|
155
|
+
}
|
|
156
|
+
/** Soul post/put/patch gate. `existing` supplies omitted fields on PATCH. */
|
|
157
|
+
export function refuseSkillAssignmentWrite(content, existing) {
|
|
158
|
+
if (assignmentKey(content, existing) !== SKILL_ASSIGNMENT_KEY)
|
|
159
|
+
return null;
|
|
160
|
+
const metadata = content?.metadata !== undefined ? content.metadata : existing?.metadata;
|
|
161
|
+
const result = registerSkillAssignment({
|
|
162
|
+
key: SKILL_ASSIGNMENT_KEY,
|
|
163
|
+
value: content?.value ?? existing?.value,
|
|
164
|
+
priority: content?.priority ?? existing?.priority,
|
|
165
|
+
metadata,
|
|
166
|
+
});
|
|
167
|
+
if (result.ok)
|
|
168
|
+
return null;
|
|
169
|
+
return new Response(JSON.stringify({
|
|
170
|
+
error: result.error,
|
|
171
|
+
path: result.path,
|
|
172
|
+
message: result.message,
|
|
173
|
+
}), { status: 400, headers: { "content-type": "application/json" } });
|
|
174
|
+
}
|
|
175
|
+
function normalizePriority(p) {
|
|
176
|
+
if (typeof p === "string" && Object.hasOwn(PRIORITY_RANK, p))
|
|
177
|
+
return p;
|
|
178
|
+
return "standard";
|
|
179
|
+
}
|
|
180
|
+
function priorityRank(p) {
|
|
181
|
+
return PRIORITY_RANK[p] ?? PRIORITY_RANK.standard;
|
|
182
|
+
}
|
|
183
|
+
function formatBase(name, priority, source) {
|
|
184
|
+
const src = source ? `, source: ${source}` : "";
|
|
185
|
+
return `- ${name} (${priority} priority${src})`;
|
|
186
|
+
}
|
|
187
|
+
function compareOutcomes(a, b) {
|
|
188
|
+
const byName = a.name.localeCompare(b.name);
|
|
189
|
+
if (byName !== 0)
|
|
190
|
+
return byName;
|
|
191
|
+
const bySource = (a.source ?? "").localeCompare(b.source ?? "");
|
|
192
|
+
if (bySource !== 0)
|
|
193
|
+
return bySource;
|
|
194
|
+
const byPri = priorityRank(a.priority) - priorityRank(b.priority);
|
|
195
|
+
if (byPri !== 0)
|
|
196
|
+
return byPri;
|
|
197
|
+
return a.reason.localeCompare(b.reason);
|
|
198
|
+
}
|
|
199
|
+
function outcomeOf(name, priority, source, decision, reason, loaded) {
|
|
200
|
+
let line = formatBase(name, priority, source);
|
|
201
|
+
if (decision === "superseded") {
|
|
202
|
+
line += ` [SKILL_CONFLICT superseded: ${reason}]`;
|
|
203
|
+
}
|
|
204
|
+
else if (decision === "refused") {
|
|
205
|
+
line += reason.startsWith("non-durable source")
|
|
206
|
+
? ` [refused: ${reason}]`
|
|
207
|
+
: ` [SKILL_CONFLICT refused: ${reason}]`;
|
|
208
|
+
}
|
|
209
|
+
return { name, priority, source, decision, reason, loaded, line };
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Stated, deterministic Active Skills outcome.
|
|
213
|
+
*
|
|
214
|
+
* Identity is `value` (name). Two different names at the same priority are
|
|
215
|
+
* not a conflict — they are two skills. Two records of the same name:
|
|
216
|
+
* unique highest priority wins (stated); an equal-priority tie refuses
|
|
217
|
+
* every member of that name-set. Non-durable sources are refused at load
|
|
218
|
+
* as well as at registration so a scratch path already on disk cannot
|
|
219
|
+
* keep applying.
|
|
220
|
+
*
|
|
221
|
+
* Output order is name → source → priority → reason, so a restart with
|
|
222
|
+
* the same records produces the same lines regardless of input order.
|
|
223
|
+
*/
|
|
224
|
+
export function resolveActiveSkills(assignments) {
|
|
225
|
+
const prepared = [];
|
|
226
|
+
const outcomes = [];
|
|
227
|
+
for (const raw of assignments) {
|
|
228
|
+
const name = typeof raw.value === "string" ? raw.value : "";
|
|
229
|
+
if (name.length === 0)
|
|
230
|
+
continue;
|
|
231
|
+
const priority = normalizePriority(raw.priority);
|
|
232
|
+
const source = skillSourceOf(raw);
|
|
233
|
+
if (source && !isDurableSkillSource(source)) {
|
|
234
|
+
outcomes.push(outcomeOf(name, priority, source, "refused", `non-durable source ${source}`, false));
|
|
235
|
+
continue;
|
|
236
|
+
}
|
|
237
|
+
prepared.push({ name, priority, source });
|
|
238
|
+
}
|
|
239
|
+
const byName = new Map();
|
|
240
|
+
for (const row of prepared) {
|
|
241
|
+
const list = byName.get(row.name);
|
|
242
|
+
if (list)
|
|
243
|
+
list.push(row);
|
|
244
|
+
else
|
|
245
|
+
byName.set(row.name, [row]);
|
|
246
|
+
}
|
|
247
|
+
for (const group of byName.values()) {
|
|
248
|
+
if (group.length === 1) {
|
|
249
|
+
const only = group[0];
|
|
250
|
+
outcomes.push(outcomeOf(only.name, only.priority, only.source, "loaded", "sole", true));
|
|
251
|
+
continue;
|
|
252
|
+
}
|
|
253
|
+
const best = Math.min(...group.map((g) => priorityRank(g.priority)));
|
|
254
|
+
const top = group.filter((g) => priorityRank(g.priority) === best);
|
|
255
|
+
if (top.length === 1) {
|
|
256
|
+
const winner = top[0];
|
|
257
|
+
outcomes.push(outcomeOf(winner.name, winner.priority, winner.source, "loaded", `unique_priority ${winner.priority}`, true));
|
|
258
|
+
for (const loser of group) {
|
|
259
|
+
if (loser === winner)
|
|
260
|
+
continue;
|
|
261
|
+
outcomes.push(outcomeOf(loser.name, loser.priority, loser.source, "superseded", `${winner.priority} priority is stated precedence over ${loser.priority}`, false));
|
|
262
|
+
}
|
|
263
|
+
continue;
|
|
264
|
+
}
|
|
265
|
+
const sources = [...new Set(top.map((t) => t.source ?? "(none)"))].sort((a, b) => a.localeCompare(b));
|
|
266
|
+
const reason = `equal-priority tie at ${top[0].priority}; load refused (sources: ${sources.join(", ")})`;
|
|
267
|
+
for (const member of group) {
|
|
268
|
+
outcomes.push(outcomeOf(member.name, member.priority, member.source, "refused", reason, false));
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
outcomes.sort(compareOutcomes);
|
|
272
|
+
return { lines: outcomes.map((o) => o.line), outcomes };
|
|
273
|
+
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* skill-write.ts — the WRITE-side skill policy (flair#1542 components 1-3).
|
|
3
3
|
*
|
|
4
4
|
* A skill is a Memory tagged "skill" (reuse the substrate — no new table).
|
|
5
|
-
* This module centralizes the
|
|
5
|
+
* This module centralizes the write-side rules that make a skill-tagged
|
|
6
6
|
* Memory behave like a skill:
|
|
7
7
|
*
|
|
8
8
|
* 1. Embedding source: a skill-tagged row embeds from `trigger` (the
|
|
@@ -22,12 +22,18 @@
|
|
|
22
22
|
* ephemeral/session skill is a contradiction in terms — ephemeral/session
|
|
23
23
|
* are rejected outright, and every other value is forced to "persistent".
|
|
24
24
|
*
|
|
25
|
+
* 4. Durable source (flair#1433): a skill-tagged write whose
|
|
26
|
+
* `metadata.source` is a filesystem path under a temp directory is
|
|
27
|
+
* refused. Content durability (3) and source durability (4) are
|
|
28
|
+
* different axes.
|
|
29
|
+
*
|
|
25
30
|
* Deliberately ZERO Harper imports — pure functions + constants, so the
|
|
26
31
|
* coverage-gate test and unit tests can import this module without the
|
|
27
32
|
* runtime (same load-bearing reason as memory-durability.ts /
|
|
28
33
|
* memory-visibility.ts).
|
|
29
34
|
*/
|
|
30
|
-
import { scanSkillContent } from "./scan/skill-scanner.js";
|
|
35
|
+
import { combineScanResults, scanSkillContent } from "./scan/skill-scanner.js";
|
|
36
|
+
import { refuseNonDurableSourceResponse, skillSourceOf } from "./skill-provenance.js";
|
|
31
37
|
/** The tag that marks a Memory as a skill. */
|
|
32
38
|
export const SKILL_TAG = "skill";
|
|
33
39
|
/** Is this write a skill-tagged Memory? */
|
|
@@ -85,20 +91,33 @@ export function rejectSkillWritePath(content) {
|
|
|
85
91
|
}), { status: 400, headers: { "content-type": "application/json" } });
|
|
86
92
|
}
|
|
87
93
|
/**
|
|
88
|
-
* SkillScan gate — run BEFORE the embedding is computed. Scans
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
*
|
|
94
|
+
* SkillScan gate — run BEFORE the embedding is computed. Scans `trigger`
|
|
95
|
+
* and `content` separately, then re-assesses the union of findings (a
|
|
96
|
+
* dangerous payload in EITHER — or split across both — is a rejection).
|
|
97
|
+
* Joining first lets a crafted trigger plant a `---` pair that steals
|
|
98
|
+
* frontmatter. Max-of-parts alone drops `shell_backtick` + URL/encoding
|
|
99
|
+
* across fields to medium. Fail-closed on high/critical; allow-with-flag
|
|
100
|
+
* on medium.
|
|
92
101
|
*
|
|
93
102
|
* Returns a 400 Response to short-circuit the write, or null to proceed.
|
|
94
103
|
*/
|
|
104
|
+
/**
|
|
105
|
+
* Refuse a skill-tagged Memory whose metadata.source is a non-durable
|
|
106
|
+
* filesystem path (flair#1433). Non-skill rows and skills without a source
|
|
107
|
+
* are a no-op.
|
|
108
|
+
*/
|
|
109
|
+
export function refuseSkillWriteSource(content) {
|
|
110
|
+
if (!isSkillWrite(content))
|
|
111
|
+
return null;
|
|
112
|
+
return refuseNonDurableSourceResponse(skillSourceOf(content));
|
|
113
|
+
}
|
|
95
114
|
export function skillScanGate(content) {
|
|
96
115
|
if (!isSkillWrite(content))
|
|
97
116
|
return null;
|
|
98
117
|
const parts = [content.trigger, content.content].filter((s) => typeof s === "string" && s.length > 0);
|
|
99
118
|
if (parts.length === 0)
|
|
100
119
|
return null;
|
|
101
|
-
const result =
|
|
120
|
+
const result = combineScanResults(parts.map((t) => scanSkillContent(t)));
|
|
102
121
|
if (result.riskLevel === "high" || result.riskLevel === "critical") {
|
|
103
122
|
return new Response(JSON.stringify({
|
|
104
123
|
error: "skill_scan_rejected",
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* harper-port-value.ts — the ONE parser for a Harper port config value, shared
|
|
3
|
+
* by the CLI (`src/`) and the runtime resources (`resources/`).
|
|
4
|
+
*
|
|
5
|
+
* Moved out of `src/cli.ts` (where it lived as `harperPortValue`), not
|
|
6
|
+
* rewritten: every consumer that interpolates a port into a URL parses it here.
|
|
7
|
+
* A second, hand-rolled parser is the same defect as a second detector — two
|
|
8
|
+
* implementations that can drift, with the drift only visible on the value one
|
|
9
|
+
* of them mishandles.
|
|
10
|
+
*
|
|
11
|
+
* Harper accepts both a bare port (`9926`, all interfaces) and the
|
|
12
|
+
* host-qualified `host:port` form flair writes for the ops API
|
|
13
|
+
* (`127.0.0.1:9925` — see `opsNetworkPortValue`). Both name the same port; only
|
|
14
|
+
* the bind differs, and `detectOpsApiAllInterfacesBind` (lib/ops-api-bind.ts) is
|
|
15
|
+
* what reads the host half. Splits on the LAST colon so an IPv6 literal
|
|
16
|
+
* (`[::1]:9925`) keeps its port.
|
|
17
|
+
*
|
|
18
|
+
* What it checks: ONLY the digits after the last colon. The host half is NOT
|
|
19
|
+
* validated — any host text is accepted and ignored, so a qualified value means
|
|
20
|
+
* "the port is whatever trails the final colon". A value with no colon, an
|
|
21
|
+
* empty string, or a non-numeric tail yields null.
|
|
22
|
+
*
|
|
23
|
+
* Range: a port outside 1..65535 yields null so the caller falls back to its
|
|
24
|
+
* default. `new URL()` rejects a port above 65535, so returning one would hand
|
|
25
|
+
* a URL builder a value that throws instead of a usable loopback URL.
|
|
26
|
+
*/
|
|
27
|
+
const MAX_TCP_PORT = 65535;
|
|
28
|
+
export function harperPortValue(value) {
|
|
29
|
+
if (value === undefined || value === null)
|
|
30
|
+
return null;
|
|
31
|
+
if (typeof value === "number") {
|
|
32
|
+
return Number.isInteger(value) && value > 0 && value <= MAX_TCP_PORT ? value : null;
|
|
33
|
+
}
|
|
34
|
+
const str = String(value).trim();
|
|
35
|
+
if (str === "")
|
|
36
|
+
return null;
|
|
37
|
+
const lastColon = str.lastIndexOf(":");
|
|
38
|
+
const portPart = lastColon > 0 ? str.slice(lastColon + 1) : str;
|
|
39
|
+
if (!/^\d+$/.test(portPart))
|
|
40
|
+
return null;
|
|
41
|
+
const n = Number(portPart);
|
|
42
|
+
return n > 0 && n <= MAX_TCP_PORT ? n : null;
|
|
43
|
+
}
|
package/docs/api-reference.md
CHANGED
|
@@ -93,7 +93,7 @@ is `GET /Name/<id>` unless noted.
|
|
|
93
93
|
|
|
94
94
|
| Method | Path | Auth | Notes |
|
|
95
95
|
|--------|------|------|-------|
|
|
96
|
-
| GET | `/Health`, `/health` | Public | Liveness. `searchReady` is always present; HTTP 503 / `ok: false` when search cannot be served. |
|
|
96
|
+
| GET | `/Health`, `/health` | Public | Liveness. `searchReady` is always present; HTTP 503 / `ok: false` when search cannot be served. `embedding: { backend, gpuLayers, source }` states the resolved embed device (flair#1437); `fallback` is present when GPU was requested but Metal did not engage. |
|
|
97
97
|
| GET | `/HealthDetail` | Ed25519 | Rich stats (counts, agents, migration). |
|
|
98
98
|
| GET | `/AgentCard/<agentId>` | Public | A2A agent-card; field-allowlisted. |
|
|
99
99
|
| GET | `/a2a`, `/A2AAdapter` | Public | A2A discovery. |
|
|
@@ -123,7 +123,7 @@ the same identity plane.
|
|
|
123
123
|
| Method | Path | Auth | Read / write |
|
|
124
124
|
|--------|------|------|--------------|
|
|
125
125
|
| GET | `/Memory`, `/Memory/<id>` | Ed25519 | open-within-org. By-id deny = 404. |
|
|
126
|
-
| POST / PUT / PATCH | `/Memory` | Ed25519 | Own `agentId` only. Auto-embed on write. Visibility defaults from durability (`permanent`/`persistent` → `shared`, `standard`/`ephemeral` → `private`). |
|
|
126
|
+
| POST / PUT / PATCH | `/Memory` | Ed25519 | Own `agentId` only. Auto-embed on write. Visibility defaults from durability (`permanent`/`persistent` → `shared`, `standard`/`ephemeral` → `private`). Identified client older than 0.18.0 → **426** `stale_flair_client` (missing version is served). |
|
|
127
127
|
| DELETE | `/Memory/<id>` | Ed25519 | Owner or admin. `permanent` owner-delete is allowed. |
|
|
128
128
|
| POST | `/SemanticSearch` | Ed25519 | Hybrid semantic + lexical. Same read-scope as Memory. Default scoring is `raw`. |
|
|
129
129
|
| POST | `/BootstrapMemories` | Ed25519 | Cold-start context (soul + predicted memories + optional org events). |
|
|
@@ -146,6 +146,39 @@ the same identity plane.
|
|
|
146
146
|
Skill-tagged Memory rows embed from `trigger` (the recall signal), not
|
|
147
147
|
`content`. MCP tools: `skill_store`, `skill_search`, `skill_get`.
|
|
148
148
|
|
|
149
|
+
#### Client version gate (HTTP 426 `stale_flair_client`)
|
|
150
|
+
|
|
151
|
+
`POST` / `PUT` / `PATCH` `/Memory` refuse an **identified**
|
|
152
|
+
`@tpsdev-ai/flair-client` or `@tpsdev-ai/flair-mcp` older than 0.18.0.
|
|
153
|
+
Identification is the
|
|
154
|
+
`X-Flair-Client` request header. A missing version is served — in-process
|
|
155
|
+
`/mcp` (`delegationContext` does not set this header) and raw HTTP callers
|
|
156
|
+
do not send one. Optional write-body `flairClientVersion` is also accepted
|
|
157
|
+
and stripped so it is never stored.
|
|
158
|
+
|
|
159
|
+
**Request header**
|
|
160
|
+
|
|
161
|
+
```
|
|
162
|
+
X-Flair-Client: flair-client/0.17.0
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
(`flair-mcp/<semver>` and a bare `<semver>` are also accepted.)
|
|
166
|
+
|
|
167
|
+
**Response** — HTTP 426, `Content-Type: application/json`
|
|
168
|
+
|
|
169
|
+
```json
|
|
170
|
+
{
|
|
171
|
+
"error": "stale_flair_client",
|
|
172
|
+
"message": "This flair-client (0.17.0) silently drops writes — including against another agent's shared memories. Upgrade the adapter, not the server: `flair upgrade`, or pin @tpsdev-ai/flair-mcp / @tpsdev-ai/flair-client >= 0.18.0.",
|
|
173
|
+
"clientVersion": "0.17.0",
|
|
174
|
+
"minimumClientVersion": "0.18.0"
|
|
175
|
+
}
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
The remedy is `flair upgrade` (the adapter), not a server upgrade alone.
|
|
179
|
+
`flair doctor` names a wired `flair-mcp` / `flair-client` pin older than
|
|
180
|
+
0.18.0. See [troubleshooting](troubleshooting.md#pre-0180-flair-client--flair-mcp-silently-drops-writes).
|
|
181
|
+
|
|
149
182
|
### Relationships, workspace, org events, attention
|
|
150
183
|
|
|
151
184
|
| Method | Path | Auth | Read / write |
|
package/docs/deployment.md
CHANGED
|
@@ -136,9 +136,40 @@ Then set `FLAIR_URL=http://localhost:19926` on the client.
|
|
|
136
136
|
|
|
137
137
|
### Direct network access
|
|
138
138
|
|
|
139
|
-
|
|
139
|
+
Flair reads the HTTP bind host from three places — the first one set wins:
|
|
140
|
+
|
|
141
|
+
1. `flair init --http-bind <host>`
|
|
142
|
+
2. `FLAIR_HTTP_BIND` in the Flair process environment
|
|
143
|
+
3. a **top-level** `httpBind:` key in `~/.flair/config.yaml`
|
|
144
|
+
|
|
145
|
+
`127.0.0.1` is the default when none is set. **Only hosts that include IPv4
|
|
146
|
+
loopback are accepted** — `127.0.0.1` itself, or a wildcard (`0.0.0.0` / `::`).
|
|
147
|
+
Every credentialed self-call Flair makes hardcodes `127.0.0.1`, so a bind that
|
|
148
|
+
excludes it is refused: it would leave those calls pointing at a dead port
|
|
149
|
+
while every bind check still passed.
|
|
150
|
+
|
|
151
|
+
To widen deliberately, pass the flag — or record it in config so the choice
|
|
152
|
+
survives `flair restart` / `flair upgrade`, neither of which takes the flag:
|
|
153
|
+
|
|
154
|
+
```bash
|
|
155
|
+
flair init --http-bind 0.0.0.0
|
|
156
|
+
```
|
|
140
157
|
|
|
141
158
|
```yaml
|
|
159
|
+
# ~/.flair/config.yaml — top-level, NOT nested under `http:`
|
|
160
|
+
httpBind: 0.0.0.0
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
> **`http.host` is not read.** Earlier versions of this page told you to widen
|
|
164
|
+
> the bind with a nested `http.host:` key. **Flair never read that key**, and
|
|
165
|
+
> from 0.55.0 it is ignored outright: an install that was only ever wide
|
|
166
|
+
> because the old default bound every interface will narrow to `127.0.0.1` on
|
|
167
|
+
> the next `flair restart` or `flair upgrade`. The block below is kept so this
|
|
168
|
+
> section stays findable from a snippet you may already have — **do not copy
|
|
169
|
+
> it**; use `httpBind:` (or `--http-bind` / `FLAIR_HTTP_BIND`) instead.
|
|
170
|
+
|
|
171
|
+
```yaml
|
|
172
|
+
# OLD — ignored by Flair. Replace with `httpBind:` as above.
|
|
142
173
|
http:
|
|
143
174
|
port: 19926
|
|
144
175
|
host: 0.0.0.0 # listen on all interfaces
|
|
@@ -154,7 +185,7 @@ All configuration lives in `~/.flair/`:
|
|
|
154
185
|
|
|
155
186
|
```
|
|
156
187
|
~/.flair/
|
|
157
|
-
├── config.yaml # port, host, embedding model
|
|
188
|
+
├── config.yaml # port, bind host, embedding model
|
|
158
189
|
├── data/ # Harper database
|
|
159
190
|
├── keys/ # Ed25519 keypairs per agent
|
|
160
191
|
└── backups/ # flair backup output
|
|
@@ -163,9 +194,10 @@ All configuration lives in `~/.flair/`:
|
|
|
163
194
|
### Key config options (`~/.flair/config.yaml`)
|
|
164
195
|
|
|
165
196
|
```yaml
|
|
166
|
-
http
|
|
167
|
-
|
|
168
|
-
|
|
197
|
+
# Top-level keys — Flair's config has no nested `http:` block, and no
|
|
198
|
+
# `http.host`.
|
|
199
|
+
port: 19926 # API port (ops port = this - 1)
|
|
200
|
+
httpBind: 127.0.0.1 # HTTP bind host (see "Direct network access" above)
|
|
169
201
|
|
|
170
202
|
clustering:
|
|
171
203
|
nodeName: flair
|
|
@@ -185,6 +217,7 @@ Set these in the Flair process environment (`~/Library/LaunchAgents/ai.tpsdev.fl
|
|
|
185
217
|
| `HDB_ADMIN_PASSWORD` | Bootstrap password for the embedded Harper. After first start, the persisted user record is the source of truth; rotate via the Harper ops API, not by changing this env var. | Set at install time. See [secrets-and-keys.md](secrets-and-keys.md) for rotation. |
|
|
186
218
|
| `FLAIR_KEY_PASSPHRASE` | Passphrase used to derive the AES-256-GCM key that wraps federation private-key seeds at rest. Auto-generated to `~/.flair/keys/.passphrase` if unset. | Set explicitly for production federation deployments so the passphrase isn't auto-generated and lost on disk wipe. |
|
|
187
219
|
| `HTTP_PORT` | Override the Harper HTTP port. Useful for sandboxes; production deployments should configure the port in `config.yaml` instead. | Rare. |
|
|
220
|
+
| `FLAIR_HTTP_BIND` | Bind address for the Harper **HTTP API**. Resolution order: `flair init --http-bind` > this variable > the top-level `httpBind` key `flair init` persists in `~/.flair/config.yaml` > `127.0.0.1`. Only `127.0.0.1` or a wildcard (`0.0.0.0` / `::`) is accepted — the listener must include IPv4 loopback for Flair's own `127.0.0.1` self-calls. Every Flair-managed Harper start re-asserts the resolved value, so the persisted key is what survives `flair restart` / `flair upgrade`. | Only for deployments that need the HTTP API reachable off-host — set it to `0.0.0.0`, or record it once with `flair init --http-bind 0.0.0.0`. Single-host installs want the loopback default. |
|
|
188
221
|
| `FLAIR_OPS_BIND` | Bind address for the Harper **ops API**. Resolution order: `flair init --ops-bind` > this variable > the `opsBind` key `flair init` persists in `~/.flair/config.yaml` > `127.0.0.1`. Every Flair-managed Harper start re-asserts the resolved value, so the persisted key is what makes a choice survive `flair restart` / `flair upgrade`. | Only for deployments that genuinely need remote ops admin (multi-host / Fabric) — set it to `0.0.0.0`, or record it once with `flair init --ops-bind 0.0.0.0`. Single-host installs want the loopback default. |
|
|
189
222
|
|
|
190
223
|
### Performance-related environment variables
|
|
@@ -194,7 +227,7 @@ These are read by the Harper process at boot (same places as the table above: la
|
|
|
194
227
|
| Variable | Default | What it does |
|
|
195
228
|
|----------|---------|--------------|
|
|
196
229
|
| `FLAIR_EMBED_THREADS` | `max(1, availableParallelism() − 1)` | CPU threads for in-process embedding (harper-fabric-embeddings / llama.cpp). Host-aware so a 4-core box does not inherit HFE's fixed 6, and an 8-vCPU ingest host is not stuck at 6 idle cores. One core is left for Harper's event loop and the OS. `availableParallelism()` respects a container CPU quota. Set a positive integer to pin. Invalid values fall back to the default. |
|
|
197
|
-
| `FLAIR_EMBED_GPU_LAYERS` |
|
|
230
|
+
| `FLAIR_EMBED_GPU_LAYERS` | derived: `99` when a usable Metal backend is present (darwin-arm64 + resolvable `@node-llama-cpp/mac-arm64-metal`), else `0` | Layers to offload to the GPU. Unset **derives** the default and states it on the boot log and `/Health` (`embedding.backend` / `gpuLayers` / `source`). `0` = pin CPU; `99` = full offload. Invalid values fall through to the derived default. If offload is requested and Metal does not engage, Health and the log state the CPU fallback — they never claim GPU for a CPU run. |
|
|
198
231
|
| `FLAIR_HYBRID_RETRIEVAL` | `true` | Hybrid BM25 + vector retrieval. Set `false` / `0` / `off` to revert to the legacy HNSW + keyword-bump path. |
|
|
199
232
|
| `FLAIR_MODELS_DIR` | `<data-dir>/models` | Directory the embedding GGUF is loaded from (and downloaded into on first boot). Point this at a pre-seeded directory to skip the HuggingFace download; see [troubleshooting.md](troubleshooting.md). |
|
|
200
233
|
|
package/docs/federation.md
CHANGED
|
@@ -4,14 +4,25 @@ Hub-and-spoke sync between Flair instances. A hub instance coordinates sync for
|
|
|
4
4
|
|
|
5
5
|
## Overview
|
|
6
6
|
|
|
7
|
-
Federation lets multiple Flair instances share memories, relationships, and agent records
|
|
7
|
+
Federation lets multiple Flair instances share memories, relationships, and agent records **in one direction per call**. Each instance maintains its own Ed25519 identity. Sync requests are signed and verified against pinned peer public keys.
|
|
8
8
|
|
|
9
9
|
```
|
|
10
|
-
Spoke A ──[
|
|
10
|
+
Spoke A ──[POST /FederationSync]──▶ Hub
|
|
11
|
+
Spoke B ──[POST /FederationSync]──▶ Hub
|
|
11
12
|
```
|
|
12
13
|
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
There is no hub → spoke arrow and no pull path. `FederationSync` declares `post()` only.
|
|
15
|
+
|
|
16
|
+
- **Hub:** accepts signed sync pushes from paired spokes. It does not push records back, and it does not expose a pull endpoint.
|
|
17
|
+
- **Spoke:** pushes local changes to the hub. It receives nothing back.
|
|
18
|
+
|
|
19
|
+
**Sync is push-only — one direction per call.** A spoke that needs hub (or other-spoke) data has no supported path today. The honest options:
|
|
20
|
+
|
|
21
|
+
1. **No downward path.** Do not plan on reading another instance's memories through the hub.
|
|
22
|
+
2. **Mutual pairing.** For records both ways, each instance pairs **as a spoke of the other** — two pairings, two tokens, two syncs. Same workaround as [deploying-on-fabric.md](deploying-on-fabric.md#federation-is-push-only) and [embedding-in-a-harper-app.md](embedding-in-a-harper-app.md#federation).
|
|
23
|
+
3. **Roadmap.** Deliberate hub-authorised downward flow is tracked in [#1452](https://github.com/tpsdev-ai/flair/issues/1452) (design) and the design frame on [#934](https://github.com/tpsdev-ai/flair/issues/934). This page does not claim that capability.
|
|
24
|
+
|
|
25
|
+
The `direction: "pull"` field written to `SyncLog` on the hub is the hub logging that *it received a push*. It is not a spoke fetching.
|
|
15
26
|
|
|
16
27
|
## Pairing a New Spoke (Bootstrap-User Flow)
|
|
17
28
|
|
|
@@ -187,7 +198,7 @@ Re-pairing an existing peer (same instance ID, same public key) does not require
|
|
|
187
198
|
|
|
188
199
|
### Originator enforcement
|
|
189
200
|
|
|
190
|
-
Spoke instances can only push records they originated. A spoke cannot overwrite records from another spoke or from the hub. The hub can
|
|
201
|
+
Spoke instances can only push records they originated. A spoke cannot overwrite records from another spoke or from the hub. The hub can accept a pushed record that originated on any instance. That is receive-side originator policy on a push, not a hub-to-spoke delivery path.
|
|
191
202
|
|
|
192
203
|
### Per-record signatures and principalId
|
|
193
204
|
|
|
@@ -264,7 +275,7 @@ schemas: **[docs/api-reference.md](api-reference.md#federation)**.
|
|
|
264
275
|
|
|
265
276
|
## Limitations (1.0)
|
|
266
277
|
|
|
267
|
-
- **HTTP push only** — no persistent WebSocket connections
|
|
278
|
+
- **HTTP push only** — no persistent WebSocket connections, no real-time sync, and no pull endpoint
|
|
268
279
|
- **Polled sync** — `flair federation sync enable` schedules a periodic one-shot (launchd / systemd, default 300s); there is no write-path trigger, so a new memory replicates on the next tick rather than immediately
|
|
269
|
-
- **Single hub** — spoke-to-spoke
|
|
280
|
+
- **Single hub, one-way** — spokes push to one hub; there is no spoke-to-spoke path and no hub-to-spoke pull
|
|
270
281
|
- **Record-level LWW** — not field-level; concurrent edits to different fields of the same record may lose data
|
package/docs/mcp-clients.md
CHANGED
|
@@ -43,6 +43,8 @@ Pick whichever you use. The MCP server is the same package; only the config synt
|
|
|
43
43
|
> **Pin the version.** An unpinned `@tpsdev-ai/flair-mcp` re-resolves to whatever is currently published on *every* agent session, so any future publish reaches your machine silently, with no lockfile and no review step in the path. `flair init` wires clients to a **pinned** spec on purpose, and every MCP-server config snippet below is written the same way: `@tpsdev-ai/flair-mcp@<version>`.
|
|
44
44
|
>
|
|
45
45
|
> Replace `<version>` with the version you intend to run — the one you already have is `flair --version` — and bump it deliberately. Leaving the literal `<version>` in place fails loudly at `npx`, which is the intended failure: better than a config that looks pinned and isn't. `flair init` is the easier path and fills this in for you.
|
|
46
|
+
>
|
|
47
|
+
> **Do not stay on a pin older than 0.18.0.** `@tpsdev-ai/flair-client` before 0.18.0 (and `@tpsdev-ai/flair-mcp` that shipped it) silently drops writes — including against another agent's shared memories — and a server upgrade does not fix that. `flair doctor` flags those pins; the remedy is `flair upgrade` (the adapter), not a newer Harper/Flair server alone. See [troubleshooting — silent write drop](troubleshooting.md#pre-0180-flair-client--flair-mcp-silently-drops-writes).
|
|
46
48
|
|
|
47
49
|
### Claude Code
|
|
48
50
|
|
|
@@ -92,7 +94,7 @@ symmetric with `flair hook uninstall`/`flair hook status`):
|
|
|
92
94
|
```bash
|
|
93
95
|
flair hook install # wires ~/.claude/settings.json for FLAIR_AGENT_ID/FLAIR_URL
|
|
94
96
|
flair hook install --dry-run # prints the exact JSON delta, writes nothing
|
|
95
|
-
flair hook status #
|
|
97
|
+
flair hook status # configured? hook command produced additionalContext? which agent/instance?
|
|
96
98
|
flair hook uninstall # removes only Flair's hook entry
|
|
97
99
|
```
|
|
98
100
|
|
|
@@ -136,7 +138,13 @@ manifests are not.
|
|
|
136
138
|
`flair hook status` recognises both the current pinned `-p` form and an older
|
|
137
139
|
unpinned `-p` invocation as `correctShape`. The pre-#1166 form (no `-p`, which
|
|
138
140
|
runs the MCP shim) is still flagged. Prefer `flair hook install` over
|
|
139
|
-
hand-editing.
|
|
141
|
+
hand-editing. A green status means the hook command **produced
|
|
142
|
+
additionalContext when run**, not that a line exists in the harness file
|
|
143
|
+
and not that the harness trusted or injected it (flair#1734). Final
|
|
144
|
+
delivery still depends on harness trust (re-approve in `/hooks`) and the
|
|
145
|
+
harness's own injection step. Configured-but-unverified (Codex untrusted,
|
|
146
|
+
hooks disabled, agent-id drift, empty bootstrap) is reported as such —
|
|
147
|
+
never an unqualified `✓ wired`.
|
|
140
148
|
|
|
141
149
|
The `sh -c ... || true` wrapper is not decoration. The invocation resolves a
|
|
142
150
|
package binary through whatever Node runtime your shell exposes, and under a
|
|
@@ -163,7 +171,9 @@ every session start (`startup`, `resume`, `clear`, `compact`); add
|
|
|
163
171
|
|
|
164
172
|
It honors the same env as the MCP server (`FLAIR_AGENT_ID`, `FLAIR_URL`,
|
|
165
173
|
`FLAIR_KEY_PATH`), plus `FLAIR_HOOK_TIMEOUT_MS` (default 8000, clamped
|
|
166
|
-
500–30000) for the bootstrap timeout.
|
|
174
|
+
500–30000) for the bootstrap timeout. Codex's installer also sets
|
|
175
|
+
`FLAIR_HOOK_HARNESS=codex` so bootstrap records the Codex channel; the
|
|
176
|
+
stdout contract stays `hookSpecificOutput.additionalContext`.
|
|
167
177
|
|
|
168
178
|
**It degrades to a no-op, always.** No `FLAIR_AGENT_ID`, Flair down, an auth
|
|
169
179
|
error, or a hung daemon (past the timeout) → the hook prints `{}` and exits 0.
|
|
@@ -232,9 +242,12 @@ flair hook status --harness codex
|
|
|
232
242
|
flair hook uninstall --harness codex
|
|
233
243
|
```
|
|
234
244
|
|
|
235
|
-
`flair doctor` reports this hook when Codex is detected.
|
|
236
|
-
|
|
237
|
-
|
|
245
|
+
`flair doctor` reports this hook when Codex is detected. `flair hook install
|
|
246
|
+
--harness codex` writes `FLAIR_HOOK_HARNESS=codex` and keeps hook stderr
|
|
247
|
+
visible (auth failures must not be swallowed). After install, **re-approve**
|
|
248
|
+
the command in Codex with `/hooks` — a wiring change resets trust, and
|
|
249
|
+
untrusted hooks are listed and skipped. `flair hook status --harness codex`
|
|
250
|
+
reports that pending-approval state as configured but delivery not verified.
|
|
238
251
|
|
|
239
252
|
---
|
|
240
253
|
|