@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/commands/restore.js
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
|
-
import { resolveAdminUser } from "../lib/auth-resolve.js";
|
|
1
|
+
import { addAdminPassOptions, isLocalBase, resolveAdminUser, sendJsonRequest } from "../lib/auth-resolve.js";
|
|
2
|
+
import { readBackupArtifact } from "../lib/backup-artifact.js";
|
|
3
|
+
import { loadApprovedArchive } from "../lib/backup-approval-store.js";
|
|
4
|
+
import { encodeRecordId } from "../lib/record-id-path.js";
|
|
5
|
+
import { comparePreservedFields } from "../lib/restore-verify.js";
|
|
6
|
+
import { refuseSkillAssignmentWrite, skillSourceIsFilesystemPath } from "../lib/skill-assignment-preflight.js";
|
|
7
|
+
import { suppliesSoulScopeFields } from "../lib/soul-scope-fields.js";
|
|
8
|
+
import { listAgentCandidates, requireLiveListing } from "../rem/restore.js";
|
|
2
9
|
import * as render from "../render.js";
|
|
3
|
-
import { existsSync
|
|
10
|
+
import { existsSync } from "node:fs";
|
|
4
11
|
let cli;
|
|
5
12
|
/** Bind the cli-locals this module depends on. */
|
|
6
13
|
export function bindCli(fns) {
|
|
@@ -11,14 +18,13 @@ function resolveHttpPort(...args) {
|
|
|
11
18
|
}
|
|
12
19
|
export function register(program) {
|
|
13
20
|
// ─── flair restore ────────────────────────────────────────────────────────────
|
|
14
|
-
program
|
|
21
|
+
addAdminPassOptions(program
|
|
15
22
|
.command("restore <path>")
|
|
16
23
|
.description("Import a Flair backup archive")
|
|
17
24
|
.option("--merge", "Add/update records without deleting existing (default)")
|
|
18
|
-
.option("--replace", "Delete
|
|
25
|
+
.option("--replace", "Delete archived Soul and Memory IDs first, then import")
|
|
19
26
|
.option("--port <port>", "Harper HTTP port")
|
|
20
|
-
.option("--url <url>", "Flair base URL (overrides --port)")
|
|
21
|
-
.option("--admin-pass <pass>", "Admin password (or set FLAIR_ADMIN_PASS env)")
|
|
27
|
+
.option("--url <url>", "Flair base URL (overrides --port)"), "Admin password (or set FLAIR_ADMIN_PASS env)")
|
|
22
28
|
.option("--admin-user <name>", "Admin username for Basic auth (env: FLAIR_ADMIN_USER; default: admin)")
|
|
23
29
|
.option("--dry-run", "Show what would be imported without making changes")
|
|
24
30
|
.action(async (backupPath, opts) => {
|
|
@@ -35,14 +41,69 @@ export function register(program) {
|
|
|
35
41
|
console.error(`Error: backup file not found: ${backupPath}`);
|
|
36
42
|
process.exit(1);
|
|
37
43
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
44
|
+
// Preflight (flair#2664), before any request in every mode, dry run
|
|
45
|
+
// included: read the archive once, hash and parse that one buffer, and
|
|
46
|
+
// require the hash to equal the digest flair backup wrote to
|
|
47
|
+
// `<archive>.sha256`. The parse refuses ill-formed UTF-8 or JSON, a
|
|
48
|
+
// repeated key or row id, an unsupported version, and rows restore cannot
|
|
49
|
+
// write (src/lib/restore-archive.ts).
|
|
50
|
+
//
|
|
51
|
+
// An archive with no sidecar (flair#2664 slice 1c) is admitted only by an
|
|
52
|
+
// unrevoked approval in this host's approval store
|
|
53
|
+
// (src/lib/backup-approval-store.ts) for the digest of the bytes just
|
|
54
|
+
// read, and only when the stored copy still hashes to that digest; the
|
|
55
|
+
// rows restored are parsed from that rechecked copy. A sidecar-backed
|
|
56
|
+
// archive needs no approval here.
|
|
57
|
+
const artifact = readBackupArtifact(backupPath);
|
|
58
|
+
let archive;
|
|
59
|
+
let admitted;
|
|
60
|
+
if (artifact.ok === false && (artifact.code !== "digest-missing" || artifact.sha256 === undefined)) {
|
|
61
|
+
console.error(`Error: ${artifact.reason}`);
|
|
62
|
+
process.exitCode = 1;
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
if (artifact.ok === false) {
|
|
66
|
+
const approved = loadApprovedArchive(artifact.sha256);
|
|
67
|
+
if (approved.ok === false) {
|
|
68
|
+
const reapprove = approved.code === "store-unsafe" || approved.code === "record-invalid"
|
|
69
|
+
? ""
|
|
70
|
+
: ` Approve the archive again on this host with flair backup-approval legacy-admit ${backupPath}.`;
|
|
71
|
+
const reason = approved.code === "not-approved"
|
|
72
|
+
? artifact.reason
|
|
73
|
+
: `archive digest sidecar ${backupPath}.sha256 not found, and ${approved.reason}; restore stopped before any write.${reapprove}`;
|
|
74
|
+
console.error(`Error: ${reason}`);
|
|
75
|
+
process.exitCode = 1;
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
archive = approved.archive;
|
|
79
|
+
admitted = `${approved.sha256} (no digest sidecar; approved on this host by ${approved.record.approvedBy} ` +
|
|
80
|
+
`at ${approved.record.approvedAt}, ${approved.record.admission} admission)`;
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
archive = artifact.archive;
|
|
84
|
+
admitted = `${artifact.sha256} (matches ${artifact.digestPath})`;
|
|
85
|
+
}
|
|
86
|
+
const { agents, memories, souls } = archive;
|
|
87
|
+
const collections = [
|
|
88
|
+
{ name: "Agent", rows: agents },
|
|
89
|
+
{ name: "Soul", rows: souls },
|
|
90
|
+
{ name: "Memory", rows: memories },
|
|
91
|
+
];
|
|
92
|
+
const failures = [];
|
|
93
|
+
function fail() {
|
|
94
|
+
for (const failure of failures)
|
|
95
|
+
console.error(`Error: ${failure}`);
|
|
96
|
+
process.exitCode = 1;
|
|
42
97
|
}
|
|
43
|
-
const { agents = [], memories = [], souls = [] } = backup;
|
|
44
98
|
const auth = `Basic ${Buffer.from(`${adminUser}:${adminPass}`).toString("base64")}`;
|
|
99
|
+
// Every preflight read and every restore write targets baseUrl and refuses
|
|
100
|
+
// redirects, so a method-specific redirect is named instead of sent to a
|
|
101
|
+
// location the preflight did not check. The read raises ApiHttpError for a
|
|
102
|
+
// non-2xx reply, which is the shape the reused candidate-listing helper
|
|
103
|
+
// turns into its route guidance.
|
|
104
|
+
const preflightCall = (method, path, body) => sendJsonRequest(new URL(`${baseUrl}${path}`), method, body, auth, isLocalBase(baseUrl), { refuseRedirects: true, withholdResponseBodyDebug: true });
|
|
45
105
|
console.log(`Restoring from: ${backupPath}`);
|
|
106
|
+
console.log(`Archive SHA-256: ${admitted}`);
|
|
46
107
|
console.log(`Mode: ${mode}${dryRun ? " (dry run)" : ""}`);
|
|
47
108
|
console.log(` Agents: ${agents.length}`);
|
|
48
109
|
console.log(` Memories: ${memories.length}`);
|
|
@@ -51,77 +112,364 @@ export function register(program) {
|
|
|
51
112
|
console.log("\n✅ Dry run complete — no changes made");
|
|
52
113
|
return;
|
|
53
114
|
}
|
|
54
|
-
async function
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
115
|
+
async function adminWrite(method, path, body) {
|
|
116
|
+
try {
|
|
117
|
+
const res = await fetch(`${baseUrl}${path}`, {
|
|
118
|
+
method,
|
|
119
|
+
headers: { "Content-Type": "application/json", Authorization: auth },
|
|
120
|
+
body: body === undefined ? undefined : JSON.stringify(body),
|
|
121
|
+
redirect: "manual",
|
|
122
|
+
signal: AbortSignal.timeout(10_000),
|
|
123
|
+
});
|
|
124
|
+
if (res.status >= 300 && res.status < 400) {
|
|
125
|
+
return { status: res.status, error: undefined, redirected: true };
|
|
126
|
+
}
|
|
127
|
+
// The refusal name is read from the body, never the outcome: a body
|
|
128
|
+
// that cannot be read keeps the status this write answered with.
|
|
129
|
+
let error;
|
|
130
|
+
try {
|
|
131
|
+
error = errorName(await res.text());
|
|
132
|
+
}
|
|
133
|
+
catch {
|
|
134
|
+
error = undefined;
|
|
135
|
+
}
|
|
136
|
+
return { status: res.status, error, redirected: false };
|
|
137
|
+
}
|
|
138
|
+
catch {
|
|
139
|
+
return { status: undefined, error: undefined, redirected: false };
|
|
64
140
|
}
|
|
65
141
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
142
|
+
/** A redirect on a restore write, named rather than followed. */
|
|
143
|
+
const redirectFailure = (name, row, method, status) => `${label(name, row)}: ${method} was answered with HTTP ${status} redirect, which restore does not follow; `
|
|
144
|
+
+ "no request was sent to the redirected location";
|
|
145
|
+
/** The `error` name in a refusal body, when it carries one. */
|
|
146
|
+
function errorName(text) {
|
|
147
|
+
try {
|
|
148
|
+
const error = JSON.parse(text)?.error;
|
|
149
|
+
return typeof error === "string" ? error : undefined;
|
|
150
|
+
}
|
|
151
|
+
catch {
|
|
152
|
+
return undefined;
|
|
76
153
|
}
|
|
77
154
|
}
|
|
78
|
-
|
|
155
|
+
const label = (name, row) => `${name} ${row.id} (agent ${name === "Agent" ? row.id : row.agentId})`;
|
|
156
|
+
const diagnostic = (name, row, method, status) => `${label(name, row)}: ${method} failed (HTTP ${status ?? "unavailable"})`;
|
|
79
157
|
if (mode === "replace") {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
158
|
+
// A replace replay sends every archived Soul row back whole after
|
|
159
|
+
// deleting the archived ids. The server refuses a Soul write that
|
|
160
|
+
// supplies a non-empty `scopeTag` or `tags` array (flair#1540) or whose
|
|
161
|
+
// `value` equals a same-agent Memory content or MemoryCandidate claim
|
|
162
|
+
// (resources/soul-write-policy.ts), so a row either rule would refuse
|
|
163
|
+
// must stop the replay before the deletes, or the refused row may lose
|
|
164
|
+
// its live copy (flair#2931, #2941). Merge mode deletes nothing and is
|
|
165
|
+
// not checked here.
|
|
166
|
+
//
|
|
167
|
+
// The learned-content comparison runs against the state each Soul PUT
|
|
168
|
+
// will meet: the archived Memory ids are deleted first, and a failed
|
|
169
|
+
// Memory DELETE stops the run before any Soul delete, so those rows are
|
|
170
|
+
// gone when the Souls are written. They are written back after the Souls,
|
|
171
|
+
// so a live Memory row counts only when its id is not in the archive.
|
|
172
|
+
// Every live candidate counts: replace never deletes MemoryCandidate rows.
|
|
173
|
+
//
|
|
174
|
+
// A concurrent same-agent write between this preflight and the PUT is not
|
|
175
|
+
// covered.
|
|
176
|
+
const LEARNED_REFUSAL = "soul_value_is_learned_content";
|
|
177
|
+
const writtenSouls = souls;
|
|
178
|
+
const refusals = [];
|
|
179
|
+
const scopeRefused = new Set();
|
|
180
|
+
for (const row of writtenSouls) {
|
|
181
|
+
if (!suppliesSoulScopeFields(row))
|
|
182
|
+
continue;
|
|
183
|
+
scopeRefused.add(String(row.id));
|
|
184
|
+
refusals.push(`Error: Soul ${row.id}: the archived row supplies a non-empty scopeTag or tags array, `
|
|
185
|
+
+ "which the Soul scope-field rule refuses; edit that row in the archive, then re-run; no rows were deleted");
|
|
84
186
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
187
|
+
// The copied predicate's filesystem classification reads this CLI
|
|
188
|
+
// process's tmpdir/TMPDIR/TMP/TEMP and working directory, while the
|
|
189
|
+
// server uses its own environment (resources/skill-provenance.ts), so a
|
|
190
|
+
// filesystem-path source can be durable to one and not the other.
|
|
191
|
+
// Non-dry-run replace refuses every such row before any delete; a
|
|
192
|
+
// non-path source keeps the environment-independent copied predicate.
|
|
193
|
+
const filesystemSourceRefused = new Set();
|
|
194
|
+
for (const row of writtenSouls) {
|
|
195
|
+
const id = String(row.id);
|
|
196
|
+
if (scopeRefused.has(id))
|
|
197
|
+
continue;
|
|
198
|
+
if (!skillSourceIsFilesystemPath(row))
|
|
199
|
+
continue;
|
|
200
|
+
filesystemSourceRefused.add(id);
|
|
201
|
+
refusals.push(`Error: Soul ${row.id}: its skill-assignment source is a filesystem path, whose durability `
|
|
202
|
+
+ "the server decides from its own environment; restore without --replace, or edit that "
|
|
203
|
+
+ "row's source in the archive, then re-run; no rows were deleted");
|
|
88
204
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
205
|
+
// The Soul PUT also refuses a skill-assignment row that the copied
|
|
206
|
+
// predicate refuses. The PUT sees no stored row (`existing` is
|
|
207
|
+
// undefined) only after a successful Soul DELETE; a failed DELETE is
|
|
208
|
+
// recorded and the PUT still runs, so the stored row may still exist.
|
|
209
|
+
const writeRuleRefused = new Set();
|
|
210
|
+
for (const row of writtenSouls) {
|
|
211
|
+
const id = String(row.id);
|
|
212
|
+
if (scopeRefused.has(id) || filesystemSourceRefused.has(id))
|
|
213
|
+
continue;
|
|
214
|
+
const skillDenied = refuseSkillAssignmentWrite(row);
|
|
215
|
+
if (!skillDenied)
|
|
216
|
+
continue;
|
|
217
|
+
writeRuleRefused.add(id);
|
|
218
|
+
let code = "skill-assignment";
|
|
219
|
+
try {
|
|
220
|
+
const body = (await skillDenied.json());
|
|
221
|
+
if (typeof body?.error === "string")
|
|
222
|
+
code = body.error;
|
|
223
|
+
}
|
|
224
|
+
catch {
|
|
225
|
+
/* keep the rule name */
|
|
226
|
+
}
|
|
227
|
+
refusals.push(`Error: Soul ${row.id}: the archived row would be refused by the Soul skill-assignment rule (${code}); `
|
|
228
|
+
+ "edit that row in the archive, then re-run; no rows were deleted");
|
|
97
229
|
}
|
|
98
|
-
|
|
99
|
-
|
|
230
|
+
// Soul id -> value each Soul PUT will send, per owning agent.
|
|
231
|
+
const learnedCandidates = new Map();
|
|
232
|
+
for (const row of writtenSouls) {
|
|
233
|
+
const id = String(row.id);
|
|
234
|
+
if (scopeRefused.has(id) || filesystemSourceRefused.has(id) || writeRuleRefused.has(id))
|
|
235
|
+
continue;
|
|
236
|
+
if (typeof row.value !== "string" || row.value === "")
|
|
237
|
+
continue;
|
|
238
|
+
if (typeof row.agentId !== "string" || row.agentId === "")
|
|
239
|
+
continue;
|
|
240
|
+
let byValue = learnedCandidates.get(row.agentId);
|
|
241
|
+
if (byValue === undefined) {
|
|
242
|
+
byValue = new Map();
|
|
243
|
+
learnedCandidates.set(row.agentId, byValue);
|
|
244
|
+
}
|
|
245
|
+
const ids = byValue.get(row.value) ?? [];
|
|
246
|
+
ids.push(id);
|
|
247
|
+
byValue.set(row.value, ids);
|
|
100
248
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
249
|
+
const learnedRefusal = (soulId, table, row) => {
|
|
250
|
+
const field = table === "Memory" ? "content" : "claim";
|
|
251
|
+
const subject = row?.id === undefined || row.id === null || row.id === ""
|
|
252
|
+
? `a ${table} row without an id`
|
|
253
|
+
: `${table} ${row.id}`;
|
|
254
|
+
return `Error: Soul ${soulId}: its value equals the ${field} of the same agent's ${subject}, `
|
|
255
|
+
+ `which the Soul learned-content rule refuses (${LEARNED_REFUSAL}); `
|
|
256
|
+
+ `remove or edit that ${table} row or the archived Soul's value, then re-run; no rows were deleted`;
|
|
257
|
+
};
|
|
258
|
+
// A live Memory row whose id is in the archive is deleted before the
|
|
259
|
+
// Souls are written, so it does not count as a survivor.
|
|
260
|
+
const archivedMemoryIds = new Set(memories.filter((row) => row?.id !== undefined && row.id !== null && row.id !== "").map((row) => String(row.id)));
|
|
106
261
|
try {
|
|
107
|
-
|
|
108
|
-
|
|
262
|
+
for (const [agentId, byValue] of learnedCandidates) {
|
|
263
|
+
const liveMemories = requireLiveListing(await preflightCall("GET", `/Memory?agentId=${encodeURIComponent(agentId)}`), "Memory", agentId);
|
|
264
|
+
const survivorByContent = new Map();
|
|
265
|
+
for (const memory of liveMemories) {
|
|
266
|
+
if (!memory || typeof memory !== "object" || Array.isArray(memory)) {
|
|
267
|
+
throw new Error(`the Memory listing for agent ${agentId} carries a row that is not an object`);
|
|
268
|
+
}
|
|
269
|
+
if (memory.agentId !== agentId)
|
|
270
|
+
continue;
|
|
271
|
+
if (typeof memory.content !== "string")
|
|
272
|
+
continue;
|
|
273
|
+
const id = memory.id === undefined || memory.id === null || memory.id === "" ? undefined : String(memory.id);
|
|
274
|
+
if (id !== undefined && archivedMemoryIds.has(id))
|
|
275
|
+
continue;
|
|
276
|
+
if (!survivorByContent.has(memory.content))
|
|
277
|
+
survivorByContent.set(memory.content, memory);
|
|
278
|
+
}
|
|
279
|
+
const unmatched = new Map(byValue);
|
|
280
|
+
for (const [value, soulIds] of byValue) {
|
|
281
|
+
const match = survivorByContent.get(value);
|
|
282
|
+
if (match === undefined)
|
|
283
|
+
continue;
|
|
284
|
+
for (const soulId of soulIds)
|
|
285
|
+
refusals.push(learnedRefusal(soulId, "Memory", match));
|
|
286
|
+
unmatched.delete(value);
|
|
287
|
+
}
|
|
288
|
+
if (unmatched.size === 0)
|
|
289
|
+
continue;
|
|
290
|
+
// The admin candidate route lists ids only; each listed row is read
|
|
291
|
+
// until every unmatched value has matched, to compare its claim
|
|
292
|
+
// exactly.
|
|
293
|
+
const candidates = await listAgentCandidates(preflightCall, agentId);
|
|
294
|
+
for (const candidate of candidates) {
|
|
295
|
+
if (unmatched.size === 0)
|
|
296
|
+
break;
|
|
297
|
+
const row = await preflightCall("GET", `/MemoryCandidate/${encodeRecordId(candidate.id)}`);
|
|
298
|
+
if (!row || typeof row !== "object" || Array.isArray(row) || typeof row.claim !== "string") {
|
|
299
|
+
throw new Error(`MemoryCandidate ${candidate.id} could not be read as a row with a claim`);
|
|
300
|
+
}
|
|
301
|
+
if (row.agentId !== agentId)
|
|
302
|
+
continue;
|
|
303
|
+
const soulIds = unmatched.get(row.claim);
|
|
304
|
+
if (soulIds === undefined)
|
|
305
|
+
continue;
|
|
306
|
+
for (const soulId of soulIds)
|
|
307
|
+
refusals.push(learnedRefusal(soulId, "MemoryCandidate", candidate));
|
|
308
|
+
unmatched.delete(row.claim);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
109
311
|
}
|
|
110
312
|
catch (err) {
|
|
111
|
-
|
|
313
|
+
// A refusal already collected stays visible even when a later listing
|
|
314
|
+
// read fails: the operator should see each refusal collected so far,
|
|
315
|
+
// not only the error that stopped it (flair#2941).
|
|
316
|
+
for (const refusal of refusals)
|
|
317
|
+
console.error(refusal);
|
|
318
|
+
console.error(`Error: ${err?.message ?? String(err)}`);
|
|
319
|
+
console.error("Error: the replace stopped before any delete: a Soul write rule could not be checked against "
|
|
320
|
+
+ "the live rows; check the target's Memory listing and MemoryCandidate listing responses, "
|
|
321
|
+
+ "then re-run. No rows were deleted.");
|
|
322
|
+
process.exitCode = 1;
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
325
|
+
if (refusals.length > 0) {
|
|
326
|
+
for (const refusal of refusals)
|
|
327
|
+
console.error(refusal);
|
|
328
|
+
process.exitCode = 1;
|
|
329
|
+
return;
|
|
330
|
+
}
|
|
331
|
+
console.log("\nDeleting existing data (replace mode)...");
|
|
332
|
+
// Memory rows go first: the learned-content check above assumes the
|
|
333
|
+
// archived Memory ids are gone before a Soul write. A Memory DELETE the
|
|
334
|
+
// server refuses leaves that row in place, so stop here rather than
|
|
335
|
+
// delete a Soul whose PUT the surviving row would refuse.
|
|
336
|
+
// Archived Memories whose DELETE succeeded or whose outcome is unknown:
|
|
337
|
+
// if a later DELETE fails, attempt their write-back, verify each successful
|
|
338
|
+
// PUT, and report any PUT or verification failure by id.
|
|
339
|
+
const memoriesToRestore = [];
|
|
340
|
+
for (const row of memories) {
|
|
341
|
+
const { status, redirected } = await adminWrite("DELETE", `/Memory/${encodeRecordId(row.id)}`);
|
|
342
|
+
if (redirected) {
|
|
343
|
+
failures.push(redirectFailure("Memory", row, "DELETE", status));
|
|
344
|
+
}
|
|
345
|
+
else if (status === undefined || (status !== 404 && (status < 200 || status >= 300))) {
|
|
346
|
+
failures.push(diagnostic("Memory", row, "DELETE", status));
|
|
347
|
+
if (status === undefined)
|
|
348
|
+
memoriesToRestore.push(row);
|
|
349
|
+
}
|
|
350
|
+
else if (status >= 200 && status < 300) {
|
|
351
|
+
memoriesToRestore.push(row);
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
if (failures.length > 0) {
|
|
355
|
+
console.error("Error: a Memory DELETE failed; no Soul row was deleted.");
|
|
356
|
+
// Attempt the archived Memory write-backs, verify each successful PUT,
|
|
357
|
+
// and report any PUT or verification failure by id.
|
|
358
|
+
for (const row of memoriesToRestore) {
|
|
359
|
+
const { status, redirected } = await adminWrite("PUT", `/Memory/${encodeRecordId(row.id)}`, row);
|
|
360
|
+
if (redirected || status === undefined || status < 200 || status >= 300) {
|
|
361
|
+
failures.push(`${label("Memory", row)}: could not be restored after a later DELETE failed (`
|
|
362
|
+
+ `${redirected ? `PUT was answered with HTTP ${status} redirect, which restore does not follow` : `PUT HTTP ${status ?? "unavailable"}`})`);
|
|
363
|
+
continue;
|
|
364
|
+
}
|
|
365
|
+
let problem;
|
|
366
|
+
try {
|
|
367
|
+
const res = await fetch(`${baseUrl}/Memory/${encodeRecordId(row.id)}`, {
|
|
368
|
+
headers: { Authorization: auth },
|
|
369
|
+
redirect: "manual",
|
|
370
|
+
signal: AbortSignal.timeout(10_000),
|
|
371
|
+
});
|
|
372
|
+
if (res.status >= 300 && res.status < 400) {
|
|
373
|
+
problem = `GET verification was answered with HTTP ${res.status} redirect, which restore does not follow`;
|
|
374
|
+
}
|
|
375
|
+
else if (!res.ok) {
|
|
376
|
+
problem = `GET verification failed (HTTP ${res.status})`;
|
|
377
|
+
}
|
|
378
|
+
else {
|
|
379
|
+
const restored = await res.json();
|
|
380
|
+
const mismatched = comparePreservedFields("Memory", row, restored);
|
|
381
|
+
if (!restored || typeof restored !== "object" || Array.isArray(restored)) {
|
|
382
|
+
problem = "GET verification returned a row that is not an object";
|
|
383
|
+
}
|
|
384
|
+
else if (restored.id !== row.id) {
|
|
385
|
+
problem = "GET verification returned a different id";
|
|
386
|
+
}
|
|
387
|
+
else if (mismatched.length > 0) {
|
|
388
|
+
problem = `GET verification failed (field mismatch: ${mismatched.join(", ")})`;
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
catch {
|
|
393
|
+
problem = "GET verification failed";
|
|
394
|
+
}
|
|
395
|
+
if (problem !== undefined) {
|
|
396
|
+
failures.push(`${label("Memory", row)}: could not be restored after a later DELETE failed: ${problem}`);
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
fail();
|
|
400
|
+
return;
|
|
401
|
+
}
|
|
402
|
+
for (const row of souls) {
|
|
403
|
+
const { status, redirected } = await adminWrite("DELETE", `/Soul/${encodeRecordId(row.id)}`);
|
|
404
|
+
if (redirected) {
|
|
405
|
+
failures.push(redirectFailure("Soul", row, "DELETE", status));
|
|
406
|
+
}
|
|
407
|
+
else if (status === undefined || (status !== 404 && (status < 200 || status >= 300))) {
|
|
408
|
+
failures.push(diagnostic("Soul", row, "DELETE", status));
|
|
409
|
+
}
|
|
112
410
|
}
|
|
113
411
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
412
|
+
for (const { name, rows } of collections) {
|
|
413
|
+
console.log(`Restoring ${name} records...`);
|
|
414
|
+
for (const row of rows) {
|
|
415
|
+
const { status, error, redirected } = await adminWrite("PUT", `/${name}/${encodeRecordId(row.id)}`, row);
|
|
416
|
+
if (redirected) {
|
|
417
|
+
failures.push(redirectFailure(name, row, "PUT", status));
|
|
418
|
+
}
|
|
419
|
+
else if (status === undefined || status < 200 || status >= 300) {
|
|
420
|
+
// A failed Soul write appends the refusal name the server returned,
|
|
421
|
+
// so a learned-content 403 is named rather than read as an auth
|
|
422
|
+
// failure (flair#2931, #2941).
|
|
423
|
+
failures.push(`${diagnostic(name, row, "PUT", status)}${name === "Soul" && error ? `: ${error}` : ""}`);
|
|
424
|
+
}
|
|
120
425
|
}
|
|
121
|
-
|
|
122
|
-
|
|
426
|
+
}
|
|
427
|
+
for (const { name, rows } of collections) {
|
|
428
|
+
for (const row of rows) {
|
|
429
|
+
const path = `/${name}/${encodeRecordId(row.id)}`;
|
|
430
|
+
let status;
|
|
431
|
+
let restored;
|
|
432
|
+
let redirect;
|
|
433
|
+
try {
|
|
434
|
+
const res = await fetch(`${baseUrl}${path}`, {
|
|
435
|
+
headers: { Authorization: auth },
|
|
436
|
+
redirect: "manual",
|
|
437
|
+
signal: AbortSignal.timeout(10_000),
|
|
438
|
+
});
|
|
439
|
+
status = res.status;
|
|
440
|
+
if (res.status >= 300 && res.status < 400) {
|
|
441
|
+
redirect = res.status;
|
|
442
|
+
throw new Error();
|
|
443
|
+
}
|
|
444
|
+
if (!res.ok)
|
|
445
|
+
throw new Error();
|
|
446
|
+
restored = await res.json();
|
|
447
|
+
if (!restored || typeof restored !== "object" || Array.isArray(restored)
|
|
448
|
+
|| restored.id !== row.id
|
|
449
|
+
|| (name !== "Agent" && restored.agentId !== row.agentId)) {
|
|
450
|
+
throw new Error();
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
catch {
|
|
454
|
+
failures.push(redirect === undefined
|
|
455
|
+
? `${diagnostic(name, row, "GET", status)}: verification failed`
|
|
456
|
+
: `${label(name, row)}: GET verification was answered with HTTP ${redirect} redirect, which restore does not follow`);
|
|
457
|
+
continue;
|
|
458
|
+
}
|
|
459
|
+
// Report mismatched field names without mismatched content values.
|
|
460
|
+
const mismatched = comparePreservedFields(name, row, restored);
|
|
461
|
+
if (mismatched.length > 0) {
|
|
462
|
+
failures.push(`${label(name, row)}: GET verification failed (field mismatch: ${mismatched.join(", ")})`);
|
|
463
|
+
}
|
|
123
464
|
}
|
|
124
465
|
}
|
|
466
|
+
if (failures.length) {
|
|
467
|
+
fail();
|
|
468
|
+
return;
|
|
469
|
+
}
|
|
470
|
+
const agentCount = agents.length;
|
|
471
|
+
const memoryCount = memories.length;
|
|
472
|
+
const soulCount = souls.length;
|
|
125
473
|
console.log(`\n${render.icons.ok} ${render.wrap(render.c.green, "Restore complete")}`);
|
|
126
474
|
console.log(render.kv("Agents restored", `${render.wrap(render.c.bold, String(agentCount))}${render.wrap(render.c.dim, `/${agents.length}`)}`));
|
|
127
475
|
console.log(render.kv("Memories restored", `${render.wrap(render.c.bold, String(memoryCount))}${render.wrap(render.c.dim, `/${memories.length}`)}`));
|
package/dist/commands/search.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { buildEd25519Auth, resolveKeyPath } from "../lib/auth-resolve.js";
|
|
1
|
+
import { buildEd25519Auth, requestTarget, requestUrl, resolveKeyPath } from "../lib/auth-resolve.js";
|
|
2
2
|
import * as render from "../render.js";
|
|
3
|
+
import { DURABILITY_CAVEAT } from "../lib/durability-copy.js";
|
|
3
4
|
let cli;
|
|
4
5
|
/** Bind the cli-locals this module depends on. */
|
|
5
6
|
export function bindCli(fns) {
|
|
@@ -100,7 +101,7 @@ export function register(program) {
|
|
|
100
101
|
.option("--scoring <mode>", "Scoring mode: raw (default) uses cosine similarity/BM25 only; composite re-ranks by durability/recency/retrieval (measurably hurts precision as of flair#623 — opt-in only)", "raw")
|
|
101
102
|
.option("--min-score <n>", "Drop results below this score (0..1)", "0")
|
|
102
103
|
// Client-side filters (applied after server response)
|
|
103
|
-
.option("--durability <level>",
|
|
104
|
+
.option("--durability <level>", `Filter results by durability (permanent/persistent/standard/ephemeral; comma-separated; client-side). ${DURABILITY_CAVEAT}`)
|
|
104
105
|
.option("--source <name>", "Filter by source/agentId (client-side)")
|
|
105
106
|
// Output modes
|
|
106
107
|
.option("--explain", "Show score breakdown (raw, composite, durability, age, usage) per hit — also added to --json output as _explain")
|
|
@@ -113,10 +114,11 @@ export function register(program) {
|
|
|
113
114
|
process.exit(2);
|
|
114
115
|
}
|
|
115
116
|
const baseUrl = resolveBaseUrl(opts);
|
|
117
|
+
const url = requestUrl(baseUrl, "/SemanticSearch");
|
|
116
118
|
const headers = { "content-type": "application/json" };
|
|
117
119
|
const keyPath = opts.key || resolveKeyPath(agentId);
|
|
118
120
|
if (keyPath) {
|
|
119
|
-
headers["authorization"] = buildEd25519Auth(agentId, "POST",
|
|
121
|
+
headers["authorization"] = buildEd25519Auth(agentId, "POST", requestTarget(url), keyPath);
|
|
120
122
|
}
|
|
121
123
|
// Build payload from CLI options. Server validates types.
|
|
122
124
|
const payload = {
|
|
@@ -141,7 +143,7 @@ export function register(program) {
|
|
|
141
143
|
const minScore = Number.parseFloat(opts.minScore ?? "0");
|
|
142
144
|
if (Number.isFinite(minScore) && minScore > 0)
|
|
143
145
|
payload.minScore = minScore;
|
|
144
|
-
const res = await fetch(
|
|
146
|
+
const res = await fetch(url, {
|
|
145
147
|
method: "POST",
|
|
146
148
|
headers,
|
|
147
149
|
body: JSON.stringify(payload),
|