@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/dist/commands/hook.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { homedir } from "node:os";
|
|
2
1
|
import * as render from "../render.js";
|
|
3
2
|
import { unpinnedSpecWarning } from "../lib/mcp-spec.js";
|
|
4
3
|
import { probeSessionStartHookDelivery, readClientMcpBlock } from "../doctor-client.js";
|
|
5
4
|
import { installHook, uninstallHook, hookStatus, hookStatusHeadline, hookStatusFailureLine, hookStatusIdentityLines, HOOK_STATUS_UNPARSED, installContinuityHooks, uninstallContinuityHooks, continuityHookStatus, isSupportedHarness, SUPPORTED_HARNESSES, hookInstallHint, harnessSupportsContinuity, resolveHookAgentId, } from "../hook-install.js";
|
|
5
|
+
import { resolveHome } from "../lib/home.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) {
|
|
@@ -51,7 +51,7 @@ export function register(program) {
|
|
|
51
51
|
.option("--continuity", "Wire the continuity capture hooks instead (PostToolUse + Stop — flair#1257; installing them IS the opt-in)")
|
|
52
52
|
.action((opts) => {
|
|
53
53
|
const harness = requireSupportedHarness(opts.harness);
|
|
54
|
-
const home =
|
|
54
|
+
const home = resolveHome();
|
|
55
55
|
const agentId = resolveHookAgentId(opts, home, harness);
|
|
56
56
|
if (!agentId) {
|
|
57
57
|
console.error("No agent id known — pass --agent <id>, set FLAIR_AGENT_ID, or run `flair init` / `flair agent add` first.");
|
|
@@ -98,7 +98,7 @@ export function register(program) {
|
|
|
98
98
|
.option("--continuity", "Remove the continuity capture hooks instead (PostToolUse + Stop — flair#1257)")
|
|
99
99
|
.action((opts) => {
|
|
100
100
|
const harness = requireSupportedHarness(opts.harness);
|
|
101
|
-
const home =
|
|
101
|
+
const home = resolveHome();
|
|
102
102
|
const dryRun = !!opts.dryRun;
|
|
103
103
|
if (opts.continuity) {
|
|
104
104
|
const result = uninstallContinuityHooks({ homeDir: home, harness, dryRun });
|
|
@@ -132,7 +132,7 @@ export function register(program) {
|
|
|
132
132
|
.option("--harness <name>", `Target harness (${SUPPORTED_HARNESSES.join(", ")})`, "claude-code")
|
|
133
133
|
.action((opts) => {
|
|
134
134
|
const harness = requireSupportedHarness(opts.harness);
|
|
135
|
-
const home =
|
|
135
|
+
const home = resolveHome();
|
|
136
136
|
const status = hookStatus(home, harness, {
|
|
137
137
|
deliveryProbe: (command) => probeSessionStartHookDelivery(command),
|
|
138
138
|
});
|
package/dist/commands/init.js
CHANGED
|
@@ -4,14 +4,15 @@ import { claudeCodeMcpEntry, detectClients, renderWiringSummary, wireAntigravity
|
|
|
4
4
|
import { DEFAULT_ADMIN_USER, authFetch, defaultAdminPassPath, defaultKeysDir, readAdminPassFileSecure, resolveAdminUser } from "../lib/auth-resolve.js";
|
|
5
5
|
import { detectPersistedAdminUser, executeAdminPasswordRotate, initAdminPassRefusalMessage, resolveInitAdminPasswordRefuseReason, resolveInitAdminPasswordSource, } from "../lib/init-admin-pass.js";
|
|
6
6
|
import { mcpServerSpec, unpinnedSpecWarning } from "../lib/mcp-spec.js";
|
|
7
|
+
import { opsSocketPathRefusal } from "../lib/socket-path-limit.js";
|
|
7
8
|
import * as render from "../render.js";
|
|
8
9
|
import { execSync, spawn } from "node:child_process";
|
|
9
10
|
import { randomBytes, randomUUID } from "node:crypto";
|
|
10
11
|
import { chmodSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
11
|
-
import {
|
|
12
|
-
import { join } from "node:path";
|
|
12
|
+
import { join, resolve } from "node:path";
|
|
13
13
|
import nacl from "tweetnacl";
|
|
14
14
|
import { httpCorsAccessList } from "../lib/http-bind.js";
|
|
15
|
+
import { resolveHome } from "../lib/home.js";
|
|
15
16
|
let cli;
|
|
16
17
|
/** Bind the cli-locals this module depends on. */
|
|
17
18
|
export function bindCli(fns) {
|
|
@@ -104,6 +105,9 @@ function resolveTarget(...args) {
|
|
|
104
105
|
function runSoulWizard(...args) {
|
|
105
106
|
return cli.runSoulWizard(...args);
|
|
106
107
|
}
|
|
108
|
+
function reconcileFederationInstanceViaOpsApi(...args) {
|
|
109
|
+
return cli.reconcileFederationInstanceViaOpsApi(...args);
|
|
110
|
+
}
|
|
107
111
|
function seedAgentViaOpsApi(...args) {
|
|
108
112
|
return cli.seedAgentViaOpsApi(...args);
|
|
109
113
|
}
|
|
@@ -198,7 +202,7 @@ export function register(program) {
|
|
|
198
202
|
flairAdminPass = randomBytes(24).toString("base64url");
|
|
199
203
|
}
|
|
200
204
|
// Write the flair admin pass to secrets directory
|
|
201
|
-
const secretsDir = join(
|
|
205
|
+
const secretsDir = join(resolveHome(), ".tps", "secrets");
|
|
202
206
|
mkdirSync(secretsDir, { recursive: true });
|
|
203
207
|
const secretPath = join(secretsDir, "flair-fabric-hdb");
|
|
204
208
|
writeFileSync(secretPath, flairAdminPass + "\n", { mode: 0o600 });
|
|
@@ -286,16 +290,38 @@ export function register(program) {
|
|
|
286
290
|
else {
|
|
287
291
|
console.log("No --agent-id provided -- skipping agent registration");
|
|
288
292
|
}
|
|
289
|
-
//
|
|
293
|
+
// Reconcile the federation Instance identity row if --remote (hub role).
|
|
294
|
+
// flair#1883: this used to INSERT a row with a fresh random id on every
|
|
295
|
+
// run, so a hub that had already answered a `GET /FederationInstance`
|
|
296
|
+
// (which find-or-creates a `spoke` row) ended up with TWO rows and no
|
|
297
|
+
// canonical identity. Reconciling keeps the row peers already know.
|
|
290
298
|
if (role) {
|
|
291
299
|
if (!pubKeyB64url) {
|
|
292
300
|
const kp = nacl.sign.keyPair();
|
|
293
301
|
pubKeyB64url = b64url(kp.publicKey);
|
|
294
302
|
}
|
|
295
303
|
instanceId = randomUUID();
|
|
296
|
-
console.log(`
|
|
297
|
-
|
|
298
|
-
|
|
304
|
+
console.log(`Reconciling federation Instance (role=${role}) via ops API...`);
|
|
305
|
+
let reconciled;
|
|
306
|
+
try {
|
|
307
|
+
reconciled = await reconcileFederationInstanceViaOpsApi(opsUrl, { instanceId, publicKey: pubKeyB64url }, adminUser, flairAdminPass);
|
|
308
|
+
}
|
|
309
|
+
catch (err) {
|
|
310
|
+
// A refusal (two rows) or an unreachable ops API — both are this
|
|
311
|
+
// command failing, and both already name what to do.
|
|
312
|
+
console.error(`Error: ${err?.message ?? err}`);
|
|
313
|
+
process.exit(1);
|
|
314
|
+
}
|
|
315
|
+
instanceId = reconciled.id;
|
|
316
|
+
if (reconciled.action === "created") {
|
|
317
|
+
console.log(`Federation Instance created: ${reconciled.id} (role=${role}) ✓`);
|
|
318
|
+
}
|
|
319
|
+
else if (reconciled.action === "updated") {
|
|
320
|
+
console.log(`Federation Instance reconciled: ${reconciled.id} is now role=${role} (id and key kept) ✓`);
|
|
321
|
+
}
|
|
322
|
+
else {
|
|
323
|
+
console.log(`Federation Instance already role=${role}: ${reconciled.id} — no change ✓`);
|
|
324
|
+
}
|
|
299
325
|
}
|
|
300
326
|
// Verify connectivity
|
|
301
327
|
if (didProvision) {
|
|
@@ -329,7 +355,7 @@ export function register(program) {
|
|
|
329
355
|
const displayTarget = target || opsTarget;
|
|
330
356
|
console.log(`\n✓ Flair hub deployed to ${displayTarget}`);
|
|
331
357
|
console.log(` Component: flair@${flavor}`);
|
|
332
|
-
console.log(` Admin user: ${adminUser} (pass written to ${join(
|
|
358
|
+
console.log(` Admin user: ${adminUser} (pass written to ${join(resolveHome(), ".tps", "secrets", "flair-fabric-hdb")})`);
|
|
333
359
|
if (instanceId)
|
|
334
360
|
console.log(` Instance: ${instanceId} (role=${role})`);
|
|
335
361
|
console.log(` Federation: ready — run \`flair federation token\` to mint a pairing token`);
|
|
@@ -349,7 +375,28 @@ export function register(program) {
|
|
|
349
375
|
}
|
|
350
376
|
// ── Local init (full one-command setup) ──
|
|
351
377
|
const keysDir = opts.keysDir ?? defaultKeysDir();
|
|
352
|
-
|
|
378
|
+
// Resolve ONCE, here: the operator means "relative to my shell's cwd", but
|
|
379
|
+
// Harper is spawned with cwd = the flair package directory, so a raw
|
|
380
|
+
// relative `--data-dir r` would make Harper bind
|
|
381
|
+
// <flairPackageDir>/r/operations-server — a different path from the one the
|
|
382
|
+
// preflight measured. Every downstream use (preflight, config/plist,
|
|
383
|
+
// ROOTPATH / HARPER_SET_CONFIG, messages) takes this resolved value.
|
|
384
|
+
const dataDir = opts.dataDir ? resolve(opts.dataDir) : defaultDataDir();
|
|
385
|
+
// flair#916: the Harper operations API is a Unix domain socket at
|
|
386
|
+
// `<data-dir>/operations-server`, and Unix socket paths are capped by
|
|
387
|
+
// `sun_path` (darwin 104 / linux 108, counting the trailing NUL, so the
|
|
388
|
+
// USABLE length is 103 / 107). A long `--data-dir` pushes the socket past
|
|
389
|
+
// the cap, and Harper then dies with a bare `listen EINVAL` that names
|
|
390
|
+
// neither the socket nor the limit — the worst moment (first run, no
|
|
391
|
+
// working install to compare against). Refuse HERE, before any install,
|
|
392
|
+
// config write, keypair, or Harper start: a refusal must leave nothing on
|
|
393
|
+
// disk. The socket path is built exactly as Harper binds it (join with the
|
|
394
|
+
// fixed "operations-server" suffix), so the measured length is the real one.
|
|
395
|
+
const socketRefusal = opsSocketPathRefusal(dataDir, process.platform);
|
|
396
|
+
if (socketRefusal) {
|
|
397
|
+
console.error(socketRefusal);
|
|
398
|
+
process.exit(1);
|
|
399
|
+
}
|
|
353
400
|
// "create" mode (flair#914): init ESTABLISHES an instance, so a data
|
|
354
401
|
// directory with no recorded port is a new instance taking the default,
|
|
355
402
|
// not the hard error every other caller gets — otherwise `flair init
|
|
@@ -1113,7 +1160,7 @@ export function register(program) {
|
|
|
1113
1160
|
// automatically here (same "just do it" shape as the MCP block
|
|
1114
1161
|
// above); --skip-claude-md opts out and prints the exact line to
|
|
1115
1162
|
// add by hand instead.
|
|
1116
|
-
const claudeMdResult = applyOrReportClaudeMdBootstrap(process.cwd(),
|
|
1163
|
+
const claudeMdResult = applyOrReportClaudeMdBootstrap(process.cwd(), resolveHome(), !!opts.skipClaudeMd);
|
|
1117
1164
|
console.log(` ${claudeMdResult.ok ? "✓" : "•"} ${claudeMdResult.message}`);
|
|
1118
1165
|
if (claudeMdResult.hint) {
|
|
1119
1166
|
for (const line of claudeMdResult.hint.split("\n"))
|
|
@@ -1124,7 +1171,7 @@ export function register(program) {
|
|
|
1124
1171
|
// ~/.claude/settings.json — without it, mcp__flair__bootstrap only
|
|
1125
1172
|
// ever runs if the agent remembers to call it itself.
|
|
1126
1173
|
// --skip-hook opts out and prints the exact JSON to add by hand.
|
|
1127
|
-
const hookResult = applyOrReportSessionStartHook(
|
|
1174
|
+
const hookResult = applyOrReportSessionStartHook(resolveHome(), agentId, !!opts.skipHook);
|
|
1128
1175
|
console.log(` ${hookResult.ok ? "✓" : "•"} ${hookResult.message}`);
|
|
1129
1176
|
if (hookResult.hint) {
|
|
1130
1177
|
for (const line of hookResult.hint.split("\n"))
|
|
@@ -1165,7 +1212,7 @@ export function register(program) {
|
|
|
1165
1212
|
// consent to set up the client, same as the Claude Code hook
|
|
1166
1213
|
// applied above. --skip-hook opts out and prints the JSON.
|
|
1167
1214
|
if (clientId === "codex" && result.ok) {
|
|
1168
|
-
const hookResult = applyOrReportSessionStartHook(
|
|
1215
|
+
const hookResult = applyOrReportSessionStartHook(resolveHome(), agentId, !!opts.skipHook, hookSettingsPath(resolveHome(), "codex"));
|
|
1169
1216
|
console.log(` ${hookResult.ok ? "✓" : "•"} ${hookResult.message}`);
|
|
1170
1217
|
if (hookResult.hint) {
|
|
1171
1218
|
for (const line of hookResult.hint.split("\n"))
|
package/dist/commands/mcp.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { chmodSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
|
-
import { homedir } from "node:os";
|
|
3
2
|
import { dirname, join } from "node:path";
|
|
4
3
|
import nacl from "tweetnacl";
|
|
5
4
|
import * as render from "../render.js";
|
|
6
5
|
import { defaultKeysDir, resolveAdminUser, resolveLocalAdminPass } from "../lib/auth-resolve.js";
|
|
7
6
|
import { resolveAgentKeyPath, loadEd25519PrivateKeyFromFile, signClientAssertion, buildTokenRequestForm, getMcpAccessToken, McpTokenRequestError, defaultMcpClientId, defaultMcpTokenEndpoint, defaultMcpResource, defaultMcpIssuer, MAX_ASSERTION_LIFETIME_SECONDS, } from "../mcp-client-assertion.js";
|
|
8
7
|
import { enableMcp, disableMcp, mcpStatus, checkLocalOriginRefusal, selfVerifyMcpMetadata, } from "../lib/mcp-enable.js";
|
|
8
|
+
import { resolveHome } from "../lib/home.js";
|
|
9
9
|
let cli;
|
|
10
10
|
/** Bind shared CLI helpers. cli.ts calls this immediately before register(program). */
|
|
11
11
|
export function bindCli(fns) {
|
|
@@ -27,7 +27,7 @@ function b64url(bytes) {
|
|
|
27
27
|
* admin-pass/config.yaml — independent of --keys-dir (a custom keys dir
|
|
28
28
|
* doesn't imply a custom manifest location, and vice versa). */
|
|
29
29
|
export function defaultMcpClientManifestPath() {
|
|
30
|
-
return join(
|
|
30
|
+
return join(resolveHome(), ".flair", "mcp-clients.json");
|
|
31
31
|
}
|
|
32
32
|
/** Read the manifest; a missing file is "no clients granted yet", not an
|
|
33
33
|
* error. Malformed JSON is also treated as empty (defensive — a corrupt
|
|
@@ -2,8 +2,8 @@ import { authFetch, resolveAdminUser } from "../lib/auth-resolve.js";
|
|
|
2
2
|
import { load as parseYaml } from "js-yaml";
|
|
3
3
|
import { randomUUID } from "node:crypto";
|
|
4
4
|
import { existsSync, mkdirSync, readFileSync, readdirSync, renameSync } from "node:fs";
|
|
5
|
-
import { homedir } from "node:os";
|
|
6
5
|
import { join, resolve, sep } from "node:path";
|
|
6
|
+
import { resolveHome } from "../lib/home.js";
|
|
7
7
|
let cli;
|
|
8
8
|
/** Bind the cli-locals this module depends on. */
|
|
9
9
|
export function bindCli(fns) {
|
|
@@ -17,9 +17,9 @@ function resolveMemoryDir(target, agentId) {
|
|
|
17
17
|
case "claude-code": {
|
|
18
18
|
const cwd = process.cwd();
|
|
19
19
|
const encodedCwd = encodeURIComponent(cwd).replace(/%2F/g, "/");
|
|
20
|
-
const memoryDir = join(
|
|
20
|
+
const memoryDir = join(resolveHome(), ".claude", "projects", encodedCwd, "memory");
|
|
21
21
|
const resolved = resolve(memoryDir);
|
|
22
|
-
const expectedRoot = join(
|
|
22
|
+
const expectedRoot = join(resolveHome(), ".claude", "projects");
|
|
23
23
|
if (!resolved.startsWith(expectedRoot + sep)) {
|
|
24
24
|
throw new Error(`Memory dir must be within ${expectedRoot}, got ${resolved}`);
|
|
25
25
|
}
|
|
@@ -28,9 +28,9 @@ function resolveMemoryDir(target, agentId) {
|
|
|
28
28
|
case "openclaw": {
|
|
29
29
|
const cwd = process.cwd();
|
|
30
30
|
const encodedCwd = encodeURIComponent(cwd).replace(/%2F/g, "/");
|
|
31
|
-
const memoryDir = join(
|
|
31
|
+
const memoryDir = join(resolveHome(), ".openclaw", "projects", encodedCwd, "memory");
|
|
32
32
|
const resolved = resolve(memoryDir);
|
|
33
|
-
const expectedRoot = join(
|
|
33
|
+
const expectedRoot = join(resolveHome(), ".openclaw", "projects");
|
|
34
34
|
if (!resolved.startsWith(expectedRoot + sep)) {
|
|
35
35
|
throw new Error(`Memory dir must be within ${expectedRoot}, got ${resolved}`);
|
|
36
36
|
}
|
|
@@ -39,9 +39,9 @@ function resolveMemoryDir(target, agentId) {
|
|
|
39
39
|
case "pi": {
|
|
40
40
|
const cwd = process.cwd();
|
|
41
41
|
const encodedCwd = encodeURIComponent(cwd).replace(/%2F/g, "/");
|
|
42
|
-
const memoryDir = join(
|
|
42
|
+
const memoryDir = join(resolveHome(), ".pi", "projects", encodedCwd, "memory");
|
|
43
43
|
const resolved = resolve(memoryDir);
|
|
44
|
-
const expectedRoot = join(
|
|
44
|
+
const expectedRoot = join(resolveHome(), ".pi", "projects");
|
|
45
45
|
if (!resolved.startsWith(expectedRoot + sep)) {
|
|
46
46
|
throw new Error(`Memory dir must be within ${expectedRoot}, got ${resolved}`);
|
|
47
47
|
}
|
|
@@ -187,7 +187,7 @@ export function register(program) {
|
|
|
187
187
|
try {
|
|
188
188
|
const httpUrl = `http://127.0.0.1:${resolveHttpPort({})}`;
|
|
189
189
|
const agentKeyId = `${agentId}.key`;
|
|
190
|
-
const keysDir = join(
|
|
190
|
+
const keysDir = join(resolveHome(), ".flair", "keys");
|
|
191
191
|
const keyPath = join(keysDir, agentKeyId);
|
|
192
192
|
let authSuccess = false;
|
|
193
193
|
if (existsSync(keyPath)) {
|
package/dist/commands/rem.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { existsSync, mkdirSync, writeFileSync, rmSync } from "node:fs";
|
|
2
|
-
import { homedir } from "node:os";
|
|
3
2
|
import { dirname, resolve } from "node:path";
|
|
4
3
|
import * as render from "../render.js";
|
|
5
4
|
import { isLocalBase, resolveAdminUser, resolveLocalAdminPass } from "../lib/auth-resolve.js";
|
|
6
5
|
import { validatePromoteOpts, validateRejectOpts, decideCandidateAction, derivePromotedTags, validateHumanReviewerId, structuralImbalance, hasTerminalPunctuation, } from "../rem/promote-policy.js";
|
|
6
|
+
import { resolveHome } from "../lib/home.js";
|
|
7
7
|
export { validatePromoteOpts, validateRejectOpts, decideCandidateAction, derivePromotedTags, derivePromotedVisibility, validateHumanReviewerId, isMachineReviewerId, ADK_SCOPE_TAG_PREFIX, CONTINUITY_SCOPE_TAG_PREFIX, MACHINE_REVIEWER_PREFIX, MACHINE_REVIEWER_ADK_AUTO_PROMOTE, } from "../rem/promote-policy.js";
|
|
8
8
|
let cli;
|
|
9
9
|
/** Bind shared CLI helpers. cli.ts calls this immediately before register(program). */
|
|
@@ -120,7 +120,7 @@ export function describeReflectError(message) {
|
|
|
120
120
|
}
|
|
121
121
|
return { kind: "other", text: message };
|
|
122
122
|
}
|
|
123
|
-
const REM_PAUSE_FLAG = resolve(
|
|
123
|
+
const REM_PAUSE_FLAG = resolve(resolveHome(), ".flair", "rem.paused");
|
|
124
124
|
function writeRemPauseSentinel() {
|
|
125
125
|
const dir = dirname(REM_PAUSE_FLAG);
|
|
126
126
|
if (!existsSync(dir))
|
package/dist/commands/service.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { DEFAULT_ADMIN_USER } from "../lib/auth-resolve.js";
|
|
2
2
|
import { classifyDaemonState } from "../lib/daemon-liveness.js";
|
|
3
3
|
import { diagnoseLaunchdPlistPaths, isDetached, renderDetachedWarning } from "../lib/launchd-management.js";
|
|
4
|
+
import { opsSocketPathRefusal } from "../lib/socket-path-limit.js";
|
|
4
5
|
import { spawn } from "node:child_process";
|
|
5
6
|
import { existsSync } from "node:fs";
|
|
6
7
|
import { join } from "node:path";
|
|
@@ -165,6 +166,17 @@ export function register(program) {
|
|
|
165
166
|
.action(async (opts) => {
|
|
166
167
|
const port = resolveHttpPort(opts);
|
|
167
168
|
const dataDir = defaultDataDir();
|
|
169
|
+
// flair#916: the operations socket is a Unix domain socket whose path is
|
|
170
|
+
// capped by sun_path (darwin 103 / linux 107, NUL-excluded); a too-long
|
|
171
|
+
// data dir would make Harper die with a bare `listen EINVAL` on boot.
|
|
172
|
+
// This command uses the hardcoded defaultDataDir() today, so the limit is
|
|
173
|
+
// unreachable here — the preflight is defensive against a future
|
|
174
|
+
// --data-dir or a lengthened default. Refuse before touching disk.
|
|
175
|
+
const socketRefusal = opsSocketPathRefusal(dataDir, process.platform);
|
|
176
|
+
if (socketRefusal) {
|
|
177
|
+
console.error(socketRefusal);
|
|
178
|
+
process.exit(1);
|
|
179
|
+
}
|
|
168
180
|
// Already-running check via the five-state liveness machine (flair#1454).
|
|
169
181
|
// The old check was a bare `fetch /Health` that treated "got a response"
|
|
170
182
|
// as "already running" and exited 0 — half of #1454. Now the machine
|
|
@@ -295,8 +307,20 @@ export function register(program) {
|
|
|
295
307
|
// Explicit, not defaulted inside restartFlair (flair#902): `flair
|
|
296
308
|
// restart` has no --data-dir, so the default install IS what it means —
|
|
297
309
|
// and saying so here is what keeps that true when someone adds one.
|
|
310
|
+
// flair#916: the same defensive preflight `flair start` runs — the
|
|
311
|
+
// operations socket path is capped by sun_path; refuse here, before a
|
|
312
|
+
// restart touches the instance, rather than let Harper die with a bare
|
|
313
|
+
// `listen EINVAL` on boot. `restart` uses the hardcoded defaultDataDir()
|
|
314
|
+
// today, so the limit is unreachable; this is defense against a future
|
|
315
|
+
// --data-dir or a lengthened default.
|
|
316
|
+
const dataDir = defaultDataDir();
|
|
317
|
+
const socketRefusal = opsSocketPathRefusal(dataDir, process.platform);
|
|
318
|
+
if (socketRefusal) {
|
|
319
|
+
console.error(socketRefusal);
|
|
320
|
+
process.exit(1);
|
|
321
|
+
}
|
|
298
322
|
try {
|
|
299
|
-
await restartFlair(port,
|
|
323
|
+
await restartFlair(port, dataDir);
|
|
300
324
|
// flair#1022: a restart that fell back off launchd left the instance
|
|
301
325
|
// running but unmanaged, and "✅ Flair restarted" was true of both
|
|
302
326
|
// outcomes. Ask launchd what it is actually running now — an
|
package/dist/commands/session.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { existsSync, mkdirSync, writeFileSync, readFileSync, chmodSync, rmSync, readdirSync, statSync } from "node:fs";
|
|
2
|
-
import { homedir } from "node:os";
|
|
3
2
|
import { resolve } from "node:path";
|
|
4
3
|
import { create as tarCreate, extract as tarExtract, list as tarList } from "tar";
|
|
5
4
|
import { validateSnapshotArchive } from "../lib/safe-snapshot-extract.js";
|
|
5
|
+
import { resolveHome } from "../lib/home.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) {
|
|
@@ -21,7 +21,7 @@ export function register(program) {
|
|
|
21
21
|
//
|
|
22
22
|
// Standalone-callable today; harness slices 3+4 will wire it into the
|
|
23
23
|
// session-reset pipeline.
|
|
24
|
-
const SNAPSHOT_ROOT = resolve(
|
|
24
|
+
const SNAPSHOT_ROOT = resolve(resolveHome(), ".flair", "snapshots");
|
|
25
25
|
function sessionSnapshotDir(agent) {
|
|
26
26
|
if (!/^[a-zA-Z0-9_-]+$/.test(agent))
|
|
27
27
|
throw new Error(`invalid agent id: ${agent}`);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { formatPurgeReport, purgeFlairInstall, purgeHadFailures } from "../lib/uninstall-purge.js";
|
|
2
2
|
import { existsSync, unlinkSync } from "node:fs";
|
|
3
|
-
import {
|
|
3
|
+
import { resolveHome } from "../lib/home.js";
|
|
4
4
|
let cli;
|
|
5
5
|
/** Bind the cli-locals this module depends on. */
|
|
6
6
|
export function bindCli(fns) {
|
|
@@ -127,7 +127,7 @@ export function register(program) {
|
|
|
127
127
|
console.log("Stop the process manually, then re-run: flair uninstall --purge");
|
|
128
128
|
}
|
|
129
129
|
else {
|
|
130
|
-
const home =
|
|
130
|
+
const home = resolveHome();
|
|
131
131
|
const result = purgeFlairInstall({ homeDir: home });
|
|
132
132
|
const report = formatPurgeReport(result);
|
|
133
133
|
console.log(report.lines.join("\n"));
|
package/dist/commands/upgrade.js
CHANGED
|
@@ -16,10 +16,10 @@ import { probeInstance } from "../probe.js";
|
|
|
16
16
|
import * as render from "../render.js";
|
|
17
17
|
import { FLAIR_PKG_NAME, primeVersionCheckCache } from "../version-check.js";
|
|
18
18
|
import { chmodSync, existsSync, lstatSync, mkdirSync, readdirSync, realpathSync, rmSync, statSync } from "node:fs";
|
|
19
|
-
import { homedir } from "node:os";
|
|
20
19
|
import { join, resolve, sep } from "node:path";
|
|
21
20
|
import { create as tarCreate } from "tar";
|
|
22
21
|
import { classifyInstalledVersion, formatUpgradeStatusLine } from "../lib/upgrade-status.js";
|
|
22
|
+
import { resolveHome } from "../lib/home.js";
|
|
23
23
|
let cli;
|
|
24
24
|
/** Bind the cli-locals this module depends on. */
|
|
25
25
|
export function bindCli(fns) {
|
|
@@ -922,7 +922,7 @@ export function register(program) {
|
|
|
922
922
|
// the NORMAL state, not "missing". Resolve it from its actual wiring
|
|
923
923
|
// (the pin in a client MCP config / the SessionStart hook) so the
|
|
924
924
|
// listing is truthful and the remedy actually works (flair#1208).
|
|
925
|
-
const home =
|
|
925
|
+
const home = resolveHome();
|
|
926
926
|
({ installed, status } = resolveFlairMcpFinding(globalProbe, latest, detectWiredFlairMcp(home)));
|
|
927
927
|
}
|
|
928
928
|
else {
|
|
@@ -1048,7 +1048,7 @@ export function register(program) {
|
|
|
1048
1048
|
// client's env — rewriting each client's FLAIR_AGENT_ID to whichever key
|
|
1049
1049
|
// happened to sort first. The writer preserves each entry's own identity
|
|
1050
1050
|
// and changes only the pinned package argument.
|
|
1051
|
-
const homeDir =
|
|
1051
|
+
const homeDir = resolveHome();
|
|
1052
1052
|
const results = refreshOwnedPins({ homeDir });
|
|
1053
1053
|
const noteworthy = results.filter(ownedPinRefreshShouldReport);
|
|
1054
1054
|
if (noteworthy.length === 0)
|
package/dist/doctor-client.js
CHANGED
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
import { spawnSync } from "node:child_process";
|
|
23
23
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
24
24
|
import { dirname, join } from "node:path";
|
|
25
|
+
import { withHome } from "./lib/home.js";
|
|
25
26
|
import { ALL_CLIENTS, clientConfigPath, piSettingsPath, resolvePiExtensionPath, scanPiSettings, } from "./install/clients.js";
|
|
26
27
|
import { FLAIR_MCP_PACKAGE, flairCliVersion, mcpServerSpec } from "./lib/mcp-spec.js";
|
|
27
28
|
import { decidePinWrite } from "./lib/pin-write-guard.js";
|
|
@@ -579,29 +580,10 @@ export function removeContinuityCaptureHooks(homeDir) {
|
|
|
579
580
|
}
|
|
580
581
|
}
|
|
581
582
|
// ── shared helpers ──────────────────────────────────────────────────────────
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
* that single source of truth for per-client config paths while keeping
|
|
587
|
-
* doctor-client's own functions parameterized by an explicit homeDir for
|
|
588
|
-
* tests — no test ever touches the real ~/.claude.json etc. The override is
|
|
589
|
-
* synchronous and restored before this function returns, so it's safe even
|
|
590
|
-
* though process.env is process-global.
|
|
591
|
-
*/
|
|
592
|
-
function withHome(homeDir, fn) {
|
|
593
|
-
const prev = process.env.HOME;
|
|
594
|
-
process.env.HOME = homeDir;
|
|
595
|
-
try {
|
|
596
|
-
return fn();
|
|
597
|
-
}
|
|
598
|
-
finally {
|
|
599
|
-
if (prev === undefined)
|
|
600
|
-
delete process.env.HOME;
|
|
601
|
-
else
|
|
602
|
-
process.env.HOME = prev;
|
|
603
|
-
}
|
|
604
|
-
}
|
|
583
|
+
// `withHome()` (src/lib/home.ts) points HOME and USERPROFILE at an explicit
|
|
584
|
+
// homeDir for a synchronous callback; clientConfigPath() (src/install/clients.ts)
|
|
585
|
+
// resolves the home at call time, so doctor-client's explicit-homeDir functions
|
|
586
|
+
// reuse that single source of truth and no test touches the real ~/.claude.json.
|
|
605
587
|
function readTextFile(path) {
|
|
606
588
|
try {
|
|
607
589
|
if (!existsSync(path))
|
package/dist/engine-version.js
CHANGED
|
@@ -18,12 +18,12 @@
|
|
|
18
18
|
// the engine cannot boot, we still need to read it.
|
|
19
19
|
import { existsSync, readdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
20
20
|
import { join, resolve } from "node:path";
|
|
21
|
-
import { homedir } from "node:os";
|
|
22
21
|
import { fetchDeclaredDependencies } from "./lib/npm-registry.js";
|
|
22
|
+
import { resolveHome } from "./lib/home.js";
|
|
23
23
|
/** Filename of the engine-version stamp inside the data directory. */
|
|
24
24
|
export const ENGINE_VERSION_STAMP = "engine-version.txt";
|
|
25
25
|
/** Root directory for pre-upgrade snapshots (~/.flair/upgrade-snapshots). */
|
|
26
|
-
export const UPGRADE_SNAPSHOT_ROOT = resolve(
|
|
26
|
+
export const UPGRADE_SNAPSHOT_ROOT = resolve(resolveHome(), ".flair", "upgrade-snapshots");
|
|
27
27
|
/** Read the Harper version installed alongside this flair package. */
|
|
28
28
|
export function readInstalledHarperVersion(packageRoot) {
|
|
29
29
|
for (const name of ["harper", "@harperfast/harper"]) {
|
|
@@ -59,16 +59,16 @@
|
|
|
59
59
|
*/
|
|
60
60
|
import { existsSync, chmodSync, rmSync, readFileSync, mkdirSync } from "node:fs";
|
|
61
61
|
import { resolve, dirname } from "node:path";
|
|
62
|
-
import { homedir } from "node:os";
|
|
63
62
|
import { fileURLToPath } from "node:url";
|
|
64
63
|
import { escapeXml } from "../lib/xml-escape.js";
|
|
65
64
|
import { detectPlatform as detectPlatformFor, spawnReport, readTemplate, renderTemplateWith, writeFileWithDir, interpretActiveResult, describeLoadFailure as describeLoadFailureFor, describeExitCode, resolveNodeBin, resolveFlairBin, formatFlairBinWarning, verifyFirstRun, probeUserLingerEnabled, STATUS_CHECK_TIMEOUT_MS, } from "../lib/scheduler-platform.js";
|
|
65
|
+
import { resolveHome } from "../lib/home.js";
|
|
66
66
|
export const LAUNCHD_LABEL = "dev.flair.federation.sync";
|
|
67
67
|
export const SYSTEMD_TIMER_UNIT = "flair-federation-sync.timer";
|
|
68
68
|
export const SYSTEMD_SERVICE_UNIT = "flair-federation-sync.service";
|
|
69
|
-
export const SHIM_PATH_DEFAULT = resolve(
|
|
70
|
-
export const LAUNCHD_PLIST_PATH = resolve(
|
|
71
|
-
export const SYSTEMD_USER_DIR = resolve(
|
|
69
|
+
export const SHIM_PATH_DEFAULT = resolve(resolveHome(), ".flair", "bin", "flair-federation-sync");
|
|
70
|
+
export const LAUNCHD_PLIST_PATH = resolve(resolveHome(), "Library", "LaunchAgents", `${LAUNCHD_LABEL}.plist`);
|
|
71
|
+
export const SYSTEMD_USER_DIR = resolve(resolveHome(), ".config", "systemd", "user");
|
|
72
72
|
export const SYSTEMD_TIMER_PATH = resolve(SYSTEMD_USER_DIR, SYSTEMD_TIMER_UNIT);
|
|
73
73
|
export const SYSTEMD_SERVICE_PATH = resolve(SYSTEMD_USER_DIR, SYSTEMD_SERVICE_UNIT);
|
|
74
74
|
/** Default seconds between one-shot syncs. See the module header for why 300. */
|
|
@@ -143,7 +143,7 @@ function buildSubstitutions(opts, shimPath, flairBin, nodeBin) {
|
|
|
143
143
|
FLAIR_BIN: flairBin,
|
|
144
144
|
NODE_BIN: nodeBin,
|
|
145
145
|
SHIM_PATH: shimPath,
|
|
146
|
-
HOME: opts.homeOverride ??
|
|
146
|
+
HOME: opts.homeOverride ?? resolveHome(),
|
|
147
147
|
INTERVAL_SECONDS: String(opts.intervalSeconds),
|
|
148
148
|
ADMIN_PASS_FILE: adminPassFile,
|
|
149
149
|
FLAIR_TARGET: opts.target ?? "",
|
package/dist/install/clients.js
CHANGED
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
// per-client locations under $HOME / $XDG_CONFIG_HOME.
|
|
21
21
|
// ---- Detection helpers ----------------------------------------------------------
|
|
22
22
|
import { accessSync, constants, existsSync, mkdirSync } from "node:fs";
|
|
23
|
-
import { homedir } from "node:os";
|
|
24
23
|
import { dirname, join } from "node:path";
|
|
24
|
+
import { resolveHome } from "../lib/home.js";
|
|
25
25
|
import { FLAIR_MCP_PACKAGE, flairCliVersion, isResolvedVersion, mcpServerSpec } from "../lib/mcp-spec.js";
|
|
26
26
|
import { decodeWiringSpec, wiringPinString } from "../lib/wiring-spec.js";
|
|
27
27
|
import { decidePinWrite } from "../lib/pin-write-guard.js";
|
|
@@ -44,15 +44,10 @@ function manualWireMessage(label, display, reason, env) {
|
|
|
44
44
|
return (`${label}: manual wiring needed (could not write ${display}: ${reason}).\n` +
|
|
45
45
|
` Add this to ${display}:\n${indent(jsonSnippet(env))}`);
|
|
46
46
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
* override"). Production behavior is unchanged (HOME is set on every OS).
|
|
52
|
-
*/
|
|
53
|
-
export function resolveHome() {
|
|
54
|
-
return process.env.HOME || process.env.USERPROFILE || homedir();
|
|
55
|
-
}
|
|
47
|
+
// The shared home resolver (src/lib/home.ts, flair#1853 round 3): resolved at
|
|
48
|
+
// call time, with the platform rule (Windows -> USERPROFILE, elsewhere -> HOME).
|
|
49
|
+
// Re-exported so importers of this module keep their existing entry point.
|
|
50
|
+
export { resolveHome };
|
|
56
51
|
/**
|
|
57
52
|
* Check if a command exists in PATH (cross-platform alternative to `which`).
|
|
58
53
|
* Does not spawn a child process — pure filesystem check.
|
package/dist/keystore.js
CHANGED
|
@@ -10,11 +10,19 @@
|
|
|
10
10
|
*/
|
|
11
11
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
12
12
|
import { join } from "node:path";
|
|
13
|
-
import {
|
|
13
|
+
import { resolveHome } from "./lib/home.js";
|
|
14
14
|
import { randomBytes, createCipheriv, createDecipheriv, hkdfSync, } from "node:crypto";
|
|
15
15
|
// ─── Helpers ────────────────────────────────────────────────────────────────
|
|
16
|
+
/**
|
|
17
|
+
* The keystore's home comes from the ONE shared resolver (src/lib/home.ts,
|
|
18
|
+
* flair#1853 round 3): resolved at CALL time, with the platform rule (Windows
|
|
19
|
+
* uses USERPROFILE, everywhere else HOME). The runtime caches `os.homedir()` at
|
|
20
|
+
* process start, so a HOME set after start — the test harness in
|
|
21
|
+
* test/helpers/sandbox-home.ts — would otherwise be invisible and the keystore
|
|
22
|
+
* would reach the REAL ~/.flair/keys.
|
|
23
|
+
*/
|
|
16
24
|
function keysDir() {
|
|
17
|
-
return join(
|
|
25
|
+
return join(resolveHome(), ".flair", "keys");
|
|
18
26
|
}
|
|
19
27
|
function keyPath(instanceId) {
|
|
20
28
|
// Sanitize instanceId to prevent directory traversal
|
package/dist/lib/auth-resolve.js
CHANGED
|
@@ -63,9 +63,9 @@
|
|
|
63
63
|
* conflict (`--admin-pass` + `--agent`) is never quiet either.
|
|
64
64
|
*/
|
|
65
65
|
import { existsSync, readFileSync, readdirSync, statSync, } from "node:fs";
|
|
66
|
-
import { homedir } from "node:os";
|
|
67
66
|
import { join } from "node:path";
|
|
68
67
|
import { createPrivateKey, randomUUID, sign as nodeCryptoSign } from "node:crypto";
|
|
68
|
+
import { resolveHome } from "./home.js";
|
|
69
69
|
// ─── Failure classification ─────────────────────────────────────────────────
|
|
70
70
|
/**
|
|
71
71
|
* Thrown by `sendJsonRequest` for an HTTP-level failure (as opposed to a
|
|
@@ -128,9 +128,55 @@ export function readSecretFileSecure(path, flagName) {
|
|
|
128
128
|
export function readAdminPassFileSecure(path) {
|
|
129
129
|
return readSecretFileSecure(path, "--admin-pass-file");
|
|
130
130
|
}
|
|
131
|
+
/** Thrown by `resolveAdminPassFromSources` when two credential sources are given at once. */
|
|
132
|
+
export class AdminPassSourceError extends Error {
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Resolve an admin password from the credential sources a command exposes, in
|
|
136
|
+
* the precedence its usage text states: an explicit option — `--admin-pass-file`
|
|
137
|
+
* or `--admin-pass` (the form the help warns against) — over the ambient
|
|
138
|
+
* `FLAIR_ADMIN_PASS`/`HDB_ADMIN_PASSWORD`. Explicit beats ambient, the same rule
|
|
139
|
+
* `resolveLocalAdminPass` applies to `--admin-pass`, so a value the operator
|
|
140
|
+
* typed is never silently replaced by one the shell happened to carry.
|
|
141
|
+
* Supplying BOTH `--admin-pass-file` and `--admin-pass` is refused: two explicit
|
|
142
|
+
* sources at once is ambiguous, and one of them is the discouraged argv form. The file is read through `readAdminPassFileSecure` — the same
|
|
143
|
+
* reader `flair backup` uses — so a group- or world-readable file is refused
|
|
144
|
+
* with a message naming the path and its mode.
|
|
145
|
+
*
|
|
146
|
+
* Returns "" when no source is set, so the caller owns its own "credential
|
|
147
|
+
* required" message; throws `AdminPassSourceError` on a conflict, or
|
|
148
|
+
* `readAdminPassFileSecure`'s error when the file is missing, empty or too
|
|
149
|
+
* open. Neither message carries the password value.
|
|
150
|
+
*/
|
|
151
|
+
export function resolveAdminPassFromSources(input) {
|
|
152
|
+
const { adminPassFile, adminPass, envPass } = input;
|
|
153
|
+
if (adminPassFile && adminPass) {
|
|
154
|
+
throw new AdminPassSourceError("--admin-pass and --admin-pass-file cannot be combined; pass exactly one. " +
|
|
155
|
+
"Prefer --admin-pass-file: it keeps the password out of shell history and the process list.");
|
|
156
|
+
}
|
|
157
|
+
if (adminPassFile)
|
|
158
|
+
return readAdminPassFileSecure(adminPassFile);
|
|
159
|
+
if (adminPass)
|
|
160
|
+
return adminPass;
|
|
161
|
+
return envPass ?? "";
|
|
162
|
+
}
|
|
131
163
|
export function defaultAdminPassPath() {
|
|
132
|
-
return join(
|
|
164
|
+
return join(resolveHome(), ".flair", "admin-pass");
|
|
133
165
|
}
|
|
166
|
+
// ─── The ONE admin-password option surface (flair#1910) ─────────────────────
|
|
167
|
+
//
|
|
168
|
+
// Every command that declares the admin-password pair declares the SAME two
|
|
169
|
+
// flags with the SAME help, so the file form is recommended identically
|
|
170
|
+
// everywhere and the argv form always carries its leak warning. Defined here,
|
|
171
|
+
// next to the resolver both forms feed (`resolveAdminPassFromSources`), so the
|
|
172
|
+
// two surfaces cannot drift between `federation token`/`pair` (which declared
|
|
173
|
+
// these strings locally, flair#1873) and the shared credential-option helper
|
|
174
|
+
// every sibling command uses.
|
|
175
|
+
export const ADMIN_PASS_FILE_FLAG = "--admin-pass-file <path>";
|
|
176
|
+
export const ADMIN_PASS_FILE_HELP = "Read the admin password from an owner-only file (mode 0600 enforced), keeping it out of shell history and the process list. " +
|
|
177
|
+
"An explicit option (this or --admin-pass) overrides FLAIR_ADMIN_PASS; combining it with --admin-pass is a usage error.";
|
|
178
|
+
export const ADMIN_PASS_FLAG = "--admin-pass <pass>";
|
|
179
|
+
export const ADMIN_PASS_HELP = "Admin password (legacy: lands in shell history and the process list — prefer --admin-pass-file or FLAIR_ADMIN_PASS)";
|
|
134
180
|
/** The admin username Harper's bootstrap creates and every Basic-auth path
|
|
135
181
|
* historically hardcoded. Kept as the default; overridable per call via
|
|
136
182
|
* `resolveAdminUser` (flair#1345). */
|
|
@@ -160,7 +206,7 @@ export function resolveAdminUser(explicit) {
|
|
|
160
206
|
return explicit || process.env.FLAIR_ADMIN_USER || DEFAULT_ADMIN_USER;
|
|
161
207
|
}
|
|
162
208
|
export function defaultKeysDir() {
|
|
163
|
-
return join(
|
|
209
|
+
return join(resolveHome(), ".flair", "keys");
|
|
164
210
|
}
|
|
165
211
|
/**
|
|
166
212
|
* Resolve an admin password for LOCAL-only CLI convenience (`agent add`,
|
|
@@ -219,8 +265,8 @@ export function resolveLocalAdminPass(explicit, isRemoteTarget = false, adminPas
|
|
|
219
265
|
export function resolveKeyPath(agentId) {
|
|
220
266
|
const candidates = [
|
|
221
267
|
process.env.FLAIR_KEY_DIR ? join(process.env.FLAIR_KEY_DIR, `${agentId}.key`) : null,
|
|
222
|
-
join(
|
|
223
|
-
join(
|
|
268
|
+
join(resolveHome(), ".flair", "keys", `${agentId}.key`),
|
|
269
|
+
join(resolveHome(), ".tps", "secrets", "flair", `${agentId}-priv.key`),
|
|
224
270
|
].filter(Boolean);
|
|
225
271
|
return candidates.find((p) => existsSync(p)) ?? null;
|
|
226
272
|
}
|