@tpsdev-ai/flair 0.58.0 → 0.62.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 +36 -0
- package/config.yaml +15 -1
- package/dist/bridges/builtins/mem0.js +63 -28
- package/dist/bridges/runtime/import-runner.js +12 -0
- package/dist/bridges/runtime/load-plugin.js +42 -13
- package/dist/bridges/runtime/yaml-loader.js +4 -2
- package/dist/build-info.json +3 -3
- package/dist/cli.js +1030 -343
- package/dist/commands/agent.js +384 -45
- package/dist/commands/attention.js +4 -3
- package/dist/commands/backup.js +202 -34
- package/dist/commands/bridge.js +172 -119
- package/dist/commands/deploy.js +37 -4
- package/dist/commands/doctor.js +601 -163
- package/dist/commands/export.js +54 -19
- package/dist/commands/federation.js +141 -21
- package/dist/commands/hook.js +155 -2
- package/dist/commands/idp.js +14 -1
- package/dist/commands/import.js +7 -3
- package/dist/commands/init.js +462 -193
- package/dist/commands/integrity.js +388 -0
- package/dist/commands/keys.js +247 -58
- package/dist/commands/mcp.js +146 -53
- package/dist/commands/memory.js +171 -21
- package/dist/commands/migrate-harness-memory.js +3 -2
- package/dist/commands/orgevent.js +46 -37
- package/dist/commands/presence.js +4 -3
- package/dist/commands/principal.js +426 -48
- package/dist/commands/quality.js +10 -1
- package/dist/commands/reembed.js +141 -17
- package/dist/commands/relationship.js +2 -1
- package/dist/commands/rem.js +56 -18
- package/dist/commands/restore.js +101 -61
- package/dist/commands/search.js +6 -4
- package/dist/commands/service.js +151 -38
- package/dist/commands/soul.js +4 -3
- package/dist/commands/status.js +43 -5
- package/dist/commands/test.js +3 -2
- package/dist/commands/upgrade.js +24 -1
- package/dist/commands/workspace.js +6 -3
- package/dist/component-env.js +31 -41
- package/dist/deploy.js +77 -1
- package/dist/doctor-client.js +529 -92
- package/dist/engine-version-contract.js +1 -0
- package/dist/engine-version.js +23 -3
- package/dist/federation-verify.js +4 -3
- package/dist/hook-install.js +670 -6
- package/dist/keystore.js +72 -0
- package/dist/lib/action-recall-runtime.js +328 -0
- package/dist/lib/agent-home-fields.js +132 -0
- package/dist/lib/agent-home.js +427 -0
- package/dist/lib/agent-id-rule.js +46 -0
- package/dist/lib/agent-roster.js +33 -0
- package/dist/lib/auth-resolve.js +49 -16
- package/dist/lib/capture-runtime.js +124 -0
- package/dist/lib/credential-status-rule.js +78 -0
- package/dist/lib/daemon-liveness.js +81 -8
- package/dist/lib/doctor-run.js +140 -35
- package/dist/lib/durability-copy.js +10 -0
- package/dist/lib/embedding-space-doctor.js +75 -0
- package/dist/lib/flair-agent-role.js +120 -0
- package/dist/lib/hub-url.js +12 -0
- package/dist/lib/init-admin-pass.js +88 -12
- package/dist/lib/init-listener-environ.js +1 -2
- package/dist/lib/init-occupied-listener.js +15 -111
- package/dist/lib/init-spawn-attribution.js +73 -0
- package/dist/lib/init-tcp-probe.js +33 -0
- package/dist/lib/instance-identity-row.js +20 -0
- package/dist/lib/launchd-management.js +27 -2
- package/dist/lib/listener-table.js +268 -0
- package/dist/lib/local-delete-instance.js +27 -0
- package/dist/lib/local-instance-pair.js +256 -0
- package/dist/lib/mcp-enable.js +1775 -338
- package/dist/lib/mcp-oauth-env-core.js +133 -0
- package/dist/lib/mcp-oauth-env.js +125 -0
- package/dist/lib/mcp-spec.js +17 -1
- package/dist/lib/memory-attributes.js +2 -0
- package/dist/lib/memory-id-policy.js +46 -0
- package/dist/lib/memory-integrity.js +309 -0
- package/dist/lib/memory-purge-response.js +20 -0
- package/dist/lib/ops-table-count.js +25 -0
- package/dist/lib/owned-pins.js +67 -10
- package/dist/lib/peer-status.js +27 -0
- package/dist/lib/principal-status.js +29 -0
- package/dist/lib/process-start-time.js +103 -7
- package/dist/lib/proto-safe-record.js +42 -0
- package/dist/lib/record-id-path.js +25 -0
- package/dist/lib/reembed-server-support.js +66 -0
- package/dist/lib/restore-verify.js +104 -0
- package/dist/lib/scheduler-platform.js +10 -6
- package/dist/lib/secret-keys.js +25 -0
- package/dist/lib/secrets-push.js +50 -22
- package/dist/lib/skill-seed-pending.js +24 -0
- package/dist/lib/skill-seed.js +365 -0
- package/dist/lib/stop-start-recovery.js +54 -0
- package/dist/lib/using-flair-skill.js +87 -0
- package/dist/mcp-client-assertion.js +112 -4
- package/dist/memory-id-checkpoint.js +326 -0
- package/dist/memory-node-compare.js +207 -0
- package/dist/packages/flair-mcp/src/secret-redaction.js +113 -0
- package/dist/rem/restore.js +6 -5
- package/dist/rem/runner.js +103 -44
- package/dist/resources/Agent.js +348 -8
- package/dist/resources/AgentKeyRegister.js +214 -0
- package/dist/resources/AgentKeyRegistration.js +28 -0
- package/dist/resources/AgentSeed.js +19 -4
- package/dist/resources/AutoPromoteCandidates.js +7 -1
- package/dist/resources/Credential.js +177 -2
- package/dist/resources/Federation.js +752 -132
- package/dist/resources/FederationRetry.js +140 -0
- package/dist/resources/InstructionVersion.js +220 -0
- package/dist/resources/Integration.js +300 -25
- package/dist/resources/Memory.js +2113 -604
- package/dist/resources/MemoryArchive.js +75 -42
- package/dist/resources/MemoryBootstrap.js +227 -64
- package/dist/resources/MemoryCandidate.js +21 -1
- package/dist/resources/MemoryDedupStats.js +30 -1
- package/dist/resources/MemoryFeed.js +327 -45
- package/dist/resources/MemoryGrant.js +21 -1
- package/dist/resources/MemoryMaintenance.js +129 -25
- package/dist/resources/MemoryPurge.js +232 -0
- package/dist/resources/MemoryReflect.js +7 -2
- package/dist/resources/MemoryReindex.js +24 -8
- package/dist/resources/Message.js +5 -3
- package/dist/resources/OAuth.js +186 -9
- package/dist/resources/OrgEvent.js +126 -3
- package/dist/resources/OrgSkillAssignment.js +209 -0
- package/dist/resources/Presence.js +144 -49
- package/dist/resources/PromoteMemoryCandidate.js +18 -7
- package/dist/resources/Relationship.js +23 -0
- package/dist/resources/SemanticSearch.js +63 -32
- package/dist/resources/Soul.js +189 -76
- package/dist/resources/TeamDirectory.js +35 -0
- package/dist/resources/WorkspaceState.js +21 -1
- package/dist/resources/XAA.js +212 -65
- package/dist/resources/agent-auth.js +40 -15
- package/dist/resources/agent-status-guard.js +63 -0
- package/dist/resources/auth-middleware.js +402 -162
- package/dist/resources/ed25519-auth.js +1 -1
- package/dist/resources/embedding-space-guard.js +366 -72
- package/dist/resources/engine-version-stamp-boot.js +53 -0
- package/dist/resources/federation-classify.js +94 -0
- package/dist/resources/federation-crypto.js +5 -5
- package/dist/resources/federation-retry-lib.js +135 -0
- package/dist/resources/flair-agent-role-boot.js +26 -0
- package/dist/resources/grant-visibility.js +135 -0
- package/dist/resources/harper-routing.js +83 -0
- package/dist/resources/health.js +130 -20
- package/dist/resources/host-source-citation.js +49 -0
- package/dist/resources/host-source-visibility.js +7 -6
- package/dist/resources/instance-create-lock.js +17 -0
- package/dist/resources/instance-identity.js +23 -0
- package/dist/resources/instruction-version-record.js +343 -0
- package/dist/resources/key-lock.js +31 -0
- package/dist/resources/mcp-handler.js +36 -8
- package/dist/resources/mcp-oauth-env-guard.js +36 -0
- package/dist/resources/mcp-oauth.js +26 -12
- package/dist/resources/mcp-tool-arguments.js +4 -6
- package/dist/resources/mcp-tools.js +150 -23
- package/dist/resources/memory-bootstrap-lib.js +5 -15
- package/dist/resources/memory-declared-attributes.js +3 -1
- package/dist/resources/memory-deletion-history.js +55 -0
- package/dist/resources/memory-durability.js +54 -0
- package/dist/resources/memory-embed-hash.js +88 -0
- package/dist/resources/memory-embedding-value.js +8 -0
- package/dist/resources/memory-host-source.js +27 -5
- package/dist/resources/memory-id-guard.js +75 -0
- package/dist/resources/memory-redaction.js +236 -0
- package/dist/resources/memory-supplied-vector.js +72 -0
- package/dist/resources/memory-write-lock.js +310 -0
- package/dist/resources/memory-write-response.js +139 -0
- package/dist/resources/migrations/data-dir.js +74 -16
- package/dist/resources/migrations/dir-safety.js +1 -1
- package/dist/resources/migrations/embedding-stamp.js +193 -79
- package/dist/resources/migrations/export.js +1 -0
- package/dist/resources/migrations/graph-heal.js +18 -25
- package/dist/resources/migrations/lock.js +7 -1
- package/dist/resources/migrations/snapshot.js +1 -0
- package/dist/resources/migrations/source-fields.js +5 -5
- package/dist/resources/migrations/synthetic-test-migration.js +14 -11
- package/dist/resources/migrations/visibility-backfill.js +29 -29
- 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/object-body-guard.js +33 -0
- package/dist/resources/org-event-created-at.js +133 -0
- package/dist/resources/originator-instance.js +39 -7
- package/dist/resources/owner-delete-recheck.js +78 -0
- package/dist/resources/owner-field-guard.js +39 -5
- package/dist/resources/owner-scoped-write-policy.js +212 -0
- package/dist/resources/owner-scoped-writes.js +58 -0
- package/dist/resources/presence-receipt.js +236 -0
- package/dist/resources/promotion-stamp.js +47 -12
- package/dist/resources/record-owner-guard.js +74 -26
- package/dist/resources/record-types.js +17 -1
- package/dist/resources/relay-ops.js +78 -6
- package/dist/resources/replay-store.js +145 -21
- package/dist/resources/request-target.js +136 -0
- package/dist/resources/request-transaction.js +35 -0
- package/dist/resources/search-readiness.js +4 -1
- package/dist/resources/seed-ids.js +9 -0
- package/dist/resources/seed-reservation.js +117 -0
- package/dist/resources/semantic-retrieval-core.js +20 -9
- package/dist/resources/skill-manifest.js +190 -0
- package/dist/resources/skill-provenance.js +15 -10
- package/dist/resources/skill-subject.js +53 -0
- package/dist/resources/skill-version-write.js +432 -0
- package/dist/resources/skill-write-fault.js +17 -0
- package/dist/resources/skill-write-policy.js +67 -0
- package/dist/resources/skill-write.js +67 -7
- package/dist/resources/table-helpers.js +10 -7
- package/dist/resources/team-directory.js +248 -0
- package/dist/resources/tool-descriptors/index.js +69 -8
- package/dist/resources/txn-pause-point.js +118 -0
- package/dist/resources/usage-recording.js +171 -63
- package/dist/resources/write-back.js +218 -0
- package/dist/src/engine-version-contract.js +1 -0
- package/dist/src/keystore.js +72 -0
- package/dist/src/lib/agent-home-fields.js +132 -0
- package/dist/src/lib/agent-id-rule.js +46 -0
- package/dist/src/lib/agent-key-register.js +80 -0
- package/dist/src/lib/atomic-write.js +256 -0
- package/dist/src/lib/credential-status-rule.js +78 -0
- package/dist/src/lib/expired-by-agent.js +37 -0
- package/dist/src/lib/flair-agent-role.js +120 -0
- package/dist/src/lib/idp-mapping-rule.js +81 -0
- package/dist/src/lib/instance-identity-row.js +20 -0
- package/dist/src/lib/mcp-oauth-env-core.js +133 -0
- package/dist/src/lib/memory-attributes.js +2 -0
- package/dist/src/lib/memory-id-policy.js +46 -0
- package/dist/src/lib/principal-status.js +29 -0
- package/dist/src/lib/proto-safe-record.js +42 -0
- package/dist/src/lib/reembed-server-support.js +66 -0
- package/dist/src/lib/scheduler-platform.js +10 -6
- package/dist/src/lib/systemd-agent-id.js +38 -0
- package/docs/access-control.md +768 -0
- package/docs/api-reference.md +52 -13
- package/docs/auth.md +10 -12
- package/docs/bridges.md +11 -0
- package/docs/claude-code.md +34 -4
- package/docs/deepseek-harness.md +1 -1
- package/docs/deploying-on-fabric.md +70 -0
- package/docs/deployment.md +2 -0
- package/docs/embedding-in-a-harper-app.md +1 -1
- package/docs/federation.md +33 -2
- package/docs/hosted-on-fabric.md +43 -36
- package/docs/integrations.md +6 -6
- package/docs/mcp-clients.md +10 -5
- package/docs/n8n.md +17 -11
- package/docs/notes/mcp-agent-auth-consumer.md +12 -4
- package/docs/notes/mcp-oauth-model2.md +34 -5
- package/docs/quickstart-fabric.md +2 -2
- package/docs/quickstart.md +9 -1
- package/docs/releasing.md +34 -28
- package/docs/rem.md +8 -0
- package/docs/secrets-and-keys.md +19 -2
- package/docs/standalone-local.md +1 -0
- package/docs/supply-chain-policy.md +13 -3
- package/docs/upgrade.md +32 -6
- package/package.json +12 -6
- package/schemas/agent-key-registration.graphql +22 -0
- package/schemas/agent.graphql +3 -0
- package/schemas/federation.graphql +38 -1
- package/schemas/memory.graphql +115 -5
- package/schemas/oauth.graphql +27 -4
- package/schemas/schema.graphql +2 -0
- package/templates/launchd/start-flair-with-admin-pass.sh +89 -16
package/dist/commands/export.js
CHANGED
|
@@ -3,6 +3,7 @@ import * as render from "../render.js";
|
|
|
3
3
|
import { chmodSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
4
4
|
import { join, resolve } from "node:path";
|
|
5
5
|
import { resolveHome } from "../lib/home.js";
|
|
6
|
+
import { encodeRecordId } from "../lib/record-id-path.js";
|
|
6
7
|
let cli;
|
|
7
8
|
/** Bind the cli-locals this module depends on. */
|
|
8
9
|
export function bindCli(fns) {
|
|
@@ -14,6 +15,16 @@ function privKeyPath(...args) {
|
|
|
14
15
|
function resolveHttpPort(...args) {
|
|
15
16
|
return cli.resolveHttpPort(...args);
|
|
16
17
|
}
|
|
18
|
+
const AGENT_REQUIRED_FIELDS = ["id", "name", "publicKey", "createdAt"];
|
|
19
|
+
const MEMORY_REQUIRED_FIELDS = ["id", "agentId", "content", "createdAt"];
|
|
20
|
+
const SOUL_REQUIRED_FIELDS = ["id", "agentId", "key", "value", "createdAt"];
|
|
21
|
+
const GRANT_REQUIRED_FIELDS = ["id", "ownerId", "granteeId", "scope"];
|
|
22
|
+
function hasRequiredStringFields(value, fields) {
|
|
23
|
+
return !!value
|
|
24
|
+
&& typeof value === "object"
|
|
25
|
+
&& !Array.isArray(value)
|
|
26
|
+
&& fields.every((field) => typeof value[field] === "string");
|
|
27
|
+
}
|
|
17
28
|
export function register(program) {
|
|
18
29
|
// ─── flair export ────────────────────────────────────────────────────────────
|
|
19
30
|
program
|
|
@@ -34,37 +45,61 @@ export function register(program) {
|
|
|
34
45
|
process.exit(1);
|
|
35
46
|
}
|
|
36
47
|
const auth = `Basic ${Buffer.from(`${resolveAdminUser(opts.adminUser)}:${adminPass}`).toString("base64")}`;
|
|
48
|
+
class HttpError extends Error {
|
|
49
|
+
status;
|
|
50
|
+
constructor(message, status) {
|
|
51
|
+
super(message);
|
|
52
|
+
this.status = status;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
37
55
|
async function adminGet(path) {
|
|
38
56
|
const res = await fetch(`${baseUrl}${path}`, { headers: { Authorization: auth }, signal: AbortSignal.timeout(10_000) });
|
|
39
57
|
if (!res.ok)
|
|
40
|
-
throw new
|
|
58
|
+
throw new HttpError(`GET ${path} failed (${res.status})`, res.status);
|
|
41
59
|
return res.json();
|
|
42
60
|
}
|
|
43
61
|
console.log(`Exporting agent '${agentId}'...`);
|
|
44
62
|
// Fetch agent record
|
|
45
63
|
let agent;
|
|
46
64
|
try {
|
|
47
|
-
agent = await adminGet(`/Agent/${agentId}`);
|
|
65
|
+
agent = await adminGet(`/Agent/${encodeRecordId(agentId)}`);
|
|
48
66
|
}
|
|
49
|
-
catch {
|
|
50
|
-
|
|
67
|
+
catch (err) {
|
|
68
|
+
// flair#1970 acceptance: a read that FAILS is not "not found". Only a
|
|
69
|
+
// definite 404 is; a transport failure, a 5xx, or an unreadable body is a
|
|
70
|
+
// refusal that names what happened rather than an absent agent.
|
|
71
|
+
if (err instanceof HttpError && err.status === 404) {
|
|
72
|
+
console.error(`Agent '${agentId}' not found`);
|
|
73
|
+
process.exit(1);
|
|
74
|
+
}
|
|
75
|
+
console.error(`Error: could not read agent '${agentId}': ${err instanceof Error ? err.message : String(err)}. Check instance access and retry.`);
|
|
51
76
|
process.exit(1);
|
|
52
77
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
78
|
+
if (!hasRequiredStringFields(agent, AGENT_REQUIRED_FIELDS) || agent.id !== agentId) {
|
|
79
|
+
console.error(`Error: could not read agent '${agentId}': response did not contain a complete requested agent. Check the instance and retry.`);
|
|
80
|
+
process.exit(1);
|
|
81
|
+
}
|
|
82
|
+
async function readCollection(path, name, requiredFields) {
|
|
83
|
+
try {
|
|
84
|
+
const rows = await adminGet(path);
|
|
85
|
+
if (!Array.isArray(rows))
|
|
86
|
+
throw new Error(`GET ${path} returned a non-array body`);
|
|
87
|
+
const malformedIndex = rows.findIndex((row) => !hasRequiredStringFields(row, requiredFields));
|
|
88
|
+
if (malformedIndex !== -1)
|
|
89
|
+
throw new Error(`GET ${path} returned a malformed item at index ${malformedIndex}`);
|
|
90
|
+
return rows;
|
|
91
|
+
}
|
|
92
|
+
catch (err) {
|
|
93
|
+
console.error(`Error: could not read ${name}: ${err instanceof Error ? err.message : String(err)}. Check instance access and retry.`);
|
|
94
|
+
process.exit(1);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
const allMemories = await readCollection("/Memory/", "memories", MEMORY_REQUIRED_FIELDS);
|
|
98
|
+
const memories = allMemories.filter((m) => m.agentId === agentId);
|
|
99
|
+
const allSouls = await readCollection("/Soul/", "souls", SOUL_REQUIRED_FIELDS);
|
|
100
|
+
const souls = allSouls.filter((s) => s.agentId === agentId);
|
|
101
|
+
const allGrants = await readCollection("/MemoryGrant/", "grants", GRANT_REQUIRED_FIELDS);
|
|
102
|
+
const grants = allGrants.filter((g) => g.ownerId === agentId || g.granteeId === agentId);
|
|
68
103
|
// Optionally include private key
|
|
69
104
|
let privateKey;
|
|
70
105
|
if (opts.includeKey) {
|
|
@@ -1,3 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* federation.ts — `flair federation` command group (flair#1620 / epic #1618).
|
|
3
|
+
*
|
|
4
|
+
* Extracted from src/cli.ts with ZERO behavior change. This file owns the
|
|
5
|
+
* group's commander registration, action handlers, and group-specific
|
|
6
|
+
* inline helpers (crypto/sign, status-fetch sentences, pair token parse,
|
|
7
|
+
* sync/watch, prune duration). Shared CLI helpers (api, resolveTarget,
|
|
8
|
+
* credential flags, …) stay in cli.ts and are bound before register().
|
|
9
|
+
*
|
|
10
|
+
* Compiled with the rest of src/ under tsconfig.check.src.json (strict).
|
|
11
|
+
* Do not import src/cli.ts from here — that would cycle and pull the
|
|
12
|
+
* non-strict entry into the strict check.
|
|
13
|
+
*/
|
|
14
|
+
import { encodeRecordId } from "../lib/record-id-path.js";
|
|
15
|
+
import { normalizeHubUrl } from "../lib/hub-url.js";
|
|
16
|
+
import { PEER_STATUS, isPeerMemberStatus } from "../lib/peer-status.js";
|
|
17
|
+
import { protoSafeRecord } from "../lib/proto-safe-record.js";
|
|
1
18
|
import nacl from "tweetnacl";
|
|
2
19
|
import { existsSync, readFileSync } from "node:fs";
|
|
3
20
|
import { randomBytes } from "node:crypto";
|
|
@@ -79,11 +96,10 @@ function sortKeys(val) {
|
|
|
79
96
|
return val;
|
|
80
97
|
if (Array.isArray(val))
|
|
81
98
|
return val.map(sortKeys);
|
|
82
|
-
const
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}
|
|
86
|
-
return sorted;
|
|
99
|
+
const src = val;
|
|
100
|
+
// Shared null-prototype copy: an own `__proto__` key is kept in the signing
|
|
101
|
+
// input rather than silently dropped (flair#2235).
|
|
102
|
+
return protoSafeRecord(src, { keys: Object.keys(src).sort(), map: sortKeys });
|
|
87
103
|
}
|
|
88
104
|
function canonicalize(obj) {
|
|
89
105
|
return JSON.stringify(sortKeys(obj));
|
|
@@ -149,7 +165,8 @@ const PAIR_TOKEN_MAYBE_CONSUMED = "The request may not have reached the hub; ver
|
|
|
149
165
|
/**
|
|
150
166
|
* Strip any userinfo (user:password) and query string from a URL before printing
|
|
151
167
|
* it. An --ops-target like https://user:pass@host/?token=... must never put the
|
|
152
|
-
* credential or the query token on stderr.
|
|
168
|
+
* credential or the query token on stderr. If parsing fails, none of the
|
|
169
|
+
* caller-controlled text is safe to classify, so print a fixed placeholder.
|
|
153
170
|
*/
|
|
154
171
|
export function redactUrl(u) {
|
|
155
172
|
try {
|
|
@@ -157,11 +174,11 @@ export function redactUrl(u) {
|
|
|
157
174
|
url.username = "";
|
|
158
175
|
url.password = "";
|
|
159
176
|
url.search = "";
|
|
177
|
+
url.hash = "";
|
|
160
178
|
return url.toString();
|
|
161
179
|
}
|
|
162
180
|
catch {
|
|
163
|
-
|
|
164
|
-
return u.replace(/\/\/[^/@]*@/, "//").replace(/\?.*$/, "");
|
|
181
|
+
return "<unparseable URL>";
|
|
165
182
|
}
|
|
166
183
|
}
|
|
167
184
|
/**
|
|
@@ -169,7 +186,7 @@ export function redactUrl(u) {
|
|
|
169
186
|
* fetch to a user-supplied URL can carry the full URL (credentials included)
|
|
170
187
|
* in err.message, so the message must never reach an error line.
|
|
171
188
|
*/
|
|
172
|
-
function fetchErrorLabel(err) {
|
|
189
|
+
export function fetchErrorLabel(err) {
|
|
173
190
|
// Node's fetch wraps the OS error: the useful code (ECONNREFUSED, ENOTFOUND,
|
|
174
191
|
// …) is on err.cause.code, so prefer it over the wrapper's code/name.
|
|
175
192
|
const e = err;
|
|
@@ -315,7 +332,7 @@ const signBodyFresh = signRequestBody;
|
|
|
315
332
|
/**
|
|
316
333
|
* Persist last-contact on the local Peer row after confirmed hub contact.
|
|
317
334
|
*
|
|
318
|
-
* Callers must invoke this only after a FederationSync
|
|
335
|
+
* Callers must invoke this only after a successful FederationSync response (sendBatch or the
|
|
319
336
|
* no-change liveness ping). lastSyncAt is the value HealthDetail counts as
|
|
320
337
|
* `connected` (flair#1499 / flair#1146) AND the spoke's OUTBOUND sync cursor
|
|
321
338
|
* (`federation sync` re-sends from it) — so a frozen value re-sends from the
|
|
@@ -558,6 +575,26 @@ export function parseTokenFromFile(filePath) {
|
|
|
558
575
|
expiresAt: parsed.expiresAt.trim(),
|
|
559
576
|
};
|
|
560
577
|
}
|
|
578
|
+
/**
|
|
579
|
+
* The counts of one FederationSync batch response, or null when they are not
|
|
580
|
+
* counts (flair#2455 rev 2.1 N2).
|
|
581
|
+
*
|
|
582
|
+
* The response body is receiver-authored. Its `merged` and `skipped` reach the
|
|
583
|
+
* sender's success log and the watch loop's line, so each must be an integer
|
|
584
|
+
* from 0 to the number of records in the batch it answers; anything else
|
|
585
|
+
* (text, a fraction, a negative, a count larger than the batch, a missing
|
|
586
|
+
* field) makes the whole response invalid. The caller reports that in local
|
|
587
|
+
* text, never the received value.
|
|
588
|
+
*/
|
|
589
|
+
export function parseSyncBatchCounts(body, batchSize) {
|
|
590
|
+
if (body === null || typeof body !== "object" || Array.isArray(body))
|
|
591
|
+
return null;
|
|
592
|
+
const isCount = (v) => typeof v === "number" && Number.isSafeInteger(v) && v >= 0 && v <= batchSize;
|
|
593
|
+
const { merged, skipped } = body;
|
|
594
|
+
if (!isCount(merged) || !isCount(skipped))
|
|
595
|
+
return null;
|
|
596
|
+
return { merged, skipped };
|
|
597
|
+
}
|
|
561
598
|
export async function runFederationSyncOnce(opts) {
|
|
562
599
|
const target = resolveTarget(opts);
|
|
563
600
|
const baseUrl = target ? target.replace(/\/$/, "") : undefined;
|
|
@@ -593,7 +630,8 @@ export async function runFederationSyncOnce(opts) {
|
|
|
593
630
|
const auth = `Basic ${Buffer.from(`${resolveAdminUser(opts.adminUser)}:${adminPass}`).toString("base64")}`;
|
|
594
631
|
const tables = ["Memory", "Soul", "Agent", "Relationship"];
|
|
595
632
|
const instance = await api("GET", "/FederationInstance", undefined, apiOpts);
|
|
596
|
-
|
|
633
|
+
// A stored endpoint with a trailing slash still yields `<hub>/FederationSync`.
|
|
634
|
+
const hubUrl = normalizeHubUrl(hub.endpoint ?? hub.id);
|
|
597
635
|
// ── Batching constants ──────────────────────────────────────────────
|
|
598
636
|
// 2MB JSON budget (server cap is 10MB; 2MB leaves headroom for headers
|
|
599
637
|
// and signature metadata) + 50 records max per batch. The hub merge itself
|
|
@@ -653,10 +691,25 @@ export async function runFederationSyncOnce(opts) {
|
|
|
653
691
|
if (!syncRes.ok) {
|
|
654
692
|
if (splittable(syncRes.status))
|
|
655
693
|
return await split();
|
|
656
|
-
|
|
657
|
-
|
|
694
|
+
// flair#2455 rev 2.1 N2: the receiver's response body is receiver-authored
|
|
695
|
+
// text and is never logged. Report the status only.
|
|
696
|
+
throw new Error(`Sync batch failed: HTTP ${syncRes.status}`);
|
|
697
|
+
}
|
|
698
|
+
// A 200 is still receiver-authored: a body that is not JSON (the parser's
|
|
699
|
+
// own error quotes part of it) or whose counts are not counts is an
|
|
700
|
+
// invalid response, reported in local text only (flair#2455 N2).
|
|
701
|
+
let body;
|
|
702
|
+
try {
|
|
703
|
+
body = await syncRes.json();
|
|
704
|
+
}
|
|
705
|
+
catch {
|
|
706
|
+
throw new Error(`Sync batch failed: invalid response (HTTP ${syncRes.status}, body is not JSON)`);
|
|
658
707
|
}
|
|
659
|
-
|
|
708
|
+
const counts = parseSyncBatchCounts(body, batch.length);
|
|
709
|
+
if (!counts) {
|
|
710
|
+
throw new Error(`Sync batch failed: invalid response (HTTP ${syncRes.status}, merged/skipped are not counts from 0 to ${batch.length})`);
|
|
711
|
+
}
|
|
712
|
+
return counts;
|
|
660
713
|
}
|
|
661
714
|
let totalBatches = 0;
|
|
662
715
|
// Memory rows that passed the since-cursor filter but were excluded as
|
|
@@ -780,7 +833,7 @@ export async function runFederationSyncOnce(opts) {
|
|
|
780
833
|
}
|
|
781
834
|
}
|
|
782
835
|
// lastSyncAt is contact, not "the driver ran" (flair#1146). Persist only
|
|
783
|
-
// after a FederationSync
|
|
836
|
+
// after a successful FederationSync response — sendBatch already threw on non-ok or invalid JSON, so
|
|
784
837
|
// totalBatches > 0 means the hub answered. The no-change path must ping
|
|
785
838
|
// first; a failed ping leaves the stamp untouched → unknown.
|
|
786
839
|
const stampLocalContact = async () => {
|
|
@@ -819,8 +872,8 @@ export async function runFederationSyncOnce(opts) {
|
|
|
819
872
|
signal: AbortSignal.timeout(10_000),
|
|
820
873
|
});
|
|
821
874
|
if (!pingRes.ok) {
|
|
822
|
-
|
|
823
|
-
console.warn(`⚠️ Liveness ping to hub failed (${pingRes.status})
|
|
875
|
+
// flair#2455 rev 2.1 N2: no receiver-authored body in the sender's log.
|
|
876
|
+
console.warn(`⚠️ Liveness ping to hub failed (HTTP ${pingRes.status}). Hub won't update spoke liveness.`);
|
|
824
877
|
}
|
|
825
878
|
else {
|
|
826
879
|
pingOk = true;
|
|
@@ -943,6 +996,18 @@ export function register(program) {
|
|
|
943
996
|
catch (err) {
|
|
944
997
|
peersErr = rewriteFederationStatusFetchFailed(err, baseUrl, urlSetting);
|
|
945
998
|
}
|
|
999
|
+
// Federation retry rows (flair#2455): the sender's pending, terminal and
|
|
1000
|
+
// malformed retry rows, read through the admin-only /FederationRetries
|
|
1001
|
+
// resource. null = unverifiable (the read failed), like peers.
|
|
1002
|
+
let retries = null;
|
|
1003
|
+
let retriesErr = null;
|
|
1004
|
+
try {
|
|
1005
|
+
const r = await api("GET", "/FederationRetries", undefined, { baseUrl });
|
|
1006
|
+
retries = { pending: r.pending ?? [], terminal: r.terminal ?? [], malformed: r.malformed ?? [] };
|
|
1007
|
+
}
|
|
1008
|
+
catch (err) {
|
|
1009
|
+
retriesErr = err;
|
|
1010
|
+
}
|
|
946
1011
|
// Auth-shaped failures stay FATAL even when the other read succeeded:
|
|
947
1012
|
// both endpoints sit behind the same allowAdmin gate, so a 401/403 is a
|
|
948
1013
|
// property of the session's credentials, not of one endpoint — and
|
|
@@ -1005,16 +1070,18 @@ export function register(program) {
|
|
|
1005
1070
|
console.log(render.asJSON({
|
|
1006
1071
|
instance,
|
|
1007
1072
|
peers,
|
|
1073
|
+
retries,
|
|
1008
1074
|
driver,
|
|
1009
1075
|
driverAssessment: assessment,
|
|
1010
1076
|
// flair#1233: name what could not be read, so a partial result is
|
|
1011
1077
|
// distinguishable from "verified absent" (instance/peers stay null
|
|
1012
1078
|
// when their read failed).
|
|
1013
|
-
...(instanceErr || peersErr
|
|
1079
|
+
...(instanceErr || peersErr || retriesErr
|
|
1014
1080
|
? {
|
|
1015
1081
|
unverifiable: {
|
|
1016
1082
|
...(instanceErr ? { instance: String(instanceErr.message ?? instanceErr) } : {}),
|
|
1017
1083
|
...(peersErr ? { peers: String(peersErr.message ?? peersErr) } : {}),
|
|
1084
|
+
...(retriesErr ? { retries: String(retriesErr.message ?? retriesErr) } : {}),
|
|
1018
1085
|
},
|
|
1019
1086
|
}
|
|
1020
1087
|
: {}),
|
|
@@ -1042,6 +1109,52 @@ export function register(program) {
|
|
|
1042
1109
|
// Instance read failed but peers succeeded — render what we have.
|
|
1043
1110
|
console.log(render.kv("Instance", `${render.icons.warn} unverifiable — ${render.wrap(render.c.dim, String(instanceErr?.message ?? instanceErr))}`));
|
|
1044
1111
|
}
|
|
1112
|
+
// Federation retry rows (flair#2455): the sender's retry bookkeeping per
|
|
1113
|
+
// peer, table and record. Rendered after the peer table, and also on the
|
|
1114
|
+
// two early returns below (no peers configured; a peer read that fails
|
|
1115
|
+
// while the instance read succeeds). The fatal exits above (an instance or
|
|
1116
|
+
// peer read auth failure, or both those reads failing) render nothing. A
|
|
1117
|
+
// retry-row read that fails, including on auth, renders the section as
|
|
1118
|
+
// unverifiable and does not by itself make the command exit non-zero.
|
|
1119
|
+
// No production sender path creates rows yet; admin-written rows show.
|
|
1120
|
+
// Once the sender is active, it re-offers pending rows; a terminal row
|
|
1121
|
+
// ended with a named resolution; a malformed row breaks a sender
|
|
1122
|
+
// convention and is never transitioned.
|
|
1123
|
+
const renderRetrySection = () => {
|
|
1124
|
+
if (retriesErr) {
|
|
1125
|
+
console.log();
|
|
1126
|
+
console.log(`${render.icons.warn} ${render.wrap(render.c.yellow, "Federation retries unverifiable — the retry read failed.")}`);
|
|
1127
|
+
console.log(` ${render.wrap(render.c.dim, String(retriesErr?.message ?? retriesErr))}`);
|
|
1128
|
+
return;
|
|
1129
|
+
}
|
|
1130
|
+
if (!retries || (retries.pending.length === 0 && retries.terminal.length === 0 && retries.malformed.length === 0))
|
|
1131
|
+
return;
|
|
1132
|
+
console.log();
|
|
1133
|
+
console.log(render.wrap(render.c.bold, "Federation retries"));
|
|
1134
|
+
const retryCols = [
|
|
1135
|
+
{ label: "state", key: "state" },
|
|
1136
|
+
{ label: "peer", key: "peerId" },
|
|
1137
|
+
{ label: "table", key: "table" },
|
|
1138
|
+
{ label: "id", key: "id" },
|
|
1139
|
+
{ label: "reason", key: "reason", format: (v) => String(v ?? "—") },
|
|
1140
|
+
{ label: "attempts", key: "attempts", format: (v) => String(v ?? "—") },
|
|
1141
|
+
{ label: "bound", key: "bound", format: (v) => String(v ?? "—") },
|
|
1142
|
+
{ label: "resolution", key: "resolution", format: (v) => String(v ?? "—") },
|
|
1143
|
+
];
|
|
1144
|
+
if (retries.pending.length > 0 || retries.terminal.length > 0) {
|
|
1145
|
+
console.log(render.table(retryCols, [...retries.pending, ...retries.terminal]));
|
|
1146
|
+
}
|
|
1147
|
+
if (retries.malformed.length > 0) {
|
|
1148
|
+
console.log();
|
|
1149
|
+
console.log(`${render.icons.warn} ${render.wrap(render.c.yellow, `${retries.malformed.length} malformed retry row${retries.malformed.length === 1 ? "" : "s"}: not pending, never transitioned.`)}`);
|
|
1150
|
+
const malformedCols = [
|
|
1151
|
+
{ label: "problem", key: "problem" },
|
|
1152
|
+
{ label: "key", key: "key", format: (v) => String(v ?? "—") },
|
|
1153
|
+
{ label: "state", key: "state", format: (v) => String(v ?? "—") },
|
|
1154
|
+
];
|
|
1155
|
+
console.log(render.table(malformedCols, retries.malformed));
|
|
1156
|
+
}
|
|
1157
|
+
};
|
|
1045
1158
|
if (peers === null) {
|
|
1046
1159
|
// Peer read failed but the instance rendered — say so explicitly
|
|
1047
1160
|
// instead of aborting: "unverifiable" is a different claim from "no
|
|
@@ -1049,10 +1162,12 @@ export function register(program) {
|
|
|
1049
1162
|
console.log();
|
|
1050
1163
|
console.log(`${render.icons.warn} ${render.wrap(render.c.yellow, "Peers unverifiable — the peer read failed. This says nothing about whether peers exist or sync runs.")}`);
|
|
1051
1164
|
console.log(` ${render.wrap(render.c.dim, String(peersErr?.message ?? peersErr))}`);
|
|
1165
|
+
renderRetrySection();
|
|
1052
1166
|
return;
|
|
1053
1167
|
}
|
|
1054
1168
|
if (peers.length === 0) {
|
|
1055
1169
|
console.log(`\n${render.icons.info} ${render.wrap(render.c.dim, "No peers configured. Use 'flair federation pair' to connect to a hub.")}`);
|
|
1170
|
+
renderRetrySection();
|
|
1056
1171
|
return;
|
|
1057
1172
|
}
|
|
1058
1173
|
// Print the driver line BEFORE the per-peer table: "is anything running
|
|
@@ -1099,7 +1214,7 @@ export function register(program) {
|
|
|
1099
1214
|
key: "status",
|
|
1100
1215
|
format: (v) => {
|
|
1101
1216
|
const s = String(v ?? "—");
|
|
1102
|
-
const color = s
|
|
1217
|
+
const color = isPeerMemberStatus(s) ? render.c.green : s === PEER_STATUS.REVOKED ? render.c.red : render.c.yellow;
|
|
1103
1218
|
return render.wrap(color, s);
|
|
1104
1219
|
},
|
|
1105
1220
|
},
|
|
@@ -1124,6 +1239,7 @@ export function register(program) {
|
|
|
1124
1239
|
},
|
|
1125
1240
|
];
|
|
1126
1241
|
console.log(render.table(cols, peers));
|
|
1242
|
+
renderRetrySection();
|
|
1127
1243
|
// Stale warning is gated on lastMergeAt (real progress), not lastSyncAt.
|
|
1128
1244
|
// A peer that "syncs" every 5min but hasn't merged a record in 24h is
|
|
1129
1245
|
// exactly the failure mode we want surfaced.
|
|
@@ -1265,7 +1381,11 @@ export function register(program) {
|
|
|
1265
1381
|
.option("--token-from <file>", "Read bootstrap triple from JSON file (use '-' for stdin)")
|
|
1266
1382
|
.option("--target <url>", "Remote Flair URL (env: FLAIR_TARGET)")
|
|
1267
1383
|
.option("--ops-target <url>", "Explicit ops API URL (env: FLAIR_OPS_TARGET; bypasses port derivation)")
|
|
1268
|
-
.action(async (
|
|
1384
|
+
.action(async (hubUrlArg, opts) => {
|
|
1385
|
+
// Strip trailing slashes once, before the hub URL is used or stored, so a
|
|
1386
|
+
// trailing slash on the typed URL does not add an empty path segment to
|
|
1387
|
+
// the appended pairing route or the stored hub-peer endpoint.
|
|
1388
|
+
const hubUrl = normalizeHubUrl(hubUrlArg);
|
|
1269
1389
|
const target = resolveTarget(opts);
|
|
1270
1390
|
// flair#1873: resolve the SPOKE admin credential FIRST, before any
|
|
1271
1391
|
// request. `--admin-pass-file` is read in-process (mode 0600 enforced),
|
|
@@ -1829,7 +1949,7 @@ export function register(program) {
|
|
|
1829
1949
|
let errors = 0;
|
|
1830
1950
|
for (const p of candidates) {
|
|
1831
1951
|
try {
|
|
1832
|
-
const res = await api("DELETE", `/FederationPeers/${
|
|
1952
|
+
const res = await api("DELETE", `/FederationPeers/${encodeRecordId(p.id)}`, undefined, baseUrl ? { baseUrl } : undefined);
|
|
1833
1953
|
const ok = res?.ok ?? res?.deleted ?? true;
|
|
1834
1954
|
if (ok) {
|
|
1835
1955
|
deleted++;
|
package/dist/commands/hook.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import * as render from "../render.js";
|
|
2
|
-
import { unpinnedSpecWarning } from "../lib/mcp-spec.js";
|
|
2
|
+
import { flairCliVersion, unpinnedSpecWarning } from "../lib/mcp-spec.js";
|
|
3
3
|
import { continuityWriteBlockers, probeSessionStartHookDelivery, readClientMcpBlock } from "../doctor-client.js";
|
|
4
|
-
import { installHook, uninstallHook, hookStatus, hookStatusHeadline, hookStatusFailureLine, hookStatusIdentityLines, HOOK_STATUS_UNPARSED, installContinuityHooks, uninstallContinuityHooks, continuityHookStatus, isSupportedHarness, SUPPORTED_HARNESSES, hookInstallHint, harnessSupportsContinuity, resolveHookAgentId, } from "../hook-install.js";
|
|
4
|
+
import { installHook, uninstallHook, hookStatus, hookStatusHeadline, hookStatusFailureLine, hookStatusIdentityLines, HOOK_STATUS_UNPARSED, installContinuityHooks, uninstallContinuityHooks, continuityHookStatus, installActionRecall, uninstallActionRecall, actionRecallHookStatus, installCaptureHooks, uninstallCaptureHooks, captureHookStatus, isSupportedHarness, SUPPORTED_HARNESSES, hookInstallHint, harnessSupportsContinuity, resolveHookAgentId, } from "../hook-install.js";
|
|
5
|
+
import { resolveActionRecallRuntime } from "../lib/action-recall-runtime.js";
|
|
6
|
+
import { resolveCaptureRuntime } from "../lib/capture-runtime.js";
|
|
5
7
|
import { resolveHome } from "../lib/home.js";
|
|
8
|
+
import { sessionStartHookPinFindings } from "../lib/owned-pins.js";
|
|
6
9
|
let cli;
|
|
7
10
|
/** Bind shared CLI helpers. cli.ts calls this immediately before register(program). */
|
|
8
11
|
export function bindCli(fns) {
|
|
@@ -49,6 +52,8 @@ export function register(program) {
|
|
|
49
52
|
.option("--agent-id <id>", "Alias for --agent")
|
|
50
53
|
.option("--url <url>", "Flair URL to wire (else FLAIR_TARGET/FLAIR_URL, else this harness's MCP wiring, else the local default)")
|
|
51
54
|
.option("--continuity", "Wire the continuity capture hooks instead (PostToolUse + Stop — flair#1257; installing them IS the opt-in)")
|
|
55
|
+
.option("--action-recall", "Wire the Claude Code PreToolUse action-recall hook instead (flair#2067)")
|
|
56
|
+
.option("--capture", "Wire the Claude Code PostToolUseFailure + PostToolUse + Stop learning-capture hooks instead (flair#2068)")
|
|
52
57
|
.action((opts) => {
|
|
53
58
|
const harness = requireSupportedHarness(opts.harness);
|
|
54
59
|
const home = resolveHome();
|
|
@@ -59,6 +64,56 @@ export function register(program) {
|
|
|
59
64
|
}
|
|
60
65
|
const flairUrl = resolveHookFlairUrl(opts, home, harness);
|
|
61
66
|
const dryRun = !!opts.dryRun;
|
|
67
|
+
if (opts.capture) {
|
|
68
|
+
const resolved = resolveCaptureRuntime({ fromUrl: import.meta.url });
|
|
69
|
+
if (!resolved.ok) {
|
|
70
|
+
const reason = "reason" in resolved ? resolved.reason : "unknown error";
|
|
71
|
+
console.error(`Capture hook not installed: ${reason}`);
|
|
72
|
+
process.exit(1);
|
|
73
|
+
}
|
|
74
|
+
const result = installCaptureHooks({
|
|
75
|
+
homeDir: home,
|
|
76
|
+
harness,
|
|
77
|
+
agentId,
|
|
78
|
+
flairUrl,
|
|
79
|
+
dryRun,
|
|
80
|
+
runtime: resolved.runtime,
|
|
81
|
+
});
|
|
82
|
+
console.log(`\n${render.wrap(render.c.bold, "🪝 flair hook install --capture")}${dryRun ? render.wrap(render.c.dim, " (dry run)") : ""}\n`);
|
|
83
|
+
console.log(` ${result.ok ? render.icons.ok : render.icons.error} ${result.message}`);
|
|
84
|
+
if (result.backupPath) {
|
|
85
|
+
console.log(` ${render.wrap(render.c.dim, `backup: ${result.backupPath}`)}`);
|
|
86
|
+
}
|
|
87
|
+
console.log("");
|
|
88
|
+
if (!result.ok)
|
|
89
|
+
process.exit(1);
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
if (opts.actionRecall) {
|
|
93
|
+
const resolved = resolveActionRecallRuntime({ fromUrl: import.meta.url });
|
|
94
|
+
if (!resolved.ok) {
|
|
95
|
+
const reason = "reason" in resolved ? resolved.reason : "unknown error";
|
|
96
|
+
console.error(`Action-recall hook not installed: ${reason}`);
|
|
97
|
+
process.exit(1);
|
|
98
|
+
}
|
|
99
|
+
const result = installActionRecall({
|
|
100
|
+
homeDir: home,
|
|
101
|
+
harness,
|
|
102
|
+
agentId,
|
|
103
|
+
flairUrl,
|
|
104
|
+
dryRun,
|
|
105
|
+
runtime: resolved.runtime,
|
|
106
|
+
});
|
|
107
|
+
console.log(`\n${render.wrap(render.c.bold, "🪝 flair hook install --action-recall")}${dryRun ? render.wrap(render.c.dim, " (dry run)") : ""}\n`);
|
|
108
|
+
console.log(` ${result.ok ? render.icons.ok : render.icons.error} ${result.message}`);
|
|
109
|
+
if (result.backupPath) {
|
|
110
|
+
console.log(` ${render.wrap(render.c.dim, `backup: ${result.backupPath}`)}`);
|
|
111
|
+
}
|
|
112
|
+
console.log("");
|
|
113
|
+
if (!result.ok)
|
|
114
|
+
process.exit(1);
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
62
117
|
if (opts.continuity) {
|
|
63
118
|
const result = installContinuityHooks({ homeDir: home, harness, agentId, flairUrl, dryRun });
|
|
64
119
|
console.log(`\n${render.wrap(render.c.bold, "🪝 flair hook install --continuity")}${dryRun ? render.wrap(render.c.dim, " (dry run)") : ""}\n`);
|
|
@@ -96,10 +151,36 @@ export function register(program) {
|
|
|
96
151
|
.option("--harness <name>", `Target harness (${SUPPORTED_HARNESSES.join(", ")})`, "claude-code")
|
|
97
152
|
.option("--dry-run", "Print the exact JSON delta without writing")
|
|
98
153
|
.option("--continuity", "Remove the continuity capture hooks instead (PostToolUse + Stop — flair#1257)")
|
|
154
|
+
.option("--action-recall", "Remove the Claude Code PreToolUse action-recall hook instead (flair#2067)")
|
|
155
|
+
.option("--capture", "Remove the Claude Code PostToolUseFailure + PostToolUse + Stop learning-capture hooks instead (flair#2068)")
|
|
99
156
|
.action((opts) => {
|
|
100
157
|
const harness = requireSupportedHarness(opts.harness);
|
|
101
158
|
const home = resolveHome();
|
|
102
159
|
const dryRun = !!opts.dryRun;
|
|
160
|
+
if (opts.capture) {
|
|
161
|
+
const result = uninstallCaptureHooks({ homeDir: home, harness, dryRun });
|
|
162
|
+
console.log(`\n${render.wrap(render.c.bold, "🪝 flair hook uninstall --capture")}${dryRun ? render.wrap(render.c.dim, " (dry run)") : ""}\n`);
|
|
163
|
+
console.log(` ${result.ok ? render.icons.ok : render.icons.error} ${result.message}`);
|
|
164
|
+
if (result.backupPath) {
|
|
165
|
+
console.log(` ${render.wrap(render.c.dim, `backup: ${result.backupPath}`)}`);
|
|
166
|
+
}
|
|
167
|
+
console.log("");
|
|
168
|
+
if (!result.ok)
|
|
169
|
+
process.exit(1);
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
if (opts.actionRecall) {
|
|
173
|
+
const result = uninstallActionRecall({ homeDir: home, harness, dryRun });
|
|
174
|
+
console.log(`\n${render.wrap(render.c.bold, "🪝 flair hook uninstall --action-recall")}${dryRun ? render.wrap(render.c.dim, " (dry run)") : ""}\n`);
|
|
175
|
+
console.log(` ${result.ok ? render.icons.ok : render.icons.error} ${result.message}`);
|
|
176
|
+
if (result.backupPath) {
|
|
177
|
+
console.log(` ${render.wrap(render.c.dim, `backup: ${result.backupPath}`)}`);
|
|
178
|
+
}
|
|
179
|
+
console.log("");
|
|
180
|
+
if (!result.ok)
|
|
181
|
+
process.exit(1);
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
103
184
|
if (opts.continuity) {
|
|
104
185
|
const result = uninstallContinuityHooks({ homeDir: home, harness, dryRun });
|
|
105
186
|
console.log(`\n${render.wrap(render.c.bold, "🪝 flair hook uninstall --continuity")}${dryRun ? render.wrap(render.c.dim, " (dry run)") : ""}\n`);
|
|
@@ -130,11 +211,17 @@ export function register(program) {
|
|
|
130
211
|
.command("status")
|
|
131
212
|
.description("Show whether the SessionStart hook is wired, its shape, and which Flair instance it targets")
|
|
132
213
|
.option("--harness <name>", `Target harness (${SUPPORTED_HARNESSES.join(", ")})`, "claude-code")
|
|
214
|
+
.option("--action-recall", "Also report the Claude Code PreToolUse action-recall hook (flair#2067)")
|
|
215
|
+
.option("--capture", "Also report the Claude Code PostToolUseFailure + PostToolUse + Stop learning-capture hooks (flair#2068)")
|
|
133
216
|
.action((opts) => {
|
|
134
217
|
const harness = requireSupportedHarness(opts.harness);
|
|
135
218
|
const home = resolveHome();
|
|
219
|
+
const pinFinding = sessionStartHookPinFindings(home).find((f) => f.reading.target.id === harness) ?? null;
|
|
136
220
|
const status = hookStatus(home, harness, {
|
|
137
221
|
deliveryProbe: (command) => probeSessionStartHookDelivery(command),
|
|
222
|
+
stalePinFinding: pinFinding
|
|
223
|
+
? { pin: pinFinding.reading.pin, direction: pinFinding.direction }
|
|
224
|
+
: null,
|
|
138
225
|
});
|
|
139
226
|
// Continuity pair (flair#1257) — reported alongside the SessionStart
|
|
140
227
|
// status in every branch below. "absent" is NOT a failure: installing the
|
|
@@ -164,6 +251,55 @@ export function register(program) {
|
|
|
164
251
|
console.log(` ${render.icons.warn} continuity capture: ${cont.state} (${missing}) ${render.wrap(render.c.dim, advice)}`);
|
|
165
252
|
}
|
|
166
253
|
};
|
|
254
|
+
// Action recall (flair#2067) — reported only when `--action-recall` is
|
|
255
|
+
// passed. Absence is informational (the hook is opt-in).
|
|
256
|
+
const renderActionRecall = () => {
|
|
257
|
+
if (!opts.actionRecall)
|
|
258
|
+
return;
|
|
259
|
+
if (harness !== "claude-code") {
|
|
260
|
+
console.log(` ${render.icons.info} action recall: Claude Code only`);
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
const recall = actionRecallHookStatus(home, harness);
|
|
264
|
+
if (recall.problems.length > 0) {
|
|
265
|
+
process.exitCode = 1;
|
|
266
|
+
console.log(` ${render.icons.warn} action recall: stale (${recall.problems.join("; ")})`);
|
|
267
|
+
}
|
|
268
|
+
else if (recall.installed && recall.refreshEnabled) {
|
|
269
|
+
console.log(` ${render.icons.ok} action recall: PreToolUse (Bash) wired, refresh enabled`);
|
|
270
|
+
}
|
|
271
|
+
else if (recall.runtimeFailure) {
|
|
272
|
+
process.exitCode = 1;
|
|
273
|
+
console.log(` ${render.icons.warn} ${recall.runtimeFailure}`);
|
|
274
|
+
}
|
|
275
|
+
else if (recall.installed) {
|
|
276
|
+
console.log(` ${render.icons.warn} action recall: PreToolUse wired, refresh NOT enabled ${render.wrap(render.c.dim, `(re-run: ${hookInstallHint(harness, "--action-recall")})`)}`);
|
|
277
|
+
}
|
|
278
|
+
else {
|
|
279
|
+
console.log(` ${render.icons.info} action recall: not enabled ${render.wrap(render.c.dim, `(opt-in: ${hookInstallHint(harness, "--action-recall")})`)}`);
|
|
280
|
+
}
|
|
281
|
+
};
|
|
282
|
+
// Capture (flair#2068) — reported only when `--capture` is passed.
|
|
283
|
+
const renderCapture = () => {
|
|
284
|
+
if (!opts.capture)
|
|
285
|
+
return;
|
|
286
|
+
if (harness !== "claude-code") {
|
|
287
|
+
console.log(` ${render.icons.info} capture: Claude Code only`);
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
const capture = captureHookStatus(home, harness);
|
|
291
|
+
if (capture.installed) {
|
|
292
|
+
console.log(` ${render.icons.ok} capture: PostToolUseFailure + PostToolUse + Stop wired`);
|
|
293
|
+
}
|
|
294
|
+
else if (capture.state === "absent") {
|
|
295
|
+
console.log(` ${render.icons.info} capture: not enabled ${render.wrap(render.c.dim, `(opt-in: ${hookInstallHint(harness, "--capture")})`)}`);
|
|
296
|
+
}
|
|
297
|
+
else {
|
|
298
|
+
process.exitCode = 1;
|
|
299
|
+
const what = capture.problems.length > 0 ? ` (${capture.problems.join("; ")})` : "";
|
|
300
|
+
console.log(` ${render.icons.warn} capture: ${capture.state}${what} ${render.wrap(render.c.dim, `(re-run: ${hookInstallHint(harness, "--capture")})`)}`);
|
|
301
|
+
}
|
|
302
|
+
};
|
|
167
303
|
console.log(`\n${render.wrap(render.c.bold, "🪝 flair hook status")}\n`);
|
|
168
304
|
console.log(` ${render.wrap(render.c.dim, "Harness:")} ${status.harness}`);
|
|
169
305
|
console.log(` ${render.wrap(render.c.dim, "Config:")} ${status.path}`);
|
|
@@ -176,9 +312,24 @@ export function register(program) {
|
|
|
176
312
|
console.log(` ${render.icons.error} ${hookStatusHeadline(status)}`);
|
|
177
313
|
console.log(` ${render.wrap(render.c.dim, "Fix:")} ${hookInstallHint(status.harness)}`);
|
|
178
314
|
renderContinuity();
|
|
315
|
+
renderActionRecall();
|
|
316
|
+
renderCapture();
|
|
317
|
+
console.log("");
|
|
318
|
+
process.exit(1);
|
|
319
|
+
}
|
|
320
|
+
if (status.pinStale) {
|
|
321
|
+
console.log(` ${render.icons.error} SessionStart hook: command names older pin flair-mcp@${status.stalePin} (installed CLI is ${flairCliVersion()})`);
|
|
322
|
+
console.log(` ${render.wrap(render.c.dim, "Fix:")} ${hookInstallHint(status.harness)}`);
|
|
323
|
+
renderContinuity();
|
|
324
|
+
renderActionRecall();
|
|
325
|
+
renderCapture();
|
|
179
326
|
console.log("");
|
|
180
327
|
process.exit(1);
|
|
181
328
|
}
|
|
329
|
+
// flair#2291: a held hook shape (see readOwnedPin) is reported.
|
|
330
|
+
if (pinFinding?.reading.held) {
|
|
331
|
+
console.log(` ${render.icons.warn} SessionStart hook: ${pinFinding.reading.held}`);
|
|
332
|
+
}
|
|
182
333
|
const headline = hookStatusHeadline(status);
|
|
183
334
|
const verified = status.delivery === "verified" && status.correctShape;
|
|
184
335
|
console.log(` ${verified ? render.icons.ok : render.icons.warn} ${headline}${status.correctShape ? "" : " (unexpected shape — was it hand-edited?)"}`);
|
|
@@ -206,6 +357,8 @@ export function register(program) {
|
|
|
206
357
|
console.log(` ${render.icons.warn} ${render.wrap(render.c.dim, "On failure:")} ${failure} — run \`${hookInstallHint(status.harness)}\` to adopt the silent form`);
|
|
207
358
|
}
|
|
208
359
|
renderContinuity();
|
|
360
|
+
renderActionRecall();
|
|
361
|
+
renderCapture();
|
|
209
362
|
console.log("");
|
|
210
363
|
});
|
|
211
364
|
}
|