@tpsdev-ai/flair 0.54.1 → 0.55.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/dist/build-info.json +3 -3
  2. package/dist/cli.js +774 -176
  3. package/dist/commands/doctor.js +73 -2
  4. package/dist/commands/federation.js +131 -36
  5. package/dist/commands/hook.js +20 -10
  6. package/dist/commands/init.js +193 -67
  7. package/dist/commands/service.js +16 -12
  8. package/dist/commands/soul.js +10 -5
  9. package/dist/commands/status.js +80 -8
  10. package/dist/commands/upgrade.js +41 -5
  11. package/dist/doctor-client.js +118 -32
  12. package/dist/engine-version.js +12 -4
  13. package/dist/fabric-upgrade.js +30 -15
  14. package/dist/hook-install.js +170 -16
  15. package/dist/lib/doctor-run.js +49 -3
  16. package/dist/lib/embed-gpu-doctor.js +30 -0
  17. package/dist/lib/federation-pair-access.js +118 -0
  18. package/dist/lib/harper-port-value.js +43 -0
  19. package/dist/lib/http-bind.js +227 -0
  20. package/dist/lib/init-admin-pass.js +316 -0
  21. package/dist/lib/launchd-management.js +16 -0
  22. package/dist/lib/launchd-repair.js +122 -1
  23. package/dist/lib/npm-registry.js +578 -0
  24. package/dist/lib/owned-pins.js +54 -1
  25. package/dist/lib/process-start-time.js +82 -0
  26. package/dist/lib/scratch-owner.js +124 -10
  27. package/dist/lib/stale-client-pin.js +26 -0
  28. package/dist/rem/runner.js +10 -1
  29. package/dist/resources/AdminInstance.js +8 -2
  30. package/dist/resources/Memory.js +36 -1
  31. package/dist/resources/MemoryBootstrap.js +23 -32
  32. package/dist/resources/MemoryFeed.js +4 -1
  33. package/dist/resources/MemoryReflect.js +121 -93
  34. package/dist/resources/SkillScan.js +13 -11
  35. package/dist/resources/Soul.js +15 -1
  36. package/dist/resources/XAA.js +16 -1
  37. package/dist/resources/a2a-url.js +5 -2
  38. package/dist/resources/client-version-gate.js +144 -0
  39. package/dist/resources/embed-gpu.js +241 -0
  40. package/dist/resources/embeddings-boot.js +34 -42
  41. package/dist/resources/federation-peer-liveness.js +7 -1
  42. package/dist/resources/health.js +12 -3
  43. package/dist/resources/mcp-tools.js +8 -3
  44. package/dist/resources/memory-reflect-lib.js +66 -0
  45. package/dist/resources/memory-reflect-models.js +9 -0
  46. package/dist/resources/migrations/embedding-stamp.js +32 -4
  47. package/dist/resources/oauth-discovery.js +3 -1
  48. package/dist/resources/record-type-kit.js +59 -0
  49. package/dist/resources/scan/skill-markdown.js +166 -0
  50. package/dist/resources/scan/skill-scanner.js +89 -68
  51. package/dist/resources/skill-provenance.js +273 -0
  52. package/dist/resources/skill-write.js +26 -7
  53. package/{node_modules/@tpsdev-ai/flair-tool-descriptors/dist → dist/resources/tool-descriptors}/index.js +4 -0
  54. package/dist/src/lib/harper-port-value.js +43 -0
  55. package/dist/version-check.js +29 -8
  56. package/docs/api-reference.md +35 -2
  57. package/docs/deployment.md +1 -1
  58. package/docs/federation.md +18 -7
  59. package/docs/mcp-clients.md +19 -6
  60. package/docs/releasing.md +96 -24
  61. package/docs/rem.md +1 -1
  62. package/docs/secrets-and-keys.md +1 -0
  63. package/docs/standalone-local.md +1 -1
  64. package/docs/troubleshooting.md +17 -0
  65. package/package.json +4 -9
  66. package/node_modules/@tpsdev-ai/flair-tool-descriptors/LICENSE +0 -19
  67. package/node_modules/@tpsdev-ai/flair-tool-descriptors/README.md +0 -22
  68. package/node_modules/@tpsdev-ai/flair-tool-descriptors/dist/index.d.ts +0 -70
  69. package/node_modules/@tpsdev-ai/flair-tool-descriptors/package.json +0 -46
@@ -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 three write-side rules that make a skill-tagged
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 the combined
89
- * `trigger` + `content` text (a dangerous shell/network payload in EITHER is
90
- * a rejection). Fail-closed on high/critical risk; allow-with-flag on medium
91
- * (findings appended to `_safetyFlags`); a clean scan is a no-op.
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 = scanSkillContent(parts.join("\n\n"));
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",
@@ -1,3 +1,7 @@
1
+ // ⚠️ GENERATED FILE — DO NOT EDIT, DO NOT COMMIT (flair#1683).
2
+ // Verbatim build-time copy of packages/flair-tool-descriptors/src/index.ts, the single source of truth.
3
+ // Regenerated by scripts/vendor-tool-descriptors.mjs (see each package's
4
+ // `prebuild`). Edit the source, not this copy.
1
5
  /**
2
6
  * Transport-agnostic MCP tool descriptors (flair#1580).
3
7
  *
@@ -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
+ }
@@ -32,6 +32,7 @@ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
32
32
  import { homedir } from "node:os";
33
33
  import { dirname, join } from "node:path";
34
34
  import { parseSemverCore } from "./fabric-upgrade.js";
35
+ import { fetchLatestVersion } from "./lib/npm-registry.js";
35
36
  export const FLAIR_PKG_NAME = "@tpsdev-ai/flair";
36
37
  export const DEFAULT_CACHE_PATH = join(homedir(), ".flair", ".version-check-cache.json");
37
38
  /** How long a cached "latest" answer is trusted before we re-hit the registry. */
@@ -65,19 +66,39 @@ function writeCacheFile(path, entry) {
65
66
  }
66
67
  async function defaultFetchLatest(timeoutMs) {
67
68
  try {
68
- const res = await fetch(`https://registry.npmjs.org/${FLAIR_PKG_NAME}/latest`, {
69
- signal: AbortSignal.timeout(timeoutMs),
70
- });
71
- if (!res.ok)
69
+ // flair#1688: honour the registry npm is configured to use (scoped
70
+ // `@scope:registry`, project/user/global .npmrc, env `npm_config_registry`)
71
+ // rather than a hardcoded public host — a private mirror must not be
72
+ // silently bypassed by the update check.
73
+ //
74
+ // flair#1692: `fetchLatestVersion` validates the URL scheme, refuses
75
+ // redirects, applies npm's transport where a bare fetch cannot, and —
76
+ // critically — validates the returned value as strict semver before it can
77
+ // ever be used as an install spec.
78
+ const result = await fetchLatestVersion(FLAIR_PKG_NAME, { timeoutMs });
79
+ if (result.kind === "ok")
80
+ return result.version;
81
+ if (result.kind === "invalid") {
82
+ // A hostile/compromised registry can return a URL or tag as `latest`;
83
+ // npm would install `pkg@<url>` as a remote tarball. Refuse, and say so
84
+ // rather than silently treating it as "no update".
85
+ console.error(`flair version check: the configured registry returned a non-semver "latest" (${JSON.stringify(result.value)}) ` +
86
+ `from ${result.registry.url} — refusing to use it. Check \`registry\` / \`@scope:registry\` (source: ${result.registry.source}).`);
72
87
  return null;
73
- const data = (await res.json());
74
- return typeof data?.version === "string" ? data.version : null;
75
- }
76
- catch {
88
+ }
89
+ if (result.kind === "refused") {
90
+ console.error(result.message);
91
+ return null;
92
+ }
77
93
  // Offline, DNS failure, timeout, registry 5xx, bad JSON — all the same:
78
94
  // we couldn't determine "latest" over the network this time.
79
95
  return null;
80
96
  }
97
+ catch {
98
+ // Defense-in-depth: the helper already swallows its failure modes. This
99
+ // guards the status/doctor never-throws contract even if it does not.
100
+ return null;
101
+ }
81
102
  }
82
103
  export function defaultVersionCheckDeps() {
83
104
  return {
@@ -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 |
@@ -194,7 +194,7 @@ These are read by the Harper process at boot (same places as the table above: la
194
194
  | Variable | Default | What it does |
195
195
  |----------|---------|--------------|
196
196
  | `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` | unset (HFE default `0`, CPU only) | Layers to offload to the GPU. **Unset omits the field** so harper-fabric-embeddings keeps its own default of 0. This is a pin for measurement (the ingest-throughput bench, flair#1436), not a new product default — #1437 is the detect-and-default decision. `0` = CPU; `99` = full offload (Metal on mac-arm64). Invalid values fall through to omit. |
197
+ | `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
198
  | `FLAIR_HYBRID_RETRIEVAL` | `true` | Hybrid BM25 + vector retrieval. Set `false` / `0` / `off` to revert to the legacy HNSW + keyword-bump path. |
199
199
  | `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
200
 
@@ -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. Each instance maintains its own Ed25519 identity. Sync requests are signed and verified against pinned peer public keys.
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 ──[signed sync]──▶ Hub ◀──[signed sync]── Spoke B
10
+ Spoke A ──[POST /FederationSync]──▶ Hub
11
+ Spoke B ──[POST /FederationSync]──▶ Hub
11
12
  ```
12
13
 
13
- - **Hub:** accepts sync pushes from paired spokes, can relay records between peers
14
- - **Spoke:** pushes local changes to the hub, receives changes from other spokes via the hub
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 relay records from any origin.
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 or real-time sync
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 sync goes through the hub
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
@@ -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 # wired? correct shape? which agent/instance?
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. After install, trust
236
- the new command in Codex with `/hooks` — untrusted hooks are listed and
237
- skipped.
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
 
package/docs/releasing.md CHANGED
@@ -2,21 +2,36 @@
2
2
 
3
3
  Flair publishes nine workspace packages to npm under `@tpsdev-ai/*`. Releases are
4
4
  **tokenless** and **staged**: CI authenticates to npm with a short-lived OIDC token
5
- (no `NPM_TOKEN` lives anywhere) and submits each package to npm's **staging** area.
6
- A maintainer then approves the staged tarballs on npmjs.com with 2FA to make them live.
5
+ (no `NPM_TOKEN` lives anywhere) and submits each package to npm's **staging** area
6
+ **under the `staged` tag** (never straight to `latest`). A maintainer then approves
7
+ the staged tarballs on npmjs.com with 2FA. Approval makes the version public, but
8
+ **not `latest`** — a credential-less post-publish canary installs that exact version
9
+ from the registry and boots it on Linux and macOS. Only a canary PASS prints the
10
+ sha256-bound promote command that moves `latest`; the canary runs on the same
11
+ definition of "it boots" the rockit ritual uses (`scripts/ci/check-instance-boot.sh`).
12
+
13
+ The staging tag is an **immutable property of the staged package** (`npm help stage`):
14
+ re-staging the same version under a different tag requires `npm stage reject` first.
15
+ There is no "fix the stage in place" — you reject it and re-cut the next patch.
7
16
 
8
17
  > `flair-bench` is version-bumped and tagged in lockstep with the other 7, and stages in
9
18
  > its own step in CI for [historical reasons](#flair-bench-bootstrap-one-time-done). That
10
19
  > step is no longer allowed to fail: every already-published package must stage
11
- > for a release to pass. `@tpsdev-ai/flair-tool-descriptors` is the one
12
- > first-publish exception until an npm org owner bootstraps it.
20
+ > for a release to pass.
13
21
 
14
22
  ```
15
- merge release PR ──▶ push tag v0.11.0 ──▶ CI stages all packages ──▶ npm staging
23
+ merge release PR ──▶ push tag v0.11.0 ──▶ CI stages all packages (tag: staged)
16
24
  │
17
25
  maintainer reviews + approves (2FA)
18
26
  ▼
19
- live on npm
27
+ public on npm, NOT latest ──▶ post-publish canary
28
+ │ installs the exact
29
+ │ version + boots it
30
+ canary PASS ───────┘
31
+ │
32
+ paste the emitted promote line
33
+ ▼
34
+ latest moves
20
35
  ```
21
36
 
22
37
  Pushing a `vX.Y.Z` tag triggers the release. This replaces the old "run
@@ -112,18 +127,67 @@ review each staged tarball, and approve with 2FA. Or from a machine logged into
112
127
  ```bash
113
128
  npm stage list # show staged packages + their stage-ids
114
129
  npm stage view <stage-id> # inspect one
115
- npm stage approve <stage-id> # 2FA prompt; package goes live
130
+ npm stage approve <stage-id> # 2FA prompt; package is made public under `staged`
116
131
  ```
117
132
 
118
133
  There are eight lockstep-staged packages, so eight approvals (the web UI lists them on
119
134
  one page). Approve in dependency order if installing immediately — flair-client before
120
135
  its dependents — though staging does not itself resolve dependencies.
121
136
 
122
- Verify when done:
123
-
124
- ```bash
125
- npm view @tpsdev-ai/flair version # should report the new version
126
- ```
137
+ Approval makes each version **public but not `latest`**: a user who runs the bare
138
+ `npm install -g @tpsdev-ai/flair` still gets the previous `latest` until the promote
139
+ step below. That window is what the canary uses.
140
+
141
+ The staging tag is immutable — if a staged package is wrong, **reject** it
142
+ (`npm stage reject <stage-id>` on npmjs.com) and cut the next patch. The same version
143
+ cannot be re-staged under a different tag.
144
+
145
+ ### Phase 4 — run the post-publish canary
146
+
147
+ The moment the staged packages are approved, dispatch the
148
+ [`post-publish canary`](../.github/workflows/canary.yml) (Actions → "Post-publish canary
149
+ — install + boot a published version") with two inputs:
150
+
151
+ | Input | Value |
152
+ | ----- | ----- |
153
+ | `version` | the version just approved, exact (e.g. `vX.Y.Z` without the `v`) |
154
+ | `expected_sha256` | the published tarball's sha256 (64 hex). The canary computes it from the registry with `node scripts/ci/registry-tarball-sha256.mjs <ver>`. |
155
+
156
+ The canary runs on clean `ubuntu-latest` and `macos-latest` runners and is
157
+ **credential-less**: it installs `@tpsdev-ai/flair@<ver>` by exact version from the
158
+ public registry, downloads the published tarball and verifies its sha256 equals
159
+ `expected_sha256` (npm exposes no sha256 directly — `dist.shasum` is a SHA-1), runs
160
+ the four install-tree assertions (`scripts/check-global-install-lockfile.mjs
161
+ --registry-version`), and boots the installed instance
162
+ (`scripts/ci/check-instance-boot.sh`: init with a 0600 pass file → adopt → `/Health`
163
+ from the supervised process → `flair doctor` → descriptors → clean stop).
164
+
165
+ It then installs the published `@tpsdev-ai/flair-mcp@<ver>` and
166
+ `@tpsdev-ai/flair-client@<ver>` (exact version, never a dist-tag) into a throwaway
167
+ prefix, writes the documented host config (`npx -y @tpsdev-ai/flair-mcp@<ver>`),
168
+ and drives a real `memory_store` → `memory_get` tool-call against the canary-booted
169
+ instance (`scripts/ci/check-plugin-canary.mjs`). That is the path a host actually
170
+ runs — not an in-process import of this checkout. A missing registry package, a
171
+ host that never comes up, or any other unmeasurable result is a FAIL, not a skip.
172
+
173
+ Nothing about the canary is optional. There is no `continue-on-error`, and an
174
+ unmeasurable run (registry lag, runner outage) is a FAIL, not a skip — a check that did
175
+ not run must not read as a pass.
176
+
177
+ ### Phase 5 — promote `latest` (or deprecate)
178
+
179
+ - **On PASS**, the canary emits the complete, sha256-bound promote command. Run it
180
+ from a repo checkout on a machine logged into npm:
181
+
182
+ ```bash
183
+ test "$(node scripts/ci/registry-tarball-sha256.mjs <ver>)" = "<sha256>" && npm dist-tag add @tpsdev-ai/flair@<ver> latest
184
+ ```
185
+
186
+ The `test` is the integrity guard: a stale PASS, a re-cut version, or a paste from a
187
+ failed run aborts before `latest` moves.
188
+ - **On FAIL**, the version stays public but unpromoted. The canary emits the
189
+ `npm deprecate` command; run it, then re-cut the next patch. A version is never
190
+ refreshed in place.
127
191
 
128
192
  ## One-time setup
129
193
 
@@ -147,17 +211,15 @@ Leave `npm publish` **unchecked** under allowed actions. This structurally preve
147
211
  CI/OIDC identity from publishing anything live directly — the only path to live is the
148
212
  human 2FA approval of a staged package.
149
213
 
150
- Packages: `flair-client`, `flair-tool-descriptors`, `flair-mcp`, `flair`,
214
+ Packages: `flair-client`, `flair-mcp`, `flair`,
151
215
  `openclaw-flair`, `pi-flair`, `n8n-nodes-flair`, `langgraph-flair`, `flair-bench`.
152
216
 
153
- > A package must already exist on npm before a trusted publisher can be added.
154
- > `@tpsdev-ai/flair-tool-descriptors` (flair#1580) is the next first-publish:
155
- > stage it with the dedicated continue-on-error step, then an npm org owner
156
- > publishes once and registers its Trusted Publisher (same playbook as
157
- > `flair-bench` below). Until that exists on the registry, `@tpsdev-ai/flair`
158
- > and `@tpsdev-ai/flair-mcp` tarballs bundle it (`bundleDependencies` +
159
- > `scripts/materialize-bundled-descriptors.mjs`) so `npm install` of those
160
- > tarballs does not 404.
217
+ > `flair-tool-descriptors` is private and never published. Since flair#1683 it is a
218
+ > **build-time source**: `scripts/vendor-tool-descriptors.mjs` copies it into each
219
+ > consumer's own tree at prebuild (`resources/tool-descriptors/` for `flair`,
220
+ > `packages/flair-mcp/src/tool-descriptors/` for `flair-mcp`) and the consumers
221
+ > import it by relative path. Nothing declares or bundles it as a dependency —
222
+ > 0.54.1's `bundleDependencies` broke fresh global installs (flair#1681 → #1683).
161
223
 
162
224
  ### `flair-bench` bootstrap (one-time, done)
163
225
 
@@ -196,6 +258,15 @@ review. Because the release is triggered by a tag push, its deployment policy mu
196
258
  **`v*` tags** (Settings → Environments → `release` → Deployment branches and tags →
197
259
  Selected branches and tags → add tag rule `v*`).
198
260
 
261
+ ### Required status checks (ruleset)
262
+
263
+ Add **`First-publish preflight`** to the main branch ruleset's required status
264
+ checks (repo settings → Rules → main). This is a repo-settings act, not a code
265
+ change: until it is listed, the release-PR job is **advisory only** and a red
266
+ first-publish preflight can be merged past. The tag-triggered
267
+ `release-publish.yml` also runs the same check before staging, so a hazard is
268
+ still stopped on the normal release path either way.
269
+
199
270
  ### Approver 2FA
200
271
 
201
272
  The maintainer who approves staged packages must have 2FA enabled on their npm account.
@@ -204,9 +275,10 @@ The maintainer who approves staged packages must have 2FA enabled on their npm a
204
275
 
205
276
  - **A staged package looks wrong** — reject it on npmjs.com instead of approving; it
206
277
  never goes live. Fix forward on `main` and cut a new patch version.
207
- - **Re-run the stage for the same version** — delete and re-push the tag
208
- (`git push origin :v0.11.0` then `git tag -f v0.11.0 && git push origin v0.11.0`).
209
- The tag push re-triggers the workflow.
278
+ - **Re-run the stage for the same version** — you cannot. The `staged` tag is an
279
+ immutable property of the staged package, so re-stage requires reject first. Reject
280
+ the staged package(s) on npmjs.com, then cut and tag the next patch version; a
281
+ re-pushed tag re-triggers the workflow for that new version.
210
282
  - **Break-glass (CI down):** `./scripts/release.sh X.Y.Z --publish` still works from a
211
283
  machine logged into npm. Prefer the staged flow; this bypasses the staging gate.
212
284
 
package/docs/rem.md CHANGED
@@ -56,7 +56,7 @@ Snapshot locality follows from this: a nightly cycle's pre-run snapshot (`~/.fla
56
56
 
57
57
  ## Interactive vs nightly
58
58
 
59
- - **Interactive (`flair rem rapid`):** one bounded, synchronous distillation call — gather cap 50 memories, bounded output tokens, seconds not minutes. Executes by default, staging candidates and printing a summary; `--prompt-only` returns the reflection prompt instead, for the bring-your-own-model handoff.
59
+ - **Interactive (`flair rem rapid`):** one bounded, synchronous distillation call — gather cap 50 memories, bounded output tokens, seconds not minutes. Executes by default, staging candidates and printing a summary; `--prompt-only` returns the reflection prompt instead, for the bring-your-own-model handoff. A cold generative backend (first Ollama model load) is warmed outside Harper's request transaction so execute fails as the documented 502/503, not HTTP 422 from the 30s open-transaction ceiling.
60
60
  - **Nightly (`flair rem nightly enable` / `run-once`):** fully detached — the scheduler runs the full cycle (snapshot → maintenance → distillation), candidates land as pending rows, and an audit row lands in `~/.flair/logs/rem-nightly.jsonl`. The operator reviews in the morning via `flair rem candidates`.
61
61
 
62
62
  ### Safety bounds (a large backlog must not take the instance down)
@@ -18,6 +18,7 @@ Agents sign every request to Flair with this key. Flair refuses unsigned request
18
18
  - The `--admin-pass-file <path>` option allows reading the password from a file (for pre-staged secrets).
19
19
  - The `--admin-pass <pass>` option is deprecated due to shell history exposure; use `--admin-pass-file` or environment variables instead. A warning is printed when this option is used.
20
20
  - Environment variables `FLAIR_ADMIN_PASS` and `HDB_ADMIN_PASSWORD` are also supported.
21
+ - After the first start, Harper's persisted user hash is the source of truth. `HDB_ADMIN_PASSWORD` will not rotate it. If `~/.flair/admin-pass` is missing and the data dir already has a user, `flair init` refuses rather than writing a file that 401s. Recovery is exact: `flair init --admin-pass-file <path>` if you have the original, or `flair init --reset-admin-pass` to rotate through the operations socket and rewrite the file.
21
22
  ## What Flair does *not* own: API keys, tokens, third-party credentials
22
23
 
23
24
  Things that are NOT Flair's job:
@@ -109,7 +109,7 @@ logging:
109
109
  | `FLAIR_KEY_PASSPHRASE` | Passphrase for AES-256-GCM encryption of federation private-key seeds. | Set explicitly for production federation deployments. |
110
110
  | `FLAIR_URL` | Override the Flair base URL for CLI commands (points to a remote instance). | When connecting from a different machine. |
111
111
  | `FLAIR_EMBED_THREADS` | CPU threads for in-process embedding. Default is `max(1, availableParallelism() − 1)` — host-aware, one core left for Harper. | Pin a positive integer on a dedicated ingest host, or when the default leaves cores idle / oversubscribed. See [deployment.md](deployment.md#performance-related-environment-variables). |
112
- | `FLAIR_EMBED_GPU_LAYERS` | GPU layers to offload. Unset leaves HFE's default of 0 (CPU only) — this is a pin, not a new default. | Only to measure Metal offload (`99`) or pin CPU (`0`). See [deployment.md](deployment.md#performance-related-environment-variables) and #1437. |
112
+ | `FLAIR_EMBED_GPU_LAYERS` | GPU layers to offload. Unset derives Metal (`99`) on Apple Silicon with a usable Metal prebuilt, else CPU (`0`). Stated on `/Health`. | Pin CPU with `0` on a Metal Mac, or force a layer count. See [deployment.md](deployment.md#performance-related-environment-variables). |
113
113
  | `FLAIR_HYBRID_RETRIEVAL` | Hybrid BM25 + vector retrieval (default on). | Set `false` to revert to HNSW-only. |
114
114
  | `FLAIR_MODELS_DIR` | Directory the embedding GGUF is loaded from. | When the model lives outside `<data-dir>/models`. |
115
115
 
@@ -8,6 +8,23 @@ flair doctor
8
8
 
9
9
  ## Common Issues
10
10
 
11
+ ### Pre-0.18.0 flair-client / flair-mcp silently drops writes
12
+
13
+ **Symptoms:** `memory_store` comes back as if it stored something (`written: false`, a `mergedWith` id, or a "deduplicated" record you did not write) and **zero rows** appear for the writing agent. The match it folded into can be **another agent's `shared` memory**. `flair doctor` after this server version names the pin.
14
+
15
+ **This is not fixed by upgrading the server.** An `@tpsdev-ai/flair-client` older than 0.18.0 (shipped inside `@tpsdev-ai/flair-mcp` ≤ 0.17, and still live in stale adapter pins) runs a cosine-only preflight and returns the existing record **without ever issuing the PUT**. The server cannot run its cosine-AND-Jaccard gate on a request that never arrives.
16
+
17
+ **Fix — upgrade the adapter:**
18
+
19
+ ```bash
20
+ flair upgrade
21
+ # or pin the MCP server / client library yourself
22
+ # @tpsdev-ai/flair-mcp@<current> (must be >= 0.18.0)
23
+ # @tpsdev-ai/flair-client@<current>
24
+ ```
25
+
26
+ Then restart the MCP host so it respawns `flair-mcp`. A current server that *sees* a client older than 0.18.0 on a Memory write (`X-Flair-Client: flair-client/0.17.0`) refuses it with HTTP 426 `stale_flair_client` instead of serving silent loss.
27
+
11
28
  ### "Harper is not running"
12
29
 
13
30
  **Symptoms:** `flair status` shows not running, bootstrap fails.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tpsdev-ai/flair",
3
- "version": "0.54.1",
3
+ "version": "0.55.0",
4
4
  "packageManager": "bun@1.3.10",
5
5
  "description": "Identity, memory, and soul for AI agents. Cryptographic identity (Ed25519), semantic memory with local embeddings, and persistent personality — all in a single process.",
6
6
  "type": "module",
@@ -46,11 +46,10 @@
46
46
  ],
47
47
  "scripts": {
48
48
  "clean": "node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\"",
49
- "prebuild": "npm run clean && cd packages/flair-tool-descriptors && npm run build",
49
+ "prebuild": "npm run clean && node scripts/vendor-tool-descriptors.mjs",
50
50
  "build": "tsc -p tsconfig.json --noCheck && node scripts/write-build-info.mjs",
51
51
  "build:cli": "tsc -p tsconfig.cli.json --noCheck && node scripts/write-build-info.mjs",
52
- "prepack": "node scripts/materialize-bundled-descriptors.mjs",
53
- "prepublishOnly": "npm run build && npm run build:cli",
52
+ "prepack": "npm run build && npm run build:cli",
54
53
  "test": "bun run test:unit",
55
54
  "test:unit": "bun scripts/test-unit.ts",
56
55
  "test:e2e": "playwright test",
@@ -72,12 +71,8 @@
72
71
  "jose": "6.2.2",
73
72
  "js-yaml": "^4.3.2",
74
73
  "tar": "^7.5.22",
75
- "tweetnacl": "1.0.3",
76
- "@tpsdev-ai/flair-tool-descriptors": "0.54.1"
74
+ "tweetnacl": "1.0.3"
77
75
  },
78
- "bundleDependencies": [
79
- "@tpsdev-ai/flair-tool-descriptors"
80
- ],
81
76
  "overrides": {
82
77
  "react-native-fs": "npm:empty-npm-package@1.0.0",
83
78
  "brace-expansion": "^5.0.9",