@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
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* flair-agent-role.ts — the `flair_agent` Harper role's grant spec, shared by
|
|
3
|
+
* the CLI (`ensureFlairAgentRole`, src/cli.ts) and the server's startup check
|
|
4
|
+
* (resources/flair-agent-role-boot.ts). No Harper imports.
|
|
5
|
+
*/
|
|
6
|
+
// ─── flair_agent role ────────────────────────────────────────────────────────
|
|
7
|
+
//
|
|
8
|
+
// The auth reshape replaces the global gate's "verified agent borrows admin
|
|
9
|
+
// super_user" elevation with a real, least-privilege Harper role. After an
|
|
10
|
+
// agent's Ed25519 signature verifies, resources resolve the request to the
|
|
11
|
+
// shared `flair_agent`-roled user instead of admin. Critically: with no
|
|
12
|
+
// `super_user` and no operations grants, /sql and /graphql become NATIVELY 403
|
|
13
|
+
// for agents (the raw-query block the gate hand-rolled is now enforced by
|
|
14
|
+
// Harper itself).
|
|
15
|
+
// Harper 5.0.21 add_role requires an `attribute_permissions` array on EVERY table
|
|
16
|
+
// grant (empty = no attribute-level restriction, so the table-level CRUD applies);
|
|
17
|
+
// omitting it makes add_role reject the whole spec ("Missing 'attribute_permissions'
|
|
18
|
+
// array"). Validated live against a spawned Harper. This helper guarantees the
|
|
19
|
+
// array is never forgotten. Also: `cluster_user` is NOT a valid top-level key —
|
|
20
|
+
// Harper reads unrecognized top-level keys as database names ("database
|
|
21
|
+
// 'cluster_user' does not exist"); only super_user / structure_user are recognized.
|
|
22
|
+
const grant = (read, insert, update, del) => ({ read, insert, update, delete: del, attribute_permissions: [] });
|
|
23
|
+
/** Canonical permission spec for flair_agent (least-privilege; real @table names). */
|
|
24
|
+
export const FLAIR_AGENT_PERMISSION = {
|
|
25
|
+
super_user: false,
|
|
26
|
+
structure_user: false,
|
|
27
|
+
flair: {
|
|
28
|
+
tables: {
|
|
29
|
+
// Core agent-owned data — CRUD envelope.
|
|
30
|
+
Memory: grant(true, true, true, true),
|
|
31
|
+
MemoryCandidate: grant(true, true, true, true),
|
|
32
|
+
MemoryGrant: grant(true, true, true, true),
|
|
33
|
+
// Asset (images-in-Flair slice 1). Harper authorizes BEFORE Asset.post
|
|
34
|
+
// runs, so a de-elevated flair_agent needs the table grant or signed
|
|
35
|
+
// POST /Asset 403s as AccessViolation (Kern P0). CRUD envelope;
|
|
36
|
+
// owner-only + write-time size/MIME gates live in resources/Asset.ts.
|
|
37
|
+
Asset: grant(true, true, true, true),
|
|
38
|
+
Soul: grant(true, true, true, false),
|
|
39
|
+
OrgEvent: grant(true, true, true, true),
|
|
40
|
+
WorkspaceState: grant(true, true, true, true),
|
|
41
|
+
Relationship: grant(true, true, true, true),
|
|
42
|
+
// Flair Relay S1 (flair#1521). Harper authorizes BEFORE the resource
|
|
43
|
+
// methods run, so a de-elevated flair_agent needs the table grant OR it
|
|
44
|
+
// 403s on POST /Message before relaySend is reached (Kern P0-2). read =
|
|
45
|
+
// the party-scoped collection (Message.search); insert = send via post().
|
|
46
|
+
// update = FALSE (least privilege, Kern P0 blocker): the ack's write goes
|
|
47
|
+
// through the IN-PROCESS static accessor (relayConsume → deps.messages.put),
|
|
48
|
+
// which bypasses role gates entirely — the same raw-put seam Federation.ts
|
|
49
|
+
// relies on — so update:true is NOT needed for any legitimate path. Leaving
|
|
50
|
+
// it granted let PATCH /Message/<id> reach Table's update verb, whose
|
|
51
|
+
// authorize step consults update:true and PASSES for any de-elevated agent,
|
|
52
|
+
// bypassing Message.put()'s FORBIDDEN guard AND relayConsume's recipient-only
|
|
53
|
+
// check (Message has no patch() at the platform level → TableResource.patch
|
|
54
|
+
// runs update()+save() directly). delete = false: direct deletes are
|
|
55
|
+
// admin/internal only. Message.patch() also guards the verb in-resource.
|
|
56
|
+
Message: grant(true, true, false, false),
|
|
57
|
+
Integration: grant(true, true, true, true),
|
|
58
|
+
Credential: grant(true, true, true, true),
|
|
59
|
+
Presence: grant(true, true, true, false),
|
|
60
|
+
// MemoryUsage (flair#683): the usage-feedback dedup ledger. Read (own
|
|
61
|
+
// contributions, scoped in resources/MemoryUsage.ts) + insert (a fresh
|
|
62
|
+
// contribution row) only — NO update/delete. This is load-bearing, not
|
|
63
|
+
// just least-privilege tidiness: the dedup rule ("(agent, memory)
|
|
64
|
+
// contributes ≤ 1") is enforced by requiring a NEW ledger row before
|
|
65
|
+
// any usageCount bump; if an agent could delete its own row, it could
|
|
66
|
+
// re-trigger the /RecordUsage endpoint for the same memory indefinitely
|
|
67
|
+
// (create → count → delete → count again → repeat), defeating the cap
|
|
68
|
+
// entirely. See resources/MemoryUsage.ts's module doc.
|
|
69
|
+
MemoryUsage: grant(true, true, false, false),
|
|
70
|
+
// MemoryHitStat (flair#1528): internal search-hit ledger. No agent REST
|
|
71
|
+
// surface (@table without @export). Counts overlay onto Memory reads.
|
|
72
|
+
MemoryHitStat: grant(false, false, false, false),
|
|
73
|
+
// Agent: read for discovery, update own card; creation/removal is admin.
|
|
74
|
+
Agent: grant(true, false, true, false),
|
|
75
|
+
// Read-only reference data.
|
|
76
|
+
Instance: grant(true, false, false, false),
|
|
77
|
+
// flair#2141 S1: org-scope skill assignments. Agents read them; every
|
|
78
|
+
// write is operator/internal only (resources/OrgSkillAssignment.ts), so
|
|
79
|
+
// no write grant. The history table has no direct REST route.
|
|
80
|
+
OrgSkillAssignment: grant(true, false, false, false),
|
|
81
|
+
OrgSkillAssignmentHistory: grant(false, false, false, false),
|
|
82
|
+
// Federation / OAuth / IdP / internal — system + admin only; agents get none.
|
|
83
|
+
Peer: grant(false, false, false, false),
|
|
84
|
+
PairingToken: grant(false, false, false, false),
|
|
85
|
+
SyncLog: grant(false, false, false, false),
|
|
86
|
+
OAuthClient: grant(false, false, false, false),
|
|
87
|
+
OAuthToken: grant(false, false, false, false),
|
|
88
|
+
OAuthAuthCode: grant(false, false, false, false),
|
|
89
|
+
IdpConfig: grant(false, false, false, false),
|
|
90
|
+
IdJagReplay: grant(false, false, false, false),
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
};
|
|
94
|
+
export const FLAIR_AGENT_ROLE_NAME = "flair_agent";
|
|
95
|
+
/**
|
|
96
|
+
* Brings an existing `flair_agent` role to FLAIR_AGENT_PERMISSION (flair#2141
|
|
97
|
+
* S1): "updated" after an `alter_role`, "unchanged" when it already matches,
|
|
98
|
+
* "absent" when the instance has no such role (this never creates it). Throws
|
|
99
|
+
* when the role list cannot be read; nothing is written then.
|
|
100
|
+
*/
|
|
101
|
+
export async function alignFlairAgentRole(op) {
|
|
102
|
+
const roles = await op({ operation: "list_roles" });
|
|
103
|
+
if (!Array.isArray(roles))
|
|
104
|
+
throw new Error("list_roles did not return a list of roles");
|
|
105
|
+
const existing = roles.find((r) => r?.role === FLAIR_AGENT_ROLE_NAME || r?.name === FLAIR_AGENT_ROLE_NAME);
|
|
106
|
+
if (!existing)
|
|
107
|
+
return "absent";
|
|
108
|
+
const permission = existing.permission ?? existing.role?.permission;
|
|
109
|
+
if (JSON.stringify(permission) === JSON.stringify(FLAIR_AGENT_PERMISSION))
|
|
110
|
+
return "unchanged";
|
|
111
|
+
// Harper's alter_role addresses the role by its `id`.
|
|
112
|
+
if (typeof existing.id !== "string" || existing.id.length === 0)
|
|
113
|
+
throw new Error("the flair_agent role has no id");
|
|
114
|
+
await op({ operation: "alter_role", id: existing.id, role: FLAIR_AGENT_ROLE_NAME, permission: FLAIR_AGENT_PERMISSION });
|
|
115
|
+
return "updated";
|
|
116
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/** Shared Memory field contract for resource writers and federation readers.
|
|
2
|
+
* Kept under src so the CLI build can include it within its rootDir; the
|
|
3
|
+
* server build also emits this dependency under dist/src/lib.
|
|
4
|
+
* Pure data: importing this contract never loads Harper.
|
|
5
|
+
*/
|
|
6
|
+
/** Every DECLARED attribute of `type Memory` in schemas/memory.graphql, in
|
|
7
|
+
* schema order. Keep in sync with the schema (the drift test enforces it). */
|
|
8
|
+
export const DECLARED_MEMORY_ATTRIBUTES = Object.freeze([
|
|
9
|
+
"id",
|
|
10
|
+
"agentId",
|
|
11
|
+
"content",
|
|
12
|
+
"contentHash",
|
|
13
|
+
"trigger",
|
|
14
|
+
"visibility",
|
|
15
|
+
"embedding",
|
|
16
|
+
"embeddingModel",
|
|
17
|
+
"tags",
|
|
18
|
+
"durability",
|
|
19
|
+
"source",
|
|
20
|
+
"type",
|
|
21
|
+
"createdAt",
|
|
22
|
+
"updatedAt",
|
|
23
|
+
"instanceToken",
|
|
24
|
+
"expiresAt",
|
|
25
|
+
"retrievalCount",
|
|
26
|
+
"lastRetrieved",
|
|
27
|
+
"usageCount",
|
|
28
|
+
"promotionStatus",
|
|
29
|
+
"promotedAt",
|
|
30
|
+
"promotedBy",
|
|
31
|
+
"archived",
|
|
32
|
+
"archivedAt",
|
|
33
|
+
"archivedBy",
|
|
34
|
+
"parentId",
|
|
35
|
+
"derivedFrom",
|
|
36
|
+
"sessionId",
|
|
37
|
+
"lastReflected",
|
|
38
|
+
"supersedes",
|
|
39
|
+
"subject",
|
|
40
|
+
"summary",
|
|
41
|
+
"validFrom",
|
|
42
|
+
"validTo",
|
|
43
|
+
"_safetyFlags",
|
|
44
|
+
"provenance",
|
|
45
|
+
"originatorInstanceId",
|
|
46
|
+
"metadata",
|
|
47
|
+
"entities",
|
|
48
|
+
]);
|
|
49
|
+
/** Pre-existing UNDECLARED attributes the codebase deliberately stores on a
|
|
50
|
+
* Memory row and must keep (the guard's job is the POINTER, not these).
|
|
51
|
+
* This is an EXPLICIT, NAMED list measured against a live store (A1'' item 1)
|
|
52
|
+
* — never derived from the schema, because the schema is not the source of
|
|
53
|
+
* truth for what is on disk:
|
|
54
|
+
* - `meta` — the continuity-journal payload {seq, processUUID, sessionId,
|
|
55
|
+
* hook} written by the capture path (PUT /Memory/<id>,
|
|
56
|
+
* flair#1257 slice 3); Kern's slice-2 ruling settled that it
|
|
57
|
+
* round-trips as an undeclared field, and
|
|
58
|
+
* test/integration/continuity-rem-promotion-1257.test.ts pins
|
|
59
|
+
* that. It is not a flat String, so declaring it would change
|
|
60
|
+
* the stored shape.
|
|
61
|
+
* - `kind` — carried on a couple of older rows.
|
|
62
|
+
* - `_originatorInstanceId`, `_syncedFrom`, `_syncedAt` — federation
|
|
63
|
+
* bookkeeping stamped by the RECEIVER at merge time
|
|
64
|
+
* (resources/Federation.ts's mergeRecord) on every synced row.
|
|
65
|
+
* Any OTHER undeclared key (in particular any pointer input) is stripped. */
|
|
66
|
+
export const UNDECLARED_ALLOWED = Object.freeze([
|
|
67
|
+
"meta",
|
|
68
|
+
"kind",
|
|
69
|
+
"_originatorInstanceId",
|
|
70
|
+
"_syncedFrom",
|
|
71
|
+
"_syncedAt",
|
|
72
|
+
]);
|
|
73
|
+
/** Every field retained by Memory writers and the inbound federation guard. */
|
|
74
|
+
export const MEMORY_ATTRIBUTES = Object.freeze([
|
|
75
|
+
...DECLARED_MEMORY_ATTRIBUTES,
|
|
76
|
+
...UNDECLARED_ALLOWED,
|
|
77
|
+
]);
|