@tpsdev-ai/flair 0.57.0 → 0.59.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 +7 -6
- package/SECURITY.md +4 -1
- package/config.yaml +3 -0
- package/dist/build-info.json +3 -3
- package/dist/cli.js +1726 -376
- package/dist/commands/agent.js +160 -2
- package/dist/commands/doctor.js +177 -27
- package/dist/commands/federation.js +2 -1
- package/dist/commands/hook.js +10 -2
- package/dist/commands/init.js +150 -44
- package/dist/commands/mcp.js +53 -22
- package/dist/commands/memory.js +24 -2
- package/dist/commands/quality.js +26 -18
- package/dist/commands/service.js +137 -22
- package/dist/commands/status.js +114 -3
- package/dist/commands/upgrade.js +204 -84
- package/dist/doctor-client.js +50 -4
- package/dist/federation/scheduler.js +253 -4
- package/dist/install/clients.js +89 -23
- package/dist/install/global-bin-path.js +26 -6
- package/dist/lib/atomic-write.js +256 -0
- package/dist/lib/daemon-liveness.js +103 -0
- package/dist/lib/doctor-run.js +72 -0
- package/dist/lib/embed-gpu-doctor.js +49 -26
- package/dist/lib/federation-memory-attributes.js +15 -0
- package/dist/lib/flair-agent-role.js +116 -0
- package/dist/lib/init-admin-pass.js +4 -2
- package/dist/lib/init-listener-environ.js +38 -0
- package/dist/lib/init-occupied-listener.js +165 -0
- package/dist/lib/launchd-domain-preflight.js +448 -0
- package/dist/lib/launchd-management.js +179 -8
- package/dist/lib/launchd-repair.js +95 -0
- package/dist/lib/mcp-enable.js +667 -72
- package/dist/lib/memory-attributes.js +77 -0
- package/dist/lib/node-alias-path.js +95 -0
- package/dist/lib/npm-registry.js +119 -6
- package/dist/lib/owned-pins.js +20 -6
- package/dist/lib/process-start-time.js +32 -0
- package/dist/lib/service-repoint-apply.js +267 -0
- package/dist/lib/service-repoint.js +575 -0
- package/dist/lib/toml-string-array.js +104 -0
- package/dist/lib/tree-divergence.js +716 -0
- package/dist/lib/upgrade-plain-tree.js +18 -8
- package/dist/lib/upgrade-prior-liveness.js +69 -0
- package/dist/lib/upgrade-rollback.js +116 -0
- package/dist/rem/runner.js +11 -0
- package/dist/resources/Agent.js +54 -21
- package/dist/resources/AgentSeed.js +44 -1
- package/dist/resources/Federation.js +84 -54
- package/dist/resources/Memory.js +567 -72
- package/dist/resources/MemoryArchive.js +9 -0
- package/dist/resources/MemoryBootstrap.js +125 -29
- package/dist/resources/MemoryFeed.js +204 -3
- package/dist/resources/MemoryHostSource.js +90 -0
- package/dist/resources/MemoryMaintenance.js +121 -32
- package/dist/resources/MemoryReflect.js +4 -1
- package/dist/resources/MemoryReindex.js +7 -4
- package/dist/resources/MemoryUsage.js +53 -3
- package/dist/resources/OrgSkillAssignment.js +209 -0
- package/dist/resources/Presence.js +18 -10
- package/dist/resources/RecordUsage.js +30 -40
- package/dist/resources/Relationship.js +167 -78
- package/dist/resources/SemanticSearch.js +19 -6
- package/dist/resources/Soul.js +31 -19
- package/dist/resources/XAA.js +47 -14
- package/dist/resources/agent-auth.js +16 -10
- package/dist/resources/agent-status-guard.js +63 -0
- package/dist/resources/auth-middleware.js +137 -49
- package/dist/resources/auto-promote-lib.js +4 -4
- package/dist/resources/bm25-index-service.js +246 -32
- package/dist/resources/bm25-status.js +132 -0
- package/dist/resources/ed25519-auth.js +11 -54
- package/dist/resources/embed-gpu.js +262 -47
- package/dist/resources/embeddings-boot.js +52 -17
- package/dist/resources/federation-classify.js +34 -0
- package/dist/resources/federation-crypto.js +65 -19
- package/dist/resources/flair-agent-role-boot.js +26 -0
- package/dist/resources/health.js +67 -16
- package/dist/resources/host-pointer/registry.js +35 -0
- package/dist/resources/host-pointer-adapter.js +15 -0
- package/dist/resources/host-source-visibility.js +167 -0
- package/dist/resources/host-source.js +151 -0
- package/dist/resources/instance-identity.js +3 -2
- package/dist/resources/key-lock.js +31 -0
- package/dist/resources/mcp-handler.js +147 -51
- package/dist/resources/mcp-oauth.js +3 -6
- package/dist/resources/mcp-tools.js +47 -25
- package/dist/resources/memory-consolidate-lib.js +3 -1
- package/dist/resources/memory-declared-attributes.js +103 -0
- package/dist/resources/memory-feed-lib.js +5 -1
- package/dist/resources/memory-host-source.js +163 -0
- package/dist/resources/migrations/synthetic-test-migration.js +4 -1
- package/dist/resources/migrations/visibility-backfill.js +4 -1
- package/dist/resources/multi-worker-guard.js +121 -0
- package/dist/resources/oauth-discovery.js +1 -0
- package/dist/resources/oauth-wellknown.js +8 -4
- package/dist/resources/originator-instance.js +235 -0
- package/dist/resources/promotion-stamp.js +2 -0
- package/dist/resources/provenance.js +111 -11
- package/dist/resources/record-owner-guard.js +19 -0
- package/dist/resources/record-type-kit.js +9 -12
- package/dist/resources/record-types.js +22 -6
- package/dist/resources/relay-ops.js +28 -3
- package/dist/resources/replay-store.js +336 -0
- package/dist/resources/request-transaction.js +78 -0
- package/dist/resources/search-readiness.js +19 -21
- package/dist/resources/semantic-retrieval-core.js +5 -1
- package/dist/resources/skill-manifest.js +181 -0
- package/dist/resources/skill-provenance.js +15 -10
- package/dist/resources/table-patch-policy.js +109 -0
- package/dist/resources/table-patches.js +17 -0
- package/dist/resources/table-post-policy.js +138 -0
- package/dist/resources/table-posts.js +22 -0
- package/dist/resources/table-subscription-policy.js +135 -0
- package/dist/resources/table-subscriptions.js +19 -0
- package/dist/resources/tool-descriptors/index.js +15 -15
- package/dist/resources/trust-block.js +10 -3
- package/dist/resources/usage-recording.js +169 -41
- package/dist/src/lib/flair-agent-role.js +116 -0
- package/dist/src/lib/memory-attributes.js +77 -0
- package/docs/access-control.md +667 -0
- package/docs/api-reference.md +85 -17
- package/docs/auth.md +4 -0
- package/docs/claude-code.md +132 -0
- package/docs/deepseek-harness.md +1 -1
- package/docs/deployment.md +1 -1
- package/docs/federation.md +1 -1
- package/docs/integrations.md +6 -6
- package/docs/mcp-clients.md +16 -24
- package/docs/notes/mcp-oauth-model2.md +15 -1
- package/docs/quickstart.md +5 -0
- package/docs/releasing.md +152 -20
- package/docs/supply-chain-policy.md +10 -5
- package/docs/troubleshooting.md +11 -0
- package/docs/upgrade.md +187 -61
- package/package.json +10 -5
- package/schemas/agent.graphql +9 -6
- package/schemas/federation.graphql +2 -11
- package/schemas/memory.graphql +137 -17
- package/schemas/oauth.graphql +8 -4
- package/schemas/replay.graphql +18 -0
- package/templates/launchd/start-flair-with-admin-pass.sh +95 -0
- package/dist/resources/federation-nonce-store.js +0 -195
package/dist/commands/agent.js
CHANGED
|
@@ -18,13 +18,156 @@ const resolveOpsPort = (opts) => cli.resolveOpsPort(opts);
|
|
|
18
18
|
const resolveEffectiveOpsUrl = (opts) => cli.resolveEffectiveOpsUrl(opts);
|
|
19
19
|
const seedAgentViaOpsApi = (opsPortOrUrl, agentId, pubKeyB64url, adminUser, adminPass) => cli.seedAgentViaOpsApi(opsPortOrUrl, agentId, pubKeyB64url, adminUser, adminPass);
|
|
20
20
|
const agentRecordIsAdmin = (record) => cli.agentRecordIsAdmin(record);
|
|
21
|
+
/** Operations API URL, same shape as `seedAgentViaOpsApi` (trailing slash). */
|
|
22
|
+
function opsApiUrl(opsPortOrUrl) {
|
|
23
|
+
return typeof opsPortOrUrl === "number"
|
|
24
|
+
? `http://127.0.0.1:${opsPortOrUrl}/`
|
|
25
|
+
: `${opsPortOrUrl.replace(/\/$/, "")}/`;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Parse an operations `search_by_value` body for one id.
|
|
29
|
+
* `[]` is the only absence. One row with this id and a string `name` is that
|
|
30
|
+
* agent even when `publicKey` is missing or empty: a missing public key is
|
|
31
|
+
* still an existing row and fails the later success check. It is not a
|
|
32
|
+
* missing row. Unreadable, and never treated as absence: a non-array, more
|
|
33
|
+
* than one row, a non-object element, a missing or empty id, a different id,
|
|
34
|
+
* a non-string `publicKey`, or a missing or non-string `name`.
|
|
35
|
+
*/
|
|
36
|
+
function parseAgentRows(body, id) {
|
|
37
|
+
if (!Array.isArray(body)) {
|
|
38
|
+
return { ok: false, reason: "operations API returned an unexpected body." };
|
|
39
|
+
}
|
|
40
|
+
if (body.length === 0)
|
|
41
|
+
return { ok: true, row: null };
|
|
42
|
+
if (body.length !== 1) {
|
|
43
|
+
return { ok: false, reason: `operations API returned ${body.length} rows for Agent '${id}'.` };
|
|
44
|
+
}
|
|
45
|
+
const row = body[0];
|
|
46
|
+
if (!row || typeof row !== "object" || Array.isArray(row)) {
|
|
47
|
+
return { ok: false, reason: "operations API returned a malformed Agent row." };
|
|
48
|
+
}
|
|
49
|
+
const rec = row;
|
|
50
|
+
if (typeof rec.id !== "string" || rec.id.length === 0) {
|
|
51
|
+
return { ok: false, reason: "operations API returned a malformed Agent row." };
|
|
52
|
+
}
|
|
53
|
+
if (rec.id !== id) {
|
|
54
|
+
return {
|
|
55
|
+
ok: false,
|
|
56
|
+
reason: `operations API returned Agent '${rec.id}' while looking up '${id}'.`,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
if (rec.publicKey !== undefined && typeof rec.publicKey !== "string") {
|
|
60
|
+
return { ok: false, reason: "operations API returned a malformed Agent row." };
|
|
61
|
+
}
|
|
62
|
+
if (typeof rec.name !== "string") {
|
|
63
|
+
return { ok: false, reason: "operations API returned an Agent row whose name is missing or not a string." };
|
|
64
|
+
}
|
|
65
|
+
const publicKey = typeof rec.publicKey === "string" && rec.publicKey.length > 0 ? rec.publicKey : undefined;
|
|
66
|
+
return {
|
|
67
|
+
ok: true,
|
|
68
|
+
row: {
|
|
69
|
+
id: rec.id,
|
|
70
|
+
name: rec.name,
|
|
71
|
+
...(publicKey !== undefined ? { publicKey } : {}),
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
function agentAlreadyExistsMessage(id) {
|
|
76
|
+
return (`Error: Agent '${id}' already exists; its stored public key was left unchanged. ` +
|
|
77
|
+
`Run \`flair agent rotate-key ${id}\` on the Flair host to replace the key, ` +
|
|
78
|
+
`or \`flair agent remove ${id}\` first and then \`flair agent add ${id}\`. ` +
|
|
79
|
+
`\`flair agent remove\` tries to delete that agent's Memory and Soul rows.`);
|
|
80
|
+
}
|
|
81
|
+
function agentKeyNotStoredMessage(id, stored) {
|
|
82
|
+
let found;
|
|
83
|
+
if (!stored) {
|
|
84
|
+
found = `Reading the record back found no Agent row for '${id}'.`;
|
|
85
|
+
}
|
|
86
|
+
else if (typeof stored.publicKey !== "string" || stored.publicKey.length === 0) {
|
|
87
|
+
found = `An Agent row for '${id}' was found, but it has no usable public key.`;
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
found = `The stored public key is '${stored.publicKey}', which is not the key generated or reused by this command.`;
|
|
91
|
+
}
|
|
92
|
+
return (`Error: Agent '${id}' was not stored with the public key generated or reused by this command. ${found} ` +
|
|
93
|
+
`Run \`flair agent rotate-key ${id}\` on the Flair host to replace the key, ` +
|
|
94
|
+
`or \`flair agent remove ${id}\` first and then \`flair agent add ${id}\`. ` +
|
|
95
|
+
`\`flair agent remove\` tries to delete that agent's Memory and Soul rows.`);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Read one Agent row by id through the operations API.
|
|
99
|
+
* Exits on a failed body read, an empty body, non-JSON, a row whose id is
|
|
100
|
+
* not the one searched, or a row that is unreadable: non-object, missing or
|
|
101
|
+
* empty id, non-string `publicKey`, or missing or non-string `name`.
|
|
102
|
+
* Those results are not "no such agent". A row with this id and a string
|
|
103
|
+
* `name` is returned even when `publicKey` is missing or empty; that is an
|
|
104
|
+
* existing row, and the add success check refuses it. Returns null only
|
|
105
|
+
* when the body is a JSON `[]`.
|
|
106
|
+
*/
|
|
107
|
+
async function readStoredAgent(opsPortOrUrl, id, adminUser, adminPass) {
|
|
108
|
+
const auth = Buffer.from(`${adminUser}:${adminPass}`).toString("base64");
|
|
109
|
+
let res;
|
|
110
|
+
try {
|
|
111
|
+
res = await fetch(opsApiUrl(opsPortOrUrl), {
|
|
112
|
+
method: "POST",
|
|
113
|
+
headers: { "Content-Type": "application/json", Authorization: `Basic ${auth}` },
|
|
114
|
+
body: JSON.stringify({
|
|
115
|
+
operation: "search_by_value",
|
|
116
|
+
database: "flair",
|
|
117
|
+
table: "Agent",
|
|
118
|
+
search_attribute: "id",
|
|
119
|
+
search_value: id,
|
|
120
|
+
get_attributes: ["id", "name", "publicKey"],
|
|
121
|
+
}),
|
|
122
|
+
signal: AbortSignal.timeout(10_000),
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
catch (err) {
|
|
126
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
127
|
+
console.error(`Error: could not read Agent '${id}': ${message}`);
|
|
128
|
+
process.exit(1);
|
|
129
|
+
}
|
|
130
|
+
let text;
|
|
131
|
+
try {
|
|
132
|
+
text = await res.text();
|
|
133
|
+
}
|
|
134
|
+
catch (err) {
|
|
135
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
136
|
+
console.error(`Error: could not read Agent '${id}': ${message}`);
|
|
137
|
+
process.exit(1);
|
|
138
|
+
}
|
|
139
|
+
if (!res.ok) {
|
|
140
|
+
console.error(`Error: could not read Agent '${id}' (${res.status}): ${text}`);
|
|
141
|
+
process.exit(1);
|
|
142
|
+
}
|
|
143
|
+
if (text.trim().length === 0) {
|
|
144
|
+
console.error(`Error: could not read Agent '${id}': operations API returned an empty body.`);
|
|
145
|
+
process.exit(1);
|
|
146
|
+
}
|
|
147
|
+
let body;
|
|
148
|
+
try {
|
|
149
|
+
body = JSON.parse(text);
|
|
150
|
+
}
|
|
151
|
+
catch {
|
|
152
|
+
console.error(`Error: could not read Agent '${id}': operations API returned a body that is not JSON.`);
|
|
153
|
+
process.exit(1);
|
|
154
|
+
}
|
|
155
|
+
const parsed = parseAgentRows(body, id);
|
|
156
|
+
// `=== false`, not `!parsed.ok`: tsconfig.cli.json is not strict, and `!`
|
|
157
|
+
// does not narrow this union there.
|
|
158
|
+
if (parsed.ok === false) {
|
|
159
|
+
console.error(`Error: could not read Agent '${id}': ${parsed.reason}`);
|
|
160
|
+
process.exit(1);
|
|
161
|
+
}
|
|
162
|
+
return parsed.row;
|
|
163
|
+
}
|
|
21
164
|
/** Register the `flair agent` command group (flair#1630). */
|
|
22
165
|
export function register(program) {
|
|
23
166
|
// ─── flair agent ─────────────────────────────────────────────────────────────
|
|
24
167
|
const agent = program.command("agent").description("Manage Flair agents");
|
|
25
168
|
agent
|
|
26
169
|
.command("add <id>")
|
|
27
|
-
.description("Register a new agent
|
|
170
|
+
.description("Register a new agent. Refuses an id whose Agent record already exists")
|
|
28
171
|
.option("--name <name>", "Display name (defaults to id)")
|
|
29
172
|
.option("--port <port>", "Harper HTTP port")
|
|
30
173
|
.option("--admin-pass <pass>", "Admin password for registration")
|
|
@@ -92,6 +235,16 @@ export function register(program) {
|
|
|
92
235
|
}
|
|
93
236
|
process.exit(1);
|
|
94
237
|
}
|
|
238
|
+
// flair#2126 — Harper 5.2.8 skips an insert whose id already exists and
|
|
239
|
+
// still returns OK, so the seed helper's 409/"already exists" path never
|
|
240
|
+
// fires and the old public key stays. Look the id up first and refuse
|
|
241
|
+
// before any key file or insert. A later read-back covers a row that
|
|
242
|
+
// appears in the gap, or an insert that does not store this key.
|
|
243
|
+
const existing = await readStoredAgent(seedOpsTarget, id, adminUser, adminPass);
|
|
244
|
+
if (existing) {
|
|
245
|
+
console.error(agentAlreadyExistsMessage(id));
|
|
246
|
+
process.exit(1);
|
|
247
|
+
}
|
|
95
248
|
mkdirSync(keysDir, { recursive: true });
|
|
96
249
|
const privPath = privKeyPath(id, keysDir);
|
|
97
250
|
const pubPath = pubKeyPath(id, keysDir);
|
|
@@ -112,11 +265,16 @@ export function register(program) {
|
|
|
112
265
|
console.log(`Keypair written: ${privPath}`);
|
|
113
266
|
}
|
|
114
267
|
await seedAgentViaOpsApi(seedOpsTarget, id, pubKeyB64url, adminUser, adminPass);
|
|
268
|
+
const stored = await readStoredAgent(seedOpsTarget, id, adminUser, adminPass);
|
|
269
|
+
if (!stored || stored.publicKey !== pubKeyB64url) {
|
|
270
|
+
console.error(agentKeyNotStoredMessage(id, stored));
|
|
271
|
+
process.exit(1);
|
|
272
|
+
}
|
|
115
273
|
console.log(typeof seedOpsTarget === "string"
|
|
116
274
|
? `✅ Agent '${id}' (${name}) registered (ops: ${seedOpsTarget})`
|
|
117
275
|
: `✅ Agent '${id}' (${name}) registered`);
|
|
118
276
|
console.log(` Private key: ${privPath}`);
|
|
119
|
-
console.log(` Public key: ${
|
|
277
|
+
console.log(` Public key: ${stored.publicKey}`);
|
|
120
278
|
// flair#1280 — connector legibility at provisioning time: an OAuth /mcp
|
|
121
279
|
// connector resolves its own token subject to an Agent via
|
|
122
280
|
// Credential(kind:idp), NOT via this key, and the two identities are
|
package/dist/commands/doctor.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { COMPONENT_ENV_FILENAME, PUBLIC_URL_KEY, describePublicUrlFinding, readEnvValue } from "../component-env.js";
|
|
2
|
-
import { checkClaudeMdBootstrap, checkContinuityCaptureHooks, describeAgentGateFinding, effectiveFlairUrl, embeddingsSkipRemedy, fixClaudeMdBootstrap, fixCommandAgentHint, fixContinuityCaptureHooks, fixSessionStartHook, inspectSessionStartHook, partitionKeyIds, planAgentIterations, readClientMcpBlock, resolveFixAgentId, resolveWireFlairUrl, upgradeSessionStartHookCommand } from "../doctor-client.js";
|
|
2
|
+
import { checkClaudeMdBootstrap, checkContinuityCaptureHooks, continuityWriteBlockers, describeAgentGateFinding, effectiveFlairUrl, embeddingsSkipRemedy, fixClaudeMdBootstrap, fixCommandAgentHint, fixContinuityCaptureHooks, fixSessionStartHook, inspectSessionStartHook, partitionKeyIds, planAgentIterations, readClientMcpBlock, resolveFixAgentId, resolveWireFlairUrl, upgradeSessionStartHookCommand } from "../doctor-client.js";
|
|
3
3
|
import { markStale, sortOldestVersionFirst } from "../fleet-presence.js";
|
|
4
4
|
import { hookSettingsPath, resolveHookAgentId } from "../hook-install.js";
|
|
5
5
|
import { ALL_CLIENTS, decideCodexPinOnly, decideJsonPinOnly, detectClients, wireAntigravity, wireClaudeCode, wireCodex, wireCursor, wireGemini } from "../install/clients.js";
|
|
@@ -8,7 +8,7 @@ import { buildEd25519Auth, defaultAdminPassPath, defaultKeysDir, resolveAdminUse
|
|
|
8
8
|
import { flairConfigYamlCandidates, readPortFromYamlFile, resolveFlairConfigYaml } from "../lib/doctor-config-path.js";
|
|
9
9
|
import { collectFederationEnv, describeFederationDriverFinding, federationPeersConfigured, loadYamlDoc } from "../lib/doctor-federation-driver.js";
|
|
10
10
|
import { plistCarriesInlineAdminPassword } from "../lib/launchd-management.js";
|
|
11
|
-
import { DOCTOR_CHECK_IDS, catalogIssueDelta, mcpRepinIcon, renderCatalogDoctorLines, runDoctorChecks } from "../lib/doctor-run.js";
|
|
11
|
+
import { DOCTOR_CHECK_IDS, catalogIssueDelta, mcpRepinIcon, probeFlairHealth, renderCatalogDoctorLines, runDoctorChecks } from "../lib/doctor-run.js";
|
|
12
12
|
import { describeEmbedGpuDoctorFinding } from "../lib/embed-gpu-doctor.js";
|
|
13
13
|
import { adminPassDesyncFinding, detectPersistedAdminUser } from "../lib/init-admin-pass.js";
|
|
14
14
|
import { opsApiBindFinding } from "../lib/ops-api-bind.js";
|
|
@@ -18,6 +18,8 @@ import { mcpClientPinFindings, refreshOwnedPins, repinSessionStartHookGuarded, s
|
|
|
18
18
|
import * as render from "../render.js";
|
|
19
19
|
import { checkVersion, formatVersionNudge, probeInstanceVersion, FLAIR_PKG_NAME } from "../version-check.js";
|
|
20
20
|
import { resolveRegistryNotice } from "../lib/npm-registry.js";
|
|
21
|
+
import { formatServingTreeLine, formatTreeAssessmentLines } from "../lib/tree-divergence.js";
|
|
22
|
+
import { rewriteFederationSchedulerRuntime } from "../federation/scheduler.js";
|
|
21
23
|
import { existsSync, readFileSync, statSync } from "node:fs";
|
|
22
24
|
import { dirname, join } from "node:path";
|
|
23
25
|
import { resolveHome } from "../lib/home.js";
|
|
@@ -130,6 +132,133 @@ export function renderEmbedGpuDoctorFinding(embedding, write = (line) => console
|
|
|
130
132
|
write(line);
|
|
131
133
|
return { lines, issueDelta: finding.isIssue ? 1 : 0 };
|
|
132
134
|
}
|
|
135
|
+
/**
|
|
136
|
+
* flair#2034 §2 — the "Install tree" doctor section: is the instance served
|
|
137
|
+
* from this CLI's install tree, and does the federation-sync shim run it?
|
|
138
|
+
*
|
|
139
|
+
* Runs in every `flair doctor` (it is not a catalog member, so it cannot be
|
|
140
|
+
* filtered out the way the catalog's launchd check is). Counting rules:
|
|
141
|
+
*
|
|
142
|
+
* - a PROVEN divergence is one issue; a deliberate runtime pin (a different
|
|
143
|
+
* node serving this CLI's own tree), a separately managed tree (a plain
|
|
144
|
+
* tree or checkout) and an unknown serving tree are reported, never counted;
|
|
145
|
+
* - `--fix` counts the divergence FIXED only after the unit was re-pointed,
|
|
146
|
+
* the instance restarted, and the serving tree re-proven to be this CLI's —
|
|
147
|
+
* "nothing to rewrite" or a failed restart is never a fix;
|
|
148
|
+
* - a federation-sync shim running another npm-global tree is one issue,
|
|
149
|
+
* fixed only when re-pointed AND re-read as current.
|
|
150
|
+
*
|
|
151
|
+
* Extracted from the action (like renderEmbedGpuDoctorFinding) so the counting
|
|
152
|
+
* is exercised directly; the action passes the real adapters.
|
|
153
|
+
*/
|
|
154
|
+
export async function runInstallTreeDoctorSection(mode, deps, write = (line) => console.log(line)) {
|
|
155
|
+
let issues = 0;
|
|
156
|
+
let fixed = 0;
|
|
157
|
+
const ok = render.icons.ok;
|
|
158
|
+
const bad = render.icons.error;
|
|
159
|
+
const info = render.icons.info;
|
|
160
|
+
const warn = render.icons.warn;
|
|
161
|
+
let a = null;
|
|
162
|
+
try {
|
|
163
|
+
a = deps.assess();
|
|
164
|
+
}
|
|
165
|
+
catch (err) {
|
|
166
|
+
write(` ${warn} install tree: could not check ${render.wrap(render.c.dim, `(${err?.message ?? err})`)}`);
|
|
167
|
+
}
|
|
168
|
+
if (a?.state === "same") {
|
|
169
|
+
write(` ${ok} ${formatServingTreeLine(a)}`);
|
|
170
|
+
if (a.nodePin?.kind === "pinned")
|
|
171
|
+
write(` ${info} ${a.nodePin.message}`);
|
|
172
|
+
}
|
|
173
|
+
else if (a?.state === "unknown") {
|
|
174
|
+
write(` ${info} ${render.wrap(render.c.dim, formatServingTreeLine(a))}`);
|
|
175
|
+
}
|
|
176
|
+
else if (a?.state === "separate") {
|
|
177
|
+
for (const line of formatTreeAssessmentLines(a, { context: "doctor" }))
|
|
178
|
+
write(` ${line}`);
|
|
179
|
+
}
|
|
180
|
+
else if (a?.state === "diverged") {
|
|
181
|
+
issues++;
|
|
182
|
+
write(` ${bad} ${render.wrap(render.c.red, "the instance is served from a different install tree than this CLI")}`);
|
|
183
|
+
for (const line of formatTreeAssessmentLines(a, { context: "doctor" }))
|
|
184
|
+
write(` ${render.wrap(render.c.yellow, line)}`);
|
|
185
|
+
if (mode.autoFix && a.cliOlder) {
|
|
186
|
+
write(` ${bad} not re-pointed: this CLI's tree is older than what the instance runs — update it first (npm i -g @tpsdev-ai/flair), then re-run.`);
|
|
187
|
+
}
|
|
188
|
+
else if (mode.autoFix && mode.dryRun) {
|
|
189
|
+
const r = deps.repoint(true);
|
|
190
|
+
write(` ${info} ${render.wrap(render.c.dim, `[dry-run] ${r.detail}; then restart the instance and re-prove which tree serves it`)}`);
|
|
191
|
+
}
|
|
192
|
+
else if (mode.autoFix) {
|
|
193
|
+
const r = deps.repoint(false);
|
|
194
|
+
if (r.kind === "repointed" || r.kind === "current") {
|
|
195
|
+
if (r.kind === "repointed")
|
|
196
|
+
write(` ${ok} ${r.detail}`);
|
|
197
|
+
try {
|
|
198
|
+
await deps.restart();
|
|
199
|
+
const after = deps.assess();
|
|
200
|
+
if (after.state === "same") {
|
|
201
|
+
fixed++;
|
|
202
|
+
write(` ${ok} ${render.wrap(render.c.green, "restarted; verified")} — ${formatServingTreeLine(after)}`);
|
|
203
|
+
}
|
|
204
|
+
else {
|
|
205
|
+
write(` ${bad} restarted, but NOT fixed — ${formatServingTreeLine(after)}`);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
catch (err) {
|
|
209
|
+
write(` ${bad} the restart failed (${err?.message ?? err}); the unit is re-pointed — run: flair restart`);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
else {
|
|
213
|
+
write(` ${bad} not re-pointed — ${r.detail}`);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
let f = null;
|
|
218
|
+
try {
|
|
219
|
+
f = deps.rewriteFederation(true);
|
|
220
|
+
}
|
|
221
|
+
catch (err) {
|
|
222
|
+
write(` ${warn} federation-sync shim: could not check ${render.wrap(render.c.dim, `(${err?.message ?? err})`)}`);
|
|
223
|
+
}
|
|
224
|
+
switch (f?.status) {
|
|
225
|
+
case "current":
|
|
226
|
+
write(` ${ok} federation-sync shim runs this CLI's tree`);
|
|
227
|
+
break;
|
|
228
|
+
case "pinned-node":
|
|
229
|
+
case "separate":
|
|
230
|
+
write(` ${info} federation-sync shim: ${f.detail}`);
|
|
231
|
+
break;
|
|
232
|
+
case "refused":
|
|
233
|
+
write(` ${warn} federation-sync shim: ${f.detail}`);
|
|
234
|
+
break;
|
|
235
|
+
case "would-rewrite": {
|
|
236
|
+
issues++;
|
|
237
|
+
write(` ${bad} the federation-sync shim runs another install tree — ${f.detail}`);
|
|
238
|
+
if (mode.autoFix && mode.dryRun) {
|
|
239
|
+
write(` ${info} ${render.wrap(render.c.dim, "[dry-run] would re-point the shim's exec line (the scheduler unit is not rewritten)")}`);
|
|
240
|
+
}
|
|
241
|
+
else if (mode.autoFix) {
|
|
242
|
+
const r = deps.rewriteFederation(false);
|
|
243
|
+
const verify = r.status === "rewritten" ? deps.rewriteFederation(true) : null;
|
|
244
|
+
if (verify?.status === "current") {
|
|
245
|
+
fixed++;
|
|
246
|
+
write(` ${ok} ${r.detail}`);
|
|
247
|
+
}
|
|
248
|
+
else {
|
|
249
|
+
write(` ${bad} federation-sync shim not re-pointed — ${verify ? verify.detail : r.detail}`);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
else {
|
|
253
|
+
write(` ${render.wrap(render.c.dim, "Fix:")} flair doctor --fix ${render.wrap(render.c.dim, "(or flair init)")}`);
|
|
254
|
+
}
|
|
255
|
+
break;
|
|
256
|
+
}
|
|
257
|
+
default:
|
|
258
|
+
break; // not enabled: nothing to say
|
|
259
|
+
}
|
|
260
|
+
return { issues, fixed };
|
|
261
|
+
}
|
|
133
262
|
// ─── flair doctor ─────────────────────────────────────────────────────────────
|
|
134
263
|
export function register(program) {
|
|
135
264
|
const __pkgVersion = cli.__pkgVersion;
|
|
@@ -256,24 +385,12 @@ export function register(program) {
|
|
|
256
385
|
console.log(` ${render.icons.ok} npm global bin dir ${render.wrap(render.c.dim, binCheck.binDir)} is on PATH`);
|
|
257
386
|
}
|
|
258
387
|
}
|
|
259
|
-
//
|
|
260
|
-
// Must return true ONLY when Harper's /Health endpoint returns 200 OK.
|
|
261
|
-
// A generic HTTP status > 0 (flair#862) would accept 404 from a Node
|
|
262
|
-
// inspector on 9229 or any other service — "present but wrong" beats
|
|
263
|
-
// "absent but correct".
|
|
388
|
+
// Probe a port's /Health.
|
|
264
389
|
async function probePort(p) {
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
return res.ok; // 200-299 only — /Health returns { ok: true } on 200
|
|
268
|
-
}
|
|
269
|
-
catch {
|
|
270
|
-
return false;
|
|
271
|
-
}
|
|
390
|
+
const probe = await probeFlairHealth(`http://127.0.0.1:${p}/Health`);
|
|
391
|
+
return probe.reaching;
|
|
272
392
|
}
|
|
273
|
-
//
|
|
274
|
-
// Scans ALL listening ports for this PID and returns the first one that
|
|
275
|
-
// responds to /Health with 200 OK. This avoids picking a debug port (9229)
|
|
276
|
-
// or any non-Flair listener that happens to share the process (flair#862).
|
|
393
|
+
// Find the PID's port by probing /Health.
|
|
277
394
|
async function discoverPortFromPid(pid) {
|
|
278
395
|
// Defense-in-depth: caller already validates, but re-check here
|
|
279
396
|
if (!/^\d+$/.test(pid))
|
|
@@ -285,7 +402,6 @@ export function register(program) {
|
|
|
285
402
|
const ports = [...out.matchAll(/n(?:\S+):(\d+)/g)].map(m => Number(m[1]));
|
|
286
403
|
if (ports.length === 0)
|
|
287
404
|
return null;
|
|
288
|
-
// Try each port until one responds to /Health with 200 OK
|
|
289
405
|
for (const port of ports) {
|
|
290
406
|
if (await probePort(port))
|
|
291
407
|
return port;
|
|
@@ -411,13 +527,17 @@ export function register(program) {
|
|
|
411
527
|
// picture here instead of a one-liner and `--fix` offers the restart.
|
|
412
528
|
let runningVersion = null;
|
|
413
529
|
let embedGpuFromHealth;
|
|
530
|
+
let workerThreads;
|
|
414
531
|
if (harperResponding) {
|
|
415
532
|
try {
|
|
416
|
-
const
|
|
417
|
-
if (
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
533
|
+
const probe = await probeFlairHealth(`${baseUrl}/Health`);
|
|
534
|
+
if (probe.reaching) {
|
|
535
|
+
workerThreads = probe.observation ?? undefined;
|
|
536
|
+
if (probe.status >= 200 && probe.status < 300 && probe.body && typeof probe.body === "object") {
|
|
537
|
+
const healthBody = probe.body;
|
|
538
|
+
runningVersion = typeof healthBody.version === "string" ? healthBody.version : null;
|
|
539
|
+
embedGpuFromHealth = healthBody.embedding;
|
|
540
|
+
}
|
|
421
541
|
}
|
|
422
542
|
}
|
|
423
543
|
catch { /* leave runningVersion null — reported below as "unknown" */ }
|
|
@@ -873,6 +993,7 @@ export function register(program) {
|
|
|
873
993
|
keysDir,
|
|
874
994
|
keyAgentIds,
|
|
875
995
|
agentFlag: typeof opts.agent === "string" ? opts.agent : undefined,
|
|
996
|
+
workerThreads,
|
|
876
997
|
};
|
|
877
998
|
const catalogBefore = runDoctorChecks(doctorCtx, { catalogIds: doctorCatalogIds });
|
|
878
999
|
// flair#1834 PR-H: a hook file on disk IS the wiring — the same rule the
|
|
@@ -1302,8 +1423,13 @@ export function register(program) {
|
|
|
1302
1423
|
const continuityDetail = continuity.state === "partial"
|
|
1303
1424
|
? (!continuity.postToolUse.present ? "the PostToolUse entry is missing" : "the Stop entry is missing")
|
|
1304
1425
|
: "an entry is not the current form (unsilenced, hand-altered, or a drifted PostToolUse matcher)";
|
|
1305
|
-
|
|
1306
|
-
|
|
1426
|
+
const pinDetail = [
|
|
1427
|
+
continuity.postToolUse.reason && "PostToolUse " + continuity.postToolUse.reason,
|
|
1428
|
+
continuity.stop.reason && "Stop " + continuity.stop.reason,
|
|
1429
|
+
].filter(Boolean).join("; ");
|
|
1430
|
+
const blockers = continuityWriteBlockers(continuity);
|
|
1431
|
+
console.log(` ${render.icons.warn} Continuity capture hooks: ${continuity.state} — ${continuityDetail}${pinDetail ? "; " + pinDetail : ""}`);
|
|
1432
|
+
if (autoFix && blockers.length === 0) {
|
|
1307
1433
|
if (dryRun) {
|
|
1308
1434
|
console.log(` ${render.wrap(render.c.dim, "Would rewrite the continuity capture hooks in")} ${continuity.path}`);
|
|
1309
1435
|
}
|
|
@@ -1327,7 +1453,15 @@ export function register(program) {
|
|
|
1327
1453
|
}
|
|
1328
1454
|
}
|
|
1329
1455
|
else {
|
|
1330
|
-
|
|
1456
|
+
if (blockers.length > 0) {
|
|
1457
|
+
const advice = pinDetail
|
|
1458
|
+
? "Resolve the listed non-version pin(s) manually; doctor cannot rewrite them."
|
|
1459
|
+
: "Continuity hook rewrite held or refused; resolve the listed reason(s) manually.";
|
|
1460
|
+
console.log(` ${advice} ${blockers.join(" ")}`);
|
|
1461
|
+
}
|
|
1462
|
+
else {
|
|
1463
|
+
console.log(` ${render.wrap(render.c.dim, "Fix:")} flair doctor --fix ${render.wrap(render.c.dim, "(rewrites both entries to the current form — same agent, same instance)")}`);
|
|
1464
|
+
}
|
|
1331
1465
|
}
|
|
1332
1466
|
issues++;
|
|
1333
1467
|
}
|
|
@@ -1557,6 +1691,22 @@ export function register(program) {
|
|
|
1557
1691
|
// Plist unreadable — the launchd plan above already reports presence.
|
|
1558
1692
|
}
|
|
1559
1693
|
}
|
|
1694
|
+
// 7c. Install tree (flair#2034 §2) — after launchd management, so a repair
|
|
1695
|
+
// above has settled which service owns the instance before this asks.
|
|
1696
|
+
console.log(`\n ${render.wrap(render.c.bold, "Install tree")}`);
|
|
1697
|
+
{
|
|
1698
|
+
const treeSection = await runInstallTreeDoctorSection({ autoFix, dryRun }, {
|
|
1699
|
+
assess: () => cli.assessInstallTree(defaultDataDir(), effectivePort, {
|
|
1700
|
+
local: true,
|
|
1701
|
+
runningVersion: effectivePort === port ? instanceVersion : null,
|
|
1702
|
+
}),
|
|
1703
|
+
repoint: (dry) => cli.repointMainServiceUnit(defaultDataDir(), effectivePort, { dryRun: dry }),
|
|
1704
|
+
restart: () => cli.restartFlair(effectivePort, defaultDataDir()),
|
|
1705
|
+
rewriteFederation: (dry) => rewriteFederationSchedulerRuntime({ dryRun: dry }),
|
|
1706
|
+
});
|
|
1707
|
+
issues += treeSection.issues;
|
|
1708
|
+
fixed += treeSection.fixed;
|
|
1709
|
+
}
|
|
1560
1710
|
// 7a. Resolve which agent identities the two verified-read sections below
|
|
1561
1711
|
// (Fleet presence, Migrations) iterate (flair#722). Previously both
|
|
1562
1712
|
// sections required --agent explicitly; doctor already enumerates every
|
|
@@ -9,6 +9,7 @@ import { redactTokenMessage } from "../lib/redact-token-id.js";
|
|
|
9
9
|
import { rewriteFederationPairHubAccessError, rewriteFederationPairLocalAccessError, } from "../lib/federation-pair-access.js";
|
|
10
10
|
import { defaultAdminPassPath, isLocalBase, resolveAdminPassFromSources, resolveAdminUser, ADMIN_PASS_FILE_FLAG, ADMIN_PASS_FILE_HELP, ADMIN_PASS_HELP, } from "../lib/auth-resolve.js";
|
|
11
11
|
import { DEFAULT_INTERVAL_SECONDS as FEDERATION_SYNC_DEFAULT_INTERVAL } from "../federation/scheduler.js";
|
|
12
|
+
import { FEDERATION_MEMORY_SELECT } from "../lib/federation-memory-attributes.js";
|
|
12
13
|
import { decideInstancePrune, formatInstanceRow, INSTANCE_ROW_PRUNE_REMEDY, prunePeerWarningLines, readInstanceRows, pruneInstanceRows, writeConfirmed, } from "../lib/instance-identity-row.js";
|
|
13
14
|
let cli;
|
|
14
15
|
/** Bind shared CLI helpers. cli.ts calls this immediately before register(program). */
|
|
@@ -677,7 +678,7 @@ export async function runFederationSyncOnce(opts) {
|
|
|
677
678
|
res = await fetch(`${opsEndpoint}/`, {
|
|
678
679
|
method: "POST",
|
|
679
680
|
headers: { "Content-Type": "application/json", Authorization: auth },
|
|
680
|
-
body: JSON.stringify({ operation: "search_by_conditions", schema: "flair", table, operator: "and", conditions: [query], get_attributes: ["*"] }),
|
|
681
|
+
body: JSON.stringify({ operation: "search_by_conditions", schema: "flair", table, operator: "and", conditions: [query], get_attributes: table === "Memory" ? [...FEDERATION_MEMORY_SELECT] : ["*"] }),
|
|
681
682
|
signal: AbortSignal.timeout(15_000),
|
|
682
683
|
});
|
|
683
684
|
}
|
package/dist/commands/hook.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as render from "../render.js";
|
|
2
2
|
import { unpinnedSpecWarning } from "../lib/mcp-spec.js";
|
|
3
|
-
import { probeSessionStartHookDelivery, readClientMcpBlock } from "../doctor-client.js";
|
|
3
|
+
import { continuityWriteBlockers, probeSessionStartHookDelivery, readClientMcpBlock } from "../doctor-client.js";
|
|
4
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
5
|
import { resolveHome } from "../lib/home.js";
|
|
6
6
|
let cli;
|
|
@@ -153,7 +153,15 @@ export function register(program) {
|
|
|
153
153
|
}
|
|
154
154
|
else {
|
|
155
155
|
const missing = !cont.postToolUse.present ? "PostToolUse missing" : !cont.stop.present ? "Stop missing" : "stale form";
|
|
156
|
-
|
|
156
|
+
const blockers = continuityWriteBlockers(cont);
|
|
157
|
+
let advice = `— re-run: ${hookInstallHint(harness, "--continuity")}`;
|
|
158
|
+
if (blockers.length > 0) {
|
|
159
|
+
const resolution = cont.postToolUse.reason || cont.stop.reason
|
|
160
|
+
? "resolve the non-version pin manually"
|
|
161
|
+
: "rewrite held or refused; resolve the listed reason(s) manually";
|
|
162
|
+
advice = `— ${resolution}; ${blockers.join(" ")}`;
|
|
163
|
+
}
|
|
164
|
+
console.log(` ${render.icons.warn} continuity capture: ${cont.state} (${missing}) ${render.wrap(render.c.dim, advice)}`);
|
|
157
165
|
}
|
|
158
166
|
};
|
|
159
167
|
console.log(`\n${render.wrap(render.c.bold, "🪝 flair hook status")}\n`);
|