@tpsdev-ai/flair 0.57.0 → 0.59.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -6
- package/SECURITY.md +4 -1
- package/config.yaml +3 -0
- package/dist/build-info.json +3 -3
- package/dist/cli.js +1726 -376
- package/dist/commands/agent.js +160 -2
- package/dist/commands/doctor.js +177 -27
- package/dist/commands/federation.js +2 -1
- package/dist/commands/hook.js +10 -2
- package/dist/commands/init.js +150 -44
- package/dist/commands/mcp.js +53 -22
- package/dist/commands/memory.js +24 -2
- package/dist/commands/quality.js +26 -18
- package/dist/commands/service.js +137 -22
- package/dist/commands/status.js +114 -3
- package/dist/commands/upgrade.js +204 -84
- package/dist/doctor-client.js +50 -4
- package/dist/federation/scheduler.js +253 -4
- package/dist/install/clients.js +89 -23
- package/dist/install/global-bin-path.js +26 -6
- package/dist/lib/atomic-write.js +256 -0
- package/dist/lib/daemon-liveness.js +103 -0
- package/dist/lib/doctor-run.js +72 -0
- package/dist/lib/embed-gpu-doctor.js +49 -26
- package/dist/lib/federation-memory-attributes.js +15 -0
- package/dist/lib/flair-agent-role.js +116 -0
- package/dist/lib/init-admin-pass.js +4 -2
- package/dist/lib/init-listener-environ.js +38 -0
- package/dist/lib/init-occupied-listener.js +165 -0
- package/dist/lib/launchd-domain-preflight.js +448 -0
- package/dist/lib/launchd-management.js +179 -8
- package/dist/lib/launchd-repair.js +95 -0
- package/dist/lib/mcp-enable.js +667 -72
- package/dist/lib/memory-attributes.js +77 -0
- package/dist/lib/node-alias-path.js +95 -0
- package/dist/lib/npm-registry.js +119 -6
- package/dist/lib/owned-pins.js +20 -6
- package/dist/lib/process-start-time.js +32 -0
- package/dist/lib/service-repoint-apply.js +267 -0
- package/dist/lib/service-repoint.js +575 -0
- package/dist/lib/toml-string-array.js +104 -0
- package/dist/lib/tree-divergence.js +716 -0
- package/dist/lib/upgrade-plain-tree.js +18 -8
- package/dist/lib/upgrade-prior-liveness.js +69 -0
- package/dist/lib/upgrade-rollback.js +116 -0
- package/dist/rem/runner.js +11 -0
- package/dist/resources/Agent.js +54 -21
- package/dist/resources/AgentSeed.js +44 -1
- package/dist/resources/Federation.js +84 -54
- package/dist/resources/Memory.js +567 -72
- package/dist/resources/MemoryArchive.js +9 -0
- package/dist/resources/MemoryBootstrap.js +125 -29
- package/dist/resources/MemoryFeed.js +204 -3
- package/dist/resources/MemoryHostSource.js +90 -0
- package/dist/resources/MemoryMaintenance.js +121 -32
- package/dist/resources/MemoryReflect.js +4 -1
- package/dist/resources/MemoryReindex.js +7 -4
- package/dist/resources/MemoryUsage.js +53 -3
- package/dist/resources/OrgSkillAssignment.js +209 -0
- package/dist/resources/Presence.js +18 -10
- package/dist/resources/RecordUsage.js +30 -40
- package/dist/resources/Relationship.js +167 -78
- package/dist/resources/SemanticSearch.js +19 -6
- package/dist/resources/Soul.js +31 -19
- package/dist/resources/XAA.js +47 -14
- package/dist/resources/agent-auth.js +16 -10
- package/dist/resources/agent-status-guard.js +63 -0
- package/dist/resources/auth-middleware.js +137 -49
- package/dist/resources/auto-promote-lib.js +4 -4
- package/dist/resources/bm25-index-service.js +246 -32
- package/dist/resources/bm25-status.js +132 -0
- package/dist/resources/ed25519-auth.js +11 -54
- package/dist/resources/embed-gpu.js +262 -47
- package/dist/resources/embeddings-boot.js +52 -17
- package/dist/resources/federation-classify.js +34 -0
- package/dist/resources/federation-crypto.js +65 -19
- package/dist/resources/flair-agent-role-boot.js +26 -0
- package/dist/resources/health.js +67 -16
- package/dist/resources/host-pointer/registry.js +35 -0
- package/dist/resources/host-pointer-adapter.js +15 -0
- package/dist/resources/host-source-visibility.js +167 -0
- package/dist/resources/host-source.js +151 -0
- package/dist/resources/instance-identity.js +3 -2
- package/dist/resources/key-lock.js +31 -0
- package/dist/resources/mcp-handler.js +147 -51
- package/dist/resources/mcp-oauth.js +3 -6
- package/dist/resources/mcp-tools.js +47 -25
- package/dist/resources/memory-consolidate-lib.js +3 -1
- package/dist/resources/memory-declared-attributes.js +103 -0
- package/dist/resources/memory-feed-lib.js +5 -1
- package/dist/resources/memory-host-source.js +163 -0
- package/dist/resources/migrations/synthetic-test-migration.js +4 -1
- package/dist/resources/migrations/visibility-backfill.js +4 -1
- package/dist/resources/multi-worker-guard.js +121 -0
- package/dist/resources/oauth-discovery.js +1 -0
- package/dist/resources/oauth-wellknown.js +8 -4
- package/dist/resources/originator-instance.js +235 -0
- package/dist/resources/promotion-stamp.js +2 -0
- package/dist/resources/provenance.js +111 -11
- package/dist/resources/record-owner-guard.js +19 -0
- package/dist/resources/record-type-kit.js +9 -12
- package/dist/resources/record-types.js +22 -6
- package/dist/resources/relay-ops.js +28 -3
- package/dist/resources/replay-store.js +336 -0
- package/dist/resources/request-transaction.js +78 -0
- package/dist/resources/search-readiness.js +19 -21
- package/dist/resources/semantic-retrieval-core.js +5 -1
- package/dist/resources/skill-manifest.js +181 -0
- package/dist/resources/skill-provenance.js +15 -10
- package/dist/resources/table-patch-policy.js +109 -0
- package/dist/resources/table-patches.js +17 -0
- package/dist/resources/table-post-policy.js +138 -0
- package/dist/resources/table-posts.js +22 -0
- package/dist/resources/table-subscription-policy.js +135 -0
- package/dist/resources/table-subscriptions.js +19 -0
- package/dist/resources/tool-descriptors/index.js +15 -15
- package/dist/resources/trust-block.js +10 -3
- package/dist/resources/usage-recording.js +169 -41
- package/dist/src/lib/flair-agent-role.js +116 -0
- package/dist/src/lib/memory-attributes.js +77 -0
- package/docs/access-control.md +667 -0
- package/docs/api-reference.md +85 -17
- package/docs/auth.md +4 -0
- package/docs/claude-code.md +132 -0
- package/docs/deepseek-harness.md +1 -1
- package/docs/deployment.md +1 -1
- package/docs/federation.md +1 -1
- package/docs/integrations.md +6 -6
- package/docs/mcp-clients.md +16 -24
- package/docs/notes/mcp-oauth-model2.md +15 -1
- package/docs/quickstart.md +5 -0
- package/docs/releasing.md +152 -20
- package/docs/supply-chain-policy.md +10 -5
- package/docs/troubleshooting.md +11 -0
- package/docs/upgrade.md +187 -61
- package/package.json +10 -5
- package/schemas/agent.graphql +9 -6
- package/schemas/federation.graphql +2 -11
- package/schemas/memory.graphql +137 -17
- package/schemas/oauth.graphql +8 -4
- package/schemas/replay.graphql +18 -0
- package/templates/launchd/start-flair-with-admin-pass.sh +95 -0
- package/dist/resources/federation-nonce-store.js +0 -195
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Resource, databases, server } from "harper";
|
|
2
|
-
import { randomBytes } from "node:crypto";
|
|
2
|
+
import { randomBytes, randomUUID } from "node:crypto";
|
|
3
3
|
import nacl from "tweetnacl";
|
|
4
4
|
import { allowAdmin } from "./agent-auth.js";
|
|
5
5
|
import { canonicalize, signBody, verifyBodySignature, signBodyFresh, verifyBodySignatureFresh, generateNonce, } from "./federation-crypto.js";
|
|
@@ -9,21 +9,29 @@ import { readAllInstanceRows } from "./instance-identity-rows.js";
|
|
|
9
9
|
import { findOrCreateInstance } from "./instance-create-lock.js";
|
|
10
10
|
import { withDetachedTxnAsync } from "./table-helpers.js";
|
|
11
11
|
import { isSkillWrite } from "./skill-write.js";
|
|
12
|
+
import { stripInboundMemoryRow, stripServerStampedFields } from "./memory-declared-attributes.js";
|
|
12
13
|
import { noteWriteStamp } from "./embedding-space-guard.js";
|
|
13
14
|
import { initFederationCleanup } from "./federation-cleanup.js";
|
|
14
|
-
import {
|
|
15
|
-
import { classifyRecord, reconstructRecordVerifyBody, checkPrincipalEntitlement, } from "./federation-classify.js";
|
|
16
|
-
export { classifyRecord, reconstructRecordVerifyBody, checkPrincipalEntitlement, recordSignatureVersion, PRINCIPAL_OWNING_TABLES, FEDERATION_TABLE_POLICY, FEDERATION_SYNC_TABLES, } from "./federation-classify.js";
|
|
17
|
-
//
|
|
18
|
-
//
|
|
19
|
-
//
|
|
20
|
-
//
|
|
21
|
-
//
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
15
|
+
import { verifyFederationRequestBody } from "./replay-store.js";
|
|
16
|
+
import { classifyRecord, reconstructRecordVerifyBody, checkPrincipalEntitlement, inboundChangesExistingPrincipalStatus, } from "./federation-classify.js";
|
|
17
|
+
export { classifyRecord, reconstructRecordVerifyBody, checkPrincipalEntitlement, inboundChangesExistingPrincipalStatus, recordSignatureVersion, PRINCIPAL_OWNING_TABLES, FEDERATION_TABLE_POLICY, FEDERATION_SYNC_TABLES, } from "./federation-classify.js";
|
|
18
|
+
// Federation anti-replay: FederationPair and FederationSync both verify through
|
|
19
|
+
// verifyFederationRequestBody (resources/replay-store.ts), which claims each
|
|
20
|
+
// body nonce ONCE in the instance-wide `ReplayNonce` table after the signature
|
|
21
|
+
// has verified (flair#2061). Nonces are globally unique (signBodyFresh generates
|
|
22
|
+
// a 128-bit random nonce per request), so the nonce alone is the key.
|
|
23
|
+
/** The response for a body whose signature, freshness or nonce check refused. */
|
|
24
|
+
function federationVerifyRefusal(reason) {
|
|
25
|
+
if (reason === "replay_store_unavailable") {
|
|
26
|
+
return new Response(JSON.stringify({
|
|
27
|
+
error: "replay_store_unavailable",
|
|
28
|
+
detail: "This instance cannot record request nonces right now, so it refuses signed federation requests. The server log names the cause.",
|
|
29
|
+
}), { status: 503, headers: { "content-type": "application/json" } });
|
|
30
|
+
}
|
|
31
|
+
return new Response(JSON.stringify({ error: `invalid signature — ${reason}` }), {
|
|
32
|
+
status: 401, headers: { "content-type": "application/json" },
|
|
33
|
+
});
|
|
34
|
+
}
|
|
27
35
|
// Re-export for consumers that import from Federation.ts
|
|
28
36
|
export { canonicalize, signBody, verifyBodySignature, signBodyFresh, verifyBodySignatureFresh, generateNonce };
|
|
29
37
|
// ─── Per-record signature enforcement mode (federation-edge-hardening slice 3b) ──
|
|
@@ -64,8 +72,8 @@ export function payloadIdMismatch(record) {
|
|
|
64
72
|
return !record.data || record.data.id !== record.id;
|
|
65
73
|
}
|
|
66
74
|
/**
|
|
67
|
-
*
|
|
68
|
-
*
|
|
75
|
+
* Record-level Last-Write-Wins merge.
|
|
76
|
+
* Incoming fields are applied when the remote record's updatedAt is later.
|
|
69
77
|
* Records with no local counterpart are accepted directly.
|
|
70
78
|
*/
|
|
71
79
|
export function mergeRecord(local, remote) {
|
|
@@ -344,22 +352,16 @@ export class FederationPair extends Resource {
|
|
|
344
352
|
status: 401, headers: { "content-type": "application/json" },
|
|
345
353
|
});
|
|
346
354
|
}
|
|
347
|
-
const verifyResult =
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
});
|
|
351
|
-
if (!verifyResult.ok) {
|
|
352
|
-
return new Response(JSON.stringify({ error: `invalid signature — ${verifyResult.reason}` }), {
|
|
353
|
-
status: 401, headers: { "content-type": "application/json" },
|
|
354
|
-
});
|
|
355
|
-
}
|
|
355
|
+
const verifyResult = await verifyFederationRequestBody(data, publicKey);
|
|
356
|
+
if (!verifyResult.ok)
|
|
357
|
+
return federationVerifyRefusal(verifyResult.reason);
|
|
356
358
|
// ── The identity this response hands the peer, decided BEFORE the pairing
|
|
357
359
|
// token is consumed, BEFORE the peer is read and before ANY peer is written
|
|
358
360
|
// (flair#1883 round 3). ──────────────────────────────────────────────────
|
|
359
361
|
//
|
|
360
362
|
// NOT "before anything": the signature check above has already run and
|
|
361
|
-
// RECORDED ITS NONCE (
|
|
362
|
-
//
|
|
363
|
+
// RECORDED ITS NONCE (verifyFederationRequestBody → the ReplayNonce table,
|
|
364
|
+
// see replay-store.ts). That is deliberate anti-replay state, not a
|
|
363
365
|
// pairing effect — but it is written, and the refusal is precise about what
|
|
364
366
|
// it precedes.
|
|
365
367
|
//
|
|
@@ -508,7 +510,7 @@ export class FederationPair extends Resource {
|
|
|
508
510
|
*/
|
|
509
511
|
export class FederationSync extends Resource {
|
|
510
512
|
// Public endpoint by design: spokes have no Harper credentials. Body signature
|
|
511
|
-
// (with timestamp + nonce, via
|
|
513
|
+
// (with timestamp + nonce, via verifyFederationRequestBody) is the auth boundary.
|
|
512
514
|
// Same pattern as FederationPair.
|
|
513
515
|
allowCreate(_user, _record, _context) {
|
|
514
516
|
return true;
|
|
@@ -535,15 +537,9 @@ export class FederationSync extends Resource {
|
|
|
535
537
|
status: 401, headers: { "content-type": "application/json" },
|
|
536
538
|
});
|
|
537
539
|
}
|
|
538
|
-
const verifyResult =
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
});
|
|
542
|
-
if (!verifyResult.ok) {
|
|
543
|
-
return new Response(JSON.stringify({ error: `invalid signature — ${verifyResult.reason}` }), {
|
|
544
|
-
status: 401, headers: { "content-type": "application/json" },
|
|
545
|
-
});
|
|
546
|
-
}
|
|
540
|
+
const verifyResult = await verifyFederationRequestBody(data, peer.publicKey);
|
|
541
|
+
if (!verifyResult.ok)
|
|
542
|
+
return federationVerifyRefusal(verifyResult.reason);
|
|
547
543
|
const startTime = Date.now();
|
|
548
544
|
let merged = 0;
|
|
549
545
|
let skipped = 0;
|
|
@@ -598,7 +594,7 @@ export class FederationSync extends Resource {
|
|
|
598
594
|
// classifyRecord's "merge" verdict above only proves the record is
|
|
599
595
|
// STRUCTURALLY eligible (known table, self-originated OR the sender
|
|
600
596
|
// is a hub, not stale, not a no-op) — that hub bypass trusts the
|
|
601
|
-
// BATCH-level signature (
|
|
597
|
+
// BATCH-level signature (verifyFederationRequestBody above, verified
|
|
602
598
|
// against the SENDER's pinned key). It does NOT prove the record's
|
|
603
599
|
// *claimed* originator actually produced it — a hub relaying on
|
|
604
600
|
// behalf of many spokes could otherwise forge a record under any
|
|
@@ -655,7 +651,28 @@ export class FederationSync extends Resource {
|
|
|
655
651
|
recordSkip(principalSkip);
|
|
656
652
|
continue;
|
|
657
653
|
}
|
|
654
|
+
// ── flair#2108: skip an inbound Agent record whose `status` differs
|
|
655
|
+
// from an existing local principal's stored value, whether or not it
|
|
656
|
+
// would win the last-write-wins merge below. The federation path
|
|
657
|
+
// carries no verified administrator authority for that principal (the
|
|
658
|
+
// batch is signed, and a record signature may also be present; neither
|
|
659
|
+
// is an admin claim). The whole record is skipped rather than merged
|
|
660
|
+
// with a pinned status, so the merge stays atomic and the other fields
|
|
661
|
+
// in the record do not land either.
|
|
662
|
+
if (inboundChangesExistingPrincipalStatus(record, local)) {
|
|
663
|
+
recordSkip("agent_status_not_federated");
|
|
664
|
+
continue;
|
|
665
|
+
}
|
|
658
666
|
const mergedData = mergeRecord(local, record);
|
|
667
|
+
// ── flair#1940 A1'' item 8: the SAME declared-attribute whitelist the
|
|
668
|
+
// writers apply. A dirty pushed row (a legacy direct-insert, or a raw
|
|
669
|
+
// writer that slipped a pointer field past the writers) must not carry
|
|
670
|
+
// a pointer attribute onto the merged Memory row here either. The named
|
|
671
|
+
// federation bookkeeping fields (_originatorInstanceId, _syncedFrom,
|
|
672
|
+
// _syncedAt, meta, kind) are on the whitelist and survive.
|
|
673
|
+
if (record.table === "Memory") {
|
|
674
|
+
stripInboundMemoryRow(mergedData);
|
|
675
|
+
}
|
|
659
676
|
// ── flair#1542: skills are not federated ──
|
|
660
677
|
// A skill-tagged Memory is a local, gated artifact (SkillScan + forced
|
|
661
678
|
// durability on the write path). Merging a pushed skill-tagged row RAW
|
|
@@ -692,6 +709,33 @@ export class FederationSync extends Resource {
|
|
|
692
709
|
mergedData._originatorInstanceId = decision.originator;
|
|
693
710
|
mergedData._syncedFrom = instanceId;
|
|
694
711
|
mergedData._syncedAt = new Date().toISOString();
|
|
712
|
+
// Re-assert the whitelist AFTER stamping the bookkeeping fields, so a
|
|
713
|
+
// dirty inbound row cannot smuggle a pointer field through this merge
|
|
714
|
+
// even if it also carried one of the allowed keys.
|
|
715
|
+
if (record.table === "Memory") {
|
|
716
|
+
stripInboundMemoryRow(mergedData);
|
|
717
|
+
// A1-iv items 1/3: a federated receive is a LOCAL incarnation — the
|
|
718
|
+
// token is OURS, never the peer's. Drop a peer-supplied server-stamped
|
|
719
|
+
// field, then PRESERVE the local row's token on a merge (a new row
|
|
720
|
+
// gets a locally-generated one).
|
|
721
|
+
//
|
|
722
|
+
// Round 22: `provenance` is NOT a local incarnation stamp — it is the
|
|
723
|
+
// ORIGINATOR's signed stamp and must survive the merge. Capture the
|
|
724
|
+
// value mergeRecord SELECTED (the inbound data for a new row; the
|
|
725
|
+
// merge's LWW choice for an update — NOT always local.provenance)
|
|
726
|
+
// before stripping, then restore it in the same per-record apply.
|
|
727
|
+
// Pinned by test/unit-isolated/federation-merge-provenance.test.ts —
|
|
728
|
+
// RED if this capture/restore is removed.
|
|
729
|
+
const mergedProvenance = mergedData.provenance;
|
|
730
|
+
stripServerStampedFields(mergedData);
|
|
731
|
+
if (typeof mergedProvenance === "string") {
|
|
732
|
+
mergedData.provenance = mergedProvenance;
|
|
733
|
+
}
|
|
734
|
+
mergedData.instanceToken =
|
|
735
|
+
local && typeof local.instanceToken === "string" && local.instanceToken.length > 0
|
|
736
|
+
? local.instanceToken
|
|
737
|
+
: randomUUID();
|
|
738
|
+
}
|
|
695
739
|
await table.put(mergedData);
|
|
696
740
|
// embedding-space-guard slice 1: a federation-merged Memory can carry a
|
|
697
741
|
// FOREIGN embeddingModel (LWW remote-win) — trip the guard's latch so
|
|
@@ -814,21 +858,7 @@ if (typeof setTimeout !== "undefined") {
|
|
|
814
858
|
// Swallow — in test/resource-env the Harper databases may not be bound.
|
|
815
859
|
// In production, initFederationCleanup handles its own error paths.
|
|
816
860
|
});
|
|
817
|
-
// Nonce
|
|
818
|
-
//
|
|
819
|
-
// Runs on the same deferred tick as the cleanup sweep above; there is a
|
|
820
|
-
// narrow window between process start and hydration completing during
|
|
821
|
-
// which a pre-restart nonce isn't yet visible — an accepted tradeoff
|
|
822
|
-
// consistent with this file's existing deferred-init pattern (see the
|
|
823
|
-
// cleanup sweep comment above).
|
|
824
|
-
federationNonceStore.hydrate().catch((err) => {
|
|
825
|
-
// Swallow — in test/resource-env the Harper databases may not be bound.
|
|
826
|
-
});
|
|
827
|
-
// Nonce table eviction sweep — runs on every instance (both hub and
|
|
828
|
-
// spoke can be the receiving/verifying side of a signed federation
|
|
829
|
-
// request), unlike PairingToken cleanup which is hub-only.
|
|
830
|
-
initNonceStoreCleanup().catch((err) => {
|
|
831
|
-
// Swallow — in test/resource-env the Harper databases may not be bound.
|
|
832
|
-
});
|
|
861
|
+
// Nonce eviction is the ReplayNonce table's own expiration (one scan per
|
|
862
|
+
// instance, on Harper's last worker) — no sweep is started here.
|
|
833
863
|
}, 0);
|
|
834
864
|
}
|