@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/dist/commands/init.js
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
import { applyOrReportClaudeMdBootstrap, applyOrReportSessionStartHook } from "../doctor-client.js";
|
|
2
2
|
import { hookSettingsPath } from "../hook-install.js";
|
|
3
|
-
import { detectClients, renderWiringSummary, wireAntigravity, wireCodex, wireCursor, wireGemini, wirePi } from "../install/clients.js";
|
|
3
|
+
import { claudeCodeMcpEntry, detectClients, renderWiringSummary, wireAntigravity, wireClaudeCodeJson, wireCodex, wireCursor, wireGemini, wirePi } from "../install/clients.js";
|
|
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) {
|
|
@@ -198,7 +199,7 @@ export function register(program) {
|
|
|
198
199
|
flairAdminPass = randomBytes(24).toString("base64url");
|
|
199
200
|
}
|
|
200
201
|
// Write the flair admin pass to secrets directory
|
|
201
|
-
const secretsDir = join(
|
|
202
|
+
const secretsDir = join(resolveHome(), ".tps", "secrets");
|
|
202
203
|
mkdirSync(secretsDir, { recursive: true });
|
|
203
204
|
const secretPath = join(secretsDir, "flair-fabric-hdb");
|
|
204
205
|
writeFileSync(secretPath, flairAdminPass + "\n", { mode: 0o600 });
|
|
@@ -329,7 +330,7 @@ export function register(program) {
|
|
|
329
330
|
const displayTarget = target || opsTarget;
|
|
330
331
|
console.log(`\n✓ Flair hub deployed to ${displayTarget}`);
|
|
331
332
|
console.log(` Component: flair@${flavor}`);
|
|
332
|
-
console.log(` Admin user: ${adminUser} (pass written to ${join(
|
|
333
|
+
console.log(` Admin user: ${adminUser} (pass written to ${join(resolveHome(), ".tps", "secrets", "flair-fabric-hdb")})`);
|
|
333
334
|
if (instanceId)
|
|
334
335
|
console.log(` Instance: ${instanceId} (role=${role})`);
|
|
335
336
|
console.log(` Federation: ready — run \`flair federation token\` to mint a pairing token`);
|
|
@@ -349,7 +350,28 @@ export function register(program) {
|
|
|
349
350
|
}
|
|
350
351
|
// ── Local init (full one-command setup) ──
|
|
351
352
|
const keysDir = opts.keysDir ?? defaultKeysDir();
|
|
352
|
-
|
|
353
|
+
// Resolve ONCE, here: the operator means "relative to my shell's cwd", but
|
|
354
|
+
// Harper is spawned with cwd = the flair package directory, so a raw
|
|
355
|
+
// relative `--data-dir r` would make Harper bind
|
|
356
|
+
// <flairPackageDir>/r/operations-server — a different path from the one the
|
|
357
|
+
// preflight measured. Every downstream use (preflight, config/plist,
|
|
358
|
+
// ROOTPATH / HARPER_SET_CONFIG, messages) takes this resolved value.
|
|
359
|
+
const dataDir = opts.dataDir ? resolve(opts.dataDir) : defaultDataDir();
|
|
360
|
+
// flair#916: the Harper operations API is a Unix domain socket at
|
|
361
|
+
// `<data-dir>/operations-server`, and Unix socket paths are capped by
|
|
362
|
+
// `sun_path` (darwin 104 / linux 108, counting the trailing NUL, so the
|
|
363
|
+
// USABLE length is 103 / 107). A long `--data-dir` pushes the socket past
|
|
364
|
+
// the cap, and Harper then dies with a bare `listen EINVAL` that names
|
|
365
|
+
// neither the socket nor the limit — the worst moment (first run, no
|
|
366
|
+
// working install to compare against). Refuse HERE, before any install,
|
|
367
|
+
// config write, keypair, or Harper start: a refusal must leave nothing on
|
|
368
|
+
// disk. The socket path is built exactly as Harper binds it (join with the
|
|
369
|
+
// fixed "operations-server" suffix), so the measured length is the real one.
|
|
370
|
+
const socketRefusal = opsSocketPathRefusal(dataDir, process.platform);
|
|
371
|
+
if (socketRefusal) {
|
|
372
|
+
console.error(socketRefusal);
|
|
373
|
+
process.exit(1);
|
|
374
|
+
}
|
|
353
375
|
// "create" mode (flair#914): init ESTABLISHES an instance, so a data
|
|
354
376
|
// directory with no recorded port is a new instance taking the default,
|
|
355
377
|
// not the hard error every other caller gets — otherwise `flair init
|
|
@@ -1045,66 +1067,65 @@ export function register(program) {
|
|
|
1045
1067
|
// Claude Code gets real auto-wiring into ~/.claude.json (zero-install
|
|
1046
1068
|
// npx form; matches the snippets everywhere else). Other clients only
|
|
1047
1069
|
// get printed instructions — the CLI can't safely edit their configs.
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
//
|
|
1061
|
-
//
|
|
1062
|
-
//
|
|
1063
|
-
//
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
const claudeJson = claudeJsonExisted
|
|
1070
|
-
? JSON.parse(readFileSync(claudeJsonPath, "utf-8"))
|
|
1071
|
-
: {};
|
|
1072
|
-
const existing = claudeJson.mcpServers?.flair;
|
|
1073
|
-
const currentSpec = mcpServerSpec();
|
|
1074
|
-
const existingArgs = existing?.args;
|
|
1075
|
-
const argsMatch = Array.isArray(existingArgs) && existingArgs.includes(currentSpec);
|
|
1076
|
-
const urlAgentMatch = existing && existing.env?.FLAIR_URL === httpUrl && existing.env?.FLAIR_AGENT_ID === agentId;
|
|
1077
|
-
// flair#1135: the pin in `args` must match the current mcpServerSpec().
|
|
1078
|
-
// A matching pin stays a no-op (idempotent); only a stale pin triggers a re-write.
|
|
1079
|
-
if (urlAgentMatch && argsMatch) {
|
|
1080
|
-
console.log(` ✓ Claude Code already wired in ~/.claude.json`);
|
|
1081
|
-
wiringResults.push({ client: "claude-code", message: "already wired", wired: true });
|
|
1082
|
-
}
|
|
1083
|
-
else {
|
|
1084
|
-
claudeJson.mcpServers = claudeJson.mcpServers || {};
|
|
1085
|
-
claudeJson.mcpServers.flair = flairMcpConfig;
|
|
1086
|
-
writeFileSync(claudeJsonPath, JSON.stringify(claudeJson, null, 2));
|
|
1087
|
-
const action = urlAgentMatch ? "refreshed pin in ~/.claude.json"
|
|
1088
|
-
: claudeJsonExisted ? "wired in ~/.claude.json"
|
|
1089
|
-
: "wired in ~/.claude.json (created)";
|
|
1090
|
-
console.log(` ✓ Claude Code ${action} (restart Claude Code to pick it up)`);
|
|
1091
|
-
wiringResults.push({
|
|
1092
|
-
client: "claude-code",
|
|
1093
|
-
message: urlAgentMatch ? "refreshed pin in ~/.claude.json"
|
|
1094
|
-
: claudeJsonExisted ? "wired ~/.claude.json"
|
|
1095
|
-
: "created and wired ~/.claude.json",
|
|
1096
|
-
wired: true,
|
|
1097
|
-
});
|
|
1098
|
-
}
|
|
1070
|
+
//
|
|
1071
|
+
// flair#1778 2c-i-d1: init no longer writes ~/.claude.json itself. It
|
|
1072
|
+
// DELEGATES to the shared clients.ts writer (wireClaudeCodeJson) — the
|
|
1073
|
+
// SAME critical section, resolveHome() and entry builder that doctor
|
|
1074
|
+
// --fix and the owned-pin refresh use — and renders its own lines from
|
|
1075
|
+
// the STRUCTURED outcome. Both writers of this file now emit ONE shape
|
|
1076
|
+
// (`type: "stdio"` KEPT, a trailing newline added); an empty file now
|
|
1077
|
+
// reads as {} instead of throwing. resolveHome() (not os.homedir(),
|
|
1078
|
+
// which is fixed at LAUNCH under Bun) is what makes an in-process HOME
|
|
1079
|
+
// override take effect — os.homedir() would still write the REAL
|
|
1080
|
+
// ~/.claude.json.
|
|
1081
|
+
// flair#718 authorship-provenance: the Claude Code env block gets its
|
|
1082
|
+
// OWN FLAIR_CLIENT label (never the shared mcpEnv object directly —
|
|
1083
|
+
// that would stamp the same label into every client's config) so
|
|
1084
|
+
// writes from THIS client's proxy stamp
|
|
1085
|
+
// provenance.claimed.client = "claude-code".
|
|
1086
|
+
const claudeEnv = { ...mcpEnv, FLAIR_CLIENT: "claude-code" };
|
|
1087
|
+
const wireOutcome = wireClaudeCodeJson(claudeEnv);
|
|
1088
|
+
if (wireOutcome.kind === "already") {
|
|
1089
|
+
console.log(` ✓ Claude Code already wired in ~/.claude.json`);
|
|
1090
|
+
wiringResults.push({ client: "claude-code", message: "already wired", wired: true });
|
|
1099
1091
|
}
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1092
|
+
else if (wireOutcome.kind === "held") {
|
|
1093
|
+
console.log(` ${render.icons.warn} ${wireOutcome.line}`);
|
|
1094
|
+
wiringResults.push({
|
|
1095
|
+
client: "claude-code",
|
|
1096
|
+
message: "held the existing pin in ~/.claude.json",
|
|
1097
|
+
wired: wireOutcome.entryPresent,
|
|
1098
|
+
});
|
|
1099
|
+
}
|
|
1100
|
+
else if (wireOutcome.kind === "refused") {
|
|
1101
|
+
console.log(` ${render.icons.warn} ${wireOutcome.line}`);
|
|
1102
|
+
wiringResults.push({
|
|
1103
|
+
client: "claude-code",
|
|
1104
|
+
message: "refused to write ~/.claude.json (unreadable CLI version)",
|
|
1105
|
+
wired: wireOutcome.entryPresent,
|
|
1106
|
+
});
|
|
1107
|
+
}
|
|
1108
|
+
else if (wireOutcome.kind === "written") {
|
|
1109
|
+
const action = wireOutcome.refreshed ? "refreshed pin in ~/.claude.json"
|
|
1110
|
+
: wireOutcome.existed ? "wired in ~/.claude.json"
|
|
1111
|
+
: "wired in ~/.claude.json (created)";
|
|
1112
|
+
console.log(` ✓ Claude Code ${action} (restart Claude Code to pick it up)`);
|
|
1113
|
+
wiringResults.push({
|
|
1114
|
+
client: "claude-code",
|
|
1115
|
+
message: wireOutcome.refreshed ? "refreshed pin in ~/.claude.json"
|
|
1116
|
+
: wireOutcome.existed ? "wired ~/.claude.json"
|
|
1117
|
+
: "created and wired ~/.claude.json",
|
|
1118
|
+
wired: true,
|
|
1119
|
+
});
|
|
1120
|
+
}
|
|
1121
|
+
else {
|
|
1122
|
+
// A genuine read/parse/write/lock failure (bad permissions,
|
|
1123
|
+
// malformed existing JSON, a held lock) — never merely "the file
|
|
1124
|
+
// does not exist yet" (an absent file is created).
|
|
1125
|
+
const reason = wireOutcome.reason ?? "unknown error";
|
|
1105
1126
|
console.log(` ${render.icons.warn} Claude Code: could not write ~/.claude.json (${reason})`);
|
|
1106
1127
|
console.log(` MCP config (add manually to ~/.claude.json):`);
|
|
1107
|
-
console.log(` { "mcpServers": { "flair": ${JSON.stringify(
|
|
1128
|
+
console.log(` { "mcpServers": { "flair": ${JSON.stringify(claudeCodeMcpEntry(claudeEnv))} } }`);
|
|
1108
1129
|
wiringResults.push({ client: "claude-code", message: `snippet printed (${reason})`, wired: false });
|
|
1109
1130
|
}
|
|
1110
1131
|
// ── CLAUDE.md bootstrap line (flair#597) ──────────────────────────
|
|
@@ -1114,7 +1135,7 @@ export function register(program) {
|
|
|
1114
1135
|
// automatically here (same "just do it" shape as the MCP block
|
|
1115
1136
|
// above); --skip-claude-md opts out and prints the exact line to
|
|
1116
1137
|
// add by hand instead.
|
|
1117
|
-
const claudeMdResult = applyOrReportClaudeMdBootstrap(process.cwd(),
|
|
1138
|
+
const claudeMdResult = applyOrReportClaudeMdBootstrap(process.cwd(), resolveHome(), !!opts.skipClaudeMd);
|
|
1118
1139
|
console.log(` ${claudeMdResult.ok ? "✓" : "•"} ${claudeMdResult.message}`);
|
|
1119
1140
|
if (claudeMdResult.hint) {
|
|
1120
1141
|
for (const line of claudeMdResult.hint.split("\n"))
|
|
@@ -1125,7 +1146,7 @@ export function register(program) {
|
|
|
1125
1146
|
// ~/.claude/settings.json — without it, mcp__flair__bootstrap only
|
|
1126
1147
|
// ever runs if the agent remembers to call it itself.
|
|
1127
1148
|
// --skip-hook opts out and prints the exact JSON to add by hand.
|
|
1128
|
-
const hookResult = applyOrReportSessionStartHook(
|
|
1149
|
+
const hookResult = applyOrReportSessionStartHook(resolveHome(), agentId, !!opts.skipHook);
|
|
1129
1150
|
console.log(` ${hookResult.ok ? "✓" : "•"} ${hookResult.message}`);
|
|
1130
1151
|
if (hookResult.hint) {
|
|
1131
1152
|
for (const line of hookResult.hint.split("\n"))
|
|
@@ -1166,7 +1187,7 @@ export function register(program) {
|
|
|
1166
1187
|
// consent to set up the client, same as the Claude Code hook
|
|
1167
1188
|
// applied above. --skip-hook opts out and prints the JSON.
|
|
1168
1189
|
if (clientId === "codex" && result.ok) {
|
|
1169
|
-
const hookResult = applyOrReportSessionStartHook(
|
|
1190
|
+
const hookResult = applyOrReportSessionStartHook(resolveHome(), agentId, !!opts.skipHook, hookSettingsPath(resolveHome(), "codex"));
|
|
1170
1191
|
console.log(` ${hookResult.ok ? "✓" : "•"} ${hookResult.message}`);
|
|
1171
1192
|
if (hookResult.hint) {
|
|
1172
1193
|
for (const line of hookResult.hint.split("\n"))
|
|
@@ -1188,8 +1209,11 @@ export function register(program) {
|
|
|
1188
1209
|
if (!opts.skipSmoke && !noMcp && clientOpt !== "none" && wiringResults.length > 0 && wiredAnyMcpClient) {
|
|
1189
1210
|
console.log("\n Smoke-testing MCP server...");
|
|
1190
1211
|
try {
|
|
1191
|
-
//
|
|
1192
|
-
//
|
|
1212
|
+
// The RUNNING CLI's own server: mcpServerSpec() pins to THIS
|
|
1213
|
+
// CLI's version. That is not necessarily the version a client
|
|
1214
|
+
// config ends up keeping — on a HELD pin the config is deliberately
|
|
1215
|
+
// left on a HIGHER version than this CLI — so the smoke exercises
|
|
1216
|
+
// what this CLI can run, not the held pin.
|
|
1193
1217
|
const mcpProc = spawn("npx", ["-y", mcpServerSpec()], {
|
|
1194
1218
|
env: { ...process.env, FLAIR_AGENT_ID: agentId, FLAIR_URL: httpUrl },
|
|
1195
1219
|
stdio: ["pipe", "pipe", "pipe"],
|
|
@@ -1229,13 +1253,13 @@ export function register(program) {
|
|
|
1229
1253
|
for (const line of lines) {
|
|
1230
1254
|
const parsed = JSON.parse(line);
|
|
1231
1255
|
if (parsed.jsonrpc === "2.0" && parsed.id === 1 && !parsed.error) {
|
|
1232
|
-
console.log(
|
|
1256
|
+
console.log(` ✓ MCP server responded (this CLI's ${mcpServerSpec()} server, not the pinned config's)`);
|
|
1233
1257
|
break;
|
|
1234
1258
|
}
|
|
1235
1259
|
}
|
|
1236
1260
|
}
|
|
1237
1261
|
catch {
|
|
1238
|
-
console.log(" ⚠ MCP server responded but response could not be parsed");
|
|
1262
|
+
console.log(" ⚠ MCP server responded but response could not be parsed (this CLI's server, not the pinned config's)");
|
|
1239
1263
|
}
|
|
1240
1264
|
finally {
|
|
1241
1265
|
// Reap the child even on the resolve path: the MCP server exits on
|
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
|
-
import { validatePromoteOpts, validateRejectOpts, decideCandidateAction, derivePromotedTags, validateHumanReviewerId, } from "../rem/promote-policy.js";
|
|
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). */
|
|
@@ -68,6 +68,28 @@ export function formatCandidateLine(candidate, maxClaimLen = 80) {
|
|
|
68
68
|
const truncated = claim.length > maxClaimLen ? `${claim.slice(0, maxClaimLen)}…` : claim;
|
|
69
69
|
return ` [${candidate.id ?? "?"}] ${truncated}`;
|
|
70
70
|
}
|
|
71
|
+
/**
|
|
72
|
+
* Flag a probable truncated claim for the HUMAN reviewer (flair#1756 slice 2,
|
|
73
|
+
* issue suggestion 3). Returns null when nothing is off; otherwise a short
|
|
74
|
+
* descriptor. This is advisory ONLY — the refusal for structural imbalance
|
|
75
|
+
* lives server-side in decideAutoPromote (the unattended path); a human
|
|
76
|
+
* promote is a legitimate place to look at a fragment and decide.
|
|
77
|
+
*
|
|
78
|
+
* Reports STRUCTURAL imbalance (unbalanced backtick/paren/bracket/brace) and, as
|
|
79
|
+
* a weaker signal, missing terminal punctuation. Neither claims the text is
|
|
80
|
+
* incomplete — a balanced claim can still be a fragment.
|
|
81
|
+
*/
|
|
82
|
+
export function candidateIncompleteFlag(claim) {
|
|
83
|
+
// A malformed row can carry a non-string claim; normalize rather than throw,
|
|
84
|
+
// so listing one bad candidate never takes down the whole review surface.
|
|
85
|
+
const text = typeof claim === "string" ? claim : "";
|
|
86
|
+
const imbalance = structuralImbalance(text);
|
|
87
|
+
if (imbalance !== null)
|
|
88
|
+
return `structurally incomplete (${imbalance}); the unattended auto-promote path refuses this`;
|
|
89
|
+
if (!hasTerminalPunctuation(text))
|
|
90
|
+
return "no terminal punctuation — possible fragment";
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
71
93
|
/**
|
|
72
94
|
* Classifies a thrown /ReflectMemories execute-mode error for CLI display.
|
|
73
95
|
* `api()` throws `Error(responseBodyText)` for non-2xx responses (see api()
|
|
@@ -98,7 +120,7 @@ export function describeReflectError(message) {
|
|
|
98
120
|
}
|
|
99
121
|
return { kind: "other", text: message };
|
|
100
122
|
}
|
|
101
|
-
const REM_PAUSE_FLAG = resolve(
|
|
123
|
+
const REM_PAUSE_FLAG = resolve(resolveHome(), ".flair", "rem.paused");
|
|
102
124
|
function writeRemPauseSentinel() {
|
|
103
125
|
const dir = dirname(REM_PAUSE_FLAG);
|
|
104
126
|
if (!existsSync(dir))
|
|
@@ -396,7 +418,8 @@ export function register(program) {
|
|
|
396
418
|
const candidates = await res.json();
|
|
397
419
|
const mode = render.resolveOutputMode(opts);
|
|
398
420
|
if (mode === "json") {
|
|
399
|
-
|
|
421
|
+
const annotated = candidates.map((c) => ({ ...c, incompleteFlag: candidateIncompleteFlag(c.claim) }));
|
|
422
|
+
console.log(render.asJSON({ agentId, status, count: candidates.length, candidates: annotated }));
|
|
400
423
|
return;
|
|
401
424
|
}
|
|
402
425
|
const statusColor = status === "promoted" ? render.c.green : status === "rejected" ? render.c.red : render.c.yellow;
|
|
@@ -423,6 +446,10 @@ export function register(program) {
|
|
|
423
446
|
}
|
|
424
447
|
console.log(` ${render.wrap(render.c.dim, c.id)} ${tag}`);
|
|
425
448
|
console.log(` ${c.claim}`);
|
|
449
|
+
const incompleteFlag = candidateIncompleteFlag(c.claim);
|
|
450
|
+
if (incompleteFlag) {
|
|
451
|
+
console.log(` ${render.wrap(render.c.yellow, "⚠ possible incomplete claim")} ${render.wrap(render.c.dim, `— ${incompleteFlag}`)}`);
|
|
452
|
+
}
|
|
426
453
|
if (c.supersedes) {
|
|
427
454
|
console.log(` ${render.wrap(render.c.dim, `(supersedes ${c.supersedes} — recurring proposal)`)}`);
|
|
428
455
|
}
|
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"));
|