@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
|
@@ -2,7 +2,7 @@ import { Resource, databases } from "harper";
|
|
|
2
2
|
import { allowVerified, resolveAgentAuth } from "./agent-auth.js";
|
|
3
3
|
import { getEmbedding } from "./embeddings-provider.js";
|
|
4
4
|
import { wrapUntrusted } from "./content-safety.js";
|
|
5
|
-
import { isTeammate,
|
|
5
|
+
import { isTeammate, directoryHint, isZeroRowNoOpEvent } from "./memory-bootstrap-lib.js";
|
|
6
6
|
import { resolveReadScope } from "./memory-read-scope.js";
|
|
7
7
|
import { isValidEntity } from "./entity-vocab.js";
|
|
8
8
|
import { withDetachedTxn, withDetachedTxnAsync } from "./table-helpers.js";
|
|
@@ -16,7 +16,10 @@ import { buildCollisionEntries, buildEntityMatchCondition, freshPresenceByAgent,
|
|
|
16
16
|
// semantic-retrieval-core.ts's module doc for the full boundary).
|
|
17
17
|
import { retrieveCandidates, DEFAULT_SELECT } from "./semantic-retrieval-core.js";
|
|
18
18
|
import { retrievalMode } from "./bm25.js";
|
|
19
|
+
import { embeddingSpaceVerdict, spaceGuardWarning } from "./embedding-space-guard.js";
|
|
19
20
|
import { buildTrustBlock } from "./trust-block.js";
|
|
21
|
+
import { projectRowsThroughPointers } from "./memory-host-source.js";
|
|
22
|
+
import { formatHostSourceCitation } from "./host-source-citation.js";
|
|
20
23
|
import { bestSemanticSimilarity, evaluateAbstention } from "./abstention.js";
|
|
21
24
|
import { estimateTokens } from "./token-estimate.js";
|
|
22
25
|
import { initialPosition, ORG_EVENT_STREAM } from "./agent-read-position-lib.js";
|
|
@@ -26,6 +29,7 @@ import { SKILL_ASSIGNMENT_KEY } from "./skill-provenance.js";
|
|
|
26
29
|
import { SKILL_TAG } from "./skill-write.js";
|
|
27
30
|
import { SKILL_ROW_SELECT, receivesOrgSkills, resolvableSkillRows, resolveSkillManifest, skillLine, } from "./skill-manifest.js";
|
|
28
31
|
import { localInstanceId } from "./instance-identity.js";
|
|
32
|
+
import { RESERVED_EVENT_KINDS } from "./org-event-reserved.js";
|
|
29
33
|
/**
|
|
30
34
|
* POST /MemoryBootstrap
|
|
31
35
|
*
|
|
@@ -267,16 +271,14 @@ const MAX_CANDIDATE_POOL = 100;
|
|
|
267
271
|
// record's own agentId differs from the bootstrapping agent), so
|
|
268
272
|
// `m._source !== agentId` is the "is this a teammate's finding" check; own
|
|
269
273
|
// memories never carry `_source` at all.
|
|
270
|
-
function formatMemory(m, agentId) {
|
|
271
|
-
// flair#1940
|
|
272
|
-
// The pointer lives in MemoryHostSource and is joined only into Memory.get/
|
|
273
|
-
// search/SemanticSearch results; the bootstrap citation (A6) arrives in slice
|
|
274
|
-
// 4. So this surface leaves the record unchanged.
|
|
274
|
+
export function formatMemory(m, agentId) {
|
|
275
|
+
// flair#1940 A6: when the gated pointer join ran, `m.hostSource` is its output.
|
|
275
276
|
const tag = m.durability === "permanent" ? "🔒" : m.durability === "persistent" ? "📌" : "📝";
|
|
276
277
|
const date = m.createdAt ? ` (${m.createdAt.slice(0, 10)})` : "";
|
|
277
278
|
const chain = m.supersedes ? " [supersedes earlier decision]" : "";
|
|
278
279
|
const attribution = m._source && m._source !== agentId ? `[via ${m._source}] ` : "";
|
|
279
|
-
const
|
|
280
|
+
const citation = formatHostSourceCitation(m.hostSource);
|
|
281
|
+
const base = `${tag} ${attribution}${m.content}${date}${chain}${citation ? ` ${citation}` : ""}`;
|
|
280
282
|
// Wrap flagged memories in safety delimiters — composes with attribution
|
|
281
283
|
// above (attribution is baked into `base` before wrapping, so a flagged
|
|
282
284
|
// teammate memory renders with BOTH the "[via <agent>]" tag and the
|
|
@@ -301,11 +303,8 @@ export class BootstrapMemories extends Resource {
|
|
|
301
303
|
includeTrust = false, // flair#744 slice 1 — opt-in per-memory trust block
|
|
302
304
|
abstain = false, // flair#744 slice 2 — opt-in task-relevance abstention
|
|
303
305
|
// flair#1199 — org-event knobs. `maxEvents` caps how many events ship
|
|
304
|
-
// (default MAX_ORG_EVENTS); `includeEventDetail` gates
|
|
305
|
-
// `detail` JSON (default OFF
|
|
306
|
-
// default bootstrap ships LEAN events (id/kind/summary/createdAt/targetIds/
|
|
307
|
-
// scope); `detail` restates the summary + migration internals and is pure
|
|
308
|
-
// bloat for a connector, so it is opt-in. Both are also counted against the
|
|
306
|
+
// (default MAX_ORG_EVENTS); `includeEventDetail` gates ordinary event
|
|
307
|
+
// `detail` JSON (default OFF). Events are counted against the
|
|
309
308
|
// shared tokenBudget below (before #1199 the events array was assembled but
|
|
310
309
|
// NEVER charged, so a maxTokens=4000 request serialized well past budget).
|
|
311
310
|
maxEvents, includeEventDetail = false,
|
|
@@ -459,6 +458,17 @@ export class BootstrapMemories extends Resource {
|
|
|
459
458
|
let eventWatermark = null;
|
|
460
459
|
let eventsHasMore = false;
|
|
461
460
|
let eventsRemaining = 0;
|
|
461
|
+
// flair#2448 item 3 (decision) — the STRUCTURED container deliberately
|
|
462
|
+
// carries NO host-source pointer: no `hostSource`, `hostSourceScope` or
|
|
463
|
+
// `hostSourceVisibility`. The pointer is a citation aid for the agent-facing
|
|
464
|
+
// RENDERED bootstrap (formatMemory's prose line); a non-admin structured
|
|
465
|
+
// consumer that needs the pointer reads the memory back through the gated
|
|
466
|
+
// Memory read (memory_get by id), which renders the pointer that caller may
|
|
467
|
+
// see. An admin Memory read takes no pointer join (Memory.ts), so it does not
|
|
468
|
+
// render the pointer either. The admin
|
|
469
|
+
// bootstrap's containers fall under the same rule (see hostSourceReader
|
|
470
|
+
// below). A test pins those three pointer fields absent here, so adding one
|
|
471
|
+
// is a deliberate change.
|
|
462
472
|
const leanMemory = (m, section) => ({
|
|
463
473
|
id: m.id,
|
|
464
474
|
content: m.content,
|
|
@@ -499,6 +509,34 @@ export class BootstrapMemories extends Resource {
|
|
|
499
509
|
// selector tests against maxTokens is now the figure that becomes
|
|
500
510
|
// `tokenEstimate` on each path.
|
|
501
511
|
const contentCost = (structured, proseLine) => includeContext ? estimateTokens(proseLine) : estimateTokens(JSON.stringify(structured));
|
|
512
|
+
// flair#1940 A3/A6 (slice 2b) — the gated pointer join for the prose surface.
|
|
513
|
+
// A non-admin caller sees a bound pointer only through the join: their OWN
|
|
514
|
+
// records render their pointer, a teammate's author-only pointer renders
|
|
515
|
+
// `"withheld"` (A3), and everything else is unchanged. An admin/operator
|
|
516
|
+
// bootstrap stays unfiltered and takes no join — the same exception the
|
|
517
|
+
// named read surfaces take. ONE batched pointer query per row set, never
|
|
518
|
+
// one per row. The retrieved rows (DEFAULT_SELECT) carry every binding field
|
|
519
|
+
// (`agentId`, `instanceToken`, `visibility`, `archived`). The own-record
|
|
520
|
+
// sections (OWN_SELECT) carry `agentId` and `instanceToken` only: their query
|
|
521
|
+
// already excludes archived rows, and the reader is the author, so the author
|
|
522
|
+
// outcome never reads `visibility`.
|
|
523
|
+
// flair#2448 item 3 (decision) — an admin bootstrap takes no join, and the
|
|
524
|
+
// structured containers are built without the pointer (see leanMemory), so
|
|
525
|
+
// neither the admin prose nor any structured container carries the host
|
|
526
|
+
// source. A non-admin structured consumer that needs the pointer reads the
|
|
527
|
+
// memory back through the gated Memory read (memory_get by id); an admin
|
|
528
|
+
// Memory read takes no pointer join, so it does not render the pointer.
|
|
529
|
+
const hostSourceReader = authenticatedAgent && !callerIsAdmin ? authenticatedAgent : undefined;
|
|
530
|
+
const pointerRenders = async (rows) => {
|
|
531
|
+
const map = new Map();
|
|
532
|
+
if (!hostSourceReader || rows.length === 0)
|
|
533
|
+
return map;
|
|
534
|
+
for (const row of await projectRowsThroughPointers(rows, hostSourceReader)) {
|
|
535
|
+
if (row && typeof row.id === "string")
|
|
536
|
+
map.set(row.id, row);
|
|
537
|
+
}
|
|
538
|
+
return map;
|
|
539
|
+
};
|
|
502
540
|
// --- 1. Soul records (budgeted — prioritized by key importance) ---
|
|
503
541
|
// Soul is who you are, but we still need to respect token budgets.
|
|
504
542
|
// Workspace files (SOUL.md, AGENTS.md) can be massive — they're already
|
|
@@ -602,17 +640,29 @@ export class BootstrapMemories extends Resource {
|
|
|
602
640
|
const org = { assignments: [], rows: [], instanceId: null };
|
|
603
641
|
if (orgRows.length > 0
|
|
604
642
|
&& receivesOrgSkills(await withDetachedTxnAsync(ctx, () => databases.flair.Agent.get(agentId)))) {
|
|
605
|
-
const refRows =
|
|
643
|
+
const refRows = new Map();
|
|
644
|
+
org.refSubjects = new Map();
|
|
606
645
|
for (const ref of new Set(orgRows.map((row) => row.skillRef).filter((ref) => typeof ref === "string"))) {
|
|
646
|
+
const referenced = await withDetachedTxnAsync(ctx, () => databases.flair.Memory.get(ref));
|
|
647
|
+
const subject = referenced && Array.isArray(referenced.tags) && referenced.tags.includes(SKILL_TAG)
|
|
648
|
+
&& typeof referenced.skillSubjectId === "string" && referenced.skillSubjectId.length > 0
|
|
649
|
+
? referenced.skillSubjectId : ref;
|
|
650
|
+
org.refSubjects.set(ref, subject);
|
|
607
651
|
const refQuery = withDetachedTxn(ctx, () => databases.flair.Memory.search({
|
|
608
|
-
conditions: [{
|
|
652
|
+
conditions: [{
|
|
653
|
+
operator: "or",
|
|
654
|
+
conditions: [
|
|
655
|
+
{ attribute: "id", comparator: "equals", value: ref },
|
|
656
|
+
{ attribute: "skillSubjectId", comparator: "equals", value: subject },
|
|
657
|
+
],
|
|
658
|
+
}],
|
|
609
659
|
select: SKILL_ROW_SELECT,
|
|
610
660
|
}));
|
|
611
661
|
for await (const record of refQuery)
|
|
612
|
-
refRows.
|
|
662
|
+
refRows.set(record.id, record);
|
|
613
663
|
}
|
|
614
664
|
org.assignments = orgRows;
|
|
615
|
-
org.rows = resolvableSkillRows(refRows, scope.isAllowed);
|
|
665
|
+
org.rows = resolvableSkillRows([...refRows.values()], scope.isAllowed);
|
|
616
666
|
org.instanceId = await localInstanceId();
|
|
617
667
|
}
|
|
618
668
|
if (skillAssignments.length > 0 || org.assignments.length > 0) {
|
|
@@ -676,8 +726,8 @@ export class BootstrapMemories extends Resource {
|
|
|
676
726
|
if (isTeammate(record, agentId))
|
|
677
727
|
teammateIds.push(record.id);
|
|
678
728
|
}
|
|
679
|
-
const line =
|
|
680
|
-
if (
|
|
729
|
+
const line = directoryHint();
|
|
730
|
+
if (teammateIds.length > 0)
|
|
681
731
|
sections.team.push(line);
|
|
682
732
|
}
|
|
683
733
|
catch {
|
|
@@ -743,9 +793,13 @@ export class BootstrapMemories extends Resource {
|
|
|
743
793
|
// #1201 — `updatedAt` is projected on BOTH paths (not just the trust path):
|
|
744
794
|
// the structured `memories`/`predicted` containers carry it so a consumer
|
|
745
795
|
// can compute freshness, and the trust block's ageDays keys off it.
|
|
796
|
+
// flair#1940 A3 (slice 2b): `instanceToken` is projected on BOTH branches so
|
|
797
|
+
// the gated pointer join can bind a pointer to the row's current
|
|
798
|
+
// incarnation; it is a join input only (leanMemory/formatMemory never emit
|
|
799
|
+
// it), so the response bytes are unchanged.
|
|
746
800
|
const OWN_SELECT = includeTrust
|
|
747
|
-
? ["id", "agentId", "content", "durability", "createdAt", "updatedAt", "supersedes", "subject", "validTo", "expiresAt", "_safetyFlags", "provenance", "usageCount", "validFrom"]
|
|
748
|
-
: ["id", "agentId", "content", "durability", "createdAt", "updatedAt", "supersedes", "subject", "validTo", "expiresAt", "_safetyFlags"];
|
|
801
|
+
? ["id", "agentId", "content", "durability", "createdAt", "updatedAt", "supersedes", "subject", "validTo", "expiresAt", "_safetyFlags", "instanceToken", "provenance", "usageCount", "validFrom"]
|
|
802
|
+
: ["id", "agentId", "content", "durability", "createdAt", "updatedAt", "supersedes", "subject", "validTo", "expiresAt", "_safetyFlags", "instanceToken"];
|
|
749
803
|
// flair#744 slice 1 — the Memory records that became visible lines in the
|
|
750
804
|
// memory-bearing sections (permanent/recent/predicted/relevant/teammate),
|
|
751
805
|
// collected as they're added so the opt-in `trust` array below can carry a
|
|
@@ -772,6 +826,11 @@ export class BootstrapMemories extends Resource {
|
|
|
772
826
|
: 0;
|
|
773
827
|
tokenBudget -= taskReserve;
|
|
774
828
|
let taskRetrievalHint;
|
|
829
|
+
// flair#2559 — the guard verdict when the task-relevant selection's
|
|
830
|
+
// embedding leg was refused (a non-uniform verdict). Declared here so the
|
|
831
|
+
// response tail can surface the state-named warning; set inside the
|
|
832
|
+
// task-relevant block below.
|
|
833
|
+
let spaceGuardVerdict = null;
|
|
775
834
|
// --- 2. Permanent memories ---
|
|
776
835
|
// Own-scoped pushdown: `agentId==self` + `durability==permanent`, both
|
|
777
836
|
// @indexed (a seek, not a scan) — strictly narrower than the prior
|
|
@@ -818,8 +877,9 @@ export class BootstrapMemories extends Resource {
|
|
|
818
877
|
if (m.supersedes)
|
|
819
878
|
permanentSupersededIds.add(m.supersedes);
|
|
820
879
|
const permanent = permanentRows.filter((m) => !permanentSupersededIds.has(m.id));
|
|
880
|
+
const permanentPtr = await pointerRenders(permanent);
|
|
821
881
|
const admitPermanent = (m) => {
|
|
822
|
-
const line = formatMemory(m, agentId);
|
|
882
|
+
const line = formatMemory(permanentPtr.get(m.id) ?? m, agentId);
|
|
823
883
|
const struct = leanMemory(m, "permanent");
|
|
824
884
|
// #1199 (0.44.11) — charge what SHIPS (structured on the /mcp path, prose
|
|
825
885
|
// on the REST path); see contentCost. #1207 stays honored: on the prose
|
|
@@ -902,8 +962,9 @@ export class BootstrapMemories extends Resource {
|
|
|
902
962
|
// Budget: up to 40% of remaining for recent
|
|
903
963
|
const recentBudget = Math.floor(tokenBudget * 0.4);
|
|
904
964
|
let recentSpent = 0;
|
|
965
|
+
const recentPtr = await pointerRenders(recent);
|
|
905
966
|
for (const m of recent) {
|
|
906
|
-
const line = formatMemory(m, agentId);
|
|
967
|
+
const line = formatMemory(recentPtr.get(m.id) ?? m, agentId);
|
|
907
968
|
const struct = leanMemory(m, "recent");
|
|
908
969
|
const cost = contentCost(struct, line); // #1199 (0.44.11) — charge what ships; see contentCost
|
|
909
970
|
// flair#1199 trust-admission — charge the trust block's real serialized
|
|
@@ -950,8 +1011,9 @@ export class BootstrapMemories extends Resource {
|
|
|
950
1011
|
.sort((a, b) => (b.createdAt || "").localeCompare(a.createdAt || ""));
|
|
951
1012
|
const predictedBudget = Math.floor(tokenBudget * 0.3);
|
|
952
1013
|
let predictedSpent = 0;
|
|
1014
|
+
const predictedPtr = await pointerRenders(subjectMemories);
|
|
953
1015
|
for (const m of subjectMemories) {
|
|
954
|
-
const line = formatMemory(m, agentId);
|
|
1016
|
+
const line = formatMemory(predictedPtr.get(m.id) ?? m, agentId);
|
|
955
1017
|
const struct = leanMemory(m, "predicted");
|
|
956
1018
|
const cost = contentCost(struct, line); // #1199 (0.44.11) — charge what ships; see contentCost
|
|
957
1019
|
// flair#1199 trust-admission — charge the trust block's real serialized
|
|
@@ -1018,7 +1080,6 @@ export class BootstrapMemories extends Resource {
|
|
|
1018
1080
|
if (currentTask && tokenBudget <= 0)
|
|
1019
1081
|
taskRetrievalHint = "Task retrieval skipped: no content budget remains.";
|
|
1020
1082
|
if (currentTask && tokenBudget > 0) {
|
|
1021
|
-
// Resolve the mode ONCE here so the embedding guard and the core agree.
|
|
1022
1083
|
// The bm25-only arm ranks on the lexical leg alone and needs NO query
|
|
1023
1084
|
// embedding — gating it on one being available would skip the lexical
|
|
1024
1085
|
// search entirely and lose task-relevant memories for no reason.
|
|
@@ -1032,9 +1093,26 @@ export class BootstrapMemories extends Resource {
|
|
|
1032
1093
|
}
|
|
1033
1094
|
catch { }
|
|
1034
1095
|
}
|
|
1035
|
-
|
|
1096
|
+
// ─── Vector-space uniformity guard (flair#2559) ────────────────────
|
|
1097
|
+
// Consult the SAME chokepoint SemanticSearch uses (embeddingSpaceVerdict()):
|
|
1098
|
+
// when the store's model stamps are not KNOWN uniform in the current
|
|
1099
|
+
// embedding space — a non-current stamp observed, or an unknown verdict
|
|
1100
|
+
// (before the first scan, or after a scan error) — cosining the task
|
|
1101
|
+
// embedding against stored vectors could cross spaces. Fails CLOSED: the
|
|
1102
|
+
// embedding leg is refused and the selection degrades to its non-vector
|
|
1103
|
+
// (lexical) path, with the SAME state-named warning SemanticSearch emits.
|
|
1104
|
+
// Consulted only when a query embedding is available (outside bm25-only,
|
|
1105
|
+
// which ignores any query embedding).
|
|
1106
|
+
if (queryEmbedding) {
|
|
1107
|
+
const verdict = await embeddingSpaceVerdict();
|
|
1108
|
+
if (!verdict.uniform) {
|
|
1109
|
+
queryEmbedding = null;
|
|
1110
|
+
spaceGuardVerdict = verdict;
|
|
1111
|
+
}
|
|
1112
|
+
}
|
|
1113
|
+
if (mode !== "bm25-only" && !queryEmbedding && !spaceGuardVerdict)
|
|
1036
1114
|
taskRetrievalHint = "Task retrieval skipped: query embedding unavailable.";
|
|
1037
|
-
if (mode === "bm25-only" || queryEmbedding) {
|
|
1115
|
+
if (mode === "bm25-only" || queryEmbedding || spaceGuardVerdict) {
|
|
1038
1116
|
// flair#1207 — exclude own memories ALREADY placed via the authoritative
|
|
1039
1117
|
// set (permanent + recent + predicted actually admitted). The old set was
|
|
1040
1118
|
// built positionally (recent.filter by index) AND omitted `predicted`, so
|
|
@@ -1057,23 +1135,7 @@ export class BootstrapMemories extends Resource {
|
|
|
1057
1135
|
queryEmbedding,
|
|
1058
1136
|
conditions: [scope.condition, { attribute: "archived", comparator: "not_equal", value: true }],
|
|
1059
1137
|
limit: candidatePoolK,
|
|
1060
|
-
|
|
1061
|
-
// core in the SAME mode memory_search does (hybrid + q via the
|
|
1062
|
-
// shared retrievalMode() selector, so the FLAIR_RETRIEVAL_MODE /
|
|
1063
|
-
// FLAIR_HYBRID_RETRIEVAL kill-switch moves BOTH surfaces together —
|
|
1064
|
-
// a split mode IS the #1246 bug). HNSW-only here was an accident of early code, and it
|
|
1065
|
-
// made bootstrap's teammate picks diverge from search on the same
|
|
1066
|
-
// store+query: a record whose task-relevance is LEXICAL (exact task
|
|
1067
|
-
// terms in semantically-atypical prose) ranks BELOW bland-generic
|
|
1068
|
-
// noise on pure cosine (measured at N=21: on-task 0.5656 vs noise
|
|
1069
|
-
// 0.6086 — HNSW rank 6 while search fused it to rank 1), and at
|
|
1070
|
-
// field scale (corpus >> candidatePoolK) that inversion becomes
|
|
1071
|
-
// exclusion from the K-bounded pool entirely. The BM25 leg is the
|
|
1072
|
-
// rescue: it admits the record at lexical rank 1 and union-RRF
|
|
1073
|
-
// fusion carries it to the top, same as search. Perf (Kern-ratified
|
|
1074
|
-
// trade): the BM25 corpus scan this adds to the bootstrap path is
|
|
1075
|
-
// the same per-call scan every memory_search request already runs.
|
|
1076
|
-
mode,
|
|
1138
|
+
mode: spaceGuardVerdict && mode === "vector-only" ? "bm25-only" : mode,
|
|
1077
1139
|
// The lexical leg — same query text the embedding was computed
|
|
1078
1140
|
// from, so both legs rank the same question (parity with search,
|
|
1079
1141
|
// where `q` drives BM25 and the keyword bump).
|
|
@@ -1139,6 +1201,7 @@ export class BootstrapMemories extends Resource {
|
|
|
1139
1201
|
const scored = candidates
|
|
1140
1202
|
.filter((m) => !includedIds.has(m.id))
|
|
1141
1203
|
.map((m) => ({ memory: m, score: m._score }));
|
|
1204
|
+
const retrievedPtr = await pointerRenders(scored.map((s) => s.memory));
|
|
1142
1205
|
// flair#681: the collision block's semantic surface — one candidate
|
|
1143
1206
|
// per teammate (`scored` is sorted best-first by the fused retrieval
|
|
1144
1207
|
// rank, so the first occurrence of a given `_source` IS that
|
|
@@ -1164,7 +1227,7 @@ export class BootstrapMemories extends Resource {
|
|
|
1164
1227
|
// budget regardless of which section they land in, so neither
|
|
1165
1228
|
// section double-spends.
|
|
1166
1229
|
for (const { memory: m } of scored) {
|
|
1167
|
-
const line = formatMemory(m, agentId);
|
|
1230
|
+
const line = formatMemory(retrievedPtr.get(m.id) ?? m, agentId);
|
|
1168
1231
|
// flair#1199 (0.44.11) — build the STRUCTURED container object BEFORE
|
|
1169
1232
|
// the budget check so the finding is charged the cost of what actually
|
|
1170
1233
|
// ships (structured on the /mcp path), not its cheaper prose line. A
|
|
@@ -1396,7 +1459,7 @@ export class BootstrapMemories extends Resource {
|
|
|
1396
1459
|
...(seekTs
|
|
1397
1460
|
? { conditions: [{ attribute: "createdAt", comparator: "greater_than_equal", value: seekTs }] }
|
|
1398
1461
|
: {}),
|
|
1399
|
-
select: ["id", "kind", "summary", "detail", "targetIds", "createdAt", "expiresAt", "scope"],
|
|
1462
|
+
select: ["id", "kind", "summary", "detail", "targetIds", "createdAt", "expiresAt", "scope", "refId"],
|
|
1400
1463
|
}));
|
|
1401
1464
|
for await (const event of recentEvents) {
|
|
1402
1465
|
if (!isCatchupEligible(event, { participantId: agentId, after: eventWatermark, since: sinceFloor }))
|
|
@@ -1412,18 +1475,11 @@ export class BootstrapMemories extends Resource {
|
|
|
1412
1475
|
continue;
|
|
1413
1476
|
eventResults.push(event);
|
|
1414
1477
|
}
|
|
1415
|
-
// flair#1200 —
|
|
1416
|
-
//
|
|
1417
|
-
// that double-fires, or the same broadcast emitted from two paths); each
|
|
1418
|
-
// physical row has a distinct id/createdAt (OrgEvent.post keys the id off
|
|
1419
|
-
// a millisecond timestamp), so they aren't caught by primary-key upsert
|
|
1420
|
-
// and render as exact dupes. Org-event slots are scarce, so dedup BEFORE
|
|
1421
|
-
// admission — otherwise ~half the slots are wasted on duplicates. Keyed on
|
|
1422
|
-
// the CONTENT (kind + summary + detail + targets), keeping the most-recent
|
|
1423
|
-
// occurrence per signature.
|
|
1478
|
+
// flair#1200 — dedup before admission, keeping the most recent occurrence.
|
|
1479
|
+
// Instruction events use version refs; other events use content.
|
|
1424
1480
|
const eventBySignature = new Map();
|
|
1425
1481
|
for (const evt of eventResults) {
|
|
1426
|
-
const sig = JSON.stringify([
|
|
1482
|
+
const sig = JSON.stringify(RESERVED_EVENT_KINDS.includes(evt.kind) ? ["instruction", evt.refId] : [
|
|
1427
1483
|
evt.kind ?? "",
|
|
1428
1484
|
evt.summary ?? "",
|
|
1429
1485
|
evt.detail ?? "",
|
|
@@ -1439,7 +1495,7 @@ export class BootstrapMemories extends Resource {
|
|
|
1439
1495
|
// NEVER charged: a maxTokens=4000 request serialized at 6286 (+57%), the
|
|
1440
1496
|
// bulk being 10 events each shipping a `detail` JSON. Now each event's
|
|
1441
1497
|
// REAL serialized cost (the structured object that actually ships — lean by
|
|
1442
|
-
// default, `detail`
|
|
1498
|
+
// default, ordinary `detail` under includeEventDetail) is charged against the
|
|
1443
1499
|
// remaining budget, so events respect maxTokens the same way every other
|
|
1444
1500
|
// content section does. An event that doesn't fit is skipped, not silently
|
|
1445
1501
|
// over-budget; smaller later events may still fit (hence continue, not
|
|
@@ -1454,18 +1510,17 @@ export class BootstrapMemories extends Resource {
|
|
|
1454
1510
|
eventsRemaining++;
|
|
1455
1511
|
continue;
|
|
1456
1512
|
}
|
|
1457
|
-
// The structured object a connector actually reads (flair#1206).
|
|
1458
|
-
|
|
1459
|
-
// JSON) only when explicitly requested. Optional fields are omitted when
|
|
1460
|
-
// absent so the object stays compact.
|
|
1513
|
+
// The structured object a connector actually reads (flair#1206).
|
|
1514
|
+
const instructionEvent = RESERVED_EVENT_KINDS.includes(evt.kind);
|
|
1461
1515
|
const structured = {
|
|
1462
1516
|
id: evt.id,
|
|
1463
1517
|
kind: evt.kind,
|
|
1464
1518
|
summary: evt.summary,
|
|
1465
|
-
...(includeEventDetail && evt.detail != null ? { detail: evt.detail } : {}),
|
|
1519
|
+
...((includeEventDetail || instructionEvent) && evt.detail != null ? { detail: evt.detail } : {}),
|
|
1466
1520
|
...(Array.isArray(evt.targetIds) && evt.targetIds.length > 0 ? { targetIds: evt.targetIds } : {}),
|
|
1467
1521
|
createdAt: evt.createdAt ?? null,
|
|
1468
1522
|
...(evt.scope != null ? { scope: evt.scope } : {}),
|
|
1523
|
+
...(instructionEvent && evt.refId != null ? { refId: evt.refId } : {}),
|
|
1469
1524
|
};
|
|
1470
1525
|
// Charge the REAL serialized cost of what ships (structured object on the
|
|
1471
1526
|
// /mcp path; the prose line is a subset of it). This is the #1199 fix:
|
|
@@ -1739,6 +1794,11 @@ export class BootstrapMemories extends Resource {
|
|
|
1739
1794
|
// never absent, so "empty" is distinguishable from "unsupported").
|
|
1740
1795
|
agentId,
|
|
1741
1796
|
...(taskRetrievalHint ? { taskRetrievalHint } : {}),
|
|
1797
|
+
// flair#2559 — the task-relevant selection refused its embedding leg for a
|
|
1798
|
+
// non-uniform verdict; the warning names the guard state (same wording as
|
|
1799
|
+
// SemanticSearch's `_warning`).
|
|
1800
|
+
...(spaceGuardVerdict ? { _warning: spaceGuardWarning(spaceGuardVerdict, "keyword") } : {}),
|
|
1801
|
+
directoryHint: directoryHint(),
|
|
1742
1802
|
scope: scopeInfo,
|
|
1743
1803
|
soul: soulMap,
|
|
1744
1804
|
// flair#2141 S1b — always present (`[]` when none), whatever includeSoul
|
|
@@ -1775,6 +1835,7 @@ export class BootstrapMemories extends Resource {
|
|
|
1775
1835
|
sections: {
|
|
1776
1836
|
soul: sections.soul.length,
|
|
1777
1837
|
skills: sections.skills.length,
|
|
1838
|
+
// Fixed directory hint when a roster exists.
|
|
1778
1839
|
team: sections.team.length,
|
|
1779
1840
|
permanent: sections.permanent.length,
|
|
1780
1841
|
recent: sections.recent.length,
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { databases } from "harper";
|
|
2
2
|
import { resolveAgentAuth } from "./agent-auth.js";
|
|
3
3
|
import { guardOwnerFieldImmutable } from "./owner-field-guard.js";
|
|
4
|
+
import { guardAuthorityFields } from "./authority-field-guard.js";
|
|
5
|
+
import { deleteOwnedRow } from "./owner-delete-recheck.js";
|
|
6
|
+
import { txnPausePoint } from "./txn-pause-point.js";
|
|
4
7
|
import { makeAuthGate, makeReadScope, makeScopedSearch, makeByIdReadGate, resolveAuthGate, stampAttribution, FORBIDDEN, UNAUTH, } from "./record-type-kit.js";
|
|
5
8
|
import { RECORD_TYPES } from "./record-types.js";
|
|
6
9
|
// Parameterized from RECORD_TYPES.MemoryCandidate (record-types slice 2,
|
|
@@ -51,8 +54,11 @@ const memoryCandidateAuthGate = makeAuthGate();
|
|
|
51
54
|
* (mirrors MemoryGrant.ts's delete() ownership check). Internal calls (the
|
|
52
55
|
* FLAIR-NIGHTLY-REM staging writer — resources/MemoryReflect.ts's
|
|
53
56
|
* `databases.flair.MemoryCandidate.put(row)` — and resources/health.ts's
|
|
54
|
-
* pending-count read) and admin agents pass
|
|
55
|
-
* like every other table this pattern covers.
|
|
57
|
+
* pending-count read) and admin agents pass the ownership checks of every
|
|
58
|
+
* method unfiltered, exactly like every other table this pattern covers. The
|
|
59
|
+
* promoted-row identity (`promotedRowId`, `promotedRowInstanceToken`,
|
|
60
|
+
* flair#2645) is server-written: a REST POST, PUT or PATCH that changes it is
|
|
61
|
+
* refused for every caller, admin included.
|
|
56
62
|
*/
|
|
57
63
|
export class MemoryCandidate extends databases.flair.MemoryCandidate {
|
|
58
64
|
/**
|
|
@@ -112,6 +118,10 @@ export class MemoryCandidate extends databases.flair.MemoryCandidate {
|
|
|
112
118
|
const auth = await resolveAgentAuth(ctx);
|
|
113
119
|
if (auth.kind === "anonymous")
|
|
114
120
|
return UNAUTH();
|
|
121
|
+
// flair#2645: the promoted-row identity is server-written.
|
|
122
|
+
const authorityDenial = await guardAuthorityFields(() => undefined, content, "MemoryCandidate");
|
|
123
|
+
if (authorityDenial)
|
|
124
|
+
return authorityDenial;
|
|
115
125
|
const attr = stampAttribution(auth, content, RECORD_TYPES.MemoryCandidate.ownerField, RECORD_TYPES.MemoryCandidate.attribution.post, "forbidden: cannot stage a memory candidate for another agent");
|
|
116
126
|
if (attr.denied)
|
|
117
127
|
return attr.denied;
|
|
@@ -132,12 +142,18 @@ export class MemoryCandidate extends databases.flair.MemoryCandidate {
|
|
|
132
142
|
const denial = await guardOwnerFieldImmutable(this, () => super.get(), content, "agentId");
|
|
133
143
|
if (denial)
|
|
134
144
|
return denial;
|
|
145
|
+
const authorityDenial = await guardAuthorityFields(() => super.get(), content, "MemoryCandidate");
|
|
146
|
+
if (authorityDenial)
|
|
147
|
+
return authorityDenial;
|
|
135
148
|
return super.patch(content, query);
|
|
136
149
|
}
|
|
137
150
|
async put(content) {
|
|
138
151
|
const __ownerDenial = await guardOwnerFieldImmutable(this, () => super.get(), content, "agentId");
|
|
139
152
|
if (__ownerDenial)
|
|
140
153
|
return __ownerDenial;
|
|
154
|
+
const __authorityDenial = await guardAuthorityFields(() => super.get(), content, "MemoryCandidate");
|
|
155
|
+
if (__authorityDenial)
|
|
156
|
+
return __authorityDenial;
|
|
141
157
|
const ctx = this.getContext?.();
|
|
142
158
|
const auth = await resolveAgentAuth(ctx);
|
|
143
159
|
if (auth.kind === "anonymous")
|
|
@@ -166,6 +182,24 @@ export class MemoryCandidate extends databases.flair.MemoryCandidate {
|
|
|
166
182
|
if (record[RECORD_TYPES.MemoryCandidate.ownerField] !== gate.agentId) {
|
|
167
183
|
return FORBIDDEN("forbidden: cannot delete a memory candidate owned by another agent");
|
|
168
184
|
}
|
|
169
|
-
|
|
185
|
+
// flair#2355: a row that is no longer the caller's at the delete's re-read
|
|
186
|
+
// or confirmation read is refused, not deleted
|
|
187
|
+
// (resources/owner-delete-recheck.ts).
|
|
188
|
+
const beforeDelete = txnPausePoint("candidate-delete-pre");
|
|
189
|
+
if (beforeDelete)
|
|
190
|
+
await beforeDelete;
|
|
191
|
+
const outcome = await deleteOwnedRow(ctx, {
|
|
192
|
+
table: databases.flair.MemoryCandidate,
|
|
193
|
+
tableName: "MemoryCandidate",
|
|
194
|
+
id: typeof id === "string" ? id : record.id,
|
|
195
|
+
ownerField: RECORD_TYPES.MemoryCandidate.ownerField,
|
|
196
|
+
callerId: gate.agentId,
|
|
197
|
+
point: "candidate-delete",
|
|
198
|
+
});
|
|
199
|
+
if (outcome.kind === "refused")
|
|
200
|
+
return outcome.response;
|
|
201
|
+
if (outcome.kind === "absent")
|
|
202
|
+
return super.delete(id, context);
|
|
203
|
+
return outcome.result;
|
|
170
204
|
}
|
|
171
205
|
}
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
* prompt string
|
|
17
17
|
*/
|
|
18
18
|
import { Resource, databases } from "harper";
|
|
19
|
-
import {
|
|
19
|
+
import { annotatedCallerIsAdmin, allowVerified } from "./agent-auth.js";
|
|
20
20
|
import { evaluate, parseDuration } from "./memory-consolidate-lib.js";
|
|
21
21
|
import { applyHitStats } from "./hit-tracking.js";
|
|
22
22
|
export class ConsolidateMemories extends Resource {
|
|
@@ -35,7 +35,7 @@ export class ConsolidateMemories extends Resource {
|
|
|
35
35
|
const request = ctx?.request ?? ctx;
|
|
36
36
|
const actorId = request?.tpsAgent;
|
|
37
37
|
const callerIsAdmin = request?.tpsAgentIsAdmin === true
|
|
38
|
-
|| (
|
|
38
|
+
|| (await annotatedCallerIsAdmin(request));
|
|
39
39
|
if (!bodyAgentId && !actorId) {
|
|
40
40
|
return new Response(JSON.stringify({ error: "agentId required" }), { status: 400 });
|
|
41
41
|
}
|
|
@@ -57,7 +57,9 @@ import { mkdirSync, writeFileSync } from "node:fs";
|
|
|
57
57
|
import { setImmediate as yieldToRequests } from "node:timers/promises";
|
|
58
58
|
import { dirname } from "node:path";
|
|
59
59
|
import { allowAdmin } from "./agent-auth.js";
|
|
60
|
+
import { txnPausePoint } from "./txn-pause-point.js";
|
|
60
61
|
import { retrieveCandidates } from "./semantic-retrieval-core.js";
|
|
62
|
+
import { embeddingSpaceVerdict, spaceGuardState } from "./embedding-space-guard.js";
|
|
61
63
|
import { DEDUP_COSINE_THRESHOLD_DEFAULT } from "./dedup.js";
|
|
62
64
|
import { countDedupClusters, DEDUP_CLUSTER_ANN_K_DEFAULT, DEDUP_CLUSTER_MAX_MEMORIES_DEFAULT, REM_DEDUP_STATS_PATH, } from "./dedup-cluster.js";
|
|
63
65
|
const NOT_ARCHIVED = [{ attribute: "archived", comparator: "not_equal", value: true }];
|
|
@@ -67,6 +69,18 @@ function persistStat(stat, pathOverride) {
|
|
|
67
69
|
mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
68
70
|
writeFileSync(path, JSON.stringify(stat, null, 2) + "\n", { mode: 0o600 });
|
|
69
71
|
}
|
|
72
|
+
/** The refusal body when uniformity is not established: no vector-derived counts, the
|
|
73
|
+
* guard's named state instead. Shared by the opening consult and the pre-persist
|
|
74
|
+
* re-check (flair#2596). */
|
|
75
|
+
function guardRefusal(v, computedAt) {
|
|
76
|
+
return {
|
|
77
|
+
clusterCount: null,
|
|
78
|
+
largestClusterSize: null,
|
|
79
|
+
totalMemoriesInClusters: null,
|
|
80
|
+
computedAt,
|
|
81
|
+
embeddingSpace: { state: v.state, reason: v.reason },
|
|
82
|
+
};
|
|
83
|
+
}
|
|
70
84
|
/**
|
|
71
85
|
* The DB-touching sweep, factored out of post() so it takes an explicit
|
|
72
86
|
* `ctx` and `nowOverride`/`pathOverride` rather than reaching for Resource
|
|
@@ -156,7 +170,17 @@ async function computeAndPersist(ctx, opts) {
|
|
|
156
170
|
const clusters = countDedupClusters(edges);
|
|
157
171
|
const computedAt = (opts?.nowOverride ?? new Date()).toISOString();
|
|
158
172
|
const result = { ...clusters, computedAt };
|
|
159
|
-
// ── 4.
|
|
173
|
+
// ── 4. Re-check the guard (flair#2596). The opening consult ran before any
|
|
174
|
+
// of the ANN work above; a guarded write carrying a foreign stamp can trip
|
|
175
|
+
// the latch during the sweep. Refuse new counts unless uniformity still holds.
|
|
176
|
+
const pause = txnPausePoint("dedup-sweep-persist");
|
|
177
|
+
if (pause)
|
|
178
|
+
await pause;
|
|
179
|
+
await embeddingSpaceVerdict();
|
|
180
|
+
const finalVerdict = spaceGuardState();
|
|
181
|
+
if (finalVerdict.state !== "uniform")
|
|
182
|
+
return guardRefusal(finalVerdict, computedAt);
|
|
183
|
+
// ── 5. Persist server-side ONLY the aggregate (never per-memory edges).
|
|
160
184
|
persistStat(result, opts?.pathOverride);
|
|
161
185
|
return result;
|
|
162
186
|
}
|
|
@@ -167,6 +191,11 @@ export class MemoryDedupStats extends Resource {
|
|
|
167
191
|
async post(_data) {
|
|
168
192
|
const ctx = this.getContext?.();
|
|
169
193
|
try {
|
|
194
|
+
// ─── Vector-space uniformity guard (flair#2559) ──────────────────────
|
|
195
|
+
// Consult the shared guard at the start of the sweep.
|
|
196
|
+
const verdict = await embeddingSpaceVerdict();
|
|
197
|
+
if (!verdict.uniform)
|
|
198
|
+
return guardRefusal(verdict, new Date().toISOString());
|
|
170
199
|
return await computeAndPersist(ctx);
|
|
171
200
|
}
|
|
172
201
|
catch (err) {
|