@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
package/README.md
CHANGED
|
@@ -49,7 +49,7 @@ boost. Hybrid search combines semantic and lexical ranks to order results, so th
|
|
|
49
49
|
first result need not have the highest percentage or be near 100%. The percentage
|
|
50
50
|
is not a probability that the memory answers your question correctly.
|
|
51
51
|
|
|
52
|
-
`flair init
|
|
52
|
+
`flair init --agent <id>` installs or reuses Harper, creates or reuses the agent's Ed25519 keypair, and checks semantic search. When wiring is enabled, it attempts to wire detected clients and may run an MCP smoke test for MCP client wiring.
|
|
53
53
|
|
|
54
54
|
> **Pass `--agent`.** A bare `flair init` bootstraps the instance and stops there — no agent, no keypair, no MCP wiring.
|
|
55
55
|
|
|
@@ -64,8 +64,7 @@ Full walkthrough with expected output at every step: **[docs/quickstart.md](docs
|
|
|
64
64
|
Two MCP paths, on purpose. A client on this machine and a remote connector are different trust situations, and each has its own mechanism. The write-up that joins them is [docs/mcp-clients.md — Two MCP paths](docs/mcp-clients.md#two-mcp-paths).
|
|
65
65
|
|
|
66
66
|
- **Local client: the `npx` stdio adapter.** `@tpsdev-ai/flair-mcp` is a separate package and is not installed globally. `flair init` writes `npx -y @tpsdev-ai/flair-mcp@<version>` into each client's config, pinned to the CLI's own version. The adapter signs requests with the agent's Ed25519 key and sends them to `FLAIR_URL`. Loopback HTTP is the right scheme on this machine (the default is `http://127.0.0.1:19926`). A remote `FLAIR_URL` should use HTTPS. This is the path for Claude Code, Cursor, Codex, Gemini, and every other local MCP client.
|
|
67
|
-
- **Remote client: native `/mcp`.** A JSON-RPC endpoint inside the server, OAuth bearer, exposing
|
|
68
|
-
|
|
67
|
+
- **Remote client: native `/mcp`.** A JSON-RPC endpoint inside the server, OAuth bearer, exposing the curated tools that the JSON-RPC `tools/list` method on `/mcp` returns. It is off by default: an unset `FLAIR_MCP_OAUTH` leaves `/mcp` unregistered; a truthy flag and a configured issuer make Flair attempt to mount it, while only the literal value `true` also enables the OAuth component. `true` is the value that turns on both Flair's route and the OAuth component; `1`, `yes`, and `on` leave the component off and every call 401s. OAuth client-metadata is fetched over HTTPS and refuses a private, loopback, or link-local host, and `flair mcp enable` refuses a local origin (localhost, loopback, RFC1918, IPv4 link-local, `.local`). Remote connectors need a publicly reachable HTTPS origin; `flair mcp enable` refuses local origins, but route registration itself does not enforce a public HTTPS issuer.
|
|
69
68
|
`@tpsdev-ai/flair-client` is likewise its own package: add it to a project when you want to call Flair from your own code ([JavaScript / TypeScript](#javascript--typescript)).
|
|
70
69
|
|
|
71
70
|
### Where the agent's key lives
|
|
@@ -79,10 +78,10 @@ Keys are how an agent *outside* the process proves who it is. Code running insid
|
|
|
79
78
|
### Useful flags
|
|
80
79
|
|
|
81
80
|
```bash
|
|
82
|
-
flair init --client claude-code
|
|
83
|
-
flair init --no-mcp
|
|
84
|
-
flair init --skip-soul
|
|
85
|
-
flair init --port 8000
|
|
81
|
+
flair init --agent mybot --client claude-code # attempt to wire one client
|
|
82
|
+
flair init --agent mybot --no-mcp # register the agent; skip MCP wiring
|
|
83
|
+
flair init --agent mybot --skip-soul # skip the personality wizard
|
|
84
|
+
flair init --agent mybot --port 8000 # use a non-default port
|
|
86
85
|
```
|
|
87
86
|
|
|
88
87
|
### Lifecycle
|
|
@@ -148,7 +147,7 @@ One Ed25519 identity, one memory store, three MCP-capable CLIs. A memory written
|
|
|
148
147
|
└──────────────────────────────────────────────────────────────────┘
|
|
149
148
|
```
|
|
150
149
|
|
|
151
|
-
|
|
150
|
+
Choose your harness from the [full integrations catalog →](docs/integrations.md).
|
|
152
151
|
|
|
153
152
|
## How it works
|
|
154
153
|
|
|
@@ -200,7 +199,7 @@ Every product here does semantic recall over stored memories. These are the dime
|
|
|
200
199
|
|---|---|---|---|---|---|---|
|
|
201
200
|
| **Where memories live** | infrastructure you run | self-host or Mem0 Cloud | self-host or hosted API | self-host or Letta Cloud | SageOx cloud | vendor cloud |
|
|
202
201
|
| **Memory is scoped to** | the agent, via an Ed25519 keypair | tenant / user | per-user tenant | the runtime | the team | the account |
|
|
203
|
-
| **Reaches other orchestrators** |
|
|
202
|
+
| **Reaches other orchestrators** | Coding assistants, workflow engines, and agent frameworks ([catalog](docs/integrations.md)) | several | several | Letta's runtime | 14+ coding agents and editors, via hooks, plugins and instruction files | no |
|
|
204
203
|
| **Sync between instances you run** | hub/spoke federation | no | no | no | one hosted service | one hosted service |
|
|
205
204
|
| **Captures in-person conversation** | no | no | no | no | yes — Ox Dot | no |
|
|
206
205
|
| **Per-agent persistent character** | first-class (Soul) | optional | persona-shaped | optional | team context, not per-agent | no |
|
|
@@ -213,7 +212,7 @@ Flair works with any agent runtime. Pick the path that fits yours — **[full ca
|
|
|
213
212
|
|
|
214
213
|
### Claude Code / Cursor / Codex CLI / Gemini CLI (MCP)
|
|
215
214
|
|
|
216
|
-
`flair init
|
|
215
|
+
`flair init --agent <id>` attempts to wire detected clients when wiring is enabled. To configure one by hand:
|
|
217
216
|
|
|
218
217
|
```json
|
|
219
218
|
// .mcp.json in your project root (Claude Code / Cursor format)
|
|
@@ -244,7 +243,7 @@ Per-CLI config snippets (Gemini CLI's `~/.gemini/settings.json`, Codex CLI's `~/
|
|
|
244
243
|
openclaw plugins install @tpsdev-ai/openclaw-flair
|
|
245
244
|
```
|
|
246
245
|
|
|
247
|
-
Auto-detects the agent identity, provides `memory_store` / `
|
|
246
|
+
Auto-detects the agent identity, provides `memory_store` / `memory_search` / `memory_get`, and provides bootstrap context from `before_prompt_build` (requires host opt-in). See the [plugin README](packages/openclaw-flair/README.md).
|
|
248
247
|
|
|
249
248
|
### n8n
|
|
250
249
|
|
|
@@ -252,7 +251,7 @@ Auto-detects the agent identity, provides `memory_store` / `memory_recall` / `me
|
|
|
252
251
|
Settings → Community Nodes → Install → @tpsdev-ai/n8n-nodes-flair
|
|
253
252
|
```
|
|
254
253
|
|
|
255
|
-
Three nodes: **Flair Chat Memory** (Memory port), **Flair Search**
|
|
254
|
+
Three nodes: **Flair Chat Memory** (Memory port), **Flair Search** (Tool port), **Flair Write** (Main connections). Setup and security guidance in **[docs/n8n.md](docs/n8n.md)** — read the auth note below first.
|
|
256
255
|
|
|
257
256
|
### Flair CLI
|
|
258
257
|
|
|
@@ -336,9 +335,9 @@ await h.post({ agentId: "mybot", content: "...", durability: "standard" });
|
|
|
336
335
|
|
|
337
336
|
### Auth across surfaces
|
|
338
337
|
|
|
339
|
-
|
|
338
|
+
Ordinary agents using Ed25519 keys sign network requests. They can write only their own records and read their own plus other agents' non-private memories. Administrator agent roles and administrator Basic credentials have broader authority, including access to private memories. Stdio MCP, Pi, LangGraph, and the wake runner can use administrator Basic auth when no signing key resolves; n8n always uses Harper's administrator password. See [SECURITY.md](SECURITY.md).
|
|
340
339
|
|
|
341
|
-
|
|
340
|
+
Treat n8n's credential as an instance-wide administrator credential: a workflow can read private memories and write under any agent ID. Use it only on an operator-controlled, single-tenant n8n instance with trusted workflow inputs. Full breakdown: [docs/auth.md](docs/auth.md#auth-across-surfaces-read-this-first).
|
|
342
341
|
|
|
343
342
|
In-process callers are a different model, not an exception to this one: they never sign, because identity is asserted through the call context rather than proven. Co-location *is* the grant — which is why Flair beside untrusted co-tenants on a shared instance is a different proposition to Flair inside your own app.
|
|
344
343
|
|
|
@@ -374,9 +373,9 @@ Managed hosting with multi-region replication and failover. Need a public URL fo
|
|
|
374
373
|
|
|
375
374
|
Full model, threat analysis and recommendations in [SECURITY.md](SECURITY.md).
|
|
376
375
|
|
|
377
|
-
- Ed25519
|
|
378
|
-
-
|
|
379
|
-
-
|
|
376
|
+
- Ordinary agent keys use Ed25519 signatures and bind writes to their agent identity.
|
|
377
|
+
- Administrator agent roles and administrator Basic credentials have broader authority.
|
|
378
|
+
- Ordinary signed agents can read their own memories and other agents' non-private memories. Private memories are owner-only for ordinary agents; administrators can also read them.
|
|
380
379
|
- Which memories are non-private is decided at write time, from durability: `permanent`/`persistent` default to `shared`, `standard`/`ephemeral` to `private`. A write that names neither is `standard`, so it lands `private`. Say what you mean with `--visibility shared|private` (CLI) or `visibility` (MCP / SDK); a write response names the visibility the record landed on, so it never has to be inferred.
|
|
381
380
|
- The admin password is generated by `flair init` and written to `~/.flair/admin-pass` (mode 0600). The CLI prints the path, never the value. Prefer `--admin-pass-file` over `--admin-pass` so it stays out of `ps` and shell history.
|
|
382
381
|
- Key rotation via `flair agent rotate-key`.
|
package/dist/build-info.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.
|
|
3
|
-
"commit": "
|
|
4
|
-
"builtAt": "2026-09-
|
|
2
|
+
"version": "0.57.0",
|
|
3
|
+
"commit": "36a21f1f53d8feafb537c2677caeaf52d3f03d86",
|
|
4
|
+
"builtAt": "2026-09-28T01:39:28.607Z",
|
|
5
5
|
"builder": "tsc"
|
|
6
6
|
}
|
package/dist/cli.js
CHANGED
|
@@ -24,7 +24,7 @@ import { flairConfigPath, flairDataDir } from "./lib/flair-paths.js";
|
|
|
24
24
|
import { httpBind, httpCorsAccessList, preserveHttpPortValue, preserveSecurePort, qualifySecureBindValue, DEFAULT_HTTP_BIND_HOST, } from "./lib/http-bind.js";
|
|
25
25
|
import { isNodeKeyId, partitionKeyIds, } from "./doctor-client.js";
|
|
26
26
|
import { cliBootPathWarning, } from "./install/global-bin-path.js";
|
|
27
|
-
import { readSecretFileSecure, readAdminPassFileSecure, defaultAdminPassPath, defaultKeysDir, resolveLocalAdminPass, DEFAULT_ADMIN_USER, resolveAdminUser, resolveKeyPath, buildEd25519Auth, authFetch, KeyLoadError, isLocalBase, authedRequest, } from "./lib/auth-resolve.js";
|
|
27
|
+
import { readSecretFileSecure, readAdminPassFileSecure, defaultAdminPassPath, defaultKeysDir, resolveLocalAdminPass, resolveAdminPassFromSources, ADMIN_PASS_FLAG, ADMIN_PASS_HELP, ADMIN_PASS_FILE_FLAG, ADMIN_PASS_FILE_HELP, DEFAULT_ADMIN_USER, resolveAdminUser, resolveKeyPath, buildEd25519Auth, authFetch, KeyLoadError, isLocalBase, authedRequest, } from "./lib/auth-resolve.js";
|
|
28
28
|
import { resolveSigningIdentity, emitSigningIdentityDebug, } from "./lib/signing-identity.js";
|
|
29
29
|
import { entityFormatHint, parseEntitiesCsv } from "./lib/entity-vocab-cli.js";
|
|
30
30
|
import { escapeXml, unescapeXml } from "./lib/xml-escape.js";
|
|
@@ -53,6 +53,7 @@ import { bindCli as bindPrincipalCli, register as registerPrincipal, agentRecord
|
|
|
53
53
|
import { bindCli as bindPresenceCli, register as registerPresence, VALID_PRESENCE_ACTIVITIES, MAX_TASK_LENGTH, } from "./commands/presence.js";
|
|
54
54
|
import { bindCli as bindRelationshipCli, register as registerRelationship, } from "./commands/relationship.js";
|
|
55
55
|
import { bindCli as bindWorkspaceCli, register as registerWorkspace, MAX_WORKSPACE_FIELD_LENGTH, } from "./commands/workspace.js";
|
|
56
|
+
import { decideHubReconcile, instanceWriteNotVerifiedMessage, multipleInstanceRowsMessage, readInstanceRows, updateInstanceRole, verifyInstanceWrite, } from "./lib/instance-identity-row.js";
|
|
56
57
|
import { applyUpgradeMigrations } from "./lib/upgrade-migrations.js";
|
|
57
58
|
import { defaultReadProcessCmdline, defaultReadProcessCwd, resolveServingFlairPackage, } from "./lib/upgrade-exec-path.js";
|
|
58
59
|
import { bindCli as bindOrgeventCli, register as registerOrgevent, MAX_ORGEVENT_DETAIL_LENGTH, MAX_ORGEVENT_SUMMARY_LENGTH, publishOrgEvent, } from "./commands/orgevent.js";
|
|
@@ -781,27 +782,47 @@ export const SHARED_IDENTITY_FLAGS = {
|
|
|
781
782
|
};
|
|
782
783
|
function addSharedCredentialOptions(cmd) {
|
|
783
784
|
return cmd
|
|
784
|
-
.option(
|
|
785
|
-
.option(
|
|
785
|
+
.option(ADMIN_PASS_FLAG, ADMIN_PASS_HELP)
|
|
786
|
+
.option(ADMIN_PASS_FILE_FLAG, ADMIN_PASS_FILE_HELP)
|
|
786
787
|
.option(SHARED_CREDENTIAL_FLAGS.adminUser, "Admin username for Basic auth (env: FLAIR_ADMIN_USER; default: admin)");
|
|
787
788
|
}
|
|
788
789
|
function addSharedIdentityOption(cmd) {
|
|
789
790
|
return cmd.option(SHARED_IDENTITY_FLAGS.agent, "Agent ID (or set FLAIR_AGENT_ID env)");
|
|
790
791
|
}
|
|
791
792
|
/**
|
|
792
|
-
* Resolve
|
|
793
|
-
*
|
|
794
|
-
*
|
|
793
|
+
* Resolve the admin password for the commands that declare the shared
|
|
794
|
+
* credential flags, through the ONE resolver (`resolveAdminPassFromSources` —
|
|
795
|
+
* the same one `federation token`/`pair` use, flair#1873/#1910). The resolved
|
|
796
|
+
* value is written back into the `adminPass` slot every call site reads.
|
|
797
|
+
*
|
|
798
|
+
* Precedence, as the usage text states: an explicit `--admin-pass-file` or
|
|
799
|
+
* `--admin-pass` over the ambient `FLAIR_ADMIN_PASS`/`HDB_ADMIN_PASSWORD`.
|
|
800
|
+
* Supplying BOTH the file and the flag is a usage error (it used to let the
|
|
801
|
+
* flag silently win); a file that is missing, empty or group-/world-readable
|
|
802
|
+
* is refused naming the path and its mode. Never prints the value.
|
|
795
803
|
*/
|
|
796
804
|
function applyAdminPassFile(opts) {
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
+
try {
|
|
806
|
+
// envPass is DELIBERATELY omitted: this wrapper folds an explicit
|
|
807
|
+
// `--admin-pass-file` (or `--admin-pass`) into `opts.adminPass`, and each
|
|
808
|
+
// call site keeps its own `opts.adminPass ?? FLAIR_ADMIN_PASS` fallback —
|
|
809
|
+
// exactly main's shape. Resolving the ambient env HERE would pre-fill
|
|
810
|
+
// `opts.adminPass`, and a call site that threads it as `explicitAdminPass`
|
|
811
|
+
// (memory add, soul, …) would then send ambient admin Basic auth where it
|
|
812
|
+
// used to send nothing and let the `--agent`/env tier decide (flair#1910
|
|
813
|
+
// round 2: `federation sync` merged nothing in the mixed-version compat
|
|
814
|
+
// lane because `memory add --agent X` with FLAIR_ADMIN_PASS set signed as
|
|
815
|
+
// admin, not as X).
|
|
816
|
+
const pass = resolveAdminPassFromSources({
|
|
817
|
+
adminPassFile: opts.adminPassFile,
|
|
818
|
+
adminPass: opts.adminPass,
|
|
819
|
+
});
|
|
820
|
+
if (pass)
|
|
821
|
+
opts.adminPass = pass;
|
|
822
|
+
}
|
|
823
|
+
catch (err) {
|
|
824
|
+
console.error(`Error: ${err.message}`);
|
|
825
|
+
process.exit(1);
|
|
805
826
|
}
|
|
806
827
|
}
|
|
807
828
|
// Ops port resolution: --ops-port flag > FLAIR_OPS_PORT env > config opsPort > httpPort - 1
|
|
@@ -2576,6 +2597,85 @@ export async function seedFederationInstanceViaOpsApi(opsPortOrUrl, instanceId,
|
|
|
2576
2597
|
httpErrorMessage: (status, text) => `Federation Instance insert via ops API failed (${status}): ${text}`,
|
|
2577
2598
|
});
|
|
2578
2599
|
}
|
|
2600
|
+
// ─── Federation instance identity (flair#1883) ───────────────────────────────
|
|
2601
|
+
//
|
|
2602
|
+
// A hub's identity is ONE `flair.Instance` row. `GET /FederationInstance`
|
|
2603
|
+
// find-or-creates it (`role: "spoke"`); `flair init --remote` used to INSERT a
|
|
2604
|
+
// second row under a fresh id, so a hub could hold a spoke row and a hub row and
|
|
2605
|
+
// every reader that took "the first row" answered from whichever the table
|
|
2606
|
+
// yielded first. `reconcileFederationInstanceViaOpsApi` is init's writer: it
|
|
2607
|
+
// reads the rows and decides (create / set the ONE row's role to hub / no-op /
|
|
2608
|
+
// refuse), never inserting over an existing identity. The decisions themselves
|
|
2609
|
+
// live in src/lib/instance-identity-row.ts, shared with the cleanup sweep and
|
|
2610
|
+
// doctor. After it writes, it RE-READS: a row that appeared in its read-then-
|
|
2611
|
+
// insert window (a concurrent `GET /FederationInstance` find-or-creates one) is
|
|
2612
|
+
// reported with the prune remedy rather than counted as a successful init. The
|
|
2613
|
+
// re-read must also hold the row it just WROTE (flair#1883 round 6): an empty
|
|
2614
|
+
// table or one different row is refused, naming what was found, because an
|
|
2615
|
+
// absent or wrong hub identity is not a completed init.
|
|
2616
|
+
/** The ops endpoint trio (URL, user, optional pass) as the identity helpers want it. */
|
|
2617
|
+
function federationInstanceEndpoint(opsPortOrUrl, adminUser, adminPass, fetchImpl) {
|
|
2618
|
+
const opsUrl = typeof opsPortOrUrl === "number" ? `http://127.0.0.1:${opsPortOrUrl}` : opsPortOrUrl;
|
|
2619
|
+
return {
|
|
2620
|
+
opsUrl,
|
|
2621
|
+
// A caller without a pass sends no Authorization header — same posture as
|
|
2622
|
+
// seedFederationInstanceViaOpsApi (loopback authorizeLocal).
|
|
2623
|
+
...(adminPass !== undefined ? { credentials: { user: adminUser, pass: adminPass } } : {}),
|
|
2624
|
+
...(fetchImpl ? { fetchImpl } : {}),
|
|
2625
|
+
};
|
|
2626
|
+
}
|
|
2627
|
+
/**
|
|
2628
|
+
* Reconcile the hub identity row for `flair init --remote`.
|
|
2629
|
+
*
|
|
2630
|
+
* Returns what actually happened so the caller's log line can name it: an
|
|
2631
|
+
* `already-hub` re-run must not claim it wrote anything.
|
|
2632
|
+
*
|
|
2633
|
+
* The write is verified by re-reading, not assumed (flair#1883 round 2): the
|
|
2634
|
+
* read-then-write window is real, and a `GET /FederationInstance` landing in it
|
|
2635
|
+
* leaves two rows. Reporting that as `created` would claim an identity this
|
|
2636
|
+
* instance does not have.
|
|
2637
|
+
*
|
|
2638
|
+
* The re-read must hold the row it just wrote (flair#1883 round 6): an empty
|
|
2639
|
+
* table (the insert never landed) or one different row (the update went
|
|
2640
|
+
* elsewhere) used to verify as success, and the caller adopted the id anyway.
|
|
2641
|
+
*/
|
|
2642
|
+
export async function reconcileFederationInstanceViaOpsApi(opsPortOrUrl, create, adminUser, adminPass, opts) {
|
|
2643
|
+
const endpoint = federationInstanceEndpoint(opsPortOrUrl, adminUser, adminPass, opts?.fetchImpl);
|
|
2644
|
+
const rows = await readInstanceRows(endpoint);
|
|
2645
|
+
const decision = decideHubReconcile(rows);
|
|
2646
|
+
switch (decision.kind) {
|
|
2647
|
+
case "refuse-multiple":
|
|
2648
|
+
throw new Error(multipleInstanceRowsMessage(decision.rows));
|
|
2649
|
+
case "already-hub":
|
|
2650
|
+
return { action: "already-hub", id: decision.id };
|
|
2651
|
+
case "update-role":
|
|
2652
|
+
await updateInstanceRole(endpoint, decision.id, "hub");
|
|
2653
|
+
await assertSingleInstanceRowAfterWrite(endpoint, decision.id);
|
|
2654
|
+
return { action: "updated", id: decision.id };
|
|
2655
|
+
default:
|
|
2656
|
+
// The create path keeps the insert (and its retry/401 guidance) unchanged.
|
|
2657
|
+
await seedFederationInstanceViaOpsApi(opsPortOrUrl, create.instanceId, create.publicKey, "hub", adminUser, adminPass);
|
|
2658
|
+
await assertSingleInstanceRowAfterWrite(endpoint, create.instanceId);
|
|
2659
|
+
return { action: "created", id: create.instanceId };
|
|
2660
|
+
}
|
|
2661
|
+
}
|
|
2662
|
+
/**
|
|
2663
|
+
* Re-read after a write: it must hold exactly the ONE hub row that was written.
|
|
2664
|
+
*
|
|
2665
|
+
* More than one row now means the write raced another writer (a `GET
|
|
2666
|
+
* /FederationInstance` creates one), and the caller must hear the refusal — with
|
|
2667
|
+
* the prune remedy — instead of a success line. An EMPTY table, one OTHER row,
|
|
2668
|
+
* or the expected id with a non-hub role is a failure too (flair#1883 round 6):
|
|
2669
|
+
* each names what the re-read found, because "the write did not land" and "the
|
|
2670
|
+
* write landed elsewhere" are different operator problems.
|
|
2671
|
+
*/
|
|
2672
|
+
async function assertSingleInstanceRowAfterWrite(endpoint, expectedId) {
|
|
2673
|
+
const verification = verifyInstanceWrite(await readInstanceRows(endpoint), expectedId);
|
|
2674
|
+
if (verification.kind === "refuse-multiple")
|
|
2675
|
+
throw new Error(multipleInstanceRowsMessage(verification.rows));
|
|
2676
|
+
if (verification.kind === "not-verified")
|
|
2677
|
+
throw new Error(instanceWriteNotVerifiedMessage(expectedId, verification.found));
|
|
2678
|
+
}
|
|
2579
2679
|
// ─── Provision Flair on Harper Fabric ──────────────────────────────────────
|
|
2580
2680
|
//
|
|
2581
2681
|
// Atomic provisioning for a fresh Harper Fabric cluster: builds a deploy
|
|
@@ -3488,6 +3588,7 @@ bindInitCli({
|
|
|
3488
3588
|
provisionFabric,
|
|
3489
3589
|
pubKeyPath,
|
|
3490
3590
|
readyOpsSocketPosture,
|
|
3591
|
+
reconcileFederationInstanceViaOpsApi,
|
|
3491
3592
|
resolveHttpPort,
|
|
3492
3593
|
writeAdminPassFile,
|
|
3493
3594
|
resolveOpsBindHost,
|
package/dist/commands/agent.js
CHANGED
|
@@ -2,7 +2,7 @@ import nacl from "tweetnacl";
|
|
|
2
2
|
import { existsSync, mkdirSync, writeFileSync, readFileSync, chmodSync } from "node:fs";
|
|
3
3
|
import { join } from "node:path";
|
|
4
4
|
import * as render from "../render.js";
|
|
5
|
-
import {
|
|
5
|
+
import { resolveAdminPassFromSources, defaultKeysDir, resolveLocalAdminPass, resolveAdminUser, resolveKeyPath, authFetch, } from "../lib/auth-resolve.js";
|
|
6
6
|
let cli;
|
|
7
7
|
/** Bind shared CLI helpers. cli.ts calls this immediately before register(program). */
|
|
8
8
|
export function bindCli(fns) {
|
|
@@ -46,22 +46,29 @@ export function register(program) {
|
|
|
46
46
|
// `flair import`: explicit --ops-target > derive from --target > localhost.
|
|
47
47
|
const seedOpsTarget = resolveEffectiveOpsUrl({ target: opts.target, opsTarget: opts.opsTarget }) ?? opsPort;
|
|
48
48
|
const isRemoteTarget = typeof seedOpsTarget === "string";
|
|
49
|
-
// flair#1259 — --admin-pass-file
|
|
50
|
-
//
|
|
49
|
+
// flair#1259 / #1910 — --admin-pass-file and --admin-pass resolve through
|
|
50
|
+
// the ONE resolver (resolveAdminPassFromSources), the file read in-process
|
|
51
51
|
// via readAdminPassFileSecure so the secret never appears in ps or shell
|
|
52
|
-
// history.
|
|
53
|
-
//
|
|
54
|
-
// explicit
|
|
55
|
-
//
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
52
|
+
// history. Combining the file and the flag is a usage error (the flag used
|
|
53
|
+
// to silently win). This does NOT weaken the #1085 remote guard below: an
|
|
54
|
+
// explicit flag naming a file IS operator intent toward this target,
|
|
55
|
+
// exactly like an explicit inline --admin-pass — what the guard blocks is
|
|
56
|
+
// the AMBIENT env/local-file fallbacks silently traveling to a third-party
|
|
57
|
+
// host.
|
|
58
|
+
let explicitPass;
|
|
59
|
+
try {
|
|
60
|
+
explicitPass =
|
|
61
|
+
resolveAdminPassFromSources({
|
|
62
|
+
adminPassFile: opts.adminPassFile,
|
|
63
|
+
adminPass: opts.adminPass,
|
|
64
|
+
envPass: undefined,
|
|
65
|
+
}) || undefined;
|
|
66
|
+
}
|
|
67
|
+
catch (err) {
|
|
68
|
+
console.error(`Error: ${err.message}`);
|
|
69
|
+
process.exit(1);
|
|
64
70
|
}
|
|
71
|
+
opts.adminPass = explicitPass;
|
|
65
72
|
// #590 — local convenience fallback: FLAIR_ADMIN_PASS env, then the secure
|
|
66
73
|
// ~/.flair/admin-pass file `flair init` already writes (mode 0600). Never
|
|
67
74
|
// applied for a remote target — see resolveLocalAdminPass.
|
package/dist/commands/bridge.js
CHANGED
|
@@ -1,6 +1,20 @@
|
|
|
1
1
|
import * as render from "../render.js";
|
|
2
2
|
import { resolveKeyPath, buildEd25519Auth } from "../lib/auth-resolve.js";
|
|
3
3
|
let cli;
|
|
4
|
+
/**
|
|
5
|
+
* Percent-encode a Memory id so it addresses exactly that record as ONE path
|
|
6
|
+
* segment (flair#1970). REFUSES an id that is exactly `.` or `..`: percent-
|
|
7
|
+
* encoding leaves those unchanged and URL normalization collapses `/Memory/.`
|
|
8
|
+
* to `/Memory/` and `/Memory/..` to `/`, so the sent path would not be the id
|
|
9
|
+
* (nor the signed path). Such an id cannot address its record.
|
|
10
|
+
*/
|
|
11
|
+
function encodeRecordId(id) {
|
|
12
|
+
if (id === "." || id === "..") {
|
|
13
|
+
throw new Error(`record id ${JSON.stringify(id)} is a URL path dot-segment ("." or ".."); ` +
|
|
14
|
+
`it cannot be addressed as one path segment of /Memory/<id>. Use a different id.`);
|
|
15
|
+
}
|
|
16
|
+
return encodeURIComponent(id);
|
|
17
|
+
}
|
|
4
18
|
/** Bind shared CLI helpers. cli.ts calls this immediately before register(program). */
|
|
5
19
|
export function bindCli(fns) {
|
|
6
20
|
cli = fns;
|
|
@@ -128,6 +142,20 @@ export function register(program) {
|
|
|
128
142
|
process.exit(1);
|
|
129
143
|
}
|
|
130
144
|
const baseUrl = opts.url ?? `http://127.0.0.1:${resolveHttpPort(opts)}`;
|
|
145
|
+
// A Flair base URL is an origin with an optional path; a query string or
|
|
146
|
+
// fragment on the base is refused before anything is imported — including
|
|
147
|
+
// for an empty or dry-run import, and including a bare trailing "?" or "#"
|
|
148
|
+
// (new URL reports those as an empty search/hash, but the join would drop
|
|
149
|
+
// the base's path). The route's own query string is what gets signed. #1970.
|
|
150
|
+
const parsedBase = new URL(baseUrl);
|
|
151
|
+
if (parsedBase.href.includes("?") || parsedBase.href.includes("#")) {
|
|
152
|
+
console.error(`Bridge import failed: refusing base URL "${baseUrl}": a Flair base URL must not carry a query string or fragment.`);
|
|
153
|
+
process.exit(1);
|
|
154
|
+
}
|
|
155
|
+
// Routes join against the PARSED base, which new URL() has normalized (for
|
|
156
|
+
// example surrounding whitespace removed), so the path sent is the path the
|
|
157
|
+
// base names.
|
|
158
|
+
const joinBase = `${parsedBase.href.replace(/\/+$/, "")}/`;
|
|
131
159
|
const ctx = makeContext({ bridge: name });
|
|
132
160
|
// Memory POST: Ed25519-signed when an agent key is available, fall back
|
|
133
161
|
// to the shared `api()` helper otherwise. Mirrors how `flair memory add`
|
|
@@ -135,17 +163,26 @@ export function register(program) {
|
|
|
135
163
|
const putMemory = async (body) => {
|
|
136
164
|
const headers = { "content-type": "application/json" };
|
|
137
165
|
const keyPath = opts.key ?? resolveKeyPath(body.agentId);
|
|
166
|
+
// One percent-encoded path segment, built once. Join the route onto the
|
|
167
|
+
// base URL's OWN path with exactly one slash between them, preserving any
|
|
168
|
+
// path the base carries (a base like http://h/flair still addresses
|
|
169
|
+
// /flair/Memory/<id>). Build the FINAL url once, then sign the path the
|
|
170
|
+
// request actually carries (#1970); ids of ordinary characters address
|
|
171
|
+
// the same record as before.
|
|
172
|
+
const memoryPath = `/Memory/${encodeRecordId(body.id)}`;
|
|
173
|
+
const memoryUrl = new URL(memoryPath.replace(/^\/+/, ""), joinBase);
|
|
174
|
+
const signedPath = `${memoryUrl.pathname}${memoryUrl.search}`;
|
|
138
175
|
if (keyPath) {
|
|
139
|
-
headers["authorization"] = buildEd25519Auth(body.agentId, "PUT",
|
|
176
|
+
headers["authorization"] = buildEd25519Auth(body.agentId, "PUT", signedPath, keyPath);
|
|
140
177
|
}
|
|
141
|
-
const res = await fetch(
|
|
178
|
+
const res = await fetch(memoryUrl, {
|
|
142
179
|
method: "PUT",
|
|
143
180
|
headers,
|
|
144
181
|
body: JSON.stringify(body),
|
|
145
182
|
});
|
|
146
183
|
if (!res.ok) {
|
|
147
184
|
const text = await res.text().catch(() => "");
|
|
148
|
-
throw new Error(`PUT
|
|
185
|
+
throw new Error(`PUT ${signedPath} → ${res.status}: ${text || res.statusText}`);
|
|
149
186
|
}
|
|
150
187
|
};
|
|
151
188
|
let lastReportedAt = Date.now();
|
package/dist/commands/doctor.js
CHANGED
|
@@ -12,6 +12,7 @@ import { DOCTOR_CHECK_IDS, catalogIssueDelta, mcpRepinIcon, renderCatalogDoctorL
|
|
|
12
12
|
import { describeEmbedGpuDoctorFinding } from "../lib/embed-gpu-doctor.js";
|
|
13
13
|
import { adminPassDesyncFinding, detectPersistedAdminUser } from "../lib/init-admin-pass.js";
|
|
14
14
|
import { opsApiBindFinding } from "../lib/ops-api-bind.js";
|
|
15
|
+
import { instanceIdentityLines, probeInstanceIdentity, } from "../lib/instance-identity-row.js";
|
|
15
16
|
import { flairCliVersion, unpinnedSpecWarning } from "../lib/mcp-spec.js";
|
|
16
17
|
import { mcpClientPinFindings, refreshOwnedPins, repinSessionStartHookGuarded, sessionStartHookPinFindings } from "../lib/owned-pins.js";
|
|
17
18
|
import * as render from "../render.js";
|
|
@@ -733,6 +734,57 @@ export function register(program) {
|
|
|
733
734
|
break;
|
|
734
735
|
}
|
|
735
736
|
}
|
|
737
|
+
// 4c. Instance identity (flair#1883). A hub's identity is ONE
|
|
738
|
+
// `flair.Instance` row, and the pairing-cleanup sweep reads its role from
|
|
739
|
+
// that row. More than one row means there is no canonical identity — the
|
|
740
|
+
// state a hub lands in when `GET /FederationInstance` find-or-creates a
|
|
741
|
+
// spoke row and `flair init --remote` inserted a second one (which is why
|
|
742
|
+
// the sweep could find no hub role and never clean up). A
|
|
743
|
+
// `flair_pair_initiator` role on an instance whose identity row is not a
|
|
744
|
+
// hub is the same debris seen from the other side. Both are read from the
|
|
745
|
+
// instance itself, so they need the ops API — same admin credential as the
|
|
746
|
+
// audit check above. A read that does not happen is UNVERIFIED: never a
|
|
747
|
+
// pass, and never a fabricated finding. The two reads are separate, so the
|
|
748
|
+
// states are separate too (flair#1883 round 2): rows read but list_roles
|
|
749
|
+
// unreadable leaves the pairing-role check UNVERIFIED while the row facts
|
|
750
|
+
// are still reported — a green line would claim a check that did not run.
|
|
751
|
+
if (harperResponding) {
|
|
752
|
+
let identityAdminPass;
|
|
753
|
+
let identityCredIssue = null;
|
|
754
|
+
try {
|
|
755
|
+
identityAdminPass = resolveLocalAdminPass(undefined);
|
|
756
|
+
}
|
|
757
|
+
catch (err) {
|
|
758
|
+
identityCredIssue = err instanceof Error ? err.message : String(err);
|
|
759
|
+
}
|
|
760
|
+
if (identityCredIssue) {
|
|
761
|
+
console.log(` ${render.icons.warn} Instance identity: UNVERIFIED (could not probe — ${identityCredIssue})`);
|
|
762
|
+
}
|
|
763
|
+
else {
|
|
764
|
+
const probe = await probeInstanceIdentity({
|
|
765
|
+
opsUrl: `http://127.0.0.1:${resolveOpsPort(opts)}`,
|
|
766
|
+
credentials: { user: resolveAdminUser(undefined), pass: identityAdminPass ?? "" },
|
|
767
|
+
});
|
|
768
|
+
if (probe.rows === null) {
|
|
769
|
+
console.log(` ${render.icons.warn} Instance identity: UNVERIFIED (could not read the Instance table via the ops API)`);
|
|
770
|
+
}
|
|
771
|
+
else {
|
|
772
|
+
// The lines — and therefore the pairing-role state — are built in
|
|
773
|
+
// `instanceIdentityLines`, so "an unread pairing-role check is never
|
|
774
|
+
// silent" is a property of the lines and not of this call site: a row
|
|
775
|
+
// finding and the pairing-role UNVERIFIED status print as two lines
|
|
776
|
+
// from one call (flair#1883 round 5).
|
|
777
|
+
for (const line of instanceIdentityLines({ rows: probe.rows, roleNames: probe.roleNames })) {
|
|
778
|
+
const icon = line.level === "ok" ? render.icons.ok : line.level === "warn" ? render.icons.warn : render.icons.error;
|
|
779
|
+
console.log(` ${icon} ${line.level === "fail" ? line.text : render.wrap(render.c.dim, line.text)}`);
|
|
780
|
+
if (line.fix)
|
|
781
|
+
console.log(` ${render.wrap(render.c.dim, line.fix)}`);
|
|
782
|
+
if (line.level === "fail")
|
|
783
|
+
issues++;
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
}
|
|
736
788
|
// 5. Stale PID file (skip if already reported in port check)
|
|
737
789
|
const dataDir = defaultDataDir();
|
|
738
790
|
const pidFile = join(dataDir, "hdb.pid");
|