@tpsdev-ai/flair 0.55.2 → 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 +18 -19
- package/dist/bridges/builtins/markdown.js +2 -2
- package/dist/bridges/discover.js +2 -2
- package/dist/bridges/runtime/allow-list.js +2 -2
- package/dist/build-info.json +3 -3
- package/dist/cli.js +125 -26
- package/dist/commands/agent.js +22 -15
- package/dist/commands/attention.js +2 -2
- package/dist/commands/backup.js +2 -2
- package/dist/commands/bridge.js +40 -3
- package/dist/commands/doctor.js +91 -28
- package/dist/commands/export.js +2 -2
- package/dist/commands/federation.js +441 -68
- package/dist/commands/hook.js +4 -4
- package/dist/commands/init.js +59 -12
- package/dist/commands/mcp.js +2 -2
- package/dist/commands/migrate-harness-memory.js +8 -8
- package/dist/commands/rem.js +2 -2
- package/dist/commands/service.js +25 -1
- package/dist/commands/session.js +2 -2
- package/dist/commands/uninstall.js +2 -2
- package/dist/commands/upgrade.js +3 -3
- package/dist/doctor-client.js +5 -23
- package/dist/engine-version.js +2 -2
- package/dist/federation/scheduler.js +5 -5
- package/dist/install/clients.js +5 -10
- package/dist/keystore.js +10 -2
- package/dist/lib/auth-resolve.js +51 -5
- package/dist/lib/doctor-config-path.js +2 -2
- package/dist/lib/flair-paths.js +29 -0
- package/dist/lib/home.js +60 -0
- package/dist/lib/instance-identity-row.js +580 -0
- package/dist/lib/launchd-repair.js +6 -0
- package/dist/lib/mcp-enable.js +4 -4
- package/dist/lib/owned-pins.js +1 -13
- package/dist/lib/redact-token-id.js +197 -0
- package/dist/lib/socket-path-limit.js +120 -0
- package/dist/lib/uninstall-purge.js +2 -18
- package/dist/lib/upgrade-plain-tree.js +2 -2
- package/dist/mcp-client-assertion.js +3 -3
- package/dist/rem/runner.js +3 -3
- package/dist/rem/scheduler.js +5 -5
- package/dist/rem/snapshot.js +2 -2
- 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/OAuth.js +62 -11
- package/dist/resources/Presence.js +135 -47
- package/dist/resources/Relationship.js +3 -11
- package/dist/resources/SemanticSearch.js +25 -13
- package/dist/resources/admin-layout.js +7 -2
- 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-reflect-lib.js +17 -1
- 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/keystore.js +10 -2
- package/dist/src/lib/home.js +60 -0
- package/dist/src/lib/instance-identity-row.js +580 -0
- package/dist/src/lib/redact-token-id.js +197 -0
- package/dist/src/rem/scheduler.js +5 -5
- package/dist/version-check.js +2 -2
- package/dist/version-handshake.js +2 -2
- package/docs/api-reference.md +32 -7
- package/docs/auth.md +19 -7
- package/docs/claude-code.md +5 -6
- package/docs/deploying-on-fabric.md +8 -4
- package/docs/deployment.md +26 -37
- package/docs/embedding-in-a-harper-app.md +4 -2
- package/docs/entity-vocabulary.md +5 -5
- package/docs/federation.md +48 -21
- package/docs/hosted-on-fabric.md +7 -4
- package/docs/integrations.md +24 -15
- package/docs/mcp-clients.md +44 -23
- 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 +44 -22
- package/docs/standalone-local.md +12 -16
- 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
|
|
|
@@ -61,11 +61,10 @@ Full walkthrough with expected output at every step: **[docs/quickstart.md](docs
|
|
|
61
61
|
|
|
62
62
|
> **Known install-size issue.** `npm install -g @tpsdev-ai/flair` currently pulls roughly 130 MB of React Native tooling that a Node install never uses — an optional dependency of Harper's SQL engine. It is inert and Flair runs normally. The durable fix is upstream ([harperfast/harper#1937](https://github.com/harperfast/harper/issues/1937)). Do **not** install with `--omit=optional` to avoid it: that also drops Harper's platform RocksDB binding, and Flair will not start.
|
|
63
63
|
|
|
64
|
-
Two
|
|
65
|
-
|
|
66
|
-
- **The server has an MCP surface built in.** `/mcp` is a JSON-RPC endpoint exposing 12 curated tools, guarded by OAuth bearer tokens. It ships inside the package — and it is **off by default**: until you set `FLAIR_MCP_OAUTH` *and* a public issuer (`FLAIR_MCP_ISSUER`, falling back to `FLAIR_PUBLIC_URL`), no `/mcp` route is registered and the path returns 404. No documented client setup uses it today.
|
|
67
|
-
- **What your MCP client actually talks to is a separate package** — `@tpsdev-ai/flair-mcp`, a stdio adapter — and that one is deliberately 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, so the client fetches it on demand and there is no second global package to keep in step.
|
|
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).
|
|
68
65
|
|
|
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 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`.
|
|
@@ -9,12 +9,12 @@
|
|
|
9
9
|
*/
|
|
10
10
|
import { promises as fsp } from "node:fs";
|
|
11
11
|
import { join } from "node:path";
|
|
12
|
-
import { homedir } from "node:os";
|
|
13
12
|
import { parseRecords } from "../runtime/formats.js";
|
|
14
13
|
import { BridgeRuntimeError } from "../types.js";
|
|
14
|
+
import { resolveHome } from "../../lib/home.js";
|
|
15
15
|
export async function* importFromDirectory(opts, ctx) {
|
|
16
16
|
// Resolve source directory
|
|
17
|
-
const sourceDir = typeof opts.source === "string" ? opts.source : join(
|
|
17
|
+
const sourceDir = typeof opts.source === "string" ? opts.source : join(resolveHome(), "notes");
|
|
18
18
|
ctx.log.info(`scanning markdown directory`, { path: sourceDir });
|
|
19
19
|
// Scan directory for .md files
|
|
20
20
|
let files;
|
package/dist/bridges/discover.js
CHANGED
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
* executing any code plugin. Runtime execution is slice 2.
|
|
12
12
|
*/
|
|
13
13
|
import { promises as fsp } from "node:fs";
|
|
14
|
-
import { homedir } from "node:os";
|
|
15
14
|
import { join, dirname, basename } from "node:path";
|
|
15
|
+
import { resolveHome } from "../lib/home.js";
|
|
16
16
|
async function exists(path) {
|
|
17
17
|
try {
|
|
18
18
|
await fsp.stat(path);
|
|
@@ -163,7 +163,7 @@ async function scanModuleRoot(base) {
|
|
|
163
163
|
*/
|
|
164
164
|
export async function discover(opts = {}) {
|
|
165
165
|
const cwd = opts.cwd ?? process.cwd();
|
|
166
|
-
const home = opts.home ??
|
|
166
|
+
const home = opts.home ?? resolveHome();
|
|
167
167
|
const moduleRoots = opts.moduleRoots ?? [
|
|
168
168
|
join(cwd, "node_modules"),
|
|
169
169
|
join(home, ".flair", "node_modules"),
|
|
@@ -37,10 +37,10 @@
|
|
|
37
37
|
import { promises as fsp } from "node:fs";
|
|
38
38
|
import { existsSync } from "node:fs";
|
|
39
39
|
import { join, dirname } from "node:path";
|
|
40
|
-
import { homedir } from "node:os";
|
|
41
40
|
import { createHash } from "node:crypto";
|
|
41
|
+
import { resolveHome } from "../../lib/home.js";
|
|
42
42
|
function resolvePath(opts) {
|
|
43
|
-
return opts?.path ?? join(
|
|
43
|
+
return opts?.path ?? join(resolveHome(), ".flair", "bridges-allowed.json");
|
|
44
44
|
}
|
|
45
45
|
function hasEntryFields(e) {
|
|
46
46
|
return (typeof e?.name === "string" &&
|
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
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { Command } from "commander";
|
|
3
3
|
import { load as parseYaml } from "js-yaml";
|
|
4
4
|
import { existsSync, mkdirSync, writeFileSync, readFileSync, openSync, closeSync, chmodSync, renameSync, cpSync, rmSync, mkdtempSync, readdirSync, statSync, lstatSync, realpathSync, unlinkSync, chownSync, constants as fsConstants, } from "node:fs";
|
|
5
|
-
import {
|
|
5
|
+
import { tmpdir } from "node:os";
|
|
6
6
|
import { join, resolve, dirname, basename } from "node:path";
|
|
7
7
|
import { fileURLToPath } from "node:url";
|
|
8
8
|
import { spawn, execFileSync, spawnSync, execSync } from "node:child_process";
|
|
@@ -20,10 +20,11 @@ import { fleetSweepShouldAbort, } from "./fleet-verify.js";
|
|
|
20
20
|
import { detectClients } from "./install/clients.js";
|
|
21
21
|
import { flairCliVersion, mcpServerSpec } from "./lib/mcp-spec.js";
|
|
22
22
|
import { harperPortValue } from "./lib/harper-port-value.js";
|
|
23
|
+
import { flairConfigPath, flairDataDir } from "./lib/flair-paths.js";
|
|
23
24
|
import { httpBind, httpCorsAccessList, preserveHttpPortValue, preserveSecurePort, qualifySecureBindValue, DEFAULT_HTTP_BIND_HOST, } from "./lib/http-bind.js";
|
|
24
25
|
import { isNodeKeyId, partitionKeyIds, } from "./doctor-client.js";
|
|
25
26
|
import { cliBootPathWarning, } from "./install/global-bin-path.js";
|
|
26
|
-
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";
|
|
27
28
|
import { resolveSigningIdentity, emitSigningIdentityDebug, } from "./lib/signing-identity.js";
|
|
28
29
|
import { entityFormatHint, parseEntitiesCsv } from "./lib/entity-vocab-cli.js";
|
|
29
30
|
import { escapeXml, unescapeXml } from "./lib/xml-escape.js";
|
|
@@ -52,6 +53,7 @@ import { bindCli as bindPrincipalCli, register as registerPrincipal, agentRecord
|
|
|
52
53
|
import { bindCli as bindPresenceCli, register as registerPresence, VALID_PRESENCE_ACTIVITIES, MAX_TASK_LENGTH, } from "./commands/presence.js";
|
|
53
54
|
import { bindCli as bindRelationshipCli, register as registerRelationship, } from "./commands/relationship.js";
|
|
54
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";
|
|
55
57
|
import { applyUpgradeMigrations } from "./lib/upgrade-migrations.js";
|
|
56
58
|
import { defaultReadProcessCmdline, defaultReadProcessCwd, resolveServingFlairPackage, } from "./lib/upgrade-exec-path.js";
|
|
57
59
|
import { bindCli as bindOrgeventCli, register as registerOrgevent, MAX_ORGEVENT_DETAIL_LENGTH, MAX_ORGEVENT_SUMMARY_LENGTH, publishOrgEvent, } from "./commands/orgevent.js";
|
|
@@ -75,6 +77,7 @@ import { bindCli as bindServiceCli, register as registerService, } from "./comma
|
|
|
75
77
|
import { bindCli as bindDoctorCli, register as registerDoctor, } from "./commands/doctor.js";
|
|
76
78
|
import { bindCli as bindQualityCli, register as registerQuality, } from "./commands/quality.js";
|
|
77
79
|
import { bindCli as bindGrantCli, register as registerGrant, } from "./commands/grant.js";
|
|
80
|
+
import { resolveHome } from "./lib/home.js";
|
|
78
81
|
// Federation crypto helpers + private-visibility filter live with the
|
|
79
82
|
// federation command group (src/commands/federation.ts, flair#1620). Inlined
|
|
80
83
|
// there for the same packaging reason: src/ must not import resources/.
|
|
@@ -141,7 +144,7 @@ const DEFAULT_OPS_BIND_HOST = "127.0.0.1";
|
|
|
141
144
|
// (flair#747) — imported above, re-exported at the bottom of this file so
|
|
142
145
|
// the public CLI module surface is unchanged.
|
|
143
146
|
function defaultDataDir() {
|
|
144
|
-
return
|
|
147
|
+
return flairDataDir();
|
|
145
148
|
}
|
|
146
149
|
// ─── launchd label (flair#693) ─────────────────────────────────────────────
|
|
147
150
|
// A bare "ai.tpsdev.flair" label is global to the current macOS user's
|
|
@@ -162,7 +165,7 @@ function defaultDataDir() {
|
|
|
162
165
|
// label so it is never orphaned.
|
|
163
166
|
const LEGACY_LAUNCHD_LABEL = "ai.tpsdev.flair";
|
|
164
167
|
function defaultLaunchAgentsDir() {
|
|
165
|
-
return join(
|
|
168
|
+
return join(resolveHome(), "Library", "LaunchAgents");
|
|
166
169
|
}
|
|
167
170
|
/** Instance-scoped launchd label for `dataDir`: ai.tpsdev.flair.<8-hex-char sha256 of the resolved data dir>. */
|
|
168
171
|
function launchdLabel(dataDir) {
|
|
@@ -422,11 +425,7 @@ function ensureLaunchdServiceLoaded(dataDir, runLaunchctl, launchAgentsDir = def
|
|
|
422
425
|
}
|
|
423
426
|
function configPath() {
|
|
424
427
|
// Check both .yaml and .yml extensions
|
|
425
|
-
|
|
426
|
-
const ymlPath = join(homedir(), ".flair", "config.yml");
|
|
427
|
-
if (existsSync(ymlPath) && !existsSync(yamlPath))
|
|
428
|
-
return ymlPath;
|
|
429
|
-
return yamlPath;
|
|
428
|
+
return flairConfigPath();
|
|
430
429
|
}
|
|
431
430
|
/**
|
|
432
431
|
* `~/.flair/config.yaml`'s `port:` — the PER-USER file, which describes the
|
|
@@ -783,27 +782,47 @@ export const SHARED_IDENTITY_FLAGS = {
|
|
|
783
782
|
};
|
|
784
783
|
function addSharedCredentialOptions(cmd) {
|
|
785
784
|
return cmd
|
|
786
|
-
.option(
|
|
787
|
-
.option(
|
|
785
|
+
.option(ADMIN_PASS_FLAG, ADMIN_PASS_HELP)
|
|
786
|
+
.option(ADMIN_PASS_FILE_FLAG, ADMIN_PASS_FILE_HELP)
|
|
788
787
|
.option(SHARED_CREDENTIAL_FLAGS.adminUser, "Admin username for Basic auth (env: FLAIR_ADMIN_USER; default: admin)");
|
|
789
788
|
}
|
|
790
789
|
function addSharedIdentityOption(cmd) {
|
|
791
790
|
return cmd.option(SHARED_IDENTITY_FLAGS.agent, "Agent ID (or set FLAIR_AGENT_ID env)");
|
|
792
791
|
}
|
|
793
792
|
/**
|
|
794
|
-
* Resolve
|
|
795
|
-
*
|
|
796
|
-
*
|
|
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.
|
|
797
803
|
*/
|
|
798
804
|
function applyAdminPassFile(opts) {
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
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);
|
|
807
826
|
}
|
|
808
827
|
}
|
|
809
828
|
// Ops port resolution: --ops-port flag > FLAIR_OPS_PORT env > config opsPort > httpPort - 1
|
|
@@ -2578,6 +2597,85 @@ export async function seedFederationInstanceViaOpsApi(opsPortOrUrl, instanceId,
|
|
|
2578
2597
|
httpErrorMessage: (status, text) => `Federation Instance insert via ops API failed (${status}): ${text}`,
|
|
2579
2598
|
});
|
|
2580
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
|
+
}
|
|
2581
2679
|
// ─── Provision Flair on Harper Fabric ──────────────────────────────────────
|
|
2582
2680
|
//
|
|
2583
2681
|
// Atomic provisioning for a fresh Harper Fabric cluster: builds a deploy
|
|
@@ -3106,7 +3204,7 @@ export function probeOpenclawPluginVersion(extensionName) {
|
|
|
3106
3204
|
try {
|
|
3107
3205
|
// process.env.HOME first so tests can override; homedir() as fallback —
|
|
3108
3206
|
// homedir() doesn't honor runtime HOME changes (caches at module load).
|
|
3109
|
-
const home =
|
|
3207
|
+
const home = resolveHome();
|
|
3110
3208
|
const pkgJsonPath = resolve(home, ".openclaw", "extensions", extensionName, "package.json");
|
|
3111
3209
|
if (!existsSync(pkgJsonPath))
|
|
3112
3210
|
return null;
|
|
@@ -3490,6 +3588,7 @@ bindInitCli({
|
|
|
3490
3588
|
provisionFabric,
|
|
3491
3589
|
pubKeyPath,
|
|
3492
3590
|
readyOpsSocketPosture,
|
|
3591
|
+
reconcileFederationInstanceViaOpsApi,
|
|
3493
3592
|
resolveHttpPort,
|
|
3494
3593
|
writeAdminPassFile,
|
|
3495
3594
|
resolveOpsBindHost,
|
|
@@ -4230,7 +4329,7 @@ async function confirmYes(question) {
|
|
|
4230
4329
|
* applies a new artifact that the old init could not have written.
|
|
4231
4330
|
*/
|
|
4232
4331
|
async function doctorRunAfterUpgrade(args) {
|
|
4233
|
-
const homeDir =
|
|
4332
|
+
const homeDir = resolveHome();
|
|
4234
4333
|
const keysDir = defaultKeysDir();
|
|
4235
4334
|
const detectedClientIds = detectClients().filter((c) => c.detected).map((c) => c.id);
|
|
4236
4335
|
// ── Version-keyed upgrade migrations (flair#1439) ─────────────────────────
|
|
@@ -4432,7 +4531,7 @@ export function buildRepairPlist(dataDir, config) {
|
|
|
4432
4531
|
passFile: {
|
|
4433
4532
|
launcher: launchdLauncherPath(),
|
|
4434
4533
|
adminPassFile: defaultAdminPassPath(),
|
|
4435
|
-
home:
|
|
4534
|
+
home: resolveHome(),
|
|
4436
4535
|
path: process.env.PATH ?? "/usr/bin:/bin:/usr/sbin:/sbin",
|
|
4437
4536
|
},
|
|
4438
4537
|
});
|
|
@@ -4624,7 +4723,7 @@ export async function writeInitLaunchdPlist(opts, deps = {}) {
|
|
|
4624
4723
|
passFile: {
|
|
4625
4724
|
launcher: launchdLauncherPath(),
|
|
4626
4725
|
adminPassFile: adminPassPath,
|
|
4627
|
-
home:
|
|
4726
|
+
home: resolveHome(),
|
|
4628
4727
|
path: process.env.PATH ?? "/usr/bin:/bin:/usr/sbin:/sbin",
|
|
4629
4728
|
},
|
|
4630
4729
|
});
|
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.
|
|
@@ -41,8 +41,8 @@ export function register(program) {
|
|
|
41
41
|
// malformed.
|
|
42
42
|
/** Render one attention-result row for its source group — human-readable mode only. */
|
|
43
43
|
program
|
|
44
|
-
.command("attention <
|
|
45
|
-
.description("What's touching entity
|
|
44
|
+
.command("attention <type:value>")
|
|
45
|
+
.description("What's touching this entity in the last N days? Argument is a vocabulary string (type:value from a closed set, e.g. repo:owner/name). Grouped view across memory/relationship/workspace/presence/orgevent (POST /AttentionQuery)")
|
|
46
46
|
.option("--days <n>", "Window size in days (default 7)")
|
|
47
47
|
.option("--agent <id>", "Agent ID (or set FLAIR_AGENT_ID env)")
|
|
48
48
|
.option("--key <path>", "Ed25519 private key path")
|
package/dist/commands/backup.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { resolveAdminUser } from "../lib/auth-resolve.js";
|
|
2
|
+
import { flairBackupOutputPath } from "../lib/flair-paths.js";
|
|
2
3
|
import * as render from "../render.js";
|
|
3
4
|
import { mkdirSync, renameSync, writeFileSync } from "node:fs";
|
|
4
|
-
import { homedir } from "node:os";
|
|
5
5
|
import { join } from "node:path";
|
|
6
6
|
let cli;
|
|
7
7
|
/** Bind the cli-locals this module depends on. */
|
|
@@ -100,7 +100,7 @@ export function register(program) {
|
|
|
100
100
|
};
|
|
101
101
|
// Determine output path
|
|
102
102
|
const timestamp = new Date().toISOString().replace(/[:.]/g, "-").slice(0, 19);
|
|
103
|
-
const defaultOutput =
|
|
103
|
+
const defaultOutput = flairBackupOutputPath(timestamp);
|
|
104
104
|
const outputPath = opts.output ?? defaultOutput;
|
|
105
105
|
mkdirSync(join(outputPath, ".."), { recursive: true });
|
|
106
106
|
const tmp = outputPath + ".tmp";
|
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();
|