@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
|
@@ -109,17 +109,79 @@ const FEDERATION_PRIVATE_VISIBILITY = "private";
|
|
|
109
109
|
function isFederationPrivateVisibility(visibility) {
|
|
110
110
|
return visibility === FEDERATION_PRIVATE_VISIBILITY;
|
|
111
111
|
}
|
|
112
|
+
/** The exact refusal sentence when nothing has reached the hub yet. */
|
|
113
|
+
const NOTHING_SENT_TO_HUB = "Nothing was sent to the hub; the pairing token is still valid.";
|
|
114
|
+
/** The post-hub failure sentence: the token is already spent. */
|
|
115
|
+
const PAIR_TOKEN_CONSUMED = "The pairing token has been consumed; mint a new one with 'flair federation token' on the hub and re-run pair.";
|
|
116
|
+
/** A rejected hub fetch may or may not have reached the hub, so be uncertain. */
|
|
117
|
+
const PAIR_TOKEN_MAYBE_CONSUMED = "The request may not have reached the hub; verify the pairing token there before re-minting one with 'flair federation token'.";
|
|
118
|
+
/**
|
|
119
|
+
* Strip any userinfo (user:password) and query string from a URL before printing
|
|
120
|
+
* it. An --ops-target like https://user:pass@host/?token=... must never put the
|
|
121
|
+
* credential or the query token on stderr.
|
|
122
|
+
*/
|
|
123
|
+
export function redactUrl(u) {
|
|
124
|
+
try {
|
|
125
|
+
const url = new URL(u);
|
|
126
|
+
url.username = "";
|
|
127
|
+
url.password = "";
|
|
128
|
+
url.search = "";
|
|
129
|
+
return url.toString();
|
|
130
|
+
}
|
|
131
|
+
catch {
|
|
132
|
+
// Not a parseable absolute URL: strip a userinfo-looking prefix and any query.
|
|
133
|
+
return u.replace(/\/\/[^/@]*@/, "//").replace(/\?.*$/, "");
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* A fetch error's code or name — NEVER its message. Under Node a rejected
|
|
138
|
+
* fetch to a user-supplied URL can carry the full URL (credentials included)
|
|
139
|
+
* in err.message, so the message must never reach an error line.
|
|
140
|
+
*/
|
|
141
|
+
function fetchErrorLabel(err) {
|
|
142
|
+
// Node's fetch wraps the OS error: the useful code (ECONNREFUSED, ENOTFOUND,
|
|
143
|
+
// …) is on err.cause.code, so prefer it over the wrapper's code/name.
|
|
144
|
+
const e = err;
|
|
145
|
+
const causeCode = typeof e?.cause?.code === "string" && e.cause.code ? e.cause.code : undefined;
|
|
146
|
+
const code = typeof e?.code === "string" && e.code ? e.code : undefined;
|
|
147
|
+
const name = typeof e?.name === "string" && e.name ? e.name : undefined;
|
|
148
|
+
return causeCode ?? code ?? name ?? "request failed";
|
|
149
|
+
}
|
|
150
|
+
/** Strip any userinfo from URLs embedded in a message before printing it. */
|
|
151
|
+
function redactMessage(text) {
|
|
152
|
+
return text.replace(/\/\/[^/@\s]+@/g, "//");
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Whether a Harper permission object can WRITE the Peer table: a super_user, or
|
|
156
|
+
* an explicit flair.Peer insert+update grant. A restrictive `operations`
|
|
157
|
+
* allowlist additionally gates the operation itself, so `upsert` must be
|
|
158
|
+
* permitted for any Peer write to reach the table. A read-only credential can
|
|
159
|
+
* search but not upsert, so the preflight must check this, not readability.
|
|
160
|
+
*/
|
|
161
|
+
export function canWritePeerPermission(permission) {
|
|
162
|
+
if (permission?.super_user === true)
|
|
163
|
+
return true;
|
|
164
|
+
const operations = permission?.operations;
|
|
165
|
+
if (Array.isArray(operations) && !operations.includes("upsert") && !operations.includes("standard_user")) {
|
|
166
|
+
return false;
|
|
167
|
+
}
|
|
168
|
+
const peer = permission?.flair?.tables?.Peer;
|
|
169
|
+
return peer?.insert === true && peer?.update === true;
|
|
170
|
+
}
|
|
112
171
|
async function loadInstanceSecretKey(instanceId, opts) {
|
|
113
172
|
// Try keystore first
|
|
114
173
|
const seed = keystore.getPrivateKeySeed(instanceId);
|
|
115
174
|
if (seed) {
|
|
116
175
|
return nacl.sign.keyPair.fromSeed(seed).secretKey;
|
|
117
176
|
}
|
|
118
|
-
// Fallback: check DB for legacy _keySeed
|
|
119
|
-
|
|
120
|
-
|
|
177
|
+
// Fallback: check DB for legacy _keySeed. Use the SAME three-source
|
|
178
|
+
// credential and the SAME resolved ops endpoint as the pair preflight, so a
|
|
179
|
+
// legacy-key spoke cannot pass preflight and then fail here for a different
|
|
180
|
+
// endpoint or a credential the fallback would not send.
|
|
181
|
+
const opsEndpoint = resolveEffectiveOpsUrl(opts) ?? `http://127.0.0.1:${resolveOpsPort(opts)}`;
|
|
182
|
+
const adminPass = opts.adminPass ?? process.env.FLAIR_ADMIN_PASS ?? process.env.HDB_ADMIN_PASSWORD ?? "";
|
|
121
183
|
const auth = `Basic ${Buffer.from(`${resolveAdminUser(opts.adminUser)}:${adminPass}`).toString("base64")}`;
|
|
122
|
-
const res = await fetch(
|
|
184
|
+
const res = await fetch(`${opsEndpoint}/`, {
|
|
123
185
|
method: "POST",
|
|
124
186
|
headers: { "Content-Type": "application/json", Authorization: auth },
|
|
125
187
|
body: JSON.stringify({ operation: "search_by_value", schema: "flair", table: "Instance", search_attribute: "id", search_type: "equals", search_value: instanceId, get_attributes: ["*"] }),
|
|
@@ -159,78 +221,65 @@ export function signRequestBody(body, secretKey) {
|
|
|
159
221
|
}
|
|
160
222
|
// Alias: signBodyFresh for clarity at call sites
|
|
161
223
|
const signBodyFresh = signRequestBody;
|
|
162
|
-
function isCompletePeerRow(row) {
|
|
163
|
-
if (!row || typeof row !== "object")
|
|
164
|
-
return false;
|
|
165
|
-
const r = row;
|
|
166
|
-
return typeof r.id === "string" && r.id.length > 0
|
|
167
|
-
&& typeof r.publicKey === "string" && r.publicKey.length > 0;
|
|
168
|
-
}
|
|
169
224
|
/**
|
|
170
225
|
* Persist last-contact on the local Peer row after confirmed hub contact.
|
|
171
226
|
*
|
|
172
|
-
* Callers must invoke this only after a FederationSync 200 (sendBatch or
|
|
173
|
-
*
|
|
174
|
-
*
|
|
175
|
-
*
|
|
227
|
+
* Callers must invoke this only after a FederationSync 200 (sendBatch or the
|
|
228
|
+
* no-change liveness ping). lastSyncAt is the value HealthDetail counts as
|
|
229
|
+
* `connected` (flair#1499 / flair#1146) AND the spoke's OUTBOUND sync cursor
|
|
230
|
+
* (`federation sync` re-sends from it) — so a frozen value re-sends from the
|
|
231
|
+
* frozen point forever and goes stale on the hub dashboard.
|
|
232
|
+
*
|
|
233
|
+
* SEMANTICS (flair#1835): `connected` means RECENT CONTACT. It does not mean a
|
|
234
|
+
* verified hub identity or pull readiness. Inbound federation separately
|
|
235
|
+
* verifies the pinned key (resources/Federation.ts post — verifyBodySignatureFresh),
|
|
236
|
+
* so a keyless row reading `connected` is correct under that definition. The
|
|
237
|
+
* missing key is repaired by #1837, not here.
|
|
176
238
|
*
|
|
177
|
-
*
|
|
178
|
-
*
|
|
179
|
-
*
|
|
180
|
-
*
|
|
181
|
-
*
|
|
239
|
+
* WHY A FIELD-ONLY UPDATE (flair#1835, was flair#1146): the 0.55.0 write was a
|
|
240
|
+
* read + FULL-row upsert gated on `isCompletePeerRow` (id + non-empty
|
|
241
|
+
* `publicKey`). A legacy pairing's local hub row has `publicKey: ""`, so the
|
|
242
|
+
* gate refused on every poll and the cursor froze. The read + full upsert also
|
|
243
|
+
* races: a key repair or a revocation written between the read and the upsert
|
|
244
|
+
* is reverted, and a row deleted in that window is recreated. The field-only
|
|
245
|
+
* `update` carries only {id, lastSyncAt, updatedAt}, so it cannot revert
|
|
246
|
+
* `publicKey`/`status`, and it never inserts.
|
|
247
|
+
*
|
|
248
|
+
* HTTP 200 is NOT success: an update that matched no row (deleted or missing)
|
|
249
|
+
* is a REFUSAL, never an insert. Harper reports which ids matched in
|
|
250
|
+
* `update_hashes`; we require ours there.
|
|
182
251
|
*/
|
|
183
252
|
export async function persistLocalPeerLastSyncAt(args) {
|
|
184
253
|
const headers = { "Content-Type": "application/json", Authorization: args.auth };
|
|
185
|
-
|
|
186
|
-
try {
|
|
187
|
-
const searchRes = await fetch(`${args.opsEndpoint}/`, {
|
|
188
|
-
method: "POST",
|
|
189
|
-
headers,
|
|
190
|
-
body: JSON.stringify({
|
|
191
|
-
operation: "search_by_value",
|
|
192
|
-
schema: "flair",
|
|
193
|
-
table: "Peer",
|
|
194
|
-
search_attribute: "id",
|
|
195
|
-
search_type: "equals",
|
|
196
|
-
search_value: args.peerId,
|
|
197
|
-
get_attributes: ["*"],
|
|
198
|
-
}),
|
|
199
|
-
signal: AbortSignal.timeout(10_000),
|
|
200
|
-
});
|
|
201
|
-
if (searchRes.ok) {
|
|
202
|
-
const rows = await searchRes.json();
|
|
203
|
-
const row = Array.isArray(rows) ? rows[0] : rows;
|
|
204
|
-
if (isCompletePeerRow(row) && row.id === args.peerId)
|
|
205
|
-
existing = row;
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
catch {
|
|
209
|
-
// Search miss — refuse to upsert an incomplete Peer.
|
|
210
|
-
}
|
|
211
|
-
if (!existing) {
|
|
212
|
-
return { ok: false, status: 0, error: "peer row missing or incomplete — refused to upsert a partial Peer" };
|
|
213
|
-
}
|
|
214
|
-
const upsertRes = await fetch(`${args.opsEndpoint}/`, {
|
|
254
|
+
const updateRes = await fetch(`${args.opsEndpoint}/`, {
|
|
215
255
|
method: "POST",
|
|
216
256
|
headers,
|
|
217
257
|
body: JSON.stringify({
|
|
218
|
-
operation: "
|
|
258
|
+
operation: "update",
|
|
219
259
|
database: "flair",
|
|
220
260
|
table: "Peer",
|
|
221
|
-
records: [{
|
|
222
|
-
...existing,
|
|
223
|
-
id: args.peerId,
|
|
224
|
-
lastSyncAt: args.lastSyncAt,
|
|
225
|
-
updatedAt: args.lastSyncAt,
|
|
226
|
-
}],
|
|
261
|
+
records: [{ id: args.peerId, lastSyncAt: args.lastSyncAt, updatedAt: args.lastSyncAt }],
|
|
227
262
|
}),
|
|
228
263
|
signal: AbortSignal.timeout(10_000),
|
|
229
264
|
});
|
|
230
|
-
if (
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
265
|
+
if (!updateRes.ok) {
|
|
266
|
+
const txt = await updateRes.text().catch(() => "");
|
|
267
|
+
return { ok: false, status: updateRes.status, error: txt.slice(0, 200) };
|
|
268
|
+
}
|
|
269
|
+
// The result check — HTTP 200 alone is not success. A miss (deleted/missing
|
|
270
|
+
// row) is reported in skipped_hashes with an empty update_hashes; refuse and
|
|
271
|
+
// never insert.
|
|
272
|
+
const parsed = (await updateRes.json().catch(() => null));
|
|
273
|
+
const matched = !!parsed && Array.isArray(parsed.update_hashes) && parsed.update_hashes.includes(args.peerId);
|
|
274
|
+
if (!matched) {
|
|
275
|
+
return {
|
|
276
|
+
ok: false,
|
|
277
|
+
status: updateRes.status,
|
|
278
|
+
error: `Peer row ${args.peerId} was not matched by the cursor update (deleted or missing) — ` +
|
|
279
|
+
`the sync cursor stays frozen; re-pair the hub. Not inserting a Peer row.`,
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
return { ok: true, status: updateRes.status };
|
|
234
283
|
}
|
|
235
284
|
/**
|
|
236
285
|
* The most recent CONTACT with any peer (max of peer.lastSyncAt), or null.
|
|
@@ -1131,6 +1180,9 @@ export function register(program) {
|
|
|
1131
1180
|
// the GET actually probes (do not cite resolveBaseUrl only in the
|
|
1132
1181
|
// rewriter while api() falls through to resolveHttpPort({})).
|
|
1133
1182
|
const identityUrl = resolveBaseUrl(opts).replace(/\/$/, "");
|
|
1183
|
+
// Set immediately before the hub's FederationPair request, so the outer
|
|
1184
|
+
// catch can say whether the one-time token may already be consumed.
|
|
1185
|
+
let hubContacted = false;
|
|
1134
1186
|
try {
|
|
1135
1187
|
// flair#820: the identity GET is pair's first step and is allowAdmin.
|
|
1136
1188
|
// A 403 here is LOCAL (or --target REMOTE), never the hub handshake.
|
|
@@ -1141,7 +1193,7 @@ export function register(program) {
|
|
|
1141
1193
|
}
|
|
1142
1194
|
catch (err) {
|
|
1143
1195
|
throw rewriteFederationPairLocalAccessError(err, {
|
|
1144
|
-
url: identityUrl,
|
|
1196
|
+
url: redactUrl(identityUrl),
|
|
1145
1197
|
side: target ? "REMOTE" : "LOCAL",
|
|
1146
1198
|
agentId: process.env.FLAIR_AGENT_ID,
|
|
1147
1199
|
});
|
|
@@ -1175,6 +1227,65 @@ export function register(program) {
|
|
|
1175
1227
|
console.error("Error: --token or --token-from is required. Ask the hub admin to run 'flair federation token' and provide the token.");
|
|
1176
1228
|
process.exit(1);
|
|
1177
1229
|
}
|
|
1230
|
+
// flair#1875: resolve the SPOKE admin credential and preflight it BEFORE
|
|
1231
|
+
// any request that consumes the one-time token. The hub's FederationPair
|
|
1232
|
+
// burns the token, so a missing or refused admin credential must be
|
|
1233
|
+
// caught here — while the token is still valid — not after the hub has
|
|
1234
|
+
// already paired us. Zero hub requests happen on this path.
|
|
1235
|
+
const adminPass = opts.adminPass ?? process.env.FLAIR_ADMIN_PASS ?? process.env.HDB_ADMIN_PASSWORD ?? "";
|
|
1236
|
+
if (!adminPass) {
|
|
1237
|
+
console.error("Error: refusing to contact the hub: the local hub-peer record needs admin auth to write — " +
|
|
1238
|
+
"pass --admin-pass, or set FLAIR_ADMIN_PASS / HDB_ADMIN_PASSWORD (the SPOKE admin password), then re-run pair. " +
|
|
1239
|
+
NOTHING_SENT_TO_HUB);
|
|
1240
|
+
process.exit(1);
|
|
1241
|
+
}
|
|
1242
|
+
const auth = `Basic ${Buffer.from(`${resolveAdminUser(opts.adminUser)}:${adminPass}`).toString("base64")}`;
|
|
1243
|
+
const opsEndpoint = resolveEffectiveOpsUrl(opts) ?? `http://127.0.0.1:${resolveOpsPort(opts)}`;
|
|
1244
|
+
const safeOps = redactUrl(opsEndpoint);
|
|
1245
|
+
// Preflight the credential against the LOCAL ops API before the hub
|
|
1246
|
+
// request. user_info reports the credential's own role/permissions, so
|
|
1247
|
+
// this proves it can WRITE flair.Peer — a read-only credential can search
|
|
1248
|
+
// but is refused by the upsert, and by then the hub has burned the token.
|
|
1249
|
+
let preflightRes;
|
|
1250
|
+
try {
|
|
1251
|
+
preflightRes = await fetch(`${opsEndpoint}/`, {
|
|
1252
|
+
method: "POST",
|
|
1253
|
+
headers: { "Content-Type": "application/json", Authorization: auth },
|
|
1254
|
+
body: JSON.stringify({ operation: "user_info" }),
|
|
1255
|
+
signal: AbortSignal.timeout(10_000),
|
|
1256
|
+
});
|
|
1257
|
+
}
|
|
1258
|
+
catch (err) {
|
|
1259
|
+
// Never print err.message: a rejected fetch to the user-supplied ops
|
|
1260
|
+
// URL can carry the full URL (credentials included) in its message.
|
|
1261
|
+
console.error(`Error: could not reach the local ops API at ${safeOps} to preflight the spoke admin credential ` +
|
|
1262
|
+
`(${fetchErrorLabel(err)}). ${NOTHING_SENT_TO_HUB}`);
|
|
1263
|
+
process.exit(1);
|
|
1264
|
+
}
|
|
1265
|
+
if (preflightRes.status === 401 || preflightRes.status === 403) {
|
|
1266
|
+
console.error(`Error: the spoke admin credential was refused by the local ops API (${preflightRes.status}). ${NOTHING_SENT_TO_HUB}`);
|
|
1267
|
+
process.exit(1);
|
|
1268
|
+
}
|
|
1269
|
+
if (!preflightRes.ok) {
|
|
1270
|
+
console.error(`Error: the local ops API at ${safeOps} answered ${preflightRes.status} to user_info. ${NOTHING_SENT_TO_HUB}`);
|
|
1271
|
+
process.exit(1);
|
|
1272
|
+
}
|
|
1273
|
+
const userInfo = (await preflightRes.json().catch(() => null));
|
|
1274
|
+
const rolePermission = userInfo?.role?.permission;
|
|
1275
|
+
if (rolePermission === undefined || rolePermission === null) {
|
|
1276
|
+
console.error(`Error: user_info returned no role information. ${NOTHING_SENT_TO_HUB}`);
|
|
1277
|
+
process.exit(1);
|
|
1278
|
+
}
|
|
1279
|
+
// super_user is the supported credential. For a non-super_user role this
|
|
1280
|
+
// checks TABLE-level grants only (flair.Peer insert+update) plus the
|
|
1281
|
+
// operations allowlist; it cannot see attribute-level grants, so a role
|
|
1282
|
+
// with table access but restricted attributes still passes here and the
|
|
1283
|
+
// upsert may fail later (reported on the consumed-token path).
|
|
1284
|
+
if (!canWritePeerPermission(rolePermission)) {
|
|
1285
|
+
const roleName = userInfo?.role?.role ?? userInfo?.role?.name ?? "(unknown)";
|
|
1286
|
+
console.error(`Error: the spoke admin credential cannot write the Peer table (role ${roleName}). ${NOTHING_SENT_TO_HUB}`);
|
|
1287
|
+
process.exit(1);
|
|
1288
|
+
}
|
|
1178
1289
|
// Load secret key and sign the pairing request.
|
|
1179
1290
|
const secretKey = await loadInstanceSecretKey(instance.id, opts);
|
|
1180
1291
|
const pairBody = {
|
|
@@ -1188,14 +1299,25 @@ export function register(program) {
|
|
|
1188
1299
|
if (authHeader) {
|
|
1189
1300
|
fetchHeaders.Authorization = authHeader;
|
|
1190
1301
|
}
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1302
|
+
let res;
|
|
1303
|
+
try {
|
|
1304
|
+
hubContacted = true;
|
|
1305
|
+
res = await fetch(`${hubUrl}/FederationPair`, {
|
|
1306
|
+
method: "POST",
|
|
1307
|
+
headers: fetchHeaders,
|
|
1308
|
+
body: JSON.stringify(signedBody),
|
|
1309
|
+
});
|
|
1310
|
+
}
|
|
1311
|
+
catch (err) {
|
|
1312
|
+
// A rejected fetch to the user-supplied hub URL: name the error, never
|
|
1313
|
+
// print its message (it can carry the URL). The request was sent, so
|
|
1314
|
+
// the token may already be consumed.
|
|
1315
|
+
console.error(`Error: could not reach the hub at ${redactUrl(hubUrl)} (${fetchErrorLabel(err)}). ${PAIR_TOKEN_MAYBE_CONSUMED}`);
|
|
1316
|
+
process.exit(1);
|
|
1317
|
+
}
|
|
1196
1318
|
if (!res.ok) {
|
|
1197
1319
|
const text = await res.text().catch(() => "");
|
|
1198
|
-
const hubDenial = rewriteFederationPairHubAccessError(res.status, hubUrl, text);
|
|
1320
|
+
const hubDenial = rewriteFederationPairHubAccessError(res.status, redactUrl(hubUrl), text);
|
|
1199
1321
|
if (hubDenial) {
|
|
1200
1322
|
console.error(`Error: ${hubDenial.message}`);
|
|
1201
1323
|
process.exit(1);
|
|
@@ -1222,42 +1344,54 @@ export function register(program) {
|
|
|
1222
1344
|
// never runs. Previously this was gated on `if (adminPass)` and the write
|
|
1223
1345
|
// result was never checked — pairing with only an agent key (or a failed
|
|
1224
1346
|
// upsert) left no peer behind a misleadingly green "✅ Paired".
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1347
|
+
// flair#1875: the admin credential was resolved and preflighted BEFORE the
|
|
1348
|
+
// hub request, so reaching here means it was accepted. A rejected write
|
|
1349
|
+
// (or a failed upsert) is a genuine post-pair failure: the token is gone.
|
|
1350
|
+
let peerRes;
|
|
1351
|
+
try {
|
|
1352
|
+
peerRes = await fetch(`${opsEndpoint}/`, {
|
|
1353
|
+
method: "POST",
|
|
1354
|
+
headers: { "Content-Type": "application/json", Authorization: auth },
|
|
1355
|
+
body: JSON.stringify({
|
|
1356
|
+
operation: "upsert", database: "flair", table: "Peer",
|
|
1357
|
+
records: [{
|
|
1358
|
+
id: resolvedHub.peer.id,
|
|
1359
|
+
publicKey: resolvedHub.peer.publicKey,
|
|
1360
|
+
role: "hub", endpoint: hubUrl, status: "paired",
|
|
1361
|
+
pairedAt: new Date().toISOString(),
|
|
1362
|
+
createdAt: new Date().toISOString(),
|
|
1363
|
+
updatedAt: new Date().toISOString(),
|
|
1364
|
+
}],
|
|
1365
|
+
}),
|
|
1366
|
+
signal: AbortSignal.timeout(10_000),
|
|
1367
|
+
});
|
|
1368
|
+
}
|
|
1369
|
+
catch (err) {
|
|
1370
|
+
// A THROWN upsert (network error) after the hub returned 200 is the same
|
|
1371
|
+
// post-pair failure as an HTTP error: the token is already consumed.
|
|
1372
|
+
// Name the error, never print its message (the ops URL is user-supplied).
|
|
1373
|
+
console.error(`Error: paired on the hub, but writing the local hub-peer record failed ` +
|
|
1374
|
+
`(${fetchErrorLabel(err)}). ${PAIR_TOKEN_CONSUMED}`);
|
|
1230
1375
|
process.exit(1);
|
|
1231
1376
|
}
|
|
1232
|
-
const auth = `Basic ${Buffer.from(`${resolveAdminUser(opts.adminUser)}:${adminPass}`).toString("base64")}`;
|
|
1233
|
-
const opsEndpoint = resolveEffectiveOpsUrl(opts) ?? `http://127.0.0.1:${resolveOpsPort(opts)}`;
|
|
1234
|
-
const peerRes = await fetch(`${opsEndpoint}/`, {
|
|
1235
|
-
method: "POST",
|
|
1236
|
-
headers: { "Content-Type": "application/json", Authorization: auth },
|
|
1237
|
-
body: JSON.stringify({
|
|
1238
|
-
operation: "upsert", database: "flair", table: "Peer",
|
|
1239
|
-
records: [{
|
|
1240
|
-
id: resolvedHub.peer.id,
|
|
1241
|
-
publicKey: resolvedHub.peer.publicKey,
|
|
1242
|
-
role: "hub", endpoint: hubUrl, status: "paired",
|
|
1243
|
-
pairedAt: new Date().toISOString(),
|
|
1244
|
-
createdAt: new Date().toISOString(),
|
|
1245
|
-
updatedAt: new Date().toISOString(),
|
|
1246
|
-
}],
|
|
1247
|
-
}),
|
|
1248
|
-
signal: AbortSignal.timeout(10_000),
|
|
1249
|
-
});
|
|
1250
1377
|
if (!peerRes.ok) {
|
|
1251
1378
|
const text = await peerRes.text().catch(() => "");
|
|
1252
|
-
console.error(`Error: paired
|
|
1253
|
-
`(${peerRes.status} ${text.slice(0, 200)}).
|
|
1254
|
-
`'flair federation sync' will not find the hub until this succeeds — check --admin-pass and the ops port.`);
|
|
1379
|
+
console.error(`Error: paired on the hub, but writing the local hub-peer record failed ` +
|
|
1380
|
+
`(${peerRes.status} ${text.slice(0, 200)}). ${PAIR_TOKEN_CONSUMED}`);
|
|
1255
1381
|
process.exit(1);
|
|
1256
1382
|
}
|
|
1257
1383
|
console.log(`✅ Recorded hub as local peer: ${resolvedHub.peer.id} → ${hubUrl}`);
|
|
1258
1384
|
}
|
|
1259
1385
|
catch (err) {
|
|
1260
|
-
|
|
1386
|
+
// A rejected fetch to a user-supplied URL can carry the full URL —
|
|
1387
|
+
// credentials included — in err.message, so for fetch-shaped errors
|
|
1388
|
+
// print the code/name instead. Append whether the hub was contacted: if
|
|
1389
|
+
// the identity GET (or anything before the hub fetch) failed, nothing
|
|
1390
|
+
// reached the hub and the token is untouched.
|
|
1391
|
+
const tail = hubContacted ? PAIR_TOKEN_CONSUMED : NOTHING_SENT_TO_HUB;
|
|
1392
|
+
const name = typeof err?.name === "string" ? err.name : "";
|
|
1393
|
+
const fetchShaped = name === "TypeError" || name === "AbortError" || name === "TimeoutError";
|
|
1394
|
+
console.error(`Error: ${fetchShaped ? fetchErrorLabel(err) : redactMessage(String(err?.message ?? err))}. ${tail}`);
|
|
1261
1395
|
process.exit(1);
|
|
1262
1396
|
}
|
|
1263
1397
|
});
|
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
|
});
|