@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/resources/health.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import { systemdAgentId } from "../src/lib/systemd-agent-id.js";
|
|
1
2
|
import { Resource, databases, server, logger } from "harper";
|
|
2
3
|
import { promises as fsp, existsSync, readFileSync } from "node:fs";
|
|
3
4
|
import { homedir, platform } from "node:os";
|
|
4
5
|
import { join, dirname } from "node:path";
|
|
5
6
|
import { fileURLToPath } from "node:url";
|
|
6
7
|
import { allowVerified, resolveAgentAuth } from "./agent-auth.js";
|
|
8
|
+
import { multiWorkerCondition, multiWorkerHealthField } from "./multi-worker-guard.js";
|
|
7
9
|
import { resolveBuildInfo } from "./build-info.js";
|
|
8
10
|
import { getMigrationStatusSnapshot } from "./migrations/status.js";
|
|
9
11
|
import { resolveMigrationDataDirForRead } from "./migrations/data-dir.js";
|
|
@@ -11,18 +13,20 @@ import { REM_DEDUP_STATS_PATH } from "./dedup-cluster.js";
|
|
|
11
13
|
import { hybridEnabled, retrievalMode } from "./bm25.js";
|
|
12
14
|
import { bm25IndexEnabled, bm25IndexInRetrievalPath, bm25IndexStatus } from "./bm25-index-service.js";
|
|
13
15
|
import { bm25DisabledWarning } from "./bm25-status.js";
|
|
14
|
-
import { normalizeStamp } from "./embedding-space-guard.js";
|
|
16
|
+
import { normalizeStamp, spaceGuardState } from "./embedding-space-guard.js";
|
|
15
17
|
import { getModelId } from "./embeddings-provider.js";
|
|
16
18
|
import { describeStampOutstanding, EMBEDDING_STAMP_ID } from "./migrations/stamp-outstanding.js";
|
|
17
19
|
import { buildPublicHealthBody, resolveSearchReadiness } from "./search-readiness.js";
|
|
18
20
|
import { embedGpuStatusNotice, withEmbedGpuHealth } from "./embed-gpu.js";
|
|
19
21
|
import { classifyPeerLiveness, federationPeersAllDisconnectedWarning, PEER_LIVENESS_MEASURED_BY, summarizePeerLiveness, } from "./federation-peer-liveness.js";
|
|
20
22
|
import { decideInstanceAnswer, INSTANCE_ROW_PRUNE_REMEDY } from "../src/lib/instance-identity-row.js";
|
|
23
|
+
import { summarizeExpiredByAgent, expiredByAgentWarningLines } from "../src/lib/expired-by-agent.js";
|
|
21
24
|
import { readAllInstanceRows } from "./Federation.js";
|
|
25
|
+
import { mcpOAuthProviderReadiness } from "./mcp-oauth-env-guard.js";
|
|
22
26
|
const db = databases;
|
|
23
27
|
const redactHome = (p) => {
|
|
24
28
|
const home = homedir();
|
|
25
|
-
return p.startsWith(home) ? "~" + p.slice(home.length) :
|
|
29
|
+
return p === home ? "~" : p.startsWith(home + "/") ? "~" + p.slice(home.length) : "[redacted]";
|
|
26
30
|
};
|
|
27
31
|
const exists = async (path) => {
|
|
28
32
|
try {
|
|
@@ -100,10 +104,6 @@ export class Health extends Resource {
|
|
|
100
104
|
// `version` (flair#695, the CLI↔server handshake — src/version-handshake.ts):
|
|
101
105
|
// exposed on the PUBLIC endpoint deliberately, so the check works even
|
|
102
106
|
// before an agent identity/key exists (fresh install, pre-`flair init`).
|
|
103
|
-
// Sherlock verdict: fine while locally bound; if /Health is ever fronted
|
|
104
|
-
// PUBLICLY over Fabric, the public surface must omit this field (the
|
|
105
|
-
// richer, auth-gated /HealthDetail already carried version pre-existing —
|
|
106
|
-
// this only adds it to the anonymous endpoint too).
|
|
107
107
|
//
|
|
108
108
|
// flair#1076: both values come from dist/build-info.json — the stamp the
|
|
109
109
|
// build wrote next to the modules Harper actually loaded — so /Health
|
|
@@ -119,9 +119,27 @@ export class Health extends Resource {
|
|
|
119
119
|
version: build?.version ?? resolveVersion(),
|
|
120
120
|
buildCommit: build?.commit ?? null,
|
|
121
121
|
}));
|
|
122
|
-
|
|
122
|
+
// flair#2530 — the query-time embedding-space guard's state, for `flair
|
|
123
|
+
// doctor`. Sync, no scan, no vector read. `state` is one of
|
|
124
|
+
// uniform | mixed | unverified | scan-failed | excluded; `reason` is the
|
|
125
|
+
// bounded error
|
|
126
|
+
// of the last failed scan (on scan-failed, or on mixed when a scan failed
|
|
127
|
+
// before or after the foreign stamp was seen); `excluded` is the last
|
|
128
|
+
// published count of arrays or typed arrays, empty included, without a trusted
|
|
129
|
+
// current-space stamp (null until a scan publishes one). Calls that consult a
|
|
130
|
+
// non-uniform verdict skip vector comparisons against the stored corpus
|
|
131
|
+
// (flair#2559). The field is on the 503 body too; doctor reads it there.
|
|
132
|
+
body.embeddingSpace = spaceGuardState();
|
|
133
|
+
const multiWorker = multiWorkerHealthField(multiWorkerCondition());
|
|
134
|
+
let status = readiness.status;
|
|
135
|
+
if (multiWorker) {
|
|
136
|
+
body.ok = false;
|
|
137
|
+
body.multiWorker = multiWorker;
|
|
138
|
+
status = 503;
|
|
139
|
+
}
|
|
140
|
+
if (status !== 200) {
|
|
123
141
|
return new Response(JSON.stringify(body), {
|
|
124
|
-
status
|
|
142
|
+
status,
|
|
125
143
|
headers: { "content-type": "application/json" },
|
|
126
144
|
});
|
|
127
145
|
}
|
|
@@ -129,7 +147,7 @@ export class Health extends Resource {
|
|
|
129
147
|
}
|
|
130
148
|
}
|
|
131
149
|
/**
|
|
132
|
-
*
|
|
150
|
+
* Sources /Health and /HealthDetail consult.
|
|
133
151
|
*
|
|
134
152
|
* `detail` includes the progress summary (doc counts) on the lag reason.
|
|
135
153
|
* Public /Health leaves it off — corpus size stays on the authenticated
|
|
@@ -175,7 +193,7 @@ export class HealthDetail extends Resource {
|
|
|
175
193
|
return allowVerified(this.getContext?.());
|
|
176
194
|
}
|
|
177
195
|
async get() {
|
|
178
|
-
const stats = { ok: true };
|
|
196
|
+
const stats = { ok: true, mcpOAuthProvider: mcpOAuthProviderReadiness() };
|
|
179
197
|
const nowMs = Date.now();
|
|
180
198
|
const warnings = [];
|
|
181
199
|
// flair#1073: set while walking memories, consumed after the migrations
|
|
@@ -240,6 +258,9 @@ export class HealthDetail extends Resource {
|
|
|
240
258
|
const isAdmin = auth.kind === "internal" || (auth.kind === "agent" && auth.isAdmin);
|
|
241
259
|
stats.caller = { agentId: callerAgent ?? null, isAdmin };
|
|
242
260
|
let memoriesList = [];
|
|
261
|
+
// Per-agent split of the expired-but-unarchived count, filled from the same
|
|
262
|
+
// single Memory scan below — not a second table read (flair#2231).
|
|
263
|
+
const expiredAgentCounts = new Map();
|
|
243
264
|
// ── Memory stats ──
|
|
244
265
|
try {
|
|
245
266
|
for await (const m of db.flair.Memory.search({})) {
|
|
@@ -266,8 +287,11 @@ export class HealthDetail extends Resource {
|
|
|
266
287
|
byDurability[d]++;
|
|
267
288
|
if (m.archived)
|
|
268
289
|
archived++;
|
|
269
|
-
if (!m.archived && m.validTo && new Date(m.validTo).getTime() < nowMs)
|
|
290
|
+
if (!m.archived && m.validTo && new Date(m.validTo).getTime() < nowMs) {
|
|
270
291
|
expired++;
|
|
292
|
+
const owner = typeof m.agentId === "string" ? m.agentId : "";
|
|
293
|
+
expiredAgentCounts.set(owner, (expiredAgentCounts.get(owner) ?? 0) + 1);
|
|
294
|
+
}
|
|
271
295
|
}
|
|
272
296
|
stats.memories = {
|
|
273
297
|
total: memoriesList.length,
|
|
@@ -555,6 +579,10 @@ export class HealthDetail extends Resource {
|
|
|
555
579
|
}
|
|
556
580
|
// ── REM ──
|
|
557
581
|
let nightlyRunFailed = false;
|
|
582
|
+
let nightlyProbeOk = false;
|
|
583
|
+
let nightlyInstalled = false;
|
|
584
|
+
let nightlyDriverAgent = null;
|
|
585
|
+
let nightlyDriverAgentKnown = false;
|
|
558
586
|
try {
|
|
559
587
|
const logsDir = join(homedir(), ".flair", "logs");
|
|
560
588
|
const remLog = join(logsDir, "rem.jsonl");
|
|
@@ -613,29 +641,89 @@ export class HealthDetail extends Resource {
|
|
|
613
641
|
// exist; async + short-timeout so a slow/hung service manager can't
|
|
614
642
|
// stall this request.
|
|
615
643
|
let nightlyEnabled = null;
|
|
616
|
-
let nightlyInstalled = false;
|
|
617
644
|
const plat = platform();
|
|
618
645
|
if (plat === "darwin" || plat === "linux") {
|
|
619
|
-
|
|
620
|
-
?
|
|
621
|
-
:
|
|
622
|
-
|
|
646
|
+
const schedulerPath = plat === "darwin"
|
|
647
|
+
? join(homedir(), "Library", "LaunchAgents", "dev.flair.rem.nightly.plist")
|
|
648
|
+
: join(homedir(), ".config", "systemd", "user", "flair-rem-nightly.timer");
|
|
649
|
+
const unitPath = plat === "darwin" ? schedulerPath
|
|
650
|
+
: join(homedir(), ".config", "systemd", "user", "flair-rem-nightly.service");
|
|
651
|
+
const probeError = (path, error) => {
|
|
652
|
+
const code = error?.code ?? "error code unavailable";
|
|
653
|
+
warnings.push({ level: "warn", message: `REM nightly driver state unknown: ${isAdmin ? path : redactHome(path)} (${code})` });
|
|
654
|
+
};
|
|
655
|
+
const filePresent = async (path) => {
|
|
656
|
+
try {
|
|
657
|
+
await fsp.stat(path);
|
|
658
|
+
return true;
|
|
659
|
+
}
|
|
660
|
+
catch (error) {
|
|
661
|
+
if (error?.code === "ENOENT")
|
|
662
|
+
return false;
|
|
663
|
+
probeError(path, error);
|
|
664
|
+
return null;
|
|
665
|
+
}
|
|
666
|
+
};
|
|
667
|
+
const [schedulerPresent, unitPresent] = await Promise.all([
|
|
668
|
+
filePresent(schedulerPath),
|
|
669
|
+
plat === "darwin" ? Promise.resolve(true) : filePresent(unitPath),
|
|
670
|
+
]);
|
|
671
|
+
nightlyInstalled = schedulerPresent === null || unitPresent === null
|
|
672
|
+
? null : schedulerPresent && unitPresent;
|
|
673
|
+
if (plat === "linux" && schedulerPresent !== null && unitPresent !== null
|
|
674
|
+
&& schedulerPresent !== unitPresent) {
|
|
675
|
+
const orphan = schedulerPresent ? "timer" : "service";
|
|
676
|
+
const orphanPath = schedulerPresent ? schedulerPath : unitPath;
|
|
677
|
+
warnings.push({ level: "warn", message: `REM nightly orphan ${orphan} file: ${isAdmin ? orphanPath : redactHome(orphanPath)}` });
|
|
678
|
+
}
|
|
679
|
+
if (nightlyInstalled === true) {
|
|
623
680
|
try {
|
|
624
681
|
const { queryActiveStateAsync } = await import("../src/rem/scheduler.js");
|
|
625
682
|
nightlyEnabled = await queryActiveStateAsync(plat);
|
|
683
|
+
if (nightlyEnabled === null)
|
|
684
|
+
probeError(schedulerPath);
|
|
626
685
|
}
|
|
627
|
-
catch {
|
|
686
|
+
catch (error) {
|
|
628
687
|
nightlyEnabled = null;
|
|
688
|
+
probeError(schedulerPath, error);
|
|
689
|
+
}
|
|
690
|
+
try {
|
|
691
|
+
const unitText = await fsp.readFile(unitPath, "utf-8");
|
|
692
|
+
const agent = plat === "darwin"
|
|
693
|
+
? unitText.match(/<key>FLAIR_AGENT_ID<\/key>\s*<string>([^<]+)<\/string>/)?.[1].trim() ?? null
|
|
694
|
+
: systemdAgentId(unitText);
|
|
695
|
+
if (agent) {
|
|
696
|
+
nightlyDriverAgent = agent;
|
|
697
|
+
nightlyDriverAgentKnown = true;
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
catch (error) {
|
|
701
|
+
probeError(unitPath, error);
|
|
629
702
|
}
|
|
630
703
|
}
|
|
631
|
-
else {
|
|
704
|
+
else if (nightlyInstalled === false) {
|
|
632
705
|
nightlyEnabled = false;
|
|
633
706
|
}
|
|
634
707
|
}
|
|
708
|
+
nightlyProbeOk = true;
|
|
635
709
|
const nightlyRecords = await tailJsonl(nightlyLog);
|
|
636
710
|
const lastNightlyRec = nightlyRecords[nightlyRecords.length - 1];
|
|
637
711
|
nightlyRunFailed = lastNightlyRec?.status === "failed";
|
|
638
712
|
const lastNightlyAt = lastNightlyRec ? (lastNightlyRec.at ?? lastNightlyRec.ts ?? lastNightlyRec.timestamp ?? null) : null;
|
|
713
|
+
// Newest distillation from a completed cycle with no errors or skips, observed in the server-local log tail.
|
|
714
|
+
let lastDistilledAt = null;
|
|
715
|
+
const completeDistillation = (rec) => rec?.status === "completed"
|
|
716
|
+
&& !rec.errors?.length && !rec.skips?.length && !rec.distill?.aborted
|
|
717
|
+
&& typeof rec.distilledAt === "string" && Number.isFinite(Date.parse(rec.distilledAt))
|
|
718
|
+
&& Number.isInteger(rec.distill?.gathered) && rec.distill.gathered > 0;
|
|
719
|
+
const lastDistillationIncomplete = !!lastNightlyRec && !completeDistillation(lastNightlyRec);
|
|
720
|
+
for (let i = nightlyRecords.length - 1; i >= 0; i--) {
|
|
721
|
+
const rec = nightlyRecords[i];
|
|
722
|
+
if (completeDistillation(rec)) {
|
|
723
|
+
lastDistilledAt = rec.distilledAt;
|
|
724
|
+
break;
|
|
725
|
+
}
|
|
726
|
+
}
|
|
639
727
|
let pendingCandidates = null;
|
|
640
728
|
try {
|
|
641
729
|
let count = 0;
|
|
@@ -653,6 +741,7 @@ export class HealthDetail extends Resource {
|
|
|
653
741
|
!lastRestorativeAt &&
|
|
654
742
|
nightlyEnabled === null &&
|
|
655
743
|
!lastNightlyAt &&
|
|
744
|
+
!lastDistilledAt &&
|
|
656
745
|
pendingCandidates === null;
|
|
657
746
|
if (allNull) {
|
|
658
747
|
stats.rem = null;
|
|
@@ -664,6 +753,8 @@ export class HealthDetail extends Resource {
|
|
|
664
753
|
lastRestorativeAt,
|
|
665
754
|
nightlyEnabled,
|
|
666
755
|
lastNightlyAt,
|
|
756
|
+
lastDistilledAt,
|
|
757
|
+
lastDistillationIncomplete,
|
|
667
758
|
pendingCandidates,
|
|
668
759
|
};
|
|
669
760
|
if (nightlyEnabled && lastNightlyAt && nowMs - new Date(lastNightlyAt).getTime() > 48 * 3600 * 1000) {
|
|
@@ -679,7 +770,7 @@ export class HealthDetail extends Resource {
|
|
|
679
770
|
}
|
|
680
771
|
// Build this after REM discovery, including its unavailable-state fallback.
|
|
681
772
|
// Health does not read the scheduler's next-run time. The existing audit
|
|
682
|
-
// row does carry status
|
|
773
|
+
// row does carry status.
|
|
683
774
|
if (stats.memories?.expired > 0) {
|
|
684
775
|
const nightlyHint = stats.rem?.nightlyEnabled === true
|
|
685
776
|
? nightlyRunFailed
|
|
@@ -688,9 +779,17 @@ export class HealthDetail extends Resource {
|
|
|
688
779
|
: stats.rem?.nightlyEnabled === false
|
|
689
780
|
? "automate: flair rem nightly enable (includes validTo archival)"
|
|
690
781
|
: "nightly state is unknown — check: flair rem nightly status";
|
|
782
|
+
const driver = {
|
|
783
|
+
installed: nightlyProbeOk ? nightlyInstalled : null,
|
|
784
|
+
agent: nightlyDriverAgent,
|
|
785
|
+
agentKnown: nightlyDriverAgentKnown,
|
|
786
|
+
};
|
|
787
|
+
const breakdown = summarizeExpiredByAgent(expiredAgentCounts, driver);
|
|
788
|
+
stats.memories.expiredByAgent = breakdown;
|
|
691
789
|
warnings.push({
|
|
692
790
|
level: "warn",
|
|
693
791
|
message: `${stats.memories.expired} memories have expired validTo but aren't archived\n` +
|
|
792
|
+
expiredByAgentWarningLines(breakdown) +
|
|
694
793
|
" clear now: flair rem light (archives expired validTo; preview: --dry-run)\n" +
|
|
695
794
|
` ${nightlyHint}`,
|
|
696
795
|
});
|
|
@@ -741,7 +840,18 @@ export class HealthDetail extends Resource {
|
|
|
741
840
|
// didn't run, not merely that it didn't.
|
|
742
841
|
try {
|
|
743
842
|
const migrationsDataDir = resolveMigrationDataDirForRead();
|
|
744
|
-
const
|
|
843
|
+
const rawSnapshot = getMigrationStatusSnapshot(migrationsDataDir);
|
|
844
|
+
const redactReason = (reason) => reason ? "details redacted; consult the operator log or an administrator" : reason;
|
|
845
|
+
const snapshot = isAdmin ? rawSnapshot : {
|
|
846
|
+
...rawSnapshot,
|
|
847
|
+
lastCycleError: redactReason(rawSnapshot.lastCycleError),
|
|
848
|
+
migrations: rawSnapshot.migrations.map((m) => ({
|
|
849
|
+
...m,
|
|
850
|
+
reason: m.state === "completed" && m.reason
|
|
851
|
+
? "recorded complete; not re-verified this boot"
|
|
852
|
+
: redactReason(m.reason),
|
|
853
|
+
})),
|
|
854
|
+
};
|
|
745
855
|
stats.migrations = {
|
|
746
856
|
cyclePhase: snapshot.cyclePhase,
|
|
747
857
|
lastCycleAt: snapshot.lastCycleAt ?? null,
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* host-source-citation.ts — the bootstrap prose citation for a bound host
|
|
3
|
+
* pointer (flair#1940 A6). PURE and Harper-free (it depends only on the A2
|
|
4
|
+
* validator), so it is unit-testable directly and usable from the prose path.
|
|
5
|
+
*
|
|
6
|
+
* A6 asks for ONE exported citation format. The citation names the host object
|
|
7
|
+
* the WRITER CLAIMED — host/kind, then the first 8 characters of the id — and
|
|
8
|
+
* marks the claim `(unverified)`: flair does not verify the host object and does
|
|
9
|
+
* not sign the pointer body, so the citation attributes a claim, it never
|
|
10
|
+
* asserts host authorship. The 8-character id is display-only; the STORED id is
|
|
11
|
+
* never truncated. The full URL never appears here (A6 reserves it for MCP/CLI
|
|
12
|
+
* detail output), and the rendered citation is well under the 20-token budget
|
|
13
|
+
* (`HOST_SOURCE_CITATION_MAX_TOKENS`) for any accepted pointer.
|
|
14
|
+
*
|
|
15
|
+
* `formatHostSourceCitation` takes the GATED join's rendered value — the
|
|
16
|
+
* validated pointer OBJECT (see host-source-visibility.ts's `projectHostSource`),
|
|
17
|
+
* the literal `"withheld"`, or nothing — NOT the raw stored string. So the
|
|
18
|
+
* citation inherits the server's redaction decision and can never render a
|
|
19
|
+
* pointer the reader could not see.
|
|
20
|
+
*/
|
|
21
|
+
/** The citation format template (A6). Exported so the test asserting the
|
|
22
|
+
* rendered shape and the caller share one definition. */
|
|
23
|
+
export const HOST_SOURCE_CITATION_FORMAT = "[via {host}/{kind} {id8} (unverified)]";
|
|
24
|
+
/** The number of id characters shown (A6: display-only; the stored id is never
|
|
25
|
+
* truncated). */
|
|
26
|
+
export const HOST_SOURCE_ID_DISPLAY_CHARS = 8;
|
|
27
|
+
/** The marker rendered in place of a pointer the reader may not see (A3). */
|
|
28
|
+
export const HOST_SOURCE_WITHHELD_CITATION = "[via withheld]";
|
|
29
|
+
/** The per-cited-item token ceiling A6 sets. */
|
|
30
|
+
export const HOST_SOURCE_CITATION_MAX_TOKENS = 20;
|
|
31
|
+
/**
|
|
32
|
+
* Render the bootstrap citation for one joined pointer value, or null when the
|
|
33
|
+
* record has no renderable pointer (no pointer, an unbound/archived pointer, or
|
|
34
|
+
* a value that does not re-validate). A `"withheld"` pointer renders the
|
|
35
|
+
* withheld marker, so the "externally sourced" signal survives without
|
|
36
|
+
* revealing the host object (A3).
|
|
37
|
+
*/
|
|
38
|
+
export function formatHostSourceCitation(rendered) {
|
|
39
|
+
if (rendered === "withheld" || rendered === HOST_SOURCE_WITHHELD_CITATION) {
|
|
40
|
+
return HOST_SOURCE_WITHHELD_CITATION;
|
|
41
|
+
}
|
|
42
|
+
if (!rendered || typeof rendered !== "object")
|
|
43
|
+
return null;
|
|
44
|
+
const { host, kind, id } = rendered;
|
|
45
|
+
if (typeof host !== "string" || typeof kind !== "string" || typeof id !== "string" || id.length === 0) {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
return `[via ${host}/${kind} ${id.slice(0, HOST_SOURCE_ID_DISPLAY_CHARS)} (unverified)]`;
|
|
49
|
+
}
|
|
@@ -34,10 +34,10 @@
|
|
|
34
34
|
* never with Memory provenance.
|
|
35
35
|
*
|
|
36
36
|
* The decision is made HERE, on the server, in the read projection — no client
|
|
37
|
-
* or MCP layer can un-redact. `Memory.get()`, `Memory.search()
|
|
38
|
-
* `SemanticSearch` render pointers through the pointer helper
|
|
39
|
-
*
|
|
40
|
-
*
|
|
37
|
+
* or MCP layer can un-redact. `Memory.get()`, `Memory.search()`,
|
|
38
|
+
* `SemanticSearch` and bootstrap render pointers through the pointer helper;
|
|
39
|
+
* bootstrap renders a visible pointer as a prose citation (A6; see
|
|
40
|
+
* resources/MemoryBootstrap.ts).
|
|
41
41
|
*/
|
|
42
42
|
import { parseHostSource } from "./host-source.js";
|
|
43
43
|
import { isPrivateVisibility } from "./memory-visibility.js";
|
|
@@ -116,8 +116,9 @@ export function pointerOutcomeFor(record, readerAgentId, pointer) {
|
|
|
116
116
|
/** The pointer-input keys the named non-admin read paths remove from their
|
|
117
117
|
* output (A1' item 1). A supported write strips them before persist; a RAW
|
|
118
118
|
* writer can leave one on the row, so the named non-admin reads (Memory.get,
|
|
119
|
-
* Memory.search, SemanticSearch) strip them.
|
|
120
|
-
*
|
|
119
|
+
* Memory.search, SemanticSearch) strip them. Bootstrap projects through the
|
|
120
|
+
* pointer helper too, so its inline fields are dropped as well, except where
|
|
121
|
+
* its `?? m` fallback uses the row as read. */
|
|
121
122
|
const INLINE_POINTER_FIELDS = ["hostSource", "hostSourceScope", "hostSourceVisibility"];
|
|
122
123
|
/** Return `record` with every inline pointer-input field removed. Returns the
|
|
123
124
|
* SAME reference when there is nothing to remove, so a clean record is
|
|
@@ -71,6 +71,23 @@ export const KEYSTORE_FAILURE_NOTE = "[federation] Could not store the federatio
|
|
|
71
71
|
/** The lock-dir remedy, in the same style as KEYSTORE_FAILURE_NOTE. */
|
|
72
72
|
export const LOCK_DIR_REMEDY = "Remedy: make the Flair home writable by the Harper process (a directory the process can create " +
|
|
73
73
|
"$HOME/.flair/locks with mode 0700). Identity creation is REFUSED while the lock dir is unusable.";
|
|
74
|
+
/** The sidecar-write failure note (flair#2200) — the seed IS stored; only ownership is missing. */
|
|
75
|
+
export function seedOwnerFailureNote(id, err) {
|
|
76
|
+
return (`[federation] stored the signing seed for ${id} but could not record its ownership sidecar ` +
|
|
77
|
+
`(${err instanceof Error ? err.message : String(err)}). Node-shaped files without .pub stay report-only. ` +
|
|
78
|
+
`Remedy: inspect and clear any conflicting sidecar path; check that $HOME/.flair/keys is writable by the Harper process (mode 0700).`);
|
|
79
|
+
}
|
|
80
|
+
/** Store the seed and attempt to record its sidecar; metadata failure is logged. */
|
|
81
|
+
export async function storeInstanceSeed(id, seed, dataDir = harperRootPath()) {
|
|
82
|
+
const { keystore, recordSeedOwner } = await import("../src/keystore.js");
|
|
83
|
+
keystore.setPrivateKeySeed(id, seed);
|
|
84
|
+
try {
|
|
85
|
+
recordSeedOwner(id, dataDir);
|
|
86
|
+
}
|
|
87
|
+
catch (err) {
|
|
88
|
+
console.error(seedOwnerFailureNote(id, err));
|
|
89
|
+
}
|
|
90
|
+
}
|
|
74
91
|
/**
|
|
75
92
|
* Harper's data root for THIS process — the `ROOTPATH` env var Harper sets for a
|
|
76
93
|
* component (read the same way `resources/models-dir.ts` reads it). The lock lives
|
|
@@ -122,6 +122,29 @@ export async function localInstanceId() {
|
|
|
122
122
|
// "none" — a SUCCESSFUL read found no Instance row: null, uncached, as today.
|
|
123
123
|
return null;
|
|
124
124
|
}
|
|
125
|
+
/**
|
|
126
|
+
* This instance's canonical id from the `Instance` table AS IT IS NOW: a fresh
|
|
127
|
+
* read on every call, through the same strict reader and the same shared rule as
|
|
128
|
+
* {@link localInstanceId}, but never answered from that function's cache and
|
|
129
|
+
* never written into it (flair#2472).
|
|
130
|
+
*
|
|
131
|
+
* For a guard that must refuse when it could not confirm a single canonical
|
|
132
|
+
* Instance row. `localInstanceId()` keeps a successful id for the process
|
|
133
|
+
* lifetime, so after that row is removed, or a second row is added, it still
|
|
134
|
+
* answers the old id. This returns null when the read finds no row, several
|
|
135
|
+
* rows, or fails.
|
|
136
|
+
*/
|
|
137
|
+
export async function currentInstanceId() {
|
|
138
|
+
let rows;
|
|
139
|
+
try {
|
|
140
|
+
rows = await readAllInstanceRows();
|
|
141
|
+
}
|
|
142
|
+
catch {
|
|
143
|
+
return null;
|
|
144
|
+
}
|
|
145
|
+
const decision = decideInstanceAnswer(rows);
|
|
146
|
+
return decision.kind === "answer" ? decision.row.id : null;
|
|
147
|
+
}
|
|
125
148
|
/**
|
|
126
149
|
* Test-only: force re-resolution on the next localInstanceId() call. The
|
|
127
150
|
* module-level cache otherwise persists across test files that share the
|