@tpsdev-ai/flair 0.57.0 → 0.58.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.
Files changed (122) hide show
  1. package/README.md +4 -4
  2. package/SECURITY.md +4 -1
  3. package/dist/build-info.json +3 -3
  4. package/dist/cli.js +1685 -279
  5. package/dist/commands/doctor.js +162 -4
  6. package/dist/commands/federation.js +2 -1
  7. package/dist/commands/hook.js +10 -2
  8. package/dist/commands/init.js +150 -44
  9. package/dist/commands/memory.js +24 -2
  10. package/dist/commands/quality.js +26 -18
  11. package/dist/commands/service.js +137 -22
  12. package/dist/commands/status.js +114 -3
  13. package/dist/commands/upgrade.js +204 -84
  14. package/dist/doctor-client.js +50 -4
  15. package/dist/federation/scheduler.js +253 -4
  16. package/dist/install/clients.js +89 -23
  17. package/dist/install/global-bin-path.js +26 -6
  18. package/dist/lib/atomic-write.js +256 -0
  19. package/dist/lib/daemon-liveness.js +61 -0
  20. package/dist/lib/doctor-run.js +5 -0
  21. package/dist/lib/embed-gpu-doctor.js +49 -26
  22. package/dist/lib/federation-memory-attributes.js +15 -0
  23. package/dist/lib/init-admin-pass.js +4 -2
  24. package/dist/lib/init-listener-environ.js +38 -0
  25. package/dist/lib/init-occupied-listener.js +165 -0
  26. package/dist/lib/launchd-domain-preflight.js +448 -0
  27. package/dist/lib/launchd-management.js +176 -6
  28. package/dist/lib/launchd-repair.js +95 -0
  29. package/dist/lib/memory-attributes.js +77 -0
  30. package/dist/lib/node-alias-path.js +95 -0
  31. package/dist/lib/npm-registry.js +119 -6
  32. package/dist/lib/owned-pins.js +20 -6
  33. package/dist/lib/service-repoint-apply.js +267 -0
  34. package/dist/lib/service-repoint.js +575 -0
  35. package/dist/lib/toml-string-array.js +104 -0
  36. package/dist/lib/tree-divergence.js +716 -0
  37. package/dist/lib/upgrade-plain-tree.js +18 -8
  38. package/dist/lib/upgrade-prior-liveness.js +69 -0
  39. package/dist/lib/upgrade-rollback.js +116 -0
  40. package/dist/rem/runner.js +11 -0
  41. package/dist/resources/Agent.js +27 -14
  42. package/dist/resources/AgentSeed.js +35 -1
  43. package/dist/resources/Federation.js +70 -52
  44. package/dist/resources/Memory.js +567 -72
  45. package/dist/resources/MemoryArchive.js +9 -0
  46. package/dist/resources/MemoryBootstrap.js +4 -0
  47. package/dist/resources/MemoryFeed.js +204 -3
  48. package/dist/resources/MemoryHostSource.js +90 -0
  49. package/dist/resources/MemoryMaintenance.js +121 -32
  50. package/dist/resources/MemoryReflect.js +4 -1
  51. package/dist/resources/MemoryReindex.js +7 -4
  52. package/dist/resources/MemoryUsage.js +53 -3
  53. package/dist/resources/Presence.js +18 -10
  54. package/dist/resources/RecordUsage.js +30 -40
  55. package/dist/resources/Relationship.js +167 -78
  56. package/dist/resources/SemanticSearch.js +19 -6
  57. package/dist/resources/Soul.js +31 -19
  58. package/dist/resources/XAA.js +7 -3
  59. package/dist/resources/agent-auth.js +16 -10
  60. package/dist/resources/auth-middleware.js +135 -48
  61. package/dist/resources/auto-promote-lib.js +4 -4
  62. package/dist/resources/bm25-index-service.js +246 -32
  63. package/dist/resources/bm25-status.js +132 -0
  64. package/dist/resources/ed25519-auth.js +11 -54
  65. package/dist/resources/embed-gpu.js +262 -47
  66. package/dist/resources/embeddings-boot.js +52 -17
  67. package/dist/resources/federation-classify.js +12 -0
  68. package/dist/resources/federation-crypto.js +65 -19
  69. package/dist/resources/health.js +57 -14
  70. package/dist/resources/host-pointer/registry.js +35 -0
  71. package/dist/resources/host-pointer-adapter.js +15 -0
  72. package/dist/resources/host-source-visibility.js +167 -0
  73. package/dist/resources/host-source.js +151 -0
  74. package/dist/resources/instance-identity.js +3 -2
  75. package/dist/resources/mcp-handler.js +147 -51
  76. package/dist/resources/mcp-tools.js +25 -21
  77. package/dist/resources/memory-consolidate-lib.js +3 -1
  78. package/dist/resources/memory-declared-attributes.js +103 -0
  79. package/dist/resources/memory-feed-lib.js +5 -1
  80. package/dist/resources/memory-host-source.js +163 -0
  81. package/dist/resources/migrations/synthetic-test-migration.js +4 -1
  82. package/dist/resources/migrations/visibility-backfill.js +4 -1
  83. package/dist/resources/originator-instance.js +235 -0
  84. package/dist/resources/promotion-stamp.js +2 -0
  85. package/dist/resources/provenance.js +111 -11
  86. package/dist/resources/record-owner-guard.js +19 -0
  87. package/dist/resources/record-type-kit.js +9 -12
  88. package/dist/resources/record-types.js +6 -6
  89. package/dist/resources/relay-ops.js +28 -3
  90. package/dist/resources/replay-store.js +289 -0
  91. package/dist/resources/request-transaction.js +78 -0
  92. package/dist/resources/search-readiness.js +19 -21
  93. package/dist/resources/semantic-retrieval-core.js +5 -1
  94. package/dist/resources/table-patch-policy.js +109 -0
  95. package/dist/resources/table-patches.js +17 -0
  96. package/dist/resources/table-post-policy.js +138 -0
  97. package/dist/resources/table-posts.js +22 -0
  98. package/dist/resources/table-subscription-policy.js +135 -0
  99. package/dist/resources/table-subscriptions.js +19 -0
  100. package/dist/resources/tool-descriptors/index.js +15 -15
  101. package/dist/resources/trust-block.js +10 -3
  102. package/dist/resources/usage-recording.js +169 -41
  103. package/dist/src/lib/memory-attributes.js +77 -0
  104. package/docs/api-reference.md +79 -15
  105. package/docs/claude-code.md +132 -0
  106. package/docs/deployment.md +1 -1
  107. package/docs/federation.md +1 -1
  108. package/docs/integrations.md +5 -5
  109. package/docs/mcp-clients.md +11 -21
  110. package/docs/notes/mcp-oauth-model2.md +15 -1
  111. package/docs/quickstart.md +5 -0
  112. package/docs/releasing.md +134 -2
  113. package/docs/supply-chain-policy.md +10 -5
  114. package/docs/troubleshooting.md +11 -0
  115. package/docs/upgrade.md +187 -61
  116. package/package.json +9 -5
  117. package/schemas/agent.graphql +9 -6
  118. package/schemas/federation.graphql +2 -11
  119. package/schemas/memory.graphql +106 -17
  120. package/schemas/replay.graphql +18 -0
  121. package/templates/launchd/start-flair-with-admin-pass.sh +22 -0
  122. package/dist/resources/federation-nonce-store.js +0 -195
@@ -1,195 +0,0 @@
1
- /**
2
- * federation-nonce-store.ts — persistent backing for the federation
3
- * anti-replay NonceStore (federation-edge-hardening slice 4).
4
- *
5
- * The gap: `federationNonceStore` in Federation.ts was a bare in-memory Map
6
- * (`createNonceStore()` in federation-crypto.ts). On process restart it's
7
- * wiped, so a signed federation request captured within its ±30s freshness
8
- * window (verifyBodySignatureFresh) could be replayed once, post-restart.
9
- * This module closes that window by backing the SAME `NonceStore` interface
10
- * with the `Nonce` Harper table, while keeping every method synchronous —
11
- * `verifyBodySignatureFresh` and its 2 call sites in Federation.ts are
12
- * UNCHANGED (they still call `.has()` / `.set()` / `.evict()` with no
13
- * `await`), so the entire existing federation-crypto-replay test suite
14
- * (all synchronous assertions) keeps working unmodified.
15
- *
16
- * How the sync interface stays sync against an inherently-async DB API:
17
- * - `has()` / `evict()` read/mutate an in-memory Map (via the existing
18
- * `createNonceStore()`), exactly as before — no DB round trip.
19
- * - `set()` updates that same in-memory Map synchronously (so replay
20
- * detection within THIS process's lifetime is unchanged), and fires an
21
- * async `Nonce.put()` in the background (not awaited) to persist the
22
- * nonce for the NEXT restart. A failed/slow persist never blocks or
23
- * fails request handling — see the perf/durability tradeoff note below.
24
- * - `hydrate()` is the new piece: an explicit async step that loads
25
- * not-yet-expired rows from the `Nonce` table into the in-memory Map.
26
- * Call it once, on startup, BEFORE the store starts guarding live
27
- * traffic — that's what makes a nonce recorded by the PREVIOUS process
28
- * visible to a FRESH store instance after a restart (the whole point).
29
- *
30
- * Known tradeoff (flagged, not fixed here — would require making NonceStore
31
- * async, which ripples into ~40 synchronous call sites across
32
- * federation-crypto-replay.test.ts + federation-sync-e2e.test.ts):
33
- * `set()`'s persistence is fire-and-forget. A crash in the narrow gap
34
- * between "response sent" and "async put() resolved" can still lose that
35
- * one nonce — narrowing the replay window to that gap, not eliminating it
36
- * outright. Defense-in-depth: the ±30s freshness check + signature
37
- * verification are still the primary guards; this closes the common case
38
- * (graceful restart / redeploy), not the crash-mid-request edge case.
39
- */
40
- import { createNonceStore } from "./federation-crypto.js";
41
- /** 2x the standard 30s freshness window — matches the in-memory `evict()` cutoff already used by verifyBodySignatureFresh. */
42
- export const DEFAULT_RETENTION_MS = 60_000;
43
- async function resolveDb(opts, cache) {
44
- if (opts.db)
45
- return opts.db;
46
- if (!cache.db) {
47
- cache.db = import("harper").then((h) => h.databases);
48
- }
49
- return cache.db;
50
- }
51
- /**
52
- * Create a `NonceStore` backed by the `Nonce` Harper table.
53
- *
54
- * Wraps the existing in-memory `createNonceStore()` (unchanged behavior for
55
- * `has()`/`set()`/`evict()` within this process) and adds:
56
- * - background persistence of newly-set nonces (`set()`)
57
- * - an explicit `hydrate()` to reload previously-persisted nonces (used
58
- * at startup, and by tests simulating a restart with a fresh instance)
59
- */
60
- export function createPersistentNonceStore(opts = {}) {
61
- const memory = createNonceStore();
62
- const dbCache = {};
63
- return {
64
- has(key) {
65
- return memory.has(key);
66
- },
67
- evict(olderThan) {
68
- memory.evict(olderThan);
69
- },
70
- set(key, value) {
71
- memory.set(key, value);
72
- // Fire-and-forget persistence — see module header for the tradeoff.
73
- void (async () => {
74
- try {
75
- const db = await resolveDb(opts, dbCache);
76
- await db.flair.Nonce.put({ id: key, seenAt: value });
77
- }
78
- catch (err) {
79
- console.error("[federation-nonce-store] failed to persist nonce (in-memory record already made — this process's replay guard is unaffected):", err?.message ?? err);
80
- }
81
- })();
82
- },
83
- async hydrate(hydrateOpts) {
84
- const retentionMs = hydrateOpts?.retentionMs ?? DEFAULT_RETENTION_MS;
85
- const now = hydrateOpts?.now ?? Date.now();
86
- const cutoff = now - retentionMs;
87
- try {
88
- const db = await resolveDb(opts, dbCache);
89
- for await (const row of db.flair.Nonce.search()) {
90
- if (row?.id != null && typeof row.seenAt === "number" && row.seenAt >= cutoff) {
91
- memory.set(String(row.id), row.seenAt);
92
- }
93
- }
94
- }
95
- catch (err) {
96
- console.error("[federation-nonce-store] failed to hydrate from Nonce table (starting with an empty replay guard):", err?.message ?? err);
97
- }
98
- },
99
- };
100
- }
101
- // ─── Eviction sweep — periodic Nonce table hygiene ─────────────────────────
102
- //
103
- // Mirrors federation-cleanup.ts's 5-min setInterval hub-pattern. Decoupled
104
- // from the in-memory `evict()` above (which runs per-request and only trims
105
- // the local Map): this sweep deletes rows from the `Nonce` TABLE itself so
106
- // it doesn't grow unbounded across restarts. No native TTL in this repo —
107
- // same app-managed-sweep idiom as PairingToken cleanup.
108
- //
109
- // Runs on every instance (hub AND spoke) — unlike PairingToken cleanup
110
- // (hub-only, since only hubs issue pairing tokens), both FederationPair and
111
- // FederationSync can be the RECEIVING side of a signed request on either
112
- // role, so both roles accumulate rows in the Nonce table and both need the
113
- // sweep.
114
- const NONCE_CLEANUP_INTERVAL_MS = 300_000; // 5 minutes
115
- let nonceCleanupTimer = null;
116
- /**
117
- * Core sweep logic — exposed for unit testing. Deletes `Nonce` rows with
118
- * `seenAt` older than `retentionMs` (default: 2x the 30s freshness window).
119
- */
120
- export async function runNonceCleanupTick(opts = {}) {
121
- let db;
122
- if (opts.db) {
123
- db = opts.db;
124
- }
125
- else {
126
- const harper = await import("harper");
127
- db = harper.databases;
128
- }
129
- const retentionMs = opts.retentionMs ?? DEFAULT_RETENTION_MS;
130
- const now = opts.now ?? Date.now();
131
- const cutoff = now - retentionMs;
132
- const toDelete = [];
133
- let scanned = 0;
134
- try {
135
- for await (const row of db.flair.Nonce.search()) {
136
- scanned++;
137
- if (typeof row?.seenAt === "number" && row.seenAt < cutoff) {
138
- toDelete.push(row.id);
139
- }
140
- }
141
- }
142
- catch (err) {
143
- console.error("[federation-nonce-store] failed to query Nonce records:", err?.message ?? err);
144
- return { deleted: 0, scanned: 0 };
145
- }
146
- let deleted = 0;
147
- for (const id of toDelete) {
148
- try {
149
- await db.flair.Nonce.delete(id);
150
- deleted++;
151
- }
152
- catch (err) {
153
- console.error("[federation-nonce-store] failed to delete expired nonce:", err?.message ?? err);
154
- }
155
- }
156
- return { deleted, scanned };
157
- }
158
- /**
159
- * Initialise the periodic Nonce-table eviction sweep (5-min cadence).
160
- *
161
- * In test environments, callers pass a mock `db` via `opts` so this module
162
- * never imports harper at the top level (mirrors
163
- * federation-cleanup.ts's `initFederationCleanup`).
164
- */
165
- export async function initNonceStoreCleanup(opts) {
166
- const immediate = opts?.immediateTick ?? true;
167
- let db;
168
- if (opts?.db) {
169
- db = opts.db;
170
- }
171
- else {
172
- try {
173
- const harper = await import("harper");
174
- db = harper.databases;
175
- }
176
- catch (err) {
177
- console.error("[federation-nonce-store] failed to load harper:", err?.message ?? err);
178
- return;
179
- }
180
- }
181
- const retentionMs = opts?.retentionMs ?? DEFAULT_RETENTION_MS;
182
- console.log("[federation-nonce-store] starting nonce eviction sweep (5-min cadence)");
183
- if (nonceCleanupTimer)
184
- clearInterval(nonceCleanupTimer);
185
- nonceCleanupTimer = setInterval(() => {
186
- runNonceCleanupTick({ db, retentionMs }).catch((err) => {
187
- console.error("[federation-nonce-store] cleanup tick error:", err?.message ?? err);
188
- });
189
- }, NONCE_CLEANUP_INTERVAL_MS);
190
- if (immediate) {
191
- runNonceCleanupTick({ db, retentionMs }).catch((err) => {
192
- console.error("[federation-nonce-store] initial cleanup tick error:", err?.message ?? err);
193
- });
194
- }
195
- }