@tpsdev-ai/flair 0.59.0 → 0.63.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 +10 -10
- package/SECURITY.md +49 -5
- package/config.yaml +23 -12
- package/dist/bridges/builtins/mem0.js +63 -28
- package/dist/bridges/runtime/execute.js +1 -0
- 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/bridges/types.js +1 -0
- package/dist/build-info.json +3 -3
- package/dist/cli.js +1054 -367
- package/dist/commands/agent.js +233 -90
- package/dist/commands/attention.js +4 -3
- package/dist/commands/backup-approval.js +218 -0
- package/dist/commands/backup.js +211 -39
- package/dist/commands/bootstrap.js +3 -1
- package/dist/commands/bridge.js +172 -119
- package/dist/commands/deploy.js +71 -8
- package/dist/commands/doctor.js +711 -146
- package/dist/commands/export.js +57 -23
- package/dist/commands/federation.js +787 -82
- package/dist/commands/grant.js +5 -6
- package/dist/commands/help.js +25 -0
- package/dist/commands/hook.js +155 -2
- package/dist/commands/idp.js +27 -19
- package/dist/commands/import.js +136 -20
- package/dist/commands/init.js +469 -200
- package/dist/commands/integrity.js +387 -0
- package/dist/commands/keys.js +247 -58
- package/dist/commands/mcp.js +108 -52
- package/dist/commands/memory.js +203 -35
- package/dist/commands/migrate-harness-memory.js +3 -2
- package/dist/commands/orgevent.js +51 -47
- package/dist/commands/presence.js +4 -3
- package/dist/commands/principal.js +428 -62
- package/dist/commands/quality.js +13 -1
- package/dist/commands/reembed.js +141 -17
- package/dist/commands/relationship.js +2 -1
- package/dist/commands/rem.js +537 -80
- package/dist/commands/restore.js +413 -65
- package/dist/commands/search.js +6 -4
- package/dist/commands/service.js +235 -40
- package/dist/commands/soul.js +4 -9
- package/dist/commands/status.js +94 -38
- package/dist/commands/test.js +7 -3
- package/dist/commands/upgrade.js +77 -23
- package/dist/commands/workspace.js +13 -11
- package/dist/component-env.js +31 -41
- package/dist/deploy.js +136 -4
- package/dist/doctor-client.js +534 -92
- package/dist/engine-version-contract.js +1 -0
- package/dist/engine-version.js +23 -3
- package/dist/fabric-upgrade.js +12 -2
- package/dist/federation/presence-send.js +139 -0
- package/dist/federation-verify.js +273 -180
- package/dist/hook-install.js +670 -6
- package/dist/install/clients.js +171 -35
- 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 +88 -0
- package/dist/lib/agent-roster.js +33 -0
- package/dist/lib/atomic-write.js +1 -1
- package/dist/lib/auth-resolve.js +1069 -60
- package/dist/lib/backup-approval-store.js +612 -0
- package/dist/lib/backup-artifact.js +343 -0
- package/dist/lib/capture-runtime.js +124 -0
- package/dist/lib/config-critical-section.js +212 -25
- package/dist/lib/connect-phase.js +33 -0
- package/dist/lib/credential-status-rule.js +78 -0
- package/dist/lib/daemon-liveness.js +43 -11
- package/dist/lib/doctor-run.js +75 -37
- package/dist/lib/durability-copy.js +10 -0
- package/dist/lib/embedding-space-doctor.js +75 -0
- package/dist/lib/federation-pair-access.js +4 -0
- package/dist/lib/federation-retry-queue.js +283 -0
- package/dist/lib/federation-retry-row.js +101 -0
- package/dist/lib/flair-agent-role.js +4 -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/instruction-event-contract.js +17 -0
- package/dist/lib/instruction-event-doctor.js +102 -0
- package/dist/lib/launchd-management.js +38 -3
- 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 +1182 -341
- 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 +4 -0
- package/dist/lib/memory-id-policy.js +46 -0
- package/dist/lib/memory-integrity.js +309 -0
- package/dist/lib/memory-provider-timeout.js +33 -0
- package/dist/lib/memory-purge-response.js +20 -0
- package/dist/lib/mqtt-config.js +132 -0
- package/dist/lib/mqtt-listener-doctor.js +104 -0
- package/dist/lib/open-live-row.js +20 -0
- package/dist/lib/ops-table-count.js +25 -0
- package/dist/lib/ops-url.js +52 -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 +76 -12
- package/dist/lib/promotion-content-hash.js +20 -0
- 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-archive.js +760 -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-assignment-preflight.js +159 -0
- package/dist/lib/skill-seed-pending.js +24 -0
- package/dist/lib/skill-seed.js +448 -0
- package/dist/lib/skill-tombstone-doctor.js +133 -0
- package/dist/lib/soul-scope-fields.js +26 -0
- package/dist/lib/stop-start-recovery.js +54 -0
- package/dist/lib/uninstall-purge.js +266 -11
- package/dist/lib/upgrade-prior-liveness.js +2 -1
- package/dist/lib/using-flair-skill.js +87 -0
- package/dist/mcp-client-assertion.js +114 -14
- package/dist/memory-id-checkpoint.js +347 -0
- package/dist/memory-node-compare.js +207 -0
- package/dist/mqtt-off-deploy.js +550 -0
- package/dist/packages/flair-mcp/src/secret-redaction.js +113 -0
- package/dist/rem/promote-policy.js +3 -3
- package/dist/rem/restore.js +303 -26
- package/dist/rem/runner.js +317 -96
- package/dist/rem/scheduler.js +21 -4
- package/dist/resources/A2AAdapter.js +131 -178
- package/dist/resources/AdminMemory.js +2 -0
- package/dist/resources/AdminMemoryCandidates.js +116 -0
- package/dist/resources/Agent.js +463 -33
- package/dist/resources/AgentCard.js +4 -0
- package/dist/resources/AgentKeyRegister.js +248 -0
- package/dist/resources/AgentKeyRegistration.js +28 -0
- package/dist/resources/AgentReadPosition.js +7 -0
- package/dist/resources/AgentSeed.js +238 -107
- package/dist/resources/AutoPromoteCandidates.js +413 -78
- package/dist/resources/Credential.js +183 -10
- package/dist/resources/Federation.js +915 -145
- package/dist/resources/FederationRetry.js +140 -0
- package/dist/resources/InstructionVersion.js +220 -0
- package/dist/resources/Integration.js +300 -25
- package/dist/resources/MCPClientMetadata.js +6 -3
- package/dist/resources/Memory.js +3300 -758
- package/dist/resources/MemoryArchive.js +171 -53
- package/dist/resources/MemoryBootstrap.js +122 -61
- package/dist/resources/MemoryCandidate.js +37 -3
- package/dist/resources/MemoryConsolidate.js +2 -2
- package/dist/resources/MemoryDedupStats.js +30 -1
- package/dist/resources/MemoryFeed.js +545 -50
- package/dist/resources/MemoryGrant.js +21 -1
- package/dist/resources/MemoryMaintenance.js +368 -46
- package/dist/resources/MemoryPurge.js +348 -0
- package/dist/resources/MemoryReflect.js +71 -12
- package/dist/resources/MemoryReindex.js +111 -17
- package/dist/resources/Message.js +16 -5
- package/dist/resources/OAuth.js +342 -48
- package/dist/resources/OAuthClient.js +1 -1
- package/dist/resources/OrgEvent.js +405 -19
- package/dist/resources/OrgEventCatchup.js +7 -0
- package/dist/resources/OrgEventMaintenance.js +48 -10
- package/dist/resources/PairingToken.js +1 -1
- package/dist/resources/Presence.js +166 -51
- package/dist/resources/PromoteMemoryCandidate.js +24 -7
- package/dist/resources/RecordUsage.js +2 -4
- package/dist/resources/Relationship.js +23 -0
- package/dist/resources/SemanticSearch.js +63 -32
- package/dist/resources/Soul.js +191 -76
- package/dist/resources/SoulFeed.js +2 -1
- package/dist/resources/TeamDirectory.js +35 -0
- package/dist/resources/WorkspaceLatest.js +4 -0
- package/dist/resources/WorkspaceState.js +21 -1
- package/dist/resources/XAA.js +207 -63
- package/dist/resources/a2a-stream.js +313 -0
- package/dist/resources/a2a-url.js +4 -5
- package/dist/resources/agent-admin.js +10 -1
- package/dist/resources/agent-auth.js +138 -83
- package/dist/resources/agent-read-position-lib.js +4 -1
- package/dist/resources/agent-status-guard.js +9 -7
- package/dist/resources/auth-middleware.js +534 -171
- package/dist/resources/authority-field-guard.js +9 -11
- package/dist/resources/auto-promote-lib.js +8 -5
- package/dist/resources/basic-auth-header.js +21 -0
- package/dist/resources/bm25-index-service.js +4 -5
- package/dist/resources/dedup-cluster.js +6 -1
- package/dist/resources/ed25519-auth.js +1 -1
- package/dist/resources/embedding-space-guard.js +366 -72
- package/dist/resources/embeddings-provider.js +25 -0
- package/dist/resources/engine-version-stamp-boot.js +53 -0
- package/dist/resources/federation-classify.js +161 -0
- package/dist/resources/federation-crypto.js +5 -5
- package/dist/resources/federation-retry-lib.js +60 -0
- package/dist/resources/grant-visibility.js +135 -0
- package/dist/resources/harper-routing.js +83 -0
- package/dist/resources/health.js +163 -22
- package/dist/resources/host-pointer/registry.js +29 -0
- package/dist/resources/host-pointer-adapter.js +1 -0
- package/dist/resources/host-source-citation.js +49 -0
- package/dist/resources/host-source-visibility.js +7 -6
- package/dist/resources/in-process.js +24 -22
- package/dist/resources/instance-create-lock.js +17 -0
- package/dist/resources/instance-identity.js +23 -0
- package/dist/resources/instruction-version-record.js +587 -0
- package/dist/resources/internal-authority.js +13 -0
- package/dist/resources/key-lock.js +3 -3
- package/dist/resources/mcp-handler.js +141 -19
- package/dist/resources/mcp-oauth-env-guard.js +36 -0
- package/dist/resources/mcp-oauth-flag.js +12 -14
- package/dist/resources/mcp-oauth.js +450 -56
- package/dist/resources/mcp-tool-arguments.js +4 -6
- package/dist/resources/mcp-tools.js +187 -40
- package/dist/resources/memory-bootstrap-lib.js +5 -15
- package/dist/resources/memory-declared-attributes.js +4 -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 +144 -0
- package/dist/resources/memory-embedding-value.js +8 -0
- package/dist/resources/memory-host-source.js +32 -7
- package/dist/resources/memory-id-guard.js +75 -0
- package/dist/resources/memory-redaction.js +236 -0
- package/dist/resources/memory-reflect-lib.js +1 -1
- package/dist/resources/memory-supplied-vector.js +72 -0
- package/dist/resources/memory-write-lock.js +489 -0
- package/dist/resources/memory-write-response.js +139 -0
- package/dist/resources/memory-write-transaction.js +243 -0
- package/dist/resources/migration-boot.js +17 -12
- package/dist/resources/migrations/boot-progress.js +25 -0
- package/dist/resources/migrations/data-dir.js +90 -19
- package/dist/resources/migrations/dir-safety.js +61 -3
- package/dist/resources/migrations/embedding-stamp.js +462 -82
- package/dist/resources/migrations/export.js +1 -0
- package/dist/resources/migrations/graph-heal.js +27 -27
- package/dist/resources/migrations/ledger.js +5 -2
- package/dist/resources/migrations/lock.js +870 -77
- package/dist/resources/migrations/progress.js +71 -10
- package/dist/resources/migrations/runner.js +212 -18
- package/dist/resources/migrations/snapshot.js +1 -0
- package/dist/resources/migrations/source-fields.js +5 -5
- package/dist/resources/migrations/state.js +36 -1
- package/dist/resources/migrations/status.js +2 -13
- package/dist/resources/migrations/synthetic-test-migration.js +81 -12
- package/dist/resources/migrations/types.js +26 -1
- package/dist/resources/migrations/visibility-backfill.js +113 -72
- package/dist/resources/oauth-discovery.js +0 -5
- package/dist/resources/object-body-guard.js +40 -0
- package/dist/resources/org-event-created-at.js +133 -0
- package/dist/resources/org-event-reserved.js +92 -0
- package/dist/resources/org-event-write-fault.js +19 -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 +256 -0
- package/dist/resources/owner-scoped-writes.js +89 -0
- package/dist/resources/path-id-rewrite.js +76 -0
- package/dist/resources/presence-internal.js +5 -5
- package/dist/resources/presence-receipt.js +236 -0
- package/dist/resources/promotion-binding.js +43 -0
- package/dist/resources/promotion-stamp.js +143 -17
- package/dist/resources/protocol-context.js +189 -0
- package/dist/resources/record-owner-guard.js +74 -26
- package/dist/resources/record-type-kit.js +2 -4
- package/dist/resources/record-types.js +1 -1
- package/dist/resources/relay-ops.js +78 -6
- package/dist/resources/replay-store.js +96 -19
- package/dist/resources/request-target.js +163 -0
- package/dist/resources/request-transaction.js +46 -1
- package/dist/resources/search-readiness.js +4 -1
- package/dist/resources/seed-ids.js +9 -0
- package/dist/resources/seed-reservation.js +116 -0
- package/dist/resources/semantic-retrieval-core.js +27 -15
- package/dist/resources/server-row-validation.js +71 -0
- package/dist/resources/skill-manifest.js +24 -14
- package/dist/resources/skill-subject.js +53 -0
- package/dist/resources/skill-version-write.js +789 -0
- package/dist/resources/skill-write-fault.js +20 -0
- package/dist/resources/skill-write-policy.js +68 -0
- package/dist/resources/skill-write.js +67 -7
- package/dist/resources/soul-write-policy.js +26 -7
- package/dist/resources/table-helpers.js +10 -7
- package/dist/resources/table-subscription-policy.js +518 -85
- package/dist/resources/table-subscriptions.js +20 -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 +235 -0
- package/dist/resources/usage-recording.js +186 -70
- package/dist/resources/write-back.js +383 -0
- package/dist/resources/write-journal-context.js +5 -0
- package/dist/resources/write-journal.js +289 -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 +88 -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/federation-retry-row.js +101 -0
- package/dist/src/lib/flair-agent-role.js +4 -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/instruction-event-contract.js +17 -0
- package/dist/src/lib/mcp-oauth-env-core.js +133 -0
- package/dist/src/lib/memory-attributes.js +4 -0
- package/dist/src/lib/memory-id-policy.js +46 -0
- package/dist/src/lib/open-live-row.js +20 -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/soul-scope-fields.js +26 -0
- package/dist/src/lib/systemd-agent-id.js +38 -0
- package/dist/src/rem/promote-policy.js +3 -3
- package/dist/src/rem/scheduler.js +21 -4
- package/docs/access-control.md +164 -54
- package/docs/api-reference.md +165 -32
- package/docs/auth.md +46 -30
- package/docs/bridges.md +11 -0
- package/docs/claude-code.md +37 -7
- package/docs/deploying-on-fabric.md +178 -0
- package/docs/deployment.md +19 -0
- package/docs/embedding-in-a-harper-app.md +17 -15
- package/docs/entity-vocabulary.md +3 -6
- package/docs/federation.md +61 -3
- package/docs/hosted-on-fabric.md +43 -36
- package/docs/integrations.md +14 -14
- package/docs/mcp-clients.md +12 -7
- package/docs/n8n.md +17 -11
- package/docs/notes/mcp-agent-auth-consumer.md +16 -13
- package/docs/notes/mcp-oauth-model2.md +40 -11
- package/docs/openclaw.md +1 -1
- package/docs/quickstart-fabric.md +4 -4
- package/docs/quickstart.md +12 -4
- package/docs/releasing.md +25 -19
- package/docs/rem.md +32 -3
- package/docs/secrets-and-keys.md +21 -4
- package/docs/standalone-local.md +30 -2
- package/docs/supply-chain-policy.md +34 -16
- package/docs/the-team.md +2 -2
- package/docs/upgrade.md +46 -6
- package/package.json +24 -12
- package/schemas/agent-key-registration.graphql +22 -0
- package/schemas/agent.graphql +6 -3
- package/schemas/federation.graphql +41 -1
- package/schemas/memory.graphql +91 -7
- package/schemas/oauth.graphql +19 -0
- package/schemas/schema.graphql +2 -0
- package/templates/bin/flair-rem-nightly.sh.tmpl +7 -1
- package/templates/launchd/start-flair-with-admin-pass.sh +188 -10
- package/dist/resources/soul-adk-guard.js +0 -68
package/dist/resources/health.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
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";
|
|
@@ -12,18 +13,20 @@ import { REM_DEDUP_STATS_PATH } from "./dedup-cluster.js";
|
|
|
12
13
|
import { hybridEnabled, retrievalMode } from "./bm25.js";
|
|
13
14
|
import { bm25IndexEnabled, bm25IndexInRetrievalPath, bm25IndexStatus } from "./bm25-index-service.js";
|
|
14
15
|
import { bm25DisabledWarning } from "./bm25-status.js";
|
|
15
|
-
import { normalizeStamp } from "./embedding-space-guard.js";
|
|
16
|
+
import { normalizeStamp, spaceGuardState } from "./embedding-space-guard.js";
|
|
16
17
|
import { getModelId } from "./embeddings-provider.js";
|
|
17
18
|
import { describeStampOutstanding, EMBEDDING_STAMP_ID } from "./migrations/stamp-outstanding.js";
|
|
18
19
|
import { buildPublicHealthBody, resolveSearchReadiness } from "./search-readiness.js";
|
|
19
20
|
import { embedGpuStatusNotice, withEmbedGpuHealth } from "./embed-gpu.js";
|
|
20
21
|
import { classifyPeerLiveness, federationPeersAllDisconnectedWarning, PEER_LIVENESS_MEASURED_BY, summarizePeerLiveness, } from "./federation-peer-liveness.js";
|
|
21
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";
|
|
22
24
|
import { readAllInstanceRows } from "./Federation.js";
|
|
25
|
+
import { mcpOAuthProviderReadiness } from "./mcp-oauth-env-guard.js";
|
|
23
26
|
const db = databases;
|
|
24
27
|
const redactHome = (p) => {
|
|
25
28
|
const home = homedir();
|
|
26
|
-
return p.startsWith(home) ? "~" + p.slice(home.length) :
|
|
29
|
+
return p === home ? "~" : p.startsWith(home + "/") ? "~" + p.slice(home.length) : "[redacted]";
|
|
27
30
|
};
|
|
28
31
|
const exists = async (path) => {
|
|
29
32
|
try {
|
|
@@ -101,10 +104,6 @@ export class Health extends Resource {
|
|
|
101
104
|
// `version` (flair#695, the CLI↔server handshake — src/version-handshake.ts):
|
|
102
105
|
// exposed on the PUBLIC endpoint deliberately, so the check works even
|
|
103
106
|
// before an agent identity/key exists (fresh install, pre-`flair init`).
|
|
104
|
-
// Sherlock verdict: fine while locally bound; if /Health is ever fronted
|
|
105
|
-
// PUBLICLY over Fabric, the public surface must omit this field (the
|
|
106
|
-
// richer, auth-gated /HealthDetail already carried version pre-existing —
|
|
107
|
-
// this only adds it to the anonymous endpoint too).
|
|
108
107
|
//
|
|
109
108
|
// flair#1076: both values come from dist/build-info.json — the stamp the
|
|
110
109
|
// build wrote next to the modules Harper actually loaded — so /Health
|
|
@@ -120,6 +119,17 @@ export class Health extends Resource {
|
|
|
120
119
|
version: build?.version ?? resolveVersion(),
|
|
121
120
|
buildCommit: build?.commit ?? null,
|
|
122
121
|
}));
|
|
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();
|
|
123
133
|
const multiWorker = multiWorkerHealthField(multiWorkerCondition());
|
|
124
134
|
let status = readiness.status;
|
|
125
135
|
if (multiWorker) {
|
|
@@ -137,7 +147,7 @@ export class Health extends Resource {
|
|
|
137
147
|
}
|
|
138
148
|
}
|
|
139
149
|
/**
|
|
140
|
-
*
|
|
150
|
+
* Sources /Health and /HealthDetail consult.
|
|
141
151
|
*
|
|
142
152
|
* `detail` includes the progress summary (doc counts) on the lag reason.
|
|
143
153
|
* Public /Health leaves it off — corpus size stays on the authenticated
|
|
@@ -183,7 +193,7 @@ export class HealthDetail extends Resource {
|
|
|
183
193
|
return allowVerified(this.getContext?.());
|
|
184
194
|
}
|
|
185
195
|
async get() {
|
|
186
|
-
const stats = { ok: true };
|
|
196
|
+
const stats = { ok: true, mcpOAuthProvider: mcpOAuthProviderReadiness() };
|
|
187
197
|
const nowMs = Date.now();
|
|
188
198
|
const warnings = [];
|
|
189
199
|
// flair#1073: set while walking memories, consumed after the migrations
|
|
@@ -193,6 +203,10 @@ export class HealthDetail extends Resource {
|
|
|
193
203
|
// corpus is one space and still outstanding against getModelId().
|
|
194
204
|
let mixedEmbeddingSpaces = false;
|
|
195
205
|
let memoryScanOk = false;
|
|
206
|
+
// Set only when the Memory scan finished without throwing. A failed or
|
|
207
|
+
// partial scan leaves it false, and the unregistered-author list is then
|
|
208
|
+
// reported unavailable (null); no other field reads this flag.
|
|
209
|
+
let memoryScanComplete = false;
|
|
196
210
|
let memoryModelCounts = {};
|
|
197
211
|
// flair#1326: same search-ready signal as public /Health. HealthDetail
|
|
198
212
|
// stays HTTP 200 (it is a stats dump, not a traffic gate); the field
|
|
@@ -248,6 +262,9 @@ export class HealthDetail extends Resource {
|
|
|
248
262
|
const isAdmin = auth.kind === "internal" || (auth.kind === "agent" && auth.isAdmin);
|
|
249
263
|
stats.caller = { agentId: callerAgent ?? null, isAdmin };
|
|
250
264
|
let memoriesList = [];
|
|
265
|
+
// Per-agent split of the expired-but-unarchived count, filled from the same
|
|
266
|
+
// single Memory scan below — not a second table read (flair#2231).
|
|
267
|
+
const expiredAgentCounts = new Map();
|
|
251
268
|
// ── Memory stats ──
|
|
252
269
|
try {
|
|
253
270
|
for await (const m of db.flair.Memory.search({})) {
|
|
@@ -274,8 +291,11 @@ export class HealthDetail extends Resource {
|
|
|
274
291
|
byDurability[d]++;
|
|
275
292
|
if (m.archived)
|
|
276
293
|
archived++;
|
|
277
|
-
if (!m.archived && m.validTo && new Date(m.validTo).getTime() < nowMs)
|
|
294
|
+
if (!m.archived && m.validTo && new Date(m.validTo).getTime() < nowMs) {
|
|
278
295
|
expired++;
|
|
296
|
+
const owner = typeof m.agentId === "string" ? m.agentId : "";
|
|
297
|
+
expiredAgentCounts.set(owner, (expiredAgentCounts.get(owner) ?? 0) + 1);
|
|
298
|
+
}
|
|
279
299
|
}
|
|
280
300
|
stats.memories = {
|
|
281
301
|
total: memoriesList.length,
|
|
@@ -319,6 +339,7 @@ export class HealthDetail extends Resource {
|
|
|
319
339
|
memoryModelCounts = modelCounts;
|
|
320
340
|
if (distinctSpaces.size > 1)
|
|
321
341
|
mixedEmbeddingSpaces = true;
|
|
342
|
+
memoryScanComplete = true;
|
|
322
343
|
}
|
|
323
344
|
catch {
|
|
324
345
|
stats.memories = null;
|
|
@@ -331,16 +352,24 @@ export class HealthDetail extends Resource {
|
|
|
331
352
|
const blank = (id) => ({
|
|
332
353
|
id, memoryCount: 0, hashFallback: 0, writes24h: 0, lastWriteAt: null, usageCount: 0,
|
|
333
354
|
});
|
|
355
|
+
// The count, the names and the table all come from one map keyed by
|
|
356
|
+
// Agent id, so the admin total, names and row set describe the same
|
|
357
|
+
// agents. A Memory row whose author has no Agent record — the
|
|
358
|
+
// operator's `skill:using-flair` seed when the operator id was never
|
|
359
|
+
// registered — is kept in a separate list, never added to `perAgent`
|
|
360
|
+
// as if it were an agent (flair#3051).
|
|
334
361
|
const perAgentMap = new Map();
|
|
335
362
|
for (const a of agents) {
|
|
336
363
|
if (a.id)
|
|
337
364
|
perAgentMap.set(a.id, blank(a.id));
|
|
338
365
|
}
|
|
366
|
+
const unregisteredMap = new Map();
|
|
339
367
|
const cutoff24h = nowMs - 24 * 3600 * 1000;
|
|
340
368
|
for (const m of memoriesList) {
|
|
341
369
|
if (!m.agentId)
|
|
342
370
|
continue;
|
|
343
|
-
const
|
|
371
|
+
const known = perAgentMap.get(m.agentId);
|
|
372
|
+
const row = known ?? unregisteredMap.get(m.agentId) ?? blank(m.agentId);
|
|
344
373
|
row.memoryCount++;
|
|
345
374
|
row.usageCount += (m.usageCount ?? 0);
|
|
346
375
|
if (!m.embeddingModel || m.embeddingModel === "hash-512d")
|
|
@@ -353,16 +382,33 @@ export class HealthDetail extends Resource {
|
|
|
353
382
|
row.lastWriteAt = m.createdAt;
|
|
354
383
|
}
|
|
355
384
|
}
|
|
356
|
-
|
|
385
|
+
if (known)
|
|
386
|
+
perAgentMap.set(m.agentId, row);
|
|
387
|
+
else
|
|
388
|
+
unregisteredMap.set(m.agentId, row);
|
|
357
389
|
}
|
|
390
|
+
const agentIds = Array.from(perAgentMap.keys());
|
|
358
391
|
const perAgentFull = Array.from(perAgentMap.values()).sort((a, b) => b.memoryCount - a.memoryCount);
|
|
359
392
|
const perAgent = isAdmin
|
|
360
393
|
? perAgentFull
|
|
361
394
|
: perAgentFull.filter((r) => r.id === callerAgent || r.memoryCount > 0);
|
|
395
|
+
const unregisteredMemoryAuthors = Array.from(unregisteredMap.values())
|
|
396
|
+
.sort((a, b) => b.memoryCount - a.memoryCount)
|
|
397
|
+
.map((r) => ({ id: r.id, memoryCount: r.memoryCount }));
|
|
362
398
|
stats.agents = {
|
|
363
|
-
count:
|
|
364
|
-
names: isAdmin ?
|
|
399
|
+
count: perAgentMap.size,
|
|
400
|
+
names: isAdmin ? agentIds : undefined,
|
|
365
401
|
perAgent,
|
|
402
|
+
// A non-admin gets the de-duplicated Agent count — one per distinct
|
|
403
|
+
// truthy Agent id, so a duplicate collapses and an id-less row is
|
|
404
|
+
// not counted — and only the perAgent rows it may see: its own row
|
|
405
|
+
// and rows with memories. unregisteredMemoryAuthors is undefined for
|
|
406
|
+
// a non-admin. An admin gets that list only after a complete Memory
|
|
407
|
+
// scan; null means the scan did not finish, so the answer is unknown
|
|
408
|
+
// rather than empty or partial.
|
|
409
|
+
unregisteredMemoryAuthors: isAdmin
|
|
410
|
+
? (memoryScanComplete ? unregisteredMemoryAuthors : null)
|
|
411
|
+
: undefined,
|
|
366
412
|
};
|
|
367
413
|
}
|
|
368
414
|
catch {
|
|
@@ -563,6 +609,10 @@ export class HealthDetail extends Resource {
|
|
|
563
609
|
}
|
|
564
610
|
// ── REM ──
|
|
565
611
|
let nightlyRunFailed = false;
|
|
612
|
+
let nightlyProbeOk = false;
|
|
613
|
+
let nightlyInstalled = false;
|
|
614
|
+
let nightlyDriverAgent = null;
|
|
615
|
+
let nightlyDriverAgentKnown = false;
|
|
566
616
|
try {
|
|
567
617
|
const logsDir = join(homedir(), ".flair", "logs");
|
|
568
618
|
const remLog = join(logsDir, "rem.jsonl");
|
|
@@ -621,29 +671,89 @@ export class HealthDetail extends Resource {
|
|
|
621
671
|
// exist; async + short-timeout so a slow/hung service manager can't
|
|
622
672
|
// stall this request.
|
|
623
673
|
let nightlyEnabled = null;
|
|
624
|
-
let nightlyInstalled = false;
|
|
625
674
|
const plat = platform();
|
|
626
675
|
if (plat === "darwin" || plat === "linux") {
|
|
627
|
-
|
|
628
|
-
?
|
|
629
|
-
:
|
|
630
|
-
|
|
676
|
+
const schedulerPath = plat === "darwin"
|
|
677
|
+
? join(homedir(), "Library", "LaunchAgents", "dev.flair.rem.nightly.plist")
|
|
678
|
+
: join(homedir(), ".config", "systemd", "user", "flair-rem-nightly.timer");
|
|
679
|
+
const unitPath = plat === "darwin" ? schedulerPath
|
|
680
|
+
: join(homedir(), ".config", "systemd", "user", "flair-rem-nightly.service");
|
|
681
|
+
const probeError = (path, error) => {
|
|
682
|
+
const code = error?.code ?? "error code unavailable";
|
|
683
|
+
warnings.push({ level: "warn", message: `REM nightly driver state unknown: ${isAdmin ? path : redactHome(path)} (${code})` });
|
|
684
|
+
};
|
|
685
|
+
const filePresent = async (path) => {
|
|
686
|
+
try {
|
|
687
|
+
await fsp.stat(path);
|
|
688
|
+
return true;
|
|
689
|
+
}
|
|
690
|
+
catch (error) {
|
|
691
|
+
if (error?.code === "ENOENT")
|
|
692
|
+
return false;
|
|
693
|
+
probeError(path, error);
|
|
694
|
+
return null;
|
|
695
|
+
}
|
|
696
|
+
};
|
|
697
|
+
const [schedulerPresent, unitPresent] = await Promise.all([
|
|
698
|
+
filePresent(schedulerPath),
|
|
699
|
+
plat === "darwin" ? Promise.resolve(true) : filePresent(unitPath),
|
|
700
|
+
]);
|
|
701
|
+
nightlyInstalled = schedulerPresent === null || unitPresent === null
|
|
702
|
+
? null : schedulerPresent && unitPresent;
|
|
703
|
+
if (plat === "linux" && schedulerPresent !== null && unitPresent !== null
|
|
704
|
+
&& schedulerPresent !== unitPresent) {
|
|
705
|
+
const orphan = schedulerPresent ? "timer" : "service";
|
|
706
|
+
const orphanPath = schedulerPresent ? schedulerPath : unitPath;
|
|
707
|
+
warnings.push({ level: "warn", message: `REM nightly orphan ${orphan} file: ${isAdmin ? orphanPath : redactHome(orphanPath)}` });
|
|
708
|
+
}
|
|
709
|
+
if (nightlyInstalled === true) {
|
|
631
710
|
try {
|
|
632
711
|
const { queryActiveStateAsync } = await import("../src/rem/scheduler.js");
|
|
633
712
|
nightlyEnabled = await queryActiveStateAsync(plat);
|
|
713
|
+
if (nightlyEnabled === null)
|
|
714
|
+
probeError(schedulerPath);
|
|
634
715
|
}
|
|
635
|
-
catch {
|
|
716
|
+
catch (error) {
|
|
636
717
|
nightlyEnabled = null;
|
|
718
|
+
probeError(schedulerPath, error);
|
|
719
|
+
}
|
|
720
|
+
try {
|
|
721
|
+
const unitText = await fsp.readFile(unitPath, "utf-8");
|
|
722
|
+
const agent = plat === "darwin"
|
|
723
|
+
? unitText.match(/<key>FLAIR_AGENT_ID<\/key>\s*<string>([^<]+)<\/string>/)?.[1].trim() ?? null
|
|
724
|
+
: systemdAgentId(unitText);
|
|
725
|
+
if (agent) {
|
|
726
|
+
nightlyDriverAgent = agent;
|
|
727
|
+
nightlyDriverAgentKnown = true;
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
catch (error) {
|
|
731
|
+
probeError(unitPath, error);
|
|
637
732
|
}
|
|
638
733
|
}
|
|
639
|
-
else {
|
|
734
|
+
else if (nightlyInstalled === false) {
|
|
640
735
|
nightlyEnabled = false;
|
|
641
736
|
}
|
|
642
737
|
}
|
|
738
|
+
nightlyProbeOk = true;
|
|
643
739
|
const nightlyRecords = await tailJsonl(nightlyLog);
|
|
644
740
|
const lastNightlyRec = nightlyRecords[nightlyRecords.length - 1];
|
|
645
741
|
nightlyRunFailed = lastNightlyRec?.status === "failed";
|
|
646
742
|
const lastNightlyAt = lastNightlyRec ? (lastNightlyRec.at ?? lastNightlyRec.ts ?? lastNightlyRec.timestamp ?? null) : null;
|
|
743
|
+
// Newest distillation from a completed cycle with no errors or skips, observed in the server-local log tail.
|
|
744
|
+
let lastDistilledAt = null;
|
|
745
|
+
const completeDistillation = (rec) => rec?.status === "completed"
|
|
746
|
+
&& !rec.errors?.length && !rec.skips?.length && !rec.distill?.aborted
|
|
747
|
+
&& typeof rec.distilledAt === "string" && Number.isFinite(Date.parse(rec.distilledAt))
|
|
748
|
+
&& Number.isInteger(rec.distill?.gathered) && rec.distill.gathered > 0;
|
|
749
|
+
const lastDistillationIncomplete = !!lastNightlyRec && !completeDistillation(lastNightlyRec);
|
|
750
|
+
for (let i = nightlyRecords.length - 1; i >= 0; i--) {
|
|
751
|
+
const rec = nightlyRecords[i];
|
|
752
|
+
if (completeDistillation(rec)) {
|
|
753
|
+
lastDistilledAt = rec.distilledAt;
|
|
754
|
+
break;
|
|
755
|
+
}
|
|
756
|
+
}
|
|
647
757
|
let pendingCandidates = null;
|
|
648
758
|
try {
|
|
649
759
|
let count = 0;
|
|
@@ -661,6 +771,7 @@ export class HealthDetail extends Resource {
|
|
|
661
771
|
!lastRestorativeAt &&
|
|
662
772
|
nightlyEnabled === null &&
|
|
663
773
|
!lastNightlyAt &&
|
|
774
|
+
!lastDistilledAt &&
|
|
664
775
|
pendingCandidates === null;
|
|
665
776
|
if (allNull) {
|
|
666
777
|
stats.rem = null;
|
|
@@ -672,6 +783,8 @@ export class HealthDetail extends Resource {
|
|
|
672
783
|
lastRestorativeAt,
|
|
673
784
|
nightlyEnabled,
|
|
674
785
|
lastNightlyAt,
|
|
786
|
+
lastDistilledAt,
|
|
787
|
+
lastDistillationIncomplete,
|
|
675
788
|
pendingCandidates,
|
|
676
789
|
};
|
|
677
790
|
if (nightlyEnabled && lastNightlyAt && nowMs - new Date(lastNightlyAt).getTime() > 48 * 3600 * 1000) {
|
|
@@ -687,7 +800,7 @@ export class HealthDetail extends Resource {
|
|
|
687
800
|
}
|
|
688
801
|
// Build this after REM discovery, including its unavailable-state fallback.
|
|
689
802
|
// Health does not read the scheduler's next-run time. The existing audit
|
|
690
|
-
// row does carry status
|
|
803
|
+
// row does carry status.
|
|
691
804
|
if (stats.memories?.expired > 0) {
|
|
692
805
|
const nightlyHint = stats.rem?.nightlyEnabled === true
|
|
693
806
|
? nightlyRunFailed
|
|
@@ -696,9 +809,17 @@ export class HealthDetail extends Resource {
|
|
|
696
809
|
: stats.rem?.nightlyEnabled === false
|
|
697
810
|
? "automate: flair rem nightly enable (includes validTo archival)"
|
|
698
811
|
: "nightly state is unknown — check: flair rem nightly status";
|
|
812
|
+
const driver = {
|
|
813
|
+
installed: nightlyProbeOk ? nightlyInstalled : null,
|
|
814
|
+
agent: nightlyDriverAgent,
|
|
815
|
+
agentKnown: nightlyDriverAgentKnown,
|
|
816
|
+
};
|
|
817
|
+
const breakdown = summarizeExpiredByAgent(expiredAgentCounts, driver);
|
|
818
|
+
stats.memories.expiredByAgent = breakdown;
|
|
699
819
|
warnings.push({
|
|
700
820
|
level: "warn",
|
|
701
821
|
message: `${stats.memories.expired} memories have expired validTo but aren't archived\n` +
|
|
822
|
+
expiredByAgentWarningLines(breakdown) +
|
|
702
823
|
" clear now: flair rem light (archives expired validTo; preview: --dry-run)\n" +
|
|
703
824
|
` ${nightlyHint}`,
|
|
704
825
|
});
|
|
@@ -749,7 +870,21 @@ export class HealthDetail extends Resource {
|
|
|
749
870
|
// didn't run, not merely that it didn't.
|
|
750
871
|
try {
|
|
751
872
|
const migrationsDataDir = resolveMigrationDataDirForRead();
|
|
752
|
-
const
|
|
873
|
+
const rawSnapshot = getMigrationStatusSnapshot(migrationsDataDir);
|
|
874
|
+
const redactReason = (reason) => reason ? "details redacted; consult the operator log or an administrator" : reason;
|
|
875
|
+
const snapshot = isAdmin ? rawSnapshot : {
|
|
876
|
+
...rawSnapshot,
|
|
877
|
+
lastCycleError: redactReason(rawSnapshot.lastCycleError),
|
|
878
|
+
migrations: rawSnapshot.migrations.map((m) => ({
|
|
879
|
+
...m,
|
|
880
|
+
// Row ids are operator detail, like the state-file path below:
|
|
881
|
+
// verified non-admin callers get the count only (flair#2840).
|
|
882
|
+
unconfirmedIds: undefined,
|
|
883
|
+
reason: m.state === "completed" && m.reason
|
|
884
|
+
? "recorded complete; not re-verified this boot"
|
|
885
|
+
: redactReason(m.reason),
|
|
886
|
+
})),
|
|
887
|
+
};
|
|
753
888
|
stats.migrations = {
|
|
754
889
|
cyclePhase: snapshot.cyclePhase,
|
|
755
890
|
lastCycleAt: snapshot.lastCycleAt ?? null,
|
|
@@ -786,6 +921,12 @@ export class HealthDetail extends Resource {
|
|
|
786
921
|
if (m.state === "halted" || m.state === "failed") {
|
|
787
922
|
warnings.push({ level: "warn", message: `migration '${m.id}' ${m.state}${m.reason ? `: ${m.reason}` : ""} — see \`flair doctor\`` });
|
|
788
923
|
}
|
|
924
|
+
else if (m.state === "completed" && (m.rowsUnconfirmed ?? 0) > 0) {
|
|
925
|
+
warnings.push({
|
|
926
|
+
level: "warn",
|
|
927
|
+
message: `migration '${m.id}' completed with ${m.rowsUnconfirmed} row(s) it could not confirm`,
|
|
928
|
+
});
|
|
929
|
+
}
|
|
789
930
|
}
|
|
790
931
|
// The boot trigger sets `scheduled` synchronously at module load, so
|
|
791
932
|
// `idle` here means resources/migration-boot.js never loaded — the
|
|
@@ -33,3 +33,32 @@ export const productionHostPointerAdapter = {
|
|
|
33
33
|
export function currentHostPointerAdapter() {
|
|
34
34
|
return productionHostPointerAdapter;
|
|
35
35
|
}
|
|
36
|
+
export class PointerAlreadyStoredError extends Error {
|
|
37
|
+
pointer;
|
|
38
|
+
constructor(pointer) {
|
|
39
|
+
super("MemoryHostSource replacement already stored");
|
|
40
|
+
this.pointer = pointer;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/** Guard the table put with Harper's commit-time entry and conflict retry. */
|
|
44
|
+
export async function restorePointerRowIfAbsent(row, ctx) {
|
|
45
|
+
const store = pointerTable()?.primaryStore;
|
|
46
|
+
if (!store || typeof ctx?.transaction?.addWrite !== "function") {
|
|
47
|
+
throw new Error("MemoryHostSource conditional restore unavailable");
|
|
48
|
+
}
|
|
49
|
+
const guard = {
|
|
50
|
+
key: row.memoryId,
|
|
51
|
+
store,
|
|
52
|
+
reloadCommitBase: true,
|
|
53
|
+
entry: undefined,
|
|
54
|
+
commit(_time, entry) {
|
|
55
|
+
if (entry?.value)
|
|
56
|
+
throw new PointerAlreadyStoredError(entry.value);
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
ctx.transaction.addWrite(guard);
|
|
60
|
+
// Distinguish a read absence from an entry Harper's save() has not read yet.
|
|
61
|
+
if (guard.entry === undefined)
|
|
62
|
+
guard.entry = null;
|
|
63
|
+
await currentHostPointerAdapter().putPointerRow(row, ctx);
|
|
64
|
+
}
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
* Production behaviour is the real table.
|
|
8
8
|
*/
|
|
9
9
|
import { currentHostPointerAdapter } from "./host-pointer/registry.js";
|
|
10
|
+
export { PointerAlreadyStoredError, restorePointerRowIfAbsent } from "./host-pointer/registry.js";
|
|
10
11
|
export function putPointerRow(row, ctx) {
|
|
11
12
|
return currentHostPointerAdapter().putPointerRow(row, ctx);
|
|
12
13
|
}
|
|
@@ -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
|
|
@@ -44,15 +44,17 @@
|
|
|
44
44
|
*
|
|
45
45
|
* resolveAgentAuth({ request: { tpsAgent: undefined } }) -> { kind: "internal" }
|
|
46
46
|
* resolveAgentAuth({ request: { tpsAgent: "" } }) -> { kind: "internal" }
|
|
47
|
-
* allowAdmin({ request: { tpsAgent: undefined } }) ->
|
|
47
|
+
* allowAdmin({ request: { tpsAgent: undefined } }) -> false
|
|
48
48
|
*
|
|
49
49
|
* `resolveAgentAuth` tests `tpsAgent` for TRUTHINESS, so a missing or empty id
|
|
50
50
|
* is indistinguishable from "no identity was supplied at all" — and that is the
|
|
51
51
|
* trusted verdict. The consequence is that the most ordinary application bug
|
|
52
52
|
* there is — `agentContext(session.agentId)` where the field is undefined, a
|
|
53
|
-
* typo'd property, a lookup that found nothing — would not fail closed
|
|
54
|
-
*
|
|
55
|
-
*
|
|
53
|
+
* typo'd property, a lookup that found nothing — would not fail closed: the
|
|
54
|
+
* agent-facing gate (`allowVerified`) admits the `internal` verdict, and a
|
|
55
|
+
* `Memory` read with it is unfiltered. The admin-only gate refuses it:
|
|
56
|
+
* `allowAdmin` admits the `internal` verdict only for a call that carries
|
|
57
|
+
* `internalContext()`'s marker and no request headers.
|
|
56
58
|
*
|
|
57
59
|
* That is the same defect class as a check that cannot fail: **the failure mode
|
|
58
60
|
* of "I forgot the id" must never be "you are now an administrator."** So:
|
|
@@ -73,7 +75,7 @@
|
|
|
73
75
|
*
|
|
74
76
|
* These guards are runtime, not types, on purpose: an embedding application may
|
|
75
77
|
* be plain JavaScript, where a `string` parameter annotation buys exactly
|
|
76
|
-
* nothing. test/integration/in-process-agents.test.ts pins both the guards and
|
|
78
|
+
* nothing. test/integration-heavy/in-process-agents.test.ts pins both the guards and
|
|
77
79
|
* the hazard they exist for, against a real Harper.
|
|
78
80
|
*
|
|
79
81
|
* ── Deliberately dependency-free ─────────────────────────────────────────────
|
|
@@ -103,9 +105,8 @@ function requireAgentId(agentId, fnName) {
|
|
|
103
105
|
: "a blank string";
|
|
104
106
|
throw new InProcessContextError(`${fnName}() requires a non-empty agent id, but received ${got}. ` +
|
|
105
107
|
"This is refused rather than defaulted because flair resolves a missing or empty " +
|
|
106
|
-
"tpsAgent to its trusted `internal` verdict, which
|
|
107
|
-
"
|
|
108
|
-
"turned a missing id into silent administrator access. Resolve the agent id from your " +
|
|
108
|
+
"tpsAgent to its trusted `internal` verdict, which can keep UNFILTERED access on " +
|
|
109
|
+
"agent-facing paths. Resolve the agent id from your " +
|
|
109
110
|
"own server-side state before calling, and never from request data.");
|
|
110
111
|
}
|
|
111
112
|
return agentId;
|
|
@@ -175,15 +176,14 @@ export function adminContext(agentId) {
|
|
|
175
176
|
*
|
|
176
177
|
* This exists for work that is genuinely infrastructure rather than an agent's:
|
|
177
178
|
* provisioning a principal, a migration, a maintenance sweep. It is the same
|
|
178
|
-
* verdict
|
|
179
|
-
*
|
|
180
|
-
*
|
|
181
|
-
* that authority deliberately.
|
|
179
|
+
* `internal` verdict that `resolveAgentAuth(undefined)` returns, and
|
|
180
|
+
* `git grep internalContext` finds textual references to this helper's name in
|
|
181
|
+
* tracked files.
|
|
182
182
|
*
|
|
183
183
|
* There is no id to validate: the verdict comes precisely from the ABSENCE of
|
|
184
|
-
* an identity annotation, so the returned object carries none. The
|
|
185
|
-
*
|
|
186
|
-
*
|
|
184
|
+
* an identity annotation, so the returned object carries none. The admin-only
|
|
185
|
+
* gate reads its marker: `allowAdmin` admits the `internal` verdict only for a
|
|
186
|
+
* call that carries it and no request headers.
|
|
187
187
|
*
|
|
188
188
|
* ```ts
|
|
189
189
|
* // Registering a principal — infrastructure, not an agent's own write.
|
|
@@ -210,13 +210,15 @@ export function internalContext() {
|
|
|
210
210
|
* start their own transaction.
|
|
211
211
|
*
|
|
212
212
|
* **They do still need the CONTEXT.** Only the collection binding is
|
|
213
|
-
* unnecessary for a read, not the identity. `Cls.search(query)` with
|
|
214
|
-
*
|
|
215
|
-
*
|
|
216
|
-
*
|
|
217
|
-
*
|
|
218
|
-
*
|
|
219
|
-
*
|
|
213
|
+
* unnecessary for a read, not the identity. `Cls.search(query)` with no explicit
|
|
214
|
+
* or ambient context resolves to the trusted `internal` verdict. The query's
|
|
215
|
+
* conditions still narrow the rows, but no agent scope applies: every agent's
|
|
216
|
+
* matching records, `private` included, are returned. With the resulting `{}`
|
|
217
|
+
* context and no `query.checkPermission`, no permission check is requested
|
|
218
|
+
* (no `context.authorize`), so `allowRead` is never consulted. Memory's
|
|
219
|
+
* `allowRead` -> `memoryAuthGate` -> `allowVerified` would admit this `internal`
|
|
220
|
+
* call even if consulted. Pass the context to every call, read or write
|
|
221
|
+
* (flair#936).
|
|
220
222
|
*/
|
|
221
223
|
export async function collectionResource(Cls, context) {
|
|
222
224
|
if (context == null || typeof context !== "object") {
|
|
@@ -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
|