@tpsdev-ai/flair 0.55.1 → 0.56.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 +3 -3
- 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 +201 -95
- package/dist/commands/attention.js +2 -2
- package/dist/commands/backup.js +2 -2
- package/dist/commands/doctor.js +168 -37
- package/dist/commands/export.js +2 -2
- package/dist/commands/federation.js +229 -95
- package/dist/commands/hook.js +4 -4
- package/dist/commands/init.js +94 -70
- package/dist/commands/mcp.js +2 -2
- package/dist/commands/migrate-harness-memory.js +8 -8
- package/dist/commands/rem.js +31 -4
- 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 +88 -69
- package/dist/doctor-client.js +341 -161
- package/dist/engine-version.js +2 -2
- package/dist/federation/scheduler.js +5 -5
- package/dist/hook-install.js +359 -176
- package/dist/install/clients.js +908 -214
- package/dist/keystore.js +10 -2
- package/dist/lib/auth-resolve.js +5 -5
- package/dist/lib/config-critical-section.js +557 -0
- package/dist/lib/doctor-config-path.js +2 -2
- package/dist/lib/doctor-run.js +107 -27
- package/dist/lib/flair-paths.js +29 -0
- package/dist/lib/home.js +60 -0
- package/dist/lib/launchd-repair.js +109 -0
- package/dist/lib/mcp-enable.js +4 -4
- package/dist/lib/owned-pins.js +256 -94
- package/dist/lib/pin-write-guard.js +87 -0
- package/dist/lib/settings-bytes.js +85 -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/lib/upgrade-status.js +164 -0
- package/dist/lib/wiring-spec.js +238 -0
- package/dist/mcp-client-assertion.js +3 -3
- package/dist/rem/promote-policy.js +102 -0
- package/dist/rem/runner.js +3 -3
- package/dist/rem/scheduler.js +5 -5
- package/dist/rem/snapshot.js +2 -2
- package/dist/resources/MemoryReflect.js +10 -0
- package/dist/resources/OAuth.js +62 -11
- package/dist/resources/Presence.js +135 -47
- package/dist/resources/admin-layout.js +7 -2
- package/dist/resources/auto-promote-lib.js +56 -0
- package/dist/resources/health.js +26 -0
- package/dist/resources/memory-reflect-lib.js +215 -6
- package/dist/resources/migrations/progress.js +17 -0
- package/dist/resources/migrations/runner.js +46 -27
- package/dist/resources/migrations/status.js +2 -1
- package/dist/src/keystore.js +10 -2
- package/dist/src/lib/home.js +60 -0
- package/dist/src/rem/promote-policy.js +102 -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 +31 -6
- package/docs/auth.md +14 -2
- package/docs/deploying-on-fabric.md +5 -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 +58 -19
- package/docs/hosted-on-fabric.md +7 -5
- package/docs/mcp-clients.md +29 -12
- package/docs/releasing.md +66 -22
- package/docs/spoke-bringup.md +41 -22
- package/docs/standalone-local.md +12 -16
- package/package.json +3 -1
package/README.md
CHANGED
|
@@ -61,10 +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
|
|
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
|
-
- **
|
|
67
|
-
- **
|
|
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 12 curated tools. It is **off by default**: until `FLAIR_MCP_OAUTH=true` and the issuer is a public HTTPS origin (`FLAIR_MCP_ISSUER`, else `FLAIR_PUBLIC_URL`), no `/mcp` route is registered and the path returns 404. `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`). A loopback install cannot be that origin, so native `/mcp` is remote-only by design.
|
|
68
68
|
|
|
69
69
|
`@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
70
|
|
|
@@ -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.56.0",
|
|
3
|
+
"commit": "3749af5f4c91a16945c8b13ac226414b6c55d9aa",
|
|
4
|
+
"builtAt": "2026-09-26T14:50:49.766Z",
|
|
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";
|
|
@@ -18,8 +18,9 @@ import { readInstalledHarperVersion, writeEngineVersionStamp, checkEngineVersion
|
|
|
18
18
|
import { checkServerHandshake, formatHandshakeNudge, invalidateHandshakeCache } from "./version-handshake.js";
|
|
19
19
|
import { fleetSweepShouldAbort, } from "./fleet-verify.js";
|
|
20
20
|
import { detectClients } from "./install/clients.js";
|
|
21
|
-
import { flairCliVersion, mcpServerSpec
|
|
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";
|
|
@@ -28,10 +29,11 @@ import { resolveSigningIdentity, emitSigningIdentityDebug, } from "./lib/signing
|
|
|
28
29
|
import { entityFormatHint, parseEntitiesCsv } from "./lib/entity-vocab-cli.js";
|
|
29
30
|
import { escapeXml, unescapeXml } from "./lib/xml-escape.js";
|
|
30
31
|
import { assessLaunchdManagement, diagnoseLaunchdPlistPaths, isDetached, pickInstancePid, plistCarriesInlineAdminPassword, readLaunchctlJobState, readPlistProgramRefs, LAUNCHCTL_QUERY_TIMEOUT_MS, } from "./lib/launchd-management.js";
|
|
31
|
-
import { classifyPlist, planLaunchdRepair, mapRepairThrow,
|
|
32
|
+
import { classifyPlist, planLaunchdRepair, mapRepairThrow, decideAdoptStopWithWait, verifyAdoptServingWithWait, } from "./lib/launchd-repair.js";
|
|
32
33
|
import { stabilizeMqttNetworkKeyOrder } from "./lib/stabilize-mqtt-network.js";
|
|
33
34
|
import { detectOpsApiAllInterfacesBind } from "./lib/ops-api-bind.js";
|
|
34
35
|
import { applyUpgradeHookConsent, runDoctorChecks, } from "./lib/doctor-run.js";
|
|
36
|
+
import { classifyInstalledVersion, shouldPrintUpgradeLine, upgradeStatusSuffix } from "./lib/upgrade-status.js";
|
|
35
37
|
import { classifyDaemonState, verifyIdentity, parseSidecarJson, classifyHealthProbe, classifyPortOwner, classifyInstanceMatch, shouldAdoptMissingSidecar, parseNullSeparatedEnviron, extractRootPath, } from "./lib/daemon-liveness.js";
|
|
36
38
|
import { readProcessStartTimeMs } from "./lib/process-start-time.js";
|
|
37
39
|
import { bindCli as bindFederationCli, register as registerFederation, signRequestBody, parseTokenFromFile, runFederationSyncOnce, persistLocalPeerLastSyncAt, runFederationWatch, federationStatusUrlSetting, describeFederationStatusFetchFailed, isFederationStatusConnectFailure, rewriteFederationStatusFetchFailed, isFederationStatusAuthFailure, isFederationStatusAuthRemedy, } from "./commands/federation.js";
|
|
@@ -74,6 +76,7 @@ import { bindCli as bindServiceCli, register as registerService, } from "./comma
|
|
|
74
76
|
import { bindCli as bindDoctorCli, register as registerDoctor, } from "./commands/doctor.js";
|
|
75
77
|
import { bindCli as bindQualityCli, register as registerQuality, } from "./commands/quality.js";
|
|
76
78
|
import { bindCli as bindGrantCli, register as registerGrant, } from "./commands/grant.js";
|
|
79
|
+
import { resolveHome } from "./lib/home.js";
|
|
77
80
|
// Federation crypto helpers + private-visibility filter live with the
|
|
78
81
|
// federation command group (src/commands/federation.ts, flair#1620). Inlined
|
|
79
82
|
// there for the same packaging reason: src/ must not import resources/.
|
|
@@ -140,7 +143,7 @@ const DEFAULT_OPS_BIND_HOST = "127.0.0.1";
|
|
|
140
143
|
// (flair#747) — imported above, re-exported at the bottom of this file so
|
|
141
144
|
// the public CLI module surface is unchanged.
|
|
142
145
|
function defaultDataDir() {
|
|
143
|
-
return
|
|
146
|
+
return flairDataDir();
|
|
144
147
|
}
|
|
145
148
|
// ─── launchd label (flair#693) ─────────────────────────────────────────────
|
|
146
149
|
// A bare "ai.tpsdev.flair" label is global to the current macOS user's
|
|
@@ -161,7 +164,7 @@ function defaultDataDir() {
|
|
|
161
164
|
// label so it is never orphaned.
|
|
162
165
|
const LEGACY_LAUNCHD_LABEL = "ai.tpsdev.flair";
|
|
163
166
|
function defaultLaunchAgentsDir() {
|
|
164
|
-
return join(
|
|
167
|
+
return join(resolveHome(), "Library", "LaunchAgents");
|
|
165
168
|
}
|
|
166
169
|
/** Instance-scoped launchd label for `dataDir`: ai.tpsdev.flair.<8-hex-char sha256 of the resolved data dir>. */
|
|
167
170
|
function launchdLabel(dataDir) {
|
|
@@ -421,11 +424,7 @@ function ensureLaunchdServiceLoaded(dataDir, runLaunchctl, launchAgentsDir = def
|
|
|
421
424
|
}
|
|
422
425
|
function configPath() {
|
|
423
426
|
// Check both .yaml and .yml extensions
|
|
424
|
-
|
|
425
|
-
const ymlPath = join(homedir(), ".flair", "config.yml");
|
|
426
|
-
if (existsSync(ymlPath) && !existsSync(yamlPath))
|
|
427
|
-
return ymlPath;
|
|
428
|
-
return yamlPath;
|
|
427
|
+
return flairConfigPath();
|
|
429
428
|
}
|
|
430
429
|
/**
|
|
431
430
|
* `~/.flair/config.yaml`'s `port:` — the PER-USER file, which describes the
|
|
@@ -2350,6 +2349,140 @@ function opsAuth401Hint(adminUser) {
|
|
|
2350
2349
|
* or hardened instance. Hardening the ops-API loopback posture is tracked in
|
|
2351
2350
|
* flair#654.
|
|
2352
2351
|
*/
|
|
2352
|
+
// ─── flair#1790: the ops-API seed names its failure and retries once ──────────
|
|
2353
|
+
//
|
|
2354
|
+
// Both seed helpers below insert through the operations API with a single bare
|
|
2355
|
+
// `fetch` under a 10 s client timeout. On a timeout that surfaced ONLY as an
|
|
2356
|
+
// undici `DOMException [TimeoutError]` stack — no operation, no target, no
|
|
2357
|
+
// timeout value — so a post-restart `flair init` that timed out produced an
|
|
2358
|
+
// unactionable failure and no daemon evidence.
|
|
2359
|
+
//
|
|
2360
|
+
// The wrap here names the failure and retries the insert ONCE, on the CLIENT
|
|
2361
|
+
// timeout only. The retry is safe because the insert is idempotent: a duplicate
|
|
2362
|
+
// answers 409 (or a "duplicate"/"already exists" body) and is treated as
|
|
2363
|
+
// success below, so a retried insert cannot double-apply. What is NOT retried:
|
|
2364
|
+
// an auth failure (401 keeps its existing hint) or any other HTTP or network
|
|
2365
|
+
// error — those are answers, not stalls.
|
|
2366
|
+
//
|
|
2367
|
+
// This is diagnosis + ergonomics, NOT a claim about WHY a seed timed out; the
|
|
2368
|
+
// mechanism is unknown (flair#1790).
|
|
2369
|
+
const OPS_AGENT_SEED_TIMEOUT_MS = 10_000;
|
|
2370
|
+
const OPS_AGENT_SEED_ATTEMPTS = 2;
|
|
2371
|
+
/**
|
|
2372
|
+
* A target URL safe to print: userinfo and query/fragment stripped. The seed
|
|
2373
|
+
* target is operator-supplied (`--target` / `--ops-target`), so it may carry
|
|
2374
|
+
* credentials or query values that must never reach init output or a log line.
|
|
2375
|
+
*/
|
|
2376
|
+
function sanitizeOpsTargetUrl(raw) {
|
|
2377
|
+
try {
|
|
2378
|
+
const u = new URL(raw);
|
|
2379
|
+
u.username = "";
|
|
2380
|
+
u.password = "";
|
|
2381
|
+
u.search = "";
|
|
2382
|
+
u.hash = "";
|
|
2383
|
+
return u.toString();
|
|
2384
|
+
}
|
|
2385
|
+
catch {
|
|
2386
|
+
return raw.replace(/\/\/[^/@]*@/, "//").split(/[?#]/)[0];
|
|
2387
|
+
}
|
|
2388
|
+
}
|
|
2389
|
+
/**
|
|
2390
|
+
* True only for the abort our OWN AbortSignal.timeout raises (never a server
|
|
2391
|
+
* answer, never a foreign abort). Checked by name AND by the attempt's own
|
|
2392
|
+
* signal being aborted (flair#1790 review S1), so a stray TimeoutError from some
|
|
2393
|
+
* other AbortSignal is not retried as if it were ours.
|
|
2394
|
+
*/
|
|
2395
|
+
function isOwnedSeedTimeout(err, signal) {
|
|
2396
|
+
const name = err?.name;
|
|
2397
|
+
if (name !== "TimeoutError" && name !== "AbortError")
|
|
2398
|
+
return false;
|
|
2399
|
+
return signal ? signal.aborted : true;
|
|
2400
|
+
}
|
|
2401
|
+
/**
|
|
2402
|
+
* The concise both-attempts-timed-out CLI error. `flairFriendly` makes runCli
|
|
2403
|
+
* print just this sentence (no undici/Node stack); the cause stays attached for
|
|
2404
|
+
* `--verbose`/diagnostics and is never printed by the default handler.
|
|
2405
|
+
*/
|
|
2406
|
+
function opsSeedBothAttemptsTimedOut(req, sanitizedUrl, cause) {
|
|
2407
|
+
const message = `Flair could not seed ${req.noun} '${req.id}': Operations API insert into ${req.tableName} at ` +
|
|
2408
|
+
`${sanitizedUrl} timed out on both attempts (${OPS_AGENT_SEED_TIMEOUT_MS} ms per attempt). ` +
|
|
2409
|
+
`Inspect the target daemon's logs, then rerun the same init command.\n` +
|
|
2410
|
+
`A timed-out insert may still complete; retrying the same ${req.noun} ID is supported.`;
|
|
2411
|
+
const err = new Error(message, { cause });
|
|
2412
|
+
err.flairFriendly = true;
|
|
2413
|
+
return err;
|
|
2414
|
+
}
|
|
2415
|
+
/**
|
|
2416
|
+
* POST one ops-API insert, retrying once on the client timeout. The response
|
|
2417
|
+
* body is read under the SAME attempt's signal, so each attempt's fresh
|
|
2418
|
+
* deadline covers the body read too. Returns normally on success or on the
|
|
2419
|
+
* idempotent duplicate path; throws a named error otherwise.
|
|
2420
|
+
*/
|
|
2421
|
+
async function opsSeedInsertWithRetry(req) {
|
|
2422
|
+
const sanitizedUrl = sanitizeOpsTargetUrl(req.url);
|
|
2423
|
+
const headers = {
|
|
2424
|
+
"Content-Type": "application/json",
|
|
2425
|
+
...(req.auth ? { Authorization: `Basic ${req.auth}` } : {}),
|
|
2426
|
+
};
|
|
2427
|
+
const overallStart = Date.now();
|
|
2428
|
+
for (let attempt = 1; attempt <= OPS_AGENT_SEED_ATTEMPTS; attempt++) {
|
|
2429
|
+
const attemptStart = Date.now();
|
|
2430
|
+
// A FRESH deadline per attempt; the response-body read runs under the SAME
|
|
2431
|
+
// signal, so it too is bounded by this attempt's timeout.
|
|
2432
|
+
const signal = AbortSignal.timeout(OPS_AGENT_SEED_TIMEOUT_MS);
|
|
2433
|
+
try {
|
|
2434
|
+
const res = await fetch(req.url, {
|
|
2435
|
+
method: "POST",
|
|
2436
|
+
headers,
|
|
2437
|
+
body: JSON.stringify(req.body),
|
|
2438
|
+
signal,
|
|
2439
|
+
});
|
|
2440
|
+
let text;
|
|
2441
|
+
try {
|
|
2442
|
+
text = await res.text();
|
|
2443
|
+
}
|
|
2444
|
+
catch (e) {
|
|
2445
|
+
// flair#1790 follow-up (A): an owned BODY-READ timeout is retryable ONLY
|
|
2446
|
+
// for an OK response — a 2xx whose body stalled is OUR stall, so retry
|
|
2447
|
+
// it. For a NON-OK response the STATUS is the answer: use empty text and
|
|
2448
|
+
// fall through to the status handling (401 → auth error first, then
|
|
2449
|
+
// 409/marker → duplicate) instead of retrying away the real error. A 401
|
|
2450
|
+
// whose body read stalls must stay the auth error, not become a
|
|
2451
|
+
// bogus "timed out on both attempts".
|
|
2452
|
+
if (res.ok && isOwnedSeedTimeout(e, signal))
|
|
2453
|
+
throw e;
|
|
2454
|
+
text = "";
|
|
2455
|
+
}
|
|
2456
|
+
// flair#1790 review C2: 401 FIRST. An auth failure must never be masked by
|
|
2457
|
+
// a body that happens to carry a "duplicate"/"already exists" marker.
|
|
2458
|
+
if (res.status === 401)
|
|
2459
|
+
throw new Error(req.auth401Message(text));
|
|
2460
|
+
// THEN the idempotent duplicate path: an unconditional 409, then the
|
|
2461
|
+
// marker match for the remaining non-OK shapes.
|
|
2462
|
+
const duplicate = res.status === 409 || text.includes("duplicate") || text.includes("already exists");
|
|
2463
|
+
if (!res.ok && !duplicate)
|
|
2464
|
+
throw new Error(req.httpErrorMessage(res.status, text));
|
|
2465
|
+
// Success, or the idempotent duplicate path.
|
|
2466
|
+
const outcome = res.ok ? "inserted" : "already exists";
|
|
2467
|
+
if (attempt > 1) {
|
|
2468
|
+
console.log(`${req.kind} seed attempt ${attempt} completed in ${Date.now() - attemptStart} ms (${outcome}); ` +
|
|
2469
|
+
`total ${Date.now() - overallStart} ms.`);
|
|
2470
|
+
}
|
|
2471
|
+
return;
|
|
2472
|
+
}
|
|
2473
|
+
catch (err) {
|
|
2474
|
+
// Auth / HTTP / other network errors are answers, not stalls: never retried.
|
|
2475
|
+
if (!isOwnedSeedTimeout(err, signal))
|
|
2476
|
+
throw err;
|
|
2477
|
+
if (attempt < OPS_AGENT_SEED_ATTEMPTS) {
|
|
2478
|
+
console.warn(`${req.kind} seed attempt ${attempt} timed out after ${OPS_AGENT_SEED_TIMEOUT_MS} ms; retrying once. ` +
|
|
2479
|
+
`Target: ${sanitizedUrl} (${req.noun} '${req.id}').`);
|
|
2480
|
+
continue;
|
|
2481
|
+
}
|
|
2482
|
+
throw opsSeedBothAttemptsTimedOut(req, sanitizedUrl, err);
|
|
2483
|
+
}
|
|
2484
|
+
}
|
|
2485
|
+
}
|
|
2353
2486
|
export async function seedAgentViaOpsApi(opsPortOrUrl, agentId, pubKeyB64url, adminUser, adminPass) {
|
|
2354
2487
|
const url = typeof opsPortOrUrl === "number"
|
|
2355
2488
|
? `http://127.0.0.1:${opsPortOrUrl}/`
|
|
@@ -2381,21 +2514,17 @@ export async function seedAgentViaOpsApi(opsPortOrUrl, agentId, pubKeyB64url, ad
|
|
|
2381
2514
|
updatedAt: now,
|
|
2382
2515
|
}],
|
|
2383
2516
|
};
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
body
|
|
2388
|
-
|
|
2517
|
+
await opsSeedInsertWithRetry({
|
|
2518
|
+
url,
|
|
2519
|
+
auth,
|
|
2520
|
+
body,
|
|
2521
|
+
kind: "Agent",
|
|
2522
|
+
noun: "agent",
|
|
2523
|
+
tableName: "flair.Agent",
|
|
2524
|
+
id: agentId,
|
|
2525
|
+
auth401Message: (text) => `Operations API insert failed (401): ${text}${opsAuth401Hint(auth === undefined ? undefined : adminUser)}`,
|
|
2526
|
+
httpErrorMessage: (status, text) => `Operations API insert failed (${status}): ${text}`,
|
|
2389
2527
|
});
|
|
2390
|
-
if (!res.ok) {
|
|
2391
|
-
const text = await res.text().catch(() => "");
|
|
2392
|
-
if (res.status === 409 || text.includes("duplicate") || text.includes("already exists"))
|
|
2393
|
-
return;
|
|
2394
|
-
if (res.status === 401) {
|
|
2395
|
-
throw new Error(`Operations API insert failed (401): ${text}${opsAuth401Hint(auth === undefined ? undefined : adminUser)}`);
|
|
2396
|
-
}
|
|
2397
|
-
throw new Error(`Operations API insert failed (${res.status}): ${text}`);
|
|
2398
|
-
}
|
|
2399
2528
|
}
|
|
2400
2529
|
// NOTE: agent records are seeded exclusively via the Harper operations API
|
|
2401
2530
|
// (seedAgentViaOpsApi above). A former seedAgentViaRestApi() helper POSTed the
|
|
@@ -2435,21 +2564,17 @@ export async function seedFederationInstanceViaOpsApi(opsPortOrUrl, instanceId,
|
|
|
2435
2564
|
updatedAt: now,
|
|
2436
2565
|
}],
|
|
2437
2566
|
};
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
body
|
|
2442
|
-
|
|
2567
|
+
await opsSeedInsertWithRetry({
|
|
2568
|
+
url,
|
|
2569
|
+
auth,
|
|
2570
|
+
body,
|
|
2571
|
+
kind: "Federation Instance",
|
|
2572
|
+
noun: "federation instance",
|
|
2573
|
+
tableName: "flair.Instance",
|
|
2574
|
+
id: instanceId,
|
|
2575
|
+
auth401Message: (text) => `Federation Instance insert via ops API failed (401): ${text}${opsAuth401Hint(auth === undefined ? undefined : adminUser)}`,
|
|
2576
|
+
httpErrorMessage: (status, text) => `Federation Instance insert via ops API failed (${status}): ${text}`,
|
|
2443
2577
|
});
|
|
2444
|
-
if (!res.ok) {
|
|
2445
|
-
const text = await res.text().catch(() => "");
|
|
2446
|
-
if (res.status === 409 || text.includes("duplicate") || text.includes("already exists"))
|
|
2447
|
-
return;
|
|
2448
|
-
if (res.status === 401) {
|
|
2449
|
-
throw new Error(`Federation Instance insert via ops API failed (401): ${text}${opsAuth401Hint(auth === undefined ? undefined : adminUser)}`);
|
|
2450
|
-
}
|
|
2451
|
-
throw new Error(`Federation Instance insert via ops API failed (${res.status}): ${text}`);
|
|
2452
|
-
}
|
|
2453
2578
|
}
|
|
2454
2579
|
// ─── Provision Flair on Harper Fabric ──────────────────────────────────────
|
|
2455
2580
|
//
|
|
@@ -2979,7 +3104,7 @@ export function probeOpenclawPluginVersion(extensionName) {
|
|
|
2979
3104
|
try {
|
|
2980
3105
|
// process.env.HOME first so tests can override; homedir() as fallback —
|
|
2981
3106
|
// homedir() doesn't honor runtime HOME changes (caches at module load).
|
|
2982
|
-
const home =
|
|
3107
|
+
const home = resolveHome();
|
|
2983
3108
|
const pkgJsonPath = resolve(home, ".openclaw", "extensions", extensionName, "package.json");
|
|
2984
3109
|
if (!existsSync(pkgJsonPath))
|
|
2985
3110
|
return null;
|
|
@@ -2991,43 +3116,13 @@ export function probeOpenclawPluginVersion(extensionName) {
|
|
|
2991
3116
|
}
|
|
2992
3117
|
}
|
|
2993
3118
|
/**
|
|
2994
|
-
*
|
|
2995
|
-
*
|
|
2996
|
-
*
|
|
2997
|
-
* (
|
|
3119
|
+
* Per-package status for the `flair upgrade` listing — the state set, the
|
|
3120
|
+
* direction-aware classifier and the renderers live ONCE in
|
|
3121
|
+
* src/lib/upgrade-status.ts and are re-exported here so existing importers keep
|
|
3122
|
+
* working (flair#1778). src/commands/upgrade.ts cannot import this file, so the
|
|
3123
|
+
* shared definition has to live outside both.
|
|
2998
3124
|
*/
|
|
2999
|
-
export
|
|
3000
|
-
if (status === "optional" && !showAll)
|
|
3001
|
-
return false;
|
|
3002
|
-
return true;
|
|
3003
|
-
}
|
|
3004
|
-
/**
|
|
3005
|
-
* Returns the human-readable suffix for a package status line in
|
|
3006
|
-
* `flair upgrade` / `flair upgrade --check` output.
|
|
3007
|
-
*
|
|
3008
|
-
* flair-mcp is zero-install via npx — its suffix must never suggest a
|
|
3009
|
-
* global install (flair#1168).
|
|
3010
|
-
*/
|
|
3011
|
-
export function upgradeStatusSuffix(name, status) {
|
|
3012
|
-
if (status === "current")
|
|
3013
|
-
return " (current)";
|
|
3014
|
-
if (status === "missing") {
|
|
3015
|
-
return name === FLAIR_MCP_PACKAGE
|
|
3016
|
-
? " (zero-install via npx — run: flair doctor --fix)"
|
|
3017
|
-
: " (run: npm install -g)";
|
|
3018
|
-
}
|
|
3019
|
-
if (status === "optional")
|
|
3020
|
-
return " (install via: openclaw plugins install @tpsdev-ai/openclaw-flair)";
|
|
3021
|
-
// flair-mcp is refreshed by re-pinning its wiring, never `npm install -g` —
|
|
3022
|
-
// a global bin does nothing for an `npx -y -p @tpsdev-ai/flair-mcp`
|
|
3023
|
-
// invocation (flair#1208). The re-pin is `flair upgrade`'s own job (the
|
|
3024
|
-
// #1135/#1167 pin refresh) — never advise `doctor --fix` for it
|
|
3025
|
-
// (flair#1324).
|
|
3026
|
-
if (status === "outdated" && name === FLAIR_MCP_PACKAGE) {
|
|
3027
|
-
return " (npx-wired — flair upgrade refreshes the pin)";
|
|
3028
|
-
}
|
|
3029
|
-
return "";
|
|
3030
|
-
}
|
|
3125
|
+
export { shouldPrintUpgradeLine, upgradeStatusSuffix };
|
|
3031
3126
|
/**
|
|
3032
3127
|
* Resolve the `flair upgrade` finding for flair-mcp from its ACTUAL wiring,
|
|
3033
3128
|
* not a global-install probe (flair#1208).
|
|
@@ -3042,7 +3137,8 @@ export function upgradeStatusSuffix(name, status) {
|
|
|
3042
3137
|
* 2. Not wired anywhere — genuinely missing; the remedy (upgradeStatusSuffix)
|
|
3043
3138
|
* is `flair doctor --fix`, never `npm install -g`.
|
|
3044
3139
|
* 3. Wired with a concrete pin — that pin IS the installed version
|
|
3045
|
-
* (current
|
|
3140
|
+
* (current / ahead / outdated by semver direction; outdated → re-pin via
|
|
3141
|
+
* doctor, ahead never re-pins down — flair#1778).
|
|
3046
3142
|
* 4. Wired but unpinned (a bare npx spec / a pre-#1143 SessionStart hook) —
|
|
3047
3143
|
* `npx -y` re-resolves latest every session, so the effective version IS
|
|
3048
3144
|
* latest → current.
|
|
@@ -3050,7 +3146,7 @@ export function upgradeStatusSuffix(name, status) {
|
|
|
3050
3146
|
export function resolveFlairMcpFinding(globalProbe, latest, wiring) {
|
|
3051
3147
|
// 1. Legacy global install.
|
|
3052
3148
|
if (globalProbe !== null) {
|
|
3053
|
-
return { installed: globalProbe, status: globalProbe
|
|
3149
|
+
return { installed: globalProbe, status: classifyInstalledVersion(globalProbe, latest) };
|
|
3054
3150
|
}
|
|
3055
3151
|
// 2. Not wired anywhere.
|
|
3056
3152
|
if (!wiring.wired) {
|
|
@@ -3060,7 +3156,7 @@ export function resolveFlairMcpFinding(globalProbe, latest, wiring) {
|
|
|
3060
3156
|
if (wiring.pinnedVersion) {
|
|
3061
3157
|
return {
|
|
3062
3158
|
installed: wiring.pinnedVersion,
|
|
3063
|
-
status: wiring.pinnedVersion
|
|
3159
|
+
status: classifyInstalledVersion(wiring.pinnedVersion, latest),
|
|
3064
3160
|
};
|
|
3065
3161
|
}
|
|
3066
3162
|
// 4. Wired but unpinned — npx resolves latest on every session.
|
|
@@ -3688,7 +3784,6 @@ bindUpgradeCli({
|
|
|
3688
3784
|
probeLibVersion,
|
|
3689
3785
|
probeOpenclawPluginVersion,
|
|
3690
3786
|
relativeTime,
|
|
3691
|
-
resolveAgentIdOrEnv,
|
|
3692
3787
|
resolveFabricCredentials,
|
|
3693
3788
|
resolveFlairMcpFinding,
|
|
3694
3789
|
resolveHttpPort,
|
|
@@ -4133,7 +4228,7 @@ async function confirmYes(question) {
|
|
|
4133
4228
|
* applies a new artifact that the old init could not have written.
|
|
4134
4229
|
*/
|
|
4135
4230
|
async function doctorRunAfterUpgrade(args) {
|
|
4136
|
-
const homeDir =
|
|
4231
|
+
const homeDir = resolveHome();
|
|
4137
4232
|
const keysDir = defaultKeysDir();
|
|
4138
4233
|
const detectedClientIds = detectClients().filter((c) => c.detected).map((c) => c.id);
|
|
4139
4234
|
// ── Version-keyed upgrade migrations (flair#1439) ─────────────────────────
|
|
@@ -4335,7 +4430,7 @@ export function buildRepairPlist(dataDir, config) {
|
|
|
4335
4430
|
passFile: {
|
|
4336
4431
|
launcher: launchdLauncherPath(),
|
|
4337
4432
|
adminPassFile: defaultAdminPassPath(),
|
|
4338
|
-
home:
|
|
4433
|
+
home: resolveHome(),
|
|
4339
4434
|
path: process.env.PATH ?? "/usr/bin:/bin:/usr/sbin:/sbin",
|
|
4340
4435
|
},
|
|
4341
4436
|
});
|
|
@@ -4527,7 +4622,7 @@ export async function writeInitLaunchdPlist(opts, deps = {}) {
|
|
|
4527
4622
|
passFile: {
|
|
4528
4623
|
launcher: launchdLauncherPath(),
|
|
4529
4624
|
adminPassFile: adminPassPath,
|
|
4530
|
-
home:
|
|
4625
|
+
home: resolveHome(),
|
|
4531
4626
|
path: process.env.PATH ?? "/usr/bin:/bin:/usr/sbin:/sbin",
|
|
4532
4627
|
},
|
|
4533
4628
|
});
|
|
@@ -4763,16 +4858,21 @@ async function repairLaunchdManagement(dataDir, port) {
|
|
|
4763
4858
|
// launchd's reported pid for this label.
|
|
4764
4859
|
if (plan.kind === "adopt") {
|
|
4765
4860
|
const label = after.label ?? resolveLaunchdLabel(dataDir).label;
|
|
4766
|
-
|
|
4767
|
-
|
|
4768
|
-
|
|
4769
|
-
|
|
4770
|
-
|
|
4771
|
-
|
|
4772
|
-
|
|
4861
|
+
// flair#1827: poll — the launchd-started Harper may not have written
|
|
4862
|
+
// hdb.pid or bound the port yet. Wait for it to serve (and for the
|
|
4863
|
+
// pre-adopt process to be gone), THEN prove identity with
|
|
4864
|
+
// verifyAdoptServing UNCHANGED on the final observation.
|
|
4865
|
+
const waited = await verifyAdoptServingWithWait({
|
|
4866
|
+
observe: () => ({
|
|
4867
|
+
directPid,
|
|
4868
|
+
managedPid: readLaunchctlJobState(label, realLaunchctlLister).pid,
|
|
4869
|
+
servingPid: resolveInstanceServingPid(dataDir, port),
|
|
4870
|
+
directPidAlive: directPid !== null && isProcessAlive(directPid),
|
|
4871
|
+
}),
|
|
4872
|
+
deadlineMs: STARTUP_TIMEOUT_MS,
|
|
4773
4873
|
});
|
|
4774
|
-
if (proof) {
|
|
4775
|
-
return { kind: "failed", detail: proof.detail, remedy: ["flair stop", "flair doctor --fix"] };
|
|
4874
|
+
if (waited.proof) {
|
|
4875
|
+
return { kind: "failed", detail: waited.proof.detail, remedy: ["flair stop", "flair doctor --fix"] };
|
|
4776
4876
|
}
|
|
4777
4877
|
}
|
|
4778
4878
|
// flair#1701: the launchd bounce (adopt and regenerate) is a first
|
|
@@ -4821,10 +4921,16 @@ async function stopDirectProcessForAdopt(port, dataDir) {
|
|
|
4821
4921
|
}
|
|
4822
4922
|
catch { /* best-effort — the port check below surfaces the real problem */ }
|
|
4823
4923
|
}
|
|
4824
|
-
|
|
4825
|
-
|
|
4826
|
-
|
|
4827
|
-
|
|
4924
|
+
// flair#1827: poll the post-stop health until the port is provably free — a
|
|
4925
|
+
// single observation that caught the listener mid-release flaked with "port
|
|
4926
|
+
// not confirmed free". decideAdoptStop is UNCHANGED; it decides on the final
|
|
4927
|
+
// observation, and a timeout names the wait and the last probe.
|
|
4928
|
+
const decision = await decideAdoptStopWithWait(state, {
|
|
4929
|
+
observe: () => probeHealth(port),
|
|
4930
|
+
deadlineMs: STARTUP_TIMEOUT_MS,
|
|
4931
|
+
});
|
|
4932
|
+
if (decision.decision !== "proceed")
|
|
4933
|
+
return decision.decision;
|
|
4828
4934
|
// Belt-and-suspenders: lsof confirms no TCP listener remains before the
|
|
4829
4935
|
// caller loads the plist. probeHealth "refused" (ECONNREFUSED) already means
|
|
4830
4936
|
// nothing is listening, but a port that is BOUND yet refuses connections
|
|
@@ -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";
|